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"
29 extern DOM_SID domain_sid
;
31 /****************************************************************************
32 display samr_user_info_7 structure
33 ****************************************************************************/
34 static void display_samr_user_info_7(struct samr_UserInfo7
*r
)
36 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
39 /****************************************************************************
40 display samr_user_info_9 structure
41 ****************************************************************************/
42 static void display_samr_user_info_9(struct samr_UserInfo9
*r
)
44 printf("\tPrimary group RID :\tox%x\n", r
->primary_gid
);
47 /****************************************************************************
48 display samr_user_info_16 structure
49 ****************************************************************************/
50 static void display_samr_user_info_16(struct samr_UserInfo16
*r
)
52 printf("\tAcct Flags :\tox%x\n", r
->acct_flags
);
55 /****************************************************************************
56 display samr_user_info_20 structure
57 ****************************************************************************/
58 static void display_samr_user_info_20(struct samr_UserInfo20
*r
)
60 printf("\tRemote Dial :\n");
61 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
65 /****************************************************************************
66 display samr_user_info_21 structure
67 ****************************************************************************/
68 static void display_samr_user_info_21(struct samr_UserInfo21
*r
)
70 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
71 printf("\tFull Name :\t%s\n", r
->full_name
.string
);
72 printf("\tHome Drive :\t%s\n", r
->home_directory
.string
);
73 printf("\tDir Drive :\t%s\n", r
->home_drive
.string
);
74 printf("\tProfile Path:\t%s\n", r
->profile_path
.string
);
75 printf("\tLogon Script:\t%s\n", r
->logon_script
.string
);
76 printf("\tDescription :\t%s\n", r
->description
.string
);
77 printf("\tWorkstations:\t%s\n", r
->workstations
.string
);
78 printf("\tComment :\t%s\n", r
->comment
.string
);
79 printf("\tRemote Dial :\n");
80 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
82 printf("\tLogon Time :\t%s\n",
83 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logon
)));
84 printf("\tLogoff Time :\t%s\n",
85 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logoff
)));
86 printf("\tKickoff Time :\t%s\n",
87 http_timestring(talloc_tos(), nt_time_to_unix(r
->acct_expiry
)));
88 printf("\tPassword last set Time :\t%s\n",
89 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_password_change
)));
90 printf("\tPassword can change Time :\t%s\n",
91 http_timestring(talloc_tos(), nt_time_to_unix(r
->allow_password_change
)));
92 printf("\tPassword must change Time:\t%s\n",
93 http_timestring(talloc_tos(), nt_time_to_unix(r
->force_password_change
)));
95 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
97 printf("\tuser_rid :\t0x%x\n" , r
->rid
); /* User ID */
98 printf("\tgroup_rid:\t0x%x\n" , r
->primary_gid
); /* Group ID */
99 printf("\tacb_info :\t0x%08x\n", r
->acct_flags
); /* Account Control Info */
101 printf("\tfields_present:\t0x%08x\n", r
->fields_present
); /* 0x00ff ffff */
102 printf("\tlogon_divs:\t%d\n", r
->logon_hours
.units_per_week
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
103 printf("\tbad_password_count:\t0x%08x\n", r
->bad_password_count
);
104 printf("\tlogon_count:\t0x%08x\n", r
->logon_count
);
106 printf("\tpadding1[0..7]...\n");
108 if (r
->logon_hours
.bits
) {
109 printf("\tlogon_hrs[0..%d]...\n", r
->logon_hours
.units_per_week
/8);
114 static void display_password_properties(uint32_t password_properties
)
116 printf("password_properties: 0x%08x\n", password_properties
);
118 if (password_properties
& DOMAIN_PASSWORD_COMPLEX
)
119 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
121 if (password_properties
& DOMAIN_PASSWORD_NO_ANON_CHANGE
)
122 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
124 if (password_properties
& DOMAIN_PASSWORD_NO_CLEAR_CHANGE
)
125 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
127 if (password_properties
& DOMAIN_PASSWORD_LOCKOUT_ADMINS
)
128 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
130 if (password_properties
& DOMAIN_PASSWORD_STORE_CLEARTEXT
)
131 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
133 if (password_properties
& DOMAIN_REFUSE_PASSWORD_CHANGE
)
134 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
137 static void display_sam_dom_info_1(struct samr_DomInfo1
*info1
)
139 printf("Minimum password length:\t\t\t%d\n",
140 info1
->min_password_length
);
141 printf("Password uniqueness (remember x passwords):\t%d\n",
142 info1
->password_history_length
);
143 display_password_properties(info1
->password_properties
);
144 printf("password expire in:\t\t\t\t%s\n",
145 display_time(info1
->max_password_age
));
146 printf("Min password age (allow changing in x days):\t%s\n",
147 display_time(info1
->min_password_age
));
150 static void display_sam_dom_info_2(struct samr_DomGeneralInformation
*general
)
152 printf("Domain:\t\t%s\n", general
->domain_name
.string
);
153 printf("Server:\t\t%s\n", general
->primary
.string
);
154 printf("Comment:\t%s\n", general
->oem_information
.string
);
156 printf("Total Users:\t%d\n", general
->num_users
);
157 printf("Total Groups:\t%d\n", general
->num_groups
);
158 printf("Total Aliases:\t%d\n", general
->num_aliases
);
160 printf("Sequence No:\t%llu\n", (unsigned long long)general
->sequence_num
);
162 printf("Force Logoff:\t%d\n",
163 (int)nt_time_to_unix_abs(&general
->force_logoff_time
));
165 printf("Domain Server State:\t0x%x\n", general
->domain_server_state
);
166 printf("Server Role:\t%s\n", server_role_str(general
->role
));
167 printf("Unknown 3:\t0x%x\n", general
->unknown3
);
170 static void display_sam_dom_info_3(struct samr_DomInfo3
*info3
)
172 printf("Force Logoff:\t%d\n",
173 (int)nt_time_to_unix_abs(&info3
->force_logoff_time
));
176 static void display_sam_dom_info_4(struct samr_DomOEMInformation
*oem
)
178 printf("Comment:\t%s\n", oem
->oem_information
.string
);
181 static void display_sam_dom_info_5(struct samr_DomInfo5
*info5
)
183 printf("Domain:\t\t%s\n", info5
->domain_name
.string
);
186 static void display_sam_dom_info_6(struct samr_DomInfo6
*info6
)
188 printf("Server:\t\t%s\n", info6
->primary
.string
);
191 static void display_sam_dom_info_7(struct samr_DomInfo7
*info7
)
193 printf("Server Role:\t%s\n", server_role_str(info7
->role
));
196 static void display_sam_dom_info_8(struct samr_DomInfo8
*info8
)
198 printf("Sequence No:\t%llu\n", (unsigned long long)info8
->sequence_num
);
199 printf("Domain Create Time:\t%s\n",
200 http_timestring(talloc_tos(), nt_time_to_unix(info8
->domain_create_time
)));
203 static void display_sam_dom_info_9(struct samr_DomInfo9
*info9
)
205 printf("Domain Server State:\t0x%x\n", info9
->domain_server_state
);
208 static void display_sam_dom_info_12(struct samr_DomInfo12
*info12
)
210 printf("Bad password lockout duration: %s\n",
211 display_time(info12
->lockout_duration
));
212 printf("Reset Lockout after: %s\n",
213 display_time(info12
->lockout_window
));
214 printf("Lockout after bad attempts: %d\n",
215 info12
->lockout_threshold
);
218 static void display_sam_dom_info_13(struct samr_DomInfo13
*info13
)
220 printf("Sequence No:\t%llu\n", (unsigned long long)info13
->sequence_num
);
221 printf("Domain Create Time:\t%s\n",
222 http_timestring(talloc_tos(), nt_time_to_unix(info13
->domain_create_time
)));
223 printf("Sequence No at last promotion:\t%llu\n",
224 (unsigned long long)info13
->modified_count_at_last_promotion
);
227 static void display_sam_info_1(struct samr_DispEntryGeneral
*r
)
229 printf("index: 0x%x ", r
->idx
);
230 printf("RID: 0x%x ", r
->rid
);
231 printf("acb: 0x%08x ", r
->acct_flags
);
232 printf("Account: %s\t", r
->account_name
.string
);
233 printf("Name: %s\t", r
->full_name
.string
);
234 printf("Desc: %s\n", r
->description
.string
);
237 static void display_sam_info_2(struct samr_DispEntryFull
*r
)
239 printf("index: 0x%x ", r
->idx
);
240 printf("RID: 0x%x ", r
->rid
);
241 printf("acb: 0x%08x ", r
->acct_flags
);
242 printf("Account: %s\t", r
->account_name
.string
);
243 printf("Desc: %s\n", r
->description
.string
);
246 static void display_sam_info_3(struct samr_DispEntryFullGroup
*r
)
248 printf("index: 0x%x ", r
->idx
);
249 printf("RID: 0x%x ", r
->rid
);
250 printf("acb: 0x%08x ", r
->acct_flags
);
251 printf("Account: %s\t", r
->account_name
.string
);
252 printf("Desc: %s\n", r
->description
.string
);
255 static void display_sam_info_4(struct samr_DispEntryAscii
*r
)
257 printf("index: 0x%x ", r
->idx
);
258 printf("Account: %s\n", r
->account_name
.string
);
261 static void display_sam_info_5(struct samr_DispEntryAscii
*r
)
263 printf("index: 0x%x ", r
->idx
);
264 printf("Account: %s\n", r
->account_name
.string
);
267 /****************************************************************************
268 ****************************************************************************/
270 static NTSTATUS
get_domain_handle(struct rpc_pipe_client
*cli
,
273 struct policy_handle
*connect_pol
,
274 uint32_t access_mask
,
275 struct dom_sid
*_domain_sid
,
276 struct policy_handle
*domain_pol
)
279 if (StrCaseCmp(sam
, "domain") == 0) {
280 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
285 } else if (StrCaseCmp(sam
, "builtin") == 0) {
286 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
289 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
293 return NT_STATUS_INVALID_PARAMETER
;
296 /**********************************************************************
297 * Query user information
299 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
301 int argc
, const char **argv
)
303 struct policy_handle connect_pol
, domain_pol
, user_pol
;
304 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
305 uint32 info_level
= 21;
306 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
307 union samr_UserInfo
*info
= NULL
;
310 if ((argc
< 2) || (argc
> 4)) {
311 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
315 sscanf(argv
[1], "%i", &user_rid
);
318 sscanf(argv
[2], "%i", &info_level
);
321 sscanf(argv
[3], "%x", &access_mask
);
324 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
325 MAXIMUM_ALLOWED_ACCESS
,
328 if (!NT_STATUS_IS_OK(result
))
331 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
333 MAXIMUM_ALLOWED_ACCESS
,
336 if (!NT_STATUS_IS_OK(result
))
339 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
345 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) &&
348 /* Probably this was a user name, try lookupnames */
349 struct samr_Ids rids
, types
;
350 struct lsa_String lsa_acct_name
;
352 init_lsa_String(&lsa_acct_name
, argv
[1]);
354 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
361 if (NT_STATUS_IS_OK(result
)) {
362 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
371 if (!NT_STATUS_IS_OK(result
))
374 result
= rpccli_samr_QueryUserInfo(cli
, mem_ctx
,
379 if (!NT_STATUS_IS_OK(result
))
382 switch (info_level
) {
384 display_samr_user_info_7(&info
->info7
);
387 display_samr_user_info_9(&info
->info9
);
390 display_samr_user_info_16(&info
->info16
);
393 display_samr_user_info_20(&info
->info20
);
396 display_samr_user_info_21(&info
->info21
);
399 printf("Unsupported infolevel: %d\n", info_level
);
403 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
404 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
405 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
411 /****************************************************************************
413 ****************************************************************************/
414 static void display_group_info1(struct samr_GroupInfoAll
*info1
)
416 printf("\tGroup Name:\t%s\n", info1
->name
.string
);
417 printf("\tDescription:\t%s\n", info1
->description
.string
);
418 printf("\tGroup Attribute:%d\n", info1
->attributes
);
419 printf("\tNum Members:%d\n", info1
->num_members
);
422 /****************************************************************************
424 ****************************************************************************/
425 static void display_group_info2(struct lsa_String
*info2
)
427 printf("\tGroup Description:%s\n", info2
->string
);
431 /****************************************************************************
433 ****************************************************************************/
434 static void display_group_info3(struct samr_GroupInfoAttributes
*info3
)
436 printf("\tGroup Attribute:%d\n", info3
->attributes
);
440 /****************************************************************************
442 ****************************************************************************/
443 static void display_group_info4(struct lsa_String
*info4
)
445 printf("\tGroup Description:%s\n", info4
->string
);
448 /****************************************************************************
450 ****************************************************************************/
451 static void display_group_info5(struct samr_GroupInfoAll
*info5
)
453 printf("\tGroup Name:\t%s\n", info5
->name
.string
);
454 printf("\tDescription:\t%s\n", info5
->description
.string
);
455 printf("\tGroup Attribute:%d\n", info5
->attributes
);
456 printf("\tNum Members:%d\n", info5
->num_members
);
459 /****************************************************************************
460 display sam sync structure
461 ****************************************************************************/
462 static void display_group_info(union samr_GroupInfo
*info
,
463 enum samr_GroupInfoEnum level
)
467 display_group_info1(&info
->all
);
470 display_group_info2(&info
->name
);
473 display_group_info3(&info
->attributes
);
476 display_group_info4(&info
->description
);
479 display_group_info5(&info
->all2
);
484 /***********************************************************************
485 * Query group information
487 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
489 int argc
, const char **argv
)
491 struct policy_handle connect_pol
, domain_pol
, group_pol
;
492 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
493 enum samr_GroupInfoEnum info_level
= GROUPINFOALL
;
494 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
495 union samr_GroupInfo
*group_info
= NULL
;
498 if ((argc
< 2) || (argc
> 4)) {
499 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
503 sscanf(argv
[1], "%i", &group_rid
);
506 info_level
= atoi(argv
[2]);
509 sscanf(argv
[3], "%x", &access_mask
);
511 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
512 MAXIMUM_ALLOWED_ACCESS
,
515 if (!NT_STATUS_IS_OK(result
))
518 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
520 MAXIMUM_ALLOWED_ACCESS
,
524 if (!NT_STATUS_IS_OK(result
))
527 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
533 if (!NT_STATUS_IS_OK(result
))
536 result
= rpccli_samr_QueryGroupInfo(cli
, mem_ctx
,
540 if (!NT_STATUS_IS_OK(result
)) {
544 display_group_info(group_info
, info_level
);
546 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
547 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
548 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
553 /* Query groups a user is a member of */
555 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
557 int argc
, const char **argv
)
559 struct policy_handle connect_pol
,
562 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
564 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
566 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
568 if ((argc
< 2) || (argc
> 3)) {
569 printf("Usage: %s rid [access mask]\n", argv
[0]);
573 sscanf(argv
[1], "%i", &user_rid
);
576 sscanf(argv
[2], "%x", &access_mask
);
578 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
579 MAXIMUM_ALLOWED_ACCESS
,
582 if (!NT_STATUS_IS_OK(result
))
585 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
587 MAXIMUM_ALLOWED_ACCESS
,
588 &domain_sid
, &domain_pol
);
590 if (!NT_STATUS_IS_OK(result
))
593 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
599 if (!NT_STATUS_IS_OK(result
))
602 result
= rpccli_samr_GetGroupsForUser(cli
, mem_ctx
,
606 if (!NT_STATUS_IS_OK(result
))
609 for (i
= 0; i
< rid_array
->count
; i
++) {
610 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
611 rid_array
->rids
[i
].rid
,
612 rid_array
->rids
[i
].attributes
);
615 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
616 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
617 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
622 /* Query aliases a user is a member of */
624 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
626 int argc
, const char **argv
)
628 struct policy_handle connect_pol
, domain_pol
;
629 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
632 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
634 struct lsa_SidArray sid_array
;
635 struct samr_Ids alias_rids
;
638 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
639 return NT_STATUS_INVALID_PARAMETER
;
645 for (i
=2; i
<argc
; i
++) {
647 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
648 printf("%s is not a legal SID\n", argv
[i
]);
649 return NT_STATUS_INVALID_PARAMETER
;
651 result
= add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
652 if (!NT_STATUS_IS_OK(result
)) {
658 sid_array
.sids
= TALLOC_ZERO_ARRAY(mem_ctx
, struct lsa_SidPtr
, num_sids
);
659 if (sid_array
.sids
== NULL
)
660 return NT_STATUS_NO_MEMORY
;
662 sid_array
.sids
= NULL
;
665 for (i
=0; i
<num_sids
; i
++) {
666 sid_array
.sids
[i
].sid
= sid_dup_talloc(mem_ctx
, &sids
[i
]);
667 if (!sid_array
.sids
[i
].sid
) {
668 return NT_STATUS_NO_MEMORY
;
672 sid_array
.num_sids
= num_sids
;
674 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
675 MAXIMUM_ALLOWED_ACCESS
,
678 if (!NT_STATUS_IS_OK(result
))
681 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
687 if (!NT_STATUS_IS_OK(result
))
690 result
= rpccli_samr_GetAliasMembership(cli
, mem_ctx
,
694 if (!NT_STATUS_IS_OK(result
))
697 for (i
= 0; i
< alias_rids
.count
; i
++) {
698 printf("\tgroup rid:[0x%x]\n", alias_rids
.ids
[i
]);
701 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
702 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
707 /* Query members of a group */
709 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
711 int argc
, const char **argv
)
713 struct policy_handle connect_pol
, domain_pol
, group_pol
;
714 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
716 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
718 unsigned int old_timeout
;
719 struct samr_RidTypeArray
*rids
= NULL
;
721 if ((argc
< 2) || (argc
> 3)) {
722 printf("Usage: %s rid [access mask]\n", argv
[0]);
726 sscanf(argv
[1], "%i", &group_rid
);
729 sscanf(argv
[2], "%x", &access_mask
);
731 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
732 MAXIMUM_ALLOWED_ACCESS
,
735 if (!NT_STATUS_IS_OK(result
))
738 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
740 MAXIMUM_ALLOWED_ACCESS
,
744 if (!NT_STATUS_IS_OK(result
))
747 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
753 if (!NT_STATUS_IS_OK(result
))
756 /* Make sure to wait for our DC's reply */
757 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
758 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
760 result
= rpccli_samr_QueryGroupMember(cli
, mem_ctx
,
764 rpccli_set_timeout(cli
, old_timeout
);
766 if (!NT_STATUS_IS_OK(result
))
769 for (i
= 0; i
< rids
->count
; i
++) {
770 printf("\trid:[0x%x] attr:[0x%x]\n", rids
->rids
[i
],
774 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
775 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
776 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
781 /* Enumerate domain users */
783 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
785 int argc
, const char **argv
)
787 struct policy_handle connect_pol
, domain_pol
;
788 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
789 uint32 start_idx
, size
, num_dom_users
, i
;
790 struct samr_SamArray
*dom_users
= NULL
;
791 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
792 uint32 acb_mask
= ACB_NORMAL
;
794 if ((argc
< 1) || (argc
> 3)) {
795 printf("Usage: %s [access_mask] [acb_mask]\n", argv
[0]);
800 sscanf(argv
[1], "%x", &access_mask
);
803 sscanf(argv
[2], "%x", &acb_mask
);
805 /* Get sam policy handle */
807 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
808 MAXIMUM_ALLOWED_ACCESS
,
811 if (!NT_STATUS_IS_OK(result
))
814 /* Get domain policy handle */
816 result
= get_domain_handle(cli
, mem_ctx
, "domain",
821 if (!NT_STATUS_IS_OK(result
))
824 /* Enumerate domain users */
830 result
= rpccli_samr_EnumDomainUsers(cli
, mem_ctx
,
838 if (NT_STATUS_IS_OK(result
) ||
839 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
841 for (i
= 0; i
< num_dom_users
; i
++)
842 printf("user:[%s] rid:[0x%x]\n",
843 dom_users
->entries
[i
].name
.string
,
844 dom_users
->entries
[i
].idx
);
847 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
850 if (is_valid_policy_hnd(&domain_pol
))
851 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
853 if (is_valid_policy_hnd(&connect_pol
))
854 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
859 /* Enumerate domain groups */
861 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
863 int argc
, const char **argv
)
865 struct policy_handle connect_pol
, domain_pol
;
866 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
867 uint32 start_idx
, size
, num_dom_groups
, i
;
868 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
869 struct samr_SamArray
*dom_groups
= NULL
;
871 if ((argc
< 1) || (argc
> 2)) {
872 printf("Usage: %s [access_mask]\n", argv
[0]);
877 sscanf(argv
[1], "%x", &access_mask
);
879 /* Get sam policy handle */
881 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
882 MAXIMUM_ALLOWED_ACCESS
,
885 if (!NT_STATUS_IS_OK(result
))
888 /* Get domain policy handle */
890 result
= get_domain_handle(cli
, mem_ctx
, "domain",
895 if (!NT_STATUS_IS_OK(result
))
898 /* Enumerate domain groups */
904 result
= rpccli_samr_EnumDomainGroups(cli
, mem_ctx
,
910 if (NT_STATUS_IS_OK(result
) ||
911 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
913 for (i
= 0; i
< num_dom_groups
; i
++)
914 printf("group:[%s] rid:[0x%x]\n",
915 dom_groups
->entries
[i
].name
.string
,
916 dom_groups
->entries
[i
].idx
);
919 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
922 if (is_valid_policy_hnd(&domain_pol
))
923 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
925 if (is_valid_policy_hnd(&connect_pol
))
926 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
931 /* Enumerate alias groups */
933 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
935 int argc
, const char **argv
)
937 struct policy_handle connect_pol
, domain_pol
;
938 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
939 uint32 start_idx
, size
, num_als_groups
, i
;
940 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
941 struct samr_SamArray
*als_groups
= NULL
;
943 if ((argc
< 2) || (argc
> 3)) {
944 printf("Usage: %s builtin|domain [access mask]\n", argv
[0]);
949 sscanf(argv
[2], "%x", &access_mask
);
951 /* Get sam policy handle */
953 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
954 MAXIMUM_ALLOWED_ACCESS
,
957 if (!NT_STATUS_IS_OK(result
))
960 /* Get domain policy handle */
962 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
968 if (!NT_STATUS_IS_OK(result
))
971 /* Enumerate alias groups */
974 size
= 0xffff; /* Number of groups to retrieve */
977 result
= rpccli_samr_EnumDomainAliases(cli
, mem_ctx
,
984 if (NT_STATUS_IS_OK(result
) ||
985 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
987 for (i
= 0; i
< num_als_groups
; i
++)
988 printf("group:[%s] rid:[0x%x]\n",
989 als_groups
->entries
[i
].name
.string
,
990 als_groups
->entries
[i
].idx
);
992 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
995 if (is_valid_policy_hnd(&domain_pol
))
996 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
998 if (is_valid_policy_hnd(&connect_pol
))
999 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1004 /* Enumerate domains */
1006 static NTSTATUS
cmd_samr_enum_domains(struct rpc_pipe_client
*cli
,
1007 TALLOC_CTX
*mem_ctx
,
1008 int argc
, const char **argv
)
1010 struct policy_handle connect_pol
;
1011 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1012 uint32 start_idx
, size
, num_entries
, i
;
1013 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1014 struct samr_SamArray
*sam
= NULL
;
1016 if ((argc
< 1) || (argc
> 2)) {
1017 printf("Usage: %s [access mask]\n", argv
[0]);
1018 return NT_STATUS_OK
;
1022 sscanf(argv
[1], "%x", &access_mask
);
1025 /* Get sam policy handle */
1027 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1031 if (!NT_STATUS_IS_OK(result
)) {
1035 /* Enumerate alias groups */
1041 result
= rpccli_samr_EnumDomains(cli
, mem_ctx
,
1048 if (NT_STATUS_IS_OK(result
) ||
1049 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1051 for (i
= 0; i
< num_entries
; i
++)
1052 printf("name:[%s] idx:[0x%x]\n",
1053 sam
->entries
[i
].name
.string
,
1054 sam
->entries
[i
].idx
);
1056 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1059 if (is_valid_policy_hnd(&connect_pol
)) {
1060 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1067 /* Query alias membership */
1069 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
1070 TALLOC_CTX
*mem_ctx
,
1071 int argc
, const char **argv
)
1073 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1074 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1075 uint32 alias_rid
, i
;
1076 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1077 struct lsa_SidArray sid_array
;
1079 if ((argc
< 3) || (argc
> 4)) {
1080 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
1081 return NT_STATUS_OK
;
1084 sscanf(argv
[2], "%i", &alias_rid
);
1087 sscanf(argv
[3], "%x", &access_mask
);
1089 /* Open SAMR handle */
1091 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1092 MAXIMUM_ALLOWED_ACCESS
,
1095 if (!NT_STATUS_IS_OK(result
))
1098 /* Open handle on domain */
1100 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1102 MAXIMUM_ALLOWED_ACCESS
,
1106 if (!NT_STATUS_IS_OK(result
))
1109 /* Open handle on alias */
1111 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1116 if (!NT_STATUS_IS_OK(result
))
1119 result
= rpccli_samr_GetMembersInAlias(cli
, mem_ctx
,
1123 if (!NT_STATUS_IS_OK(result
))
1126 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
1129 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
1130 printf("\tsid:[%s]\n", sid_str
);
1133 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1134 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1135 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1140 /* Query alias info */
1142 static NTSTATUS
cmd_samr_query_aliasinfo(struct rpc_pipe_client
*cli
,
1143 TALLOC_CTX
*mem_ctx
,
1144 int argc
, const char **argv
)
1146 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1147 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1149 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1150 union samr_AliasInfo
*info
= NULL
;
1151 enum samr_AliasInfoEnum level
= ALIASINFOALL
;
1153 if ((argc
< 3) || (argc
> 4)) {
1154 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1156 return NT_STATUS_OK
;
1159 sscanf(argv
[2], "%i", &alias_rid
);
1162 level
= atoi(argv
[3]);
1166 sscanf(argv
[4], "%x", &access_mask
);
1169 /* Open SAMR handle */
1171 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1172 SEC_FLAG_MAXIMUM_ALLOWED
,
1175 if (!NT_STATUS_IS_OK(result
)) {
1179 /* Open handle on domain */
1181 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1183 SEC_FLAG_MAXIMUM_ALLOWED
,
1187 if (!NT_STATUS_IS_OK(result
)) {
1191 /* Open handle on alias */
1193 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1198 if (!NT_STATUS_IS_OK(result
)) {
1202 result
= rpccli_samr_QueryAliasInfo(cli
, mem_ctx
,
1207 if (!NT_STATUS_IS_OK(result
)) {
1213 printf("Name: %s\n", info
->all
.name
.string
);
1214 printf("Description: %s\n", info
->all
.description
.string
);
1215 printf("Num Members: %d\n", info
->all
.num_members
);
1218 printf("Name: %s\n", info
->name
.string
);
1220 case ALIASINFODESCRIPTION
:
1221 printf("Description: %s\n", info
->description
.string
);
1227 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1228 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1229 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1235 /* Query delete an alias membership */
1237 static NTSTATUS
cmd_samr_delete_alias(struct rpc_pipe_client
*cli
,
1238 TALLOC_CTX
*mem_ctx
,
1239 int argc
, const char **argv
)
1241 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1242 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1244 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1247 printf("Usage: %s builtin|domain [rid|name]\n", argv
[0]);
1248 return NT_STATUS_OK
;
1251 alias_rid
= strtoul(argv
[2], NULL
, 10);
1253 /* Open SAMR handle */
1255 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1256 MAXIMUM_ALLOWED_ACCESS
,
1259 if (!NT_STATUS_IS_OK(result
))
1262 /* Open handle on domain */
1264 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1266 MAXIMUM_ALLOWED_ACCESS
,
1270 if (!NT_STATUS_IS_OK(result
))
1273 /* Open handle on alias */
1275 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1280 if (!NT_STATUS_IS_OK(result
) && (alias_rid
== 0)) {
1281 /* Probably this was a user name, try lookupnames */
1282 struct samr_Ids rids
, types
;
1283 struct lsa_String lsa_acct_name
;
1285 init_lsa_String(&lsa_acct_name
, argv
[2]);
1287 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1294 if (NT_STATUS_IS_OK(result
)) {
1295 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1303 result
= rpccli_samr_DeleteDomAlias(cli
, mem_ctx
,
1306 if (!NT_STATUS_IS_OK(result
))
1309 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1310 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1315 /* Query display info */
1317 static NTSTATUS
cmd_samr_query_dispinfo_internal(struct rpc_pipe_client
*cli
,
1318 TALLOC_CTX
*mem_ctx
,
1319 int argc
, const char **argv
,
1322 struct policy_handle connect_pol
, domain_pol
;
1323 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1324 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
= 0, i
;
1325 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1326 uint32 info_level
= 1;
1327 union samr_DispInfo info
;
1329 bool got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1330 uint32_t total_size
, returned_size
;
1333 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1334 return NT_STATUS_OK
;
1338 sscanf(argv
[1], "%i", &info_level
);
1341 sscanf(argv
[2], "%i", &start_idx
);
1344 sscanf(argv
[3], "%i", &max_entries
);
1349 sscanf(argv
[4], "%i", &max_size
);
1354 sscanf(argv
[5], "%x", &access_mask
);
1356 /* Get sam policy handle */
1358 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1359 MAXIMUM_ALLOWED_ACCESS
,
1362 if (!NT_STATUS_IS_OK(result
))
1365 /* Get domain policy handle */
1367 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1373 if (!NT_STATUS_IS_OK(result
))
1376 /* Query display info */
1381 get_query_dispinfo_params(
1382 loop_count
, &max_entries
, &max_size
);
1385 case NDR_SAMR_QUERYDISPLAYINFO
:
1386 result
= rpccli_samr_QueryDisplayInfo(cli
, mem_ctx
,
1396 case NDR_SAMR_QUERYDISPLAYINFO2
:
1397 result
= rpccli_samr_QueryDisplayInfo2(cli
, mem_ctx
,
1408 case NDR_SAMR_QUERYDISPLAYINFO3
:
1409 result
= rpccli_samr_QueryDisplayInfo3(cli
, mem_ctx
,
1421 return NT_STATUS_INVALID_PARAMETER
;
1424 if (!NT_STATUS_IS_OK(result
) &&
1425 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
1426 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
1432 switch (info_level
) {
1434 num_entries
= info
.info1
.count
;
1437 num_entries
= info
.info2
.count
;
1440 num_entries
= info
.info3
.count
;
1443 num_entries
= info
.info4
.count
;
1446 num_entries
= info
.info5
.count
;
1452 start_idx
+= num_entries
;
1454 if (num_entries
== 0)
1457 for (i
= 0; i
< num_entries
; i
++) {
1458 switch (info_level
) {
1460 display_sam_info_1(&info
.info1
.entries
[i
]);
1463 display_sam_info_2(&info
.info2
.entries
[i
]);
1466 display_sam_info_3(&info
.info3
.entries
[i
]);
1469 display_sam_info_4(&info
.info4
.entries
[i
]);
1472 display_sam_info_5(&info
.info5
.entries
[i
]);
1476 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1478 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1479 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1484 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1485 TALLOC_CTX
*mem_ctx
,
1486 int argc
, const char **argv
)
1488 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1489 NDR_SAMR_QUERYDISPLAYINFO
);
1492 static NTSTATUS
cmd_samr_query_dispinfo2(struct rpc_pipe_client
*cli
,
1493 TALLOC_CTX
*mem_ctx
,
1494 int argc
, const char **argv
)
1496 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1497 NDR_SAMR_QUERYDISPLAYINFO2
);
1500 static NTSTATUS
cmd_samr_query_dispinfo3(struct rpc_pipe_client
*cli
,
1501 TALLOC_CTX
*mem_ctx
,
1502 int argc
, const char **argv
)
1504 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1505 NDR_SAMR_QUERYDISPLAYINFO3
);
1508 /* Query domain info */
1510 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1511 TALLOC_CTX
*mem_ctx
,
1512 int argc
, const char **argv
)
1514 struct policy_handle connect_pol
, domain_pol
;
1515 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1516 uint32 switch_level
= 2;
1517 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1518 union samr_DomainInfo
*info
= NULL
;
1521 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1522 return NT_STATUS_OK
;
1526 sscanf(argv
[1], "%i", &switch_level
);
1529 sscanf(argv
[2], "%x", &access_mask
);
1531 /* Get sam policy handle */
1533 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1534 MAXIMUM_ALLOWED_ACCESS
,
1537 if (!NT_STATUS_IS_OK(result
))
1540 /* Get domain policy handle */
1542 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1548 if (!NT_STATUS_IS_OK(result
))
1551 /* Query domain info */
1553 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1558 if (!NT_STATUS_IS_OK(result
))
1561 /* Display domain info */
1563 switch (switch_level
) {
1565 display_sam_dom_info_1(&info
->info1
);
1568 display_sam_dom_info_2(&info
->general
);
1571 display_sam_dom_info_3(&info
->info3
);
1574 display_sam_dom_info_4(&info
->oem
);
1577 display_sam_dom_info_5(&info
->info5
);
1580 display_sam_dom_info_6(&info
->info6
);
1583 display_sam_dom_info_7(&info
->info7
);
1586 display_sam_dom_info_8(&info
->info8
);
1589 display_sam_dom_info_9(&info
->info9
);
1592 display_sam_dom_info_12(&info
->info12
);
1595 display_sam_dom_info_13(&info
->info13
);
1599 printf("cannot display domain info for switch value %d\n",
1606 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1607 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1611 /* Create domain user */
1613 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1614 TALLOC_CTX
*mem_ctx
,
1615 int argc
, const char **argv
)
1617 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1618 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1619 struct lsa_String acct_name
;
1621 uint32 acct_flags
, user_rid
;
1622 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1623 uint32_t access_granted
= 0;
1625 if ((argc
< 2) || (argc
> 3)) {
1626 printf("Usage: %s username [access mask]\n", argv
[0]);
1627 return NT_STATUS_OK
;
1630 init_lsa_String(&acct_name
, argv
[1]);
1633 sscanf(argv
[2], "%x", &access_mask
);
1635 /* Get sam policy handle */
1637 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1638 MAXIMUM_ALLOWED_ACCESS
,
1641 if (!NT_STATUS_IS_OK(result
))
1644 /* Get domain policy handle */
1646 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1652 if (!NT_STATUS_IS_OK(result
))
1655 /* Create domain user */
1657 acb_info
= ACB_NORMAL
;
1658 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1659 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1660 SAMR_USER_ACCESS_SET_PASSWORD
|
1661 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1662 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1664 result
= rpccli_samr_CreateUser2(cli
, mem_ctx
,
1673 if (!NT_STATUS_IS_OK(result
))
1676 result
= rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
1677 if (!NT_STATUS_IS_OK(result
)) goto done
;
1679 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1680 if (!NT_STATUS_IS_OK(result
)) goto done
;
1682 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1683 if (!NT_STATUS_IS_OK(result
)) goto done
;
1689 /* Create domain group */
1691 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1692 TALLOC_CTX
*mem_ctx
,
1693 int argc
, const char **argv
)
1695 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1696 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1697 struct lsa_String grp_name
;
1698 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1701 if ((argc
< 2) || (argc
> 3)) {
1702 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1703 return NT_STATUS_OK
;
1706 init_lsa_String(&grp_name
, argv
[1]);
1709 sscanf(argv
[2], "%x", &access_mask
);
1711 /* Get sam policy handle */
1713 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1714 MAXIMUM_ALLOWED_ACCESS
,
1717 if (!NT_STATUS_IS_OK(result
))
1720 /* Get domain policy handle */
1722 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1728 if (!NT_STATUS_IS_OK(result
))
1731 /* Create domain user */
1732 result
= rpccli_samr_CreateDomainGroup(cli
, mem_ctx
,
1735 MAXIMUM_ALLOWED_ACCESS
,
1739 if (!NT_STATUS_IS_OK(result
))
1742 result
= rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
1743 if (!NT_STATUS_IS_OK(result
)) goto done
;
1745 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1746 if (!NT_STATUS_IS_OK(result
)) goto done
;
1748 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1749 if (!NT_STATUS_IS_OK(result
)) goto done
;
1755 /* Create domain alias */
1757 static NTSTATUS
cmd_samr_create_dom_alias(struct rpc_pipe_client
*cli
,
1758 TALLOC_CTX
*mem_ctx
,
1759 int argc
, const char **argv
)
1761 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1762 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1763 struct lsa_String alias_name
;
1764 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1767 if ((argc
< 2) || (argc
> 3)) {
1768 printf("Usage: %s aliasname [access mask]\n", argv
[0]);
1769 return NT_STATUS_OK
;
1772 init_lsa_String(&alias_name
, argv
[1]);
1775 sscanf(argv
[2], "%x", &access_mask
);
1777 /* Get sam policy handle */
1779 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1780 MAXIMUM_ALLOWED_ACCESS
,
1783 if (!NT_STATUS_IS_OK(result
))
1786 /* Get domain policy handle */
1788 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1794 if (!NT_STATUS_IS_OK(result
))
1797 /* Create domain user */
1799 result
= rpccli_samr_CreateDomAlias(cli
, mem_ctx
,
1802 MAXIMUM_ALLOWED_ACCESS
,
1806 if (!NT_STATUS_IS_OK(result
))
1809 result
= rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1810 if (!NT_STATUS_IS_OK(result
)) goto done
;
1812 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1813 if (!NT_STATUS_IS_OK(result
)) goto done
;
1815 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1816 if (!NT_STATUS_IS_OK(result
)) goto done
;
1822 /* Lookup sam names */
1824 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
1825 TALLOC_CTX
*mem_ctx
,
1826 int argc
, const char **argv
)
1828 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1829 struct policy_handle connect_pol
, domain_pol
;
1831 struct samr_Ids rids
, name_types
;
1833 struct lsa_String
*names
= NULL
;;
1836 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1837 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1838 printf("or check on the builtin SID: S-1-5-32\n");
1839 return NT_STATUS_OK
;
1842 /* Get sam policy and domain handles */
1844 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1845 MAXIMUM_ALLOWED_ACCESS
,
1848 if (!NT_STATUS_IS_OK(result
))
1851 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1853 MAXIMUM_ALLOWED_ACCESS
,
1857 if (!NT_STATUS_IS_OK(result
))
1862 num_names
= argc
- 2;
1864 if ((names
= TALLOC_ARRAY(mem_ctx
, struct lsa_String
, num_names
)) == NULL
) {
1865 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1866 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1867 result
= NT_STATUS_NO_MEMORY
;
1871 for (i
= 0; i
< num_names
; i
++) {
1872 init_lsa_String(&names
[i
], argv
[i
+ 2]);
1875 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1882 if (!NT_STATUS_IS_OK(result
))
1885 /* Display results */
1887 for (i
= 0; i
< num_names
; i
++)
1888 printf("name %s: 0x%x (%d)\n", names
[i
].string
, rids
.ids
[i
],
1891 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1892 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1897 /* Lookup sam rids */
1899 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
1900 TALLOC_CTX
*mem_ctx
,
1901 int argc
, const char **argv
)
1903 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1904 struct policy_handle connect_pol
, domain_pol
;
1905 uint32_t num_rids
, *rids
;
1906 struct lsa_Strings names
;
1907 struct samr_Ids types
;
1912 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1913 return NT_STATUS_OK
;
1916 /* Get sam policy and domain handles */
1918 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1919 MAXIMUM_ALLOWED_ACCESS
,
1922 if (!NT_STATUS_IS_OK(result
))
1925 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1927 MAXIMUM_ALLOWED_ACCESS
,
1931 if (!NT_STATUS_IS_OK(result
))
1936 num_rids
= argc
- 2;
1938 if ((rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
)) == NULL
) {
1939 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1940 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1941 result
= NT_STATUS_NO_MEMORY
;
1945 for (i
= 0; i
< argc
- 2; i
++)
1946 sscanf(argv
[i
+ 2], "%i", &rids
[i
]);
1948 result
= rpccli_samr_LookupRids(cli
, mem_ctx
,
1955 if (!NT_STATUS_IS_OK(result
) &&
1956 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1959 /* Display results */
1961 for (i
= 0; i
< num_rids
; i
++) {
1962 printf("rid 0x%x: %s (%d)\n",
1963 rids
[i
], names
.names
[i
].string
, types
.ids
[i
]);
1966 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1967 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1972 /* Delete domain group */
1974 static NTSTATUS
cmd_samr_delete_dom_group(struct rpc_pipe_client
*cli
,
1975 TALLOC_CTX
*mem_ctx
,
1976 int argc
, const char **argv
)
1978 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1979 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1980 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1982 if ((argc
< 2) || (argc
> 3)) {
1983 printf("Usage: %s groupname\n", argv
[0]);
1984 return NT_STATUS_OK
;
1988 sscanf(argv
[2], "%x", &access_mask
);
1990 /* Get sam policy and domain handles */
1992 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1993 MAXIMUM_ALLOWED_ACCESS
,
1996 if (!NT_STATUS_IS_OK(result
))
1999 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2001 MAXIMUM_ALLOWED_ACCESS
,
2005 if (!NT_STATUS_IS_OK(result
))
2008 /* Get handle on group */
2011 struct samr_Ids group_rids
, name_types
;
2012 struct lsa_String lsa_acct_name
;
2014 init_lsa_String(&lsa_acct_name
, argv
[1]);
2016 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2022 if (!NT_STATUS_IS_OK(result
))
2025 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
2031 if (!NT_STATUS_IS_OK(result
))
2037 result
= rpccli_samr_DeleteDomainGroup(cli
, mem_ctx
,
2040 if (!NT_STATUS_IS_OK(result
))
2043 /* Display results */
2045 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
2046 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2047 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2053 /* Delete domain user */
2055 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
2056 TALLOC_CTX
*mem_ctx
,
2057 int argc
, const char **argv
)
2059 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2060 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2061 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2063 if ((argc
< 2) || (argc
> 3)) {
2064 printf("Usage: %s username\n", argv
[0]);
2065 return NT_STATUS_OK
;
2069 sscanf(argv
[2], "%x", &access_mask
);
2071 /* Get sam policy and domain handles */
2073 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2074 MAXIMUM_ALLOWED_ACCESS
,
2077 if (!NT_STATUS_IS_OK(result
))
2080 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2082 MAXIMUM_ALLOWED_ACCESS
,
2086 if (!NT_STATUS_IS_OK(result
))
2089 /* Get handle on user */
2092 struct samr_Ids user_rids
, name_types
;
2093 struct lsa_String lsa_acct_name
;
2095 init_lsa_String(&lsa_acct_name
, argv
[1]);
2097 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2104 if (!NT_STATUS_IS_OK(result
))
2107 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2113 if (!NT_STATUS_IS_OK(result
))
2119 result
= rpccli_samr_DeleteUser(cli
, mem_ctx
,
2122 if (!NT_STATUS_IS_OK(result
))
2125 /* Display results */
2127 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2128 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2129 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2135 /**********************************************************************
2136 * Query user security object
2138 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
2139 TALLOC_CTX
*mem_ctx
,
2140 int argc
, const char **argv
)
2142 struct policy_handle connect_pol
, domain_pol
, user_pol
, *pol
;
2143 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2144 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
2145 uint32 user_rid
= 0;
2146 TALLOC_CTX
*ctx
= NULL
;
2147 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
2148 bool domain
= False
;
2150 ctx
=talloc_init("cmd_samr_query_sec_obj");
2152 if ((argc
< 1) || (argc
> 3)) {
2153 printf("Usage: %s [rid|-d] [sec_info]\n", argv
[0]);
2154 printf("\tSpecify rid for security on user, -d for security on domain\n");
2155 talloc_destroy(ctx
);
2156 return NT_STATUS_OK
;
2160 if (strcmp(argv
[1], "-d") == 0)
2163 sscanf(argv
[1], "%i", &user_rid
);
2167 sec_info
= atoi(argv
[2]);
2170 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2171 MAXIMUM_ALLOWED_ACCESS
,
2174 if (!NT_STATUS_IS_OK(result
))
2177 if (domain
|| user_rid
)
2178 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2180 MAXIMUM_ALLOWED_ACCESS
,
2184 if (!NT_STATUS_IS_OK(result
))
2188 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2190 MAXIMUM_ALLOWED_ACCESS
,
2194 if (!NT_STATUS_IS_OK(result
))
2197 /* Pick which query pol to use */
2207 /* Query SAM security object */
2209 result
= rpccli_samr_QuerySecurity(cli
, mem_ctx
,
2214 if (!NT_STATUS_IS_OK(result
))
2217 display_sec_desc(sec_desc_buf
->sd
);
2219 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2220 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2221 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2223 talloc_destroy(ctx
);
2227 static NTSTATUS
cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client
*cli
,
2228 TALLOC_CTX
*mem_ctx
,
2229 int argc
, const char **argv
)
2231 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2232 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2233 struct samr_PwInfo info
;
2237 printf("Usage: %s rid\n", argv
[0]);
2238 return NT_STATUS_OK
;
2241 sscanf(argv
[1], "%i", &rid
);
2243 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2244 MAXIMUM_ALLOWED_ACCESS
,
2247 if (!NT_STATUS_IS_OK(result
)) {
2251 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2253 MAXIMUM_ALLOWED_ACCESS
,
2257 if (!NT_STATUS_IS_OK(result
)) {
2261 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2263 MAXIMUM_ALLOWED_ACCESS
,
2267 if (!NT_STATUS_IS_OK(result
)) {
2271 result
= rpccli_samr_GetUserPwInfo(cli
, mem_ctx
, &user_pol
, &info
);
2272 if (NT_STATUS_IS_OK(result
)) {
2273 printf("min_password_length: %d\n", info
.min_password_length
);
2275 NDR_PRINT_STRUCT_STRING(mem_ctx
,
2276 samr_PasswordProperties
, &info
.password_properties
));
2280 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2281 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2282 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2287 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
2288 TALLOC_CTX
*mem_ctx
,
2289 int argc
, const char **argv
)
2291 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2292 struct lsa_String domain_name
;
2293 struct samr_PwInfo info
;
2295 if (argc
< 1 || argc
> 3) {
2296 printf("Usage: %s <domain>\n", argv
[0]);
2297 return NT_STATUS_OK
;
2300 init_lsa_String(&domain_name
, argv
[1]);
2302 result
= rpccli_samr_GetDomPwInfo(cli
, mem_ctx
, &domain_name
, &info
);
2304 if (NT_STATUS_IS_OK(result
)) {
2305 printf("min_password_length: %d\n", info
.min_password_length
);
2306 display_password_properties(info
.password_properties
);
2312 /* Look up domain name */
2314 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
2315 TALLOC_CTX
*mem_ctx
,
2316 int argc
, const char **argv
)
2318 struct policy_handle connect_pol
, domain_pol
;
2319 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2320 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2322 struct lsa_String domain_name
;
2323 DOM_SID
*sid
= NULL
;
2326 printf("Usage: %s domain_name\n", argv
[0]);
2327 return NT_STATUS_OK
;
2330 init_lsa_String(&domain_name
, argv
[1]);
2332 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2336 if (!NT_STATUS_IS_OK(result
))
2339 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2345 if (!NT_STATUS_IS_OK(result
))
2348 result
= rpccli_samr_LookupDomain(cli
, mem_ctx
,
2353 if (NT_STATUS_IS_OK(result
)) {
2354 sid_to_fstring(sid_string
, sid
);
2355 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2356 argv
[1], sid_string
);
2359 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2360 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2365 /* Change user password */
2367 static NTSTATUS
cmd_samr_chgpasswd(struct rpc_pipe_client
*cli
,
2368 TALLOC_CTX
*mem_ctx
,
2369 int argc
, const char **argv
)
2371 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2372 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2373 const char *user
, *oldpass
, *newpass
;
2374 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2375 struct samr_Ids rids
, types
;
2376 struct lsa_String lsa_acct_name
;
2379 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2380 return NT_STATUS_INVALID_PARAMETER
;
2387 /* Get sam policy handle */
2389 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2390 MAXIMUM_ALLOWED_ACCESS
,
2393 if (!NT_STATUS_IS_OK(result
)) {
2397 /* Get domain policy handle */
2399 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2405 if (!NT_STATUS_IS_OK(result
)) {
2409 init_lsa_String(&lsa_acct_name
, user
);
2411 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2418 if (!NT_STATUS_IS_OK(result
)) {
2422 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2428 if (!NT_STATUS_IS_OK(result
)) {
2432 /* Change user password */
2433 result
= rpccli_samr_chgpasswd_user(cli
, mem_ctx
,
2438 if (!NT_STATUS_IS_OK(result
)) {
2443 if (is_valid_policy_hnd(&user_pol
)) {
2444 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2446 if (is_valid_policy_hnd(&domain_pol
)) {
2447 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2449 if (is_valid_policy_hnd(&connect_pol
)) {
2450 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2457 /* Change user password */
2459 static NTSTATUS
cmd_samr_chgpasswd2(struct rpc_pipe_client
*cli
,
2460 TALLOC_CTX
*mem_ctx
,
2461 int argc
, const char **argv
)
2463 struct policy_handle connect_pol
, domain_pol
;
2464 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2465 const char *user
, *oldpass
, *newpass
;
2466 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2469 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2470 return NT_STATUS_INVALID_PARAMETER
;
2477 /* Get sam policy handle */
2479 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2480 MAXIMUM_ALLOWED_ACCESS
,
2483 if (!NT_STATUS_IS_OK(result
))
2486 /* Get domain policy handle */
2488 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2494 if (!NT_STATUS_IS_OK(result
))
2497 /* Change user password */
2498 result
= rpccli_samr_chgpasswd_user2(cli
, mem_ctx
, user
, newpass
, oldpass
);
2500 if (!NT_STATUS_IS_OK(result
))
2503 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2504 if (!NT_STATUS_IS_OK(result
)) goto done
;
2506 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2507 if (!NT_STATUS_IS_OK(result
)) goto done
;
2514 /* Change user password */
2516 static NTSTATUS
cmd_samr_chgpasswd3(struct rpc_pipe_client
*cli
,
2517 TALLOC_CTX
*mem_ctx
,
2518 int argc
, const char **argv
)
2520 struct policy_handle connect_pol
, domain_pol
;
2521 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2522 const char *user
, *oldpass
, *newpass
;
2523 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2524 struct samr_DomInfo1
*info
= NULL
;
2525 struct samr_ChangeReject
*reject
= NULL
;
2528 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2529 return NT_STATUS_INVALID_PARAMETER
;
2536 /* Get sam policy handle */
2538 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2539 MAXIMUM_ALLOWED_ACCESS
,
2542 if (!NT_STATUS_IS_OK(result
))
2545 /* Get domain policy handle */
2547 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2553 if (!NT_STATUS_IS_OK(result
))
2556 /* Change user password */
2557 result
= rpccli_samr_chgpasswd_user3(cli
, mem_ctx
,
2564 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
)) {
2566 display_sam_dom_info_1(info
);
2568 switch (reject
->reason
) {
2569 case SAMR_REJECT_TOO_SHORT
:
2570 d_printf("SAMR_REJECT_TOO_SHORT\n");
2572 case SAMR_REJECT_IN_HISTORY
:
2573 d_printf("SAMR_REJECT_IN_HISTORY\n");
2575 case SAMR_REJECT_COMPLEXITY
:
2576 d_printf("SAMR_REJECT_COMPLEXITY\n");
2578 case SAMR_REJECT_OTHER
:
2579 d_printf("SAMR_REJECT_OTHER\n");
2582 d_printf("unknown reject reason: %d\n",
2588 if (!NT_STATUS_IS_OK(result
))
2591 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2592 if (!NT_STATUS_IS_OK(result
)) goto done
;
2594 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2595 if (!NT_STATUS_IS_OK(result
)) goto done
;
2601 static NTSTATUS
cmd_samr_setuserinfo_int(struct rpc_pipe_client
*cli
,
2602 TALLOC_CTX
*mem_ctx
,
2603 int argc
, const char **argv
,
2606 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2607 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
2608 const char *user
, *param
;
2609 uint32_t access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2612 union samr_UserInfo info
;
2613 struct samr_CryptPassword pwd_buf
;
2614 struct samr_CryptPasswordEx pwd_buf_ex
;
2615 uint8_t nt_hash
[16];
2616 uint8_t lm_hash
[16];
2617 DATA_BLOB session_key
;
2618 uint8_t password_expired
= 0;
2621 printf("Usage: %s username level password [password_expired]\n",
2623 return NT_STATUS_INVALID_PARAMETER
;
2627 level
= atoi(argv
[2]);
2631 password_expired
= atoi(argv
[4]);
2634 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2635 if (!NT_STATUS_IS_OK(status
)) {
2639 init_samr_CryptPassword(param
, &session_key
, &pwd_buf
);
2640 init_samr_CryptPasswordEx(param
, &session_key
, &pwd_buf_ex
);
2641 nt_lm_owf_gen(param
, nt_hash
, lm_hash
);
2647 in
= data_blob_const(nt_hash
, 16);
2648 out
= data_blob_talloc_zero(mem_ctx
, 16);
2649 sess_crypt_blob(&out
, &in
, &session_key
, true);
2650 memcpy(nt_hash
, out
.data
, out
.length
);
2654 in
= data_blob_const(lm_hash
, 16);
2655 out
= data_blob_talloc_zero(mem_ctx
, 16);
2656 sess_crypt_blob(&out
, &in
, &session_key
, true);
2657 memcpy(lm_hash
, out
.data
, out
.length
);
2660 memcpy(info
.info18
.nt_pwd
.hash
, nt_hash
, 16);
2661 memcpy(info
.info18
.lm_pwd
.hash
, lm_hash
, 16);
2662 info
.info18
.nt_pwd_active
= true;
2663 info
.info18
.lm_pwd_active
= true;
2664 info
.info18
.password_expired
= password_expired
;
2668 ZERO_STRUCT(info
.info21
);
2670 info
.info21
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2671 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2673 info
.info21
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2674 info
.info21
.password_expired
= password_expired
;
2677 info
.info21
.lm_password_set
= true;
2678 info
.info21
.lm_owf_password
.length
= 16;
2679 info
.info21
.lm_owf_password
.size
= 16;
2681 info
.info21
.nt_password_set
= true;
2682 info
.info21
.nt_owf_password
.length
= 16;
2683 info
.info21
.nt_owf_password
.size
= 16;
2687 in
= data_blob_const(nt_hash
, 16);
2688 out
= data_blob_talloc_zero(mem_ctx
, 16);
2689 sess_crypt_blob(&out
, &in
, &session_key
, true);
2690 info
.info21
.nt_owf_password
.array
=
2691 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2695 in
= data_blob_const(lm_hash
, 16);
2696 out
= data_blob_talloc_zero(mem_ctx
, 16);
2697 sess_crypt_blob(&out
, &in
, &session_key
, true);
2698 info
.info21
.lm_owf_password
.array
=
2699 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2704 ZERO_STRUCT(info
.info23
);
2706 info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2707 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2709 info
.info23
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2710 info
.info23
.info
.password_expired
= password_expired
;
2713 info
.info23
.password
= pwd_buf
;
2717 info
.info24
.password
= pwd_buf
;
2718 info
.info24
.password_expired
= password_expired
;
2722 ZERO_STRUCT(info
.info25
);
2724 info
.info25
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2725 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2727 info
.info25
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2728 info
.info25
.info
.password_expired
= password_expired
;
2731 info
.info25
.password
= pwd_buf_ex
;
2735 info
.info26
.password
= pwd_buf_ex
;
2736 info
.info26
.password_expired
= password_expired
;
2740 return NT_STATUS_INVALID_INFO_CLASS
;
2743 /* Get sam policy handle */
2745 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2746 MAXIMUM_ALLOWED_ACCESS
,
2749 if (!NT_STATUS_IS_OK(status
))
2752 /* Get domain policy handle */
2754 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2760 if (!NT_STATUS_IS_OK(status
))
2763 user_rid
= strtol(user
, NULL
, 0);
2765 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2772 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
) ||
2775 /* Probably this was a user name, try lookupnames */
2776 struct samr_Ids rids
, types
;
2777 struct lsa_String lsa_acct_name
;
2779 init_lsa_String(&lsa_acct_name
, user
);
2781 status
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2787 if (!NT_STATUS_IS_OK(status
)) {
2791 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2796 if (!NT_STATUS_IS_OK(status
)) {
2802 case NDR_SAMR_SETUSERINFO
:
2803 status
= rpccli_samr_SetUserInfo(cli
, mem_ctx
,
2808 case NDR_SAMR_SETUSERINFO2
:
2809 status
= rpccli_samr_SetUserInfo2(cli
, mem_ctx
,
2815 return NT_STATUS_INVALID_PARAMETER
;
2822 static NTSTATUS
cmd_samr_setuserinfo(struct rpc_pipe_client
*cli
,
2823 TALLOC_CTX
*mem_ctx
,
2824 int argc
, const char **argv
)
2826 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2827 NDR_SAMR_SETUSERINFO
);
2830 static NTSTATUS
cmd_samr_setuserinfo2(struct rpc_pipe_client
*cli
,
2831 TALLOC_CTX
*mem_ctx
,
2832 int argc
, const char **argv
)
2834 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2835 NDR_SAMR_SETUSERINFO2
);
2838 static NTSTATUS
cmd_samr_get_dispinfo_idx(struct rpc_pipe_client
*cli
,
2839 TALLOC_CTX
*mem_ctx
,
2840 int argc
, const char **argv
)
2843 struct policy_handle connect_handle
;
2844 struct policy_handle domain_handle
;
2846 struct lsa_String name
;
2849 if (argc
< 2 || argc
> 3) {
2850 printf("Usage: %s name level\n", argv
[0]);
2851 return NT_STATUS_INVALID_PARAMETER
;
2854 init_lsa_String(&name
, argv
[1]);
2857 level
= atoi(argv
[2]);
2860 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2861 SEC_FLAG_MAXIMUM_ALLOWED
,
2864 if (!NT_STATUS_IS_OK(status
)) {
2868 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2870 SEC_FLAG_MAXIMUM_ALLOWED
,
2874 if (!NT_STATUS_IS_OK(status
))
2878 status
= rpccli_samr_GetDisplayEnumerationIndex(cli
, mem_ctx
,
2884 if (NT_STATUS_IS_OK(status
) ||
2885 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2886 printf("idx: %d (0x%08x)\n", idx
, idx
);
2890 if (is_valid_policy_hnd(&domain_handle
)) {
2891 rpccli_samr_Close(cli
, mem_ctx
, &domain_handle
);
2893 if (is_valid_policy_hnd(&connect_handle
)) {
2894 rpccli_samr_Close(cli
, mem_ctx
, &connect_handle
);
2900 /* List of commands exported by this module */
2902 struct cmd_set samr_commands
[] = {
2906 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user info", "" },
2907 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group info", "" },
2908 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user groups", "" },
2909 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user aliases", "" },
2910 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group membership", "" },
2911 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias membership", "" },
2912 { "queryaliasinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias info", "" },
2913 { "deletealias", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete an alias", "" },
2914 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2915 { "querydispinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2916 { "querydispinfo3", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2917 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query domain info", "" },
2918 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain users", "" },
2919 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain groups", "" },
2920 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate alias groups", "" },
2921 { "enumdomains", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_domains
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domains", "" },
2923 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain user", "" },
2924 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain group", "" },
2925 { "createdomalias", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain alias", "" },
2926 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2927 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2928 { "deletedomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain group", "" },
2929 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain user", "" },
2930 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query SAMR security object", "" },
2931 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve domain password info", "" },
2932 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_usrdom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve user domain password info", "" },
2934 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Lookup Domain Name", "" },
2935 { "chgpasswd", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2936 { "chgpasswd2", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2937 { "chgpasswd3", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2938 { "getdispinfoidx", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dispinfo_idx
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Get Display Information Index", "" },
2939 { "setuserinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info", "" },
2940 { "setuserinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info2", "" },