ctdb-scripts: Support storing statd-callout state in cluster filesystem
[samba4-gss.git] / source4 / torture / rpc / samsync.c
blob40bea6e8e2d295dfdfb411947d2dde1a9a69fadd
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 "libcli/auth/libcli_auth.h"
31 #include "libcli/samsync/samsync.h"
32 #include "libcli/security/security.h"
33 #include "librpc/gen_ndr/ndr_netlogon.h"
34 #include "librpc/gen_ndr/ndr_netlogon_c.h"
35 #include "librpc/gen_ndr/ndr_lsa_c.h"
36 #include "librpc/gen_ndr/ndr_samr_c.h"
37 #include "librpc/gen_ndr/ndr_security.h"
38 #include "param/param.h"
39 #include "lib/crypto/gnutls_helpers.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;
65 int rc;
67 ninfo.identity_info.domain_name.string = domain;
68 ninfo.identity_info.parameter_control = 0;
69 ninfo.identity_info.logon_id = 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 rc = SMBOWFencrypt(nt_hash->hash, ninfo.challenge,
78 ninfo.nt.data);
79 if (rc != 0) {
80 return gnutls_error_to_ntstatus(rc, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER);
82 } else {
83 ninfo.nt.length = 0;
84 ninfo.nt.data = NULL;
87 if (lm_hash) {
88 ninfo.lm.length = 24;
89 ninfo.lm.data = talloc_array(mem_ctx, uint8_t, 24);
90 rc = SMBOWFencrypt(lm_hash->hash, ninfo.challenge,
91 ninfo.lm.data);
92 if (rc != 0) {
93 return gnutls_error_to_ntstatus(rc, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER);
95 } else {
96 ninfo.lm.length = 0;
97 ninfo.lm.data = NULL;
100 logon.network = &ninfo;
102 r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
103 r.in.computer_name = workstation;
104 r.in.credential = &auth;
105 r.in.return_authenticator = &auth2;
106 r.in.logon_level = NetlogonNetworkInformation;
107 r.in.logon = &logon;
108 r.out.validation = &validation;
109 r.out.authoritative = &authoritative;
111 ZERO_STRUCT(auth2);
112 netlogon_creds_client_authenticator(creds, &auth);
114 r.in.validation_level = 3;
116 status = dcerpc_netr_LogonSamLogon_r(b, mem_ctx, &r);
117 if (!NT_STATUS_IS_OK(status)) {
118 return status;
121 if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
122 torture_comment(tctx, "Credential chaining failed\n");
125 if (info3) {
126 *info3 = validation.sam3;
129 return r.out.result;
132 struct samsync_state {
133 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
134 uint64_t seq_num[3];
135 const char *domain_name[2];
136 struct samsync_secret *secrets;
137 struct samsync_trusted_domain *trusted_domains;
138 struct netlogon_creds_CredentialState *creds;
139 struct netlogon_creds_CredentialState *creds_netlogon_wksta;
140 struct policy_handle *connect_handle;
141 struct policy_handle *domain_handle[2];
142 struct dom_sid *sid[2];
143 struct dcerpc_pipe *p;
144 struct dcerpc_binding_handle *b;
145 struct dcerpc_pipe *p_netlogon_wksta;
146 struct dcerpc_pipe *p_samr;
147 struct dcerpc_binding_handle *b_samr;
148 struct dcerpc_pipe *p_lsa;
149 struct dcerpc_binding_handle *b_lsa;
150 struct policy_handle *lsa_handle;
153 struct samsync_secret {
154 struct samsync_secret *prev, *next;
155 DATA_BLOB secret;
156 const char *name;
157 NTTIME mtime;
160 struct samsync_trusted_domain {
161 struct samsync_trusted_domain *prev, *next;
162 struct dom_sid *sid;
163 const char *name;
166 static struct policy_handle *samsync_open_domain(struct torture_context *tctx,
167 TALLOC_CTX *mem_ctx,
168 struct samsync_state *samsync_state,
169 const char *domain,
170 struct dom_sid **sid_p)
172 struct lsa_String name;
173 struct samr_OpenDomain o;
174 struct samr_LookupDomain l;
175 struct dom_sid2 *sid = NULL;
176 struct policy_handle *domain_handle = talloc(mem_ctx, struct policy_handle);
177 NTSTATUS nt_status;
179 name.string = domain;
180 l.in.connect_handle = samsync_state->connect_handle;
181 l.in.domain_name = &name;
182 l.out.sid = &sid;
184 nt_status = dcerpc_samr_LookupDomain_r(samsync_state->b_samr, mem_ctx, &l);
185 if (!NT_STATUS_IS_OK(nt_status)) {
186 torture_comment(tctx, "LookupDomain failed - %s\n", nt_errstr(nt_status));
187 return NULL;
189 if (!NT_STATUS_IS_OK(l.out.result)) {
190 torture_comment(tctx, "LookupDomain failed - %s\n", nt_errstr(l.out.result));
191 return NULL;
194 o.in.connect_handle = samsync_state->connect_handle;
195 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
196 o.in.sid = *l.out.sid;
197 o.out.domain_handle = domain_handle;
199 if (sid_p) {
200 *sid_p = *l.out.sid;
203 nt_status = dcerpc_samr_OpenDomain_r(samsync_state->b_samr, mem_ctx, &o);
204 if (!NT_STATUS_IS_OK(nt_status)) {
205 torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(nt_status));
206 return NULL;
208 if (!NT_STATUS_IS_OK(o.out.result)) {
209 torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(o.out.result));
210 return NULL;
213 return domain_handle;
216 static struct sec_desc_buf *samsync_query_samr_sec_desc(struct torture_context *tctx,
217 TALLOC_CTX *mem_ctx,
218 struct samsync_state *samsync_state,
219 struct policy_handle *handle)
221 struct samr_QuerySecurity r;
222 struct sec_desc_buf *sdbuf = NULL;
223 NTSTATUS status;
225 r.in.handle = handle;
226 r.in.sec_info = 0x7;
227 r.out.sdbuf = &sdbuf;
229 status = dcerpc_samr_QuerySecurity_r(samsync_state->b_samr, mem_ctx, &r);
230 if (!NT_STATUS_IS_OK(status)) {
231 torture_comment(tctx, "SAMR QuerySecurity failed - %s\n", nt_errstr(status));
232 return NULL;
234 if (!NT_STATUS_IS_OK(r.out.result)) {
235 torture_comment(tctx, "SAMR QuerySecurity failed - %s\n", nt_errstr(r.out.result));
236 return NULL;
239 return sdbuf;
242 static struct sec_desc_buf *samsync_query_lsa_sec_desc(struct torture_context *tctx,
243 TALLOC_CTX *mem_ctx,
244 struct samsync_state *samsync_state,
245 struct policy_handle *handle)
247 struct lsa_QuerySecurity r;
248 struct sec_desc_buf *sdbuf = NULL;
249 NTSTATUS status;
251 r.in.handle = handle;
252 r.in.sec_info = 0x7;
253 r.out.sdbuf = &sdbuf;
255 status = dcerpc_lsa_QuerySecurity_r(samsync_state->b_lsa, mem_ctx, &r);
256 if (!NT_STATUS_IS_OK(status)) {
257 torture_comment(tctx, "LSA QuerySecurity failed - %s\n", nt_errstr(status));
258 return NULL;
260 if (!NT_STATUS_IS_OK(r.out.result)) {
261 torture_comment(tctx, "LSA QuerySecurity failed - %s\n", nt_errstr(r.out.result));
262 return NULL;
265 return sdbuf;
268 #define TEST_UINT64_EQUAL(i1, i2) do {\
269 if (i1 != i2) {\
270 torture_comment(tctx, "%s: uint64 mismatch: " #i1 ": 0x%016llx (%lld) != " #i2 ": 0x%016llx (%lld)\n", \
271 __location__, \
272 (long long)i1, (long long)i1, \
273 (long long)i2, (long long)i2);\
274 ret = false;\
276 } while (0)
277 #define TEST_INT_EQUAL(i1, i2) do {\
278 if (i1 != i2) {\
279 torture_comment(tctx, "%s: integer mismatch: " #i1 ": 0x%08x (%d) != " #i2 ": 0x%08x (%d)\n", \
280 __location__, i1, i1, i2, i2); \
281 ret = false;\
283 } while (0)
284 #define TEST_TIME_EQUAL(t1, t2) do {\
285 if (t1 != t2) {\
286 torture_comment(tctx, "%s: NTTIME mismatch: " #t1 ":%s != " #t2 ": %s\n", \
287 __location__, nt_time_string(mem_ctx, t1), nt_time_string(mem_ctx, t2));\
288 ret = false;\
290 } while (0)
292 #define TEST_STRING_EQUAL(s1, s2) do {\
293 if (!((!s1.string || s1.string[0]=='\0') && (!s2.string || s2.string[0]=='\0')) \
294 && strcmp_safe(s1.string, s2.string) != 0) {\
295 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
296 __location__, s1.string, s2.string);\
297 ret = false;\
299 } while (0)
301 #define TEST_BINARY_STRING_EQUAL(s1, s2) do {\
302 if (!((!s1.array || s1.array[0]=='\0') && (!s2.array || s2.array[0]=='\0')) \
303 && memcmp(s1.array, s2.array, s1.length * 2) != 0) {\
304 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
305 __location__, (const char *)s1.array, (const char *)s2.array);\
306 ret = false;\
308 } while (0)
310 #define TEST_SID_EQUAL(s1, s2) do {\
311 if (!dom_sid_equal(s1, s2)) {\
312 torture_comment(tctx, "%s: dom_sid mismatch: " #s1 ":%s != " #s2 ": %s\n", \
313 __location__, dom_sid_string(mem_ctx, s1), dom_sid_string(mem_ctx, s2));\
314 ret = false;\
316 } while (0)
318 /* The ~SEC_DESC_SACL_PRESENT is because we don't, as administrator,
319 * get back the SACL part of the SD when we ask over SAMR */
321 #define TEST_SEC_DESC_EQUAL(sd1, pipe, handle) do {\
322 struct sec_desc_buf *sdbuf = samsync_query_ ##pipe## _sec_desc(tctx, mem_ctx, samsync_state, \
323 handle); \
324 if (!sdbuf || !sdbuf->sd) { \
325 torture_comment(tctx, "Could not obtain security descriptor to match " #sd1 "\n");\
326 ret = false; \
327 } else {\
328 if (!security_descriptor_mask_equal(sd1.sd, sdbuf->sd, \
329 ~SEC_DESC_SACL_PRESENT)) {\
330 torture_comment(tctx, "Security Descriptor Mismatch for %s:\n", #sd1);\
331 NDR_PRINT_DEBUG(security_descriptor, sd1.sd);\
332 NDR_PRINT_DEBUG(security_descriptor, sdbuf->sd);\
333 ret = false;\
336 } while (0)
338 static bool samsync_handle_domain(struct torture_context *tctx, TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
339 int database_id, struct netr_DELTA_ENUM *delta)
341 struct netr_DELTA_DOMAIN *domain = delta->delta_union.domain;
342 struct dom_sid *dom_sid = NULL;
343 struct samr_QueryDomainInfo q[14]; /* q[0] will be unused simple for clarity */
344 union samr_DomainInfo *info[14];
345 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
346 int i;
347 bool ret = true;
349 samsync_state->seq_num[database_id] =
350 domain->sequence_num;
351 switch (database_id) {
352 case SAM_DATABASE_DOMAIN:
353 break;
354 case SAM_DATABASE_BUILTIN:
355 if (strcasecmp_m("BUILTIN", domain->domain_name.string) != 0) {
356 torture_comment(tctx, "BUILTIN domain has different name: %s\n", domain->domain_name.string);
358 break;
359 case SAM_DATABASE_PRIVS:
360 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
361 return false;
362 break;
365 if (!samsync_state->domain_name[database_id]) {
366 samsync_state->domain_name[database_id] =
367 talloc_strdup(samsync_state, domain->domain_name.string);
368 } else {
369 if (strcasecmp_m(samsync_state->domain_name[database_id], domain->domain_name.string) != 0) {
370 torture_comment(tctx, "Domain has name varies!: %s != %s\n", samsync_state->domain_name[database_id],
371 domain->domain_name.string);
372 return false;
376 if (!samsync_state->domain_handle[database_id]) {
377 samsync_state->domain_handle[database_id] =
378 samsync_open_domain(tctx,
379 samsync_state,
380 samsync_state,
381 samsync_state->domain_name[database_id],
382 &dom_sid);
384 if (samsync_state->domain_handle[database_id]) {
385 samsync_state->sid[database_id] = dom_sid_dup(samsync_state, dom_sid);
388 torture_comment(tctx, "\tsequence_nums[%d/%s]=%llu\n",
389 database_id, domain->domain_name.string,
390 (long long)samsync_state->seq_num[database_id]);
392 for (i=0;i<ARRAY_SIZE(levels);i++) {
394 q[levels[i]].in.domain_handle = samsync_state->domain_handle[database_id];
395 q[levels[i]].in.level = levels[i];
396 q[levels[i]].out.info = &info[levels[i]];
398 torture_assert_ntstatus_ok(tctx,
399 dcerpc_samr_QueryDomainInfo_r(samsync_state->b_samr, mem_ctx, &q[levels[i]]),
400 talloc_asprintf(tctx, "QueryDomainInfo level %u failed", q[levels[i]].in.level));
401 torture_assert_ntstatus_ok(tctx, q[levels[i]].out.result,
402 talloc_asprintf(tctx, "QueryDomainInfo level %u failed", q[levels[i]].in.level));
405 TEST_STRING_EQUAL(info[5]->info5.domain_name, domain->domain_name);
407 TEST_STRING_EQUAL(info[2]->general.oem_information, domain->oem_information);
408 TEST_STRING_EQUAL(info[4]->oem.oem_information, domain->oem_information);
409 TEST_TIME_EQUAL(info[2]->general.force_logoff_time, domain->force_logoff_time);
410 TEST_TIME_EQUAL(info[3]->info3.force_logoff_time, domain->force_logoff_time);
412 TEST_TIME_EQUAL(info[1]->info1.min_password_length, domain->min_password_length);
413 TEST_TIME_EQUAL(info[1]->info1.password_history_length, domain->password_history_length);
414 TEST_TIME_EQUAL(info[1]->info1.max_password_age, domain->max_password_age);
415 TEST_TIME_EQUAL(info[1]->info1.min_password_age, domain->min_password_age);
417 TEST_UINT64_EQUAL(info[8]->info8.sequence_num,
418 domain->sequence_num);
419 TEST_TIME_EQUAL(info[8]->info8.domain_create_time,
420 domain->domain_create_time);
421 TEST_TIME_EQUAL(info[13]->info13.domain_create_time,
422 domain->domain_create_time);
424 TEST_SEC_DESC_EQUAL(domain->sdbuf, samr, samsync_state->domain_handle[database_id]);
426 return ret;
429 static bool samsync_handle_policy(struct torture_context *tctx,
430 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
431 int database_id, struct netr_DELTA_ENUM *delta)
433 struct netr_DELTA_POLICY *policy = delta->delta_union.policy;
435 switch (database_id) {
436 case SAM_DATABASE_DOMAIN:
437 case SAM_DATABASE_BUILTIN:
438 break;
439 case SAM_DATABASE_PRIVS:
440 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
441 return false;
444 samsync_state->seq_num[database_id] =
445 policy->sequence_num;
447 if (!samsync_state->domain_name[SAM_DATABASE_DOMAIN]) {
448 samsync_state->domain_name[SAM_DATABASE_DOMAIN] =
449 talloc_strdup(samsync_state, policy->primary_domain_name.string);
450 } else {
451 if (strcasecmp_m(samsync_state->domain_name[SAM_DATABASE_DOMAIN], policy->primary_domain_name.string) != 0) {
452 torture_comment(tctx, "PRIMARY domain has name varies between DOMAIN and POLICY!: %s != %s\n", samsync_state->domain_name[SAM_DATABASE_DOMAIN],
453 policy->primary_domain_name.string);
454 return false;
458 if (!dom_sid_equal(samsync_state->sid[SAM_DATABASE_DOMAIN], policy->sid)) {
459 torture_comment(tctx, "Domain SID from POLICY (%s) does not match domain sid from SAMR (%s)\n",
460 dom_sid_string(mem_ctx, policy->sid), dom_sid_string(mem_ctx, samsync_state->sid[SAM_DATABASE_DOMAIN]));
461 return false;
464 torture_comment(tctx, "\tsequence_nums[%d/PRIVS]=%llu\n",
465 database_id,
466 (long long)samsync_state->seq_num[database_id]);
467 return true;
470 static bool samsync_handle_user(struct torture_context *tctx, TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
471 int database_id, struct netr_DELTA_ENUM *delta)
473 uint32_t rid = delta->delta_id_union.rid;
474 struct netr_DELTA_USER *user = delta->delta_union.user;
475 struct netr_SamInfo3 *info3 = NULL;
476 struct samr_Password lm_hash;
477 struct samr_Password nt_hash;
478 struct samr_Password *lm_hash_p = NULL;
479 struct samr_Password *nt_hash_p = NULL;
480 const char *domain;
481 const char *username = user->account_name.string;
482 NTSTATUS nt_status;
483 bool ret = true;
484 struct samr_OpenUser r;
485 struct samr_QueryUserInfo q;
486 union samr_UserInfo *info;
487 struct policy_handle user_handle;
488 struct samr_GetGroupsForUser getgr;
489 struct samr_RidWithAttributeArray *rids;
491 switch (database_id) {
492 case SAM_DATABASE_DOMAIN:
493 case SAM_DATABASE_BUILTIN:
494 break;
495 case SAM_DATABASE_PRIVS:
496 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
497 return false;
500 domain = samsync_state->domain_name[database_id];
502 if (domain == NULL ||
503 samsync_state->domain_handle[database_id] == NULL) {
504 torture_comment(tctx, "SamSync needs domain information before the users\n");
505 return false;
508 r.in.domain_handle = samsync_state->domain_handle[database_id];
509 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
510 r.in.rid = rid;
511 r.out.user_handle = &user_handle;
513 torture_assert_ntstatus_ok(tctx,
514 dcerpc_samr_OpenUser_r(samsync_state->b_samr, mem_ctx, &r),
515 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
516 torture_assert_ntstatus_ok(tctx, r.out.result,
517 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
519 q.in.user_handle = &user_handle;
520 q.in.level = 21;
521 q.out.info = &info;
523 TEST_SEC_DESC_EQUAL(user->sdbuf, samr, &user_handle);
525 torture_assert_ntstatus_ok(tctx,
526 dcerpc_samr_QueryUserInfo_r(samsync_state->b_samr, mem_ctx, &q),
527 talloc_asprintf(tctx, "OpenUserInfo level %u failed", q.in.level));
528 torture_assert_ntstatus_ok(tctx, q.out.result,
529 talloc_asprintf(tctx, "OpenUserInfo level %u failed", q.in.level));
531 getgr.in.user_handle = &user_handle;
532 getgr.out.rids = &rids;
534 torture_assert_ntstatus_ok(tctx,
535 dcerpc_samr_GetGroupsForUser_r(samsync_state->b_samr, mem_ctx, &getgr),
536 "GetGroupsForUser failed");
537 torture_assert_ntstatus_ok(tctx, getgr.out.result,
538 "GetGroupsForUser failed");
540 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &user_handle)) {
541 torture_comment(tctx, "samr_handle_Close failed\n");
542 ret = false;
544 if (!ret) {
545 return false;
548 TEST_STRING_EQUAL(info->info21.account_name, user->account_name);
549 TEST_STRING_EQUAL(info->info21.full_name, user->full_name);
550 TEST_INT_EQUAL(info->info21.rid, user->rid);
551 TEST_INT_EQUAL(info->info21.primary_gid, user->primary_gid);
552 TEST_STRING_EQUAL(info->info21.home_directory, user->home_directory);
553 TEST_STRING_EQUAL(info->info21.home_drive, user->home_drive);
554 TEST_STRING_EQUAL(info->info21.logon_script, user->logon_script);
555 TEST_STRING_EQUAL(info->info21.description, user->description);
556 TEST_STRING_EQUAL(info->info21.workstations, user->workstations);
558 TEST_TIME_EQUAL(info->info21.last_logon, user->last_logon);
559 TEST_TIME_EQUAL(info->info21.last_logoff, user->last_logoff);
562 TEST_INT_EQUAL(info->info21.logon_hours.units_per_week,
563 user->logon_hours.units_per_week);
564 if (ret) {
565 if (memcmp(info->info21.logon_hours.bits, user->logon_hours.bits,
566 info->info21.logon_hours.units_per_week/8) != 0) {
567 torture_comment(tctx, "Logon hours mismatch\n");
568 ret = false;
572 TEST_INT_EQUAL(info->info21.bad_password_count,
573 user->bad_password_count);
574 TEST_INT_EQUAL(info->info21.logon_count,
575 user->logon_count);
577 TEST_TIME_EQUAL(info->info21.last_password_change,
578 user->last_password_change);
579 TEST_TIME_EQUAL(info->info21.acct_expiry,
580 user->acct_expiry);
582 TEST_INT_EQUAL((info->info21.acct_flags & ~ACB_PW_EXPIRED), user->acct_flags);
583 if (user->acct_flags & ACB_PWNOEXP) {
584 if (info->info21.acct_flags & ACB_PW_EXPIRED) {
585 torture_comment(tctx, "ACB flags mismatch: both expired and no expiry!\n");
586 ret = false;
588 if (info->info21.force_password_change != (NTTIME)0x7FFFFFFFFFFFFFFFULL) {
589 torture_comment(tctx, "ACB flags mismatch: no password expiry, but force password change 0x%016llx (%lld) != 0x%016llx (%lld)\n",
590 (unsigned long long)info->info21.force_password_change,
591 (unsigned long long)info->info21.force_password_change,
592 (unsigned long long)0x7FFFFFFFFFFFFFFFULL, (unsigned long long)0x7FFFFFFFFFFFFFFFULL
594 ret = false;
598 TEST_INT_EQUAL(info->info21.nt_password_set, user->nt_password_present);
599 TEST_INT_EQUAL(info->info21.lm_password_set, user->lm_password_present);
600 TEST_INT_EQUAL(info->info21.password_expired, user->password_expired);
602 TEST_STRING_EQUAL(info->info21.comment, user->comment);
603 TEST_BINARY_STRING_EQUAL(info->info21.parameters, user->parameters);
605 TEST_INT_EQUAL(info->info21.country_code, user->country_code);
606 TEST_INT_EQUAL(info->info21.code_page, user->code_page);
608 TEST_STRING_EQUAL(info->info21.profile_path, user->profile_path);
610 if (user->lm_password_present) {
611 lm_hash_p = &lm_hash;
613 if (user->nt_password_present) {
614 nt_hash_p = &nt_hash;
617 if (user->user_private_info.SensitiveData) {
618 DATA_BLOB data;
619 struct netr_USER_KEYS keys;
620 enum ndr_err_code ndr_err;
621 data.data = user->user_private_info.SensitiveData;
622 data.length = user->user_private_info.DataLength;
623 ndr_err = ndr_pull_struct_blob(&data, mem_ctx, &keys, (ndr_pull_flags_fn_t)ndr_pull_netr_USER_KEYS);
624 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
625 if (keys.keys.keys2.lmpassword.length == 16) {
626 lm_hash_p = &lm_hash;
628 if (keys.keys.keys2.ntpassword.length == 16) {
629 nt_hash_p = &nt_hash;
631 } else {
632 torture_comment(tctx, "Failed to parse Sensitive Data for %s:\n", username);
633 #if 0
634 dump_data(0, data.data, data.length);
635 #endif
636 return false;
640 if (nt_hash_p) {
641 DATA_BLOB nt_hash_blob = data_blob_const(nt_hash_p, 16);
642 DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &nt_hash_blob)));
644 if (lm_hash_p) {
645 DATA_BLOB lm_hash_blob = data_blob_const(lm_hash_p, 16);
646 DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &lm_hash_blob)));
649 nt_status = test_SamLogon(tctx,
650 samsync_state->p_netlogon_wksta, mem_ctx, samsync_state->creds_netlogon_wksta,
651 domain,
652 username,
653 TEST_WKSTA_MACHINE_NAME,
654 lm_hash_p,
655 nt_hash_p,
656 &info3);
658 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_DISABLED)) {
659 if (user->acct_flags & ACB_DISABLED) {
660 return true;
662 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT)) {
663 if (user->acct_flags & ACB_WSTRUST) {
664 return true;
666 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT)) {
667 if (user->acct_flags & ACB_SVRTRUST) {
668 return true;
670 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
671 if (user->acct_flags & ACB_DOMTRUST) {
672 return true;
674 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
675 if (user->acct_flags & ACB_DOMTRUST) {
676 return true;
678 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_LOCKED_OUT)) {
679 if (user->acct_flags & ACB_AUTOLOCK) {
680 return true;
682 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_EXPIRED)) {
683 if (info->info21.acct_flags & ACB_PW_EXPIRED) {
684 return true;
686 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
687 if (!lm_hash_p && !nt_hash_p) {
688 return true;
690 } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_MUST_CHANGE)) {
691 /* We would need to know the server's current time to test this properly */
692 return true;
693 } else if (NT_STATUS_IS_OK(nt_status)) {
694 TEST_INT_EQUAL(user->rid, info3->base.rid);
695 TEST_INT_EQUAL(user->primary_gid, info3->base.primary_gid);
696 /* this is 0x0 from NT4 sp6 */
697 if (info3->base.acct_flags) {
698 TEST_INT_EQUAL(user->acct_flags, info3->base.acct_flags);
700 /* this is NULL from NT4 sp6 */
701 if (info3->base.account_name.string) {
702 TEST_STRING_EQUAL(user->account_name, info3->base.account_name);
704 /* this is NULL from Win2k3 */
705 if (info3->base.full_name.string) {
706 TEST_STRING_EQUAL(user->full_name, info3->base.full_name);
708 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
709 TEST_STRING_EQUAL(user->profile_path, info3->base.profile_path);
710 TEST_STRING_EQUAL(user->home_directory, info3->base.home_directory);
711 TEST_STRING_EQUAL(user->home_drive, info3->base.home_drive);
712 TEST_STRING_EQUAL(user->logon_script, info3->base.logon_script);
715 TEST_TIME_EQUAL(user->last_logon, info3->base.logon_time);
716 TEST_TIME_EQUAL(user->acct_expiry, info3->base.kickoff_time);
717 TEST_TIME_EQUAL(user->last_password_change, info3->base.last_password_change);
718 TEST_TIME_EQUAL(info->info21.force_password_change, info3->base.force_password_change);
720 /* Does the concept of a logoff time ever really
721 * exist? (not in any sensible way, according to the
722 * doco I read -- abartlet) */
724 /* This copes with the two different versions of 0 I see */
725 /* with NT4 sp6 we have the || case */
726 if (!((user->last_logoff == 0)
727 || (info3->base.logoff_time == 0x7fffffffffffffffLL))) {
728 TEST_TIME_EQUAL(user->last_logoff, info3->base.logoff_time);
731 TEST_INT_EQUAL(rids->count, info3->base.groups.count);
732 if (rids->count == info3->base.groups.count) {
733 int i, j;
734 int count = rids->count;
735 bool *matched = talloc_zero_array(mem_ctx, bool, rids->count);
737 for (i = 0; i < count; i++) {
738 for (j = 0; j < count; j++) {
739 if ((rids->rids[i].rid ==
740 info3->base.groups.rids[j].rid)
741 && (rids->rids[i].attributes ==
742 info3->base.groups.rids[j].attributes)) {
743 matched[i] = true;
748 for (i = 0; i < rids->count; i++) {
749 if (matched[i] == false) {
750 ret = false;
751 torture_comment(tctx, "Could not find group RID %u found in getgroups in NETLOGON reply\n",
752 rids->rids[i].rid);
756 return ret;
757 } else {
758 torture_comment(tctx, "Could not validate password for user %s\\%s: %s\n",
759 domain, username, nt_errstr(nt_status));
760 return false;
762 return false;
765 static bool samsync_handle_alias(struct torture_context *tctx,
766 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
767 int database_id, struct netr_DELTA_ENUM *delta)
769 uint32_t rid = delta->delta_id_union.rid;
770 struct netr_DELTA_ALIAS *alias = delta->delta_union.alias;
771 bool ret = true;
773 struct samr_OpenAlias r;
774 struct samr_QueryAliasInfo q;
775 union samr_AliasInfo *info;
776 struct policy_handle alias_handle;
778 switch (database_id) {
779 case SAM_DATABASE_DOMAIN:
780 case SAM_DATABASE_BUILTIN:
781 break;
782 case SAM_DATABASE_PRIVS:
783 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
784 return false;
787 if (samsync_state->domain_name[database_id] == NULL ||
788 samsync_state->domain_handle[database_id] == NULL) {
789 torture_comment(tctx, "SamSync needs domain information before the users\n");
790 return false;
793 r.in.domain_handle = samsync_state->domain_handle[database_id];
794 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
795 r.in.rid = rid;
796 r.out.alias_handle = &alias_handle;
798 torture_assert_ntstatus_ok(tctx,
799 dcerpc_samr_OpenAlias_r(samsync_state->b_samr, mem_ctx, &r),
800 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
801 torture_assert_ntstatus_ok(tctx, r.out.result,
802 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
804 q.in.alias_handle = &alias_handle;
805 q.in.level = 1;
806 q.out.info = &info;
808 TEST_SEC_DESC_EQUAL(alias->sdbuf, samr, &alias_handle);
810 torture_assert_ntstatus_ok(tctx,
811 dcerpc_samr_QueryAliasInfo_r(samsync_state->b_samr, mem_ctx, &q),
812 "QueryAliasInfo failed");
813 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &alias_handle)) {
814 return false;
817 if (!NT_STATUS_IS_OK(q.out.result)) {
818 torture_comment(tctx, "QueryAliasInfo level %u failed - %s\n",
819 q.in.level, nt_errstr(q.out.result));
820 return false;
823 TEST_STRING_EQUAL(info->all.name, alias->alias_name);
824 TEST_STRING_EQUAL(info->all.description, alias->description);
825 return ret;
828 static bool samsync_handle_group(struct torture_context *tctx,
829 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
830 int database_id, struct netr_DELTA_ENUM *delta)
832 uint32_t rid = delta->delta_id_union.rid;
833 struct netr_DELTA_GROUP *group = delta->delta_union.group;
834 bool ret = true;
836 struct samr_OpenGroup r;
837 struct samr_QueryGroupInfo q;
838 union samr_GroupInfo *info;
839 struct policy_handle group_handle;
841 switch (database_id) {
842 case SAM_DATABASE_DOMAIN:
843 case SAM_DATABASE_BUILTIN:
844 break;
845 case SAM_DATABASE_PRIVS:
846 torture_comment(tctx, "DOMAIN entry on privs DB!\n");
847 return false;
850 if (samsync_state->domain_name[database_id] == NULL ||
851 samsync_state->domain_handle[database_id] == NULL) {
852 torture_comment(tctx, "SamSync needs domain information before the users\n");
853 return false;
856 r.in.domain_handle = samsync_state->domain_handle[database_id];
857 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
858 r.in.rid = rid;
859 r.out.group_handle = &group_handle;
861 torture_assert_ntstatus_ok(tctx,
862 dcerpc_samr_OpenGroup_r(samsync_state->b_samr, mem_ctx, &r),
863 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
864 torture_assert_ntstatus_ok(tctx, r.out.result,
865 talloc_asprintf(tctx, "OpenUser(%u) failed", rid));
867 q.in.group_handle = &group_handle;
868 q.in.level = 1;
869 q.out.info = &info;
871 TEST_SEC_DESC_EQUAL(group->sdbuf, samr, &group_handle);
873 torture_assert_ntstatus_ok(tctx,
874 dcerpc_samr_QueryGroupInfo_r(samsync_state->b_samr, mem_ctx, &q),
875 "QueryGroupInfo failed");
876 if (!test_samr_handle_Close(samsync_state->b_samr, tctx, &group_handle)) {
877 return false;
880 if (!NT_STATUS_IS_OK(q.out.result)) {
881 torture_comment(tctx, "QueryGroupInfo level %u failed - %s\n",
882 q.in.level, nt_errstr(q.out.result));
883 return false;
886 TEST_STRING_EQUAL(info->all.name, group->group_name);
887 TEST_INT_EQUAL(info->all.attributes, group->attributes);
888 TEST_STRING_EQUAL(info->all.description, group->description);
889 return ret;
892 static bool samsync_handle_secret(struct torture_context *tctx,
893 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
894 int database_id, struct netr_DELTA_ENUM *delta)
896 struct netr_DELTA_SECRET *secret = delta->delta_union.secret;
897 const char *name = delta->delta_id_union.name;
898 struct samsync_secret *nsec = talloc(samsync_state, struct samsync_secret);
899 struct samsync_secret *old = talloc(mem_ctx, struct samsync_secret);
900 struct lsa_QuerySecret q;
901 struct lsa_OpenSecret o;
902 struct policy_handle sec_handle;
903 struct lsa_DATA_BUF_PTR bufp1;
904 struct lsa_DATA_BUF_PTR bufp2;
905 NTTIME nsec_mtime;
906 NTTIME old_mtime;
907 bool ret = true;
908 DATA_BLOB lsa_blob1, lsa_blob_out, session_key;
909 NTSTATUS status;
911 nsec->name = talloc_strdup(nsec, name);
912 nsec->secret = data_blob_talloc(nsec, secret->current_cipher.cipher_data, secret->current_cipher.maxlen);
913 nsec->mtime = secret->current_cipher_set_time;
915 DLIST_ADD(samsync_state->secrets, nsec);
917 old->name = talloc_strdup(old, name);
918 old->secret = data_blob_const(secret->old_cipher.cipher_data, secret->old_cipher.maxlen);
919 old->mtime = secret->old_cipher_set_time;
921 o.in.handle = samsync_state->lsa_handle;
922 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
923 o.in.name.string = name;
924 o.out.sec_handle = &sec_handle;
926 torture_assert_ntstatus_ok(tctx,
927 dcerpc_lsa_OpenSecret_r(samsync_state->b_lsa, mem_ctx, &o),
928 "OpenSecret failed");
929 torture_assert_ntstatus_ok(tctx, o.out.result,
930 "OpenSecret failed");
933 We would like to do this, but it is NOT_SUPPORTED on win2k3
934 TEST_SEC_DESC_EQUAL(secret->sdbuf, lsa, &sec_handle);
936 status = dcerpc_binding_handle_transport_session_key(samsync_state->b_lsa,
937 mem_ctx,
938 &session_key);
939 if (!NT_STATUS_IS_OK(status)) {
940 torture_comment(tctx, "transport_session_key failed - %s\n", nt_errstr(status));
941 return false;
945 ZERO_STRUCT(nsec_mtime);
946 ZERO_STRUCT(old_mtime);
948 /* fetch the secret back again */
949 q.in.sec_handle = &sec_handle;
950 q.in.new_val = &bufp1;
951 q.in.new_mtime = &nsec_mtime;
952 q.in.old_val = &bufp2;
953 q.in.old_mtime = &old_mtime;
955 bufp1.buf = NULL;
956 bufp2.buf = NULL;
958 torture_assert_ntstatus_ok(tctx,
959 dcerpc_lsa_QuerySecret_r(samsync_state->b_lsa, mem_ctx, &q),
960 "QuerySecret failed");
961 if (NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, q.out.result)) {
962 /* some things are just off limits */
963 return true;
964 } else if (!NT_STATUS_IS_OK(q.out.result)) {
965 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(q.out.result));
966 return false;
969 if (q.out.old_val->buf == NULL) {
970 /* probably just not available due to ACLs */
971 } else {
972 lsa_blob1.data = q.out.old_val->buf->data;
973 lsa_blob1.length = q.out.old_val->buf->length;
975 status = sess_decrypt_blob(mem_ctx, &lsa_blob1, &session_key, &lsa_blob_out);
976 if (!NT_STATUS_IS_OK(status)) {
977 torture_comment(tctx, "Failed to decrypt secrets OLD blob: %s\n", nt_errstr(status));
978 return false;
981 if (!q.out.old_mtime) {
982 torture_comment(tctx, "OLD mtime not available on LSA for secret %s\n", old->name);
983 ret = false;
985 if (old->mtime != *q.out.old_mtime) {
986 torture_comment(tctx, "OLD mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
987 old->name, nt_time_string(mem_ctx, old->mtime),
988 nt_time_string(mem_ctx, *q.out.old_mtime));
989 ret = false;
992 if (old->secret.length != lsa_blob_out.length) {
993 torture_comment(tctx, "Returned secret %s doesn't match: %d != %d\n",
994 old->name, (int)old->secret.length, (int)lsa_blob_out.length);
995 ret = false;
996 } else if (memcmp(lsa_blob_out.data,
997 old->secret.data, old->secret.length) != 0) {
998 torture_comment(tctx, "Returned secret %s doesn't match: \n",
999 old->name);
1000 DEBUG(1, ("SamSync Secret:\n"));
1001 dump_data(1, old->secret.data, old->secret.length);
1002 DEBUG(1, ("LSA Secret:\n"));
1003 dump_data(1, lsa_blob_out.data, lsa_blob_out.length);
1004 ret = false;
1009 if (q.out.new_val->buf == NULL) {
1010 /* probably just not available due to ACLs */
1011 } else {
1012 lsa_blob1.data = q.out.new_val->buf->data;
1013 lsa_blob1.length = q.out.new_val->buf->length;
1015 status = sess_decrypt_blob(mem_ctx, &lsa_blob1, &session_key, &lsa_blob_out);
1016 if (!NT_STATUS_IS_OK(status)) {
1017 torture_comment(tctx, "Failed to decrypt secrets OLD blob\n");
1018 return false;
1021 if (!q.out.new_mtime) {
1022 torture_comment(tctx, "NEW mtime not available on LSA for secret %s\n", nsec->name);
1023 ret = false;
1025 if (nsec->mtime != *q.out.new_mtime) {
1026 torture_comment(tctx, "NEW mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
1027 nsec->name, nt_time_string(mem_ctx, nsec->mtime),
1028 nt_time_string(mem_ctx, *q.out.new_mtime));
1029 ret = false;
1032 if (nsec->secret.length != lsa_blob_out.length) {
1033 torture_comment(tctx, "Returned secret %s doesn't match: %d != %d\n",
1034 nsec->name, (int)nsec->secret.length, (int)lsa_blob_out.length);
1035 ret = false;
1036 } else if (memcmp(lsa_blob_out.data,
1037 nsec->secret.data, nsec->secret.length) != 0) {
1038 torture_comment(tctx, "Returned secret %s doesn't match: \n",
1039 nsec->name);
1040 DEBUG(1, ("SamSync Secret:\n"));
1041 dump_data(1, nsec->secret.data, nsec->secret.length);
1042 DEBUG(1, ("LSA Secret:\n"));
1043 dump_data(1, lsa_blob_out.data, lsa_blob_out.length);
1044 ret = false;
1048 return ret;
1051 static bool samsync_handle_trusted_domain(struct torture_context *tctx,
1052 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
1053 int database_id, struct netr_DELTA_ENUM *delta)
1055 bool ret = true;
1056 struct netr_DELTA_TRUSTED_DOMAIN *trusted_domain = delta->delta_union.trusted_domain;
1057 struct dom_sid *dom_sid = delta->delta_id_union.sid;
1059 struct samsync_trusted_domain *ndom = talloc(samsync_state, struct samsync_trusted_domain);
1060 struct lsa_OpenTrustedDomain t;
1061 struct policy_handle trustdom_handle;
1062 struct lsa_QueryTrustedDomainInfo q;
1063 union lsa_TrustedDomainInfo *info[9];
1064 union lsa_TrustedDomainInfo *_info = NULL;
1065 int levels [] = {1, 3, 8};
1066 int i;
1068 ndom->name = talloc_strdup(ndom, trusted_domain->domain_name.string);
1069 ndom->sid = dom_sid_dup(ndom, dom_sid);
1071 t.in.handle = samsync_state->lsa_handle;
1072 t.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1073 t.in.sid = dom_sid;
1074 t.out.trustdom_handle = &trustdom_handle;
1076 torture_assert_ntstatus_ok(tctx,
1077 dcerpc_lsa_OpenTrustedDomain_r(samsync_state->b_lsa, mem_ctx, &t),
1078 "OpenTrustedDomain failed");
1079 torture_assert_ntstatus_ok(tctx, t.out.result,
1080 "OpenTrustedDomain failed");
1082 for (i=0; i< ARRAY_SIZE(levels); i++) {
1083 q.in.trustdom_handle = &trustdom_handle;
1084 q.in.level = levels[i];
1085 q.out.info = &_info;
1086 torture_assert_ntstatus_ok(tctx,
1087 dcerpc_lsa_QueryTrustedDomainInfo_r(samsync_state->b_lsa, mem_ctx, &q),
1088 "QueryTrustedDomainInfo failed");
1089 if (!NT_STATUS_IS_OK(q.out.result)) {
1090 if (q.in.level == 8 && NT_STATUS_EQUAL(q.out.result, NT_STATUS_INVALID_PARAMETER)) {
1091 info[levels[i]] = NULL;
1092 continue;
1094 torture_comment(tctx, "QueryInfoTrustedDomain level %d failed - %s\n",
1095 levels[i], nt_errstr(q.out.result));
1096 return false;
1098 info[levels[i]] = _info;
1101 if (info[8]) {
1102 TEST_SID_EQUAL(info[8]->full_info.info_ex.sid, dom_sid);
1103 TEST_STRING_EQUAL(info[8]->full_info.info_ex.netbios_name, trusted_domain->domain_name);
1105 TEST_STRING_EQUAL(info[1]->name.netbios_name, trusted_domain->domain_name);
1106 TEST_INT_EQUAL(info[3]->posix_offset.posix_offset, trusted_domain->posix_offset);
1108 We would like to do this, but it is NOT_SUPPORTED on win2k3
1109 TEST_SEC_DESC_EQUAL(trusted_domain->sdbuf, lsa, &trustdom_handle);
1111 DLIST_ADD(samsync_state->trusted_domains, ndom);
1113 return ret;
1116 static bool samsync_handle_account(struct torture_context *tctx,
1117 TALLOC_CTX *mem_ctx, struct samsync_state *samsync_state,
1118 int database_id, struct netr_DELTA_ENUM *delta)
1120 bool ret = true;
1121 struct netr_DELTA_ACCOUNT *account = delta->delta_union.account;
1122 struct dom_sid *dom_sid = delta->delta_id_union.sid;
1124 struct lsa_OpenAccount a;
1125 struct policy_handle acct_handle;
1126 struct lsa_EnumPrivsAccount e;
1127 struct lsa_PrivilegeSet *privs = NULL;
1128 struct lsa_LookupPrivName r;
1130 int i, j;
1132 bool *found_priv_in_lsa;
1134 a.in.handle = samsync_state->lsa_handle;
1135 a.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1136 a.in.sid = dom_sid;
1137 a.out.acct_handle = &acct_handle;
1139 torture_assert_ntstatus_ok(tctx,
1140 dcerpc_lsa_OpenAccount_r(samsync_state->b_lsa, mem_ctx, &a),
1141 "OpenAccount failed");
1142 torture_assert_ntstatus_ok(tctx, a.out.result,
1143 "OpenAccount failed");
1145 TEST_SEC_DESC_EQUAL(account->sdbuf, lsa, &acct_handle);
1147 found_priv_in_lsa = talloc_zero_array(mem_ctx, bool, account->privilege_entries);
1149 e.in.handle = &acct_handle;
1150 e.out.privs = &privs;
1152 torture_assert_ntstatus_ok(tctx,
1153 dcerpc_lsa_EnumPrivsAccount_r(samsync_state->b_lsa, mem_ctx, &e),
1154 "EnumPrivsAccount failed");
1155 torture_assert_ntstatus_ok(tctx, e.out.result,
1156 "EnumPrivsAccount failed");
1158 if ((account->privilege_entries && !privs)) {
1159 torture_comment(tctx, "Account %s has privileges in SamSync, but not LSA\n",
1160 dom_sid_string(mem_ctx, dom_sid));
1161 return false;
1164 if (!account->privilege_entries && privs && privs->count) {
1165 torture_comment(tctx, "Account %s has privileges in LSA, but not SamSync\n",
1166 dom_sid_string(mem_ctx, dom_sid));
1167 return false;
1170 TEST_INT_EQUAL(account->privilege_entries, privs->count);
1172 for (i=0;i< privs->count; i++) {
1174 struct lsa_StringLarge *name = NULL;
1176 r.in.handle = samsync_state->lsa_handle;
1177 r.in.luid = &privs->set[i].luid;
1178 r.out.name = &name;
1180 torture_assert_ntstatus_ok(tctx,
1181 dcerpc_lsa_LookupPrivName_r(samsync_state->b_lsa, mem_ctx, &r),
1182 "\nLookupPrivName failed");
1183 torture_assert_ntstatus_ok(tctx, r.out.result,
1184 "\nLookupPrivName failed");
1186 if (!r.out.name) {
1187 torture_comment(tctx, "\nLookupPrivName failed to return a name\n");
1188 return false;
1190 for (j=0;j<account->privilege_entries; j++) {
1191 if (strcmp(name->string, account->privilege_name[j].string) == 0) {
1192 found_priv_in_lsa[j] = true;
1193 break;
1197 for (j=0;j<account->privilege_entries; j++) {
1198 if (!found_priv_in_lsa[j]) {
1199 torture_comment(tctx, "Privilege %s on account %s not found in LSA\n", account->privilege_name[j].string,
1200 dom_sid_string(mem_ctx, dom_sid));
1201 ret = false;
1204 return ret;
1208 try a netlogon DatabaseSync
1210 static bool test_DatabaseSync(struct torture_context *tctx,
1211 struct samsync_state *samsync_state,
1212 TALLOC_CTX *mem_ctx)
1214 TALLOC_CTX *loop_ctx, *delta_ctx, *trustdom_ctx;
1215 struct netr_DatabaseSync r;
1216 const enum netr_SamDatabaseID database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS};
1217 int i, d;
1218 bool ret = true;
1219 struct samsync_trusted_domain *t;
1220 struct samsync_secret *s;
1221 struct netr_Authenticator return_authenticator, credential;
1222 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1224 const char *domain, *username;
1226 ZERO_STRUCT(return_authenticator);
1228 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
1229 r.in.computername = TEST_MACHINE_NAME;
1230 r.in.preferredmaximumlength = (uint32_t)-1;
1231 r.in.return_authenticator = &return_authenticator;
1232 r.out.return_authenticator = &return_authenticator;
1233 r.out.delta_enum_array = &delta_enum_array;
1235 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1237 uint32_t sync_context = 0;
1239 r.in.database_id = database_ids[i];
1240 r.in.sync_context = &sync_context;
1241 r.out.sync_context = &sync_context;
1243 torture_comment(tctx, "Testing DatabaseSync of id %d\n", r.in.database_id);
1245 do {
1246 loop_ctx = talloc_named(mem_ctx, 0, "DatabaseSync loop context");
1247 netlogon_creds_client_authenticator(samsync_state->creds, &credential);
1249 r.in.credential = &credential;
1251 torture_assert_ntstatus_ok(tctx,
1252 dcerpc_netr_DatabaseSync_r(samsync_state->b, loop_ctx, &r),
1253 "DatabaseSync failed");
1254 if (!NT_STATUS_IS_OK(r.out.result) &&
1255 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
1256 torture_comment(tctx, "DatabaseSync - %s\n", nt_errstr(r.out.result));
1257 ret = false;
1258 break;
1261 if (!netlogon_creds_client_check(samsync_state->creds, &r.out.return_authenticator->cred)) {
1262 torture_comment(tctx, "Credential chaining failed\n");
1265 r.in.sync_context = r.out.sync_context;
1267 for (d=0; d < delta_enum_array->num_deltas; d++) {
1268 delta_ctx = talloc_named(loop_ctx, 0, "DatabaseSync delta context");
1270 if (!NT_STATUS_IS_OK(samsync_fix_delta(delta_ctx, samsync_state->creds,
1271 r.in.database_id,
1272 &delta_enum_array->delta_enum[d]))) {
1273 torture_comment(tctx, "Failed to decrypt delta\n");
1274 ret = false;
1277 switch (delta_enum_array->delta_enum[d].delta_type) {
1278 case NETR_DELTA_DOMAIN:
1279 if (!samsync_handle_domain(tctx, delta_ctx, samsync_state,
1280 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1281 torture_comment(tctx, "Failed to handle DELTA_DOMAIN\n");
1282 ret = false;
1284 break;
1285 case NETR_DELTA_GROUP:
1286 if (!samsync_handle_group(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_USER:
1293 if (!samsync_handle_user(tctx, delta_ctx, samsync_state,
1294 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1295 torture_comment(tctx, "Failed to handle DELTA_USER\n");
1296 ret = false;
1298 break;
1299 case NETR_DELTA_ALIAS:
1300 if (!samsync_handle_alias(tctx, delta_ctx, samsync_state,
1301 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1302 torture_comment(tctx, "Failed to handle DELTA_ALIAS\n");
1303 ret = false;
1305 break;
1306 case NETR_DELTA_POLICY:
1307 if (!samsync_handle_policy(tctx, delta_ctx, samsync_state,
1308 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1309 torture_comment(tctx, "Failed to handle DELTA_POLICY\n");
1310 ret = false;
1312 break;
1313 case NETR_DELTA_TRUSTED_DOMAIN:
1314 if (!samsync_handle_trusted_domain(tctx, delta_ctx, samsync_state,
1315 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1316 torture_comment(tctx, "Failed to handle DELTA_TRUSTED_DOMAIN\n");
1317 ret = false;
1319 break;
1320 case NETR_DELTA_ACCOUNT:
1321 if (!samsync_handle_account(tctx, delta_ctx, samsync_state,
1322 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1323 torture_comment(tctx, "Failed to handle DELTA_ACCOUNT\n");
1324 ret = false;
1326 break;
1327 case NETR_DELTA_SECRET:
1328 if (!samsync_handle_secret(tctx, delta_ctx, samsync_state,
1329 r.in.database_id, &delta_enum_array->delta_enum[d])) {
1330 torture_comment(tctx, "Failed to handle DELTA_SECRET\n");
1331 ret = false;
1333 break;
1334 case NETR_DELTA_GROUP_MEMBER:
1335 case NETR_DELTA_ALIAS_MEMBER:
1336 /* These are harder to cross-check, and we expect them */
1337 break;
1338 case NETR_DELTA_DELETE_GROUP:
1339 case NETR_DELTA_RENAME_GROUP:
1340 case NETR_DELTA_DELETE_USER:
1341 case NETR_DELTA_RENAME_USER:
1342 case NETR_DELTA_DELETE_ALIAS:
1343 case NETR_DELTA_RENAME_ALIAS:
1344 case NETR_DELTA_DELETE_TRUST:
1345 case NETR_DELTA_DELETE_ACCOUNT:
1346 case NETR_DELTA_DELETE_SECRET:
1347 case NETR_DELTA_DELETE_GROUP2:
1348 case NETR_DELTA_DELETE_USER2:
1349 case NETR_DELTA_MODIFY_COUNT:
1350 default:
1351 torture_comment(tctx, "Uxpected delta type %d\n", delta_enum_array->delta_enum[d].delta_type);
1352 ret = false;
1353 break;
1355 talloc_free(delta_ctx);
1357 talloc_free(loop_ctx);
1358 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1362 domain = samsync_state->domain_name[SAM_DATABASE_DOMAIN];
1363 if (!domain) {
1364 torture_comment(tctx, "Never got a DOMAIN object in samsync!\n");
1365 return false;
1368 trustdom_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync Trusted domains context");
1370 username = talloc_asprintf(trustdom_ctx, "%s$", domain);
1371 for (t=samsync_state->trusted_domains; t; t=t->next) {
1372 char *secret_name = talloc_asprintf(trustdom_ctx, "G$$%s", t->name);
1373 for (s=samsync_state->secrets; s; s=s->next) {
1374 if (strcasecmp_m(s->name, secret_name) == 0) {
1375 NTSTATUS nt_status;
1376 struct samr_Password nt_hash;
1377 mdfour(nt_hash.hash, s->secret.data, s->secret.length);
1379 torture_comment(tctx, "Checking password for %s\\%s\n", t->name, username);
1380 nt_status = test_SamLogon(tctx,
1381 samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta,
1382 t->name,
1383 username,
1384 TEST_WKSTA_MACHINE_NAME,
1385 NULL,
1386 &nt_hash,
1387 NULL);
1388 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_LOGON_SERVERS)) {
1389 torture_comment(tctx, "Verifiction of trust password to %s failed: %s (the trusted domain is not available)\n",
1390 t->name, nt_errstr(nt_status));
1392 break;
1394 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
1395 torture_comment(tctx, "Verifiction of trust password to %s: should have failed (nologon interdomain trust account), instead: %s\n",
1396 t->name, nt_errstr(nt_status));
1397 ret = false;
1400 /* break it */
1401 nt_hash.hash[0]++;
1402 nt_status = test_SamLogon(tctx,
1403 samsync_state->p_netlogon_wksta, trustdom_ctx, samsync_state->creds_netlogon_wksta,
1404 t->name,
1405 username,
1406 TEST_WKSTA_MACHINE_NAME,
1407 NULL,
1408 &nt_hash,
1409 NULL);
1411 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD)) {
1412 torture_comment(tctx, "Verifiction of trust password to %s: should have failed (wrong password), instead: %s\n",
1413 t->name, nt_errstr(nt_status));
1414 ret = false;
1417 break;
1421 talloc_free(trustdom_ctx);
1422 return ret;
1427 try a netlogon DatabaseDeltas
1429 static bool test_DatabaseDeltas(struct torture_context *tctx,
1430 struct samsync_state *samsync_state, TALLOC_CTX *mem_ctx)
1432 TALLOC_CTX *loop_ctx;
1433 struct netr_DatabaseDeltas r;
1434 struct netr_Authenticator credential;
1435 struct netr_Authenticator return_authenticator;
1436 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1437 const uint32_t database_ids[] = {0, 1, 2};
1438 int i;
1439 bool ret = true;
1441 ZERO_STRUCT(return_authenticator);
1443 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(samsync_state->p));
1444 r.in.computername = TEST_MACHINE_NAME;
1445 r.in.credential = &credential;
1446 r.in.preferredmaximumlength = (uint32_t)-1;
1447 r.in.return_authenticator = &return_authenticator;
1448 r.out.return_authenticator = &return_authenticator;
1449 r.out.delta_enum_array = &delta_enum_array;
1451 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1453 uint64_t seq_num = samsync_state->seq_num[i];
1455 r.in.database_id = database_ids[i];
1456 r.in.sequence_num = &seq_num;
1457 r.out.sequence_num = &seq_num;
1459 if (seq_num == 0) continue;
1461 /* this shows that the bdc doesn't need to do a single call for
1462 * each seqnumber, and the pdc doesn't need to know about old values
1463 * -- metze
1465 seq_num -= 10;
1467 torture_comment(tctx, "Testing DatabaseDeltas of id %d at %llu\n",
1468 r.in.database_id, (long long)seq_num);
1470 do {
1471 loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseDeltas loop context");
1472 netlogon_creds_client_authenticator(samsync_state->creds, &credential);
1474 torture_assert_ntstatus_ok(tctx,
1475 dcerpc_netr_DatabaseDeltas_r(samsync_state->b, loop_ctx, &r),
1476 "DatabaseDeltas failed");
1477 if (!NT_STATUS_IS_OK(r.out.result) &&
1478 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) &&
1479 !NT_STATUS_EQUAL(r.out.result, NT_STATUS_SYNCHRONIZATION_REQUIRED)) {
1480 torture_comment(tctx, "DatabaseDeltas - %s\n", nt_errstr(r.out.result));
1481 ret = false;
1484 if (!netlogon_creds_client_check(samsync_state->creds, &return_authenticator.cred)) {
1485 torture_comment(tctx, "Credential chaining failed\n");
1488 seq_num++;
1489 talloc_free(loop_ctx);
1490 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1493 return ret;
1498 try a netlogon DatabaseSync2
1500 static bool test_DatabaseSync2(struct torture_context *tctx,
1501 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1502 struct netlogon_creds_CredentialState *creds)
1504 TALLOC_CTX *loop_ctx;
1505 struct netr_DatabaseSync2 r;
1506 const uint32_t database_ids[] = {0, 1, 2};
1507 int i;
1508 bool ret = true;
1509 struct netr_Authenticator return_authenticator, credential;
1510 struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
1511 struct dcerpc_binding_handle *b = p->binding_handle;
1513 ZERO_STRUCT(return_authenticator);
1515 r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
1516 r.in.computername = TEST_MACHINE_NAME;
1517 r.in.preferredmaximumlength = (uint32_t)-1;
1518 r.in.return_authenticator = &return_authenticator;
1519 r.out.return_authenticator = &return_authenticator;
1520 r.out.delta_enum_array = &delta_enum_array;
1522 for (i=0;i<ARRAY_SIZE(database_ids);i++) {
1524 uint32_t sync_context = 0;
1526 r.in.database_id = database_ids[i];
1527 r.in.sync_context = &sync_context;
1528 r.out.sync_context = &sync_context;
1529 r.in.restart_state = 0;
1531 torture_comment(tctx, "Testing DatabaseSync2 of id %d\n", r.in.database_id);
1533 do {
1534 loop_ctx = talloc_named(mem_ctx, 0, "test_DatabaseSync2 loop context");
1535 netlogon_creds_client_authenticator(creds, &credential);
1537 r.in.credential = &credential;
1539 torture_assert_ntstatus_ok(tctx,
1540 dcerpc_netr_DatabaseSync2_r(b, loop_ctx, &r),
1541 "DatabaseSync2 failed");
1542 if (!NT_STATUS_IS_OK(r.out.result) &&
1543 !NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
1544 torture_comment(tctx, "DatabaseSync2 - %s\n", nt_errstr(r.out.result));
1545 ret = false;
1548 if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) {
1549 torture_comment(tctx, "Credential chaining failed\n");
1552 talloc_free(loop_ctx);
1553 } while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
1556 return ret;
1561 bool torture_rpc_samsync(struct torture_context *torture)
1563 NTSTATUS status;
1564 TALLOC_CTX *mem_ctx;
1565 bool ret = true;
1566 struct test_join *join_ctx;
1567 struct test_join *join_ctx2;
1568 struct test_join *user_ctx;
1569 const char *machine_password;
1570 const char *wksta_machine_password;
1571 struct dcerpc_binding *b;
1572 struct dcerpc_binding *b_netlogon_wksta;
1573 struct samr_Connect c;
1574 struct samr_SetDomainInfo s;
1575 struct policy_handle *domain_policy;
1577 struct lsa_ObjectAttribute attr;
1578 struct lsa_QosInfo qos;
1579 struct lsa_OpenPolicy2 r;
1580 struct cli_credentials *credentials;
1581 struct cli_credentials *credentials_wksta;
1583 struct samsync_state *samsync_state;
1585 char *test_machine_account;
1587 char *test_wksta_machine_account;
1589 mem_ctx = talloc_init("torture_rpc_netlogon");
1591 test_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_MACHINE_NAME);
1592 join_ctx = torture_create_testuser(torture, test_machine_account,
1593 lpcfg_workgroup(torture->lp_ctx), ACB_SVRTRUST,
1594 &machine_password);
1595 if (!join_ctx) {
1596 talloc_free(mem_ctx);
1597 torture_comment(torture, "Failed to join as BDC\n");
1598 return false;
1601 test_wksta_machine_account = talloc_asprintf(mem_ctx, "%s$", TEST_WKSTA_MACHINE_NAME);
1602 join_ctx2 = torture_create_testuser(torture, test_wksta_machine_account, lpcfg_workgroup(torture->lp_ctx), ACB_WSTRUST, &wksta_machine_password);
1603 if (!join_ctx2) {
1604 talloc_free(mem_ctx);
1605 torture_comment(torture, "Failed to join as member\n");
1606 return false;
1609 user_ctx = torture_create_testuser(torture, TEST_USER_NAME,
1610 lpcfg_workgroup(torture->lp_ctx),
1611 ACB_NORMAL, NULL);
1612 if (!user_ctx) {
1613 talloc_free(mem_ctx);
1614 torture_comment(torture, "Failed to create test account\n");
1615 return false;
1618 samsync_state = talloc_zero(mem_ctx, struct samsync_state);
1620 samsync_state->p_samr = torture_join_samr_pipe(join_ctx);
1621 samsync_state->b_samr = samsync_state->p_samr->binding_handle;
1622 samsync_state->connect_handle = talloc_zero(samsync_state, struct policy_handle);
1623 samsync_state->lsa_handle = talloc_zero(samsync_state, struct policy_handle);
1624 c.in.system_name = NULL;
1625 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1626 c.out.connect_handle = samsync_state->connect_handle;
1628 torture_assert_ntstatus_ok_goto(torture,
1629 dcerpc_samr_Connect_r(samsync_state->b_samr, mem_ctx, &c),
1630 ret, failed,
1631 "samr_Connect failed");
1632 torture_assert_ntstatus_ok_goto(torture, c.out.result,
1633 ret, failed,
1634 "samr_Connect failed");
1636 domain_policy = samsync_open_domain(torture, mem_ctx, samsync_state, lpcfg_workgroup(torture->lp_ctx), NULL);
1637 if (!domain_policy) {
1638 torture_comment(torture, "samrsync_open_domain failed\n");
1639 ret = false;
1640 goto failed;
1643 s.in.domain_handle = domain_policy;
1644 s.in.level = 4;
1645 s.in.info = talloc(mem_ctx, union samr_DomainInfo);
1647 s.in.info->oem.oem_information.string
1648 = talloc_asprintf(mem_ctx,
1649 "Tortured by Samba4: %s",
1650 timestring(mem_ctx, time(NULL)));
1651 torture_assert_ntstatus_ok_goto(torture,
1652 dcerpc_samr_SetDomainInfo_r(samsync_state->b_samr, mem_ctx, &s),
1653 ret, failed,
1654 "SetDomainInfo failed");
1656 if (!test_samr_handle_Close(samsync_state->b_samr, torture, domain_policy)) {
1657 ret = false;
1658 goto failed;
1661 torture_assert_ntstatus_ok_goto(torture, s.out.result,
1662 ret, failed,
1663 talloc_asprintf(torture, "SetDomainInfo level %u failed", s.in.level));
1665 status = torture_rpc_connection(torture,
1666 &samsync_state->p_lsa,
1667 &ndr_table_lsarpc);
1669 if (!NT_STATUS_IS_OK(status)) {
1670 ret = false;
1671 goto failed;
1673 samsync_state->b_lsa = samsync_state->p_lsa->binding_handle;
1675 qos.len = 0;
1676 qos.impersonation_level = 2;
1677 qos.context_mode = 1;
1678 qos.effective_only = 0;
1680 attr.len = 0;
1681 attr.root_dir = NULL;
1682 attr.object_name = NULL;
1683 attr.attributes = 0;
1684 attr.sec_desc = NULL;
1685 attr.sec_qos = &qos;
1687 r.in.system_name = "\\";
1688 r.in.attr = &attr;
1689 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1690 r.out.handle = samsync_state->lsa_handle;
1692 torture_assert_ntstatus_ok_goto(torture,
1693 dcerpc_lsa_OpenPolicy2_r(samsync_state->b_lsa, mem_ctx, &r),
1694 ret, failed,
1695 "OpenPolicy2 failed");
1696 torture_assert_ntstatus_ok_goto(torture, r.out.result,
1697 ret, failed,
1698 "OpenPolicy2 failed");
1700 status = torture_rpc_binding(torture, &b);
1701 if (!NT_STATUS_IS_OK(status)) {
1702 ret = false;
1703 goto failed;
1706 status = dcerpc_binding_set_flags(b,
1707 DCERPC_SCHANNEL | DCERPC_SIGN,
1708 DCERPC_AUTH_OPTIONS);
1709 torture_assert_ntstatus_ok(torture, status, "set flags");
1711 credentials = cli_credentials_init(mem_ctx);
1713 cli_credentials_set_workstation(credentials, TEST_MACHINE_NAME, CRED_SPECIFIED);
1714 cli_credentials_set_domain(credentials, lpcfg_workgroup(torture->lp_ctx), CRED_SPECIFIED);
1715 cli_credentials_set_username(credentials, test_machine_account, CRED_SPECIFIED);
1716 cli_credentials_set_password(credentials, machine_password, CRED_SPECIFIED);
1717 cli_credentials_set_secure_channel_type(credentials,
1718 SEC_CHAN_BDC);
1720 status = dcerpc_pipe_connect_b(samsync_state,
1721 &samsync_state->p, b,
1722 &ndr_table_netlogon,
1723 credentials, torture->ev, torture->lp_ctx);
1725 if (!NT_STATUS_IS_OK(status)) {
1726 torture_comment(torture, "Failed to connect to server as a BDC: %s\n", nt_errstr(status));
1727 ret = false;
1728 goto failed;
1730 samsync_state->b = samsync_state->p->binding_handle;
1732 samsync_state->creds = cli_credentials_get_netlogon_creds(credentials);
1733 if (samsync_state->creds == NULL) {
1734 ret = false;
1739 status = torture_rpc_binding(torture, &b_netlogon_wksta);
1740 if (!NT_STATUS_IS_OK(status)) {
1741 ret = false;
1742 goto failed;
1745 status = dcerpc_binding_set_flags(b_netlogon_wksta,
1746 DCERPC_SCHANNEL | DCERPC_SIGN,
1747 DCERPC_AUTH_OPTIONS);
1748 torture_assert_ntstatus_ok(torture, status, "set flags");
1750 credentials_wksta = cli_credentials_init(mem_ctx);
1752 cli_credentials_set_workstation(credentials_wksta, TEST_WKSTA_MACHINE_NAME, CRED_SPECIFIED);
1753 cli_credentials_set_domain(credentials_wksta, lpcfg_workgroup(torture->lp_ctx), CRED_SPECIFIED);
1754 cli_credentials_set_username(credentials_wksta, test_wksta_machine_account, CRED_SPECIFIED);
1755 cli_credentials_set_password(credentials_wksta, wksta_machine_password, CRED_SPECIFIED);
1756 cli_credentials_set_secure_channel_type(credentials_wksta,
1757 SEC_CHAN_WKSTA);
1759 status = dcerpc_pipe_connect_b(samsync_state,
1760 &samsync_state->p_netlogon_wksta,
1761 b_netlogon_wksta,
1762 &ndr_table_netlogon,
1763 credentials_wksta, torture->ev, torture->lp_ctx);
1765 if (!NT_STATUS_IS_OK(status)) {
1766 torture_comment(torture, "Failed to connect to server as a Workstation: %s\n", nt_errstr(status));
1767 ret = false;
1768 goto failed;
1771 samsync_state->creds_netlogon_wksta = cli_credentials_get_netlogon_creds(credentials_wksta);
1772 if (samsync_state->creds_netlogon_wksta == NULL) {
1773 torture_comment(torture, "Failed to obtail schanel creds!\n");
1774 ret = false;
1777 if (!test_DatabaseSync(torture, samsync_state, mem_ctx)) {
1778 torture_comment(torture, "DatabaseSync failed\n");
1779 ret = false;
1782 if (!test_DatabaseDeltas(torture, samsync_state, mem_ctx)) {
1783 torture_comment(torture, "DatabaseDeltas failed\n");
1784 ret = false;
1787 if (!test_DatabaseSync2(torture, samsync_state->p, mem_ctx, samsync_state->creds)) {
1788 torture_comment(torture, "DatabaseSync2 failed\n");
1789 ret = false;
1791 failed:
1793 torture_leave_domain(torture, join_ctx);
1794 torture_leave_domain(torture, join_ctx2);
1795 torture_leave_domain(torture, user_ctx);
1797 talloc_free(mem_ctx);
1799 return ret;