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 DBG_PREFIX(dbg_level, (
291 "%s: creating NEG_TOKEN_INIT for %s failed "
293 spnego_state->sub_sec_security->ops->name,
294 principal, next, nt_errstr(nt_status)));
297 * Pretend we never started it
299 gensec_spnego_update_sub_abort(spnego_state);
302 DBG_WARNING("Failed to setup SPNEGO negTokenInit request: %s\n",
303 nt_errstr(nt_status));
307 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
309 send_mech_types = gensec_security_oids_from_ops_wrapped(out_mem_ctx,
312 ok = spnego_write_mech_types(spnego_state,
314 &spnego_state->mech_types);
316 DBG_ERR("Failed to write mechTypes\n");
317 return NT_STATUS_NO_MEMORY;
320 /* List the remaining mechs as options */
321 spnego_out.negTokenInit.mechTypes = send_mech_types;
322 spnego_out.negTokenInit.reqFlags = data_blob_null;
323 spnego_out.negTokenInit.reqFlagsPadding = 0;
325 if (spnego_state->state_position == SPNEGO_SERVER_START) {
326 spnego_out.negTokenInit.mechListMIC
327 = data_blob_string_const(ADS_IGNORE_PRINCIPAL);
329 spnego_out.negTokenInit.mechListMIC = data_blob_null;
332 spnego_out.negTokenInit.mechToken = unwrapped_out;
334 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
335 DBG_ERR("Failed to write NEG_TOKEN_INIT\n");
336 return NT_STATUS_INVALID_PARAMETER;
340 spnego_state->neg_oid = all_sec[i].oid;
342 if (spnego_state->state_position == SPNEGO_SERVER_START) {
343 spnego_state->state_position = SPNEGO_SERVER_START;
344 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
346 spnego_state->state_position = SPNEGO_CLIENT_TARG;
347 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
350 return NT_STATUS_MORE_PROCESSING_REQUIRED;
353 static NTSTATUS gensec_spnego_client_negTokenInit(struct gensec_security *gensec_security,
354 struct spnego_state *spnego_state,
355 struct tevent_context *ev,
356 struct spnego_data *spnego_in,
357 TALLOC_CTX *out_mem_ctx,
360 TALLOC_CTX *frame = talloc_stackframe();
361 DATA_BLOB sub_out = data_blob_null;
362 const char *tp = NULL;
363 const char * const *mech_types = NULL;
365 const struct gensec_security_ops_wrapper *all_sec = NULL;
366 struct spnego_data spnego_out;
367 const char *my_mechs[] = {NULL, NULL};
371 *out = data_blob_null;
373 /* The server offers a list of mechanisms */
375 tp = spnego_in->negTokenInit.targetPrincipal;
376 if (tp != NULL && strcmp(tp, ADS_IGNORE_PRINCIPAL) != 0) {
377 DBG_INFO("Server claims it's principal name is %s\n", tp);
378 if (lpcfg_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
379 gensec_set_target_principal(gensec_security, tp);
383 mech_types = spnego_in->negTokenInit.mechTypes;
384 if (mech_types == NULL) {
386 return NT_STATUS_INVALID_PARAMETER;
389 all_sec = gensec_security_by_oid_list(gensec_security,
392 if (all_sec == NULL) {
393 DBG_WARNING("gensec_security_by_oid_list() failed\n");
395 return NT_STATUS_INVALID_PARAMETER;
398 for (; all_sec[all_idx].op; all_idx++) {
399 const struct gensec_security_ops_wrapper *cur_sec =
401 const char *next = NULL;
402 const char *principal = NULL;
403 int dbg_level = DBGLVL_WARNING;
404 bool allow_fallback = false;
406 status = gensec_subcontext_start(spnego_state,
408 &spnego_state->sub_sec_security);
409 if (!NT_STATUS_IS_OK(status)) {
414 /* select the sub context */
415 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
417 if (!NT_STATUS_IS_OK(status)) {
419 * Pretend we never started it.
421 gensec_spnego_update_sub_abort(spnego_state);
425 spnego_state->neg_oid = cur_sec->oid;
428 * As client we don't use an optimistic token from the server.
430 status = gensec_update_ev(spnego_state->sub_sec_security,
431 frame, ev, data_blob_null, &sub_out);
432 if (NT_STATUS_IS_OK(status)) {
433 spnego_state->sub_sec_ready = true;
436 if (!GENSEC_UPDATE_IS_NTERROR(status)) {
437 /* OK or MORE_PROCESSING_REQUIRED */
442 * it is likely that a NULL input token will
443 * not be liked by most server mechs, but if
444 * we are in the client, we want the first
445 * update packet to be able to abort the use
448 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
449 NT_STATUS_EQUAL(status, NT_STATUS_NO_LOGON_SERVERS) ||
450 NT_STATUS_EQUAL(status, NT_STATUS_TIME_DIFFERENCE_AT_DC) ||
451 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO))
453 allow_fallback = true;
456 if (allow_fallback && cur_sec[1].op != NULL) {
457 next = cur_sec[1].op->name;
458 dbg_level = DBGLVL_NOTICE;
461 if (gensec_security->target.principal != NULL) {
462 principal = gensec_security->target.principal;
463 } else if (gensec_security->target.service != NULL &&
464 gensec_security->target.hostname != NULL)
466 principal = talloc_asprintf(spnego_state->sub_sec_security,
468 gensec_security->target.service,
469 gensec_security->target.hostname);
471 principal = gensec_security->target.hostname;
474 DBG_PREFIX(dbg_level, (
475 "%s: creating NEG_TOKEN_INIT "
476 "for %s failed (next[%s]): %s\n",
477 spnego_state->sub_sec_security->ops->name,
478 principal, next, nt_errstr(status)));
482 * A hard error without a possible fallback.
489 * Pretend we never started it.
491 gensec_spnego_update_sub_abort(spnego_state);
494 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
496 return NT_STATUS_INVALID_PARAMETER;
499 my_mechs[0] = spnego_state->neg_oid;
501 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
502 spnego_out.negTokenInit.mechTypes = my_mechs;
503 spnego_out.negTokenInit.reqFlags = data_blob_null;
504 spnego_out.negTokenInit.reqFlagsPadding = 0;
505 spnego_out.negTokenInit.mechListMIC = data_blob_null;
506 spnego_out.negTokenInit.mechToken = sub_out;
508 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
509 DBG_ERR("Failed to write SPNEGO reply to NEG_TOKEN_INIT\n");
511 return NT_STATUS_INVALID_PARAMETER;
514 ok = spnego_write_mech_types(spnego_state,
516 &spnego_state->mech_types);
518 DBG_ERR("failed to write mechTypes\n");
520 return NT_STATUS_NO_MEMORY;
524 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
525 spnego_state->state_position = SPNEGO_CLIENT_TARG;
528 return NT_STATUS_MORE_PROCESSING_REQUIRED;
531 static NTSTATUS gensec_spnego_client_negTokenTarg(struct gensec_security *gensec_security,
532 struct spnego_state *spnego_state,
533 struct tevent_context *ev,
534 struct spnego_data *spnego_in,
535 TALLOC_CTX *out_mem_ctx,
538 struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
539 DATA_BLOB sub_in = ta->responseToken;
540 DATA_BLOB mech_list_mic = data_blob_null;
541 DATA_BLOB sub_out = data_blob_null;
542 struct spnego_data spnego_out;
545 *out = data_blob_null;
547 spnego_state->num_targs++;
549 if (ta->negResult == SPNEGO_REJECT) {
550 return NT_STATUS_LOGON_FAILURE;
553 if (ta->negResult == SPNEGO_REQUEST_MIC) {
554 spnego_state->mic_requested = true;
557 if (ta->mechListMIC.length > 0) {
558 DATA_BLOB *m = &ta->mechListMIC;
559 const DATA_BLOB *r = &ta->responseToken;
562 * Windows 2000 has a bug, it repeats the
563 * responseToken in the mechListMIC field.
565 if (m->length == r->length) {
568 cmp = memcmp(m->data, r->data, m->length);
575 /* Server didn't like our choice of mech, and chose something else */
576 if (((ta->negResult == SPNEGO_ACCEPT_INCOMPLETE) ||
577 (ta->negResult == SPNEGO_REQUEST_MIC)) &&
578 ta->supportedMech != NULL &&
579 strcmp(ta->supportedMech, spnego_state->neg_oid) != 0)
581 const char *client_mech = NULL;
582 const char *client_oid = NULL;
583 const char *server_mech = NULL;
584 const char *server_oid = NULL;
586 client_mech = gensec_get_name_by_oid(gensec_security,
587 spnego_state->neg_oid);
588 client_oid = spnego_state->neg_oid;
589 server_mech = gensec_get_name_by_oid(gensec_security,
591 server_oid = ta->supportedMech;
593 DBG_NOTICE("client preferred mech (%s[%s]) not accepted, "
594 "server wants: %s[%s]\n",
595 client_mech, client_oid, server_mech, server_oid);
597 spnego_state->downgraded = true;
598 gensec_spnego_update_sub_abort(spnego_state);
600 status = gensec_subcontext_start(spnego_state,
602 &spnego_state->sub_sec_security);
603 if (!NT_STATUS_IS_OK(status)) {
607 /* select the sub context */
608 status = gensec_start_mech_by_oid(spnego_state->sub_sec_security,
610 if (!NT_STATUS_IS_OK(status)) {
614 spnego_state->neg_oid = talloc_strdup(spnego_state,
616 if (spnego_state->neg_oid == NULL) {
617 return NT_STATUS_NO_MEMORY;
621 if (ta->mechListMIC.length > 0) {
622 if (spnego_state->sub_sec_ready) {
623 spnego_state->needs_mic_check = true;
627 if (spnego_state->needs_mic_check) {
628 if (ta->responseToken.length != 0) {
629 DBG_WARNING("non empty response token not expected\n");
630 return NT_STATUS_INVALID_PARAMETER;
633 if (ta->mechListMIC.length == 0
634 && spnego_state->may_skip_mic_check) {
636 * In this case we don't require
637 * a mechListMIC from the server.
639 * This works around bugs in the Azure
640 * and Apple spnego implementations.
643 * https://bugzilla.samba.org/show_bug.cgi?id=11994
645 spnego_state->needs_mic_check = false;
646 status = NT_STATUS_OK;
647 goto client_response;
650 status = gensec_check_packet(spnego_state->sub_sec_security,
651 spnego_state->mech_types.data,
652 spnego_state->mech_types.length,
653 spnego_state->mech_types.data,
654 spnego_state->mech_types.length,
656 if (!NT_STATUS_IS_OK(status)) {
657 DBG_WARNING("failed to verify mechListMIC: %s\n",
661 spnego_state->needs_mic_check = false;
662 spnego_state->done_mic_check = true;
663 goto client_response;
666 if (!spnego_state->sub_sec_ready) {
667 status = gensec_update_ev(spnego_state->sub_sec_security,
671 if (NT_STATUS_IS_OK(status)) {
672 spnego_state->sub_sec_ready = true;
674 if (!NT_STATUS_IS_OK(status)) {
675 goto client_response;
678 status = NT_STATUS_OK;
681 if (!spnego_state->done_mic_check) {
682 bool have_sign = true;
683 bool new_spnego = false;
685 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
686 GENSEC_FEATURE_SIGN);
687 if (spnego_state->simulate_w2k) {
690 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
691 GENSEC_FEATURE_NEW_SPNEGO);
693 switch (ta->negResult) {
694 case SPNEGO_ACCEPT_COMPLETED:
695 case SPNEGO_NONE_RESULT:
696 if (spnego_state->num_targs == 1) {
698 * the first exchange doesn't require
706 case SPNEGO_ACCEPT_INCOMPLETE:
707 if (ta->mechListMIC.length > 0) {
712 if (spnego_state->downgraded) {
714 * A downgrade should be protected if
721 * The caller may just asked for
722 * GENSEC_FEATURE_SESSION_KEY, this
723 * is only reflected in the want_features.
726 * gensec_have_features(GENSEC_FEATURE_SIGN)
729 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
732 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
736 * Here we're sure our preferred mech was
737 * selected by the server and our caller doesn't
738 * need GENSEC_FEATURE_SIGN nor
739 * GENSEC_FEATURE_SEAL support.
741 * In this case we don't require
742 * a mechListMIC from the server.
744 * This works around bugs in the Azure
745 * and Apple spnego implementations.
748 * https://bugzilla.samba.org/show_bug.cgi?id=11994
750 spnego_state->may_skip_mic_check = true;
753 case SPNEGO_REQUEST_MIC:
754 if (ta->mechListMIC.length > 0) {
762 if (spnego_state->mic_requested) {
768 if (have_sign && new_spnego) {
769 spnego_state->needs_mic_check = true;
770 spnego_state->needs_mic_sign = true;
774 if (ta->mechListMIC.length > 0) {
775 status = gensec_check_packet(spnego_state->sub_sec_security,
776 spnego_state->mech_types.data,
777 spnego_state->mech_types.length,
778 spnego_state->mech_types.data,
779 spnego_state->mech_types.length,
781 if (!NT_STATUS_IS_OK(status)) {
782 DBG_WARNING("failed to verify mechListMIC: %s\n",
786 spnego_state->needs_mic_check = false;
787 spnego_state->done_mic_check = true;
790 if (spnego_state->needs_mic_sign) {
791 status = gensec_sign_packet(spnego_state->sub_sec_security,
793 spnego_state->mech_types.data,
794 spnego_state->mech_types.length,
795 spnego_state->mech_types.data,
796 spnego_state->mech_types.length,
798 if (!NT_STATUS_IS_OK(status)) {
799 DBG_WARNING("failed to sign mechListMIC: %s\n",
803 spnego_state->needs_mic_sign = false;
806 if (spnego_state->needs_mic_check) {
807 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
811 if (GENSEC_UPDATE_IS_NTERROR(status)) {
812 DBG_WARNING("SPNEGO(%s) login failed: %s\n",
813 spnego_state->sub_sec_security->ops->name,
818 if (sub_out.length || mech_list_mic.length) {
820 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
821 spnego_out.negTokenTarg.negResult = SPNEGO_NONE_RESULT;
822 spnego_out.negTokenTarg.supportedMech = NULL;
823 spnego_out.negTokenTarg.responseToken = sub_out;
824 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
826 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
827 DBG_WARNING("Failed to write NEG_TOKEN_TARG\n");
828 return NT_STATUS_INVALID_PARAMETER;
831 spnego_state->num_targs++;
832 spnego_state->state_position = SPNEGO_CLIENT_TARG;
833 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
836 /* all done - server has accepted, and we agree */
837 *out = data_blob_null;
839 if (ta->negResult != SPNEGO_ACCEPT_COMPLETED) {
840 /* unless of course it did not accept */
841 DBG_WARNING("gensec_update ok but not accepted\n");
842 status = NT_STATUS_INVALID_PARAMETER;
845 spnego_state->state_position = SPNEGO_DONE;
851 /** create a server negTokenTarg
853 * This is the case, where the client is the first one who sends data
856 static NTSTATUS gensec_spnego_server_response(struct spnego_state *spnego_state,
857 TALLOC_CTX *out_mem_ctx,
859 const DATA_BLOB unwrapped_out,
860 DATA_BLOB mech_list_mic,
863 struct spnego_data spnego_out;
866 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
867 spnego_out.negTokenTarg.responseToken = unwrapped_out;
868 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
869 spnego_out.negTokenTarg.supportedMech = NULL;
871 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
872 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
873 if (spnego_state->mic_requested) {
874 spnego_out.negTokenTarg.negResult = SPNEGO_REQUEST_MIC;
875 spnego_state->mic_requested = false;
877 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
879 spnego_state->state_position = SPNEGO_SERVER_TARG;
880 } else if (NT_STATUS_IS_OK(nt_status)) {
881 if (unwrapped_out.data) {
882 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
884 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
885 spnego_state->state_position = SPNEGO_DONE;
887 spnego_out.negTokenTarg.negResult = SPNEGO_REJECT;
888 spnego_out.negTokenTarg.mechListMIC = data_blob_null;
889 DEBUG(2, ("SPNEGO login failed: %s\n", nt_errstr(nt_status)));
890 spnego_state->state_position = SPNEGO_DONE;
893 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
894 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
895 return NT_STATUS_INVALID_PARAMETER;
898 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
899 spnego_state->num_targs++;
904 static NTSTATUS gensec_spnego_server_negTokenInit(struct gensec_security *gensec_security,
905 struct spnego_state *spnego_state,
906 struct tevent_context *ev,
907 struct spnego_data *spnego_in,
908 TALLOC_CTX *out_mem_ctx,
911 TALLOC_CTX *frame = talloc_stackframe();
912 DATA_BLOB sub_out = data_blob_null;
913 DATA_BLOB mech_list_mic = data_blob_null;
914 const char * const *mech_types = NULL;
916 const struct gensec_security_ops_wrapper *all_sec = NULL;
921 mech_types = spnego_in->negTokenInit.mechTypes;
922 if (mech_types == NULL) {
924 return NT_STATUS_INVALID_PARAMETER;
927 all_sec = gensec_security_by_oid_list(gensec_security, frame,
928 mech_types, GENSEC_OID_SPNEGO);
929 if (all_sec == NULL) {
930 DBG_WARNING("gensec_security_by_oid_list() failed\n");
932 return NT_STATUS_INVALID_PARAMETER;
935 ok = spnego_write_mech_types(spnego_state, mech_types,
936 &spnego_state->mech_types);
938 DBG_ERR("Failed to write mechTypes\n");
940 return NT_STATUS_NO_MEMORY;
944 * First try the preferred mechs from the client.
946 for (; mech_types[mech_idx]; mech_idx++) {
947 const char *cur_mech = mech_types[mech_idx];
948 const struct gensec_security_ops_wrapper *cur_sec = NULL;
949 DATA_BLOB sub_in = data_blob_null;
951 for (all_idx = 0; all_sec[all_idx].op; all_idx++) {
952 if (strcmp(cur_mech, all_sec[all_idx].oid) == 0) {
953 cur_sec = &all_sec[all_idx];
958 if (cur_sec == NULL) {
962 status = gensec_subcontext_start(spnego_state,
964 &spnego_state->sub_sec_security);
965 if (!NT_STATUS_IS_OK(status)) {
970 /* select the sub context */
971 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
973 if (!NT_STATUS_IS_OK(status)) {
975 * Pretend we never started it
977 gensec_spnego_update_sub_abort(spnego_state);
983 * Indicate the downgrade and request a
986 spnego_state->downgraded = true;
987 spnego_state->mic_requested = true;
988 /* no optimistic token */
989 spnego_state->neg_oid = cur_sec->oid;
990 sub_out = data_blob_null;
991 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
996 * Try the optimistic token from the client
998 sub_in = spnego_in->negTokenInit.mechToken;
999 status = gensec_update_ev(spnego_state->sub_sec_security,
1000 frame, ev, sub_in, &sub_out);
1001 if (NT_STATUS_IS_OK(status)) {
1002 spnego_state->sub_sec_ready = true;
1004 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
1005 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
1007 DBG_WARNING("%s: NEG_TOKEN_INIT failed to parse contents: %s\n",
1008 cur_sec->op->name, nt_errstr(status));
1011 * Pretend we never started it
1013 gensec_spnego_update_sub_abort(spnego_state);
1017 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1018 DBG_WARNING("%s: NEG_TOKEN_INIT failed: %s\n",
1019 cur_sec->op->name, nt_errstr(status));
1023 spnego_state->neg_oid = cur_sec->oid;
1024 goto reply; /* OK or MORE PROCESSING */
1027 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
1028 status = NT_STATUS_INVALID_PARAMETER;
1031 if (spnego_state->simulate_w2k) {
1033 * Windows 2000 returns the unwrapped token
1034 * also in the mech_list_mic field.
1036 * In order to verify our client code,
1037 * we need a way to have a server with this
1040 mech_list_mic = sub_out;
1043 status = gensec_spnego_server_response(spnego_state,
1053 static NTSTATUS gensec_spnego_server_negTokenTarg(struct gensec_security *gensec_security,
1054 struct spnego_state *spnego_state,
1055 struct tevent_context *ev,
1056 struct spnego_data *spnego_in,
1057 TALLOC_CTX *out_mem_ctx,
1060 const struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
1061 DATA_BLOB sub_in = ta->responseToken;
1062 DATA_BLOB mech_list_mic = data_blob_null;
1063 DATA_BLOB sub_out = data_blob_null;
1065 bool have_sign = true;
1066 bool new_spnego = false;
1068 spnego_state->num_targs++;
1070 if (spnego_state->sub_sec_security == NULL) {
1071 DBG_ERR("SPNEGO: Did not setup a mech in NEG_TOKEN_INIT\n");
1072 return NT_STATUS_INVALID_PARAMETER;
1075 if (spnego_state->needs_mic_check) {
1076 if (ta->responseToken.length != 0) {
1077 DBG_WARNING("non empty response token not expected\n");
1078 return NT_STATUS_INVALID_PARAMETER;
1081 status = gensec_check_packet(spnego_state->sub_sec_security,
1082 spnego_state->mech_types.data,
1083 spnego_state->mech_types.length,
1084 spnego_state->mech_types.data,
1085 spnego_state->mech_types.length,
1087 if (!NT_STATUS_IS_OK(status)) {
1088 DBG_WARNING("failed to verify mechListMIC: %s\n",
1090 goto server_response;
1093 spnego_state->needs_mic_check = false;
1094 spnego_state->done_mic_check = true;
1095 goto server_response;
1098 if (!spnego_state->sub_sec_ready) {
1099 status = gensec_update_ev(spnego_state->sub_sec_security,
1102 if (NT_STATUS_IS_OK(status)) {
1103 spnego_state->sub_sec_ready = true;
1105 if (!NT_STATUS_IS_OK(status)) {
1106 goto server_response;
1109 status = NT_STATUS_OK;
1112 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
1113 GENSEC_FEATURE_SIGN);
1114 if (spnego_state->simulate_w2k) {
1117 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
1118 GENSEC_FEATURE_NEW_SPNEGO);
1119 if (ta->mechListMIC.length > 0) {
1123 if (have_sign && new_spnego) {
1124 spnego_state->needs_mic_check = true;
1125 spnego_state->needs_mic_sign = true;
1128 if (have_sign && ta->mechListMIC.length > 0) {
1129 status = gensec_check_packet(spnego_state->sub_sec_security,
1130 spnego_state->mech_types.data,
1131 spnego_state->mech_types.length,
1132 spnego_state->mech_types.data,
1133 spnego_state->mech_types.length,
1135 if (!NT_STATUS_IS_OK(status)) {
1136 DBG_WARNING("failed to verify mechListMIC: %s\n",
1138 goto server_response;
1141 spnego_state->needs_mic_check = false;
1142 spnego_state->done_mic_check = true;
1145 if (spnego_state->needs_mic_sign) {
1146 status = gensec_sign_packet(spnego_state->sub_sec_security,
1148 spnego_state->mech_types.data,
1149 spnego_state->mech_types.length,
1150 spnego_state->mech_types.data,
1151 spnego_state->mech_types.length,
1153 if (!NT_STATUS_IS_OK(status)) {
1154 DBG_WARNING("failed to sign mechListMIC: %s\n",
1158 spnego_state->needs_mic_sign = false;
1161 if (spnego_state->needs_mic_check) {
1162 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
1166 return gensec_spnego_server_response(spnego_state,
1174 struct gensec_spnego_update_state {
1175 struct tevent_context *ev;
1176 struct gensec_security *gensec;
1177 struct spnego_state *spnego;
1180 struct spnego_data _spnego_in;
1181 struct spnego_data *spnego_in;
1194 static void gensec_spnego_update_cleanup(struct tevent_req *req,
1195 enum tevent_req_state req_state)
1197 struct gensec_spnego_update_state *state =
1198 tevent_req_data(req,
1199 struct gensec_spnego_update_state);
1201 switch (req_state) {
1202 case TEVENT_REQ_USER_ERROR:
1203 case TEVENT_REQ_TIMED_OUT:
1204 case TEVENT_REQ_NO_MEMORY:
1206 * A fatal error, further updates are not allowed.
1208 state->spnego->state_position = SPNEGO_DONE;
1215 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1216 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1217 DATA_BLOB *full_in);
1218 static void gensec_spnego_update_pre(struct tevent_req *req);
1219 static void gensec_spnego_update_done(struct tevent_req *subreq);
1220 static void gensec_spnego_update_post(struct tevent_req *req);
1221 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1222 TALLOC_CTX *out_mem_ctx,
1225 static struct tevent_req *gensec_spnego_update_send(TALLOC_CTX *mem_ctx,
1226 struct tevent_context *ev,
1227 struct gensec_security *gensec_security,
1230 struct spnego_state *spnego_state =
1231 talloc_get_type_abort(gensec_security->private_data,
1232 struct spnego_state);
1233 struct tevent_req *req = NULL;
1234 struct gensec_spnego_update_state *state = NULL;
1238 req = tevent_req_create(mem_ctx, &state,
1239 struct gensec_spnego_update_state);
1244 state->gensec = gensec_security;
1245 state->spnego = spnego_state;
1246 tevent_req_set_cleanup_fn(req, gensec_spnego_update_cleanup);
1248 if (spnego_state->out_frag.length > 0) {
1249 if (in.length > 0) {
1250 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1251 return tevent_req_post(req, ev);
1254 status = gensec_spnego_update_out(gensec_security,
1255 state, &state->out);
1256 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1257 tevent_req_nterror(req, status);
1258 return tevent_req_post(req, ev);
1261 state->status = status;
1262 tevent_req_done(req);
1263 return tevent_req_post(req, ev);
1266 status = gensec_spnego_update_in(gensec_security, in,
1267 state, &state->full_in);
1268 state->status = status;
1269 if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1270 tevent_req_done(req);
1271 return tevent_req_post(req, ev);
1273 if (tevent_req_nterror(req, status)) {
1274 return tevent_req_post(req, ev);
1277 /* Check if we got a valid SPNEGO blob... */
1279 switch (spnego_state->state_position) {
1280 case SPNEGO_FALLBACK:
1283 case SPNEGO_CLIENT_TARG:
1284 case SPNEGO_SERVER_TARG:
1285 if (state->full_in.length == 0) {
1286 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1287 return tevent_req_post(req, ev);
1291 case SPNEGO_CLIENT_START:
1292 case SPNEGO_SERVER_START:
1294 if (state->full_in.length == 0) {
1295 /* create_negTokenInit later */
1299 len = spnego_read_data(state,
1301 &state->_spnego_in);
1303 if (spnego_state->state_position != SPNEGO_SERVER_START) {
1304 DEBUG(1, ("Invalid SPNEGO request:\n"));
1305 dump_data(1, state->full_in.data,
1306 state->full_in.length);
1307 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1308 return tevent_req_post(req, ev);
1312 * This is the 'fallback' case, where we don't get
1313 * SPNEGO, and have to try all the other options (and
1314 * hope they all have a magic string they check)
1316 status = gensec_spnego_server_try_fallback(gensec_security,
1320 if (tevent_req_nterror(req, status)) {
1321 return tevent_req_post(req, ev);
1325 * We'll continue with SPNEGO_FALLBACK below...
1329 state->spnego_in = &state->_spnego_in;
1331 /* OK, so it's real SPNEGO, check the packet's the one we expect */
1332 if (state->spnego_in->type != spnego_state->expected_packet) {
1333 DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n",
1334 state->spnego_in->type,
1335 spnego_state->expected_packet));
1336 dump_data(1, state->full_in.data,
1337 state->full_in.length);
1338 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1339 return tevent_req_post(req, ev);
1345 smb_panic(__location__);
1349 gensec_spnego_update_pre(req);
1350 if (!tevent_req_is_in_progress(req)) {
1351 return tevent_req_post(req, ev);
1354 if (state->sub.needed) {
1355 struct tevent_req *subreq = NULL;
1358 * We may need one more roundtrip...
1360 subreq = gensec_update_send(state, state->ev,
1361 spnego_state->sub_sec_security,
1363 if (tevent_req_nomem(subreq, req)) {
1364 return tevent_req_post(req, ev);
1366 tevent_req_set_callback(subreq,
1367 gensec_spnego_update_done,
1369 state->sub.needed = false;
1373 gensec_spnego_update_post(req);
1374 if (!tevent_req_is_in_progress(req)) {
1375 return tevent_req_post(req, ev);
1381 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1382 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1385 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1389 *full_in = data_blob_null;
1391 switch (spnego_state->state_position) {
1392 case SPNEGO_FALLBACK:
1394 spnego_state->in_needed = 0;
1395 return NT_STATUS_OK;
1397 case SPNEGO_CLIENT_START:
1398 case SPNEGO_CLIENT_TARG:
1399 case SPNEGO_SERVER_START:
1400 case SPNEGO_SERVER_TARG:
1405 return NT_STATUS_INVALID_PARAMETER;
1408 if (spnego_state->in_needed == 0) {
1413 * try to work out the size of the full
1414 * input token, it might be fragmented
1416 ret = asn1_peek_full_tag(in, ASN1_APPLICATION(0), &size);
1417 if ((ret != 0) && (ret != EAGAIN)) {
1418 ret = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
1421 if ((ret == 0) || (ret == EAGAIN)) {
1422 spnego_state->in_needed = size;
1425 * If it is not an asn1 message
1426 * just call the next layer.
1428 spnego_state->in_needed = in.length;
1432 if (spnego_state->in_needed > UINT16_MAX) {
1434 * limit the incoming message to 0xFFFF
1435 * to avoid DoS attacks.
1437 return NT_STATUS_INVALID_BUFFER_SIZE;
1440 if ((spnego_state->in_needed > 0) && (in.length == 0)) {
1442 * If we reach this, we know we got at least
1443 * part of an asn1 message, getting 0 means
1444 * the remote peer wants us to spin.
1446 return NT_STATUS_INVALID_PARAMETER;
1449 expected = spnego_state->in_needed - spnego_state->in_frag.length;
1450 if (in.length > expected) {
1452 * we got more than expected
1454 return NT_STATUS_INVALID_PARAMETER;
1457 if (in.length == spnego_state->in_needed) {
1459 * if the in.length contains the full blob
1462 * Note: this implies spnego_state->in_frag.length == 0,
1463 * but we do not need to check this explicitly
1464 * because we already know that we did not get
1465 * more than expected.
1468 spnego_state->in_needed = 0;
1469 return NT_STATUS_OK;
1472 ok = data_blob_append(spnego_state, &spnego_state->in_frag,
1473 in.data, in.length);
1475 return NT_STATUS_NO_MEMORY;
1478 if (spnego_state->in_needed > spnego_state->in_frag.length) {
1479 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1482 *full_in = spnego_state->in_frag;
1483 talloc_steal(mem_ctx, full_in->data);
1484 spnego_state->in_frag = data_blob_null;
1485 spnego_state->in_needed = 0;
1486 return NT_STATUS_OK;
1489 static void gensec_spnego_update_pre(struct tevent_req *req)
1491 struct gensec_spnego_update_state *state =
1492 tevent_req_data(req,
1493 struct gensec_spnego_update_state);
1494 struct gensec_security *gensec_security = state->gensec;
1495 struct spnego_state *spnego_state = state->spnego;
1496 struct tevent_context *ev = state->ev;
1499 state->sub.needed = false;
1500 state->sub.in = data_blob_null;
1501 state->sub.status = NT_STATUS_INTERNAL_ERROR;
1502 state->sub.out = data_blob_null;
1504 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1505 state->sub.in = state->full_in;
1506 state->full_in = data_blob_null;
1507 state->sub.needed = true;
1511 switch (spnego_state->state_position) {
1512 case SPNEGO_CLIENT_START:
1513 if (state->spnego_in == NULL) {
1514 /* client to produce negTokenInit */
1515 status = gensec_spnego_create_negTokenInit(gensec_security,
1516 spnego_state, state, ev,
1517 &spnego_state->out_frag);
1518 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1519 tevent_req_nterror(req, status);
1525 status = gensec_spnego_client_negTokenInit(gensec_security,
1527 state->spnego_in, state,
1528 &spnego_state->out_frag);
1531 case SPNEGO_CLIENT_TARG:
1532 status = gensec_spnego_client_negTokenTarg(gensec_security,
1534 state->spnego_in, state,
1535 &spnego_state->out_frag);
1536 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1537 tevent_req_nterror(req, status);
1542 case SPNEGO_SERVER_START:
1543 if (state->spnego_in == NULL) {
1544 /* server to produce negTokenInit */
1545 status = gensec_spnego_create_negTokenInit(gensec_security,
1546 spnego_state, state, ev,
1547 &spnego_state->out_frag);
1548 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1549 tevent_req_nterror(req, status);
1555 status = gensec_spnego_server_negTokenInit(gensec_security,
1557 state->spnego_in, state,
1558 &spnego_state->out_frag);
1559 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1560 tevent_req_nterror(req, status);
1565 case SPNEGO_SERVER_TARG:
1566 status = gensec_spnego_server_negTokenTarg(gensec_security,
1568 state->spnego_in, state,
1569 &spnego_state->out_frag);
1570 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1571 tevent_req_nterror(req, status);
1577 smb_panic(__location__);
1581 spnego_state->out_status = status;
1584 static void gensec_spnego_update_done(struct tevent_req *subreq)
1586 struct tevent_req *req =
1587 tevent_req_callback_data(subreq,
1589 struct gensec_spnego_update_state *state =
1590 tevent_req_data(req,
1591 struct gensec_spnego_update_state);
1592 struct spnego_state *spnego_state = state->spnego;
1594 state->sub.status = gensec_update_recv(subreq, state, &state->sub.out);
1595 TALLOC_FREE(subreq);
1596 if (NT_STATUS_IS_OK(state->sub.status)) {
1597 spnego_state->sub_sec_ready = true;
1600 gensec_spnego_update_post(req);
1603 static void gensec_spnego_update_post(struct tevent_req *req)
1605 struct gensec_spnego_update_state *state =
1606 tevent_req_data(req,
1607 struct gensec_spnego_update_state);
1608 struct spnego_state *spnego_state = state->spnego;
1611 state->sub.in = data_blob_null;
1612 state->sub.needed = false;
1614 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1615 status = state->sub.status;
1616 spnego_state->out_frag = state->sub.out;
1617 talloc_steal(spnego_state, spnego_state->out_frag.data);
1618 state->sub.out = data_blob_null;
1623 * For now just handle the sync processing done
1624 * in gensec_spnego_update_pre()
1626 status = spnego_state->out_status;
1628 if (NT_STATUS_IS_OK(status)) {
1629 bool reset_full = true;
1631 reset_full = !spnego_state->done_mic_check;
1633 status = gensec_may_reset_crypto(spnego_state->sub_sec_security,
1635 if (tevent_req_nterror(req, status)) {
1641 spnego_state->out_status = status;
1643 status = gensec_spnego_update_out(state->gensec,
1644 state, &state->out);
1645 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1646 tevent_req_nterror(req, status);
1650 state->status = status;
1651 tevent_req_done(req);
1655 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1656 TALLOC_CTX *out_mem_ctx,
1659 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1660 DATA_BLOB out = data_blob_null;
1663 *_out = data_blob_null;
1665 if (spnego_state->out_frag.length <= spnego_state->out_max_length) {
1667 * Fast path, we can deliver everything
1670 *_out = spnego_state->out_frag;
1671 if (spnego_state->out_frag.length > 0) {
1672 talloc_steal(out_mem_ctx, _out->data);
1673 spnego_state->out_frag = data_blob_null;
1676 if (!NT_STATUS_IS_OK(spnego_state->out_status)) {
1677 return spnego_state->out_status;
1681 * We're completely done, further updates are not allowed.
1683 spnego_state->state_position = SPNEGO_DONE;
1684 return gensec_child_ready(gensec_security,
1685 spnego_state->sub_sec_security);
1688 out = spnego_state->out_frag;
1691 * copy the remaining bytes
1693 spnego_state->out_frag = data_blob_talloc(spnego_state,
1694 out.data + spnego_state->out_max_length,
1695 out.length - spnego_state->out_max_length);
1696 if (spnego_state->out_frag.data == NULL) {
1697 return NT_STATUS_NO_MEMORY;
1701 * truncate the buffer
1703 ok = data_blob_realloc(spnego_state, &out,
1704 spnego_state->out_max_length);
1706 return NT_STATUS_NO_MEMORY;
1709 talloc_steal(out_mem_ctx, out.data);
1711 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1714 static NTSTATUS gensec_spnego_update_recv(struct tevent_req *req,
1715 TALLOC_CTX *out_mem_ctx,
1718 struct gensec_spnego_update_state *state =
1719 tevent_req_data(req,
1720 struct gensec_spnego_update_state);
1723 *out = data_blob_null;
1725 if (tevent_req_is_nterror(req, &status)) {
1726 tevent_req_received(req);
1731 talloc_steal(out_mem_ctx, state->out.data);
1732 status = state->status;
1733 tevent_req_received(req);
1737 static const char *gensec_spnego_oids[] = {
1742 static const struct gensec_security_ops gensec_spnego_security_ops = {
1744 .sasl_name = "GSS-SPNEGO",
1745 .auth_type = DCERPC_AUTH_TYPE_SPNEGO,
1746 .oid = gensec_spnego_oids,
1747 .client_start = gensec_spnego_client_start,
1748 .server_start = gensec_spnego_server_start,
1749 .update_send = gensec_spnego_update_send,
1750 .update_recv = gensec_spnego_update_recv,
1751 .seal_packet = gensec_child_seal_packet,
1752 .sign_packet = gensec_child_sign_packet,
1753 .sig_size = gensec_child_sig_size,
1754 .max_wrapped_size = gensec_child_max_wrapped_size,
1755 .max_input_size = gensec_child_max_input_size,
1756 .check_packet = gensec_child_check_packet,
1757 .unseal_packet = gensec_child_unseal_packet,
1758 .wrap = gensec_child_wrap,
1759 .unwrap = gensec_child_unwrap,
1760 .session_key = gensec_child_session_key,
1761 .session_info = gensec_child_session_info,
1762 .want_feature = gensec_child_want_feature,
1763 .have_feature = gensec_child_have_feature,
1764 .expire_time = gensec_child_expire_time,
1765 .final_auth_type = gensec_child_final_auth_type,
1767 .priority = GENSEC_SPNEGO
1770 _PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx)
1773 ret = gensec_register(ctx, &gensec_spnego_security_ops);
1774 if (!NT_STATUS_IS_OK(ret)) {
1775 DEBUG(0,("Failed to register '%s' gensec backend!\n",
1776 gensec_spnego_security_ops.name));