Lines Matching refs:ctx

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