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 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 "librpc/gen_ndr/ndr_netlogon.h"
26 #include "librpc/gen_ndr/ndr_netlogon_c.h"
27 #include "librpc/gen_ndr/ndr_samr_c.h"
28 #include "../lib/crypto/crypto.h"
29 #include "lib/cmdline/popt_common.h"
30 #include "torture/rpc/torture_rpc.h"
31 #include "auth/gensec/gensec.h"
32 #include "libcli/auth/libcli_auth.h"
33 #include "param/param.h"
35 #define TEST_MACHINE_NAME "samlogontest"
36 #define TEST_USER_NAME "samlogontestuser"
37 #define TEST_USER_NAME_WRONG_WKS "samlogontest2"
38 #define TEST_USER_NAME_WRONG_TIME "samlogontest3"
49 struct samlogon_state
{
51 struct torture_context
*tctx
;
53 const char *account_name
;
54 const char *account_domain
;
55 const char *netbios_name
;
57 const char *workgroup
;
58 struct dcerpc_pipe
*p
;
60 uint32_t parameter_control
;
61 struct netr_LogonSamLogon r
;
62 struct netr_LogonSamLogonEx r_ex
;
63 struct netr_LogonSamLogonWithFlags r_flags
;
64 struct netr_Authenticator auth
, auth2
;
65 struct netlogon_creds_CredentialState
*creds
;
66 NTSTATUS expected_error
;
67 bool old_password
; /* Allow an old password to be accepted or rejected without error, as well as session key bugs */
72 Authenticate a user with a challenge/response, checking session key
73 and valid authentication types
75 static NTSTATUS
check_samlogon(struct samlogon_state
*samlogon_state
,
76 enum ntlm_break break_which
,
77 uint32_t parameter_control
,
79 DATA_BLOB
*lm_response
,
80 DATA_BLOB
*nt_response
,
82 uint8_t user_session_key
[16],
86 struct netr_LogonSamLogon
*r
= &samlogon_state
->r
;
87 struct netr_LogonSamLogonEx
*r_ex
= &samlogon_state
->r_ex
;
88 struct netr_LogonSamLogonWithFlags
*r_flags
= &samlogon_state
->r_flags
;
89 struct netr_NetworkInfo ninfo
;
90 struct netr_SamBaseInfo
*base
= NULL
;
91 uint16_t validation_level
= 0;
93 samlogon_state
->r
.in
.logon
->network
= &ninfo
;
94 samlogon_state
->r_ex
.in
.logon
->network
= &ninfo
;
95 samlogon_state
->r_flags
.in
.logon
->network
= &ninfo
;
97 ninfo
.identity_info
.domain_name
.string
= samlogon_state
->account_domain
;
98 ninfo
.identity_info
.parameter_control
= parameter_control
;
99 ninfo
.identity_info
.logon_id_low
= 0;
100 ninfo
.identity_info
.logon_id_high
= 0;
101 ninfo
.identity_info
.account_name
.string
= samlogon_state
->account_name
;
102 ninfo
.identity_info
.workstation
.string
= TEST_MACHINE_NAME
;
104 memcpy(ninfo
.challenge
, chall
->data
, 8);
106 switch (break_which
) {
110 if (lm_response
&& lm_response
->data
) {
111 lm_response
->data
[0]++;
115 if (nt_response
&& nt_response
->data
) {
116 nt_response
->data
[0]++;
120 if (lm_response
&& lm_response
->data
) {
121 lm_response
->data
[0]++;
123 if (nt_response
&& nt_response
->data
) {
124 nt_response
->data
[0]++;
128 data_blob_free(lm_response
);
131 data_blob_free(nt_response
);
136 ninfo
.nt
.data
= nt_response
->data
;
137 ninfo
.nt
.length
= nt_response
->length
;
139 ninfo
.nt
.data
= NULL
;
144 ninfo
.lm
.data
= lm_response
->data
;
145 ninfo
.lm
.length
= lm_response
->length
;
147 ninfo
.lm
.data
= NULL
;
151 switch (samlogon_state
->function_level
) {
152 case NDR_NETR_LOGONSAMLOGON
:
153 ZERO_STRUCT(samlogon_state
->auth2
);
154 netlogon_creds_client_authenticator(samlogon_state
->creds
, &samlogon_state
->auth
);
156 r
->out
.return_authenticator
= NULL
;
157 status
= dcerpc_netr_LogonSamLogon_r(samlogon_state
->p
->binding_handle
,
158 samlogon_state
->mem_ctx
, r
);
159 if (!NT_STATUS_IS_OK(status
)) {
161 *error_string
= strdup(nt_errstr(status
));
165 if (!r
->out
.return_authenticator
||
166 !netlogon_creds_client_check(samlogon_state
->creds
, &r
->out
.return_authenticator
->cred
)) {
167 torture_comment(samlogon_state
->tctx
, "Credential chaining failed\n");
169 if (!NT_STATUS_IS_OK(r
->out
.result
)) {
171 *error_string
= strdup(nt_errstr(r
->out
.result
));
173 return r
->out
.result
;
176 validation_level
= r
->in
.validation_level
;
178 netlogon_creds_decrypt_samlogon_validation(samlogon_state
->creds
,
182 switch (validation_level
) {
184 base
= &r
->out
.validation
->sam2
->base
;
187 base
= &r
->out
.validation
->sam3
->base
;
190 base
= &r
->out
.validation
->sam6
->base
;
194 case NDR_NETR_LOGONSAMLOGONEX
:
195 status
= dcerpc_netr_LogonSamLogonEx_r(samlogon_state
->p
->binding_handle
,
196 samlogon_state
->mem_ctx
, r_ex
);
197 if (!NT_STATUS_IS_OK(status
)) {
199 *error_string
= strdup(nt_errstr(status
));
203 if (!NT_STATUS_IS_OK(r_ex
->out
.result
)) {
205 *error_string
= strdup(nt_errstr(r_ex
->out
.result
));
207 return r_ex
->out
.result
;
210 validation_level
= r_ex
->in
.validation_level
;
212 netlogon_creds_decrypt_samlogon_validation(samlogon_state
->creds
,
214 r_ex
->out
.validation
);
216 switch (validation_level
) {
218 base
= &r_ex
->out
.validation
->sam2
->base
;
221 base
= &r_ex
->out
.validation
->sam3
->base
;
224 base
= &r_ex
->out
.validation
->sam6
->base
;
228 case NDR_NETR_LOGONSAMLOGONWITHFLAGS
:
229 ZERO_STRUCT(samlogon_state
->auth2
);
230 netlogon_creds_client_authenticator(samlogon_state
->creds
, &samlogon_state
->auth
);
232 r_flags
->out
.return_authenticator
= NULL
;
233 status
= dcerpc_netr_LogonSamLogonWithFlags_r(samlogon_state
->p
->binding_handle
,
234 samlogon_state
->mem_ctx
, r_flags
);
235 if (!NT_STATUS_IS_OK(status
)) {
237 *error_string
= strdup(nt_errstr(status
));
241 if (!r_flags
->out
.return_authenticator
||
242 !netlogon_creds_client_check(samlogon_state
->creds
, &r_flags
->out
.return_authenticator
->cred
)) {
243 torture_comment(samlogon_state
->tctx
, "Credential chaining failed\n");
245 if (!NT_STATUS_IS_OK(r_flags
->out
.result
)) {
247 *error_string
= strdup(nt_errstr(r_flags
->out
.result
));
249 return r_flags
->out
.result
;
252 validation_level
= r_flags
->in
.validation_level
;
254 netlogon_creds_decrypt_samlogon_validation(samlogon_state
->creds
,
256 r_flags
->out
.validation
);
258 switch (validation_level
) {
260 base
= &r_flags
->out
.validation
->sam2
->base
;
263 base
= &r_flags
->out
.validation
->sam3
->base
;
266 base
= &r_flags
->out
.validation
->sam6
->base
;
272 return NT_STATUS_INVALID_PARAMETER
;
276 torture_comment(samlogon_state
->tctx
, "No user info returned from 'successful' SamLogon*() call!\n");
277 return NT_STATUS_INVALID_PARAMETER
;
280 if (user_session_key
) {
281 memcpy(user_session_key
, base
->key
.key
, 16);
284 memcpy(lm_key
, base
->LMSessKey
.key
, 8);
292 * Test the normal 'LM and NTLM' combination
295 static bool test_lm_ntlm_broken(struct samlogon_state
*samlogon_state
, enum ntlm_break break_which
, char **error_string
)
300 DATA_BLOB lm_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
301 DATA_BLOB nt_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
302 DATA_BLOB session_key
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 16);
305 uint8_t user_session_key
[16];
310 ZERO_STRUCT(user_session_key
);
312 lm_good
= SMBencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
, lm_response
.data
);
314 ZERO_STRUCT(lm_hash
);
316 E_deshash(samlogon_state
->password
, lm_hash
);
319 SMBNTencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
, nt_response
.data
);
321 E_md4hash(samlogon_state
->password
, nt_hash
);
322 SMBsesskeygen_ntv1(nt_hash
, session_key
.data
);
324 nt_status
= check_samlogon(samlogon_state
,
326 samlogon_state
->parameter_control
,
327 &samlogon_state
->chall
,
334 data_blob_free(&lm_response
);
336 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
337 /* for 'long' passwords, the LM password is invalid */
338 if (break_which
== NO_NT
&& !lm_good
) {
341 /* for 'old' passwords, we allow the server to be OK or wrong password */
342 if (samlogon_state
->old_password
) {
345 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
));
346 } else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND
, nt_status
) && strchr_m(samlogon_state
->account_name
, '@')) {
347 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
) || (break_which
== NO_NT
));
348 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
351 SAFE_FREE(*error_string
);
352 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
354 *error_string
= NULL
;
357 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
359 } else if (!NT_STATUS_IS_OK(nt_status
)) {
363 if (break_which
== NO_NT
&& !lm_good
) {
364 *error_string
= strdup("LM password is 'long' (> 14 chars and therefore invalid) but login did not fail!");
368 if (memcmp(lm_hash
, lm_key
,
369 sizeof(lm_key
)) != 0) {
370 torture_comment(samlogon_state
->tctx
, "LM Key does not match expectations!\n");
371 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
372 dump_data(1, lm_key
, 8);
373 torture_comment(samlogon_state
->tctx
, "expected:\n");
374 dump_data(1, lm_hash
, 8);
378 switch (break_which
) {
381 uint8_t lm_key_expected
[16];
382 memcpy(lm_key_expected
, lm_hash
, 8);
383 memset(lm_key_expected
+8, '\0', 8);
384 if (memcmp(lm_key_expected
, user_session_key
,
386 *error_string
= strdup("NT Session Key does not match expectations (should be first-8 LM hash)!\n");
387 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
388 dump_data(1, user_session_key
, sizeof(user_session_key
));
389 torture_comment(samlogon_state
->tctx
, "expected:\n");
390 dump_data(1, lm_key_expected
, sizeof(lm_key_expected
));
396 if (memcmp(session_key
.data
, user_session_key
,
397 sizeof(user_session_key
)) != 0) {
398 *error_string
= strdup("NT Session Key does not match expectations!\n");
399 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
400 dump_data(1, user_session_key
, 16);
401 torture_comment(samlogon_state
->tctx
, "expected:\n");
402 dump_data(1, session_key
.data
, session_key
.length
);
410 * Test LM authentication, no NT response supplied
413 static bool test_lm(struct samlogon_state
*samlogon_state
, char **error_string
)
416 return test_lm_ntlm_broken(samlogon_state
, NO_NT
, error_string
);
420 * Test the NTLM response only, no LM.
423 static bool test_ntlm(struct samlogon_state
*samlogon_state
, char **error_string
)
425 return test_lm_ntlm_broken(samlogon_state
, NO_LM
, error_string
);
429 * Test the NTLM response only, but in the LM field.
432 static bool test_ntlm_in_lm(struct samlogon_state
*samlogon_state
, char **error_string
)
437 DATA_BLOB nt_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
438 DATA_BLOB session_key
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 16);
442 uint8_t user_session_key
[16];
446 ZERO_STRUCT(user_session_key
);
448 SMBNTencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
,
450 E_md4hash(samlogon_state
->password
, nt_hash
);
451 SMBsesskeygen_ntv1(nt_hash
,
454 lm_good
= E_deshash(samlogon_state
->password
, lm_hash
);
456 ZERO_STRUCT(lm_hash
);
458 nt_status
= check_samlogon(samlogon_state
,
460 samlogon_state
->parameter_control
,
461 &samlogon_state
->chall
,
468 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
469 /* for 'old' passwords, we allow the server to be OK or wrong password */
470 if (samlogon_state
->old_password
) {
474 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
477 SAFE_FREE(*error_string
);
478 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
480 *error_string
= NULL
;
483 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
485 } else if (!NT_STATUS_IS_OK(nt_status
)) {
490 if (memcmp(lm_hash
, lm_key
,
491 sizeof(lm_key
)) != 0) {
492 torture_comment(samlogon_state
->tctx
, "LM Key does not match expectations!\n");
493 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
494 dump_data(1, lm_key
, 8);
495 torture_comment(samlogon_state
->tctx
, "expected:\n");
496 dump_data(1, lm_hash
, 8);
501 if (memcmp(session_key
.data
, lm_key
,
502 sizeof(lm_key
)) != 0) {
503 torture_comment(samlogon_state
->tctx
, "LM Key does not match expectations (first 8 session key)!\n");
504 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
505 dump_data(1, lm_key
, 8);
506 torture_comment(samlogon_state
->tctx
, "expected:\n");
507 dump_data(1, session_key
.data
, 8);
512 if (lm_good
&& memcmp(lm_hash
, user_session_key
, 8) != 0) {
513 uint8_t lm_key_expected
[16];
514 memcpy(lm_key_expected
, lm_hash
, 8);
515 memset(lm_key_expected
+8, '\0', 8);
516 if (memcmp(lm_key_expected
, user_session_key
,
518 torture_comment(samlogon_state
->tctx
, "NT Session Key does not match expectations (should be first-8 LM hash)!\n");
519 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
520 dump_data(1, user_session_key
, sizeof(user_session_key
));
521 torture_comment(samlogon_state
->tctx
, "expected:\n");
522 dump_data(1, lm_key_expected
, sizeof(lm_key_expected
));
530 * Test the NTLM response only, but in the both the NT and LM fields.
533 static bool test_ntlm_in_both(struct samlogon_state
*samlogon_state
, char **error_string
)
538 DATA_BLOB nt_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
539 DATA_BLOB session_key
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 16);
543 uint8_t user_session_key
[16];
547 ZERO_STRUCT(user_session_key
);
549 SMBNTencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
,
551 E_md4hash(samlogon_state
->password
, nt_hash
);
552 SMBsesskeygen_ntv1(nt_hash
,
555 lm_good
= E_deshash(samlogon_state
->password
, lm_hash
);
557 ZERO_STRUCT(lm_hash
);
560 nt_status
= check_samlogon(samlogon_state
,
562 samlogon_state
->parameter_control
,
563 &samlogon_state
->chall
,
570 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
571 /* for 'old' passwords, we allow the server to be OK or wrong password */
572 if (samlogon_state
->old_password
) {
576 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
579 SAFE_FREE(*error_string
);
580 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
582 *error_string
= NULL
;
585 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
587 } else if (!NT_STATUS_IS_OK(nt_status
)) {
591 if (!NT_STATUS_IS_OK(nt_status
)) {
595 if (memcmp(lm_hash
, lm_key
,
596 sizeof(lm_key
)) != 0) {
597 torture_comment(samlogon_state
->tctx
, "LM Key does not match expectations!\n");
598 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
599 dump_data(1, lm_key
, 8);
600 torture_comment(samlogon_state
->tctx
, "expected:\n");
601 dump_data(1, lm_hash
, 8);
604 if (memcmp(session_key
.data
, user_session_key
,
605 sizeof(user_session_key
)) != 0) {
606 torture_comment(samlogon_state
->tctx
, "NT Session Key does not match expectations!\n");
607 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
608 dump_data(1, user_session_key
, 16);
609 torture_comment(samlogon_state
->tctx
, "expected:\n");
610 dump_data(1, session_key
.data
, session_key
.length
);
619 * Test the NTLMv2 and LMv2 responses
627 static bool test_lmv2_ntlmv2_broken(struct samlogon_state
*samlogon_state
,
628 enum ntlm_break break_which
,
629 enum ntlmv2_domain ntlmv2_domain
,
634 DATA_BLOB ntlmv2_response
= data_blob(NULL
, 0);
635 DATA_BLOB lmv2_response
= data_blob(NULL
, 0);
636 DATA_BLOB lmv2_session_key
= data_blob(NULL
, 0);
637 DATA_BLOB ntlmv2_session_key
= data_blob(NULL
, 0);
638 DATA_BLOB names_blob
= NTLMv2_generate_names_blob(samlogon_state
->mem_ctx
, TEST_MACHINE_NAME
, samlogon_state
->workgroup
);
640 uint8_t lm_session_key
[8];
641 uint8_t user_session_key
[16];
643 ZERO_STRUCT(lm_session_key
);
644 ZERO_STRUCT(user_session_key
);
646 switch (ntlmv2_domain
) {
648 if (!SMBNTLMv2encrypt(samlogon_state
->mem_ctx
,
649 samlogon_state
->account_name
, samlogon_state
->account_domain
,
650 samlogon_state
->password
, &samlogon_state
->chall
,
652 &lmv2_response
, &ntlmv2_response
,
653 &lmv2_session_key
, &ntlmv2_session_key
)) {
654 data_blob_free(&names_blob
);
659 if (!SMBNTLMv2encrypt(samlogon_state
->mem_ctx
,
660 samlogon_state
->account_name
, "",
661 samlogon_state
->password
, &samlogon_state
->chall
,
663 &lmv2_response
, &ntlmv2_response
,
664 &lmv2_session_key
, &ntlmv2_session_key
)) {
665 data_blob_free(&names_blob
);
670 data_blob_free(&names_blob
);
672 nt_status
= check_samlogon(samlogon_state
,
674 samlogon_state
->parameter_control
,
675 &samlogon_state
->chall
,
682 data_blob_free(&lmv2_response
);
683 data_blob_free(&ntlmv2_response
);
686 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
687 /* for 'old' passwords, we allow the server to be OK or wrong password */
688 if (samlogon_state
->old_password
) {
691 return break_which
== BREAK_BOTH
;
692 } else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND
, nt_status
) && strchr_m(samlogon_state
->account_name
, '@')) {
693 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
) || (break_which
== NO_NT
));
694 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
697 SAFE_FREE(*error_string
);
698 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
700 *error_string
= NULL
;
703 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
705 } else if (!NT_STATUS_IS_OK(nt_status
)) {
710 switch (break_which
) {
712 if (memcmp(lmv2_session_key
.data
, user_session_key
,
713 sizeof(user_session_key
)) != 0) {
714 torture_comment(samlogon_state
->tctx
, "USER (LMv2) Session Key does not match expectations!\n");
715 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
716 dump_data(1, user_session_key
, 16);
717 torture_comment(samlogon_state
->tctx
, "expected:\n");
718 dump_data(1, lmv2_session_key
.data
, ntlmv2_session_key
.length
);
721 if (memcmp(lmv2_session_key
.data
, lm_session_key
,
722 sizeof(lm_session_key
)) != 0) {
723 torture_comment(samlogon_state
->tctx
, "LM (LMv2) Session Key does not match expectations!\n");
724 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
725 dump_data(1, lm_session_key
, 8);
726 torture_comment(samlogon_state
->tctx
, "expected:\n");
727 dump_data(1, lmv2_session_key
.data
, 8);
732 if (memcmp(ntlmv2_session_key
.data
, user_session_key
,
733 sizeof(user_session_key
)) != 0) {
734 if (memcmp(lmv2_session_key
.data
, user_session_key
,
735 sizeof(user_session_key
)) == 0) {
736 torture_comment(samlogon_state
->tctx
, "USER (NTLMv2) Session Key expected, got LMv2 sessesion key instead:\n");
737 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
738 dump_data(1, user_session_key
, 16);
739 torture_comment(samlogon_state
->tctx
, "expected:\n");
740 dump_data(1, ntlmv2_session_key
.data
, ntlmv2_session_key
.length
);
744 torture_comment(samlogon_state
->tctx
, "USER (NTLMv2) Session Key does not match expectations!\n");
745 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
746 dump_data(1, user_session_key
, 16);
747 torture_comment(samlogon_state
->tctx
, "expected:\n");
748 dump_data(1, ntlmv2_session_key
.data
, ntlmv2_session_key
.length
);
752 if (memcmp(ntlmv2_session_key
.data
, lm_session_key
,
753 sizeof(lm_session_key
)) != 0) {
754 if (memcmp(lmv2_session_key
.data
, lm_session_key
,
755 sizeof(lm_session_key
)) == 0) {
756 torture_comment(samlogon_state
->tctx
, "LM (NTLMv2) Session Key expected, got LMv2 sessesion key instead:\n");
757 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
758 dump_data(1, lm_session_key
, 8);
759 torture_comment(samlogon_state
->tctx
, "expected:\n");
760 dump_data(1, ntlmv2_session_key
.data
, 8);
763 torture_comment(samlogon_state
->tctx
, "LM (NTLMv2) Session Key does not match expectations!\n");
764 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
765 dump_data(1, lm_session_key
, 8);
766 torture_comment(samlogon_state
->tctx
, "expected:\n");
767 dump_data(1, ntlmv2_session_key
.data
, 8);
777 * Test the NTLM and LMv2 responses
780 static bool test_lmv2_ntlm_broken(struct samlogon_state
*samlogon_state
,
781 enum ntlm_break break_which
,
782 enum ntlmv2_domain ntlmv2_domain
,
787 DATA_BLOB ntlmv2_response
= data_blob(NULL
, 0);
788 DATA_BLOB lmv2_response
= data_blob(NULL
, 0);
789 DATA_BLOB lmv2_session_key
= data_blob(NULL
, 0);
790 DATA_BLOB ntlmv2_session_key
= data_blob(NULL
, 0);
791 DATA_BLOB names_blob
= NTLMv2_generate_names_blob(samlogon_state
->mem_ctx
, samlogon_state
->netbios_name
, samlogon_state
->workgroup
);
793 DATA_BLOB ntlm_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
794 DATA_BLOB ntlm_session_key
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 16);
798 uint8_t lm_session_key
[8];
799 uint8_t user_session_key
[16];
802 SMBNTencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
,
804 E_md4hash(samlogon_state
->password
, nt_hash
);
805 SMBsesskeygen_ntv1(nt_hash
,
806 ntlm_session_key
.data
);
808 lm_good
= E_deshash(samlogon_state
->password
, lm_hash
);
810 ZERO_STRUCT(lm_hash
);
813 ZERO_STRUCT(lm_session_key
);
814 ZERO_STRUCT(user_session_key
);
816 switch (ntlmv2_domain
) {
818 /* TODO - test with various domain cases, and without domain */
819 if (!SMBNTLMv2encrypt(samlogon_state
->mem_ctx
,
820 samlogon_state
->account_name
, samlogon_state
->account_domain
,
821 samlogon_state
->password
, &samlogon_state
->chall
,
823 &lmv2_response
, &ntlmv2_response
,
824 &lmv2_session_key
, &ntlmv2_session_key
)) {
825 data_blob_free(&names_blob
);
830 /* TODO - test with various domain cases, and without domain */
831 if (!SMBNTLMv2encrypt(samlogon_state
->mem_ctx
,
832 samlogon_state
->account_name
, "",
833 samlogon_state
->password
, &samlogon_state
->chall
,
835 &lmv2_response
, &ntlmv2_response
,
836 &lmv2_session_key
, &ntlmv2_session_key
)) {
837 data_blob_free(&names_blob
);
843 data_blob_free(&names_blob
);
845 nt_status
= check_samlogon(samlogon_state
,
847 samlogon_state
->parameter_control
,
848 &samlogon_state
->chall
,
855 data_blob_free(&lmv2_response
);
856 data_blob_free(&ntlmv2_response
);
859 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
860 /* for 'old' passwords, we allow the server to be OK or wrong password */
861 if (samlogon_state
->old_password
) {
864 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
));
865 } else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND
, nt_status
) && strchr_m(samlogon_state
->account_name
, '@')) {
866 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
));
867 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
870 SAFE_FREE(*error_string
);
871 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
873 *error_string
= NULL
;
876 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
878 } else if (!NT_STATUS_IS_OK(nt_status
)) {
882 switch (break_which
) {
884 if (memcmp(lmv2_session_key
.data
, user_session_key
,
885 sizeof(user_session_key
)) != 0) {
886 torture_comment(samlogon_state
->tctx
, "USER (LMv2) Session Key does not match expectations!\n");
887 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
888 dump_data(1, user_session_key
, 16);
889 torture_comment(samlogon_state
->tctx
, "expected:\n");
890 dump_data(1, lmv2_session_key
.data
, ntlmv2_session_key
.length
);
893 if (memcmp(lmv2_session_key
.data
, lm_session_key
,
894 sizeof(lm_session_key
)) != 0) {
895 torture_comment(samlogon_state
->tctx
, "LM (LMv2) Session Key does not match expectations!\n");
896 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
897 dump_data(1, lm_session_key
, 8);
898 torture_comment(samlogon_state
->tctx
, "expected:\n");
899 dump_data(1, lmv2_session_key
.data
, 8);
904 if (memcmp(ntlm_session_key
.data
, user_session_key
,
905 sizeof(user_session_key
)) != 0) {
906 torture_comment(samlogon_state
->tctx
, "USER (NTLMv2) Session Key does not match expectations!\n");
907 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
908 dump_data(1, user_session_key
, 16);
909 torture_comment(samlogon_state
->tctx
, "expected:\n");
910 dump_data(1, ntlm_session_key
.data
, ntlm_session_key
.length
);
914 if (memcmp(lm_hash
, lm_session_key
,
915 sizeof(lm_session_key
)) != 0) {
916 torture_comment(samlogon_state
->tctx
, "LM Session Key does not match expectations!\n");
917 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
918 dump_data(1, lm_session_key
, 8);
919 torture_comment(samlogon_state
->tctx
, "expected:\n");
920 dump_data(1, lm_hash
, 8);
924 if (!all_zero(lm_session_key
,
925 sizeof(lm_session_key
))) {
926 torture_comment(samlogon_state
->tctx
, "LM Session Key does not match expectations (zeros)!\n");
927 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
928 dump_data(1, lm_session_key
, 8);
934 if (memcmp(ntlm_session_key
.data
, user_session_key
,
935 sizeof(user_session_key
)) != 0) {
936 torture_comment(samlogon_state
->tctx
, "USER (NTLMv2) Session Key does not match expectations!\n");
937 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
938 dump_data(1, user_session_key
, 16);
939 torture_comment(samlogon_state
->tctx
, "expected:\n");
940 dump_data(1, ntlm_session_key
.data
, ntlm_session_key
.length
);
943 if (memcmp(ntlm_session_key
.data
, lm_session_key
,
944 sizeof(lm_session_key
)) != 0) {
945 torture_comment(samlogon_state
->tctx
, "LM (NTLMv2) Session Key does not match expectations!\n");
946 torture_comment(samlogon_state
->tctx
, "lm_session_key:\n");
947 dump_data(1, lm_session_key
, 8);
948 torture_comment(samlogon_state
->tctx
, "expected:\n");
949 dump_data(1, ntlm_session_key
.data
, 8);
958 * Test the NTLMv2 and LMv2 responses
961 static bool test_lmv2_ntlmv2(struct samlogon_state
*samlogon_state
, char **error_string
)
963 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_NONE
, UPPER_DOMAIN
, error_string
);
967 static bool test_lmv2_ntlmv2_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
969 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_NONE
, NO_DOMAIN
, error_string
);
974 * Test the LMv2 response only
977 static bool test_lmv2(struct samlogon_state
*samlogon_state
, char **error_string
)
979 return test_lmv2_ntlmv2_broken(samlogon_state
, NO_NT
, UPPER_DOMAIN
, error_string
);
982 static bool test_lmv2_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
984 return test_lmv2_ntlmv2_broken(samlogon_state
, NO_NT
, NO_DOMAIN
, error_string
);
988 * Test the NTLMv2 response only
991 static bool test_ntlmv2(struct samlogon_state
*samlogon_state
, char **error_string
)
993 return test_lmv2_ntlmv2_broken(samlogon_state
, NO_LM
, UPPER_DOMAIN
, error_string
);
996 static bool test_ntlmv2_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
998 return test_lmv2_ntlmv2_broken(samlogon_state
, NO_LM
, NO_DOMAIN
, error_string
);
1001 static bool test_lm_ntlm(struct samlogon_state
*samlogon_state
, char **error_string
)
1003 return test_lm_ntlm_broken(samlogon_state
, BREAK_NONE
, error_string
);
1006 static bool test_ntlm_lm_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1008 return test_lm_ntlm_broken(samlogon_state
, BREAK_LM
, error_string
);
1011 static bool test_ntlm_ntlm_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1013 return test_lm_ntlm_broken(samlogon_state
, BREAK_NT
, error_string
);
1016 static bool test_lm_ntlm_both_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1018 return test_lm_ntlm_broken(samlogon_state
, BREAK_BOTH
, error_string
);
1020 static bool test_ntlmv2_lmv2_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1022 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_LM
, UPPER_DOMAIN
, error_string
);
1025 static bool test_ntlmv2_lmv2_broken_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1027 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_LM
, NO_DOMAIN
, error_string
);
1030 static bool test_ntlmv2_ntlmv2_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1032 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_NT
, UPPER_DOMAIN
, error_string
);
1036 static bool test_ntlmv2_ntlmv2_broken_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1038 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_NT
, NO_DOMAIN
, error_string
);
1042 static bool test_ntlmv2_both_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1044 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_BOTH
, UPPER_DOMAIN
, error_string
);
1047 static bool test_ntlmv2_both_broken_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1049 return test_lmv2_ntlmv2_broken(samlogon_state
, BREAK_BOTH
, NO_DOMAIN
, error_string
);
1052 static bool test_lmv2_ntlm_both_broken(struct samlogon_state
*samlogon_state
, char **error_string
)
1054 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_BOTH
, UPPER_DOMAIN
, error_string
);
1057 static bool test_lmv2_ntlm_both_broken_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1059 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_BOTH
, NO_DOMAIN
, error_string
);
1062 static bool test_lmv2_ntlm_break_ntlm(struct samlogon_state
*samlogon_state
, char **error_string
)
1064 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_NT
, UPPER_DOMAIN
, error_string
);
1067 static bool test_lmv2_ntlm_break_ntlm_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1069 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_NT
, NO_DOMAIN
, error_string
);
1072 static bool test_lmv2_ntlm_break_lm(struct samlogon_state
*samlogon_state
, char **error_string
)
1074 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_LM
, UPPER_DOMAIN
, error_string
);
1077 static bool test_lmv2_ntlm_break_lm_no_dom(struct samlogon_state
*samlogon_state
, char **error_string
)
1079 return test_lmv2_ntlm_broken(samlogon_state
, BREAK_LM
, NO_DOMAIN
, error_string
);
1083 * Test the NTLM2 response (extra challenge in LM feild)
1085 * This test is the same as the 'break LM' test, but checks that the
1086 * server implements NTLM2 session security in the right place
1087 * (NETLOGON is the wrong place).
1090 static bool test_ntlm2(struct samlogon_state
*samlogon_state
, char **error_string
)
1094 DATA_BLOB lm_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
1095 DATA_BLOB nt_response
= data_blob_talloc(samlogon_state
->mem_ctx
, NULL
, 24);
1099 uint8_t nt_hash
[16];
1100 uint8_t lm_hash
[16];
1102 uint8_t user_session_key
[16];
1103 uint8_t expected_user_session_key
[16];
1104 uint8_t session_nonce_hash
[16];
1105 uint8_t client_chall
[8];
1107 MD5_CTX md5_session_nonce_ctx
;
1108 HMACMD5Context hmac_ctx
;
1110 ZERO_STRUCT(user_session_key
);
1111 ZERO_STRUCT(lm_key
);
1112 generate_random_buffer(client_chall
, 8);
1114 MD5Init(&md5_session_nonce_ctx
);
1115 MD5Update(&md5_session_nonce_ctx
, samlogon_state
->chall
.data
, 8);
1116 MD5Update(&md5_session_nonce_ctx
, client_chall
, 8);
1117 MD5Final(session_nonce_hash
, &md5_session_nonce_ctx
);
1119 E_md4hash(samlogon_state
->password
, (uint8_t *)nt_hash
);
1120 lm_good
= E_deshash(samlogon_state
->password
, (uint8_t *)lm_hash
);
1121 SMBsesskeygen_ntv1((const uint8_t *)nt_hash
,
1124 SMBNTencrypt(samlogon_state
->password
, samlogon_state
->chall
.data
, nt_response
.data
);
1126 memcpy(lm_response
.data
, session_nonce_hash
, 8);
1127 memset(lm_response
.data
+ 8, 0, 16);
1129 hmac_md5_init_rfc2104(nt_key
, 16, &hmac_ctx
);
1130 hmac_md5_update(samlogon_state
->chall
.data
, 8, &hmac_ctx
);
1131 hmac_md5_update(client_chall
, 8, &hmac_ctx
);
1132 hmac_md5_final(expected_user_session_key
, &hmac_ctx
);
1134 nt_status
= check_samlogon(samlogon_state
,
1136 samlogon_state
->parameter_control
,
1137 &samlogon_state
->chall
,
1144 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
1145 /* for 'old' passwords, we allow the server to be OK or wrong password */
1146 if (samlogon_state
->old_password
) {
1150 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
1153 SAFE_FREE(*error_string
);
1154 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
1156 *error_string
= NULL
;
1159 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
1161 } else if (!NT_STATUS_IS_OK(nt_status
)) {
1166 if (memcmp(lm_hash
, lm_key
,
1167 sizeof(lm_key
)) != 0) {
1168 torture_comment(samlogon_state
->tctx
, "LM Key does not match expectations!\n");
1169 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
1170 dump_data(1, lm_key
, 8);
1171 torture_comment(samlogon_state
->tctx
, "expected:\n");
1172 dump_data(1, lm_hash
, 8);
1176 if (!all_zero(lm_key
, sizeof(lm_key
))) {
1177 torture_comment(samlogon_state
->tctx
, "LM Session Key does not match expectations (zeros)!\n");
1178 torture_comment(samlogon_state
->tctx
, "lm_key:\n");
1179 dump_data(1, lm_key
, 8);
1183 if (memcmp(nt_key
, user_session_key
, 16) != 0) {
1184 torture_comment(samlogon_state
->tctx
, "NT Session Key does not match expectations (should be NT Key)!\n");
1185 torture_comment(samlogon_state
->tctx
, "user_session_key:\n");
1186 dump_data(1, user_session_key
, sizeof(user_session_key
));
1187 torture_comment(samlogon_state
->tctx
, "expected:\n");
1188 dump_data(1, nt_key
, sizeof(nt_key
));
1194 static bool test_plaintext(struct samlogon_state
*samlogon_state
, enum ntlm_break break_which
, char **error_string
)
1197 DATA_BLOB nt_response
= data_blob(NULL
, 0);
1198 DATA_BLOB lm_response
= data_blob(NULL
, 0);
1201 smb_ucs2_t
*unicodepw
;
1202 size_t converted_size
= 0;
1203 uint8_t user_session_key
[16];
1205 uint8_t lm_hash
[16];
1206 DATA_BLOB chall
= data_blob_talloc_zero(samlogon_state
->mem_ctx
, 8);
1207 bool lm_good
= E_deshash(samlogon_state
->password
, lm_hash
);
1209 ZERO_STRUCT(user_session_key
);
1211 if (!push_ucs2_talloc(samlogon_state
->mem_ctx
,
1212 &unicodepw
, samlogon_state
->password
, &converted_size
)) {
1213 DEBUG(0, ("push_ucs2_allocate failed!\n"));
1217 nt_response
= data_blob_talloc(samlogon_state
->mem_ctx
, unicodepw
, strlen_m(samlogon_state
->password
)*2);
1219 password
= strupper_talloc(samlogon_state
->mem_ctx
, samlogon_state
->password
);
1221 if (!convert_string_talloc(samlogon_state
->mem_ctx
,
1223 password
, strlen(password
)+1,
1224 (void**)&dospw
, &converted_size
)) {
1225 DEBUG(0, ("convert_string_talloc failed!\n"));
1229 lm_response
= data_blob_talloc(samlogon_state
->mem_ctx
, dospw
, strlen(dospw
));
1231 nt_status
= check_samlogon(samlogon_state
,
1233 samlogon_state
->parameter_control
| MSV1_0_CLEARTEXT_PASSWORD_ALLOWED
,
1241 if (NT_STATUS_EQUAL(NT_STATUS_WRONG_PASSWORD
, nt_status
)) {
1242 /* for 'old' passwords, we allow the server to be OK or wrong password */
1243 if (samlogon_state
->old_password
) {
1246 /* for 'long' passwords, the LM password is invalid */
1247 if (break_which
== NO_NT
&& !lm_good
) {
1250 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
));
1251 } else if (NT_STATUS_EQUAL(NT_STATUS_NOT_FOUND
, nt_status
) && strchr_m(samlogon_state
->account_name
, '@')) {
1252 return ((break_which
== BREAK_NT
) || (break_which
== BREAK_BOTH
) || (break_which
== NO_NT
));
1253 } else if (!NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
)) {
1256 SAFE_FREE(*error_string
);
1257 ret
= asprintf(error_string
, "Expected error: %s, got %s", nt_errstr(samlogon_state
->expected_error
), nt_errstr(nt_status
));
1259 *error_string
= NULL
;
1262 } else if (NT_STATUS_EQUAL(samlogon_state
->expected_error
, nt_status
) && !NT_STATUS_IS_OK(nt_status
)) {
1264 } else if (!NT_STATUS_IS_OK(nt_status
)) {
1268 if (break_which
== NO_NT
&& !lm_good
) {
1269 *error_string
= strdup("LM password is 'long' (> 14 chars and therefore invalid) but login did not fail!");
1276 static bool test_plaintext_none_broken(struct samlogon_state
*samlogon_state
,
1277 char **error_string
) {
1278 return test_plaintext(samlogon_state
, BREAK_NONE
, error_string
);
1281 static bool test_plaintext_lm_broken(struct samlogon_state
*samlogon_state
,
1282 char **error_string
) {
1283 return test_plaintext(samlogon_state
, BREAK_LM
, error_string
);
1286 static bool test_plaintext_nt_broken(struct samlogon_state
*samlogon_state
,
1287 char **error_string
) {
1288 return test_plaintext(samlogon_state
, BREAK_NT
, error_string
);
1291 static bool test_plaintext_nt_only(struct samlogon_state
*samlogon_state
,
1292 char **error_string
) {
1293 return test_plaintext(samlogon_state
, NO_LM
, error_string
);
1296 static bool test_plaintext_lm_only(struct samlogon_state
*samlogon_state
,
1297 char **error_string
) {
1298 return test_plaintext(samlogon_state
, NO_NT
, error_string
);
1312 - plaintext tests (in challenge-response fields)
1314 check we get the correct session key in each case
1315 check what values we get for the LM session key
1319 static const struct ntlm_tests
{
1320 bool (*fn
)(struct samlogon_state
*, char **);
1324 {test_lmv2_ntlmv2
, "NTLMv2 and LMv2", false},
1326 {test_lmv2_ntlmv2_no_dom
, "NTLMv2 and LMv2 (no domain)", false},
1328 {test_lm
, "LM", false},
1329 {test_lm_ntlm
, "LM and NTLM", false},
1330 {test_lm_ntlm_both_broken
, "LM and NTLM, both broken", false},
1331 {test_ntlm
, "NTLM", false},
1332 {test_ntlm_in_lm
, "NTLM in LM", false},
1333 {test_ntlm_in_both
, "NTLM in both", false},
1334 {test_ntlmv2
, "NTLMv2", false},
1335 {test_ntlmv2_no_dom
, "NTLMv2 (no domain)", false},
1336 {test_lmv2
, "LMv2", false},
1337 {test_lmv2_no_dom
, "LMv2 (no domain)", false},
1338 {test_ntlmv2_lmv2_broken
, "NTLMv2 and LMv2, LMv2 broken", false},
1339 {test_ntlmv2_lmv2_broken_no_dom
, "NTLMv2 and LMv2, LMv2 broken (no domain)", false},
1340 {test_ntlmv2_ntlmv2_broken
, "NTLMv2 and LMv2, NTLMv2 broken", false},
1342 {test_ntlmv2_ntlmv2_broken_no_dom
, "NTLMv2 and LMv2, NTLMv2 broken (no domain)", false},
1344 {test_ntlmv2_both_broken
, "NTLMv2 and LMv2, both broken", false},
1345 {test_ntlmv2_both_broken_no_dom
, "NTLMv2 and LMv2, both broken (no domain)", false},
1346 {test_ntlm_lm_broken
, "NTLM and LM, LM broken", false},
1347 {test_ntlm_ntlm_broken
, "NTLM and LM, NTLM broken", false},
1348 {test_ntlm2
, "NTLM2 (NTLMv2 session security)", false},
1349 {test_lmv2_ntlm_both_broken
, "LMv2 and NTLM, both broken", false},
1350 {test_lmv2_ntlm_both_broken_no_dom
, "LMv2 and NTLM, both broken (no domain)", false},
1351 {test_lmv2_ntlm_break_ntlm
, "LMv2 and NTLM, NTLM broken", false},
1352 {test_lmv2_ntlm_break_ntlm_no_dom
, "LMv2 and NTLM, NTLM broken (no domain)", false},
1353 {test_lmv2_ntlm_break_lm
, "LMv2 and NTLM, LMv2 broken", false},
1354 {test_lmv2_ntlm_break_lm_no_dom
, "LMv2 and NTLM, LMv2 broken (no domain)", false},
1355 {test_plaintext_none_broken
, "Plaintext", false},
1356 {test_plaintext_lm_broken
, "Plaintext LM broken", false},
1357 {test_plaintext_nt_broken
, "Plaintext NT broken", false},
1358 {test_plaintext_nt_only
, "Plaintext NT only", false},
1359 {test_plaintext_lm_only
, "Plaintext LM only", false},
1364 try a netlogon SamLogon
1366 static bool test_SamLogon(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1367 struct torture_context
*tctx
,
1368 struct netlogon_creds_CredentialState
*creds
,
1369 const char *comment
,
1370 const char *account_domain
, const char *account_name
,
1371 const char *plain_pass
, uint32_t parameter_control
,
1372 NTSTATUS expected_error
, bool old_password
,
1375 TALLOC_CTX
*fn_ctx
= talloc_named(mem_ctx
, 0, "test_SamLogon function-level context");
1378 int validation_levels
[] = {2,3,6};
1379 int logon_levels
[] = { NetlogonNetworkInformation
, NetlogonNetworkTransitiveInformation
};
1380 int function_levels
[] = {
1381 NDR_NETR_LOGONSAMLOGON
,
1382 NDR_NETR_LOGONSAMLOGONEX
,
1383 NDR_NETR_LOGONSAMLOGONWITHFLAGS
};
1384 struct samlogon_state samlogon_state
;
1386 union netr_LogonLevel logon
;
1387 union netr_Validation validation
;
1388 uint8_t authoritative
= 0;
1393 torture_comment(tctx
, "Testing netr_LogonSamLogon and netr_LogonSamLogonWithFlags\n");
1395 samlogon_state
.comment
= comment
;
1396 samlogon_state
.account_name
= account_name
;
1397 samlogon_state
.account_domain
= account_domain
;
1398 samlogon_state
.password
= plain_pass
;
1399 samlogon_state
.workgroup
= lpcfg_workgroup(tctx
->lp_ctx
);
1400 samlogon_state
.netbios_name
= lpcfg_netbios_name(tctx
->lp_ctx
);
1401 samlogon_state
.p
= p
;
1402 samlogon_state
.creds
= creds
;
1403 samlogon_state
.expected_error
= expected_error
;
1404 samlogon_state
.chall
= data_blob_talloc(fn_ctx
, NULL
, 8);
1405 samlogon_state
.parameter_control
= parameter_control
;
1406 samlogon_state
.old_password
= old_password
;
1407 samlogon_state
.tctx
= tctx
;
1409 generate_random_buffer(samlogon_state
.chall
.data
, 8);
1410 samlogon_state
.r_flags
.in
.server_name
= talloc_asprintf(fn_ctx
, "\\\\%s", dcerpc_server_name(p
));
1411 samlogon_state
.r_flags
.in
.computer_name
= TEST_MACHINE_NAME
;
1412 samlogon_state
.r_flags
.in
.credential
= &samlogon_state
.auth
;
1413 samlogon_state
.r_flags
.in
.return_authenticator
= &samlogon_state
.auth2
;
1414 samlogon_state
.r_flags
.in
.flags
= &flags
;
1415 samlogon_state
.r_flags
.in
.logon
= &logon
;
1416 samlogon_state
.r_flags
.out
.validation
= &validation
;
1417 samlogon_state
.r_flags
.out
.authoritative
= &authoritative
;
1418 samlogon_state
.r_flags
.out
.flags
= &flags
;
1420 samlogon_state
.r_ex
.in
.server_name
= talloc_asprintf(fn_ctx
, "\\\\%s", dcerpc_server_name(p
));
1421 samlogon_state
.r_ex
.in
.computer_name
= TEST_MACHINE_NAME
;
1422 samlogon_state
.r_ex
.in
.flags
= &flags
;
1423 samlogon_state
.r_ex
.in
.logon
= &logon
;
1424 samlogon_state
.r_ex
.out
.validation
= &validation
;
1425 samlogon_state
.r_ex
.out
.authoritative
= &authoritative
;
1426 samlogon_state
.r_ex
.out
.flags
= &flags
;
1428 samlogon_state
.r
.in
.server_name
= talloc_asprintf(fn_ctx
, "\\\\%s", dcerpc_server_name(p
));
1429 samlogon_state
.r
.in
.computer_name
= TEST_MACHINE_NAME
;
1430 samlogon_state
.r
.in
.credential
= &samlogon_state
.auth
;
1431 samlogon_state
.r
.in
.return_authenticator
= &samlogon_state
.auth2
;
1432 samlogon_state
.r
.in
.logon
= &logon
;
1433 samlogon_state
.r
.out
.validation
= &validation
;
1434 samlogon_state
.r
.out
.authoritative
= &authoritative
;
1437 for (f
=0;f
<ARRAY_SIZE(function_levels
);f
++) {
1438 for (i
=0; test_table
[i
].fn
; i
++) {
1439 if (n_subtests
&& (i
> n_subtests
)) {
1442 for (v
=0;v
<ARRAY_SIZE(validation_levels
);v
++) {
1443 for (l
=0;l
<ARRAY_SIZE(logon_levels
);l
++) {
1444 char *error_string
= NULL
;
1445 TALLOC_CTX
*tmp_ctx
= talloc_named(fn_ctx
, 0, "test_SamLogon inner loop");
1446 samlogon_state
.mem_ctx
= tmp_ctx
;
1447 samlogon_state
.function_level
= function_levels
[f
];
1448 samlogon_state
.r
.in
.validation_level
= validation_levels
[v
];
1449 samlogon_state
.r
.in
.logon_level
= logon_levels
[l
];
1450 samlogon_state
.r_ex
.in
.validation_level
= validation_levels
[v
];
1451 samlogon_state
.r_ex
.in
.logon_level
= logon_levels
[l
];
1452 samlogon_state
.r_flags
.in
.validation_level
= validation_levels
[v
];
1453 samlogon_state
.r_flags
.in
.logon_level
= logon_levels
[l
];
1454 if (!test_table
[i
].fn(&samlogon_state
, &error_string
)) {
1455 torture_comment(tctx
, "Testing '%s' [%s]\\[%s] '%s' at validation level %d, logon level %d, function %d: \n",
1456 samlogon_state
.comment
,
1457 samlogon_state
.account_domain
,
1458 samlogon_state
.account_name
,
1459 test_table
[i
].name
, validation_levels
[v
],
1460 logon_levels
[l
], function_levels
[f
]);
1462 if (test_table
[i
].expect_fail
) {
1463 torture_comment(tctx
, " failed (expected, test incomplete): %s\n", error_string
);
1465 torture_comment(tctx
, " failed: %s\n", error_string
);
1468 SAFE_FREE(error_string
);
1470 talloc_free(tmp_ctx
);
1475 talloc_free(fn_ctx
);
1480 test an ADS style interactive domain logon
1482 bool test_InteractiveLogon(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1483 struct torture_context
*tctx
,
1484 struct netlogon_creds_CredentialState
*creds
,
1485 const char *comment
,
1486 const char *workstation_name
,
1487 const char *account_domain
, const char *account_name
,
1488 const char *plain_pass
, uint32_t parameter_control
,
1489 NTSTATUS expected_error
)
1492 TALLOC_CTX
*fn_ctx
= talloc_named(mem_ctx
, 0, "test_InteractiveLogon function-level context");
1494 struct netr_LogonSamLogonWithFlags r
;
1495 struct netr_Authenticator a
, ra
;
1496 struct netr_PasswordInfo pinfo
;
1499 union netr_LogonLevel logon
;
1500 union netr_Validation validation
;
1501 uint8_t authoritative
= 0;
1502 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1509 ZERO_STRUCT(validation
);
1511 netlogon_creds_client_authenticator(creds
, &a
);
1513 logon
.password
= &pinfo
;
1515 r
.in
.server_name
= talloc_asprintf(fn_ctx
, "\\\\%s", dcerpc_server_name(p
));
1516 r
.in
.computer_name
= TEST_MACHINE_NAME
;
1517 r
.in
.credential
= &a
;
1518 r
.in
.return_authenticator
= &ra
;
1519 r
.in
.logon_level
= NetlogonInteractiveTransitiveInformation
;
1520 r
.in
.logon
= &logon
;
1521 r
.in
.validation_level
= 6;
1522 r
.in
.flags
= &flags
;
1523 r
.out
.validation
= &validation
;
1524 r
.out
.authoritative
= &authoritative
;
1525 r
.out
.flags
= &flags
;
1527 pinfo
.identity_info
.domain_name
.string
= account_domain
;
1528 pinfo
.identity_info
.parameter_control
= parameter_control
;
1529 pinfo
.identity_info
.logon_id_low
= 0;
1530 pinfo
.identity_info
.logon_id_high
= 0;
1531 pinfo
.identity_info
.account_name
.string
= account_name
;
1532 pinfo
.identity_info
.workstation
.string
= workstation_name
;
1534 if (!E_deshash(plain_pass
, pinfo
.lmpassword
.hash
)) {
1535 ZERO_STRUCT(pinfo
.lmpassword
.hash
);
1537 E_md4hash(plain_pass
, pinfo
.ntpassword
.hash
);
1539 if (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
) {
1540 netlogon_creds_arcfour_crypt(creds
, pinfo
.lmpassword
.hash
, 16);
1541 netlogon_creds_arcfour_crypt(creds
, pinfo
.ntpassword
.hash
, 16);
1543 netlogon_creds_des_encrypt(creds
, &pinfo
.lmpassword
);
1544 netlogon_creds_des_encrypt(creds
, &pinfo
.ntpassword
);
1547 torture_comment(tctx
, "Testing netr_LogonSamLogonWithFlags '%s' (Interactive Logon)\n", comment
);
1549 status
= dcerpc_netr_LogonSamLogonWithFlags_r(b
, fn_ctx
, &r
);
1550 torture_assert_ntstatus_ok_goto(tctx
,
1553 talloc_asprintf(tctx
, "%s: netr_LogonSamLogonWithFlags - %s\n",
1554 __location__
, nt_errstr(status
)));
1556 if (!r
.out
.return_authenticator
) {
1557 talloc_free(fn_ctx
);
1558 torture_fail(tctx
, "no authenticator returned");
1561 torture_assert_goto(tctx
,
1562 netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
1564 "Credential chaining failed\n");
1566 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, expected_error
,
1567 talloc_asprintf(tctx
, "[%s]\\[%s] netr_LogonSamLogonWithFlags - expected %s got %s\n",
1568 account_domain
, account_name
, nt_errstr(expected_error
), nt_errstr(r
.out
.result
)));
1572 talloc_free(fn_ctx
);
1577 /* This sets and resets the "minPwdAge" (in order to allow immediate user
1578 * password changes). The behaviour is controlled by the "set" boolean. */
1579 static bool handle_minPwdAge(struct torture_context
*torture
,
1580 TALLOC_CTX
*mem_ctx
, bool set
)
1582 struct dcerpc_pipe
*p
;
1583 struct policy_handle connect_handle
, domain_handle
;
1584 struct samr_Connect c_r
;
1585 struct samr_LookupDomain ld_r
;
1586 struct samr_OpenDomain od_r
;
1587 struct samr_QueryDomainInfo qdi_r
;
1588 struct samr_SetDomainInfo sdi_r
;
1589 struct samr_Close cl_r
;
1590 struct lsa_String domName
;
1591 struct dom_sid
*domSid
= NULL
;
1592 union samr_DomainInfo
*domInfo
= NULL
;
1593 static int64_t old_minPwdAge
= 0;
1596 status
= torture_rpc_connection(torture
, &p
, &ndr_table_samr
);
1597 if (!NT_STATUS_IS_OK(status
)) {
1601 c_r
.in
.system_name
= 0;
1602 c_r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1603 c_r
.out
.connect_handle
= &connect_handle
;
1605 torture_assert_ntstatus_ok(torture
,
1606 dcerpc_samr_Connect_r(p
->binding_handle
, mem_ctx
, &c_r
),
1608 torture_assert_ntstatus_ok(torture
, c_r
.out
.result
, "Connect failed");
1610 ld_r
.in
.connect_handle
= &connect_handle
;
1611 ld_r
.in
.domain_name
= &domName
;
1612 ld_r
.in
.domain_name
->string
= lpcfg_workgroup(torture
->lp_ctx
);
1613 ld_r
.out
.sid
= &domSid
;
1615 torture_assert_ntstatus_ok(torture
,
1616 dcerpc_samr_LookupDomain_r(p
->binding_handle
, mem_ctx
, &ld_r
),
1617 "LookupDomain failed");
1618 torture_assert_ntstatus_ok(torture
, ld_r
.out
.result
,
1619 "LookupDomain failed");
1621 od_r
.in
.connect_handle
= &connect_handle
;
1622 od_r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1623 od_r
.in
.sid
= *ld_r
.out
.sid
;
1624 od_r
.out
.domain_handle
= &domain_handle
;
1626 torture_assert_ntstatus_ok(torture
,
1627 dcerpc_samr_OpenDomain_r(p
->binding_handle
, mem_ctx
, &od_r
),
1628 "OpenDomain failed");
1629 torture_assert_ntstatus_ok(torture
, od_r
.out
.result
,
1630 "OpenDomain failed");
1632 qdi_r
.in
.domain_handle
= &domain_handle
;
1633 qdi_r
.in
.level
= DomainPasswordInformation
;
1634 qdi_r
.out
.info
= &domInfo
;
1636 torture_assert_ntstatus_ok(torture
,
1637 dcerpc_samr_QueryDomainInfo_r(p
->binding_handle
, mem_ctx
, &qdi_r
),
1638 "QueryDomainInfo failed");
1639 torture_assert_ntstatus_ok(torture
, qdi_r
.out
.result
,
1640 "QueryDomainInfo failed");
1643 old_minPwdAge
= domInfo
->info1
.min_password_age
;
1644 domInfo
->info1
.min_password_age
= 0;
1646 domInfo
->info1
.min_password_age
= old_minPwdAge
;
1649 sdi_r
.in
.domain_handle
= &domain_handle
;
1650 sdi_r
.in
.level
= DomainPasswordInformation
;
1651 sdi_r
.in
.info
= domInfo
;
1653 torture_assert_ntstatus_ok(torture
,
1654 dcerpc_samr_SetDomainInfo_r(p
->binding_handle
, mem_ctx
, &sdi_r
),
1655 "SetDomainInfo failed");
1656 torture_assert_ntstatus_ok(torture
, sdi_r
.out
.result
,
1657 "SetDomainInfo failed");
1659 cl_r
.in
.handle
= &connect_handle
;
1660 cl_r
.out
.handle
= &connect_handle
;
1662 torture_assert_ntstatus_ok(torture
,
1663 dcerpc_samr_Close_r(p
->binding_handle
, mem_ctx
, &cl_r
),
1665 torture_assert_ntstatus_ok(torture
, cl_r
.out
.result
, "Close failed");
1670 bool torture_rpc_samlogon(struct torture_context
*torture
)
1673 struct dcerpc_pipe
*p
;
1674 struct dcerpc_binding
*b
;
1675 struct cli_credentials
*machine_credentials
;
1676 TALLOC_CTX
*mem_ctx
= talloc_init("torture_rpc_netlogon");
1678 struct test_join
*join_ctx
= NULL
;
1679 struct test_join
*user_ctx
= NULL
, *user_ctx_wrong_wks
= NULL
, *user_ctx_wrong_time
= NULL
;
1680 const char *old_user_password
, *user_password_wrong_wks
, *user_password_wrong_time
;
1681 char *user_password
;
1682 const char *userdomain
;
1683 struct samr_SetUserInfo s
;
1684 union samr_UserInfo u
;
1688 unsigned int credential_flags
[] = {
1689 NETLOGON_NEG_AUTH2_FLAGS
,
1690 NETLOGON_NEG_ARCFOUR
,
1691 NETLOGON_NEG_ARCFOUR
| NETLOGON_NEG_128BIT
,
1692 NETLOGON_NEG_AUTH2_ADS_FLAGS
,
1693 0 /* yes, this is a valid flag, causes the use of DES */
1696 struct netlogon_creds_CredentialState
*creds
;
1697 struct dcerpc_pipe
*tmp_p
= NULL
;
1699 torture_assert(torture
, handle_minPwdAge(torture
, mem_ctx
, true),
1700 "handle_minPwdAge error!");
1702 /* We only need to join as a workstation here, and in future,
1703 * if we wish to test against trusted domains, we must be a
1704 * workstation here */
1705 join_ctx
= torture_join_domain(torture
, TEST_MACHINE_NAME
, ACB_WSTRUST
,
1706 &machine_credentials
);
1707 torture_assert(torture
, join_ctx
, "Failed to join as Workstation\n");
1709 userdomain
= torture_setting_string(torture
, "userdomain", lpcfg_workgroup(torture
->lp_ctx
));
1711 user_ctx
= torture_create_testuser(torture
,
1715 &old_user_password
);
1716 torture_assert(torture
, user_ctx
, "Failed to create a test user\n");
1718 user_password
= talloc_strdup(torture
, old_user_password
);
1719 torture_assert(torture
, user_password
!= NULL
, "Failed to copy old_user_password\n");
1721 tmp_p
= torture_join_samr_pipe(user_ctx
);
1722 torture_assert(torture
, tmp_p
, "torture_join_samr_pipe failed\n");
1723 test_ChangePasswordUser3(tmp_p
, torture
,
1724 TEST_USER_NAME
, 16 /* > 14 */, &user_password
,
1727 user_ctx_wrong_wks
= torture_create_testuser(torture
,
1728 TEST_USER_NAME_WRONG_WKS
,
1731 &user_password_wrong_wks
);
1732 torture_assert(torture
, user_ctx_wrong_wks
,
1733 "Failed to create a test user (wrong workstation test)\n");
1736 s
.in
.user_handle
= torture_join_samr_user_policy(user_ctx_wrong_wks
);
1740 u
.info21
.fields_present
= SAMR_FIELD_WORKSTATIONS
;
1741 u
.info21
.workstations
.string
= "not" TEST_MACHINE_NAME
;
1743 tmp_p
= torture_join_samr_pipe(user_ctx_wrong_wks
);
1744 status
= dcerpc_samr_SetUserInfo_r(tmp_p
->binding_handle
, mem_ctx
, &s
);
1745 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, failed
,
1746 talloc_asprintf(torture
, "SetUserInfo (list of workstations) failed - %s\n", nt_errstr(status
)));
1747 torture_assert_ntstatus_ok_goto(torture
, s
.out
.result
, ret
, failed
,
1748 talloc_asprintf(torture
, "SetUserInfo (list of workstations) failed - %s\n", nt_errstr(s
.out
.result
)));
1751 = torture_create_testuser(torture
, TEST_USER_NAME_WRONG_TIME
,
1754 &user_password_wrong_time
);
1755 torture_assert(torture
, user_ctx_wrong_time
,
1756 "Failed to create a test user (wrong workstation test)\n");
1759 s
.in
.user_handle
= torture_join_samr_user_policy(user_ctx_wrong_time
);
1763 u
.info21
.fields_present
= SAMR_FIELD_WORKSTATIONS
| SAMR_FIELD_LOGON_HOURS
;
1764 u
.info21
.workstations
.string
= TEST_MACHINE_NAME
;
1765 u
.info21
.logon_hours
.units_per_week
= 168;
1766 u
.info21
.logon_hours
.bits
= talloc_zero_array(mem_ctx
, uint8_t, 168);
1768 tmp_p
= torture_join_samr_pipe(user_ctx_wrong_time
);
1769 status
= dcerpc_samr_SetUserInfo_r(tmp_p
->binding_handle
, mem_ctx
, &s
);
1770 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, failed
,
1771 talloc_asprintf(torture
, "SetUserInfo (logon times and list of workstations) failed - %s\n", nt_errstr(status
)));
1772 torture_assert_ntstatus_ok_goto(torture
, s
.out
.result
, ret
, failed
,
1773 talloc_asprintf(torture
, "SetUserInfo (list of workstations) failed - %s\n", nt_errstr(s
.out
.result
)));
1775 status
= torture_rpc_binding(torture
, &b
);
1776 if (!NT_STATUS_IS_OK(status
)) {
1781 /* We have to use schannel, otherwise the SamLogonEx fails
1782 * with INTERNAL_ERROR */
1784 status
= dcerpc_binding_set_flags(b
,
1786 DCERPC_SIGN
| DCERPC_SEAL
|
1787 DCERPC_SCHANNEL_128
,
1788 DCERPC_AUTH_OPTIONS
);
1789 torture_assert_ntstatus_ok(torture
, status
, "set flags");
1791 status
= dcerpc_pipe_connect_b(mem_ctx
, &p
, b
,
1792 &ndr_table_netlogon
,
1793 machine_credentials
, torture
->ev
, torture
->lp_ctx
);
1795 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, failed
,
1796 talloc_asprintf(torture
, "RPC pipe connect as domain member failed: %s\n", nt_errstr(status
)));
1798 creds
= cli_credentials_get_netlogon_creds(machine_credentials
);
1799 if (creds
== NULL
) {
1807 const char *comment
;
1809 const char *username
;
1810 const char *password
;
1812 NTSTATUS expected_interactive_error
;
1813 NTSTATUS expected_network_error
;
1814 uint32_t parameter_control
;
1815 bool old_password
; /* Allow an old password to be accepted or rejected without error, as well as session key bugs */
1818 .comment
= "domain\\user",
1819 .domain
= cli_credentials_get_domain(
1820 popt_get_cmdline_credentials()),
1821 .username
= cli_credentials_get_username(
1822 popt_get_cmdline_credentials()),
1823 .password
= cli_credentials_get_password(
1824 popt_get_cmdline_credentials()),
1825 .network_login
= true,
1826 .expected_interactive_error
= NT_STATUS_OK
,
1827 .expected_network_error
= NT_STATUS_OK
1830 .comment
= "realm\\user",
1831 .domain
= cli_credentials_get_realm(
1832 popt_get_cmdline_credentials()),
1833 .username
= cli_credentials_get_username(
1834 popt_get_cmdline_credentials()),
1835 .password
= cli_credentials_get_password(
1836 popt_get_cmdline_credentials()),
1837 .network_login
= true,
1838 .expected_interactive_error
= NT_STATUS_OK
,
1839 .expected_network_error
= NT_STATUS_OK
1842 .comment
= "user@domain",
1844 .username
= talloc_asprintf(mem_ctx
,
1846 cli_credentials_get_username(
1847 popt_get_cmdline_credentials()),
1848 cli_credentials_get_domain(
1849 popt_get_cmdline_credentials())
1851 .password
= cli_credentials_get_password(
1852 popt_get_cmdline_credentials()),
1853 .network_login
= false, /* works for some things, but not NTLMv2. Odd */
1854 .expected_interactive_error
= NT_STATUS_OK
,
1855 .expected_network_error
= NT_STATUS_OK
1858 .comment
= "user@realm",
1860 .username
= talloc_asprintf(mem_ctx
,
1862 cli_credentials_get_username(
1863 popt_get_cmdline_credentials()),
1864 cli_credentials_get_realm(
1865 popt_get_cmdline_credentials())
1867 .password
= cli_credentials_get_password(
1868 popt_get_cmdline_credentials()),
1869 .network_login
= true,
1870 .expected_interactive_error
= NT_STATUS_OK
,
1871 .expected_network_error
= NT_STATUS_OK
1874 .comment
= "machine domain\\user",
1875 .domain
= cli_credentials_get_domain(machine_credentials
),
1876 .username
= cli_credentials_get_username(machine_credentials
),
1877 .password
= cli_credentials_get_password(machine_credentials
),
1878 .network_login
= true,
1879 .expected_interactive_error
= NT_STATUS_NO_SUCH_USER
,
1880 .parameter_control
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
1883 .comment
= "machine domain\\user",
1884 .domain
= cli_credentials_get_domain(machine_credentials
),
1885 .username
= cli_credentials_get_username(machine_credentials
),
1886 .password
= cli_credentials_get_password(machine_credentials
),
1887 .network_login
= true,
1888 .expected_interactive_error
= NT_STATUS_NO_SUCH_USER
,
1889 .expected_network_error
= NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
1892 .comment
= "machine realm\\user",
1893 .domain
= cli_credentials_get_realm(machine_credentials
),
1894 .username
= cli_credentials_get_username(machine_credentials
),
1895 .password
= cli_credentials_get_password(machine_credentials
),
1896 .network_login
= true,
1897 .expected_interactive_error
= NT_STATUS_NO_SUCH_USER
,
1898 .parameter_control
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
1901 .comment
= "machine user@domain",
1903 .username
= talloc_asprintf(mem_ctx
,
1905 cli_credentials_get_username(machine_credentials
),
1906 cli_credentials_get_domain(machine_credentials
)
1908 .password
= cli_credentials_get_password(machine_credentials
),
1909 .network_login
= false, /* works for some things, but not NTLMv2. Odd */
1910 .expected_interactive_error
= NT_STATUS_NO_SUCH_USER
,
1911 .parameter_control
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
1914 .comment
= "machine user@realm",
1916 .username
= talloc_asprintf(mem_ctx
,
1918 cli_credentials_get_username(machine_credentials
),
1919 cli_credentials_get_realm(machine_credentials
)
1921 .password
= cli_credentials_get_password(machine_credentials
),
1922 .network_login
= true,
1923 .expected_interactive_error
= NT_STATUS_NO_SUCH_USER
,
1924 .parameter_control
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
1927 .comment
= "test user (long pw): domain\\user",
1928 .domain
= userdomain
,
1929 .username
= TEST_USER_NAME
,
1930 .password
= user_password
,
1931 .network_login
= true,
1932 .expected_interactive_error
= NT_STATUS_OK
,
1933 .expected_network_error
= NT_STATUS_OK
1936 .comment
= "test user (long pw): user@realm",
1938 .username
= talloc_asprintf(mem_ctx
,
1941 lpcfg_realm(torture
->lp_ctx
)),
1942 .password
= user_password
,
1943 .network_login
= true,
1944 .expected_interactive_error
= NT_STATUS_OK
,
1945 .expected_network_error
= NT_STATUS_OK
1948 .comment
= "test user (long pw): user@domain",
1950 .username
= talloc_asprintf(mem_ctx
,
1954 .password
= user_password
,
1955 .network_login
= false, /* works for some things, but not NTLMv2. Odd */
1956 .expected_interactive_error
= NT_STATUS_OK
,
1957 .expected_network_error
= NT_STATUS_OK
1959 /* Oddball, can we use the old password ? */
1961 .comment
= "test user: user\\domain OLD PASSWORD",
1962 .domain
= userdomain
,
1963 .username
= TEST_USER_NAME
,
1964 .password
= old_user_password
,
1965 .network_login
= true,
1966 .expected_interactive_error
= NT_STATUS_WRONG_PASSWORD
,
1967 .expected_network_error
= NT_STATUS_OK
,
1968 .old_password
= true
1971 .comment
= "test user (wrong workstation): domain\\user",
1972 .domain
= userdomain
,
1973 .username
= TEST_USER_NAME_WRONG_WKS
,
1974 .password
= user_password_wrong_wks
,
1975 .network_login
= true,
1976 .expected_interactive_error
= NT_STATUS_INVALID_WORKSTATION
,
1977 .expected_network_error
= NT_STATUS_INVALID_WORKSTATION
1981 /* Try all the tests for different username forms */
1982 for (ci
= 0; ci
< ARRAY_SIZE(usercreds
); ci
++) {
1984 if (!test_InteractiveLogon(p
, mem_ctx
, torture
, creds
,
1985 usercreds
[ci
].comment
,
1987 usercreds
[ci
].domain
,
1988 usercreds
[ci
].username
,
1989 usercreds
[ci
].password
,
1990 usercreds
[ci
].parameter_control
,
1991 usercreds
[ci
].expected_interactive_error
)) {
1996 if (usercreds
[ci
].network_login
) {
1997 if (!test_SamLogon(p
, mem_ctx
, torture
, creds
,
1998 usercreds
[ci
].comment
,
1999 usercreds
[ci
].domain
,
2000 usercreds
[ci
].username
,
2001 usercreds
[ci
].password
,
2002 usercreds
[ci
].parameter_control
,
2003 usercreds
[ci
].expected_network_error
,
2004 usercreds
[ci
].old_password
,
2012 /* Using the first username form, try the different
2013 * credentials flag setups, on only one of the tests (checks
2014 * session key encryption) */
2016 for (i
=0; i
< ARRAY_SIZE(credential_flags
); i
++) {
2017 /* TODO: Somehow we lost setting up the different credential flags here! */
2019 torture_comment(torture
,
2020 "Testing with flags: 0x%08x\n",
2021 credential_flags
[i
]);
2023 if (!test_InteractiveLogon(p
, mem_ctx
, torture
, creds
,
2024 usercreds
[0].comment
,
2026 usercreds
[0].domain
,
2027 usercreds
[0].username
,
2028 usercreds
[0].password
,
2029 usercreds
[0].parameter_control
,
2030 usercreds
[0].expected_interactive_error
)) {
2035 if (usercreds
[0].network_login
) {
2036 if (!test_SamLogon(p
, mem_ctx
, torture
, creds
,
2037 usercreds
[0].comment
,
2038 usercreds
[0].domain
,
2039 usercreds
[0].username
,
2040 usercreds
[0].password
,
2041 usercreds
[0].parameter_control
,
2042 usercreds
[0].expected_network_error
,
2043 usercreds
[0].old_password
,
2053 torture_assert(torture
, handle_minPwdAge(torture
, mem_ctx
, false),
2054 "handle_minPwdAge error!");
2056 talloc_free(mem_ctx
);
2058 torture_leave_domain(torture
, join_ctx
);
2059 torture_leave_domain(torture
, user_ctx
);
2060 torture_leave_domain(torture
, user_ctx_wrong_wks
);
2061 torture_leave_domain(torture
, user_ctx_wrong_time
);