s3-winbindd: add cm_connect_lsat().
[Samba/vl.git] / auth / ntlmssp / gensec_ntlmssp.c
blob9e1d8a839e82057eb22c9a45f2cf29eddf415d0f
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
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.
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.
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/>.
22 #include "includes.h"
23 #include "auth/ntlmssp/ntlmssp.h"
24 #include "auth/gensec/gensec.h"
25 #include "auth/ntlmssp/ntlmssp_private.h"
27 NTSTATUS gensec_ntlmssp_magic(struct gensec_security *gensec_security,
28 const DATA_BLOB *first_packet)
30 if (ntlmssp_blob_matches_magic(first_packet)) {
31 return NT_STATUS_OK;
32 } else {
33 return NT_STATUS_INVALID_PARAMETER;
37 /**
38 * Return the NTLMSSP master session key
40 * @param ntlmssp_state NTLMSSP State
43 NTSTATUS gensec_ntlmssp_session_key(struct gensec_security *gensec_security,
44 TALLOC_CTX *mem_ctx,
45 DATA_BLOB *session_key)
47 struct gensec_ntlmssp_context *gensec_ntlmssp =
48 talloc_get_type_abort(gensec_security->private_data,
49 struct gensec_ntlmssp_context);
50 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
52 if (ntlmssp_state->expected_state != NTLMSSP_DONE) {
53 return NT_STATUS_NO_USER_SESSION_KEY;
56 if (!ntlmssp_state->session_key.data) {
57 return NT_STATUS_NO_USER_SESSION_KEY;
59 *session_key = data_blob_talloc(mem_ctx, ntlmssp_state->session_key.data, ntlmssp_state->session_key.length);
60 if (!session_key->data) {
61 return NT_STATUS_NO_MEMORY;
64 return NT_STATUS_OK;
67 bool gensec_ntlmssp_have_feature(struct gensec_security *gensec_security,
68 uint32_t feature)
70 struct gensec_ntlmssp_context *gensec_ntlmssp =
71 talloc_get_type_abort(gensec_security->private_data,
72 struct gensec_ntlmssp_context);
73 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
75 if (feature & GENSEC_FEATURE_SIGN) {
76 if (!ntlmssp_state->session_key.length) {
77 return false;
79 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN) {
80 return true;
83 if (feature & GENSEC_FEATURE_SEAL) {
84 if (!ntlmssp_state->session_key.length) {
85 return false;
87 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL) {
88 return true;
91 if (feature & GENSEC_FEATURE_SESSION_KEY) {
92 if (ntlmssp_state->session_key.length) {
93 return true;
96 if (feature & GENSEC_FEATURE_DCE_STYLE) {
97 return true;
99 if (feature & GENSEC_FEATURE_ASYNC_REPLIES) {
100 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
101 return true;
104 return false;
107 NTSTATUS gensec_ntlmssp_start(struct gensec_security *gensec_security)
109 struct gensec_ntlmssp_context *gensec_ntlmssp;
111 gensec_ntlmssp = talloc_zero(gensec_security,
112 struct gensec_ntlmssp_context);
113 if (!gensec_ntlmssp) {
114 return NT_STATUS_NO_MEMORY;
117 gensec_security->private_data = gensec_ntlmssp;
118 return NT_STATUS_OK;
121 NTSTATUS gensec_ntlmssp_sign_packet(struct gensec_security *gensec_security,
122 TALLOC_CTX *sig_mem_ctx,
123 const uint8_t *data, size_t length,
124 const uint8_t *whole_pdu, size_t pdu_length,
125 DATA_BLOB *sig)
127 struct gensec_ntlmssp_context *gensec_ntlmssp =
128 talloc_get_type_abort(gensec_security->private_data,
129 struct gensec_ntlmssp_context);
130 NTSTATUS nt_status;
132 nt_status = ntlmssp_sign_packet(gensec_ntlmssp->ntlmssp_state,
133 sig_mem_ctx,
134 data, length,
135 whole_pdu, pdu_length,
136 sig);
138 return nt_status;
141 NTSTATUS gensec_ntlmssp_check_packet(struct gensec_security *gensec_security,
142 const uint8_t *data, size_t length,
143 const uint8_t *whole_pdu, size_t pdu_length,
144 const DATA_BLOB *sig)
146 struct gensec_ntlmssp_context *gensec_ntlmssp =
147 talloc_get_type_abort(gensec_security->private_data,
148 struct gensec_ntlmssp_context);
149 NTSTATUS nt_status;
151 nt_status = ntlmssp_check_packet(gensec_ntlmssp->ntlmssp_state,
152 data, length,
153 whole_pdu, pdu_length,
154 sig);
156 return nt_status;
159 NTSTATUS gensec_ntlmssp_seal_packet(struct gensec_security *gensec_security,
160 TALLOC_CTX *sig_mem_ctx,
161 uint8_t *data, size_t length,
162 const uint8_t *whole_pdu, size_t pdu_length,
163 DATA_BLOB *sig)
165 struct gensec_ntlmssp_context *gensec_ntlmssp =
166 talloc_get_type_abort(gensec_security->private_data,
167 struct gensec_ntlmssp_context);
168 NTSTATUS nt_status;
170 nt_status = ntlmssp_seal_packet(gensec_ntlmssp->ntlmssp_state,
171 sig_mem_ctx,
172 data, length,
173 whole_pdu, pdu_length,
174 sig);
176 return nt_status;
180 wrappers for the ntlmssp_*() functions
182 NTSTATUS gensec_ntlmssp_unseal_packet(struct gensec_security *gensec_security,
183 uint8_t *data, size_t length,
184 const uint8_t *whole_pdu, size_t pdu_length,
185 const DATA_BLOB *sig)
187 struct gensec_ntlmssp_context *gensec_ntlmssp =
188 talloc_get_type_abort(gensec_security->private_data,
189 struct gensec_ntlmssp_context);
190 NTSTATUS nt_status;
192 nt_status = ntlmssp_unseal_packet(gensec_ntlmssp->ntlmssp_state,
193 data, length,
194 whole_pdu, pdu_length,
195 sig);
197 return nt_status;
200 size_t gensec_ntlmssp_sig_size(struct gensec_security *gensec_security, size_t data_size)
202 return NTLMSSP_SIG_SIZE;
205 NTSTATUS gensec_ntlmssp_wrap(struct gensec_security *gensec_security,
206 TALLOC_CTX *out_mem_ctx,
207 const DATA_BLOB *in,
208 DATA_BLOB *out)
210 struct gensec_ntlmssp_context *gensec_ntlmssp =
211 talloc_get_type_abort(gensec_security->private_data,
212 struct gensec_ntlmssp_context);
214 return ntlmssp_wrap(gensec_ntlmssp->ntlmssp_state,
215 out_mem_ctx,
216 in, out);
220 NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security,
221 TALLOC_CTX *out_mem_ctx,
222 const DATA_BLOB *in,
223 DATA_BLOB *out)
225 struct gensec_ntlmssp_context *gensec_ntlmssp =
226 talloc_get_type_abort(gensec_security->private_data,
227 struct gensec_ntlmssp_context);
229 return ntlmssp_unwrap(gensec_ntlmssp->ntlmssp_state,
230 out_mem_ctx,
231 in, out);