Lines Matching refs:ctx

226 	authsvc_context_t *ctx;  in smbd_authsvc_listen()  local
272 ctx = smbd_authctx_create(); in smbd_authsvc_listen()
273 if (ctx == NULL) { in smbd_authsvc_listen()
281 ctx->ctx_socket = ns; in smbd_authsvc_listen()
283 rc = pthread_create(&tid, &attr, smbd_authsvc_work, ctx); in smbd_authsvc_listen()
289 smbd_authctx_destroy(ctx); in smbd_authsvc_listen()
292 ctx = NULL; /* given to the new thread */ in smbd_authsvc_listen()
319 authsvc_context_t *ctx; in smbd_authctx_create() local
321 ctx = malloc(sizeof (*ctx)); in smbd_authctx_create()
322 if (ctx == NULL) in smbd_authctx_create()
324 bzero(ctx, sizeof (*ctx)); in smbd_authctx_create()
326 ctx->ctx_irawlen = smbd_authsvc_bufsize; in smbd_authctx_create()
327 ctx->ctx_irawbuf = malloc(ctx->ctx_irawlen); in smbd_authctx_create()
328 ctx->ctx_orawlen = smbd_authsvc_bufsize; in smbd_authctx_create()
329 ctx->ctx_orawbuf = malloc(ctx->ctx_orawlen); in smbd_authctx_create()
330 if (ctx->ctx_irawbuf == NULL || ctx->ctx_orawbuf == NULL) in smbd_authctx_create()
333 ctx->ctx_ibodylen = smbd_authsvc_bufsize; in smbd_authctx_create()
334 ctx->ctx_ibodybuf = malloc(ctx->ctx_ibodylen); in smbd_authctx_create()
335 ctx->ctx_obodylen = smbd_authsvc_bufsize; in smbd_authctx_create()
336 ctx->ctx_obodybuf = malloc(ctx->ctx_obodylen); in smbd_authctx_create()
337 if (ctx->ctx_ibodybuf == NULL || ctx->ctx_obodybuf == NULL) in smbd_authctx_create()
340 return (ctx); in smbd_authctx_create()
343 smbd_authctx_destroy(ctx); in smbd_authctx_create()
348 smbd_authctx_destroy(authsvc_context_t *ctx) in smbd_authctx_destroy() argument
350 if (ctx->ctx_socket != -1) { in smbd_authctx_destroy()
351 (void) close(ctx->ctx_socket); in smbd_authctx_destroy()
352 ctx->ctx_socket = -1; in smbd_authctx_destroy()
355 if (ctx->ctx_token != NULL) in smbd_authctx_destroy()
356 smb_token_destroy(ctx->ctx_token); in smbd_authctx_destroy()
358 if (ctx->ctx_itoken != NULL) in smbd_authctx_destroy()
359 spnegoFreeData(ctx->ctx_itoken); in smbd_authctx_destroy()
360 if (ctx->ctx_otoken != NULL) in smbd_authctx_destroy()
361 spnegoFreeData(ctx->ctx_otoken); in smbd_authctx_destroy()
363 free(ctx->ctx_irawbuf); in smbd_authctx_destroy()
364 free(ctx->ctx_orawbuf); in smbd_authctx_destroy()
365 free(ctx->ctx_ibodybuf); in smbd_authctx_destroy()
366 free(ctx->ctx_obodybuf); in smbd_authctx_destroy()
368 free(ctx); in smbd_authctx_destroy()
387 authsvc_context_t *ctx = arg; in smbd_authsvc_work() local
389 int sock = ctx->ctx_socket; in smbd_authsvc_work()
422 len = recv(sock, ctx->ctx_irawbuf, hdr.lmh_msglen, in smbd_authsvc_work()
429 ctx->ctx_irawtype = hdr.lmh_msgtype; in smbd_authsvc_work()
430 ctx->ctx_irawlen = hdr.lmh_msglen; in smbd_authsvc_work()
431 ctx->ctx_orawlen = smbd_authsvc_bufsize; in smbd_authsvc_work()
432 ctx->ctx_ibodylen = smbd_authsvc_bufsize; in smbd_authsvc_work()
433 ctx->ctx_obodylen = smbd_authsvc_bufsize; in smbd_authsvc_work()
438 rc = smbd_authsvc_dispatch(ctx); in smbd_authsvc_work()
442 hdr.lmh_msgtype = ctx->ctx_orawtype; in smbd_authsvc_work()
443 hdr.lmh_msglen = ctx->ctx_orawlen; in smbd_authsvc_work()
450 if (ctx->ctx_orawlen > 0) { in smbd_authsvc_work()
451 len = send(sock, ctx->ctx_orawbuf, in smbd_authsvc_work()
452 ctx->ctx_orawlen, 0); in smbd_authsvc_work()
453 if (len != ctx->ctx_orawlen) { in smbd_authsvc_work()
461 if (ctx->ctx_mh_fini) in smbd_authsvc_work()
462 (ctx->ctx_mh_fini)(ctx); in smbd_authsvc_work()
464 smbd_authctx_destroy(ctx); in smbd_authsvc_work()
478 smbd_authsvc_dispatch(authsvc_context_t *ctx) in smbd_authsvc_dispatch() argument
482 switch (ctx->ctx_irawtype) { in smbd_authsvc_dispatch()
489 rc = smbd_authsvc_oldreq(ctx); in smbd_authsvc_dispatch()
493 rc = smbd_authsvc_clinfo(ctx); in smbd_authsvc_dispatch()
497 rc = smbd_authsvc_esfirst(ctx); in smbd_authsvc_dispatch()
505 rc = smbd_authsvc_esnext(ctx); in smbd_authsvc_dispatch()
509 rc = smbd_authsvc_gettoken(ctx); in smbd_authsvc_dispatch()
523 smb_lsa_eresp_t *er = ctx->ctx_orawbuf; in smbd_authsvc_dispatch()
524 ctx->ctx_orawtype = LSA_MTYPE_ERROR; in smbd_authsvc_dispatch()
525 ctx->ctx_orawlen = sizeof (*er); in smbd_authsvc_dispatch()
534 smbd_authsvc_oldreq(authsvc_context_t *ctx) in smbd_authsvc_oldreq() argument
542 xdrmem_create(&xdrs, ctx->ctx_irawbuf, ctx->ctx_irawlen, in smbd_authsvc_oldreq()
555 ctx->ctx_token = token; in smbd_authsvc_oldreq()
561 smbd_authsvc_clinfo(authsvc_context_t *ctx) in smbd_authsvc_clinfo() argument
564 if (ctx->ctx_irawlen != sizeof (smb_lsa_clinfo_t)) in smbd_authsvc_clinfo()
566 (void) memcpy(&ctx->ctx_clinfo, ctx->ctx_irawbuf, in smbd_authsvc_clinfo()
569 ctx->ctx_orawtype = LSA_MTYPE_OK; in smbd_authsvc_clinfo()
570 ctx->ctx_orawlen = 0; in smbd_authsvc_clinfo()
581 smbd_authsvc_esfirst(authsvc_context_t *ctx) in smbd_authsvc_esfirst() argument
591 if (ctx->ctx_irawlen < 8) { in smbd_authsvc_esfirst()
599 if (bcmp(ctx->ctx_irawbuf, "NTLMSSP", 8) == 0) { in smbd_authsvc_esfirst()
600 rc = smbd_raw_ntlmssp_esfirst(ctx); in smbd_authsvc_esfirst()
607 rc = spnegoInitFromBinary(ctx->ctx_irawbuf, in smbd_authsvc_esfirst()
608 ctx->ctx_irawlen, &ctx->ctx_itoken); in smbd_authsvc_esfirst()
614 rc = spnegoGetTokenType(ctx->ctx_itoken, &ctx->ctx_itoktype); in smbd_authsvc_esfirst()
620 if (ctx->ctx_itoktype != SPNEGO_TOKEN_INIT) { in smbd_authsvc_esfirst()
622 ctx->ctx_itoktype); in smbd_authsvc_esfirst()
644 if (spnegoIsMechTypeAvailable(ctx->ctx_itoken, in smbd_authsvc_esfirst()
660 ctx->ctx_mech_oid = mh->mh_oid; in smbd_authsvc_esfirst()
661 ctx->ctx_mh_work = mh->mh_work; in smbd_authsvc_esfirst()
662 ctx->ctx_mh_fini = mh->mh_fini; in smbd_authsvc_esfirst()
663 rc = mh->mh_init(ctx); in smbd_authsvc_esfirst()
672 rc = smbd_authsvc_escmn(ctx); in smbd_authsvc_esfirst()
683 smbd_authsvc_esnext(authsvc_context_t *ctx) in smbd_authsvc_esnext() argument
691 if (ctx->ctx_mh_work == NULL) in smbd_authsvc_esnext()
694 if (ctx->ctx_mech_oid == special_mech_raw_NTLMSSP) { in smbd_authsvc_esnext()
695 rc = smbd_raw_ntlmssp_esnext(ctx); in smbd_authsvc_esnext()
702 if (ctx->ctx_itoken != NULL) { in smbd_authsvc_esnext()
703 spnegoFreeData(ctx->ctx_itoken); in smbd_authsvc_esnext()
704 ctx->ctx_itoken = NULL; in smbd_authsvc_esnext()
710 rc = spnegoInitFromBinary(ctx->ctx_irawbuf, in smbd_authsvc_esnext()
711 ctx->ctx_irawlen, &ctx->ctx_itoken); in smbd_authsvc_esnext()
715 rc = spnegoGetTokenType(ctx->ctx_itoken, &ctx->ctx_itoktype); in smbd_authsvc_esnext()
719 if (ctx->ctx_itoktype != SPNEGO_TOKEN_TARG) in smbd_authsvc_esnext()
722 rc = smbd_authsvc_escmn(ctx); in smbd_authsvc_esnext()
727 smbd_authsvc_escmn(authsvc_context_t *ctx) in smbd_authsvc_escmn() argument
736 if (ctx->ctx_otoken != NULL) { in smbd_authsvc_escmn()
737 spnegoFreeData(ctx->ctx_otoken); in smbd_authsvc_escmn()
738 ctx->ctx_otoken = NULL; in smbd_authsvc_escmn()
744 toklen = ctx->ctx_ibodylen; in smbd_authsvc_escmn()
745 rc = spnegoGetMechToken(ctx->ctx_itoken, in smbd_authsvc_escmn()
746 ctx->ctx_ibodybuf, &toklen); in smbd_authsvc_escmn()
758 ctx->ctx_ibodylen = toklen; in smbd_authsvc_escmn()
771 rc = ctx->ctx_mh_work(ctx); in smbd_authsvc_escmn()
780 if (ctx->ctx_itoktype == SPNEGO_TOKEN_INIT) { in smbd_authsvc_escmn()
782 oid = ctx->ctx_mech_oid; in smbd_authsvc_escmn()
792 switch (ctx->ctx_orawtype) { in smbd_authsvc_escmn()
794 ctx->ctx_negresult = spnego_negresult_rejected; in smbd_authsvc_escmn()
797 ctx->ctx_negresult = spnego_negresult_success; in smbd_authsvc_escmn()
800 ctx->ctx_negresult = spnego_negresult_incomplete; in smbd_authsvc_escmn()
808 ctx->ctx_negresult, in smbd_authsvc_escmn()
809 ctx->ctx_obodybuf, /* may be NULL */ in smbd_authsvc_escmn()
810 ctx->ctx_obodylen, in smbd_authsvc_escmn()
812 &ctx->ctx_otoken); in smbd_authsvc_escmn()
819 rc = spnegoTokenGetBinary(ctx->ctx_otoken, in smbd_authsvc_escmn()
820 (uchar_t *)ctx->ctx_orawbuf, &toklen); in smbd_authsvc_escmn()
823 ctx->ctx_orawlen = (uint_t)toklen; in smbd_authsvc_escmn()
835 smbd_raw_ntlmssp_esfirst(authsvc_context_t *ctx) in smbd_raw_ntlmssp_esfirst() argument
841 rc = mh->mh_init(ctx); in smbd_raw_ntlmssp_esfirst()
845 ctx->ctx_mech_oid = mh->mh_oid; in smbd_raw_ntlmssp_esfirst()
846 ctx->ctx_mh_work = mh->mh_work; in smbd_raw_ntlmssp_esfirst()
847 ctx->ctx_mh_fini = mh->mh_fini; in smbd_raw_ntlmssp_esfirst()
849 rc = smbd_raw_ntlmssp_esnext(ctx); in smbd_raw_ntlmssp_esfirst()
862 smbd_raw_ntlmssp_esnext(authsvc_context_t *ctx) in smbd_raw_ntlmssp_esnext() argument
866 ctx->ctx_ibodylen = ctx->ctx_irawlen; in smbd_raw_ntlmssp_esnext()
867 (void) memcpy(ctx->ctx_ibodybuf, in smbd_raw_ntlmssp_esnext()
868 ctx->ctx_irawbuf, ctx->ctx_irawlen); in smbd_raw_ntlmssp_esnext()
870 rc = ctx->ctx_mh_work(ctx); in smbd_raw_ntlmssp_esnext()
872 ctx->ctx_orawlen = ctx->ctx_obodylen; in smbd_raw_ntlmssp_esnext()
873 (void) memcpy(ctx->ctx_orawbuf, in smbd_raw_ntlmssp_esnext()
874 ctx->ctx_obodybuf, ctx->ctx_obodylen); in smbd_raw_ntlmssp_esnext()
884 smbd_authsvc_gettoken(authsvc_context_t *ctx) in smbd_authsvc_gettoken() argument
891 if ((token = ctx->ctx_token) == NULL) in smbd_authsvc_gettoken()
898 if (len > ctx->ctx_orawlen) { in smbd_authsvc_gettoken()
899 if ((ctx->ctx_orawbuf = realloc(ctx->ctx_orawbuf, len)) == in smbd_authsvc_gettoken()
905 ctx->ctx_orawtype = LSA_MTYPE_TOKEN; in smbd_authsvc_gettoken()
906 ctx->ctx_orawlen = len; in smbd_authsvc_gettoken()
907 xdrmem_create(&xdrs, ctx->ctx_orawbuf, len, XDR_ENCODE); in smbd_authsvc_gettoken()