2 Unix SMB/CIFS implementation.
4 test suite for netlogon SamLogon operations
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003-2004
8 Copyright (C) Tim Potter 2003
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "librpc/gen_ndr/ndr_netlogon.h"
27 #include "auth/auth.h"
28 #include "lib/crypto/crypto.h"
29 #include "lib/cmdline/popt_common.h"
31 #define TEST_MACHINE_NAME "samlogontest"
32 #define TEST_USER_NAME "samlogontestuser"
43 struct samlogon_state {
45 const char *account_name;
46 const char *account_domain;
48 struct dcerpc_pipe *p;
50 struct netr_LogonSamLogon r;
51 struct netr_LogonSamLogonEx r_ex;
52 struct netr_LogonSamLogonWithFlags r_flags;
53 struct netr_Authenticator auth, auth2;
54 struct creds_CredentialState *creds;
55 NTSTATUS expected_error;
60 Authenticate a user with a challenge/response, checking session key
61 and valid authentication types
63 static NTSTATUS check_samlogon(struct samlogon_state *samlogon_state,
64 enum ntlm_break break_which,
66 DATA_BLOB *lm_response,
67 DATA_BLOB *nt_response,
69 uint8_t user_session_key[16],
73 struct netr_LogonSamLogon *r = &samlogon_state->r;
74 struct netr_LogonSamLogonEx *r_ex = &samlogon_state->r_ex;
75 struct netr_LogonSamLogonWithFlags *r_flags = &samlogon_state->r_flags;
76 struct netr_NetworkInfo ninfo;
77 struct netr_SamBaseInfo *base = NULL;
78 uint16_t validation_level = 0;
80 samlogon_state->r.in.logon.network = &ninfo;
81 samlogon_state->r_ex.in.logon.network = &ninfo;
82 samlogon_state->r_flags.in.logon.network = &ninfo;
84 ninfo.identity_info.domain_name.string = samlogon_state->account_domain;
85 ninfo.identity_info.parameter_control = 0;
86 ninfo.identity_info.logon_id_low = 0;
87 ninfo.identity_info.logon_id_high = 0;
88 ninfo.identity_info.account_name.string = samlogon_state->account_name;
89 ninfo.identity_info.workstation.string = TEST_MACHINE_NAME;
91 memcpy(ninfo.challenge, chall->data, 8);
93 switch (break_which) {
97 if (lm_response && lm_response->data) {
98 lm_response->data[0]++;
102 if (nt_response && nt_response->data) {
103 nt_response->data[0]++;
107 if (lm_response && lm_response->data) {
108 lm_response->data[0]++;
110 if (nt_response && nt_response->data) {
111 nt_response->data[0]++;
115 data_blob_free(lm_response);
118 data_blob_free(nt_response);
123 ninfo.nt.data = nt_response->data;
124 ninfo.nt.length = nt_response->length;
126 ninfo.nt.data = NULL;
131 ninfo.lm.data = lm_response->data;
132 ninfo.lm.length = lm_response->length;
134 ninfo.lm.data = NULL;
138 switch (samlogon_state->function_level) {
139 case DCERPC_NETR_LOGONSAMLOGON:
140 ZERO_STRUCT(samlogon_state->auth2);
141 creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
143 r->out.return_authenticator = NULL;
144 status = dcerpc_netr_LogonSamLogon(samlogon_state->p, samlogon_state->mem_ctx, r);
145 if (!r->out.return_authenticator ||
146 !creds_client_check(samlogon_state->creds, &r->out.return_authenticator->cred)) {
147 printf("Credential chaining failed\n");
149 if (!NT_STATUS_IS_OK(status)) {
151 *error_string = strdup(nt_errstr(status));
155 validation_level = r->in.validation_level;
156 switch (validation_level) {
158 base = &r->out.validation.sam2->base;
161 base = &r->out.validation.sam3->base;
164 base = &r->out.validation.sam6->base;
168 case DCERPC_NETR_LOGONSAMLOGONEX:
169 status = dcerpc_netr_LogonSamLogonEx(samlogon_state->p, samlogon_state->mem_ctx, r_ex);
170 if (!NT_STATUS_IS_OK(status)) {
172 *error_string = strdup(nt_errstr(status));
176 validation_level = r_ex->in.validation_level;
177 switch (validation_level) {
179 base = &r_ex->out.validation.sam2->base;
182 base = &r_ex->out.validation.sam3->base;
185 base = &r_ex->out.validation.sam6->base;
189 case DCERPC_NETR_LOGONSAMLOGONWITHFLAGS:
190 ZERO_STRUCT(samlogon_state->auth2);
191 creds_client_authenticator(samlogon_state->creds, &samlogon_state->auth);
193 r_flags->out.return_authenticator = NULL;
194 status = dcerpc_netr_LogonSamLogonWithFlags(samlogon_state->p, samlogon_state->mem_ctx, r_flags);
195 if (!r_flags->out.return_authenticator ||
196 !creds_client_check(samlogon_state->creds, &r_flags->out.return_authenticator->cred)) {
197 printf("Credential chaining failed\n");
199 if (!NT_STATUS_IS_OK(status)) {
201 *error_string = strdup(nt_errstr(status));
205 validation_level = r_flags->in.validation_level;
206 switch (validation_level) {
208 base = &r_flags->out.validation.sam2->base;
211 base = &r_flags->out.validation.sam3->base;
214 base = &r_flags->out.validation.sam6->base;
221 if (!NT_STATUS_IS_OK(status)) {
222 /* we cannot check the session key, if the logon failed... */
227 printf("No user info returned from 'successful' SamLogon*() call!\n");
228 return NT_STATUS_INVALID_PARAMETER;
231 /* find and decyrpt the session keys, return in parameters above */
232 if (validation_level == 6) {
233 /* they aren't encrypted! */
234 if (user_session_key) {
235 memcpy(user_session_key, base->key.key, 16);
238 memcpy(lm_key, base->LMSessKey.key, 8);
240 } else if (samlogon_state->creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
241 static const char zeros[16];
243 if (memcmp(base->key.key, zeros,
244 sizeof(base->key.key)) != 0) {
245 creds_arcfour_crypt(samlogon_state->creds,
247 sizeof(base->key.key));
250 if (user_session_key) {
251 memcpy(user_session_key, base->key.key, 16);
254 if (memcmp(base->LMSessKey.key, zeros,
255 sizeof(base->LMSessKey.key)) != 0) {
256 creds_arcfour_crypt(samlogon_state->creds,
258 sizeof(base->LMSessKey.key));
262 memcpy(lm_key, base->LMSessKey.key, 8);
265 static const char zeros[16];
267 if (user_session_key) {
268 memcpy(user_session_key, base->key.key, 16);
271 if (memcmp(base->LMSessKey.key, zeros,
272 sizeof(base->LMSessKey.key)) != 0) {
273 creds_des_decrypt_LMKey(samlogon_state->creds,
278 memcpy(lm_key, base->LMSessKey.key, 8);
287 * Test the normal 'LM and NTLM' combination
290 static BOOL test_lm_ntlm_broken(struct samlogon_state *samlogon_state, enum ntlm_break break_which, char **error_string)
295 DATA_BLOB lm_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
296 DATA_BLOB nt_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
297 DATA_BLOB session_key = data_blob_talloc(samlogon_state->mem_ctx, NULL, 16);
300 uint8_t user_session_key[16];
305 ZERO_STRUCT(user_session_key);
307 lm_good = SMBencrypt(samlogon_state->password, samlogon_state->chall.data, lm_response.data);
309 ZERO_STRUCT(lm_hash);
311 E_deshash(samlogon_state->password, lm_hash);
314 SMBNTencrypt(samlogon_state->password, samlogon_state->chall.data, nt_response.data);
316 E_md4hash(samlogon_state->password, nt_hash);
317 SMBsesskeygen_ntv1(nt_hash, session_key.data);
319 nt_status = check_samlogon(samlogon_state,
321 &samlogon_state->chall,
328 data_blob_free(&lm_response);
330 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD, nt_status)) {
331 /* for 'long' passwords, the LM password is invalid */
332 if (break_which == NO_NT && !lm_good) {
335 return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH));
338 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
339 SAFE_FREE(*error_string);
340 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
342 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
344 } else if (!NT_STATUS_IS_OK(nt_status)) {
348 if (break_which == NO_NT && !lm_good) {
349 *error_string = strdup("LM password is 'long' (> 14 chars and therefore invalid) but login did not fail!");
353 if (memcmp(lm_hash, lm_key,
354 sizeof(lm_key)) != 0) {
355 printf("LM Key does not match expectations!\n");
357 dump_data(1, lm_key, 8);
358 printf("expected:\n");
359 dump_data(1, lm_hash, 8);
363 switch (break_which) {
366 uint8_t lm_key_expected[16];
367 memcpy(lm_key_expected, lm_hash, 8);
368 memset(lm_key_expected+8, '\0', 8);
369 if (memcmp(lm_key_expected, user_session_key,
371 *error_string = strdup("NT Session Key does not match expectations (should be first-8 LM hash)!\n");
372 printf("user_session_key:\n");
373 dump_data(1, user_session_key, sizeof(user_session_key));
374 printf("expected:\n");
375 dump_data(1, lm_key_expected, sizeof(lm_key_expected));
381 if (memcmp(session_key.data, user_session_key,
382 sizeof(user_session_key)) != 0) {
383 *error_string = strdup("NT Session Key does not match expectations!\n");
384 printf("user_session_key:\n");
385 dump_data(1, user_session_key, 16);
386 printf("expected:\n");
387 dump_data(1, session_key.data, session_key.length);
395 * Test LM authentication, no NT response supplied
398 static BOOL test_lm(struct samlogon_state *samlogon_state, char **error_string)
401 return test_lm_ntlm_broken(samlogon_state, NO_NT, error_string);
405 * Test the NTLM response only, no LM.
408 static BOOL test_ntlm(struct samlogon_state *samlogon_state, char **error_string)
410 return test_lm_ntlm_broken(samlogon_state, NO_LM, error_string);
414 * Test the NTLM response only, but in the LM field.
417 static BOOL test_ntlm_in_lm(struct samlogon_state *samlogon_state, char **error_string)
421 DATA_BLOB nt_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
425 uint8_t user_session_key[16];
427 ZERO_STRUCT(user_session_key);
429 SMBNTencrypt(samlogon_state->password, samlogon_state->chall.data, nt_response.data);
431 E_deshash(samlogon_state->password, lm_hash);
433 nt_status = check_samlogon(samlogon_state,
435 &samlogon_state->chall,
442 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
443 SAFE_FREE(*error_string);
444 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
446 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
448 } else if (!NT_STATUS_IS_OK(nt_status)) {
452 if (memcmp(lm_hash, lm_key,
453 sizeof(lm_key)) != 0) {
454 printf("LM Key does not match expectations!\n");
456 dump_data(1, lm_key, 8);
457 printf("expected:\n");
458 dump_data(1, lm_hash, 8);
461 if (memcmp(lm_hash, user_session_key, 8) != 0) {
462 uint8_t lm_key_expected[16];
463 memcpy(lm_key_expected, lm_hash, 8);
464 memset(lm_key_expected+8, '\0', 8);
465 if (memcmp(lm_key_expected, user_session_key,
467 printf("NT Session Key does not match expectations (should be first-8 LM hash)!\n");
468 printf("user_session_key:\n");
469 dump_data(1, user_session_key, sizeof(user_session_key));
470 printf("expected:\n");
471 dump_data(1, lm_key_expected, sizeof(lm_key_expected));
479 * Test the NTLM response only, but in the both the NT and LM fields.
482 static BOOL test_ntlm_in_both(struct samlogon_state *samlogon_state, char **error_string)
487 DATA_BLOB nt_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
488 DATA_BLOB session_key = data_blob_talloc(samlogon_state->mem_ctx, NULL, 16);
492 uint8_t user_session_key[16];
496 ZERO_STRUCT(user_session_key);
498 SMBNTencrypt(samlogon_state->password, samlogon_state->chall.data,
500 E_md4hash(samlogon_state->password, nt_hash);
501 SMBsesskeygen_ntv1(nt_hash,
504 lm_good = E_deshash(samlogon_state->password, lm_hash);
506 ZERO_STRUCT(lm_hash);
509 nt_status = check_samlogon(samlogon_state,
511 &samlogon_state->chall,
518 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
519 SAFE_FREE(*error_string);
520 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
522 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
524 } else if (!NT_STATUS_IS_OK(nt_status)) {
528 if (!NT_STATUS_IS_OK(nt_status)) {
532 if (memcmp(lm_hash, lm_key,
533 sizeof(lm_key)) != 0) {
534 printf("LM Key does not match expectations!\n");
536 dump_data(1, lm_key, 8);
537 printf("expected:\n");
538 dump_data(1, lm_hash, 8);
541 if (memcmp(session_key.data, user_session_key,
542 sizeof(user_session_key)) != 0) {
543 printf("NT Session Key does not match expectations!\n");
544 printf("user_session_key:\n");
545 dump_data(1, user_session_key, 16);
546 printf("expected:\n");
547 dump_data(1, session_key.data, session_key.length);
556 * Test the NTLMv2 and LMv2 responses
564 static BOOL test_lmv2_ntlmv2_broken(struct samlogon_state *samlogon_state,
565 enum ntlm_break break_which,
566 enum ntlmv2_domain ntlmv2_domain,
571 DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
572 DATA_BLOB lmv2_response = data_blob(NULL, 0);
573 DATA_BLOB lmv2_session_key = data_blob(NULL, 0);
574 DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0);
575 DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, TEST_MACHINE_NAME, lp_workgroup());
577 uint8_t lm_session_key[8];
578 uint8_t user_session_key[16];
580 ZERO_STRUCT(lm_session_key);
581 ZERO_STRUCT(user_session_key);
583 switch (ntlmv2_domain) {
585 if (!SMBNTLMv2encrypt(samlogon_state->mem_ctx,
586 samlogon_state->account_name, samlogon_state->account_domain,
587 samlogon_state->password, &samlogon_state->chall,
589 &lmv2_response, &ntlmv2_response,
590 &lmv2_session_key, &ntlmv2_session_key)) {
591 data_blob_free(&names_blob);
596 if (!SMBNTLMv2encrypt(samlogon_state->mem_ctx,
597 samlogon_state->account_name, "",
598 samlogon_state->password, &samlogon_state->chall,
600 &lmv2_response, &ntlmv2_response,
601 &lmv2_session_key, &ntlmv2_session_key)) {
602 data_blob_free(&names_blob);
607 data_blob_free(&names_blob);
609 nt_status = check_samlogon(samlogon_state,
611 &samlogon_state->chall,
618 data_blob_free(&lmv2_response);
619 data_blob_free(&ntlmv2_response);
622 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
623 return break_which == BREAK_BOTH;
626 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
627 SAFE_FREE(*error_string);
628 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
630 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
632 } else if (!NT_STATUS_IS_OK(nt_status)) {
637 switch (break_which) {
639 if (memcmp(lmv2_session_key.data, user_session_key,
640 sizeof(user_session_key)) != 0) {
641 printf("USER (LMv2) Session Key does not match expectations!\n");
642 printf("user_session_key:\n");
643 dump_data(1, user_session_key, 16);
644 printf("expected:\n");
645 dump_data(1, lmv2_session_key.data, ntlmv2_session_key.length);
648 if (memcmp(lmv2_session_key.data, lm_session_key,
649 sizeof(lm_session_key)) != 0) {
650 printf("LM (LMv2) Session Key does not match expectations!\n");
651 printf("lm_session_key:\n");
652 dump_data(1, lm_session_key, 8);
653 printf("expected:\n");
654 dump_data(1, lmv2_session_key.data, 8);
659 if (memcmp(ntlmv2_session_key.data, user_session_key,
660 sizeof(user_session_key)) != 0) {
661 if (memcmp(lmv2_session_key.data, user_session_key,
662 sizeof(user_session_key)) == 0) {
663 printf("USER (NTLMv2) Session Key expected, got LMv2 sessesion key instead:\n");
664 printf("user_session_key:\n");
665 dump_data(1, user_session_key, 16);
666 printf("expected:\n");
667 dump_data(1, ntlmv2_session_key.data, ntlmv2_session_key.length);
671 printf("USER (NTLMv2) Session Key does not match expectations!\n");
672 printf("user_session_key:\n");
673 dump_data(1, user_session_key, 16);
674 printf("expected:\n");
675 dump_data(1, ntlmv2_session_key.data, ntlmv2_session_key.length);
679 if (memcmp(ntlmv2_session_key.data, lm_session_key,
680 sizeof(lm_session_key)) != 0) {
681 if (memcmp(lmv2_session_key.data, lm_session_key,
682 sizeof(lm_session_key)) == 0) {
683 printf("LM (NTLMv2) Session Key expected, got LMv2 sessesion key instead:\n");
684 printf("user_session_key:\n");
685 dump_data(1, lm_session_key, 8);
686 printf("expected:\n");
687 dump_data(1, ntlmv2_session_key.data, 8);
690 printf("LM (NTLMv2) Session Key does not match expectations!\n");
691 printf("lm_session_key:\n");
692 dump_data(1, lm_session_key, 8);
693 printf("expected:\n");
694 dump_data(1, ntlmv2_session_key.data, 8);
704 * Test the NTLM and LMv2 responses
707 static BOOL test_lmv2_ntlm_broken(struct samlogon_state *samlogon_state,
708 enum ntlm_break break_which,
709 enum ntlmv2_domain ntlmv2_domain,
714 DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
715 DATA_BLOB lmv2_response = data_blob(NULL, 0);
716 DATA_BLOB lmv2_session_key = data_blob(NULL, 0);
717 DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0);
718 DATA_BLOB names_blob = NTLMv2_generate_names_blob(samlogon_state->mem_ctx, lp_netbios_name(), lp_workgroup());
720 DATA_BLOB ntlm_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
721 DATA_BLOB ntlm_session_key = data_blob_talloc(samlogon_state->mem_ctx, NULL, 16);
724 uint8_t lm_session_key[8];
725 uint8_t user_session_key[16];
728 SMBNTencrypt(samlogon_state->password, samlogon_state->chall.data,
730 E_md4hash(samlogon_state->password, nt_hash);
731 SMBsesskeygen_ntv1(nt_hash,
732 ntlm_session_key.data);
733 E_deshash(samlogon_state->password, lm_hash);
735 ZERO_STRUCT(lm_session_key);
736 ZERO_STRUCT(user_session_key);
738 switch (ntlmv2_domain) {
740 /* TODO - test with various domain cases, and without domain */
741 if (!SMBNTLMv2encrypt(samlogon_state->mem_ctx,
742 samlogon_state->account_name, samlogon_state->account_domain,
743 samlogon_state->password, &samlogon_state->chall,
745 &lmv2_response, &ntlmv2_response,
746 &lmv2_session_key, &ntlmv2_session_key)) {
747 data_blob_free(&names_blob);
752 /* TODO - test with various domain cases, and without domain */
753 if (!SMBNTLMv2encrypt(samlogon_state->mem_ctx,
754 samlogon_state->account_name, "",
755 samlogon_state->password, &samlogon_state->chall,
757 &lmv2_response, &ntlmv2_response,
758 &lmv2_session_key, &ntlmv2_session_key)) {
759 data_blob_free(&names_blob);
765 data_blob_free(&names_blob);
767 nt_status = check_samlogon(samlogon_state,
769 &samlogon_state->chall,
776 data_blob_free(&lmv2_response);
777 data_blob_free(&ntlmv2_response);
780 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD, nt_status)) {
781 return ((break_which == BREAK_NT) || (break_which == BREAK_BOTH));
784 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
785 SAFE_FREE(*error_string);
786 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
788 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
790 } else if (!NT_STATUS_IS_OK(nt_status)) {
794 switch (break_which) {
796 if (memcmp(lmv2_session_key.data, user_session_key,
797 sizeof(user_session_key)) != 0) {
798 printf("USER (LMv2) Session Key does not match expectations!\n");
799 printf("user_session_key:\n");
800 dump_data(1, user_session_key, 16);
801 printf("expected:\n");
802 dump_data(1, lmv2_session_key.data, ntlmv2_session_key.length);
805 if (memcmp(lmv2_session_key.data, lm_session_key,
806 sizeof(lm_session_key)) != 0) {
807 printf("LM (LMv2) Session Key does not match expectations!\n");
808 printf("lm_session_key:\n");
809 dump_data(1, lm_session_key, 8);
810 printf("expected:\n");
811 dump_data(1, lmv2_session_key.data, 8);
816 if (memcmp(ntlm_session_key.data, user_session_key,
817 sizeof(user_session_key)) != 0) {
818 printf("USER (NTLMv2) Session Key does not match expectations!\n");
819 printf("user_session_key:\n");
820 dump_data(1, user_session_key, 16);
821 printf("expected:\n");
822 dump_data(1, ntlm_session_key.data, ntlm_session_key.length);
825 if (memcmp(lm_hash, lm_session_key,
826 sizeof(lm_session_key)) != 0) {
827 printf("LM Session Key does not match expectations!\n");
828 printf("lm_session_key:\n");
829 dump_data(1, lm_session_key, 8);
830 printf("expected:\n");
831 dump_data(1, lm_hash, 8);
836 if (memcmp(ntlm_session_key.data, user_session_key,
837 sizeof(user_session_key)) != 0) {
838 printf("USER (NTLMv2) Session Key does not match expectations!\n");
839 printf("user_session_key:\n");
840 dump_data(1, user_session_key, 16);
841 printf("expected:\n");
842 dump_data(1, ntlm_session_key.data, ntlm_session_key.length);
845 if (memcmp(ntlm_session_key.data, lm_session_key,
846 sizeof(lm_session_key)) != 0) {
847 printf("LM (NTLMv2) Session Key does not match expectations!\n");
848 printf("lm_session_key:\n");
849 dump_data(1, lm_session_key, 8);
850 printf("expected:\n");
851 dump_data(1, ntlm_session_key.data, 8);
860 * Test the NTLMv2 and LMv2 responses
863 static BOOL test_lmv2_ntlmv2(struct samlogon_state *samlogon_state, char **error_string)
865 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_NONE, UPPER_DOMAIN, error_string);
869 static BOOL test_lmv2_ntlmv2_no_dom(struct samlogon_state *samlogon_state, char **error_string)
871 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_NONE, NO_DOMAIN, error_string);
876 * Test the LMv2 response only
879 static BOOL test_lmv2(struct samlogon_state *samlogon_state, char **error_string)
881 return test_lmv2_ntlmv2_broken(samlogon_state, NO_NT, UPPER_DOMAIN, error_string);
884 static BOOL test_lmv2_no_dom(struct samlogon_state *samlogon_state, char **error_string)
886 return test_lmv2_ntlmv2_broken(samlogon_state, NO_NT, NO_DOMAIN, error_string);
890 * Test the NTLMv2 response only
893 static BOOL test_ntlmv2(struct samlogon_state *samlogon_state, char **error_string)
895 return test_lmv2_ntlmv2_broken(samlogon_state, NO_LM, UPPER_DOMAIN, error_string);
898 static BOOL test_ntlmv2_no_dom(struct samlogon_state *samlogon_state, char **error_string)
900 return test_lmv2_ntlmv2_broken(samlogon_state, NO_LM, NO_DOMAIN, error_string);
903 static BOOL test_lm_ntlm(struct samlogon_state *samlogon_state, char **error_string)
905 return test_lm_ntlm_broken(samlogon_state, BREAK_NONE, error_string);
908 static BOOL test_ntlm_lm_broken(struct samlogon_state *samlogon_state, char **error_string)
910 return test_lm_ntlm_broken(samlogon_state, BREAK_LM, error_string);
913 static BOOL test_ntlm_ntlm_broken(struct samlogon_state *samlogon_state, char **error_string)
915 return test_lm_ntlm_broken(samlogon_state, BREAK_NT, error_string);
918 static BOOL test_lm_ntlm_both_broken(struct samlogon_state *samlogon_state, char **error_string)
920 return test_lm_ntlm_broken(samlogon_state, BREAK_BOTH, error_string);
922 static BOOL test_ntlmv2_lmv2_broken(struct samlogon_state *samlogon_state, char **error_string)
924 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_LM, UPPER_DOMAIN, error_string);
927 static BOOL test_ntlmv2_lmv2_broken_no_dom(struct samlogon_state *samlogon_state, char **error_string)
929 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_LM, NO_DOMAIN, error_string);
932 static BOOL test_ntlmv2_ntlmv2_broken(struct samlogon_state *samlogon_state, char **error_string)
934 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_NT, UPPER_DOMAIN, error_string);
938 static BOOL test_ntlmv2_ntlmv2_broken_no_dom(struct samlogon_state *samlogon_state, char **error_string)
940 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_NT, NO_DOMAIN, error_string);
944 static BOOL test_ntlmv2_both_broken(struct samlogon_state *samlogon_state, char **error_string)
946 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_BOTH, UPPER_DOMAIN, error_string);
949 static BOOL test_ntlmv2_both_broken_no_dom(struct samlogon_state *samlogon_state, char **error_string)
951 return test_lmv2_ntlmv2_broken(samlogon_state, BREAK_BOTH, NO_DOMAIN, error_string);
954 static BOOL test_lmv2_ntlm_both_broken(struct samlogon_state *samlogon_state, char **error_string)
956 return test_lmv2_ntlm_broken(samlogon_state, BREAK_BOTH, UPPER_DOMAIN, error_string);
959 static BOOL test_lmv2_ntlm_both_broken_no_dom(struct samlogon_state *samlogon_state, char **error_string)
961 return test_lmv2_ntlm_broken(samlogon_state, BREAK_BOTH, NO_DOMAIN, error_string);
964 static BOOL test_lmv2_ntlm_break_ntlm(struct samlogon_state *samlogon_state, char **error_string)
966 return test_lmv2_ntlm_broken(samlogon_state, BREAK_NT, UPPER_DOMAIN, error_string);
969 static BOOL test_lmv2_ntlm_break_ntlm_no_dom(struct samlogon_state *samlogon_state, char **error_string)
971 return test_lmv2_ntlm_broken(samlogon_state, BREAK_NT, NO_DOMAIN, error_string);
974 static BOOL test_lmv2_ntlm_break_lm(struct samlogon_state *samlogon_state, char **error_string)
976 return test_lmv2_ntlm_broken(samlogon_state, BREAK_LM, UPPER_DOMAIN, error_string);
979 static BOOL test_lmv2_ntlm_break_lm_no_dom(struct samlogon_state *samlogon_state, char **error_string)
981 return test_lmv2_ntlm_broken(samlogon_state, BREAK_LM, NO_DOMAIN, error_string);
985 * Test the NTLM2 response (extra challenge in LM feild)
987 * This test is the same as the 'break LM' test, but checks that the
988 * server implements NTLM2 session security in the right place
989 * (NETLOGON is the wrong place).
992 static BOOL test_ntlm2(struct samlogon_state *samlogon_state, char **error_string)
996 DATA_BLOB lm_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
997 DATA_BLOB nt_response = data_blob_talloc(samlogon_state->mem_ctx, NULL, 24);
1000 uint8_t nt_hash[16];
1001 uint8_t lm_hash[16];
1003 uint8_t user_session_key[16];
1004 uint8_t expected_user_session_key[16];
1005 uint8_t session_nonce_hash[16];
1006 uint8_t client_chall[8];
1008 struct MD5Context md5_session_nonce_ctx;
1009 HMACMD5Context hmac_ctx;
1011 ZERO_STRUCT(user_session_key);
1012 ZERO_STRUCT(lm_key);
1013 generate_random_buffer(client_chall, 8);
1015 MD5Init(&md5_session_nonce_ctx);
1016 MD5Update(&md5_session_nonce_ctx, samlogon_state->chall.data, 8);
1017 MD5Update(&md5_session_nonce_ctx, client_chall, 8);
1018 MD5Final(session_nonce_hash, &md5_session_nonce_ctx);
1020 E_md4hash(samlogon_state->password, (uint8_t *)nt_hash);
1021 E_deshash(samlogon_state->password, (uint8_t *)lm_hash);
1022 SMBsesskeygen_ntv1((const uint8_t *)nt_hash,
1025 SMBNTencrypt(samlogon_state->password, samlogon_state->chall.data, nt_response.data);
1027 memcpy(lm_response.data, session_nonce_hash, 8);
1028 memset(lm_response.data + 8, 0, 16);
1030 hmac_md5_init_rfc2104(nt_key, 16, &hmac_ctx);
1031 hmac_md5_update(samlogon_state->chall.data, 8, &hmac_ctx);
1032 hmac_md5_update(client_chall, 8, &hmac_ctx);
1033 hmac_md5_final(expected_user_session_key, &hmac_ctx);
1035 nt_status = check_samlogon(samlogon_state,
1037 &samlogon_state->chall,
1044 if (!NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status)) {
1045 SAFE_FREE(*error_string);
1046 asprintf(error_string, "Expected error: %s, got %s", nt_errstr(samlogon_state->expected_error), nt_errstr(nt_status));
1048 } else if (NT_STATUS_EQUAL(samlogon_state->expected_error, nt_status) && !NT_STATUS_IS_OK(nt_status)) {
1050 } else if (!NT_STATUS_IS_OK(nt_status)) {
1054 if (memcmp(lm_hash, lm_key,
1055 sizeof(lm_key)) != 0) {
1056 printf("LM Key does not match expectations!\n");
1057 printf("lm_key:\n");
1058 dump_data(1, lm_key, 8);
1059 printf("expected:\n");
1060 dump_data(1, lm_hash, 8);
1063 if (memcmp(nt_key, user_session_key, 16) != 0) {
1064 printf("NT Session Key does not match expectations (should be first-8 LM hash)!\n");
1065 printf("user_session_key:\n");
1066 dump_data(1, user_session_key, sizeof(user_session_key));
1067 printf("expected:\n");
1068 dump_data(1, nt_key, sizeof(nt_key));
1074 static BOOL test_plaintext(struct samlogon_state *samlogon_state, enum ntlm_break break_which, char **error_string)
1077 DATA_BLOB nt_response = data_blob(NULL, 0);
1078 DATA_BLOB lm_response = data_blob(NULL, 0);
1083 uint8_t user_session_key[16];
1085 static const uint8_t zeros[8];
1086 DATA_BLOB chall = data_blob_talloc(samlogon_state->mem_ctx, zeros, sizeof(zeros));
1088 ZERO_STRUCT(user_session_key);
1090 if ((push_ucs2_talloc(samlogon_state->mem_ctx, &unicodepw,
1091 samlogon_state->password)) == -1) {
1092 DEBUG(0, ("push_ucs2_allocate failed!\n"));
1096 nt_response = data_blob_talloc(samlogon_state->mem_ctx, unicodepw, strlen_m(samlogon_state->password)*2);
1098 password = strupper_talloc(samlogon_state->mem_ctx, samlogon_state->password);
1100 if ((convert_string_talloc(samlogon_state->mem_ctx, CH_UNIX,
1103 (void**)&dospw)) == -1) {
1104 DEBUG(0, ("convert_string_talloc failed!\n"));
1108 lm_response = data_blob_talloc(samlogon_state->mem_ctx, dospw, strlen(dospw));
1110 nt_status = check_samlogon(samlogon_state,
1119 if (!NT_STATUS_IS_OK(nt_status)) {
1120 return break_which == BREAK_NT;
1126 static BOOL test_plaintext_none_broken(struct samlogon_state *samlogon_state,
1127 char **error_string) {
1128 return test_plaintext(samlogon_state, BREAK_NONE, error_string);
1131 static BOOL test_plaintext_lm_broken(struct samlogon_state *samlogon_state,
1132 char **error_string) {
1133 return test_plaintext(samlogon_state, BREAK_LM, error_string);
1136 static BOOL test_plaintext_nt_broken(struct samlogon_state *samlogon_state,
1137 char **error_string) {
1138 return test_plaintext(samlogon_state, BREAK_NT, error_string);
1141 static BOOL test_plaintext_nt_only(struct samlogon_state *samlogon_state,
1142 char **error_string) {
1143 return test_plaintext(samlogon_state, NO_LM, error_string);
1146 static BOOL test_plaintext_lm_only(struct samlogon_state *samlogon_state,
1147 char **error_string) {
1148 return test_plaintext(samlogon_state, NO_NT, error_string);
1162 - plaintext tests (in challenge-response fields)
1164 check we get the correct session key in each case
1165 check what values we get for the LM session key
1169 static const struct ntlm_tests {
1170 BOOL (*fn)(struct samlogon_state *, char **);
1174 {test_lmv2_ntlmv2, "NTLMv2 and LMv2", False},
1176 {test_lmv2_ntlmv2_no_dom, "NTLMv2 and LMv2 (no domain)", False},
1178 {test_lm, "LM", False},
1179 {test_lm_ntlm, "LM and NTLM", False},
1180 {test_lm_ntlm_both_broken, "LM and NTLM, both broken", False},
1181 {test_ntlm, "NTLM", False},
1182 {test_ntlm_in_lm, "NTLM in LM", False},
1183 {test_ntlm_in_both, "NTLM in both", False},
1184 {test_ntlmv2, "NTLMv2", False},
1185 {test_ntlmv2_no_dom, "NTLMv2 (no domain)", False},
1186 {test_lmv2, "LMv2", False},
1187 {test_lmv2_no_dom, "LMv2 (no domain)", False},
1188 {test_ntlmv2_lmv2_broken, "NTLMv2 and LMv2, LMv2 broken", False},
1189 {test_ntlmv2_lmv2_broken_no_dom, "NTLMv2 and LMv2, LMv2 broken (no domain)", False},
1190 {test_ntlmv2_ntlmv2_broken, "NTLMv2 and LMv2, NTLMv2 broken", False},
1192 {test_ntlmv2_ntlmv2_broken_no_dom, "NTLMv2 and LMv2, NTLMv2 broken (no domain)", False},
1194 {test_ntlmv2_both_broken, "NTLMv2 and LMv2, both broken", False},
1195 {test_ntlmv2_both_broken_no_dom, "NTLMv2 and LMv2, both broken (no domain)", False},
1196 {test_ntlm_lm_broken, "NTLM and LM, LM broken", False},
1197 {test_ntlm_ntlm_broken, "NTLM and LM, NTLM broken", False},
1198 {test_ntlm2, "NTLM2 (NTLMv2 session security)", False},
1199 {test_lmv2_ntlm_both_broken, "LMv2 and NTLM, both broken", False},
1200 {test_lmv2_ntlm_both_broken_no_dom, "LMv2 and NTLM, both broken (no domain)", False},
1201 {test_lmv2_ntlm_break_ntlm, "LMv2 and NTLM, NTLM broken", False},
1202 {test_lmv2_ntlm_break_ntlm_no_dom, "LMv2 and NTLM, NTLM broken (no domain)", False},
1203 {test_lmv2_ntlm_break_lm, "LMv2 and NTLM, LMv2 broken", False},
1204 {test_lmv2_ntlm_break_lm_no_dom, "LMv2 and NTLM, LMv2 broken (no domain)", False},
1205 {test_plaintext_none_broken, "Plaintext", True},
1206 {test_plaintext_lm_broken, "Plaintext LM broken", True},
1207 {test_plaintext_nt_broken, "Plaintext NT broken", True},
1208 {test_plaintext_nt_only, "Plaintext NT only", True},
1209 {test_plaintext_lm_only, "Plaintext LM only", True},
1214 try a netlogon SamLogon
1216 static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1217 struct creds_CredentialState *creds,
1218 const char *account_domain, const char *account_name,
1219 const char *plain_pass, NTSTATUS expected_error,
1222 TALLOC_CTX *fn_ctx = talloc_named(mem_ctx, 0, "test_SamLogon function-level context");
1225 int validation_levels[] = {2,3,6};
1226 int logon_levels[] = { 2, 6 };
1227 int function_levels[] = {
1228 DCERPC_NETR_LOGONSAMLOGON,
1229 DCERPC_NETR_LOGONSAMLOGONEX,
1230 DCERPC_NETR_LOGONSAMLOGONWITHFLAGS };
1231 struct samlogon_state samlogon_state;
1233 printf("testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
1235 samlogon_state.account_name = account_name;
1236 samlogon_state.account_domain = account_domain;
1237 samlogon_state.password = plain_pass;
1238 samlogon_state.p = p;
1239 samlogon_state.creds = creds;
1240 samlogon_state.expected_error = expected_error;
1241 samlogon_state.chall = data_blob_talloc(fn_ctx, NULL, 8);
1243 generate_random_buffer(samlogon_state.chall.data, 8);
1244 samlogon_state.r_flags.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
1245 samlogon_state.r_flags.in.workstation = TEST_MACHINE_NAME;
1246 samlogon_state.r_flags.in.credential = &samlogon_state.auth;
1247 samlogon_state.r_flags.in.return_authenticator = &samlogon_state.auth2;
1248 samlogon_state.r_flags.in.flags = 0;
1250 samlogon_state.r_ex.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
1251 samlogon_state.r_ex.in.workstation = TEST_MACHINE_NAME;
1252 samlogon_state.r_ex.in.flags = 0;
1254 samlogon_state.r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
1255 samlogon_state.r.in.workstation = TEST_MACHINE_NAME;
1256 samlogon_state.r.in.credential = &samlogon_state.auth;
1257 samlogon_state.r.in.return_authenticator = &samlogon_state.auth2;
1259 for (f=0;f<ARRAY_SIZE(function_levels);f++) {
1260 for (i=0; test_table[i].fn; i++) {
1261 if (n_subtests && (i > n_subtests)) {
1264 for (v=0;v<ARRAY_SIZE(validation_levels);v++) {
1265 for (l=0;l<ARRAY_SIZE(logon_levels);l++) {
1266 char *error_string = NULL;
1267 TALLOC_CTX *tmp_ctx = talloc_named(fn_ctx, 0, "test_SamLogon inner loop");
1268 samlogon_state.mem_ctx = tmp_ctx;
1269 samlogon_state.function_level = function_levels[f];
1270 samlogon_state.r.in.validation_level = validation_levels[v];
1271 samlogon_state.r.in.logon_level = logon_levels[l];
1272 samlogon_state.r_ex.in.validation_level = validation_levels[v];
1273 samlogon_state.r_ex.in.logon_level = logon_levels[l];
1274 samlogon_state.r_flags.in.validation_level = validation_levels[v];
1275 samlogon_state.r_flags.in.logon_level = logon_levels[l];
1276 if (!test_table[i].fn(&samlogon_state, &error_string)) {
1277 printf("Testing [%s]\\[%s] '%s' at validation level %d, logon level %d, function %d: \n",
1278 samlogon_state.account_domain,
1279 samlogon_state.account_name,
1280 test_table[i].name, validation_levels[v],
1281 logon_levels[l], function_levels[f]);
1283 if (test_table[i].expect_fail) {
1284 printf(" failed (expected, test incomplete): %s\n", error_string);
1286 printf(" failed: %s\n", error_string);
1289 SAFE_FREE(error_string);
1291 talloc_free(tmp_ctx);
1296 talloc_free(fn_ctx);
1301 test an ADS style interactive domain logon
1303 BOOL test_InteractiveLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1304 struct creds_CredentialState *creds,
1305 const char *workstation_name,
1306 const char *account_domain, const char *account_name,
1307 const char *plain_pass, NTSTATUS expected_error)
1310 TALLOC_CTX *fn_ctx = talloc_named(mem_ctx, 0, "test_InteractiveLogon function-level context");
1311 struct netr_LogonSamLogonWithFlags r;
1312 struct netr_Authenticator a, ra;
1313 struct netr_PasswordInfo pinfo;
1319 creds_client_authenticator(creds, &a);
1321 r.in.server_name = talloc_asprintf(fn_ctx, "\\\\%s", dcerpc_server_name(p));
1322 r.in.workstation = TEST_MACHINE_NAME;
1323 r.in.credential = &a;
1324 r.in.return_authenticator = &ra;
1325 r.in.logon_level = 5;
1326 r.in.logon.password = &pinfo;
1327 r.in.validation_level = 6;
1330 pinfo.identity_info.domain_name.string = account_domain;
1331 pinfo.identity_info.parameter_control = 0;
1332 pinfo.identity_info.logon_id_low = 0;
1333 pinfo.identity_info.logon_id_high = 0;
1334 pinfo.identity_info.account_name.string = account_name;
1335 pinfo.identity_info.workstation.string = workstation_name;
1337 if (!E_deshash(plain_pass, pinfo.lmpassword.hash)) {
1338 ZERO_STRUCT(pinfo.lmpassword.hash);
1340 E_md4hash(plain_pass, pinfo.ntpassword.hash);
1342 if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
1343 creds_arcfour_crypt(creds, pinfo.lmpassword.hash, 16);
1344 creds_arcfour_crypt(creds, pinfo.ntpassword.hash, 16);
1346 creds_des_encrypt(creds, &pinfo.lmpassword);
1347 creds_des_encrypt(creds, &pinfo.ntpassword);
1350 printf("Testing netr_LogonSamLogonWithFlags (Interactive Logon)\n");
1352 status = dcerpc_netr_LogonSamLogonWithFlags(p, fn_ctx, &r);
1353 if (!r.out.return_authenticator
1354 || !creds_client_check(creds, &r.out.return_authenticator->cred)) {
1355 printf("Credential chaining failed\n");
1356 talloc_free(fn_ctx);
1360 talloc_free(fn_ctx);
1362 if (!NT_STATUS_EQUAL(expected_error, status)) {
1363 printf("[%s]\\[%s] netr_LogonSamLogonWithFlags - expected %s got %s\n",
1364 account_domain, account_name, nt_errstr(expected_error), nt_errstr(status));
1373 BOOL torture_rpc_samlogon(void)
1376 struct dcerpc_pipe *p;
1377 struct dcerpc_binding *b;
1378 struct cli_credentials *machine_credentials;
1379 TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_netlogon");
1381 struct test_join *join_ctx;
1382 struct test_join *user_ctx;
1383 const char *user_password;
1384 char *test_machine_account;
1385 const char *binding = lp_parm_string(-1, "torture", "binding");
1386 const char *userdomain;
1390 unsigned int credential_flags[] = {
1391 NETLOGON_NEG_AUTH2_FLAGS,
1392 NETLOGON_NEG_ARCFOUR,
1393 NETLOGON_NEG_ARCFOUR | NETLOGON_NEG_128BIT,
1394 NETLOGON_NEG_AUTH2_ADS_FLAGS,
1395 0 /* yes, this is a valid flag, causes the use of DES */
1398 struct creds_CredentialState *creds;
1400 test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
1401 /* We only need to join as a workstation here, and in future,
1402 * if we wish to test against trusted domains, we must be a
1403 * workstation here */
1404 join_ctx = torture_join_domain(TEST_MACHINE_NAME, ACB_WSTRUST,
1405 &machine_credentials);
1407 printf("Failed to join as Workstation\n");
1411 userdomain = lp_parm_string(-1, "torture", "userdomain");
1413 userdomain = lp_workgroup();
1416 user_ctx = torture_create_testuser(TEST_USER_NAME,
1421 printf("Failed to join as Workstation\n");
1425 status = dcerpc_parse_binding(mem_ctx, binding, &b);
1426 if (!NT_STATUS_IS_OK(status)) {
1427 printf("Bad binding string %s\n", binding);
1432 /* We have to use schannel, otherwise the SamLogonEx fails
1433 * with INTERNAL_ERROR */
1435 b->flags &= ~DCERPC_AUTH_OPTIONS;
1436 b->flags |= DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128;
1438 status = dcerpc_pipe_connect_b(mem_ctx, &p, b,
1439 DCERPC_NETLOGON_UUID,
1440 DCERPC_NETLOGON_VERSION,
1441 machine_credentials, NULL);
1443 if (!NT_STATUS_IS_OK(status)) {
1444 printf("RPC pipe connect as domain member failed: %s\n", nt_errstr(status));
1449 status = dcerpc_schannel_creds(p->conn->security_state.generic_state, mem_ctx, &creds);
1450 if (!NT_STATUS_IS_OK(status)) {
1459 const char *username;
1460 const char *password;
1462 NTSTATUS expected_interactive_error;
1463 NTSTATUS expected_network_error;
1466 cli_credentials_get_domain(cmdline_credentials),
1467 cli_credentials_get_username(cmdline_credentials),
1468 cli_credentials_get_password(cmdline_credentials),
1474 cli_credentials_get_realm(cmdline_credentials),
1475 cli_credentials_get_username(cmdline_credentials),
1476 cli_credentials_get_password(cmdline_credentials),
1483 talloc_asprintf(mem_ctx,
1485 cli_credentials_get_username(cmdline_credentials),
1486 cli_credentials_get_domain(cmdline_credentials)
1488 cli_credentials_get_password(cmdline_credentials),
1495 talloc_asprintf(mem_ctx,
1497 cli_credentials_get_username(cmdline_credentials),
1498 cli_credentials_get_realm(cmdline_credentials)
1500 cli_credentials_get_password(cmdline_credentials),
1506 cli_credentials_get_domain(machine_credentials),
1507 cli_credentials_get_username(machine_credentials),
1508 cli_credentials_get_password(machine_credentials),
1510 NT_STATUS_NO_SUCH_USER,
1511 NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
1514 cli_credentials_get_realm(machine_credentials),
1515 cli_credentials_get_username(machine_credentials),
1516 cli_credentials_get_password(machine_credentials),
1518 NT_STATUS_NO_SUCH_USER,
1519 NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
1523 talloc_asprintf(mem_ctx,
1525 cli_credentials_get_username(machine_credentials),
1526 cli_credentials_get_domain(machine_credentials)
1528 cli_credentials_get_password(machine_credentials),
1530 NT_STATUS_NO_SUCH_USER,
1531 NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
1535 talloc_asprintf(mem_ctx,
1537 cli_credentials_get_username(machine_credentials),
1538 cli_credentials_get_realm(machine_credentials)
1540 cli_credentials_get_password(machine_credentials),
1542 NT_STATUS_NO_SUCH_USER,
1543 NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
1555 talloc_asprintf(mem_ctx,
1566 talloc_asprintf(mem_ctx,
1577 /* Try all the tests for different username forms */
1578 for (ci = 0; ci < ARRAY_SIZE(usercreds); ci++) {
1580 if (!test_InteractiveLogon(p, mem_ctx, creds,
1582 usercreds[ci].domain,
1583 usercreds[ci].username,
1584 usercreds[ci].password,
1585 usercreds[ci].expected_interactive_error)) {
1589 if (usercreds[ci].network_login) {
1590 if (!test_SamLogon(p, mem_ctx, creds,
1591 usercreds[ci].domain,
1592 usercreds[ci].username,
1593 usercreds[ci].password,
1594 usercreds[ci].expected_network_error,
1601 /* Using the first username form, try the different
1602 * credentials flag setups, on only one of the tests (checks
1603 * session key encryption) */
1605 for (i=0; i < ARRAY_SIZE(credential_flags); i++) {
1606 if (!test_InteractiveLogon(p, mem_ctx, creds,
1608 usercreds[0].domain,
1609 usercreds[0].username,
1610 usercreds[0].password,
1611 usercreds[0].expected_interactive_error)) {
1615 if (usercreds[ci].network_login) {
1616 if (!test_SamLogon(p, mem_ctx, creds,
1617 usercreds[0].domain,
1618 usercreds[0].username,
1619 usercreds[0].password,
1620 usercreds[0].expected_network_error,
1629 talloc_free(mem_ctx);
1631 torture_leave_domain(join_ctx);
1632 torture_leave_domain(user_ctx);