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 "librpc/gen_ndr/ndr_netlogon.h"
27 #include "auth/auth.h"
28 #include "dlinklist.h"
29 #include "lib/crypto/crypto.h"
31 #define TEST_MACHINE_NAME "samsynctest"
34 try a netlogon SamLogon
36 static NTSTATUS test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
37 struct creds_CredentialState *creds,
38 const char *domain, const char *username,
39 struct samr_Password *lm_hash,
40 struct samr_Password *nt_hash,
41 struct netr_SamInfo3 **info3)
44 struct netr_LogonSamLogon r;
45 struct netr_Authenticator auth, auth2;
46 struct netr_NetworkInfo ninfo;
48 ninfo.identity_info.domain_name.string = domain;
49 ninfo.identity_info.parameter_control = 0;
50 ninfo.identity_info.logon_id_low = 0;
51 ninfo.identity_info.logon_id_high = 0;
52 ninfo.identity_info.account_name.string = username;
53 ninfo.identity_info.workstation.string = TEST_MACHINE_NAME;
54 generate_random_buffer(ninfo.challenge,
55 sizeof(ninfo.challenge));
58 ninfo.nt.data = talloc(mem_ctx, 24);
59 SMBOWFencrypt(nt_hash->hash, ninfo.challenge, ninfo.nt.data);
67 ninfo.lm.data = talloc(mem_ctx, 24);
68 SMBOWFencrypt(lm_hash->hash, ninfo.challenge, ninfo.lm.data);
74 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
75 r.in.workstation = TEST_MACHINE_NAME;
76 r.in.credential = &auth;
77 r.in.return_authenticator = &auth2;
79 r.in.logon.network = &ninfo;
82 creds_client_authenticator(creds, &auth);
84 r.in.validation_level = 3;
86 status = dcerpc_netr_LogonSamLogon(p, mem_ctx, &r);
88 if (!creds_client_check(creds, &r.out.return_authenticator->cred)) {
89 printf("Credential chaining failed\n");
93 *info3 = r.out.validation.sam3;
99 struct samsync_state {
100 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
102 char *domain_name[2];
103 struct samsync_secret *secrets;
104 struct samsync_trusted_domain *trusted_domains;
105 struct creds_CredentialState *creds;
106 struct policy_handle *connect_handle;
107 struct policy_handle *domain_handle[2];
108 struct dom_sid *sid[2];
109 struct dcerpc_pipe *p;
110 struct dcerpc_pipe *p_samr;
113 struct samsync_secret {
114 struct samsync_secret *prev, *next;
119 struct samsync_trusted_domain {
120 struct samsync_trusted_domain *prev, *next;
125 static struct policy_handle *samsync_open_domain(TALLOC_CTX *mem_ctx,
126 struct samsync_state *samsync_state,
128 struct dom_sid **sid)
130 struct samr_String name;
131 struct samr_OpenDomain o;
132 struct samr_LookupDomain l;
133 struct policy_handle *domain_handle = talloc_p(mem_ctx, struct policy_handle);
136 name.string = domain;
137 l.in.connect_handle = samsync_state->connect_handle;
140 nt_status = dcerpc_samr_LookupDomain(samsync_state->p_samr, mem_ctx, &l);
141 if (!NT_STATUS_IS_OK(nt_status)) {
142 printf("LookupDomain failed - %s\n", nt_errstr(nt_status));
146 o.in.connect_handle = samsync_state->connect_handle;
147 o.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
148 o.in.sid = l.out.sid;
149 o.out.domain_handle = domain_handle;
155 nt_status = dcerpc_samr_OpenDomain(samsync_state->p_samr, mem_ctx, &o);
156 if (!NT_STATUS_IS_OK(nt_status)) {
157 printf("OpenDomain failed - %s\n", nt_errstr(nt_status));
161 return domain_handle;
164 static BOOL samsync_handle_domain(TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
165 int database_id, struct netr_DELTA_ENUM *delta)
167 struct netr_DELTA_DOMAIN *domain = delta->delta_union.domain;
168 struct dom_sid *dom_sid;
169 samsync_state->seq_num[database_id] =
170 domain->sequence_num;
171 switch (database_id) {
172 case SAM_DATABASE_DOMAIN:
174 case SAM_DATABASE_BUILTIN:
175 if (StrCaseCmp("BUILTIN", domain->domain_name.string) != 0) {
176 printf("BUILTIN domain has different name: %s\n", domain->domain_name.string);
179 case SAM_DATABASE_PRIVS:
180 printf("DOMAIN entry on privs DB!\n");
185 if (!samsync_state->domain_name[database_id]) {
186 samsync_state->domain_name[database_id] =
187 talloc_reference(samsync_state, domain->domain_name.string);
189 if (StrCaseCmp(samsync_state->domain_name[database_id], domain->domain_name.string) != 0) {
190 printf("Domain has name varies!: %s != %s\n", samsync_state->domain_name[database_id],
191 domain->domain_name.string);
196 if (!samsync_state->domain_handle[database_id]) {
197 samsync_state->domain_handle[database_id]
198 = samsync_open_domain(mem_ctx, samsync_state, samsync_state->domain_name[database_id],
201 if (samsync_state->domain_handle[database_id]) {
202 samsync_state->sid[database_id] = talloc_reference(samsync_state, dom_sid);
205 printf("\tsequence_nums[%d/%s]=%llu\n",
206 database_id, domain->domain_name.string,
207 samsync_state->seq_num[database_id]);
211 static BOOL samsync_handle_policy(TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
212 int database_id, struct netr_DELTA_ENUM *delta)
214 struct netr_DELTA_POLICY *policy = delta->delta_union.policy;
216 samsync_state->seq_num[database_id] =
217 policy->sequence_num;
219 if (!samsync_state->domain_name[SAM_DATABASE_DOMAIN]) {
220 samsync_state->domain_name[SAM_DATABASE_DOMAIN] =
221 talloc_reference(samsync_state, policy->primary_domain_name.string);
223 if (StrCaseCmp(samsync_state->domain_name[SAM_DATABASE_DOMAIN], policy->primary_domain_name.string) != 0) {
224 printf("PRIMARY domain has name varies between DOMAIN and POLICY!: %s != %s\n", samsync_state->domain_name[SAM_DATABASE_DOMAIN],
225 policy->primary_domain_name.string);
230 if (!sid_equal(samsync_state->sid[SAM_DATABASE_DOMAIN], policy->sid)) {
231 printf("Domain SID from POLICY (%s) does not match domain sid from SAMR (%s)\n",
232 dom_sid_string(mem_ctx, policy->sid), dom_sid_string(mem_ctx, samsync_state->sid[SAM_DATABASE_DOMAIN]));
236 printf("\tsequence_nums[%d/PRIVS]=%llu\n",
238 samsync_state->seq_num[database_id]);
242 #define TEST_INT_EQUAL(i1, i2) do {\
244 printf("integer mismatch: " #i1 ":%d != " #i2 ": %d\n", \
249 #define TEST_TIME_EQUAL(t1, t2) do {\
251 printf("NTTIME mismatch: " #t1 ":%s != " #t2 ": %s\n", \
252 nt_time_string(mem_ctx, t1), nt_time_string(mem_ctx, t2));\
256 #define TEST_STRING_EQUAL(s1, s2) do {\
257 if (!((!s1.string || s1.string[0]=='\0') && (!s2.string || s2.string[0]=='\0')) \
258 && strcmp_safe(s1.string, s2.string) != 0) {\
259 printf("string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
260 s1.string, s2.string);\
266 static BOOL samsync_handle_user(TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
267 int database_id, struct netr_DELTA_ENUM *delta)
269 uint32 rid = delta->delta_id_union.rid;
270 struct netr_DELTA_USER *user = delta->delta_union.user;
271 struct netr_SamInfo3 *info3;
272 struct samr_Password lm_hash;
273 struct samr_Password nt_hash;
274 struct samr_Password *lm_hash_p = NULL;
275 struct samr_Password *nt_hash_p = NULL;
276 const char *domain = samsync_state->domain_name[database_id];
277 const char *username = user->account_name.string;
281 struct samr_OpenUser r;
282 struct samr_QueryUserInfo q;
283 struct policy_handle user_handle;
285 if (!samsync_state->domain_name || !samsync_state->domain_handle[database_id]) {
286 printf("SamSync needs domain information before the users\n");
290 r.in.domain_handle = samsync_state->domain_handle[database_id];
291 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
293 r.out.user_handle = &user_handle;
295 nt_status = dcerpc_samr_OpenUser(samsync_state->p_samr, mem_ctx, &r);
296 if (!NT_STATUS_IS_OK(nt_status)) {
297 printf("OpenUser(%u) failed - %s\n", rid, nt_errstr(nt_status));
301 q.in.user_handle = &user_handle;
304 nt_status = dcerpc_samr_QueryUserInfo(samsync_state->p_samr, mem_ctx, &q);
305 if (!test_samr_handle_Close(samsync_state->p_samr, mem_ctx, &user_handle)) {
309 if (!NT_STATUS_IS_OK(nt_status)) {
310 printf("QueryUserInfo level %u failed - %s\n",
311 q.in.level, nt_errstr(nt_status));
315 TEST_STRING_EQUAL(q.out.info->info21.account_name, user->account_name);
316 TEST_STRING_EQUAL(q.out.info->info21.full_name, user->full_name);
317 TEST_INT_EQUAL(q.out.info->info21.rid, user->rid);
318 TEST_INT_EQUAL(q.out.info->info21.primary_gid, user->primary_gid);
319 TEST_STRING_EQUAL(q.out.info->info21.home_directory, user->home_directory);
320 TEST_STRING_EQUAL(q.out.info->info21.home_drive, user->home_drive);
321 TEST_STRING_EQUAL(q.out.info->info21.logon_script, user->logon_script);
322 TEST_STRING_EQUAL(q.out.info->info21.description, user->description);
323 TEST_STRING_EQUAL(q.out.info->info21.workstations, user->workstations);
325 TEST_TIME_EQUAL(q.out.info->info21.last_logon, user->last_logon);
326 TEST_TIME_EQUAL(q.out.info->info21.last_logoff, user->last_logoff);
329 TEST_INT_EQUAL(q.out.info->info21.logon_hours.units_per_week,
330 user->logon_hours.units_per_week);
332 if (memcmp(q.out.info->info21.logon_hours.bitmap, user->logon_hours.bitmap,
333 q.out.info->info21.logon_hours.units_per_week/8) != 0) {
334 printf("Logon hours mismatch\n");
339 TEST_INT_EQUAL(q.out.info->info21.bad_password_count,
340 user->bad_password_count);
341 TEST_INT_EQUAL(q.out.info->info21.logon_count,
344 TEST_TIME_EQUAL(q.out.info->info21.last_password_change,
345 user->last_password_change);
346 TEST_TIME_EQUAL(q.out.info->info21.acct_expiry,
349 TEST_INT_EQUAL(q.out.info->info21.logon_hours.units_per_week,
350 user->logon_hours.units_per_week);
352 TEST_INT_EQUAL(q.out.info->info21.acct_flags, user->acct_flags);
353 TEST_INT_EQUAL(q.out.info->info21.nt_password_set, user->nt_password_present);
354 TEST_INT_EQUAL(q.out.info->info21.lm_password_set, user->lm_password_present);
355 TEST_INT_EQUAL(q.out.info->info21.password_expired, user->password_expired);
357 TEST_STRING_EQUAL(q.out.info->info21.comment, user->comment);
358 TEST_STRING_EQUAL(q.out.info->info21.parameters, user->parameters);
360 TEST_INT_EQUAL(q.out.info->info21.country_code, user->country_code);
361 TEST_INT_EQUAL(q.out.info->info21.code_page, user->code_page);
363 TEST_STRING_EQUAL(q.out.info->info21.profile_path, user->profile_path);
365 if (user->lm_password_present) {
366 sam_rid_crypt(rid, user->lmpassword.hash, lm_hash.hash, 0);
367 lm_hash_p = &lm_hash;
369 if (user->nt_password_present) {
370 sam_rid_crypt(rid, user->ntpassword.hash, nt_hash.hash, 0);
371 nt_hash_p = &nt_hash;
374 if (user->user_private_info.SensitiveData) {
376 struct netr_USER_KEYS keys;
377 data.data = user->user_private_info.SensitiveData;
378 data.length = user->user_private_info.DataLength;
379 creds_arcfour_crypt(samsync_state->creds, data.data, data.length);
381 printf("Sensitive Data for %s:\n", username);
382 dump_data(0, data.data, data.length);
384 nt_status = ndr_pull_struct_blob(&data, mem_ctx, &keys, (ndr_pull_flags_fn_t)ndr_pull_netr_USER_KEYS);
385 if (NT_STATUS_IS_OK(nt_status)) {
386 if (keys.keys.keys2.lmpassword.length == 16) {
387 sam_rid_crypt(rid, keys.keys.keys2.lmpassword.pwd.hash, lm_hash.hash, 0);
388 lm_hash_p = &lm_hash;
390 if (keys.keys.keys2.ntpassword.length == 16) {
391 sam_rid_crypt(rid, keys.keys.keys2.ntpassword.pwd.hash, nt_hash.hash, 0);
392 nt_hash_p = &nt_hash;
398 if (!lm_hash_p && !nt_hash_p) {
399 printf("NO password set for %s\n",
400 user->account_name.string);
404 nt_status = test_SamLogon(samsync_state->p, mem_ctx, samsync_state->creds,
411 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_DISABLED)) {
412 if (user->acct_flags & ACB_DISABLED) {
415 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT)) {
416 if (user->acct_flags & ACB_WSTRUST) {
419 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT)) {
420 if (user->acct_flags & ACB_SVRTRUST) {
423 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
424 if (user->acct_flags & ACB_DOMTRUST) {
427 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
428 if (user->acct_flags & ACB_DOMTRUST) {
431 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_LOCKED_OUT)) {
432 if (user->acct_flags & ACB_AUTOLOCK) {
435 } else if (NT_STATUS_IS_OK(nt_status)) {
436 TEST_INT_EQUAL(user->rid, info3->base.rid);
437 TEST_INT_EQUAL(user->primary_gid, info3->base.primary_gid);
438 TEST_INT_EQUAL(user->acct_flags, info3->base.acct_flags);
439 TEST_STRING_EQUAL(user->account_name, info3->base.account_name);
440 TEST_STRING_EQUAL(user->full_name, info3->base.full_name);
441 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
442 TEST_STRING_EQUAL(user->profile_path, info3->base.profile_path);
443 TEST_STRING_EQUAL(user->home_directory, info3->base.home_directory);
444 TEST_STRING_EQUAL(user->home_drive, info3->base.home_drive);
445 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
448 TEST_TIME_EQUAL(user->last_logon, info3->base.last_logon);
449 TEST_TIME_EQUAL(user->acct_expiry, info3->base.acct_expiry);
450 TEST_TIME_EQUAL(user->last_password_change, info3->base.last_password_change);
452 /* Does the concept of a logoff time ever really
453 * exist? (not in any sensible way, according to the
454 * doco I read -- abartlet) */
456 /* This copes with the two different versions of 0 I see */
457 if (!((user->last_logoff == 0)
458 && (info3->base.last_logoff == 0x7fffffffffffffffLL))) {
459 TEST_TIME_EQUAL(user->last_logoff, info3->base.last_logoff);
463 printf("Could not validate password for user %s\\%s: %s\n",
464 domain, username, nt_errstr(nt_status));
470 static BOOL samsync_handle_secret(TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
471 int database_id, struct netr_DELTA_ENUM *delta)
473 struct netr_DELTA_SECRET *secret = delta->delta_union.secret;
474 const char *name = delta->delta_id_union.name;
475 struct samsync_secret *new = talloc_p(samsync_state, struct samsync_secret);
477 creds_arcfour_crypt(samsync_state->creds, secret->current_cipher.cipher_data,
478 secret->current_cipher.maxlen);
480 creds_arcfour_crypt(samsync_state->creds, secret->old_cipher.cipher_data,
481 secret->old_cipher.maxlen);
483 new->name = talloc_reference(new, name);
484 new->secret = data_blob_talloc(new, secret->current_cipher.cipher_data, secret->current_cipher.maxlen);
486 DLIST_ADD(samsync_state->secrets, new);
491 static BOOL samsync_handle_trusted_domain(TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
492 int database_id, struct netr_DELTA_ENUM *delta)
494 struct netr_DELTA_TRUSTED_DOMAIN *trusted_domain = delta->delta_union.trusted_domain;
495 struct dom_sid *dom_sid = delta->delta_id_union.sid;
497 struct samsync_trusted_domain *new = talloc_p(samsync_state, struct samsync_trusted_domain);
498 new->name = talloc_reference(new, trusted_domain->domain_name.string);
499 new->sid = talloc_reference(new, dom_sid);
501 DLIST_ADD(samsync_state->trusted_domains, new);
507 try a netlogon DatabaseSync
509 static BOOL test_DatabaseSync(struct samsync_state *samsync_state,
513 struct netr_DatabaseSync r;
514 const uint32_t database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS};
517 struct samsync_trusted_domain *t;
518 struct samsync_secret *s;
520 const char *domain, *username;
522 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
523 r.in.computername = TEST_MACHINE_NAME;
524 r.in.preferredmaximumlength = (uint32_t)-1;
525 ZERO_STRUCT(r.in.return_authenticator);
527 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
528 r.in.sync_context = 0;
529 r.in.database_id = database_ids[i];
531 printf("Testing DatabaseSync of id %d\n", r.in.database_id);
534 creds_client_authenticator(samsync_state->creds, &r.in.credential);
536 status = dcerpc_netr_DatabaseSync(samsync_state->p, mem_ctx, &r);
537 if (!NT_STATUS_IS_OK(status) &&
538 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
539 printf("DatabaseSync - %s\n", nt_errstr(status));
544 if (!creds_client_check(samsync_state->creds, &r.out.return_authenticator.cred)) {
545 printf("Credential chaining failed\n");
548 r.in.sync_context = r.out.sync_context;
550 for (d=0; d < r.out.delta_enum_array->num_deltas; d++) {
551 switch (r.out.delta_enum_array->delta_enum[d].delta_type) {
552 case NETR_DELTA_DOMAIN:
553 ret &= samsync_handle_domain(mem_ctx, samsync_state,
554 r.in.database_id, &r.out.delta_enum_array->delta_enum[d]);
556 case NETR_DELTA_USER:
557 ret &= samsync_handle_user(mem_ctx, samsync_state,
558 r.in.database_id, &r.out.delta_enum_array->delta_enum[d]);
560 case NETR_DELTA_TRUSTED_DOMAIN:
561 ret &= samsync_handle_trusted_domain(mem_ctx, samsync_state,
562 r.in.database_id, &r.out.delta_enum_array->delta_enum[d]);
564 case NETR_DELTA_SECRET:
565 ret &= samsync_handle_secret(mem_ctx, samsync_state,
566 r.in.database_id, &r.out.delta_enum_array->delta_enum[d]);
568 case NETR_DELTA_POLICY:
569 ret &= samsync_handle_policy(mem_ctx, samsync_state,
570 r.in.database_id, &r.out.delta_enum_array->delta_enum[d]);
574 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
578 domain = samsync_state->domain_name[SAM_DATABASE_DOMAIN];
580 printf("Never got a DOMAIN object in samsync!\n");
584 username = talloc_asprintf(mem_ctx, "%s$", domain);
585 for (t=samsync_state->trusted_domains; t; t=t->next) {
586 char *secret_name = talloc_asprintf(mem_ctx, "G$$%s", t->name);
587 for (s=samsync_state->secrets; s; s=s->next) {
588 printf("Checking secret %s against %s\n",
589 s->name, secret_name);
590 if (StrCaseCmp(s->name, secret_name) == 0) {
592 struct samr_Password nt_hash;
593 mdfour(nt_hash.hash, s->secret.data, s->secret.length);
595 printf("Checking password for %s\\%s\n", t->name, username);
596 nt_status = test_SamLogon(samsync_state->p, mem_ctx, samsync_state->creds,
602 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
603 printf("Could not verify trust password to %s: %s\n",
604 t->name, nt_errstr(nt_status));
610 nt_status = test_SamLogon(samsync_state->p, mem_ctx, samsync_state->creds,
617 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
618 printf("Verifiction of trust password to %s: should have failed (wrong password), instead: %s\n",
619 t->name, nt_errstr(nt_status));
633 try a netlogon DatabaseDeltas
635 static BOOL test_DatabaseDeltas(struct samsync_state *samsync_state, TALLOC_CTX *mem_ctx)
638 struct netr_DatabaseDeltas r;
639 const uint32_t database_ids[] = {0, 1, 2};
643 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
644 r.in.computername = TEST_MACHINE_NAME;
645 r.in.preferredmaximumlength = (uint32_t)-1;
646 ZERO_STRUCT(r.in.return_authenticator);
648 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
649 r.in.database_id = database_ids[i];
650 r.in.sequence_num = samsync_state->seq_num[i];
652 if (r.in.sequence_num == 0) continue;
654 r.in.sequence_num -= 1;
657 printf("Testing DatabaseDeltas of id %d at %llu\n",
658 r.in.database_id, r.in.sequence_num);
661 creds_client_authenticator(samsync_state->creds, &r.in.credential);
663 status = dcerpc_netr_DatabaseDeltas(samsync_state->p, mem_ctx, &r);
664 if (!NT_STATUS_IS_OK(status) &&
665 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
666 printf("DatabaseDeltas - %s\n", nt_errstr(status));
671 if (!creds_client_check(samsync_state->creds, &r.out.return_authenticator.cred)) {
672 printf("Credential chaining failed\n");
676 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
684 try a netlogon DatabaseSync2
686 static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
687 struct creds_CredentialState *creds)
690 struct netr_DatabaseSync2 r;
691 const uint32_t database_ids[] = {0, 1, 2};
695 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
696 r.in.computername = TEST_MACHINE_NAME;
697 r.in.preferredmaximumlength = (uint32_t)-1;
698 ZERO_STRUCT(r.in.return_authenticator);
700 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
701 r.in.sync_context = 0;
702 r.in.database_id = database_ids[i];
703 r.in.restart_state = 0;
705 printf("Testing DatabaseSync2 of id %d\n", r.in.database_id);
708 creds_client_authenticator(creds, &r.in.credential);
710 status = dcerpc_netr_DatabaseSync2(p, mem_ctx, &r);
711 if (!NT_STATUS_IS_OK(status) &&
712 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
713 printf("DatabaseSync2 - %s\n", nt_errstr(status));
718 if (!creds_client_check(creds, &r.out.return_authenticator.cred)) {
719 printf("Credential chaining failed\n");
722 r.in.sync_context = r.out.sync_context;
723 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
731 BOOL torture_rpc_samsync(void)
736 struct test_join *join_ctx;
737 const char *machine_password;
738 const char *binding = lp_parm_string(-1, "torture", "binding");
739 struct dcerpc_binding b;
740 struct samr_Connect c;
742 struct samsync_state *samsync_state;
744 mem_ctx = talloc_init("torture_rpc_netlogon");
746 join_ctx = torture_join_domain(TEST_MACHINE_NAME, lp_workgroup(), ACB_SVRTRUST,
749 printf("Failed to join as BDC\n");
753 samsync_state = talloc_zero_p(mem_ctx, struct samsync_state);
755 samsync_state->p_samr = torture_join_samr_pipe(join_ctx);
756 samsync_state->connect_handle = talloc_zero_p(samsync_state, struct policy_handle);
757 c.in.system_name = NULL;
758 c.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
759 c.out.connect_handle = samsync_state->connect_handle;
761 status = dcerpc_samr_Connect(samsync_state->p_samr, mem_ctx, &c);
762 if (!NT_STATUS_IS_OK(status)) {
763 printf("samr_Connect failed\n");
768 status = dcerpc_parse_binding(mem_ctx, binding, &b);
769 if (!NT_STATUS_IS_OK(status)) {
770 printf("Bad binding string %s\n", binding);
775 b.flags &= ~DCERPC_AUTH_OPTIONS;
776 b.flags |= DCERPC_SCHANNEL_BDC | DCERPC_SIGN | DCERPC_SCHANNEL_128;
778 status = dcerpc_pipe_connect_b(&samsync_state->p, &b,
779 DCERPC_NETLOGON_UUID,
780 DCERPC_NETLOGON_VERSION,
785 if (!NT_STATUS_IS_OK(status)) {
790 status = dcerpc_schannel_creds(samsync_state->p->security_state.generic_state, mem_ctx, &samsync_state->creds);
791 if (!NT_STATUS_IS_OK(status)) {
795 if (!test_DatabaseSync(samsync_state, mem_ctx)) {
799 if (!test_DatabaseDeltas(samsync_state, mem_ctx)) {
803 if (!test_DatabaseSync2(samsync_state->p, mem_ctx, samsync_state->creds)) {
807 torture_rpc_close(samsync_state->p);
809 torture_leave_domain(join_ctx);
811 talloc_destroy(mem_ctx);