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 3 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, see <http://www.gnu.org/licenses/>.
25 #include "system/network.h"
26 #include "lib/tsocket/tsocket.h"
27 #include "auth/ntlmssp/ntlmssp.h"
28 #include "../librpc/gen_ndr/ndr_ntlmssp.h"
29 #include "../libcli/auth/ntlmssp_ndr.h"
30 #include "../libcli/auth/libcli_auth.h"
31 #include "../lib/crypto/crypto.h"
32 #include "auth/gensec/gensec.h"
33 #include "auth/gensec/gensec_proto.h"
34 #include "auth/auth.h"
35 #include "param/param.h"
38 * Determine correct target name flags for reply, given server role
39 * and negotiated flags
41 * @param ntlmssp_state NTLMSSP State
42 * @param neg_flags The flags from the packet
43 * @param chal_flags The flags to be set in the reply packet
44 * @return The 'target name' string.
47 static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
48 uint32_t neg_flags, uint32_t *chal_flags)
50 if (neg_flags & NTLMSSP_REQUEST_TARGET) {
51 *chal_flags |= NTLMSSP_NEGOTIATE_TARGET_INFO;
52 *chal_flags |= NTLMSSP_REQUEST_TARGET;
53 if (ntlmssp_state->server.is_standalone) {
54 *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
55 return ntlmssp_state->server.netbios_name;
57 *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
58 return ntlmssp_state->server.netbios_domain;
68 * Next state function for the Negotiate packet
70 * @param gensec_security GENSEC state
71 * @param out_mem_ctx Memory context for *out
72 * @param in The request, as a DATA_BLOB. reply.data must be NULL
73 * @param out The reply, as an allocated DATA_BLOB, caller to free.
74 * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
77 NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security,
78 TALLOC_CTX *out_mem_ctx,
79 const DATA_BLOB request, DATA_BLOB *reply)
81 struct gensec_ntlmssp_context *gensec_ntlmssp =
82 talloc_get_type_abort(gensec_security->private_data,
83 struct gensec_ntlmssp_context);
84 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
85 DATA_BLOB struct_blob;
86 uint32_t neg_flags = 0;
87 uint32_t ntlmssp_command, chal_flags;
89 const char *target_name;
92 /* parse the NTLMSSP packet */
94 file_save("ntlmssp_negotiate.dat", request.data, request.length);
98 if ((request.length < 16) || !msrpc_parse(ntlmssp_state, &request, "Cdd",
102 DEBUG(1, ("ntlmssp_server_negotiate: failed to parse NTLMSSP Negotiate of length %u\n",
103 (unsigned int)request.length));
104 dump_data(2, request.data, request.length);
105 return NT_STATUS_INVALID_PARAMETER;
107 debug_ntlmssp_flags(neg_flags);
109 if (DEBUGLEVEL >= 10) {
110 struct NEGOTIATE_MESSAGE *negotiate = talloc(
111 ntlmssp_state, struct NEGOTIATE_MESSAGE);
112 if (negotiate != NULL) {
113 status = ntlmssp_pull_NEGOTIATE_MESSAGE(
114 &request, negotiate, negotiate);
115 if (NT_STATUS_IS_OK(status)) {
116 NDR_PRINT_DEBUG(NEGOTIATE_MESSAGE,
119 TALLOC_FREE(negotiate);
124 ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key);
126 /* Ask our caller what challenge they would like in the packet */
127 status = ntlmssp_state->get_challenge(ntlmssp_state, cryptkey);
128 if (!NT_STATUS_IS_OK(status)) {
129 DEBUG(1, ("ntlmssp_server_negotiate: backend doesn't give a challenge: %s\n",
134 /* Check if we may set the challenge */
135 if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) {
136 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
139 /* The flags we send back are not just the negotiated flags,
140 * they are also 'what is in this packet'. Therfore, we
141 * operate on 'chal_flags' from here on
144 chal_flags = ntlmssp_state->neg_flags;
146 /* get the right name to fill in as 'target' */
147 target_name = ntlmssp_target_name(ntlmssp_state,
148 neg_flags, &chal_flags);
149 if (target_name == NULL)
150 return NT_STATUS_INVALID_PARAMETER;
152 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
153 ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state,
156 /* This creates the 'blob' of names that appears at the end of the packet */
157 if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO)
159 msrpc_gen(ntlmssp_state, &struct_blob, "aaaaa",
160 MsvAvNbDomainName, target_name,
161 MsvAvNbComputerName, ntlmssp_state->server.netbios_name,
162 MsvAvDnsDomainName, ntlmssp_state->server.dns_domain,
163 MsvAvDnsComputerName, ntlmssp_state->server.dns_name,
166 struct_blob = data_blob_null;
170 /* Marshal the packet in the right format, be it unicode or ASCII */
171 const char *gen_string;
172 DATA_BLOB version_blob = data_blob_null;
174 if (chal_flags & NTLMSSP_NEGOTIATE_VERSION) {
175 enum ndr_err_code err;
178 /* "What Windows returns" as a version number. */
180 vers.ProductMajorVersion = NTLMSSP_WINDOWS_MAJOR_VERSION_6;
181 vers.ProductMinorVersion = NTLMSSP_WINDOWS_MINOR_VERSION_1;
182 vers.ProductBuild = 0;
183 vers.NTLMRevisionCurrent = NTLMSSP_REVISION_W2K3;
185 err = ndr_push_struct_blob(&version_blob,
188 (ndr_push_flags_fn_t)ndr_push_VERSION);
190 if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
191 data_blob_free(&struct_blob);
192 return NT_STATUS_NO_MEMORY;
196 if (ntlmssp_state->unicode) {
197 gen_string = "CdUdbddBb";
199 gen_string = "CdAdbddBb";
202 msrpc_gen(out_mem_ctx, reply, gen_string,
209 struct_blob.data, struct_blob.length,
210 version_blob.data, version_blob.length);
212 data_blob_free(&version_blob);
214 if (DEBUGLEVEL >= 10) {
215 struct CHALLENGE_MESSAGE *challenge = talloc(
216 ntlmssp_state, struct CHALLENGE_MESSAGE);
217 if (challenge != NULL) {
218 challenge->NegotiateFlags = chal_flags;
219 status = ntlmssp_pull_CHALLENGE_MESSAGE(
220 reply, challenge, challenge);
221 if (NT_STATUS_IS_OK(status)) {
222 NDR_PRINT_DEBUG(CHALLENGE_MESSAGE,
225 TALLOC_FREE(challenge);
230 data_blob_free(&struct_blob);
232 ntlmssp_state->expected_state = NTLMSSP_AUTH;
234 return NT_STATUS_MORE_PROCESSING_REQUIRED;
237 struct ntlmssp_server_auth_state {
238 DATA_BLOB user_session_key;
239 DATA_BLOB lm_session_key;
240 /* internal variables used by KEY_EXCH (client-supplied user session key */
241 DATA_BLOB encrypted_session_key;
243 /* internal variables used by NTLM2 */
244 uint8_t session_nonce[16];
248 * Next state function for the Authenticate packet
250 * @param ntlmssp_state NTLMSSP State
251 * @param request The request, as a DATA_BLOB
252 * @return Errors or NT_STATUS_OK.
255 static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state,
256 struct ntlmssp_server_auth_state *state,
257 const DATA_BLOB request)
259 uint32_t ntlmssp_command, auth_flags;
262 uint8_t session_nonce_hash[16];
264 const char *parse_string;
267 file_save("ntlmssp_auth.dat", request.data, request.length);
270 if (ntlmssp_state->unicode) {
271 parse_string = "CdBBUUUBd";
273 parse_string = "CdBBAAABd";
277 data_blob_free(&ntlmssp_state->session_key);
278 data_blob_free(&ntlmssp_state->lm_resp);
279 data_blob_free(&ntlmssp_state->nt_resp);
281 ntlmssp_state->user = NULL;
282 ntlmssp_state->domain = NULL;
283 ntlmssp_state->client.netbios_name = NULL;
285 /* now the NTLMSSP encoded auth hashes */
286 if (!msrpc_parse(ntlmssp_state, &request, parse_string,
289 &ntlmssp_state->lm_resp,
290 &ntlmssp_state->nt_resp,
291 &ntlmssp_state->domain,
292 &ntlmssp_state->user,
293 &ntlmssp_state->client.netbios_name,
294 &state->encrypted_session_key,
296 DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n"));
297 dump_data(10, request.data, request.length);
300 data_blob_free(&state->encrypted_session_key);
303 /* Try again with a shorter string (Win9X truncates this packet) */
304 if (ntlmssp_state->unicode) {
305 parse_string = "CdBBUUU";
307 parse_string = "CdBBAAA";
310 /* now the NTLMSSP encoded auth hashes */
311 if (!msrpc_parse(ntlmssp_state, &request, parse_string,
314 &ntlmssp_state->lm_resp,
315 &ntlmssp_state->nt_resp,
316 &ntlmssp_state->domain,
317 &ntlmssp_state->user,
318 &ntlmssp_state->client.netbios_name)) {
319 DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP (tried both formats):\n"));
320 dump_data(2, request.data, request.length);
322 return NT_STATUS_INVALID_PARAMETER;
326 talloc_steal(state, state->encrypted_session_key.data);
329 ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key);
331 if (DEBUGLEVEL >= 10) {
332 struct AUTHENTICATE_MESSAGE *authenticate = talloc(
333 ntlmssp_state, struct AUTHENTICATE_MESSAGE);
334 if (authenticate != NULL) {
336 authenticate->NegotiateFlags = auth_flags;
337 status = ntlmssp_pull_AUTHENTICATE_MESSAGE(
338 &request, authenticate, authenticate);
339 if (NT_STATUS_IS_OK(status)) {
340 NDR_PRINT_DEBUG(AUTHENTICATE_MESSAGE,
343 TALLOC_FREE(authenticate);
347 DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n",
348 ntlmssp_state->user, ntlmssp_state->domain,
349 ntlmssp_state->client.netbios_name,
350 (unsigned long)ntlmssp_state->lm_resp.length,
351 (unsigned long)ntlmssp_state->nt_resp.length));
354 file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length);
355 file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length);
358 /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a
361 However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful.
363 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
364 if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
365 struct MD5Context md5_session_nonce_ctx;
366 state->doing_ntlm2 = true;
368 memcpy(state->session_nonce, ntlmssp_state->internal_chal.data, 8);
369 memcpy(&state->session_nonce[8], ntlmssp_state->lm_resp.data, 8);
371 SMB_ASSERT(ntlmssp_state->internal_chal.data && ntlmssp_state->internal_chal.length == 8);
373 MD5Init(&md5_session_nonce_ctx);
374 MD5Update(&md5_session_nonce_ctx, state->session_nonce, 16);
375 MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
377 ntlmssp_state->chal = data_blob_talloc(
378 ntlmssp_state, session_nonce_hash, 8);
380 /* LM response is no longer useful */
381 data_blob_free(&ntlmssp_state->lm_resp);
383 /* We changed the effective challenge - set it */
384 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_state->set_challenge(ntlmssp_state, &ntlmssp_state->chal))) {
388 /* LM Key is incompatible. */
389 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
396 * Next state function for the Authenticate packet
397 * (after authentication - figures out the session keys etc)
399 * @param ntlmssp_state NTLMSSP State
400 * @return Errors or NT_STATUS_OK.
403 static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
404 struct ntlmssp_server_auth_state *state)
406 struct gensec_ntlmssp_context *gensec_ntlmssp =
407 talloc_get_type_abort(gensec_security->private_data,
408 struct gensec_ntlmssp_context);
409 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
410 DATA_BLOB *user_session_key = &state->user_session_key;
411 DATA_BLOB *lm_session_key = &state->lm_session_key;
413 DATA_BLOB session_key = data_blob(NULL, 0);
415 if (user_session_key)
416 dump_data_pw("USER session key:\n", user_session_key->data, user_session_key->length);
419 dump_data_pw("LM first-8:\n", lm_session_key->data, lm_session_key->length);
421 /* Handle the different session key derivation for NTLM2 */
422 if (state->doing_ntlm2) {
423 if (user_session_key && user_session_key->data && user_session_key->length == 16) {
424 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
425 hmac_md5(user_session_key->data, state->session_nonce,
426 sizeof(state->session_nonce), session_key.data);
427 DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n"));
428 dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length);
431 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n"));
432 session_key = data_blob_null;
434 } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
435 /* Ensure we can never get here on NTLMv2 */
436 && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) {
438 if (lm_session_key && lm_session_key->data && lm_session_key->length >= 8) {
439 if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) {
440 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
441 SMBsesskeygen_lm_sess_key(lm_session_key->data, ntlmssp_state->lm_resp.data,
443 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
445 static const uint8_t zeros[24] = {0, };
446 session_key = data_blob_talloc(
447 ntlmssp_state, NULL, 16);
448 if (session_key.data == NULL) {
449 return NT_STATUS_NO_MEMORY;
451 SMBsesskeygen_lm_sess_key(zeros, zeros,
453 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
454 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
456 dump_data_pw("LM session key:\n", session_key.data,
459 /* LM Key not selected */
460 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
462 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n"));
463 session_key = data_blob_null;
466 } else if (user_session_key && user_session_key->data) {
467 session_key = data_blob_talloc(ntlmssp_state, user_session_key->data, user_session_key->length);
468 DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
469 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
471 /* LM Key not selected */
472 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
474 } else if (lm_session_key && lm_session_key->data) {
475 /* Very weird to have LM key, but no user session key, but anyway.. */
476 session_key = data_blob_talloc(ntlmssp_state, lm_session_key->data, lm_session_key->length);
477 DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
478 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
480 /* LM Key not selected */
481 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
484 DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n"));
485 session_key = data_blob(NULL, 0);
487 /* LM Key not selected */
488 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
491 /* With KEY_EXCH, the client supplies the proposed session key,
492 but encrypts it with the long-term key */
493 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
494 if (!state->encrypted_session_key.data
495 || state->encrypted_session_key.length != 16) {
496 data_blob_free(&state->encrypted_session_key);
497 DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n",
498 (unsigned)state->encrypted_session_key.length));
499 return NT_STATUS_INVALID_PARAMETER;
500 } else if (!session_key.data || session_key.length != 16) {
501 DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n",
502 (unsigned int)session_key.length));
503 ntlmssp_state->session_key = session_key;
505 dump_data_pw("KEY_EXCH session key (enc):\n",
506 state->encrypted_session_key.data,
507 state->encrypted_session_key.length);
508 arcfour_crypt(state->encrypted_session_key.data,
510 state->encrypted_session_key.length);
511 ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
512 state->encrypted_session_key.data,
513 state->encrypted_session_key.length);
514 dump_data_pw("KEY_EXCH session key:\n",
515 state->encrypted_session_key.data,
516 state->encrypted_session_key.length);
517 talloc_free(session_key.data);
520 ntlmssp_state->session_key = session_key;
523 if (ntlmssp_state->session_key.length) {
524 nt_status = ntlmssp_sign_init(ntlmssp_state);
527 ntlmssp_state->expected_state = NTLMSSP_DONE;
534 * Next state function for the Authenticate packet
536 * @param gensec_security GENSEC state
537 * @param out_mem_ctx Memory context for *out
538 * @param in The request, as a DATA_BLOB. reply.data must be NULL
539 * @param out The reply, as an allocated DATA_BLOB, caller to free.
540 * @return Errors or NT_STATUS_OK if authentication sucessful
543 NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security,
544 TALLOC_CTX *out_mem_ctx,
545 const DATA_BLOB in, DATA_BLOB *out)
547 struct gensec_ntlmssp_context *gensec_ntlmssp =
548 talloc_get_type_abort(gensec_security->private_data,
549 struct gensec_ntlmssp_context);
550 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
551 struct ntlmssp_server_auth_state *state;
554 /* zero the outbound NTLMSSP packet */
555 *out = data_blob_null;
557 state = talloc_zero(ntlmssp_state, struct ntlmssp_server_auth_state);
559 return NT_STATUS_NO_MEMORY;
562 nt_status = ntlmssp_server_preauth(ntlmssp_state, state, in);
563 if (!NT_STATUS_IS_OK(nt_status)) {
569 * Note we don't check here for NTLMv2 auth settings. If NTLMv2 auth
570 * is required (by "ntlm auth = no" and "lm auth = no" being set in the
571 * smb.conf file) and no NTLMv2 response was sent then the password check
572 * will fail here. JRA.
575 /* Finally, actually ask if the password is OK */
576 nt_status = ntlmssp_state->check_password(ntlmssp_state,
577 &state->user_session_key,
578 &state->lm_session_key);
579 if (!NT_STATUS_IS_OK(nt_status)) {
584 nt_status = ntlmssp_server_postauth(gensec_security, state);
585 if (!NT_STATUS_IS_OK(nt_status)) {
595 * Return the challenge as determined by the authentication subsystem
596 * @return an 8 byte random challenge
599 static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
602 struct gensec_ntlmssp_context *gensec_ntlmssp =
603 talloc_get_type_abort(ntlmssp_state->callback_private,
604 struct gensec_ntlmssp_context);
605 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
608 status = auth_context->get_challenge(auth_context, chal);
609 if (!NT_STATUS_IS_OK(status)) {
610 DEBUG(1, ("auth_ntlmssp_get_challenge: failed to get challenge: %s\n",
619 * Some authentication methods 'fix' the challenge, so we may not be able to set it
621 * @return If the effective challenge used by the auth subsystem may be modified
623 static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
625 struct gensec_ntlmssp_context *gensec_ntlmssp =
626 talloc_get_type_abort(ntlmssp_state->callback_private,
627 struct gensec_ntlmssp_context);
628 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
630 return auth_context->challenge_may_be_modified(auth_context);
634 * NTLM2 authentication modifies the effective challenge,
635 * @param challenge The new challenge value
637 static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
639 struct gensec_ntlmssp_context *gensec_ntlmssp =
640 talloc_get_type_abort(ntlmssp_state->callback_private,
641 struct gensec_ntlmssp_context);
642 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
646 if (challenge->length != 8) {
647 return NT_STATUS_INVALID_PARAMETER;
650 chal = challenge->data;
652 nt_status = auth_context->set_challenge(auth_context,
654 "NTLMSSP callback (NTLM2)");
660 * Check the password on an NTLMSSP login.
662 * Return the session keys used on the connection.
665 static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
666 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
668 struct gensec_ntlmssp_context *gensec_ntlmssp =
669 talloc_get_type_abort(ntlmssp_state->callback_private,
670 struct gensec_ntlmssp_context);
671 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
673 struct auth_usersupplied_info *user_info;
675 user_info = talloc(ntlmssp_state, struct auth_usersupplied_info);
677 return NT_STATUS_NO_MEMORY;
680 user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT;
681 user_info->flags = 0;
682 user_info->mapped_state = false;
683 user_info->client.account_name = ntlmssp_state->user;
684 user_info->client.domain_name = ntlmssp_state->domain;
685 user_info->workstation_name = ntlmssp_state->client.netbios_name;
686 user_info->remote_host = gensec_get_remote_address(gensec_ntlmssp->gensec_security);
688 user_info->password_state = AUTH_PASSWORD_RESPONSE;
689 user_info->password.response.lanman = ntlmssp_state->lm_resp;
690 user_info->password.response.lanman.data = talloc_steal(user_info, ntlmssp_state->lm_resp.data);
691 user_info->password.response.nt = ntlmssp_state->nt_resp;
692 user_info->password.response.nt.data = talloc_steal(user_info, ntlmssp_state->nt_resp.data);
694 nt_status = auth_context->check_password(auth_context,
697 &gensec_ntlmssp->server_info);
698 talloc_free(user_info);
699 NT_STATUS_NOT_OK_RETURN(nt_status);
701 if (gensec_ntlmssp->server_info->user_session_key.length) {
702 DEBUG(10, ("Got NT session key of length %u\n",
703 (unsigned)gensec_ntlmssp->server_info->user_session_key.length));
704 *user_session_key = gensec_ntlmssp->server_info->user_session_key;
706 if (gensec_ntlmssp->server_info->lm_session_key.length) {
707 DEBUG(10, ("Got LM session key of length %u\n",
708 (unsigned)gensec_ntlmssp->server_info->lm_session_key.length));
709 *lm_session_key = gensec_ntlmssp->server_info->lm_session_key;
715 * Return the credentials of a logged on user, including session keys
718 * Only valid after a successful authentication
720 * May only be called once per authentication.
724 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
725 struct auth_session_info **session_info)
728 struct gensec_ntlmssp_context *gensec_ntlmssp =
729 talloc_get_type_abort(gensec_security->private_data,
730 struct gensec_ntlmssp_context);
731 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
733 nt_status = gensec_generate_session_info(ntlmssp_state,
735 gensec_ntlmssp->server_info,
737 NT_STATUS_NOT_OK_RETURN(nt_status);
739 (*session_info)->session_key = data_blob_talloc(*session_info,
740 ntlmssp_state->session_key.data,
741 ntlmssp_state->session_key.length);
747 * Start NTLMSSP on the server side
750 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security)
753 struct ntlmssp_state *ntlmssp_state;
754 struct gensec_ntlmssp_context *gensec_ntlmssp;
756 nt_status = gensec_ntlmssp_start(gensec_security);
757 NT_STATUS_NOT_OK_RETURN(nt_status);
759 gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data,
760 struct gensec_ntlmssp_context);
761 ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
763 ntlmssp_state->role = NTLMSSP_SERVER;
765 ntlmssp_state->expected_state = NTLMSSP_NEGOTIATE;
767 ntlmssp_state->allow_lm_key = (lpcfg_lanman_auth(gensec_security->settings->lp_ctx)
768 && gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "allow_lm_key", false));
770 ntlmssp_state->neg_flags =
771 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION;
773 ntlmssp_state->lm_resp = data_blob(NULL, 0);
774 ntlmssp_state->nt_resp = data_blob(NULL, 0);
776 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "128bit", true)) {
777 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128;
780 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "56bit", true)) {
781 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56;
784 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "keyexchange", true)) {
785 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH;
788 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "alwayssign", true)) {
789 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
792 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "ntlm2", true)) {
793 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
796 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
797 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
799 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
800 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
803 gensec_ntlmssp->auth_context = gensec_security->auth_context;
805 ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
806 ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
807 ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
808 ntlmssp_state->check_password = auth_ntlmssp_check_password;
809 if (lpcfg_server_role(gensec_security->settings->lp_ctx) == ROLE_STANDALONE) {
810 ntlmssp_state->server.is_standalone = true;
812 ntlmssp_state->server.is_standalone = false;
815 ntlmssp_state->server.netbios_name = lpcfg_netbios_name(gensec_security->settings->lp_ctx);
817 ntlmssp_state->server.netbios_domain = lpcfg_workgroup(gensec_security->settings->lp_ctx);
820 char dnsdomname[MAXHOSTNAMELEN], dnsname[MAXHOSTNAMELEN];
822 /* Find out the DNS domain name */
823 dnsdomname[0] = '\0';
824 safe_strcpy(dnsdomname, lpcfg_dnsdomain(gensec_security->settings->lp_ctx), sizeof(dnsdomname) - 1);
826 /* Find out the DNS host name */
827 safe_strcpy(dnsname, ntlmssp_state->server.netbios_name, sizeof(dnsname) - 1);
828 if (dnsdomname[0] != '\0') {
829 safe_strcat(dnsname, ".", sizeof(dnsname) - 1);
830 safe_strcat(dnsname, dnsdomname, sizeof(dnsname) - 1);
834 ntlmssp_state->server.dns_name = talloc_strdup(ntlmssp_state,
836 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_name);
838 ntlmssp_state->server.dns_domain = talloc_strdup(ntlmssp_state,
840 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_domain);