s4:gensec: pass down want_features to the spnego backend mech
[kai/samba.git] / source4 / auth / gensec / spnego.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    RFC2478 Compliant SPNEGO implementation
5    
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
9
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.
14    
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.
19
20    
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/>.
23 */
24
25 #include "includes.h"
26 #include "auth/gensec/spnego.h"
27 #include "librpc/gen_ndr/ndr_dcerpc.h"
28 #include "auth/credentials/credentials.h"
29 #include "auth/gensec/gensec.h"
30 #include "auth/gensec/gensec_proto.h"
31
32 enum spnego_state_position {
33         SPNEGO_SERVER_START,
34         SPNEGO_CLIENT_START,
35         SPNEGO_SERVER_TARG,
36         SPNEGO_CLIENT_TARG,
37         SPNEGO_FALLBACK,
38         SPNEGO_DONE
39 };
40
41 struct spnego_state {
42         enum spnego_message_type expected_packet;
43         enum spnego_state_position state_position;
44         struct gensec_security *sub_sec_security;
45         bool no_response_expected;
46
47         const char *neg_oid;
48
49         DATA_BLOB mech_types;
50 };
51
52
53 static NTSTATUS gensec_spnego_client_start(struct gensec_security *gensec_security)
54 {
55         struct spnego_state *spnego_state;
56
57         spnego_state = talloc(gensec_security, struct spnego_state);
58         if (!spnego_state) {
59                 return NT_STATUS_NO_MEMORY;
60         }
61
62         spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
63         spnego_state->state_position = SPNEGO_CLIENT_START;
64         spnego_state->sub_sec_security = NULL;
65         spnego_state->no_response_expected = false;
66         spnego_state->mech_types = data_blob(NULL, 0);
67
68         gensec_security->private_data = spnego_state;
69         return NT_STATUS_OK;
70 }
71
72 static NTSTATUS gensec_spnego_server_start(struct gensec_security *gensec_security)
73 {
74         struct spnego_state *spnego_state;
75
76         spnego_state = talloc(gensec_security, struct spnego_state);            
77         if (!spnego_state) {
78                 return NT_STATUS_NO_MEMORY;
79         }
80
81         spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
82         spnego_state->state_position = SPNEGO_SERVER_START;
83         spnego_state->sub_sec_security = NULL;
84         spnego_state->no_response_expected = false;
85         spnego_state->mech_types = data_blob(NULL, 0);
86
87         gensec_security->private_data = spnego_state;
88         return NT_STATUS_OK;
89 }
90
91 /*
92   wrappers for the spnego_*() functions
93 */
94 static NTSTATUS gensec_spnego_unseal_packet(struct gensec_security *gensec_security, 
95                                             TALLOC_CTX *mem_ctx, 
96                                             uint8_t *data, size_t length, 
97                                             const uint8_t *whole_pdu, size_t pdu_length, 
98                                             const DATA_BLOB *sig)
99 {
100         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
101
102         if (spnego_state->state_position != SPNEGO_DONE 
103             && spnego_state->state_position != SPNEGO_FALLBACK) {
104                 return NT_STATUS_INVALID_PARAMETER;
105         }
106         
107         return gensec_unseal_packet(spnego_state->sub_sec_security, 
108                                     mem_ctx, 
109                                     data, length, 
110                                     whole_pdu, pdu_length,
111                                     sig); 
112 }
113
114 static NTSTATUS gensec_spnego_check_packet(struct gensec_security *gensec_security, 
115                                            TALLOC_CTX *mem_ctx, 
116                                            const uint8_t *data, size_t length, 
117                                            const uint8_t *whole_pdu, size_t pdu_length, 
118                                            const DATA_BLOB *sig)
119 {
120         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
121
122         if (spnego_state->state_position != SPNEGO_DONE 
123             && spnego_state->state_position != SPNEGO_FALLBACK) {
124                 return NT_STATUS_INVALID_PARAMETER;
125         }
126         
127         return gensec_check_packet(spnego_state->sub_sec_security, 
128                                    mem_ctx, 
129                                    data, length, 
130                                    whole_pdu, pdu_length,
131                                    sig);
132 }
133
134 static NTSTATUS gensec_spnego_seal_packet(struct gensec_security *gensec_security, 
135                                           TALLOC_CTX *mem_ctx, 
136                                           uint8_t *data, size_t length, 
137                                           const uint8_t *whole_pdu, size_t pdu_length, 
138                                           DATA_BLOB *sig)
139 {
140         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
141
142         if (spnego_state->state_position != SPNEGO_DONE 
143             && spnego_state->state_position != SPNEGO_FALLBACK) {
144                 return NT_STATUS_INVALID_PARAMETER;
145         }
146         
147         return gensec_seal_packet(spnego_state->sub_sec_security, 
148                                   mem_ctx, 
149                                   data, length, 
150                                   whole_pdu, pdu_length,
151                                   sig);
152 }
153
154 static NTSTATUS gensec_spnego_sign_packet(struct gensec_security *gensec_security, 
155                                           TALLOC_CTX *mem_ctx, 
156                                           const uint8_t *data, size_t length, 
157                                           const uint8_t *whole_pdu, size_t pdu_length, 
158                                           DATA_BLOB *sig)
159 {
160         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
161
162         if (spnego_state->state_position != SPNEGO_DONE 
163             && spnego_state->state_position != SPNEGO_FALLBACK) {
164                 return NT_STATUS_INVALID_PARAMETER;
165         }
166         
167         return gensec_sign_packet(spnego_state->sub_sec_security, 
168                                   mem_ctx, 
169                                   data, length, 
170                                   whole_pdu, pdu_length,
171                                   sig);
172 }
173
174 static NTSTATUS gensec_spnego_wrap(struct gensec_security *gensec_security, 
175                                    TALLOC_CTX *mem_ctx, 
176                                    const DATA_BLOB *in, 
177                                    DATA_BLOB *out)
178 {
179         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
180
181         if (spnego_state->state_position != SPNEGO_DONE 
182             && spnego_state->state_position != SPNEGO_FALLBACK) {
183                 DEBUG(1, ("gensec_spnego_wrap: wrong state for wrap\n"));
184                 return NT_STATUS_INVALID_PARAMETER;
185         }
186         
187         return gensec_wrap(spnego_state->sub_sec_security, 
188                            mem_ctx, in, out);
189 }
190
191 static NTSTATUS gensec_spnego_unwrap(struct gensec_security *gensec_security, 
192                                      TALLOC_CTX *mem_ctx, 
193                                      const DATA_BLOB *in, 
194                                      DATA_BLOB *out)
195 {
196         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
197
198         if (spnego_state->state_position != SPNEGO_DONE 
199             && spnego_state->state_position != SPNEGO_FALLBACK) {
200                 DEBUG(1, ("gensec_spnego_unwrap: wrong state for unwrap\n"));
201                 return NT_STATUS_INVALID_PARAMETER;
202         }
203         
204         return gensec_unwrap(spnego_state->sub_sec_security, 
205                              mem_ctx, in, out);
206 }
207
208 static NTSTATUS gensec_spnego_wrap_packets(struct gensec_security *gensec_security, 
209                                            TALLOC_CTX *mem_ctx, 
210                                            const DATA_BLOB *in, 
211                                            DATA_BLOB *out,
212                                            size_t *len_processed) 
213 {
214         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
215
216         if (spnego_state->state_position != SPNEGO_DONE 
217             && spnego_state->state_position != SPNEGO_FALLBACK) {
218                 DEBUG(1, ("gensec_spnego_wrap: wrong state for wrap\n"));
219                 return NT_STATUS_INVALID_PARAMETER;
220         }
221         
222         return gensec_wrap_packets(spnego_state->sub_sec_security, 
223                                    mem_ctx, in, out,
224                                    len_processed);
225 }
226
227 static NTSTATUS gensec_spnego_packet_full_request(struct gensec_security *gensec_security, 
228                                                 DATA_BLOB blob, size_t *size)
229 {
230         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
231
232         if (spnego_state->state_position != SPNEGO_DONE 
233             && spnego_state->state_position != SPNEGO_FALLBACK) {
234                 DEBUG(1, ("gensec_spnego_unwrap: wrong state for unwrap\n"));
235                 return NT_STATUS_INVALID_PARAMETER;
236         }
237         
238         return gensec_packet_full_request(spnego_state->sub_sec_security, 
239                                           blob, size);
240 }
241
242 static NTSTATUS gensec_spnego_unwrap_packets(struct gensec_security *gensec_security, 
243                                              TALLOC_CTX *mem_ctx, 
244                                              const DATA_BLOB *in, 
245                                              DATA_BLOB *out,
246                                              size_t *len_processed) 
247 {
248         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
249
250         if (spnego_state->state_position != SPNEGO_DONE 
251             && spnego_state->state_position != SPNEGO_FALLBACK) {
252                 DEBUG(1, ("gensec_spnego_unwrap: wrong state for unwrap\n"));
253                 return NT_STATUS_INVALID_PARAMETER;
254         }
255         
256         return gensec_unwrap_packets(spnego_state->sub_sec_security, 
257                                      mem_ctx, in, out,
258                                      len_processed);
259 }
260
261 static size_t gensec_spnego_sig_size(struct gensec_security *gensec_security, size_t data_size) 
262 {
263         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
264
265         if (spnego_state->state_position != SPNEGO_DONE 
266             && spnego_state->state_position != SPNEGO_FALLBACK) {
267                 return 0;
268         }
269         
270         return gensec_sig_size(spnego_state->sub_sec_security, data_size);
271 }
272
273 static size_t gensec_spnego_max_input_size(struct gensec_security *gensec_security) 
274 {
275         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
276
277         if (spnego_state->state_position != SPNEGO_DONE 
278             && spnego_state->state_position != SPNEGO_FALLBACK) {
279                 return 0;
280         }
281         
282         return gensec_max_input_size(spnego_state->sub_sec_security);
283 }
284
285 static size_t gensec_spnego_max_wrapped_size(struct gensec_security *gensec_security) 
286 {
287         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
288
289         if (spnego_state->state_position != SPNEGO_DONE 
290             && spnego_state->state_position != SPNEGO_FALLBACK) {
291                 return 0;
292         }
293         
294         return gensec_max_wrapped_size(spnego_state->sub_sec_security);
295 }
296
297 static NTSTATUS gensec_spnego_session_key(struct gensec_security *gensec_security, 
298                                           DATA_BLOB *session_key)
299 {
300         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
301         if (!spnego_state->sub_sec_security) {
302                 return NT_STATUS_INVALID_PARAMETER;
303         }
304         
305         return gensec_session_key(spnego_state->sub_sec_security, 
306                                   session_key);
307 }
308
309 static NTSTATUS gensec_spnego_session_info(struct gensec_security *gensec_security,
310                                                                       struct auth_session_info **session_info) 
311 {
312         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
313         if (!spnego_state->sub_sec_security) {
314                 return NT_STATUS_INVALID_PARAMETER;
315         }
316         
317         return gensec_session_info(spnego_state->sub_sec_security, 
318                                    session_info);
319 }
320
321 /** Fallback to another GENSEC mechanism, based on magic strings 
322  *
323  * This is the 'fallback' case, where we don't get SPNEGO, and have to
324  * try all the other options (and hope they all have a magic string
325  * they check)
326 */
327
328 static NTSTATUS gensec_spnego_server_try_fallback(struct gensec_security *gensec_security, 
329                                                   struct spnego_state *spnego_state,
330                                                   TALLOC_CTX *out_mem_ctx, 
331                                                   const DATA_BLOB in, DATA_BLOB *out) 
332 {
333         int i,j;
334         struct gensec_security_ops **all_ops
335                 = gensec_security_mechs(gensec_security, out_mem_ctx);
336         for (i=0; all_ops[i]; i++) {
337                 bool is_spnego;
338                 NTSTATUS nt_status;
339                 if (!all_ops[i]->oid) {
340                         continue;
341                 }
342
343                 is_spnego = false;
344                 for (j=0; all_ops[i]->oid[j]; j++) {
345                         if (strcasecmp(GENSEC_OID_SPNEGO,all_ops[i]->oid[j]) == 0) {
346                                 is_spnego = true;
347                         }
348                 }
349                 if (is_spnego) {
350                         continue;
351                 }
352
353                 if (!all_ops[i]->magic) {
354                         continue;
355                 }
356
357                 nt_status = all_ops[i]->magic(gensec_security, &in);
358                 if (!NT_STATUS_IS_OK(nt_status)) {
359                         continue;
360                 }
361
362                 spnego_state->state_position = SPNEGO_FALLBACK;
363
364                 nt_status = gensec_subcontext_start(spnego_state, 
365                                                     gensec_security, 
366                                                     &spnego_state->sub_sec_security);
367
368                 if (!NT_STATUS_IS_OK(nt_status)) {
369                         return nt_status;
370                 }
371                 /* select the sub context */
372                 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
373                                                      all_ops[i]);
374                 if (!NT_STATUS_IS_OK(nt_status)) {
375                         return nt_status;
376                 }
377                 nt_status = gensec_update(spnego_state->sub_sec_security,
378                                           out_mem_ctx, in, out);
379                 return nt_status;
380         }
381         DEBUG(1, ("Failed to parse SPNEGO request\n"));
382         return NT_STATUS_INVALID_PARAMETER;
383         
384 }
385
386 /* 
387    Parse the netTokenInit, either from the client, to the server, or
388    from the server to the client.
389 */
390
391 static NTSTATUS gensec_spnego_parse_negTokenInit(struct gensec_security *gensec_security,
392                                                  struct spnego_state *spnego_state, 
393                                                  TALLOC_CTX *out_mem_ctx, 
394                                                  const char **mechType,
395                                                  const DATA_BLOB unwrapped_in, DATA_BLOB *unwrapped_out) 
396 {
397         int i;
398         NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER;
399         DATA_BLOB null_data_blob = data_blob(NULL,0);
400         bool ok;
401
402         const struct gensec_security_ops_wrapper *all_sec
403                 = gensec_security_by_oid_list(gensec_security, 
404                                               out_mem_ctx, 
405                                               mechType,
406                                               GENSEC_OID_SPNEGO);
407
408         ok = spnego_write_mech_types(spnego_state,
409                                      mechType,
410                                      &spnego_state->mech_types);
411         if (!ok) {
412                 DEBUG(1, ("SPNEGO: Failed to write mechTypes\n"));
413                 return NT_STATUS_NO_MEMORY;
414         }
415
416         if (spnego_state->state_position == SPNEGO_SERVER_START) {
417                 for (i=0; all_sec && all_sec[i].op; i++) {
418                         /* optomisitic token */
419                         if (strcmp(all_sec[i].oid, mechType[0]) == 0) {
420                                 nt_status = gensec_subcontext_start(spnego_state,
421                                                                     gensec_security,
422                                                                     &spnego_state->sub_sec_security);
423                                 if (!NT_STATUS_IS_OK(nt_status)) {
424                                         return nt_status;
425                                 }
426                                 /* select the sub context */
427                                 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
428                                                                      all_sec[i].op);
429                                 if (!NT_STATUS_IS_OK(nt_status)) {
430                                         talloc_free(spnego_state->sub_sec_security);
431                                         spnego_state->sub_sec_security = NULL;
432                                         break;
433                                 }
434                                 
435                                 nt_status = gensec_update(spnego_state->sub_sec_security,
436                                                           out_mem_ctx, 
437                                                           unwrapped_in,
438                                                           unwrapped_out);
439                                 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_PARAMETER) || 
440                                     NT_STATUS_EQUAL(nt_status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
441                                         /* Pretend we never started it (lets the first run find some incompatible demand) */
442                                         
443                                         DEBUG(1, ("SPNEGO(%s) NEG_TOKEN_INIT failed to parse contents: %s\n", 
444                                                   spnego_state->sub_sec_security->ops->name, nt_errstr(nt_status)));
445                                         talloc_free(spnego_state->sub_sec_security);
446                                         spnego_state->sub_sec_security = NULL;
447                                         break;
448                                 }
449
450                                 spnego_state->neg_oid = all_sec[i].oid;
451                                 break;
452                         }
453                 }
454         }
455         
456         /* Having tried any optomisitc token from the client (if we
457          * were the server), if we didn't get anywhere, walk our list
458          * in our preference order */
459         
460         if (!spnego_state->sub_sec_security) {
461                 for (i=0; all_sec && all_sec[i].op; i++) {
462                         nt_status = gensec_subcontext_start(spnego_state,
463                                                             gensec_security,
464                                                             &spnego_state->sub_sec_security);
465                         if (!NT_STATUS_IS_OK(nt_status)) {
466                                 return nt_status;
467                         }
468                         /* select the sub context */
469                         nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
470                                                              all_sec[i].op);
471                         if (!NT_STATUS_IS_OK(nt_status)) {
472                                 talloc_free(spnego_state->sub_sec_security);
473                                 spnego_state->sub_sec_security = NULL;
474                                 continue;
475                         }
476                         
477                         spnego_state->neg_oid = all_sec[i].oid;
478
479                         /* only get the helping start blob for the first OID */
480                         nt_status = gensec_update(spnego_state->sub_sec_security,
481                                                   out_mem_ctx, 
482                                                   null_data_blob, 
483                                                   unwrapped_out);
484
485                         /* it is likely that a NULL input token will
486                          * not be liked by most server mechs, but if
487                          * we are in the client, we want the first
488                          * update packet to be able to abort the use
489                          * of this mech */
490                         if (spnego_state->state_position != SPNEGO_SERVER_START) {
491                                 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_PARAMETER) || 
492                                     NT_STATUS_EQUAL(nt_status, NT_STATUS_CANT_ACCESS_DOMAIN_INFO)) {
493                                         /* Pretend we never started it (lets the first run find some incompatible demand) */
494                                         
495                                         DEBUG(1, ("SPNEGO(%s) NEG_TOKEN_INIT failed to parse: %s\n", 
496                                                   spnego_state->sub_sec_security->ops->name, nt_errstr(nt_status)));
497                                         talloc_free(spnego_state->sub_sec_security);
498                                         spnego_state->sub_sec_security = NULL;
499                                         continue;
500                                 }
501                         }
502
503                         break;
504                 }
505         }
506
507         if (spnego_state->sub_sec_security) {
508                 /* it is likely that a NULL input token will
509                  * not be liked by most server mechs, but this
510                  * does the right thing in the CIFS client.
511                  * just push us along the merry-go-round
512                  * again, and hope for better luck next
513                  * time */
514                 
515                 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_PARAMETER)) {
516                         *unwrapped_out = data_blob(NULL, 0);
517                         nt_status = NT_STATUS_MORE_PROCESSING_REQUIRED;
518                 }
519                 
520                 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_PARAMETER) 
521                     && !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED) 
522                     && !NT_STATUS_IS_OK(nt_status)) {
523                         DEBUG(1, ("SPNEGO(%s) NEG_TOKEN_INIT failed: %s\n", 
524                                   spnego_state->sub_sec_security->ops->name, nt_errstr(nt_status)));
525                         talloc_free(spnego_state->sub_sec_security);
526                         spnego_state->sub_sec_security = NULL;
527                         
528                         /* We started the mech correctly, and the
529                          * input from the other side was valid.
530                          * Return the error (say bad password, invalid
531                          * ticket) */
532                         return nt_status;
533                 }
534         
535                 
536                 return nt_status; /* OK, INVALID_PARAMETER ore MORE PROCESSING */
537         }
538
539         DEBUG(1, ("SPNEGO: Could not find a suitable mechtype in NEG_TOKEN_INIT\n"));
540         /* we could re-negotiate here, but it would only work
541          * if the client or server lied about what it could
542          * support the first time.  Lets keep this code to
543          * reality */
544
545         return nt_status;
546 }
547
548 /** create a negTokenInit 
549  *
550  * This is the same packet, no matter if the client or server sends it first, but it is always the first packet
551 */
552 static NTSTATUS gensec_spnego_create_negTokenInit(struct gensec_security *gensec_security, 
553                                                   struct spnego_state *spnego_state,
554                                                   TALLOC_CTX *out_mem_ctx, 
555                                                   const DATA_BLOB in, DATA_BLOB *out) 
556 {
557         int i;
558         NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER;
559         DATA_BLOB null_data_blob = data_blob(NULL,0);
560         const char **mechTypes = NULL;
561         DATA_BLOB unwrapped_out = data_blob(NULL, 0);
562         const struct gensec_security_ops_wrapper *all_sec;
563         const char *principal = NULL;
564
565         mechTypes = gensec_security_oids(gensec_security, 
566                                          out_mem_ctx, GENSEC_OID_SPNEGO);
567
568         all_sec = gensec_security_by_oid_list(gensec_security, 
569                                               out_mem_ctx, 
570                                               mechTypes,
571                                               GENSEC_OID_SPNEGO);
572         for (i=0; all_sec && all_sec[i].op; i++) {
573                 struct spnego_data spnego_out;
574                 const char **send_mech_types;
575                 bool ok;
576
577                 nt_status = gensec_subcontext_start(spnego_state,
578                                                     gensec_security,
579                                                     &spnego_state->sub_sec_security);
580                 if (!NT_STATUS_IS_OK(nt_status)) {
581                         return nt_status;
582                 }
583                 /* select the sub context */
584                 nt_status = gensec_start_mech_by_ops(spnego_state->sub_sec_security,
585                                                      all_sec[i].op);
586                 if (!NT_STATUS_IS_OK(nt_status)) {
587                         talloc_free(spnego_state->sub_sec_security);
588                         spnego_state->sub_sec_security = NULL;
589                         continue;
590                 }
591
592                 /* In the client, try and produce the first (optimistic) packet */
593                 if (spnego_state->state_position == SPNEGO_CLIENT_START) {
594                         nt_status = gensec_update(spnego_state->sub_sec_security,
595                                                   out_mem_ctx, 
596                                                   null_data_blob,
597                                                   &unwrapped_out);
598                         
599                         if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED) 
600                             && !NT_STATUS_IS_OK(nt_status)) {
601                                 DEBUG(1, ("SPNEGO(%s) creating NEG_TOKEN_INIT failed: %s\n", 
602                                           spnego_state->sub_sec_security->ops->name, nt_errstr(nt_status)));
603                                 talloc_free(spnego_state->sub_sec_security);
604                                 spnego_state->sub_sec_security = NULL;
605                                 /* Pretend we never started it (lets the first run find some incompatible demand) */
606                                 
607                                 continue;
608                         }
609                 }
610
611                 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
612
613                 send_mech_types = gensec_security_oids_from_ops_wrapped(out_mem_ctx,
614                                                                         &all_sec[i]);
615
616                 ok = spnego_write_mech_types(spnego_state,
617                                              send_mech_types,
618                                              &spnego_state->mech_types);
619                 if (!ok) {
620                         DEBUG(1, ("SPNEGO: Failed to write mechTypes\n"));
621                         return NT_STATUS_NO_MEMORY;
622                 }
623
624                 /* List the remaining mechs as options */
625                 spnego_out.negTokenInit.mechTypes = send_mech_types;
626                 spnego_out.negTokenInit.reqFlags = 0;
627                 
628                 if (spnego_state->state_position == SPNEGO_SERVER_START) {
629                         /* server credentials */
630                         struct cli_credentials *creds = gensec_get_credentials(gensec_security);
631                         if (creds) {
632                                 principal = cli_credentials_get_principal(creds, out_mem_ctx);
633                         }
634                 }
635                 if (principal) {
636                         spnego_out.negTokenInit.mechListMIC
637                                 = data_blob_string_const(principal);
638                 } else {
639                         spnego_out.negTokenInit.mechListMIC = null_data_blob;
640                 }
641
642                 spnego_out.negTokenInit.mechToken = unwrapped_out;
643                 
644                 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
645                         DEBUG(1, ("Failed to write NEG_TOKEN_INIT\n"));
646                                 return NT_STATUS_INVALID_PARAMETER;
647                 }
648                 
649                 /* set next state */
650                 spnego_state->neg_oid = all_sec[i].oid;
651                 
652                 if (NT_STATUS_IS_OK(nt_status)) {
653                         spnego_state->no_response_expected = true;
654                 }
655
656                 return NT_STATUS_MORE_PROCESSING_REQUIRED;
657         } 
658         talloc_free(spnego_state->sub_sec_security);
659         spnego_state->sub_sec_security = NULL;
660
661         DEBUG(1, ("Failed to setup SPNEGO negTokenInit request: %s\n", nt_errstr(nt_status)));
662         return NT_STATUS_INVALID_PARAMETER;
663 }
664
665
666 /** create a server negTokenTarg 
667  *
668  * This is the case, where the client is the first one who sends data
669 */
670
671 static NTSTATUS gensec_spnego_server_negTokenTarg(struct gensec_security *gensec_security, 
672                                                   struct spnego_state *spnego_state,
673                                                   TALLOC_CTX *out_mem_ctx, 
674                                                   NTSTATUS nt_status,
675                                                   const DATA_BLOB unwrapped_out,
676                                                   DATA_BLOB mech_list_mic,
677                                                   DATA_BLOB *out)
678 {
679         struct spnego_data spnego_out;
680         DATA_BLOB null_data_blob = data_blob(NULL, 0);
681
682         /* compose reply */
683         spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
684         spnego_out.negTokenTarg.responseToken = unwrapped_out;
685         spnego_out.negTokenTarg.mechListMIC = null_data_blob;
686         spnego_out.negTokenTarg.supportedMech = NULL;
687
688         if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {   
689                 spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
690                 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
691                 spnego_state->state_position = SPNEGO_SERVER_TARG;
692         } else if (NT_STATUS_IS_OK(nt_status)) {
693                 if (unwrapped_out.data) {
694                         spnego_out.negTokenTarg.supportedMech = spnego_state->neg_oid;
695                 }
696                 spnego_out.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
697                 spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
698                 spnego_state->state_position = SPNEGO_DONE;
699         } else {
700                 spnego_out.negTokenTarg.negResult = SPNEGO_REJECT;
701                 DEBUG(2, ("SPNEGO login failed: %s\n", nt_errstr(nt_status)));
702                 spnego_state->state_position = SPNEGO_DONE;
703         }
704
705         if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
706                 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
707                 return NT_STATUS_INVALID_PARAMETER;
708         }
709
710         spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
711
712         return nt_status;
713 }
714
715
716 static NTSTATUS gensec_spnego_update(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx, 
717                                      const DATA_BLOB in, DATA_BLOB *out) 
718 {
719         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
720         DATA_BLOB null_data_blob = data_blob(NULL, 0);
721         DATA_BLOB mech_list_mic = data_blob(NULL, 0);
722         DATA_BLOB unwrapped_out = data_blob(NULL, 0);
723         struct spnego_data spnego_out;
724         struct spnego_data spnego;
725
726         ssize_t len;
727
728         *out = data_blob(NULL, 0);
729
730         if (!out_mem_ctx) {
731                 out_mem_ctx = spnego_state;
732         }
733
734         /* and switch into the state machine */
735
736         switch (spnego_state->state_position) {
737         case SPNEGO_FALLBACK:
738                 return gensec_update(spnego_state->sub_sec_security,
739                                      out_mem_ctx, in, out);
740         case SPNEGO_SERVER_START:
741         {
742                 NTSTATUS nt_status;
743                 if (in.length) {
744
745                         len = spnego_read_data(gensec_security, in, &spnego);
746                         if (len == -1) {
747                                 return gensec_spnego_server_try_fallback(gensec_security, spnego_state, 
748                                                                          out_mem_ctx, in, out);
749                         }
750                         /* client sent NegTargetInit, we send NegTokenTarg */
751
752                         /* OK, so it's real SPNEGO, check the packet's the one we expect */
753                         if (spnego.type != spnego_state->expected_packet) {
754                                 DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n", spnego.type, 
755                                           spnego_state->expected_packet));
756                                 dump_data(1, in.data, in.length);
757                                 spnego_free_data(&spnego);
758                                 return NT_STATUS_INVALID_PARAMETER;
759                         }
760                         
761                         nt_status = gensec_spnego_parse_negTokenInit(gensec_security,
762                                                                      spnego_state,
763                                                                      out_mem_ctx, 
764                                                                      spnego.negTokenInit.mechTypes,
765                                                                      spnego.negTokenInit.mechToken, 
766                                                                      &unwrapped_out);
767                         
768                         nt_status = gensec_spnego_server_negTokenTarg(gensec_security,
769                                                                       spnego_state,
770                                                                       out_mem_ctx,
771                                                                       nt_status,
772                                                                       unwrapped_out,
773                                                                       null_data_blob,
774                                                                       out);
775                         
776                         spnego_free_data(&spnego);
777                         
778                         return nt_status;
779                 } else {
780                         nt_status = gensec_spnego_create_negTokenInit(gensec_security, spnego_state, 
781                                                                       out_mem_ctx, in, out);
782                         spnego_state->state_position = SPNEGO_SERVER_START;
783                         spnego_state->expected_packet = SPNEGO_NEG_TOKEN_INIT;
784                         return nt_status;
785                 }
786         }
787         
788         case SPNEGO_CLIENT_START:
789         {
790                 /* The server offers a list of mechanisms */
791                 
792                 const char *my_mechs[] = {NULL, NULL};
793                 NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER;
794
795                 if (!in.length) {
796                         /* client to produce negTokenInit */
797                         nt_status = gensec_spnego_create_negTokenInit(gensec_security, spnego_state, 
798                                                                  out_mem_ctx, in, out);
799                         spnego_state->state_position = SPNEGO_CLIENT_TARG;
800                         spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
801                         return nt_status;
802                 }
803                 
804                 len = spnego_read_data(gensec_security, in, &spnego);
805                 
806                 if (len == -1) {
807                         DEBUG(1, ("Invalid SPNEGO request:\n"));
808                         dump_data(1, in.data, in.length);
809                         return NT_STATUS_INVALID_PARAMETER;
810                 }
811                 
812                 /* OK, so it's real SPNEGO, check the packet's the one we expect */
813                 if (spnego.type != spnego_state->expected_packet) {
814                         DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n", spnego.type, 
815                                   spnego_state->expected_packet));
816                         dump_data(1, in.data, in.length);
817                         spnego_free_data(&spnego);
818                         return NT_STATUS_INVALID_PARAMETER;
819                 }
820
821                 if (spnego.negTokenInit.targetPrincipal) {
822                         DEBUG(5, ("Server claims it's principal name is %s\n", spnego.negTokenInit.targetPrincipal));
823                         gensec_set_target_principal(gensec_security, spnego.negTokenInit.targetPrincipal);
824                 }
825
826                 nt_status = gensec_spnego_parse_negTokenInit(gensec_security,
827                                                              spnego_state,
828                                                              out_mem_ctx, 
829                                                              spnego.negTokenInit.mechTypes,
830                                                              spnego.negTokenInit.mechToken, 
831                                                              &unwrapped_out);
832
833                 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(nt_status)) {
834                         spnego_free_data(&spnego);
835                         return nt_status;
836                 }
837
838                 my_mechs[0] = spnego_state->neg_oid;
839                 /* compose reply */
840                 spnego_out.type = SPNEGO_NEG_TOKEN_INIT;
841                 spnego_out.negTokenInit.mechTypes = my_mechs;
842                 spnego_out.negTokenInit.reqFlags = 0;
843                 spnego_out.negTokenInit.mechListMIC = null_data_blob;
844                 spnego_out.negTokenInit.mechToken = unwrapped_out;
845                 
846                 if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
847                         DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_INIT\n"));
848                                 return NT_STATUS_INVALID_PARAMETER;
849                 }
850                 
851                 /* set next state */
852                 spnego_state->expected_packet = SPNEGO_NEG_TOKEN_TARG;
853                 spnego_state->state_position = SPNEGO_CLIENT_TARG;
854
855                 if (NT_STATUS_IS_OK(nt_status)) {
856                         spnego_state->no_response_expected = true;
857                 }
858                 
859                 spnego_free_data(&spnego);
860                 return NT_STATUS_MORE_PROCESSING_REQUIRED;
861         }
862         case SPNEGO_SERVER_TARG:
863         {
864                 NTSTATUS nt_status;
865                 bool new_spnego = false;
866
867                 if (!in.length) {
868                         return NT_STATUS_INVALID_PARAMETER;
869                 }
870                 
871                 len = spnego_read_data(gensec_security, in, &spnego);
872                 
873                 if (len == -1) {
874                         DEBUG(1, ("Invalid SPNEGO request:\n"));
875                         dump_data(1, in.data, in.length);
876                         return NT_STATUS_INVALID_PARAMETER;
877                 }
878                 
879                 /* OK, so it's real SPNEGO, check the packet's the one we expect */
880                 if (spnego.type != spnego_state->expected_packet) {
881                         DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n", spnego.type, 
882                                   spnego_state->expected_packet));
883                         dump_data(1, in.data, in.length);
884                         spnego_free_data(&spnego);
885                         return NT_STATUS_INVALID_PARAMETER;
886                 }
887
888                 if (!spnego_state->sub_sec_security) {
889                         DEBUG(1, ("SPNEGO: Did not setup a mech in NEG_TOKEN_INIT\n"));
890                         spnego_free_data(&spnego);
891                         return NT_STATUS_INVALID_PARAMETER;
892                 }
893
894                 nt_status = gensec_update(spnego_state->sub_sec_security,
895                                           out_mem_ctx, 
896                                           spnego.negTokenTarg.responseToken,
897                                           &unwrapped_out);
898                 if (NT_STATUS_IS_OK(nt_status) && spnego.negTokenTarg.mechListMIC.length > 0) {
899                         new_spnego = true;
900                         nt_status = gensec_check_packet(spnego_state->sub_sec_security,
901                                                         out_mem_ctx,
902                                                         spnego_state->mech_types.data,
903                                                         spnego_state->mech_types.length,
904                                                         spnego_state->mech_types.data,
905                                                         spnego_state->mech_types.length,
906                                                         &spnego.negTokenTarg.mechListMIC);
907                         if (!NT_STATUS_IS_OK(nt_status)) {
908                                 DEBUG(2,("GENSEC SPNEGO: failed to verify mechListMIC: %s\n",
909                                         nt_errstr(nt_status)));
910                         }
911                 }
912                 if (NT_STATUS_IS_OK(nt_status) && new_spnego) {
913                         nt_status = gensec_sign_packet(spnego_state->sub_sec_security,
914                                                        out_mem_ctx,
915                                                        spnego_state->mech_types.data,
916                                                        spnego_state->mech_types.length,
917                                                        spnego_state->mech_types.data,
918                                                        spnego_state->mech_types.length,
919                                                        &mech_list_mic);
920                         if (!NT_STATUS_IS_OK(nt_status)) {
921                                 DEBUG(2,("GENSEC SPNEGO: failed to sign mechListMIC: %s\n",
922                                         nt_errstr(nt_status)));
923                         }
924                 }
925
926                 nt_status = gensec_spnego_server_negTokenTarg(gensec_security,
927                                                               spnego_state,
928                                                               out_mem_ctx, 
929                                                               nt_status,
930                                                               unwrapped_out,
931                                                               mech_list_mic,
932                                                               out);
933                 
934                 spnego_free_data(&spnego);
935                 
936                 return nt_status;
937         }
938         case SPNEGO_CLIENT_TARG:
939         {
940                 NTSTATUS nt_status;
941                 if (!in.length) {
942                         return NT_STATUS_INVALID_PARAMETER;
943                 }
944                 
945                 len = spnego_read_data(gensec_security, in, &spnego);
946                 
947                 if (len == -1) {
948                         DEBUG(1, ("Invalid SPNEGO request:\n"));
949                         dump_data(1, in.data, in.length);
950                         return NT_STATUS_INVALID_PARAMETER;
951                 }
952                 
953                 /* OK, so it's real SPNEGO, check the packet's the one we expect */
954                 if (spnego.type != spnego_state->expected_packet) {
955                         DEBUG(1, ("Invalid SPNEGO request: %d, expected %d\n", spnego.type, 
956                                   spnego_state->expected_packet));
957                         dump_data(1, in.data, in.length);
958                         spnego_free_data(&spnego);
959                         return NT_STATUS_INVALID_PARAMETER;
960                 }
961         
962                 if (spnego.negTokenTarg.negResult == SPNEGO_REJECT) {
963                         spnego_free_data(&spnego);
964                         return NT_STATUS_ACCESS_DENIED;
965                 }
966
967                 /* Server didn't like our choice of mech, and chose something else */
968                 if ((spnego.negTokenTarg.negResult == SPNEGO_ACCEPT_INCOMPLETE) &&
969                     spnego.negTokenTarg.supportedMech &&
970                     strcmp(spnego.negTokenTarg.supportedMech, spnego_state->neg_oid) != 0) {
971                         DEBUG(3,("GENSEC SPNEGO: client preferred mech (%s) not accepted, server wants: %s\n",
972                                  gensec_get_name_by_oid(spnego.negTokenTarg.supportedMech), 
973                                  gensec_get_name_by_oid(spnego_state->neg_oid)));
974                         
975                         talloc_free(spnego_state->sub_sec_security);
976                         nt_status = gensec_subcontext_start(spnego_state,
977                                                             gensec_security,
978                                                             &spnego_state->sub_sec_security);
979                         if (!NT_STATUS_IS_OK(nt_status)) {
980                                 spnego_free_data(&spnego);
981                                 return nt_status;
982                         }
983                         /* select the sub context */
984                         nt_status = gensec_start_mech_by_oid(spnego_state->sub_sec_security,
985                                                              spnego.negTokenTarg.supportedMech);
986                         if (!NT_STATUS_IS_OK(nt_status)) {
987                                 spnego_free_data(&spnego);
988                                 return nt_status;
989                         }
990
991                         nt_status = gensec_update(spnego_state->sub_sec_security,
992                                                   out_mem_ctx, 
993                                                   spnego.negTokenTarg.responseToken,
994                                                   &unwrapped_out);
995                         spnego_state->neg_oid = talloc_strdup(spnego_state, spnego.negTokenTarg.supportedMech);
996                 } else if (spnego_state->no_response_expected) {
997                         if (spnego.negTokenTarg.negResult != SPNEGO_ACCEPT_COMPLETED) {
998                                 DEBUG(3,("GENSEC SPNEGO: client GENSEC accepted, but server rejected (bad password?)\n"));
999                                 nt_status = NT_STATUS_INVALID_PARAMETER;
1000                         } else if (spnego.negTokenTarg.responseToken.length) {
1001                                 DEBUG(2,("GENSEC SPNEGO: client GENSEC accepted, but server continued negotiation!\n"));
1002                                 nt_status = NT_STATUS_INVALID_PARAMETER;
1003                         } else {
1004                                 nt_status = NT_STATUS_OK;
1005                         }
1006                         if (NT_STATUS_IS_OK(nt_status) && spnego.negTokenTarg.mechListMIC.length > 0) {
1007                                 nt_status = gensec_check_packet(spnego_state->sub_sec_security,
1008                                                                 out_mem_ctx,
1009                                                                 spnego_state->mech_types.data,
1010                                                                 spnego_state->mech_types.length,
1011                                                                 spnego_state->mech_types.data,
1012                                                                 spnego_state->mech_types.length,
1013                                                                 &spnego.negTokenTarg.mechListMIC);
1014                                 if (!NT_STATUS_IS_OK(nt_status)) {
1015                                         DEBUG(2,("GENSEC SPNEGO: failed to verify mechListMIC: %s\n",
1016                                                 nt_errstr(nt_status)));
1017                                 }
1018                         }
1019                 } else {
1020                         bool new_spnego = false;
1021
1022                         nt_status = gensec_update(spnego_state->sub_sec_security,
1023                                                   out_mem_ctx, 
1024                                                   spnego.negTokenTarg.responseToken, 
1025                                                   &unwrapped_out);
1026
1027                         if (NT_STATUS_IS_OK(nt_status)) {
1028                                 new_spnego = gensec_have_feature(spnego_state->sub_sec_security,
1029                                                                  GENSEC_FEATURE_NEW_SPNEGO);
1030                         }
1031                         if (NT_STATUS_IS_OK(nt_status) && new_spnego) {
1032                                 nt_status = gensec_sign_packet(spnego_state->sub_sec_security,
1033                                                                out_mem_ctx,
1034                                                                spnego_state->mech_types.data,
1035                                                                spnego_state->mech_types.length,
1036                                                                spnego_state->mech_types.data,
1037                                                                spnego_state->mech_types.length,
1038                                                                &mech_list_mic);
1039                                 if (!NT_STATUS_IS_OK(nt_status)) {
1040                                         DEBUG(2,("GENSEC SPNEGO: failed to sign mechListMIC: %s\n",
1041                                                 nt_errstr(nt_status)));
1042                                 }
1043                         }
1044                         if (NT_STATUS_IS_OK(nt_status)) {
1045                                 spnego_state->no_response_expected = true;
1046                         }
1047                 } 
1048                 
1049                 spnego_free_data(&spnego);
1050
1051                 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)
1052                         && !NT_STATUS_IS_OK(nt_status)) {
1053                         DEBUG(1, ("SPNEGO(%s) login failed: %s\n", 
1054                                   spnego_state->sub_sec_security->ops->name, 
1055                                   nt_errstr(nt_status)));
1056                         return nt_status;
1057                 }
1058
1059                 if (unwrapped_out.length) {
1060                         /* compose reply */
1061                         spnego_out.type = SPNEGO_NEG_TOKEN_TARG;
1062                         spnego_out.negTokenTarg.negResult = SPNEGO_NONE_RESULT;
1063                         spnego_out.negTokenTarg.supportedMech = NULL;
1064                         spnego_out.negTokenTarg.responseToken = unwrapped_out;
1065                         spnego_out.negTokenTarg.mechListMIC = mech_list_mic;
1066                         
1067                         if (spnego_write_data(out_mem_ctx, out, &spnego_out) == -1) {
1068                                 DEBUG(1, ("Failed to write SPNEGO reply to NEG_TOKEN_TARG\n"));
1069                                 return NT_STATUS_INVALID_PARAMETER;
1070                         }
1071                 
1072                         spnego_state->state_position = SPNEGO_CLIENT_TARG;
1073                         nt_status = NT_STATUS_MORE_PROCESSING_REQUIRED;
1074                 } else {
1075
1076                         /* all done - server has accepted, and we agree */
1077                         *out = null_data_blob;
1078
1079                         if (spnego.negTokenTarg.negResult != SPNEGO_ACCEPT_COMPLETED) {
1080                                 /* unless of course it did not accept */
1081                                 DEBUG(1,("gensec_update ok but not accepted\n"));
1082                                 nt_status = NT_STATUS_INVALID_PARAMETER;
1083                         }
1084                 
1085                         spnego_state->state_position = SPNEGO_DONE;
1086                 }
1087
1088                 return nt_status;
1089         }
1090         case SPNEGO_DONE:
1091                 /* We should not be called after we are 'done' */
1092                 return NT_STATUS_INVALID_PARAMETER;
1093         }
1094         return NT_STATUS_INVALID_PARAMETER;
1095 }
1096
1097 static void gensec_spnego_want_feature(struct gensec_security *gensec_security,
1098                                        uint32_t feature)
1099 {
1100         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1101
1102         if (!spnego_state || !spnego_state->sub_sec_security) {
1103                 gensec_security->want_features |= feature;
1104                 return;
1105         }
1106
1107         gensec_want_feature(spnego_state->sub_sec_security,
1108                             feature);
1109 }
1110
1111 static bool gensec_spnego_have_feature(struct gensec_security *gensec_security,
1112                                        uint32_t feature) 
1113 {
1114         struct spnego_state *spnego_state = (struct spnego_state *)gensec_security->private_data;
1115         if (!spnego_state->sub_sec_security) {
1116                 return false;
1117         }
1118         
1119         return gensec_have_feature(spnego_state->sub_sec_security, 
1120                                    feature);
1121 }
1122
1123 static const char *gensec_spnego_oids[] = { 
1124         GENSEC_OID_SPNEGO,
1125         NULL 
1126 };
1127
1128 static const struct gensec_security_ops gensec_spnego_security_ops = {
1129         .name             = "spnego",
1130         .sasl_name        = "GSS-SPNEGO",
1131         .auth_type        = DCERPC_AUTH_TYPE_SPNEGO,
1132         .oid              = gensec_spnego_oids,
1133         .client_start     = gensec_spnego_client_start,
1134         .server_start     = gensec_spnego_server_start,
1135         .update           = gensec_spnego_update,
1136         .seal_packet      = gensec_spnego_seal_packet,
1137         .sign_packet      = gensec_spnego_sign_packet,
1138         .sig_size         = gensec_spnego_sig_size,
1139         .max_wrapped_size = gensec_spnego_max_wrapped_size,
1140         .max_input_size   = gensec_spnego_max_input_size,
1141         .check_packet     = gensec_spnego_check_packet,
1142         .unseal_packet    = gensec_spnego_unseal_packet,
1143         .packet_full_request = gensec_spnego_packet_full_request,
1144         .wrap             = gensec_spnego_wrap,
1145         .unwrap           = gensec_spnego_unwrap,
1146         .wrap_packets     = gensec_spnego_wrap_packets,
1147         .unwrap_packets   = gensec_spnego_unwrap_packets,
1148         .session_key      = gensec_spnego_session_key,
1149         .session_info     = gensec_spnego_session_info,
1150         .want_feature     = gensec_spnego_want_feature,
1151         .have_feature     = gensec_spnego_have_feature,
1152         .enabled          = true,
1153         .priority         = GENSEC_SPNEGO
1154 };
1155
1156 _PUBLIC_ NTSTATUS gensec_spnego_init(void)
1157 {
1158         NTSTATUS ret;
1159         ret = gensec_register(&gensec_spnego_security_ops);
1160         if (!NT_STATUS_IS_OK(ret)) {
1161                 DEBUG(0,("Failed to register '%s' gensec backend!\n",
1162                         gensec_spnego_security_ops.name));
1163                 return ret;
1164         }
1165
1166         return ret;
1167 }