s4-selftest: fix output of opened connections in torture_holdcon
[Samba/gebeck_regimport.git] / auth / ntlmssp / ntlmssp.h
blob54d3e53526a91aab035d76990eb269d416b4ed36
1 /*
2 Unix SMB/CIFS implementation.
3 SMB parameters and setup
4 Copyright (C) Andrew Tridgell 1992-1997
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6 Copyright (C) Paul Ashton 1997
7 Copyright (C) Andrew Bartlett 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "../librpc/gen_ndr/ntlmssp.h"
25 NTSTATUS gensec_ntlmssp_init(void);
27 struct auth_context;
28 struct auth_serversupplied_info;
29 struct tsocket_address;
30 struct auth_user_info_dc;
31 struct gensec_security;
32 struct ntlmssp_state;
34 struct gensec_ntlmssp_context {
35 /* used only by s3 server implementation */
36 struct auth_context *auth_context;
38 /* For GENSEC users */
39 struct gensec_security *gensec_security;
40 void *server_returned_info;
42 /* used by both client and server implementation */
43 struct ntlmssp_state *ntlmssp_state;
46 /* NTLMSSP mode */
47 enum ntlmssp_role
49 NTLMSSP_SERVER,
50 NTLMSSP_CLIENT
53 /* NTLMSSP message types */
54 enum ntlmssp_message_type
56 NTLMSSP_INITIAL = 0 /* samba internal state */,
57 NTLMSSP_NEGOTIATE = 1,
58 NTLMSSP_CHALLENGE = 2,
59 NTLMSSP_AUTH = 3,
60 NTLMSSP_UNKNOWN = 4,
61 NTLMSSP_DONE = 5 /* samba final state */
64 #define NTLMSSP_FEATURE_SESSION_KEY 0x00000001
65 #define NTLMSSP_FEATURE_SIGN 0x00000002
66 #define NTLMSSP_FEATURE_SEAL 0x00000004
67 #define NTLMSSP_FEATURE_CCACHE 0x00000008
69 union ntlmssp_crypt_state;
71 struct ntlmssp_state
73 enum ntlmssp_role role;
74 uint32_t expected_state;
76 bool unicode;
77 bool use_ntlmv2;
78 bool use_ccache;
79 bool use_nt_response; /* Set to 'False' to debug what happens when the NT response is omited */
80 bool allow_lm_key; /* The LM_KEY code is not very secure... */
82 const char *user;
83 const char *domain;
84 uint8_t *nt_hash;
85 uint8_t *lm_hash;
87 struct {
88 const char *netbios_name;
89 const char *netbios_domain;
90 } client;
92 struct {
93 bool is_standalone;
94 const char *netbios_name;
95 const char *netbios_domain;
96 const char *dns_name;
97 const char *dns_domain;
98 } server;
100 DATA_BLOB internal_chal; /* Random challenge as supplied to the client for NTLM authentication */
102 DATA_BLOB chal; /* Random challenge as input into the actual NTLM (or NTLM2) authentication */
103 DATA_BLOB lm_resp;
104 DATA_BLOB nt_resp;
105 DATA_BLOB session_key;
107 uint32_t neg_flags; /* the current state of negotiation with the NTLMSSP partner */
110 * Private data for the callback functions
112 void *callback_private;
115 * Callback to get the 'challenge' used for NTLM authentication.
117 * @param ntlmssp_state This structure
118 * @return 8 bytes of challenge data, determined by the server to be the challenge for NTLM authentication
121 NTSTATUS (*get_challenge)(const struct ntlmssp_state *ntlmssp_state,
122 uint8_t challenge[8]);
125 * Callback to find if the challenge used by NTLM authentication may be modified
127 * The NTLM2 authentication scheme modifies the effective challenge, but this is not compatiable with the
128 * current 'security=server' implementation..
130 * @param ntlmssp_state This structure
131 * @return Can the challenge be set to arbitary values?
134 bool (*may_set_challenge)(const struct ntlmssp_state *ntlmssp_state);
137 * Callback to set the 'challenge' used for NTLM authentication.
139 * The callback may use the void *auth_context to store state information, but the same value is always available
140 * from the DATA_BLOB chal on this structure.
142 * @param ntlmssp_state This structure
143 * @param challenge 8 bytes of data, agreed by the client and server to be the effective challenge for NTLM2 authentication
146 NTSTATUS (*set_challenge)(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge);
149 * Callback to check the user's password.
151 * The callback must reads the feilds of this structure for the information it needs on the user
152 * @param ntlmssp_state This structure
153 * @param mem_ctx Talloc context for LM and NT session key to be returned on
154 * @param nt_session_key If an NT session key is returned by the authentication process, return it here
155 * @param lm_session_key If an LM session key is returned by the authentication process, return it here
158 NTSTATUS (*check_password)(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
159 DATA_BLOB *nt_session_key, DATA_BLOB *lm_session_key);
161 union ntlmssp_crypt_state *crypt;
164 /* The following definitions come from libcli/auth/ntlmssp_sign.c */
166 NTSTATUS ntlmssp_sign_packet(struct ntlmssp_state *ntlmssp_state,
167 TALLOC_CTX *sig_mem_ctx,
168 const uint8_t *data, size_t length,
169 const uint8_t *whole_pdu, size_t pdu_length,
170 DATA_BLOB *sig);
171 NTSTATUS ntlmssp_check_packet(struct ntlmssp_state *ntlmssp_state,
172 const uint8_t *data, size_t length,
173 const uint8_t *whole_pdu, size_t pdu_length,
174 const DATA_BLOB *sig) ;
175 NTSTATUS ntlmssp_seal_packet(struct ntlmssp_state *ntlmssp_state,
176 TALLOC_CTX *sig_mem_ctx,
177 uint8_t *data, size_t length,
178 const uint8_t *whole_pdu, size_t pdu_length,
179 DATA_BLOB *sig);
180 NTSTATUS ntlmssp_unseal_packet(struct ntlmssp_state *ntlmssp_state,
181 uint8_t *data, size_t length,
182 const uint8_t *whole_pdu, size_t pdu_length,
183 const DATA_BLOB *sig);
184 NTSTATUS ntlmssp_wrap(struct ntlmssp_state *ntlmssp_state,
185 TALLOC_CTX *out_mem_ctx,
186 const DATA_BLOB *in,
187 DATA_BLOB *out);
188 NTSTATUS ntlmssp_unwrap(struct ntlmssp_state *ntlmssp_stae,
189 TALLOC_CTX *out_mem_ctx,
190 const DATA_BLOB *in,
191 DATA_BLOB *out);
192 NTSTATUS ntlmssp_sign_init(struct ntlmssp_state *ntlmssp_state);
194 bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob);
195 /* The following definitions come from ../source4/auth/ntlmssp/ntlmssp.c */
199 * Return the NTLMSSP master session key
201 * @param ntlmssp_state NTLMSSP State
203 NTSTATUS gensec_ntlmssp_magic(struct gensec_security *gensec_security,
204 const DATA_BLOB *first_packet);
205 bool gensec_ntlmssp_have_feature(struct gensec_security *gensec_security,
206 uint32_t feature);
207 NTSTATUS gensec_ntlmssp_session_key(struct gensec_security *gensec_security,
208 TALLOC_CTX *mem_ctx,
209 DATA_BLOB *session_key);
210 NTSTATUS gensec_ntlmssp_start(struct gensec_security *gensec_security);
212 /* The following definitions come from ../source4/auth/ntlmssp/ntlmssp_sign.c */
214 NTSTATUS gensec_ntlmssp_sign_packet(struct gensec_security *gensec_security,
215 TALLOC_CTX *sig_mem_ctx,
216 const uint8_t *data, size_t length,
217 const uint8_t *whole_pdu, size_t pdu_length,
218 DATA_BLOB *sig);
219 NTSTATUS gensec_ntlmssp_check_packet(struct gensec_security *gensec_security,
220 const uint8_t *data, size_t length,
221 const uint8_t *whole_pdu, size_t pdu_length,
222 const DATA_BLOB *sig);
223 NTSTATUS gensec_ntlmssp_seal_packet(struct gensec_security *gensec_security,
224 TALLOC_CTX *sig_mem_ctx,
225 uint8_t *data, size_t length,
226 const uint8_t *whole_pdu, size_t pdu_length,
227 DATA_BLOB *sig);
228 NTSTATUS gensec_ntlmssp_unseal_packet(struct gensec_security *gensec_security,
229 uint8_t *data, size_t length,
230 const uint8_t *whole_pdu, size_t pdu_length,
231 const DATA_BLOB *sig);
232 size_t gensec_ntlmssp_sig_size(struct gensec_security *gensec_security, size_t data_size) ;
233 NTSTATUS gensec_ntlmssp_wrap(struct gensec_security *gensec_security,
234 TALLOC_CTX *out_mem_ctx,
235 const DATA_BLOB *in,
236 DATA_BLOB *out);
237 NTSTATUS gensec_ntlmssp_unwrap(struct gensec_security *gensec_security,
238 TALLOC_CTX *out_mem_ctx,
239 const DATA_BLOB *in,
240 DATA_BLOB *out);