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 "../libcli/auth/libcli_auth.h"
29 #include "../lib/crypto/crypto.h"
30 #include "auth/gensec/gensec.h"
31 #include "auth/gensec/gensec_proto.h"
32 #include "auth/auth.h"
33 #include "param/param.h"
36 * Set a username on an NTLMSSP context - ensures it is talloc()ed
40 static NTSTATUS ntlmssp_set_username(struct ntlmssp_state *ntlmssp_state, const char *user)
43 /* it should be at least "" */
44 DEBUG(1, ("NTLMSSP failed to set username - cannot accept NULL username\n"));
45 return NT_STATUS_INVALID_PARAMETER;
47 ntlmssp_state->user = talloc_strdup(ntlmssp_state, user);
48 if (!ntlmssp_state->user) {
49 return NT_STATUS_NO_MEMORY;
55 * Set a domain on an NTLMSSP context - ensures it is talloc()ed
58 static NTSTATUS ntlmssp_set_domain(struct ntlmssp_state *ntlmssp_state, const char *domain)
60 ntlmssp_state->domain = talloc_strdup(ntlmssp_state, domain);
61 if (!ntlmssp_state->domain) {
62 return NT_STATUS_NO_MEMORY;
68 * Set a workstation on an NTLMSSP context - ensures it is talloc()ed
71 static NTSTATUS ntlmssp_set_workstation(struct ntlmssp_state *ntlmssp_state, const char *workstation)
73 ntlmssp_state->workstation = talloc_strdup(ntlmssp_state, workstation);
74 if (!ntlmssp_state->workstation) {
75 return NT_STATUS_NO_MEMORY;
81 * Determine correct target name flags for reply, given server role
82 * and negotiated flags
84 * @param ntlmssp_state NTLMSSP State
85 * @param neg_flags The flags from the packet
86 * @param chal_flags The flags to be set in the reply packet
87 * @return The 'target name' string.
90 static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
91 uint32_t neg_flags, uint32_t *chal_flags)
93 if (neg_flags & NTLMSSP_REQUEST_TARGET) {
94 *chal_flags |= NTLMSSP_NEGOTIATE_TARGET_INFO;
95 *chal_flags |= NTLMSSP_REQUEST_TARGET;
96 if (ntlmssp_state->server.is_standalone) {
97 *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
98 return ntlmssp_state->server.netbios_name;
100 *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
101 return ntlmssp_state->server.netbios_domain;
111 * Next state function for the Negotiate packet
113 * @param gensec_security GENSEC state
114 * @param out_mem_ctx Memory context for *out
115 * @param in The request, as a DATA_BLOB. reply.data must be NULL
116 * @param out The reply, as an allocated DATA_BLOB, caller to free.
117 * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
120 NTSTATUS ntlmssp_server_negotiate(struct gensec_security *gensec_security,
121 TALLOC_CTX *out_mem_ctx,
122 const DATA_BLOB in, DATA_BLOB *out)
124 struct gensec_ntlmssp_context *gensec_ntlmssp =
125 talloc_get_type_abort(gensec_security->private_data,
126 struct gensec_ntlmssp_context);
127 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
128 DATA_BLOB struct_blob;
129 uint32_t neg_flags = 0;
130 uint32_t ntlmssp_command, chal_flags;
132 const char *target_name;
135 /* parse the NTLMSSP packet */
137 file_save("ntlmssp_negotiate.dat", request.data, request.length);
141 if ((in.length < 16) || !msrpc_parse(out_mem_ctx,
146 DEBUG(1, ("ntlmssp_server_negotiate: failed to parse "
147 "NTLMSSP Negotiate of length %u:\n",
148 (unsigned int)in.length ));
149 dump_data(2, in.data, in.length);
150 return NT_STATUS_INVALID_PARAMETER;
152 debug_ntlmssp_flags(neg_flags);
155 ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, ntlmssp_state->allow_lm_key);
157 /* Ask our caller what challenge they would like in the packet */
158 status = ntlmssp_state->get_challenge(ntlmssp_state, cryptkey);
159 if (!NT_STATUS_IS_OK(status)) {
160 DEBUG(1, ("ntlmssp_server_negotiate: backend doesn't give a challenge: %s\n",
165 /* Check if we may set the challenge */
166 if (!ntlmssp_state->may_set_challenge(ntlmssp_state)) {
167 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
170 /* The flags we send back are not just the negotiated flags,
171 * they are also 'what is in this packet'. Therfore, we
172 * operate on 'chal_flags' from here on
175 chal_flags = ntlmssp_state->neg_flags;
177 /* get the right name to fill in as 'target' */
178 target_name = ntlmssp_target_name(ntlmssp_state,
179 neg_flags, &chal_flags);
180 if (target_name == NULL)
181 return NT_STATUS_INVALID_PARAMETER;
183 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
184 ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state, cryptkey, 8);
186 /* This creates the 'blob' of names that appears at the end of the packet */
187 if (chal_flags & NTLMSSP_NEGOTIATE_TARGET_INFO) {
188 msrpc_gen(out_mem_ctx,
189 &struct_blob, "aaaaa",
190 MsvAvNbDomainName, target_name,
191 MsvAvNbComputerName, ntlmssp_state->server.netbios_name,
192 MsvAvDnsDomainName, ntlmssp_state->server.dns_domain,
193 MsvAvDnsComputerName, ntlmssp_state->server.dns_name,
196 struct_blob = data_blob(NULL, 0);
200 /* Marshal the packet in the right format, be it unicode or ASCII */
201 const char *gen_string;
202 if (ntlmssp_state->unicode) {
203 gen_string = "CdUdbddB";
205 gen_string = "CdAdbddB";
208 msrpc_gen(out_mem_ctx,
216 struct_blob.data, struct_blob.length);
219 ntlmssp_state->expected_state = NTLMSSP_AUTH;
221 return NT_STATUS_MORE_PROCESSING_REQUIRED;
224 struct ntlmssp_server_auth_state {
225 DATA_BLOB user_session_key;
226 DATA_BLOB lm_session_key;
227 /* internal variables used by KEY_EXCH (client-supplied user session key */
228 DATA_BLOB encrypted_session_key;
230 /* internal variables used by NTLM2 */
231 uint8_t session_nonce[16];
235 * Next state function for the Authenticate packet
237 * @param ntlmssp_state NTLMSSP State
238 * @param request The request, as a DATA_BLOB
239 * @return Errors or NT_STATUS_OK.
242 static NTSTATUS ntlmssp_server_preauth(struct ntlmssp_state *ntlmssp_state,
243 struct ntlmssp_server_auth_state *state,
244 const DATA_BLOB request)
246 uint32_t ntlmssp_command, auth_flags;
249 uint8_t session_nonce_hash[16];
251 const char *parse_string;
254 char *workstation = NULL;
257 file_save("ntlmssp_auth.dat", request.data, request.length);
260 if (ntlmssp_state->unicode) {
261 parse_string = "CdBBUUUBd";
263 parse_string = "CdBBAAABd";
267 data_blob_free(&ntlmssp_state->session_key);
268 data_blob_free(&ntlmssp_state->lm_resp);
269 data_blob_free(&ntlmssp_state->nt_resp);
271 ntlmssp_state->user = NULL;
272 ntlmssp_state->domain = NULL;
273 ntlmssp_state->workstation = NULL;
275 /* now the NTLMSSP encoded auth hashes */
276 if (!msrpc_parse(ntlmssp_state,
277 &request, parse_string,
280 &ntlmssp_state->lm_resp,
281 &ntlmssp_state->nt_resp,
285 &state->encrypted_session_key,
287 DEBUG(10, ("ntlmssp_server_auth: failed to parse NTLMSSP (nonfatal):\n"));
288 dump_data(10, request.data, request.length);
291 data_blob_free(&state->encrypted_session_key);
294 /* Try again with a shorter string (Win9X truncates this packet) */
295 if (ntlmssp_state->unicode) {
296 parse_string = "CdBBUUU";
298 parse_string = "CdBBAAA";
301 /* now the NTLMSSP encoded auth hashes */
302 if (!msrpc_parse(ntlmssp_state,
303 &request, parse_string,
306 &ntlmssp_state->lm_resp,
307 &ntlmssp_state->nt_resp,
311 DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP:\n"));
312 dump_data(2, request.data, request.length);
314 return NT_STATUS_INVALID_PARAMETER;
318 talloc_steal(state, state->encrypted_session_key.data);
321 ntlmssp_handle_neg_flags(ntlmssp_state, auth_flags, ntlmssp_state->allow_lm_key);
323 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_domain(ntlmssp_state, domain))) {
327 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_username(ntlmssp_state, user))) {
331 if (!NT_STATUS_IS_OK(nt_status = ntlmssp_set_workstation(ntlmssp_state, workstation))) {
335 DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%lu len2=%lu\n",
336 ntlmssp_state->user, ntlmssp_state->domain, ntlmssp_state->workstation, (unsigned long)ntlmssp_state->lm_resp.length, (unsigned long)ntlmssp_state->nt_resp.length));
339 file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length);
340 file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length);
343 /* NTLM2 uses a 'challenge' that is made of up both the server challenge, and a
346 However, the NTLM2 flag may still be set for the real NTLMv2 logins, be careful.
348 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
349 if (ntlmssp_state->nt_resp.length == 24 && ntlmssp_state->lm_resp.length == 24) {
350 struct MD5Context md5_session_nonce_ctx;
351 SMB_ASSERT(ntlmssp_state->internal_chal.data
352 && ntlmssp_state->internal_chal.length == 8);
354 state->doing_ntlm2 = true;
356 memcpy(state->session_nonce, ntlmssp_state->internal_chal.data, 8);
357 memcpy(&state->session_nonce[8], ntlmssp_state->lm_resp.data, 8);
359 MD5Init(&md5_session_nonce_ctx);
360 MD5Update(&md5_session_nonce_ctx, state->session_nonce, 16);
361 MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
363 ntlmssp_state->chal = data_blob_talloc(ntlmssp_state,
364 session_nonce_hash, 8);
366 /* LM response is no longer useful, zero it out */
367 data_blob_free(&ntlmssp_state->lm_resp);
369 /* We changed the effective challenge - set it */
370 if (!NT_STATUS_IS_OK(nt_status =
371 ntlmssp_state->set_challenge(ntlmssp_state,
372 &ntlmssp_state->chal))) {
376 /* LM Key is incompatible... */
377 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
384 * Next state function for the Authenticate packet
385 * (after authentication - figures out the session keys etc)
387 * @param ntlmssp_state NTLMSSP State
388 * @return Errors or NT_STATUS_OK.
391 static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
392 struct ntlmssp_server_auth_state *state)
394 struct gensec_ntlmssp_context *gensec_ntlmssp =
395 talloc_get_type_abort(gensec_security->private_data,
396 struct gensec_ntlmssp_context);
397 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
398 DATA_BLOB *user_session_key = &state->user_session_key;
399 DATA_BLOB *lm_session_key = &state->lm_session_key;
401 DATA_BLOB session_key = data_blob(NULL, 0);
403 if (!(gensec_security->want_features
404 & (GENSEC_FEATURE_SIGN|GENSEC_FEATURE_SEAL|GENSEC_FEATURE_SESSION_KEY))) {
408 if (user_session_key)
409 dump_data_pw("USER session key:\n", user_session_key->data, user_session_key->length);
412 dump_data_pw("LM first-8:\n", lm_session_key->data, lm_session_key->length);
414 /* Handle the different session key derivation for NTLM2 */
415 if (state->doing_ntlm2) {
416 if (user_session_key && user_session_key->data && user_session_key->length == 16) {
417 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
418 hmac_md5(user_session_key->data, state->session_nonce,
419 sizeof(state->session_nonce), session_key.data);
420 DEBUG(10,("ntlmssp_server_auth: Created NTLM2 session key.\n"));
421 dump_data_pw("NTLM2 session key:\n", session_key.data, session_key.length);
424 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM2 session key.\n"));
425 session_key = data_blob(NULL, 0);
427 } else if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
428 /* Ensure we can never get here on NTLMv2 */
429 && (ntlmssp_state->nt_resp.length == 0 || ntlmssp_state->nt_resp.length == 24)) {
431 if (lm_session_key && lm_session_key->data && lm_session_key->length >= 8) {
432 if (ntlmssp_state->lm_resp.data && ntlmssp_state->lm_resp.length == 24) {
433 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
434 SMBsesskeygen_lm_sess_key(lm_session_key->data, ntlmssp_state->lm_resp.data,
436 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
437 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
440 /* When there is no LM response, just use zeros */
441 static const uint8_t zeros[24];
442 session_key = data_blob_talloc(ntlmssp_state, NULL, 16);
443 SMBsesskeygen_lm_sess_key(zeros, zeros,
445 DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
446 dump_data_pw("LM session key:\n", session_key.data, session_key.length);
449 /* LM Key not selected */
450 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
452 DEBUG(10,("ntlmssp_server_auth: Failed to create NTLM session key.\n"));
453 session_key = data_blob(NULL, 0);
456 } else if (user_session_key && user_session_key->data) {
457 session_key = data_blob_talloc(ntlmssp_state, user_session_key->data, user_session_key->length);
458 DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
459 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
461 /* LM Key not selected */
462 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
464 } else if (lm_session_key && lm_session_key->data) {
465 /* Very weird to have LM key, but no user session key, but anyway.. */
466 session_key = data_blob_talloc(ntlmssp_state, lm_session_key->data, lm_session_key->length);
467 DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
468 dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
470 /* LM Key not selected */
471 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
474 DEBUG(10,("ntlmssp_server_auth: Failed to create unmodified session key.\n"));
475 session_key = data_blob(NULL, 0);
477 /* LM Key not selected */
478 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
481 /* With KEY_EXCH, the client supplies the proposed session key,
482 but encrypts it with the long-term key */
483 if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH) {
484 if (!state->encrypted_session_key.data
485 || state->encrypted_session_key.length != 16) {
486 data_blob_free(&state->encrypted_session_key);
487 DEBUG(1, ("Client-supplied KEY_EXCH session key was of invalid length (%u)!\n",
488 (unsigned)state->encrypted_session_key.length));
489 return NT_STATUS_INVALID_PARAMETER;
490 } else if (!session_key.data || session_key.length != 16) {
491 DEBUG(5, ("server session key is invalid (len == %u), cannot do KEY_EXCH!\n",
492 (unsigned)session_key.length));
493 ntlmssp_state->session_key = session_key;
495 dump_data_pw("KEY_EXCH session key (enc):\n",
496 state->encrypted_session_key.data,
497 state->encrypted_session_key.length);
498 arcfour_crypt(state->encrypted_session_key.data,
500 state->encrypted_session_key.length);
501 ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
502 state->encrypted_session_key.data,
503 state->encrypted_session_key.length);
504 dump_data_pw("KEY_EXCH session key:\n",
505 state->encrypted_session_key.data,
506 state->encrypted_session_key.length);
507 talloc_free(session_key.data);
510 ntlmssp_state->session_key = session_key;
513 if ((gensec_security->want_features & GENSEC_FEATURE_SIGN)
514 || (gensec_security->want_features & GENSEC_FEATURE_SEAL)) {
515 nt_status = ntlmssp_sign_init(ntlmssp_state);
517 nt_status = NT_STATUS_OK;
520 ntlmssp_state->expected_state = NTLMSSP_DONE;
527 * Next state function for the Authenticate packet
529 * @param gensec_security GENSEC state
530 * @param out_mem_ctx Memory context for *out
531 * @param in The request, as a DATA_BLOB. reply.data must be NULL
532 * @param out The reply, as an allocated DATA_BLOB, caller to free.
533 * @return Errors or NT_STATUS_OK if authentication sucessful
536 NTSTATUS ntlmssp_server_auth(struct gensec_security *gensec_security,
537 TALLOC_CTX *out_mem_ctx,
538 const DATA_BLOB in, DATA_BLOB *out)
540 struct gensec_ntlmssp_context *gensec_ntlmssp =
541 talloc_get_type_abort(gensec_security->private_data,
542 struct gensec_ntlmssp_context);
543 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
544 struct ntlmssp_server_auth_state *state;
547 /* zero the outbound NTLMSSP packet */
548 *out = data_blob_null;
550 state = talloc_zero(ntlmssp_state, struct ntlmssp_server_auth_state);
552 return NT_STATUS_NO_MEMORY;
555 nt_status = ntlmssp_server_preauth(ntlmssp_state, state, in);
556 if (!NT_STATUS_IS_OK(nt_status)) {
562 * Note we don't check here for NTLMv2 auth settings. If NTLMv2 auth
563 * is required (by "ntlm auth = no" and "lm auth = no" being set in the
564 * smb.conf file) and no NTLMv2 response was sent then the password check
565 * will fail here. JRA.
568 /* Finally, actually ask if the password is OK */
569 nt_status = ntlmssp_state->check_password(ntlmssp_state,
570 &state->user_session_key,
571 &state->lm_session_key);
572 if (!NT_STATUS_IS_OK(nt_status)) {
577 nt_status = ntlmssp_server_postauth(gensec_security, state);
578 if (!NT_STATUS_IS_OK(nt_status)) {
588 * Return the challenge as determined by the authentication subsystem
589 * @return an 8 byte random challenge
592 static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
595 struct gensec_ntlmssp_context *gensec_ntlmssp =
596 talloc_get_type_abort(ntlmssp_state->callback_private,
597 struct gensec_ntlmssp_context);
598 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
601 status = auth_context->get_challenge(auth_context, chal);
602 if (!NT_STATUS_IS_OK(status)) {
603 DEBUG(1, ("auth_ntlmssp_get_challenge: failed to get challenge: %s\n",
612 * Some authentication methods 'fix' the challenge, so we may not be able to set it
614 * @return If the effective challenge used by the auth subsystem may be modified
616 static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
618 struct gensec_ntlmssp_context *gensec_ntlmssp =
619 talloc_get_type_abort(ntlmssp_state->callback_private,
620 struct gensec_ntlmssp_context);
621 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
623 return auth_context->challenge_may_be_modified(auth_context);
627 * NTLM2 authentication modifies the effective challenge,
628 * @param challenge The new challenge value
630 static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
632 struct gensec_ntlmssp_context *gensec_ntlmssp =
633 talloc_get_type_abort(ntlmssp_state->callback_private,
634 struct gensec_ntlmssp_context);
635 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
639 if (challenge->length != 8) {
640 return NT_STATUS_INVALID_PARAMETER;
643 chal = challenge->data;
645 nt_status = auth_context->set_challenge(auth_context,
647 "NTLMSSP callback (NTLM2)");
653 * Check the password on an NTLMSSP login.
655 * Return the session keys used on the connection.
658 static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
659 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
661 struct gensec_ntlmssp_context *gensec_ntlmssp =
662 talloc_get_type_abort(ntlmssp_state->callback_private,
663 struct gensec_ntlmssp_context);
664 struct auth_context *auth_context = gensec_ntlmssp->auth_context;
666 struct auth_usersupplied_info *user_info;
668 user_info = talloc(ntlmssp_state, struct auth_usersupplied_info);
670 return NT_STATUS_NO_MEMORY;
673 user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT;
674 user_info->flags = 0;
675 user_info->mapped_state = false;
676 user_info->client.account_name = ntlmssp_state->user;
677 user_info->client.domain_name = ntlmssp_state->domain;
678 user_info->workstation_name = ntlmssp_state->workstation;
679 user_info->remote_host = gensec_get_remote_address(gensec_ntlmssp->gensec_security);
681 user_info->password_state = AUTH_PASSWORD_RESPONSE;
682 user_info->password.response.lanman = ntlmssp_state->lm_resp;
683 user_info->password.response.lanman.data = talloc_steal(user_info, ntlmssp_state->lm_resp.data);
684 user_info->password.response.nt = ntlmssp_state->nt_resp;
685 user_info->password.response.nt.data = talloc_steal(user_info, ntlmssp_state->nt_resp.data);
687 nt_status = auth_context->check_password(auth_context,
690 &gensec_ntlmssp->server_info);
691 talloc_free(user_info);
692 NT_STATUS_NOT_OK_RETURN(nt_status);
694 if (gensec_ntlmssp->server_info->user_session_key.length) {
695 DEBUG(10, ("Got NT session key of length %u\n",
696 (unsigned)gensec_ntlmssp->server_info->user_session_key.length));
697 *user_session_key = gensec_ntlmssp->server_info->user_session_key;
699 if (gensec_ntlmssp->server_info->lm_session_key.length) {
700 DEBUG(10, ("Got LM session key of length %u\n",
701 (unsigned)gensec_ntlmssp->server_info->lm_session_key.length));
702 *lm_session_key = gensec_ntlmssp->server_info->lm_session_key;
708 * Return the credentials of a logged on user, including session keys
711 * Only valid after a successful authentication
713 * May only be called once per authentication.
717 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
718 struct auth_session_info **session_info)
721 struct gensec_ntlmssp_context *gensec_ntlmssp =
722 talloc_get_type_abort(gensec_security->private_data,
723 struct gensec_ntlmssp_context);
724 struct ntlmssp_state *ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
726 nt_status = gensec_generate_session_info(ntlmssp_state,
728 gensec_ntlmssp->server_info,
730 NT_STATUS_NOT_OK_RETURN(nt_status);
732 (*session_info)->session_key = data_blob_talloc(*session_info,
733 ntlmssp_state->session_key.data,
734 ntlmssp_state->session_key.length);
740 * Start NTLMSSP on the server side
743 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security)
746 struct ntlmssp_state *ntlmssp_state;
747 struct gensec_ntlmssp_context *gensec_ntlmssp;
749 nt_status = gensec_ntlmssp_start(gensec_security);
750 NT_STATUS_NOT_OK_RETURN(nt_status);
752 gensec_ntlmssp = talloc_get_type_abort(gensec_security->private_data,
753 struct gensec_ntlmssp_context);
754 ntlmssp_state = gensec_ntlmssp->ntlmssp_state;
756 ntlmssp_state->role = NTLMSSP_SERVER;
758 ntlmssp_state->expected_state = NTLMSSP_NEGOTIATE;
760 ntlmssp_state->allow_lm_key = (lp_lanman_auth(gensec_security->settings->lp_ctx)
761 && gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "allow_lm_key", false));
763 ntlmssp_state->neg_flags =
764 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_VERSION;
766 ntlmssp_state->lm_resp = data_blob(NULL, 0);
767 ntlmssp_state->nt_resp = data_blob(NULL, 0);
769 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "128bit", true)) {
770 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_128;
773 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "56bit", true)) {
774 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_56;
777 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "keyexchange", true)) {
778 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_KEY_EXCH;
781 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "alwayssign", true)) {
782 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
785 if (gensec_setting_bool(gensec_security->settings, "ntlmssp_server", "ntlm2", true)) {
786 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
789 if (gensec_security->want_features & GENSEC_FEATURE_SIGN) {
790 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
792 if (gensec_security->want_features & GENSEC_FEATURE_SEAL) {
793 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
796 gensec_ntlmssp->auth_context = gensec_security->auth_context;
798 ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
799 ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
800 ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
801 ntlmssp_state->check_password = auth_ntlmssp_check_password;
802 if (lp_server_role(gensec_security->settings->lp_ctx) == ROLE_STANDALONE) {
803 ntlmssp_state->server.is_standalone = true;
805 ntlmssp_state->server.is_standalone = false;
808 ntlmssp_state->server.netbios_name = lp_netbios_name(gensec_security->settings->lp_ctx);
810 ntlmssp_state->server.netbios_domain = lp_workgroup(gensec_security->settings->lp_ctx);
813 char dnsdomname[MAXHOSTNAMELEN], dnsname[MAXHOSTNAMELEN];
815 /* Find out the DNS domain name */
816 dnsdomname[0] = '\0';
817 safe_strcpy(dnsdomname, lp_dnsdomain(gensec_security->settings->lp_ctx), sizeof(dnsdomname) - 1);
819 /* Find out the DNS host name */
820 safe_strcpy(dnsname, ntlmssp_state->server.netbios_name, sizeof(dnsname) - 1);
821 if (dnsdomname[0] != '\0') {
822 safe_strcat(dnsname, ".", sizeof(dnsname) - 1);
823 safe_strcat(dnsname, dnsdomname, sizeof(dnsname) - 1);
827 ntlmssp_state->server.dns_name = talloc_strdup(ntlmssp_state,
829 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_name);
831 ntlmssp_state->server.dns_domain = talloc_strdup(ntlmssp_state,
833 NT_STATUS_HAVE_NO_MEMORY(ntlmssp_state->server.dns_domain);