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 "auth/gensec/schannel.h"
31 #include "libcli/auth/libcli_auth.h"
32 #include "libcli/samsync/samsync.h"
33 #include "libcli/security/security.h"
34 #include "librpc/gen_ndr/ndr_netlogon.h"
35 #include "librpc/gen_ndr/ndr_netlogon_c.h"
36 #include "librpc/gen_ndr/ndr_lsa_c.h"
37 #include "librpc/gen_ndr/ndr_samr_c.h"
38 #include "librpc/gen_ndr/ndr_security.h"
39 #include "param/param.h"
41 #define TEST_MACHINE_NAME "samsynctest"
42 #define TEST_WKSTA_MACHINE_NAME "samsynctest2"
43 #define TEST_USER_NAME "samsynctestuser"
46 try a netlogon SamLogon
48 static NTSTATUS
test_SamLogon(struct torture_context
*tctx
,
49 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
50 struct netlogon_creds_CredentialState
*creds
,
51 const char *domain
, const char *account_name
,
52 const char *workstation
,
53 struct samr_Password
*lm_hash
,
54 struct samr_Password
*nt_hash
,
55 struct netr_SamInfo3
**info3
)
58 struct netr_LogonSamLogon r
;
59 struct netr_Authenticator auth
, auth2
;
60 struct netr_NetworkInfo ninfo
;
61 union netr_LogonLevel logon
;
62 union netr_Validation validation
;
63 uint8_t authoritative
;
64 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
66 ninfo
.identity_info
.domain_name
.string
= domain
;
67 ninfo
.identity_info
.parameter_control
= 0;
68 ninfo
.identity_info
.logon_id_low
= 0;
69 ninfo
.identity_info
.logon_id_high
= 0;
70 ninfo
.identity_info
.account_name
.string
= account_name
;
71 ninfo
.identity_info
.workstation
.string
= workstation
;
72 generate_random_buffer(ninfo
.challenge
,
73 sizeof(ninfo
.challenge
));
76 ninfo
.nt
.data
= talloc_array(mem_ctx
, uint8_t, 24);
77 SMBOWFencrypt(nt_hash
->hash
, ninfo
.challenge
, ninfo
.nt
.data
);
85 ninfo
.lm
.data
= talloc_array(mem_ctx
, uint8_t, 24);
86 SMBOWFencrypt(lm_hash
->hash
, ninfo
.challenge
, ninfo
.lm
.data
);
92 logon
.network
= &ninfo
;
94 r
.in
.server_name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
95 r
.in
.computer_name
= workstation
;
96 r
.in
.credential
= &auth
;
97 r
.in
.return_authenticator
= &auth2
;
98 r
.in
.logon_level
= NetlogonNetworkInformation
;
100 r
.out
.validation
= &validation
;
101 r
.out
.authoritative
= &authoritative
;
104 netlogon_creds_client_authenticator(creds
, &auth
);
106 r
.in
.validation_level
= 3;
108 status
= dcerpc_netr_LogonSamLogon_r(b
, mem_ctx
, &r
);
109 if (!NT_STATUS_IS_OK(status
)) {
113 if (!netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
)) {
114 torture_comment(tctx
, "Credential chaining failed\n");
118 *info3
= validation
.sam3
;
124 struct samsync_state
{
125 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
127 const char *domain_name
[2];
128 struct samsync_secret
*secrets
;
129 struct samsync_trusted_domain
*trusted_domains
;
130 struct netlogon_creds_CredentialState
*creds
;
131 struct netlogon_creds_CredentialState
*creds_netlogon_wksta
;
132 struct policy_handle
*connect_handle
;
133 struct policy_handle
*domain_handle
[2];
134 struct dom_sid
*sid
[2];
135 struct dcerpc_pipe
*p
;
136 struct dcerpc_binding_handle
*b
;
137 struct dcerpc_pipe
*p_netlogon_wksta
;
138 struct dcerpc_pipe
*p_samr
;
139 struct dcerpc_binding_handle
*b_samr
;
140 struct dcerpc_pipe
*p_lsa
;
141 struct dcerpc_binding_handle
*b_lsa
;
142 struct policy_handle
*lsa_handle
;
145 struct samsync_secret
{
146 struct samsync_secret
*prev
, *next
;
152 struct samsync_trusted_domain
{
153 struct samsync_trusted_domain
*prev
, *next
;
158 static struct policy_handle
*samsync_open_domain(struct torture_context
*tctx
,
160 struct samsync_state
*samsync_state
,
162 struct dom_sid
**sid_p
)
164 struct lsa_String name
;
165 struct samr_OpenDomain o
;
166 struct samr_LookupDomain l
;
167 struct dom_sid2
*sid
= NULL
;
168 struct policy_handle
*domain_handle
= talloc(mem_ctx
, struct policy_handle
);
171 name
.string
= domain
;
172 l
.in
.connect_handle
= samsync_state
->connect_handle
;
173 l
.in
.domain_name
= &name
;
176 nt_status
= dcerpc_samr_LookupDomain_r(samsync_state
->b_samr
, mem_ctx
, &l
);
177 if (!NT_STATUS_IS_OK(nt_status
)) {
178 torture_comment(tctx
, "LookupDomain failed - %s\n", nt_errstr(nt_status
));
181 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
182 torture_comment(tctx
, "LookupDomain failed - %s\n", nt_errstr(l
.out
.result
));
186 o
.in
.connect_handle
= samsync_state
->connect_handle
;
187 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
188 o
.in
.sid
= *l
.out
.sid
;
189 o
.out
.domain_handle
= domain_handle
;
195 nt_status
= dcerpc_samr_OpenDomain_r(samsync_state
->b_samr
, mem_ctx
, &o
);
196 if (!NT_STATUS_IS_OK(nt_status
)) {
197 torture_comment(tctx
, "OpenDomain failed - %s\n", nt_errstr(nt_status
));
200 if (!NT_STATUS_IS_OK(o
.out
.result
)) {
201 torture_comment(tctx
, "OpenDomain failed - %s\n", nt_errstr(o
.out
.result
));
205 return domain_handle
;
208 static struct sec_desc_buf
*samsync_query_samr_sec_desc(struct torture_context
*tctx
,
210 struct samsync_state
*samsync_state
,
211 struct policy_handle
*handle
)
213 struct samr_QuerySecurity r
;
214 struct sec_desc_buf
*sdbuf
= NULL
;
217 r
.in
.handle
= handle
;
219 r
.out
.sdbuf
= &sdbuf
;
221 status
= dcerpc_samr_QuerySecurity_r(samsync_state
->b_samr
, mem_ctx
, &r
);
222 if (!NT_STATUS_IS_OK(status
)) {
223 torture_comment(tctx
, "SAMR QuerySecurity failed - %s\n", nt_errstr(status
));
226 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
227 torture_comment(tctx
, "SAMR QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
234 static struct sec_desc_buf
*samsync_query_lsa_sec_desc(struct torture_context
*tctx
,
236 struct samsync_state
*samsync_state
,
237 struct policy_handle
*handle
)
239 struct lsa_QuerySecurity r
;
240 struct sec_desc_buf
*sdbuf
= NULL
;
243 r
.in
.handle
= handle
;
245 r
.out
.sdbuf
= &sdbuf
;
247 status
= dcerpc_lsa_QuerySecurity_r(samsync_state
->b_lsa
, mem_ctx
, &r
);
248 if (!NT_STATUS_IS_OK(status
)) {
249 torture_comment(tctx
, "LSA QuerySecurity failed - %s\n", nt_errstr(status
));
252 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
253 torture_comment(tctx
, "LSA QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
260 #define TEST_UINT64_EQUAL(i1, i2) do {\
262 torture_comment(tctx, "%s: uint64 mismatch: " #i1 ": 0x%016llx (%lld) != " #i2 ": 0x%016llx (%lld)\n", \
264 (long long)i1, (long long)i1, \
265 (long long)i2, (long long)i2);\
269 #define TEST_INT_EQUAL(i1, i2) do {\
271 torture_comment(tctx, "%s: integer mismatch: " #i1 ": 0x%08x (%d) != " #i2 ": 0x%08x (%d)\n", \
272 __location__, i1, i1, i2, i2); \
276 #define TEST_TIME_EQUAL(t1, t2) do {\
278 torture_comment(tctx, "%s: NTTIME mismatch: " #t1 ":%s != " #t2 ": %s\n", \
279 __location__, nt_time_string(mem_ctx, t1), nt_time_string(mem_ctx, t2));\
284 #define TEST_STRING_EQUAL(s1, s2) do {\
285 if (!((!s1.string || s1.string[0]=='\0') && (!s2.string || s2.string[0]=='\0')) \
286 && strcmp_safe(s1.string, s2.string) != 0) {\
287 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
288 __location__, s1.string, s2.string);\
293 #define TEST_BINARY_STRING_EQUAL(s1, s2) do {\
294 if (!((!s1.array || s1.array[0]=='\0') && (!s2.array || s2.array[0]=='\0')) \
295 && memcmp(s1.array, s2.array, s1.length * 2) != 0) {\
296 torture_comment(tctx, "%s: string mismatch: " #s1 ":%s != " #s2 ": %s\n", \
297 __location__, (const char *)s1.array, (const char *)s2.array);\
302 #define TEST_SID_EQUAL(s1, s2) do {\
303 if (!dom_sid_equal(s1, s2)) {\
304 torture_comment(tctx, "%s: dom_sid mismatch: " #s1 ":%s != " #s2 ": %s\n", \
305 __location__, dom_sid_string(mem_ctx, s1), dom_sid_string(mem_ctx, s2));\
310 /* The ~SEC_DESC_SACL_PRESENT is because we don't, as administrator,
311 * get back the SACL part of the SD when we ask over SAMR */
313 #define TEST_SEC_DESC_EQUAL(sd1, pipe, handle) do {\
314 struct sec_desc_buf *sdbuf = samsync_query_ ##pipe## _sec_desc(tctx, mem_ctx, samsync_state, \
316 if (!sdbuf || !sdbuf->sd) { \
317 torture_comment(tctx, "Could not obtain security descriptor to match " #sd1 "\n");\
320 if (!security_descriptor_mask_equal(sd1.sd, sdbuf->sd, \
321 ~SEC_DESC_SACL_PRESENT)) {\
322 torture_comment(tctx, "Security Descriptor Mismatch for %s:\n", #sd1);\
323 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamSync", sd1.sd);\
324 ndr_print_debug((ndr_print_fn_t)ndr_print_security_descriptor, "SamR", sdbuf->sd);\
330 static bool samsync_handle_domain(struct torture_context
*tctx
, TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
331 int database_id
, struct netr_DELTA_ENUM
*delta
)
333 struct netr_DELTA_DOMAIN
*domain
= delta
->delta_union
.domain
;
334 struct dom_sid
*dom_sid
;
335 struct samr_QueryDomainInfo q
[14]; /* q[0] will be unused simple for clarity */
336 union samr_DomainInfo
*info
[14];
337 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
341 samsync_state
->seq_num
[database_id
] =
342 domain
->sequence_num
;
343 switch (database_id
) {
344 case SAM_DATABASE_DOMAIN
:
346 case SAM_DATABASE_BUILTIN
:
347 if (strcasecmp_m("BUILTIN", domain
->domain_name
.string
) != 0) {
348 torture_comment(tctx
, "BUILTIN domain has different name: %s\n", domain
->domain_name
.string
);
351 case SAM_DATABASE_PRIVS
:
352 torture_comment(tctx
, "DOMAIN entry on privs DB!\n");
357 if (!samsync_state
->domain_name
[database_id
]) {
358 samsync_state
->domain_name
[database_id
] =
359 talloc_reference(samsync_state
, domain
->domain_name
.string
);
361 if (strcasecmp_m(samsync_state
->domain_name
[database_id
], domain
->domain_name
.string
) != 0) {
362 torture_comment(tctx
, "Domain has name varies!: %s != %s\n", samsync_state
->domain_name
[database_id
],
363 domain
->domain_name
.string
);
368 if (!samsync_state
->domain_handle
[database_id
]) {
369 samsync_state
->domain_handle
[database_id
]
370 = talloc_reference(samsync_state
,
371 samsync_open_domain(tctx
,
372 mem_ctx
, samsync_state
, samsync_state
->domain_name
[database_id
],
375 if (samsync_state
->domain_handle
[database_id
]) {
376 samsync_state
->sid
[database_id
] = talloc_reference(samsync_state
, dom_sid
);
379 torture_comment(tctx
, "\tsequence_nums[%d/%s]=%llu\n",
380 database_id
, domain
->domain_name
.string
,
381 (long long)samsync_state
->seq_num
[database_id
]);
383 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
385 q
[levels
[i
]].in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
386 q
[levels
[i
]].in
.level
= levels
[i
];
387 q
[levels
[i
]].out
.info
= &info
[levels
[i
]];
389 torture_assert_ntstatus_ok(tctx
,
390 dcerpc_samr_QueryDomainInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
[levels
[i
]]),
391 talloc_asprintf(tctx
, "QueryDomainInfo level %u failed", q
[levels
[i
]].in
.level
));
392 torture_assert_ntstatus_ok(tctx
, q
[levels
[i
]].out
.result
,
393 talloc_asprintf(tctx
, "QueryDomainInfo level %u failed", q
[levels
[i
]].in
.level
));
396 TEST_STRING_EQUAL(info
[5]->info5
.domain_name
, domain
->domain_name
);
398 TEST_STRING_EQUAL(info
[2]->general
.oem_information
, domain
->oem_information
);
399 TEST_STRING_EQUAL(info
[4]->oem
.oem_information
, domain
->oem_information
);
400 TEST_TIME_EQUAL(info
[2]->general
.force_logoff_time
, domain
->force_logoff_time
);
401 TEST_TIME_EQUAL(info
[3]->info3
.force_logoff_time
, domain
->force_logoff_time
);
403 TEST_TIME_EQUAL(info
[1]->info1
.min_password_length
, domain
->min_password_length
);
404 TEST_TIME_EQUAL(info
[1]->info1
.password_history_length
, domain
->password_history_length
);
405 TEST_TIME_EQUAL(info
[1]->info1
.max_password_age
, domain
->max_password_age
);
406 TEST_TIME_EQUAL(info
[1]->info1
.min_password_age
, domain
->min_password_age
);
408 TEST_UINT64_EQUAL(info
[8]->info8
.sequence_num
,
409 domain
->sequence_num
);
410 TEST_TIME_EQUAL(info
[8]->info8
.domain_create_time
,
411 domain
->domain_create_time
);
412 TEST_TIME_EQUAL(info
[13]->info13
.domain_create_time
,
413 domain
->domain_create_time
);
415 TEST_SEC_DESC_EQUAL(domain
->sdbuf
, samr
, samsync_state
->domain_handle
[database_id
]);
420 static bool samsync_handle_policy(struct torture_context
*tctx
,
421 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
422 int database_id
, struct netr_DELTA_ENUM
*delta
)
424 struct netr_DELTA_POLICY
*policy
= delta
->delta_union
.policy
;
426 samsync_state
->seq_num
[database_id
] =
427 policy
->sequence_num
;
429 if (!samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
]) {
430 samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
] =
431 talloc_reference(samsync_state
, policy
->primary_domain_name
.string
);
433 if (strcasecmp_m(samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
], policy
->primary_domain_name
.string
) != 0) {
434 torture_comment(tctx
, "PRIMARY domain has name varies between DOMAIN and POLICY!: %s != %s\n", samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
],
435 policy
->primary_domain_name
.string
);
440 if (!dom_sid_equal(samsync_state
->sid
[SAM_DATABASE_DOMAIN
], policy
->sid
)) {
441 torture_comment(tctx
, "Domain SID from POLICY (%s) does not match domain sid from SAMR (%s)\n",
442 dom_sid_string(mem_ctx
, policy
->sid
), dom_sid_string(mem_ctx
, samsync_state
->sid
[SAM_DATABASE_DOMAIN
]));
446 torture_comment(tctx
, "\tsequence_nums[%d/PRIVS]=%llu\n",
448 (long long)samsync_state
->seq_num
[database_id
]);
452 static bool samsync_handle_user(struct torture_context
*tctx
, TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
453 int database_id
, struct netr_DELTA_ENUM
*delta
)
455 uint32_t rid
= delta
->delta_id_union
.rid
;
456 struct netr_DELTA_USER
*user
= delta
->delta_union
.user
;
457 struct netr_SamInfo3
*info3
;
458 struct samr_Password lm_hash
;
459 struct samr_Password nt_hash
;
460 struct samr_Password
*lm_hash_p
= NULL
;
461 struct samr_Password
*nt_hash_p
= NULL
;
462 const char *domain
= samsync_state
->domain_name
[database_id
];
463 const char *username
= user
->account_name
.string
;
467 struct samr_OpenUser r
;
468 struct samr_QueryUserInfo q
;
469 union samr_UserInfo
*info
;
470 struct policy_handle user_handle
;
472 struct samr_GetGroupsForUser getgroups
;
473 struct samr_RidWithAttributeArray
*rids
;
475 if (!samsync_state
->domain_name
|| !samsync_state
->domain_handle
[database_id
]) {
476 torture_comment(tctx
, "SamSync needs domain information before the users\n");
480 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
481 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
483 r
.out
.user_handle
= &user_handle
;
485 torture_assert_ntstatus_ok(tctx
,
486 dcerpc_samr_OpenUser_r(samsync_state
->b_samr
, mem_ctx
, &r
),
487 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
488 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
489 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
491 q
.in
.user_handle
= &user_handle
;
495 TEST_SEC_DESC_EQUAL(user
->sdbuf
, samr
, &user_handle
);
497 torture_assert_ntstatus_ok(tctx
,
498 dcerpc_samr_QueryUserInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
499 talloc_asprintf(tctx
, "OpenUserInfo level %u failed", q
.in
.level
));
500 torture_assert_ntstatus_ok(tctx
, q
.out
.result
,
501 talloc_asprintf(tctx
, "OpenUserInfo level %u failed", q
.in
.level
));
503 getgroups
.in
.user_handle
= &user_handle
;
504 getgroups
.out
.rids
= &rids
;
506 torture_assert_ntstatus_ok(tctx
,
507 dcerpc_samr_GetGroupsForUser_r(samsync_state
->b_samr
, mem_ctx
, &getgroups
),
508 "GetGroupsForUser failed");
509 torture_assert_ntstatus_ok(tctx
, getgroups
.out
.result
,
510 "GetGroupsForUser failed");
512 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &user_handle
)) {
513 torture_comment(tctx
, "samr_handle_Close failed\n");
520 TEST_STRING_EQUAL(info
->info21
.account_name
, user
->account_name
);
521 TEST_STRING_EQUAL(info
->info21
.full_name
, user
->full_name
);
522 TEST_INT_EQUAL(info
->info21
.rid
, user
->rid
);
523 TEST_INT_EQUAL(info
->info21
.primary_gid
, user
->primary_gid
);
524 TEST_STRING_EQUAL(info
->info21
.home_directory
, user
->home_directory
);
525 TEST_STRING_EQUAL(info
->info21
.home_drive
, user
->home_drive
);
526 TEST_STRING_EQUAL(info
->info21
.logon_script
, user
->logon_script
);
527 TEST_STRING_EQUAL(info
->info21
.description
, user
->description
);
528 TEST_STRING_EQUAL(info
->info21
.workstations
, user
->workstations
);
530 TEST_TIME_EQUAL(info
->info21
.last_logon
, user
->last_logon
);
531 TEST_TIME_EQUAL(info
->info21
.last_logoff
, user
->last_logoff
);
534 TEST_INT_EQUAL(info
->info21
.logon_hours
.units_per_week
,
535 user
->logon_hours
.units_per_week
);
537 if (memcmp(info
->info21
.logon_hours
.bits
, user
->logon_hours
.bits
,
538 info
->info21
.logon_hours
.units_per_week
/8) != 0) {
539 torture_comment(tctx
, "Logon hours mismatch\n");
544 TEST_INT_EQUAL(info
->info21
.bad_password_count
,
545 user
->bad_password_count
);
546 TEST_INT_EQUAL(info
->info21
.logon_count
,
549 TEST_TIME_EQUAL(info
->info21
.last_password_change
,
550 user
->last_password_change
);
551 TEST_TIME_EQUAL(info
->info21
.acct_expiry
,
554 TEST_INT_EQUAL((info
->info21
.acct_flags
& ~ACB_PW_EXPIRED
), user
->acct_flags
);
555 if (user
->acct_flags
& ACB_PWNOEXP
) {
556 if (info
->info21
.acct_flags
& ACB_PW_EXPIRED
) {
557 torture_comment(tctx
, "ACB flags mismatch: both expired and no expiry!\n");
560 if (info
->info21
.force_password_change
!= (NTTIME
)0x7FFFFFFFFFFFFFFFULL
) {
561 torture_comment(tctx
, "ACB flags mismatch: no password expiry, but force password change 0x%016llx (%lld) != 0x%016llx (%lld)\n",
562 (unsigned long long)info
->info21
.force_password_change
,
563 (unsigned long long)info
->info21
.force_password_change
,
564 (unsigned long long)0x7FFFFFFFFFFFFFFFULL
, (unsigned long long)0x7FFFFFFFFFFFFFFFULL
570 TEST_INT_EQUAL(info
->info21
.nt_password_set
, user
->nt_password_present
);
571 TEST_INT_EQUAL(info
->info21
.lm_password_set
, user
->lm_password_present
);
572 TEST_INT_EQUAL(info
->info21
.password_expired
, user
->password_expired
);
574 TEST_STRING_EQUAL(info
->info21
.comment
, user
->comment
);
575 TEST_BINARY_STRING_EQUAL(info
->info21
.parameters
, user
->parameters
);
577 TEST_INT_EQUAL(info
->info21
.country_code
, user
->country_code
);
578 TEST_INT_EQUAL(info
->info21
.code_page
, user
->code_page
);
580 TEST_STRING_EQUAL(info
->info21
.profile_path
, user
->profile_path
);
582 if (user
->lm_password_present
) {
583 lm_hash_p
= &lm_hash
;
585 if (user
->nt_password_present
) {
586 nt_hash_p
= &nt_hash
;
589 if (user
->user_private_info
.SensitiveData
) {
591 struct netr_USER_KEYS keys
;
592 enum ndr_err_code ndr_err
;
593 data
.data
= user
->user_private_info
.SensitiveData
;
594 data
.length
= user
->user_private_info
.DataLength
;
595 ndr_err
= ndr_pull_struct_blob(&data
, mem_ctx
, &keys
, (ndr_pull_flags_fn_t
)ndr_pull_netr_USER_KEYS
);
596 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
597 if (keys
.keys
.keys2
.lmpassword
.length
== 16) {
598 lm_hash_p
= &lm_hash
;
600 if (keys
.keys
.keys2
.ntpassword
.length
== 16) {
601 nt_hash_p
= &nt_hash
;
604 torture_comment(tctx
, "Failed to parse Sensitive Data for %s:\n", username
);
606 dump_data(0, data
.data
, data
.length
);
613 DATA_BLOB nt_hash_blob
= data_blob_const(nt_hash_p
, 16);
614 DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state
->domain_name
[0], username
, data_blob_hex_string_upper(mem_ctx
, &nt_hash_blob
)));
617 DATA_BLOB lm_hash_blob
= data_blob_const(lm_hash_p
, 16);
618 DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state
->domain_name
[0], username
, data_blob_hex_string_upper(mem_ctx
, &lm_hash_blob
)));
621 nt_status
= test_SamLogon(tctx
,
622 samsync_state
->p_netlogon_wksta
, mem_ctx
, samsync_state
->creds_netlogon_wksta
,
625 TEST_WKSTA_MACHINE_NAME
,
630 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_DISABLED
)) {
631 if (user
->acct_flags
& ACB_DISABLED
) {
634 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
)) {
635 if (user
->acct_flags
& ACB_WSTRUST
) {
638 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT
)) {
639 if (user
->acct_flags
& ACB_SVRTRUST
) {
642 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
643 if (user
->acct_flags
& ACB_DOMTRUST
) {
646 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
647 if (user
->acct_flags
& ACB_DOMTRUST
) {
650 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_ACCOUNT_LOCKED_OUT
)) {
651 if (user
->acct_flags
& ACB_AUTOLOCK
) {
654 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_PASSWORD_EXPIRED
)) {
655 if (info
->info21
.acct_flags
& ACB_PW_EXPIRED
) {
658 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
)) {
659 if (!lm_hash_p
&& !nt_hash_p
) {
662 } else if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_PASSWORD_MUST_CHANGE
)) {
663 /* We would need to know the server's current time to test this properly */
665 } else if (NT_STATUS_IS_OK(nt_status
)) {
666 TEST_INT_EQUAL(user
->rid
, info3
->base
.rid
);
667 TEST_INT_EQUAL(user
->primary_gid
, info3
->base
.primary_gid
);
668 /* this is 0x0 from NT4 sp6 */
669 if (info3
->base
.acct_flags
) {
670 TEST_INT_EQUAL(user
->acct_flags
, info3
->base
.acct_flags
);
672 /* this is NULL from NT4 sp6 */
673 if (info3
->base
.account_name
.string
) {
674 TEST_STRING_EQUAL(user
->account_name
, info3
->base
.account_name
);
676 /* this is NULL from Win2k3 */
677 if (info3
->base
.full_name
.string
) {
678 TEST_STRING_EQUAL(user
->full_name
, info3
->base
.full_name
);
680 TEST_STRING_EQUAL(user
->logon_script
, info3
->base
.logon_script
);
681 TEST_STRING_EQUAL(user
->profile_path
, info3
->base
.profile_path
);
682 TEST_STRING_EQUAL(user
->home_directory
, info3
->base
.home_directory
);
683 TEST_STRING_EQUAL(user
->home_drive
, info3
->base
.home_drive
);
684 TEST_STRING_EQUAL(user
->logon_script
, info3
->base
.logon_script
);
687 TEST_TIME_EQUAL(user
->last_logon
, info3
->base
.logon_time
);
688 TEST_TIME_EQUAL(user
->acct_expiry
, info3
->base
.kickoff_time
);
689 TEST_TIME_EQUAL(user
->last_password_change
, info3
->base
.last_password_change
);
690 TEST_TIME_EQUAL(info
->info21
.force_password_change
, info3
->base
.force_password_change
);
692 /* Does the concept of a logoff time ever really
693 * exist? (not in any sensible way, according to the
694 * doco I read -- abartlet) */
696 /* This copes with the two different versions of 0 I see */
697 /* with NT4 sp6 we have the || case */
698 if (!((user
->last_logoff
== 0)
699 || (info3
->base
.logoff_time
== 0x7fffffffffffffffLL
))) {
700 TEST_TIME_EQUAL(user
->last_logoff
, info3
->base
.logoff_time
);
703 TEST_INT_EQUAL(rids
->count
, info3
->base
.groups
.count
);
704 if (rids
->count
== info3
->base
.groups
.count
) {
706 int count
= rids
->count
;
707 bool *matched
= talloc_zero_array(mem_ctx
, bool, rids
->count
);
709 for (i
= 0; i
< count
; i
++) {
710 for (j
= 0; j
< count
; j
++) {
711 if ((rids
->rids
[i
].rid
==
712 info3
->base
.groups
.rids
[j
].rid
)
713 && (rids
->rids
[i
].attributes
==
714 info3
->base
.groups
.rids
[j
].attributes
)) {
720 for (i
= 0; i
< rids
->count
; i
++) {
721 if (matched
[i
] == false) {
723 torture_comment(tctx
, "Could not find group RID %u found in getgroups in NETLOGON reply\n",
730 torture_comment(tctx
, "Could not validate password for user %s\\%s: %s\n",
731 domain
, username
, nt_errstr(nt_status
));
737 static bool samsync_handle_alias(struct torture_context
*tctx
,
738 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
739 int database_id
, struct netr_DELTA_ENUM
*delta
)
741 uint32_t rid
= delta
->delta_id_union
.rid
;
742 struct netr_DELTA_ALIAS
*alias
= delta
->delta_union
.alias
;
745 struct samr_OpenAlias r
;
746 struct samr_QueryAliasInfo q
;
747 union samr_AliasInfo
*info
;
748 struct policy_handle alias_handle
;
750 if (!samsync_state
->domain_name
|| !samsync_state
->domain_handle
[database_id
]) {
751 torture_comment(tctx
, "SamSync needs domain information before the users\n");
755 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
756 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
758 r
.out
.alias_handle
= &alias_handle
;
760 torture_assert_ntstatus_ok(tctx
,
761 dcerpc_samr_OpenAlias_r(samsync_state
->b_samr
, mem_ctx
, &r
),
762 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
763 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
764 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
766 q
.in
.alias_handle
= &alias_handle
;
770 TEST_SEC_DESC_EQUAL(alias
->sdbuf
, samr
, &alias_handle
);
772 torture_assert_ntstatus_ok(tctx
,
773 dcerpc_samr_QueryAliasInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
774 "QueryAliasInfo failed");
775 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &alias_handle
)) {
779 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
780 torture_comment(tctx
, "QueryAliasInfo level %u failed - %s\n",
781 q
.in
.level
, nt_errstr(q
.out
.result
));
785 TEST_STRING_EQUAL(info
->all
.name
, alias
->alias_name
);
786 TEST_STRING_EQUAL(info
->all
.description
, alias
->description
);
790 static bool samsync_handle_group(struct torture_context
*tctx
,
791 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
792 int database_id
, struct netr_DELTA_ENUM
*delta
)
794 uint32_t rid
= delta
->delta_id_union
.rid
;
795 struct netr_DELTA_GROUP
*group
= delta
->delta_union
.group
;
798 struct samr_OpenGroup r
;
799 struct samr_QueryGroupInfo q
;
800 union samr_GroupInfo
*info
;
801 struct policy_handle group_handle
;
803 if (!samsync_state
->domain_name
|| !samsync_state
->domain_handle
[database_id
]) {
804 torture_comment(tctx
, "SamSync needs domain information before the users\n");
808 r
.in
.domain_handle
= samsync_state
->domain_handle
[database_id
];
809 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
811 r
.out
.group_handle
= &group_handle
;
813 torture_assert_ntstatus_ok(tctx
,
814 dcerpc_samr_OpenGroup_r(samsync_state
->b_samr
, mem_ctx
, &r
),
815 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
816 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
817 talloc_asprintf(tctx
, "OpenUser(%u) failed", rid
));
819 q
.in
.group_handle
= &group_handle
;
823 TEST_SEC_DESC_EQUAL(group
->sdbuf
, samr
, &group_handle
);
825 torture_assert_ntstatus_ok(tctx
,
826 dcerpc_samr_QueryGroupInfo_r(samsync_state
->b_samr
, mem_ctx
, &q
),
827 "QueryGroupInfo failed");
828 if (!test_samr_handle_Close(samsync_state
->b_samr
, tctx
, &group_handle
)) {
832 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
833 torture_comment(tctx
, "QueryGroupInfo level %u failed - %s\n",
834 q
.in
.level
, nt_errstr(q
.out
.result
));
838 TEST_STRING_EQUAL(info
->all
.name
, group
->group_name
);
839 TEST_INT_EQUAL(info
->all
.attributes
, group
->attributes
);
840 TEST_STRING_EQUAL(info
->all
.description
, group
->description
);
844 static bool samsync_handle_secret(struct torture_context
*tctx
,
845 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
846 int database_id
, struct netr_DELTA_ENUM
*delta
)
848 struct netr_DELTA_SECRET
*secret
= delta
->delta_union
.secret
;
849 const char *name
= delta
->delta_id_union
.name
;
850 struct samsync_secret
*nsec
= talloc(samsync_state
, struct samsync_secret
);
851 struct samsync_secret
*old
= talloc(mem_ctx
, struct samsync_secret
);
852 struct lsa_QuerySecret q
;
853 struct lsa_OpenSecret o
;
854 struct policy_handle sec_handle
;
855 struct lsa_DATA_BUF_PTR bufp1
;
856 struct lsa_DATA_BUF_PTR bufp2
;
860 DATA_BLOB lsa_blob1
, lsa_blob_out
, session_key
;
863 nsec
->name
= talloc_reference(nsec
, name
);
864 nsec
->secret
= data_blob_talloc(nsec
, secret
->current_cipher
.cipher_data
, secret
->current_cipher
.maxlen
);
865 nsec
->mtime
= secret
->current_cipher_set_time
;
867 nsec
= talloc_reference(samsync_state
, nsec
);
868 DLIST_ADD(samsync_state
->secrets
, nsec
);
870 old
->name
= talloc_reference(old
, name
);
871 old
->secret
= data_blob_const(secret
->old_cipher
.cipher_data
, secret
->old_cipher
.maxlen
);
872 old
->mtime
= secret
->old_cipher_set_time
;
874 o
.in
.handle
= samsync_state
->lsa_handle
;
875 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
876 o
.in
.name
.string
= name
;
877 o
.out
.sec_handle
= &sec_handle
;
879 torture_assert_ntstatus_ok(tctx
,
880 dcerpc_lsa_OpenSecret_r(samsync_state
->b_lsa
, mem_ctx
, &o
),
881 "OpenSecret failed");
882 torture_assert_ntstatus_ok(tctx
, o
.out
.result
,
883 "OpenSecret failed");
886 We would like to do this, but it is NOT_SUPPORTED on win2k3
887 TEST_SEC_DESC_EQUAL(secret->sdbuf, lsa, &sec_handle);
889 status
= dcerpc_fetch_session_key(samsync_state
->p_lsa
, &session_key
);
890 if (!NT_STATUS_IS_OK(status
)) {
891 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
896 ZERO_STRUCT(nsec_mtime
);
897 ZERO_STRUCT(old_mtime
);
899 /* fetch the secret back again */
900 q
.in
.sec_handle
= &sec_handle
;
901 q
.in
.new_val
= &bufp1
;
902 q
.in
.new_mtime
= &nsec_mtime
;
903 q
.in
.old_val
= &bufp2
;
904 q
.in
.old_mtime
= &old_mtime
;
909 torture_assert_ntstatus_ok(tctx
,
910 dcerpc_lsa_QuerySecret_r(samsync_state
->b_lsa
, mem_ctx
, &q
),
911 "QuerySecret failed");
912 if (NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED
, q
.out
.result
)) {
913 /* some things are just off limits */
915 } else if (!NT_STATUS_IS_OK(q
.out
.result
)) {
916 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(q
.out
.result
));
920 if (q
.out
.old_val
->buf
== NULL
) {
921 /* probably just not available due to ACLs */
923 lsa_blob1
.data
= q
.out
.old_val
->buf
->data
;
924 lsa_blob1
.length
= q
.out
.old_val
->buf
->length
;
926 status
= sess_decrypt_blob(mem_ctx
, &lsa_blob1
, &session_key
, &lsa_blob_out
);
927 if (!NT_STATUS_IS_OK(status
)) {
928 torture_comment(tctx
, "Failed to decrypt secrets OLD blob: %s\n", nt_errstr(status
));
932 if (!q
.out
.old_mtime
) {
933 torture_comment(tctx
, "OLD mtime not available on LSA for secret %s\n", old
->name
);
936 if (old
->mtime
!= *q
.out
.old_mtime
) {
937 torture_comment(tctx
, "OLD mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
938 old
->name
, nt_time_string(mem_ctx
, old
->mtime
),
939 nt_time_string(mem_ctx
, *q
.out
.old_mtime
));
943 if (old
->secret
.length
!= lsa_blob_out
.length
) {
944 torture_comment(tctx
, "Returned secret %s doesn't match: %d != %d\n",
945 old
->name
, (int)old
->secret
.length
, (int)lsa_blob_out
.length
);
947 } else if (memcmp(lsa_blob_out
.data
,
948 old
->secret
.data
, old
->secret
.length
) != 0) {
949 torture_comment(tctx
, "Returned secret %s doesn't match: \n",
951 DEBUG(1, ("SamSync Secret:\n"));
952 dump_data(1, old
->secret
.data
, old
->secret
.length
);
953 DEBUG(1, ("LSA Secret:\n"));
954 dump_data(1, lsa_blob_out
.data
, lsa_blob_out
.length
);
960 if (q
.out
.new_val
->buf
== NULL
) {
961 /* probably just not available due to ACLs */
963 lsa_blob1
.data
= q
.out
.new_val
->buf
->data
;
964 lsa_blob1
.length
= q
.out
.new_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\n");
972 if (!q
.out
.new_mtime
) {
973 torture_comment(tctx
, "NEW mtime not available on LSA for secret %s\n", nsec
->name
);
976 if (nsec
->mtime
!= *q
.out
.new_mtime
) {
977 torture_comment(tctx
, "NEW mtime on secret %s does not match between SAMSYNC (%s) and LSA (%s)\n",
978 nsec
->name
, nt_time_string(mem_ctx
, nsec
->mtime
),
979 nt_time_string(mem_ctx
, *q
.out
.new_mtime
));
983 if (nsec
->secret
.length
!= lsa_blob_out
.length
) {
984 torture_comment(tctx
, "Returned secret %s doesn't match: %d != %d\n",
985 nsec
->name
, (int)nsec
->secret
.length
, (int)lsa_blob_out
.length
);
987 } else if (memcmp(lsa_blob_out
.data
,
988 nsec
->secret
.data
, nsec
->secret
.length
) != 0) {
989 torture_comment(tctx
, "Returned secret %s doesn't match: \n",
991 DEBUG(1, ("SamSync Secret:\n"));
992 dump_data(1, nsec
->secret
.data
, nsec
->secret
.length
);
993 DEBUG(1, ("LSA Secret:\n"));
994 dump_data(1, lsa_blob_out
.data
, lsa_blob_out
.length
);
1002 static bool samsync_handle_trusted_domain(struct torture_context
*tctx
,
1003 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
1004 int database_id
, struct netr_DELTA_ENUM
*delta
)
1007 struct netr_DELTA_TRUSTED_DOMAIN
*trusted_domain
= delta
->delta_union
.trusted_domain
;
1008 struct dom_sid
*dom_sid
= delta
->delta_id_union
.sid
;
1010 struct samsync_trusted_domain
*ndom
= talloc(samsync_state
, struct samsync_trusted_domain
);
1011 struct lsa_OpenTrustedDomain t
;
1012 struct policy_handle trustdom_handle
;
1013 struct lsa_QueryTrustedDomainInfo q
;
1014 union lsa_TrustedDomainInfo
*info
[9];
1015 union lsa_TrustedDomainInfo
*_info
= NULL
;
1016 int levels
[] = {1, 3, 8};
1019 ndom
->name
= talloc_reference(ndom
, trusted_domain
->domain_name
.string
);
1020 ndom
->sid
= talloc_reference(ndom
, dom_sid
);
1022 t
.in
.handle
= samsync_state
->lsa_handle
;
1023 t
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1025 t
.out
.trustdom_handle
= &trustdom_handle
;
1027 torture_assert_ntstatus_ok(tctx
,
1028 dcerpc_lsa_OpenTrustedDomain_r(samsync_state
->b_lsa
, mem_ctx
, &t
),
1029 "OpenTrustedDomain failed");
1030 torture_assert_ntstatus_ok(tctx
, t
.out
.result
,
1031 "OpenTrustedDomain failed");
1033 for (i
=0; i
< ARRAY_SIZE(levels
); i
++) {
1034 q
.in
.trustdom_handle
= &trustdom_handle
;
1035 q
.in
.level
= levels
[i
];
1036 q
.out
.info
= &_info
;
1037 torture_assert_ntstatus_ok(tctx
,
1038 dcerpc_lsa_QueryTrustedDomainInfo_r(samsync_state
->b_lsa
, mem_ctx
, &q
),
1039 "QueryTrustedDomainInfo failed");
1040 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
1041 if (q
.in
.level
== 8 && NT_STATUS_EQUAL(q
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
1042 info
[levels
[i
]] = NULL
;
1045 torture_comment(tctx
, "QueryInfoTrustedDomain level %d failed - %s\n",
1046 levels
[i
], nt_errstr(q
.out
.result
));
1049 info
[levels
[i
]] = _info
;
1053 TEST_SID_EQUAL(info
[8]->full_info
.info_ex
.sid
, dom_sid
);
1054 TEST_STRING_EQUAL(info
[8]->full_info
.info_ex
.netbios_name
, trusted_domain
->domain_name
);
1056 TEST_STRING_EQUAL(info
[1]->name
.netbios_name
, trusted_domain
->domain_name
);
1057 TEST_INT_EQUAL(info
[3]->posix_offset
.posix_offset
, trusted_domain
->posix_offset
);
1059 We would like to do this, but it is NOT_SUPPORTED on win2k3
1060 TEST_SEC_DESC_EQUAL(trusted_domain->sdbuf, lsa, &trustdom_handle);
1062 ndom
= talloc_reference(samsync_state
, ndom
);
1063 DLIST_ADD(samsync_state
->trusted_domains
, ndom
);
1068 static bool samsync_handle_account(struct torture_context
*tctx
,
1069 TALLOC_CTX
*mem_ctx
, struct samsync_state
*samsync_state
,
1070 int database_id
, struct netr_DELTA_ENUM
*delta
)
1073 struct netr_DELTA_ACCOUNT
*account
= delta
->delta_union
.account
;
1074 struct dom_sid
*dom_sid
= delta
->delta_id_union
.sid
;
1076 struct lsa_OpenAccount a
;
1077 struct policy_handle acct_handle
;
1078 struct lsa_EnumPrivsAccount e
;
1079 struct lsa_PrivilegeSet
*privs
= NULL
;
1080 struct lsa_LookupPrivName r
;
1084 bool *found_priv_in_lsa
;
1086 a
.in
.handle
= samsync_state
->lsa_handle
;
1087 a
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1089 a
.out
.acct_handle
= &acct_handle
;
1091 torture_assert_ntstatus_ok(tctx
,
1092 dcerpc_lsa_OpenAccount_r(samsync_state
->b_lsa
, mem_ctx
, &a
),
1093 "OpenAccount failed");
1094 torture_assert_ntstatus_ok(tctx
, a
.out
.result
,
1095 "OpenAccount failed");
1097 TEST_SEC_DESC_EQUAL(account
->sdbuf
, lsa
, &acct_handle
);
1099 found_priv_in_lsa
= talloc_zero_array(mem_ctx
, bool, account
->privilege_entries
);
1101 e
.in
.handle
= &acct_handle
;
1102 e
.out
.privs
= &privs
;
1104 torture_assert_ntstatus_ok(tctx
,
1105 dcerpc_lsa_EnumPrivsAccount_r(samsync_state
->b_lsa
, mem_ctx
, &e
),
1106 "EnumPrivsAccount failed");
1107 torture_assert_ntstatus_ok(tctx
, e
.out
.result
,
1108 "EnumPrivsAccount failed");
1110 if ((account
->privilege_entries
&& !privs
)) {
1111 torture_comment(tctx
, "Account %s has privileges in SamSync, but not LSA\n",
1112 dom_sid_string(mem_ctx
, dom_sid
));
1116 if (!account
->privilege_entries
&& privs
&& privs
->count
) {
1117 torture_comment(tctx
, "Account %s has privileges in LSA, but not SamSync\n",
1118 dom_sid_string(mem_ctx
, dom_sid
));
1122 TEST_INT_EQUAL(account
->privilege_entries
, privs
->count
);
1124 for (i
=0;i
< privs
->count
; i
++) {
1126 struct lsa_StringLarge
*name
= NULL
;
1128 r
.in
.handle
= samsync_state
->lsa_handle
;
1129 r
.in
.luid
= &privs
->set
[i
].luid
;
1132 torture_assert_ntstatus_ok(tctx
,
1133 dcerpc_lsa_LookupPrivName_r(samsync_state
->b_lsa
, mem_ctx
, &r
),
1134 "\nLookupPrivName failed");
1135 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1136 "\nLookupPrivName failed");
1139 torture_comment(tctx
, "\nLookupPrivName failed to return a name\n");
1142 for (j
=0;j
<account
->privilege_entries
; j
++) {
1143 if (strcmp(name
->string
, account
->privilege_name
[j
].string
) == 0) {
1144 found_priv_in_lsa
[j
] = true;
1149 for (j
=0;j
<account
->privilege_entries
; j
++) {
1150 if (!found_priv_in_lsa
[j
]) {
1151 torture_comment(tctx
, "Privilege %s on account %s not found in LSA\n", account
->privilege_name
[j
].string
,
1152 dom_sid_string(mem_ctx
, dom_sid
));
1160 try a netlogon DatabaseSync
1162 static bool test_DatabaseSync(struct torture_context
*tctx
,
1163 struct samsync_state
*samsync_state
,
1164 TALLOC_CTX
*mem_ctx
)
1166 TALLOC_CTX
*loop_ctx
, *delta_ctx
, *trustdom_ctx
;
1167 struct netr_DatabaseSync r
;
1168 const enum netr_SamDatabaseID database_ids
[] = {SAM_DATABASE_DOMAIN
, SAM_DATABASE_BUILTIN
, SAM_DATABASE_PRIVS
};
1171 struct samsync_trusted_domain
*t
;
1172 struct samsync_secret
*s
;
1173 struct netr_Authenticator return_authenticator
, credential
;
1174 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1176 const char *domain
, *username
;
1178 ZERO_STRUCT(return_authenticator
);
1180 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(samsync_state
->p
));
1181 r
.in
.computername
= TEST_MACHINE_NAME
;
1182 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1183 r
.in
.return_authenticator
= &return_authenticator
;
1184 r
.out
.return_authenticator
= &return_authenticator
;
1185 r
.out
.delta_enum_array
= &delta_enum_array
;
1187 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1189 uint32_t sync_context
= 0;
1191 r
.in
.database_id
= database_ids
[i
];
1192 r
.in
.sync_context
= &sync_context
;
1193 r
.out
.sync_context
= &sync_context
;
1195 torture_comment(tctx
, "Testing DatabaseSync of id %d\n", r
.in
.database_id
);
1198 loop_ctx
= talloc_named(mem_ctx
, 0, "DatabaseSync loop context");
1199 netlogon_creds_client_authenticator(samsync_state
->creds
, &credential
);
1201 r
.in
.credential
= &credential
;
1203 torture_assert_ntstatus_ok(tctx
,
1204 dcerpc_netr_DatabaseSync_r(samsync_state
->b
, loop_ctx
, &r
),
1205 "DatabaseSync failed");
1206 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1207 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
1208 torture_comment(tctx
, "DatabaseSync - %s\n", nt_errstr(r
.out
.result
));
1213 if (!netlogon_creds_client_check(samsync_state
->creds
, &r
.out
.return_authenticator
->cred
)) {
1214 torture_comment(tctx
, "Credential chaining failed\n");
1217 r
.in
.sync_context
= r
.out
.sync_context
;
1219 for (d
=0; d
< delta_enum_array
->num_deltas
; d
++) {
1220 delta_ctx
= talloc_named(loop_ctx
, 0, "DatabaseSync delta context");
1222 if (!NT_STATUS_IS_OK(samsync_fix_delta(delta_ctx
, samsync_state
->creds
,
1224 &delta_enum_array
->delta_enum
[d
]))) {
1225 torture_comment(tctx
, "Failed to decrypt delta\n");
1229 switch (delta_enum_array
->delta_enum
[d
].delta_type
) {
1230 case NETR_DELTA_DOMAIN
:
1231 if (!samsync_handle_domain(tctx
, delta_ctx
, samsync_state
,
1232 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1233 torture_comment(tctx
, "Failed to handle DELTA_DOMAIN\n");
1237 case NETR_DELTA_GROUP
:
1238 if (!samsync_handle_group(tctx
, delta_ctx
, samsync_state
,
1239 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1240 torture_comment(tctx
, "Failed to handle DELTA_USER\n");
1244 case NETR_DELTA_USER
:
1245 if (!samsync_handle_user(tctx
, delta_ctx
, samsync_state
,
1246 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1247 torture_comment(tctx
, "Failed to handle DELTA_USER\n");
1251 case NETR_DELTA_ALIAS
:
1252 if (!samsync_handle_alias(tctx
, delta_ctx
, samsync_state
,
1253 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1254 torture_comment(tctx
, "Failed to handle DELTA_ALIAS\n");
1258 case NETR_DELTA_POLICY
:
1259 if (!samsync_handle_policy(tctx
, delta_ctx
, samsync_state
,
1260 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1261 torture_comment(tctx
, "Failed to handle DELTA_POLICY\n");
1265 case NETR_DELTA_TRUSTED_DOMAIN
:
1266 if (!samsync_handle_trusted_domain(tctx
, delta_ctx
, samsync_state
,
1267 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1268 torture_comment(tctx
, "Failed to handle DELTA_TRUSTED_DOMAIN\n");
1272 case NETR_DELTA_ACCOUNT
:
1273 if (!samsync_handle_account(tctx
, delta_ctx
, samsync_state
,
1274 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1275 torture_comment(tctx
, "Failed to handle DELTA_ACCOUNT\n");
1279 case NETR_DELTA_SECRET
:
1280 if (!samsync_handle_secret(tctx
, delta_ctx
, samsync_state
,
1281 r
.in
.database_id
, &delta_enum_array
->delta_enum
[d
])) {
1282 torture_comment(tctx
, "Failed to handle DELTA_SECRET\n");
1286 case NETR_DELTA_GROUP_MEMBER
:
1287 case NETR_DELTA_ALIAS_MEMBER
:
1288 /* These are harder to cross-check, and we expect them */
1290 case NETR_DELTA_DELETE_GROUP
:
1291 case NETR_DELTA_RENAME_GROUP
:
1292 case NETR_DELTA_DELETE_USER
:
1293 case NETR_DELTA_RENAME_USER
:
1294 case NETR_DELTA_DELETE_ALIAS
:
1295 case NETR_DELTA_RENAME_ALIAS
:
1296 case NETR_DELTA_DELETE_TRUST
:
1297 case NETR_DELTA_DELETE_ACCOUNT
:
1298 case NETR_DELTA_DELETE_SECRET
:
1299 case NETR_DELTA_DELETE_GROUP2
:
1300 case NETR_DELTA_DELETE_USER2
:
1301 case NETR_DELTA_MODIFY_COUNT
:
1303 torture_comment(tctx
, "Uxpected delta type %d\n", delta_enum_array
->delta_enum
[d
].delta_type
);
1307 talloc_free(delta_ctx
);
1309 talloc_free(loop_ctx
);
1310 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1314 domain
= samsync_state
->domain_name
[SAM_DATABASE_DOMAIN
];
1316 torture_comment(tctx
, "Never got a DOMAIN object in samsync!\n");
1320 trustdom_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseSync Trusted domains context");
1322 username
= talloc_asprintf(trustdom_ctx
, "%s$", domain
);
1323 for (t
=samsync_state
->trusted_domains
; t
; t
=t
->next
) {
1324 char *secret_name
= talloc_asprintf(trustdom_ctx
, "G$$%s", t
->name
);
1325 for (s
=samsync_state
->secrets
; s
; s
=s
->next
) {
1326 if (strcasecmp_m(s
->name
, secret_name
) == 0) {
1328 struct samr_Password nt_hash
;
1329 mdfour(nt_hash
.hash
, s
->secret
.data
, s
->secret
.length
);
1331 torture_comment(tctx
, "Checking password for %s\\%s\n", t
->name
, username
);
1332 nt_status
= test_SamLogon(tctx
,
1333 samsync_state
->p_netlogon_wksta
, trustdom_ctx
, samsync_state
->creds_netlogon_wksta
,
1336 TEST_WKSTA_MACHINE_NAME
,
1340 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_LOGON_SERVERS
)) {
1341 torture_comment(tctx
, "Verifiction of trust password to %s failed: %s (the trusted domain is not available)\n",
1342 t
->name
, nt_errstr(nt_status
));
1346 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
1347 torture_comment(tctx
, "Verifiction of trust password to %s: should have failed (nologon interdomain trust account), instead: %s\n",
1348 t
->name
, nt_errstr(nt_status
));
1354 nt_status
= test_SamLogon(tctx
,
1355 samsync_state
->p_netlogon_wksta
, trustdom_ctx
, samsync_state
->creds_netlogon_wksta
,
1358 TEST_WKSTA_MACHINE_NAME
,
1363 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_WRONG_PASSWORD
)) {
1364 torture_comment(tctx
, "Verifiction of trust password to %s: should have failed (wrong password), instead: %s\n",
1365 t
->name
, nt_errstr(nt_status
));
1373 talloc_free(trustdom_ctx
);
1379 try a netlogon DatabaseDeltas
1381 static bool test_DatabaseDeltas(struct torture_context
*tctx
,
1382 struct samsync_state
*samsync_state
, TALLOC_CTX
*mem_ctx
)
1384 TALLOC_CTX
*loop_ctx
;
1385 struct netr_DatabaseDeltas r
;
1386 struct netr_Authenticator credential
;
1387 struct netr_Authenticator return_authenticator
;
1388 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1389 const uint32_t database_ids
[] = {0, 1, 2};
1393 ZERO_STRUCT(return_authenticator
);
1395 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(samsync_state
->p
));
1396 r
.in
.computername
= TEST_MACHINE_NAME
;
1397 r
.in
.credential
= &credential
;
1398 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1399 r
.in
.return_authenticator
= &return_authenticator
;
1400 r
.out
.return_authenticator
= &return_authenticator
;
1401 r
.out
.delta_enum_array
= &delta_enum_array
;
1403 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1405 uint64_t seq_num
= samsync_state
->seq_num
[i
];
1407 r
.in
.database_id
= database_ids
[i
];
1408 r
.in
.sequence_num
= &seq_num
;
1409 r
.out
.sequence_num
= &seq_num
;
1411 if (seq_num
== 0) continue;
1413 /* this shows that the bdc doesn't need to do a single call for
1414 * each seqnumber, and the pdc doesn't need to know about old values
1419 torture_comment(tctx
, "Testing DatabaseDeltas of id %d at %llu\n",
1420 r
.in
.database_id
, (long long)seq_num
);
1423 loop_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseDeltas loop context");
1424 netlogon_creds_client_authenticator(samsync_state
->creds
, &credential
);
1426 torture_assert_ntstatus_ok(tctx
,
1427 dcerpc_netr_DatabaseDeltas_r(samsync_state
->b
, loop_ctx
, &r
),
1428 "DatabaseDeltas failed");
1429 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1430 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) &&
1431 !NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_SYNCHRONIZATION_REQUIRED
)) {
1432 torture_comment(tctx
, "DatabaseDeltas - %s\n", nt_errstr(r
.out
.result
));
1436 if (!netlogon_creds_client_check(samsync_state
->creds
, &return_authenticator
.cred
)) {
1437 torture_comment(tctx
, "Credential chaining failed\n");
1441 talloc_free(loop_ctx
);
1442 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1450 try a netlogon DatabaseSync2
1452 static bool test_DatabaseSync2(struct torture_context
*tctx
,
1453 struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1454 struct netlogon_creds_CredentialState
*creds
)
1456 TALLOC_CTX
*loop_ctx
;
1457 struct netr_DatabaseSync2 r
;
1458 const uint32_t database_ids
[] = {0, 1, 2};
1461 struct netr_Authenticator return_authenticator
, credential
;
1462 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1463 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1465 ZERO_STRUCT(return_authenticator
);
1467 r
.in
.logon_server
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
1468 r
.in
.computername
= TEST_MACHINE_NAME
;
1469 r
.in
.preferredmaximumlength
= (uint32_t)-1;
1470 r
.in
.return_authenticator
= &return_authenticator
;
1471 r
.out
.return_authenticator
= &return_authenticator
;
1472 r
.out
.delta_enum_array
= &delta_enum_array
;
1474 for (i
=0;i
<ARRAY_SIZE(database_ids
);i
++) {
1476 uint32_t sync_context
= 0;
1478 r
.in
.database_id
= database_ids
[i
];
1479 r
.in
.sync_context
= &sync_context
;
1480 r
.out
.sync_context
= &sync_context
;
1481 r
.in
.restart_state
= 0;
1483 torture_comment(tctx
, "Testing DatabaseSync2 of id %d\n", r
.in
.database_id
);
1486 loop_ctx
= talloc_named(mem_ctx
, 0, "test_DatabaseSync2 loop context");
1487 netlogon_creds_client_authenticator(creds
, &credential
);
1489 r
.in
.credential
= &credential
;
1491 torture_assert_ntstatus_ok(tctx
,
1492 dcerpc_netr_DatabaseSync2_r(b
, loop_ctx
, &r
),
1493 "DatabaseSync2 failed");
1494 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
1495 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
1496 torture_comment(tctx
, "DatabaseSync2 - %s\n", nt_errstr(r
.out
.result
));
1500 if (!netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
)) {
1501 torture_comment(tctx
, "Credential chaining failed\n");
1504 talloc_free(loop_ctx
);
1505 } while (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
));
1513 bool torture_rpc_samsync(struct torture_context
*torture
)
1516 TALLOC_CTX
*mem_ctx
;
1518 struct test_join
*join_ctx
;
1519 struct test_join
*join_ctx2
;
1520 struct test_join
*user_ctx
;
1521 const char *machine_password
;
1522 const char *wksta_machine_password
;
1523 struct dcerpc_binding
*b
;
1524 struct dcerpc_binding
*b_netlogon_wksta
;
1525 struct samr_Connect c
;
1526 struct samr_SetDomainInfo s
;
1527 struct policy_handle
*domain_policy
;
1529 struct lsa_ObjectAttribute attr
;
1530 struct lsa_QosInfo qos
;
1531 struct lsa_OpenPolicy2 r
;
1532 struct cli_credentials
*credentials
;
1533 struct cli_credentials
*credentials_wksta
;
1535 struct samsync_state
*samsync_state
;
1537 char *test_machine_account
;
1539 char *test_wksta_machine_account
;
1541 mem_ctx
= talloc_init("torture_rpc_netlogon");
1543 test_machine_account
= talloc_asprintf(mem_ctx
, "%s$", TEST_MACHINE_NAME
);
1544 join_ctx
= torture_create_testuser(torture
, test_machine_account
,
1545 lpcfg_workgroup(torture
->lp_ctx
), ACB_SVRTRUST
,
1548 talloc_free(mem_ctx
);
1549 torture_comment(torture
, "Failed to join as BDC\n");
1553 test_wksta_machine_account
= talloc_asprintf(mem_ctx
, "%s$", TEST_WKSTA_MACHINE_NAME
);
1554 join_ctx2
= torture_create_testuser(torture
, test_wksta_machine_account
, lpcfg_workgroup(torture
->lp_ctx
), ACB_WSTRUST
, &wksta_machine_password
);
1556 talloc_free(mem_ctx
);
1557 torture_comment(torture
, "Failed to join as member\n");
1561 user_ctx
= torture_create_testuser(torture
, TEST_USER_NAME
,
1562 lpcfg_workgroup(torture
->lp_ctx
),
1565 talloc_free(mem_ctx
);
1566 torture_comment(torture
, "Failed to create test account\n");
1570 samsync_state
= talloc_zero(mem_ctx
, struct samsync_state
);
1572 samsync_state
->p_samr
= torture_join_samr_pipe(join_ctx
);
1573 samsync_state
->b_samr
= samsync_state
->p_samr
->binding_handle
;
1574 samsync_state
->connect_handle
= talloc_zero(samsync_state
, struct policy_handle
);
1575 samsync_state
->lsa_handle
= talloc_zero(samsync_state
, struct policy_handle
);
1576 c
.in
.system_name
= NULL
;
1577 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1578 c
.out
.connect_handle
= samsync_state
->connect_handle
;
1580 torture_assert_ntstatus_ok_goto(torture
,
1581 dcerpc_samr_Connect_r(samsync_state
->b_samr
, mem_ctx
, &c
),
1583 "samr_Connect failed");
1584 torture_assert_ntstatus_ok_goto(torture
, c
.out
.result
,
1586 "samr_Connect failed");
1588 domain_policy
= samsync_open_domain(torture
, mem_ctx
, samsync_state
, lpcfg_workgroup(torture
->lp_ctx
), NULL
);
1589 if (!domain_policy
) {
1590 torture_comment(torture
, "samrsync_open_domain failed\n");
1595 s
.in
.domain_handle
= domain_policy
;
1597 s
.in
.info
= talloc(mem_ctx
, union samr_DomainInfo
);
1599 s
.in
.info
->oem
.oem_information
.string
1600 = talloc_asprintf(mem_ctx
,
1601 "Tortured by Samba4: %s",
1602 timestring(mem_ctx
, time(NULL
)));
1603 torture_assert_ntstatus_ok_goto(torture
,
1604 dcerpc_samr_SetDomainInfo_r(samsync_state
->b_samr
, mem_ctx
, &s
),
1606 "SetDomainInfo failed");
1608 if (!test_samr_handle_Close(samsync_state
->b_samr
, torture
, domain_policy
)) {
1613 torture_assert_ntstatus_ok_goto(torture
, s
.out
.result
,
1615 talloc_asprintf(torture
, "SetDomainInfo level %u failed", s
.in
.level
));
1617 status
= torture_rpc_connection(torture
,
1618 &samsync_state
->p_lsa
,
1621 if (!NT_STATUS_IS_OK(status
)) {
1625 samsync_state
->b_lsa
= samsync_state
->p_lsa
->binding_handle
;
1628 qos
.impersonation_level
= 2;
1629 qos
.context_mode
= 1;
1630 qos
.effective_only
= 0;
1633 attr
.root_dir
= NULL
;
1634 attr
.object_name
= NULL
;
1635 attr
.attributes
= 0;
1636 attr
.sec_desc
= NULL
;
1637 attr
.sec_qos
= &qos
;
1639 r
.in
.system_name
= "\\";
1641 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1642 r
.out
.handle
= samsync_state
->lsa_handle
;
1644 torture_assert_ntstatus_ok_goto(torture
,
1645 dcerpc_lsa_OpenPolicy2_r(samsync_state
->b_lsa
, mem_ctx
, &r
),
1647 "OpenPolicy2 failed");
1648 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
,
1650 "OpenPolicy2 failed");
1652 status
= torture_rpc_binding(torture
, &b
);
1653 if (!NT_STATUS_IS_OK(status
)) {
1658 b
->flags
&= ~DCERPC_AUTH_OPTIONS
;
1659 b
->flags
|= DCERPC_SCHANNEL
| DCERPC_SIGN
;
1661 credentials
= cli_credentials_init(mem_ctx
);
1663 cli_credentials_set_workstation(credentials
, TEST_MACHINE_NAME
, CRED_SPECIFIED
);
1664 cli_credentials_set_domain(credentials
, lpcfg_workgroup(torture
->lp_ctx
), CRED_SPECIFIED
);
1665 cli_credentials_set_username(credentials
, test_machine_account
, CRED_SPECIFIED
);
1666 cli_credentials_set_password(credentials
, machine_password
, CRED_SPECIFIED
);
1667 cli_credentials_set_secure_channel_type(credentials
,
1670 status
= dcerpc_pipe_connect_b(samsync_state
,
1671 &samsync_state
->p
, b
,
1672 &ndr_table_netlogon
,
1673 credentials
, torture
->ev
, torture
->lp_ctx
);
1675 if (!NT_STATUS_IS_OK(status
)) {
1676 torture_comment(torture
, "Failed to connect to server as a BDC: %s\n", nt_errstr(status
));
1680 samsync_state
->b
= samsync_state
->p
->binding_handle
;
1682 status
= dcerpc_schannel_creds(samsync_state
->p
->conn
->security_state
.generic_state
,
1683 samsync_state
, &samsync_state
->creds
);
1684 if (!NT_STATUS_IS_OK(status
)) {
1690 status
= torture_rpc_binding(torture
, &b_netlogon_wksta
);
1691 if (!NT_STATUS_IS_OK(status
)) {
1696 b_netlogon_wksta
->flags
&= ~DCERPC_AUTH_OPTIONS
;
1697 b_netlogon_wksta
->flags
|= DCERPC_SCHANNEL
| DCERPC_SIGN
;
1699 credentials_wksta
= cli_credentials_init(mem_ctx
);
1701 cli_credentials_set_workstation(credentials_wksta
, TEST_WKSTA_MACHINE_NAME
, CRED_SPECIFIED
);
1702 cli_credentials_set_domain(credentials_wksta
, lpcfg_workgroup(torture
->lp_ctx
), CRED_SPECIFIED
);
1703 cli_credentials_set_username(credentials_wksta
, test_wksta_machine_account
, CRED_SPECIFIED
);
1704 cli_credentials_set_password(credentials_wksta
, wksta_machine_password
, CRED_SPECIFIED
);
1705 cli_credentials_set_secure_channel_type(credentials_wksta
,
1708 status
= dcerpc_pipe_connect_b(samsync_state
,
1709 &samsync_state
->p_netlogon_wksta
,
1711 &ndr_table_netlogon
,
1712 credentials_wksta
, torture
->ev
, torture
->lp_ctx
);
1714 if (!NT_STATUS_IS_OK(status
)) {
1715 torture_comment(torture
, "Failed to connect to server as a Workstation: %s\n", nt_errstr(status
));
1720 status
= dcerpc_schannel_creds(samsync_state
->p_netlogon_wksta
->conn
->security_state
.generic_state
,
1721 samsync_state
, &samsync_state
->creds_netlogon_wksta
);
1722 if (!NT_STATUS_IS_OK(status
)) {
1723 torture_comment(torture
, "Failed to obtail schanel creds!\n");
1727 if (!test_DatabaseSync(torture
, samsync_state
, mem_ctx
)) {
1728 torture_comment(torture
, "DatabaseSync failed\n");
1732 if (!test_DatabaseDeltas(torture
, samsync_state
, mem_ctx
)) {
1733 torture_comment(torture
, "DatabaseDeltas failed\n");
1737 if (!test_DatabaseSync2(torture
, samsync_state
->p
, mem_ctx
, samsync_state
->creds
)) {
1738 torture_comment(torture
, "DatabaseSync2 failed\n");
1743 torture_leave_domain(torture
, join_ctx
);
1744 torture_leave_domain(torture
, join_ctx2
);
1745 torture_leave_domain(torture
, user_ctx
);
1747 talloc_free(mem_ctx
);