r22327: Finish the gss-spnego part of the seal code. Now
[mat/samba.git] / source3 / smbd / seal.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB Transport encryption (sealing) code - server code.
4    Copyright (C) Jeremy Allison 2007.
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /******************************************************************************
24  Server side encryption.
25 ******************************************************************************/
26
27 /******************************************************************************
28  Global server state.
29 ******************************************************************************/
30
31 struct smb_srv_trans_enc_ctx {
32         struct smb_trans_enc_state *es;
33         AUTH_NTLMSSP_STATE *auth_ntlmssp_state; /* Must be kept in sync with pointer in ec->ntlmssp_state. */
34 };
35
36 static struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx;
37 static struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx;
38
39 /******************************************************************************
40  Is server encryption on ?
41 ******************************************************************************/
42
43 BOOL srv_encryption_on(void)
44 {
45         if (srv_trans_enc_ctx) {
46                 return common_encryption_on(srv_trans_enc_ctx->es);
47         }
48         return False;
49 }
50
51 /******************************************************************************
52  Create an auth_ntlmssp_state and ensure pointer copy is correct.
53 ******************************************************************************/
54
55 static NTSTATUS make_auth_ntlmssp(struct smb_srv_trans_enc_ctx *ec)
56 {
57         NTSTATUS status = auth_ntlmssp_start(&ec->auth_ntlmssp_state);
58         if (!NT_STATUS_IS_OK(status)) {
59                 return nt_status_squash(status);
60         }
61
62         /*
63          * We must remember to update the pointer copy for the common
64          * functions after any auth_ntlmssp_start/auth_ntlmssp_end.
65          */
66         ec->es->s.ntlmssp_state = ec->auth_ntlmssp_state->ntlmssp_state;
67         return status;
68 }
69
70 /******************************************************************************
71  Destroy an auth_ntlmssp_state and ensure pointer copy is correct.
72 ******************************************************************************/
73
74 static void destroy_auth_ntlmssp(struct smb_srv_trans_enc_ctx *ec)
75 {
76         /*
77          * We must remember to update the pointer copy for the common
78          * functions after any auth_ntlmssp_start/auth_ntlmssp_end.
79          */
80
81         if (ec->auth_ntlmssp_state) {
82                 auth_ntlmssp_end(&ec->auth_ntlmssp_state);
83                 /* The auth_ntlmssp_end killed this already. */
84                 ec->es->s.ntlmssp_state = NULL;
85         }
86 }
87
88 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
89
90 /******************************************************************************
91  Import a name.
92 ******************************************************************************/
93
94 static NTSTATUS get_srv_gss_creds(const char *service,
95                                 const char *name,
96                                 gss_cred_usage_t cred_type,
97                                 gss_cred_id_t *p_srv_cred)
98 {
99         OM_uint32 ret;
100         OM_uint32 min;
101         gss_name_t srv_name;
102         gss_buffer_desc input_name;
103         char *host_princ_s = NULL;
104         NTSTATUS status = NT_STATUS_OK;
105
106         gss_OID_desc nt_hostbased_service =
107         {10, CONST_DISCARD(char *,"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04")};
108
109         asprintf(&host_princ_s, "%s@%s", service, name);
110         if (host_princ_s == NULL) {
111                 return NT_STATUS_NO_MEMORY;
112         }
113
114         input_name.value = host_princ_s;
115         input_name.length = strlen(host_princ_s) + 1;
116
117         ret = gss_import_name(&min,
118                                 &input_name,
119                                 &nt_hostbased_service,
120                                 &srv_name);
121
122         if (ret != GSS_S_COMPLETE) {
123                 SAFE_FREE(host_princ_s);
124                 return map_nt_error_from_gss(ret, min);
125         }
126
127         ret = gss_acquire_cred(&min,
128                                 &srv_name,
129                                 GSS_C_INDEFINITE,
130                                 GSS_C_NULL_OID_SET,
131                                 cred_type,
132                                 p_srv_cred,
133                                 NULL,
134                                 NULL);
135
136         if (ret != GSS_S_COMPLETE) {
137                 status = map_nt_error_from_gss(ret, min);
138         }
139
140         SAFE_FREE(host_princ_s);
141         gss_release_name(&min, &srv_name);
142         return status;
143 }
144
145 /******************************************************************************
146  Create a gss state.
147  Try and get the cifs/server@realm principal first, then fall back to
148  host/server@realm.
149 ******************************************************************************/
150
151 static NTSTATUS make_auth_gss(struct smb_srv_trans_enc_ctx *ec)
152 {
153         NTSTATUS status;
154         gss_cred_id_t srv_cred;
155         fstring fqdn;
156
157         name_to_fqdn(fqdn, global_myname());
158         strlower_m(fqdn);
159
160         status = get_srv_gss_creds("cifs", fqdn, GSS_C_ACCEPT, &srv_cred);
161         if (!NT_STATUS_IS_OK(status)) {
162                 status = get_srv_gss_creds("host", fqdn, GSS_C_ACCEPT, &srv_cred);
163                 if (!NT_STATUS_IS_OK(status)) {
164                         return nt_status_squash(status);
165                 }
166         }
167
168         ec->es->s.gss_state = SMB_MALLOC_P(struct smb_tran_enc_state_gss);
169         if (!ec->es->s.gss_state) {
170                 OM_uint32 min;
171                 gss_release_cred(&min, &srv_cred);
172                 return NT_STATUS_NO_MEMORY;
173         }
174         ZERO_STRUCTP(ec->es->s.gss_state);
175         ec->es->s.gss_state->creds = srv_cred;
176
177         /* No context yet. */
178         ec->es->s.gss_state->gss_ctx = GSS_C_NO_CONTEXT;
179
180         return NT_STATUS_OK;
181 }
182 #endif
183
184 /******************************************************************************
185  Shutdown a server encryption context.
186 ******************************************************************************/
187
188 static void srv_free_encryption_context(struct smb_srv_trans_enc_ctx **pp_ec)
189 {
190         struct smb_srv_trans_enc_ctx *ec = *pp_ec;
191
192         if (!ec) {
193                 return;
194         }
195
196         if (ec->es) {
197                 switch (ec->es->smb_enc_type) {
198                         case SMB_TRANS_ENC_NTLM:
199                                 destroy_auth_ntlmssp(ec);
200                                 break;
201 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
202                         case SMB_TRANS_ENC_GSS:
203                                 break;
204 #endif
205                 }
206                 common_free_encryption_state(&ec->es);
207         }
208
209         SAFE_FREE(ec);
210         *pp_ec = NULL;
211 }
212
213 /******************************************************************************
214  Create a server encryption context.
215 ******************************************************************************/
216
217 static NTSTATUS make_srv_encryption_context(enum smb_trans_enc_type smb_enc_type, struct smb_srv_trans_enc_ctx **pp_ec)
218 {
219         struct smb_srv_trans_enc_ctx *ec;
220
221         *pp_ec = NULL;
222
223         ec = SMB_MALLOC_P(struct smb_srv_trans_enc_ctx);
224         if (!ec) {
225                 return NT_STATUS_NO_MEMORY;
226         }
227         ZERO_STRUCTP(partial_srv_trans_enc_ctx);
228         ec->es = SMB_MALLOC_P(struct smb_trans_enc_state);
229         if (!ec->es) {
230                 SAFE_FREE(ec);
231                 return NT_STATUS_NO_MEMORY;
232         }
233         ZERO_STRUCTP(ec->es);
234         ec->es->smb_enc_type = smb_enc_type;
235         switch (smb_enc_type) {
236                 case SMB_TRANS_ENC_NTLM:
237                         {
238                                 NTSTATUS status = make_auth_ntlmssp(ec);
239                                 if (!NT_STATUS_IS_OK(status)) {
240                                         srv_free_encryption_context(&ec);
241                                         return status;
242                                 }
243                         }
244                         break;
245
246 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
247                 case SMB_TRANS_ENC_GSS:
248                         /* Acquire our credentials by calling gss_acquire_cred here. */
249                         {
250                                 NTSTATUS status = make_auth_gss(ec);
251                                 if (!NT_STATUS_IS_OK(status)) {
252                                         srv_free_encryption_context(&ec);
253                                         return status;
254                                 }
255                         }
256                         break;
257 #endif
258                 default:
259                         srv_free_encryption_context(&ec);
260                         return NT_STATUS_INVALID_PARAMETER;
261         }
262         *pp_ec = ec;
263         return NT_STATUS_OK;
264 }
265
266 /******************************************************************************
267  Free an encryption-allocated buffer.
268 ******************************************************************************/
269
270 void srv_free_enc_buffer(char *buf)
271 {
272         /* We know this is an smb buffer, and we
273          * didn't malloc, only copy, for a keepalive,
274          * so ignore session keepalives. */
275
276         if(CVAL(buf,0) == SMBkeepalive) {
277                 return;
278         }
279
280         if (srv_trans_enc_ctx) {
281                 common_free_enc_buffer(srv_trans_enc_ctx->es, buf);
282         }
283 }
284
285 /******************************************************************************
286  Decrypt an incoming buffer.
287 ******************************************************************************/
288
289 NTSTATUS srv_decrypt_buffer(char *buf)
290 {
291         /* Ignore session keepalives. */
292         if(CVAL(buf,0) == SMBkeepalive) {
293                 return NT_STATUS_OK;
294         }
295
296         if (srv_trans_enc_ctx) {
297                 return common_decrypt_buffer(srv_trans_enc_ctx->es, buf);
298         }
299
300         return NT_STATUS_OK;
301 }
302
303 /******************************************************************************
304  Encrypt an outgoing buffer. Return the encrypted pointer in buf_out.
305 ******************************************************************************/
306
307 NTSTATUS srv_encrypt_buffer(char *buf, char **buf_out)
308 {
309         *buf_out = buf;
310
311         /* Ignore session keepalives. */
312         if(CVAL(buf,0) == SMBkeepalive) {
313                 return NT_STATUS_OK;
314         }
315
316         if (srv_trans_enc_ctx) {
317                 return common_encrypt_buffer(srv_trans_enc_ctx->es, buf, buf_out);
318         }
319         /* Not encrypting. */
320         return NT_STATUS_OK;
321 }
322
323 /******************************************************************************
324  Do the gss encryption negotiation. Parameters are in/out.
325  Until success we do everything on the partial enc ctx.
326 ******************************************************************************/
327
328 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
329 static NTSTATUS srv_enc_spnego_gss_negotiate(unsigned char **ppdata, size_t *p_data_size, DATA_BLOB secblob)
330 {
331         OM_uint32 ret;
332         OM_uint32 min;
333         OM_uint32 flags = 0;
334         gss_buffer_desc in_buf, out_buf;
335         struct smb_tran_enc_state_gss *gss_state;
336         DATA_BLOB auth_reply = data_blob(NULL,0);
337         DATA_BLOB response = data_blob(NULL,0);
338         NTSTATUS status;
339
340         if (!partial_srv_trans_enc_ctx) {
341                 status = make_srv_encryption_context(SMB_TRANS_ENC_GSS, &partial_srv_trans_enc_ctx);
342                 if (!NT_STATUS_IS_OK(status)) {
343                         return status;
344                 }
345         }
346
347         gss_state = partial_srv_trans_enc_ctx->es->s.gss_state;
348
349         in_buf.value = secblob.data;
350         in_buf.length = secblob.length;
351
352         out_buf.value = NULL;
353         out_buf.length = 0;
354
355         ret = gss_accept_sec_context(&min,
356                                 &gss_state->gss_ctx,
357                                 gss_state->creds,
358                                 &in_buf,
359                                 GSS_C_NO_CHANNEL_BINDINGS,
360                                 NULL,
361                                 NULL,           /* Ignore oids. */
362                                 &out_buf,       /* To return. */
363                                 &flags,
364                                 NULL,           /* Ingore time. */
365                                 NULL);          /* Ignore delegated creds. */
366
367         status = gss_err_to_ntstatus(ret, min);
368         if (ret != GSS_S_COMPLETE && ret != GSS_S_CONTINUE_NEEDED) {
369                 return status;
370         }
371
372         /* Ensure we've got sign+seal available. */
373         if (ret == GSS_S_COMPLETE) {
374                 if ((flags & (GSS_C_INTEG_FLAG|GSS_C_CONF_FLAG|GSS_C_REPLAY_FLAG|GSS_C_SEQUENCE_FLAG)) !=
375                                 (GSS_C_INTEG_FLAG|GSS_C_CONF_FLAG|GSS_C_REPLAY_FLAG|GSS_C_SEQUENCE_FLAG)) {
376                         DEBUG(0,("srv_enc_spnego_gss_negotiate: quality of service not good enough "
377                                 "for SMB sealing.\n"));
378                         gss_release_buffer(&min, &out_buf);
379                         return NT_STATUS_ACCESS_DENIED;
380                 }
381         }
382
383         auth_reply = data_blob(out_buf.value, out_buf.length);
384         gss_release_buffer(&min, &out_buf);
385
386         /* Wrap in SPNEGO. */
387         response = spnego_gen_auth_response(&auth_reply, status, OID_KERBEROS5);
388         data_blob_free(&auth_reply);
389
390         SAFE_FREE(*ppdata);
391         *ppdata = response.data;
392         *p_data_size = response.length;
393
394         return status;
395 }
396 #endif
397
398 /******************************************************************************
399  Do the NTLM SPNEGO (or raw) encryption negotiation. Parameters are in/out.
400  Until success we do everything on the partial enc ctx.
401 ******************************************************************************/
402
403 static NTSTATUS srv_enc_ntlm_negotiate(unsigned char **ppdata, size_t *p_data_size, DATA_BLOB secblob, BOOL spnego_wrap)
404 {
405         NTSTATUS status;
406         DATA_BLOB chal = data_blob(NULL, 0);
407         DATA_BLOB response = data_blob(NULL, 0);
408
409         status = make_srv_encryption_context(SMB_TRANS_ENC_NTLM, &partial_srv_trans_enc_ctx);
410         if (!NT_STATUS_IS_OK(status)) {
411                 return status;
412         }
413
414         status = auth_ntlmssp_update(partial_srv_trans_enc_ctx->auth_ntlmssp_state, secblob, &chal);
415
416         /* status here should be NT_STATUS_MORE_PROCESSING_REQUIRED
417          * for success ... */
418
419         if (spnego_wrap) {
420                 response = spnego_gen_auth_response(&chal, status, OID_NTLMSSP);
421                 data_blob_free(&chal);
422         } else {
423                 /* Return the raw blob. */
424                 response = chal;
425         }
426
427         SAFE_FREE(*ppdata);
428         *ppdata = response.data;
429         *p_data_size = response.length;
430         return status;
431 }
432
433 /******************************************************************************
434  Do the SPNEGO encryption negotiation. Parameters are in/out.
435  Based off code in smbd/sesssionsetup.c
436  Until success we do everything on the partial enc ctx.
437 ******************************************************************************/
438
439 static NTSTATUS srv_enc_spnego_negotiate(connection_struct *conn,
440                                         unsigned char **ppdata,
441                                         size_t *p_data_size,
442                                         unsigned char **pparam,
443                                         size_t *p_param_size)
444 {
445         NTSTATUS status;
446         DATA_BLOB blob = data_blob(NULL,0);
447         DATA_BLOB secblob = data_blob(NULL, 0);
448         BOOL got_kerberos_mechanism = False;
449
450         blob = data_blob_const(*ppdata, *p_data_size);
451
452         status = parse_spnego_mechanisms(blob, &secblob, &got_kerberos_mechanism);
453         if (!NT_STATUS_IS_OK(status)) {
454                 return nt_status_squash(status);
455         }
456
457         /* We should have no partial context at this point. */
458
459         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
460
461 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
462         if (got_kerberos_mechanism && lp_use_kerberos_keytab() ) {
463                 status = srv_enc_spnego_gss_negotiate(ppdata, p_data_size, secblob);
464         } else 
465 #endif
466         {
467                 status = srv_enc_ntlm_negotiate(ppdata, p_data_size, secblob, True);
468         }
469
470         data_blob_free(&secblob);
471
472         if (!NT_STATUS_EQUAL(status,NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) {
473                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
474                 return nt_status_squash(status);
475         }
476
477         if (NT_STATUS_IS_OK(status)) {
478                 /* Return the context we're using for this encryption state. */
479                 *pparam = SMB_MALLOC(2);
480                 if (!*pparam) {
481                         return NT_STATUS_NO_MEMORY;
482                 }
483                 SSVAL(*pparam,0,partial_srv_trans_enc_ctx->es->enc_ctx_num);
484                 *p_param_size = 2;
485         }
486
487         return status;
488 }
489
490 /******************************************************************************
491  Complete a SPNEGO encryption negotiation. Parameters are in/out.
492  We only get this for a NTLM auth second stage.
493 ******************************************************************************/
494
495 static NTSTATUS srv_enc_spnego_ntlm_auth(connection_struct *conn,
496                                         unsigned char **ppdata,
497                                         size_t *p_data_size,
498                                         unsigned char **pparam,
499                                         size_t *p_param_size)
500 {
501         NTSTATUS status;
502         DATA_BLOB blob = data_blob(NULL,0);
503         DATA_BLOB auth = data_blob(NULL,0);
504         DATA_BLOB auth_reply = data_blob(NULL,0);
505         DATA_BLOB response = data_blob(NULL,0);
506         struct smb_srv_trans_enc_ctx *ec = partial_srv_trans_enc_ctx;
507
508         /* We must have a partial context here. */
509
510         if (!ec || !ec->es || ec->auth_ntlmssp_state == NULL || ec->es->smb_enc_type != SMB_TRANS_ENC_NTLM) {
511                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
512                 return NT_STATUS_INVALID_PARAMETER;
513         }
514
515         blob = data_blob_const(*ppdata, *p_data_size);
516         if (!spnego_parse_auth(blob, &auth)) {
517                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
518                 return NT_STATUS_INVALID_PARAMETER;
519         }
520
521         status = auth_ntlmssp_update(ec->auth_ntlmssp_state, auth, &auth_reply);
522         data_blob_free(&auth);
523
524         response = spnego_gen_auth_response(&auth_reply, status, OID_NTLMSSP);
525         data_blob_free(&auth_reply);
526
527         if (NT_STATUS_IS_OK(status)) {
528                 /* Return the context we're using for this encryption state. */
529                 *pparam = SMB_MALLOC(2);
530                 if (!*pparam) {
531                         return NT_STATUS_NO_MEMORY;
532                 }
533                 SSVAL(*pparam,0,ec->es->enc_ctx_num);
534                 *p_param_size = 2;
535         }
536
537         SAFE_FREE(*ppdata);
538         *ppdata = response.data;
539         *p_data_size = response.length;
540         return status;
541 }
542
543 /******************************************************************************
544  Raw NTLM encryption negotiation. Parameters are in/out.
545  This function does both steps.
546 ******************************************************************************/
547
548 static NTSTATUS srv_enc_raw_ntlm_auth(connection_struct *conn,
549                                         unsigned char **ppdata,
550                                         size_t *p_data_size,
551                                         unsigned char **pparam,
552                                         size_t *p_param_size)
553 {
554         NTSTATUS status;
555         DATA_BLOB blob = data_blob_const(*ppdata, *p_data_size);
556         DATA_BLOB response = data_blob(NULL,0);
557         struct smb_srv_trans_enc_ctx *ec;
558
559         if (!partial_srv_trans_enc_ctx) {
560                 /* This is the initial step. */
561                 status = srv_enc_ntlm_negotiate(ppdata, p_data_size, blob, False);
562                 if (!NT_STATUS_EQUAL(status,NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) {
563                         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
564                         return nt_status_squash(status);
565                 }
566                 return status;
567         }
568
569         ec = partial_srv_trans_enc_ctx;
570         if (!ec || !ec->es || ec->auth_ntlmssp_state == NULL || ec->es->smb_enc_type != SMB_TRANS_ENC_NTLM) {
571                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
572                 return NT_STATUS_INVALID_PARAMETER;
573         }
574
575         /* Second step. */
576         status = auth_ntlmssp_update(partial_srv_trans_enc_ctx->auth_ntlmssp_state, blob, &response);
577
578         if (NT_STATUS_IS_OK(status)) {
579                 /* Return the context we're using for this encryption state. */
580                 *pparam = SMB_MALLOC(2);
581                 if (!*pparam) {
582                         return NT_STATUS_NO_MEMORY;
583                 }
584                 SSVAL(*pparam,0,ec->es->enc_ctx_num);
585                 *p_param_size = 2;
586         }
587
588         /* Return the raw blob. */
589         SAFE_FREE(*ppdata);
590         *ppdata = response.data;
591         *p_data_size = response.length;
592         return status;
593 }
594
595 /******************************************************************************
596  Do the SPNEGO encryption negotiation. Parameters are in/out.
597 ******************************************************************************/
598
599 NTSTATUS srv_request_encryption_setup(connection_struct *conn,
600                                         unsigned char **ppdata,
601                                         size_t *p_data_size,
602                                         unsigned char **pparam,
603                                         size_t *p_param_size)
604 {
605         unsigned char *pdata = *ppdata;
606
607         SAFE_FREE(*pparam);
608         *p_param_size = 0;
609
610         if (*p_data_size < 1) {
611                 return NT_STATUS_INVALID_PARAMETER;
612         }
613
614         if (pdata[0] == ASN1_APPLICATION(0)) {
615                 /* its a negTokenTarg packet */
616                 return srv_enc_spnego_negotiate(conn, ppdata, p_data_size, pparam, p_param_size);
617         }
618
619         if (pdata[0] == ASN1_CONTEXT(1)) {
620                 /* It's an auth packet */
621                 return srv_enc_spnego_ntlm_auth(conn, ppdata, p_data_size, pparam, p_param_size);
622         }
623
624         /* Maybe it's a raw unwrapped auth ? */
625         if (*p_data_size < 7) {
626                 return NT_STATUS_INVALID_PARAMETER;
627         }
628
629         if (strncmp((char *)pdata, "NTLMSSP", 7) == 0) {
630                 return srv_enc_raw_ntlm_auth(conn, ppdata, p_data_size, pparam, p_param_size);
631         }
632
633         DEBUG(1,("srv_request_encryption_setup: Unknown packet\n"));
634
635         return NT_STATUS_LOGON_FAILURE;
636 }
637
638 /******************************************************************************
639  Negotiation was successful - turn on server-side encryption.
640 ******************************************************************************/
641
642 static NTSTATUS check_enc_good(struct smb_srv_trans_enc_ctx *ec)
643 {
644         if (!ec || !ec->es) {
645                 return NT_STATUS_LOGON_FAILURE;
646         }
647
648         if (ec->es->smb_enc_type == SMB_TRANS_ENC_NTLM) {
649                 if ((ec->es->s.ntlmssp_state->neg_flags & (NTLMSSP_NEGOTIATE_SIGN|NTLMSSP_NEGOTIATE_SEAL)) !=
650                                 (NTLMSSP_NEGOTIATE_SIGN|NTLMSSP_NEGOTIATE_SEAL)) {
651                         return NT_STATUS_INVALID_PARAMETER;
652                 }
653         }
654         /* Todo - check gssapi case. */
655
656         return NT_STATUS_OK;
657 }
658
659 /******************************************************************************
660  Negotiation was successful - turn on server-side encryption.
661 ******************************************************************************/
662
663 NTSTATUS srv_encryption_start(connection_struct *conn)
664 {
665         NTSTATUS status;
666
667         /* Check that we are really doing sign+seal. */
668         status = check_enc_good(partial_srv_trans_enc_ctx);
669         if (!NT_STATUS_IS_OK(status)) {
670                 return status;
671         }
672         /* Throw away the context we're using currently (if any). */
673         srv_free_encryption_context(&srv_trans_enc_ctx);
674
675         /* Steal the partial pointer. Deliberate shallow copy. */
676         srv_trans_enc_ctx = partial_srv_trans_enc_ctx;
677         srv_trans_enc_ctx->es->enc_on = True;
678
679         partial_srv_trans_enc_ctx = NULL;
680         return NT_STATUS_OK;
681 }
682
683 /******************************************************************************
684  Shutdown all server contexts.
685 ******************************************************************************/
686
687 void server_encryption_shutdown(void)
688 {
689         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
690         srv_free_encryption_context(&srv_trans_enc_ctx);
691 }