2 Unix SMB/Netbios implementation.
4 handle NLTMSSP, server side
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2001-2003
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Print out the NTLMSSP flags for debugging
28 * @param neg_flags The flags from the packet
31 void debug_ntlmssp_flags(uint32 neg_flags)
33 DEBUG(3,("Got NTLMSSP neg_flags=0x%08x\n", neg_flags));
35 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE)
36 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_UNICODE\n"));
37 if (neg_flags & NTLMSSP_NEGOTIATE_OEM)
38 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_OEM\n"));
39 if (neg_flags & NTLMSSP_REQUEST_TARGET)
40 DEBUGADD(4, (" NTLMSSP_REQUEST_TARGET\n"));
41 if (neg_flags & NTLMSSP_NEGOTIATE_SIGN)
42 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_SIGN\n"));
43 if (neg_flags & NTLMSSP_NEGOTIATE_SEAL)
44 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_SEAL\n"));
45 if (neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
46 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_LM_KEY\n"));
47 if (neg_flags & NTLMSSP_NEGOTIATE_NETWARE)
48 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NETWARE\n"));
49 if (neg_flags & NTLMSSP_NEGOTIATE_NTLM)
50 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NTLM\n"));
51 if (neg_flags & NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED)
52 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED\n"));
53 if (neg_flags & NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED)
54 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED\n"));
55 if (neg_flags & NTLMSSP_NEGOTIATE_THIS_IS_LOCAL_CALL)
56 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_THIS_IS_LOCAL_CALL\n"));
57 if (neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)
58 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_ALWAYS_SIGN\n"));
59 if (neg_flags & NTLMSSP_NEGOTIATE_NTLM2)
60 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_NTLM2\n"));
61 if (neg_flags & NTLMSSP_CHAL_TARGET_INFO)
62 DEBUGADD(4, (" NTLMSSP_CHAL_TARGET_INFO\n"));
63 if (neg_flags & NTLMSSP_NEGOTIATE_128)
64 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_128\n"));
65 if (neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH)
66 DEBUGADD(4, (" NTLMSSP_NEGOTIATE_KEY_EXCH\n"));
70 * Default challenge generation code.
74 static const uint8 *get_challenge(struct ntlmssp_state *ntlmssp_state)
77 generate_random_buffer(chal, sizeof(chal), False);
83 * Determine correct target name flags for reply, given server role
84 * and negotiated flags
86 * @param ntlmssp_state NTLMSSP State
87 * @param neg_flags The flags from the packet
88 * @param chal_flags The flags to be set in the reply packet
89 * @return The 'target name' string.
92 static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
93 uint32 neg_flags, uint32 *chal_flags)
95 if (neg_flags & NTLMSSP_REQUEST_TARGET) {
96 *chal_flags |= NTLMSSP_CHAL_TARGET_INFO;
97 *chal_flags |= NTLMSSP_REQUEST_TARGET;
98 if (ntlmssp_state->server_role == ROLE_STANDALONE) {
99 *chal_flags |= NTLMSSP_TARGET_TYPE_SERVER;
100 return ntlmssp_state->get_global_myname();
102 *chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN;
103 return ntlmssp_state->get_domain();
111 * Next state function for the Negotiate packet
113 * @param ntlmssp_state NTLMSSP State
114 * @param request The request, as a DATA_BLOB
115 * @param request The reply, as an allocated DATA_BLOB, caller to free.
116 * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent.
119 static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
120 const DATA_BLOB request, DATA_BLOB *reply)
122 DATA_BLOB struct_blob;
123 fstring dnsname, dnsdomname;
124 uint32 neg_flags = 0;
125 uint32 ntlmssp_command, chal_flags;
126 char *cliname=NULL, *domname=NULL;
127 const uint8 *cryptkey;
128 const char *target_name;
130 /* parse the NTLMSSP packet */
132 file_save("ntlmssp_negotiate.dat", request.data, request.length);
135 if (request.length) {
136 if (!msrpc_parse(&request, "CddAA",
142 DEBUG(1, ("ntlmssp_server_negotiate: failed to parse NTLMSSP:\n"));
143 dump_data(2, request.data, request.length);
144 return NT_STATUS_INVALID_PARAMETER;
150 debug_ntlmssp_flags(neg_flags);
153 cryptkey = ntlmssp_state->get_challenge(ntlmssp_state);
155 data_blob_free(&ntlmssp_state->chal);
156 ntlmssp_state->chal = data_blob(cryptkey, 8);
158 /* Give them the challenge. For now, ignore neg_flags and just
159 return the flags we want. Obviously this is not correct */
162 NTLMSSP_NEGOTIATE_128 |
163 NTLMSSP_NEGOTIATE_NTLM;
165 if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
166 chal_flags |= NTLMSSP_NEGOTIATE_UNICODE;
167 ntlmssp_state->unicode = True;
169 chal_flags |= NTLMSSP_NEGOTIATE_OEM;
172 target_name = ntlmssp_target_name(ntlmssp_state,
173 neg_flags, &chal_flags);
175 /* This should be a 'netbios domain -> DNS domain' mapping */
176 dnsdomname[0] = '\0';
177 get_mydomname(dnsdomname);
178 strlower_m(dnsdomname);
181 get_myfullname(dnsname);
184 if (chal_flags & NTLMSSP_CHAL_TARGET_INFO)
186 const char *target_name_dns = "";
187 if (chal_flags |= NTLMSSP_TARGET_TYPE_DOMAIN) {
188 target_name_dns = dnsdomname;
189 } else if (chal_flags |= NTLMSSP_TARGET_TYPE_SERVER) {
190 target_name_dns = dnsname;
193 msrpc_gen(&struct_blob, "aaaaa",
194 ntlmssp_state->unicode, NTLMSSP_NAME_TYPE_DOMAIN, target_name,
195 ntlmssp_state->unicode, NTLMSSP_NAME_TYPE_SERVER, ntlmssp_state->get_global_myname(),
196 ntlmssp_state->unicode, NTLMSSP_NAME_TYPE_DOMAIN_DNS, target_name_dns,
197 ntlmssp_state->unicode, NTLMSSP_NAME_TYPE_SERVER_DNS, dnsdomname,
198 ntlmssp_state->unicode, 0, "");
200 struct_blob = data_blob(NULL, 0);
204 const char *gen_string;
205 if (ntlmssp_state->unicode) {
206 gen_string = "CdUdbddB";
208 gen_string = "CdAdbddB";
211 msrpc_gen(reply, gen_string,
218 struct_blob.data, struct_blob.length);
221 data_blob_free(&struct_blob);
223 ntlmssp_state->expected_state = NTLMSSP_AUTH;
225 return NT_STATUS_MORE_PROCESSING_REQUIRED;
229 * Next state function for the Authenticate packet
231 * @param ntlmssp_state NTLMSSP State
232 * @param request The request, as a DATA_BLOB
233 * @param request The reply, as an allocated DATA_BLOB, caller to free.
234 * @return Errors or NT_STATUS_OK.
237 static NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
238 const DATA_BLOB request, DATA_BLOB *reply)
241 uint32 ntlmssp_command, neg_flags;
244 const char *parse_string;
246 /* parse the NTLMSSP packet */
248 file_save("ntlmssp_auth.dat", request.data, request.length);
251 if (ntlmssp_state->unicode) {
252 parse_string = "CdBBUUUBd";
254 parse_string = "CdBBAAABd";
257 data_blob_free(&ntlmssp_state->lm_resp);
258 data_blob_free(&ntlmssp_state->nt_resp);
260 SAFE_FREE(ntlmssp_state->user);
261 SAFE_FREE(ntlmssp_state->domain);
262 SAFE_FREE(ntlmssp_state->workstation);
264 /* now the NTLMSSP encoded auth hashes */
265 if (!msrpc_parse(&request, parse_string,
268 &ntlmssp_state->lm_resp,
269 &ntlmssp_state->nt_resp,
270 &ntlmssp_state->domain,
271 &ntlmssp_state->user,
272 &ntlmssp_state->workstation,
275 DEBUG(1, ("ntlmssp_server_auth: failed to parse NTLMSSP:\n"));
276 dump_data(2, request.data, request.length);
277 return NT_STATUS_INVALID_PARAMETER;
280 data_blob_free(&sess_key);
282 DEBUG(3,("Got user=[%s] domain=[%s] workstation=[%s] len1=%d len2=%d\n",
283 ntlmssp_state->user, ntlmssp_state->domain, ntlmssp_state->workstation, ntlmssp_state->lm_resp.length, ntlmssp_state->nt_resp.length));
286 file_save("nthash1.dat", &ntlmssp_state->nt_resp.data, &ntlmssp_state->nt_resp.length);
287 file_save("lmhash1.dat", &ntlmssp_state->lm_resp.data, &ntlmssp_state->lm_resp.length);
290 nt_status = ntlmssp_state->check_password(ntlmssp_state);
292 *reply = data_blob(NULL, 0);
298 * Create an NTLMSSP state machine
300 * @param ntlmssp_state NTLMSSP State, allocated by this function
303 NTSTATUS ntlmssp_server_start(NTLMSSP_STATE **ntlmssp_state)
307 mem_ctx = talloc_init("NTLMSSP context");
309 *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state));
310 if (!*ntlmssp_state) {
311 DEBUG(0,("ntlmssp_server_start: talloc failed!\n"));
312 talloc_destroy(mem_ctx);
313 return NT_STATUS_NO_MEMORY;
316 (*ntlmssp_state)->mem_ctx = mem_ctx;
317 (*ntlmssp_state)->get_challenge = get_challenge;
319 (*ntlmssp_state)->get_global_myname = global_myname;
320 (*ntlmssp_state)->get_domain = lp_workgroup;
321 (*ntlmssp_state)->server_role = ROLE_DOMAIN_MEMBER; /* a good default */
323 (*ntlmssp_state)->expected_state = NTLMSSP_NEGOTIATE;
329 * End an NTLMSSP state machine
331 * @param ntlmssp_state NTLMSSP State, free()ed by this function
334 NTSTATUS ntlmssp_server_end(NTLMSSP_STATE **ntlmssp_state)
336 TALLOC_CTX *mem_ctx = (*ntlmssp_state)->mem_ctx;
338 data_blob_free(&(*ntlmssp_state)->chal);
339 data_blob_free(&(*ntlmssp_state)->lm_resp);
340 data_blob_free(&(*ntlmssp_state)->nt_resp);
342 SAFE_FREE((*ntlmssp_state)->user);
343 SAFE_FREE((*ntlmssp_state)->domain);
344 SAFE_FREE((*ntlmssp_state)->workstation);
346 talloc_destroy(mem_ctx);
347 *ntlmssp_state = NULL;
352 * Next state function for the NTLMSSP state machine
354 * @param ntlmssp_state NTLMSSP State
355 * @param request The request, as a DATA_BLOB
356 * @param request The reply, as an allocated DATA_BLOB, caller to free.
357 * @return Errors, NT_STATUS_MORE_PROCESSING_REQUIRED or NT_STATUS_OK.
360 NTSTATUS ntlmssp_server_update(NTLMSSP_STATE *ntlmssp_state,
361 const DATA_BLOB request, DATA_BLOB *reply)
363 uint32 ntlmssp_command;
364 *reply = data_blob(NULL, 0);
366 if (request.length) {
367 if (!msrpc_parse(&request, "Cd",
370 return NT_STATUS_INVALID_PARAMETER;
373 /* 'datagram' mode - no neg packet */
374 ntlmssp_command = NTLMSSP_NEGOTIATE;
377 if (ntlmssp_command != ntlmssp_state->expected_state) {
378 DEBUG(1, ("got NTLMSSP command %u, expected %u\n", ntlmssp_command, ntlmssp_state->expected_state));
379 return NT_STATUS_INVALID_PARAMETER;
382 if (ntlmssp_command == NTLMSSP_NEGOTIATE) {
383 return ntlmssp_server_negotiate(ntlmssp_state, request, reply);
384 } else if (ntlmssp_command == NTLMSSP_AUTH) {
385 return ntlmssp_server_auth(ntlmssp_state, request, reply);
387 DEBUG(1, ("unknown NTLMSSP command %u, expected %u\n", ntlmssp_command, ntlmssp_state->expected_state));
388 return NT_STATUS_INVALID_PARAMETER;
392 /*********************************************************************
394 *********************************************************************/
397 * Next state function for the Initial packet
399 * @param ntlmssp_state NTLMSSP State
400 * @param request The request, as a DATA_BLOB. reply.data must be NULL
401 * @param request The reply, as an allocated DATA_BLOB, caller to free.
402 * @return Errors or NT_STATUS_OK.
405 static NTSTATUS ntlmssp_client_initial(struct ntlmssp_client_state *ntlmssp_state,
406 DATA_BLOB reply, DATA_BLOB *next_request)
408 if (ntlmssp_state->unicode) {
409 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
412 if (ntlmssp_state->use_ntlmv2) {
413 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
416 /* generate the ntlmssp negotiate packet */
417 msrpc_gen(next_request, "CddAA",
420 ntlmssp_state->neg_flags,
421 ntlmssp_state->get_domain(),
422 ntlmssp_state->get_global_myname());
424 return NT_STATUS_MORE_PROCESSING_REQUIRED;
428 * Next state function for the Challenge Packet. Generate an auth packet.
430 * @param ntlmssp_state NTLMSSP State
431 * @param request The request, as a DATA_BLOB. reply.data must be NULL
432 * @param request The reply, as an allocated DATA_BLOB, caller to free.
433 * @return Errors or NT_STATUS_OK.
436 static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_client_state *ntlmssp_state,
437 const DATA_BLOB reply, DATA_BLOB *next_request)
439 uint32 chal_flags, ntlmssp_command, unkn1, unkn2;
440 DATA_BLOB server_domain_blob;
441 DATA_BLOB challenge_blob;
442 DATA_BLOB struct_blob = data_blob(NULL, 0);
444 const char *chal_parse_string;
445 const char *auth_gen_string;
446 DATA_BLOB lm_response = data_blob(NULL, 0);
447 DATA_BLOB nt_response = data_blob(NULL, 0);
448 DATA_BLOB session_key = data_blob(NULL, 0);
449 uint8 datagram_sess_key[16];
450 size_t datagram_sess_key_len;
452 #if 0 /* until we know what flag to tigger it on */
453 generate_random_buffer(datagram_sess_key, sizeof(datagram_sess_key), False);
454 datagram_sess_key_len = sizeof(datagram_sess_key);
456 ZERO_STRUCT(datagram_sess_key);
457 datagram_sess_key_len = 0;
460 if (!msrpc_parse(&reply, "CdBd",
465 DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#1)\n"));
466 dump_data(2, reply.data, reply.length);
468 return NT_STATUS_INVALID_PARAMETER;
471 data_blob_free(&server_domain_blob);
473 DEBUG(3, ("Got challenge flags:\n"));
474 debug_ntlmssp_flags(chal_flags);
476 if (chal_flags & NTLMSSP_NEGOTIATE_UNICODE) {
477 if (chal_flags & NTLMSSP_CHAL_TARGET_INFO) {
478 chal_parse_string = "CdUdbddB";
480 chal_parse_string = "CdUdbdd";
482 auth_gen_string = "CdBBUUUBd";
483 ntlmssp_state->unicode = True;
484 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
485 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM;
486 } else if (chal_flags & NTLMSSP_NEGOTIATE_OEM) {
487 if (chal_flags & NTLMSSP_CHAL_TARGET_INFO) {
488 chal_parse_string = "CdAdbddB";
490 chal_parse_string = "CdAdbdd";
492 auth_gen_string = "CdBBAAABd";
493 ntlmssp_state->unicode = False;
494 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE;
495 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM;
497 return NT_STATUS_INVALID_PARAMETER;
500 if (chal_flags & NTLMSSP_NEGOTIATE_LM_KEY && lp_client_lanman_auth()) {
501 /* server forcing us to use LM */
502 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY;
503 ntlmssp_state->use_ntlmv2 = False;
505 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
508 if (!(chal_flags & NTLMSSP_NEGOTIATE_NTLM2)) {
509 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
512 if (!(chal_flags & NTLMSSP_NEGOTIATE_128)) {
513 ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128;
516 DEBUG(3, ("NTLMSSP: Set final flags:\n"));
517 debug_ntlmssp_flags(ntlmssp_state->neg_flags);
519 if (!msrpc_parse(&reply, chal_parse_string,
527 DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#2)\n"));
528 dump_data(2, reply.data, reply.length);
529 return NT_STATUS_INVALID_PARAMETER;
532 SAFE_FREE(server_domain);
533 if (challenge_blob.length != 8) {
534 data_blob_free(&struct_blob);
535 return NT_STATUS_INVALID_PARAMETER;
538 if (ntlmssp_state->use_ntlmv2) {
540 if (!struct_blob.length) {
541 /* be lazy, match win2k - we can't do NTLMv2 without it */
542 return NT_STATUS_INVALID_PARAMETER;
545 /* TODO: if the remote server is standalone, then we should replace 'domain'
546 with the server name as supplied above */
548 if (!SMBNTLMv2encrypt(ntlmssp_state->user,
549 ntlmssp_state->domain,
550 ntlmssp_state->password, &challenge_blob,
552 &lm_response, &nt_response, &session_key)) {
553 data_blob_free(&challenge_blob);
554 data_blob_free(&struct_blob);
555 return NT_STATUS_NO_MEMORY;
560 E_deshash(ntlmssp_state->password, lm_hash);
561 E_md4hash(ntlmssp_state->password, nt_hash);
563 /* lanman auth is insecure, it may be disabled */
564 if (lp_client_lanman_auth()) {
565 lm_response = data_blob(NULL, 24);
566 SMBencrypt(ntlmssp_state->password,challenge_blob.data,
570 nt_response = data_blob(NULL, 24);
571 SMBNTencrypt(ntlmssp_state->password,challenge_blob.data,
574 session_key = data_blob(NULL, 16);
575 if ((ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_LM_KEY)
576 && lp_client_lanman_auth()) {
577 SMBsesskeygen_lmv1(lm_hash, lm_response.data,
580 SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
583 data_blob_free(&struct_blob);
585 /* this generates the actual auth packet */
586 if (!msrpc_gen(next_request, auth_gen_string,
589 lm_response.data, lm_response.length,
590 nt_response.data, nt_response.length,
591 ntlmssp_state->domain,
593 ntlmssp_state->get_global_myname(),
594 datagram_sess_key, datagram_sess_key_len,
595 ntlmssp_state->neg_flags)) {
597 data_blob_free(&lm_response);
598 data_blob_free(&nt_response);
599 data_blob_free(&session_key);
600 return NT_STATUS_NO_MEMORY;
603 data_blob_free(&ntlmssp_state->chal);
604 data_blob_free(&ntlmssp_state->lm_resp);
605 data_blob_free(&ntlmssp_state->nt_resp);
606 data_blob_free(&ntlmssp_state->session_key);
608 ntlmssp_state->chal = challenge_blob;
609 ntlmssp_state->lm_resp = lm_response;
610 ntlmssp_state->nt_resp = nt_response;
611 ntlmssp_state->session_key = session_key;
613 return NT_STATUS_MORE_PROCESSING_REQUIRED;
616 NTSTATUS ntlmssp_client_start(NTLMSSP_CLIENT_STATE **ntlmssp_state)
620 mem_ctx = talloc_init("NTLMSSP Client context");
622 *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state));
623 if (!*ntlmssp_state) {
624 DEBUG(0,("ntlmssp_server_start: talloc failed!\n"));
625 talloc_destroy(mem_ctx);
626 return NT_STATUS_NO_MEMORY;
629 (*ntlmssp_state)->mem_ctx = mem_ctx;
631 (*ntlmssp_state)->get_global_myname = global_myname;
632 (*ntlmssp_state)->get_domain = lp_workgroup;
634 (*ntlmssp_state)->unicode = True;
636 (*ntlmssp_state)->use_ntlmv2 = lp_client_ntlmv2_auth();
638 (*ntlmssp_state)->neg_flags =
639 NTLMSSP_NEGOTIATE_128 |
640 NTLMSSP_NEGOTIATE_NTLM |
641 NTLMSSP_REQUEST_TARGET;
643 (*ntlmssp_state)->ref_count = 1;
648 NTSTATUS ntlmssp_client_end(NTLMSSP_CLIENT_STATE **ntlmssp_state)
650 TALLOC_CTX *mem_ctx = (*ntlmssp_state)->mem_ctx;
652 (*ntlmssp_state)->ref_count--;
654 if ((*ntlmssp_state)->ref_count == 0) {
655 data_blob_free(&(*ntlmssp_state)->chal);
656 data_blob_free(&(*ntlmssp_state)->lm_resp);
657 data_blob_free(&(*ntlmssp_state)->nt_resp);
658 data_blob_free(&(*ntlmssp_state)->session_key);
659 data_blob_free(&(*ntlmssp_state)->stored_response);
660 talloc_destroy(mem_ctx);
663 *ntlmssp_state = NULL;
667 NTSTATUS ntlmssp_client_update(NTLMSSP_CLIENT_STATE *ntlmssp_state,
668 DATA_BLOB reply, DATA_BLOB *next_request)
670 NTSTATUS nt_status = NT_STATUS_INVALID_PARAMETER;
671 uint32 ntlmssp_command;
672 *next_request = data_blob(NULL, 0);
675 /* If there is a cached reply, use it - otherwise this is the first packet */
676 if (!ntlmssp_state->stored_response.length) {
677 return ntlmssp_client_initial(ntlmssp_state, reply, next_request);
680 reply = ntlmssp_state->stored_response;
683 if (!msrpc_parse(&reply, "Cd",
686 return NT_STATUS_INVALID_PARAMETER;
689 if (ntlmssp_command == NTLMSSP_CHALLENGE) {
690 nt_status = ntlmssp_client_challenge(ntlmssp_state, reply, next_request);
692 if (ntlmssp_state->stored_response.length) {
693 data_blob_free(&ntlmssp_state->stored_response);
698 NTSTATUS ntlmssp_set_username(NTLMSSP_CLIENT_STATE *ntlmssp_state, const char *user)
700 ntlmssp_state->user = talloc_strdup(ntlmssp_state->mem_ctx, user);
701 if (!ntlmssp_state->user) {
702 return NT_STATUS_NO_MEMORY;
707 NTSTATUS ntlmssp_set_password(NTLMSSP_CLIENT_STATE *ntlmssp_state, const char *password)
709 ntlmssp_state->password = talloc_strdup(ntlmssp_state->mem_ctx, password);
710 if (!ntlmssp_state->password) {
711 return NT_STATUS_NO_MEMORY;
716 NTSTATUS ntlmssp_set_domain(NTLMSSP_CLIENT_STATE *ntlmssp_state, const char *domain)
718 ntlmssp_state->domain = talloc_strdup(ntlmssp_state->mem_ctx, domain);
719 if (!ntlmssp_state->domain) {
720 return NT_STATUS_NO_MEMORY;
726 * Store a DATA_BLOB containing an NTLMSSP response, for use later.
727 * This 'keeps' the data blob - the caller must *not* free it.
730 NTSTATUS ntlmssp_client_store_response(NTLMSSP_CLIENT_STATE *ntlmssp_state,
733 data_blob_free(&ntlmssp_state->stored_response);
734 ntlmssp_state->stored_response = response;