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/libcli_auth.h"
30 #include "../lib/crypto/crypto.h"
31 #include "auth/gensec/gensec.h"
32 #include "auth/gensec/gensec_proto.h"
33 #include "auth/auth.h"
34 #include "param/param.h"
37 * Determine correct target name flags for reply, given server role
38 * and negotiated flags
40 * @param ntlmssp_state NTLMSSP State
41 * @param neg_flags The flags from the packet
42 * @param chal_flags The flags to be set in the reply packet
43 * @return The 'target name' string.
46 static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
47 uint32_t neg_flags, uint32_t *chal_flags)
49 if (neg_flags & NTLMSSP_REQUEST_TARGET) {
50 *chal_flags |= NTLMSSP_NEGOTIATE_TARGET_INFO;
51 *chal_flags |= NTLMSSP_REQUEST_TARGET;
52 if (ntlmssp_state->server.is_standalone) {
53 *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
54 return ntlmssp_state->server.netbios_name;
56 *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
57 return ntlmssp_state->server.netbios_domain;
67 * Next state function for the Negotiate packet
69 * @param gensec_security GENSEC state
70 * @param out_mem_ctx Memory context for *out
71 * @param in The request, as a DATA_BLOB. reply.data must be NULL
72 * @param out The reply, as an allocated DATA_BLOB, caller to free.
73 * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
76 NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security,
77 TALLOC_CTX *out_mem_ctx,
78 const DATA_BLOB in, DATA_BLOB *out)
80 struct gensec_ntlmssp_context *gensec_ntlmssp =
81 talloc_get_type_abort(gensec_security->private_data,
82 struct gensec_ntlmssp_context);
83 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
84 DATA_BLOB struct_blob;
85 uint32_t neg_flags = 0;
86 uint32_t ntlmssp_command, chal_flags;
88 const char *target_name;
91 /* parse the NTLMSSP packet */
93 file_save("ntlmssp_negotiate.dat", request.data, request.length);
97 if ((in.length < 16) || !msrpc_parse(out_mem_ctx,
102 DEBUG(1, ("ntlmssp_server_negotiate: failed to parse "
103 "NTLMSSP Negotiate of length %u:\n",
104 (unsigned int)in.length ));
105 dump_data(2, in.data, in.length);
106 return NT_STATUS_INVALID_PARAMETER;
108 debug_ntlmssp_flags(neg_flags);
111 ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key);
113 /* Ask our caller what challenge they would like in the packet */
114 status = ntlmssp_state->get_challenge(ntlmssp_state, cryptkey);
115 if (!NT_STATUS_IS_OK(status)) {
116 DEBUG(1, ("ntlmssp_server_negotiate: backend doesn't give a challenge: %s\n",
121 /* Check if we may set the challenge */
122 if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) {
123 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
126 /* The flags we send back are not just the negotiated flags,
127 * they are also 'what is in this packet'. Therfore, we
128 * operate on 'chal_flags' from here on
131 chal_flags = ntlmssp_state->neg_flags;
133 /* get the right name to fill in as 'target' */
134 target_name = ntlmssp_target_name(ntlmssp_state,
135 neg_flags, &chal_flags);
136 if (target_name == NULL)
137 return NT_STATUS_INVALID_PARAMETER;
139 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
140 ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
142 /* This creates the 'blob' of names that appears at the end of the packet */
143 if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO) {
144 msrpc_gen(out_mem_ctx,
145 &struct_blob, "aaaaa",
146 MsvAvNbDomainName, target_name,
147 MsvAvNbComputerName, ntlmssp_state->server.netbios_name,
148 MsvAvDnsDomainName, ntlmssp_state->server.dns_domain,
149 MsvAvDnsComputerName, ntlmssp_state->server.dns_name,
152 struct_blob = data_blob(NULL, 0);
156 /* Marshal the packet in the right format, be it unicode or ASCII */
157 const char *gen_string;
158 DATA_BLOB version_blob = data_blob_null;
160 if (chal_flags & NTLMSSP_NEGOTIATE_VERSION) {
161 enum ndr_err_code err;
164 /* "What Windows returns" as a version number. */
166 vers.ProductMajorVersion = NTLMSSP_WINDOWS_MAJOR_VERSION_6;
167 vers.ProductMinorVersion = NTLMSSP_WINDOWS_MINOR_VERSION_1;
168 vers.ProductBuild = 0;
169 vers.NTLMRevisionCurrent = NTLMSSP_REVISION_W2K3;
171 err = ndr_push_struct_blob(&version_blob,
174 (ndr_push_flags_fn_t)ndr_push_VERSION);
176 if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
177 return NT_STATUS_NO_MEMORY;
181 if (ntlmssp_state->unicode) {
182 gen_string = "CdUdbddBb";
184 gen_string = "CdAdbddBb";
187 msrpc_gen(out_mem_ctx,
195 struct_blob.data, struct_blob.length,
196 version_blob.data, version_blob.length);
198 data_blob_free(&version_blob);
201 ntlmssp_state->expected_state = NTLMSSP_AUTH;
203 return NT_STATUS_MORE_PROCESSING_REQUIRED;
206 struct ntlmssp_server_auth_state {
207 DATA_BLOB user_session_key;
208 DATA_BLOB lm_session_key;
209 /* internal variables used by KEY_EXCH (client-supplied user session key */
210 DATA_BLOB encrypted_session_key;
212 /* internal variables used by NTLM2 */
213 uint8_t session_nonce[16];
217 * Next state function for the Authenticate packet
219 * @param ntlmssp_state NTLMSSP State
220 * @param request The request, as a DATA_BLOB
221 * @return Errors or NT_STATUS_OK.
224 static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state,
225 struct ntlmssp_server_auth_state *state,
226 const DATA_BLOB request)
228 uint32_t ntlmssp_command, auth_flags;
231 uint8_t session_nonce_hash[16];
233 const char *parse_string;
236 file_save("ntlmssp_auth.dat", request.data, request.length);
239 if (ntlmssp_state->unicode) {
240 parse_string = "CdBBUUUBd";
242 parse_string = "CdBBAAABd";
246 data_blob_free(&ntlmssp_state->session_key);
247 data_blob_free(&ntlmssp_state->lm_resp);
248 data_blob_free(&ntlmssp_state->nt_resp);
250 ntlmssp_state->user = NULL;
251 ntlmssp_state->domain = NULL;
252 ntlmssp_state->client.netbios_name = NULL;
254 /* now the NTLMSSP encoded auth hashes */
255 if (!msrpc_parse(ntlmssp_state,
256 &request, parse_string,
259 &ntlmssp_state->lm_resp,
260 &ntlmssp_state->nt_resp,
261 &ntlmssp_state->domain,
262 &ntlmssp_state->user,
263 &ntlmssp_state->client.netbios_name,
264 &state->encrypted_session_key,
266 DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n"));
267 dump_data(10, request.data, request.length);
270 data_blob_free(&state->encrypted_session_key);
273 /* Try again with a shorter string (Win9X truncates this packet) */
274 if (ntlmssp_state->unicode) {
275 parse_string = "CdBBUUU";
277 parse_string = "CdBBAAA";
280 /* now the NTLMSSP encoded auth hashes */
281 if (!msrpc_parse(ntlmssp_state,
282 &request, parse_string,
285 &ntlmssp_state->lm_resp,
286 &ntlmssp_state->nt_resp,
287 &ntlmssp_state->domain,
288 &ntlmssp_state->user,
289 &ntlmssp_state->client.netbios_name)) {
290 DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP:\n"));
291 dump_data(2, request.data, request.length);
293 return NT_STATUS_INVALID_PARAMETER;
297 talloc_steal(state, state->encrypted_session_key.data);
300 ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key);
302 DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n",
303 ntlmssp_state->user, ntlmssp_state->domain, ntlmssp_state->client.netbios_name, (unsigned long)ntlmssp_state->lm_resp.length, (unsigned long)ntlmssp_state->nt_resp.length));
306 file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length);
307 file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length);
310 /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a
313 However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful.
315 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
316 if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
317 struct MD5Context md5_session_nonce_ctx;
318 SMB_ASSERT(ntlmssp_state->internal_chal.data
319 && ntlmssp_state->internal_chal.length == 8);
321 state->doing_ntlm2 = true;
323 memcpy(state->session_nonce, ntlmssp_state->internal_chal.data, 8);
324 memcpy(&state->session_nonce[8], ntlmssp_state->lm_resp.data, 8);
326 MD5Init(&md5_session_nonce_ctx);
327 MD5Update(&md5_session_nonce_ctx, state->session_nonce, 16);
328 MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
330 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state,
331 session_nonce_hash, 8);
333 /* LM response is no longer useful, zero it out */
334 data_blob_free(&ntlmssp_state->lm_resp);
336 /* We changed the effective challenge - set it */
337 if (!NT_STATUS_IS_OK(nt_status =
338 ntlmssp_state->set_challenge(ntlmssp_state,
339 &ntlmssp_state->chal))) {
343 /* LM Key is incompatible... */
344 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
351 * Next state function for the Authenticate packet
352 * (after authentication - figures out the session keys etc)
354 * @param ntlmssp_state NTLMSSP State
355 * @return Errors or NT_STATUS_OK.
358 static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
359 struct ntlmssp_server_auth_state *state)
361 struct gensec_ntlmssp_context *gensec_ntlmssp =
362 talloc_get_type_abort(gensec_security->private_data,
363 struct gensec_ntlmssp_context);
364 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
365 DATA_BLOB *user_session_key = &state->user_session_key;
366 DATA_BLOB *lm_session_key = &state->lm_session_key;
368 DATA_BLOB session_key = data_blob(NULL, 0);
370 if (!(gensec_security->want_features
371 & (GENSEC_FEATURE_SIGN|GENSEC_FEATURE_SEAL|GENSEC_FEATURE_SESSION_KEY))) {
375 if (user_session_key)
376 dump_data_pw("USER session key:\n", user_session_key->data, user_session_key->length);
379 dump_data_pw("LM first-8:\n", lm_session_key->data, lm_session_key->length);
381 /* Handle the different session key derivation for NTLM2 */
382 if (state->doing_ntlm2) {
383 if (user_session_key && user_session_key->data && user_session_key->length == 16) {
384 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
385 hmac_md5(user_session_key->data, state->session_nonce,
386 sizeof(state->session_nonce), session_key.data);
387 DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n"));
388 dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length);
391 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n"));
392 session_key = data_blob(NULL, 0);
394 } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
395 /* Ensure we can never get here on NTLMv2 */
396 && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) {
398 if (lm_session_key && lm_session_key->data && lm_session_key->length >= 8) {
399 if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) {
400 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
401 SMBsesskeygen_lm_sess_key(lm_session_key->data, ntlmssp_state->lm_resp.data,
403 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
404 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
407 /* When there is no LM response, just use zeros */
408 static const uint8_t zeros[24];
409 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
410 SMBsesskeygen_lm_sess_key(zeros, zeros,
412 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
413 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
416 /* LM Key not selected */
417 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
419 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n"));
420 session_key = data_blob(NULL, 0);
423 } else if (user_session_key && user_session_key->data) {
424 session_key = data_blob_talloc(ntlmssp_state, user_session_key->data, user_session_key->length);
425 DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
426 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
428 /* LM Key not selected */
429 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
431 } else if (lm_session_key && lm_session_key->data) {
432 /* Very weird to have LM key, but no user session key, but anyway.. */
433 session_key = data_blob_talloc(ntlmssp_state, lm_session_key->data, lm_session_key->length);
434 DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
435 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
437 /* LM Key not selected */
438 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
441 DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n"));
442 session_key = data_blob(NULL, 0);
444 /* LM Key not selected */
445 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
448 /* With KEY_EXCH, the client supplies the proposed session key,
449 but encrypts it with the long-term key */
450 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
451 if (!state->encrypted_session_key.data
452 || state->encrypted_session_key.length != 16) {
453 data_blob_free(&state->encrypted_session_key);
454 DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n",
455 (unsigned)state->encrypted_session_key.length));
456 return NT_STATUS_INVALID_PARAMETER;
457 } else if (!session_key.data || session_key.length != 16) {
458 DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n",
459 (unsigned)session_key.length));
460 ntlmssp_state->session_key = session_key;
462 dump_data_pw("KEY_EXCH session key (enc):\n",
463 state->encrypted_session_key.data,
464 state->encrypted_session_key.length);
465 arcfour_crypt(state->encrypted_session_key.data,
467 state->encrypted_session_key.length);
468 ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
469 state->encrypted_session_key.data,
470 state->encrypted_session_key.length);
471 dump_data_pw("KEY_EXCH session key:\n",
472 state->encrypted_session_key.data,
473 state->encrypted_session_key.length);
474 talloc_free(session_key.data);
477 ntlmssp_state->session_key = session_key;
480 if ((gensec_security->want_features & GENSEC_FEATURE_SIGN)
481 || (gensec_security->want_features & GENSEC_FEATURE_SEAL)) {
482 nt_status = ntlmssp_sign_init(ntlmssp_state);
484 nt_status = NT_STATUS_OK;
487 ntlmssp_state->expected_state = NTLMSSP_DONE;
494 * Next state function for the Authenticate packet
496 * @param gensec_security GENSEC state
497 * @param out_mem_ctx Memory context for *out
498 * @param in The request, as a DATA_BLOB. reply.data must be NULL
499 * @param out The reply, as an allocated DATA_BLOB, caller to free.
500 * @return Errors or NT_STATUS_OK if authentication sucessful
503 NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security,
504 TALLOC_CTX *out_mem_ctx,
505 const DATA_BLOB in, DATA_BLOB *out)
507 struct gensec_ntlmssp_context *gensec_ntlmssp =
508 talloc_get_type_abort(gensec_security->private_data,
509 struct gensec_ntlmssp_context);
510 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
511 struct ntlmssp_server_auth_state *state;
514 /* zero the outbound NTLMSSP packet */
515 *out = data_blob_null;
517 state = talloc_zero(ntlmssp_state, struct ntlmssp_server_auth_state);
519 return NT_STATUS_NO_MEMORY;
522 nt_status = ntlmssp_server_preauth(ntlmssp_state, state, in);
523 if (!NT_STATUS_IS_OK(nt_status)) {
529 * Note we don't check here for NTLMv2 auth settings. If NTLMv2 auth
530 * is required (by "ntlm auth = no" and "lm auth = no" being set in the
531 * smb.conf file) and no NTLMv2 response was sent then the password check
532 * will fail here. JRA.
535 /* Finally, actually ask if the password is OK */
536 nt_status = ntlmssp_state->check_password(ntlmssp_state,
537 &state->user_session_key,
538 &state->lm_session_key);
539 if (!NT_STATUS_IS_OK(nt_status)) {
544 nt_status = ntlmssp_server_postauth(gensec_security, state);
545 if (!NT_STATUS_IS_OK(nt_status)) {
555 * Return the challenge as determined by the authentication subsystem
556 * @return an 8 byte random challenge
559 static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
562 struct gensec_ntlmssp_context *gensec_ntlmssp =
563 talloc_get_type_abort(ntlmssp_state->callback_private,
564 struct gensec_ntlmssp_context);
565 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
568 status = auth_context->get_challenge(auth_context, chal);
569 if (!NT_STATUS_IS_OK(status)) {
570 DEBUG(1, ("auth_ntlmssp_get_challenge: failed to get challenge: %s\n",
579 * Some authentication methods 'fix' the challenge, so we may not be able to set it
581 * @return If the effective challenge used by the auth subsystem may be modified
583 static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
585 struct gensec_ntlmssp_context *gensec_ntlmssp =
586 talloc_get_type_abort(ntlmssp_state->callback_private,
587 struct gensec_ntlmssp_context);
588 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
590 return auth_context->challenge_may_be_modified(auth_context);
594 * NTLM2 authentication modifies the effective challenge,
595 * @param challenge The new challenge value
597 static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
599 struct gensec_ntlmssp_context *gensec_ntlmssp =
600 talloc_get_type_abort(ntlmssp_state->callback_private,
601 struct gensec_ntlmssp_context);
602 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
606 if (challenge->length != 8) {
607 return NT_STATUS_INVALID_PARAMETER;
610 chal = challenge->data;
612 nt_status = auth_context->set_challenge(auth_context,
614 "NTLMSSP callback (NTLM2)");
620 * Check the password on an NTLMSSP login.
622 * Return the session keys used on the connection.
625 static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
626 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
628 struct gensec_ntlmssp_context *gensec_ntlmssp =
629 talloc_get_type_abort(ntlmssp_state->callback_private,
630 struct gensec_ntlmssp_context);
631 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
633 struct auth_usersupplied_info *user_info;
635 user_info = talloc(ntlmssp_state, struct auth_usersupplied_info);
637 return NT_STATUS_NO_MEMORY;
640 user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT;
641 user_info->flags = 0;
642 user_info->mapped_state = false;
643 user_info->client.account_name = ntlmssp_state->user;
644 user_info->client.domain_name = ntlmssp_state->domain;
645 user_info->workstation_name = ntlmssp_state->client.netbios_name;
646 user_info->remote_host = gensec_get_remote_address(gensec_ntlmssp->gensec_security);
648 user_info->password_state = AUTH_PASSWORD_RESPONSE;
649 user_info->password.response.lanman = ntlmssp_state->lm_resp;
650 user_info->password.response.lanman.data = talloc_steal(user_info, ntlmssp_state->lm_resp.data);
651 user_info->password.response.nt = ntlmssp_state->nt_resp;
652 user_info->password.response.nt.data = talloc_steal(user_info, ntlmssp_state->nt_resp.data);
654 nt_status = auth_context->check_password(auth_context,
657 &gensec_ntlmssp->server_info);
658 talloc_free(user_info);
659 NT_STATUS_NOT_OK_RETURN(nt_status);
661 if (gensec_ntlmssp->server_info->user_session_key.length) {
662 DEBUG(10, ("Got NT session key of length %u\n",
663 (unsigned)gensec_ntlmssp->server_info->user_session_key.length));
664 *user_session_key = gensec_ntlmssp->server_info->user_session_key;
666 if (gensec_ntlmssp->server_info->lm_session_key.length) {
667 DEBUG(10, ("Got LM session key of length %u\n",
668 (unsigned)gensec_ntlmssp->server_info->lm_session_key.length));
669 *lm_session_key = gensec_ntlmssp->server_info->lm_session_key;
675 * Return the credentials of a logged on user, including session keys
678 * Only valid after a successful authentication
680 * May only be called once per authentication.
684 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
685 struct auth_session_info **session_info)
688 struct gensec_ntlmssp_context *gensec_ntlmssp =
689 talloc_get_type_abort(gensec_security->private_data,
690 struct gensec_ntlmssp_context);
691 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
693 nt_status = gensec_generate_session_info(ntlmssp_state,
695 gensec_ntlmssp->server_info,
697 NT_STATUS_NOT_OK_RETURN(nt_status);
699 (*session_info)->session_key = data_blob_talloc(*session_info,
700 ntlmssp_state->session_key.data,
701 ntlmssp_state->session_key.length);
707 * Start NTLMSSP on the server side
710 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security)
713 struct ntlmssp_state *ntlmssp_state;
714 struct gensec_ntlmssp_context *gensec_ntlmssp;
716 nt_status = gensec_ntlmssp_start(gensec_security);
717 NT_STATUS_NOT_OK_RETURN(nt_status);
719 gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data,
720 struct gensec_ntlmssp_context);
721 ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
723 ntlmssp_state->role = NTLMSSP_SERVER;
725 ntlmssp_state->expected_state = NTLMSSP_NEGOTIATE;
727 ntlmssp_state->allow_lm_key = (lpcfg_lanman_auth(gensec_security->settings->lp_ctx)
728 && gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "allow_lm_key", false));
730 ntlmssp_state->neg_flags =
731 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION;
733 ntlmssp_state->lm_resp = data_blob(NULL, 0);
734 ntlmssp_state->nt_resp = data_blob(NULL, 0);
736 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "128bit", true)) {
737 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128;
740 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "56bit", true)) {
741 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56;
744 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "keyexchange", true)) {
745 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH;
748 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "alwayssign", true)) {
749 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
752 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "ntlm2", true)) {
753 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
756 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
757 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
759 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
760 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
763 gensec_ntlmssp->auth_context = gensec_security->auth_context;
765 ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
766 ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
767 ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
768 ntlmssp_state->check_password = auth_ntlmssp_check_password;
769 if (lpcfg_server_role(gensec_security->settings->lp_ctx) == ROLE_STANDALONE) {
770 ntlmssp_state->server.is_standalone = true;
772 ntlmssp_state->server.is_standalone = false;
775 ntlmssp_state->server.netbios_name = lpcfg_netbios_name(gensec_security->settings->lp_ctx);
777 ntlmssp_state->server.netbios_domain = lpcfg_workgroup(gensec_security->settings->lp_ctx);
780 char dnsdomname[MAXHOSTNAMELEN], dnsname[MAXHOSTNAMELEN];
782 /* Find out the DNS domain name */
783 dnsdomname[0] = '\0';
784 safe_strcpy(dnsdomname, lpcfg_dnsdomain(gensec_security->settings->lp_ctx), sizeof(dnsdomname) - 1);
786 /* Find out the DNS host name */
787 safe_strcpy(dnsname, ntlmssp_state->server.netbios_name, sizeof(dnsname) - 1);
788 if (dnsdomname[0] != '\0') {
789 safe_strcat(dnsname, ".", sizeof(dnsname) - 1);
790 safe_strcat(dnsname, dnsdomname, sizeof(dnsname) - 1);
794 ntlmssp_state->server.dns_name = talloc_strdup(ntlmssp_state,
796 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_name);
798 ntlmssp_state->server.dns_domain = talloc_strdup(ntlmssp_state,
800 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_domain);