2 Unix SMB/CIFS implementation.
3 test suite for samr rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define TEST_ACCOUNT_NAME "samrtorturetest"
26 #define TEST_ALIASNAME "samrtorturetestalias"
27 #define TEST_GROUPNAME "samrtorturetestgroup"
28 #define TEST_MACHINENAME "samrtorturetestmach$"
29 #define TEST_DOMAINNAME "samrtorturetestdom$"
32 static BOOL
test_QueryUserInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
33 struct policy_handle
*handle
);
35 static BOOL
test_QueryUserInfo2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
36 struct policy_handle
*handle
);
38 static BOOL
test_QueryAliasInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
39 struct policy_handle
*handle
);
41 static void init_samr_Name(struct samr_Name
*name
, const char *s
)
46 static BOOL
test_Close(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
47 struct policy_handle
*handle
)
53 r
.out
.handle
= handle
;
55 status
= dcerpc_samr_Close(p
, mem_ctx
, &r
);
56 if (!NT_STATUS_IS_OK(status
)) {
57 printf("Close handle failed - %s\n", nt_errstr(status
));
64 static BOOL
test_Shutdown(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
65 struct policy_handle
*handle
)
68 struct samr_Shutdown r
;
70 if (lp_parm_int(-1, "torture", "dangerous") != 1) {
71 printf("samr_Shutdown disabled - enable dangerous tests to use\n");
75 r
.in
.connect_handle
= handle
;
77 printf("testing samr_Shutdown\n");
79 status
= dcerpc_samr_Shutdown(p
, mem_ctx
, &r
);
80 if (!NT_STATUS_IS_OK(status
)) {
81 printf("samr_Shutdown failed - %s\n", nt_errstr(status
));
88 static BOOL
test_SetDsrmPassword(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
89 struct policy_handle
*handle
)
92 struct samr_SetDsrmPassword r
;
93 struct samr_Name name
;
94 struct samr_Password hash
;
96 if (lp_parm_int(-1, "torture", "dangerous") != 1) {
97 printf("samr_SetDsrmPassword disabled - enable dangerous tests to use\n");
101 E_md4hash("TeSTDSRM123", hash
.hash
);
103 init_samr_Name(&name
, "Administrator");
109 printf("testing samr_SetDsrmPassword\n");
111 status
= dcerpc_samr_SetDsrmPassword(p
, mem_ctx
, &r
);
112 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
113 printf("samr_SetDsrmPassword failed - %s\n", nt_errstr(status
));
121 static BOOL
test_QuerySecurity(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
122 struct policy_handle
*handle
)
125 struct samr_QuerySecurity r
;
126 struct samr_SetSecurity s
;
128 r
.in
.handle
= handle
;
131 status
= dcerpc_samr_QuerySecurity(p
, mem_ctx
, &r
);
132 if (!NT_STATUS_IS_OK(status
)) {
133 printf("QuerySecurity failed - %s\n", nt_errstr(status
));
137 if (r
.out
.sdbuf
== NULL
) {
141 s
.in
.handle
= handle
;
143 s
.in
.sdbuf
= r
.out
.sdbuf
;
145 status
= dcerpc_samr_SetSecurity(p
, mem_ctx
, &s
);
146 if (!NT_STATUS_IS_OK(status
)) {
147 printf("SetSecurity failed - %s\n", nt_errstr(status
));
151 status
= dcerpc_samr_QuerySecurity(p
, mem_ctx
, &r
);
152 if (!NT_STATUS_IS_OK(status
)) {
153 printf("QuerySecurity failed - %s\n", nt_errstr(status
));
161 static BOOL
test_SetUserInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
162 struct policy_handle
*handle
)
165 struct samr_SetUserInfo s
;
166 struct samr_SetUserInfo2 s2
;
167 struct samr_QueryUserInfo q
;
168 struct samr_QueryUserInfo q0
;
169 union samr_UserInfo u
;
172 s
.in
.user_handle
= handle
;
175 s2
.in
.user_handle
= handle
;
178 q
.in
.user_handle
= handle
;
182 #define TESTCALL(call, r) \
183 status = dcerpc_samr_ ##call(p, mem_ctx, &r); \
184 if (!NT_STATUS_IS_OK(status)) { \
185 printf(#call " level %u failed - %s (line %d)\n", \
186 r.in.level, nt_errstr(status), __LINE__); \
191 #define STRING_EQUAL(s1, s2, field) \
192 if ((s1 && !s2) || (s2 && !s1) || strcmp(s1, s2)) { \
193 printf("Failed to set %s to '%s' (line %d)\n", \
194 #field, s2, __LINE__); \
199 #define INT_EQUAL(i1, i2, field) \
201 printf("Failed to set %s to %u (line %d)\n", \
202 #field, i2, __LINE__); \
207 #define TEST_USERINFO_NAME(lvl1, field1, lvl2, field2, value, fpval) do { \
208 printf("field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
210 TESTCALL(QueryUserInfo, q) \
212 s2.in.level = lvl1; \
215 ZERO_STRUCT(u.info21); \
216 u.info21.fields_present = fpval; \
218 init_samr_Name(&u.info ## lvl1.field1, value); \
219 TESTCALL(SetUserInfo, s) \
220 TESTCALL(SetUserInfo2, s2) \
221 init_samr_Name(&u.info ## lvl1.field1, ""); \
222 TESTCALL(QueryUserInfo, q); \
224 STRING_EQUAL(u.info ## lvl1.field1.name, value, field1); \
226 TESTCALL(QueryUserInfo, q) \
228 STRING_EQUAL(u.info ## lvl2.field2.name, value, field2); \
231 #define TEST_USERINFO_INT(lvl1, field1, lvl2, field2, value, fpval) do { \
232 printf("field test %d/%s vs %d/%s\n", lvl1, #field1, lvl2, #field2); \
234 TESTCALL(QueryUserInfo, q) \
236 s2.in.level = lvl1; \
239 uint8_t *bitmap = u.info21.logon_hours.bitmap; \
240 ZERO_STRUCT(u.info21); \
241 if (fpval == SAMR_FIELD_LOGON_HOURS) { \
242 u.info21.logon_hours.units_per_week = 168; \
243 u.info21.logon_hours.bitmap = bitmap; \
245 u.info21.fields_present = fpval; \
247 u.info ## lvl1.field1 = value; \
248 TESTCALL(SetUserInfo, s) \
249 TESTCALL(SetUserInfo2, s2) \
250 u.info ## lvl1.field1 = 0; \
251 TESTCALL(QueryUserInfo, q); \
253 INT_EQUAL(u.info ## lvl1.field1, value, field1); \
255 TESTCALL(QueryUserInfo, q) \
257 INT_EQUAL(u.info ## lvl2.field2, value, field1); \
261 do { TESTCALL(QueryUserInfo
, q0
) } while (0);
263 TEST_USERINFO_NAME(2, comment
, 1, comment
, "xx2-1 comment", 0);
264 TEST_USERINFO_NAME(2, comment
, 21, comment
, "xx2-21 comment", 0);
265 TEST_USERINFO_NAME(21, comment
, 21, comment
, "xx21-21 comment",
268 TEST_USERINFO_NAME(6, full_name
, 1, full_name
, "xx6-1 full_name", 0);
269 TEST_USERINFO_NAME(6, full_name
, 3, full_name
, "xx6-3 full_name", 0);
270 TEST_USERINFO_NAME(6, full_name
, 5, full_name
, "xx6-5 full_name", 0);
271 TEST_USERINFO_NAME(6, full_name
, 6, full_name
, "xx6-6 full_name", 0);
272 TEST_USERINFO_NAME(6, full_name
, 8, full_name
, "xx6-8 full_name", 0);
273 TEST_USERINFO_NAME(6, full_name
, 21, full_name
, "xx6-21 full_name", 0);
274 TEST_USERINFO_NAME(8, full_name
, 21, full_name
, "xx8-21 full_name", 0);
275 TEST_USERINFO_NAME(21, full_name
, 21, full_name
, "xx21-21 full_name",
278 TEST_USERINFO_NAME(11, logon_script
, 3, logon_script
, "xx11-3 logon_script", 0);
279 TEST_USERINFO_NAME(11, logon_script
, 5, logon_script
, "xx11-5 logon_script", 0);
280 TEST_USERINFO_NAME(11, logon_script
, 21, logon_script
, "xx11-21 logon_script", 0);
281 TEST_USERINFO_NAME(21, logon_script
, 21, logon_script
, "xx21-21 logon_script",
282 SAMR_FIELD_LOGON_SCRIPT
);
284 TEST_USERINFO_NAME(12, profile_path
, 3, profile_path
, "xx12-3 profile_path", 0);
285 TEST_USERINFO_NAME(12, profile_path
, 5, profile_path
, "xx12-5 profile_path", 0);
286 TEST_USERINFO_NAME(12, profile_path
, 21, profile_path
, "xx12-21 profile_path", 0);
287 TEST_USERINFO_NAME(21, profile_path
, 21, profile_path
, "xx21-21 profile_path",
288 SAMR_FIELD_PROFILE_PATH
);
290 TEST_USERINFO_NAME(13, description
, 1, description
, "xx13-1 description", 0);
291 TEST_USERINFO_NAME(13, description
, 5, description
, "xx13-5 description", 0);
292 TEST_USERINFO_NAME(13, description
, 21, description
, "xx13-21 description", 0);
293 TEST_USERINFO_NAME(21, description
, 21, description
, "xx21-21 description",
294 SAMR_FIELD_DESCRIPTION
);
296 TEST_USERINFO_NAME(14, workstations
, 3, workstations
, "14workstation3", 0);
297 TEST_USERINFO_NAME(14, workstations
, 5, workstations
, "14workstation4", 0);
298 TEST_USERINFO_NAME(14, workstations
, 21, workstations
, "14workstation21", 0);
299 TEST_USERINFO_NAME(21, workstations
, 21, workstations
, "21workstation21",
300 SAMR_FIELD_WORKSTATION
);
302 TEST_USERINFO_NAME(20, callback
, 21, callback
, "xx20-21 callback", 0);
303 TEST_USERINFO_NAME(21, callback
, 21, callback
, "xx21-21 callback",
304 SAMR_FIELD_CALLBACK
);
306 TEST_USERINFO_INT(2, country_code
, 21, country_code
, __LINE__
, 0);
307 TEST_USERINFO_INT(21, country_code
, 21, country_code
, __LINE__
,
308 SAMR_FIELD_COUNTRY_CODE
);
310 TEST_USERINFO_INT(2, code_page
, 21, code_page
, __LINE__
, 0);
311 TEST_USERINFO_INT(21, code_page
, 21, code_page
, __LINE__
,
312 SAMR_FIELD_CODE_PAGE
);
314 TEST_USERINFO_INT(4, logon_hours
.bitmap
[3], 3, logon_hours
.bitmap
[3], 1, 0);
315 TEST_USERINFO_INT(4, logon_hours
.bitmap
[3], 5, logon_hours
.bitmap
[3], 2, 0);
316 TEST_USERINFO_INT(4, logon_hours
.bitmap
[3], 21, logon_hours
.bitmap
[3], 3, 0);
317 TEST_USERINFO_INT(21, logon_hours
.bitmap
[3], 21, logon_hours
.bitmap
[3], 4,
318 SAMR_FIELD_LOGON_HOURS
);
321 /* these fail with win2003 - it appears you can't set the primary gid?
322 the set succeeds, but the gid isn't changed. Very weird! */
323 TEST_USERINFO_INT(9, primary_gid
, 1, primary_gid
, 513);
324 TEST_USERINFO_INT(9, primary_gid
, 3, primary_gid
, 513);
325 TEST_USERINFO_INT(9, primary_gid
, 5, primary_gid
, 513);
326 TEST_USERINFO_INT(9, primary_gid
, 21, primary_gid
, 513);
332 generate a random password for password change tests
334 static char *samr_rand_pass(TALLOC_CTX
*mem_ctx
)
336 size_t len
= 8 + (random() % 6);
337 char *s
= generate_random_str(mem_ctx
, len
);
338 printf("Generated password '%s'\n", s
);
342 static BOOL
test_SetUserPass(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
343 struct policy_handle
*handle
, char **password
)
346 struct samr_SetUserInfo s
;
347 union samr_UserInfo u
;
349 DATA_BLOB session_key
;
350 char *newpass
= samr_rand_pass(mem_ctx
);
352 s
.in
.user_handle
= handle
;
356 encode_pw_buffer(u
.info24
.password
.data
, newpass
, STR_UNICODE
);
357 /* w2k3 ignores this length */
358 u
.info24
.pw_len
= strlen_m(newpass
) * 2;
360 status
= dcerpc_fetch_session_key(p
, &session_key
);
361 if (!NT_STATUS_IS_OK(status
)) {
362 printf("SetUserInfo level %u - no session key - %s\n",
363 s
.in
.level
, nt_errstr(status
));
367 arcfour_crypt_blob(u
.info24
.password
.data
, 516, &session_key
);
369 printf("Testing SetUserInfo level 24 (set password)\n");
371 status
= dcerpc_samr_SetUserInfo(p
, mem_ctx
, &s
);
372 if (!NT_STATUS_IS_OK(status
)) {
373 printf("SetUserInfo level %u failed - %s\n",
374 s
.in
.level
, nt_errstr(status
));
384 static BOOL
test_SetUserPass_23(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
385 struct policy_handle
*handle
, char **password
)
388 struct samr_SetUserInfo s
;
389 union samr_UserInfo u
;
391 DATA_BLOB session_key
;
392 char *newpass
= samr_rand_pass(mem_ctx
);
394 s
.in
.user_handle
= handle
;
400 u
.info23
.info
.fields_present
= SAMR_FIELD_PASSWORD
;
402 encode_pw_buffer(u
.info23
.password
.data
, newpass
, STR_UNICODE
);
404 status
= dcerpc_fetch_session_key(p
, &session_key
);
405 if (!NT_STATUS_IS_OK(status
)) {
406 printf("SetUserInfo level %u - no session key - %s\n",
407 s
.in
.level
, nt_errstr(status
));
411 arcfour_crypt_blob(u
.info23
.password
.data
, 516, &session_key
);
413 printf("Testing SetUserInfo level 23 (set password)\n");
415 status
= dcerpc_samr_SetUserInfo(p
, mem_ctx
, &s
);
416 if (!NT_STATUS_IS_OK(status
)) {
417 printf("SetUserInfo level %u failed - %s\n",
418 s
.in
.level
, nt_errstr(status
));
428 static BOOL
test_SetUserPassEx(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
429 struct policy_handle
*handle
, char **password
)
432 struct samr_SetUserInfo s
;
433 union samr_UserInfo u
;
435 DATA_BLOB session_key
;
436 DATA_BLOB confounded_session_key
= data_blob_talloc(mem_ctx
, NULL
, 16);
437 uint8_t confounder
[16];
438 char *newpass
= samr_rand_pass(mem_ctx
);
439 struct MD5Context ctx
;
441 s
.in
.user_handle
= handle
;
445 encode_pw_buffer(u
.info26
.password
.data
, newpass
, STR_UNICODE
);
446 u
.info26
.pw_len
= strlen(newpass
);
448 status
= dcerpc_fetch_session_key(p
, &session_key
);
449 if (!NT_STATUS_IS_OK(status
)) {
450 printf("SetUserInfo level %u - no session key - %s\n",
451 s
.in
.level
, nt_errstr(status
));
455 generate_random_buffer((uint8_t *)confounder
, 16);
458 MD5Update(&ctx
, confounder
, 16);
459 MD5Update(&ctx
, session_key
.data
, session_key
.length
);
460 MD5Final(confounded_session_key
.data
, &ctx
);
462 arcfour_crypt_blob(u
.info26
.password
.data
, 516, &confounded_session_key
);
463 memcpy(&u
.info26
.password
.data
[516], confounder
, 16);
465 printf("Testing SetUserInfo level 26 (set password ex)\n");
467 status
= dcerpc_samr_SetUserInfo(p
, mem_ctx
, &s
);
468 if (!NT_STATUS_IS_OK(status
)) {
469 printf("SetUserInfo level %u failed - %s\n",
470 s
.in
.level
, nt_errstr(status
));
479 static BOOL
test_SetUserPass_25(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
480 struct policy_handle
*handle
, char **password
)
483 struct samr_SetUserInfo s
;
484 union samr_UserInfo u
;
486 DATA_BLOB session_key
;
487 DATA_BLOB confounded_session_key
= data_blob_talloc(mem_ctx
, NULL
, 16);
488 uint8_t confounder
[16];
489 char *newpass
= samr_rand_pass(mem_ctx
);
490 struct MD5Context ctx
;
492 s
.in
.user_handle
= handle
;
498 u
.info25
.info
.fields_present
= SAMR_FIELD_PASSWORD
;
500 encode_pw_buffer(u
.info25
.password
.data
, newpass
, STR_UNICODE
);
502 status
= dcerpc_fetch_session_key(p
, &session_key
);
503 if (!NT_STATUS_IS_OK(status
)) {
504 printf("SetUserInfo level %u - no session key - %s\n",
505 s
.in
.level
, nt_errstr(status
));
509 generate_random_buffer((uint8_t *)confounder
, 16);
512 MD5Update(&ctx
, confounder
, 16);
513 MD5Update(&ctx
, session_key
.data
, session_key
.length
);
514 MD5Final(confounded_session_key
.data
, &ctx
);
516 arcfour_crypt_blob(u
.info25
.password
.data
, 516, &confounded_session_key
);
517 memcpy(&u
.info25
.password
.data
[516], confounder
, 16);
519 printf("Testing SetUserInfo level 25 (set password ex)\n");
521 status
= dcerpc_samr_SetUserInfo(p
, mem_ctx
, &s
);
522 if (!NT_STATUS_IS_OK(status
)) {
523 printf("SetUserInfo level %u failed - %s\n",
524 s
.in
.level
, nt_errstr(status
));
533 static BOOL
test_SetAliasInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
534 struct policy_handle
*handle
)
537 struct samr_SetAliasInfo r
;
538 struct samr_QueryAliasInfo q
;
539 uint16_t levels
[] = {2, 3};
543 /* Ignoring switch level 1, as that includes the number of members for the alias
544 * and setting this to a wrong value might have negative consequences
547 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
548 printf("Testing SetAliasInfo level %u\n", levels
[i
]);
550 r
.in
.alias_handle
= handle
;
551 r
.in
.level
= levels
[i
];
552 switch (r
.in
.level
) {
553 case 2 : init_samr_Name(&r
.in
.info
.name
,TEST_ALIASNAME
); break;
554 case 3 : init_samr_Name(&r
.in
.info
.description
,
555 "Test Description, should test I18N as well"); break;
558 status
= dcerpc_samr_SetAliasInfo(p
, mem_ctx
, &r
);
559 if (!NT_STATUS_IS_OK(status
)) {
560 printf("SetAliasInfo level %u failed - %s\n",
561 levels
[i
], nt_errstr(status
));
565 q
.in
.alias_handle
= handle
;
566 q
.in
.level
= levels
[i
];
568 status
= dcerpc_samr_QueryAliasInfo(p
, mem_ctx
, &q
);
569 if (!NT_STATUS_IS_OK(status
)) {
570 printf("QueryAliasInfo level %u failed - %s\n",
571 levels
[i
], nt_errstr(status
));
579 static BOOL
test_GetGroupsForUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
580 struct policy_handle
*user_handle
)
582 struct samr_GetGroupsForUser r
;
586 printf("testing GetGroupsForUser\n");
588 r
.in
.user_handle
= user_handle
;
590 status
= dcerpc_samr_GetGroupsForUser(p
, mem_ctx
, &r
);
591 if (!NT_STATUS_IS_OK(status
)) {
592 printf("GetGroupsForUser failed - %s\n",nt_errstr(status
));
600 static BOOL
test_GetDomPwInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
601 struct samr_Name
*domain_name
)
604 struct samr_GetDomPwInfo r
;
607 r
.in
.name
= domain_name
;
608 printf("Testing GetDomPwInfo with name %s\n", r
.in
.name
->name
);
610 status
= dcerpc_samr_GetDomPwInfo(p
, mem_ctx
, &r
);
611 if (!NT_STATUS_IS_OK(status
)) {
612 printf("GetDomPwInfo failed - %s\n", nt_errstr(status
));
616 r
.in
.name
->name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
617 printf("Testing GetDomPwInfo with name %s\n", r
.in
.name
->name
);
619 status
= dcerpc_samr_GetDomPwInfo(p
, mem_ctx
, &r
);
620 if (!NT_STATUS_IS_OK(status
)) {
621 printf("GetDomPwInfo failed - %s\n", nt_errstr(status
));
625 r
.in
.name
->name
= "\\\\__NONAME__";
626 printf("Testing GetDomPwInfo with name %s\n", r
.in
.name
->name
);
628 status
= dcerpc_samr_GetDomPwInfo(p
, mem_ctx
, &r
);
629 if (!NT_STATUS_IS_OK(status
)) {
630 printf("GetDomPwInfo failed - %s\n", nt_errstr(status
));
634 r
.in
.name
->name
= "\\\\Builtin";
635 printf("Testing GetDomPwInfo with name %s\n", r
.in
.name
->name
);
637 status
= dcerpc_samr_GetDomPwInfo(p
, mem_ctx
, &r
);
638 if (!NT_STATUS_IS_OK(status
)) {
639 printf("GetDomPwInfo failed - %s\n", nt_errstr(status
));
647 static BOOL
test_GetUserPwInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
648 struct policy_handle
*handle
)
651 struct samr_GetUserPwInfo r
;
654 printf("Testing GetUserPwInfo\n");
656 r
.in
.user_handle
= handle
;
658 status
= dcerpc_samr_GetUserPwInfo(p
, mem_ctx
, &r
);
659 if (!NT_STATUS_IS_OK(status
)) {
660 printf("GetUserPwInfo failed - %s\n", nt_errstr(status
));
667 static NTSTATUS
test_LookupName(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
668 struct policy_handle
*domain_handle
, const char *name
,
672 struct samr_LookupNames n
;
673 struct samr_Name sname
[2];
675 init_samr_Name(&sname
[0], name
);
677 n
.in
.domain_handle
= domain_handle
;
680 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &n
);
681 if (NT_STATUS_IS_OK(status
)) {
682 *rid
= n
.out
.rids
.ids
[0];
687 init_samr_Name(&sname
[1], "xxNONAMExx");
689 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &n
);
690 if (!NT_STATUS_EQUAL(status
, STATUS_SOME_UNMAPPED
)) {
691 printf("LookupNames[2] failed - %s\n", nt_errstr(status
));
695 init_samr_Name(&sname
[1], "xxNONAMExx");
697 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &n
);
698 if (!NT_STATUS_IS_OK(status
)) {
699 printf("LookupNames[0] failed - %s\n", nt_errstr(status
));
705 static NTSTATUS
test_OpenUser_byname(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
706 struct policy_handle
*domain_handle
,
707 const char *name
, struct policy_handle
*user_handle
)
710 struct samr_OpenUser r
;
713 status
= test_LookupName(p
, mem_ctx
, domain_handle
, name
, &rid
);
714 if (!NT_STATUS_IS_OK(status
)) {
718 r
.in
.domain_handle
= domain_handle
;
719 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
721 r
.out
.user_handle
= user_handle
;
722 status
= dcerpc_samr_OpenUser(p
, mem_ctx
, &r
);
723 if (!NT_STATUS_IS_OK(status
)) {
724 printf("OpenUser_byname(%s) failed - %s\n", name
, nt_errstr(status
));
731 static BOOL
test_ChangePasswordNT3(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
732 struct policy_handle
*handle
)
735 struct samr_ChangePasswordUser r
;
737 struct samr_Password hash1
, hash2
, hash3
, hash4
, hash5
, hash6
;
738 struct policy_handle user_handle
;
739 char *oldpass
= "test";
740 char *newpass
= "test2";
741 uint8_t old_nt_hash
[16], new_nt_hash
[16];
742 uint8_t old_lm_hash
[16], new_lm_hash
[16];
744 status
= test_OpenUser_byname(p
, mem_ctx
, handle
, "testuser", &user_handle
);
745 if (!NT_STATUS_IS_OK(status
)) {
749 printf("Testing ChangePasswordUser for user 'testuser'\n");
751 printf("old password: %s\n", oldpass
);
752 printf("new password: %s\n", newpass
);
754 E_md4hash(oldpass
, old_nt_hash
);
755 E_md4hash(newpass
, new_nt_hash
);
756 E_deshash(oldpass
, old_lm_hash
);
757 E_deshash(newpass
, new_lm_hash
);
759 E_old_pw_hash(new_lm_hash
, old_lm_hash
, hash1
.hash
);
760 E_old_pw_hash(old_lm_hash
, new_lm_hash
, hash2
.hash
);
761 E_old_pw_hash(new_nt_hash
, old_nt_hash
, hash3
.hash
);
762 E_old_pw_hash(old_nt_hash
, new_nt_hash
, hash4
.hash
);
763 E_old_pw_hash(old_lm_hash
, new_nt_hash
, hash5
.hash
);
764 E_old_pw_hash(old_nt_hash
, new_lm_hash
, hash6
.hash
);
766 r
.in
.handle
= &user_handle
;
768 r
.in
.old_lm_crypted
= &hash1
;
769 r
.in
.new_lm_crypted
= &hash2
;
771 r
.in
.old_nt_crypted
= &hash3
;
772 r
.in
.new_nt_crypted
= &hash4
;
773 r
.in
.cross1_present
= 1;
774 r
.in
.nt_cross
= &hash5
;
775 r
.in
.cross2_present
= 1;
776 r
.in
.lm_cross
= &hash6
;
778 status
= dcerpc_samr_ChangePasswordUser(p
, mem_ctx
, &r
);
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("ChangePasswordUser failed - %s\n", nt_errstr(status
));
784 if (!test_Close(p
, mem_ctx
, &user_handle
)) {
792 static BOOL
test_ChangePasswordUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
793 struct policy_handle
*handle
, char **password
)
796 struct samr_ChangePasswordUser r
;
798 struct samr_Password hash1
, hash2
, hash3
, hash4
, hash5
, hash6
;
799 struct policy_handle user_handle
;
800 char *oldpass
= *password
;
801 char *newpass
= samr_rand_pass(mem_ctx
);
802 uint8_t old_nt_hash
[16], new_nt_hash
[16];
803 uint8_t old_lm_hash
[16], new_lm_hash
[16];
805 status
= test_OpenUser_byname(p
, mem_ctx
, handle
, TEST_ACCOUNT_NAME
, &user_handle
);
806 if (!NT_STATUS_IS_OK(status
)) {
810 printf("Testing ChangePasswordUser\n");
812 E_md4hash(oldpass
, old_nt_hash
);
813 E_md4hash(newpass
, new_nt_hash
);
814 E_deshash(oldpass
, old_lm_hash
);
815 E_deshash(newpass
, new_lm_hash
);
817 E_old_pw_hash(new_lm_hash
, old_lm_hash
, hash1
.hash
);
818 E_old_pw_hash(old_lm_hash
, new_lm_hash
, hash2
.hash
);
819 E_old_pw_hash(new_nt_hash
, old_nt_hash
, hash3
.hash
);
820 E_old_pw_hash(old_nt_hash
, new_nt_hash
, hash4
.hash
);
821 E_old_pw_hash(old_lm_hash
, new_nt_hash
, hash5
.hash
);
822 E_old_pw_hash(old_nt_hash
, new_lm_hash
, hash6
.hash
);
824 r
.in
.user_handle
= &user_handle
;
826 r
.in
.old_lm_crypted
= &hash1
;
827 r
.in
.new_lm_crypted
= &hash2
;
829 r
.in
.old_nt_crypted
= &hash3
;
830 r
.in
.new_nt_crypted
= &hash4
;
831 r
.in
.cross1_present
= 1;
832 r
.in
.nt_cross
= &hash5
;
833 r
.in
.cross2_present
= 1;
834 r
.in
.lm_cross
= &hash6
;
836 status
= dcerpc_samr_ChangePasswordUser(p
, mem_ctx
, &r
);
837 if (!NT_STATUS_IS_OK(status
)) {
838 printf("ChangePasswordUser failed - %s\n", nt_errstr(status
));
844 if (!test_Close(p
, mem_ctx
, &user_handle
)) {
852 static BOOL
test_OemChangePasswordUser2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
853 struct policy_handle
*handle
, char **password
)
856 struct samr_OemChangePasswordUser2 r
;
858 struct samr_Password lm_verifier
;
859 struct samr_CryptPassword lm_pass
;
860 struct samr_AsciiName server
, account
;
861 char *oldpass
= *password
;
862 char *newpass
= samr_rand_pass(mem_ctx
);
863 uint8_t old_lm_hash
[16], new_lm_hash
[16];
865 printf("Testing OemChangePasswordUser2\n");
867 server
.name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
868 account
.name
= TEST_ACCOUNT_NAME
;
870 E_deshash(oldpass
, old_lm_hash
);
871 E_deshash(newpass
, new_lm_hash
);
873 encode_pw_buffer(lm_pass
.data
, newpass
, STR_ASCII
);
874 arcfour_crypt(lm_pass
.data
, old_lm_hash
, 516);
875 E_old_pw_hash(new_lm_hash
, old_lm_hash
, lm_verifier
.hash
);
877 r
.in
.server
= &server
;
878 r
.in
.account
= &account
;
879 r
.in
.password
= &lm_pass
;
880 r
.in
.hash
= &lm_verifier
;
882 status
= dcerpc_samr_OemChangePasswordUser2(p
, mem_ctx
, &r
);
883 if (!NT_STATUS_IS_OK(status
)) {
884 printf("OemChangePasswordUser2 failed - %s\n", nt_errstr(status
));
894 static BOOL
test_ChangePasswordUser2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
895 struct policy_handle
*handle
, char **password
)
898 struct samr_ChangePasswordUser2 r
;
900 struct samr_Name server
, account
;
901 struct samr_CryptPassword nt_pass
, lm_pass
;
902 struct samr_Password nt_verifier
, lm_verifier
;
903 char *oldpass
= *password
;
904 char *newpass
= samr_rand_pass(mem_ctx
);
905 uint8_t old_nt_hash
[16], new_nt_hash
[16];
906 uint8_t old_lm_hash
[16], new_lm_hash
[16];
908 printf("Testing ChangePasswordUser2\n");
910 server
.name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
911 init_samr_Name(&account
, TEST_ACCOUNT_NAME
);
913 E_md4hash(oldpass
, old_nt_hash
);
914 E_md4hash(newpass
, new_nt_hash
);
916 E_deshash(oldpass
, old_lm_hash
);
917 E_deshash(newpass
, new_lm_hash
);
919 encode_pw_buffer(lm_pass
.data
, newpass
, STR_ASCII
|STR_TERMINATE
);
920 arcfour_crypt(lm_pass
.data
, old_lm_hash
, 516);
921 E_old_pw_hash(new_lm_hash
, old_lm_hash
, lm_verifier
.hash
);
923 encode_pw_buffer(nt_pass
.data
, newpass
, STR_UNICODE
);
924 arcfour_crypt(nt_pass
.data
, old_nt_hash
, 516);
925 E_old_pw_hash(new_nt_hash
, old_nt_hash
, nt_verifier
.hash
);
927 r
.in
.server
= &server
;
928 r
.in
.account
= &account
;
929 r
.in
.nt_password
= &nt_pass
;
930 r
.in
.nt_verifier
= &nt_verifier
;
932 r
.in
.lm_password
= &lm_pass
;
933 r
.in
.lm_verifier
= &lm_verifier
;
935 status
= dcerpc_samr_ChangePasswordUser2(p
, mem_ctx
, &r
);
936 if (!NT_STATUS_IS_OK(status
)) {
937 printf("ChangePasswordUser2 failed - %s\n", nt_errstr(status
));
947 static BOOL
test_ChangePasswordUser3(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
948 struct policy_handle
*handle
, char **password
)
951 struct samr_ChangePasswordUser3 r
;
953 struct samr_Name server
, account
;
954 struct samr_CryptPassword nt_pass
, lm_pass
;
955 struct samr_Password nt_verifier
, lm_verifier
;
956 char *oldpass
= *password
;
957 char *newpass
= samr_rand_pass(mem_ctx
);
958 uint8_t old_nt_hash
[16], new_nt_hash
[16];
959 uint8_t old_lm_hash
[16], new_lm_hash
[16];
961 printf("Testing ChangePasswordUser3\n");
963 server
.name
= talloc_asprintf(mem_ctx
, "\\\\%s", dcerpc_server_name(p
));
964 init_samr_Name(&account
, TEST_ACCOUNT_NAME
);
966 E_md4hash(oldpass
, old_nt_hash
);
967 E_md4hash(newpass
, new_nt_hash
);
969 E_deshash(oldpass
, old_lm_hash
);
970 E_deshash(newpass
, new_lm_hash
);
972 encode_pw_buffer(lm_pass
.data
, newpass
, STR_UNICODE
);
973 arcfour_crypt(lm_pass
.data
, old_nt_hash
, 516);
974 E_old_pw_hash(new_lm_hash
, old_lm_hash
, lm_verifier
.hash
);
976 encode_pw_buffer(nt_pass
.data
, newpass
, STR_UNICODE
);
977 arcfour_crypt(nt_pass
.data
, old_nt_hash
, 516);
978 E_old_pw_hash(new_nt_hash
, old_nt_hash
, nt_verifier
.hash
);
980 r
.in
.server
= &server
;
981 r
.in
.account
= &account
;
982 r
.in
.nt_password
= &nt_pass
;
983 r
.in
.nt_verifier
= &nt_verifier
;
985 r
.in
.lm_password
= &lm_pass
;
986 r
.in
.lm_verifier
= &lm_verifier
;
987 r
.in
.password3
= NULL
;
989 status
= dcerpc_samr_ChangePasswordUser3(p
, mem_ctx
, &r
);
990 if (!NT_STATUS_IS_OK(status
)) {
991 printf("ChangePasswordUser3 failed - %s\n", nt_errstr(status
));
1001 static BOOL
test_GetMembersInAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1002 struct policy_handle
*alias_handle
)
1004 struct samr_GetMembersInAlias r
;
1005 struct lsa_SidArray sids
;
1009 printf("Testing GetMembersInAlias\n");
1011 r
.in
.alias_handle
= alias_handle
;
1014 status
= dcerpc_samr_GetMembersInAlias(p
, mem_ctx
, &r
);
1015 if (!NT_STATUS_IS_OK(status
)) {
1016 printf("GetMembersInAlias failed - %s\n",
1024 static BOOL
test_AddMemberToAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1025 struct policy_handle
*alias_handle
,
1026 const struct dom_sid
*domain_sid
)
1028 struct samr_AddAliasMember r
;
1029 struct samr_DeleteAliasMember d
;
1032 struct dom_sid
*sid
;
1034 sid
= dom_sid_add_rid(mem_ctx
, domain_sid
, 512);
1036 printf("testing AddAliasMember\n");
1037 r
.in
.alias_handle
= alias_handle
;
1040 status
= dcerpc_samr_AddAliasMember(p
, mem_ctx
, &r
);
1041 if (!NT_STATUS_IS_OK(status
)) {
1042 printf("AddAliasMember failed - %s\n", nt_errstr(status
));
1046 d
.in
.alias_handle
= alias_handle
;
1049 status
= dcerpc_samr_DeleteAliasMember(p
, mem_ctx
, &d
);
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 printf("DelAliasMember failed - %s\n", nt_errstr(status
));
1058 static BOOL
test_AddMultipleMembersToAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1059 struct policy_handle
*alias_handle
)
1061 struct samr_AddMultipleMembersToAlias a
;
1062 struct samr_RemoveMultipleMembersFromAlias r
;
1065 struct lsa_SidArray sids
;
1067 printf("testing AddMultipleMembersToAlias\n");
1068 a
.in
.alias_handle
= alias_handle
;
1072 sids
.sids
= talloc_array_p(mem_ctx
, struct lsa_SidPtr
, 3);
1074 sids
.sids
[0].sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-1-2-3-1");
1075 sids
.sids
[1].sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-1-2-3-2");
1076 sids
.sids
[2].sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-1-2-3-3");
1078 status
= dcerpc_samr_AddMultipleMembersToAlias(p
, mem_ctx
, &a
);
1079 if (!NT_STATUS_IS_OK(status
)) {
1080 printf("AddMultipleMembersToAlias failed - %s\n", nt_errstr(status
));
1085 printf("testing RemoveMultipleMembersFromAlias\n");
1086 r
.in
.alias_handle
= alias_handle
;
1089 status
= dcerpc_samr_RemoveMultipleMembersFromAlias(p
, mem_ctx
, &r
);
1090 if (!NT_STATUS_IS_OK(status
)) {
1091 printf("RemoveMultipleMembersFromAlias failed - %s\n", nt_errstr(status
));
1095 /* strange! removing twice doesn't give any error */
1096 status
= dcerpc_samr_RemoveMultipleMembersFromAlias(p
, mem_ctx
, &r
);
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 printf("RemoveMultipleMembersFromAlias failed - %s\n", nt_errstr(status
));
1102 /* but removing an alias that isn't there does */
1103 sids
.sids
[2].sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-1-2-3-4");
1105 status
= dcerpc_samr_RemoveMultipleMembersFromAlias(p
, mem_ctx
, &r
);
1106 if (!NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND
, status
)) {
1107 printf("RemoveMultipleMembersFromAlias failed - %s\n", nt_errstr(status
));
1114 static BOOL
test_TestPrivateFunctionsUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1115 struct policy_handle
*user_handle
)
1117 struct samr_TestPrivateFunctionsUser r
;
1121 printf("Testing TestPrivateFunctionsUser\n");
1123 r
.in
.user_handle
= user_handle
;
1125 status
= dcerpc_samr_TestPrivateFunctionsUser(p
, mem_ctx
, &r
);
1126 if (!NT_STATUS_EQUAL(NT_STATUS_NOT_IMPLEMENTED
, status
)) {
1127 printf("TestPrivateFunctionsUser failed - %s\n", nt_errstr(status
));
1135 static BOOL
test_user_ops(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1136 struct policy_handle
*handle
)
1140 if (!test_QuerySecurity(p
, mem_ctx
, handle
)) {
1144 if (!test_QueryUserInfo(p
, mem_ctx
, handle
)) {
1148 if (!test_QueryUserInfo2(p
, mem_ctx
, handle
)) {
1152 if (!test_SetUserInfo(p
, mem_ctx
, handle
)) {
1156 if (!test_GetUserPwInfo(p
, mem_ctx
, handle
)) {
1160 if (!test_TestPrivateFunctionsUser(p
, mem_ctx
, handle
)) {
1167 static BOOL
test_alias_ops(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1168 struct policy_handle
*alias_handle
,
1169 const struct dom_sid
*domain_sid
)
1173 if (!test_QuerySecurity(p
, mem_ctx
, alias_handle
)) {
1177 if (!test_QueryAliasInfo(p
, mem_ctx
, alias_handle
)) {
1181 if (!test_SetAliasInfo(p
, mem_ctx
, alias_handle
)) {
1185 if (!test_AddMemberToAlias(p
, mem_ctx
, alias_handle
, domain_sid
)) {
1189 if (!test_AddMultipleMembersToAlias(p
, mem_ctx
, alias_handle
)) {
1197 BOOL
test_DeleteUser_byname(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1198 struct policy_handle
*handle
, const char *name
)
1201 struct samr_DeleteUser d
;
1202 struct policy_handle user_handle
;
1205 status
= test_LookupName(p
, mem_ctx
, handle
, name
, &rid
);
1206 if (!NT_STATUS_IS_OK(status
)) {
1210 status
= test_OpenUser_byname(p
, mem_ctx
, handle
, name
, &user_handle
);
1211 if (!NT_STATUS_IS_OK(status
)) {
1215 d
.in
.user_handle
= &user_handle
;
1216 d
.out
.user_handle
= &user_handle
;
1217 status
= dcerpc_samr_DeleteUser(p
, mem_ctx
, &d
);
1218 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("DeleteUser_byname(%s) failed - %s\n", name
, nt_errstr(status
));
1230 static BOOL
test_DeleteGroup_byname(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1231 struct policy_handle
*handle
, const char *name
)
1234 struct samr_OpenGroup r
;
1235 struct samr_DeleteDomainGroup d
;
1236 struct policy_handle group_handle
;
1239 status
= test_LookupName(p
, mem_ctx
, handle
, name
, &rid
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1244 r
.in
.domain_handle
= handle
;
1245 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1247 r
.out
.group_handle
= &group_handle
;
1248 status
= dcerpc_samr_OpenGroup(p
, mem_ctx
, &r
);
1249 if (!NT_STATUS_IS_OK(status
)) {
1253 d
.in
.group_handle
= &group_handle
;
1254 d
.out
.group_handle
= &group_handle
;
1255 status
= dcerpc_samr_DeleteDomainGroup(p
, mem_ctx
, &d
);
1256 if (!NT_STATUS_IS_OK(status
)) {
1263 printf("DeleteGroup_byname(%s) failed - %s\n", name
, nt_errstr(status
));
1268 static BOOL
test_DeleteAlias_byname(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1269 struct policy_handle
*domain_handle
, const char *name
)
1272 struct samr_OpenAlias r
;
1273 struct samr_DeleteDomAlias d
;
1274 struct policy_handle alias_handle
;
1277 printf("testing DeleteAlias_byname\n");
1279 status
= test_LookupName(p
, mem_ctx
, domain_handle
, name
, &rid
);
1280 if (!NT_STATUS_IS_OK(status
)) {
1284 r
.in
.domain_handle
= domain_handle
;
1285 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1287 r
.out
.alias_handle
= &alias_handle
;
1288 status
= dcerpc_samr_OpenAlias(p
, mem_ctx
, &r
);
1289 if (!NT_STATUS_IS_OK(status
)) {
1293 d
.in
.alias_handle
= &alias_handle
;
1294 d
.out
.alias_handle
= &alias_handle
;
1295 status
= dcerpc_samr_DeleteDomAlias(p
, mem_ctx
, &d
);
1296 if (!NT_STATUS_IS_OK(status
)) {
1303 printf("DeleteUser_byname(%s) failed - %s\n", name
, nt_errstr(status
));
1307 static BOOL
test_DeleteAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1308 struct policy_handle
*alias_handle
)
1310 struct samr_DeleteDomAlias d
;
1313 printf("Testing DeleteAlias\n");
1315 d
.in
.alias_handle
= alias_handle
;
1316 d
.out
.alias_handle
= alias_handle
;
1318 status
= dcerpc_samr_DeleteDomAlias(p
, mem_ctx
, &d
);
1319 if (!NT_STATUS_IS_OK(status
)) {
1320 printf("DeleteAlias failed - %s\n", nt_errstr(status
));
1327 static BOOL
test_CreateAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1328 struct policy_handle
*domain_handle
,
1329 struct policy_handle
*alias_handle
,
1330 const struct dom_sid
*domain_sid
)
1333 struct samr_CreateDomAlias r
;
1334 struct samr_Name name
;
1338 init_samr_Name(&name
, TEST_ALIASNAME
);
1339 r
.in
.domain_handle
= domain_handle
;
1340 r
.in
.aliasname
= &name
;
1341 r
.in
.access_mask
= SEC_RIGHT_MAXIMUM_ALLOWED
;
1342 r
.out
.alias_handle
= alias_handle
;
1345 printf("Testing CreateAlias (%s)\n", r
.in
.aliasname
->name
);
1347 status
= dcerpc_samr_CreateDomAlias(p
, mem_ctx
, &r
);
1349 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
1350 printf("Server refused create of '%s'\n", r
.in
.aliasname
->name
);
1354 if (NT_STATUS_EQUAL(status
, NT_STATUS_ALIAS_EXISTS
)) {
1355 if (!test_DeleteAlias_byname(p
, mem_ctx
, domain_handle
, r
.in
.aliasname
->name
)) {
1358 status
= dcerpc_samr_CreateDomAlias(p
, mem_ctx
, &r
);
1361 if (!NT_STATUS_IS_OK(status
)) {
1362 printf("CreateAlias failed - %s\n", nt_errstr(status
));
1366 if (!test_alias_ops(p
, mem_ctx
, alias_handle
, domain_sid
)) {
1373 static BOOL
test_ChangePassword(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1374 struct policy_handle
*domain_handle
, char **password
)
1382 if (!test_ChangePasswordUser(p
, mem_ctx
, domain_handle
, password
)) {
1386 if (!test_ChangePasswordUser2(p
, mem_ctx
, domain_handle
, password
)) {
1390 if (!test_OemChangePasswordUser2(p
, mem_ctx
, domain_handle
, password
)) {
1394 if (!test_ChangePasswordUser3(p
, mem_ctx
, domain_handle
, password
)) {
1401 static BOOL
test_CreateUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1402 struct policy_handle
*domain_handle
, struct policy_handle
*user_handle
)
1405 struct samr_CreateUser r
;
1406 struct samr_QueryUserInfo q
;
1408 char *password
= NULL
;
1410 /* This call creates a 'normal' account - check that it really does */
1411 const uint32_t acct_flags
= ACB_NORMAL
;
1412 struct samr_Name name
;
1415 init_samr_Name(&name
, TEST_ACCOUNT_NAME
);
1417 r
.in
.domain_handle
= domain_handle
;
1418 r
.in
.account_name
= &name
;
1419 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1420 r
.out
.user_handle
= user_handle
;
1423 printf("Testing CreateUser(%s)\n", r
.in
.account_name
->name
);
1425 status
= dcerpc_samr_CreateUser(p
, mem_ctx
, &r
);
1427 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
1428 printf("Server refused create of '%s'\n", r
.in
.account_name
->name
);
1429 ZERO_STRUCTP(user_handle
);
1433 if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
1434 if (!test_DeleteUser_byname(p
, mem_ctx
, domain_handle
, r
.in
.account_name
->name
)) {
1437 status
= dcerpc_samr_CreateUser(p
, mem_ctx
, &r
);
1439 if (!NT_STATUS_IS_OK(status
)) {
1440 printf("CreateUser failed - %s\n", nt_errstr(status
));
1444 q
.in
.user_handle
= user_handle
;
1447 status
= dcerpc_samr_QueryUserInfo(p
, mem_ctx
, &q
);
1448 if (!NT_STATUS_IS_OK(status
)) {
1449 printf("QueryUserInfo level %u failed - %s\n",
1450 q
.in
.level
, nt_errstr(status
));
1453 if ((q
.out
.info
->info16
.acct_flags
& acct_flags
) != acct_flags
) {
1454 printf("QuerUserInfo level 16 failed, it returned 0x%08x (%u) when we expected flags of 0x%08x (%u)\n",
1455 q
.out
.info
->info16
.acct_flags
, q
.out
.info
->info16
.acct_flags
,
1456 acct_flags
, acct_flags
);
1461 if (!test_user_ops(p
, mem_ctx
, user_handle
)) {
1465 if (!test_SetUserPass(p
, mem_ctx
, user_handle
, &password
)) {
1469 if (!test_SetUserPass_23(p
, mem_ctx
, user_handle
, &password
)) {
1473 if (!test_SetUserPassEx(p
, mem_ctx
, user_handle
, &password
)) {
1477 if (!test_SetUserPass_25(p
, mem_ctx
, user_handle
, &password
)) {
1481 /* we change passwords twice - this has the effect of verifying
1482 they were changed correctly */
1483 if (!test_ChangePassword(p
, mem_ctx
, domain_handle
, &password
)) {
1487 if (!test_ChangePassword(p
, mem_ctx
, domain_handle
, &password
)) {
1496 static BOOL
test_DeleteUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1497 struct policy_handle
*user_handle
)
1499 struct samr_DeleteUser d
;
1503 printf("Testing DeleteUser\n");
1505 d
.in
.user_handle
= user_handle
;
1506 d
.out
.user_handle
= user_handle
;
1508 status
= dcerpc_samr_DeleteUser(p
, mem_ctx
, &d
);
1509 if (!NT_STATUS_IS_OK(status
)) {
1510 printf("DeleteUser failed - %s\n", nt_errstr(status
));
1517 static BOOL
test_CreateUser2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1518 struct policy_handle
*handle
)
1521 struct samr_CreateUser2 r
;
1522 struct samr_QueryUserInfo q
;
1523 struct samr_DeleteUser d
;
1524 struct policy_handle user_handle
;
1526 struct samr_Name name
;
1531 uint32_t acct_flags
;
1532 const char *account_name
;
1534 } account_types
[] = {
1535 { ACB_NORMAL
, TEST_ACCOUNT_NAME
, NT_STATUS_OK
},
1536 { ACB_NORMAL
| ACB_DISABLED
, TEST_ACCOUNT_NAME
, NT_STATUS_INVALID_PARAMETER
},
1537 { ACB_NORMAL
| ACB_PWNOEXP
, TEST_ACCOUNT_NAME
, NT_STATUS_INVALID_PARAMETER
},
1538 { ACB_WSTRUST
, TEST_MACHINENAME
, NT_STATUS_OK
},
1539 { ACB_WSTRUST
| ACB_DISABLED
, TEST_MACHINENAME
, NT_STATUS_INVALID_PARAMETER
},
1540 { ACB_WSTRUST
| ACB_PWNOEXP
, TEST_MACHINENAME
, NT_STATUS_INVALID_PARAMETER
},
1541 { ACB_SVRTRUST
, TEST_MACHINENAME
, NT_STATUS_OK
},
1542 { ACB_SVRTRUST
| ACB_DISABLED
, TEST_MACHINENAME
, NT_STATUS_INVALID_PARAMETER
},
1543 { ACB_SVRTRUST
| ACB_PWNOEXP
, TEST_MACHINENAME
, NT_STATUS_INVALID_PARAMETER
},
1544 { ACB_DOMTRUST
, TEST_DOMAINNAME
, NT_STATUS_OK
},
1545 { ACB_DOMTRUST
| ACB_DISABLED
, TEST_DOMAINNAME
, NT_STATUS_INVALID_PARAMETER
},
1546 { ACB_DOMTRUST
| ACB_PWNOEXP
, TEST_DOMAINNAME
, NT_STATUS_INVALID_PARAMETER
},
1547 { 0, TEST_ACCOUNT_NAME
, NT_STATUS_INVALID_PARAMETER
},
1548 { ACB_DISABLED
, TEST_ACCOUNT_NAME
, NT_STATUS_INVALID_PARAMETER
},
1549 { 0, NULL
, NT_STATUS_INVALID_PARAMETER
}
1552 for (i
= 0; account_types
[i
].account_name
; i
++) {
1553 uint32_t acct_flags
= account_types
[i
].acct_flags
;
1554 uint32_t access_granted
;
1556 init_samr_Name(&name
, account_types
[i
].account_name
);
1558 r
.in
.domain_handle
= handle
;
1559 r
.in
.account_name
= &name
;
1560 r
.in
.acct_flags
= acct_flags
;
1561 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1562 r
.out
.user_handle
= &user_handle
;
1563 r
.out
.access_granted
= &access_granted
;
1566 printf("Testing CreateUser2(%s)\n", r
.in
.account_name
->name
);
1568 status
= dcerpc_samr_CreateUser2(p
, mem_ctx
, &r
);
1570 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
1571 printf("Server refused create of '%s'\n", r
.in
.account_name
->name
);
1574 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
1575 if (!test_DeleteUser_byname(p
, mem_ctx
, handle
, r
.in
.account_name
->name
)) {
1578 status
= dcerpc_samr_CreateUser2(p
, mem_ctx
, &r
);
1581 if (!NT_STATUS_EQUAL(status
, account_types
[i
].nt_status
)) {
1582 printf("CreateUser2 failed gave incorrect error return - %s (should be %s)\n",
1583 nt_errstr(status
), nt_errstr(account_types
[i
].nt_status
));
1587 if (NT_STATUS_IS_OK(status
)) {
1588 q
.in
.user_handle
= &user_handle
;
1591 status
= dcerpc_samr_QueryUserInfo(p
, mem_ctx
, &q
);
1592 if (!NT_STATUS_IS_OK(status
)) {
1593 printf("QueryUserInfo level %u failed - %s\n",
1594 q
.in
.level
, nt_errstr(status
));
1597 if ((q
.out
.info
->info16
.acct_flags
& acct_flags
) != acct_flags
) {
1598 printf("QuerUserInfo level 16 failed, it returned 0x%08x when we expected flags of 0x%08x\n",
1599 q
.out
.info
->info16
.acct_flags
,
1605 if (!test_user_ops(p
, mem_ctx
, &user_handle
)) {
1609 printf("Testing DeleteUser (createuser2 test)\n");
1611 d
.in
.user_handle
= &user_handle
;
1612 d
.out
.user_handle
= &user_handle
;
1614 status
= dcerpc_samr_DeleteUser(p
, mem_ctx
, &d
);
1615 if (!NT_STATUS_IS_OK(status
)) {
1616 printf("DeleteUser failed - %s\n", nt_errstr(status
));
1625 static BOOL
test_QueryAliasInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1626 struct policy_handle
*handle
)
1629 struct samr_QueryAliasInfo r
;
1630 uint16_t levels
[] = {1, 2, 3};
1634 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1635 printf("Testing QueryAliasInfo level %u\n", levels
[i
]);
1637 r
.in
.alias_handle
= handle
;
1638 r
.in
.level
= levels
[i
];
1640 status
= dcerpc_samr_QueryAliasInfo(p
, mem_ctx
, &r
);
1641 if (!NT_STATUS_IS_OK(status
)) {
1642 printf("QueryAliasInfo level %u failed - %s\n",
1643 levels
[i
], nt_errstr(status
));
1651 static BOOL
test_QueryGroupInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1652 struct policy_handle
*handle
)
1655 struct samr_QueryGroupInfo r
;
1656 uint16_t levels
[] = {1, 2, 3, 4};
1660 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1661 printf("Testing QueryGroupInfo level %u\n", levels
[i
]);
1663 r
.in
.group_handle
= handle
;
1664 r
.in
.level
= levels
[i
];
1666 status
= dcerpc_samr_QueryGroupInfo(p
, mem_ctx
, &r
);
1667 if (!NT_STATUS_IS_OK(status
)) {
1668 printf("QueryGroupInfo level %u failed - %s\n",
1669 levels
[i
], nt_errstr(status
));
1678 static BOOL
test_SetGroupInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1679 struct policy_handle
*handle
)
1682 struct samr_QueryGroupInfo r
;
1683 struct samr_SetGroupInfo s
;
1684 uint16_t levels
[] = {1, 2, 3, 4};
1685 uint16_t set_ok
[] = {0, 1, 1, 1};
1689 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1690 printf("Testing QueryGroupInfo level %u\n", levels
[i
]);
1692 r
.in
.group_handle
= handle
;
1693 r
.in
.level
= levels
[i
];
1695 status
= dcerpc_samr_QueryGroupInfo(p
, mem_ctx
, &r
);
1696 if (!NT_STATUS_IS_OK(status
)) {
1697 printf("QueryGroupInfo level %u failed - %s\n",
1698 levels
[i
], nt_errstr(status
));
1702 printf("Testing SetGroupInfo level %u\n", levels
[i
]);
1704 s
.in
.group_handle
= handle
;
1705 s
.in
.level
= levels
[i
];
1706 s
.in
.info
= r
.out
.info
;
1709 /* disabled this, as it changes the name only from the point of view of samr,
1710 but leaves the name from the point of view of w2k3 internals (and ldap). This means
1711 the name is still reserved, so creating the old name fails, but deleting by the old name
1713 if (s
.in
.level
== 2) {
1714 init_samr_Name(&s
.in
.info
->name
, "NewName");
1718 if (s
.in
.level
== 4) {
1719 init_samr_Name(&s
.in
.info
->description
, "test description");
1722 status
= dcerpc_samr_SetGroupInfo(p
, mem_ctx
, &s
);
1724 if (!NT_STATUS_IS_OK(status
)) {
1725 printf("SetGroupInfo level %u failed - %s\n",
1726 r
.in
.level
, nt_errstr(status
));
1731 if (!NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS
, status
)) {
1732 printf("SetGroupInfo level %u gave %s - should have been NT_STATUS_INVALID_INFO_CLASS\n",
1733 r
.in
.level
, nt_errstr(status
));
1743 static BOOL
test_QueryUserInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1744 struct policy_handle
*handle
)
1747 struct samr_QueryUserInfo r
;
1748 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1749 11, 12, 13, 14, 16, 17, 20, 21};
1753 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1754 printf("Testing QueryUserInfo level %u\n", levels
[i
]);
1756 r
.in
.user_handle
= handle
;
1757 r
.in
.level
= levels
[i
];
1759 status
= dcerpc_samr_QueryUserInfo(p
, mem_ctx
, &r
);
1760 if (!NT_STATUS_IS_OK(status
)) {
1761 printf("QueryUserInfo level %u failed - %s\n",
1762 levels
[i
], nt_errstr(status
));
1770 static BOOL
test_QueryUserInfo2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1771 struct policy_handle
*handle
)
1774 struct samr_QueryUserInfo2 r
;
1775 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1776 11, 12, 13, 14, 16, 17, 20, 21};
1780 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1781 printf("Testing QueryUserInfo2 level %u\n", levels
[i
]);
1783 r
.in
.user_handle
= handle
;
1784 r
.in
.level
= levels
[i
];
1786 status
= dcerpc_samr_QueryUserInfo2(p
, mem_ctx
, &r
);
1787 if (!NT_STATUS_IS_OK(status
)) {
1788 printf("QueryUserInfo2 level %u failed - %s\n",
1789 levels
[i
], nt_errstr(status
));
1797 static BOOL
test_OpenUser(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1798 struct policy_handle
*handle
, uint32_t rid
)
1801 struct samr_OpenUser r
;
1802 struct policy_handle user_handle
;
1805 printf("Testing OpenUser(%u)\n", rid
);
1807 r
.in
.domain_handle
= handle
;
1808 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1810 r
.out
.user_handle
= &user_handle
;
1812 status
= dcerpc_samr_OpenUser(p
, mem_ctx
, &r
);
1813 if (!NT_STATUS_IS_OK(status
)) {
1814 printf("OpenUser(%u) failed - %s\n", rid
, nt_errstr(status
));
1818 if (!test_QuerySecurity(p
, mem_ctx
, &user_handle
)) {
1822 if (!test_QueryUserInfo(p
, mem_ctx
, &user_handle
)) {
1826 if (!test_QueryUserInfo2(p
, mem_ctx
, &user_handle
)) {
1830 if (!test_GetUserPwInfo(p
, mem_ctx
, &user_handle
)) {
1834 if (!test_GetGroupsForUser(p
,mem_ctx
, &user_handle
)) {
1838 if (!test_Close(p
, mem_ctx
, &user_handle
)) {
1845 static BOOL
test_OpenGroup(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1846 struct policy_handle
*handle
, uint32_t rid
)
1849 struct samr_OpenGroup r
;
1850 struct policy_handle group_handle
;
1853 printf("Testing OpenGroup(%u)\n", rid
);
1855 r
.in
.domain_handle
= handle
;
1856 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1858 r
.out
.group_handle
= &group_handle
;
1860 status
= dcerpc_samr_OpenGroup(p
, mem_ctx
, &r
);
1861 if (!NT_STATUS_IS_OK(status
)) {
1862 printf("OpenGroup(%u) failed - %s\n", rid
, nt_errstr(status
));
1866 if (!test_QuerySecurity(p
, mem_ctx
, &group_handle
)) {
1870 if (!test_QueryGroupInfo(p
, mem_ctx
, &group_handle
)) {
1874 if (!test_Close(p
, mem_ctx
, &group_handle
)) {
1881 static BOOL
test_OpenAlias(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1882 struct policy_handle
*handle
, uint32_t rid
)
1885 struct samr_OpenAlias r
;
1886 struct policy_handle alias_handle
;
1889 printf("Testing OpenAlias(%u)\n", rid
);
1891 r
.in
.domain_handle
= handle
;
1892 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1894 r
.out
.alias_handle
= &alias_handle
;
1896 status
= dcerpc_samr_OpenAlias(p
, mem_ctx
, &r
);
1897 if (!NT_STATUS_IS_OK(status
)) {
1898 printf("OpenAlias(%u) failed - %s\n", rid
, nt_errstr(status
));
1902 if (!test_QuerySecurity(p
, mem_ctx
, &alias_handle
)) {
1906 if (!test_QueryAliasInfo(p
, mem_ctx
, &alias_handle
)) {
1910 if (!test_GetMembersInAlias(p
, mem_ctx
, &alias_handle
)) {
1914 if (!test_Close(p
, mem_ctx
, &alias_handle
)) {
1921 static BOOL
test_EnumDomainUsers(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1922 struct policy_handle
*handle
)
1925 struct samr_EnumDomainUsers r
;
1926 uint32_t resume_handle
=0;
1929 struct samr_LookupNames n
;
1930 struct samr_LookupRids lr
;
1932 printf("Testing EnumDomainUsers\n");
1934 r
.in
.domain_handle
= handle
;
1935 r
.in
.resume_handle
= &resume_handle
;
1936 r
.in
.acct_flags
= 0;
1937 r
.in
.max_size
= (uint32_t)-1;
1938 r
.out
.resume_handle
= &resume_handle
;
1940 status
= dcerpc_samr_EnumDomainUsers(p
, mem_ctx
, &r
);
1941 if (!NT_STATUS_IS_OK(status
)) {
1942 printf("EnumDomainUsers failed - %s\n", nt_errstr(status
));
1950 if (r
.out
.sam
->count
== 0) {
1954 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
1955 if (!test_OpenUser(p
, mem_ctx
, handle
, r
.out
.sam
->entries
[i
].idx
)) {
1960 printf("Testing LookupNames\n");
1961 n
.in
.domain_handle
= handle
;
1962 n
.in
.num_names
= r
.out
.sam
->count
;
1963 n
.in
.names
= talloc(mem_ctx
, r
.out
.sam
->count
* sizeof(struct samr_Name
));
1964 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
1965 n
.in
.names
[i
] = r
.out
.sam
->entries
[i
].name
;
1967 status
= dcerpc_samr_LookupNames(p
, mem_ctx
, &n
);
1968 if (!NT_STATUS_IS_OK(status
)) {
1969 printf("LookupNames failed - %s\n", nt_errstr(status
));
1974 printf("Testing LookupRids\n");
1975 lr
.in
.domain_handle
= handle
;
1976 lr
.in
.num_rids
= r
.out
.sam
->count
;
1977 lr
.in
.rids
= talloc(mem_ctx
, r
.out
.sam
->count
* sizeof(uint32_t));
1978 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
1979 lr
.in
.rids
[i
] = r
.out
.sam
->entries
[i
].idx
;
1981 status
= dcerpc_samr_LookupRids(p
, mem_ctx
, &lr
);
1982 if (!NT_STATUS_IS_OK(status
)) {
1983 printf("LookupRids failed - %s\n", nt_errstr(status
));
1991 try blasting the server with a bunch of sync requests
1993 static BOOL
test_EnumDomainUsers_async(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
1994 struct policy_handle
*handle
)
1997 struct samr_EnumDomainUsers r
;
1998 uint32_t resume_handle
=0;
2000 #define ASYNC_COUNT 100
2001 struct rpc_request
*req
[ASYNC_COUNT
];
2003 if (lp_parm_int(-1, "torture", "dangerous") != 1) {
2004 printf("samr async test disabled - enable dangerous tests to use\n");
2008 printf("Testing EnumDomainUsers_async\n");
2010 r
.in
.domain_handle
= handle
;
2011 r
.in
.resume_handle
= &resume_handle
;
2012 r
.in
.acct_flags
= 0;
2013 r
.in
.max_size
= (uint32_t)-1;
2014 r
.out
.resume_handle
= &resume_handle
;
2016 for (i
=0;i
<ASYNC_COUNT
;i
++) {
2017 req
[i
] = dcerpc_samr_EnumDomainUsers_send(p
, mem_ctx
, &r
);
2020 for (i
=0;i
<ASYNC_COUNT
;i
++) {
2021 status
= dcerpc_ndr_request_recv(req
[i
]);
2022 if (!NT_STATUS_IS_OK(status
)) {
2023 printf("EnumDomainUsers[%d] failed - %s\n",
2024 i
, nt_errstr(status
));
2029 printf("%d async requests OK\n", i
);
2034 static BOOL
test_EnumDomainGroups(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2035 struct policy_handle
*handle
)
2038 struct samr_EnumDomainGroups r
;
2039 uint32_t resume_handle
=0;
2043 printf("Testing EnumDomainGroups\n");
2045 r
.in
.domain_handle
= handle
;
2046 r
.in
.resume_handle
= &resume_handle
;
2047 r
.in
.max_size
= (uint32_t)-1;
2048 r
.out
.resume_handle
= &resume_handle
;
2050 status
= dcerpc_samr_EnumDomainGroups(p
, mem_ctx
, &r
);
2051 if (!NT_STATUS_IS_OK(status
)) {
2052 printf("EnumDomainGroups failed - %s\n", nt_errstr(status
));
2060 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
2061 if (!test_OpenGroup(p
, mem_ctx
, handle
, r
.out
.sam
->entries
[i
].idx
)) {
2069 static BOOL
test_EnumDomainAliases(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2070 struct policy_handle
*handle
)
2073 struct samr_EnumDomainAliases r
;
2074 uint32_t resume_handle
=0;
2078 printf("Testing EnumDomainAliases\n");
2080 r
.in
.domain_handle
= handle
;
2081 r
.in
.resume_handle
= &resume_handle
;
2082 r
.in
.acct_flags
= (uint32_t)-1;
2083 r
.out
.resume_handle
= &resume_handle
;
2085 status
= dcerpc_samr_EnumDomainAliases(p
, mem_ctx
, &r
);
2086 if (!NT_STATUS_IS_OK(status
)) {
2087 printf("EnumDomainAliases failed - %s\n", nt_errstr(status
));
2095 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
2096 if (!test_OpenAlias(p
, mem_ctx
, handle
, r
.out
.sam
->entries
[i
].idx
)) {
2104 static BOOL
test_GetDisplayEnumerationIndex(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2105 struct policy_handle
*handle
)
2108 struct samr_GetDisplayEnumerationIndex r
;
2110 uint16_t levels
[] = {1, 2, 3, 4, 5};
2111 uint16_t ok_lvl
[] = {1, 1, 1, 0, 0};
2114 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2115 printf("Testing GetDisplayEnumerationIndex level %u\n", levels
[i
]);
2117 r
.in
.domain_handle
= handle
;
2118 r
.in
.level
= levels
[i
];
2119 init_samr_Name(&r
.in
.name
, TEST_ACCOUNT_NAME
);
2121 status
= dcerpc_samr_GetDisplayEnumerationIndex(p
, mem_ctx
, &r
);
2124 !NT_STATUS_IS_OK(status
) &&
2125 !NT_STATUS_EQUAL(NT_STATUS_NO_MORE_ENTRIES
, status
)) {
2126 printf("GetDisplayEnumerationIndex level %u failed - %s\n",
2127 levels
[i
], nt_errstr(status
));
2131 init_samr_Name(&r
.in
.name
, "zzzzzzzz");
2133 status
= dcerpc_samr_GetDisplayEnumerationIndex(p
, mem_ctx
, &r
);
2135 if (ok_lvl
[i
] && !NT_STATUS_EQUAL(NT_STATUS_NO_MORE_ENTRIES
, status
)) {
2136 printf("GetDisplayEnumerationIndex level %u failed - %s\n",
2137 levels
[i
], nt_errstr(status
));
2145 static BOOL
test_GetDisplayEnumerationIndex2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2146 struct policy_handle
*handle
)
2149 struct samr_GetDisplayEnumerationIndex2 r
;
2151 uint16_t levels
[] = {1, 2, 3, 4, 5};
2152 uint16_t ok_lvl
[] = {1, 1, 1, 0, 0};
2155 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2156 printf("Testing GetDisplayEnumerationIndex2 level %u\n", levels
[i
]);
2158 r
.in
.domain_handle
= handle
;
2159 r
.in
.level
= levels
[i
];
2160 init_samr_Name(&r
.in
.name
, TEST_ACCOUNT_NAME
);
2162 status
= dcerpc_samr_GetDisplayEnumerationIndex2(p
, mem_ctx
, &r
);
2164 !NT_STATUS_IS_OK(status
) &&
2165 !NT_STATUS_EQUAL(NT_STATUS_NO_MORE_ENTRIES
, status
)) {
2166 printf("GetDisplayEnumerationIndex2 level %u failed - %s\n",
2167 levels
[i
], nt_errstr(status
));
2171 init_samr_Name(&r
.in
.name
, "zzzzzzzz");
2173 status
= dcerpc_samr_GetDisplayEnumerationIndex2(p
, mem_ctx
, &r
);
2174 if (ok_lvl
[i
] && !NT_STATUS_EQUAL(NT_STATUS_NO_MORE_ENTRIES
, status
)) {
2175 printf("GetDisplayEnumerationIndex2 level %u failed - %s\n",
2176 levels
[i
], nt_errstr(status
));
2184 static BOOL
test_QueryDisplayInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2185 struct policy_handle
*handle
)
2188 struct samr_QueryDisplayInfo r
;
2190 uint16_t levels
[] = {1, 2, 3, 4, 5};
2193 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2194 printf("Testing QueryDisplayInfo level %u\n", levels
[i
]);
2196 r
.in
.domain_handle
= handle
;
2197 r
.in
.level
= levels
[i
];
2199 r
.in
.max_entries
= 1000;
2200 r
.in
.buf_size
= (uint32_t)-1;
2202 status
= dcerpc_samr_QueryDisplayInfo(p
, mem_ctx
, &r
);
2203 if (!NT_STATUS_IS_OK(status
)) {
2204 printf("QueryDisplayInfo level %u failed - %s\n",
2205 levels
[i
], nt_errstr(status
));
2213 static BOOL
test_QueryDisplayInfo2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2214 struct policy_handle
*handle
)
2217 struct samr_QueryDisplayInfo2 r
;
2219 uint16_t levels
[] = {1, 2, 3, 4, 5};
2222 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2223 printf("Testing QueryDisplayInfo2 level %u\n", levels
[i
]);
2225 r
.in
.domain_handle
= handle
;
2226 r
.in
.level
= levels
[i
];
2228 r
.in
.max_entries
= 1000;
2229 r
.in
.buf_size
= (uint32_t)-1;
2231 status
= dcerpc_samr_QueryDisplayInfo2(p
, mem_ctx
, &r
);
2232 if (!NT_STATUS_IS_OK(status
)) {
2233 printf("QueryDisplayInfo2 level %u failed - %s\n",
2234 levels
[i
], nt_errstr(status
));
2242 static BOOL
test_QueryDisplayInfo3(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2243 struct policy_handle
*handle
)
2246 struct samr_QueryDisplayInfo3 r
;
2248 uint16_t levels
[] = {1, 2, 3, 4, 5};
2251 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2252 printf("Testing QueryDisplayInfo3 level %u\n", levels
[i
]);
2254 r
.in
.domain_handle
= handle
;
2255 r
.in
.level
= levels
[i
];
2257 r
.in
.max_entries
= 1000;
2258 r
.in
.buf_size
= (uint32_t)-1;
2260 status
= dcerpc_samr_QueryDisplayInfo3(p
, mem_ctx
, &r
);
2261 if (!NT_STATUS_IS_OK(status
)) {
2262 printf("QueryDisplayInfo3 level %u failed - %s\n",
2263 levels
[i
], nt_errstr(status
));
2271 static BOOL
test_QueryDomainInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2272 struct policy_handle
*handle
)
2275 struct samr_QueryDomainInfo r
;
2276 struct samr_SetDomainInfo s
;
2277 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
2278 uint16_t set_ok
[] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0};
2282 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2283 printf("Testing QueryDomainInfo level %u\n", levels
[i
]);
2285 r
.in
.domain_handle
= handle
;
2286 r
.in
.level
= levels
[i
];
2288 status
= dcerpc_samr_QueryDomainInfo(p
, mem_ctx
, &r
);
2289 if (!NT_STATUS_IS_OK(status
)) {
2290 printf("QueryDomainInfo level %u failed - %s\n",
2291 r
.in
.level
, nt_errstr(status
));
2296 printf("Testing SetDomainInfo level %u\n", levels
[i
]);
2298 s
.in
.domain_handle
= handle
;
2299 s
.in
.level
= levels
[i
];
2300 s
.in
.info
= r
.out
.info
;
2302 status
= dcerpc_samr_SetDomainInfo(p
, mem_ctx
, &s
);
2304 if (!NT_STATUS_IS_OK(status
)) {
2305 printf("SetDomainInfo level %u failed - %s\n",
2306 r
.in
.level
, nt_errstr(status
));
2311 if (!NT_STATUS_EQUAL(NT_STATUS_INVALID_INFO_CLASS
, status
)) {
2312 printf("SetDomainInfo level %u gave %s - should have been NT_STATUS_INVALID_INFO_CLASS\n",
2313 r
.in
.level
, nt_errstr(status
));
2319 status
= dcerpc_samr_QueryDomainInfo(p
, mem_ctx
, &r
);
2320 if (!NT_STATUS_IS_OK(status
)) {
2321 printf("QueryDomainInfo level %u failed - %s\n",
2322 r
.in
.level
, nt_errstr(status
));
2332 static BOOL
test_QueryDomainInfo2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2333 struct policy_handle
*handle
)
2336 struct samr_QueryDomainInfo2 r
;
2337 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13};
2341 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2342 printf("Testing QueryDomainInfo2 level %u\n", levels
[i
]);
2344 r
.in
.domain_handle
= handle
;
2345 r
.in
.level
= levels
[i
];
2347 status
= dcerpc_samr_QueryDomainInfo2(p
, mem_ctx
, &r
);
2348 if (!NT_STATUS_IS_OK(status
)) {
2349 printf("QueryDomainInfo2 level %u failed - %s\n",
2350 r
.in
.level
, nt_errstr(status
));
2359 /* Test whether querydispinfo level 5 and enumdomgroups return the same
2360 set of group names. */
2361 static BOOL
test_GroupList(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2362 struct policy_handle
*handle
)
2364 struct samr_EnumDomainGroups q1
;
2365 struct samr_QueryDisplayInfo q2
;
2367 uint32_t resume_handle
=0;
2372 const char **names
= NULL
;
2374 printf("Testing coherency of querydispinfo vs enumdomgroups\n");
2376 q1
.in
.domain_handle
= handle
;
2377 q1
.in
.resume_handle
= &resume_handle
;
2379 q1
.out
.resume_handle
= &resume_handle
;
2381 status
= STATUS_MORE_ENTRIES
;
2382 while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
2383 status
= dcerpc_samr_EnumDomainGroups(p
, mem_ctx
, &q1
);
2385 if (!NT_STATUS_IS_OK(status
) &&
2386 !NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
))
2389 for (i
=0; i
<q1
.out
.sam
->count
; i
++) {
2390 add_string_to_array(mem_ctx
,
2391 q1
.out
.sam
->entries
[i
].name
.name
,
2392 &names
, &num_names
);
2396 if (!NT_STATUS_IS_OK(status
)) {
2397 printf("EnumDomainGroups failed - %s\n", nt_errstr(status
));
2405 q2
.in
.domain_handle
= handle
;
2407 q2
.in
.start_idx
= 0;
2408 q2
.in
.max_entries
= 5;
2409 q2
.in
.buf_size
= (uint32_t)-1;
2411 status
= STATUS_MORE_ENTRIES
;
2412 while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
2413 status
= dcerpc_samr_QueryDisplayInfo(p
, mem_ctx
, &q2
);
2415 if (!NT_STATUS_IS_OK(status
) &&
2416 !NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
))
2419 for (i
=0; i
<q2
.out
.info
.info5
.count
; i
++) {
2425 /* Querydisplayinfo returns ascii -- convert */
2427 namelen
= convert_string_talloc(mem_ctx
, CH_DISPLAY
, CH_UNIX
,
2428 q2
.out
.info
.info5
.entries
[i
].account_name
.name
,
2429 q2
.out
.info
.info5
.entries
[i
].account_name
.name_len
,
2432 for (j
=0; j
<num_names
; j
++) {
2433 if (names
[j
] == NULL
)
2435 /* Hmm. No strequal in samba4 */
2436 if (strequal(names
[j
], name
)) {
2444 printf("QueryDisplayInfo gave name [%s] that EnumDomainGroups did not\n",
2449 q2
.in
.start_idx
+= q2
.out
.info
.info5
.count
;
2452 if (!NT_STATUS_IS_OK(status
)) {
2453 printf("QueryDisplayInfo level 5 failed - %s\n",
2458 for (i
=0; i
<num_names
; i
++) {
2459 if (names
[i
] != NULL
) {
2460 printf("EnumDomainGroups gave name [%s] that QueryDisplayInfo did not\n",
2469 static BOOL
test_DeleteDomainGroup(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2470 struct policy_handle
*group_handle
)
2472 struct samr_DeleteDomainGroup d
;
2476 printf("Testing DeleteDomainGroup\n");
2478 d
.in
.group_handle
= group_handle
;
2479 d
.out
.group_handle
= group_handle
;
2481 status
= dcerpc_samr_DeleteDomainGroup(p
, mem_ctx
, &d
);
2482 if (!NT_STATUS_IS_OK(status
)) {
2483 printf("DeleteDomainGroup failed - %s\n", nt_errstr(status
));
2490 static BOOL
test_TestPrivateFunctionsDomain(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2491 struct policy_handle
*domain_handle
)
2493 struct samr_TestPrivateFunctionsDomain r
;
2497 printf("Testing TestPrivateFunctionsDomain\n");
2499 r
.in
.domain_handle
= domain_handle
;
2501 status
= dcerpc_samr_TestPrivateFunctionsDomain(p
, mem_ctx
, &r
);
2502 if (!NT_STATUS_EQUAL(NT_STATUS_NOT_IMPLEMENTED
, status
)) {
2503 printf("TestPrivateFunctionsDomain failed - %s\n", nt_errstr(status
));
2510 static BOOL
test_RidToSid(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2511 struct policy_handle
*domain_handle
)
2513 struct samr_RidToSid r
;
2517 printf("Testing RidToSid\n");
2519 r
.in
.domain_handle
= domain_handle
;
2522 status
= dcerpc_samr_RidToSid(p
, mem_ctx
, &r
);
2523 if (!NT_STATUS_IS_OK(status
)) {
2524 printf("RidToSid failed - %s\n", nt_errstr(status
));
2531 static BOOL
test_GetBootKeyInformation(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2532 struct policy_handle
*domain_handle
)
2534 struct samr_GetBootKeyInformation r
;
2538 printf("Testing GetBootKeyInformation\n");
2540 r
.in
.domain_handle
= domain_handle
;
2542 status
= dcerpc_samr_GetBootKeyInformation(p
, mem_ctx
, &r
);
2543 if (!NT_STATUS_IS_OK(status
)) {
2544 /* w2k3 seems to fail this sometimes and pass it sometimes */
2545 printf("GetBootKeyInformation (ignored) - %s\n", nt_errstr(status
));
2551 static BOOL
test_AddGroupMember(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2552 struct policy_handle
*domain_handle
,
2553 struct policy_handle
*group_handle
)
2556 struct samr_AddGroupMember r
;
2557 struct samr_DeleteGroupMember d
;
2558 struct samr_QueryGroupMember q
;
2559 struct samr_SetMemberAttributesOfGroup s
;
2563 status
= test_LookupName(p
, mem_ctx
, domain_handle
, TEST_ACCOUNT_NAME
, &rid
);
2564 if (!NT_STATUS_IS_OK(status
)) {
2568 r
.in
.group_handle
= group_handle
;
2570 r
.in
.flags
= 0; /* ??? */
2572 printf("Testing AddGroupMember and DeleteGroupMember\n");
2574 d
.in
.group_handle
= group_handle
;
2577 status
= dcerpc_samr_DeleteGroupMember(p
, mem_ctx
, &d
);
2578 if (!NT_STATUS_EQUAL(NT_STATUS_MEMBER_NOT_IN_GROUP
, status
)) {
2579 printf("DeleteGroupMember gave %s - should be NT_STATUS_MEMBER_NOT_IN_GROUP\n",
2584 status
= dcerpc_samr_AddGroupMember(p
, mem_ctx
, &r
);
2585 if (!NT_STATUS_IS_OK(status
)) {
2586 printf("AddGroupMember failed - %s\n", nt_errstr(status
));
2590 status
= dcerpc_samr_AddGroupMember(p
, mem_ctx
, &r
);
2591 if (!NT_STATUS_EQUAL(NT_STATUS_MEMBER_IN_GROUP
, status
)) {
2592 printf("AddGroupMember gave %s - should be NT_STATUS_MEMBER_IN_GROUP\n",
2597 /* this one is quite strange. I am using random inputs in the
2598 hope of triggering an error that might give us a clue */
2599 s
.in
.group_handle
= group_handle
;
2600 s
.in
.unknown1
= random();
2601 s
.in
.unknown2
= random();
2603 status
= dcerpc_samr_SetMemberAttributesOfGroup(p
, mem_ctx
, &s
);
2604 if (!NT_STATUS_IS_OK(status
)) {
2605 printf("SetMemberAttributesOfGroup failed - %s\n", nt_errstr(status
));
2609 q
.in
.group_handle
= group_handle
;
2611 status
= dcerpc_samr_QueryGroupMember(p
, mem_ctx
, &q
);
2612 if (!NT_STATUS_IS_OK(status
)) {
2613 printf("QueryGroupMember failed - %s\n", nt_errstr(status
));
2617 status
= dcerpc_samr_DeleteGroupMember(p
, mem_ctx
, &d
);
2618 if (!NT_STATUS_IS_OK(status
)) {
2619 printf("DeleteGroupMember failed - %s\n", nt_errstr(status
));
2623 status
= dcerpc_samr_AddGroupMember(p
, mem_ctx
, &r
);
2624 if (!NT_STATUS_IS_OK(status
)) {
2625 printf("AddGroupMember failed - %s\n", nt_errstr(status
));
2633 static BOOL
test_CreateDomainGroup(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2634 struct policy_handle
*domain_handle
, struct policy_handle
*group_handle
)
2637 struct samr_CreateDomainGroup r
;
2639 struct samr_Name name
;
2642 init_samr_Name(&name
, TEST_GROUPNAME
);
2644 r
.in
.domain_handle
= domain_handle
;
2646 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2647 r
.out
.group_handle
= group_handle
;
2650 printf("Testing CreateDomainGroup(%s)\n", r
.in
.name
->name
);
2652 status
= dcerpc_samr_CreateDomainGroup(p
, mem_ctx
, &r
);
2654 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
2655 printf("Server refused create of '%s'\n", r
.in
.name
->name
);
2656 ZERO_STRUCTP(group_handle
);
2660 if (NT_STATUS_EQUAL(status
, NT_STATUS_GROUP_EXISTS
) ||
2661 NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
2662 if (!test_DeleteGroup_byname(p
, mem_ctx
, domain_handle
, r
.in
.name
->name
)) {
2665 status
= dcerpc_samr_CreateDomainGroup(p
, mem_ctx
, &r
);
2667 if (!NT_STATUS_IS_OK(status
)) {
2668 printf("CreateDomainGroup failed - %s\n", nt_errstr(status
));
2672 if (!test_AddGroupMember(p
, mem_ctx
, domain_handle
, group_handle
)) {
2676 if (!test_SetGroupInfo(p
, mem_ctx
, group_handle
)) {
2685 its not totally clear what this does. It seems to accept any sid you like.
2687 static BOOL
test_RemoveMemberFromForeignDomain(struct dcerpc_pipe
*p
,
2688 TALLOC_CTX
*mem_ctx
,
2689 struct policy_handle
*domain_handle
)
2692 struct samr_RemoveMemberFromForeignDomain r
;
2694 r
.in
.domain_handle
= domain_handle
;
2695 r
.in
.sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-12-34-56-78-9");
2697 status
= dcerpc_samr_RemoveMemberFromForeignDomain(p
, mem_ctx
, &r
);
2698 if (!NT_STATUS_IS_OK(status
)) {
2699 printf("RemoveMemberFromForeignDomain failed - %s\n", nt_errstr(status
));
2709 static BOOL
test_OpenDomain(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2710 struct policy_handle
*handle
, struct dom_sid
*sid
)
2713 struct samr_OpenDomain r
;
2714 struct policy_handle domain_handle
;
2715 struct policy_handle user_handle
;
2716 struct policy_handle alias_handle
;
2717 struct policy_handle group_handle
;
2720 ZERO_STRUCT(user_handle
);
2721 ZERO_STRUCT(alias_handle
);
2722 ZERO_STRUCT(group_handle
);
2723 ZERO_STRUCT(domain_handle
);
2725 printf("Testing OpenDomain\n");
2727 r
.in
.connect_handle
= handle
;
2728 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2730 r
.out
.domain_handle
= &domain_handle
;
2732 status
= dcerpc_samr_OpenDomain(p
, mem_ctx
, &r
);
2733 if (!NT_STATUS_IS_OK(status
)) {
2734 printf("OpenDomain failed - %s\n", nt_errstr(status
));
2738 if (!test_QuerySecurity(p
, mem_ctx
, &domain_handle
)) {
2742 if (!test_RemoveMemberFromForeignDomain(p
, mem_ctx
, &domain_handle
)) {
2746 if (!test_CreateUser2(p
, mem_ctx
, &domain_handle
)) {
2750 if (!test_CreateUser(p
, mem_ctx
, &domain_handle
, &user_handle
)) {
2754 if (!test_CreateAlias(p
, mem_ctx
, &domain_handle
, &alias_handle
, sid
)) {
2758 if (!test_CreateDomainGroup(p
, mem_ctx
, &domain_handle
, &group_handle
)) {
2762 if (!test_QueryDomainInfo(p
, mem_ctx
, &domain_handle
)) {
2766 if (!test_QueryDomainInfo2(p
, mem_ctx
, &domain_handle
)) {
2770 if (!test_EnumDomainUsers(p
, mem_ctx
, &domain_handle
)) {
2774 if (!test_EnumDomainUsers_async(p
, mem_ctx
, &domain_handle
)) {
2778 if (!test_EnumDomainGroups(p
, mem_ctx
, &domain_handle
)) {
2782 if (!test_EnumDomainAliases(p
, mem_ctx
, &domain_handle
)) {
2786 if (!test_QueryDisplayInfo(p
, mem_ctx
, &domain_handle
)) {
2790 if (!test_QueryDisplayInfo2(p
, mem_ctx
, &domain_handle
)) {
2794 if (!test_QueryDisplayInfo3(p
, mem_ctx
, &domain_handle
)) {
2798 if (!test_GetDisplayEnumerationIndex(p
, mem_ctx
, &domain_handle
)) {
2802 if (!test_GetDisplayEnumerationIndex2(p
, mem_ctx
, &domain_handle
)) {
2806 if (!test_GroupList(p
, mem_ctx
, &domain_handle
)) {
2810 if (!test_TestPrivateFunctionsDomain(p
, mem_ctx
, &domain_handle
)) {
2814 if (!test_RidToSid(p
, mem_ctx
, &domain_handle
)) {
2818 if (!test_GetBootKeyInformation(p
, mem_ctx
, &domain_handle
)) {
2822 if (!policy_handle_empty(&user_handle
) &&
2823 !test_DeleteUser(p
, mem_ctx
, &user_handle
)) {
2827 if (!policy_handle_empty(&alias_handle
) &&
2828 !test_DeleteAlias(p
, mem_ctx
, &alias_handle
)) {
2832 if (!policy_handle_empty(&group_handle
) &&
2833 !test_DeleteDomainGroup(p
, mem_ctx
, &group_handle
)) {
2837 if (!test_Close(p
, mem_ctx
, &domain_handle
)) {
2844 static BOOL
test_LookupDomain(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2845 struct policy_handle
*handle
, struct samr_Name
*domain
)
2848 struct samr_LookupDomain r
;
2849 struct samr_Name n2
;
2852 printf("Testing LookupDomain(%s)\n", domain
->name
);
2854 /* check for correct error codes */
2855 r
.in
.connect_handle
= handle
;
2859 status
= dcerpc_samr_LookupDomain(p
, mem_ctx
, &r
);
2860 if (!NT_STATUS_EQUAL(NT_STATUS_INVALID_PARAMETER
, status
)) {
2861 printf("failed: LookupDomain expected NT_STATUS_INVALID_PARAMETER - %s\n", nt_errstr(status
));
2865 n2
.name
= "xxNODOMAINxx";
2867 status
= dcerpc_samr_LookupDomain(p
, mem_ctx
, &r
);
2868 if (!NT_STATUS_EQUAL(NT_STATUS_NO_SUCH_DOMAIN
, status
)) {
2869 printf("failed: LookupDomain expected NT_STATUS_NO_SUCH_DOMAIN - %s\n", nt_errstr(status
));
2873 r
.in
.connect_handle
= handle
;
2874 r
.in
.domain
= domain
;
2876 status
= dcerpc_samr_LookupDomain(p
, mem_ctx
, &r
);
2877 if (!NT_STATUS_IS_OK(status
)) {
2878 printf("LookupDomain failed - %s\n", nt_errstr(status
));
2882 if (!test_GetDomPwInfo(p
, mem_ctx
, domain
)) {
2886 if (!test_OpenDomain(p
, mem_ctx
, handle
, r
.out
.sid
)) {
2894 static BOOL
test_EnumDomains(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2895 struct policy_handle
*handle
)
2898 struct samr_EnumDomains r
;
2899 uint32_t resume_handle
= 0;
2903 r
.in
.connect_handle
= handle
;
2904 r
.in
.resume_handle
= &resume_handle
;
2905 r
.in
.buf_size
= (uint32_t)-1;
2906 r
.out
.resume_handle
= &resume_handle
;
2908 status
= dcerpc_samr_EnumDomains(p
, mem_ctx
, &r
);
2909 if (!NT_STATUS_IS_OK(status
)) {
2910 printf("EnumDomains failed - %s\n", nt_errstr(status
));
2918 for (i
=0;i
<r
.out
.sam
->count
;i
++) {
2919 if (!test_LookupDomain(p
, mem_ctx
, handle
,
2920 &r
.out
.sam
->entries
[i
].name
)) {
2925 status
= dcerpc_samr_EnumDomains(p
, mem_ctx
, &r
);
2926 if (!NT_STATUS_IS_OK(status
)) {
2927 printf("EnumDomains failed - %s\n", nt_errstr(status
));
2935 static BOOL
test_Connect(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
2936 struct policy_handle
*handle
)
2939 struct samr_Connect r
;
2940 struct samr_Connect2 r2
;
2941 struct samr_Connect3 r3
;
2942 struct samr_Connect4 r4
;
2943 struct samr_Connect5 r5
;
2944 union samr_ConnectInfo info
;
2947 printf("testing samr_Connect\n");
2949 r
.in
.system_name
= 0;
2950 r
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2951 r
.out
.connect_handle
= handle
;
2953 status
= dcerpc_samr_Connect(p
, mem_ctx
, &r
);
2954 if (!NT_STATUS_IS_OK(status
)) {
2955 printf("Connect failed - %s\n", nt_errstr(status
));
2959 printf("testing samr_Connect2\n");
2961 r2
.in
.system_name
= NULL
;
2962 r2
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2963 r2
.out
.connect_handle
= handle
;
2965 status
= dcerpc_samr_Connect2(p
, mem_ctx
, &r2
);
2966 if (!NT_STATUS_IS_OK(status
)) {
2967 printf("Connect2 failed - %s\n", nt_errstr(status
));
2971 printf("testing samr_Connect3\n");
2973 r3
.in
.system_name
= NULL
;
2975 r3
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2976 r3
.out
.connect_handle
= handle
;
2978 status
= dcerpc_samr_Connect3(p
, mem_ctx
, &r3
);
2979 if (!NT_STATUS_IS_OK(status
)) {
2980 printf("Connect3 failed - %s\n", nt_errstr(status
));
2984 printf("testing samr_Connect4\n");
2986 r4
.in
.system_name
= "";
2988 r4
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
2989 r4
.out
.connect_handle
= handle
;
2991 status
= dcerpc_samr_Connect4(p
, mem_ctx
, &r4
);
2992 if (!NT_STATUS_IS_OK(status
)) {
2993 printf("Connect4 failed - %s\n", nt_errstr(status
));
2997 printf("testing samr_Connect5\n");
2999 info
.info1
.unknown1
= 0;
3000 info
.info1
.unknown2
= 0;
3002 r5
.in
.system_name
= "";
3003 r5
.in
.access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
3006 r5
.out
.info
= &info
;
3007 r5
.out
.connect_handle
= handle
;
3009 status
= dcerpc_samr_Connect5(p
, mem_ctx
, &r5
);
3010 if (!NT_STATUS_IS_OK(status
)) {
3011 printf("Connect5 failed - %s\n", nt_errstr(status
));
3019 BOOL
torture_rpc_samr(int dummy
)
3022 struct dcerpc_pipe
*p
;
3023 TALLOC_CTX
*mem_ctx
;
3025 struct policy_handle handle
;
3027 mem_ctx
= talloc_init("torture_rpc_samr");
3029 status
= torture_rpc_connection(&p
,
3032 DCERPC_SAMR_VERSION
);
3033 if (!NT_STATUS_IS_OK(status
)) {
3037 if (!test_Connect(p
, mem_ctx
, &handle
)) {
3041 if (!test_QuerySecurity(p
, mem_ctx
, &handle
)) {
3045 if (!test_EnumDomains(p
, mem_ctx
, &handle
)) {
3049 if (!test_SetDsrmPassword(p
, mem_ctx
, &handle
)) {
3053 if (!test_Shutdown(p
, mem_ctx
, &handle
)) {
3057 if (!test_Close(p
, mem_ctx
, &handle
)) {
3061 talloc_destroy(mem_ctx
);
3063 torture_rpc_close(p
);