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;
222 mechTypes = gensec_security_oids(gensec_security,
223 out_mem_ctx, GENSEC_OID_SPNEGO);
225 all_sec = gensec_security_by_oid_list(gensec_security,
229 for (i=0; all_sec && all_sec[i].op; i++) {
230 struct spnego_data spnego_out;
231 const char **send_mech_types;
234 nt_status = gensec_subcontext_start(spnego_state,
236 &spnego_state->sub_sec_security);
237 if (!NT_STATUS_IS_OK(nt_status)) {
240 /* select the sub context */
241 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
243 if (!NT_STATUS_IS_OK(nt_status)) {
244 gensec_spnego_update_sub_abort(spnego_state);
248 /* In the client, try and produce the first (optimistic) packet */
249 if (spnego_state->state_position == SPNEGO_CLIENT_START) {
250 nt_status = gensec_update_ev(spnego_state->sub_sec_security,
255 if (NT_STATUS_IS_OK(nt_status)) {
256 spnego_state->sub_sec_ready = true;
259 if (GENSEC_UPDATE_IS_NTERROR(nt_status)) {
260 const char *next = NULL;
261 const char *principal = NULL;
262 int dbg_level = DBGLVL_WARNING;
264 if (all_sec[i+1].op != NULL) {
265 next = all_sec[i+1].op->name;
266 dbg_level = DBGLVL_NOTICE;
269 if (gensec_security->target.principal != NULL) {
270 principal = gensec_security->target.principal;
271 } else if (gensec_security->target.service != NULL &&
272 gensec_security->target.hostname != NULL)
274 principal = talloc_asprintf(spnego_state->sub_sec_security,
276 gensec_security->target.service,
277 gensec_security->target.hostname);
279 principal = gensec_security->target.hostname;
282 DEBUG(dbg_level, ("SPNEGO(%s) creating NEG_TOKEN_INIT for %s failed (next[%s]): %s\n",
283 spnego_state->sub_sec_security->ops->name,
285 next, nt_errstr(nt_status)));
288 * Pretend we never started it
290 gensec_spnego_update_sub_abort(spnego_state);
295 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
297 send_mech_types = gensec_security_oids_from_ops_wrapped(out_mem_ctx,
300 ok = spnego_write_mech_types(spnego_state,
302 &spnego_state->mech_types);
304 DEBUG(1, ("SPNEGO: Failed to write mechTypes\n"));
305 return NT_STATUS_NO_MEMORY;
308 /* List the remaining mechs as options */
309 spnego_out.negTokenInit.mechTypes = send_mech_types;
310 spnego_out.negTokenInit.reqFlags = data_blob_null;
311 spnego_out.negTokenInit.reqFlagsPadding = 0;
313 if (spnego_state->state_position == SPNEGO_SERVER_START) {
314 spnego_out.negTokenInit.mechListMIC
315 = data_blob_string_const(ADS_IGNORE_PRINCIPAL);
317 spnego_out.negTokenInit.mechListMIC = data_blob_null;
320 spnego_out.negTokenInit.mechToken = unwrapped_out;
322 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
323 DEBUG(1, ("Failed to write NEG_TOKEN_INIT\n"));
324 return NT_STATUS_INVALID_PARAMETER;
328 spnego_state->neg_oid = all_sec[i].oid;
330 if (spnego_state->state_position == SPNEGO_SERVER_START) {
331 spnego_state->state_position = SPNEGO_SERVER_START;
332 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
334 spnego_state->state_position = SPNEGO_CLIENT_TARG;
335 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
338 return NT_STATUS_MORE_PROCESSING_REQUIRED;
340 gensec_spnego_update_sub_abort(spnego_state);
342 DEBUG(10, ("Failed to setup SPNEGO negTokenInit request: %s\n", nt_errstr(nt_status)));
346 static NTSTATUS gensec_spnego_client_negTokenInit(struct gensec_security *gensec_security,
347 struct spnego_state *spnego_state,
348 struct tevent_context *ev,
349 struct spnego_data *spnego_in,
350 TALLOC_CTX *out_mem_ctx,
353 TALLOC_CTX *frame = talloc_stackframe();
354 DATA_BLOB sub_out = data_blob_null;
355 const char *tp = NULL;
356 const char * const *mech_types = NULL;
358 const struct gensec_security_ops_wrapper *all_sec = NULL;
359 struct spnego_data spnego_out;
360 const char *my_mechs[] = {NULL, NULL};
364 *out = data_blob_null;
366 /* The server offers a list of mechanisms */
368 tp = spnego_in->negTokenInit.targetPrincipal;
369 if (tp != NULL && strcmp(tp, ADS_IGNORE_PRINCIPAL) != 0) {
370 DBG_INFO("Server claims it's principal name is %s\n", tp);
371 if (lpcfg_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
372 gensec_set_target_principal(gensec_security, tp);
376 mech_types = spnego_in->negTokenInit.mechTypes;
377 if (mech_types == NULL) {
379 return NT_STATUS_INVALID_PARAMETER;
382 all_sec = gensec_security_by_oid_list(gensec_security,
385 if (all_sec == NULL) {
386 DBG_WARNING("gensec_security_by_oid_list() failed\n");
388 return NT_STATUS_INVALID_PARAMETER;
391 for (; all_sec[all_idx].op; all_idx++) {
392 const struct gensec_security_ops_wrapper *cur_sec =
394 const char *next = NULL;
395 const char *principal = NULL;
396 int dbg_level = DBGLVL_WARNING;
397 bool allow_fallback = false;
399 status = gensec_subcontext_start(spnego_state,
401 &spnego_state->sub_sec_security);
402 if (!NT_STATUS_IS_OK(status)) {
407 /* select the sub context */
408 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
410 if (!NT_STATUS_IS_OK(status)) {
412 * Pretend we never started it.
414 gensec_spnego_update_sub_abort(spnego_state);
418 spnego_state->neg_oid = cur_sec->oid;
421 * As client we don't use an optimistic token from the server.
423 status = gensec_update_ev(spnego_state->sub_sec_security,
424 frame, ev, data_blob_null, &sub_out);
425 if (NT_STATUS_IS_OK(status)) {
426 spnego_state->sub_sec_ready = true;
429 if (!GENSEC_UPDATE_IS_NTERROR(status)) {
430 /* OK or MORE_PROCESSING_REQUIRED */
435 * it is likely that a NULL input token will
436 * not be liked by most server mechs, but if
437 * we are in the client, we want the first
438 * update packet to be able to abort the use
441 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
442 NT_STATUS_EQUAL(status, NT_STATUS_NO_LOGON_SERVERS) ||
443 NT_STATUS_EQUAL(status, NT_STATUS_TIME_DIFFERENCE_AT_DC) ||
444 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO))
446 allow_fallback = true;
449 if (allow_fallback && cur_sec[1].op != NULL) {
450 next = cur_sec[1].op->name;
451 dbg_level = DBGLVL_NOTICE;
454 if (gensec_security->target.principal != NULL) {
455 principal = gensec_security->target.principal;
456 } else if (gensec_security->target.service != NULL &&
457 gensec_security->target.hostname != NULL)
459 principal = talloc_asprintf(spnego_state->sub_sec_security,
461 gensec_security->target.service,
462 gensec_security->target.hostname);
464 principal = gensec_security->target.hostname;
467 DBG_PREFIX(dbg_level, (
468 "%s: creating NEG_TOKEN_INIT "
469 "for %s failed (next[%s]): %s\n",
470 spnego_state->sub_sec_security->ops->name,
471 principal, next, nt_errstr(status)));
475 * A hard error without a possible fallback.
482 * Pretend we never started it.
484 gensec_spnego_update_sub_abort(spnego_state);
487 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
489 return NT_STATUS_INVALID_PARAMETER;
492 my_mechs[0] = spnego_state->neg_oid;
494 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
495 spnego_out.negTokenInit.mechTypes = my_mechs;
496 spnego_out.negTokenInit.reqFlags = data_blob_null;
497 spnego_out.negTokenInit.reqFlagsPadding = 0;
498 spnego_out.negTokenInit.mechListMIC = data_blob_null;
499 spnego_out.negTokenInit.mechToken = sub_out;
501 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
502 DBG_ERR("Failed to write SPNEGO reply to NEG_TOKEN_INIT\n");
504 return NT_STATUS_INVALID_PARAMETER;
507 ok = spnego_write_mech_types(spnego_state,
509 &spnego_state->mech_types);
511 DBG_ERR("failed to write mechTypes\n");
513 return NT_STATUS_NO_MEMORY;
517 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
518 spnego_state->state_position = SPNEGO_CLIENT_TARG;
521 return NT_STATUS_MORE_PROCESSING_REQUIRED;
524 static NTSTATUS gensec_spnego_client_negTokenTarg(struct gensec_security *gensec_security,
525 struct spnego_state *spnego_state,
526 struct tevent_context *ev,
527 struct spnego_data *spnego_in,
528 TALLOC_CTX *out_mem_ctx,
531 struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
532 DATA_BLOB sub_in = ta->responseToken;
533 DATA_BLOB mech_list_mic = data_blob_null;
534 DATA_BLOB sub_out = data_blob_null;
535 struct spnego_data spnego_out;
538 *out = data_blob_null;
540 spnego_state->num_targs++;
542 if (ta->negResult == SPNEGO_REJECT) {
543 return NT_STATUS_LOGON_FAILURE;
546 if (ta->negResult == SPNEGO_REQUEST_MIC) {
547 spnego_state->mic_requested = true;
550 if (ta->mechListMIC.length > 0) {
551 DATA_BLOB *m = &ta->mechListMIC;
552 const DATA_BLOB *r = &ta->responseToken;
555 * Windows 2000 has a bug, it repeats the
556 * responseToken in the mechListMIC field.
558 if (m->length == r->length) {
561 cmp = memcmp(m->data, r->data, m->length);
568 /* Server didn't like our choice of mech, and chose something else */
569 if (((ta->negResult == SPNEGO_ACCEPT_INCOMPLETE) ||
570 (ta->negResult == SPNEGO_REQUEST_MIC)) &&
571 ta->supportedMech != NULL &&
572 strcmp(ta->supportedMech, spnego_state->neg_oid) != 0)
574 const char *client_mech = NULL;
575 const char *client_oid = NULL;
576 const char *server_mech = NULL;
577 const char *server_oid = NULL;
579 client_mech = gensec_get_name_by_oid(gensec_security,
580 spnego_state->neg_oid);
581 client_oid = spnego_state->neg_oid;
582 server_mech = gensec_get_name_by_oid(gensec_security,
584 server_oid = ta->supportedMech;
586 DBG_NOTICE("client preferred mech (%s[%s]) not accepted, "
587 "server wants: %s[%s]\n",
588 client_mech, client_oid, server_mech, server_oid);
590 spnego_state->downgraded = true;
591 gensec_spnego_update_sub_abort(spnego_state);
593 status = gensec_subcontext_start(spnego_state,
595 &spnego_state->sub_sec_security);
596 if (!NT_STATUS_IS_OK(status)) {
600 /* select the sub context */
601 status = gensec_start_mech_by_oid(spnego_state->sub_sec_security,
603 if (!NT_STATUS_IS_OK(status)) {
607 spnego_state->neg_oid = talloc_strdup(spnego_state,
609 if (spnego_state->neg_oid == NULL) {
610 return NT_STATUS_NO_MEMORY;
614 if (ta->mechListMIC.length > 0) {
615 if (spnego_state->sub_sec_ready) {
616 spnego_state->needs_mic_check = true;
620 if (spnego_state->needs_mic_check) {
621 if (ta->responseToken.length != 0) {
622 DBG_WARNING("non empty response token not expected\n");
623 return NT_STATUS_INVALID_PARAMETER;
626 if (ta->mechListMIC.length == 0
627 && spnego_state->may_skip_mic_check) {
629 * In this case we don't require
630 * a mechListMIC from the server.
632 * This works around bugs in the Azure
633 * and Apple spnego implementations.
636 * https://bugzilla.samba.org/show_bug.cgi?id=11994
638 spnego_state->needs_mic_check = false;
639 status = NT_STATUS_OK;
640 goto client_response;
643 status = gensec_check_packet(spnego_state->sub_sec_security,
644 spnego_state->mech_types.data,
645 spnego_state->mech_types.length,
646 spnego_state->mech_types.data,
647 spnego_state->mech_types.length,
649 if (!NT_STATUS_IS_OK(status)) {
650 DBG_WARNING("failed to verify mechListMIC: %s\n",
654 spnego_state->needs_mic_check = false;
655 spnego_state->done_mic_check = true;
656 goto client_response;
659 if (!spnego_state->sub_sec_ready) {
660 status = gensec_update_ev(spnego_state->sub_sec_security,
664 if (NT_STATUS_IS_OK(status)) {
665 spnego_state->sub_sec_ready = true;
667 if (!NT_STATUS_IS_OK(status)) {
668 goto client_response;
671 status = NT_STATUS_OK;
674 if (!spnego_state->done_mic_check) {
675 bool have_sign = true;
676 bool new_spnego = false;
678 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
679 GENSEC_FEATURE_SIGN);
680 if (spnego_state->simulate_w2k) {
683 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
684 GENSEC_FEATURE_NEW_SPNEGO);
686 switch (ta->negResult) {
687 case SPNEGO_ACCEPT_COMPLETED:
688 case SPNEGO_NONE_RESULT:
689 if (spnego_state->num_targs == 1) {
691 * the first exchange doesn't require
699 case SPNEGO_ACCEPT_INCOMPLETE:
700 if (ta->mechListMIC.length > 0) {
705 if (spnego_state->downgraded) {
707 * A downgrade should be protected if
714 * The caller may just asked for
715 * GENSEC_FEATURE_SESSION_KEY, this
716 * is only reflected in the want_features.
719 * gensec_have_features(GENSEC_FEATURE_SIGN)
722 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
725 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
729 * Here we're sure our preferred mech was
730 * selected by the server and our caller doesn't
731 * need GENSEC_FEATURE_SIGN nor
732 * GENSEC_FEATURE_SEAL support.
734 * In this case we don't require
735 * a mechListMIC from the server.
737 * This works around bugs in the Azure
738 * and Apple spnego implementations.
741 * https://bugzilla.samba.org/show_bug.cgi?id=11994
743 spnego_state->may_skip_mic_check = true;
746 case SPNEGO_REQUEST_MIC:
747 if (ta->mechListMIC.length > 0) {
755 if (spnego_state->mic_requested) {
761 if (have_sign && new_spnego) {
762 spnego_state->needs_mic_check = true;
763 spnego_state->needs_mic_sign = true;
767 if (ta->mechListMIC.length > 0) {
768 status = gensec_check_packet(spnego_state->sub_sec_security,
769 spnego_state->mech_types.data,
770 spnego_state->mech_types.length,
771 spnego_state->mech_types.data,
772 spnego_state->mech_types.length,
774 if (!NT_STATUS_IS_OK(status)) {
775 DBG_WARNING("failed to verify mechListMIC: %s\n",
779 spnego_state->needs_mic_check = false;
780 spnego_state->done_mic_check = true;
783 if (spnego_state->needs_mic_sign) {
784 status = gensec_sign_packet(spnego_state->sub_sec_security,
786 spnego_state->mech_types.data,
787 spnego_state->mech_types.length,
788 spnego_state->mech_types.data,
789 spnego_state->mech_types.length,
791 if (!NT_STATUS_IS_OK(status)) {
792 DBG_WARNING("failed to sign mechListMIC: %s\n",
796 spnego_state->needs_mic_sign = false;
799 if (spnego_state->needs_mic_check) {
800 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
804 if (GENSEC_UPDATE_IS_NTERROR(status)) {
805 DBG_WARNING("SPNEGO(%s) login failed: %s\n",
806 spnego_state->sub_sec_security->ops->name,
811 if (sub_out.length || mech_list_mic.length) {
813 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
814 spnego_out.negTokenTarg.negResult = SPNEGO_NONE_RESULT;
815 spnego_out.negTokenTarg.supportedMech = NULL;
816 spnego_out.negTokenTarg.responseToken = sub_out;
817 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
819 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
820 DBG_WARNING("Failed to write NEG_TOKEN_TARG\n");
821 return NT_STATUS_INVALID_PARAMETER;
824 spnego_state->num_targs++;
825 spnego_state->state_position = SPNEGO_CLIENT_TARG;
826 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
829 /* all done - server has accepted, and we agree */
830 *out = data_blob_null;
832 if (ta->negResult != SPNEGO_ACCEPT_COMPLETED) {
833 /* unless of course it did not accept */
834 DBG_WARNING("gensec_update ok but not accepted\n");
835 status = NT_STATUS_INVALID_PARAMETER;
838 spnego_state->state_position = SPNEGO_DONE;
844 /** create a server negTokenTarg
846 * This is the case, where the client is the first one who sends data
849 static NTSTATUS gensec_spnego_server_response(struct spnego_state *spnego_state,
850 TALLOC_CTX *out_mem_ctx,
852 const DATA_BLOB unwrapped_out,
853 DATA_BLOB mech_list_mic,
856 struct spnego_data spnego_out;
859 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
860 spnego_out.negTokenTarg.responseToken = unwrapped_out;
861 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
862 spnego_out.negTokenTarg.supportedMech = NULL;
864 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
865 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
866 if (spnego_state->mic_requested) {
867 spnego_out.negTokenTarg.negResult = SPNEGO_REQUEST_MIC;
868 spnego_state->mic_requested = false;
870 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
872 spnego_state->state_position = SPNEGO_SERVER_TARG;
873 } else if (NT_STATUS_IS_OK(nt_status)) {
874 if (unwrapped_out.data) {
875 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
877 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
878 spnego_state->state_position = SPNEGO_DONE;
880 spnego_out.negTokenTarg.negResult = SPNEGO_REJECT;
881 spnego_out.negTokenTarg.mechListMIC = data_blob_null;
882 DEBUG(2, ("SPNEGO login failed: %s\n", nt_errstr(nt_status)));
883 spnego_state->state_position = SPNEGO_DONE;
886 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
887 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
888 return NT_STATUS_INVALID_PARAMETER;
891 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
892 spnego_state->num_targs++;
897 static NTSTATUS gensec_spnego_server_negTokenInit(struct gensec_security *gensec_security,
898 struct spnego_state *spnego_state,
899 struct tevent_context *ev,
900 struct spnego_data *spnego_in,
901 TALLOC_CTX *out_mem_ctx,
904 TALLOC_CTX *frame = talloc_stackframe();
905 DATA_BLOB sub_out = data_blob_null;
906 DATA_BLOB mech_list_mic = data_blob_null;
907 const char * const *mech_types = NULL;
909 const struct gensec_security_ops_wrapper *all_sec = NULL;
914 mech_types = spnego_in->negTokenInit.mechTypes;
915 if (mech_types == NULL) {
917 return NT_STATUS_INVALID_PARAMETER;
920 all_sec = gensec_security_by_oid_list(gensec_security, frame,
921 mech_types, GENSEC_OID_SPNEGO);
922 if (all_sec == NULL) {
923 DBG_WARNING("gensec_security_by_oid_list() failed\n");
925 return NT_STATUS_INVALID_PARAMETER;
928 ok = spnego_write_mech_types(spnego_state, mech_types,
929 &spnego_state->mech_types);
931 DBG_ERR("Failed to write mechTypes\n");
933 return NT_STATUS_NO_MEMORY;
937 * First try the preferred mechs from the client.
939 for (; mech_types[mech_idx]; mech_idx++) {
940 const char *cur_mech = mech_types[mech_idx];
941 const struct gensec_security_ops_wrapper *cur_sec = NULL;
942 DATA_BLOB sub_in = data_blob_null;
944 for (all_idx = 0; all_sec[all_idx].op; all_idx++) {
945 if (strcmp(cur_mech, all_sec[all_idx].oid) == 0) {
946 cur_sec = &all_sec[all_idx];
951 if (cur_sec == NULL) {
955 status = gensec_subcontext_start(spnego_state,
957 &spnego_state->sub_sec_security);
958 if (!NT_STATUS_IS_OK(status)) {
963 /* select the sub context */
964 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
966 if (!NT_STATUS_IS_OK(status)) {
968 * Pretend we never started it
970 gensec_spnego_update_sub_abort(spnego_state);
976 * Indicate the downgrade and request a
979 spnego_state->downgraded = true;
980 spnego_state->mic_requested = true;
981 /* no optimistic token */
982 spnego_state->neg_oid = cur_sec->oid;
983 sub_out = data_blob_null;
984 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
989 * Try the optimistic token from the client
991 sub_in = spnego_in->negTokenInit.mechToken;
992 status = gensec_update_ev(spnego_state->sub_sec_security,
993 frame, ev, sub_in, &sub_out);
994 if (NT_STATUS_IS_OK(status)) {
995 spnego_state->sub_sec_ready = true;
997 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
998 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
1000 DBG_WARNING("%s: NEG_TOKEN_INIT failed to parse contents: %s\n",
1001 cur_sec->op->name, nt_errstr(status));
1004 * Pretend we never started it
1006 gensec_spnego_update_sub_abort(spnego_state);
1010 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1011 DBG_WARNING("%s: NEG_TOKEN_INIT failed: %s\n",
1012 cur_sec->op->name, nt_errstr(status));
1016 spnego_state->neg_oid = cur_sec->oid;
1017 goto reply; /* OK or MORE PROCESSING */
1020 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
1021 status = NT_STATUS_INVALID_PARAMETER;
1024 if (spnego_state->simulate_w2k) {
1026 * Windows 2000 returns the unwrapped token
1027 * also in the mech_list_mic field.
1029 * In order to verify our client code,
1030 * we need a way to have a server with this
1033 mech_list_mic = sub_out;
1036 status = gensec_spnego_server_response(spnego_state,
1046 static NTSTATUS gensec_spnego_server_negTokenTarg(struct gensec_security *gensec_security,
1047 struct spnego_state *spnego_state,
1048 struct tevent_context *ev,
1049 struct spnego_data *spnego_in,
1050 TALLOC_CTX *out_mem_ctx,
1053 const struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
1054 DATA_BLOB sub_in = ta->responseToken;
1055 DATA_BLOB mech_list_mic = data_blob_null;
1056 DATA_BLOB sub_out = data_blob_null;
1058 bool have_sign = true;
1059 bool new_spnego = false;
1061 spnego_state->num_targs++;
1063 if (spnego_state->sub_sec_security == NULL) {
1064 DBG_ERR("SPNEGO: Did not setup a mech in NEG_TOKEN_INIT\n");
1065 return NT_STATUS_INVALID_PARAMETER;
1068 if (spnego_state->needs_mic_check) {
1069 if (ta->responseToken.length != 0) {
1070 DBG_WARNING("non empty response token not expected\n");
1071 return NT_STATUS_INVALID_PARAMETER;
1074 status = gensec_check_packet(spnego_state->sub_sec_security,
1075 spnego_state->mech_types.data,
1076 spnego_state->mech_types.length,
1077 spnego_state->mech_types.data,
1078 spnego_state->mech_types.length,
1080 if (!NT_STATUS_IS_OK(status)) {
1081 DBG_WARNING("failed to verify mechListMIC: %s\n",
1083 goto server_response;
1086 spnego_state->needs_mic_check = false;
1087 spnego_state->done_mic_check = true;
1088 goto server_response;
1091 if (!spnego_state->sub_sec_ready) {
1092 status = gensec_update_ev(spnego_state->sub_sec_security,
1095 if (NT_STATUS_IS_OK(status)) {
1096 spnego_state->sub_sec_ready = true;
1098 if (!NT_STATUS_IS_OK(status)) {
1099 goto server_response;
1102 status = NT_STATUS_OK;
1105 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
1106 GENSEC_FEATURE_SIGN);
1107 if (spnego_state->simulate_w2k) {
1110 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
1111 GENSEC_FEATURE_NEW_SPNEGO);
1112 if (ta->mechListMIC.length > 0) {
1116 if (have_sign && new_spnego) {
1117 spnego_state->needs_mic_check = true;
1118 spnego_state->needs_mic_sign = true;
1121 if (have_sign && ta->mechListMIC.length > 0) {
1122 status = gensec_check_packet(spnego_state->sub_sec_security,
1123 spnego_state->mech_types.data,
1124 spnego_state->mech_types.length,
1125 spnego_state->mech_types.data,
1126 spnego_state->mech_types.length,
1128 if (!NT_STATUS_IS_OK(status)) {
1129 DBG_WARNING("failed to verify mechListMIC: %s\n",
1131 goto server_response;
1134 spnego_state->needs_mic_check = false;
1135 spnego_state->done_mic_check = true;
1138 if (spnego_state->needs_mic_sign) {
1139 status = gensec_sign_packet(spnego_state->sub_sec_security,
1141 spnego_state->mech_types.data,
1142 spnego_state->mech_types.length,
1143 spnego_state->mech_types.data,
1144 spnego_state->mech_types.length,
1146 if (!NT_STATUS_IS_OK(status)) {
1147 DBG_WARNING("failed to sign mechListMIC: %s\n",
1151 spnego_state->needs_mic_sign = false;
1154 if (spnego_state->needs_mic_check) {
1155 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
1159 return gensec_spnego_server_response(spnego_state,
1167 struct gensec_spnego_update_state {
1168 struct tevent_context *ev;
1169 struct gensec_security *gensec;
1170 struct spnego_state *spnego;
1173 struct spnego_data _spnego_in;
1174 struct spnego_data *spnego_in;
1187 static void gensec_spnego_update_cleanup(struct tevent_req *req,
1188 enum tevent_req_state req_state)
1190 struct gensec_spnego_update_state *state =
1191 tevent_req_data(req,
1192 struct gensec_spnego_update_state);
1194 switch (req_state) {
1195 case TEVENT_REQ_USER_ERROR:
1196 case TEVENT_REQ_TIMED_OUT:
1197 case TEVENT_REQ_NO_MEMORY:
1199 * A fatal error, further updates are not allowed.
1201 state->spnego->state_position = SPNEGO_DONE;
1208 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1209 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1210 DATA_BLOB *full_in);
1211 static void gensec_spnego_update_pre(struct tevent_req *req);
1212 static void gensec_spnego_update_done(struct tevent_req *subreq);
1213 static void gensec_spnego_update_post(struct tevent_req *req);
1214 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1215 TALLOC_CTX *out_mem_ctx,
1218 static struct tevent_req *gensec_spnego_update_send(TALLOC_CTX *mem_ctx,
1219 struct tevent_context *ev,
1220 struct gensec_security *gensec_security,
1223 struct spnego_state *spnego_state =
1224 talloc_get_type_abort(gensec_security->private_data,
1225 struct spnego_state);
1226 struct tevent_req *req = NULL;
1227 struct gensec_spnego_update_state *state = NULL;
1231 req = tevent_req_create(mem_ctx, &state,
1232 struct gensec_spnego_update_state);
1237 state->gensec = gensec_security;
1238 state->spnego = spnego_state;
1239 tevent_req_set_cleanup_fn(req, gensec_spnego_update_cleanup);
1241 if (spnego_state->out_frag.length > 0) {
1242 if (in.length > 0) {
1243 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1244 return tevent_req_post(req, ev);
1247 status = gensec_spnego_update_out(gensec_security,
1248 state, &state->out);
1249 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1250 tevent_req_nterror(req, status);
1251 return tevent_req_post(req, ev);
1254 state->status = status;
1255 tevent_req_done(req);
1256 return tevent_req_post(req, ev);
1259 status = gensec_spnego_update_in(gensec_security, in,
1260 state, &state->full_in);
1261 state->status = status;
1262 if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1263 tevent_req_done(req);
1264 return tevent_req_post(req, ev);
1266 if (tevent_req_nterror(req, status)) {
1267 return tevent_req_post(req, ev);
1270 /* Check if we got a valid SPNEGO blob... */
1272 switch (spnego_state->state_position) {
1273 case SPNEGO_FALLBACK:
1276 case SPNEGO_CLIENT_TARG:
1277 case SPNEGO_SERVER_TARG:
1278 if (state->full_in.length == 0) {
1279 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1280 return tevent_req_post(req, ev);
1284 case SPNEGO_CLIENT_START:
1285 case SPNEGO_SERVER_START:
1287 if (state->full_in.length == 0) {
1288 /* create_negTokenInit later */
1292 len = spnego_read_data(state,
1294 &state->_spnego_in);
1296 if (spnego_state->state_position != SPNEGO_SERVER_START) {
1297 DEBUG(1, ("Invalid SPNEGO request:\n"));
1298 dump_data(1, state->full_in.data,
1299 state->full_in.length);
1300 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1301 return tevent_req_post(req, ev);
1305 * This is the 'fallback' case, where we don't get
1306 * SPNEGO, and have to try all the other options (and
1307 * hope they all have a magic string they check)
1309 status = gensec_spnego_server_try_fallback(gensec_security,
1313 if (tevent_req_nterror(req, status)) {
1314 return tevent_req_post(req, ev);
1318 * We'll continue with SPNEGO_FALLBACK below...
1322 state->spnego_in = &state->_spnego_in;
1324 /* OK, so it's real SPNEGO, check the packet's the one we expect */
1325 if (state->spnego_in->type != spnego_state->expected_packet) {
1326 DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n",
1327 state->spnego_in->type,
1328 spnego_state->expected_packet));
1329 dump_data(1, state->full_in.data,
1330 state->full_in.length);
1331 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1332 return tevent_req_post(req, ev);
1338 smb_panic(__location__);
1342 gensec_spnego_update_pre(req);
1343 if (!tevent_req_is_in_progress(req)) {
1344 return tevent_req_post(req, ev);
1347 if (state->sub.needed) {
1348 struct tevent_req *subreq = NULL;
1351 * We may need one more roundtrip...
1353 subreq = gensec_update_send(state, state->ev,
1354 spnego_state->sub_sec_security,
1356 if (tevent_req_nomem(subreq, req)) {
1357 return tevent_req_post(req, ev);
1359 tevent_req_set_callback(subreq,
1360 gensec_spnego_update_done,
1362 state->sub.needed = false;
1366 gensec_spnego_update_post(req);
1367 if (!tevent_req_is_in_progress(req)) {
1368 return tevent_req_post(req, ev);
1374 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1375 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1378 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1382 *full_in = data_blob_null;
1384 switch (spnego_state->state_position) {
1385 case SPNEGO_FALLBACK:
1387 spnego_state->in_needed = 0;
1388 return NT_STATUS_OK;
1390 case SPNEGO_CLIENT_START:
1391 case SPNEGO_CLIENT_TARG:
1392 case SPNEGO_SERVER_START:
1393 case SPNEGO_SERVER_TARG:
1398 return NT_STATUS_INVALID_PARAMETER;
1401 if (spnego_state->in_needed == 0) {
1406 * try to work out the size of the full
1407 * input token, it might be fragmented
1409 ret = asn1_peek_full_tag(in, ASN1_APPLICATION(0), &size);
1410 if ((ret != 0) && (ret != EAGAIN)) {
1411 ret = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
1414 if ((ret == 0) || (ret == EAGAIN)) {
1415 spnego_state->in_needed = size;
1418 * If it is not an asn1 message
1419 * just call the next layer.
1421 spnego_state->in_needed = in.length;
1425 if (spnego_state->in_needed > UINT16_MAX) {
1427 * limit the incoming message to 0xFFFF
1428 * to avoid DoS attacks.
1430 return NT_STATUS_INVALID_BUFFER_SIZE;
1433 if ((spnego_state->in_needed > 0) && (in.length == 0)) {
1435 * If we reach this, we know we got at least
1436 * part of an asn1 message, getting 0 means
1437 * the remote peer wants us to spin.
1439 return NT_STATUS_INVALID_PARAMETER;
1442 expected = spnego_state->in_needed - spnego_state->in_frag.length;
1443 if (in.length > expected) {
1445 * we got more than expected
1447 return NT_STATUS_INVALID_PARAMETER;
1450 if (in.length == spnego_state->in_needed) {
1452 * if the in.length contains the full blob
1455 * Note: this implies spnego_state->in_frag.length == 0,
1456 * but we do not need to check this explicitly
1457 * because we already know that we did not get
1458 * more than expected.
1461 spnego_state->in_needed = 0;
1462 return NT_STATUS_OK;
1465 ok = data_blob_append(spnego_state, &spnego_state->in_frag,
1466 in.data, in.length);
1468 return NT_STATUS_NO_MEMORY;
1471 if (spnego_state->in_needed > spnego_state->in_frag.length) {
1472 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1475 *full_in = spnego_state->in_frag;
1476 talloc_steal(mem_ctx, full_in->data);
1477 spnego_state->in_frag = data_blob_null;
1478 spnego_state->in_needed = 0;
1479 return NT_STATUS_OK;
1482 static void gensec_spnego_update_pre(struct tevent_req *req)
1484 struct gensec_spnego_update_state *state =
1485 tevent_req_data(req,
1486 struct gensec_spnego_update_state);
1487 struct gensec_security *gensec_security = state->gensec;
1488 struct spnego_state *spnego_state = state->spnego;
1489 struct tevent_context *ev = state->ev;
1492 state->sub.needed = false;
1493 state->sub.in = data_blob_null;
1494 state->sub.status = NT_STATUS_INTERNAL_ERROR;
1495 state->sub.out = data_blob_null;
1497 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1498 state->sub.in = state->full_in;
1499 state->full_in = data_blob_null;
1500 state->sub.needed = true;
1504 switch (spnego_state->state_position) {
1505 case SPNEGO_CLIENT_START:
1506 if (state->spnego_in == NULL) {
1507 /* client to produce negTokenInit */
1508 status = gensec_spnego_create_negTokenInit(gensec_security,
1509 spnego_state, state, ev,
1510 &spnego_state->out_frag);
1511 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1512 tevent_req_nterror(req, status);
1518 status = gensec_spnego_client_negTokenInit(gensec_security,
1520 state->spnego_in, state,
1521 &spnego_state->out_frag);
1524 case SPNEGO_CLIENT_TARG:
1525 status = gensec_spnego_client_negTokenTarg(gensec_security,
1527 state->spnego_in, state,
1528 &spnego_state->out_frag);
1529 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1530 tevent_req_nterror(req, status);
1535 case SPNEGO_SERVER_START:
1536 if (state->spnego_in == NULL) {
1537 /* server to produce negTokenInit */
1538 status = gensec_spnego_create_negTokenInit(gensec_security,
1539 spnego_state, state, ev,
1540 &spnego_state->out_frag);
1541 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1542 tevent_req_nterror(req, status);
1548 status = gensec_spnego_server_negTokenInit(gensec_security,
1550 state->spnego_in, state,
1551 &spnego_state->out_frag);
1552 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1553 tevent_req_nterror(req, status);
1558 case SPNEGO_SERVER_TARG:
1559 status = gensec_spnego_server_negTokenTarg(gensec_security,
1561 state->spnego_in, state,
1562 &spnego_state->out_frag);
1563 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1564 tevent_req_nterror(req, status);
1570 smb_panic(__location__);
1574 spnego_state->out_status = status;
1577 static void gensec_spnego_update_done(struct tevent_req *subreq)
1579 struct tevent_req *req =
1580 tevent_req_callback_data(subreq,
1582 struct gensec_spnego_update_state *state =
1583 tevent_req_data(req,
1584 struct gensec_spnego_update_state);
1585 struct spnego_state *spnego_state = state->spnego;
1587 state->sub.status = gensec_update_recv(subreq, state, &state->sub.out);
1588 TALLOC_FREE(subreq);
1589 if (NT_STATUS_IS_OK(state->sub.status)) {
1590 spnego_state->sub_sec_ready = true;
1593 gensec_spnego_update_post(req);
1596 static void gensec_spnego_update_post(struct tevent_req *req)
1598 struct gensec_spnego_update_state *state =
1599 tevent_req_data(req,
1600 struct gensec_spnego_update_state);
1601 struct spnego_state *spnego_state = state->spnego;
1604 state->sub.in = data_blob_null;
1605 state->sub.needed = false;
1607 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1608 status = state->sub.status;
1609 spnego_state->out_frag = state->sub.out;
1610 talloc_steal(spnego_state, spnego_state->out_frag.data);
1611 state->sub.out = data_blob_null;
1616 * For now just handle the sync processing done
1617 * in gensec_spnego_update_pre()
1619 status = spnego_state->out_status;
1621 if (NT_STATUS_IS_OK(status)) {
1622 bool reset_full = true;
1624 reset_full = !spnego_state->done_mic_check;
1626 status = gensec_may_reset_crypto(spnego_state->sub_sec_security,
1628 if (tevent_req_nterror(req, status)) {
1634 spnego_state->out_status = status;
1636 status = gensec_spnego_update_out(state->gensec,
1637 state, &state->out);
1638 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1639 tevent_req_nterror(req, status);
1643 state->status = status;
1644 tevent_req_done(req);
1648 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1649 TALLOC_CTX *out_mem_ctx,
1652 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1653 DATA_BLOB out = data_blob_null;
1656 *_out = data_blob_null;
1658 if (spnego_state->out_frag.length <= spnego_state->out_max_length) {
1660 * Fast path, we can deliver everything
1663 *_out = spnego_state->out_frag;
1664 if (spnego_state->out_frag.length > 0) {
1665 talloc_steal(out_mem_ctx, _out->data);
1666 spnego_state->out_frag = data_blob_null;
1669 if (!NT_STATUS_IS_OK(spnego_state->out_status)) {
1670 return spnego_state->out_status;
1674 * We're completely done, further updates are not allowed.
1676 spnego_state->state_position = SPNEGO_DONE;
1677 return gensec_child_ready(gensec_security,
1678 spnego_state->sub_sec_security);
1681 out = spnego_state->out_frag;
1684 * copy the remaining bytes
1686 spnego_state->out_frag = data_blob_talloc(spnego_state,
1687 out.data + spnego_state->out_max_length,
1688 out.length - spnego_state->out_max_length);
1689 if (spnego_state->out_frag.data == NULL) {
1690 return NT_STATUS_NO_MEMORY;
1694 * truncate the buffer
1696 ok = data_blob_realloc(spnego_state, &out,
1697 spnego_state->out_max_length);
1699 return NT_STATUS_NO_MEMORY;
1702 talloc_steal(out_mem_ctx, out.data);
1704 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1707 static NTSTATUS gensec_spnego_update_recv(struct tevent_req *req,
1708 TALLOC_CTX *out_mem_ctx,
1711 struct gensec_spnego_update_state *state =
1712 tevent_req_data(req,
1713 struct gensec_spnego_update_state);
1716 *out = data_blob_null;
1718 if (tevent_req_is_nterror(req, &status)) {
1719 tevent_req_received(req);
1724 talloc_steal(out_mem_ctx, state->out.data);
1725 status = state->status;
1726 tevent_req_received(req);
1730 static const char *gensec_spnego_oids[] = {
1735 static const struct gensec_security_ops gensec_spnego_security_ops = {
1737 .sasl_name = "GSS-SPNEGO",
1738 .auth_type = DCERPC_AUTH_TYPE_SPNEGO,
1739 .oid = gensec_spnego_oids,
1740 .client_start = gensec_spnego_client_start,
1741 .server_start = gensec_spnego_server_start,
1742 .update_send = gensec_spnego_update_send,
1743 .update_recv = gensec_spnego_update_recv,
1744 .seal_packet = gensec_child_seal_packet,
1745 .sign_packet = gensec_child_sign_packet,
1746 .sig_size = gensec_child_sig_size,
1747 .max_wrapped_size = gensec_child_max_wrapped_size,
1748 .max_input_size = gensec_child_max_input_size,
1749 .check_packet = gensec_child_check_packet,
1750 .unseal_packet = gensec_child_unseal_packet,
1751 .wrap = gensec_child_wrap,
1752 .unwrap = gensec_child_unwrap,
1753 .session_key = gensec_child_session_key,
1754 .session_info = gensec_child_session_info,
1755 .want_feature = gensec_child_want_feature,
1756 .have_feature = gensec_child_have_feature,
1757 .expire_time = gensec_child_expire_time,
1758 .final_auth_type = gensec_child_final_auth_type,
1760 .priority = GENSEC_SPNEGO
1763 _PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx)
1766 ret = gensec_register(ctx, &gensec_spnego_security_ops);
1767 if (!NT_STATUS_IS_OK(ret)) {
1768 DEBUG(0,("Failed to register '%s' gensec backend!\n",
1769 gensec_spnego_security_ops.name));