2 Unix SMB/Netbios implementation.
4 handle NLTMSSP, client server side parsing
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2005
8 Copyright (C) Stefan Metzmacher 2005
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "auth/auth.h"
27 #include "auth/ntlmssp/ntlmssp.h"
28 #include "lib/crypto/crypto.h"
32 * Set a username on an NTLMSSP context - ensures it is talloc()ed
36 static NTSTATUS ntlmssp_set_username(struct ntlmssp_state *ntlmssp_state, const char *user)
39 /* it should be at least "" */
40 DEBUG(1, ("NTLMSSP failed to set username - cannot accept NULL username\n"));
41 return NT_STATUS_INVALID_PARAMETER;
43 ntlmssp_state->user = talloc_strdup(ntlmssp_state, user);
44 if (!ntlmssp_state->user) {
45 return NT_STATUS_NO_MEMORY;
51 * Set a domain on an NTLMSSP context - ensures it is talloc()ed
54 static NTSTATUS ntlmssp_set_domain(struct ntlmssp_state *ntlmssp_state, const char *domain)
56 ntlmssp_state->domain = talloc_strdup(ntlmssp_state, domain);
57 if (!ntlmssp_state->domain) {
58 return NT_STATUS_NO_MEMORY;
64 * Set a workstation on an NTLMSSP context - ensures it is talloc()ed
67 static NTSTATUS ntlmssp_set_workstation(struct ntlmssp_state *ntlmssp_state, const char *workstation)
69 ntlmssp_state->workstation = talloc_strdup(ntlmssp_state, workstation);
70 if (!ntlmssp_state->workstation) {
71 return NT_STATUS_NO_MEMORY;
77 * Default challenge generation code.
81 static const uint8_t *get_challenge(const struct ntlmssp_state *ntlmssp_state)
83 uint8_t *chal = talloc_size(ntlmssp_state, 8);
84 generate_random_buffer(chal, 8);
90 * Default 'we can set the challenge to anything we like' implementation
94 static BOOL may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
100 * Default 'we can set the challenge to anything we like' implementation
102 * Does not actually do anything, as the value is always in the structure anyway.
106 static NTSTATUS set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
108 SMB_ASSERT(challenge->length == 8);
113 * Determine correct target name flags for reply, given server role
114 * and negotiated flags
116 * @param ntlmssp_state NTLMSSP State
117 * @param neg_flags The flags from the packet
118 * @param chal_flags The flags to be set in the reply packet
119 * @return The 'target name' string.
122 static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
123 uint32_t neg_flags, uint32_t *chal_flags)
125 if (neg_flags & NTLMSSP_REQUEST_TARGET) {
126 *chal_flags |= NTLMSSP_CHAL_TARGET_INFO;
127 *chal_flags |= NTLMSSP_REQUEST_TARGET;
128 if (ntlmssp_state->server_role == ROLE_STANDALONE) {
129 *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
130 return ntlmssp_state->server_name;
132 *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
133 return ntlmssp_state->get_domain();
141 * Next state function for the Negotiate packet
143 * @param ntlmssp_state NTLMSSP State
144 * @param out_mem_ctx The TALLOC_CTX for *out to be allocated on
145 * @param in The request, as a DATA_BLOB
146 * @param out The reply, as an talloc()ed DATA_BLOB, on *out_mem_ctx
147 * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent.
150 NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security,
151 TALLOC_CTX *out_mem_ctx,
152 const DATA_BLOB in, DATA_BLOB *out)
154 struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_security->private_data;
155 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp_state->ntlmssp_state;
156 DATA_BLOB struct_blob;
157 fstring dnsname, dnsdomname;
158 uint32_t neg_flags = 0;
159 uint32_t ntlmssp_command, chal_flags;
160 char *cliname=NULL, *domname=NULL;
161 const uint8_t *cryptkey;
162 const char *target_name;
164 /* parse the NTLMSSP packet */
166 file_save("ntlmssp_negotiate.dat", request.data, request.length);
170 if (!msrpc_parse(ntlmssp_state,
177 DEBUG(1, ("ntlmssp_server_negotiate: failed to parse NTLMSSP:\n"));
178 dump_data(2, in.data, in.length);
179 return NT_STATUS_INVALID_PARAMETER;
182 debug_ntlmssp_flags(neg_flags);
185 ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key);
187 /* Ask our caller what challenge they would like in the packet */
188 cryptkey = ntlmssp_state->get_challenge(ntlmssp_state);
190 /* Check if we may set the challenge */
191 if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) {
192 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
195 /* The flags we send back are not just the negotiated flags,
196 * they are also 'what is in this packet'. Therfore, we
197 * operate on 'chal_flags' from here on
200 chal_flags = ntlmssp_state->neg_flags;
202 /* get the right name to fill in as 'target' */
203 target_name = ntlmssp_target_name(ntlmssp_state,
204 neg_flags, &chal_flags);
205 if (target_name == NULL)
206 return NT_STATUS_INVALID_PARAMETER;
208 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
209 ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
211 /* This should be a 'netbios domain -> DNS domain' mapping */
212 dnsdomname[0] = '\0';
213 get_mydomname(dnsdomname);
214 strlower_m(dnsdomname);
217 get_myfullname(dnsname);
219 /* This creates the 'blob' of names that appears at the end of the packet */
220 if (chal_flags & NTLMSSP_CHAL_TARGET_INFO)
222 const char *target_name_dns = "";
223 if (chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN) {
224 target_name_dns = dnsdomname;
225 } else if (chal_flags |= NTLMSSP_TARGET_TYPE_SERVER) {
226 target_name_dns = dnsname;
229 msrpc_gen(out_mem_ctx,
230 &struct_blob, "aaaaa",
231 NTLMSSP_NAME_TYPE_DOMAIN, target_name,
232 NTLMSSP_NAME_TYPE_SERVER, ntlmssp_state->server_name,
233 NTLMSSP_NAME_TYPE_DOMAIN_DNS, dnsdomname,
234 NTLMSSP_NAME_TYPE_SERVER_DNS, dnsname,
237 struct_blob = data_blob(NULL, 0);
241 /* Marshel the packet in the right format, be it unicode or ASCII */
242 const char *gen_string;
243 if (ntlmssp_state->unicode) {
244 gen_string = "CdUdbddB";
246 gen_string = "CdAdbddB";
249 msrpc_gen(out_mem_ctx,
257 struct_blob.data, struct_blob.length);
260 ntlmssp_state->expected_state = NTLMSSP_AUTH;
262 return NT_STATUS_MORE_PROCESSING_REQUIRED;
266 * Next state function for the Authenticate packet
268 * @param ntlmssp_state NTLMSSP State
269 * @param request The request, as a DATA_BLOB
270 * @return Errors or NT_STATUS_OK.
273 static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state,
274 const DATA_BLOB request)
276 uint32_t ntlmssp_command, auth_flags;
279 uint8_t session_nonce_hash[16];
281 const char *parse_string;
284 char *workstation = NULL;
287 file_save("ntlmssp_auth.dat", request.data, request.length);
290 if (ntlmssp_state->unicode) {
291 parse_string = "CdBBUUUBd";
293 parse_string = "CdBBAAABd";
297 data_blob_free(&ntlmssp_state->lm_resp);
298 data_blob_free(&ntlmssp_state->nt_resp);
300 ntlmssp_state->user = NULL;
301 ntlmssp_state->domain = NULL;
302 ntlmssp_state->workstation = NULL;
304 /* now the NTLMSSP encoded auth hashes */
305 if (!msrpc_parse(ntlmssp_state,
306 &request, parse_string,
309 &ntlmssp_state->lm_resp,
310 &ntlmssp_state->nt_resp,
314 &ntlmssp_state->encrypted_session_key,
316 DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n"));
317 dump_data(10, request.data, request.length);
320 data_blob_free(&ntlmssp_state->encrypted_session_key);
323 /* Try again with a shorter string (Win9X truncates this packet) */
324 if (ntlmssp_state->unicode) {
325 parse_string = "CdBBUUU";
327 parse_string = "CdBBAAA";
330 /* now the NTLMSSP encoded auth hashes */
331 if (!msrpc_parse(ntlmssp_state,
332 &request, parse_string,
335 &ntlmssp_state->lm_resp,
336 &ntlmssp_state->nt_resp,
340 DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP:\n"));
341 dump_data(2, request.data, request.length);
343 return NT_STATUS_INVALID_PARAMETER;
348 ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key);
350 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_domain(ntlmssp_state, domain))) {
352 data_blob_free(&ntlmssp_state->encrypted_session_key);
356 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_username(ntlmssp_state, user))) {
358 data_blob_free(&ntlmssp_state->encrypted_session_key);
362 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_workstation(ntlmssp_state, workstation))) {
364 data_blob_free(&ntlmssp_state->encrypted_session_key);
368 DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n",
369 ntlmssp_state->user, ntlmssp_state->domain, ntlmssp_state->workstation, (unsigned long)ntlmssp_state->lm_resp.length, (unsigned long)ntlmssp_state->nt_resp.length));
372 file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length);
373 file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length);
376 /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a
379 However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful.
381 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
382 if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
383 struct MD5Context md5_session_nonce_ctx;
384 SMB_ASSERT(ntlmssp_state->internal_chal.data
385 && ntlmssp_state->internal_chal.length == 8);
387 ntlmssp_state->doing_ntlm2 = True;
389 memcpy(ntlmssp_state->session_nonce, ntlmssp_state->internal_chal.data, 8);
390 memcpy(&ntlmssp_state->session_nonce[8], ntlmssp_state->lm_resp.data, 8);
392 MD5Init(&md5_session_nonce_ctx);
393 MD5Update(&md5_session_nonce_ctx, ntlmssp_state->session_nonce, 16);
394 MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
396 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state,
397 session_nonce_hash, 8);
399 /* LM response is no longer useful, zero it out */
400 data_blob_free(&ntlmssp_state->lm_resp);
402 /* We changed the effective challenge - set it */
403 if (!NT_STATUS_IS_OK(nt_status =
404 ntlmssp_state->set_challenge(ntlmssp_state,
405 &ntlmssp_state->chal))) {
407 data_blob_free(&ntlmssp_state->encrypted_session_key);
411 /* LM Key is incompatible... */
412 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
419 * Next state function for the Authenticate packet
420 * (after authentication - figures out the session keys etc)
422 * @param ntlmssp_state NTLMSSP State
423 * @return Errors or NT_STATUS_OK.
426 static NTSTATUS ntlmssp_server_postauth(struct ntlmssp_state *ntlmssp_state,
427 DATA_BLOB *user_session_key,
428 DATA_BLOB *lm_session_key)
431 DATA_BLOB session_key = data_blob(NULL, 0);
433 if (user_session_key)
434 dump_data_pw("USER session key:\n", user_session_key->data, user_session_key->length);
437 dump_data_pw("LM first-8:\n", lm_session_key->data, lm_session_key->length);
439 /* Handle the different session key derivation for NTLM2 */
440 if (ntlmssp_state->doing_ntlm2) {
441 if (user_session_key && user_session_key->data && user_session_key->length == 16) {
442 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
443 hmac_md5(user_session_key->data, ntlmssp_state->session_nonce,
444 sizeof(ntlmssp_state->session_nonce), session_key.data);
445 DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n"));
446 dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length);
449 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n"));
450 session_key = data_blob(NULL, 0);
452 } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
453 /* Ensure we can never get here on NTLMv2 */
454 && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) {
456 if (lm_session_key && lm_session_key->data && lm_session_key->length >= 8) {
457 if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) {
458 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
459 SMBsesskeygen_lm_sess_key(lm_session_key->data, ntlmssp_state->lm_resp.data,
461 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
462 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
465 /* When there is no LM response, just use zeros */
466 static const uint8_t zeros[24];
467 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
468 SMBsesskeygen_lm_sess_key(zeros, zeros,
470 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
471 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
474 /* LM Key not selected */
475 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
477 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n"));
478 session_key = data_blob(NULL, 0);
481 } else if (user_session_key && user_session_key->data) {
482 session_key = *user_session_key;
483 DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
484 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
486 /* LM Key not selected */
487 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
489 } else if (lm_session_key && lm_session_key->data) {
490 /* Very weird to have LM key, but no user session key, but anyway.. */
491 session_key = *lm_session_key;
492 DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
493 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
495 /* LM Key not selected */
496 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
499 DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n"));
500 session_key = data_blob(NULL, 0);
502 /* LM Key not selected */
503 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
506 /* With KEY_EXCH, the client supplies the proposed session key,
507 but encrypts it with the long-term key */
508 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
509 if (!ntlmssp_state->encrypted_session_key.data
510 || ntlmssp_state->encrypted_session_key.length != 16) {
511 data_blob_free(&ntlmssp_state->encrypted_session_key);
512 DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n",
513 ntlmssp_state->encrypted_session_key.length));
514 return NT_STATUS_INVALID_PARAMETER;
515 } else if (!session_key.data || session_key.length != 16) {
516 DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n",
517 session_key.length));
518 ntlmssp_state->session_key = session_key;
520 dump_data_pw("KEY_EXCH session key (enc):\n",
521 ntlmssp_state->encrypted_session_key.data,
522 ntlmssp_state->encrypted_session_key.length);
523 arcfour_crypt(ntlmssp_state->encrypted_session_key.data,
525 ntlmssp_state->encrypted_session_key.length);
526 ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
527 ntlmssp_state->encrypted_session_key.data,
528 ntlmssp_state->encrypted_session_key.length);
529 dump_data_pw("KEY_EXCH session key:\n", ntlmssp_state->encrypted_session_key.data,
530 ntlmssp_state->encrypted_session_key.length);
533 ntlmssp_state->session_key = session_key;
536 /* The server might need us to use a partial-strength session key */
537 ntlmssp_weaken_keys(ntlmssp_state);
539 nt_status = ntlmssp_sign_init(ntlmssp_state);
541 data_blob_free(&ntlmssp_state->encrypted_session_key);
543 /* allow arbitarily many authentications, but watch that this will cause a
544 memory leak, until the ntlmssp_state is shutdown
547 if (ntlmssp_state->server_multiple_authentications) {
548 ntlmssp_state->expected_state = NTLMSSP_AUTH;
550 ntlmssp_state->expected_state = NTLMSSP_DONE;
558 * Next state function for the Authenticate packet
560 * @param ntlmssp_state NTLMSSP State
561 * @param in The packet in from the NTLMSSP partner, as a DATA_BLOB
562 * @param out The reply, as an allocated DATA_BLOB, caller to free.
563 * @return Errors, NT_STATUS_MORE_PROCESSING_REQUIRED or NT_STATUS_OK.
566 NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security,
567 TALLOC_CTX *out_mem_ctx,
568 const DATA_BLOB in, DATA_BLOB *out)
570 struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_security->private_data;
571 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp_state->ntlmssp_state;
572 DATA_BLOB user_session_key = data_blob(NULL, 0);
573 DATA_BLOB lm_session_key = data_blob(NULL, 0);
576 /* zero the outbound NTLMSSP packet */
577 *out = data_blob_talloc(out_mem_ctx, NULL, 0);
579 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_server_preauth(ntlmssp_state, in))) {
584 * Note we don't check here for NTLMv2 auth settings. If NTLMv2 auth
585 * is required (by "ntlm auth = no" and "lm auth = no" being set in the
586 * smb.conf file) and no NTLMv2 response was sent then the password check
587 * will fail here. JRA.
590 /* Finally, actually ask if the password is OK */
592 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_state->check_password(ntlmssp_state,
593 &user_session_key, &lm_session_key))) {
597 if (ntlmssp_state->server_use_session_keys) {
598 return ntlmssp_server_postauth(ntlmssp_state, &user_session_key, &lm_session_key);
600 ntlmssp_state->session_key = data_blob(NULL, 0);
606 * Create an NTLMSSP state machine
608 * @param ntlmssp_state NTLMSSP State, allocated by this function
611 static NTSTATUS ntlmssp_server_start(TALLOC_CTX *mem_ctx, struct ntlmssp_state **ntlmssp_state)
613 *ntlmssp_state = talloc(mem_ctx, struct ntlmssp_state);
614 if (!*ntlmssp_state) {
615 DEBUG(0,("ntlmssp_server_start: talloc failed!\n"));
616 return NT_STATUS_NO_MEMORY;
618 ZERO_STRUCTP(*ntlmssp_state);
620 (*ntlmssp_state)->role = NTLMSSP_SERVER;
622 (*ntlmssp_state)->get_challenge = get_challenge;
623 (*ntlmssp_state)->set_challenge = set_challenge;
624 (*ntlmssp_state)->may_set_challenge = may_set_challenge;
626 (*ntlmssp_state)->workstation = NULL;
627 (*ntlmssp_state)->server_name = lp_netbios_name();
629 (*ntlmssp_state)->get_domain = lp_workgroup;
630 (*ntlmssp_state)->server_role = ROLE_DOMAIN_MEMBER; /* a good default */
632 (*ntlmssp_state)->expected_state = NTLMSSP_NEGOTIATE;
634 (*ntlmssp_state)->allow_lm_key = (lp_lanman_auth()
635 && lp_parm_bool(-1, "ntlmssp_server", "allow_lm_key", False));
637 (*ntlmssp_state)->server_use_session_keys = True;
638 (*ntlmssp_state)->server_multiple_authentications = False;
640 (*ntlmssp_state)->ref_count = 1;
642 (*ntlmssp_state)->neg_flags =
643 NTLMSSP_NEGOTIATE_NTLM;
645 if (lp_parm_bool(-1, "ntlmssp_server", "128bit", True)) {
646 (*ntlmssp_state)->neg_flags |= NTLMSSP_NEGOTIATE_128;
649 if (lp_parm_bool(-1, "ntlmssp_server", "keyexchange", True)) {
650 (*ntlmssp_state)->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH;
653 if (lp_parm_bool(-1, "ntlmssp_server", "ntlm2", True)) {
654 (*ntlmssp_state)->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
661 * Return the challenge as determined by the authentication subsystem
662 * @return an 8 byte random challenge
665 static const uint8_t *auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state)
667 struct gensec_ntlmssp_state *gensec_ntlmssp_state = ntlmssp_state->auth_context;
671 status = auth_get_challenge(gensec_ntlmssp_state->auth_context, &chal);
672 if (!NT_STATUS_IS_OK(status)) {
680 * Some authentication methods 'fix' the challenge, so we may not be able to set it
682 * @return If the effective challenge used by the auth subsystem may be modified
684 static BOOL auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
686 struct gensec_ntlmssp_state *gensec_ntlmssp_state = ntlmssp_state->auth_context;
688 return auth_challenge_may_be_modified(gensec_ntlmssp_state->auth_context);
692 * NTLM2 authentication modifies the effective challenge,
693 * @param challenge The new challenge value
695 static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
698 struct gensec_ntlmssp_state *gensec_ntlmssp_state = ntlmssp_state->auth_context;
699 struct auth_context *auth_context = gensec_ntlmssp_state->auth_context;
702 if (challenge->length != 8) {
703 return NT_STATUS_INVALID_PARAMETER;
706 chal = challenge->data;
708 nt_status = auth_context_set_challenge(auth_context, chal, "NTLMSSP callback (NTLM2)");
714 * Check the password on an NTLMSSP login.
716 * Return the session keys used on the connection.
719 static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
721 struct gensec_ntlmssp_state *gensec_ntlmssp_state = ntlmssp_state->auth_context;
722 struct auth_usersupplied_info *user_info = NULL;
725 nt_status = make_user_info_map(ntlmssp_state,
726 gensec_ntlmssp_state->ntlmssp_state->user,
727 gensec_ntlmssp_state->ntlmssp_state->domain,
728 gensec_ntlmssp_state->ntlmssp_state->workstation,
729 gensec_ntlmssp_state->ntlmssp_state->lm_resp.data ? &gensec_ntlmssp_state->ntlmssp_state->lm_resp : NULL,
730 gensec_ntlmssp_state->ntlmssp_state->nt_resp.data ? &gensec_ntlmssp_state->ntlmssp_state->nt_resp : NULL,
731 NULL, NULL, NULL, True,
733 NT_STATUS_NOT_OK_RETURN(nt_status);
735 nt_status = auth_check_password(gensec_ntlmssp_state->auth_context, gensec_ntlmssp_state,
736 user_info, &gensec_ntlmssp_state->server_info);
737 talloc_free(user_info);
738 NT_STATUS_NOT_OK_RETURN(nt_status);
740 if (gensec_ntlmssp_state->server_info->user_session_key.length) {
741 DEBUG(10, ("Got NT session key of length %u\n", gensec_ntlmssp_state->server_info->user_session_key.length));
742 *user_session_key = data_blob_talloc(ntlmssp_state,
743 gensec_ntlmssp_state->server_info->user_session_key.data,
744 gensec_ntlmssp_state->server_info->user_session_key.length);
746 if (gensec_ntlmssp_state->server_info->lm_session_key.length) {
747 DEBUG(10, ("Got LM session key of length %u\n", gensec_ntlmssp_state->server_info->lm_session_key.length));
748 *lm_session_key = data_blob_talloc(ntlmssp_state,
749 gensec_ntlmssp_state->server_info->lm_session_key.data,
750 gensec_ntlmssp_state->server_info->lm_session_key.length);
755 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security)
758 struct ntlmssp_state *ntlmssp_state;
759 struct gensec_ntlmssp_state *gensec_ntlmssp_state;
761 nt_status = gensec_ntlmssp_start(gensec_security);
762 NT_STATUS_NOT_OK_RETURN(nt_status);
764 gensec_ntlmssp_state = gensec_security->private_data;
766 nt_status = ntlmssp_server_start(gensec_ntlmssp_state, &gensec_ntlmssp_state->ntlmssp_state);
767 NT_STATUS_NOT_OK_RETURN(nt_status);
769 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
770 gensec_ntlmssp_state->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
772 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
773 gensec_ntlmssp_state->ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
776 nt_status = auth_context_create(gensec_ntlmssp_state, lp_auth_methods(), &gensec_ntlmssp_state->auth_context);
777 NT_STATUS_NOT_OK_RETURN(nt_status);
779 ntlmssp_state = gensec_ntlmssp_state->ntlmssp_state;
780 ntlmssp_state->auth_context = gensec_ntlmssp_state;
781 ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
782 ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
783 ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
784 ntlmssp_state->check_password = auth_ntlmssp_check_password;
785 ntlmssp_state->server_role = lp_server_role();
791 * Return the credentials of a logged on user, including session keys
794 * Only valid after a successful authentication
796 * May only be called once per authentication.
800 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
801 struct auth_session_info **session_info)
804 struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_security->private_data;
806 nt_status = auth_generate_session_info(gensec_ntlmssp_state, gensec_ntlmssp_state->server_info, session_info);
807 NT_STATUS_NOT_OK_RETURN(nt_status);
809 (*session_info)->session_key = data_blob_talloc(*session_info,
810 gensec_ntlmssp_state->ntlmssp_state->session_key.data,
811 gensec_ntlmssp_state->ntlmssp_state->session_key.length);