gensec: Remove mem_ctx from calls that do not return memory
[nivanova/samba-autobuild/.git] / source4 / auth / ntlmssp / ntlmssp_sign.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Version 3.0
4  *  NTLMSSP Signing routines
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2001
6  *  Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003-2005
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #include "includes.h"
23 #include "auth/ntlmssp/ntlmssp.h"
24 #include "auth/gensec/gensec.h"
25 #include "../libcli/auth/ntlmssp_private.h"
26
27 NTSTATUS gensec_ntlmssp_sign_packet(struct gensec_security *gensec_security,
28                                     TALLOC_CTX *sig_mem_ctx,
29                                     const uint8_t *data, size_t length,
30                                     const uint8_t *whole_pdu, size_t pdu_length,
31                                     DATA_BLOB *sig)
32 {
33         struct gensec_ntlmssp_context *gensec_ntlmssp =
34                 talloc_get_type_abort(gensec_security->private_data,
35                                       struct gensec_ntlmssp_context);
36         NTSTATUS nt_status;
37
38         nt_status = ntlmssp_sign_packet(gensec_ntlmssp->ntlmssp_state,
39                                         sig_mem_ctx,
40                                         data, length,
41                                         whole_pdu, pdu_length,
42                                         sig);
43
44         return nt_status;
45 }
46
47 NTSTATUS gensec_ntlmssp_check_packet(struct gensec_security *gensec_security,
48                                      const uint8_t *data, size_t length,
49                                      const uint8_t *whole_pdu, size_t pdu_length,
50                                      const DATA_BLOB *sig)
51 {
52         struct gensec_ntlmssp_context *gensec_ntlmssp =
53                 talloc_get_type_abort(gensec_security->private_data,
54                                       struct gensec_ntlmssp_context);
55         NTSTATUS nt_status;
56
57         nt_status = ntlmssp_check_packet(gensec_ntlmssp->ntlmssp_state,
58                                          data, length,
59                                          whole_pdu, pdu_length,
60                                          sig);
61
62         return nt_status;
63 }
64
65 NTSTATUS gensec_ntlmssp_seal_packet(struct gensec_security *gensec_security,
66                                     TALLOC_CTX *sig_mem_ctx,
67                                     uint8_t *data, size_t length,
68                                     const uint8_t *whole_pdu, size_t pdu_length,
69                                     DATA_BLOB *sig)
70 {
71         struct gensec_ntlmssp_context *gensec_ntlmssp =
72                 talloc_get_type_abort(gensec_security->private_data,
73                                       struct gensec_ntlmssp_context);
74         NTSTATUS nt_status;
75
76         nt_status = ntlmssp_seal_packet(gensec_ntlmssp->ntlmssp_state,
77                                         sig_mem_ctx,
78                                         data, length,
79                                         whole_pdu, pdu_length,
80                                         sig);
81
82         return nt_status;
83 }
84
85 /*
86   wrappers for the ntlmssp_*() functions
87 */
88 NTSTATUS gensec_ntlmssp_unseal_packet(struct gensec_security *gensec_security,
89                                       uint8_t *data, size_t length,
90                                       const uint8_t *whole_pdu, size_t pdu_length,
91                                       const DATA_BLOB *sig)
92 {
93         struct gensec_ntlmssp_context *gensec_ntlmssp =
94                 talloc_get_type_abort(gensec_security->private_data,
95                                       struct gensec_ntlmssp_context);
96         NTSTATUS nt_status;
97
98         nt_status = ntlmssp_unseal_packet(gensec_ntlmssp->ntlmssp_state,
99                                           data, length,
100                                           whole_pdu, pdu_length,
101                                           sig);
102
103         return nt_status;
104 }
105
106 size_t gensec_ntlmssp_sig_size(struct gensec_security *gensec_security, size_t data_size) 
107 {
108         return NTLMSSP_SIG_SIZE;
109 }
110
111 NTSTATUS gensec_ntlmssp_wrap(struct gensec_security *gensec_security, 
112                              TALLOC_CTX *out_mem_ctx,
113                              const DATA_BLOB *in, 
114                              DATA_BLOB *out)
115 {
116         struct gensec_ntlmssp_context *gensec_ntlmssp =
117                 talloc_get_type_abort(gensec_security->private_data,
118                                       struct gensec_ntlmssp_context);
119
120         return ntlmssp_wrap(gensec_ntlmssp->ntlmssp_state,
121                             out_mem_ctx,
122                             in, out);
123 }
124
125
126 NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security, 
127                                TALLOC_CTX *out_mem_ctx,
128                                const DATA_BLOB *in, 
129                                DATA_BLOB *out)
130 {
131         struct gensec_ntlmssp_context *gensec_ntlmssp =
132                 talloc_get_type_abort(gensec_security->private_data,
133                                       struct gensec_ntlmssp_context);
134
135         return ntlmssp_unwrap(gensec_ntlmssp->ntlmssp_state,
136                               out_mem_ctx,
137                               in, out);
138 }