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 nt_status = gensec_subcontext_start(spnego_state,
235 &spnego_state->sub_sec_security);
236 if (!NT_STATUS_IS_OK(nt_status)) {
239 /* select the sub context */
240 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
242 if (!NT_STATUS_IS_OK(nt_status)) {
243 gensec_spnego_update_sub_abort(spnego_state);
247 /* In the client, try and produce the first (optimistic) packet */
248 if (spnego_state->state_position == SPNEGO_CLIENT_START) {
249 nt_status = gensec_update_ev(spnego_state->sub_sec_security,
254 if (NT_STATUS_IS_OK(nt_status)) {
255 spnego_state->sub_sec_ready = true;
258 if (GENSEC_UPDATE_IS_NTERROR(nt_status)) {
259 const char *next = NULL;
260 const char *principal = NULL;
261 int dbg_level = DBGLVL_WARNING;
263 if (all_sec[i+1].op != NULL) {
264 next = all_sec[i+1].op->name;
265 dbg_level = DBGLVL_NOTICE;
268 if (gensec_security->target.principal != NULL) {
269 principal = gensec_security->target.principal;
270 } else if (gensec_security->target.service != NULL &&
271 gensec_security->target.hostname != NULL)
273 principal = talloc_asprintf(spnego_state->sub_sec_security,
275 gensec_security->target.service,
276 gensec_security->target.hostname);
278 principal = gensec_security->target.hostname;
281 DEBUG(dbg_level, ("SPNEGO(%s) creating NEG_TOKEN_INIT for %s failed (next[%s]): %s\n",
282 spnego_state->sub_sec_security->ops->name,
284 next, nt_errstr(nt_status)));
287 * Pretend we never started it
289 gensec_spnego_update_sub_abort(spnego_state);
296 gensec_spnego_update_sub_abort(spnego_state);
298 DEBUG(10, ("Failed to setup SPNEGO negTokenInit request: %s\n", nt_errstr(nt_status)));
302 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
304 send_mech_types = gensec_security_oids_from_ops_wrapped(out_mem_ctx,
307 ok = spnego_write_mech_types(spnego_state,
309 &spnego_state->mech_types);
311 DEBUG(1, ("SPNEGO: Failed to write mechTypes\n"));
312 return NT_STATUS_NO_MEMORY;
315 /* List the remaining mechs as options */
316 spnego_out.negTokenInit.mechTypes = send_mech_types;
317 spnego_out.negTokenInit.reqFlags = data_blob_null;
318 spnego_out.negTokenInit.reqFlagsPadding = 0;
320 if (spnego_state->state_position == SPNEGO_SERVER_START) {
321 spnego_out.negTokenInit.mechListMIC
322 = data_blob_string_const(ADS_IGNORE_PRINCIPAL);
324 spnego_out.negTokenInit.mechListMIC = data_blob_null;
327 spnego_out.negTokenInit.mechToken = unwrapped_out;
329 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
330 DEBUG(1, ("Failed to write NEG_TOKEN_INIT\n"));
331 return NT_STATUS_INVALID_PARAMETER;
335 spnego_state->neg_oid = all_sec[i].oid;
337 if (spnego_state->state_position == SPNEGO_SERVER_START) {
338 spnego_state->state_position = SPNEGO_SERVER_START;
339 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
341 spnego_state->state_position = SPNEGO_CLIENT_TARG;
342 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
345 return NT_STATUS_MORE_PROCESSING_REQUIRED;
348 static NTSTATUS gensec_spnego_client_negTokenInit(struct gensec_security *gensec_security,
349 struct spnego_state *spnego_state,
350 struct tevent_context *ev,
351 struct spnego_data *spnego_in,
352 TALLOC_CTX *out_mem_ctx,
355 TALLOC_CTX *frame = talloc_stackframe();
356 DATA_BLOB sub_out = data_blob_null;
357 const char *tp = NULL;
358 const char * const *mech_types = NULL;
360 const struct gensec_security_ops_wrapper *all_sec = NULL;
361 struct spnego_data spnego_out;
362 const char *my_mechs[] = {NULL, NULL};
366 *out = data_blob_null;
368 /* The server offers a list of mechanisms */
370 tp = spnego_in->negTokenInit.targetPrincipal;
371 if (tp != NULL && strcmp(tp, ADS_IGNORE_PRINCIPAL) != 0) {
372 DBG_INFO("Server claims it's principal name is %s\n", tp);
373 if (lpcfg_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
374 gensec_set_target_principal(gensec_security, tp);
378 mech_types = spnego_in->negTokenInit.mechTypes;
379 if (mech_types == NULL) {
381 return NT_STATUS_INVALID_PARAMETER;
384 all_sec = gensec_security_by_oid_list(gensec_security,
387 if (all_sec == NULL) {
388 DBG_WARNING("gensec_security_by_oid_list() failed\n");
390 return NT_STATUS_INVALID_PARAMETER;
393 for (; all_sec[all_idx].op; all_idx++) {
394 const struct gensec_security_ops_wrapper *cur_sec =
396 const char *next = NULL;
397 const char *principal = NULL;
398 int dbg_level = DBGLVL_WARNING;
399 bool allow_fallback = false;
401 status = gensec_subcontext_start(spnego_state,
403 &spnego_state->sub_sec_security);
404 if (!NT_STATUS_IS_OK(status)) {
409 /* select the sub context */
410 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
412 if (!NT_STATUS_IS_OK(status)) {
414 * Pretend we never started it.
416 gensec_spnego_update_sub_abort(spnego_state);
420 spnego_state->neg_oid = cur_sec->oid;
423 * As client we don't use an optimistic token from the server.
425 status = gensec_update_ev(spnego_state->sub_sec_security,
426 frame, ev, data_blob_null, &sub_out);
427 if (NT_STATUS_IS_OK(status)) {
428 spnego_state->sub_sec_ready = true;
431 if (!GENSEC_UPDATE_IS_NTERROR(status)) {
432 /* OK or MORE_PROCESSING_REQUIRED */
437 * it is likely that a NULL input token will
438 * not be liked by most server mechs, but if
439 * we are in the client, we want the first
440 * update packet to be able to abort the use
443 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
444 NT_STATUS_EQUAL(status, NT_STATUS_NO_LOGON_SERVERS) ||
445 NT_STATUS_EQUAL(status, NT_STATUS_TIME_DIFFERENCE_AT_DC) ||
446 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO))
448 allow_fallback = true;
451 if (allow_fallback && cur_sec[1].op != NULL) {
452 next = cur_sec[1].op->name;
453 dbg_level = DBGLVL_NOTICE;
456 if (gensec_security->target.principal != NULL) {
457 principal = gensec_security->target.principal;
458 } else if (gensec_security->target.service != NULL &&
459 gensec_security->target.hostname != NULL)
461 principal = talloc_asprintf(spnego_state->sub_sec_security,
463 gensec_security->target.service,
464 gensec_security->target.hostname);
466 principal = gensec_security->target.hostname;
469 DBG_PREFIX(dbg_level, (
470 "%s: creating NEG_TOKEN_INIT "
471 "for %s failed (next[%s]): %s\n",
472 spnego_state->sub_sec_security->ops->name,
473 principal, next, nt_errstr(status)));
477 * A hard error without a possible fallback.
484 * Pretend we never started it.
486 gensec_spnego_update_sub_abort(spnego_state);
489 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
491 return NT_STATUS_INVALID_PARAMETER;
494 my_mechs[0] = spnego_state->neg_oid;
496 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
497 spnego_out.negTokenInit.mechTypes = my_mechs;
498 spnego_out.negTokenInit.reqFlags = data_blob_null;
499 spnego_out.negTokenInit.reqFlagsPadding = 0;
500 spnego_out.negTokenInit.mechListMIC = data_blob_null;
501 spnego_out.negTokenInit.mechToken = sub_out;
503 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
504 DBG_ERR("Failed to write SPNEGO reply to NEG_TOKEN_INIT\n");
506 return NT_STATUS_INVALID_PARAMETER;
509 ok = spnego_write_mech_types(spnego_state,
511 &spnego_state->mech_types);
513 DBG_ERR("failed to write mechTypes\n");
515 return NT_STATUS_NO_MEMORY;
519 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
520 spnego_state->state_position = SPNEGO_CLIENT_TARG;
523 return NT_STATUS_MORE_PROCESSING_REQUIRED;
526 static NTSTATUS gensec_spnego_client_negTokenTarg(struct gensec_security *gensec_security,
527 struct spnego_state *spnego_state,
528 struct tevent_context *ev,
529 struct spnego_data *spnego_in,
530 TALLOC_CTX *out_mem_ctx,
533 struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
534 DATA_BLOB sub_in = ta->responseToken;
535 DATA_BLOB mech_list_mic = data_blob_null;
536 DATA_BLOB sub_out = data_blob_null;
537 struct spnego_data spnego_out;
540 *out = data_blob_null;
542 spnego_state->num_targs++;
544 if (ta->negResult == SPNEGO_REJECT) {
545 return NT_STATUS_LOGON_FAILURE;
548 if (ta->negResult == SPNEGO_REQUEST_MIC) {
549 spnego_state->mic_requested = true;
552 if (ta->mechListMIC.length > 0) {
553 DATA_BLOB *m = &ta->mechListMIC;
554 const DATA_BLOB *r = &ta->responseToken;
557 * Windows 2000 has a bug, it repeats the
558 * responseToken in the mechListMIC field.
560 if (m->length == r->length) {
563 cmp = memcmp(m->data, r->data, m->length);
570 /* Server didn't like our choice of mech, and chose something else */
571 if (((ta->negResult == SPNEGO_ACCEPT_INCOMPLETE) ||
572 (ta->negResult == SPNEGO_REQUEST_MIC)) &&
573 ta->supportedMech != NULL &&
574 strcmp(ta->supportedMech, spnego_state->neg_oid) != 0)
576 const char *client_mech = NULL;
577 const char *client_oid = NULL;
578 const char *server_mech = NULL;
579 const char *server_oid = NULL;
581 client_mech = gensec_get_name_by_oid(gensec_security,
582 spnego_state->neg_oid);
583 client_oid = spnego_state->neg_oid;
584 server_mech = gensec_get_name_by_oid(gensec_security,
586 server_oid = ta->supportedMech;
588 DBG_NOTICE("client preferred mech (%s[%s]) not accepted, "
589 "server wants: %s[%s]\n",
590 client_mech, client_oid, server_mech, server_oid);
592 spnego_state->downgraded = true;
593 gensec_spnego_update_sub_abort(spnego_state);
595 status = gensec_subcontext_start(spnego_state,
597 &spnego_state->sub_sec_security);
598 if (!NT_STATUS_IS_OK(status)) {
602 /* select the sub context */
603 status = gensec_start_mech_by_oid(spnego_state->sub_sec_security,
605 if (!NT_STATUS_IS_OK(status)) {
609 spnego_state->neg_oid = talloc_strdup(spnego_state,
611 if (spnego_state->neg_oid == NULL) {
612 return NT_STATUS_NO_MEMORY;
616 if (ta->mechListMIC.length > 0) {
617 if (spnego_state->sub_sec_ready) {
618 spnego_state->needs_mic_check = true;
622 if (spnego_state->needs_mic_check) {
623 if (ta->responseToken.length != 0) {
624 DBG_WARNING("non empty response token not expected\n");
625 return NT_STATUS_INVALID_PARAMETER;
628 if (ta->mechListMIC.length == 0
629 && spnego_state->may_skip_mic_check) {
631 * In this case we don't require
632 * a mechListMIC from the server.
634 * This works around bugs in the Azure
635 * and Apple spnego implementations.
638 * https://bugzilla.samba.org/show_bug.cgi?id=11994
640 spnego_state->needs_mic_check = false;
641 status = NT_STATUS_OK;
642 goto client_response;
645 status = gensec_check_packet(spnego_state->sub_sec_security,
646 spnego_state->mech_types.data,
647 spnego_state->mech_types.length,
648 spnego_state->mech_types.data,
649 spnego_state->mech_types.length,
651 if (!NT_STATUS_IS_OK(status)) {
652 DBG_WARNING("failed to verify mechListMIC: %s\n",
656 spnego_state->needs_mic_check = false;
657 spnego_state->done_mic_check = true;
658 goto client_response;
661 if (!spnego_state->sub_sec_ready) {
662 status = gensec_update_ev(spnego_state->sub_sec_security,
666 if (NT_STATUS_IS_OK(status)) {
667 spnego_state->sub_sec_ready = true;
669 if (!NT_STATUS_IS_OK(status)) {
670 goto client_response;
673 status = NT_STATUS_OK;
676 if (!spnego_state->done_mic_check) {
677 bool have_sign = true;
678 bool new_spnego = false;
680 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
681 GENSEC_FEATURE_SIGN);
682 if (spnego_state->simulate_w2k) {
685 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
686 GENSEC_FEATURE_NEW_SPNEGO);
688 switch (ta->negResult) {
689 case SPNEGO_ACCEPT_COMPLETED:
690 case SPNEGO_NONE_RESULT:
691 if (spnego_state->num_targs == 1) {
693 * the first exchange doesn't require
701 case SPNEGO_ACCEPT_INCOMPLETE:
702 if (ta->mechListMIC.length > 0) {
707 if (spnego_state->downgraded) {
709 * A downgrade should be protected if
716 * The caller may just asked for
717 * GENSEC_FEATURE_SESSION_KEY, this
718 * is only reflected in the want_features.
721 * gensec_have_features(GENSEC_FEATURE_SIGN)
724 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
727 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
731 * Here we're sure our preferred mech was
732 * selected by the server and our caller doesn't
733 * need GENSEC_FEATURE_SIGN nor
734 * GENSEC_FEATURE_SEAL support.
736 * In this case we don't require
737 * a mechListMIC from the server.
739 * This works around bugs in the Azure
740 * and Apple spnego implementations.
743 * https://bugzilla.samba.org/show_bug.cgi?id=11994
745 spnego_state->may_skip_mic_check = true;
748 case SPNEGO_REQUEST_MIC:
749 if (ta->mechListMIC.length > 0) {
757 if (spnego_state->mic_requested) {
763 if (have_sign && new_spnego) {
764 spnego_state->needs_mic_check = true;
765 spnego_state->needs_mic_sign = true;
769 if (ta->mechListMIC.length > 0) {
770 status = gensec_check_packet(spnego_state->sub_sec_security,
771 spnego_state->mech_types.data,
772 spnego_state->mech_types.length,
773 spnego_state->mech_types.data,
774 spnego_state->mech_types.length,
776 if (!NT_STATUS_IS_OK(status)) {
777 DBG_WARNING("failed to verify mechListMIC: %s\n",
781 spnego_state->needs_mic_check = false;
782 spnego_state->done_mic_check = true;
785 if (spnego_state->needs_mic_sign) {
786 status = gensec_sign_packet(spnego_state->sub_sec_security,
788 spnego_state->mech_types.data,
789 spnego_state->mech_types.length,
790 spnego_state->mech_types.data,
791 spnego_state->mech_types.length,
793 if (!NT_STATUS_IS_OK(status)) {
794 DBG_WARNING("failed to sign mechListMIC: %s\n",
798 spnego_state->needs_mic_sign = false;
801 if (spnego_state->needs_mic_check) {
802 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
806 if (GENSEC_UPDATE_IS_NTERROR(status)) {
807 DBG_WARNING("SPNEGO(%s) login failed: %s\n",
808 spnego_state->sub_sec_security->ops->name,
813 if (sub_out.length || mech_list_mic.length) {
815 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
816 spnego_out.negTokenTarg.negResult = SPNEGO_NONE_RESULT;
817 spnego_out.negTokenTarg.supportedMech = NULL;
818 spnego_out.negTokenTarg.responseToken = sub_out;
819 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
821 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
822 DBG_WARNING("Failed to write NEG_TOKEN_TARG\n");
823 return NT_STATUS_INVALID_PARAMETER;
826 spnego_state->num_targs++;
827 spnego_state->state_position = SPNEGO_CLIENT_TARG;
828 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
831 /* all done - server has accepted, and we agree */
832 *out = data_blob_null;
834 if (ta->negResult != SPNEGO_ACCEPT_COMPLETED) {
835 /* unless of course it did not accept */
836 DBG_WARNING("gensec_update ok but not accepted\n");
837 status = NT_STATUS_INVALID_PARAMETER;
840 spnego_state->state_position = SPNEGO_DONE;
846 /** create a server negTokenTarg
848 * This is the case, where the client is the first one who sends data
851 static NTSTATUS gensec_spnego_server_response(struct spnego_state *spnego_state,
852 TALLOC_CTX *out_mem_ctx,
854 const DATA_BLOB unwrapped_out,
855 DATA_BLOB mech_list_mic,
858 struct spnego_data spnego_out;
861 spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
862 spnego_out.negTokenTarg.responseToken = unwrapped_out;
863 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
864 spnego_out.negTokenTarg.supportedMech = NULL;
866 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
867 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
868 if (spnego_state->mic_requested) {
869 spnego_out.negTokenTarg.negResult = SPNEGO_REQUEST_MIC;
870 spnego_state->mic_requested = false;
872 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
874 spnego_state->state_position = SPNEGO_SERVER_TARG;
875 } else if (NT_STATUS_IS_OK(nt_status)) {
876 if (unwrapped_out.data) {
877 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
879 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
880 spnego_state->state_position = SPNEGO_DONE;
882 spnego_out.negTokenTarg.negResult = SPNEGO_REJECT;
883 spnego_out.negTokenTarg.mechListMIC = data_blob_null;
884 DEBUG(2, ("SPNEGO login failed: %s\n", nt_errstr(nt_status)));
885 spnego_state->state_position = SPNEGO_DONE;
888 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
889 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
890 return NT_STATUS_INVALID_PARAMETER;
893 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
894 spnego_state->num_targs++;
899 static NTSTATUS gensec_spnego_server_negTokenInit(struct gensec_security *gensec_security,
900 struct spnego_state *spnego_state,
901 struct tevent_context *ev,
902 struct spnego_data *spnego_in,
903 TALLOC_CTX *out_mem_ctx,
906 TALLOC_CTX *frame = talloc_stackframe();
907 DATA_BLOB sub_out = data_blob_null;
908 DATA_BLOB mech_list_mic = data_blob_null;
909 const char * const *mech_types = NULL;
911 const struct gensec_security_ops_wrapper *all_sec = NULL;
916 mech_types = spnego_in->negTokenInit.mechTypes;
917 if (mech_types == NULL) {
919 return NT_STATUS_INVALID_PARAMETER;
922 all_sec = gensec_security_by_oid_list(gensec_security, frame,
923 mech_types, GENSEC_OID_SPNEGO);
924 if (all_sec == NULL) {
925 DBG_WARNING("gensec_security_by_oid_list() failed\n");
927 return NT_STATUS_INVALID_PARAMETER;
930 ok = spnego_write_mech_types(spnego_state, mech_types,
931 &spnego_state->mech_types);
933 DBG_ERR("Failed to write mechTypes\n");
935 return NT_STATUS_NO_MEMORY;
939 * First try the preferred mechs from the client.
941 for (; mech_types[mech_idx]; mech_idx++) {
942 const char *cur_mech = mech_types[mech_idx];
943 const struct gensec_security_ops_wrapper *cur_sec = NULL;
944 DATA_BLOB sub_in = data_blob_null;
946 for (all_idx = 0; all_sec[all_idx].op; all_idx++) {
947 if (strcmp(cur_mech, all_sec[all_idx].oid) == 0) {
948 cur_sec = &all_sec[all_idx];
953 if (cur_sec == NULL) {
957 status = gensec_subcontext_start(spnego_state,
959 &spnego_state->sub_sec_security);
960 if (!NT_STATUS_IS_OK(status)) {
965 /* select the sub context */
966 status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
968 if (!NT_STATUS_IS_OK(status)) {
970 * Pretend we never started it
972 gensec_spnego_update_sub_abort(spnego_state);
978 * Indicate the downgrade and request a
981 spnego_state->downgraded = true;
982 spnego_state->mic_requested = true;
983 /* no optimistic token */
984 spnego_state->neg_oid = cur_sec->oid;
985 sub_out = data_blob_null;
986 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
991 * Try the optimistic token from the client
993 sub_in = spnego_in->negTokenInit.mechToken;
994 status = gensec_update_ev(spnego_state->sub_sec_security,
995 frame, ev, sub_in, &sub_out);
996 if (NT_STATUS_IS_OK(status)) {
997 spnego_state->sub_sec_ready = true;
999 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) ||
1000 NT_STATUS_EQUAL(status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
1002 DBG_WARNING("%s: NEG_TOKEN_INIT failed to parse contents: %s\n",
1003 cur_sec->op->name, nt_errstr(status));
1006 * Pretend we never started it
1008 gensec_spnego_update_sub_abort(spnego_state);
1012 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1013 DBG_WARNING("%s: NEG_TOKEN_INIT failed: %s\n",
1014 cur_sec->op->name, nt_errstr(status));
1018 spnego_state->neg_oid = cur_sec->oid;
1019 goto reply; /* OK or MORE PROCESSING */
1022 DBG_WARNING("Could not find a suitable mechtype in NEG_TOKEN_INIT\n");
1023 status = NT_STATUS_INVALID_PARAMETER;
1026 if (spnego_state->simulate_w2k) {
1028 * Windows 2000 returns the unwrapped token
1029 * also in the mech_list_mic field.
1031 * In order to verify our client code,
1032 * we need a way to have a server with this
1035 mech_list_mic = sub_out;
1038 status = gensec_spnego_server_response(spnego_state,
1048 static NTSTATUS gensec_spnego_server_negTokenTarg(struct gensec_security *gensec_security,
1049 struct spnego_state *spnego_state,
1050 struct tevent_context *ev,
1051 struct spnego_data *spnego_in,
1052 TALLOC_CTX *out_mem_ctx,
1055 const struct spnego_negTokenTarg *ta = &spnego_in->negTokenTarg;
1056 DATA_BLOB sub_in = ta->responseToken;
1057 DATA_BLOB mech_list_mic = data_blob_null;
1058 DATA_BLOB sub_out = data_blob_null;
1060 bool have_sign = true;
1061 bool new_spnego = false;
1063 spnego_state->num_targs++;
1065 if (spnego_state->sub_sec_security == NULL) {
1066 DBG_ERR("SPNEGO: Did not setup a mech in NEG_TOKEN_INIT\n");
1067 return NT_STATUS_INVALID_PARAMETER;
1070 if (spnego_state->needs_mic_check) {
1071 if (ta->responseToken.length != 0) {
1072 DBG_WARNING("non empty response token not expected\n");
1073 return NT_STATUS_INVALID_PARAMETER;
1076 status = gensec_check_packet(spnego_state->sub_sec_security,
1077 spnego_state->mech_types.data,
1078 spnego_state->mech_types.length,
1079 spnego_state->mech_types.data,
1080 spnego_state->mech_types.length,
1082 if (!NT_STATUS_IS_OK(status)) {
1083 DBG_WARNING("failed to verify mechListMIC: %s\n",
1085 goto server_response;
1088 spnego_state->needs_mic_check = false;
1089 spnego_state->done_mic_check = true;
1090 goto server_response;
1093 if (!spnego_state->sub_sec_ready) {
1094 status = gensec_update_ev(spnego_state->sub_sec_security,
1097 if (NT_STATUS_IS_OK(status)) {
1098 spnego_state->sub_sec_ready = true;
1100 if (!NT_STATUS_IS_OK(status)) {
1101 goto server_response;
1104 status = NT_STATUS_OK;
1107 have_sign = gensec_have_feature(spnego_state->sub_sec_security,
1108 GENSEC_FEATURE_SIGN);
1109 if (spnego_state->simulate_w2k) {
1112 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
1113 GENSEC_FEATURE_NEW_SPNEGO);
1114 if (ta->mechListMIC.length > 0) {
1118 if (have_sign && new_spnego) {
1119 spnego_state->needs_mic_check = true;
1120 spnego_state->needs_mic_sign = true;
1123 if (have_sign && ta->mechListMIC.length > 0) {
1124 status = gensec_check_packet(spnego_state->sub_sec_security,
1125 spnego_state->mech_types.data,
1126 spnego_state->mech_types.length,
1127 spnego_state->mech_types.data,
1128 spnego_state->mech_types.length,
1130 if (!NT_STATUS_IS_OK(status)) {
1131 DBG_WARNING("failed to verify mechListMIC: %s\n",
1133 goto server_response;
1136 spnego_state->needs_mic_check = false;
1137 spnego_state->done_mic_check = true;
1140 if (spnego_state->needs_mic_sign) {
1141 status = gensec_sign_packet(spnego_state->sub_sec_security,
1143 spnego_state->mech_types.data,
1144 spnego_state->mech_types.length,
1145 spnego_state->mech_types.data,
1146 spnego_state->mech_types.length,
1148 if (!NT_STATUS_IS_OK(status)) {
1149 DBG_WARNING("failed to sign mechListMIC: %s\n",
1153 spnego_state->needs_mic_sign = false;
1156 if (spnego_state->needs_mic_check) {
1157 status = NT_STATUS_MORE_PROCESSING_REQUIRED;
1161 return gensec_spnego_server_response(spnego_state,
1169 struct gensec_spnego_update_state {
1170 struct tevent_context *ev;
1171 struct gensec_security *gensec;
1172 struct spnego_state *spnego;
1175 struct spnego_data _spnego_in;
1176 struct spnego_data *spnego_in;
1189 static void gensec_spnego_update_cleanup(struct tevent_req *req,
1190 enum tevent_req_state req_state)
1192 struct gensec_spnego_update_state *state =
1193 tevent_req_data(req,
1194 struct gensec_spnego_update_state);
1196 switch (req_state) {
1197 case TEVENT_REQ_USER_ERROR:
1198 case TEVENT_REQ_TIMED_OUT:
1199 case TEVENT_REQ_NO_MEMORY:
1201 * A fatal error, further updates are not allowed.
1203 state->spnego->state_position = SPNEGO_DONE;
1210 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1211 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1212 DATA_BLOB *full_in);
1213 static void gensec_spnego_update_pre(struct tevent_req *req);
1214 static void gensec_spnego_update_done(struct tevent_req *subreq);
1215 static void gensec_spnego_update_post(struct tevent_req *req);
1216 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1217 TALLOC_CTX *out_mem_ctx,
1220 static struct tevent_req *gensec_spnego_update_send(TALLOC_CTX *mem_ctx,
1221 struct tevent_context *ev,
1222 struct gensec_security *gensec_security,
1225 struct spnego_state *spnego_state =
1226 talloc_get_type_abort(gensec_security->private_data,
1227 struct spnego_state);
1228 struct tevent_req *req = NULL;
1229 struct gensec_spnego_update_state *state = NULL;
1233 req = tevent_req_create(mem_ctx, &state,
1234 struct gensec_spnego_update_state);
1239 state->gensec = gensec_security;
1240 state->spnego = spnego_state;
1241 tevent_req_set_cleanup_fn(req, gensec_spnego_update_cleanup);
1243 if (spnego_state->out_frag.length > 0) {
1244 if (in.length > 0) {
1245 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1246 return tevent_req_post(req, ev);
1249 status = gensec_spnego_update_out(gensec_security,
1250 state, &state->out);
1251 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1252 tevent_req_nterror(req, status);
1253 return tevent_req_post(req, ev);
1256 state->status = status;
1257 tevent_req_done(req);
1258 return tevent_req_post(req, ev);
1261 status = gensec_spnego_update_in(gensec_security, in,
1262 state, &state->full_in);
1263 state->status = status;
1264 if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1265 tevent_req_done(req);
1266 return tevent_req_post(req, ev);
1268 if (tevent_req_nterror(req, status)) {
1269 return tevent_req_post(req, ev);
1272 /* Check if we got a valid SPNEGO blob... */
1274 switch (spnego_state->state_position) {
1275 case SPNEGO_FALLBACK:
1278 case SPNEGO_CLIENT_TARG:
1279 case SPNEGO_SERVER_TARG:
1280 if (state->full_in.length == 0) {
1281 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1282 return tevent_req_post(req, ev);
1286 case SPNEGO_CLIENT_START:
1287 case SPNEGO_SERVER_START:
1289 if (state->full_in.length == 0) {
1290 /* create_negTokenInit later */
1294 len = spnego_read_data(state,
1296 &state->_spnego_in);
1298 if (spnego_state->state_position != SPNEGO_SERVER_START) {
1299 DEBUG(1, ("Invalid SPNEGO request:\n"));
1300 dump_data(1, state->full_in.data,
1301 state->full_in.length);
1302 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1303 return tevent_req_post(req, ev);
1307 * This is the 'fallback' case, where we don't get
1308 * SPNEGO, and have to try all the other options (and
1309 * hope they all have a magic string they check)
1311 status = gensec_spnego_server_try_fallback(gensec_security,
1315 if (tevent_req_nterror(req, status)) {
1316 return tevent_req_post(req, ev);
1320 * We'll continue with SPNEGO_FALLBACK below...
1324 state->spnego_in = &state->_spnego_in;
1326 /* OK, so it's real SPNEGO, check the packet's the one we expect */
1327 if (state->spnego_in->type != spnego_state->expected_packet) {
1328 DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n",
1329 state->spnego_in->type,
1330 spnego_state->expected_packet));
1331 dump_data(1, state->full_in.data,
1332 state->full_in.length);
1333 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
1334 return tevent_req_post(req, ev);
1340 smb_panic(__location__);
1344 gensec_spnego_update_pre(req);
1345 if (!tevent_req_is_in_progress(req)) {
1346 return tevent_req_post(req, ev);
1349 if (state->sub.needed) {
1350 struct tevent_req *subreq = NULL;
1353 * We may need one more roundtrip...
1355 subreq = gensec_update_send(state, state->ev,
1356 spnego_state->sub_sec_security,
1358 if (tevent_req_nomem(subreq, req)) {
1359 return tevent_req_post(req, ev);
1361 tevent_req_set_callback(subreq,
1362 gensec_spnego_update_done,
1364 state->sub.needed = false;
1368 gensec_spnego_update_post(req);
1369 if (!tevent_req_is_in_progress(req)) {
1370 return tevent_req_post(req, ev);
1376 static NTSTATUS gensec_spnego_update_in(struct gensec_security *gensec_security,
1377 const DATA_BLOB in, TALLOC_CTX *mem_ctx,
1380 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1384 *full_in = data_blob_null;
1386 switch (spnego_state->state_position) {
1387 case SPNEGO_FALLBACK:
1389 spnego_state->in_needed = 0;
1390 return NT_STATUS_OK;
1392 case SPNEGO_CLIENT_START:
1393 case SPNEGO_CLIENT_TARG:
1394 case SPNEGO_SERVER_START:
1395 case SPNEGO_SERVER_TARG:
1400 return NT_STATUS_INVALID_PARAMETER;
1403 if (spnego_state->in_needed == 0) {
1408 * try to work out the size of the full
1409 * input token, it might be fragmented
1411 ret = asn1_peek_full_tag(in, ASN1_APPLICATION(0), &size);
1412 if ((ret != 0) && (ret != EAGAIN)) {
1413 ret = asn1_peek_full_tag(in, ASN1_CONTEXT(1), &size);
1416 if ((ret == 0) || (ret == EAGAIN)) {
1417 spnego_state->in_needed = size;
1420 * If it is not an asn1 message
1421 * just call the next layer.
1423 spnego_state->in_needed = in.length;
1427 if (spnego_state->in_needed > UINT16_MAX) {
1429 * limit the incoming message to 0xFFFF
1430 * to avoid DoS attacks.
1432 return NT_STATUS_INVALID_BUFFER_SIZE;
1435 if ((spnego_state->in_needed > 0) && (in.length == 0)) {
1437 * If we reach this, we know we got at least
1438 * part of an asn1 message, getting 0 means
1439 * the remote peer wants us to spin.
1441 return NT_STATUS_INVALID_PARAMETER;
1444 expected = spnego_state->in_needed - spnego_state->in_frag.length;
1445 if (in.length > expected) {
1447 * we got more than expected
1449 return NT_STATUS_INVALID_PARAMETER;
1452 if (in.length == spnego_state->in_needed) {
1454 * if the in.length contains the full blob
1457 * Note: this implies spnego_state->in_frag.length == 0,
1458 * but we do not need to check this explicitly
1459 * because we already know that we did not get
1460 * more than expected.
1463 spnego_state->in_needed = 0;
1464 return NT_STATUS_OK;
1467 ok = data_blob_append(spnego_state, &spnego_state->in_frag,
1468 in.data, in.length);
1470 return NT_STATUS_NO_MEMORY;
1473 if (spnego_state->in_needed > spnego_state->in_frag.length) {
1474 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1477 *full_in = spnego_state->in_frag;
1478 talloc_steal(mem_ctx, full_in->data);
1479 spnego_state->in_frag = data_blob_null;
1480 spnego_state->in_needed = 0;
1481 return NT_STATUS_OK;
1484 static void gensec_spnego_update_pre(struct tevent_req *req)
1486 struct gensec_spnego_update_state *state =
1487 tevent_req_data(req,
1488 struct gensec_spnego_update_state);
1489 struct gensec_security *gensec_security = state->gensec;
1490 struct spnego_state *spnego_state = state->spnego;
1491 struct tevent_context *ev = state->ev;
1494 state->sub.needed = false;
1495 state->sub.in = data_blob_null;
1496 state->sub.status = NT_STATUS_INTERNAL_ERROR;
1497 state->sub.out = data_blob_null;
1499 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1500 state->sub.in = state->full_in;
1501 state->full_in = data_blob_null;
1502 state->sub.needed = true;
1506 switch (spnego_state->state_position) {
1507 case SPNEGO_CLIENT_START:
1508 if (state->spnego_in == NULL) {
1509 /* client to produce negTokenInit */
1510 status = gensec_spnego_create_negTokenInit(gensec_security,
1511 spnego_state, state, ev,
1512 &spnego_state->out_frag);
1513 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1514 tevent_req_nterror(req, status);
1520 status = gensec_spnego_client_negTokenInit(gensec_security,
1522 state->spnego_in, state,
1523 &spnego_state->out_frag);
1526 case SPNEGO_CLIENT_TARG:
1527 status = gensec_spnego_client_negTokenTarg(gensec_security,
1529 state->spnego_in, state,
1530 &spnego_state->out_frag);
1531 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1532 tevent_req_nterror(req, status);
1537 case SPNEGO_SERVER_START:
1538 if (state->spnego_in == NULL) {
1539 /* server to produce negTokenInit */
1540 status = gensec_spnego_create_negTokenInit(gensec_security,
1541 spnego_state, state, ev,
1542 &spnego_state->out_frag);
1543 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1544 tevent_req_nterror(req, status);
1550 status = gensec_spnego_server_negTokenInit(gensec_security,
1552 state->spnego_in, state,
1553 &spnego_state->out_frag);
1554 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1555 tevent_req_nterror(req, status);
1560 case SPNEGO_SERVER_TARG:
1561 status = gensec_spnego_server_negTokenTarg(gensec_security,
1563 state->spnego_in, state,
1564 &spnego_state->out_frag);
1565 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1566 tevent_req_nterror(req, status);
1572 smb_panic(__location__);
1576 spnego_state->out_status = status;
1579 static void gensec_spnego_update_done(struct tevent_req *subreq)
1581 struct tevent_req *req =
1582 tevent_req_callback_data(subreq,
1584 struct gensec_spnego_update_state *state =
1585 tevent_req_data(req,
1586 struct gensec_spnego_update_state);
1587 struct spnego_state *spnego_state = state->spnego;
1589 state->sub.status = gensec_update_recv(subreq, state, &state->sub.out);
1590 TALLOC_FREE(subreq);
1591 if (NT_STATUS_IS_OK(state->sub.status)) {
1592 spnego_state->sub_sec_ready = true;
1595 gensec_spnego_update_post(req);
1598 static void gensec_spnego_update_post(struct tevent_req *req)
1600 struct gensec_spnego_update_state *state =
1601 tevent_req_data(req,
1602 struct gensec_spnego_update_state);
1603 struct spnego_state *spnego_state = state->spnego;
1606 state->sub.in = data_blob_null;
1607 state->sub.needed = false;
1609 if (spnego_state->state_position == SPNEGO_FALLBACK) {
1610 status = state->sub.status;
1611 spnego_state->out_frag = state->sub.out;
1612 talloc_steal(spnego_state, spnego_state->out_frag.data);
1613 state->sub.out = data_blob_null;
1618 * For now just handle the sync processing done
1619 * in gensec_spnego_update_pre()
1621 status = spnego_state->out_status;
1623 if (NT_STATUS_IS_OK(status)) {
1624 bool reset_full = true;
1626 reset_full = !spnego_state->done_mic_check;
1628 status = gensec_may_reset_crypto(spnego_state->sub_sec_security,
1630 if (tevent_req_nterror(req, status)) {
1636 spnego_state->out_status = status;
1638 status = gensec_spnego_update_out(state->gensec,
1639 state, &state->out);
1640 if (GENSEC_UPDATE_IS_NTERROR(status)) {
1641 tevent_req_nterror(req, status);
1645 state->status = status;
1646 tevent_req_done(req);
1650 static NTSTATUS gensec_spnego_update_out(struct gensec_security *gensec_security,
1651 TALLOC_CTX *out_mem_ctx,
1654 struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1655 DATA_BLOB out = data_blob_null;
1658 *_out = data_blob_null;
1660 if (spnego_state->out_frag.length <= spnego_state->out_max_length) {
1662 * Fast path, we can deliver everything
1665 *_out = spnego_state->out_frag;
1666 if (spnego_state->out_frag.length > 0) {
1667 talloc_steal(out_mem_ctx, _out->data);
1668 spnego_state->out_frag = data_blob_null;
1671 if (!NT_STATUS_IS_OK(spnego_state->out_status)) {
1672 return spnego_state->out_status;
1676 * We're completely done, further updates are not allowed.
1678 spnego_state->state_position = SPNEGO_DONE;
1679 return gensec_child_ready(gensec_security,
1680 spnego_state->sub_sec_security);
1683 out = spnego_state->out_frag;
1686 * copy the remaining bytes
1688 spnego_state->out_frag = data_blob_talloc(spnego_state,
1689 out.data + spnego_state->out_max_length,
1690 out.length - spnego_state->out_max_length);
1691 if (spnego_state->out_frag.data == NULL) {
1692 return NT_STATUS_NO_MEMORY;
1696 * truncate the buffer
1698 ok = data_blob_realloc(spnego_state, &out,
1699 spnego_state->out_max_length);
1701 return NT_STATUS_NO_MEMORY;
1704 talloc_steal(out_mem_ctx, out.data);
1706 return NT_STATUS_MORE_PROCESSING_REQUIRED;
1709 static NTSTATUS gensec_spnego_update_recv(struct tevent_req *req,
1710 TALLOC_CTX *out_mem_ctx,
1713 struct gensec_spnego_update_state *state =
1714 tevent_req_data(req,
1715 struct gensec_spnego_update_state);
1718 *out = data_blob_null;
1720 if (tevent_req_is_nterror(req, &status)) {
1721 tevent_req_received(req);
1726 talloc_steal(out_mem_ctx, state->out.data);
1727 status = state->status;
1728 tevent_req_received(req);
1732 static const char *gensec_spnego_oids[] = {
1737 static const struct gensec_security_ops gensec_spnego_security_ops = {
1739 .sasl_name = "GSS-SPNEGO",
1740 .auth_type = DCERPC_AUTH_TYPE_SPNEGO,
1741 .oid = gensec_spnego_oids,
1742 .client_start = gensec_spnego_client_start,
1743 .server_start = gensec_spnego_server_start,
1744 .update_send = gensec_spnego_update_send,
1745 .update_recv = gensec_spnego_update_recv,
1746 .seal_packet = gensec_child_seal_packet,
1747 .sign_packet = gensec_child_sign_packet,
1748 .sig_size = gensec_child_sig_size,
1749 .max_wrapped_size = gensec_child_max_wrapped_size,
1750 .max_input_size = gensec_child_max_input_size,
1751 .check_packet = gensec_child_check_packet,
1752 .unseal_packet = gensec_child_unseal_packet,
1753 .wrap = gensec_child_wrap,
1754 .unwrap = gensec_child_unwrap,
1755 .session_key = gensec_child_session_key,
1756 .session_info = gensec_child_session_info,
1757 .want_feature = gensec_child_want_feature,
1758 .have_feature = gensec_child_have_feature,
1759 .expire_time = gensec_child_expire_time,
1760 .final_auth_type = gensec_child_final_auth_type,
1762 .priority = GENSEC_SPNEGO
1765 _PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx)
1768 ret = gensec_register(ctx, &gensec_spnego_security_ops);
1769 if (!NT_STATUS_IS_OK(ret)) {
1770 DEBUG(0,("Failed to register '%s' gensec backend!\n",
1771 gensec_spnego_security_ops.name));