2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 1992-2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 Copyright (C) Elrond 2000,
8 Copyright (C) Tim Potter 2000
9 Copyright (C) Guenther Deschner 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "rpcclient.h"
27 #include "../libcli/auth/libcli_auth.h"
28 #include "../librpc/gen_ndr/ndr_samr.h"
29 #include "../librpc/gen_ndr/cli_samr.h"
30 #include "rpc_client/cli_samr.h"
31 #include "rpc_client/init_samr.h"
32 #include "rpc_client/init_lsa.h"
33 #include "../libcli/security/dom_sid.h"
35 extern struct dom_sid domain_sid
;
37 /****************************************************************************
38 display samr_user_info_7 structure
39 ****************************************************************************/
40 static void display_samr_user_info_7(struct samr_UserInfo7
*r
)
42 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
45 /****************************************************************************
46 display samr_user_info_9 structure
47 ****************************************************************************/
48 static void display_samr_user_info_9(struct samr_UserInfo9
*r
)
50 printf("\tPrimary group RID :\tox%x\n", r
->primary_gid
);
53 /****************************************************************************
54 display samr_user_info_16 structure
55 ****************************************************************************/
56 static void display_samr_user_info_16(struct samr_UserInfo16
*r
)
58 printf("\tAcct Flags :\tox%x\n", r
->acct_flags
);
61 /****************************************************************************
62 display samr_user_info_20 structure
63 ****************************************************************************/
64 static void display_samr_user_info_20(struct samr_UserInfo20
*r
)
66 printf("\tRemote Dial :\n");
67 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
71 /****************************************************************************
72 display samr_user_info_21 structure
73 ****************************************************************************/
74 static void display_samr_user_info_21(struct samr_UserInfo21
*r
)
76 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
77 printf("\tFull Name :\t%s\n", r
->full_name
.string
);
78 printf("\tHome Drive :\t%s\n", r
->home_directory
.string
);
79 printf("\tDir Drive :\t%s\n", r
->home_drive
.string
);
80 printf("\tProfile Path:\t%s\n", r
->profile_path
.string
);
81 printf("\tLogon Script:\t%s\n", r
->logon_script
.string
);
82 printf("\tDescription :\t%s\n", r
->description
.string
);
83 printf("\tWorkstations:\t%s\n", r
->workstations
.string
);
84 printf("\tComment :\t%s\n", r
->comment
.string
);
85 printf("\tRemote Dial :\n");
86 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
88 printf("\tLogon Time :\t%s\n",
89 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logon
)));
90 printf("\tLogoff Time :\t%s\n",
91 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logoff
)));
92 printf("\tKickoff Time :\t%s\n",
93 http_timestring(talloc_tos(), nt_time_to_unix(r
->acct_expiry
)));
94 printf("\tPassword last set Time :\t%s\n",
95 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_password_change
)));
96 printf("\tPassword can change Time :\t%s\n",
97 http_timestring(talloc_tos(), nt_time_to_unix(r
->allow_password_change
)));
98 printf("\tPassword must change Time:\t%s\n",
99 http_timestring(talloc_tos(), nt_time_to_unix(r
->force_password_change
)));
101 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
103 printf("\tuser_rid :\t0x%x\n" , r
->rid
); /* User ID */
104 printf("\tgroup_rid:\t0x%x\n" , r
->primary_gid
); /* Group ID */
105 printf("\tacb_info :\t0x%08x\n", r
->acct_flags
); /* Account Control Info */
107 printf("\tfields_present:\t0x%08x\n", r
->fields_present
); /* 0x00ff ffff */
108 printf("\tlogon_divs:\t%d\n", r
->logon_hours
.units_per_week
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
109 printf("\tbad_password_count:\t0x%08x\n", r
->bad_password_count
);
110 printf("\tlogon_count:\t0x%08x\n", r
->logon_count
);
112 printf("\tpadding1[0..7]...\n");
114 if (r
->logon_hours
.bits
) {
115 printf("\tlogon_hrs[0..%d]...\n", r
->logon_hours
.units_per_week
/8);
120 static void display_password_properties(uint32_t password_properties
)
122 printf("password_properties: 0x%08x\n", password_properties
);
124 if (password_properties
& DOMAIN_PASSWORD_COMPLEX
)
125 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
127 if (password_properties
& DOMAIN_PASSWORD_NO_ANON_CHANGE
)
128 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
130 if (password_properties
& DOMAIN_PASSWORD_NO_CLEAR_CHANGE
)
131 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
133 if (password_properties
& DOMAIN_PASSWORD_LOCKOUT_ADMINS
)
134 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
136 if (password_properties
& DOMAIN_PASSWORD_STORE_CLEARTEXT
)
137 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
139 if (password_properties
& DOMAIN_REFUSE_PASSWORD_CHANGE
)
140 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
143 static void display_sam_dom_info_1(struct samr_DomInfo1
*info1
)
145 printf("Minimum password length:\t\t\t%d\n",
146 info1
->min_password_length
);
147 printf("Password uniqueness (remember x passwords):\t%d\n",
148 info1
->password_history_length
);
149 display_password_properties(info1
->password_properties
);
150 printf("password expire in:\t\t\t\t%s\n",
151 display_time(info1
->max_password_age
));
152 printf("Min password age (allow changing in x days):\t%s\n",
153 display_time(info1
->min_password_age
));
156 static void display_sam_dom_info_2(struct samr_DomGeneralInformation
*general
)
158 printf("Domain:\t\t%s\n", general
->domain_name
.string
);
159 printf("Server:\t\t%s\n", general
->primary
.string
);
160 printf("Comment:\t%s\n", general
->oem_information
.string
);
162 printf("Total Users:\t%d\n", general
->num_users
);
163 printf("Total Groups:\t%d\n", general
->num_groups
);
164 printf("Total Aliases:\t%d\n", general
->num_aliases
);
166 printf("Sequence No:\t%llu\n", (unsigned long long)general
->sequence_num
);
168 printf("Force Logoff:\t%d\n",
169 (int)nt_time_to_unix_abs(&general
->force_logoff_time
));
171 printf("Domain Server State:\t0x%x\n", general
->domain_server_state
);
172 printf("Server Role:\t%s\n", server_role_str(general
->role
));
173 printf("Unknown 3:\t0x%x\n", general
->unknown3
);
176 static void display_sam_dom_info_3(struct samr_DomInfo3
*info3
)
178 printf("Force Logoff:\t%d\n",
179 (int)nt_time_to_unix_abs(&info3
->force_logoff_time
));
182 static void display_sam_dom_info_4(struct samr_DomOEMInformation
*oem
)
184 printf("Comment:\t%s\n", oem
->oem_information
.string
);
187 static void display_sam_dom_info_5(struct samr_DomInfo5
*info5
)
189 printf("Domain:\t\t%s\n", info5
->domain_name
.string
);
192 static void display_sam_dom_info_6(struct samr_DomInfo6
*info6
)
194 printf("Server:\t\t%s\n", info6
->primary
.string
);
197 static void display_sam_dom_info_7(struct samr_DomInfo7
*info7
)
199 printf("Server Role:\t%s\n", server_role_str(info7
->role
));
202 static void display_sam_dom_info_8(struct samr_DomInfo8
*info8
)
204 printf("Sequence No:\t%llu\n", (unsigned long long)info8
->sequence_num
);
205 printf("Domain Create Time:\t%s\n",
206 http_timestring(talloc_tos(), nt_time_to_unix(info8
->domain_create_time
)));
209 static void display_sam_dom_info_9(struct samr_DomInfo9
*info9
)
211 printf("Domain Server State:\t0x%x\n", info9
->domain_server_state
);
214 static void display_sam_dom_info_12(struct samr_DomInfo12
*info12
)
216 printf("Bad password lockout duration: %s\n",
217 display_time(info12
->lockout_duration
));
218 printf("Reset Lockout after: %s\n",
219 display_time(info12
->lockout_window
));
220 printf("Lockout after bad attempts: %d\n",
221 info12
->lockout_threshold
);
224 static void display_sam_dom_info_13(struct samr_DomInfo13
*info13
)
226 printf("Sequence No:\t%llu\n", (unsigned long long)info13
->sequence_num
);
227 printf("Domain Create Time:\t%s\n",
228 http_timestring(talloc_tos(), nt_time_to_unix(info13
->domain_create_time
)));
229 printf("Sequence No at last promotion:\t%llu\n",
230 (unsigned long long)info13
->modified_count_at_last_promotion
);
233 static void display_sam_info_1(struct samr_DispEntryGeneral
*r
)
235 printf("index: 0x%x ", r
->idx
);
236 printf("RID: 0x%x ", r
->rid
);
237 printf("acb: 0x%08x ", r
->acct_flags
);
238 printf("Account: %s\t", r
->account_name
.string
);
239 printf("Name: %s\t", r
->full_name
.string
);
240 printf("Desc: %s\n", r
->description
.string
);
243 static void display_sam_info_2(struct samr_DispEntryFull
*r
)
245 printf("index: 0x%x ", r
->idx
);
246 printf("RID: 0x%x ", r
->rid
);
247 printf("acb: 0x%08x ", r
->acct_flags
);
248 printf("Account: %s\t", r
->account_name
.string
);
249 printf("Desc: %s\n", r
->description
.string
);
252 static void display_sam_info_3(struct samr_DispEntryFullGroup
*r
)
254 printf("index: 0x%x ", r
->idx
);
255 printf("RID: 0x%x ", r
->rid
);
256 printf("acb: 0x%08x ", r
->acct_flags
);
257 printf("Account: %s\t", r
->account_name
.string
);
258 printf("Desc: %s\n", r
->description
.string
);
261 static void display_sam_info_4(struct samr_DispEntryAscii
*r
)
263 printf("index: 0x%x ", r
->idx
);
264 printf("Account: %s\n", r
->account_name
.string
);
267 static void display_sam_info_5(struct samr_DispEntryAscii
*r
)
269 printf("index: 0x%x ", r
->idx
);
270 printf("Account: %s\n", r
->account_name
.string
);
273 /****************************************************************************
274 ****************************************************************************/
276 static NTSTATUS
get_domain_handle(struct rpc_pipe_client
*cli
,
279 struct policy_handle
*connect_pol
,
280 uint32_t access_mask
,
281 struct dom_sid
*_domain_sid
,
282 struct policy_handle
*domain_pol
)
285 if (StrCaseCmp(sam
, "domain") == 0) {
286 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
291 } else if (StrCaseCmp(sam
, "builtin") == 0) {
292 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
295 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
299 return NT_STATUS_INVALID_PARAMETER
;
302 /**********************************************************************
303 * Query user information
305 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
307 int argc
, const char **argv
)
309 struct policy_handle connect_pol
, domain_pol
, user_pol
;
310 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
311 uint32 info_level
= 21;
312 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
313 union samr_UserInfo
*info
= NULL
;
316 if ((argc
< 2) || (argc
> 4)) {
317 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
321 sscanf(argv
[1], "%i", &user_rid
);
324 sscanf(argv
[2], "%i", &info_level
);
327 sscanf(argv
[3], "%x", &access_mask
);
330 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
331 MAXIMUM_ALLOWED_ACCESS
,
334 if (!NT_STATUS_IS_OK(result
))
337 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
339 MAXIMUM_ALLOWED_ACCESS
,
342 if (!NT_STATUS_IS_OK(result
))
345 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
351 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) &&
354 /* Probably this was a user name, try lookupnames */
355 struct samr_Ids rids
, types
;
356 struct lsa_String lsa_acct_name
;
358 init_lsa_String(&lsa_acct_name
, argv
[1]);
360 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
367 if (NT_STATUS_IS_OK(result
)) {
368 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
377 if (!NT_STATUS_IS_OK(result
))
380 result
= rpccli_samr_QueryUserInfo(cli
, mem_ctx
,
385 if (!NT_STATUS_IS_OK(result
))
388 switch (info_level
) {
390 display_samr_user_info_7(&info
->info7
);
393 display_samr_user_info_9(&info
->info9
);
396 display_samr_user_info_16(&info
->info16
);
399 display_samr_user_info_20(&info
->info20
);
402 display_samr_user_info_21(&info
->info21
);
405 printf("Unsupported infolevel: %d\n", info_level
);
409 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
410 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
411 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
417 /****************************************************************************
419 ****************************************************************************/
420 static void display_group_info1(struct samr_GroupInfoAll
*info1
)
422 printf("\tGroup Name:\t%s\n", info1
->name
.string
);
423 printf("\tDescription:\t%s\n", info1
->description
.string
);
424 printf("\tGroup Attribute:%d\n", info1
->attributes
);
425 printf("\tNum Members:%d\n", info1
->num_members
);
428 /****************************************************************************
430 ****************************************************************************/
431 static void display_group_info2(struct lsa_String
*info2
)
433 printf("\tGroup Description:%s\n", info2
->string
);
437 /****************************************************************************
439 ****************************************************************************/
440 static void display_group_info3(struct samr_GroupInfoAttributes
*info3
)
442 printf("\tGroup Attribute:%d\n", info3
->attributes
);
446 /****************************************************************************
448 ****************************************************************************/
449 static void display_group_info4(struct lsa_String
*info4
)
451 printf("\tGroup Description:%s\n", info4
->string
);
454 /****************************************************************************
456 ****************************************************************************/
457 static void display_group_info5(struct samr_GroupInfoAll
*info5
)
459 printf("\tGroup Name:\t%s\n", info5
->name
.string
);
460 printf("\tDescription:\t%s\n", info5
->description
.string
);
461 printf("\tGroup Attribute:%d\n", info5
->attributes
);
462 printf("\tNum Members:%d\n", info5
->num_members
);
465 /****************************************************************************
466 display sam sync structure
467 ****************************************************************************/
468 static void display_group_info(union samr_GroupInfo
*info
,
469 enum samr_GroupInfoEnum level
)
473 display_group_info1(&info
->all
);
476 display_group_info2(&info
->name
);
479 display_group_info3(&info
->attributes
);
482 display_group_info4(&info
->description
);
485 display_group_info5(&info
->all2
);
490 /***********************************************************************
491 * Query group information
493 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
495 int argc
, const char **argv
)
497 struct policy_handle connect_pol
, domain_pol
, group_pol
;
498 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
499 enum samr_GroupInfoEnum info_level
= GROUPINFOALL
;
500 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
501 union samr_GroupInfo
*group_info
= NULL
;
504 if ((argc
< 2) || (argc
> 4)) {
505 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
509 sscanf(argv
[1], "%i", &group_rid
);
512 info_level
= atoi(argv
[2]);
515 sscanf(argv
[3], "%x", &access_mask
);
517 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
518 MAXIMUM_ALLOWED_ACCESS
,
521 if (!NT_STATUS_IS_OK(result
))
524 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
526 MAXIMUM_ALLOWED_ACCESS
,
530 if (!NT_STATUS_IS_OK(result
))
533 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
539 if (!NT_STATUS_IS_OK(result
))
542 result
= rpccli_samr_QueryGroupInfo(cli
, mem_ctx
,
546 if (!NT_STATUS_IS_OK(result
)) {
550 display_group_info(group_info
, info_level
);
552 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
553 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
554 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
559 /* Query groups a user is a member of */
561 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
563 int argc
, const char **argv
)
565 struct policy_handle connect_pol
,
568 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
570 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
572 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
574 if ((argc
< 2) || (argc
> 3)) {
575 printf("Usage: %s rid [access mask]\n", argv
[0]);
579 sscanf(argv
[1], "%i", &user_rid
);
582 sscanf(argv
[2], "%x", &access_mask
);
584 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
585 MAXIMUM_ALLOWED_ACCESS
,
588 if (!NT_STATUS_IS_OK(result
))
591 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
593 MAXIMUM_ALLOWED_ACCESS
,
594 &domain_sid
, &domain_pol
);
596 if (!NT_STATUS_IS_OK(result
))
599 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
605 if (!NT_STATUS_IS_OK(result
))
608 result
= rpccli_samr_GetGroupsForUser(cli
, mem_ctx
,
612 if (!NT_STATUS_IS_OK(result
))
615 for (i
= 0; i
< rid_array
->count
; i
++) {
616 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
617 rid_array
->rids
[i
].rid
,
618 rid_array
->rids
[i
].attributes
);
621 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
622 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
623 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
628 /* Query aliases a user is a member of */
630 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
632 int argc
, const char **argv
)
634 struct policy_handle connect_pol
, domain_pol
;
635 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
636 struct dom_sid
*sids
;
638 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
640 struct lsa_SidArray sid_array
;
641 struct samr_Ids alias_rids
;
644 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
645 return NT_STATUS_INVALID_PARAMETER
;
651 for (i
=2; i
<argc
; i
++) {
652 struct dom_sid tmp_sid
;
653 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
654 printf("%s is not a legal SID\n", argv
[i
]);
655 return NT_STATUS_INVALID_PARAMETER
;
657 result
= add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
658 if (!NT_STATUS_IS_OK(result
)) {
664 sid_array
.sids
= TALLOC_ZERO_ARRAY(mem_ctx
, struct lsa_SidPtr
, num_sids
);
665 if (sid_array
.sids
== NULL
)
666 return NT_STATUS_NO_MEMORY
;
668 sid_array
.sids
= NULL
;
671 for (i
=0; i
<num_sids
; i
++) {
672 sid_array
.sids
[i
].sid
= dom_sid_dup(mem_ctx
, &sids
[i
]);
673 if (!sid_array
.sids
[i
].sid
) {
674 return NT_STATUS_NO_MEMORY
;
678 sid_array
.num_sids
= num_sids
;
680 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
681 MAXIMUM_ALLOWED_ACCESS
,
684 if (!NT_STATUS_IS_OK(result
))
687 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
693 if (!NT_STATUS_IS_OK(result
))
696 result
= rpccli_samr_GetAliasMembership(cli
, mem_ctx
,
700 if (!NT_STATUS_IS_OK(result
))
703 for (i
= 0; i
< alias_rids
.count
; i
++) {
704 printf("\tgroup rid:[0x%x]\n", alias_rids
.ids
[i
]);
707 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
708 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
713 /* Query members of a group */
715 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
717 int argc
, const char **argv
)
719 struct policy_handle connect_pol
, domain_pol
, group_pol
;
720 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
722 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
724 unsigned int old_timeout
;
725 struct samr_RidAttrArray
*rids
= NULL
;
727 if ((argc
< 2) || (argc
> 3)) {
728 printf("Usage: %s rid [access mask]\n", argv
[0]);
732 sscanf(argv
[1], "%i", &group_rid
);
735 sscanf(argv
[2], "%x", &access_mask
);
737 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
738 MAXIMUM_ALLOWED_ACCESS
,
741 if (!NT_STATUS_IS_OK(result
))
744 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
746 MAXIMUM_ALLOWED_ACCESS
,
750 if (!NT_STATUS_IS_OK(result
))
753 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
759 if (!NT_STATUS_IS_OK(result
))
762 /* Make sure to wait for our DC's reply */
763 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
764 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
766 result
= rpccli_samr_QueryGroupMember(cli
, mem_ctx
,
770 rpccli_set_timeout(cli
, old_timeout
);
772 if (!NT_STATUS_IS_OK(result
))
775 for (i
= 0; i
< rids
->count
; i
++) {
776 printf("\trid:[0x%x] attr:[0x%x]\n", rids
->rids
[i
],
777 rids
->attributes
[i
]);
780 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
781 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
782 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
787 /* Enumerate domain users */
789 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
791 int argc
, const char **argv
)
793 struct policy_handle connect_pol
, domain_pol
;
794 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
795 uint32 start_idx
, num_dom_users
, i
;
796 struct samr_SamArray
*dom_users
= NULL
;
797 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
798 uint32 acb_mask
= ACB_NORMAL
;
799 uint32_t size
= 0xffff;
801 if ((argc
< 1) || (argc
> 4)) {
802 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv
[0]);
807 sscanf(argv
[1], "%x", &access_mask
);
811 sscanf(argv
[2], "%x", &acb_mask
);
815 sscanf(argv
[3], "%x", &size
);
818 /* Get sam policy handle */
820 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
821 MAXIMUM_ALLOWED_ACCESS
,
824 if (!NT_STATUS_IS_OK(result
))
827 /* Get domain policy handle */
829 result
= get_domain_handle(cli
, mem_ctx
, "domain",
834 if (!NT_STATUS_IS_OK(result
))
837 /* Enumerate domain users */
842 result
= rpccli_samr_EnumDomainUsers(cli
, mem_ctx
,
850 if (NT_STATUS_IS_OK(result
) ||
851 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
853 for (i
= 0; i
< num_dom_users
; i
++)
854 printf("user:[%s] rid:[0x%x]\n",
855 dom_users
->entries
[i
].name
.string
,
856 dom_users
->entries
[i
].idx
);
859 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
862 if (is_valid_policy_hnd(&domain_pol
))
863 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
865 if (is_valid_policy_hnd(&connect_pol
))
866 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
871 /* Enumerate domain groups */
873 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
875 int argc
, const char **argv
)
877 struct policy_handle connect_pol
, domain_pol
;
878 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
879 uint32 start_idx
, num_dom_groups
, i
;
880 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
881 struct samr_SamArray
*dom_groups
= NULL
;
882 uint32_t size
= 0xffff;
884 if ((argc
< 1) || (argc
> 3)) {
885 printf("Usage: %s [access_mask] [max_size]\n", argv
[0]);
890 sscanf(argv
[1], "%x", &access_mask
);
894 sscanf(argv
[2], "%x", &size
);
897 /* Get sam policy handle */
899 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
900 MAXIMUM_ALLOWED_ACCESS
,
903 if (!NT_STATUS_IS_OK(result
))
906 /* Get domain policy handle */
908 result
= get_domain_handle(cli
, mem_ctx
, "domain",
913 if (!NT_STATUS_IS_OK(result
))
916 /* Enumerate domain groups */
921 result
= rpccli_samr_EnumDomainGroups(cli
, mem_ctx
,
927 if (NT_STATUS_IS_OK(result
) ||
928 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
930 for (i
= 0; i
< num_dom_groups
; i
++)
931 printf("group:[%s] rid:[0x%x]\n",
932 dom_groups
->entries
[i
].name
.string
,
933 dom_groups
->entries
[i
].idx
);
936 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
939 if (is_valid_policy_hnd(&domain_pol
))
940 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
942 if (is_valid_policy_hnd(&connect_pol
))
943 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
948 /* Enumerate alias groups */
950 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
952 int argc
, const char **argv
)
954 struct policy_handle connect_pol
, domain_pol
;
955 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
956 uint32 start_idx
, num_als_groups
, i
;
957 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
958 struct samr_SamArray
*als_groups
= NULL
;
959 uint32_t size
= 0xffff;
961 if ((argc
< 2) || (argc
> 4)) {
962 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv
[0]);
967 sscanf(argv
[2], "%x", &access_mask
);
971 sscanf(argv
[3], "%x", &size
);
974 /* Get sam policy handle */
976 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
977 MAXIMUM_ALLOWED_ACCESS
,
980 if (!NT_STATUS_IS_OK(result
))
983 /* Get domain policy handle */
985 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
991 if (!NT_STATUS_IS_OK(result
))
994 /* Enumerate alias groups */
999 result
= rpccli_samr_EnumDomainAliases(cli
, mem_ctx
,
1006 if (NT_STATUS_IS_OK(result
) ||
1007 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1009 for (i
= 0; i
< num_als_groups
; i
++)
1010 printf("group:[%s] rid:[0x%x]\n",
1011 als_groups
->entries
[i
].name
.string
,
1012 als_groups
->entries
[i
].idx
);
1014 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1017 if (is_valid_policy_hnd(&domain_pol
))
1018 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1020 if (is_valid_policy_hnd(&connect_pol
))
1021 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1026 /* Enumerate domains */
1028 static NTSTATUS
cmd_samr_enum_domains(struct rpc_pipe_client
*cli
,
1029 TALLOC_CTX
*mem_ctx
,
1030 int argc
, const char **argv
)
1032 struct policy_handle connect_pol
;
1033 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1034 uint32 start_idx
, size
, num_entries
, i
;
1035 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1036 struct samr_SamArray
*sam
= NULL
;
1038 if ((argc
< 1) || (argc
> 2)) {
1039 printf("Usage: %s [access mask]\n", argv
[0]);
1040 return NT_STATUS_OK
;
1044 sscanf(argv
[1], "%x", &access_mask
);
1047 /* Get sam policy handle */
1049 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1053 if (!NT_STATUS_IS_OK(result
)) {
1057 /* Enumerate alias groups */
1063 result
= rpccli_samr_EnumDomains(cli
, mem_ctx
,
1070 if (NT_STATUS_IS_OK(result
) ||
1071 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1073 for (i
= 0; i
< num_entries
; i
++)
1074 printf("name:[%s] idx:[0x%x]\n",
1075 sam
->entries
[i
].name
.string
,
1076 sam
->entries
[i
].idx
);
1078 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1081 if (is_valid_policy_hnd(&connect_pol
)) {
1082 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1089 /* Query alias membership */
1091 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
1092 TALLOC_CTX
*mem_ctx
,
1093 int argc
, const char **argv
)
1095 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1096 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1097 uint32 alias_rid
, i
;
1098 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1099 struct lsa_SidArray sid_array
;
1101 if ((argc
< 3) || (argc
> 4)) {
1102 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
1103 return NT_STATUS_OK
;
1106 sscanf(argv
[2], "%i", &alias_rid
);
1109 sscanf(argv
[3], "%x", &access_mask
);
1111 /* Open SAMR handle */
1113 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1114 MAXIMUM_ALLOWED_ACCESS
,
1117 if (!NT_STATUS_IS_OK(result
))
1120 /* Open handle on domain */
1122 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1124 MAXIMUM_ALLOWED_ACCESS
,
1128 if (!NT_STATUS_IS_OK(result
))
1131 /* Open handle on alias */
1133 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1138 if (!NT_STATUS_IS_OK(result
))
1141 result
= rpccli_samr_GetMembersInAlias(cli
, mem_ctx
,
1145 if (!NT_STATUS_IS_OK(result
))
1148 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
1151 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
1152 printf("\tsid:[%s]\n", sid_str
);
1155 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1156 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1157 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1162 /* Query alias info */
1164 static NTSTATUS
cmd_samr_query_aliasinfo(struct rpc_pipe_client
*cli
,
1165 TALLOC_CTX
*mem_ctx
,
1166 int argc
, const char **argv
)
1168 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1169 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1171 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1172 union samr_AliasInfo
*info
= NULL
;
1173 enum samr_AliasInfoEnum level
= ALIASINFOALL
;
1175 if ((argc
< 3) || (argc
> 4)) {
1176 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1178 return NT_STATUS_OK
;
1181 sscanf(argv
[2], "%i", &alias_rid
);
1184 level
= atoi(argv
[3]);
1188 sscanf(argv
[4], "%x", &access_mask
);
1191 /* Open SAMR handle */
1193 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1194 SEC_FLAG_MAXIMUM_ALLOWED
,
1197 if (!NT_STATUS_IS_OK(result
)) {
1201 /* Open handle on domain */
1203 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1205 SEC_FLAG_MAXIMUM_ALLOWED
,
1209 if (!NT_STATUS_IS_OK(result
)) {
1213 /* Open handle on alias */
1215 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1220 if (!NT_STATUS_IS_OK(result
)) {
1224 result
= rpccli_samr_QueryAliasInfo(cli
, mem_ctx
,
1229 if (!NT_STATUS_IS_OK(result
)) {
1235 printf("Name: %s\n", info
->all
.name
.string
);
1236 printf("Description: %s\n", info
->all
.description
.string
);
1237 printf("Num Members: %d\n", info
->all
.num_members
);
1240 printf("Name: %s\n", info
->name
.string
);
1242 case ALIASINFODESCRIPTION
:
1243 printf("Description: %s\n", info
->description
.string
);
1249 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1250 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1251 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1257 /* Query delete an alias membership */
1259 static NTSTATUS
cmd_samr_delete_alias(struct rpc_pipe_client
*cli
,
1260 TALLOC_CTX
*mem_ctx
,
1261 int argc
, const char **argv
)
1263 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1264 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1266 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1269 printf("Usage: %s builtin|domain [rid|name]\n", argv
[0]);
1270 return NT_STATUS_OK
;
1273 alias_rid
= strtoul(argv
[2], NULL
, 10);
1275 /* Open SAMR handle */
1277 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1278 MAXIMUM_ALLOWED_ACCESS
,
1281 if (!NT_STATUS_IS_OK(result
))
1284 /* Open handle on domain */
1286 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1288 MAXIMUM_ALLOWED_ACCESS
,
1292 if (!NT_STATUS_IS_OK(result
))
1295 /* Open handle on alias */
1297 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1302 if (!NT_STATUS_IS_OK(result
) && (alias_rid
== 0)) {
1303 /* Probably this was a user name, try lookupnames */
1304 struct samr_Ids rids
, types
;
1305 struct lsa_String lsa_acct_name
;
1307 init_lsa_String(&lsa_acct_name
, argv
[2]);
1309 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1316 if (NT_STATUS_IS_OK(result
)) {
1317 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1325 result
= rpccli_samr_DeleteDomAlias(cli
, mem_ctx
,
1328 if (!NT_STATUS_IS_OK(result
))
1331 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1332 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1337 /* Query display info */
1339 static NTSTATUS
cmd_samr_query_dispinfo_internal(struct rpc_pipe_client
*cli
,
1340 TALLOC_CTX
*mem_ctx
,
1341 int argc
, const char **argv
,
1344 struct policy_handle connect_pol
, domain_pol
;
1345 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1346 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
= 0, i
;
1347 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1348 uint32 info_level
= 1;
1349 union samr_DispInfo info
;
1351 bool got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1352 uint32_t total_size
, returned_size
;
1355 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1356 return NT_STATUS_OK
;
1360 sscanf(argv
[1], "%i", &info_level
);
1363 sscanf(argv
[2], "%i", &start_idx
);
1366 sscanf(argv
[3], "%i", &max_entries
);
1371 sscanf(argv
[4], "%i", &max_size
);
1376 sscanf(argv
[5], "%x", &access_mask
);
1378 /* Get sam policy handle */
1380 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1381 MAXIMUM_ALLOWED_ACCESS
,
1384 if (!NT_STATUS_IS_OK(result
))
1387 /* Get domain policy handle */
1389 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1395 if (!NT_STATUS_IS_OK(result
))
1398 /* Query display info */
1403 get_query_dispinfo_params(
1404 loop_count
, &max_entries
, &max_size
);
1407 case NDR_SAMR_QUERYDISPLAYINFO
:
1408 result
= rpccli_samr_QueryDisplayInfo(cli
, mem_ctx
,
1418 case NDR_SAMR_QUERYDISPLAYINFO2
:
1419 result
= rpccli_samr_QueryDisplayInfo2(cli
, mem_ctx
,
1430 case NDR_SAMR_QUERYDISPLAYINFO3
:
1431 result
= rpccli_samr_QueryDisplayInfo3(cli
, mem_ctx
,
1443 return NT_STATUS_INVALID_PARAMETER
;
1446 if (!NT_STATUS_IS_OK(result
) &&
1447 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
1448 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
1454 switch (info_level
) {
1456 num_entries
= info
.info1
.count
;
1459 num_entries
= info
.info2
.count
;
1462 num_entries
= info
.info3
.count
;
1465 num_entries
= info
.info4
.count
;
1468 num_entries
= info
.info5
.count
;
1474 start_idx
+= num_entries
;
1476 if (num_entries
== 0)
1479 for (i
= 0; i
< num_entries
; i
++) {
1480 switch (info_level
) {
1482 display_sam_info_1(&info
.info1
.entries
[i
]);
1485 display_sam_info_2(&info
.info2
.entries
[i
]);
1488 display_sam_info_3(&info
.info3
.entries
[i
]);
1491 display_sam_info_4(&info
.info4
.entries
[i
]);
1494 display_sam_info_5(&info
.info5
.entries
[i
]);
1498 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1500 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1501 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1506 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1507 TALLOC_CTX
*mem_ctx
,
1508 int argc
, const char **argv
)
1510 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1511 NDR_SAMR_QUERYDISPLAYINFO
);
1514 static NTSTATUS
cmd_samr_query_dispinfo2(struct rpc_pipe_client
*cli
,
1515 TALLOC_CTX
*mem_ctx
,
1516 int argc
, const char **argv
)
1518 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1519 NDR_SAMR_QUERYDISPLAYINFO2
);
1522 static NTSTATUS
cmd_samr_query_dispinfo3(struct rpc_pipe_client
*cli
,
1523 TALLOC_CTX
*mem_ctx
,
1524 int argc
, const char **argv
)
1526 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1527 NDR_SAMR_QUERYDISPLAYINFO3
);
1530 /* Query domain info */
1532 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1533 TALLOC_CTX
*mem_ctx
,
1534 int argc
, const char **argv
)
1536 struct policy_handle connect_pol
, domain_pol
;
1537 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1538 uint32 switch_level
= 2;
1539 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1540 union samr_DomainInfo
*info
= NULL
;
1543 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1544 return NT_STATUS_OK
;
1548 sscanf(argv
[1], "%i", &switch_level
);
1551 sscanf(argv
[2], "%x", &access_mask
);
1553 /* Get sam policy handle */
1555 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1556 MAXIMUM_ALLOWED_ACCESS
,
1559 if (!NT_STATUS_IS_OK(result
))
1562 /* Get domain policy handle */
1564 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1570 if (!NT_STATUS_IS_OK(result
))
1573 /* Query domain info */
1575 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1580 if (!NT_STATUS_IS_OK(result
))
1583 /* Display domain info */
1585 switch (switch_level
) {
1587 display_sam_dom_info_1(&info
->info1
);
1590 display_sam_dom_info_2(&info
->general
);
1593 display_sam_dom_info_3(&info
->info3
);
1596 display_sam_dom_info_4(&info
->oem
);
1599 display_sam_dom_info_5(&info
->info5
);
1602 display_sam_dom_info_6(&info
->info6
);
1605 display_sam_dom_info_7(&info
->info7
);
1608 display_sam_dom_info_8(&info
->info8
);
1611 display_sam_dom_info_9(&info
->info9
);
1614 display_sam_dom_info_12(&info
->info12
);
1617 display_sam_dom_info_13(&info
->info13
);
1621 printf("cannot display domain info for switch value %d\n",
1628 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1629 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1633 /* Create domain user */
1635 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1636 TALLOC_CTX
*mem_ctx
,
1637 int argc
, const char **argv
)
1639 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1640 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1641 struct lsa_String acct_name
;
1643 uint32 acct_flags
, user_rid
;
1644 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1645 uint32_t access_granted
= 0;
1647 if ((argc
< 2) || (argc
> 3)) {
1648 printf("Usage: %s username [access mask]\n", argv
[0]);
1649 return NT_STATUS_OK
;
1652 init_lsa_String(&acct_name
, argv
[1]);
1655 sscanf(argv
[2], "%x", &access_mask
);
1657 /* Get sam policy handle */
1659 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1660 MAXIMUM_ALLOWED_ACCESS
,
1663 if (!NT_STATUS_IS_OK(result
))
1666 /* Get domain policy handle */
1668 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1674 if (!NT_STATUS_IS_OK(result
))
1677 /* Create domain user */
1679 acb_info
= ACB_NORMAL
;
1680 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1681 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1682 SAMR_USER_ACCESS_SET_PASSWORD
|
1683 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1684 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1686 result
= rpccli_samr_CreateUser2(cli
, mem_ctx
,
1695 if (!NT_STATUS_IS_OK(result
))
1698 result
= rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
1699 if (!NT_STATUS_IS_OK(result
)) goto done
;
1701 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1702 if (!NT_STATUS_IS_OK(result
)) goto done
;
1704 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1705 if (!NT_STATUS_IS_OK(result
)) goto done
;
1711 /* Create domain group */
1713 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1714 TALLOC_CTX
*mem_ctx
,
1715 int argc
, const char **argv
)
1717 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1718 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1719 struct lsa_String grp_name
;
1720 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1723 if ((argc
< 2) || (argc
> 3)) {
1724 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1725 return NT_STATUS_OK
;
1728 init_lsa_String(&grp_name
, argv
[1]);
1731 sscanf(argv
[2], "%x", &access_mask
);
1733 /* Get sam policy handle */
1735 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1736 MAXIMUM_ALLOWED_ACCESS
,
1739 if (!NT_STATUS_IS_OK(result
))
1742 /* Get domain policy handle */
1744 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1750 if (!NT_STATUS_IS_OK(result
))
1753 /* Create domain user */
1754 result
= rpccli_samr_CreateDomainGroup(cli
, mem_ctx
,
1757 MAXIMUM_ALLOWED_ACCESS
,
1761 if (!NT_STATUS_IS_OK(result
))
1764 result
= rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
1765 if (!NT_STATUS_IS_OK(result
)) goto done
;
1767 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1768 if (!NT_STATUS_IS_OK(result
)) goto done
;
1770 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1771 if (!NT_STATUS_IS_OK(result
)) goto done
;
1777 /* Create domain alias */
1779 static NTSTATUS
cmd_samr_create_dom_alias(struct rpc_pipe_client
*cli
,
1780 TALLOC_CTX
*mem_ctx
,
1781 int argc
, const char **argv
)
1783 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1784 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1785 struct lsa_String alias_name
;
1786 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1789 if ((argc
< 2) || (argc
> 3)) {
1790 printf("Usage: %s aliasname [access mask]\n", argv
[0]);
1791 return NT_STATUS_OK
;
1794 init_lsa_String(&alias_name
, argv
[1]);
1797 sscanf(argv
[2], "%x", &access_mask
);
1799 /* Get sam policy handle */
1801 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1802 MAXIMUM_ALLOWED_ACCESS
,
1805 if (!NT_STATUS_IS_OK(result
))
1808 /* Get domain policy handle */
1810 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1816 if (!NT_STATUS_IS_OK(result
))
1819 /* Create domain user */
1821 result
= rpccli_samr_CreateDomAlias(cli
, mem_ctx
,
1824 MAXIMUM_ALLOWED_ACCESS
,
1828 if (!NT_STATUS_IS_OK(result
))
1831 result
= rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1832 if (!NT_STATUS_IS_OK(result
)) goto done
;
1834 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1835 if (!NT_STATUS_IS_OK(result
)) goto done
;
1837 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1838 if (!NT_STATUS_IS_OK(result
)) goto done
;
1844 /* Lookup sam names */
1846 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
1847 TALLOC_CTX
*mem_ctx
,
1848 int argc
, const char **argv
)
1850 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1851 struct policy_handle connect_pol
, domain_pol
;
1853 struct samr_Ids rids
, name_types
;
1855 struct lsa_String
*names
= NULL
;;
1858 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1859 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1860 printf("or check on the builtin SID: S-1-5-32\n");
1861 return NT_STATUS_OK
;
1864 /* Get sam policy and domain handles */
1866 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1867 MAXIMUM_ALLOWED_ACCESS
,
1870 if (!NT_STATUS_IS_OK(result
))
1873 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1875 MAXIMUM_ALLOWED_ACCESS
,
1879 if (!NT_STATUS_IS_OK(result
))
1884 num_names
= argc
- 2;
1886 if ((names
= TALLOC_ARRAY(mem_ctx
, struct lsa_String
, num_names
)) == NULL
) {
1887 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1888 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1889 result
= NT_STATUS_NO_MEMORY
;
1893 for (i
= 0; i
< num_names
; i
++) {
1894 init_lsa_String(&names
[i
], argv
[i
+ 2]);
1897 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1904 if (!NT_STATUS_IS_OK(result
))
1907 /* Display results */
1909 for (i
= 0; i
< num_names
; i
++)
1910 printf("name %s: 0x%x (%d)\n", names
[i
].string
, rids
.ids
[i
],
1913 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1914 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1919 /* Lookup sam rids */
1921 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
1922 TALLOC_CTX
*mem_ctx
,
1923 int argc
, const char **argv
)
1925 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1926 struct policy_handle connect_pol
, domain_pol
;
1927 uint32_t num_rids
, *rids
;
1928 struct lsa_Strings names
;
1929 struct samr_Ids types
;
1934 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1935 return NT_STATUS_OK
;
1938 /* Get sam policy and domain handles */
1940 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1941 MAXIMUM_ALLOWED_ACCESS
,
1944 if (!NT_STATUS_IS_OK(result
))
1947 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1949 MAXIMUM_ALLOWED_ACCESS
,
1953 if (!NT_STATUS_IS_OK(result
))
1958 num_rids
= argc
- 2;
1960 if ((rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
)) == NULL
) {
1961 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1962 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1963 result
= NT_STATUS_NO_MEMORY
;
1967 for (i
= 0; i
< argc
- 2; i
++)
1968 sscanf(argv
[i
+ 2], "%i", &rids
[i
]);
1970 result
= rpccli_samr_LookupRids(cli
, mem_ctx
,
1977 if (!NT_STATUS_IS_OK(result
) &&
1978 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1981 /* Display results */
1983 for (i
= 0; i
< num_rids
; i
++) {
1984 printf("rid 0x%x: %s (%d)\n",
1985 rids
[i
], names
.names
[i
].string
, types
.ids
[i
]);
1988 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1989 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1994 /* Delete domain group */
1996 static NTSTATUS
cmd_samr_delete_dom_group(struct rpc_pipe_client
*cli
,
1997 TALLOC_CTX
*mem_ctx
,
1998 int argc
, const char **argv
)
2000 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2001 struct policy_handle connect_pol
, domain_pol
, group_pol
;
2002 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2004 if ((argc
< 2) || (argc
> 3)) {
2005 printf("Usage: %s groupname\n", argv
[0]);
2006 return NT_STATUS_OK
;
2010 sscanf(argv
[2], "%x", &access_mask
);
2012 /* Get sam policy and domain handles */
2014 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2015 MAXIMUM_ALLOWED_ACCESS
,
2018 if (!NT_STATUS_IS_OK(result
))
2021 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2023 MAXIMUM_ALLOWED_ACCESS
,
2027 if (!NT_STATUS_IS_OK(result
))
2030 /* Get handle on group */
2033 struct samr_Ids group_rids
, name_types
;
2034 struct lsa_String lsa_acct_name
;
2036 init_lsa_String(&lsa_acct_name
, argv
[1]);
2038 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2044 if (!NT_STATUS_IS_OK(result
))
2047 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
2053 if (!NT_STATUS_IS_OK(result
))
2059 result
= rpccli_samr_DeleteDomainGroup(cli
, mem_ctx
,
2062 if (!NT_STATUS_IS_OK(result
))
2065 /* Display results */
2067 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
2068 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2069 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2075 /* Delete domain user */
2077 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
2078 TALLOC_CTX
*mem_ctx
,
2079 int argc
, const char **argv
)
2081 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2082 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2083 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2085 if ((argc
< 2) || (argc
> 3)) {
2086 printf("Usage: %s username\n", argv
[0]);
2087 return NT_STATUS_OK
;
2091 sscanf(argv
[2], "%x", &access_mask
);
2093 /* Get sam policy and domain handles */
2095 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2096 MAXIMUM_ALLOWED_ACCESS
,
2099 if (!NT_STATUS_IS_OK(result
))
2102 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2104 MAXIMUM_ALLOWED_ACCESS
,
2108 if (!NT_STATUS_IS_OK(result
))
2111 /* Get handle on user */
2114 struct samr_Ids user_rids
, name_types
;
2115 struct lsa_String lsa_acct_name
;
2117 init_lsa_String(&lsa_acct_name
, argv
[1]);
2119 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2126 if (!NT_STATUS_IS_OK(result
))
2129 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2135 if (!NT_STATUS_IS_OK(result
))
2141 result
= rpccli_samr_DeleteUser(cli
, mem_ctx
,
2144 if (!NT_STATUS_IS_OK(result
))
2147 /* Display results */
2149 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2150 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2151 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2157 /**********************************************************************
2158 * Query user security object
2160 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
2161 TALLOC_CTX
*mem_ctx
,
2162 int argc
, const char **argv
)
2164 struct policy_handle connect_pol
, domain_pol
, user_pol
, *pol
;
2165 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2166 uint32 sec_info
= SECINFO_DACL
;
2167 uint32 user_rid
= 0;
2168 TALLOC_CTX
*ctx
= NULL
;
2169 struct sec_desc_buf
*sec_desc_buf
=NULL
;
2170 bool domain
= False
;
2172 ctx
=talloc_init("cmd_samr_query_sec_obj");
2174 if ((argc
< 1) || (argc
> 3)) {
2175 printf("Usage: %s [rid|-d] [sec_info]\n", argv
[0]);
2176 printf("\tSpecify rid for security on user, -d for security on domain\n");
2177 talloc_destroy(ctx
);
2178 return NT_STATUS_OK
;
2182 if (strcmp(argv
[1], "-d") == 0)
2185 sscanf(argv
[1], "%i", &user_rid
);
2189 sec_info
= atoi(argv
[2]);
2192 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2193 MAXIMUM_ALLOWED_ACCESS
,
2196 if (!NT_STATUS_IS_OK(result
))
2199 if (domain
|| user_rid
)
2200 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2202 MAXIMUM_ALLOWED_ACCESS
,
2206 if (!NT_STATUS_IS_OK(result
))
2210 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2212 MAXIMUM_ALLOWED_ACCESS
,
2216 if (!NT_STATUS_IS_OK(result
))
2219 /* Pick which query pol to use */
2229 /* Query SAM security object */
2231 result
= rpccli_samr_QuerySecurity(cli
, mem_ctx
,
2236 if (!NT_STATUS_IS_OK(result
))
2239 display_sec_desc(sec_desc_buf
->sd
);
2241 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2242 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2243 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2245 talloc_destroy(ctx
);
2249 static NTSTATUS
cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client
*cli
,
2250 TALLOC_CTX
*mem_ctx
,
2251 int argc
, const char **argv
)
2253 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2254 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2255 struct samr_PwInfo info
;
2259 printf("Usage: %s rid\n", argv
[0]);
2260 return NT_STATUS_OK
;
2263 sscanf(argv
[1], "%i", &rid
);
2265 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2266 MAXIMUM_ALLOWED_ACCESS
,
2269 if (!NT_STATUS_IS_OK(result
)) {
2273 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2275 MAXIMUM_ALLOWED_ACCESS
,
2279 if (!NT_STATUS_IS_OK(result
)) {
2283 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2285 MAXIMUM_ALLOWED_ACCESS
,
2289 if (!NT_STATUS_IS_OK(result
)) {
2293 result
= rpccli_samr_GetUserPwInfo(cli
, mem_ctx
, &user_pol
, &info
);
2294 if (NT_STATUS_IS_OK(result
)) {
2295 printf("min_password_length: %d\n", info
.min_password_length
);
2297 NDR_PRINT_STRUCT_STRING(mem_ctx
,
2298 samr_PasswordProperties
, &info
.password_properties
));
2302 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2303 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2304 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2309 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
2310 TALLOC_CTX
*mem_ctx
,
2311 int argc
, const char **argv
)
2313 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2314 struct lsa_String domain_name
;
2315 struct samr_PwInfo info
;
2317 if (argc
< 1 || argc
> 3) {
2318 printf("Usage: %s <domain>\n", argv
[0]);
2319 return NT_STATUS_OK
;
2322 init_lsa_String(&domain_name
, argv
[1]);
2324 result
= rpccli_samr_GetDomPwInfo(cli
, mem_ctx
, &domain_name
, &info
);
2326 if (NT_STATUS_IS_OK(result
)) {
2327 printf("min_password_length: %d\n", info
.min_password_length
);
2328 display_password_properties(info
.password_properties
);
2334 /* Look up domain name */
2336 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
2337 TALLOC_CTX
*mem_ctx
,
2338 int argc
, const char **argv
)
2340 struct policy_handle connect_pol
, domain_pol
;
2341 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2342 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2344 struct lsa_String domain_name
;
2345 struct dom_sid
*sid
= NULL
;
2348 printf("Usage: %s domain_name\n", argv
[0]);
2349 return NT_STATUS_OK
;
2352 init_lsa_String(&domain_name
, argv
[1]);
2354 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2358 if (!NT_STATUS_IS_OK(result
))
2361 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2367 if (!NT_STATUS_IS_OK(result
))
2370 result
= rpccli_samr_LookupDomain(cli
, mem_ctx
,
2375 if (NT_STATUS_IS_OK(result
)) {
2376 sid_to_fstring(sid_string
, sid
);
2377 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2378 argv
[1], sid_string
);
2381 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2382 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2387 /* Change user password */
2389 static NTSTATUS
cmd_samr_chgpasswd(struct rpc_pipe_client
*cli
,
2390 TALLOC_CTX
*mem_ctx
,
2391 int argc
, const char **argv
)
2393 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2394 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2395 const char *user
, *oldpass
, *newpass
;
2396 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2397 struct samr_Ids rids
, types
;
2398 struct lsa_String lsa_acct_name
;
2401 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2402 return NT_STATUS_INVALID_PARAMETER
;
2409 /* Get sam policy handle */
2411 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2412 MAXIMUM_ALLOWED_ACCESS
,
2415 if (!NT_STATUS_IS_OK(result
)) {
2419 /* Get domain policy handle */
2421 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2427 if (!NT_STATUS_IS_OK(result
)) {
2431 init_lsa_String(&lsa_acct_name
, user
);
2433 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2440 if (!NT_STATUS_IS_OK(result
)) {
2444 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2450 if (!NT_STATUS_IS_OK(result
)) {
2454 /* Change user password */
2455 result
= rpccli_samr_chgpasswd_user(cli
, mem_ctx
,
2460 if (!NT_STATUS_IS_OK(result
)) {
2465 if (is_valid_policy_hnd(&user_pol
)) {
2466 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2468 if (is_valid_policy_hnd(&domain_pol
)) {
2469 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2471 if (is_valid_policy_hnd(&connect_pol
)) {
2472 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2479 /* Change user password */
2481 static NTSTATUS
cmd_samr_chgpasswd2(struct rpc_pipe_client
*cli
,
2482 TALLOC_CTX
*mem_ctx
,
2483 int argc
, const char **argv
)
2485 struct policy_handle connect_pol
, domain_pol
;
2486 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2487 const char *user
, *oldpass
, *newpass
;
2488 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2491 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2492 return NT_STATUS_INVALID_PARAMETER
;
2499 /* Get sam policy handle */
2501 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2502 MAXIMUM_ALLOWED_ACCESS
,
2505 if (!NT_STATUS_IS_OK(result
))
2508 /* Get domain policy handle */
2510 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2516 if (!NT_STATUS_IS_OK(result
))
2519 /* Change user password */
2520 result
= rpccli_samr_chgpasswd_user2(cli
, mem_ctx
, user
, newpass
, oldpass
);
2522 if (!NT_STATUS_IS_OK(result
))
2525 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2526 if (!NT_STATUS_IS_OK(result
)) goto done
;
2528 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2529 if (!NT_STATUS_IS_OK(result
)) goto done
;
2536 /* Change user password */
2538 static NTSTATUS
cmd_samr_chgpasswd3(struct rpc_pipe_client
*cli
,
2539 TALLOC_CTX
*mem_ctx
,
2540 int argc
, const char **argv
)
2542 struct policy_handle connect_pol
, domain_pol
;
2543 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2544 const char *user
, *oldpass
, *newpass
;
2545 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2546 struct samr_DomInfo1
*info
= NULL
;
2547 struct userPwdChangeFailureInformation
*reject
= NULL
;
2550 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2551 return NT_STATUS_INVALID_PARAMETER
;
2558 /* Get sam policy handle */
2560 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2561 MAXIMUM_ALLOWED_ACCESS
,
2564 if (!NT_STATUS_IS_OK(result
))
2567 /* Get domain policy handle */
2569 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2575 if (!NT_STATUS_IS_OK(result
))
2578 /* Change user password */
2579 result
= rpccli_samr_chgpasswd_user3(cli
, mem_ctx
,
2586 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
)) {
2588 display_sam_dom_info_1(info
);
2590 switch (reject
->extendedFailureReason
) {
2591 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT
:
2592 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2594 case SAM_PWD_CHANGE_PWD_IN_HISTORY
:
2595 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2597 case SAM_PWD_CHANGE_NOT_COMPLEX
:
2598 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2601 d_printf("unknown reject reason: %d\n",
2602 reject
->extendedFailureReason
);
2607 if (!NT_STATUS_IS_OK(result
))
2610 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2611 if (!NT_STATUS_IS_OK(result
)) goto done
;
2613 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2614 if (!NT_STATUS_IS_OK(result
)) goto done
;
2620 static NTSTATUS
cmd_samr_setuserinfo_int(struct rpc_pipe_client
*cli
,
2621 TALLOC_CTX
*mem_ctx
,
2622 int argc
, const char **argv
,
2625 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2626 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
2627 const char *user
, *param
;
2628 uint32_t access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2631 union samr_UserInfo info
;
2632 struct samr_CryptPassword pwd_buf
;
2633 struct samr_CryptPasswordEx pwd_buf_ex
;
2634 uint8_t nt_hash
[16];
2635 uint8_t lm_hash
[16];
2636 DATA_BLOB session_key
;
2637 uint8_t password_expired
= 0;
2640 printf("Usage: %s username level password [password_expired]\n",
2642 return NT_STATUS_INVALID_PARAMETER
;
2646 level
= atoi(argv
[2]);
2650 password_expired
= atoi(argv
[4]);
2653 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2654 if (!NT_STATUS_IS_OK(status
)) {
2658 init_samr_CryptPassword(param
, &session_key
, &pwd_buf
);
2659 init_samr_CryptPasswordEx(param
, &session_key
, &pwd_buf_ex
);
2660 nt_lm_owf_gen(param
, nt_hash
, lm_hash
);
2666 in
= data_blob_const(nt_hash
, 16);
2667 out
= data_blob_talloc_zero(mem_ctx
, 16);
2668 sess_crypt_blob(&out
, &in
, &session_key
, true);
2669 memcpy(nt_hash
, out
.data
, out
.length
);
2673 in
= data_blob_const(lm_hash
, 16);
2674 out
= data_blob_talloc_zero(mem_ctx
, 16);
2675 sess_crypt_blob(&out
, &in
, &session_key
, true);
2676 memcpy(lm_hash
, out
.data
, out
.length
);
2679 memcpy(info
.info18
.nt_pwd
.hash
, nt_hash
, 16);
2680 memcpy(info
.info18
.lm_pwd
.hash
, lm_hash
, 16);
2681 info
.info18
.nt_pwd_active
= true;
2682 info
.info18
.lm_pwd_active
= true;
2683 info
.info18
.password_expired
= password_expired
;
2687 ZERO_STRUCT(info
.info21
);
2689 info
.info21
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2690 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2692 info
.info21
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2693 info
.info21
.password_expired
= password_expired
;
2696 info
.info21
.lm_password_set
= true;
2697 info
.info21
.lm_owf_password
.length
= 16;
2698 info
.info21
.lm_owf_password
.size
= 16;
2700 info
.info21
.nt_password_set
= true;
2701 info
.info21
.nt_owf_password
.length
= 16;
2702 info
.info21
.nt_owf_password
.size
= 16;
2706 in
= data_blob_const(nt_hash
, 16);
2707 out
= data_blob_talloc_zero(mem_ctx
, 16);
2708 sess_crypt_blob(&out
, &in
, &session_key
, true);
2709 info
.info21
.nt_owf_password
.array
=
2710 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2714 in
= data_blob_const(lm_hash
, 16);
2715 out
= data_blob_talloc_zero(mem_ctx
, 16);
2716 sess_crypt_blob(&out
, &in
, &session_key
, true);
2717 info
.info21
.lm_owf_password
.array
=
2718 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2723 ZERO_STRUCT(info
.info23
);
2725 info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2726 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2728 info
.info23
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2729 info
.info23
.info
.password_expired
= password_expired
;
2732 info
.info23
.password
= pwd_buf
;
2736 info
.info24
.password
= pwd_buf
;
2737 info
.info24
.password_expired
= password_expired
;
2741 ZERO_STRUCT(info
.info25
);
2743 info
.info25
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2744 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2746 info
.info25
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2747 info
.info25
.info
.password_expired
= password_expired
;
2750 info
.info25
.password
= pwd_buf_ex
;
2754 info
.info26
.password
= pwd_buf_ex
;
2755 info
.info26
.password_expired
= password_expired
;
2759 return NT_STATUS_INVALID_INFO_CLASS
;
2762 /* Get sam policy handle */
2764 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2765 MAXIMUM_ALLOWED_ACCESS
,
2768 if (!NT_STATUS_IS_OK(status
))
2771 /* Get domain policy handle */
2773 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2779 if (!NT_STATUS_IS_OK(status
))
2782 user_rid
= strtol(user
, NULL
, 0);
2784 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2791 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
) ||
2794 /* Probably this was a user name, try lookupnames */
2795 struct samr_Ids rids
, types
;
2796 struct lsa_String lsa_acct_name
;
2798 init_lsa_String(&lsa_acct_name
, user
);
2800 status
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2806 if (!NT_STATUS_IS_OK(status
)) {
2810 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2815 if (!NT_STATUS_IS_OK(status
)) {
2821 case NDR_SAMR_SETUSERINFO
:
2822 status
= rpccli_samr_SetUserInfo(cli
, mem_ctx
,
2827 case NDR_SAMR_SETUSERINFO2
:
2828 status
= rpccli_samr_SetUserInfo2(cli
, mem_ctx
,
2834 return NT_STATUS_INVALID_PARAMETER
;
2841 static NTSTATUS
cmd_samr_setuserinfo(struct rpc_pipe_client
*cli
,
2842 TALLOC_CTX
*mem_ctx
,
2843 int argc
, const char **argv
)
2845 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2846 NDR_SAMR_SETUSERINFO
);
2849 static NTSTATUS
cmd_samr_setuserinfo2(struct rpc_pipe_client
*cli
,
2850 TALLOC_CTX
*mem_ctx
,
2851 int argc
, const char **argv
)
2853 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2854 NDR_SAMR_SETUSERINFO2
);
2857 static NTSTATUS
cmd_samr_get_dispinfo_idx(struct rpc_pipe_client
*cli
,
2858 TALLOC_CTX
*mem_ctx
,
2859 int argc
, const char **argv
)
2862 struct policy_handle connect_handle
;
2863 struct policy_handle domain_handle
;
2865 struct lsa_String name
;
2868 if (argc
< 2 || argc
> 3) {
2869 printf("Usage: %s name level\n", argv
[0]);
2870 return NT_STATUS_INVALID_PARAMETER
;
2873 init_lsa_String(&name
, argv
[1]);
2876 level
= atoi(argv
[2]);
2879 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2880 SEC_FLAG_MAXIMUM_ALLOWED
,
2883 if (!NT_STATUS_IS_OK(status
)) {
2887 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2889 SEC_FLAG_MAXIMUM_ALLOWED
,
2893 if (!NT_STATUS_IS_OK(status
))
2897 status
= rpccli_samr_GetDisplayEnumerationIndex(cli
, mem_ctx
,
2903 if (NT_STATUS_IS_OK(status
) ||
2904 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2905 printf("idx: %d (0x%08x)\n", idx
, idx
);
2909 if (is_valid_policy_hnd(&domain_handle
)) {
2910 rpccli_samr_Close(cli
, mem_ctx
, &domain_handle
);
2912 if (is_valid_policy_hnd(&connect_handle
)) {
2913 rpccli_samr_Close(cli
, mem_ctx
, &connect_handle
);
2919 /* List of commands exported by this module */
2921 struct cmd_set samr_commands
[] = {
2925 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user info", "" },
2926 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group info", "" },
2927 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user groups", "" },
2928 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user aliases", "" },
2929 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group membership", "" },
2930 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias membership", "" },
2931 { "queryaliasinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias info", "" },
2932 { "deletealias", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete an alias", "" },
2933 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2934 { "querydispinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2935 { "querydispinfo3", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2936 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query domain info", "" },
2937 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain users", "" },
2938 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain groups", "" },
2939 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate alias groups", "" },
2940 { "enumdomains", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_domains
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domains", "" },
2942 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain user", "" },
2943 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain group", "" },
2944 { "createdomalias", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain alias", "" },
2945 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2946 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2947 { "deletedomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain group", "" },
2948 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain user", "" },
2949 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query SAMR security object", "" },
2950 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve domain password info", "" },
2951 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_usrdom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve user domain password info", "" },
2953 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Lookup Domain Name", "" },
2954 { "chgpasswd", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2955 { "chgpasswd2", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2956 { "chgpasswd3", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2957 { "getdispinfoidx", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dispinfo_idx
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Get Display Information Index", "" },
2958 { "setuserinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info", "" },
2959 { "setuserinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info2", "" },