s3:lib/events: add missing TEVENT_TRACE_BEFORE/AFTER_WAIT handling
[Samba/gebeck_regimport.git] / source4 / torture / rpc / samsync.c
blob81027d0658ddf42b49b7c16b77d5334741975ec6
1 /*
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 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/>.
24 #include "includes.h"
25 #include "../lib/util/dlinklist.h"
26 #include "../lib/crypto/crypto.h"
27 #include "system/time.h"
28 #include "torture/rpc/torture_rpc.h"
29 #include "auth/gensec/gensec.h"
30 #include "auth/gensec/schannel.h"
31 #include "libcli/auth/libcli_auth.h"
32 #include "libcli/samsync/samsync.h"
33 #include "libcli/security/security.h"
34 #include "librpc/gen_ndr/ndr_netlogon.h"
35 #include "librpc/gen_ndr/ndr_netlogon_c.h"
36 #include "librpc/gen_ndr/ndr_lsa_c.h"
37 #include "librpc/gen_ndr/ndr_samr_c.h"
38 #include "librpc/gen_ndr/ndr_security.h"
39 #include "param/param.h"
41 #define TEST_MACHINE_NAME "samsynctest"
42 #define TEST_WKSTA_MACHINE_NAME "samsynctest2"
43 #define TEST_USER_NAME "samsynctestuser"
46 try a netlogon SamLogon
48 static NTSTATUS test_SamLogon(struct torture_context *tctx,
49 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
50 struct netlogon_creds_CredentialState *creds,
51 const char *domain, const char *account_name,
52 const char *workstation,
53 struct samr_Password *lm_hash,
54 struct samr_Password *nt_hash,
55 struct netr_SamInfo3 **info3)
57 NTSTATUS status;
58 struct netr_LogonSamLogon r;
59 struct netr_Authenticator auth, auth2;
60 struct netr_NetworkInfo ninfo;
61 union netr_LogonLevel logon;
62 union netr_Validation validation;
63 uint8_t authoritative;
64 struct dcerpc_binding_handle *b = p->binding_handle;
66 ninfo.identity_info.domain_name.string = domain;
67 ninfo.identity_info.parameter_control = 0;
68 ninfo.identity_info.logon_id_low = 0;
69 ninfo.identity_info.logon_id_high = 0;
70 ninfo.identity_info.account_name.string = account_name;
71 ninfo.identity_info.workstation.string = workstation;
72 generate_random_buffer(ninfo.challenge,
73 sizeof(ninfo.challenge));
74 if (nt_hash) {
75 ninfo.nt.length = 24;
76 ninfo.nt.data = talloc_array(mem_ctx, uint8_t, 24);
77 SMBOWFencrypt(nt_hash->hash, ninfo.challenge, ninfo.nt.data);
78 } else {
79 ninfo.nt.length = 0;
80 ninfo.nt.data = NULL;
83 if (lm_hash) {
84 ninfo.lm.length = 24;
85 ninfo.lm.data = talloc_array(mem_ctx, uint8_t, 24);
86 SMBOWFencrypt(lm_hash->hash, ninfo.challenge, ninfo.lm.data);
87 } else {
88 ninfo.lm.length = 0;
89 ninfo.lm.data = NULL;
92 logon.network = &ninfo;
94 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
95 r.in.computer_name = workstation;
96 r.in.credential = &auth;
97 r.in.return_authenticator = &auth2;
98 r.in.logon_level = NetlogonNetworkInformation;
99 r.in.logon = &logon;
100 r.out.validation = &validation;
101 r.out.authoritative = &authoritative;
103 ZERO_STRUCT(auth2);
104 netlogon_creds_client_authenticator(creds, &auth);
106 r.in.validation_level = 3;
108 status = dcerpc_netr_LogonSamLogon_r(b, mem_ctx, &r);
109 if (!NT_STATUS_IS_OK(status)) {
110 return status;
113 if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
114 torture_comment(tctx, "Credential chaining failed\n");
117 if (info3) {
118 *info3 = validation.sam3;
121 return r.out.result;
124 struct samsync_state {
125 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
126 uint64_t seq_num[3];
127 const char *domain_name[2];
128 struct samsync_secret *secrets;
129 struct samsync_trusted_domain *trusted_domains;
130 struct netlogon_creds_CredentialState *creds;
131 struct netlogon_creds_CredentialState *creds_netlogon_wksta;
132 struct policy_handle *connect_handle;
133 struct policy_handle *domain_handle[2];
134 struct dom_sid *sid[2];
135 struct dcerpc_pipe *p;
136 struct dcerpc_binding_handle *b;
137 struct dcerpc_pipe *p_netlogon_wksta;
138 struct dcerpc_pipe *p_samr;
139 struct dcerpc_binding_handle *b_samr;
140 struct dcerpc_pipe *p_lsa;
141 struct dcerpc_binding_handle *b_lsa;
142 struct policy_handle *lsa_handle;
145 struct samsync_secret {
146 struct samsync_secret *prev, *next;
147 DATA_BLOB secret;
148 const char *name;
149 NTTIME mtime;
152 struct samsync_trusted_domain {
153 struct samsync_trusted_domain *prev, *next;
154 struct dom_sid *sid;
155 const char *name;
158 static struct policy_handle *samsync_open_domain(struct torture_context *tctx,
159 TALLOC_CTX *mem_ctx,
160 struct samsync_state *samsync_state,
161 const char *domain,
162 struct dom_sid **sid_p)
164 struct lsa_String name;
165 struct samr_OpenDomain o;
166 struct samr_LookupDomain l;
167 struct dom_sid2 *sid = NULL;
168 struct policy_handle *domain_handle = talloc(mem_ctx, struct policy_handle);
169 NTSTATUS nt_status;
171 name.string = domain;
172 l.in.connect_handle = samsync_state->connect_handle;
173 l.in.domain_name = &name;
174 l.out.sid = &sid;
176 nt_status = dcerpc_samr_LookupDomain_r(samsync_state->b_samr, mem_ctx, &l);
177 if (!NT_STATUS_IS_OK(nt_status)) {
178 torture_comment(tctx, "LookupDomain failed - %s\n", nt_errstr(nt_status));
179 return NULL;
181 if (!NT_STATUS_IS_OK(l.out.result)) {
182 torture_comment(tctx, "LookupDomain failed - %s\n", nt_errstr(l.out.result));
183 return NULL;
186 o.in.connect_handle = samsync_state->connect_handle;
187 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
188 o.in.sid = *l.out.sid;
189 o.out.domain_handle = domain_handle;
191 if (sid_p) {
192 *sid_p = *l.out.sid;
195 nt_status = dcerpc_samr_OpenDomain_r(samsync_state->b_samr, mem_ctx, &o);
196 if (!NT_STATUS_IS_OK(nt_status)) {
197 torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(nt_status));
198 return NULL;
200 if (!NT_STATUS_IS_OK(o.out.result)) {
201 torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(o.out.result));
202 return NULL;
205 return domain_handle;
208 static struct sec_desc_buf *samsync_query_samr_sec_desc(struct torture_context *tctx,
209 TALLOC_CTX *mem_ctx,
210 struct samsync_state *samsync_state,
211 struct policy_handle *handle)
213 struct samr_QuerySecurity r;
214 struct sec_desc_buf *sdbuf = NULL;
215 NTSTATUS status;
217 r.in.handle = handle;
218 r.in.sec_info = 0x7;
219 r.out.sdbuf = &sdbuf;
221 status = dcerpc_samr_QuerySecurity_r(samsync_state->b_samr, mem_ctx, &r);
222 if (!NT_STATUS_IS_OK(status)) {
223 torture_comment(tctx, "SAMR QuerySecurity failed - %s\n", nt_errstr(status));
224 return NULL;
226 if (!NT_STATUS_IS_OK(r.out.result)) {
227 torture_comment(tctx, "SAMR QuerySecurity failed - %s\n", nt_errstr(r.out.result));
228 return NULL;
231 return sdbuf;
234 static struct sec_desc_buf *samsync_query_lsa_sec_desc(struct torture_context *tctx,
235 TALLOC_CTX *mem_ctx,
236 struct samsync_state *samsync_state,
237 struct policy_handle *handle)
239 struct lsa_QuerySecurity r;
240 struct sec_desc_buf *sdbuf = NULL;
241 NTSTATUS status;
243 r.in.handle = handle;
244 r.in.sec_info = 0x7;
245 r.out.sdbuf = &sdbuf;
247 status = dcerpc_lsa_QuerySecurity_r(samsync_state->b_lsa, mem_ctx, &r);
248 if (!NT_STATUS_IS_OK(status)) {
249 torture_comment(tctx, "LSA QuerySecurity failed - %s\n", nt_errstr(status));
250 return NULL;
252 if (!NT_STATUS_IS_OK(r.out.result)) {
253 torture_comment(tctx, "LSA QuerySecurity failed - %s\n", nt_errstr(r.out.result));
254 return NULL;
257 return sdbuf;
260 #define TEST_UINT64_EQUAL(i1, i2) do {\
261 if (i1 != i2) {\
262 torture_comment(tctx, "%s: uint64 mismatch: " #i1 ": 0x%016llx (%lld) != " #i2 ": 0x%016llx (%lld)\n", \
263 __location__, \
264 (long long)i1, (long long)i1, \
265 (long long)i2, (long long)i2);\
266 ret = false;\
268 } while (0)
269 #define TEST_INT_EQUAL(i1, i2) do {\
270 if (i1 != i2) {\
271 torture_comment(tctx, "%s: integer mismatch: " #i1 ": 0x%08x (%d) != " #i2 ": 0x%08x (%d)\n", \
272 __location__, i1, i1, i2, i2); \
273 ret = false;\
275 } while (0)
276 #define TEST_TIME_EQUAL(t1, t2) do {\
277 if (t1 != t2) {\
278 torture_comment(tctx, "%s: NTTIME mismatch: " #t1 ":%s != " #t2 ": %s\n", \
279 __location__, nt_time_string(mem_ctx, t1), nt_time_string(mem_ctx, t2));\
280 ret = false;\
282 } while (0)
284 #define TEST_STRING_EQUAL(s1, s2) do {\
285 if (!((!s1.string || s1.string[0]=='\0') && (!s2.string || s2.string[0]=='\0')) \
286 && strcmp_safe(s1.string, s2.string) != 0) {\
287 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
288 __location__, s1.string, s2.string);\
289 ret = false;\
291 } while (0)
293 #define TEST_BINARY_STRING_EQUAL(s1, s2) do {\
294 if (!((!s1.array || s1.array[0]=='\0') && (!s2.array || s2.array[0]=='\0')) \
295 && memcmp(s1.array, s2.array, s1.length * 2) != 0) {\
296 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
297 __location__, (const char *)s1.array, (const char *)s2.array);\
298 ret = false;\
300 } while (0)
302 #define TEST_SID_EQUAL(s1, s2) do {\
303 if (!dom_sid_equal(s1, s2)) {\
304 torture_comment(tctx, "%s: dom_sid mismatch: " #s1 ":%s != " #s2 ": %s\n", \
305 __location__, dom_sid_string(mem_ctx, s1), dom_sid_string(mem_ctx, s2));\
306 ret = false;\
308 } while (0)
310 /* The ~SEC_DESC_SACL_PRESENT is because we don't, as administrator,
311 * get back the SACL part of the SD when we ask over SAMR */
313 #define TEST_SEC_DESC_EQUAL(sd1, pipe, handle) do {\
314 struct sec_desc_buf *sdbuf = samsync_query_ ##pipe## _sec_desc(tctx, mem_ctx, samsync_state, \
315 handle); \
316 if (!sdbuf || !sdbuf->sd) { \
317 torture_comment(tctx, "Could not obtain security descriptor to match " #sd1 "\n");\
318 ret = false; \
319 } else {\
320 if (!security_descriptor_mask_equal(sd1.sd, sdbuf->sd, \
321 ~SEC_DESC_SACL_PRESENT)) {\
322 torture_comment(tctx, "Security Descriptor Mismatch for %s:\n", #sd1);\
323 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamSync", sd1.sd);\
324 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamR", sdbuf->sd);\
325 ret = false;\
328 } while (0)
330 static bool samsync_handle_domain(struct torture_context *tctx, TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
331 int database_id, struct netr_DELTA_ENUM *delta)
333 struct netr_DELTA_DOMAIN *domain = delta->delta_union.domain;
334 struct dom_sid *dom_sid;
335 struct samr_QueryDomainInfo q[14]; /* q[0] will be unused simple for clarity */
336 union samr_DomainInfo *info[14];
337 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
338 int i;
339 bool ret = true;
341 samsync_state->seq_num[database_id] =
342 domain->sequence_num;
343 switch (database_id) {
344 case SAM_DATABASE_DOMAIN:
345 break;
346 case SAM_DATABASE_BUILTIN:
347 if (strcasecmp_m("BUILTIN", domain->domain_name.string) != 0) {
348 torture_comment(tctx, "BUILTIN domain has different name: %s\n", domain->domain_name.string);
350 break;
351 case SAM_DATABASE_PRIVS:
352 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
353 return false;
354 break;
357 if (!samsync_state->domain_name[database_id]) {
358 samsync_state->domain_name[database_id] =
359 talloc_reference(samsync_state, domain->domain_name.string);
360 } else {
361 if (strcasecmp_m(samsync_state->domain_name[database_id], domain->domain_name.string) != 0) {
362 torture_comment(tctx, "Domain has name varies!: %s != %s\n", samsync_state->domain_name[database_id],
363 domain->domain_name.string);
364 return false;
368 if (!samsync_state->domain_handle[database_id]) {
369 samsync_state->domain_handle[database_id]
370 = talloc_reference(samsync_state,
371 samsync_open_domain(tctx,
372 mem_ctx, samsync_state, samsync_state->domain_name[database_id],
373 &dom_sid));
375 if (samsync_state->domain_handle[database_id]) {
376 samsync_state->sid[database_id] = talloc_reference(samsync_state, dom_sid);
379 torture_comment(tctx, "\tsequence_nums[%d/%s]=%llu\n",
380 database_id, domain->domain_name.string,
381 (long long)samsync_state->seq_num[database_id]);
383 for (i=0;i<ARRAY_SIZE(levels);i++) {
385 q[levels[i]].in.domain_handle = samsync_state->domain_handle[database_id];
386 q[levels[i]].in.level = levels[i];
387 q[levels[i]].out.info = &info[levels[i]];
389 torture_assert_ntstatus_ok(tctx,
390 dcerpc_samr_QueryDomainInfo_r(samsync_state->b_samr, mem_ctx, &q[levels[i]]),
391 talloc_asprintf(tctx, "QueryDomainInfo level %u failed", q[levels[i]].in.level));
392 torture_assert_ntstatus_ok(tctx, q[levels[i]].out.result,
393 talloc_asprintf(tctx, "QueryDomainInfo level %u failed", q[levels[i]].in.level));
396 TEST_STRING_EQUAL(info[5]->info5.domain_name, domain->domain_name);
398 TEST_STRING_EQUAL(info[2]->general.oem_information, domain->oem_information);
399 TEST_STRING_EQUAL(info[4]->oem.oem_information, domain->oem_information);
400 TEST_TIME_EQUAL(info[2]->general.force_logoff_time, domain->force_logoff_time);
401 TEST_TIME_EQUAL(info[3]->info3.force_logoff_time, domain->force_logoff_time);
403 TEST_TIME_EQUAL(info[1]->info1.min_password_length, domain->min_password_length);
404 TEST_TIME_EQUAL(info[1]->info1.password_history_length, domain->password_history_length);
405 TEST_TIME_EQUAL(info[1]->info1.max_password_age, domain->max_password_age);
406 TEST_TIME_EQUAL(info[1]->info1.min_password_age, domain->min_password_age);
408 TEST_UINT64_EQUAL(info[8]->info8.sequence_num,
409 domain->sequence_num);
410 TEST_TIME_EQUAL(info[8]->info8.domain_create_time,
411 domain->domain_create_time);
412 TEST_TIME_EQUAL(info[13]->info13.domain_create_time,
413 domain->domain_create_time);
415 TEST_SEC_DESC_EQUAL(domain->sdbuf, samr, samsync_state->domain_handle[database_id]);
417 return ret;
420 static bool samsync_handle_policy(struct torture_context *tctx,
421 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
422 int database_id, struct netr_DELTA_ENUM *delta)
424 struct netr_DELTA_POLICY *policy = delta->delta_union.policy;
426 switch (database_id) {
427 case SAM_DATABASE_DOMAIN:
428 case SAM_DATABASE_BUILTIN:
429 break;
430 case SAM_DATABASE_PRIVS:
431 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
432 return false;
435 samsync_state->seq_num[database_id] =
436 policy->sequence_num;
438 if (!samsync_state->domain_name[SAM_DATABASE_DOMAIN]) {
439 samsync_state->domain_name[SAM_DATABASE_DOMAIN] =
440 talloc_reference(samsync_state, policy->primary_domain_name.string);
441 } else {
442 if (strcasecmp_m(samsync_state->domain_name[SAM_DATABASE_DOMAIN], policy->primary_domain_name.string) != 0) {
443 torture_comment(tctx, "PRIMARY domain has name varies between DOMAIN and POLICY!: %s != %s\n", samsync_state->domain_name[SAM_DATABASE_DOMAIN],
444 policy->primary_domain_name.string);
445 return false;
449 if (!dom_sid_equal(samsync_state->sid[SAM_DATABASE_DOMAIN], policy->sid)) {
450 torture_comment(tctx, "Domain SID from POLICY (%s) does not match domain sid from SAMR (%s)\n",
451 dom_sid_string(mem_ctx, policy->sid), dom_sid_string(mem_ctx, samsync_state->sid[SAM_DATABASE_DOMAIN]));
452 return false;
455 torture_comment(tctx, "\tsequence_nums[%d/PRIVS]=%llu\n",
456 database_id,
457 (long long)samsync_state->seq_num[database_id]);
458 return true;
461 static bool samsync_handle_user(struct torture_context *tctx, TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
462 int database_id, struct netr_DELTA_ENUM *delta)
464 uint32_t rid = delta->delta_id_union.rid;
465 struct netr_DELTA_USER *user = delta->delta_union.user;
466 struct netr_SamInfo3 *info3;
467 struct samr_Password lm_hash;
468 struct samr_Password nt_hash;
469 struct samr_Password *lm_hash_p = NULL;
470 struct samr_Password *nt_hash_p = NULL;
471 const char *domain;
472 const char *username = user->account_name.string;
473 NTSTATUS nt_status;
474 bool ret = true;
476 switch (database_id) {
477 case SAM_DATABASE_DOMAIN:
478 case SAM_DATABASE_BUILTIN:
479 break;
480 case SAM_DATABASE_PRIVS:
481 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
482 return false;
485 domain = samsync_state->domain_name[database_id];
487 struct samr_OpenUser r;
488 struct samr_QueryUserInfo q;
489 union samr_UserInfo *info;
490 struct policy_handle user_handle;
492 struct samr_GetGroupsForUser getgroups;
493 struct samr_RidWithAttributeArray *rids;
495 if (domain == NULL ||
496 samsync_state->domain_handle[database_id] == NULL) {
497 torture_comment(tctx, "SamSync needs domain information before the users\n");
498 return false;
501 r.in.domain_handle = samsync_state->domain_handle[database_id];
502 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
503 r.in.rid = rid;
504 r.out.user_handle = &user_handle;
506 torture_assert_ntstatus_ok(tctx,
507 dcerpc_samr_OpenUser_r(samsync_state->b_samr, mem_ctx, &r),
508 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
509 torture_assert_ntstatus_ok(tctx, r.out.result,
510 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
512 q.in.user_handle = &user_handle;
513 q.in.level = 21;
514 q.out.info = &info;
516 TEST_SEC_DESC_EQUAL(user->sdbuf, samr, &user_handle);
518 torture_assert_ntstatus_ok(tctx,
519 dcerpc_samr_QueryUserInfo_r(samsync_state->b_samr, mem_ctx, &q),
520 talloc_asprintf(tctx, "OpenUserInfo level %u failed", q.in.level));
521 torture_assert_ntstatus_ok(tctx, q.out.result,
522 talloc_asprintf(tctx, "OpenUserInfo level %u failed", q.in.level));
524 getgroups.in.user_handle = &user_handle;
525 getgroups.out.rids = &rids;
527 torture_assert_ntstatus_ok(tctx,
528 dcerpc_samr_GetGroupsForUser_r(samsync_state->b_samr, mem_ctx, &getgroups),
529 "GetGroupsForUser failed");
530 torture_assert_ntstatus_ok(tctx, getgroups.out.result,
531 "GetGroupsForUser failed");
533 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &user_handle)) {
534 torture_comment(tctx, "samr_handle_Close failed\n");
535 ret = false;
537 if (!ret) {
538 return false;
541 TEST_STRING_EQUAL(info->info21.account_name, user->account_name);
542 TEST_STRING_EQUAL(info->info21.full_name, user->full_name);
543 TEST_INT_EQUAL(info->info21.rid, user->rid);
544 TEST_INT_EQUAL(info->info21.primary_gid, user->primary_gid);
545 TEST_STRING_EQUAL(info->info21.home_directory, user->home_directory);
546 TEST_STRING_EQUAL(info->info21.home_drive, user->home_drive);
547 TEST_STRING_EQUAL(info->info21.logon_script, user->logon_script);
548 TEST_STRING_EQUAL(info->info21.description, user->description);
549 TEST_STRING_EQUAL(info->info21.workstations, user->workstations);
551 TEST_TIME_EQUAL(info->info21.last_logon, user->last_logon);
552 TEST_TIME_EQUAL(info->info21.last_logoff, user->last_logoff);
555 TEST_INT_EQUAL(info->info21.logon_hours.units_per_week,
556 user->logon_hours.units_per_week);
557 if (ret) {
558 if (memcmp(info->info21.logon_hours.bits, user->logon_hours.bits,
559 info->info21.logon_hours.units_per_week/8) != 0) {
560 torture_comment(tctx, "Logon hours mismatch\n");
561 ret = false;
565 TEST_INT_EQUAL(info->info21.bad_password_count,
566 user->bad_password_count);
567 TEST_INT_EQUAL(info->info21.logon_count,
568 user->logon_count);
570 TEST_TIME_EQUAL(info->info21.last_password_change,
571 user->last_password_change);
572 TEST_TIME_EQUAL(info->info21.acct_expiry,
573 user->acct_expiry);
575 TEST_INT_EQUAL((info->info21.acct_flags & ~ACB_PW_EXPIRED), user->acct_flags);
576 if (user->acct_flags & ACB_PWNOEXP) {
577 if (info->info21.acct_flags & ACB_PW_EXPIRED) {
578 torture_comment(tctx, "ACB flags mismatch: both expired and no expiry!\n");
579 ret = false;
581 if (info->info21.force_password_change != (NTTIME)0x7FFFFFFFFFFFFFFFULL) {
582 torture_comment(tctx, "ACB flags mismatch: no password expiry, but force password change 0x%016llx (%lld) != 0x%016llx (%lld)\n",
583 (unsigned long long)info->info21.force_password_change,
584 (unsigned long long)info->info21.force_password_change,
585 (unsigned long long)0x7FFFFFFFFFFFFFFFULL, (unsigned long long)0x7FFFFFFFFFFFFFFFULL
587 ret = false;
591 TEST_INT_EQUAL(info->info21.nt_password_set, user->nt_password_present);
592 TEST_INT_EQUAL(info->info21.lm_password_set, user->lm_password_present);
593 TEST_INT_EQUAL(info->info21.password_expired, user->password_expired);
595 TEST_STRING_EQUAL(info->info21.comment, user->comment);
596 TEST_BINARY_STRING_EQUAL(info->info21.parameters, user->parameters);
598 TEST_INT_EQUAL(info->info21.country_code, user->country_code);
599 TEST_INT_EQUAL(info->info21.code_page, user->code_page);
601 TEST_STRING_EQUAL(info->info21.profile_path, user->profile_path);
603 if (user->lm_password_present) {
604 lm_hash_p = &lm_hash;
606 if (user->nt_password_present) {
607 nt_hash_p = &nt_hash;
610 if (user->user_private_info.SensitiveData) {
611 DATA_BLOB data;
612 struct netr_USER_KEYS keys;
613 enum ndr_err_code ndr_err;
614 data.data = user->user_private_info.SensitiveData;
615 data.length = user->user_private_info.DataLength;
616 ndr_err = ndr_pull_struct_blob(&data, mem_ctx, &keys, (ndr_pull_flags_fn_t)ndr_pull_netr_USER_KEYS);
617 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
618 if (keys.keys.keys2.lmpassword.length == 16) {
619 lm_hash_p = &lm_hash;
621 if (keys.keys.keys2.ntpassword.length == 16) {
622 nt_hash_p = &nt_hash;
624 } else {
625 torture_comment(tctx, "Failed to parse Sensitive Data for %s:\n", username);
626 #if 0
627 dump_data(0, data.data, data.length);
628 #endif
629 return false;
633 if (nt_hash_p) {
634 DATA_BLOB nt_hash_blob = data_blob_const(nt_hash_p, 16);
635 DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &nt_hash_blob)));
637 if (lm_hash_p) {
638 DATA_BLOB lm_hash_blob = data_blob_const(lm_hash_p, 16);
639 DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &lm_hash_blob)));
642 nt_status = test_SamLogon(tctx,
643 samsync_state->p_netlogon_wksta, mem_ctx, samsync_state->creds_netlogon_wksta,
644 domain,
645 username,
646 TEST_WKSTA_MACHINE_NAME,
647 lm_hash_p,
648 nt_hash_p,
649 &info3);
651 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_DISABLED)) {
652 if (user->acct_flags & ACB_DISABLED) {
653 return true;
655 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT)) {
656 if (user->acct_flags & ACB_WSTRUST) {
657 return true;
659 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT)) {
660 if (user->acct_flags & ACB_SVRTRUST) {
661 return true;
663 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
664 if (user->acct_flags & ACB_DOMTRUST) {
665 return true;
667 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
668 if (user->acct_flags & ACB_DOMTRUST) {
669 return true;
671 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_LOCKED_OUT)) {
672 if (user->acct_flags & ACB_AUTOLOCK) {
673 return true;
675 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_EXPIRED)) {
676 if (info->info21.acct_flags & ACB_PW_EXPIRED) {
677 return true;
679 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
680 if (!lm_hash_p && !nt_hash_p) {
681 return true;
683 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_MUST_CHANGE)) {
684 /* We would need to know the server's current time to test this properly */
685 return true;
686 } else if (NT_STATUS_IS_OK(nt_status)) {
687 TEST_INT_EQUAL(user->rid, info3->base.rid);
688 TEST_INT_EQUAL(user->primary_gid, info3->base.primary_gid);
689 /* this is 0x0 from NT4 sp6 */
690 if (info3->base.acct_flags) {
691 TEST_INT_EQUAL(user->acct_flags, info3->base.acct_flags);
693 /* this is NULL from NT4 sp6 */
694 if (info3->base.account_name.string) {
695 TEST_STRING_EQUAL(user->account_name, info3->base.account_name);
697 /* this is NULL from Win2k3 */
698 if (info3->base.full_name.string) {
699 TEST_STRING_EQUAL(user->full_name, info3->base.full_name);
701 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
702 TEST_STRING_EQUAL(user->profile_path, info3->base.profile_path);
703 TEST_STRING_EQUAL(user->home_directory, info3->base.home_directory);
704 TEST_STRING_EQUAL(user->home_drive, info3->base.home_drive);
705 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
708 TEST_TIME_EQUAL(user->last_logon, info3->base.logon_time);
709 TEST_TIME_EQUAL(user->acct_expiry, info3->base.kickoff_time);
710 TEST_TIME_EQUAL(user->last_password_change, info3->base.last_password_change);
711 TEST_TIME_EQUAL(info->info21.force_password_change, info3->base.force_password_change);
713 /* Does the concept of a logoff time ever really
714 * exist? (not in any sensible way, according to the
715 * doco I read -- abartlet) */
717 /* This copes with the two different versions of 0 I see */
718 /* with NT4 sp6 we have the || case */
719 if (!((user->last_logoff == 0)
720 || (info3->base.logoff_time == 0x7fffffffffffffffLL))) {
721 TEST_TIME_EQUAL(user->last_logoff, info3->base.logoff_time);
724 TEST_INT_EQUAL(rids->count, info3->base.groups.count);
725 if (rids->count == info3->base.groups.count) {
726 int i, j;
727 int count = rids->count;
728 bool *matched = talloc_zero_array(mem_ctx, bool, rids->count);
730 for (i = 0; i < count; i++) {
731 for (j = 0; j < count; j++) {
732 if ((rids->rids[i].rid ==
733 info3->base.groups.rids[j].rid)
734 && (rids->rids[i].attributes ==
735 info3->base.groups.rids[j].attributes)) {
736 matched[i] = true;
741 for (i = 0; i < rids->count; i++) {
742 if (matched[i] == false) {
743 ret = false;
744 torture_comment(tctx, "Could not find group RID %u found in getgroups in NETLOGON reply\n",
745 rids->rids[i].rid);
749 return ret;
750 } else {
751 torture_comment(tctx, "Could not validate password for user %s\\%s: %s\n",
752 domain, username, nt_errstr(nt_status));
753 return false;
755 return false;
758 static bool samsync_handle_alias(struct torture_context *tctx,
759 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
760 int database_id, struct netr_DELTA_ENUM *delta)
762 uint32_t rid = delta->delta_id_union.rid;
763 struct netr_DELTA_ALIAS *alias = delta->delta_union.alias;
764 bool ret = true;
766 struct samr_OpenAlias r;
767 struct samr_QueryAliasInfo q;
768 union samr_AliasInfo *info;
769 struct policy_handle alias_handle;
771 switch (database_id) {
772 case SAM_DATABASE_DOMAIN:
773 case SAM_DATABASE_BUILTIN:
774 break;
775 case SAM_DATABASE_PRIVS:
776 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
777 return false;
780 if (samsync_state->domain_name[database_id] == NULL ||
781 samsync_state->domain_handle[database_id] == NULL) {
782 torture_comment(tctx, "SamSync needs domain information before the users\n");
783 return false;
786 r.in.domain_handle = samsync_state->domain_handle[database_id];
787 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
788 r.in.rid = rid;
789 r.out.alias_handle = &alias_handle;
791 torture_assert_ntstatus_ok(tctx,
792 dcerpc_samr_OpenAlias_r(samsync_state->b_samr, mem_ctx, &r),
793 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
794 torture_assert_ntstatus_ok(tctx, r.out.result,
795 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
797 q.in.alias_handle = &alias_handle;
798 q.in.level = 1;
799 q.out.info = &info;
801 TEST_SEC_DESC_EQUAL(alias->sdbuf, samr, &alias_handle);
803 torture_assert_ntstatus_ok(tctx,
804 dcerpc_samr_QueryAliasInfo_r(samsync_state->b_samr, mem_ctx, &q),
805 "QueryAliasInfo failed");
806 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &alias_handle)) {
807 return false;
810 if (!NT_STATUS_IS_OK(q.out.result)) {
811 torture_comment(tctx, "QueryAliasInfo level %u failed - %s\n",
812 q.in.level, nt_errstr(q.out.result));
813 return false;
816 TEST_STRING_EQUAL(info->all.name, alias->alias_name);
817 TEST_STRING_EQUAL(info->all.description, alias->description);
818 return ret;
821 static bool samsync_handle_group(struct torture_context *tctx,
822 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
823 int database_id, struct netr_DELTA_ENUM *delta)
825 uint32_t rid = delta->delta_id_union.rid;
826 struct netr_DELTA_GROUP *group = delta->delta_union.group;
827 bool ret = true;
829 struct samr_OpenGroup r;
830 struct samr_QueryGroupInfo q;
831 union samr_GroupInfo *info;
832 struct policy_handle group_handle;
834 switch (database_id) {
835 case SAM_DATABASE_DOMAIN:
836 case SAM_DATABASE_BUILTIN:
837 break;
838 case SAM_DATABASE_PRIVS:
839 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
840 return false;
843 if (samsync_state->domain_name[database_id] == NULL ||
844 samsync_state->domain_handle[database_id] == NULL) {
845 torture_comment(tctx, "SamSync needs domain information before the users\n");
846 return false;
849 r.in.domain_handle = samsync_state->domain_handle[database_id];
850 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
851 r.in.rid = rid;
852 r.out.group_handle = &group_handle;
854 torture_assert_ntstatus_ok(tctx,
855 dcerpc_samr_OpenGroup_r(samsync_state->b_samr, mem_ctx, &r),
856 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
857 torture_assert_ntstatus_ok(tctx, r.out.result,
858 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
860 q.in.group_handle = &group_handle;
861 q.in.level = 1;
862 q.out.info = &info;
864 TEST_SEC_DESC_EQUAL(group->sdbuf, samr, &group_handle);
866 torture_assert_ntstatus_ok(tctx,
867 dcerpc_samr_QueryGroupInfo_r(samsync_state->b_samr, mem_ctx, &q),
868 "QueryGroupInfo failed");
869 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &group_handle)) {
870 return false;
873 if (!NT_STATUS_IS_OK(q.out.result)) {
874 torture_comment(tctx, "QueryGroupInfo level %u failed - %s\n",
875 q.in.level, nt_errstr(q.out.result));
876 return false;
879 TEST_STRING_EQUAL(info->all.name, group->group_name);
880 TEST_INT_EQUAL(info->all.attributes, group->attributes);
881 TEST_STRING_EQUAL(info->all.description, group->description);
882 return ret;
885 static bool samsync_handle_secret(struct torture_context *tctx,
886 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
887 int database_id, struct netr_DELTA_ENUM *delta)
889 struct netr_DELTA_SECRET *secret = delta->delta_union.secret;
890 const char *name = delta->delta_id_union.name;
891 struct samsync_secret *nsec = talloc(samsync_state, struct samsync_secret);
892 struct samsync_secret *old = talloc(mem_ctx, struct samsync_secret);
893 struct lsa_QuerySecret q;
894 struct lsa_OpenSecret o;
895 struct policy_handle sec_handle;
896 struct lsa_DATA_BUF_PTR bufp1;
897 struct lsa_DATA_BUF_PTR bufp2;
898 NTTIME nsec_mtime;
899 NTTIME old_mtime;
900 bool ret = true;
901 DATA_BLOB lsa_blob1, lsa_blob_out, session_key;
902 NTSTATUS status;
904 nsec->name = talloc_reference(nsec, name);
905 nsec->secret = data_blob_talloc(nsec, secret->current_cipher.cipher_data, secret->current_cipher.maxlen);
906 nsec->mtime = secret->current_cipher_set_time;
908 nsec = talloc_reference(samsync_state, nsec);
909 DLIST_ADD(samsync_state->secrets, nsec);
911 old->name = talloc_reference(old, name);
912 old->secret = data_blob_const(secret->old_cipher.cipher_data, secret->old_cipher.maxlen);
913 old->mtime = secret->old_cipher_set_time;
915 o.in.handle = samsync_state->lsa_handle;
916 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
917 o.in.name.string = name;
918 o.out.sec_handle = &sec_handle;
920 torture_assert_ntstatus_ok(tctx,
921 dcerpc_lsa_OpenSecret_r(samsync_state->b_lsa, mem_ctx, &o),
922 "OpenSecret failed");
923 torture_assert_ntstatus_ok(tctx, o.out.result,
924 "OpenSecret failed");
927 We would like to do this, but it is NOT_SUPPORTED on win2k3
928 TEST_SEC_DESC_EQUAL(secret->sdbuf, lsa, &sec_handle);
930 status = dcerpc_fetch_session_key(samsync_state->p_lsa, &session_key);
931 if (!NT_STATUS_IS_OK(status)) {
932 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
933 return false;
937 ZERO_STRUCT(nsec_mtime);
938 ZERO_STRUCT(old_mtime);
940 /* fetch the secret back again */
941 q.in.sec_handle = &sec_handle;
942 q.in.new_val = &bufp1;
943 q.in.new_mtime = &nsec_mtime;
944 q.in.old_val = &bufp2;
945 q.in.old_mtime = &old_mtime;
947 bufp1.buf = NULL;
948 bufp2.buf = NULL;
950 torture_assert_ntstatus_ok(tctx,
951 dcerpc_lsa_QuerySecret_r(samsync_state->b_lsa, mem_ctx, &q),
952 "QuerySecret failed");
953 if (NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, q.out.result)) {
954 /* some things are just off limits */
955 return true;
956 } else if (!NT_STATUS_IS_OK(q.out.result)) {
957 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(q.out.result));
958 return false;
961 if (q.out.old_val->buf == NULL) {
962 /* probably just not available due to ACLs */
963 } else {
964 lsa_blob1.data = q.out.old_val->buf->data;
965 lsa_blob1.length = q.out.old_val->buf->length;
967 status = sess_decrypt_blob(mem_ctx, &lsa_blob1, &session_key, &lsa_blob_out);
968 if (!NT_STATUS_IS_OK(status)) {
969 torture_comment(tctx, "Failed to decrypt secrets OLD blob: %s\n", nt_errstr(status));
970 return false;
973 if (!q.out.old_mtime) {
974 torture_comment(tctx, "OLD mtime not available on LSA for secret %s\n", old->name);
975 ret = false;
977 if (old->mtime != *q.out.old_mtime) {
978 torture_comment(tctx, "OLD mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
979 old->name, nt_time_string(mem_ctx, old->mtime),
980 nt_time_string(mem_ctx, *q.out.old_mtime));
981 ret = false;
984 if (old->secret.length != lsa_blob_out.length) {
985 torture_comment(tctx, "Returned secret %s doesn't match: %d != %d\n",
986 old->name, (int)old->secret.length, (int)lsa_blob_out.length);
987 ret = false;
988 } else if (memcmp(lsa_blob_out.data,
989 old->secret.data, old->secret.length) != 0) {
990 torture_comment(tctx, "Returned secret %s doesn't match: \n",
991 old->name);
992 DEBUG(1, ("SamSync Secret:\n"));
993 dump_data(1, old->secret.data, old->secret.length);
994 DEBUG(1, ("LSA Secret:\n"));
995 dump_data(1, lsa_blob_out.data, lsa_blob_out.length);
996 ret = false;
1001 if (q.out.new_val->buf == NULL) {
1002 /* probably just not available due to ACLs */
1003 } else {
1004 lsa_blob1.data = q.out.new_val->buf->data;
1005 lsa_blob1.length = q.out.new_val->buf->length;
1007 status = sess_decrypt_blob(mem_ctx, &lsa_blob1, &session_key, &lsa_blob_out);
1008 if (!NT_STATUS_IS_OK(status)) {
1009 torture_comment(tctx, "Failed to decrypt secrets OLD blob\n");
1010 return false;
1013 if (!q.out.new_mtime) {
1014 torture_comment(tctx, "NEW mtime not available on LSA for secret %s\n", nsec->name);
1015 ret = false;
1017 if (nsec->mtime != *q.out.new_mtime) {
1018 torture_comment(tctx, "NEW mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
1019 nsec->name, nt_time_string(mem_ctx, nsec->mtime),
1020 nt_time_string(mem_ctx, *q.out.new_mtime));
1021 ret = false;
1024 if (nsec->secret.length != lsa_blob_out.length) {
1025 torture_comment(tctx, "Returned secret %s doesn't match: %d != %d\n",
1026 nsec->name, (int)nsec->secret.length, (int)lsa_blob_out.length);
1027 ret = false;
1028 } else if (memcmp(lsa_blob_out.data,
1029 nsec->secret.data, nsec->secret.length) != 0) {
1030 torture_comment(tctx, "Returned secret %s doesn't match: \n",
1031 nsec->name);
1032 DEBUG(1, ("SamSync Secret:\n"));
1033 dump_data(1, nsec->secret.data, nsec->secret.length);
1034 DEBUG(1, ("LSA Secret:\n"));
1035 dump_data(1, lsa_blob_out.data, lsa_blob_out.length);
1036 ret = false;
1040 return ret;
1043 static bool samsync_handle_trusted_domain(struct torture_context *tctx,
1044 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
1045 int database_id, struct netr_DELTA_ENUM *delta)
1047 bool ret = true;
1048 struct netr_DELTA_TRUSTED_DOMAIN *trusted_domain = delta->delta_union.trusted_domain;
1049 struct dom_sid *dom_sid = delta->delta_id_union.sid;
1051 struct samsync_trusted_domain *ndom = talloc(samsync_state, struct samsync_trusted_domain);
1052 struct lsa_OpenTrustedDomain t;
1053 struct policy_handle trustdom_handle;
1054 struct lsa_QueryTrustedDomainInfo q;
1055 union lsa_TrustedDomainInfo *info[9];
1056 union lsa_TrustedDomainInfo *_info = NULL;
1057 int levels [] = {1, 3, 8};
1058 int i;
1060 ndom->name = talloc_reference(ndom, trusted_domain->domain_name.string);
1061 ndom->sid = talloc_reference(ndom, dom_sid);
1063 t.in.handle = samsync_state->lsa_handle;
1064 t.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1065 t.in.sid = dom_sid;
1066 t.out.trustdom_handle = &trustdom_handle;
1068 torture_assert_ntstatus_ok(tctx,
1069 dcerpc_lsa_OpenTrustedDomain_r(samsync_state->b_lsa, mem_ctx, &t),
1070 "OpenTrustedDomain failed");
1071 torture_assert_ntstatus_ok(tctx, t.out.result,
1072 "OpenTrustedDomain failed");
1074 for (i=0; i< ARRAY_SIZE(levels); i++) {
1075 q.in.trustdom_handle = &trustdom_handle;
1076 q.in.level = levels[i];
1077 q.out.info = &_info;
1078 torture_assert_ntstatus_ok(tctx,
1079 dcerpc_lsa_QueryTrustedDomainInfo_r(samsync_state->b_lsa, mem_ctx, &q),
1080 "QueryTrustedDomainInfo failed");
1081 if (!NT_STATUS_IS_OK(q.out.result)) {
1082 if (q.in.level == 8 && NT_STATUS_EQUAL(q.out.result, NT_STATUS_INVALID_PARAMETER)) {
1083 info[levels[i]] = NULL;
1084 continue;
1086 torture_comment(tctx, "QueryInfoTrustedDomain level %d failed - %s\n",
1087 levels[i], nt_errstr(q.out.result));
1088 return false;
1090 info[levels[i]] = _info;
1093 if (info[8]) {
1094 TEST_SID_EQUAL(info[8]->full_info.info_ex.sid, dom_sid);
1095 TEST_STRING_EQUAL(info[8]->full_info.info_ex.netbios_name, trusted_domain->domain_name);
1097 TEST_STRING_EQUAL(info[1]->name.netbios_name, trusted_domain->domain_name);
1098 TEST_INT_EQUAL(info[3]->posix_offset.posix_offset, trusted_domain->posix_offset);
1100 We would like to do this, but it is NOT_SUPPORTED on win2k3
1101 TEST_SEC_DESC_EQUAL(trusted_domain->sdbuf, lsa, &trustdom_handle);
1103 ndom = talloc_reference(samsync_state, ndom);
1104 DLIST_ADD(samsync_state->trusted_domains, ndom);
1106 return ret;
1109 static bool samsync_handle_account(struct torture_context *tctx,
1110 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
1111 int database_id, struct netr_DELTA_ENUM *delta)
1113 bool ret = true;
1114 struct netr_DELTA_ACCOUNT *account = delta->delta_union.account;
1115 struct dom_sid *dom_sid = delta->delta_id_union.sid;
1117 struct lsa_OpenAccount a;
1118 struct policy_handle acct_handle;
1119 struct lsa_EnumPrivsAccount e;
1120 struct lsa_PrivilegeSet *privs = NULL;
1121 struct lsa_LookupPrivName r;
1123 int i, j;
1125 bool *found_priv_in_lsa;
1127 a.in.handle = samsync_state->lsa_handle;
1128 a.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1129 a.in.sid = dom_sid;
1130 a.out.acct_handle = &acct_handle;
1132 torture_assert_ntstatus_ok(tctx,
1133 dcerpc_lsa_OpenAccount_r(samsync_state->b_lsa, mem_ctx, &a),
1134 "OpenAccount failed");
1135 torture_assert_ntstatus_ok(tctx, a.out.result,
1136 "OpenAccount failed");
1138 TEST_SEC_DESC_EQUAL(account->sdbuf, lsa, &acct_handle);
1140 found_priv_in_lsa = talloc_zero_array(mem_ctx, bool, account->privilege_entries);
1142 e.in.handle = &acct_handle;
1143 e.out.privs = &privs;
1145 torture_assert_ntstatus_ok(tctx,
1146 dcerpc_lsa_EnumPrivsAccount_r(samsync_state->b_lsa, mem_ctx, &e),
1147 "EnumPrivsAccount failed");
1148 torture_assert_ntstatus_ok(tctx, e.out.result,
1149 "EnumPrivsAccount failed");
1151 if ((account->privilege_entries && !privs)) {
1152 torture_comment(tctx, "Account %s has privileges in SamSync, but not LSA\n",
1153 dom_sid_string(mem_ctx, dom_sid));
1154 return false;
1157 if (!account->privilege_entries && privs && privs->count) {
1158 torture_comment(tctx, "Account %s has privileges in LSA, but not SamSync\n",
1159 dom_sid_string(mem_ctx, dom_sid));
1160 return false;
1163 TEST_INT_EQUAL(account->privilege_entries, privs->count);
1165 for (i=0;i< privs->count; i++) {
1167 struct lsa_StringLarge *name = NULL;
1169 r.in.handle = samsync_state->lsa_handle;
1170 r.in.luid = &privs->set[i].luid;
1171 r.out.name = &name;
1173 torture_assert_ntstatus_ok(tctx,
1174 dcerpc_lsa_LookupPrivName_r(samsync_state->b_lsa, mem_ctx, &r),
1175 "\nLookupPrivName failed");
1176 torture_assert_ntstatus_ok(tctx, r.out.result,
1177 "\nLookupPrivName failed");
1179 if (!r.out.name) {
1180 torture_comment(tctx, "\nLookupPrivName failed to return a name\n");
1181 return false;
1183 for (j=0;j<account->privilege_entries; j++) {
1184 if (strcmp(name->string, account->privilege_name[j].string) == 0) {
1185 found_priv_in_lsa[j] = true;
1186 break;
1190 for (j=0;j<account->privilege_entries; j++) {
1191 if (!found_priv_in_lsa[j]) {
1192 torture_comment(tctx, "Privilege %s on account %s not found in LSA\n", account->privilege_name[j].string,
1193 dom_sid_string(mem_ctx, dom_sid));
1194 ret = false;
1197 return ret;
1201 try a netlogon DatabaseSync
1203 static bool test_DatabaseSync(struct torture_context *tctx,
1204 struct samsync_state *samsync_state,
1205 TALLOC_CTX *mem_ctx)
1207 TALLOC_CTX *loop_ctx, *delta_ctx, *trustdom_ctx;
1208 struct netr_DatabaseSync r;
1209 const enum netr_SamDatabaseID database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS};
1210 int i, d;
1211 bool ret = true;
1212 struct samsync_trusted_domain *t;
1213 struct samsync_secret *s;
1214 struct netr_Authenticator return_authenticator, credential;
1215 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1217 const char *domain, *username;
1219 ZERO_STRUCT(return_authenticator);
1221 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
1222 r.in.computername = TEST_MACHINE_NAME;
1223 r.in.preferredmaximumlength = (uint32_t)-1;
1224 r.in.return_authenticator = &return_authenticator;
1225 r.out.return_authenticator = &return_authenticator;
1226 r.out.delta_enum_array = &delta_enum_array;
1228 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1230 uint32_t sync_context = 0;
1232 r.in.database_id = database_ids[i];
1233 r.in.sync_context = &sync_context;
1234 r.out.sync_context = &sync_context;
1236 torture_comment(tctx, "Testing DatabaseSync of id %d\n", r.in.database_id);
1238 do {
1239 loop_ctx = talloc_named(mem_ctx, 0, "DatabaseSync loop context");
1240 netlogon_creds_client_authenticator(samsync_state->creds, &credential);
1242 r.in.credential = &credential;
1244 torture_assert_ntstatus_ok(tctx,
1245 dcerpc_netr_DatabaseSync_r(samsync_state->b, loop_ctx, &r),
1246 "DatabaseSync failed");
1247 if (!NT_STATUS_IS_OK(r.out.result) &&
1248 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
1249 torture_comment(tctx, "DatabaseSync - %s\n", nt_errstr(r.out.result));
1250 ret = false;
1251 break;
1254 if (!netlogon_creds_client_check(samsync_state->creds, &r.out.return_authenticator->cred)) {
1255 torture_comment(tctx, "Credential chaining failed\n");
1258 r.in.sync_context = r.out.sync_context;
1260 for (d=0; d < delta_enum_array->num_deltas; d++) {
1261 delta_ctx = talloc_named(loop_ctx, 0, "DatabaseSync delta context");
1263 if (!NT_STATUS_IS_OK(samsync_fix_delta(delta_ctx, samsync_state->creds,
1264 r.in.database_id,
1265 &delta_enum_array->delta_enum[d]))) {
1266 torture_comment(tctx, "Failed to decrypt delta\n");
1267 ret = false;
1270 switch (delta_enum_array->delta_enum[d].delta_type) {
1271 case NETR_DELTA_DOMAIN:
1272 if (!samsync_handle_domain(tctx, delta_ctx, samsync_state,
1273 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1274 torture_comment(tctx, "Failed to handle DELTA_DOMAIN\n");
1275 ret = false;
1277 break;
1278 case NETR_DELTA_GROUP:
1279 if (!samsync_handle_group(tctx, delta_ctx, samsync_state,
1280 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1281 torture_comment(tctx, "Failed to handle DELTA_USER\n");
1282 ret = false;
1284 break;
1285 case NETR_DELTA_USER:
1286 if (!samsync_handle_user(tctx, delta_ctx, samsync_state,
1287 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1288 torture_comment(tctx, "Failed to handle DELTA_USER\n");
1289 ret = false;
1291 break;
1292 case NETR_DELTA_ALIAS:
1293 if (!samsync_handle_alias(tctx, delta_ctx, samsync_state,
1294 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1295 torture_comment(tctx, "Failed to handle DELTA_ALIAS\n");
1296 ret = false;
1298 break;
1299 case NETR_DELTA_POLICY:
1300 if (!samsync_handle_policy(tctx, delta_ctx, samsync_state,
1301 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1302 torture_comment(tctx, "Failed to handle DELTA_POLICY\n");
1303 ret = false;
1305 break;
1306 case NETR_DELTA_TRUSTED_DOMAIN:
1307 if (!samsync_handle_trusted_domain(tctx, delta_ctx, samsync_state,
1308 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1309 torture_comment(tctx, "Failed to handle DELTA_TRUSTED_DOMAIN\n");
1310 ret = false;
1312 break;
1313 case NETR_DELTA_ACCOUNT:
1314 if (!samsync_handle_account(tctx, delta_ctx, samsync_state,
1315 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1316 torture_comment(tctx, "Failed to handle DELTA_ACCOUNT\n");
1317 ret = false;
1319 break;
1320 case NETR_DELTA_SECRET:
1321 if (!samsync_handle_secret(tctx, delta_ctx, samsync_state,
1322 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1323 torture_comment(tctx, "Failed to handle DELTA_SECRET\n");
1324 ret = false;
1326 break;
1327 case NETR_DELTA_GROUP_MEMBER:
1328 case NETR_DELTA_ALIAS_MEMBER:
1329 /* These are harder to cross-check, and we expect them */
1330 break;
1331 case NETR_DELTA_DELETE_GROUP:
1332 case NETR_DELTA_RENAME_GROUP:
1333 case NETR_DELTA_DELETE_USER:
1334 case NETR_DELTA_RENAME_USER:
1335 case NETR_DELTA_DELETE_ALIAS:
1336 case NETR_DELTA_RENAME_ALIAS:
1337 case NETR_DELTA_DELETE_TRUST:
1338 case NETR_DELTA_DELETE_ACCOUNT:
1339 case NETR_DELTA_DELETE_SECRET:
1340 case NETR_DELTA_DELETE_GROUP2:
1341 case NETR_DELTA_DELETE_USER2:
1342 case NETR_DELTA_MODIFY_COUNT:
1343 default:
1344 torture_comment(tctx, "Uxpected delta type %d\n", delta_enum_array->delta_enum[d].delta_type);
1345 ret = false;
1346 break;
1348 talloc_free(delta_ctx);
1350 talloc_free(loop_ctx);
1351 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1355 domain = samsync_state->domain_name[SAM_DATABASE_DOMAIN];
1356 if (!domain) {
1357 torture_comment(tctx, "Never got a DOMAIN object in samsync!\n");
1358 return false;
1361 trustdom_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync Trusted domains context");
1363 username = talloc_asprintf(trustdom_ctx, "%s$", domain);
1364 for (t=samsync_state->trusted_domains; t; t=t->next) {
1365 char *secret_name = talloc_asprintf(trustdom_ctx, "G$$%s", t->name);
1366 for (s=samsync_state->secrets; s; s=s->next) {
1367 if (strcasecmp_m(s->name, secret_name) == 0) {
1368 NTSTATUS nt_status;
1369 struct samr_Password nt_hash;
1370 mdfour(nt_hash.hash, s->secret.data, s->secret.length);
1372 torture_comment(tctx, "Checking password for %s\\%s\n", t->name, username);
1373 nt_status = test_SamLogon(tctx,
1374 samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta,
1375 t->name,
1376 username,
1377 TEST_WKSTA_MACHINE_NAME,
1378 NULL,
1379 &nt_hash,
1380 NULL);
1381 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_LOGON_SERVERS)) {
1382 torture_comment(tctx, "Verifiction of trust password to %s failed: %s (the trusted domain is not available)\n",
1383 t->name, nt_errstr(nt_status));
1385 break;
1387 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
1388 torture_comment(tctx, "Verifiction of trust password to %s: should have failed (nologon interdomain trust account), instead: %s\n",
1389 t->name, nt_errstr(nt_status));
1390 ret = false;
1393 /* break it */
1394 nt_hash.hash[0]++;
1395 nt_status = test_SamLogon(tctx,
1396 samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta,
1397 t->name,
1398 username,
1399 TEST_WKSTA_MACHINE_NAME,
1400 NULL,
1401 &nt_hash,
1402 NULL);
1404 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
1405 torture_comment(tctx, "Verifiction of trust password to %s: should have failed (wrong password), instead: %s\n",
1406 t->name, nt_errstr(nt_status));
1407 ret = false;
1410 break;
1414 talloc_free(trustdom_ctx);
1415 return ret;
1420 try a netlogon DatabaseDeltas
1422 static bool test_DatabaseDeltas(struct torture_context *tctx,
1423 struct samsync_state *samsync_state, TALLOC_CTX *mem_ctx)
1425 TALLOC_CTX *loop_ctx;
1426 struct netr_DatabaseDeltas r;
1427 struct netr_Authenticator credential;
1428 struct netr_Authenticator return_authenticator;
1429 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1430 const uint32_t database_ids[] = {0, 1, 2};
1431 int i;
1432 bool ret = true;
1434 ZERO_STRUCT(return_authenticator);
1436 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
1437 r.in.computername = TEST_MACHINE_NAME;
1438 r.in.credential = &credential;
1439 r.in.preferredmaximumlength = (uint32_t)-1;
1440 r.in.return_authenticator = &return_authenticator;
1441 r.out.return_authenticator = &return_authenticator;
1442 r.out.delta_enum_array = &delta_enum_array;
1444 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1446 uint64_t seq_num = samsync_state->seq_num[i];
1448 r.in.database_id = database_ids[i];
1449 r.in.sequence_num = &seq_num;
1450 r.out.sequence_num = &seq_num;
1452 if (seq_num == 0) continue;
1454 /* this shows that the bdc doesn't need to do a single call for
1455 * each seqnumber, and the pdc doesn't need to know about old values
1456 * -- metze
1458 seq_num -= 10;
1460 torture_comment(tctx, "Testing DatabaseDeltas of id %d at %llu\n",
1461 r.in.database_id, (long long)seq_num);
1463 do {
1464 loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseDeltas loop context");
1465 netlogon_creds_client_authenticator(samsync_state->creds, &credential);
1467 torture_assert_ntstatus_ok(tctx,
1468 dcerpc_netr_DatabaseDeltas_r(samsync_state->b, loop_ctx, &r),
1469 "DatabaseDeltas failed");
1470 if (!NT_STATUS_IS_OK(r.out.result) &&
1471 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) &&
1472 !NT_STATUS_EQUAL(r.out.result, NT_STATUS_SYNCHRONIZATION_REQUIRED)) {
1473 torture_comment(tctx, "DatabaseDeltas - %s\n", nt_errstr(r.out.result));
1474 ret = false;
1477 if (!netlogon_creds_client_check(samsync_state->creds, &return_authenticator.cred)) {
1478 torture_comment(tctx, "Credential chaining failed\n");
1481 seq_num++;
1482 talloc_free(loop_ctx);
1483 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1486 return ret;
1491 try a netlogon DatabaseSync2
1493 static bool test_DatabaseSync2(struct torture_context *tctx,
1494 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1495 struct netlogon_creds_CredentialState *creds)
1497 TALLOC_CTX *loop_ctx;
1498 struct netr_DatabaseSync2 r;
1499 const uint32_t database_ids[] = {0, 1, 2};
1500 int i;
1501 bool ret = true;
1502 struct netr_Authenticator return_authenticator, credential;
1503 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1504 struct dcerpc_binding_handle *b = p->binding_handle;
1506 ZERO_STRUCT(return_authenticator);
1508 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1509 r.in.computername = TEST_MACHINE_NAME;
1510 r.in.preferredmaximumlength = (uint32_t)-1;
1511 r.in.return_authenticator = &return_authenticator;
1512 r.out.return_authenticator = &return_authenticator;
1513 r.out.delta_enum_array = &delta_enum_array;
1515 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1517 uint32_t sync_context = 0;
1519 r.in.database_id = database_ids[i];
1520 r.in.sync_context = &sync_context;
1521 r.out.sync_context = &sync_context;
1522 r.in.restart_state = 0;
1524 torture_comment(tctx, "Testing DatabaseSync2 of id %d\n", r.in.database_id);
1526 do {
1527 loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync2 loop context");
1528 netlogon_creds_client_authenticator(creds, &credential);
1530 r.in.credential = &credential;
1532 torture_assert_ntstatus_ok(tctx,
1533 dcerpc_netr_DatabaseSync2_r(b, loop_ctx, &r),
1534 "DatabaseSync2 failed");
1535 if (!NT_STATUS_IS_OK(r.out.result) &&
1536 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
1537 torture_comment(tctx, "DatabaseSync2 - %s\n", nt_errstr(r.out.result));
1538 ret = false;
1541 if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
1542 torture_comment(tctx, "Credential chaining failed\n");
1545 talloc_free(loop_ctx);
1546 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1549 return ret;
1554 bool torture_rpc_samsync(struct torture_context *torture)
1556 NTSTATUS status;
1557 TALLOC_CTX *mem_ctx;
1558 bool ret = true;
1559 struct test_join *join_ctx;
1560 struct test_join *join_ctx2;
1561 struct test_join *user_ctx;
1562 const char *machine_password;
1563 const char *wksta_machine_password;
1564 struct dcerpc_binding *b;
1565 struct dcerpc_binding *b_netlogon_wksta;
1566 struct samr_Connect c;
1567 struct samr_SetDomainInfo s;
1568 struct policy_handle *domain_policy;
1570 struct lsa_ObjectAttribute attr;
1571 struct lsa_QosInfo qos;
1572 struct lsa_OpenPolicy2 r;
1573 struct cli_credentials *credentials;
1574 struct cli_credentials *credentials_wksta;
1576 struct samsync_state *samsync_state;
1578 char *test_machine_account;
1580 char *test_wksta_machine_account;
1582 mem_ctx = talloc_init("torture_rpc_netlogon");
1584 test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
1585 join_ctx = torture_create_testuser(torture, test_machine_account,
1586 lpcfg_workgroup(torture->lp_ctx), ACB_SVRTRUST,
1587 &machine_password);
1588 if (!join_ctx) {
1589 talloc_free(mem_ctx);
1590 torture_comment(torture, "Failed to join as BDC\n");
1591 return false;
1594 test_wksta_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_WKSTA_MACHINE_NAME);
1595 join_ctx2 = torture_create_testuser(torture, test_wksta_machine_account, lpcfg_workgroup(torture->lp_ctx), ACB_WSTRUST, &wksta_machine_password);
1596 if (!join_ctx2) {
1597 talloc_free(mem_ctx);
1598 torture_comment(torture, "Failed to join as member\n");
1599 return false;
1602 user_ctx = torture_create_testuser(torture, TEST_USER_NAME,
1603 lpcfg_workgroup(torture->lp_ctx),
1604 ACB_NORMAL, NULL);
1605 if (!user_ctx) {
1606 talloc_free(mem_ctx);
1607 torture_comment(torture, "Failed to create test account\n");
1608 return false;
1611 samsync_state = talloc_zero(mem_ctx, struct samsync_state);
1613 samsync_state->p_samr = torture_join_samr_pipe(join_ctx);
1614 samsync_state->b_samr = samsync_state->p_samr->binding_handle;
1615 samsync_state->connect_handle = talloc_zero(samsync_state, struct policy_handle);
1616 samsync_state->lsa_handle = talloc_zero(samsync_state, struct policy_handle);
1617 c.in.system_name = NULL;
1618 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1619 c.out.connect_handle = samsync_state->connect_handle;
1621 torture_assert_ntstatus_ok_goto(torture,
1622 dcerpc_samr_Connect_r(samsync_state->b_samr, mem_ctx, &c),
1623 ret, failed,
1624 "samr_Connect failed");
1625 torture_assert_ntstatus_ok_goto(torture, c.out.result,
1626 ret, failed,
1627 "samr_Connect failed");
1629 domain_policy = samsync_open_domain(torture, mem_ctx, samsync_state, lpcfg_workgroup(torture->lp_ctx), NULL);
1630 if (!domain_policy) {
1631 torture_comment(torture, "samrsync_open_domain failed\n");
1632 ret = false;
1633 goto failed;
1636 s.in.domain_handle = domain_policy;
1637 s.in.level = 4;
1638 s.in.info = talloc(mem_ctx, union samr_DomainInfo);
1640 s.in.info->oem.oem_information.string
1641 = talloc_asprintf(mem_ctx,
1642 "Tortured by Samba4: %s",
1643 timestring(mem_ctx, time(NULL)));
1644 torture_assert_ntstatus_ok_goto(torture,
1645 dcerpc_samr_SetDomainInfo_r(samsync_state->b_samr, mem_ctx, &s),
1646 ret, failed,
1647 "SetDomainInfo failed");
1649 if (!test_samr_handle_Close(samsync_state->b_samr, torture, domain_policy)) {
1650 ret = false;
1651 goto failed;
1654 torture_assert_ntstatus_ok_goto(torture, s.out.result,
1655 ret, failed,
1656 talloc_asprintf(torture, "SetDomainInfo level %u failed", s.in.level));
1658 status = torture_rpc_connection(torture,
1659 &samsync_state->p_lsa,
1660 &ndr_table_lsarpc);
1662 if (!NT_STATUS_IS_OK(status)) {
1663 ret = false;
1664 goto failed;
1666 samsync_state->b_lsa = samsync_state->p_lsa->binding_handle;
1668 qos.len = 0;
1669 qos.impersonation_level = 2;
1670 qos.context_mode = 1;
1671 qos.effective_only = 0;
1673 attr.len = 0;
1674 attr.root_dir = NULL;
1675 attr.object_name = NULL;
1676 attr.attributes = 0;
1677 attr.sec_desc = NULL;
1678 attr.sec_qos = &qos;
1680 r.in.system_name = "\\";
1681 r.in.attr = &attr;
1682 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1683 r.out.handle = samsync_state->lsa_handle;
1685 torture_assert_ntstatus_ok_goto(torture,
1686 dcerpc_lsa_OpenPolicy2_r(samsync_state->b_lsa, mem_ctx, &r),
1687 ret, failed,
1688 "OpenPolicy2 failed");
1689 torture_assert_ntstatus_ok_goto(torture, r.out.result,
1690 ret, failed,
1691 "OpenPolicy2 failed");
1693 status = torture_rpc_binding(torture, &b);
1694 if (!NT_STATUS_IS_OK(status)) {
1695 ret = false;
1696 goto failed;
1699 b->flags &= ~DCERPC_AUTH_OPTIONS;
1700 b->flags |= DCERPC_SCHANNEL | DCERPC_SIGN;
1702 credentials = cli_credentials_init(mem_ctx);
1704 cli_credentials_set_workstation(credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
1705 cli_credentials_set_domain(credentials, lpcfg_workgroup(torture->lp_ctx), CRED_SPECIFIED);
1706 cli_credentials_set_username(credentials, test_machine_account, CRED_SPECIFIED);
1707 cli_credentials_set_password(credentials, machine_password, CRED_SPECIFIED);
1708 cli_credentials_set_secure_channel_type(credentials,
1709 SEC_CHAN_BDC);
1711 status = dcerpc_pipe_connect_b(samsync_state,
1712 &samsync_state->p, b,
1713 &ndr_table_netlogon,
1714 credentials, torture->ev, torture->lp_ctx);
1716 if (!NT_STATUS_IS_OK(status)) {
1717 torture_comment(torture, "Failed to connect to server as a BDC: %s\n", nt_errstr(status));
1718 ret = false;
1719 goto failed;
1721 samsync_state->b = samsync_state->p->binding_handle;
1723 status = dcerpc_schannel_creds(samsync_state->p->conn->security_state.generic_state,
1724 samsync_state, &samsync_state->creds);
1725 if (!NT_STATUS_IS_OK(status)) {
1726 ret = false;
1731 status = torture_rpc_binding(torture, &b_netlogon_wksta);
1732 if (!NT_STATUS_IS_OK(status)) {
1733 ret = false;
1734 goto failed;
1737 b_netlogon_wksta->flags &= ~DCERPC_AUTH_OPTIONS;
1738 b_netlogon_wksta->flags |= DCERPC_SCHANNEL | DCERPC_SIGN;
1740 credentials_wksta = cli_credentials_init(mem_ctx);
1742 cli_credentials_set_workstation(credentials_wksta, TEST_WKSTA_MACHINE_NAME, CRED_SPECIFIED);
1743 cli_credentials_set_domain(credentials_wksta, lpcfg_workgroup(torture->lp_ctx), CRED_SPECIFIED);
1744 cli_credentials_set_username(credentials_wksta, test_wksta_machine_account, CRED_SPECIFIED);
1745 cli_credentials_set_password(credentials_wksta, wksta_machine_password, CRED_SPECIFIED);
1746 cli_credentials_set_secure_channel_type(credentials_wksta,
1747 SEC_CHAN_WKSTA);
1749 status = dcerpc_pipe_connect_b(samsync_state,
1750 &samsync_state->p_netlogon_wksta,
1751 b_netlogon_wksta,
1752 &ndr_table_netlogon,
1753 credentials_wksta, torture->ev, torture->lp_ctx);
1755 if (!NT_STATUS_IS_OK(status)) {
1756 torture_comment(torture, "Failed to connect to server as a Workstation: %s\n", nt_errstr(status));
1757 ret = false;
1758 goto failed;
1761 status = dcerpc_schannel_creds(samsync_state->p_netlogon_wksta->conn->security_state.generic_state,
1762 samsync_state, &samsync_state->creds_netlogon_wksta);
1763 if (!NT_STATUS_IS_OK(status)) {
1764 torture_comment(torture, "Failed to obtail schanel creds!\n");
1765 ret = false;
1768 if (!test_DatabaseSync(torture, samsync_state, mem_ctx)) {
1769 torture_comment(torture, "DatabaseSync failed\n");
1770 ret = false;
1773 if (!test_DatabaseDeltas(torture, samsync_state, mem_ctx)) {
1774 torture_comment(torture, "DatabaseDeltas failed\n");
1775 ret = false;
1778 if (!test_DatabaseSync2(torture, samsync_state->p, mem_ctx, samsync_state->creds)) {
1779 torture_comment(torture, "DatabaseSync2 failed\n");
1780 ret = false;
1782 failed:
1784 torture_leave_domain(torture, join_ctx);
1785 torture_leave_domain(torture, join_ctx2);
1786 torture_leave_domain(torture, user_ctx);
1788 talloc_free(mem_ctx);
1790 return ret;