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"
40 #define TEST_MACHINE_NAME "samsynctest"
41 #define TEST_WKSTA_MACHINE_NAME "samsynctest2"
42 #define TEST_USER_NAME "samsynctestuser"
45 try a netlogon SamLogon
47 static NTSTATUS
test_SamLogon(struct torture_context
*tctx
,
48 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
49 struct netlogon_creds_CredentialState
*creds
,
50 const char *domain
, const char *account_name
,
51 const char *workstation
,
52 struct samr_Password
*lm_hash
,
53 struct samr_Password
*nt_hash
,
54 struct netr_SamInfo3
**info3
)
57 struct netr_LogonSamLogon r
;
58 struct netr_Authenticator auth
, auth2
;
59 struct netr_NetworkInfo ninfo
;
60 union netr_LogonLevel logon
;
61 union netr_Validation validation
;
62 uint8_t authoritative
;
63 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
65 ninfo
.identity_info
.domain_name
.string
= domain
;
66 ninfo
.identity_info
.parameter_control
= 0;
67 ninfo
.identity_info
.logon_id_low
= 0;
68 ninfo
.identity_info
.logon_id_high
= 0;
69 ninfo
.identity_info
.account_name
.string
= account_name
;
70 ninfo
.identity_info
.workstation
.string
= workstation
;
71 generate_random_buffer(ninfo
.challenge
,
72 sizeof(ninfo
.challenge
));
75 ninfo
.nt
.data
= talloc_array(mem_ctx
, uint8_t, 24);
76 SMBOWFencrypt(nt_hash
->hash
, ninfo
.challenge
, ninfo
.nt
.data
);
84 ninfo
.lm
.data
= talloc_array(mem_ctx
, uint8_t, 24);
85 SMBOWFencrypt(lm_hash
->hash
, ninfo
.challenge
, ninfo
.lm
.data
);
91 logon
.network
= &ninfo
;
93 r
.in
.server_name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
94 r
.in
.computer_name
= workstation
;
95 r
.in
.credential
= &auth
;
96 r
.in
.return_authenticator
= &auth2
;
97 r
.in
.logon_level
= NetlogonNetworkInformation
;
99 r
.out
.validation
= &validation
;
100 r
.out
.authoritative
= &authoritative
;
103 netlogon_creds_client_authenticator(creds
, &auth
);
105 r
.in
.validation_level
= 3;
107 status
= dcerpc_netr_LogonSamLogon_r(b
, mem_ctx
, &r
);
108 if (!NT_STATUS_IS_OK(status
)) {
112 if (!netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
)) {
113 torture_comment(tctx
, "Credential chaining failed\n");
117 *info3
= validation
.sam3
;
123 struct samsync_state
{
124 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
126 const char *domain_name
[2];
127 struct samsync_secret
*secrets
;
128 struct samsync_trusted_domain
*trusted_domains
;
129 struct netlogon_creds_CredentialState
*creds
;
130 struct netlogon_creds_CredentialState
*creds_netlogon_wksta
;
131 struct policy_handle
*connect_handle
;
132 struct policy_handle
*domain_handle
[2];
133 struct dom_sid
*sid
[2];
134 struct dcerpc_pipe
*p
;
135 struct dcerpc_binding_handle
*b
;
136 struct dcerpc_pipe
*p_netlogon_wksta
;
137 struct dcerpc_pipe
*p_samr
;
138 struct dcerpc_binding_handle
*b_samr
;
139 struct dcerpc_pipe
*p_lsa
;
140 struct dcerpc_binding_handle
*b_lsa
;
141 struct policy_handle
*lsa_handle
;
144 struct samsync_secret
{
145 struct samsync_secret
*prev
, *next
;
151 struct samsync_trusted_domain
{
152 struct samsync_trusted_domain
*prev
, *next
;
157 static struct policy_handle
*samsync_open_domain(struct torture_context
*tctx
,
159 struct samsync_state
*samsync_state
,
161 struct dom_sid
**sid_p
)
163 struct lsa_String name
;
164 struct samr_OpenDomain o
;
165 struct samr_LookupDomain l
;
166 struct dom_sid2
*sid
= NULL
;
167 struct policy_handle
*domain_handle
= talloc(mem_ctx
, struct policy_handle
);
170 name
.string
= domain
;
171 l
.in
.connect_handle
= samsync_state
->connect_handle
;
172 l
.in
.domain_name
= &name
;
175 nt_status
= dcerpc_samr_LookupDomain_r(samsync_state
->b_samr
, mem_ctx
, &l
);
176 if (!NT_STATUS_IS_OK(nt_status
)) {
177 torture_comment(tctx
, "LookupDomain failed - %s\n", nt_errstr(nt_status
));
180 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
181 torture_comment(tctx
, "LookupDomain failed - %s\n", nt_errstr(l
.out
.result
));
185 o
.in
.connect_handle
= samsync_state
->connect_handle
;
186 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
187 o
.in
.sid
= *l
.out
.sid
;
188 o
.out
.domain_handle
= domain_handle
;
194 nt_status
= dcerpc_samr_OpenDomain_r(samsync_state
->b_samr
, mem_ctx
, &o
);
195 if (!NT_STATUS_IS_OK(nt_status
)) {
196 torture_comment(tctx
, "OpenDomain failed - %s\n", nt_errstr(nt_status
));
199 if (!NT_STATUS_IS_OK(o
.out
.result
)) {
200 torture_comment(tctx
, "OpenDomain failed - %s\n", nt_errstr(o
.out
.result
));
204 return domain_handle
;
207 static struct sec_desc_buf
*samsync_query_samr_sec_desc(struct torture_context
*tctx
,
209 struct samsync_state
*samsync_state
,
210 struct policy_handle
*handle
)
212 struct samr_QuerySecurity r
;
213 struct sec_desc_buf
*sdbuf
= NULL
;
216 r
.in
.handle
= handle
;
218 r
.out
.sdbuf
= &sdbuf
;
220 status
= dcerpc_samr_QuerySecurity_r(samsync_state
->b_samr
, mem_ctx
, &r
);
221 if (!NT_STATUS_IS_OK(status
)) {
222 torture_comment(tctx
, "SAMR QuerySecurity failed - %s\n", nt_errstr(status
));
225 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
226 torture_comment(tctx
, "SAMR QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
233 static struct sec_desc_buf
*samsync_query_lsa_sec_desc(struct torture_context
*tctx
,
235 struct samsync_state
*samsync_state
,
236 struct policy_handle
*handle
)
238 struct lsa_QuerySecurity r
;
239 struct sec_desc_buf
*sdbuf
= NULL
;
242 r
.in
.handle
= handle
;
244 r
.out
.sdbuf
= &sdbuf
;
246 status
= dcerpc_lsa_QuerySecurity_r(samsync_state
->b_lsa
, mem_ctx
, &r
);
247 if (!NT_STATUS_IS_OK(status
)) {
248 torture_comment(tctx
, "LSA QuerySecurity failed - %s\n", nt_errstr(status
));
251 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
252 torture_comment(tctx
, "LSA QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
259 #define TEST_UINT64_EQUAL(i1, i2) do {\
261 torture_comment(tctx, "%s: uint64 mismatch: " #i1 ": 0x%016llx (%lld) != " #i2 ": 0x%016llx (%lld)\n", \
263 (long long)i1, (long long)i1, \
264 (long long)i2, (long long)i2);\
268 #define TEST_INT_EQUAL(i1, i2) do {\
270 torture_comment(tctx, "%s: integer mismatch: " #i1 ": 0x%08x (%d) != " #i2 ": 0x%08x (%d)\n", \
271 __location__, i1, i1, i2, i2); \
275 #define TEST_TIME_EQUAL(t1, t2) do {\
277 torture_comment(tctx, "%s: NTTIME mismatch: " #t1 ":%s != " #t2 ": %s\n", \
278 __location__, nt_time_string(mem_ctx, t1), nt_time_string(mem_ctx, t2));\
283 #define TEST_STRING_EQUAL(s1, s2) do {\
284 if (!((!s1.string || s1.string[0]=='\0') && (!s2.string || s2.string[0]=='\0')) \
285 && strcmp_safe(s1.string, s2.string) != 0) {\
286 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
287 __location__, s1.string, s2.string);\
292 #define TEST_BINARY_STRING_EQUAL(s1, s2) do {\
293 if (!((!s1.array || s1.array[0]=='\0') && (!s2.array || s2.array[0]=='\0')) \
294 && memcmp(s1.array, s2.array, s1.length * 2) != 0) {\
295 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
296 __location__, (const char *)s1.array, (const char *)s2.array);\
301 #define TEST_SID_EQUAL(s1, s2) do {\
302 if (!dom_sid_equal(s1, s2)) {\
303 torture_comment(tctx, "%s: dom_sid mismatch: " #s1 ":%s != " #s2 ": %s\n", \
304 __location__, dom_sid_string(mem_ctx, s1), dom_sid_string(mem_ctx, s2));\
309 /* The ~SEC_DESC_SACL_PRESENT is because we don't, as administrator,
310 * get back the SACL part of the SD when we ask over SAMR */
312 #define TEST_SEC_DESC_EQUAL(sd1, pipe, handle) do {\
313 struct sec_desc_buf *sdbuf = samsync_query_ ##pipe## _sec_desc(tctx, mem_ctx, samsync_state, \
315 if (!sdbuf || !sdbuf->sd) { \
316 torture_comment(tctx, "Could not obtain security descriptor to match " #sd1 "\n");\
319 if (!security_descriptor_mask_equal(sd1.sd, sdbuf->sd, \
320 ~SEC_DESC_SACL_PRESENT)) {\
321 torture_comment(tctx, "Security Descriptor Mismatch for %s:\n", #sd1);\
322 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamSync", sd1.sd);\
323 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamR", sdbuf->sd);\
329 static bool samsync_handle_domain(struct torture_context
*tctx
, TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
330 int database_id
, struct netr_DELTA_ENUM
*delta
)
332 struct netr_DELTA_DOMAIN
*domain
= delta
->delta_union
.domain
;
333 struct dom_sid
*dom_sid
;
334 struct samr_QueryDomainInfo q
[14]; /* q[0] will be unused simple for clarity */
335 union samr_DomainInfo
*info
[14];
336 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
340 samsync_state
->seq_num
[database_id
] =
341 domain
->sequence_num
;
342 switch (database_id
) {
343 case SAM_DATABASE_DOMAIN
:
345 case SAM_DATABASE_BUILTIN
:
346 if (strcasecmp_m("BUILTIN", domain
->domain_name
.string
) != 0) {
347 torture_comment(tctx
, "BUILTIN domain has different name: %s\n", domain
->domain_name
.string
);
350 case SAM_DATABASE_PRIVS
:
351 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
356 if (!samsync_state
->domain_name
[database_id
]) {
357 samsync_state
->domain_name
[database_id
] =
358 talloc_reference(samsync_state
, domain
->domain_name
.string
);
360 if (strcasecmp_m(samsync_state
->domain_name
[database_id
], domain
->domain_name
.string
) != 0) {
361 torture_comment(tctx
, "Domain has name varies!: %s != %s\n", samsync_state
->domain_name
[database_id
],
362 domain
->domain_name
.string
);
367 if (!samsync_state
->domain_handle
[database_id
]) {
368 samsync_state
->domain_handle
[database_id
]
369 = talloc_reference(samsync_state
,
370 samsync_open_domain(tctx
,
371 mem_ctx
, samsync_state
, samsync_state
->domain_name
[database_id
],
374 if (samsync_state
->domain_handle
[database_id
]) {
375 samsync_state
->sid
[database_id
] = talloc_reference(samsync_state
, dom_sid
);
378 torture_comment(tctx
, "\tsequence_nums[%d/%s]=%llu\n",
379 database_id
, domain
->domain_name
.string
,
380 (long long)samsync_state
->seq_num
[database_id
]);
382 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
384 q
[levels
[i
]].in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
385 q
[levels
[i
]].in
.level
= levels
[i
];
386 q
[levels
[i
]].out
.info
= &info
[levels
[i
]];
388 torture_assert_ntstatus_ok(tctx
,
389 dcerpc_samr_QueryDomainInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
[levels
[i
]]),
390 talloc_asprintf(tctx
, "QueryDomainInfo level %u failed", q
[levels
[i
]].in
.level
));
391 torture_assert_ntstatus_ok(tctx
, q
[levels
[i
]].out
.result
,
392 talloc_asprintf(tctx
, "QueryDomainInfo level %u failed", q
[levels
[i
]].in
.level
));
395 TEST_STRING_EQUAL(info
[5]->info5
.domain_name
, domain
->domain_name
);
397 TEST_STRING_EQUAL(info
[2]->general
.oem_information
, domain
->oem_information
);
398 TEST_STRING_EQUAL(info
[4]->oem
.oem_information
, domain
->oem_information
);
399 TEST_TIME_EQUAL(info
[2]->general
.force_logoff_time
, domain
->force_logoff_time
);
400 TEST_TIME_EQUAL(info
[3]->info3
.force_logoff_time
, domain
->force_logoff_time
);
402 TEST_TIME_EQUAL(info
[1]->info1
.min_password_length
, domain
->min_password_length
);
403 TEST_TIME_EQUAL(info
[1]->info1
.password_history_length
, domain
->password_history_length
);
404 TEST_TIME_EQUAL(info
[1]->info1
.max_password_age
, domain
->max_password_age
);
405 TEST_TIME_EQUAL(info
[1]->info1
.min_password_age
, domain
->min_password_age
);
407 TEST_UINT64_EQUAL(info
[8]->info8
.sequence_num
,
408 domain
->sequence_num
);
409 TEST_TIME_EQUAL(info
[8]->info8
.domain_create_time
,
410 domain
->domain_create_time
);
411 TEST_TIME_EQUAL(info
[13]->info13
.domain_create_time
,
412 domain
->domain_create_time
);
414 TEST_SEC_DESC_EQUAL(domain
->sdbuf
, samr
, samsync_state
->domain_handle
[database_id
]);
419 static bool samsync_handle_policy(struct torture_context
*tctx
,
420 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
421 int database_id
, struct netr_DELTA_ENUM
*delta
)
423 struct netr_DELTA_POLICY
*policy
= delta
->delta_union
.policy
;
425 switch (database_id
) {
426 case SAM_DATABASE_DOMAIN
:
427 case SAM_DATABASE_BUILTIN
:
429 case SAM_DATABASE_PRIVS
:
430 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
434 samsync_state
->seq_num
[database_id
] =
435 policy
->sequence_num
;
437 if (!samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
]) {
438 samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
] =
439 talloc_reference(samsync_state
, policy
->primary_domain_name
.string
);
441 if (strcasecmp_m(samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
], policy
->primary_domain_name
.string
) != 0) {
442 torture_comment(tctx
, "PRIMARY domain has name varies between DOMAIN and POLICY!: %s != %s\n", samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
],
443 policy
->primary_domain_name
.string
);
448 if (!dom_sid_equal(samsync_state
->sid
[SAM_DATABASE_DOMAIN
], policy
->sid
)) {
449 torture_comment(tctx
, "Domain SID from POLICY (%s) does not match domain sid from SAMR (%s)\n",
450 dom_sid_string(mem_ctx
, policy
->sid
), dom_sid_string(mem_ctx
, samsync_state
->sid
[SAM_DATABASE_DOMAIN
]));
454 torture_comment(tctx
, "\tsequence_nums[%d/PRIVS]=%llu\n",
456 (long long)samsync_state
->seq_num
[database_id
]);
460 static bool samsync_handle_user(struct torture_context
*tctx
, TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
461 int database_id
, struct netr_DELTA_ENUM
*delta
)
463 uint32_t rid
= delta
->delta_id_union
.rid
;
464 struct netr_DELTA_USER
*user
= delta
->delta_union
.user
;
465 struct netr_SamInfo3
*info3
;
466 struct samr_Password lm_hash
;
467 struct samr_Password nt_hash
;
468 struct samr_Password
*lm_hash_p
= NULL
;
469 struct samr_Password
*nt_hash_p
= NULL
;
471 const char *username
= user
->account_name
.string
;
475 switch (database_id
) {
476 case SAM_DATABASE_DOMAIN
:
477 case SAM_DATABASE_BUILTIN
:
479 case SAM_DATABASE_PRIVS
:
480 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
484 domain
= samsync_state
->domain_name
[database_id
];
486 struct samr_OpenUser r
;
487 struct samr_QueryUserInfo q
;
488 union samr_UserInfo
*info
;
489 struct policy_handle user_handle
;
491 struct samr_GetGroupsForUser getgroups
;
492 struct samr_RidWithAttributeArray
*rids
;
494 if (domain
== NULL
||
495 samsync_state
->domain_handle
[database_id
] == NULL
) {
496 torture_comment(tctx
, "SamSync needs domain information before the users\n");
500 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
501 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
503 r
.out
.user_handle
= &user_handle
;
505 torture_assert_ntstatus_ok(tctx
,
506 dcerpc_samr_OpenUser_r(samsync_state
->b_samr
, mem_ctx
, &r
),
507 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
508 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
509 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
511 q
.in
.user_handle
= &user_handle
;
515 TEST_SEC_DESC_EQUAL(user
->sdbuf
, samr
, &user_handle
);
517 torture_assert_ntstatus_ok(tctx
,
518 dcerpc_samr_QueryUserInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
519 talloc_asprintf(tctx
, "OpenUserInfo level %u failed", q
.in
.level
));
520 torture_assert_ntstatus_ok(tctx
, q
.out
.result
,
521 talloc_asprintf(tctx
, "OpenUserInfo level %u failed", q
.in
.level
));
523 getgroups
.in
.user_handle
= &user_handle
;
524 getgroups
.out
.rids
= &rids
;
526 torture_assert_ntstatus_ok(tctx
,
527 dcerpc_samr_GetGroupsForUser_r(samsync_state
->b_samr
, mem_ctx
, &getgroups
),
528 "GetGroupsForUser failed");
529 torture_assert_ntstatus_ok(tctx
, getgroups
.out
.result
,
530 "GetGroupsForUser failed");
532 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &user_handle
)) {
533 torture_comment(tctx
, "samr_handle_Close failed\n");
540 TEST_STRING_EQUAL(info
->info21
.account_name
, user
->account_name
);
541 TEST_STRING_EQUAL(info
->info21
.full_name
, user
->full_name
);
542 TEST_INT_EQUAL(info
->info21
.rid
, user
->rid
);
543 TEST_INT_EQUAL(info
->info21
.primary_gid
, user
->primary_gid
);
544 TEST_STRING_EQUAL(info
->info21
.home_directory
, user
->home_directory
);
545 TEST_STRING_EQUAL(info
->info21
.home_drive
, user
->home_drive
);
546 TEST_STRING_EQUAL(info
->info21
.logon_script
, user
->logon_script
);
547 TEST_STRING_EQUAL(info
->info21
.description
, user
->description
);
548 TEST_STRING_EQUAL(info
->info21
.workstations
, user
->workstations
);
550 TEST_TIME_EQUAL(info
->info21
.last_logon
, user
->last_logon
);
551 TEST_TIME_EQUAL(info
->info21
.last_logoff
, user
->last_logoff
);
554 TEST_INT_EQUAL(info
->info21
.logon_hours
.units_per_week
,
555 user
->logon_hours
.units_per_week
);
557 if (memcmp(info
->info21
.logon_hours
.bits
, user
->logon_hours
.bits
,
558 info
->info21
.logon_hours
.units_per_week
/8) != 0) {
559 torture_comment(tctx
, "Logon hours mismatch\n");
564 TEST_INT_EQUAL(info
->info21
.bad_password_count
,
565 user
->bad_password_count
);
566 TEST_INT_EQUAL(info
->info21
.logon_count
,
569 TEST_TIME_EQUAL(info
->info21
.last_password_change
,
570 user
->last_password_change
);
571 TEST_TIME_EQUAL(info
->info21
.acct_expiry
,
574 TEST_INT_EQUAL((info
->info21
.acct_flags
& ~ACB_PW_EXPIRED
), user
->acct_flags
);
575 if (user
->acct_flags
& ACB_PWNOEXP
) {
576 if (info
->info21
.acct_flags
& ACB_PW_EXPIRED
) {
577 torture_comment(tctx
, "ACB flags mismatch: both expired and no expiry!\n");
580 if (info
->info21
.force_password_change
!= (NTTIME
)0x7FFFFFFFFFFFFFFFULL
) {
581 torture_comment(tctx
, "ACB flags mismatch: no password expiry, but force password change 0x%016llx (%lld) != 0x%016llx (%lld)\n",
582 (unsigned long long)info
->info21
.force_password_change
,
583 (unsigned long long)info
->info21
.force_password_change
,
584 (unsigned long long)0x7FFFFFFFFFFFFFFFULL
, (unsigned long long)0x7FFFFFFFFFFFFFFFULL
590 TEST_INT_EQUAL(info
->info21
.nt_password_set
, user
->nt_password_present
);
591 TEST_INT_EQUAL(info
->info21
.lm_password_set
, user
->lm_password_present
);
592 TEST_INT_EQUAL(info
->info21
.password_expired
, user
->password_expired
);
594 TEST_STRING_EQUAL(info
->info21
.comment
, user
->comment
);
595 TEST_BINARY_STRING_EQUAL(info
->info21
.parameters
, user
->parameters
);
597 TEST_INT_EQUAL(info
->info21
.country_code
, user
->country_code
);
598 TEST_INT_EQUAL(info
->info21
.code_page
, user
->code_page
);
600 TEST_STRING_EQUAL(info
->info21
.profile_path
, user
->profile_path
);
602 if (user
->lm_password_present
) {
603 lm_hash_p
= &lm_hash
;
605 if (user
->nt_password_present
) {
606 nt_hash_p
= &nt_hash
;
609 if (user
->user_private_info
.SensitiveData
) {
611 struct netr_USER_KEYS keys
;
612 enum ndr_err_code ndr_err
;
613 data
.data
= user
->user_private_info
.SensitiveData
;
614 data
.length
= user
->user_private_info
.DataLength
;
615 ndr_err
= ndr_pull_struct_blob(&data
, mem_ctx
, &keys
, (ndr_pull_flags_fn_t
)ndr_pull_netr_USER_KEYS
);
616 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
617 if (keys
.keys
.keys2
.lmpassword
.length
== 16) {
618 lm_hash_p
= &lm_hash
;
620 if (keys
.keys
.keys2
.ntpassword
.length
== 16) {
621 nt_hash_p
= &nt_hash
;
624 torture_comment(tctx
, "Failed to parse Sensitive Data for %s:\n", username
);
626 dump_data(0, data
.data
, data
.length
);
633 DATA_BLOB nt_hash_blob
= data_blob_const(nt_hash_p
, 16);
634 DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state
->domain_name
[0], username
, data_blob_hex_string_upper(mem_ctx
, &nt_hash_blob
)));
637 DATA_BLOB lm_hash_blob
= data_blob_const(lm_hash_p
, 16);
638 DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state
->domain_name
[0], username
, data_blob_hex_string_upper(mem_ctx
, &lm_hash_blob
)));
641 nt_status
= test_SamLogon(tctx
,
642 samsync_state
->p_netlogon_wksta
, mem_ctx
, samsync_state
->creds_netlogon_wksta
,
645 TEST_WKSTA_MACHINE_NAME
,
650 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_DISABLED
)) {
651 if (user
->acct_flags
& ACB_DISABLED
) {
654 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
)) {
655 if (user
->acct_flags
& ACB_WSTRUST
) {
658 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT
)) {
659 if (user
->acct_flags
& ACB_SVRTRUST
) {
662 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
663 if (user
->acct_flags
& ACB_DOMTRUST
) {
666 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
667 if (user
->acct_flags
& ACB_DOMTRUST
) {
670 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_LOCKED_OUT
)) {
671 if (user
->acct_flags
& ACB_AUTOLOCK
) {
674 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_PASSWORD_EXPIRED
)) {
675 if (info
->info21
.acct_flags
& ACB_PW_EXPIRED
) {
678 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
)) {
679 if (!lm_hash_p
&& !nt_hash_p
) {
682 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_PASSWORD_MUST_CHANGE
)) {
683 /* We would need to know the server's current time to test this properly */
685 } else if (NT_STATUS_IS_OK(nt_status
)) {
686 TEST_INT_EQUAL(user
->rid
, info3
->base
.rid
);
687 TEST_INT_EQUAL(user
->primary_gid
, info3
->base
.primary_gid
);
688 /* this is 0x0 from NT4 sp6 */
689 if (info3
->base
.acct_flags
) {
690 TEST_INT_EQUAL(user
->acct_flags
, info3
->base
.acct_flags
);
692 /* this is NULL from NT4 sp6 */
693 if (info3
->base
.account_name
.string
) {
694 TEST_STRING_EQUAL(user
->account_name
, info3
->base
.account_name
);
696 /* this is NULL from Win2k3 */
697 if (info3
->base
.full_name
.string
) {
698 TEST_STRING_EQUAL(user
->full_name
, info3
->base
.full_name
);
700 TEST_STRING_EQUAL(user
->logon_script
, info3
->base
.logon_script
);
701 TEST_STRING_EQUAL(user
->profile_path
, info3
->base
.profile_path
);
702 TEST_STRING_EQUAL(user
->home_directory
, info3
->base
.home_directory
);
703 TEST_STRING_EQUAL(user
->home_drive
, info3
->base
.home_drive
);
704 TEST_STRING_EQUAL(user
->logon_script
, info3
->base
.logon_script
);
707 TEST_TIME_EQUAL(user
->last_logon
, info3
->base
.logon_time
);
708 TEST_TIME_EQUAL(user
->acct_expiry
, info3
->base
.kickoff_time
);
709 TEST_TIME_EQUAL(user
->last_password_change
, info3
->base
.last_password_change
);
710 TEST_TIME_EQUAL(info
->info21
.force_password_change
, info3
->base
.force_password_change
);
712 /* Does the concept of a logoff time ever really
713 * exist? (not in any sensible way, according to the
714 * doco I read -- abartlet) */
716 /* This copes with the two different versions of 0 I see */
717 /* with NT4 sp6 we have the || case */
718 if (!((user
->last_logoff
== 0)
719 || (info3
->base
.logoff_time
== 0x7fffffffffffffffLL
))) {
720 TEST_TIME_EQUAL(user
->last_logoff
, info3
->base
.logoff_time
);
723 TEST_INT_EQUAL(rids
->count
, info3
->base
.groups
.count
);
724 if (rids
->count
== info3
->base
.groups
.count
) {
726 int count
= rids
->count
;
727 bool *matched
= talloc_zero_array(mem_ctx
, bool, rids
->count
);
729 for (i
= 0; i
< count
; i
++) {
730 for (j
= 0; j
< count
; j
++) {
731 if ((rids
->rids
[i
].rid
==
732 info3
->base
.groups
.rids
[j
].rid
)
733 && (rids
->rids
[i
].attributes
==
734 info3
->base
.groups
.rids
[j
].attributes
)) {
740 for (i
= 0; i
< rids
->count
; i
++) {
741 if (matched
[i
] == false) {
743 torture_comment(tctx
, "Could not find group RID %u found in getgroups in NETLOGON reply\n",
750 torture_comment(tctx
, "Could not validate password for user %s\\%s: %s\n",
751 domain
, username
, nt_errstr(nt_status
));
757 static bool samsync_handle_alias(struct torture_context
*tctx
,
758 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
759 int database_id
, struct netr_DELTA_ENUM
*delta
)
761 uint32_t rid
= delta
->delta_id_union
.rid
;
762 struct netr_DELTA_ALIAS
*alias
= delta
->delta_union
.alias
;
765 struct samr_OpenAlias r
;
766 struct samr_QueryAliasInfo q
;
767 union samr_AliasInfo
*info
;
768 struct policy_handle alias_handle
;
770 switch (database_id
) {
771 case SAM_DATABASE_DOMAIN
:
772 case SAM_DATABASE_BUILTIN
:
774 case SAM_DATABASE_PRIVS
:
775 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
779 if (samsync_state
->domain_name
[database_id
] == NULL
||
780 samsync_state
->domain_handle
[database_id
] == NULL
) {
781 torture_comment(tctx
, "SamSync needs domain information before the users\n");
785 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
786 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
788 r
.out
.alias_handle
= &alias_handle
;
790 torture_assert_ntstatus_ok(tctx
,
791 dcerpc_samr_OpenAlias_r(samsync_state
->b_samr
, mem_ctx
, &r
),
792 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
793 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
794 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
796 q
.in
.alias_handle
= &alias_handle
;
800 TEST_SEC_DESC_EQUAL(alias
->sdbuf
, samr
, &alias_handle
);
802 torture_assert_ntstatus_ok(tctx
,
803 dcerpc_samr_QueryAliasInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
804 "QueryAliasInfo failed");
805 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &alias_handle
)) {
809 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
810 torture_comment(tctx
, "QueryAliasInfo level %u failed - %s\n",
811 q
.in
.level
, nt_errstr(q
.out
.result
));
815 TEST_STRING_EQUAL(info
->all
.name
, alias
->alias_name
);
816 TEST_STRING_EQUAL(info
->all
.description
, alias
->description
);
820 static bool samsync_handle_group(struct torture_context
*tctx
,
821 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
822 int database_id
, struct netr_DELTA_ENUM
*delta
)
824 uint32_t rid
= delta
->delta_id_union
.rid
;
825 struct netr_DELTA_GROUP
*group
= delta
->delta_union
.group
;
828 struct samr_OpenGroup r
;
829 struct samr_QueryGroupInfo q
;
830 union samr_GroupInfo
*info
;
831 struct policy_handle group_handle
;
833 switch (database_id
) {
834 case SAM_DATABASE_DOMAIN
:
835 case SAM_DATABASE_BUILTIN
:
837 case SAM_DATABASE_PRIVS
:
838 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
842 if (samsync_state
->domain_name
[database_id
] == NULL
||
843 samsync_state
->domain_handle
[database_id
] == NULL
) {
844 torture_comment(tctx
, "SamSync needs domain information before the users\n");
848 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
849 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
851 r
.out
.group_handle
= &group_handle
;
853 torture_assert_ntstatus_ok(tctx
,
854 dcerpc_samr_OpenGroup_r(samsync_state
->b_samr
, mem_ctx
, &r
),
855 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
856 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
857 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
859 q
.in
.group_handle
= &group_handle
;
863 TEST_SEC_DESC_EQUAL(group
->sdbuf
, samr
, &group_handle
);
865 torture_assert_ntstatus_ok(tctx
,
866 dcerpc_samr_QueryGroupInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
867 "QueryGroupInfo failed");
868 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &group_handle
)) {
872 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
873 torture_comment(tctx
, "QueryGroupInfo level %u failed - %s\n",
874 q
.in
.level
, nt_errstr(q
.out
.result
));
878 TEST_STRING_EQUAL(info
->all
.name
, group
->group_name
);
879 TEST_INT_EQUAL(info
->all
.attributes
, group
->attributes
);
880 TEST_STRING_EQUAL(info
->all
.description
, group
->description
);
884 static bool samsync_handle_secret(struct torture_context
*tctx
,
885 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
886 int database_id
, struct netr_DELTA_ENUM
*delta
)
888 struct netr_DELTA_SECRET
*secret
= delta
->delta_union
.secret
;
889 const char *name
= delta
->delta_id_union
.name
;
890 struct samsync_secret
*nsec
= talloc(samsync_state
, struct samsync_secret
);
891 struct samsync_secret
*old
= talloc(mem_ctx
, struct samsync_secret
);
892 struct lsa_QuerySecret q
;
893 struct lsa_OpenSecret o
;
894 struct policy_handle sec_handle
;
895 struct lsa_DATA_BUF_PTR bufp1
;
896 struct lsa_DATA_BUF_PTR bufp2
;
900 DATA_BLOB lsa_blob1
, lsa_blob_out
, session_key
;
903 nsec
->name
= talloc_reference(nsec
, name
);
904 nsec
->secret
= data_blob_talloc(nsec
, secret
->current_cipher
.cipher_data
, secret
->current_cipher
.maxlen
);
905 nsec
->mtime
= secret
->current_cipher_set_time
;
907 nsec
= talloc_reference(samsync_state
, nsec
);
908 DLIST_ADD(samsync_state
->secrets
, nsec
);
910 old
->name
= talloc_reference(old
, name
);
911 old
->secret
= data_blob_const(secret
->old_cipher
.cipher_data
, secret
->old_cipher
.maxlen
);
912 old
->mtime
= secret
->old_cipher_set_time
;
914 o
.in
.handle
= samsync_state
->lsa_handle
;
915 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
916 o
.in
.name
.string
= name
;
917 o
.out
.sec_handle
= &sec_handle
;
919 torture_assert_ntstatus_ok(tctx
,
920 dcerpc_lsa_OpenSecret_r(samsync_state
->b_lsa
, mem_ctx
, &o
),
921 "OpenSecret failed");
922 torture_assert_ntstatus_ok(tctx
, o
.out
.result
,
923 "OpenSecret failed");
926 We would like to do this, but it is NOT_SUPPORTED on win2k3
927 TEST_SEC_DESC_EQUAL(secret->sdbuf, lsa, &sec_handle);
929 status
= dcerpc_fetch_session_key(samsync_state
->p_lsa
, &session_key
);
930 if (!NT_STATUS_IS_OK(status
)) {
931 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
936 ZERO_STRUCT(nsec_mtime
);
937 ZERO_STRUCT(old_mtime
);
939 /* fetch the secret back again */
940 q
.in
.sec_handle
= &sec_handle
;
941 q
.in
.new_val
= &bufp1
;
942 q
.in
.new_mtime
= &nsec_mtime
;
943 q
.in
.old_val
= &bufp2
;
944 q
.in
.old_mtime
= &old_mtime
;
949 torture_assert_ntstatus_ok(tctx
,
950 dcerpc_lsa_QuerySecret_r(samsync_state
->b_lsa
, mem_ctx
, &q
),
951 "QuerySecret failed");
952 if (NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED
, q
.out
.result
)) {
953 /* some things are just off limits */
955 } else if (!NT_STATUS_IS_OK(q
.out
.result
)) {
956 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(q
.out
.result
));
960 if (q
.out
.old_val
->buf
== NULL
) {
961 /* probably just not available due to ACLs */
963 lsa_blob1
.data
= q
.out
.old_val
->buf
->data
;
964 lsa_blob1
.length
= q
.out
.old_val
->buf
->length
;
966 status
= sess_decrypt_blob(mem_ctx
, &lsa_blob1
, &session_key
, &lsa_blob_out
);
967 if (!NT_STATUS_IS_OK(status
)) {
968 torture_comment(tctx
, "Failed to decrypt secrets OLD blob: %s\n", nt_errstr(status
));
972 if (!q
.out
.old_mtime
) {
973 torture_comment(tctx
, "OLD mtime not available on LSA for secret %s\n", old
->name
);
976 if (old
->mtime
!= *q
.out
.old_mtime
) {
977 torture_comment(tctx
, "OLD mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
978 old
->name
, nt_time_string(mem_ctx
, old
->mtime
),
979 nt_time_string(mem_ctx
, *q
.out
.old_mtime
));
983 if (old
->secret
.length
!= lsa_blob_out
.length
) {
984 torture_comment(tctx
, "Returned secret %s doesn't match: %d != %d\n",
985 old
->name
, (int)old
->secret
.length
, (int)lsa_blob_out
.length
);
987 } else if (memcmp(lsa_blob_out
.data
,
988 old
->secret
.data
, old
->secret
.length
) != 0) {
989 torture_comment(tctx
, "Returned secret %s doesn't match: \n",
991 DEBUG(1, ("SamSync Secret:\n"));
992 dump_data(1, old
->secret
.data
, old
->secret
.length
);
993 DEBUG(1, ("LSA Secret:\n"));
994 dump_data(1, lsa_blob_out
.data
, lsa_blob_out
.length
);
1000 if (q
.out
.new_val
->buf
== NULL
) {
1001 /* probably just not available due to ACLs */
1003 lsa_blob1
.data
= q
.out
.new_val
->buf
->data
;
1004 lsa_blob1
.length
= q
.out
.new_val
->buf
->length
;
1006 status
= sess_decrypt_blob(mem_ctx
, &lsa_blob1
, &session_key
, &lsa_blob_out
);
1007 if (!NT_STATUS_IS_OK(status
)) {
1008 torture_comment(tctx
, "Failed to decrypt secrets OLD blob\n");
1012 if (!q
.out
.new_mtime
) {
1013 torture_comment(tctx
, "NEW mtime not available on LSA for secret %s\n", nsec
->name
);
1016 if (nsec
->mtime
!= *q
.out
.new_mtime
) {
1017 torture_comment(tctx
, "NEW mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
1018 nsec
->name
, nt_time_string(mem_ctx
, nsec
->mtime
),
1019 nt_time_string(mem_ctx
, *q
.out
.new_mtime
));
1023 if (nsec
->secret
.length
!= lsa_blob_out
.length
) {
1024 torture_comment(tctx
, "Returned secret %s doesn't match: %d != %d\n",
1025 nsec
->name
, (int)nsec
->secret
.length
, (int)lsa_blob_out
.length
);
1027 } else if (memcmp(lsa_blob_out
.data
,
1028 nsec
->secret
.data
, nsec
->secret
.length
) != 0) {
1029 torture_comment(tctx
, "Returned secret %s doesn't match: \n",
1031 DEBUG(1, ("SamSync Secret:\n"));
1032 dump_data(1, nsec
->secret
.data
, nsec
->secret
.length
);
1033 DEBUG(1, ("LSA Secret:\n"));
1034 dump_data(1, lsa_blob_out
.data
, lsa_blob_out
.length
);
1042 static bool samsync_handle_trusted_domain(struct torture_context
*tctx
,
1043 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
1044 int database_id
, struct netr_DELTA_ENUM
*delta
)
1047 struct netr_DELTA_TRUSTED_DOMAIN
*trusted_domain
= delta
->delta_union
.trusted_domain
;
1048 struct dom_sid
*dom_sid
= delta
->delta_id_union
.sid
;
1050 struct samsync_trusted_domain
*ndom
= talloc(samsync_state
, struct samsync_trusted_domain
);
1051 struct lsa_OpenTrustedDomain t
;
1052 struct policy_handle trustdom_handle
;
1053 struct lsa_QueryTrustedDomainInfo q
;
1054 union lsa_TrustedDomainInfo
*info
[9];
1055 union lsa_TrustedDomainInfo
*_info
= NULL
;
1056 int levels
[] = {1, 3, 8};
1059 ndom
->name
= talloc_reference(ndom
, trusted_domain
->domain_name
.string
);
1060 ndom
->sid
= talloc_reference(ndom
, dom_sid
);
1062 t
.in
.handle
= samsync_state
->lsa_handle
;
1063 t
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1065 t
.out
.trustdom_handle
= &trustdom_handle
;
1067 torture_assert_ntstatus_ok(tctx
,
1068 dcerpc_lsa_OpenTrustedDomain_r(samsync_state
->b_lsa
, mem_ctx
, &t
),
1069 "OpenTrustedDomain failed");
1070 torture_assert_ntstatus_ok(tctx
, t
.out
.result
,
1071 "OpenTrustedDomain failed");
1073 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
1074 q
.in
.trustdom_handle
= &trustdom_handle
;
1075 q
.in
.level
= levels
[i
];
1076 q
.out
.info
= &_info
;
1077 torture_assert_ntstatus_ok(tctx
,
1078 dcerpc_lsa_QueryTrustedDomainInfo_r(samsync_state
->b_lsa
, mem_ctx
, &q
),
1079 "QueryTrustedDomainInfo failed");
1080 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
1081 if (q
.in
.level
== 8 && NT_STATUS_EQUAL(q
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
1082 info
[levels
[i
]] = NULL
;
1085 torture_comment(tctx
, "QueryInfoTrustedDomain level %d failed - %s\n",
1086 levels
[i
], nt_errstr(q
.out
.result
));
1089 info
[levels
[i
]] = _info
;
1093 TEST_SID_EQUAL(info
[8]->full_info
.info_ex
.sid
, dom_sid
);
1094 TEST_STRING_EQUAL(info
[8]->full_info
.info_ex
.netbios_name
, trusted_domain
->domain_name
);
1096 TEST_STRING_EQUAL(info
[1]->name
.netbios_name
, trusted_domain
->domain_name
);
1097 TEST_INT_EQUAL(info
[3]->posix_offset
.posix_offset
, trusted_domain
->posix_offset
);
1099 We would like to do this, but it is NOT_SUPPORTED on win2k3
1100 TEST_SEC_DESC_EQUAL(trusted_domain->sdbuf, lsa, &trustdom_handle);
1102 ndom
= talloc_reference(samsync_state
, ndom
);
1103 DLIST_ADD(samsync_state
->trusted_domains
, ndom
);
1108 static bool samsync_handle_account(struct torture_context
*tctx
,
1109 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
1110 int database_id
, struct netr_DELTA_ENUM
*delta
)
1113 struct netr_DELTA_ACCOUNT
*account
= delta
->delta_union
.account
;
1114 struct dom_sid
*dom_sid
= delta
->delta_id_union
.sid
;
1116 struct lsa_OpenAccount a
;
1117 struct policy_handle acct_handle
;
1118 struct lsa_EnumPrivsAccount e
;
1119 struct lsa_PrivilegeSet
*privs
= NULL
;
1120 struct lsa_LookupPrivName r
;
1124 bool *found_priv_in_lsa
;
1126 a
.in
.handle
= samsync_state
->lsa_handle
;
1127 a
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1129 a
.out
.acct_handle
= &acct_handle
;
1131 torture_assert_ntstatus_ok(tctx
,
1132 dcerpc_lsa_OpenAccount_r(samsync_state
->b_lsa
, mem_ctx
, &a
),
1133 "OpenAccount failed");
1134 torture_assert_ntstatus_ok(tctx
, a
.out
.result
,
1135 "OpenAccount failed");
1137 TEST_SEC_DESC_EQUAL(account
->sdbuf
, lsa
, &acct_handle
);
1139 found_priv_in_lsa
= talloc_zero_array(mem_ctx
, bool, account
->privilege_entries
);
1141 e
.in
.handle
= &acct_handle
;
1142 e
.out
.privs
= &privs
;
1144 torture_assert_ntstatus_ok(tctx
,
1145 dcerpc_lsa_EnumPrivsAccount_r(samsync_state
->b_lsa
, mem_ctx
, &e
),
1146 "EnumPrivsAccount failed");
1147 torture_assert_ntstatus_ok(tctx
, e
.out
.result
,
1148 "EnumPrivsAccount failed");
1150 if ((account
->privilege_entries
&& !privs
)) {
1151 torture_comment(tctx
, "Account %s has privileges in SamSync, but not LSA\n",
1152 dom_sid_string(mem_ctx
, dom_sid
));
1156 if (!account
->privilege_entries
&& privs
&& privs
->count
) {
1157 torture_comment(tctx
, "Account %s has privileges in LSA, but not SamSync\n",
1158 dom_sid_string(mem_ctx
, dom_sid
));
1162 TEST_INT_EQUAL(account
->privilege_entries
, privs
->count
);
1164 for (i
=0;i
< privs
->count
; i
++) {
1166 struct lsa_StringLarge
*name
= NULL
;
1168 r
.in
.handle
= samsync_state
->lsa_handle
;
1169 r
.in
.luid
= &privs
->set
[i
].luid
;
1172 torture_assert_ntstatus_ok(tctx
,
1173 dcerpc_lsa_LookupPrivName_r(samsync_state
->b_lsa
, mem_ctx
, &r
),
1174 "\nLookupPrivName failed");
1175 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1176 "\nLookupPrivName failed");
1179 torture_comment(tctx
, "\nLookupPrivName failed to return a name\n");
1182 for (j
=0;j
<account
->privilege_entries
; j
++) {
1183 if (strcmp(name
->string
, account
->privilege_name
[j
].string
) == 0) {
1184 found_priv_in_lsa
[j
] = true;
1189 for (j
=0;j
<account
->privilege_entries
; j
++) {
1190 if (!found_priv_in_lsa
[j
]) {
1191 torture_comment(tctx
, "Privilege %s on account %s not found in LSA\n", account
->privilege_name
[j
].string
,
1192 dom_sid_string(mem_ctx
, dom_sid
));
1200 try a netlogon DatabaseSync
1202 static bool test_DatabaseSync(struct torture_context
*tctx
,
1203 struct samsync_state
*samsync_state
,
1204 TALLOC_CTX
*mem_ctx
)
1206 TALLOC_CTX
*loop_ctx
, *delta_ctx
, *trustdom_ctx
;
1207 struct netr_DatabaseSync r
;
1208 const enum netr_SamDatabaseID database_ids
[] = {SAM_DATABASE_DOMAIN
, SAM_DATABASE_BUILTIN
, SAM_DATABASE_PRIVS
};
1211 struct samsync_trusted_domain
*t
;
1212 struct samsync_secret
*s
;
1213 struct netr_Authenticator return_authenticator
, credential
;
1214 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1216 const char *domain
, *username
;
1218 ZERO_STRUCT(return_authenticator
);
1220 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(samsync_state
->p
));
1221 r
.in
.computername
= TEST_MACHINE_NAME
;
1222 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1223 r
.in
.return_authenticator
= &return_authenticator
;
1224 r
.out
.return_authenticator
= &return_authenticator
;
1225 r
.out
.delta_enum_array
= &delta_enum_array
;
1227 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1229 uint32_t sync_context
= 0;
1231 r
.in
.database_id
= database_ids
[i
];
1232 r
.in
.sync_context
= &sync_context
;
1233 r
.out
.sync_context
= &sync_context
;
1235 torture_comment(tctx
, "Testing DatabaseSync of id %d\n", r
.in
.database_id
);
1238 loop_ctx
= talloc_named(mem_ctx
, 0, "DatabaseSync loop context");
1239 netlogon_creds_client_authenticator(samsync_state
->creds
, &credential
);
1241 r
.in
.credential
= &credential
;
1243 torture_assert_ntstatus_ok(tctx
,
1244 dcerpc_netr_DatabaseSync_r(samsync_state
->b
, loop_ctx
, &r
),
1245 "DatabaseSync failed");
1246 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1247 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
1248 torture_comment(tctx
, "DatabaseSync - %s\n", nt_errstr(r
.out
.result
));
1253 if (!netlogon_creds_client_check(samsync_state
->creds
, &r
.out
.return_authenticator
->cred
)) {
1254 torture_comment(tctx
, "Credential chaining failed\n");
1257 r
.in
.sync_context
= r
.out
.sync_context
;
1259 for (d
=0; d
< delta_enum_array
->num_deltas
; d
++) {
1260 delta_ctx
= talloc_named(loop_ctx
, 0, "DatabaseSync delta context");
1262 if (!NT_STATUS_IS_OK(samsync_fix_delta(delta_ctx
, samsync_state
->creds
,
1264 &delta_enum_array
->delta_enum
[d
]))) {
1265 torture_comment(tctx
, "Failed to decrypt delta\n");
1269 switch (delta_enum_array
->delta_enum
[d
].delta_type
) {
1270 case NETR_DELTA_DOMAIN
:
1271 if (!samsync_handle_domain(tctx
, delta_ctx
, samsync_state
,
1272 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1273 torture_comment(tctx
, "Failed to handle DELTA_DOMAIN\n");
1277 case NETR_DELTA_GROUP
:
1278 if (!samsync_handle_group(tctx
, delta_ctx
, samsync_state
,
1279 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1280 torture_comment(tctx
, "Failed to handle DELTA_USER\n");
1284 case NETR_DELTA_USER
:
1285 if (!samsync_handle_user(tctx
, delta_ctx
, samsync_state
,
1286 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1287 torture_comment(tctx
, "Failed to handle DELTA_USER\n");
1291 case NETR_DELTA_ALIAS
:
1292 if (!samsync_handle_alias(tctx
, delta_ctx
, samsync_state
,
1293 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1294 torture_comment(tctx
, "Failed to handle DELTA_ALIAS\n");
1298 case NETR_DELTA_POLICY
:
1299 if (!samsync_handle_policy(tctx
, delta_ctx
, samsync_state
,
1300 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1301 torture_comment(tctx
, "Failed to handle DELTA_POLICY\n");
1305 case NETR_DELTA_TRUSTED_DOMAIN
:
1306 if (!samsync_handle_trusted_domain(tctx
, delta_ctx
, samsync_state
,
1307 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1308 torture_comment(tctx
, "Failed to handle DELTA_TRUSTED_DOMAIN\n");
1312 case NETR_DELTA_ACCOUNT
:
1313 if (!samsync_handle_account(tctx
, delta_ctx
, samsync_state
,
1314 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1315 torture_comment(tctx
, "Failed to handle DELTA_ACCOUNT\n");
1319 case NETR_DELTA_SECRET
:
1320 if (!samsync_handle_secret(tctx
, delta_ctx
, samsync_state
,
1321 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1322 torture_comment(tctx
, "Failed to handle DELTA_SECRET\n");
1326 case NETR_DELTA_GROUP_MEMBER
:
1327 case NETR_DELTA_ALIAS_MEMBER
:
1328 /* These are harder to cross-check, and we expect them */
1330 case NETR_DELTA_DELETE_GROUP
:
1331 case NETR_DELTA_RENAME_GROUP
:
1332 case NETR_DELTA_DELETE_USER
:
1333 case NETR_DELTA_RENAME_USER
:
1334 case NETR_DELTA_DELETE_ALIAS
:
1335 case NETR_DELTA_RENAME_ALIAS
:
1336 case NETR_DELTA_DELETE_TRUST
:
1337 case NETR_DELTA_DELETE_ACCOUNT
:
1338 case NETR_DELTA_DELETE_SECRET
:
1339 case NETR_DELTA_DELETE_GROUP2
:
1340 case NETR_DELTA_DELETE_USER2
:
1341 case NETR_DELTA_MODIFY_COUNT
:
1343 torture_comment(tctx
, "Uxpected delta type %d\n", delta_enum_array
->delta_enum
[d
].delta_type
);
1347 talloc_free(delta_ctx
);
1349 talloc_free(loop_ctx
);
1350 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1354 domain
= samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
];
1356 torture_comment(tctx
, "Never got a DOMAIN object in samsync!\n");
1360 trustdom_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseSync Trusted domains context");
1362 username
= talloc_asprintf(trustdom_ctx
, "%s$", domain
);
1363 for (t
=samsync_state
->trusted_domains
; t
; t
=t
->next
) {
1364 char *secret_name
= talloc_asprintf(trustdom_ctx
, "G$$%s", t
->name
);
1365 for (s
=samsync_state
->secrets
; s
; s
=s
->next
) {
1366 if (strcasecmp_m(s
->name
, secret_name
) == 0) {
1368 struct samr_Password nt_hash
;
1369 mdfour(nt_hash
.hash
, s
->secret
.data
, s
->secret
.length
);
1371 torture_comment(tctx
, "Checking password for %s\\%s\n", t
->name
, username
);
1372 nt_status
= test_SamLogon(tctx
,
1373 samsync_state
->p_netlogon_wksta
, trustdom_ctx
, samsync_state
->creds_netlogon_wksta
,
1376 TEST_WKSTA_MACHINE_NAME
,
1380 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_LOGON_SERVERS
)) {
1381 torture_comment(tctx
, "Verifiction of trust password to %s failed: %s (the trusted domain is not available)\n",
1382 t
->name
, nt_errstr(nt_status
));
1386 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
1387 torture_comment(tctx
, "Verifiction of trust password to %s: should have failed (nologon interdomain trust account), instead: %s\n",
1388 t
->name
, nt_errstr(nt_status
));
1394 nt_status
= test_SamLogon(tctx
,
1395 samsync_state
->p_netlogon_wksta
, trustdom_ctx
, samsync_state
->creds_netlogon_wksta
,
1398 TEST_WKSTA_MACHINE_NAME
,
1403 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
)) {
1404 torture_comment(tctx
, "Verifiction of trust password to %s: should have failed (wrong password), instead: %s\n",
1405 t
->name
, nt_errstr(nt_status
));
1413 talloc_free(trustdom_ctx
);
1419 try a netlogon DatabaseDeltas
1421 static bool test_DatabaseDeltas(struct torture_context
*tctx
,
1422 struct samsync_state
*samsync_state
, TALLOC_CTX
*mem_ctx
)
1424 TALLOC_CTX
*loop_ctx
;
1425 struct netr_DatabaseDeltas r
;
1426 struct netr_Authenticator credential
;
1427 struct netr_Authenticator return_authenticator
;
1428 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1429 const uint32_t database_ids
[] = {0, 1, 2};
1433 ZERO_STRUCT(return_authenticator
);
1435 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(samsync_state
->p
));
1436 r
.in
.computername
= TEST_MACHINE_NAME
;
1437 r
.in
.credential
= &credential
;
1438 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1439 r
.in
.return_authenticator
= &return_authenticator
;
1440 r
.out
.return_authenticator
= &return_authenticator
;
1441 r
.out
.delta_enum_array
= &delta_enum_array
;
1443 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1445 uint64_t seq_num
= samsync_state
->seq_num
[i
];
1447 r
.in
.database_id
= database_ids
[i
];
1448 r
.in
.sequence_num
= &seq_num
;
1449 r
.out
.sequence_num
= &seq_num
;
1451 if (seq_num
== 0) continue;
1453 /* this shows that the bdc doesn't need to do a single call for
1454 * each seqnumber, and the pdc doesn't need to know about old values
1459 torture_comment(tctx
, "Testing DatabaseDeltas of id %d at %llu\n",
1460 r
.in
.database_id
, (long long)seq_num
);
1463 loop_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseDeltas loop context");
1464 netlogon_creds_client_authenticator(samsync_state
->creds
, &credential
);
1466 torture_assert_ntstatus_ok(tctx
,
1467 dcerpc_netr_DatabaseDeltas_r(samsync_state
->b
, loop_ctx
, &r
),
1468 "DatabaseDeltas failed");
1469 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1470 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) &&
1471 !NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_SYNCHRONIZATION_REQUIRED
)) {
1472 torture_comment(tctx
, "DatabaseDeltas - %s\n", nt_errstr(r
.out
.result
));
1476 if (!netlogon_creds_client_check(samsync_state
->creds
, &return_authenticator
.cred
)) {
1477 torture_comment(tctx
, "Credential chaining failed\n");
1481 talloc_free(loop_ctx
);
1482 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1490 try a netlogon DatabaseSync2
1492 static bool test_DatabaseSync2(struct torture_context
*tctx
,
1493 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1494 struct netlogon_creds_CredentialState
*creds
)
1496 TALLOC_CTX
*loop_ctx
;
1497 struct netr_DatabaseSync2 r
;
1498 const uint32_t database_ids
[] = {0, 1, 2};
1501 struct netr_Authenticator return_authenticator
, credential
;
1502 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1503 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1505 ZERO_STRUCT(return_authenticator
);
1507 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
1508 r
.in
.computername
= TEST_MACHINE_NAME
;
1509 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1510 r
.in
.return_authenticator
= &return_authenticator
;
1511 r
.out
.return_authenticator
= &return_authenticator
;
1512 r
.out
.delta_enum_array
= &delta_enum_array
;
1514 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1516 uint32_t sync_context
= 0;
1518 r
.in
.database_id
= database_ids
[i
];
1519 r
.in
.sync_context
= &sync_context
;
1520 r
.out
.sync_context
= &sync_context
;
1521 r
.in
.restart_state
= 0;
1523 torture_comment(tctx
, "Testing DatabaseSync2 of id %d\n", r
.in
.database_id
);
1526 loop_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseSync2 loop context");
1527 netlogon_creds_client_authenticator(creds
, &credential
);
1529 r
.in
.credential
= &credential
;
1531 torture_assert_ntstatus_ok(tctx
,
1532 dcerpc_netr_DatabaseSync2_r(b
, loop_ctx
, &r
),
1533 "DatabaseSync2 failed");
1534 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1535 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
1536 torture_comment(tctx
, "DatabaseSync2 - %s\n", nt_errstr(r
.out
.result
));
1540 if (!netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
)) {
1541 torture_comment(tctx
, "Credential chaining failed\n");
1544 talloc_free(loop_ctx
);
1545 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1553 bool torture_rpc_samsync(struct torture_context
*torture
)
1556 TALLOC_CTX
*mem_ctx
;
1558 struct test_join
*join_ctx
;
1559 struct test_join
*join_ctx2
;
1560 struct test_join
*user_ctx
;
1561 const char *machine_password
;
1562 const char *wksta_machine_password
;
1563 struct dcerpc_binding
*b
;
1564 struct dcerpc_binding
*b_netlogon_wksta
;
1565 struct samr_Connect c
;
1566 struct samr_SetDomainInfo s
;
1567 struct policy_handle
*domain_policy
;
1569 struct lsa_ObjectAttribute attr
;
1570 struct lsa_QosInfo qos
;
1571 struct lsa_OpenPolicy2 r
;
1572 struct cli_credentials
*credentials
;
1573 struct cli_credentials
*credentials_wksta
;
1575 struct samsync_state
*samsync_state
;
1577 char *test_machine_account
;
1579 char *test_wksta_machine_account
;
1581 mem_ctx
= talloc_init("torture_rpc_netlogon");
1583 test_machine_account
= talloc_asprintf(mem_ctx
, "%s$", TEST_MACHINE_NAME
);
1584 join_ctx
= torture_create_testuser(torture
, test_machine_account
,
1585 lpcfg_workgroup(torture
->lp_ctx
), ACB_SVRTRUST
,
1588 talloc_free(mem_ctx
);
1589 torture_comment(torture
, "Failed to join as BDC\n");
1593 test_wksta_machine_account
= talloc_asprintf(mem_ctx
, "%s$", TEST_WKSTA_MACHINE_NAME
);
1594 join_ctx2
= torture_create_testuser(torture
, test_wksta_machine_account
, lpcfg_workgroup(torture
->lp_ctx
), ACB_WSTRUST
, &wksta_machine_password
);
1596 talloc_free(mem_ctx
);
1597 torture_comment(torture
, "Failed to join as member\n");
1601 user_ctx
= torture_create_testuser(torture
, TEST_USER_NAME
,
1602 lpcfg_workgroup(torture
->lp_ctx
),
1605 talloc_free(mem_ctx
);
1606 torture_comment(torture
, "Failed to create test account\n");
1610 samsync_state
= talloc_zero(mem_ctx
, struct samsync_state
);
1612 samsync_state
->p_samr
= torture_join_samr_pipe(join_ctx
);
1613 samsync_state
->b_samr
= samsync_state
->p_samr
->binding_handle
;
1614 samsync_state
->connect_handle
= talloc_zero(samsync_state
, struct policy_handle
);
1615 samsync_state
->lsa_handle
= talloc_zero(samsync_state
, struct policy_handle
);
1616 c
.in
.system_name
= NULL
;
1617 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1618 c
.out
.connect_handle
= samsync_state
->connect_handle
;
1620 torture_assert_ntstatus_ok_goto(torture
,
1621 dcerpc_samr_Connect_r(samsync_state
->b_samr
, mem_ctx
, &c
),
1623 "samr_Connect failed");
1624 torture_assert_ntstatus_ok_goto(torture
, c
.out
.result
,
1626 "samr_Connect failed");
1628 domain_policy
= samsync_open_domain(torture
, mem_ctx
, samsync_state
, lpcfg_workgroup(torture
->lp_ctx
), NULL
);
1629 if (!domain_policy
) {
1630 torture_comment(torture
, "samrsync_open_domain failed\n");
1635 s
.in
.domain_handle
= domain_policy
;
1637 s
.in
.info
= talloc(mem_ctx
, union samr_DomainInfo
);
1639 s
.in
.info
->oem
.oem_information
.string
1640 = talloc_asprintf(mem_ctx
,
1641 "Tortured by Samba4: %s",
1642 timestring(mem_ctx
, time(NULL
)));
1643 torture_assert_ntstatus_ok_goto(torture
,
1644 dcerpc_samr_SetDomainInfo_r(samsync_state
->b_samr
, mem_ctx
, &s
),
1646 "SetDomainInfo failed");
1648 if (!test_samr_handle_Close(samsync_state
->b_samr
, torture
, domain_policy
)) {
1653 torture_assert_ntstatus_ok_goto(torture
, s
.out
.result
,
1655 talloc_asprintf(torture
, "SetDomainInfo level %u failed", s
.in
.level
));
1657 status
= torture_rpc_connection(torture
,
1658 &samsync_state
->p_lsa
,
1661 if (!NT_STATUS_IS_OK(status
)) {
1665 samsync_state
->b_lsa
= samsync_state
->p_lsa
->binding_handle
;
1668 qos
.impersonation_level
= 2;
1669 qos
.context_mode
= 1;
1670 qos
.effective_only
= 0;
1673 attr
.root_dir
= NULL
;
1674 attr
.object_name
= NULL
;
1675 attr
.attributes
= 0;
1676 attr
.sec_desc
= NULL
;
1677 attr
.sec_qos
= &qos
;
1679 r
.in
.system_name
= "\\";
1681 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1682 r
.out
.handle
= samsync_state
->lsa_handle
;
1684 torture_assert_ntstatus_ok_goto(torture
,
1685 dcerpc_lsa_OpenPolicy2_r(samsync_state
->b_lsa
, mem_ctx
, &r
),
1687 "OpenPolicy2 failed");
1688 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
,
1690 "OpenPolicy2 failed");
1692 status
= torture_rpc_binding(torture
, &b
);
1693 if (!NT_STATUS_IS_OK(status
)) {
1698 b
->flags
&= ~DCERPC_AUTH_OPTIONS
;
1699 b
->flags
|= DCERPC_SCHANNEL
| DCERPC_SIGN
;
1701 credentials
= cli_credentials_init(mem_ctx
);
1703 cli_credentials_set_workstation(credentials
, TEST_MACHINE_NAME
, CRED_SPECIFIED
);
1704 cli_credentials_set_domain(credentials
, lpcfg_workgroup(torture
->lp_ctx
), CRED_SPECIFIED
);
1705 cli_credentials_set_username(credentials
, test_machine_account
, CRED_SPECIFIED
);
1706 cli_credentials_set_password(credentials
, machine_password
, CRED_SPECIFIED
);
1707 cli_credentials_set_secure_channel_type(credentials
,
1710 status
= dcerpc_pipe_connect_b(samsync_state
,
1711 &samsync_state
->p
, b
,
1712 &ndr_table_netlogon
,
1713 credentials
, torture
->ev
, torture
->lp_ctx
);
1715 if (!NT_STATUS_IS_OK(status
)) {
1716 torture_comment(torture
, "Failed to connect to server as a BDC: %s\n", nt_errstr(status
));
1720 samsync_state
->b
= samsync_state
->p
->binding_handle
;
1722 samsync_state
->creds
= cli_credentials_get_netlogon_creds(credentials
);
1723 if (samsync_state
->creds
== NULL
) {
1729 status
= torture_rpc_binding(torture
, &b_netlogon_wksta
);
1730 if (!NT_STATUS_IS_OK(status
)) {
1735 b_netlogon_wksta
->flags
&= ~DCERPC_AUTH_OPTIONS
;
1736 b_netlogon_wksta
->flags
|= DCERPC_SCHANNEL
| DCERPC_SIGN
;
1738 credentials_wksta
= cli_credentials_init(mem_ctx
);
1740 cli_credentials_set_workstation(credentials_wksta
, TEST_WKSTA_MACHINE_NAME
, CRED_SPECIFIED
);
1741 cli_credentials_set_domain(credentials_wksta
, lpcfg_workgroup(torture
->lp_ctx
), CRED_SPECIFIED
);
1742 cli_credentials_set_username(credentials_wksta
, test_wksta_machine_account
, CRED_SPECIFIED
);
1743 cli_credentials_set_password(credentials_wksta
, wksta_machine_password
, CRED_SPECIFIED
);
1744 cli_credentials_set_secure_channel_type(credentials_wksta
,
1747 status
= dcerpc_pipe_connect_b(samsync_state
,
1748 &samsync_state
->p_netlogon_wksta
,
1750 &ndr_table_netlogon
,
1751 credentials_wksta
, torture
->ev
, torture
->lp_ctx
);
1753 if (!NT_STATUS_IS_OK(status
)) {
1754 torture_comment(torture
, "Failed to connect to server as a Workstation: %s\n", nt_errstr(status
));
1759 samsync_state
->creds_netlogon_wksta
= cli_credentials_get_netlogon_creds(credentials_wksta
);
1760 if (samsync_state
->creds_netlogon_wksta
== NULL
) {
1761 torture_comment(torture
, "Failed to obtail schanel creds!\n");
1765 if (!test_DatabaseSync(torture
, samsync_state
, mem_ctx
)) {
1766 torture_comment(torture
, "DatabaseSync failed\n");
1770 if (!test_DatabaseDeltas(torture
, samsync_state
, mem_ctx
)) {
1771 torture_comment(torture
, "DatabaseDeltas failed\n");
1775 if (!test_DatabaseSync2(torture
, samsync_state
->p
, mem_ctx
, samsync_state
->creds
)) {
1776 torture_comment(torture
, "DatabaseSync2 failed\n");
1781 torture_leave_domain(torture
, join_ctx
);
1782 torture_leave_domain(torture
, join_ctx2
);
1783 torture_leave_domain(torture
, user_ctx
);
1785 talloc_free(mem_ctx
);