2 Unix SMB/CIFS implementation.
4 RFC2478 Compliant SPNEGO implementation
6 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 Copyright (C) Stefan Metzmacher <metze@samba.org> 2004-2008
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "lib/util/tevent_ntstatus.h"
28 #include "../libcli/auth/spnego.h"
29 #include "librpc/gen_ndr/ndr_dcerpc.h"
30 #include "auth/credentials/credentials.h"
31 #include "auth/gensec/gensec.h"
32 #include "auth/gensec/gensec_internal.h"
33 #include "param/param.h"
34 #include "lib/util/asn1.h"
35 #include "lib/util/base64.h"
39 _PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx);
41 enum spnego_state_position {
51 enum spnego_message_type expected_packet;
52 enum spnego_state_position state_position;
53 struct gensec_security *sub_sec_security;
64 bool may_skip_mic_check;
70 * The following is used to implement
71 * the update token fragmentation
75 size_t out_max_length;
80 static void gensec_spnego_update_sub_abort(struct spnego_state *spnego_state)
82 spnego_state->sub_sec_ready = false;
83 TALLOC_FREE(spnego_state->sub_sec_security);
86 static NTSTATUS gensec_spnego_client_start(struct gensec_security *gensec_security)
88 struct spnego_state *spnego_state;
90 spnego_state = talloc_zero(gensec_security, struct spnego_state);
92 return NT_STATUS_NO_MEMORY;
95 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
96 spnego_state->state_position = SPNEGO_CLIENT_START;
97 spnego_state->sub_sec_security = NULL;
98 spnego_state->sub_sec_ready = false;
99 spnego_state->mech_types = data_blob_null;
100 spnego_state->out_max_length = gensec_max_update_size(gensec_security);
101 spnego_state->out_status = NT_STATUS_MORE_PROCESSING_REQUIRED;
103 spnego_state->simulate_w2k = gensec_setting_bool(gensec_security->settings,
104 "spnego", "simulate_w2k", false);
106 gensec_security->private_data = spnego_state;
110 static NTSTATUS gensec_spnego_server_start(struct gensec_security *gensec_security)
112 struct spnego_state *spnego_state;
114 spnego_state = talloc_zero(gensec_security, struct spnego_state);
116 return NT_STATUS_NO_MEMORY;
119 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
120 spnego_state->state_position = SPNEGO_SERVER_START;
121 spnego_state->sub_sec_security = NULL;
122 spnego_state->sub_sec_ready = false;
123 spnego_state->mech_types = data_blob_null;
124 spnego_state->out_max_length = gensec_max_update_size(gensec_security);
125 spnego_state->out_status = NT_STATUS_MORE_PROCESSING_REQUIRED;
127 spnego_state->simulate_w2k = gensec_setting_bool(gensec_security->settings,
128 "spnego", "simulate_w2k", false);
130 gensec_security->private_data = spnego_state;
134 /** Fallback to another GENSEC mechanism, based on magic strings
136 * This is the 'fallback' case, where we don't get SPNEGO, and have to
137 * try all the other options (and hope they all have a magic string
141 static NTSTATUS gensec_spnego_server_try_fallback(struct gensec_security *gensec_security,
142 struct spnego_state *spnego_state,
147 const struct gensec_security_ops **all_ops;
149 all_ops = gensec_security_mechs(gensec_security, mem_ctx);
151 for (i=0; all_ops && all_ops[i]; i++) {
155 if (gensec_security != NULL &&
156 !gensec_security_ops_enabled(all_ops[i], gensec_security))
161 if (!all_ops[i]->oid) {
166 for (j=0; all_ops[i]->oid[j]; j++) {
167 if (strcasecmp(GENSEC_OID_SPNEGO,all_ops[i]->oid[j]) == 0) {
175 if (!all_ops[i]->magic) {
179 nt_status = all_ops[i]->magic(gensec_security, &in);
180 if (!NT_STATUS_IS_OK(nt_status)) {
184 spnego_state->state_position = SPNEGO_FALLBACK;
186 nt_status = gensec_subcontext_start(spnego_state,
188 &spnego_state->sub_sec_security);
190 if (!NT_STATUS_IS_OK(nt_status)) {
193 /* select the sub context */
194 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
196 if (!NT_STATUS_IS_OK(nt_status)) {
202 DEBUG(1, ("Failed to parse SPNEGO request\n"));
203 return NT_STATUS_INVALID_PARAMETER;
206 /** create a negTokenInit
208 * This is the same packet, no matter if the client or server sends it first, but it is always the first packet
210 static NTSTATUS gensec_spnego_create_negTokenInit(struct gensec_security *gensec_security,
211 struct spnego_state *spnego_state,
212 TALLOC_CTX *out_mem_ctx,
213 struct tevent_context *ev,
217 NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER;
218 const char **mechTypes = NULL;
219 DATA_BLOB unwrapped_out = data_blob_null;
220 const struct gensec_security_ops_wrapper *all_sec;
221 const char **send_mech_types = NULL;
222 struct spnego_data spnego_out;
225 mechTypes = gensec_security_oids(gensec_security,
226 out_mem_ctx, GENSEC_OID_SPNEGO);
228 all_sec = gensec_security_by_oid_list(gensec_security,
232 for (i=0; all_sec && all_sec[i].op; i++) {
233 const char *next = NULL;
234 const char *principal = NULL;
235 int dbg_level = DBGLVL_WARNING;
237 nt_status = gensec_subcontext_start(spnego_state,
239 &spnego_state->sub_sec_security);
240 if (!NT_STATUS_IS_OK(nt_status)) {
243 /* select the sub context */
244 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
246 if (!NT_STATUS_IS_OK(nt_status)) {
247 gensec_spnego_update_sub_abort(spnego_state);
251 if (spnego_state->state_position != SPNEGO_CLIENT_START) {
253 * The server doesn't generate an optimistic token.
258 /* In the client, try and produce the first (optimistic) packet */
259 nt_status = gensec_update_ev(spnego_state->sub_sec_security,
264 if (NT_STATUS_IS_OK(nt_status)) {
265 spnego_state->sub_sec_ready = true;
268 if (!GENSEC_UPDATE_IS_NTERROR(nt_status)) {
272 if (all_sec[i+1].op != NULL) {
273 next = all_sec[i+1].op->name;
274 dbg_level = DBGLVL_NOTICE;
277 if (gensec_security->target.principal != NULL) {
278 principal = gensec_security->target.principal;
279 } else if (gensec_security->target.service != NULL &&
280 gensec_security->target.hostname != NULL)
282 principal = talloc_asprintf(spnego_state->sub_sec_security,
284 gensec_security->target.service,
285 gensec_security->target.hostname);
287 principal = gensec_security->target.hostname;
290 DEBUG(dbg_level, ("SPNEGO(%s) creating NEG_TOKEN_INIT for %s failed (next[%s]): %s\n",
291 spnego_state->sub_sec_security->ops->name,
293 next, nt_errstr(nt_status)));
296 * Pretend we never started it
298 gensec_spnego_update_sub_abort(spnego_state);
301 DEBUG(10, ("Failed to setup SPNEGO negTokenInit request: %s\n", nt_errstr(nt_status)));
305 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
307 send_mech_types = gensec_security_oids_from_ops_wrapped(out_mem_ctx,
310 ok = spnego_write_mech_types(spnego_state,
312 &spnego_state->mech_types);
314 DEBUG(1, ("SPNEGO: Failed to write mechTypes\n"));
315 return NT_STATUS_NO_MEMORY;
318 /* List the remaining mechs as options */
319 spnego_out.negTokenInit.mechTypes = send_mech_types;
320 spnego_out.negTokenInit.reqFlags = data_blob_null;
321 spnego_out.negTokenInit.reqFlagsPadding = 0;
323 if (spnego_state->state_position == SPNEGO_SERVER_START) {
324 spnego_out.negTokenInit.mechListMIC
325 = data_blob_string_const(ADS_IGNORE_PRINCIPAL);
327 spnego_out.negTokenInit.mechListMIC = data_blob_null;
330 spnego_out.negTokenInit.mechToken = unwrapped_out;
332 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
333 DEBUG(1, ("Failed to write NEG_TOKEN_INIT\n"));
334 return NT_STATUS_INVALID_PARAMETER;
338 spnego_state->neg_oid = all_sec[i].oid;
340 if (spnego_state->state_position == SPNEGO_SERVER_START) {
341 spnego_state->state_position = SPNEGO_SERVER_START;
342 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
344 spnego_state->state_position = SPNEGO_CLIENT_TARG;
345 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
348 return NT_STATUS_MORE_PROCESSING_REQUIRED;
351 static NTSTATUS gensec_spnego_client_negTokenInit(struct gensec_security *gensec_security,
352 struct spnego_state *spnego_state,
353 struct tevent_context *ev,
354 struct spnego_data *spnego_in,
355 TALLOC_CTX *out_mem_ctx,
358 TALLOC_CTX *frame = talloc_stackframe();
359 DATA_BLOB sub_out = data_blob_null;
360 const char *tp = NULL;
361 const char * const *mech_types = NULL;
363 const struct gensec_security_ops_wrapper *all_sec = NULL;
364 struct spnego_data spnego_out;
365 const char *my_mechs[] = {NULL, NULL};
369 *out = data_blob_null;
371 /* The server offers a list of mechanisms */
373 tp = spnego_in->negTokenInit.targetPrincipal;
374 if (tp != NULL && strcmp(tp, ADS_IGNORE_PRINCIPAL) != 0) {
375 DBG_INFO("Server claims it's principal name is %s\n", tp);
376 if (lpcfg_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
377 gensec_set_target_principal(gensec_security, tp);
381 mech_types = spnego_in->negTokenInit.mechTypes;
382 if (mech_types == NULL) {
384 return NT_STATUS_INVALID_PARAMETER;
387 all_sec = gensec_security_by_oid_list(gensec_security,
390 if (all_sec == NULL) {
391 DBG_WARNING("gensec_security_by_oid_list() failed\n");
393 return NT_STATUS_INVALID_PARAMETER;
396 for (; all_sec[all_idx].op; all_idx++) {
397 const struct gensec_security_ops_wrapper *cur_sec =
399 const char *next = NULL;
400 const char *principal = NULL;
401 int dbg_level = DBGLVL_WARNING;
402 bool allow_fallback = false;
404 status = gensec_subcontext_start(spnego_state,
406 &spnego_state->sub_sec_security);
407 if (!NT_STATUS_IS_OK(status)) {
412 /* select the sub context */
413 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
415 if (!NT_STATUS_IS_OK(status)) {
417 * Pretend we never started it.
419 gensec_spnego_update_sub_abort(spnego_state);
423 spnego_state->neg_oid = cur_sec->oid;
426 * As client we don't use an optimistic token from the server.
428 status = gensec_update_ev(spnego_state->sub_sec_security,
429 frame, ev, data_blob_null, &sub_out);
430 if (NT_STATUS_IS_OK(status)) {
431 spnego_state->sub_sec_ready = true;
434 if (!GENSEC_UPDATE_IS_NTERROR(status)) {
435 /* OK or MORE_PROCESSING_REQUIRED */
440 * it is likely that a NULL input token will
441 * not be liked by most server mechs, but if
442 * we are in the client, we want the first
443 * update packet to be able to abort the use
446 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
447 NT_STATUS_EQUAL(status, NT_STATUS_NO_LOGON_SERVERS) ||
448 NT_STATUS_EQUAL(status, NT_STATUS_TIME_DIFFERENCE_AT_DC) ||
449 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO))
451 allow_fallback = true;
454 if (allow_fallback && cur_sec[1].op != NULL) {
455 next = cur_sec[1].op->name;
456 dbg_level = DBGLVL_NOTICE;
459 if (gensec_security->target.principal != NULL) {
460 principal = gensec_security->target.principal;
461 } else if (gensec_security->target.service != NULL &&
462 gensec_security->target.hostname != NULL)
464 principal = talloc_asprintf(spnego_state->sub_sec_security,
466 gensec_security->target.service,
467 gensec_security->target.hostname);
469 principal = gensec_security->target.hostname;
472 DBG_PREFIX(dbg_level, (
473 "%s: creating NEG_TOKEN_INIT "
474 "for %s failed (next[%s]): %s\n",
475 spnego_state->sub_sec_security->ops->name,
476 principal, next, nt_errstr(status)));
480 * A hard error without a possible fallback.
487 * Pretend we never started it.
489 gensec_spnego_update_sub_abort(spnego_state);
492 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
494 return NT_STATUS_INVALID_PARAMETER;
497 my_mechs[0] = spnego_state->neg_oid;
499 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
500 spnego_out.negTokenInit.mechTypes = my_mechs;
501 spnego_out.negTokenInit.reqFlags = data_blob_null;
502 spnego_out.negTokenInit.reqFlagsPadding = 0;
503 spnego_out.negTokenInit.mechListMIC = data_blob_null;
504 spnego_out.negTokenInit.mechToken = sub_out;
506 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
507 DBG_ERR("Failed to write SPNEGO reply to NEG_TOKEN_INIT\n");
509 return NT_STATUS_INVALID_PARAMETER;
512 ok = spnego_write_mech_types(spnego_state,
514 &spnego_state->mech_types);
516 DBG_ERR("failed to write mechTypes\n");
518 return NT_STATUS_NO_MEMORY;
522 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
523 spnego_state->state_position = SPNEGO_CLIENT_TARG;
526 return NT_STATUS_MORE_PROCESSING_REQUIRED;
529 static NTSTATUS gensec_spnego_client_negTokenTarg(struct gensec_security *gensec_security,
530 struct spnego_state *spnego_state,
531 struct tevent_context *ev,
532 struct spnego_data *spnego_in,
533 TALLOC_CTX *out_mem_ctx,
536 struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
537 DATA_BLOB sub_in = ta->responseToken;
538 DATA_BLOB mech_list_mic = data_blob_null;
539 DATA_BLOB sub_out = data_blob_null;
540 struct spnego_data spnego_out;
543 *out = data_blob_null;
545 spnego_state->num_targs++;
547 if (ta->negResult == SPNEGO_REJECT) {
548 return NT_STATUS_LOGON_FAILURE;
551 if (ta->negResult == SPNEGO_REQUEST_MIC) {
552 spnego_state->mic_requested = true;
555 if (ta->mechListMIC.length > 0) {
556 DATA_BLOB *m = &ta->mechListMIC;
557 const DATA_BLOB *r = &ta->responseToken;
560 * Windows 2000 has a bug, it repeats the
561 * responseToken in the mechListMIC field.
563 if (m->length == r->length) {
566 cmp = memcmp(m->data, r->data, m->length);
573 /* Server didn't like our choice of mech, and chose something else */
574 if (((ta->negResult == SPNEGO_ACCEPT_INCOMPLETE) ||
575 (ta->negResult == SPNEGO_REQUEST_MIC)) &&
576 ta->supportedMech != NULL &&
577 strcmp(ta->supportedMech, spnego_state->neg_oid) != 0)
579 const char *client_mech = NULL;
580 const char *client_oid = NULL;
581 const char *server_mech = NULL;
582 const char *server_oid = NULL;
584 client_mech = gensec_get_name_by_oid(gensec_security,
585 spnego_state->neg_oid);
586 client_oid = spnego_state->neg_oid;
587 server_mech = gensec_get_name_by_oid(gensec_security,
589 server_oid = ta->supportedMech;
591 DBG_NOTICE("client preferred mech (%s[%s]) not accepted, "
592 "server wants: %s[%s]\n",
593 client_mech, client_oid, server_mech, server_oid);
595 spnego_state->downgraded = true;
596 gensec_spnego_update_sub_abort(spnego_state);
598 status = gensec_subcontext_start(spnego_state,
600 &spnego_state->sub_sec_security);
601 if (!NT_STATUS_IS_OK(status)) {
605 /* select the sub context */
606 status = gensec_start_mech_by_oid(spnego_state->sub_sec_security,
608 if (!NT_STATUS_IS_OK(status)) {
612 spnego_state->neg_oid = talloc_strdup(spnego_state,
614 if (spnego_state->neg_oid == NULL) {
615 return NT_STATUS_NO_MEMORY;
619 if (ta->mechListMIC.length > 0) {
620 if (spnego_state->sub_sec_ready) {
621 spnego_state->needs_mic_check = true;
625 if (spnego_state->needs_mic_check) {
626 if (ta->responseToken.length != 0) {
627 DBG_WARNING("non empty response token not expected\n");
628 return NT_STATUS_INVALID_PARAMETER;
631 if (ta->mechListMIC.length == 0
632 && spnego_state->may_skip_mic_check) {
634 * In this case we don't require
635 * a mechListMIC from the server.
637 * This works around bugs in the Azure
638 * and Apple spnego implementations.
641 * https://bugzilla.samba.org/show_bug.cgi?id=11994
643 spnego_state->needs_mic_check = false;
644 status = NT_STATUS_OK;
645 goto client_response;
648 status = gensec_check_packet(spnego_state->sub_sec_security,
649 spnego_state->mech_types.data,
650 spnego_state->mech_types.length,
651 spnego_state->mech_types.data,
652 spnego_state->mech_types.length,
654 if (!NT_STATUS_IS_OK(status)) {
655 DBG_WARNING("failed to verify mechListMIC: %s\n",
659 spnego_state->needs_mic_check = false;
660 spnego_state->done_mic_check = true;
661 goto client_response;
664 if (!spnego_state->sub_sec_ready) {
665 status = gensec_update_ev(spnego_state->sub_sec_security,
669 if (NT_STATUS_IS_OK(status)) {
670 spnego_state->sub_sec_ready = true;
672 if (!NT_STATUS_IS_OK(status)) {
673 goto client_response;
676 status = NT_STATUS_OK;
679 if (!spnego_state->done_mic_check) {
680 bool have_sign = true;
681 bool new_spnego = false;
683 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
684 GENSEC_FEATURE_SIGN);
685 if (spnego_state->simulate_w2k) {
688 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
689 GENSEC_FEATURE_NEW_SPNEGO);
691 switch (ta->negResult) {
692 case SPNEGO_ACCEPT_COMPLETED:
693 case SPNEGO_NONE_RESULT:
694 if (spnego_state->num_targs == 1) {
696 * the first exchange doesn't require
704 case SPNEGO_ACCEPT_INCOMPLETE:
705 if (ta->mechListMIC.length > 0) {
710 if (spnego_state->downgraded) {
712 * A downgrade should be protected if
719 * The caller may just asked for
720 * GENSEC_FEATURE_SESSION_KEY, this
721 * is only reflected in the want_features.
724 * gensec_have_features(GENSEC_FEATURE_SIGN)
727 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
730 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
734 * Here we're sure our preferred mech was
735 * selected by the server and our caller doesn't
736 * need GENSEC_FEATURE_SIGN nor
737 * GENSEC_FEATURE_SEAL support.
739 * In this case we don't require
740 * a mechListMIC from the server.
742 * This works around bugs in the Azure
743 * and Apple spnego implementations.
746 * https://bugzilla.samba.org/show_bug.cgi?id=11994
748 spnego_state->may_skip_mic_check = true;
751 case SPNEGO_REQUEST_MIC:
752 if (ta->mechListMIC.length > 0) {
760 if (spnego_state->mic_requested) {
766 if (have_sign && new_spnego) {
767 spnego_state->needs_mic_check = true;
768 spnego_state->needs_mic_sign = true;
772 if (ta->mechListMIC.length > 0) {
773 status = gensec_check_packet(spnego_state->sub_sec_security,
774 spnego_state->mech_types.data,
775 spnego_state->mech_types.length,
776 spnego_state->mech_types.data,
777 spnego_state->mech_types.length,
779 if (!NT_STATUS_IS_OK(status)) {
780 DBG_WARNING("failed to verify mechListMIC: %s\n",
784 spnego_state->needs_mic_check = false;
785 spnego_state->done_mic_check = true;
788 if (spnego_state->needs_mic_sign) {
789 status = gensec_sign_packet(spnego_state->sub_sec_security,
791 spnego_state->mech_types.data,
792 spnego_state->mech_types.length,
793 spnego_state->mech_types.data,
794 spnego_state->mech_types.length,
796 if (!NT_STATUS_IS_OK(status)) {
797 DBG_WARNING("failed to sign mechListMIC: %s\n",
801 spnego_state->needs_mic_sign = false;
804 if (spnego_state->needs_mic_check) {
805 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
809 if (GENSEC_UPDATE_IS_NTERROR(status)) {
810 DBG_WARNING("SPNEGO(%s) login failed: %s\n",
811 spnego_state->sub_sec_security->ops->name,
816 if (sub_out.length || mech_list_mic.length) {
818 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
819 spnego_out.negTokenTarg.negResult = SPNEGO_NONE_RESULT;
820 spnego_out.negTokenTarg.supportedMech = NULL;
821 spnego_out.negTokenTarg.responseToken = sub_out;
822 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
824 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
825 DBG_WARNING("Failed to write NEG_TOKEN_TARG\n");
826 return NT_STATUS_INVALID_PARAMETER;
829 spnego_state->num_targs++;
830 spnego_state->state_position = SPNEGO_CLIENT_TARG;
831 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
834 /* all done - server has accepted, and we agree */
835 *out = data_blob_null;
837 if (ta->negResult != SPNEGO_ACCEPT_COMPLETED) {
838 /* unless of course it did not accept */
839 DBG_WARNING("gensec_update ok but not accepted\n");
840 status = NT_STATUS_INVALID_PARAMETER;
843 spnego_state->state_position = SPNEGO_DONE;
849 /** create a server negTokenTarg
851 * This is the case, where the client is the first one who sends data
854 static NTSTATUS gensec_spnego_server_response(struct spnego_state *spnego_state,
855 TALLOC_CTX *out_mem_ctx,
857 const DATA_BLOB unwrapped_out,
858 DATA_BLOB mech_list_mic,
861 struct spnego_data spnego_out;
864 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
865 spnego_out.negTokenTarg.responseToken = unwrapped_out;
866 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
867 spnego_out.negTokenTarg.supportedMech = NULL;
869 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
870 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
871 if (spnego_state->mic_requested) {
872 spnego_out.negTokenTarg.negResult = SPNEGO_REQUEST_MIC;
873 spnego_state->mic_requested = false;
875 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
877 spnego_state->state_position = SPNEGO_SERVER_TARG;
878 } else if (NT_STATUS_IS_OK(nt_status)) {
879 if (unwrapped_out.data) {
880 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
882 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
883 spnego_state->state_position = SPNEGO_DONE;
885 spnego_out.negTokenTarg.negResult = SPNEGO_REJECT;
886 spnego_out.negTokenTarg.mechListMIC = data_blob_null;
887 DEBUG(2, ("SPNEGO login failed: %s\n", nt_errstr(nt_status)));
888 spnego_state->state_position = SPNEGO_DONE;
891 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
892 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
893 return NT_STATUS_INVALID_PARAMETER;
896 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
897 spnego_state->num_targs++;
902 static NTSTATUS gensec_spnego_server_negTokenInit(struct gensec_security *gensec_security,
903 struct spnego_state *spnego_state,
904 struct tevent_context *ev,
905 struct spnego_data *spnego_in,
906 TALLOC_CTX *out_mem_ctx,
909 TALLOC_CTX *frame = talloc_stackframe();
910 DATA_BLOB sub_out = data_blob_null;
911 DATA_BLOB mech_list_mic = data_blob_null;
912 const char * const *mech_types = NULL;
914 const struct gensec_security_ops_wrapper *all_sec = NULL;
919 mech_types = spnego_in->negTokenInit.mechTypes;
920 if (mech_types == NULL) {
922 return NT_STATUS_INVALID_PARAMETER;
925 all_sec = gensec_security_by_oid_list(gensec_security, frame,
926 mech_types, GENSEC_OID_SPNEGO);
927 if (all_sec == NULL) {
928 DBG_WARNING("gensec_security_by_oid_list() failed\n");
930 return NT_STATUS_INVALID_PARAMETER;
933 ok = spnego_write_mech_types(spnego_state, mech_types,
934 &spnego_state->mech_types);
936 DBG_ERR("Failed to write mechTypes\n");
938 return NT_STATUS_NO_MEMORY;
942 * First try the preferred mechs from the client.
944 for (; mech_types[mech_idx]; mech_idx++) {
945 const char *cur_mech = mech_types[mech_idx];
946 const struct gensec_security_ops_wrapper *cur_sec = NULL;
947 DATA_BLOB sub_in = data_blob_null;
949 for (all_idx = 0; all_sec[all_idx].op; all_idx++) {
950 if (strcmp(cur_mech, all_sec[all_idx].oid) == 0) {
951 cur_sec = &all_sec[all_idx];
956 if (cur_sec == NULL) {
960 status = gensec_subcontext_start(spnego_state,
962 &spnego_state->sub_sec_security);
963 if (!NT_STATUS_IS_OK(status)) {
968 /* select the sub context */
969 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
971 if (!NT_STATUS_IS_OK(status)) {
973 * Pretend we never started it
975 gensec_spnego_update_sub_abort(spnego_state);
981 * Indicate the downgrade and request a
984 spnego_state->downgraded = true;
985 spnego_state->mic_requested = true;
986 /* no optimistic token */
987 spnego_state->neg_oid = cur_sec->oid;
988 sub_out = data_blob_null;
989 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
994 * Try the optimistic token from the client
996 sub_in = spnego_in->negTokenInit.mechToken;
997 status = gensec_update_ev(spnego_state->sub_sec_security,
998 frame, ev, sub_in, &sub_out);
999 if (NT_STATUS_IS_OK(status)) {
1000 spnego_state->sub_sec_ready = true;
1002 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
1003 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
1005 DBG_WARNING("%s: NEG_TOKEN_INIT failed to parse contents: %s\n",
1006 cur_sec->op->name, nt_errstr(status));
1009 * Pretend we never started it
1011 gensec_spnego_update_sub_abort(spnego_state);
1015 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1016 DBG_WARNING("%s: NEG_TOKEN_INIT failed: %s\n",
1017 cur_sec->op->name, nt_errstr(status));
1021 spnego_state->neg_oid = cur_sec->oid;
1022 goto reply; /* OK or MORE PROCESSING */
1025 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
1026 status = NT_STATUS_INVALID_PARAMETER;
1029 if (spnego_state->simulate_w2k) {
1031 * Windows 2000 returns the unwrapped token
1032 * also in the mech_list_mic field.
1034 * In order to verify our client code,
1035 * we need a way to have a server with this
1038 mech_list_mic = sub_out;
1041 status = gensec_spnego_server_response(spnego_state,
1051 static NTSTATUS gensec_spnego_server_negTokenTarg(struct gensec_security *gensec_security,
1052 struct spnego_state *spnego_state,
1053 struct tevent_context *ev,
1054 struct spnego_data *spnego_in,
1055 TALLOC_CTX *out_mem_ctx,
1058 const struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
1059 DATA_BLOB sub_in = ta->responseToken;
1060 DATA_BLOB mech_list_mic = data_blob_null;
1061 DATA_BLOB sub_out = data_blob_null;
1063 bool have_sign = true;
1064 bool new_spnego = false;
1066 spnego_state->num_targs++;
1068 if (spnego_state->sub_sec_security == NULL) {
1069 DBG_ERR("SPNEGO: Did not setup a mech in NEG_TOKEN_INIT\n");
1070 return NT_STATUS_INVALID_PARAMETER;
1073 if (spnego_state->needs_mic_check) {
1074 if (ta->responseToken.length != 0) {
1075 DBG_WARNING("non empty response token not expected\n");
1076 return NT_STATUS_INVALID_PARAMETER;
1079 status = gensec_check_packet(spnego_state->sub_sec_security,
1080 spnego_state->mech_types.data,
1081 spnego_state->mech_types.length,
1082 spnego_state->mech_types.data,
1083 spnego_state->mech_types.length,
1085 if (!NT_STATUS_IS_OK(status)) {
1086 DBG_WARNING("failed to verify mechListMIC: %s\n",
1088 goto server_response;
1091 spnego_state->needs_mic_check = false;
1092 spnego_state->done_mic_check = true;
1093 goto server_response;
1096 if (!spnego_state->sub_sec_ready) {
1097 status = gensec_update_ev(spnego_state->sub_sec_security,
1100 if (NT_STATUS_IS_OK(status)) {
1101 spnego_state->sub_sec_ready = true;
1103 if (!NT_STATUS_IS_OK(status)) {
1104 goto server_response;
1107 status = NT_STATUS_OK;
1110 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
1111 GENSEC_FEATURE_SIGN);
1112 if (spnego_state->simulate_w2k) {
1115 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
1116 GENSEC_FEATURE_NEW_SPNEGO);
1117 if (ta->mechListMIC.length > 0) {
1121 if (have_sign && new_spnego) {
1122 spnego_state->needs_mic_check = true;
1123 spnego_state->needs_mic_sign = true;
1126 if (have_sign && ta->mechListMIC.length > 0) {
1127 status = gensec_check_packet(spnego_state->sub_sec_security,
1128 spnego_state->mech_types.data,
1129 spnego_state->mech_types.length,
1130 spnego_state->mech_types.data,
1131 spnego_state->mech_types.length,
1133 if (!NT_STATUS_IS_OK(status)) {
1134 DBG_WARNING("failed to verify mechListMIC: %s\n",
1136 goto server_response;
1139 spnego_state->needs_mic_check = false;
1140 spnego_state->done_mic_check = true;
1143 if (spnego_state->needs_mic_sign) {
1144 status = gensec_sign_packet(spnego_state->sub_sec_security,
1146 spnego_state->mech_types.data,
1147 spnego_state->mech_types.length,
1148 spnego_state->mech_types.data,
1149 spnego_state->mech_types.length,
1151 if (!NT_STATUS_IS_OK(status)) {
1152 DBG_WARNING("failed to sign mechListMIC: %s\n",
1156 spnego_state->needs_mic_sign = false;
1159 if (spnego_state->needs_mic_check) {
1160 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
1164 return gensec_spnego_server_response(spnego_state,
1172 struct gensec_spnego_update_state {
1173 struct tevent_context *ev;
1174 struct gensec_security *gensec;
1175 struct spnego_state *spnego;
1178 struct spnego_data _spnego_in;
1179 struct spnego_data *spnego_in;
1192 static void gensec_spnego_update_cleanup(struct tevent_req *req,
1193 enum tevent_req_state req_state)
1195 struct gensec_spnego_update_state *state =
1196 tevent_req_data(req,
1197 struct gensec_spnego_update_state);
1199 switch (req_state) {
1200 case TEVENT_REQ_USER_ERROR:
1201 case TEVENT_REQ_TIMED_OUT:
1202 case TEVENT_REQ_NO_MEMORY:
1204 * A fatal error, further updates are not allowed.
1206 state->spnego->state_position = SPNEGO_DONE;
1213 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1214 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1215 DATA_BLOB *full_in);
1216 static void gensec_spnego_update_pre(struct tevent_req *req);
1217 static void gensec_spnego_update_done(struct tevent_req *subreq);
1218 static void gensec_spnego_update_post(struct tevent_req *req);
1219 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1220 TALLOC_CTX *out_mem_ctx,
1223 static struct tevent_req *gensec_spnego_update_send(TALLOC_CTX *mem_ctx,
1224 struct tevent_context *ev,
1225 struct gensec_security *gensec_security,
1228 struct spnego_state *spnego_state =
1229 talloc_get_type_abort(gensec_security->private_data,
1230 struct spnego_state);
1231 struct tevent_req *req = NULL;
1232 struct gensec_spnego_update_state *state = NULL;
1236 req = tevent_req_create(mem_ctx, &state,
1237 struct gensec_spnego_update_state);
1242 state->gensec = gensec_security;
1243 state->spnego = spnego_state;
1244 tevent_req_set_cleanup_fn(req, gensec_spnego_update_cleanup);
1246 if (spnego_state->out_frag.length > 0) {
1247 if (in.length > 0) {
1248 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1249 return tevent_req_post(req, ev);
1252 status = gensec_spnego_update_out(gensec_security,
1253 state, &state->out);
1254 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1255 tevent_req_nterror(req, status);
1256 return tevent_req_post(req, ev);
1259 state->status = status;
1260 tevent_req_done(req);
1261 return tevent_req_post(req, ev);
1264 status = gensec_spnego_update_in(gensec_security, in,
1265 state, &state->full_in);
1266 state->status = status;
1267 if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1268 tevent_req_done(req);
1269 return tevent_req_post(req, ev);
1271 if (tevent_req_nterror(req, status)) {
1272 return tevent_req_post(req, ev);
1275 /* Check if we got a valid SPNEGO blob... */
1277 switch (spnego_state->state_position) {
1278 case SPNEGO_FALLBACK:
1281 case SPNEGO_CLIENT_TARG:
1282 case SPNEGO_SERVER_TARG:
1283 if (state->full_in.length == 0) {
1284 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1285 return tevent_req_post(req, ev);
1289 case SPNEGO_CLIENT_START:
1290 case SPNEGO_SERVER_START:
1292 if (state->full_in.length == 0) {
1293 /* create_negTokenInit later */
1297 len = spnego_read_data(state,
1299 &state->_spnego_in);
1301 if (spnego_state->state_position != SPNEGO_SERVER_START) {
1302 DEBUG(1, ("Invalid SPNEGO request:\n"));
1303 dump_data(1, state->full_in.data,
1304 state->full_in.length);
1305 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1306 return tevent_req_post(req, ev);
1310 * This is the 'fallback' case, where we don't get
1311 * SPNEGO, and have to try all the other options (and
1312 * hope they all have a magic string they check)
1314 status = gensec_spnego_server_try_fallback(gensec_security,
1318 if (tevent_req_nterror(req, status)) {
1319 return tevent_req_post(req, ev);
1323 * We'll continue with SPNEGO_FALLBACK below...
1327 state->spnego_in = &state->_spnego_in;
1329 /* OK, so it's real SPNEGO, check the packet's the one we expect */
1330 if (state->spnego_in->type != spnego_state->expected_packet) {
1331 DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n",
1332 state->spnego_in->type,
1333 spnego_state->expected_packet));
1334 dump_data(1, state->full_in.data,
1335 state->full_in.length);
1336 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1337 return tevent_req_post(req, ev);
1343 smb_panic(__location__);
1347 gensec_spnego_update_pre(req);
1348 if (!tevent_req_is_in_progress(req)) {
1349 return tevent_req_post(req, ev);
1352 if (state->sub.needed) {
1353 struct tevent_req *subreq = NULL;
1356 * We may need one more roundtrip...
1358 subreq = gensec_update_send(state, state->ev,
1359 spnego_state->sub_sec_security,
1361 if (tevent_req_nomem(subreq, req)) {
1362 return tevent_req_post(req, ev);
1364 tevent_req_set_callback(subreq,
1365 gensec_spnego_update_done,
1367 state->sub.needed = false;
1371 gensec_spnego_update_post(req);
1372 if (!tevent_req_is_in_progress(req)) {
1373 return tevent_req_post(req, ev);
1379 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1380 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1383 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1387 *full_in = data_blob_null;
1389 switch (spnego_state->state_position) {
1390 case SPNEGO_FALLBACK:
1392 spnego_state->in_needed = 0;
1393 return NT_STATUS_OK;
1395 case SPNEGO_CLIENT_START:
1396 case SPNEGO_CLIENT_TARG:
1397 case SPNEGO_SERVER_START:
1398 case SPNEGO_SERVER_TARG:
1403 return NT_STATUS_INVALID_PARAMETER;
1406 if (spnego_state->in_needed == 0) {
1411 * try to work out the size of the full
1412 * input token, it might be fragmented
1414 ret = asn1_peek_full_tag(in, ASN1_APPLICATION(0), &size);
1415 if ((ret != 0) && (ret != EAGAIN)) {
1416 ret = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
1419 if ((ret == 0) || (ret == EAGAIN)) {
1420 spnego_state->in_needed = size;
1423 * If it is not an asn1 message
1424 * just call the next layer.
1426 spnego_state->in_needed = in.length;
1430 if (spnego_state->in_needed > UINT16_MAX) {
1432 * limit the incoming message to 0xFFFF
1433 * to avoid DoS attacks.
1435 return NT_STATUS_INVALID_BUFFER_SIZE;
1438 if ((spnego_state->in_needed > 0) && (in.length == 0)) {
1440 * If we reach this, we know we got at least
1441 * part of an asn1 message, getting 0 means
1442 * the remote peer wants us to spin.
1444 return NT_STATUS_INVALID_PARAMETER;
1447 expected = spnego_state->in_needed - spnego_state->in_frag.length;
1448 if (in.length > expected) {
1450 * we got more than expected
1452 return NT_STATUS_INVALID_PARAMETER;
1455 if (in.length == spnego_state->in_needed) {
1457 * if the in.length contains the full blob
1460 * Note: this implies spnego_state->in_frag.length == 0,
1461 * but we do not need to check this explicitly
1462 * because we already know that we did not get
1463 * more than expected.
1466 spnego_state->in_needed = 0;
1467 return NT_STATUS_OK;
1470 ok = data_blob_append(spnego_state, &spnego_state->in_frag,
1471 in.data, in.length);
1473 return NT_STATUS_NO_MEMORY;
1476 if (spnego_state->in_needed > spnego_state->in_frag.length) {
1477 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1480 *full_in = spnego_state->in_frag;
1481 talloc_steal(mem_ctx, full_in->data);
1482 spnego_state->in_frag = data_blob_null;
1483 spnego_state->in_needed = 0;
1484 return NT_STATUS_OK;
1487 static void gensec_spnego_update_pre(struct tevent_req *req)
1489 struct gensec_spnego_update_state *state =
1490 tevent_req_data(req,
1491 struct gensec_spnego_update_state);
1492 struct gensec_security *gensec_security = state->gensec;
1493 struct spnego_state *spnego_state = state->spnego;
1494 struct tevent_context *ev = state->ev;
1497 state->sub.needed = false;
1498 state->sub.in = data_blob_null;
1499 state->sub.status = NT_STATUS_INTERNAL_ERROR;
1500 state->sub.out = data_blob_null;
1502 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1503 state->sub.in = state->full_in;
1504 state->full_in = data_blob_null;
1505 state->sub.needed = true;
1509 switch (spnego_state->state_position) {
1510 case SPNEGO_CLIENT_START:
1511 if (state->spnego_in == NULL) {
1512 /* client to produce negTokenInit */
1513 status = gensec_spnego_create_negTokenInit(gensec_security,
1514 spnego_state, state, ev,
1515 &spnego_state->out_frag);
1516 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1517 tevent_req_nterror(req, status);
1523 status = gensec_spnego_client_negTokenInit(gensec_security,
1525 state->spnego_in, state,
1526 &spnego_state->out_frag);
1529 case SPNEGO_CLIENT_TARG:
1530 status = gensec_spnego_client_negTokenTarg(gensec_security,
1532 state->spnego_in, state,
1533 &spnego_state->out_frag);
1534 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1535 tevent_req_nterror(req, status);
1540 case SPNEGO_SERVER_START:
1541 if (state->spnego_in == NULL) {
1542 /* server to produce negTokenInit */
1543 status = gensec_spnego_create_negTokenInit(gensec_security,
1544 spnego_state, state, ev,
1545 &spnego_state->out_frag);
1546 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1547 tevent_req_nterror(req, status);
1553 status = gensec_spnego_server_negTokenInit(gensec_security,
1555 state->spnego_in, state,
1556 &spnego_state->out_frag);
1557 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1558 tevent_req_nterror(req, status);
1563 case SPNEGO_SERVER_TARG:
1564 status = gensec_spnego_server_negTokenTarg(gensec_security,
1566 state->spnego_in, state,
1567 &spnego_state->out_frag);
1568 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1569 tevent_req_nterror(req, status);
1575 smb_panic(__location__);
1579 spnego_state->out_status = status;
1582 static void gensec_spnego_update_done(struct tevent_req *subreq)
1584 struct tevent_req *req =
1585 tevent_req_callback_data(subreq,
1587 struct gensec_spnego_update_state *state =
1588 tevent_req_data(req,
1589 struct gensec_spnego_update_state);
1590 struct spnego_state *spnego_state = state->spnego;
1592 state->sub.status = gensec_update_recv(subreq, state, &state->sub.out);
1593 TALLOC_FREE(subreq);
1594 if (NT_STATUS_IS_OK(state->sub.status)) {
1595 spnego_state->sub_sec_ready = true;
1598 gensec_spnego_update_post(req);
1601 static void gensec_spnego_update_post(struct tevent_req *req)
1603 struct gensec_spnego_update_state *state =
1604 tevent_req_data(req,
1605 struct gensec_spnego_update_state);
1606 struct spnego_state *spnego_state = state->spnego;
1609 state->sub.in = data_blob_null;
1610 state->sub.needed = false;
1612 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1613 status = state->sub.status;
1614 spnego_state->out_frag = state->sub.out;
1615 talloc_steal(spnego_state, spnego_state->out_frag.data);
1616 state->sub.out = data_blob_null;
1621 * For now just handle the sync processing done
1622 * in gensec_spnego_update_pre()
1624 status = spnego_state->out_status;
1626 if (NT_STATUS_IS_OK(status)) {
1627 bool reset_full = true;
1629 reset_full = !spnego_state->done_mic_check;
1631 status = gensec_may_reset_crypto(spnego_state->sub_sec_security,
1633 if (tevent_req_nterror(req, status)) {
1639 spnego_state->out_status = status;
1641 status = gensec_spnego_update_out(state->gensec,
1642 state, &state->out);
1643 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1644 tevent_req_nterror(req, status);
1648 state->status = status;
1649 tevent_req_done(req);
1653 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1654 TALLOC_CTX *out_mem_ctx,
1657 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1658 DATA_BLOB out = data_blob_null;
1661 *_out = data_blob_null;
1663 if (spnego_state->out_frag.length <= spnego_state->out_max_length) {
1665 * Fast path, we can deliver everything
1668 *_out = spnego_state->out_frag;
1669 if (spnego_state->out_frag.length > 0) {
1670 talloc_steal(out_mem_ctx, _out->data);
1671 spnego_state->out_frag = data_blob_null;
1674 if (!NT_STATUS_IS_OK(spnego_state->out_status)) {
1675 return spnego_state->out_status;
1679 * We're completely done, further updates are not allowed.
1681 spnego_state->state_position = SPNEGO_DONE;
1682 return gensec_child_ready(gensec_security,
1683 spnego_state->sub_sec_security);
1686 out = spnego_state->out_frag;
1689 * copy the remaining bytes
1691 spnego_state->out_frag = data_blob_talloc(spnego_state,
1692 out.data + spnego_state->out_max_length,
1693 out.length - spnego_state->out_max_length);
1694 if (spnego_state->out_frag.data == NULL) {
1695 return NT_STATUS_NO_MEMORY;
1699 * truncate the buffer
1701 ok = data_blob_realloc(spnego_state, &out,
1702 spnego_state->out_max_length);
1704 return NT_STATUS_NO_MEMORY;
1707 talloc_steal(out_mem_ctx, out.data);
1709 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1712 static NTSTATUS gensec_spnego_update_recv(struct tevent_req *req,
1713 TALLOC_CTX *out_mem_ctx,
1716 struct gensec_spnego_update_state *state =
1717 tevent_req_data(req,
1718 struct gensec_spnego_update_state);
1721 *out = data_blob_null;
1723 if (tevent_req_is_nterror(req, &status)) {
1724 tevent_req_received(req);
1729 talloc_steal(out_mem_ctx, state->out.data);
1730 status = state->status;
1731 tevent_req_received(req);
1735 static const char *gensec_spnego_oids[] = {
1740 static const struct gensec_security_ops gensec_spnego_security_ops = {
1742 .sasl_name = "GSS-SPNEGO",
1743 .auth_type = DCERPC_AUTH_TYPE_SPNEGO,
1744 .oid = gensec_spnego_oids,
1745 .client_start = gensec_spnego_client_start,
1746 .server_start = gensec_spnego_server_start,
1747 .update_send = gensec_spnego_update_send,
1748 .update_recv = gensec_spnego_update_recv,
1749 .seal_packet = gensec_child_seal_packet,
1750 .sign_packet = gensec_child_sign_packet,
1751 .sig_size = gensec_child_sig_size,
1752 .max_wrapped_size = gensec_child_max_wrapped_size,
1753 .max_input_size = gensec_child_max_input_size,
1754 .check_packet = gensec_child_check_packet,
1755 .unseal_packet = gensec_child_unseal_packet,
1756 .wrap = gensec_child_wrap,
1757 .unwrap = gensec_child_unwrap,
1758 .session_key = gensec_child_session_key,
1759 .session_info = gensec_child_session_info,
1760 .want_feature = gensec_child_want_feature,
1761 .have_feature = gensec_child_have_feature,
1762 .expire_time = gensec_child_expire_time,
1763 .final_auth_type = gensec_child_final_auth_type,
1765 .priority = GENSEC_SPNEGO
1768 _PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx)
1771 ret = gensec_register(ctx, &gensec_spnego_security_ops);
1772 if (!NT_STATUS_IS_OK(ret)) {
1773 DEBUG(0,("Failed to register '%s' gensec backend!\n",
1774 gensec_spnego_security_ops.name));