Lines Matching refs:ctx

281 	authsvc_context_t *ctx;  in smbd_authsvc_listen()  local
334 ctx = smbd_authctx_create(); in smbd_authsvc_listen()
335 if (ctx == NULL) { in smbd_authsvc_listen()
343 ctx->ctx_socket = ns; in smbd_authsvc_listen()
345 rc = pthread_create(&tid, &attr, smbd_authsvc_work, ctx); in smbd_authsvc_listen()
351 smbd_authctx_destroy(ctx); in smbd_authsvc_listen()
352 ctx = NULL; in smbd_authsvc_listen()
355 ctx = NULL; /* given to the new thread or destroyed */ in smbd_authsvc_listen()
383 authsvc_context_t *ctx; in smbd_authctx_create() local
385 ctx = malloc(sizeof (*ctx)); in smbd_authctx_create()
386 if (ctx == NULL) in smbd_authctx_create()
388 bzero(ctx, sizeof (*ctx)); in smbd_authctx_create()
390 ctx->ctx_irawlen = smbd_authsvc_bufsize; in smbd_authctx_create()
391 ctx->ctx_irawbuf = malloc(ctx->ctx_irawlen); in smbd_authctx_create()
392 ctx->ctx_orawlen = smbd_authsvc_bufsize; in smbd_authctx_create()
393 ctx->ctx_orawbuf = malloc(ctx->ctx_orawlen); in smbd_authctx_create()
394 if (ctx->ctx_irawbuf == NULL || ctx->ctx_orawbuf == NULL) in smbd_authctx_create()
397 ctx->ctx_ibodylen = smbd_authsvc_bufsize; in smbd_authctx_create()
398 ctx->ctx_ibodybuf = malloc(ctx->ctx_ibodylen); in smbd_authctx_create()
399 ctx->ctx_obodylen = smbd_authsvc_bufsize; in smbd_authctx_create()
400 ctx->ctx_obodybuf = malloc(ctx->ctx_obodylen); in smbd_authctx_create()
401 if (ctx->ctx_ibodybuf == NULL || ctx->ctx_obodybuf == NULL) in smbd_authctx_create()
404 return (ctx); in smbd_authctx_create()
407 smbd_authctx_destroy(ctx); in smbd_authctx_create()
412 smbd_authctx_destroy(authsvc_context_t *ctx) in smbd_authctx_destroy() argument
414 if (ctx->ctx_socket != -1) { in smbd_authctx_destroy()
415 (void) close(ctx->ctx_socket); in smbd_authctx_destroy()
416 ctx->ctx_socket = -1; in smbd_authctx_destroy()
419 if (ctx->ctx_token != NULL) in smbd_authctx_destroy()
420 smb_token_destroy(ctx->ctx_token); in smbd_authctx_destroy()
422 if (ctx->ctx_itoken != NULL) in smbd_authctx_destroy()
423 spnegoFreeData(ctx->ctx_itoken); in smbd_authctx_destroy()
424 if (ctx->ctx_otoken != NULL) in smbd_authctx_destroy()
425 spnegoFreeData(ctx->ctx_otoken); in smbd_authctx_destroy()
427 free(ctx->ctx_irawbuf); in smbd_authctx_destroy()
428 free(ctx->ctx_orawbuf); in smbd_authctx_destroy()
429 free(ctx->ctx_ibodybuf); in smbd_authctx_destroy()
430 free(ctx->ctx_obodybuf); in smbd_authctx_destroy()
432 free(ctx); in smbd_authctx_destroy()
451 authsvc_context_t *ctx = arg; in smbd_authsvc_work() local
453 int sock = ctx->ctx_socket; in smbd_authsvc_work()
486 len = recv(sock, ctx->ctx_irawbuf, hdr.lmh_msglen, in smbd_authsvc_work()
493 ctx->ctx_irawtype = hdr.lmh_msgtype; in smbd_authsvc_work()
494 ctx->ctx_irawlen = hdr.lmh_msglen; in smbd_authsvc_work()
495 ctx->ctx_orawlen = smbd_authsvc_bufsize; in smbd_authsvc_work()
496 ctx->ctx_ibodylen = smbd_authsvc_bufsize; in smbd_authsvc_work()
497 ctx->ctx_obodylen = smbd_authsvc_bufsize; in smbd_authsvc_work()
502 rc = smbd_authsvc_dispatch(ctx); in smbd_authsvc_work()
506 hdr.lmh_msgtype = ctx->ctx_orawtype; in smbd_authsvc_work()
507 hdr.lmh_msglen = ctx->ctx_orawlen; in smbd_authsvc_work()
514 if (ctx->ctx_orawlen > 0) { in smbd_authsvc_work()
515 len = send(sock, ctx->ctx_orawbuf, in smbd_authsvc_work()
516 ctx->ctx_orawlen, 0); in smbd_authsvc_work()
517 if (len != ctx->ctx_orawlen) { in smbd_authsvc_work()
525 if (ctx->ctx_mh_fini) in smbd_authsvc_work()
526 (ctx->ctx_mh_fini)(ctx); in smbd_authsvc_work()
528 smbd_authctx_destroy(ctx); in smbd_authsvc_work()
542 smbd_authsvc_dispatch(authsvc_context_t *ctx) in smbd_authsvc_dispatch() argument
546 switch (ctx->ctx_irawtype) { in smbd_authsvc_dispatch()
553 rc = smbd_authsvc_oldreq(ctx); in smbd_authsvc_dispatch()
557 rc = smbd_authsvc_clinfo(ctx); in smbd_authsvc_dispatch()
561 rc = smbd_authsvc_esfirst(ctx); in smbd_authsvc_dispatch()
569 rc = smbd_authsvc_esnext(ctx); in smbd_authsvc_dispatch()
573 rc = smbd_authsvc_gettoken(ctx); in smbd_authsvc_dispatch()
590 smb_lsa_eresp_t *er = ctx->ctx_orawbuf; in smbd_authsvc_dispatch()
591 ctx->ctx_orawtype = LSA_MTYPE_ERROR; in smbd_authsvc_dispatch()
592 ctx->ctx_orawlen = sizeof (*er); in smbd_authsvc_dispatch()
601 smbd_authsvc_oldreq(authsvc_context_t *ctx) in smbd_authsvc_oldreq() argument
609 xdrmem_create(&xdrs, ctx->ctx_irawbuf, ctx->ctx_irawlen, in smbd_authsvc_oldreq()
626 ctx->ctx_token = token; in smbd_authsvc_oldreq()
632 smbd_authsvc_clinfo(authsvc_context_t *ctx) in smbd_authsvc_clinfo() argument
635 if (ctx->ctx_irawlen != sizeof (smb_lsa_clinfo_t)) in smbd_authsvc_clinfo()
637 (void) memcpy(&ctx->ctx_clinfo, ctx->ctx_irawbuf, in smbd_authsvc_clinfo()
640 ctx->ctx_orawtype = LSA_MTYPE_OK; in smbd_authsvc_clinfo()
641 ctx->ctx_orawlen = 0; in smbd_authsvc_clinfo()
652 smbd_authsvc_esfirst(authsvc_context_t *ctx) in smbd_authsvc_esfirst() argument
662 if (ctx->ctx_irawlen < 8) { in smbd_authsvc_esfirst()
670 if (bcmp(ctx->ctx_irawbuf, "NTLMSSP", 8) == 0) { in smbd_authsvc_esfirst()
671 rc = smbd_raw_ntlmssp_esfirst(ctx); in smbd_authsvc_esfirst()
678 rc = spnegoInitFromBinary(ctx->ctx_irawbuf, in smbd_authsvc_esfirst()
679 ctx->ctx_irawlen, &ctx->ctx_itoken); in smbd_authsvc_esfirst()
685 rc = spnegoGetTokenType(ctx->ctx_itoken, &ctx->ctx_itoktype); in smbd_authsvc_esfirst()
691 if (ctx->ctx_itoktype != SPNEGO_TOKEN_INIT) { in smbd_authsvc_esfirst()
693 ctx->ctx_itoktype); in smbd_authsvc_esfirst()
715 if (spnegoIsMechTypeAvailable(ctx->ctx_itoken, in smbd_authsvc_esfirst()
731 ctx->ctx_mech_oid = mh->mh_oid; in smbd_authsvc_esfirst()
732 ctx->ctx_mh_work = mh->mh_work; in smbd_authsvc_esfirst()
733 ctx->ctx_mh_fini = mh->mh_fini; in smbd_authsvc_esfirst()
734 rc = mh->mh_init(ctx); in smbd_authsvc_esfirst()
746 rc = smbd_authsvc_newmech(ctx); in smbd_authsvc_esfirst()
751 rc = smbd_authsvc_escmn(ctx); in smbd_authsvc_esfirst()
763 smbd_authsvc_esnext(authsvc_context_t *ctx) in smbd_authsvc_esnext() argument
771 if (ctx->ctx_mh_work == NULL) in smbd_authsvc_esnext()
774 if (ctx->ctx_mech_oid == special_mech_raw_NTLMSSP) { in smbd_authsvc_esnext()
775 rc = smbd_raw_ntlmssp_esnext(ctx); in smbd_authsvc_esnext()
782 if (ctx->ctx_itoken != NULL) { in smbd_authsvc_esnext()
783 spnegoFreeData(ctx->ctx_itoken); in smbd_authsvc_esnext()
784 ctx->ctx_itoken = NULL; in smbd_authsvc_esnext()
790 rc = spnegoInitFromBinary(ctx->ctx_irawbuf, in smbd_authsvc_esnext()
791 ctx->ctx_irawlen, &ctx->ctx_itoken); in smbd_authsvc_esnext()
795 rc = spnegoGetTokenType(ctx->ctx_itoken, &ctx->ctx_itoktype); in smbd_authsvc_esnext()
799 if (ctx->ctx_itoktype != SPNEGO_TOKEN_TARG) in smbd_authsvc_esnext()
802 rc = smbd_authsvc_escmn(ctx); in smbd_authsvc_esnext()
807 smbd_authsvc_escmn(authsvc_context_t *ctx) in smbd_authsvc_escmn() argument
816 if (ctx->ctx_otoken != NULL) { in smbd_authsvc_escmn()
817 spnegoFreeData(ctx->ctx_otoken); in smbd_authsvc_escmn()
818 ctx->ctx_otoken = NULL; in smbd_authsvc_escmn()
824 toklen = ctx->ctx_ibodylen; in smbd_authsvc_escmn()
825 rc = spnegoGetMechToken(ctx->ctx_itoken, in smbd_authsvc_escmn()
826 ctx->ctx_ibodybuf, &toklen); in smbd_authsvc_escmn()
838 ctx->ctx_ibodylen = toklen; in smbd_authsvc_escmn()
851 rc = ctx->ctx_mh_work(ctx); in smbd_authsvc_escmn()
860 if (ctx->ctx_itoktype == SPNEGO_TOKEN_INIT) { in smbd_authsvc_escmn()
862 oid = ctx->ctx_mech_oid; in smbd_authsvc_escmn()
872 switch (ctx->ctx_orawtype) { in smbd_authsvc_escmn()
874 ctx->ctx_negresult = spnego_negresult_rejected; in smbd_authsvc_escmn()
877 ctx->ctx_negresult = spnego_negresult_success; in smbd_authsvc_escmn()
880 ctx->ctx_negresult = spnego_negresult_incomplete; in smbd_authsvc_escmn()
888 ctx->ctx_negresult, in smbd_authsvc_escmn()
889 ctx->ctx_obodybuf, /* may be NULL */ in smbd_authsvc_escmn()
890 ctx->ctx_obodylen, in smbd_authsvc_escmn()
892 &ctx->ctx_otoken); in smbd_authsvc_escmn()
901 rc = spnegoTokenGetBinary(ctx->ctx_otoken, in smbd_authsvc_escmn()
902 (uchar_t *)ctx->ctx_orawbuf, &toklen); in smbd_authsvc_escmn()
905 ctx->ctx_orawlen = (uint_t)toklen; in smbd_authsvc_escmn()
927 smbd_authsvc_newmech(authsvc_context_t *ctx) in smbd_authsvc_newmech() argument
936 ctx->ctx_ibodylen = 0; in smbd_authsvc_newmech()
937 ctx->ctx_orawtype = LSA_MTYPE_ES_CONT; in smbd_authsvc_newmech()
938 ctx->ctx_obodylen = 0; in smbd_authsvc_newmech()
939 ctx->ctx_negresult = spnego_negresult_request_mic; in smbd_authsvc_newmech()
942 ctx->ctx_mech_oid, in smbd_authsvc_newmech()
943 ctx->ctx_negresult, in smbd_authsvc_newmech()
946 &ctx->ctx_otoken); in smbd_authsvc_newmech()
955 rc = spnegoTokenGetBinary(ctx->ctx_otoken, in smbd_authsvc_newmech()
956 (uchar_t *)ctx->ctx_orawbuf, &toklen); in smbd_authsvc_newmech()
959 ctx->ctx_orawlen = (uint_t)toklen; in smbd_authsvc_newmech()
971 smbd_raw_ntlmssp_esfirst(authsvc_context_t *ctx) in smbd_raw_ntlmssp_esfirst() argument
977 rc = mh->mh_init(ctx); in smbd_raw_ntlmssp_esfirst()
981 ctx->ctx_mech_oid = mh->mh_oid; in smbd_raw_ntlmssp_esfirst()
982 ctx->ctx_mh_work = mh->mh_work; in smbd_raw_ntlmssp_esfirst()
983 ctx->ctx_mh_fini = mh->mh_fini; in smbd_raw_ntlmssp_esfirst()
985 rc = smbd_raw_ntlmssp_esnext(ctx); in smbd_raw_ntlmssp_esfirst()
998 smbd_raw_ntlmssp_esnext(authsvc_context_t *ctx) in smbd_raw_ntlmssp_esnext() argument
1002 ctx->ctx_ibodylen = ctx->ctx_irawlen; in smbd_raw_ntlmssp_esnext()
1003 (void) memcpy(ctx->ctx_ibodybuf, in smbd_raw_ntlmssp_esnext()
1004 ctx->ctx_irawbuf, ctx->ctx_irawlen); in smbd_raw_ntlmssp_esnext()
1006 rc = ctx->ctx_mh_work(ctx); in smbd_raw_ntlmssp_esnext()
1008 ctx->ctx_orawlen = ctx->ctx_obodylen; in smbd_raw_ntlmssp_esnext()
1009 (void) memcpy(ctx->ctx_orawbuf, in smbd_raw_ntlmssp_esnext()
1010 ctx->ctx_obodybuf, ctx->ctx_obodylen); in smbd_raw_ntlmssp_esnext()
1020 smbd_authsvc_gettoken(authsvc_context_t *ctx) in smbd_authsvc_gettoken() argument
1027 if ((token = ctx->ctx_token) == NULL) in smbd_authsvc_gettoken()
1034 if (len > ctx->ctx_orawlen) { in smbd_authsvc_gettoken()
1035 if ((ctx->ctx_orawbuf = realloc(ctx->ctx_orawbuf, len)) == in smbd_authsvc_gettoken()
1041 ctx->ctx_orawtype = LSA_MTYPE_TOKEN; in smbd_authsvc_gettoken()
1042 ctx->ctx_orawlen = len; in smbd_authsvc_gettoken()
1043 xdrmem_create(&xdrs, ctx->ctx_orawbuf, len, XDR_ENCODE); in smbd_authsvc_gettoken()