r22013: Move to SSPI framing (sig first in NTLM).
[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         asprintf(&host_princ_s, "%s@%s", service, name);
107         if (host_princ_s == NULL) {
108                 return NT_STATUS_NO_MEMORY;
109         }
110
111         input_name.value = host_princ_s;
112         input_name.length = strlen(host_princ_s) + 1;
113
114         ret = gss_import_name(&min,
115                                 &input_name,
116                                 GSS_C_NT_HOSTBASED_SERVICE,
117                                 &srv_name);
118
119         if (ret != GSS_S_COMPLETE) {
120                 SAFE_FREE(host_princ_s);
121                 return map_nt_error_from_gss(ret, min);
122         }
123
124         ret = gss_acquire_cred(&min,
125                                 &srv_name,
126                                 GSS_C_INDEFINITE,
127                                 GSS_C_NULL_OID_SET,
128                                 cred_type,
129                                 p_srv_cred,
130                                 NULL,
131                                 NULL);
132
133         if (ret != GSS_S_COMPLETE) {
134                 status = map_nt_error_from_gss(ret, min);
135         }
136
137         SAFE_FREE(host_princ_s);
138         gss_release_name(&min, &srv_name);
139         return status;
140 }
141
142 /******************************************************************************
143  Create a gss state.
144  Try and get the cifs/server@realm principal first, then fall back to
145  host/server@realm.
146 ******************************************************************************/
147
148 static NTSTATUS make_auth_gss(struct smb_srv_trans_enc_ctx *ec)
149 {
150         NTSTATUS status;
151         gss_cred_id_t srv_cred;
152         fstring fqdn;
153
154         name_to_fqdn(fqdn, global_myname());
155         strlower_m(fqdn);
156
157         status = get_srv_gss_creds("cifs", fqdn, GSS_C_ACCEPT, &srv_cred);
158         if (!NT_STATUS_IS_OK(status)) {
159                 status = get_srv_gss_creds("host", fqdn, GSS_C_ACCEPT, &srv_cred);
160                 if (!NT_STATUS_IS_OK(status)) {
161                         return nt_status_squash(status);
162                 }
163         }
164
165         ec->es->s.gss_state = SMB_MALLOC_P(struct smb_tran_enc_state_gss);
166         if (!ec->es->s.gss_state) {
167                 OM_uint32 min;
168                 gss_release_cred(&min, &srv_cred);
169                 return NT_STATUS_NO_MEMORY;
170         }
171         ZERO_STRUCTP(ec->es->s.gss_state);
172         ec->es->s.gss_state->creds = srv_cred;
173
174         /* No context yet. */
175         ec->es->s.gss_state->gss_ctx = GSS_C_NO_CONTEXT;
176
177         return NT_STATUS_OK;
178 }
179 #endif
180
181 /******************************************************************************
182  Shutdown a server encryption context.
183 ******************************************************************************/
184
185 static void srv_free_encryption_context(struct smb_srv_trans_enc_ctx **pp_ec)
186 {
187         struct smb_srv_trans_enc_ctx *ec = *pp_ec;
188
189         if (!ec) {
190                 return;
191         }
192
193         if (ec->es) {
194                 switch (ec->es->smb_enc_type) {
195                         case SMB_TRANS_ENC_NTLM:
196                                 destroy_auth_ntlmssp(ec);
197                                 break;
198 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
199                         case SMB_TRANS_ENC_GSS:
200                                 break;
201 #endif
202                 }
203                 common_free_encryption_state(&ec->es);
204         }
205
206         SAFE_FREE(ec);
207         *pp_ec = NULL;
208 }
209
210 /******************************************************************************
211  Create a server encryption context.
212 ******************************************************************************/
213
214 static NTSTATUS make_srv_encryption_context(enum smb_trans_enc_type smb_enc_type, struct smb_srv_trans_enc_ctx **pp_ec)
215 {
216         struct smb_srv_trans_enc_ctx *ec;
217
218         *pp_ec = NULL;
219
220         ec = SMB_MALLOC_P(struct smb_srv_trans_enc_ctx);
221         if (!ec) {
222                 return NT_STATUS_NO_MEMORY;
223         }
224         ZERO_STRUCTP(partial_srv_trans_enc_ctx);
225         ec->es = SMB_MALLOC_P(struct smb_trans_enc_state);
226         if (!ec->es) {
227                 SAFE_FREE(ec);
228                 return NT_STATUS_NO_MEMORY;
229         }
230         ZERO_STRUCTP(ec->es);
231         ec->es->smb_enc_type = smb_enc_type;
232         switch (smb_enc_type) {
233                 case SMB_TRANS_ENC_NTLM:
234                         {
235                                 NTSTATUS status = make_auth_ntlmssp(ec);
236                                 if (!NT_STATUS_IS_OK(status)) {
237                                         srv_free_encryption_context(&ec);
238                                         return status;
239                                 }
240                         }
241                         break;
242
243 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
244                 case SMB_TRANS_ENC_GSS:
245                         /* Acquire our credentials by calling gss_acquire_cred here. */
246                         {
247                                 NTSTATUS status = make_auth_gss(ec);
248                                 if (!NT_STATUS_IS_OK(status)) {
249                                         srv_free_encryption_context(&ec);
250                                         return status;
251                                 }
252                         }
253                         break;
254 #endif
255                 default:
256                         srv_free_encryption_context(&ec);
257                         return NT_STATUS_INVALID_PARAMETER;
258         }
259         *pp_ec = ec;
260         return NT_STATUS_OK;
261 }
262
263 /******************************************************************************
264  Free an encryption-allocated buffer.
265 ******************************************************************************/
266
267 void srv_free_enc_buffer(char *buf)
268 {
269         /* We know this is an smb buffer, and we
270          * didn't malloc, only copy, for a keepalive,
271          * so ignore session keepalives. */
272
273         if(CVAL(buf,0) == SMBkeepalive) {
274                 return;
275         }
276
277         if (srv_trans_enc_ctx) {
278                 common_free_enc_buffer(srv_trans_enc_ctx->es, buf);
279         }
280 }
281
282 /******************************************************************************
283  Decrypt an incoming buffer.
284 ******************************************************************************/
285
286 NTSTATUS srv_decrypt_buffer(char *buf)
287 {
288         /* Ignore session keepalives. */
289         if(CVAL(buf,0) == SMBkeepalive) {
290                 return NT_STATUS_OK;
291         }
292
293         if (srv_trans_enc_ctx) {
294                 return common_decrypt_buffer(srv_trans_enc_ctx->es, buf);
295         }
296
297         return NT_STATUS_OK;
298 }
299
300 /******************************************************************************
301  Encrypt an outgoing buffer. Return the encrypted pointer in buf_out.
302 ******************************************************************************/
303
304 NTSTATUS srv_encrypt_buffer(char *buf, char **buf_out)
305 {
306         *buf_out = buf;
307
308         /* Ignore session keepalives. */
309         if(CVAL(buf,0) == SMBkeepalive) {
310                 return NT_STATUS_OK;
311         }
312
313         if (srv_trans_enc_ctx) {
314                 return common_encrypt_buffer(srv_trans_enc_ctx->es, buf, buf_out);
315         }
316         /* Not encrypting. */
317         return NT_STATUS_OK;
318 }
319
320 /******************************************************************************
321  Do the gss encryption negotiation. Parameters are in/out.
322  Until success we do everything on the partial enc ctx.
323 ******************************************************************************/
324
325 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
326 static NTSTATUS srv_enc_spnego_gss_negotiate(unsigned char **ppdata, size_t *p_data_size, DATA_BLOB secblob)
327 {
328         OM_uint32 ret;
329         OM_uint32 min;
330         OM_uint32 flags = 0;
331         gss_buffer_desc in_buf, out_buf;
332         struct smb_tran_enc_state_gss *gss_state;
333
334         if (!partial_srv_trans_enc_ctx) {
335                 NTSTATUS status = make_srv_encryption_context(SMB_TRANS_ENC_GSS, &partial_srv_trans_enc_ctx);
336                 if (!NT_STATUS_IS_OK(status)) {
337                         return status;
338                 }
339         }
340
341         gss_state = partial_srv_trans_enc_ctx->es->s.gss_state;
342
343         in_buf.value = secblob.data;
344         in_buf.length = secblob.length;
345
346         out_buf.value = NULL;
347         out_buf.length = 0;
348
349         ret = gss_accept_sec_context(&min,
350                                 &gss_state->gss_ctx,
351                                 gss_state->creds,
352                                 &in_buf,
353                                 GSS_C_NO_CHANNEL_BINDINGS,
354                                 NULL,
355                                 NULL,           /* Ignore oids. */
356                                 &out_buf,       /* To return. */
357                                 &flags,
358                                 NULL,           /* Ingore time. */
359                                 NULL);          /* Ignore delegated creds. */
360
361         if (ret != GSS_S_COMPLETE && ret != GSS_S_CONTINUE_NEEDED) {
362                 return gss_err_to_ntstatus(ret, min);
363         }
364
365         /* Ensure we've got sign+seal available. */
366         if (ret == GSS_S_COMPLETE) {
367                 if ((flags & (GSS_C_INTEG_FLAG|GSS_C_CONF_FLAG|GSS_C_REPLAY_FLAG|GSS_C_SEQUENCE_FLAG)) !=
368                                 (GSS_C_INTEG_FLAG|GSS_C_CONF_FLAG|GSS_C_REPLAY_FLAG|GSS_C_SEQUENCE_FLAG)) {
369                         DEBUG(0,("srv_enc_spnego_gss_negotiate: quality of service not good enough "
370                                 "for SMB sealing.\n"));
371                         gss_release_buffer(&min, &out_buf);
372                         return NT_STATUS_ACCESS_DENIED;
373                 }
374         }
375
376         SAFE_FREE(*ppdata);
377         *ppdata = memdup(out_buf.value, out_buf.length);
378         if (!*ppdata) {
379                 gss_release_buffer(&min, &out_buf);
380                 return NT_STATUS_NO_MEMORY;
381         }
382         *p_data_size = out_buf.length;
383         gss_release_buffer(&min, &out_buf);
384
385         if (ret != GSS_S_CONTINUE_NEEDED) {
386                 return NT_STATUS_MORE_PROCESSING_REQUIRED;
387         } else {
388                 return NT_STATUS_OK;
389         }
390 }
391 #endif
392
393 /******************************************************************************
394  Do the NTLM SPNEGO (or raw) encryption negotiation. Parameters are in/out.
395  Until success we do everything on the partial enc ctx.
396 ******************************************************************************/
397
398 static NTSTATUS srv_enc_ntlm_negotiate(unsigned char **ppdata, size_t *p_data_size, DATA_BLOB secblob, BOOL spnego_wrap)
399 {
400         NTSTATUS status;
401         DATA_BLOB chal = data_blob(NULL, 0);
402         DATA_BLOB response = data_blob(NULL, 0);
403
404         status = make_srv_encryption_context(SMB_TRANS_ENC_NTLM, &partial_srv_trans_enc_ctx);
405         if (!NT_STATUS_IS_OK(status)) {
406                 return status;
407         }
408
409         status = auth_ntlmssp_update(partial_srv_trans_enc_ctx->auth_ntlmssp_state, secblob, &chal);
410
411         /* status here should be NT_STATUS_MORE_PROCESSING_REQUIRED
412          * for success ... */
413
414         if (spnego_wrap) {
415                 response = spnego_gen_auth_response(&chal, status, OID_NTLMSSP);
416                 data_blob_free(&chal);
417         } else {
418                 /* Return the raw blob. */
419                 response = chal;
420         }
421
422         SAFE_FREE(*ppdata);
423         *ppdata = response.data;
424         *p_data_size = response.length;
425         return status;
426 }
427
428 /******************************************************************************
429  Do the SPNEGO encryption negotiation. Parameters are in/out.
430  Based off code in smbd/sesssionsetup.c
431  Until success we do everything on the partial enc ctx.
432 ******************************************************************************/
433
434 static NTSTATUS srv_enc_spnego_negotiate(connection_struct *conn,
435                                         unsigned char **ppdata,
436                                         size_t *p_data_size,
437                                         unsigned char **pparam,
438                                         size_t *p_param_size)
439 {
440         NTSTATUS status;
441         DATA_BLOB blob = data_blob(NULL,0);
442         DATA_BLOB secblob = data_blob(NULL, 0);
443         BOOL got_kerberos_mechanism = False;
444
445         blob = data_blob_const(*ppdata, *p_data_size);
446
447         status = parse_spnego_mechanisms(blob, &secblob, &got_kerberos_mechanism);
448         if (!NT_STATUS_IS_OK(status)) {
449                 return nt_status_squash(status);
450         }
451
452         /* We should have no partial context at this point. */
453
454         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
455
456 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5)
457         if (got_kerberos_mechanism && lp_use_kerberos_keytab() ) {
458                 status = srv_enc_spnego_gss_negotiate(ppdata, p_data_size, secblob);
459         } else 
460 #endif
461         {
462                 status = srv_enc_ntlm_negotiate(ppdata, p_data_size, secblob, True);
463         }
464
465         data_blob_free(&secblob);
466
467         if (!NT_STATUS_EQUAL(status,NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) {
468                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
469                 return nt_status_squash(status);
470         }
471
472         if (NT_STATUS_IS_OK(status)) {
473                 /* Return the context we're using for this encryption state. */
474                 *pparam = SMB_MALLOC(2);
475                 if (!*pparam) {
476                         return NT_STATUS_NO_MEMORY;
477                 }
478                 SSVAL(*pparam,0,partial_srv_trans_enc_ctx->es->enc_ctx_num);
479                 *p_param_size = 2;
480         }
481
482         return status;
483 }
484
485 /******************************************************************************
486  Complete a SPNEGO encryption negotiation. Parameters are in/out.
487  We only get this for a NTLM auth second stage.
488 ******************************************************************************/
489
490 static NTSTATUS srv_enc_spnego_ntlm_auth(connection_struct *conn,
491                                         unsigned char **ppdata,
492                                         size_t *p_data_size,
493                                         unsigned char **pparam,
494                                         size_t *p_param_size)
495 {
496         NTSTATUS status;
497         DATA_BLOB blob = data_blob(NULL,0);
498         DATA_BLOB auth = data_blob(NULL,0);
499         DATA_BLOB auth_reply = data_blob(NULL,0);
500         DATA_BLOB response = data_blob(NULL,0);
501         struct smb_srv_trans_enc_ctx *ec = partial_srv_trans_enc_ctx;
502
503         /* We must have a partial context here. */
504
505         if (!ec || !ec->es || ec->auth_ntlmssp_state == NULL || ec->es->smb_enc_type != SMB_TRANS_ENC_NTLM) {
506                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
507                 return NT_STATUS_INVALID_PARAMETER;
508         }
509
510         blob = data_blob_const(*ppdata, *p_data_size);
511         if (!spnego_parse_auth(blob, &auth)) {
512                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
513                 return NT_STATUS_INVALID_PARAMETER;
514         }
515
516         status = auth_ntlmssp_update(ec->auth_ntlmssp_state, auth, &auth_reply);
517         data_blob_free(&auth);
518
519         response = spnego_gen_auth_response(&auth_reply, status, OID_NTLMSSP);
520         data_blob_free(&auth_reply);
521
522         if (NT_STATUS_IS_OK(status)) {
523                 /* Return the context we're using for this encryption state. */
524                 *pparam = SMB_MALLOC(2);
525                 if (!*pparam) {
526                         return NT_STATUS_NO_MEMORY;
527                 }
528                 SSVAL(*pparam,0,ec->es->enc_ctx_num);
529                 *p_param_size = 2;
530         }
531
532         SAFE_FREE(*ppdata);
533         *ppdata = response.data;
534         *p_data_size = response.length;
535         return status;
536 }
537
538 /******************************************************************************
539  Raw NTLM encryption negotiation. Parameters are in/out.
540  This function does both steps.
541 ******************************************************************************/
542
543 static NTSTATUS srv_enc_raw_ntlm_auth(connection_struct *conn,
544                                         unsigned char **ppdata,
545                                         size_t *p_data_size,
546                                         unsigned char **pparam,
547                                         size_t *p_param_size)
548 {
549         NTSTATUS status;
550         DATA_BLOB blob = data_blob_const(*ppdata, *p_data_size);
551         DATA_BLOB response = data_blob(NULL,0);
552         struct smb_srv_trans_enc_ctx *ec;
553
554         if (!partial_srv_trans_enc_ctx) {
555                 /* This is the initial step. */
556                 status = srv_enc_ntlm_negotiate(ppdata, p_data_size, blob, False);
557                 if (!NT_STATUS_EQUAL(status,NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) {
558                         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
559                         return nt_status_squash(status);
560                 }
561                 return status;
562         }
563
564         ec = partial_srv_trans_enc_ctx;
565         if (!ec || !ec->es || ec->auth_ntlmssp_state == NULL || ec->es->smb_enc_type != SMB_TRANS_ENC_NTLM) {
566                 srv_free_encryption_context(&partial_srv_trans_enc_ctx);
567                 return NT_STATUS_INVALID_PARAMETER;
568         }
569
570         /* Second step. */
571         status = auth_ntlmssp_update(partial_srv_trans_enc_ctx->auth_ntlmssp_state, blob, &response);
572
573         if (NT_STATUS_IS_OK(status)) {
574                 /* Return the context we're using for this encryption state. */
575                 *pparam = SMB_MALLOC(2);
576                 if (!*pparam) {
577                         return NT_STATUS_NO_MEMORY;
578                 }
579                 SSVAL(*pparam,0,ec->es->enc_ctx_num);
580                 *p_param_size = 2;
581         }
582
583         /* Return the raw blob. */
584         SAFE_FREE(*ppdata);
585         *ppdata = response.data;
586         *p_data_size = response.length;
587         return status;
588 }
589
590 /******************************************************************************
591  Do the SPNEGO encryption negotiation. Parameters are in/out.
592 ******************************************************************************/
593
594 NTSTATUS srv_request_encryption_setup(connection_struct *conn,
595                                         unsigned char **ppdata,
596                                         size_t *p_data_size,
597                                         unsigned char **pparam,
598                                         size_t *p_param_size)
599 {
600         unsigned char *pdata = *ppdata;
601
602         SAFE_FREE(*pparam);
603         *p_param_size = 0;
604
605         if (*p_data_size < 1) {
606                 return NT_STATUS_INVALID_PARAMETER;
607         }
608
609         if (pdata[0] == ASN1_APPLICATION(0)) {
610                 /* its a negTokenTarg packet */
611                 return srv_enc_spnego_negotiate(conn, ppdata, p_data_size, pparam, p_param_size);
612         }
613
614         if (pdata[0] == ASN1_CONTEXT(1)) {
615                 /* It's an auth packet */
616                 return srv_enc_spnego_ntlm_auth(conn, ppdata, p_data_size, pparam, p_param_size);
617         }
618
619         /* Maybe it's a raw unwrapped auth ? */
620         if (*p_data_size < 7) {
621                 return NT_STATUS_INVALID_PARAMETER;
622         }
623
624         if (strncmp((char *)pdata, "NTLMSSP", 7) == 0) {
625                 return srv_enc_raw_ntlm_auth(conn, ppdata, p_data_size, pparam, p_param_size);
626         }
627
628         DEBUG(1,("srv_request_encryption_setup: Unknown packet\n"));
629
630         return NT_STATUS_LOGON_FAILURE;
631 }
632
633 /******************************************************************************
634  Negotiation was successful - turn on server-side encryption.
635 ******************************************************************************/
636
637 static NTSTATUS check_enc_good(struct smb_srv_trans_enc_ctx *ec)
638 {
639         if (!ec || !ec->es) {
640                 return NT_STATUS_LOGON_FAILURE;
641         }
642
643         if (ec->es->smb_enc_type == SMB_TRANS_ENC_NTLM) {
644                 if ((ec->es->s.ntlmssp_state->neg_flags & (NTLMSSP_NEGOTIATE_SIGN|NTLMSSP_NEGOTIATE_SEAL)) !=
645                                 (NTLMSSP_NEGOTIATE_SIGN|NTLMSSP_NEGOTIATE_SEAL)) {
646                         return NT_STATUS_INVALID_PARAMETER;
647                 }
648         }
649         /* Todo - check gssapi case. */
650
651         return NT_STATUS_OK;
652 }
653
654 /******************************************************************************
655  Negotiation was successful - turn on server-side encryption.
656 ******************************************************************************/
657
658 NTSTATUS srv_encryption_start(connection_struct *conn)
659 {
660         NTSTATUS status;
661
662         /* Check that we are really doing sign+seal. */
663         status = check_enc_good(partial_srv_trans_enc_ctx);
664         if (!NT_STATUS_IS_OK(status)) {
665                 return status;
666         }
667         /* Throw away the context we're using currently (if any). */
668         srv_free_encryption_context(&srv_trans_enc_ctx);
669
670         /* Steal the partial pointer. Deliberate shallow copy. */
671         srv_trans_enc_ctx = partial_srv_trans_enc_ctx;
672         srv_trans_enc_ctx->es->enc_on = True;
673
674         partial_srv_trans_enc_ctx = NULL;
675         return NT_STATUS_OK;
676 }
677
678 /******************************************************************************
679  Shutdown all server contexts.
680 ******************************************************************************/
681
682 void server_encryption_shutdown(void)
683 {
684         srv_free_encryption_context(&partial_srv_trans_enc_ctx);
685         srv_free_encryption_context(&srv_trans_enc_ctx);
686 }