2 Unix SMB/CIFS implementation.
4 test suite for netlogon rpc 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 "torture/torture.h"
27 #include "lib/events/events.h"
28 #include "auth/auth.h"
29 #include "lib/cmdline/popt_common.h"
30 #include "torture/rpc/rpc.h"
31 #include "libcli/auth/libcli_auth.h"
32 #include "librpc/gen_ndr/ndr_netlogon_c.h"
33 #include "librpc/gen_ndr/ndr_lsa_c.h"
35 static const char *machine_password;
37 #define TEST_MACHINE_NAME "torturetest"
39 static BOOL test_LogonUasLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
42 struct netr_LogonUasLogon r;
44 if (lp_parm_bool(-1, "torture", "samba4", False)) {
45 printf("skipping LogonUasLogon test against Samba4\n");
49 r.in.server_name = NULL;
50 r.in.account_name = cli_credentials_get_username(cmdline_credentials);
51 r.in.workstation = TEST_MACHINE_NAME;
53 printf("Testing LogonUasLogon\n");
55 status = dcerpc_netr_LogonUasLogon(p, mem_ctx, &r);
56 if (!NT_STATUS_IS_OK(status)) {
57 printf("LogonUasLogon - %s\n", nt_errstr(status));
65 static BOOL test_LogonUasLogoff(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
68 struct netr_LogonUasLogoff r;
70 if (lp_parm_bool(-1, "torture", "samba4", False)) {
71 printf("skipping LogonUasLogoff test against Samba4\n");
75 r.in.server_name = NULL;
76 r.in.account_name = cli_credentials_get_username(cmdline_credentials);
77 r.in.workstation = TEST_MACHINE_NAME;
79 printf("Testing LogonUasLogoff\n");
81 status = dcerpc_netr_LogonUasLogoff(p, mem_ctx, &r);
82 if (!NT_STATUS_IS_OK(status)) {
83 printf("LogonUasLogoff - %s\n", nt_errstr(status));
91 static BOOL test_SetupCredentials(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
92 const char *machine_name,
93 const char *plain_pass,
94 struct creds_CredentialState **creds_out)
97 struct netr_ServerReqChallenge r;
98 struct netr_ServerAuthenticate a;
99 struct netr_Credential credentials1, credentials2, credentials3;
100 struct creds_CredentialState *creds;
101 struct samr_Password mach_password;
103 printf("Testing ServerReqChallenge\n");
105 creds = talloc(mem_ctx, struct creds_CredentialState);
110 r.in.server_name = NULL;
111 r.in.computer_name = machine_name;
112 r.in.credentials = &credentials1;
113 r.out.credentials = &credentials2;
115 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
117 status = dcerpc_netr_ServerReqChallenge(p, mem_ctx, &r);
118 if (!NT_STATUS_IS_OK(status)) {
119 printf("ServerReqChallenge - %s\n", nt_errstr(status));
123 E_md4hash(plain_pass, mach_password.hash);
125 a.in.server_name = NULL;
126 a.in.account_name = talloc_asprintf(mem_ctx, "%s$", machine_name);
127 a.in.secure_channel_type = SEC_CHAN_BDC;
128 a.in.computer_name = machine_name;
129 a.in.credentials = &credentials3;
130 a.out.credentials = &credentials3;
132 creds_client_init(creds, &credentials1, &credentials2,
133 &mach_password, &credentials3,
136 printf("Testing ServerAuthenticate\n");
138 status = dcerpc_netr_ServerAuthenticate(p, mem_ctx, &a);
139 if (!NT_STATUS_IS_OK(status)) {
140 printf("ServerAuthenticate - %s\n", nt_errstr(status));
144 if (!creds_client_check(creds, &credentials3)) {
145 printf("Credential chaining failed\n");
153 static BOOL test_SetupCredentials2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
154 uint32_t negotiate_flags,
155 const char *machine_name,
156 const char *plain_pass,
158 struct creds_CredentialState **creds_out)
161 struct netr_ServerReqChallenge r;
162 struct netr_ServerAuthenticate2 a;
163 struct netr_Credential credentials1, credentials2, credentials3;
164 struct creds_CredentialState *creds;
165 struct samr_Password mach_password;
167 printf("Testing ServerReqChallenge\n");
169 creds = talloc(mem_ctx, struct creds_CredentialState);
174 r.in.server_name = NULL;
175 r.in.computer_name = machine_name;
176 r.in.credentials = &credentials1;
177 r.out.credentials = &credentials2;
179 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
181 status = dcerpc_netr_ServerReqChallenge(p, mem_ctx, &r);
182 if (!NT_STATUS_IS_OK(status)) {
183 printf("ServerReqChallenge - %s\n", nt_errstr(status));
187 E_md4hash(plain_pass, mach_password.hash);
189 a.in.server_name = NULL;
190 a.in.account_name = talloc_asprintf(mem_ctx, "%s$", machine_name);
191 a.in.secure_channel_type = sec_chan_type;
192 a.in.computer_name = machine_name;
193 a.in.negotiate_flags = &negotiate_flags;
194 a.out.negotiate_flags = &negotiate_flags;
195 a.in.credentials = &credentials3;
196 a.out.credentials = &credentials3;
198 creds_client_init(creds, &credentials1, &credentials2,
199 &mach_password, &credentials3,
202 printf("Testing ServerAuthenticate2\n");
204 status = dcerpc_netr_ServerAuthenticate2(p, mem_ctx, &a);
205 if (!NT_STATUS_IS_OK(status)) {
206 printf("ServerAuthenticate2 - %s\n", nt_errstr(status));
210 if (!creds_client_check(creds, &credentials3)) {
211 printf("Credential chaining failed\n");
215 printf("negotiate_flags=0x%08x\n", negotiate_flags);
222 static BOOL test_SetupCredentials3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
223 uint32_t negotiate_flags,
224 const char *machine_name,
225 const char *plain_pass,
226 struct creds_CredentialState **creds_out)
229 struct netr_ServerReqChallenge r;
230 struct netr_ServerAuthenticate3 a;
231 struct netr_Credential credentials1, credentials2, credentials3;
232 struct creds_CredentialState *creds;
233 struct samr_Password mach_password;
236 printf("Testing ServerReqChallenge\n");
238 creds = talloc(mem_ctx, struct creds_CredentialState);
243 r.in.server_name = NULL;
244 r.in.computer_name = machine_name;
245 r.in.credentials = &credentials1;
246 r.out.credentials = &credentials2;
248 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
250 status = dcerpc_netr_ServerReqChallenge(p, mem_ctx, &r);
251 if (!NT_STATUS_IS_OK(status)) {
252 printf("ServerReqChallenge - %s\n", nt_errstr(status));
256 E_md4hash(plain_pass, mach_password.hash);
258 a.in.server_name = NULL;
259 a.in.account_name = talloc_asprintf(mem_ctx, "%s$", machine_name);
260 a.in.secure_channel_type = SEC_CHAN_BDC;
261 a.in.computer_name = machine_name;
262 a.in.negotiate_flags = &negotiate_flags;
263 a.in.credentials = &credentials3;
264 a.out.credentials = &credentials3;
265 a.out.negotiate_flags = &negotiate_flags;
268 creds_client_init(creds, &credentials1, &credentials2,
269 &mach_password, &credentials3,
272 printf("Testing ServerAuthenticate3\n");
274 status = dcerpc_netr_ServerAuthenticate3(p, mem_ctx, &a);
275 if (!NT_STATUS_IS_OK(status)) {
276 printf("ServerAuthenticate3 - %s\n", nt_errstr(status));
280 if (!creds_client_check(creds, &credentials3)) {
281 printf("Credential chaining failed\n");
285 printf("negotiate_flags=0x%08x\n", negotiate_flags);
292 try a change password for our machine account
294 static BOOL test_SetPassword(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
297 struct netr_ServerPasswordSet r;
298 const char *password;
299 struct creds_CredentialState *creds;
301 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME,
302 machine_password, &creds)) {
306 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
307 r.in.account_name = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
308 r.in.secure_channel_type = SEC_CHAN_BDC;
309 r.in.computer_name = TEST_MACHINE_NAME;
311 password = generate_random_str(mem_ctx, 8);
312 E_md4hash(password, r.in.new_password.hash);
314 creds_des_encrypt(creds, &r.in.new_password);
316 printf("Testing ServerPasswordSet on machine account\n");
317 d_printf("Changing machine account password to '%s'\n", password);
319 creds_client_authenticator(creds, &r.in.credential);
321 status = dcerpc_netr_ServerPasswordSet(p, mem_ctx, &r);
322 if (!NT_STATUS_IS_OK(status)) {
323 printf("ServerPasswordSet - %s\n", nt_errstr(status));
327 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
328 printf("Credential chaining failed\n");
331 /* by changing the machine password twice we test the
332 credentials chaining fully, and we verify that the server
333 allows the password to be set to the same value twice in a
334 row (match win2k3) */
335 printf("Testing a second ServerPasswordSet on machine account\n");
336 d_printf("Changing machine account password to '%s' (same as previous run)\n", password);
338 creds_client_authenticator(creds, &r.in.credential);
340 status = dcerpc_netr_ServerPasswordSet(p, mem_ctx, &r);
341 if (!NT_STATUS_IS_OK(status)) {
342 printf("ServerPasswordSet (2) - %s\n", nt_errstr(status));
346 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
347 printf("Credential chaining failed\n");
350 machine_password = password;
352 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
353 printf("ServerPasswordSet failed to actually change the password\n");
361 try a change password for our machine account
363 static BOOL test_SetPassword2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
366 struct netr_ServerPasswordSet2 r;
367 const char *password;
368 struct creds_CredentialState *creds;
369 struct samr_CryptPassword password_buf;
371 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME,
372 machine_password, &creds)) {
376 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
377 r.in.account_name = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
378 r.in.secure_channel_type = SEC_CHAN_BDC;
379 r.in.computer_name = TEST_MACHINE_NAME;
381 password = generate_random_str(mem_ctx, 8);
382 encode_pw_buffer(password_buf.data, password, STR_UNICODE);
383 creds_arcfour_crypt(creds, password_buf.data, 516);
385 memcpy(r.in.new_password.data, password_buf.data, 512);
386 r.in.new_password.length = IVAL(password_buf.data, 512);
388 printf("Testing ServerPasswordSet2 on machine account\n");
389 d_printf("Changing machine account password to '%s'\n", password);
391 creds_client_authenticator(creds, &r.in.credential);
393 status = dcerpc_netr_ServerPasswordSet2(p, mem_ctx, &r);
394 if (!NT_STATUS_IS_OK(status)) {
395 printf("ServerPasswordSet2 - %s\n", nt_errstr(status));
399 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
400 printf("Credential chaining failed\n");
403 machine_password = password;
405 if (!lp_parm_bool(-1, "torture", "dangerous", False)) {
406 printf("Not testing ability to set password to '', enable dangerous tests to perform this test\n");
408 /* by changing the machine password to ""
409 * we check if the server uses password restrictions
410 * for ServerPasswordSet2
411 * (win2k3 accepts "")
414 encode_pw_buffer(password_buf.data, password, STR_UNICODE);
415 creds_arcfour_crypt(creds, password_buf.data, 516);
417 memcpy(r.in.new_password.data, password_buf.data, 512);
418 r.in.new_password.length = IVAL(password_buf.data, 512);
420 printf("Testing ServerPasswordSet2 on machine account\n");
421 d_printf("Changing machine account password to '%s'\n", password);
423 creds_client_authenticator(creds, &r.in.credential);
425 status = dcerpc_netr_ServerPasswordSet2(p, mem_ctx, &r);
426 if (!NT_STATUS_IS_OK(status)) {
427 printf("ServerPasswordSet2 - %s\n", nt_errstr(status));
431 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
432 printf("Credential chaining failed\n");
435 machine_password = password;
438 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
439 printf("ServerPasswordSet failed to actually change the password\n");
443 /* now try a random password */
444 password = generate_random_str(mem_ctx, 8);
445 encode_pw_buffer(password_buf.data, password, STR_UNICODE);
446 creds_arcfour_crypt(creds, password_buf.data, 516);
448 memcpy(r.in.new_password.data, password_buf.data, 512);
449 r.in.new_password.length = IVAL(password_buf.data, 512);
451 printf("Testing second ServerPasswordSet2 on machine account\n");
452 d_printf("Changing machine account password to '%s'\n", password);
454 creds_client_authenticator(creds, &r.in.credential);
456 status = dcerpc_netr_ServerPasswordSet2(p, mem_ctx, &r);
457 if (!NT_STATUS_IS_OK(status)) {
458 printf("ServerPasswordSet2 (2) - %s\n", nt_errstr(status));
462 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
463 printf("Credential chaining failed\n");
466 /* by changing the machine password twice we test the
467 credentials chaining fully, and we verify that the server
468 allows the password to be set to the same value twice in a
469 row (match win2k3) */
470 printf("Testing a second ServerPasswordSet2 on machine account\n");
471 d_printf("Changing machine account password to '%s' (same as previous run)\n", password);
473 creds_client_authenticator(creds, &r.in.credential);
475 status = dcerpc_netr_ServerPasswordSet2(p, mem_ctx, &r);
476 if (!NT_STATUS_IS_OK(status)) {
477 printf("ServerPasswordSet (3) - %s\n", nt_errstr(status));
481 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
482 printf("Credential chaining failed\n");
485 machine_password = password;
487 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
488 printf("ServerPasswordSet failed to actually change the password\n");
496 try a netlogon SamLogon
498 BOOL test_netlogon_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
499 struct cli_credentials *credentials,
500 struct creds_CredentialState *creds)
503 struct netr_LogonSamLogon r;
504 struct netr_Authenticator auth, auth2;
505 struct netr_NetworkInfo ninfo;
506 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
509 int flags = CLI_CRED_NTLM_AUTH;
510 if (lp_client_lanman_auth()) {
511 flags |= CLI_CRED_LANMAN_AUTH;
514 if (lp_client_ntlmv2_auth()) {
515 flags |= CLI_CRED_NTLMv2_AUTH;
518 cli_credentials_get_ntlm_username_domain(cmdline_credentials, mem_ctx,
519 &ninfo.identity_info.account_name.string,
520 &ninfo.identity_info.domain_name.string);
522 generate_random_buffer(ninfo.challenge,
523 sizeof(ninfo.challenge));
524 chal = data_blob_const(ninfo.challenge,
525 sizeof(ninfo.challenge));
527 names_blob = NTLMv2_generate_names_blob(mem_ctx, cli_credentials_get_workstation(credentials),
528 cli_credentials_get_domain(credentials));
530 status = cli_credentials_get_ntlm_response(cmdline_credentials, mem_ctx,
536 if (!NT_STATUS_IS_OK(status)) {
537 printf("cli_credentials_get_ntlm_response failed: %s\n",
542 ninfo.lm.data = lm_resp.data;
543 ninfo.lm.length = lm_resp.length;
545 ninfo.nt.data = nt_resp.data;
546 ninfo.nt.length = nt_resp.length;
548 ninfo.identity_info.parameter_control = 0;
549 ninfo.identity_info.logon_id_low = 0;
550 ninfo.identity_info.logon_id_high = 0;
551 ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
553 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
554 r.in.computer_name = cli_credentials_get_workstation(credentials);
555 r.in.credential = &auth;
556 r.in.return_authenticator = &auth2;
557 r.in.logon_level = 2;
558 r.in.logon.network = &ninfo;
560 d_printf("Testing LogonSamLogon with name %s\n", ninfo.identity_info.account_name.string);
564 creds_client_authenticator(creds, &auth);
566 r.in.validation_level = i;
568 status = dcerpc_netr_LogonSamLogon(p, mem_ctx, &r);
569 if (!NT_STATUS_IS_OK(status)) {
570 printf("LogonSamLogon failed: %s\n",
575 if (!creds_client_check(creds, &r.out.return_authenticator->cred)) {
576 printf("Credential chaining failed\n");
581 r.in.credential = NULL;
585 r.in.validation_level = i;
587 printf("Testing SamLogon with validation level %d and a NULL credential\n", i);
589 status = dcerpc_netr_LogonSamLogon(p, mem_ctx, &r);
590 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
591 printf("LogonSamLogon expected INVALID_PARAMETER, got: %s\n", nt_errstr(status));
601 try a netlogon SamLogon
603 static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
604 struct cli_credentials *credentials)
606 struct creds_CredentialState *creds;
608 if (!test_SetupCredentials(p, mem_ctx, cli_credentials_get_workstation(credentials),
609 cli_credentials_get_password(credentials), &creds)) {
613 return test_netlogon_ops(p, mem_ctx, credentials, creds);
616 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
617 static uint64_t sequence_nums[3];
620 try a netlogon DatabaseSync
622 static BOOL test_DatabaseSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
625 struct netr_DatabaseSync r;
626 struct creds_CredentialState *creds;
627 const uint32_t database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS};
631 if (lp_parm_bool(-1, "torture", "samba4", False)) {
632 printf("skipping DatabaseSync test against Samba4\n");
636 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
640 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
641 r.in.computername = TEST_MACHINE_NAME;
642 r.in.preferredmaximumlength = (uint32_t)-1;
643 ZERO_STRUCT(r.in.return_authenticator);
645 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
646 r.in.sync_context = 0;
647 r.in.database_id = database_ids[i];
649 printf("Testing DatabaseSync of id %d\n", r.in.database_id);
652 creds_client_authenticator(creds, &r.in.credential);
654 status = dcerpc_netr_DatabaseSync(p, mem_ctx, &r);
655 if (!NT_STATUS_IS_OK(status) &&
656 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
657 printf("DatabaseSync - %s\n", nt_errstr(status));
662 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
663 printf("Credential chaining failed\n");
666 r.in.sync_context = r.out.sync_context;
668 if (r.out.delta_enum_array &&
669 r.out.delta_enum_array->num_deltas > 0 &&
670 r.out.delta_enum_array->delta_enum[0].delta_type == NETR_DELTA_DOMAIN &&
671 r.out.delta_enum_array->delta_enum[0].delta_union.domain) {
672 sequence_nums[r.in.database_id] =
673 r.out.delta_enum_array->delta_enum[0].delta_union.domain->sequence_num;
674 printf("\tsequence_nums[%d]=%llu\n",
676 (unsigned long long)sequence_nums[r.in.database_id]);
678 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
686 try a netlogon DatabaseDeltas
688 static BOOL test_DatabaseDeltas(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
691 struct netr_DatabaseDeltas r;
692 struct creds_CredentialState *creds;
693 const uint32_t database_ids[] = {0, 1, 2};
697 if (lp_parm_bool(-1, "torture", "samba4", False)) {
698 printf("skipping DatabaseDeltas test against Samba4\n");
702 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
706 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
707 r.in.computername = TEST_MACHINE_NAME;
708 r.in.preferredmaximumlength = (uint32_t)-1;
709 ZERO_STRUCT(r.in.return_authenticator);
711 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
712 r.in.database_id = database_ids[i];
713 r.in.sequence_num = sequence_nums[r.in.database_id];
715 if (r.in.sequence_num == 0) continue;
717 r.in.sequence_num -= 1;
720 printf("Testing DatabaseDeltas of id %d at %llu\n",
721 r.in.database_id, (unsigned long long)r.in.sequence_num);
724 creds_client_authenticator(creds, &r.in.credential);
726 status = dcerpc_netr_DatabaseDeltas(p, mem_ctx, &r);
727 if (NT_STATUS_EQUAL(status,
728 NT_STATUS_SYNCHRONIZATION_REQUIRED)) {
729 printf("no considering %s to be an error\n",
733 if (!NT_STATUS_IS_OK(status) &&
734 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
735 printf("DatabaseDeltas - %s\n", nt_errstr(status));
740 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
741 printf("Credential chaining failed\n");
745 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
753 try a netlogon AccountDeltas
755 static BOOL test_AccountDeltas(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
758 struct netr_AccountDeltas r;
759 struct creds_CredentialState *creds;
762 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
766 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
767 r.in.computername = TEST_MACHINE_NAME;
768 ZERO_STRUCT(r.in.return_authenticator);
769 creds_client_authenticator(creds, &r.in.credential);
770 ZERO_STRUCT(r.in.uas);
775 printf("Testing AccountDeltas\n");
777 /* w2k3 returns "NOT IMPLEMENTED" for this call */
778 status = dcerpc_netr_AccountDeltas(p, mem_ctx, &r);
779 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
780 printf("AccountDeltas - %s\n", nt_errstr(status));
788 try a netlogon AccountSync
790 static BOOL test_AccountSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
793 struct netr_AccountSync r;
794 struct creds_CredentialState *creds;
797 if (!test_SetupCredentials(p, mem_ctx, TEST_MACHINE_NAME, machine_password, &creds)) {
801 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
802 r.in.computername = TEST_MACHINE_NAME;
803 ZERO_STRUCT(r.in.return_authenticator);
804 creds_client_authenticator(creds, &r.in.credential);
805 ZERO_STRUCT(r.in.recordid);
810 printf("Testing AccountSync\n");
812 /* w2k3 returns "NOT IMPLEMENTED" for this call */
813 status = dcerpc_netr_AccountSync(p, mem_ctx, &r);
814 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
815 printf("AccountSync - %s\n", nt_errstr(status));
823 try a netlogon GetDcName
825 static BOOL test_GetDcName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
828 struct netr_GetDcName r;
831 if (lp_parm_bool(-1, "torture", "samba4", False)) {
832 printf("skipping GetDCName test against Samba4\n");
836 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
837 r.in.domainname = lp_workgroup();
839 printf("Testing GetDcName\n");
841 status = dcerpc_netr_GetDcName(p, mem_ctx, &r);
842 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
843 printf("GetDcName - %s/%s\n", nt_errstr(status), win_errstr(r.out.result));
847 d_printf("\tDC is at '%s'\n", r.out.dcname);
853 try a netlogon LogonControl
855 static BOOL test_LogonControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
858 struct netr_LogonControl r;
862 if (lp_parm_bool(-1, "torture", "samba4", False)) {
863 printf("skipping LogonControl test against Samba4\n");
867 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
868 r.in.function_code = 1;
873 printf("Testing LogonControl level %d\n", i);
875 status = dcerpc_netr_LogonControl(p, mem_ctx, &r);
876 if (!NT_STATUS_IS_OK(status)) {
877 printf("LogonControl - %s\n", nt_errstr(status));
887 try a netlogon GetAnyDCName
889 static BOOL test_GetAnyDCName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
892 struct netr_GetAnyDCName r;
894 if (lp_parm_bool(-1, "torture", "samba4", False)) {
895 printf("skipping GetAnyDCName test against Samba4\n");
899 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
900 r.in.domainname = lp_workgroup();
902 printf("Testing GetAnyDCName\n");
904 status = dcerpc_netr_GetAnyDCName(p, mem_ctx, &r);
905 if (!NT_STATUS_IS_OK(status)) {
906 printf("GetAnyDCName - %s\n", nt_errstr(status));
911 printf("\tDC is at '%s'\n", r.out.dcname);
919 try a netlogon LogonControl2
921 static BOOL test_LogonControl2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
924 struct netr_LogonControl2 r;
928 if (lp_parm_bool(-1, "torture", "samba4", False)) {
929 printf("skipping LogonControl2 test against Samba4\n");
933 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
935 r.in.function_code = NETLOGON_CONTROL_REDISCOVER;
936 r.in.data.domain = lp_workgroup();
941 printf("Testing LogonControl2 level %d function %d\n",
942 i, r.in.function_code);
944 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
945 if (!NT_STATUS_IS_OK(status)) {
946 printf("LogonControl - %s\n", nt_errstr(status));
951 r.in.function_code = NETLOGON_CONTROL_TC_QUERY;
952 r.in.data.domain = lp_workgroup();
957 printf("Testing LogonControl2 level %d function %d\n",
958 i, r.in.function_code);
960 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
961 if (!NT_STATUS_IS_OK(status)) {
962 printf("LogonControl - %s\n", nt_errstr(status));
967 r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY;
968 r.in.data.domain = lp_workgroup();
973 printf("Testing LogonControl2 level %d function %d\n",
974 i, r.in.function_code);
976 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
977 if (!NT_STATUS_IS_OK(status)) {
978 printf("LogonControl - %s\n", nt_errstr(status));
983 r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG;
984 r.in.data.debug_level = ~0;
989 printf("Testing LogonControl2 level %d function %d\n",
990 i, r.in.function_code);
992 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
993 if (!NT_STATUS_IS_OK(status)) {
994 printf("LogonControl - %s\n", nt_errstr(status));
1003 try a netlogon DatabaseSync2
1005 static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1008 struct netr_DatabaseSync2 r;
1009 struct creds_CredentialState *creds;
1010 const uint32_t database_ids[] = {0, 1, 2};
1014 if (!test_SetupCredentials2(p, mem_ctx, NETLOGON_NEG_AUTH2_FLAGS,
1015 TEST_MACHINE_NAME, machine_password,
1016 SEC_CHAN_BDC, &creds)) {
1020 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1021 printf("skipping DatabaseSync2 test against Samba4\n");
1025 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1026 r.in.computername = TEST_MACHINE_NAME;
1027 r.in.preferredmaximumlength = (uint32_t)-1;
1028 ZERO_STRUCT(r.in.return_authenticator);
1030 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1031 r.in.sync_context = 0;
1032 r.in.database_id = database_ids[i];
1033 r.in.restart_state = 0;
1035 printf("Testing DatabaseSync2 of id %d\n", r.in.database_id);
1038 creds_client_authenticator(creds, &r.in.credential);
1040 status = dcerpc_netr_DatabaseSync2(p, mem_ctx, &r);
1041 if (!NT_STATUS_IS_OK(status) &&
1042 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
1043 printf("DatabaseSync2 - %s\n", nt_errstr(status));
1048 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
1049 printf("Credential chaining failed\n");
1052 r.in.sync_context = r.out.sync_context;
1053 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
1061 try a netlogon LogonControl2Ex
1063 static BOOL test_LogonControl2Ex(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1066 struct netr_LogonControl2Ex r;
1070 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1071 printf("skipping DatabaseSync2 test against Samba4\n");
1075 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1077 r.in.function_code = NETLOGON_CONTROL_REDISCOVER;
1078 r.in.data.domain = lp_workgroup();
1083 printf("Testing LogonControl2Ex level %d function %d\n",
1084 i, r.in.function_code);
1086 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
1087 if (!NT_STATUS_IS_OK(status)) {
1088 printf("LogonControl - %s\n", nt_errstr(status));
1093 r.in.function_code = NETLOGON_CONTROL_TC_QUERY;
1094 r.in.data.domain = lp_workgroup();
1099 printf("Testing LogonControl2Ex level %d function %d\n",
1100 i, r.in.function_code);
1102 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
1103 if (!NT_STATUS_IS_OK(status)) {
1104 printf("LogonControl - %s\n", nt_errstr(status));
1109 r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY;
1110 r.in.data.domain = lp_workgroup();
1115 printf("Testing LogonControl2Ex level %d function %d\n",
1116 i, r.in.function_code);
1118 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
1119 if (!NT_STATUS_IS_OK(status)) {
1120 printf("LogonControl - %s\n", nt_errstr(status));
1125 r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG;
1126 r.in.data.debug_level = ~0;
1131 printf("Testing LogonControl2Ex level %d function %d\n",
1132 i, r.in.function_code);
1134 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
1135 if (!NT_STATUS_IS_OK(status)) {
1136 printf("LogonControl - %s\n", nt_errstr(status));
1144 static BOOL test_netr_DsRGetForestTrustInformation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *trusted_domain_name)
1147 struct netr_DsRGetForestTrustInformation r;
1149 struct lsa_ForestTrustInformation info, *info_ptr;
1151 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1152 printf("skipping DsRGetForestTrustInformation test against Samba4\n");
1158 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1159 r.in.trusted_domain_name = trusted_domain_name;
1161 r.out.forest_trust_info = &info_ptr;
1163 printf("Testing netr_DsRGetForestTrustInformation\n");
1165 status = dcerpc_netr_DsRGetForestTrustInformation(p, mem_ctx, &r);
1166 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1167 printf("netr_DsRGetForestTrustInformation - %s/%s\n",
1168 nt_errstr(status), win_errstr(r.out.result));
1175 try a netlogon netr_DsrEnumerateDomainTrusts
1177 static BOOL test_DsrEnumerateDomainTrusts(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1180 struct netr_DsrEnumerateDomainTrusts r;
1183 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1184 r.in.trust_flags = 0x3f;
1186 printf("Testing netr_DsrEnumerateDomainTrusts\n");
1188 status = dcerpc_netr_DsrEnumerateDomainTrusts(p, mem_ctx, &r);
1189 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1190 printf("netr_DsrEnumerateDomainTrusts - %s/%s\n",
1191 nt_errstr(status), win_errstr(r.out.result));
1195 /* when trusted_domain_name is NULL, netr_DsRGetForestTrustInformation
1196 * will show non-forest trusts and all UPN suffixes of the own forest
1197 * as LSA_FOREST_TRUST_TOP_LEVEL_NAME types */
1200 if (!test_netr_DsRGetForestTrustInformation(p, mem_ctx, NULL)) {
1205 for (i=0; i<r.out.count; i++) {
1207 /* get info for transitive forest trusts */
1209 if (r.out.trusts[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1210 if (!test_netr_DsRGetForestTrustInformation(p, mem_ctx,
1211 r.out.trusts[i].dns_name)) {
1220 static BOOL test_netr_DsRGetSiteName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1221 const char *computer_name,
1222 const char *expected_site)
1225 struct netr_DsRGetSiteName r;
1228 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1229 printf("skipping DsRGetSiteName test against Samba4\n");
1233 r.in.computer_name = computer_name;
1234 printf("Testing netr_DsRGetSiteName\n");
1236 status = dcerpc_netr_DsRGetSiteName(p, mem_ctx, &r);
1237 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1238 printf("netr_DsRGetSiteName - %s/%s\n",
1239 nt_errstr(status), win_errstr(r.out.result));
1242 if (strcmp(expected_site, r.out.site) != 0) {
1243 d_printf("netr_DsRGetSiteName - unexpected result: %s, expected %s\n",
1244 r.out.site, expected_site);
1249 r.in.computer_name = talloc_asprintf(mem_ctx, "\\\\%s", computer_name);
1250 d_printf("Testing netr_DsRGetSiteName with broken computer name: %s\n", r.in.computer_name);
1252 status = dcerpc_netr_DsRGetSiteName(p, mem_ctx, &r);
1253 if (!NT_STATUS_IS_OK(status)) {
1254 printf("netr_DsRGetSiteName - %s\n",
1257 } else if (!W_ERROR_EQUAL(r.out.result, WERR_INVALID_COMPUTERNAME)) {
1258 printf("netr_DsRGetSiteName - incorrect error return %s, expected %s\n",
1259 win_errstr(r.out.result), win_errstr(WERR_INVALID_COMPUTERNAME));
1266 try a netlogon netr_DsRGetDCName
1268 static BOOL test_netr_DsRGetDCName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1271 struct netr_DsRGetDCName r;
1274 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1275 r.in.domain_name = talloc_asprintf(mem_ctx, "%s", lp_realm());
1276 r.in.domain_guid = NULL;
1277 r.in.site_guid = NULL;
1278 r.in.flags = DS_RETURN_DNS_NAME;
1280 printf("Testing netr_DsRGetDCName\n");
1282 status = dcerpc_netr_DsRGetDCName(p, mem_ctx, &r);
1283 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1284 printf("netr_DsRGetDCName - %s/%s\n",
1285 nt_errstr(status), win_errstr(r.out.result));
1288 ret = test_netr_DsRGetSiteName(p, mem_ctx,
1290 r.out.info->dc_site_name);
1297 try a netlogon netr_DsRGetDCNameEx
1299 static BOOL test_netr_DsRGetDCNameEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1302 struct netr_DsRGetDCNameEx r;
1305 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1306 r.in.domain_name = talloc_asprintf(mem_ctx, "%s", lp_realm());
1307 r.in.domain_guid = NULL;
1308 r.in.site_name = NULL;
1309 r.in.flags = DS_RETURN_DNS_NAME;
1311 printf("Testing netr_DsRGetDCNameEx\n");
1313 status = dcerpc_netr_DsRGetDCNameEx(p, mem_ctx, &r);
1314 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1315 printf("netr_DsRGetDCNameEx - %s/%s\n",
1316 nt_errstr(status), win_errstr(r.out.result));
1319 ret = test_netr_DsRGetSiteName(p, mem_ctx,
1321 r.out.info->dc_site_name);
1328 try a netlogon netr_DsRGetDCNameEx2
1330 static BOOL test_netr_DsRGetDCNameEx2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1333 struct netr_DsRGetDCNameEx2 r;
1336 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1337 r.in.client_account = NULL;
1338 r.in.mask = 0x00000000;
1339 r.in.domain_name = talloc_asprintf(mem_ctx, "%s", lp_realm());
1340 r.in.domain_guid = NULL;
1341 r.in.site_name = NULL;
1342 r.in.flags = DS_RETURN_DNS_NAME;
1344 printf("Testing netr_DsRGetDCNameEx2 without client account\n");
1346 status = dcerpc_netr_DsRGetDCNameEx2(p, mem_ctx, &r);
1347 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1348 printf("netr_DsRGetDCNameEx2 - %s/%s\n",
1349 nt_errstr(status), win_errstr(r.out.result));
1353 printf("Testing netr_DsRGetDCNameEx2 with client acount\n");
1354 r.in.client_account = TEST_MACHINE_NAME"$";
1355 r.in.mask = ACB_SVRTRUST;
1356 r.in.flags = DS_RETURN_FLAT_NAME;
1358 status = dcerpc_netr_DsRGetDCNameEx2(p, mem_ctx, &r);
1359 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1360 printf("netr_DsRGetDCNameEx2 - %s/%s\n",
1361 nt_errstr(status), win_errstr(r.out.result));
1364 ret = test_netr_DsRGetSiteName(p, mem_ctx,
1366 r.out.info->dc_site_name);
1372 static BOOL test_netr_DsrGetDcSiteCoverageW(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1375 struct netr_DsrGetDcSiteCoverageW r;
1378 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1379 printf("skipping DsrGetDcSiteCoverageW test against Samba4\n");
1383 r.in.server_name = "";
1384 printf("Testing netr_DsrGetDcSiteCoverageW\n");
1386 status = dcerpc_netr_DsrGetDcSiteCoverageW(p, mem_ctx, &r);
1387 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
1388 printf("netr_DsrGetDcSiteCoverageW - %s/%s\n",
1389 nt_errstr(status), win_errstr(r.out.result));
1396 static BOOL test_GetDomainInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1399 struct netr_LogonGetDomainInfo r;
1400 struct netr_DomainQuery1 q1;
1401 struct netr_Authenticator a;
1402 struct creds_CredentialState *creds;
1404 if (!test_SetupCredentials3(p, mem_ctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
1405 TEST_MACHINE_NAME, machine_password, &creds)) {
1411 creds_client_authenticator(creds, &a);
1413 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1414 r.in.computer_name = TEST_MACHINE_NAME;
1416 r.in.credential = &a;
1417 r.in.return_authenticator = &a;
1418 r.out.return_authenticator = &a;
1420 r.in.query.query1 = &q1;
1423 /* this should really be the fully qualified name */
1424 q1.workstation_domain = TEST_MACHINE_NAME;
1425 q1.workstation_site = "Default-First-Site-Name";
1426 q1.blob2.length = 0;
1428 q1.blob2.data = NULL;
1429 q1.product.string = "product string";
1431 printf("Testing netr_LogonGetDomainInfo\n");
1433 status = dcerpc_netr_LogonGetDomainInfo(p, mem_ctx, &r);
1434 if (!NT_STATUS_IS_OK(status)) {
1435 printf("netr_LogonGetDomainInfo - %s\n", nt_errstr(status));
1439 if (!creds_client_check(creds, &a.cred)) {
1440 printf("Credential chaining failed\n");
1448 static void async_callback(struct rpc_request *req)
1450 int *counter = req->async.private_data;
1451 if (NT_STATUS_IS_OK(req->status)) {
1456 static BOOL test_GetDomainInfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1459 struct netr_LogonGetDomainInfo r;
1460 struct netr_DomainQuery1 q1;
1461 struct netr_Authenticator a;
1462 #define ASYNC_COUNT 100
1463 struct creds_CredentialState *creds;
1464 struct creds_CredentialState *creds_async[ASYNC_COUNT];
1465 struct rpc_request *req[ASYNC_COUNT];
1467 int *async_counter = talloc(mem_ctx, int);
1469 if (!lp_parm_bool(-1, "torture", "dangerous", False)) {
1470 printf("test_GetDomainInfo_async disabled - enable dangerous tests to use\n");
1474 if (!test_SetupCredentials3(p, mem_ctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
1475 TEST_MACHINE_NAME, machine_password, &creds)) {
1480 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1481 r.in.computer_name = TEST_MACHINE_NAME;
1483 r.in.credential = &a;
1484 r.in.return_authenticator = &a;
1485 r.out.return_authenticator = &a;
1487 r.in.query.query1 = &q1;
1490 /* this should really be the fully qualified name */
1491 q1.workstation_domain = TEST_MACHINE_NAME;
1492 q1.workstation_site = "Default-First-Site-Name";
1493 q1.blob2.length = 0;
1495 q1.blob2.data = NULL;
1496 q1.product.string = "product string";
1498 printf("Testing netr_LogonGetDomainInfo - async count %d\n", ASYNC_COUNT);
1502 for (i=0;i<ASYNC_COUNT;i++) {
1503 creds_client_authenticator(creds, &a);
1505 creds_async[i] = talloc_memdup(creds, creds, sizeof(*creds));
1506 req[i] = dcerpc_netr_LogonGetDomainInfo_send(p, mem_ctx, &r);
1508 req[i]->async.callback = async_callback;
1509 req[i]->async.private_data = async_counter;
1511 /* even with this flush per request a w2k3 server seems to
1512 clag with multiple outstanding requests. bleergh. */
1513 if (event_loop_once(dcerpc_event_context(p)) != 0) {
1518 for (i=0;i<ASYNC_COUNT;i++) {
1519 status = dcerpc_ndr_request_recv(req[i]);
1520 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(r.out.result)) {
1521 printf("netr_LogonGetDomainInfo_async(%d) - %s/%s\n",
1522 i, nt_errstr(status), nt_errstr(r.out.result));
1526 if (!creds_client_check(creds_async[i], &a.cred)) {
1527 printf("Credential chaining failed at async %d\n", i);
1532 printf("Testing netr_LogonGetDomainInfo - async count %d OK\n", *async_counter);
1534 return (*async_counter) == ASYNC_COUNT;
1537 static BOOL test_ManyGetDCName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1540 struct dcerpc_pipe *p2;
1541 struct lsa_ObjectAttribute attr;
1542 struct lsa_QosInfo qos;
1543 struct lsa_OpenPolicy2 o;
1544 struct policy_handle lsa_handle;
1545 struct lsa_DomainList domains;
1547 struct lsa_EnumTrustDom t;
1548 uint32_t resume_handle = 0;
1549 struct netr_GetAnyDCName d;
1554 if (p->conn->transport.transport != NCACN_NP) {
1558 printf("Torturing GetDCName\n");
1560 status = dcerpc_secondary_connection(p, &p2, p->binding);
1561 if (!NT_STATUS_IS_OK(status)) {
1562 printf("Failed to create secondary connection\n");
1566 status = dcerpc_bind_auth_none(p2, &dcerpc_table_lsarpc);
1567 if (!NT_STATUS_IS_OK(status)) {
1568 printf("Failed to create bind on secondary connection\n");
1573 qos.impersonation_level = 2;
1574 qos.context_mode = 1;
1575 qos.effective_only = 0;
1578 attr.root_dir = NULL;
1579 attr.object_name = NULL;
1580 attr.attributes = 0;
1581 attr.sec_desc = NULL;
1582 attr.sec_qos = &qos;
1584 o.in.system_name = "\\";
1586 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1587 o.out.handle = &lsa_handle;
1589 status = dcerpc_lsa_OpenPolicy2(p2, mem_ctx, &o);
1590 if (!NT_STATUS_IS_OK(status)) {
1591 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
1595 t.in.handle = &lsa_handle;
1596 t.in.resume_handle = &resume_handle;
1597 t.in.max_size = 1000;
1598 t.out.domains = &domains;
1599 t.out.resume_handle = &resume_handle;
1601 status = dcerpc_lsa_EnumTrustDom(p2, mem_ctx, &t);
1603 if ((!NT_STATUS_IS_OK(status) &&
1604 (!NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)))) {
1605 printf("Could not list domains\n");
1611 d.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s",
1612 dcerpc_server_name(p));
1614 for (i=0; i<domains.count * 4; i++) {
1615 struct lsa_DomainInfo *info =
1616 &domains.domains[rand()%domains.count];
1618 d.in.domainname = info->name.string;
1620 status = dcerpc_netr_GetAnyDCName(p, mem_ctx, &d);
1621 if (!NT_STATUS_IS_OK(status)) {
1622 printf("GetAnyDCName - %s\n", nt_errstr(status));
1626 printf("\tDC for domain %s is %s\n", info->name.string,
1627 d.out.dcname ? d.out.dcname : "unknown");
1634 BOOL torture_rpc_netlogon(struct torture_context *torture)
1637 struct dcerpc_pipe *p;
1638 TALLOC_CTX *mem_ctx;
1640 struct test_join *join_ctx;
1641 struct cli_credentials *machine_credentials;
1643 mem_ctx = talloc_init("torture_rpc_netlogon");
1645 join_ctx = torture_join_domain(TEST_MACHINE_NAME, ACB_SVRTRUST,
1646 &machine_credentials);
1648 talloc_free(mem_ctx);
1649 printf("Failed to join as BDC\n");
1653 machine_password = cli_credentials_get_password(machine_credentials);
1655 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_netlogon);
1656 if (!NT_STATUS_IS_OK(status)) {
1657 talloc_free(mem_ctx);
1661 ret &= test_LogonUasLogon(p, mem_ctx);
1662 ret &= test_LogonUasLogoff(p, mem_ctx);
1663 ret &= test_SamLogon(p, mem_ctx, machine_credentials);
1664 ret &= test_SetPassword(p, mem_ctx);
1665 ret &= test_SetPassword2(p, mem_ctx);
1666 ret &= test_GetDomainInfo(p, mem_ctx);
1667 ret &= test_DatabaseSync(p, mem_ctx);
1668 ret &= test_DatabaseDeltas(p, mem_ctx);
1669 ret &= test_AccountDeltas(p, mem_ctx);
1670 ret &= test_AccountSync(p, mem_ctx);
1671 ret &= test_GetDcName(p, mem_ctx);
1672 ret &= test_ManyGetDCName(p, mem_ctx);
1673 ret &= test_LogonControl(p, mem_ctx);
1674 ret &= test_GetAnyDCName(p, mem_ctx);
1675 ret &= test_LogonControl2(p, mem_ctx);
1676 ret &= test_DatabaseSync2(p, mem_ctx);
1677 ret &= test_LogonControl2Ex(p, mem_ctx);
1678 ret &= test_DsrEnumerateDomainTrusts(p, mem_ctx);
1679 ret &= test_GetDomainInfo_async(p, mem_ctx);
1680 ret &= test_netr_DsRGetDCName(p, mem_ctx);
1681 ret &= test_netr_DsRGetDCNameEx(p, mem_ctx);
1682 ret &= test_netr_DsRGetDCNameEx2(p, mem_ctx);
1683 ret &= test_netr_DsrGetDcSiteCoverageW(p, mem_ctx);
1685 talloc_free(mem_ctx);
1687 torture_leave_domain(join_ctx);