s3-ntlmssp Add mem_ctx argument to auth_ntlmssp_get_session_key()
[nivanova/samba-autobuild/.git] / source3 / libsmb / ntlmssp_wrap.c
1 /*
2    NLTMSSP wrappers
3
4    Copyright (C) Andrew Tridgell      2001
5    Copyright (C) Andrew Bartlett 2001-2003
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "libcli/auth/ntlmssp.h"
23 #include "ntlmssp_wrap.h"
24
25 NTSTATUS auth_ntlmssp_sign_packet(struct auth_ntlmssp_state *ans,
26                                   TALLOC_CTX *sig_mem_ctx,
27                                   const uint8_t *data,
28                                   size_t length,
29                                   const uint8_t *whole_pdu,
30                                   size_t pdu_length,
31                                   DATA_BLOB *sig)
32 {
33         return ntlmssp_sign_packet(ans->ntlmssp_state,
34                                    sig_mem_ctx,
35                                    data, length,
36                                    whole_pdu, pdu_length,
37                                    sig);
38 }
39
40 NTSTATUS auth_ntlmssp_check_packet(struct auth_ntlmssp_state *ans,
41                                    const uint8_t *data,
42                                    size_t length,
43                                    const uint8_t *whole_pdu,
44                                    size_t pdu_length,
45                                    const DATA_BLOB *sig)
46 {
47         return ntlmssp_check_packet(ans->ntlmssp_state,
48                                     data, length,
49                                     whole_pdu, pdu_length,
50                                     sig);
51 }
52
53 NTSTATUS auth_ntlmssp_seal_packet(struct auth_ntlmssp_state *ans,
54                                   TALLOC_CTX *sig_mem_ctx,
55                                   uint8_t *data,
56                                   size_t length,
57                                   const uint8_t *whole_pdu,
58                                   size_t pdu_length,
59                                   DATA_BLOB *sig)
60 {
61         return ntlmssp_seal_packet(ans->ntlmssp_state,
62                                    sig_mem_ctx,
63                                    data, length,
64                                    whole_pdu, pdu_length,
65                                    sig);
66 }
67
68 NTSTATUS auth_ntlmssp_unseal_packet(struct auth_ntlmssp_state *ans,
69                                     uint8_t *data,
70                                     size_t length,
71                                     const uint8_t *whole_pdu,
72                                     size_t pdu_length,
73                                     const DATA_BLOB *sig)
74 {
75         return ntlmssp_unseal_packet(ans->ntlmssp_state,
76                                      data, length,
77                                      whole_pdu, pdu_length,
78                                      sig);
79 }
80
81 bool auth_ntlmssp_negotiated_sign(struct auth_ntlmssp_state *ans)
82 {
83         return ans->ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN;
84 }
85
86 bool auth_ntlmssp_negotiated_seal(struct auth_ntlmssp_state *ans)
87 {
88         return ans->ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL;
89 }
90
91 /* Needed for 'smb username' processing */
92 const char *auth_ntlmssp_get_username(struct auth_ntlmssp_state *ans)
93 {
94         return ans->ntlmssp_state->user;
95 }
96
97 const uint8_t *auth_ntlmssp_get_nt_hash(struct auth_ntlmssp_state *ans)
98 {
99         return ans->ntlmssp_state->nt_hash;
100 }
101
102 NTSTATUS auth_ntlmssp_set_username(struct auth_ntlmssp_state *ans,
103                                    const char *user)
104 {
105         return ntlmssp_set_username(ans->ntlmssp_state, user);
106 }
107
108 NTSTATUS auth_ntlmssp_set_domain(struct auth_ntlmssp_state *ans,
109                                  const char *domain)
110 {
111         return ntlmssp_set_domain(ans->ntlmssp_state, domain);
112 }
113
114 NTSTATUS auth_ntlmssp_set_password(struct auth_ntlmssp_state *ans,
115                                    const char *password)
116 {
117         return ntlmssp_set_password(ans->ntlmssp_state, password);
118 }
119
120 void auth_ntlmssp_and_flags(struct auth_ntlmssp_state *ans, uint32_t flags)
121 {
122         ans->ntlmssp_state->neg_flags &= flags;
123 }
124
125 void auth_ntlmssp_or_flags(struct auth_ntlmssp_state *ans, uint32_t flags)
126 {
127         ans->ntlmssp_state->neg_flags |= flags;
128 }
129
130 void auth_ntlmssp_want_feature(struct auth_ntlmssp_state *ans, uint32_t feature)
131 {
132         ntlmssp_want_feature(ans->ntlmssp_state, feature);
133 }
134
135 DATA_BLOB auth_ntlmssp_get_session_key(struct auth_ntlmssp_state *ans, TALLOC_CTX *mem_ctx)
136 {
137         return data_blob_talloc(mem_ctx, ans->ntlmssp_state->session_key.data, ans->ntlmssp_state->session_key.length);
138 }
139
140 NTSTATUS auth_ntlmssp_update(struct auth_ntlmssp_state *ans,
141                              const DATA_BLOB request, DATA_BLOB *reply)
142 {
143         return ntlmssp_update(ans->ntlmssp_state, request, reply);
144 }
145
146 NTSTATUS auth_ntlmssp_client_start(TALLOC_CTX *mem_ctx,
147                                    const char *netbios_name,
148                                    const char *netbios_domain,
149                                    bool use_ntlmv2,
150                                    struct auth_ntlmssp_state **_ans)
151 {
152         struct auth_ntlmssp_state *ans;
153         NTSTATUS status;
154
155         ans = talloc_zero(mem_ctx, struct auth_ntlmssp_state);
156
157         status = ntlmssp_client_start(ans,
158                                         netbios_name, netbios_domain,
159                                         use_ntlmv2, &ans->ntlmssp_state);
160         if (!NT_STATUS_IS_OK(status)) {
161                 return status;
162         }
163
164         *_ans = ans;
165         return NT_STATUS_OK;
166 }