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/>.
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
)
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
;
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
));
76 ninfo
.nt
.data
= talloc_array(mem_ctx
, uint8_t, 24);
77 rc
= SMBOWFencrypt(nt_hash
->hash
, ninfo
.challenge
,
80 return gnutls_error_to_ntstatus(rc
, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER
);
89 ninfo
.lm
.data
= talloc_array(mem_ctx
, uint8_t, 24);
90 rc
= SMBOWFencrypt(lm_hash
->hash
, ninfo
.challenge
,
93 return gnutls_error_to_ntstatus(rc
, NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER
);
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
;
108 r
.out
.validation
= &validation
;
109 r
.out
.authoritative
= &authoritative
;
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
)) {
121 if (!netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
)) {
122 torture_comment(tctx
, "Credential chaining failed\n");
126 *info3
= validation
.sam3
;
132 struct samsync_state
{
133 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
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
;
160 struct samsync_trusted_domain
{
161 struct samsync_trusted_domain
*prev
, *next
;
166 static struct policy_handle
*samsync_open_domain(struct torture_context
*tctx
,
168 struct samsync_state
*samsync_state
,
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
);
179 name
.string
= domain
;
180 l
.in
.connect_handle
= samsync_state
->connect_handle
;
181 l
.in
.domain_name
= &name
;
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
));
189 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
190 torture_comment(tctx
, "LookupDomain failed - %s\n", nt_errstr(l
.out
.result
));
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
;
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
));
208 if (!NT_STATUS_IS_OK(o
.out
.result
)) {
209 torture_comment(tctx
, "OpenDomain failed - %s\n", nt_errstr(o
.out
.result
));
213 return domain_handle
;
216 static struct sec_desc_buf
*samsync_query_samr_sec_desc(struct torture_context
*tctx
,
218 struct samsync_state
*samsync_state
,
219 struct policy_handle
*handle
)
221 struct samr_QuerySecurity r
;
222 struct sec_desc_buf
*sdbuf
= NULL
;
225 r
.in
.handle
= handle
;
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
));
234 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
235 torture_comment(tctx
, "SAMR QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
242 static struct sec_desc_buf
*samsync_query_lsa_sec_desc(struct torture_context
*tctx
,
244 struct samsync_state
*samsync_state
,
245 struct policy_handle
*handle
)
247 struct lsa_QuerySecurity r
;
248 struct sec_desc_buf
*sdbuf
= NULL
;
251 r
.in
.handle
= handle
;
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
));
260 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
261 torture_comment(tctx
, "LSA QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
268 #define TEST_UINT64_EQUAL(i1, i2) do {\
270 torture_comment(tctx, "%s: uint64 mismatch: " #i1 ": 0x%016llx (%lld) != " #i2 ": 0x%016llx (%lld)\n", \
272 (long long)i1, (long long)i1, \
273 (long long)i2, (long long)i2);\
277 #define TEST_INT_EQUAL(i1, i2) do {\
279 torture_comment(tctx, "%s: integer mismatch: " #i1 ": 0x%08x (%d) != " #i2 ": 0x%08x (%d)\n", \
280 __location__, i1, i1, i2, i2); \
284 #define TEST_TIME_EQUAL(t1, t2) do {\
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));\
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);\
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);\
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));\
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, \
324 if (!sdbuf || !sdbuf->sd) { \
325 torture_comment(tctx, "Could not obtain security descriptor to match " #sd1 "\n");\
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);\
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};
349 samsync_state
->seq_num
[database_id
] =
350 domain
->sequence_num
;
351 switch (database_id
) {
352 case SAM_DATABASE_DOMAIN
:
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
);
359 case SAM_DATABASE_PRIVS
:
360 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
365 if (!samsync_state
->domain_name
[database_id
]) {
366 samsync_state
->domain_name
[database_id
] =
367 talloc_strdup(samsync_state
, domain
->domain_name
.string
);
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
);
376 if (!samsync_state
->domain_handle
[database_id
]) {
377 samsync_state
->domain_handle
[database_id
] =
378 samsync_open_domain(tctx
,
381 samsync_state
->domain_name
[database_id
],
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
]);
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
:
439 case SAM_DATABASE_PRIVS
:
440 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
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
);
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
);
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
]));
464 torture_comment(tctx
, "\tsequence_nums[%d/PRIVS]=%llu\n",
466 (long long)samsync_state
->seq_num
[database_id
]);
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
;
481 const char *username
= user
->account_name
.string
;
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
:
495 case SAM_DATABASE_PRIVS
:
496 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
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");
508 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
509 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
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
;
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");
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
);
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");
572 TEST_INT_EQUAL(info
->info21
.bad_password_count
,
573 user
->bad_password_count
);
574 TEST_INT_EQUAL(info
->info21
.logon_count
,
577 TEST_TIME_EQUAL(info
->info21
.last_password_change
,
578 user
->last_password_change
);
579 TEST_TIME_EQUAL(info
->info21
.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");
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
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
) {
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
;
632 torture_comment(tctx
, "Failed to parse Sensitive Data for %s:\n", username
);
634 dump_data(0, data
.data
, data
.length
);
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
)));
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
,
653 TEST_WKSTA_MACHINE_NAME
,
658 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_DISABLED
)) {
659 if (user
->acct_flags
& ACB_DISABLED
) {
662 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
)) {
663 if (user
->acct_flags
& ACB_WSTRUST
) {
666 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT
)) {
667 if (user
->acct_flags
& ACB_SVRTRUST
) {
670 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
671 if (user
->acct_flags
& ACB_DOMTRUST
) {
674 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
675 if (user
->acct_flags
& ACB_DOMTRUST
) {
678 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_LOCKED_OUT
)) {
679 if (user
->acct_flags
& ACB_AUTOLOCK
) {
682 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_PASSWORD_EXPIRED
)) {
683 if (info
->info21
.acct_flags
& ACB_PW_EXPIRED
) {
686 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
)) {
687 if (!lm_hash_p
&& !nt_hash_p
) {
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 */
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
) {
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
)) {
748 for (i
= 0; i
< rids
->count
; i
++) {
749 if (matched
[i
] == false) {
751 torture_comment(tctx
, "Could not find group RID %u found in getgroups in NETLOGON reply\n",
758 torture_comment(tctx
, "Could not validate password for user %s\\%s: %s\n",
759 domain
, username
, nt_errstr(nt_status
));
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
;
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
:
782 case SAM_DATABASE_PRIVS
:
783 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
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");
793 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
794 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
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
;
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
)) {
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
));
823 TEST_STRING_EQUAL(info
->all
.name
, alias
->alias_name
);
824 TEST_STRING_EQUAL(info
->all
.description
, alias
->description
);
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
;
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
:
845 case SAM_DATABASE_PRIVS
:
846 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
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");
856 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
857 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
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
;
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
)) {
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
));
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
);
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
;
908 DATA_BLOB lsa_blob1
, lsa_blob_out
, session_key
;
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
,
939 if (!NT_STATUS_IS_OK(status
)) {
940 torture_comment(tctx
, "transport_session_key failed - %s\n", nt_errstr(status
));
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
;
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 */
964 } else if (!NT_STATUS_IS_OK(q
.out
.result
)) {
965 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(q
.out
.result
));
969 if (q
.out
.old_val
->buf
== NULL
) {
970 /* probably just not available due to ACLs */
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
));
981 if (!q
.out
.old_mtime
) {
982 torture_comment(tctx
, "OLD mtime not available on LSA for secret %s\n", old
->name
);
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
));
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
);
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",
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
);
1009 if (q
.out
.new_val
->buf
== NULL
) {
1010 /* probably just not available due to ACLs */
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");
1021 if (!q
.out
.new_mtime
) {
1022 torture_comment(tctx
, "NEW mtime not available on LSA for secret %s\n", nsec
->name
);
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
));
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
);
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",
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
);
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
)
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};
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
;
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
;
1094 torture_comment(tctx
, "QueryInfoTrustedDomain level %d failed - %s\n",
1095 levels
[i
], nt_errstr(q
.out
.result
));
1098 info
[levels
[i
]] = _info
;
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
);
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
)
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
;
1132 bool *found_priv_in_lsa
;
1134 a
.in
.handle
= samsync_state
->lsa_handle
;
1135 a
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
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
));
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
));
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
;
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");
1187 torture_comment(tctx
, "\nLookupPrivName failed to return a name\n");
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;
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
));
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
};
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
);
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
));
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
,
1272 &delta_enum_array
->delta_enum
[d
]))) {
1273 torture_comment(tctx
, "Failed to decrypt delta\n");
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");
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");
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");
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");
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");
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");
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");
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");
1334 case NETR_DELTA_GROUP_MEMBER
:
1335 case NETR_DELTA_ALIAS_MEMBER
:
1336 /* These are harder to cross-check, and we expect them */
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
:
1351 torture_comment(tctx
, "Uxpected delta type %d\n", delta_enum_array
->delta_enum
[d
].delta_type
);
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
];
1364 torture_comment(tctx
, "Never got a DOMAIN object in samsync!\n");
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) {
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
,
1384 TEST_WKSTA_MACHINE_NAME
,
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
));
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
));
1402 nt_status
= test_SamLogon(tctx
,
1403 samsync_state
->p_netlogon_wksta
, trustdom_ctx
, samsync_state
->creds_netlogon_wksta
,
1406 TEST_WKSTA_MACHINE_NAME
,
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
));
1421 talloc_free(trustdom_ctx
);
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};
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
1467 torture_comment(tctx
, "Testing DatabaseDeltas of id %d at %llu\n",
1468 r
.in
.database_id
, (long long)seq_num
);
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
));
1484 if (!netlogon_creds_client_check(samsync_state
->creds
, &return_authenticator
.cred
)) {
1485 torture_comment(tctx
, "Credential chaining failed\n");
1489 talloc_free(loop_ctx
);
1490 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
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};
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
);
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
));
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
));
1561 bool torture_rpc_samsync(struct torture_context
*torture
)
1564 TALLOC_CTX
*mem_ctx
;
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
,
1596 talloc_free(mem_ctx
);
1597 torture_comment(torture
, "Failed to join as BDC\n");
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
);
1604 talloc_free(mem_ctx
);
1605 torture_comment(torture
, "Failed to join as member\n");
1609 user_ctx
= torture_create_testuser(torture
, TEST_USER_NAME
,
1610 lpcfg_workgroup(torture
->lp_ctx
),
1613 talloc_free(mem_ctx
);
1614 torture_comment(torture
, "Failed to create test account\n");
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
),
1631 "samr_Connect failed");
1632 torture_assert_ntstatus_ok_goto(torture
, c
.out
.result
,
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");
1643 s
.in
.domain_handle
= domain_policy
;
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
),
1654 "SetDomainInfo failed");
1656 if (!test_samr_handle_Close(samsync_state
->b_samr
, torture
, domain_policy
)) {
1661 torture_assert_ntstatus_ok_goto(torture
, s
.out
.result
,
1663 talloc_asprintf(torture
, "SetDomainInfo level %u failed", s
.in
.level
));
1665 status
= torture_rpc_connection(torture
,
1666 &samsync_state
->p_lsa
,
1669 if (!NT_STATUS_IS_OK(status
)) {
1673 samsync_state
->b_lsa
= samsync_state
->p_lsa
->binding_handle
;
1676 qos
.impersonation_level
= 2;
1677 qos
.context_mode
= 1;
1678 qos
.effective_only
= 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
= "\\";
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
),
1695 "OpenPolicy2 failed");
1696 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
,
1698 "OpenPolicy2 failed");
1700 status
= torture_rpc_binding(torture
, &b
);
1701 if (!NT_STATUS_IS_OK(status
)) {
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
,
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
));
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
) {
1739 status
= torture_rpc_binding(torture
, &b_netlogon_wksta
);
1740 if (!NT_STATUS_IS_OK(status
)) {
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
,
1759 status
= dcerpc_pipe_connect_b(samsync_state
,
1760 &samsync_state
->p_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
));
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");
1777 if (!test_DatabaseSync(torture
, samsync_state
, mem_ctx
)) {
1778 torture_comment(torture
, "DatabaseSync failed\n");
1782 if (!test_DatabaseDeltas(torture
, samsync_state
, mem_ctx
)) {
1783 torture_comment(torture
, "DatabaseDeltas failed\n");
1787 if (!test_DatabaseSync2(torture
, samsync_state
->p
, mem_ctx
, samsync_state
->creds
)) {
1788 torture_comment(torture
, "DatabaseSync2 failed\n");
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
);