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"
28 extern DOM_SID domain_sid
;
30 /****************************************************************************
31 display samr_user_info_7 structure
32 ****************************************************************************/
33 static void display_samr_user_info_7(struct samr_UserInfo7
*r
)
35 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
38 /****************************************************************************
39 display samr_user_info_9 structure
40 ****************************************************************************/
41 static void display_samr_user_info_9(struct samr_UserInfo9
*r
)
43 printf("\tPrimary group RID :\tox%x\n", r
->primary_gid
);
46 /****************************************************************************
47 display samr_user_info_16 structure
48 ****************************************************************************/
49 static void display_samr_user_info_16(struct samr_UserInfo16
*r
)
51 printf("\tAcct Flags :\tox%x\n", r
->acct_flags
);
54 /****************************************************************************
55 display samr_user_info_20 structure
56 ****************************************************************************/
57 static void display_samr_user_info_20(struct samr_UserInfo20
*r
)
59 printf("\tRemote Dial :\n");
60 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
64 /****************************************************************************
65 display samr_user_info_21 structure
66 ****************************************************************************/
67 static void display_samr_user_info_21(struct samr_UserInfo21
*r
)
69 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
70 printf("\tFull Name :\t%s\n", r
->full_name
.string
);
71 printf("\tHome Drive :\t%s\n", r
->home_directory
.string
);
72 printf("\tDir Drive :\t%s\n", r
->home_drive
.string
);
73 printf("\tProfile Path:\t%s\n", r
->profile_path
.string
);
74 printf("\tLogon Script:\t%s\n", r
->logon_script
.string
);
75 printf("\tDescription :\t%s\n", r
->description
.string
);
76 printf("\tWorkstations:\t%s\n", r
->workstations
.string
);
77 printf("\tComment :\t%s\n", r
->comment
.string
);
78 printf("\tRemote Dial :\n");
79 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
81 printf("\tLogon Time :\t%s\n",
82 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logon
)));
83 printf("\tLogoff Time :\t%s\n",
84 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logoff
)));
85 printf("\tKickoff Time :\t%s\n",
86 http_timestring(talloc_tos(), nt_time_to_unix(r
->acct_expiry
)));
87 printf("\tPassword last set Time :\t%s\n",
88 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_password_change
)));
89 printf("\tPassword can change Time :\t%s\n",
90 http_timestring(talloc_tos(), nt_time_to_unix(r
->allow_password_change
)));
91 printf("\tPassword must change Time:\t%s\n",
92 http_timestring(talloc_tos(), nt_time_to_unix(r
->force_password_change
)));
94 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
96 printf("\tuser_rid :\t0x%x\n" , r
->rid
); /* User ID */
97 printf("\tgroup_rid:\t0x%x\n" , r
->primary_gid
); /* Group ID */
98 printf("\tacb_info :\t0x%08x\n", r
->acct_flags
); /* Account Control Info */
100 printf("\tfields_present:\t0x%08x\n", r
->fields_present
); /* 0x00ff ffff */
101 printf("\tlogon_divs:\t%d\n", r
->logon_hours
.units_per_week
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
102 printf("\tbad_password_count:\t0x%08x\n", r
->bad_password_count
);
103 printf("\tlogon_count:\t0x%08x\n", r
->logon_count
);
105 printf("\tpadding1[0..7]...\n");
107 if (r
->logon_hours
.bits
) {
108 printf("\tlogon_hrs[0..%d]...\n", r
->logon_hours
.units_per_week
/8);
113 static void display_password_properties(uint32_t password_properties
)
115 printf("password_properties: 0x%08x\n", password_properties
);
117 if (password_properties
& DOMAIN_PASSWORD_COMPLEX
)
118 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
120 if (password_properties
& DOMAIN_PASSWORD_NO_ANON_CHANGE
)
121 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
123 if (password_properties
& DOMAIN_PASSWORD_NO_CLEAR_CHANGE
)
124 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
126 if (password_properties
& DOMAIN_PASSWORD_LOCKOUT_ADMINS
)
127 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
129 if (password_properties
& DOMAIN_PASSWORD_STORE_CLEARTEXT
)
130 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
132 if (password_properties
& DOMAIN_REFUSE_PASSWORD_CHANGE
)
133 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
136 static void display_sam_dom_info_1(struct samr_DomInfo1
*info1
)
138 printf("Minimum password length:\t\t\t%d\n",
139 info1
->min_password_length
);
140 printf("Password uniqueness (remember x passwords):\t%d\n",
141 info1
->password_history_length
);
142 display_password_properties(info1
->password_properties
);
143 printf("password expire in:\t\t\t\t%s\n",
144 display_time(info1
->max_password_age
));
145 printf("Min password age (allow changing in x days):\t%s\n",
146 display_time(info1
->min_password_age
));
149 static void display_sam_dom_info_2(struct samr_DomGeneralInformation
*general
)
151 printf("Domain:\t\t%s\n", general
->domain_name
.string
);
152 printf("Server:\t\t%s\n", general
->primary
.string
);
153 printf("Comment:\t%s\n", general
->oem_information
.string
);
155 printf("Total Users:\t%d\n", general
->num_users
);
156 printf("Total Groups:\t%d\n", general
->num_groups
);
157 printf("Total Aliases:\t%d\n", general
->num_aliases
);
159 printf("Sequence No:\t%llu\n", (unsigned long long)general
->sequence_num
);
161 printf("Force Logoff:\t%d\n",
162 (int)nt_time_to_unix_abs(&general
->force_logoff_time
));
164 printf("Domain Server State:\t0x%x\n", general
->domain_server_state
);
165 printf("Server Role:\t%s\n", server_role_str(general
->role
));
166 printf("Unknown 3:\t0x%x\n", general
->unknown3
);
169 static void display_sam_dom_info_3(struct samr_DomInfo3
*info3
)
171 printf("Force Logoff:\t%d\n",
172 (int)nt_time_to_unix_abs(&info3
->force_logoff_time
));
175 static void display_sam_dom_info_4(struct samr_DomOEMInformation
*oem
)
177 printf("Comment:\t%s\n", oem
->oem_information
.string
);
180 static void display_sam_dom_info_5(struct samr_DomInfo5
*info5
)
182 printf("Domain:\t\t%s\n", info5
->domain_name
.string
);
185 static void display_sam_dom_info_6(struct samr_DomInfo6
*info6
)
187 printf("Server:\t\t%s\n", info6
->primary
.string
);
190 static void display_sam_dom_info_7(struct samr_DomInfo7
*info7
)
192 printf("Server Role:\t%s\n", server_role_str(info7
->role
));
195 static void display_sam_dom_info_8(struct samr_DomInfo8
*info8
)
197 printf("Sequence No:\t%llu\n", (unsigned long long)info8
->sequence_num
);
198 printf("Domain Create Time:\t%s\n",
199 http_timestring(talloc_tos(), nt_time_to_unix(info8
->domain_create_time
)));
202 static void display_sam_dom_info_9(struct samr_DomInfo9
*info9
)
204 printf("Domain Server State:\t0x%x\n", info9
->domain_server_state
);
207 static void display_sam_dom_info_12(struct samr_DomInfo12
*info12
)
209 printf("Bad password lockout duration: %s\n",
210 display_time(info12
->lockout_duration
));
211 printf("Reset Lockout after: %s\n",
212 display_time(info12
->lockout_window
));
213 printf("Lockout after bad attempts: %d\n",
214 info12
->lockout_threshold
);
217 static void display_sam_dom_info_13(struct samr_DomInfo13
*info13
)
219 printf("Sequence No:\t%llu\n", (unsigned long long)info13
->sequence_num
);
220 printf("Domain Create Time:\t%s\n",
221 http_timestring(talloc_tos(), nt_time_to_unix(info13
->domain_create_time
)));
222 printf("Sequence No at last promotion:\t%llu\n",
223 (unsigned long long)info13
->modified_count_at_last_promotion
);
226 static void display_sam_info_1(struct samr_DispEntryGeneral
*r
)
228 printf("index: 0x%x ", r
->idx
);
229 printf("RID: 0x%x ", r
->rid
);
230 printf("acb: 0x%08x ", r
->acct_flags
);
231 printf("Account: %s\t", r
->account_name
.string
);
232 printf("Name: %s\t", r
->full_name
.string
);
233 printf("Desc: %s\n", r
->description
.string
);
236 static void display_sam_info_2(struct samr_DispEntryFull
*r
)
238 printf("index: 0x%x ", r
->idx
);
239 printf("RID: 0x%x ", r
->rid
);
240 printf("acb: 0x%08x ", r
->acct_flags
);
241 printf("Account: %s\t", r
->account_name
.string
);
242 printf("Desc: %s\n", r
->description
.string
);
245 static void display_sam_info_3(struct samr_DispEntryFullGroup
*r
)
247 printf("index: 0x%x ", r
->idx
);
248 printf("RID: 0x%x ", r
->rid
);
249 printf("acb: 0x%08x ", r
->acct_flags
);
250 printf("Account: %s\t", r
->account_name
.string
);
251 printf("Desc: %s\n", r
->description
.string
);
254 static void display_sam_info_4(struct samr_DispEntryAscii
*r
)
256 printf("index: 0x%x ", r
->idx
);
257 printf("Account: %s\n", r
->account_name
.string
);
260 static void display_sam_info_5(struct samr_DispEntryAscii
*r
)
262 printf("index: 0x%x ", r
->idx
);
263 printf("Account: %s\n", r
->account_name
.string
);
266 /****************************************************************************
267 ****************************************************************************/
269 static NTSTATUS
get_domain_handle(struct rpc_pipe_client
*cli
,
272 struct policy_handle
*connect_pol
,
273 uint32_t access_mask
,
274 struct dom_sid
*_domain_sid
,
275 struct policy_handle
*domain_pol
)
278 if (StrCaseCmp(sam
, "domain") == 0) {
279 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
284 } else if (StrCaseCmp(sam
, "builtin") == 0) {
285 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
288 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
292 return NT_STATUS_INVALID_PARAMETER
;
295 /**********************************************************************
296 * Query user information
298 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
300 int argc
, const char **argv
)
302 struct policy_handle connect_pol
, domain_pol
, user_pol
;
303 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
304 uint32 info_level
= 21;
305 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
306 union samr_UserInfo
*info
= NULL
;
309 if ((argc
< 2) || (argc
> 4)) {
310 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
314 sscanf(argv
[1], "%i", &user_rid
);
317 sscanf(argv
[2], "%i", &info_level
);
320 sscanf(argv
[3], "%x", &access_mask
);
323 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
324 MAXIMUM_ALLOWED_ACCESS
,
327 if (!NT_STATUS_IS_OK(result
))
330 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
332 MAXIMUM_ALLOWED_ACCESS
,
335 if (!NT_STATUS_IS_OK(result
))
338 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
344 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) &&
347 /* Probably this was a user name, try lookupnames */
348 struct samr_Ids rids
, types
;
349 struct lsa_String lsa_acct_name
;
351 init_lsa_String(&lsa_acct_name
, argv
[1]);
353 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
360 if (NT_STATUS_IS_OK(result
)) {
361 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
370 if (!NT_STATUS_IS_OK(result
))
373 result
= rpccli_samr_QueryUserInfo(cli
, mem_ctx
,
378 if (!NT_STATUS_IS_OK(result
))
381 switch (info_level
) {
383 display_samr_user_info_7(&info
->info7
);
386 display_samr_user_info_9(&info
->info9
);
389 display_samr_user_info_16(&info
->info16
);
392 display_samr_user_info_20(&info
->info20
);
395 display_samr_user_info_21(&info
->info21
);
398 printf("Unsupported infolevel: %d\n", info_level
);
402 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
403 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
404 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
410 /****************************************************************************
412 ****************************************************************************/
413 static void display_group_info1(struct samr_GroupInfoAll
*info1
)
415 printf("\tGroup Name:\t%s\n", info1
->name
.string
);
416 printf("\tDescription:\t%s\n", info1
->description
.string
);
417 printf("\tGroup Attribute:%d\n", info1
->attributes
);
418 printf("\tNum Members:%d\n", info1
->num_members
);
421 /****************************************************************************
423 ****************************************************************************/
424 static void display_group_info2(struct lsa_String
*info2
)
426 printf("\tGroup Description:%s\n", info2
->string
);
430 /****************************************************************************
432 ****************************************************************************/
433 static void display_group_info3(struct samr_GroupInfoAttributes
*info3
)
435 printf("\tGroup Attribute:%d\n", info3
->attributes
);
439 /****************************************************************************
441 ****************************************************************************/
442 static void display_group_info4(struct lsa_String
*info4
)
444 printf("\tGroup Description:%s\n", info4
->string
);
447 /****************************************************************************
449 ****************************************************************************/
450 static void display_group_info5(struct samr_GroupInfoAll
*info5
)
452 printf("\tGroup Name:\t%s\n", info5
->name
.string
);
453 printf("\tDescription:\t%s\n", info5
->description
.string
);
454 printf("\tGroup Attribute:%d\n", info5
->attributes
);
455 printf("\tNum Members:%d\n", info5
->num_members
);
458 /****************************************************************************
459 display sam sync structure
460 ****************************************************************************/
461 static void display_group_info(union samr_GroupInfo
*info
,
462 enum samr_GroupInfoEnum level
)
466 display_group_info1(&info
->all
);
469 display_group_info2(&info
->name
);
472 display_group_info3(&info
->attributes
);
475 display_group_info4(&info
->description
);
478 display_group_info5(&info
->all2
);
483 /***********************************************************************
484 * Query group information
486 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
488 int argc
, const char **argv
)
490 struct policy_handle connect_pol
, domain_pol
, group_pol
;
491 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
492 enum samr_GroupInfoEnum info_level
= GROUPINFOALL
;
493 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
494 union samr_GroupInfo
*group_info
= NULL
;
497 if ((argc
< 2) || (argc
> 4)) {
498 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
502 sscanf(argv
[1], "%i", &group_rid
);
505 info_level
= atoi(argv
[2]);
508 sscanf(argv
[3], "%x", &access_mask
);
510 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
511 MAXIMUM_ALLOWED_ACCESS
,
514 if (!NT_STATUS_IS_OK(result
))
517 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
519 MAXIMUM_ALLOWED_ACCESS
,
523 if (!NT_STATUS_IS_OK(result
))
526 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
532 if (!NT_STATUS_IS_OK(result
))
535 result
= rpccli_samr_QueryGroupInfo(cli
, mem_ctx
,
539 if (!NT_STATUS_IS_OK(result
)) {
543 display_group_info(group_info
, info_level
);
545 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
546 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
547 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
552 /* Query groups a user is a member of */
554 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
556 int argc
, const char **argv
)
558 struct policy_handle connect_pol
,
561 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
563 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
565 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
567 if ((argc
< 2) || (argc
> 3)) {
568 printf("Usage: %s rid [access mask]\n", argv
[0]);
572 sscanf(argv
[1], "%i", &user_rid
);
575 sscanf(argv
[2], "%x", &access_mask
);
577 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
578 MAXIMUM_ALLOWED_ACCESS
,
581 if (!NT_STATUS_IS_OK(result
))
584 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
586 MAXIMUM_ALLOWED_ACCESS
,
587 &domain_sid
, &domain_pol
);
589 if (!NT_STATUS_IS_OK(result
))
592 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
598 if (!NT_STATUS_IS_OK(result
))
601 result
= rpccli_samr_GetGroupsForUser(cli
, mem_ctx
,
605 if (!NT_STATUS_IS_OK(result
))
608 for (i
= 0; i
< rid_array
->count
; i
++) {
609 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
610 rid_array
->rids
[i
].rid
,
611 rid_array
->rids
[i
].attributes
);
614 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
615 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
616 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
621 /* Query aliases a user is a member of */
623 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
625 int argc
, const char **argv
)
627 struct policy_handle connect_pol
, domain_pol
;
628 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
631 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
633 struct lsa_SidArray sid_array
;
634 struct samr_Ids alias_rids
;
637 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
638 return NT_STATUS_INVALID_PARAMETER
;
644 for (i
=2; i
<argc
; i
++) {
646 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
647 printf("%s is not a legal SID\n", argv
[i
]);
648 return NT_STATUS_INVALID_PARAMETER
;
650 result
= add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
651 if (!NT_STATUS_IS_OK(result
)) {
657 sid_array
.sids
= TALLOC_ZERO_ARRAY(mem_ctx
, struct lsa_SidPtr
, num_sids
);
658 if (sid_array
.sids
== NULL
)
659 return NT_STATUS_NO_MEMORY
;
661 sid_array
.sids
= NULL
;
664 for (i
=0; i
<num_sids
; i
++) {
665 sid_array
.sids
[i
].sid
= sid_dup_talloc(mem_ctx
, &sids
[i
]);
666 if (!sid_array
.sids
[i
].sid
) {
667 return NT_STATUS_NO_MEMORY
;
671 sid_array
.num_sids
= num_sids
;
673 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
674 MAXIMUM_ALLOWED_ACCESS
,
677 if (!NT_STATUS_IS_OK(result
))
680 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
686 if (!NT_STATUS_IS_OK(result
))
689 result
= rpccli_samr_GetAliasMembership(cli
, mem_ctx
,
693 if (!NT_STATUS_IS_OK(result
))
696 for (i
= 0; i
< alias_rids
.count
; i
++) {
697 printf("\tgroup rid:[0x%x]\n", alias_rids
.ids
[i
]);
700 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
701 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
706 /* Query members of a group */
708 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
710 int argc
, const char **argv
)
712 struct policy_handle connect_pol
, domain_pol
, group_pol
;
713 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
715 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
717 unsigned int old_timeout
;
718 struct samr_RidTypeArray
*rids
= NULL
;
720 if ((argc
< 2) || (argc
> 3)) {
721 printf("Usage: %s rid [access mask]\n", argv
[0]);
725 sscanf(argv
[1], "%i", &group_rid
);
728 sscanf(argv
[2], "%x", &access_mask
);
730 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
731 MAXIMUM_ALLOWED_ACCESS
,
734 if (!NT_STATUS_IS_OK(result
))
737 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
739 MAXIMUM_ALLOWED_ACCESS
,
743 if (!NT_STATUS_IS_OK(result
))
746 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
752 if (!NT_STATUS_IS_OK(result
))
755 /* Make sure to wait for our DC's reply */
756 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
757 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
759 result
= rpccli_samr_QueryGroupMember(cli
, mem_ctx
,
763 rpccli_set_timeout(cli
, old_timeout
);
765 if (!NT_STATUS_IS_OK(result
))
768 for (i
= 0; i
< rids
->count
; i
++) {
769 printf("\trid:[0x%x] attr:[0x%x]\n", rids
->rids
[i
],
773 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
774 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
775 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
780 /* Enumerate domain users */
782 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
784 int argc
, const char **argv
)
786 struct policy_handle connect_pol
, domain_pol
;
787 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
788 uint32 start_idx
, size
, num_dom_users
, i
;
789 struct samr_SamArray
*dom_users
= NULL
;
790 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
791 uint32 acb_mask
= ACB_NORMAL
;
793 if ((argc
< 1) || (argc
> 3)) {
794 printf("Usage: %s [access_mask] [acb_mask]\n", argv
[0]);
799 sscanf(argv
[1], "%x", &access_mask
);
802 sscanf(argv
[2], "%x", &acb_mask
);
804 /* Get sam policy handle */
806 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
807 MAXIMUM_ALLOWED_ACCESS
,
810 if (!NT_STATUS_IS_OK(result
))
813 /* Get domain policy handle */
815 result
= get_domain_handle(cli
, mem_ctx
, "domain",
820 if (!NT_STATUS_IS_OK(result
))
823 /* Enumerate domain users */
829 result
= rpccli_samr_EnumDomainUsers(cli
, mem_ctx
,
837 if (NT_STATUS_IS_OK(result
) ||
838 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
840 for (i
= 0; i
< num_dom_users
; i
++)
841 printf("user:[%s] rid:[0x%x]\n",
842 dom_users
->entries
[i
].name
.string
,
843 dom_users
->entries
[i
].idx
);
846 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
849 if (is_valid_policy_hnd(&domain_pol
))
850 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
852 if (is_valid_policy_hnd(&connect_pol
))
853 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
858 /* Enumerate domain groups */
860 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
862 int argc
, const char **argv
)
864 struct policy_handle connect_pol
, domain_pol
;
865 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
866 uint32 start_idx
, size
, num_dom_groups
, i
;
867 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
868 struct samr_SamArray
*dom_groups
= NULL
;
870 if ((argc
< 1) || (argc
> 2)) {
871 printf("Usage: %s [access_mask]\n", argv
[0]);
876 sscanf(argv
[1], "%x", &access_mask
);
878 /* Get sam policy handle */
880 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
881 MAXIMUM_ALLOWED_ACCESS
,
884 if (!NT_STATUS_IS_OK(result
))
887 /* Get domain policy handle */
889 result
= get_domain_handle(cli
, mem_ctx
, "domain",
894 if (!NT_STATUS_IS_OK(result
))
897 /* Enumerate domain groups */
903 result
= rpccli_samr_EnumDomainGroups(cli
, mem_ctx
,
909 if (NT_STATUS_IS_OK(result
) ||
910 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
912 for (i
= 0; i
< num_dom_groups
; i
++)
913 printf("group:[%s] rid:[0x%x]\n",
914 dom_groups
->entries
[i
].name
.string
,
915 dom_groups
->entries
[i
].idx
);
918 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
921 if (is_valid_policy_hnd(&domain_pol
))
922 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
924 if (is_valid_policy_hnd(&connect_pol
))
925 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
930 /* Enumerate alias groups */
932 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
934 int argc
, const char **argv
)
936 struct policy_handle connect_pol
, domain_pol
;
937 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
938 uint32 start_idx
, size
, num_als_groups
, i
;
939 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
940 struct samr_SamArray
*als_groups
= NULL
;
942 if ((argc
< 2) || (argc
> 3)) {
943 printf("Usage: %s builtin|domain [access mask]\n", argv
[0]);
948 sscanf(argv
[2], "%x", &access_mask
);
950 /* Get sam policy handle */
952 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
953 MAXIMUM_ALLOWED_ACCESS
,
956 if (!NT_STATUS_IS_OK(result
))
959 /* Get domain policy handle */
961 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
967 if (!NT_STATUS_IS_OK(result
))
970 /* Enumerate alias groups */
973 size
= 0xffff; /* Number of groups to retrieve */
976 result
= rpccli_samr_EnumDomainAliases(cli
, mem_ctx
,
983 if (NT_STATUS_IS_OK(result
) ||
984 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
986 for (i
= 0; i
< num_als_groups
; i
++)
987 printf("group:[%s] rid:[0x%x]\n",
988 als_groups
->entries
[i
].name
.string
,
989 als_groups
->entries
[i
].idx
);
991 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
994 if (is_valid_policy_hnd(&domain_pol
))
995 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
997 if (is_valid_policy_hnd(&connect_pol
))
998 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1003 /* Enumerate domains */
1005 static NTSTATUS
cmd_samr_enum_domains(struct rpc_pipe_client
*cli
,
1006 TALLOC_CTX
*mem_ctx
,
1007 int argc
, const char **argv
)
1009 struct policy_handle connect_pol
;
1010 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1011 uint32 start_idx
, size
, num_entries
, i
;
1012 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1013 struct samr_SamArray
*sam
= NULL
;
1015 if ((argc
< 1) || (argc
> 2)) {
1016 printf("Usage: %s [access mask]\n", argv
[0]);
1017 return NT_STATUS_OK
;
1021 sscanf(argv
[1], "%x", &access_mask
);
1024 /* Get sam policy handle */
1026 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1030 if (!NT_STATUS_IS_OK(result
)) {
1034 /* Enumerate alias groups */
1040 result
= rpccli_samr_EnumDomains(cli
, mem_ctx
,
1047 if (NT_STATUS_IS_OK(result
) ||
1048 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1050 for (i
= 0; i
< num_entries
; i
++)
1051 printf("name:[%s] idx:[0x%x]\n",
1052 sam
->entries
[i
].name
.string
,
1053 sam
->entries
[i
].idx
);
1055 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1058 if (is_valid_policy_hnd(&connect_pol
)) {
1059 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1066 /* Query alias membership */
1068 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
1069 TALLOC_CTX
*mem_ctx
,
1070 int argc
, const char **argv
)
1072 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1073 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1074 uint32 alias_rid
, i
;
1075 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1076 struct lsa_SidArray sid_array
;
1078 if ((argc
< 3) || (argc
> 4)) {
1079 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
1080 return NT_STATUS_OK
;
1083 sscanf(argv
[2], "%i", &alias_rid
);
1086 sscanf(argv
[3], "%x", &access_mask
);
1088 /* Open SAMR handle */
1090 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1091 MAXIMUM_ALLOWED_ACCESS
,
1094 if (!NT_STATUS_IS_OK(result
))
1097 /* Open handle on domain */
1099 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1101 MAXIMUM_ALLOWED_ACCESS
,
1105 if (!NT_STATUS_IS_OK(result
))
1108 /* Open handle on alias */
1110 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1115 if (!NT_STATUS_IS_OK(result
))
1118 result
= rpccli_samr_GetMembersInAlias(cli
, mem_ctx
,
1122 if (!NT_STATUS_IS_OK(result
))
1125 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
1128 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
1129 printf("\tsid:[%s]\n", sid_str
);
1132 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1133 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1134 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1139 /* Query alias info */
1141 static NTSTATUS
cmd_samr_query_aliasinfo(struct rpc_pipe_client
*cli
,
1142 TALLOC_CTX
*mem_ctx
,
1143 int argc
, const char **argv
)
1145 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1146 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1148 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1149 union samr_AliasInfo
*info
= NULL
;
1150 enum samr_AliasInfoEnum level
= ALIASINFOALL
;
1152 if ((argc
< 3) || (argc
> 4)) {
1153 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1155 return NT_STATUS_OK
;
1158 sscanf(argv
[2], "%i", &alias_rid
);
1161 level
= atoi(argv
[3]);
1165 sscanf(argv
[4], "%x", &access_mask
);
1168 /* Open SAMR handle */
1170 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1171 SEC_FLAG_MAXIMUM_ALLOWED
,
1174 if (!NT_STATUS_IS_OK(result
)) {
1178 /* Open handle on domain */
1180 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1182 SEC_FLAG_MAXIMUM_ALLOWED
,
1186 if (!NT_STATUS_IS_OK(result
)) {
1190 /* Open handle on alias */
1192 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1197 if (!NT_STATUS_IS_OK(result
)) {
1201 result
= rpccli_samr_QueryAliasInfo(cli
, mem_ctx
,
1206 if (!NT_STATUS_IS_OK(result
)) {
1212 printf("Name: %s\n", info
->all
.name
.string
);
1213 printf("Description: %s\n", info
->all
.description
.string
);
1214 printf("Num Members: %d\n", info
->all
.num_members
);
1217 printf("Name: %s\n", info
->name
.string
);
1219 case ALIASINFODESCRIPTION
:
1220 printf("Description: %s\n", info
->description
.string
);
1226 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1227 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1228 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1234 /* Query delete an alias membership */
1236 static NTSTATUS
cmd_samr_delete_alias(struct rpc_pipe_client
*cli
,
1237 TALLOC_CTX
*mem_ctx
,
1238 int argc
, const char **argv
)
1240 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1241 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1243 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1246 printf("Usage: %s builtin|domain [rid|name]\n", argv
[0]);
1247 return NT_STATUS_OK
;
1250 alias_rid
= strtoul(argv
[2], NULL
, 10);
1252 /* Open SAMR handle */
1254 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1255 MAXIMUM_ALLOWED_ACCESS
,
1258 if (!NT_STATUS_IS_OK(result
))
1261 /* Open handle on domain */
1263 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1265 MAXIMUM_ALLOWED_ACCESS
,
1269 if (!NT_STATUS_IS_OK(result
))
1272 /* Open handle on alias */
1274 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1279 if (!NT_STATUS_IS_OK(result
) && (alias_rid
== 0)) {
1280 /* Probably this was a user name, try lookupnames */
1281 struct samr_Ids rids
, types
;
1282 struct lsa_String lsa_acct_name
;
1284 init_lsa_String(&lsa_acct_name
, argv
[2]);
1286 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1293 if (NT_STATUS_IS_OK(result
)) {
1294 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1302 result
= rpccli_samr_DeleteDomAlias(cli
, mem_ctx
,
1305 if (!NT_STATUS_IS_OK(result
))
1308 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1309 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1314 /* Query display info */
1316 static NTSTATUS
cmd_samr_query_dispinfo_internal(struct rpc_pipe_client
*cli
,
1317 TALLOC_CTX
*mem_ctx
,
1318 int argc
, const char **argv
,
1321 struct policy_handle connect_pol
, domain_pol
;
1322 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1323 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
= 0, i
;
1324 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1325 uint32 info_level
= 1;
1326 union samr_DispInfo info
;
1328 bool got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1329 uint32_t total_size
, returned_size
;
1332 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1333 return NT_STATUS_OK
;
1337 sscanf(argv
[1], "%i", &info_level
);
1340 sscanf(argv
[2], "%i", &start_idx
);
1343 sscanf(argv
[3], "%i", &max_entries
);
1348 sscanf(argv
[4], "%i", &max_size
);
1353 sscanf(argv
[5], "%x", &access_mask
);
1355 /* Get sam policy handle */
1357 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1358 MAXIMUM_ALLOWED_ACCESS
,
1361 if (!NT_STATUS_IS_OK(result
))
1364 /* Get domain policy handle */
1366 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1372 if (!NT_STATUS_IS_OK(result
))
1375 /* Query display info */
1380 get_query_dispinfo_params(
1381 loop_count
, &max_entries
, &max_size
);
1384 case NDR_SAMR_QUERYDISPLAYINFO
:
1385 result
= rpccli_samr_QueryDisplayInfo(cli
, mem_ctx
,
1395 case NDR_SAMR_QUERYDISPLAYINFO2
:
1396 result
= rpccli_samr_QueryDisplayInfo2(cli
, mem_ctx
,
1407 case NDR_SAMR_QUERYDISPLAYINFO3
:
1408 result
= rpccli_samr_QueryDisplayInfo3(cli
, mem_ctx
,
1420 return NT_STATUS_INVALID_PARAMETER
;
1423 if (!NT_STATUS_IS_OK(result
) &&
1424 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
1425 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
1431 switch (info_level
) {
1433 num_entries
= info
.info1
.count
;
1436 num_entries
= info
.info2
.count
;
1439 num_entries
= info
.info3
.count
;
1442 num_entries
= info
.info4
.count
;
1445 num_entries
= info
.info5
.count
;
1451 start_idx
+= num_entries
;
1453 if (num_entries
== 0)
1456 for (i
= 0; i
< num_entries
; i
++) {
1457 switch (info_level
) {
1459 display_sam_info_1(&info
.info1
.entries
[i
]);
1462 display_sam_info_2(&info
.info2
.entries
[i
]);
1465 display_sam_info_3(&info
.info3
.entries
[i
]);
1468 display_sam_info_4(&info
.info4
.entries
[i
]);
1471 display_sam_info_5(&info
.info5
.entries
[i
]);
1475 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1477 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1478 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1483 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1484 TALLOC_CTX
*mem_ctx
,
1485 int argc
, const char **argv
)
1487 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1488 NDR_SAMR_QUERYDISPLAYINFO
);
1491 static NTSTATUS
cmd_samr_query_dispinfo2(struct rpc_pipe_client
*cli
,
1492 TALLOC_CTX
*mem_ctx
,
1493 int argc
, const char **argv
)
1495 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1496 NDR_SAMR_QUERYDISPLAYINFO2
);
1499 static NTSTATUS
cmd_samr_query_dispinfo3(struct rpc_pipe_client
*cli
,
1500 TALLOC_CTX
*mem_ctx
,
1501 int argc
, const char **argv
)
1503 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1504 NDR_SAMR_QUERYDISPLAYINFO3
);
1507 /* Query domain info */
1509 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1510 TALLOC_CTX
*mem_ctx
,
1511 int argc
, const char **argv
)
1513 struct policy_handle connect_pol
, domain_pol
;
1514 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1515 uint32 switch_level
= 2;
1516 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1517 union samr_DomainInfo
*info
= NULL
;
1520 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1521 return NT_STATUS_OK
;
1525 sscanf(argv
[1], "%i", &switch_level
);
1528 sscanf(argv
[2], "%x", &access_mask
);
1530 /* Get sam policy handle */
1532 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1533 MAXIMUM_ALLOWED_ACCESS
,
1536 if (!NT_STATUS_IS_OK(result
))
1539 /* Get domain policy handle */
1541 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1547 if (!NT_STATUS_IS_OK(result
))
1550 /* Query domain info */
1552 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1557 if (!NT_STATUS_IS_OK(result
))
1560 /* Display domain info */
1562 switch (switch_level
) {
1564 display_sam_dom_info_1(&info
->info1
);
1567 display_sam_dom_info_2(&info
->general
);
1570 display_sam_dom_info_3(&info
->info3
);
1573 display_sam_dom_info_4(&info
->oem
);
1576 display_sam_dom_info_5(&info
->info5
);
1579 display_sam_dom_info_6(&info
->info6
);
1582 display_sam_dom_info_7(&info
->info7
);
1585 display_sam_dom_info_8(&info
->info8
);
1588 display_sam_dom_info_9(&info
->info9
);
1591 display_sam_dom_info_12(&info
->info12
);
1594 display_sam_dom_info_13(&info
->info13
);
1598 printf("cannot display domain info for switch value %d\n",
1605 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1606 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1610 /* Create domain user */
1612 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1613 TALLOC_CTX
*mem_ctx
,
1614 int argc
, const char **argv
)
1616 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1617 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1618 struct lsa_String acct_name
;
1620 uint32 acct_flags
, user_rid
;
1621 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1622 uint32_t access_granted
= 0;
1624 if ((argc
< 2) || (argc
> 3)) {
1625 printf("Usage: %s username [access mask]\n", argv
[0]);
1626 return NT_STATUS_OK
;
1629 init_lsa_String(&acct_name
, argv
[1]);
1632 sscanf(argv
[2], "%x", &access_mask
);
1634 /* Get sam policy handle */
1636 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1637 MAXIMUM_ALLOWED_ACCESS
,
1640 if (!NT_STATUS_IS_OK(result
))
1643 /* Get domain policy handle */
1645 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1651 if (!NT_STATUS_IS_OK(result
))
1654 /* Create domain user */
1656 acb_info
= ACB_NORMAL
;
1657 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1658 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1659 SAMR_USER_ACCESS_SET_PASSWORD
|
1660 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1661 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1663 result
= rpccli_samr_CreateUser2(cli
, mem_ctx
,
1672 if (!NT_STATUS_IS_OK(result
))
1675 result
= rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
1676 if (!NT_STATUS_IS_OK(result
)) goto done
;
1678 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1679 if (!NT_STATUS_IS_OK(result
)) goto done
;
1681 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1682 if (!NT_STATUS_IS_OK(result
)) goto done
;
1688 /* Create domain group */
1690 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1691 TALLOC_CTX
*mem_ctx
,
1692 int argc
, const char **argv
)
1694 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1695 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1696 struct lsa_String grp_name
;
1697 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1700 if ((argc
< 2) || (argc
> 3)) {
1701 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1702 return NT_STATUS_OK
;
1705 init_lsa_String(&grp_name
, argv
[1]);
1708 sscanf(argv
[2], "%x", &access_mask
);
1710 /* Get sam policy handle */
1712 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1713 MAXIMUM_ALLOWED_ACCESS
,
1716 if (!NT_STATUS_IS_OK(result
))
1719 /* Get domain policy handle */
1721 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1727 if (!NT_STATUS_IS_OK(result
))
1730 /* Create domain user */
1731 result
= rpccli_samr_CreateDomainGroup(cli
, mem_ctx
,
1734 MAXIMUM_ALLOWED_ACCESS
,
1738 if (!NT_STATUS_IS_OK(result
))
1741 result
= rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
1742 if (!NT_STATUS_IS_OK(result
)) goto done
;
1744 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1745 if (!NT_STATUS_IS_OK(result
)) goto done
;
1747 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1748 if (!NT_STATUS_IS_OK(result
)) goto done
;
1754 /* Create domain alias */
1756 static NTSTATUS
cmd_samr_create_dom_alias(struct rpc_pipe_client
*cli
,
1757 TALLOC_CTX
*mem_ctx
,
1758 int argc
, const char **argv
)
1760 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1761 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1762 struct lsa_String alias_name
;
1763 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1766 if ((argc
< 2) || (argc
> 3)) {
1767 printf("Usage: %s aliasname [access mask]\n", argv
[0]);
1768 return NT_STATUS_OK
;
1771 init_lsa_String(&alias_name
, argv
[1]);
1774 sscanf(argv
[2], "%x", &access_mask
);
1776 /* Get sam policy handle */
1778 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1779 MAXIMUM_ALLOWED_ACCESS
,
1782 if (!NT_STATUS_IS_OK(result
))
1785 /* Get domain policy handle */
1787 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1793 if (!NT_STATUS_IS_OK(result
))
1796 /* Create domain user */
1798 result
= rpccli_samr_CreateDomAlias(cli
, mem_ctx
,
1801 MAXIMUM_ALLOWED_ACCESS
,
1805 if (!NT_STATUS_IS_OK(result
))
1808 result
= rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1809 if (!NT_STATUS_IS_OK(result
)) goto done
;
1811 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1812 if (!NT_STATUS_IS_OK(result
)) goto done
;
1814 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1815 if (!NT_STATUS_IS_OK(result
)) goto done
;
1821 /* Lookup sam names */
1823 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
1824 TALLOC_CTX
*mem_ctx
,
1825 int argc
, const char **argv
)
1827 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1828 struct policy_handle connect_pol
, domain_pol
;
1830 struct samr_Ids rids
, name_types
;
1832 struct lsa_String
*names
= NULL
;;
1835 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1836 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1837 printf("or check on the builtin SID: S-1-5-32\n");
1838 return NT_STATUS_OK
;
1841 /* Get sam policy and domain handles */
1843 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1844 MAXIMUM_ALLOWED_ACCESS
,
1847 if (!NT_STATUS_IS_OK(result
))
1850 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1852 MAXIMUM_ALLOWED_ACCESS
,
1856 if (!NT_STATUS_IS_OK(result
))
1861 num_names
= argc
- 2;
1863 if ((names
= TALLOC_ARRAY(mem_ctx
, struct lsa_String
, num_names
)) == NULL
) {
1864 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1865 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1866 result
= NT_STATUS_NO_MEMORY
;
1870 for (i
= 0; i
< num_names
; i
++) {
1871 init_lsa_String(&names
[i
], argv
[i
+ 2]);
1874 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1881 if (!NT_STATUS_IS_OK(result
))
1884 /* Display results */
1886 for (i
= 0; i
< num_names
; i
++)
1887 printf("name %s: 0x%x (%d)\n", names
[i
].string
, rids
.ids
[i
],
1890 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1891 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1896 /* Lookup sam rids */
1898 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
1899 TALLOC_CTX
*mem_ctx
,
1900 int argc
, const char **argv
)
1902 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1903 struct policy_handle connect_pol
, domain_pol
;
1904 uint32_t num_rids
, *rids
;
1905 struct lsa_Strings names
;
1906 struct samr_Ids types
;
1911 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1912 return NT_STATUS_OK
;
1915 /* Get sam policy and domain handles */
1917 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1918 MAXIMUM_ALLOWED_ACCESS
,
1921 if (!NT_STATUS_IS_OK(result
))
1924 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1926 MAXIMUM_ALLOWED_ACCESS
,
1930 if (!NT_STATUS_IS_OK(result
))
1935 num_rids
= argc
- 2;
1937 if ((rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
)) == NULL
) {
1938 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1939 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1940 result
= NT_STATUS_NO_MEMORY
;
1944 for (i
= 0; i
< argc
- 2; i
++)
1945 sscanf(argv
[i
+ 2], "%i", &rids
[i
]);
1947 result
= rpccli_samr_LookupRids(cli
, mem_ctx
,
1954 if (!NT_STATUS_IS_OK(result
) &&
1955 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1958 /* Display results */
1960 for (i
= 0; i
< num_rids
; i
++) {
1961 printf("rid 0x%x: %s (%d)\n",
1962 rids
[i
], names
.names
[i
].string
, types
.ids
[i
]);
1965 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1966 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1971 /* Delete domain group */
1973 static NTSTATUS
cmd_samr_delete_dom_group(struct rpc_pipe_client
*cli
,
1974 TALLOC_CTX
*mem_ctx
,
1975 int argc
, const char **argv
)
1977 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1978 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1979 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1981 if ((argc
< 2) || (argc
> 3)) {
1982 printf("Usage: %s groupname\n", argv
[0]);
1983 return NT_STATUS_OK
;
1987 sscanf(argv
[2], "%x", &access_mask
);
1989 /* Get sam policy and domain handles */
1991 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1992 MAXIMUM_ALLOWED_ACCESS
,
1995 if (!NT_STATUS_IS_OK(result
))
1998 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2000 MAXIMUM_ALLOWED_ACCESS
,
2004 if (!NT_STATUS_IS_OK(result
))
2007 /* Get handle on group */
2010 struct samr_Ids group_rids
, name_types
;
2011 struct lsa_String lsa_acct_name
;
2013 init_lsa_String(&lsa_acct_name
, argv
[1]);
2015 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2021 if (!NT_STATUS_IS_OK(result
))
2024 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
2030 if (!NT_STATUS_IS_OK(result
))
2036 result
= rpccli_samr_DeleteDomainGroup(cli
, mem_ctx
,
2039 if (!NT_STATUS_IS_OK(result
))
2042 /* Display results */
2044 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
2045 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2046 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2052 /* Delete domain user */
2054 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
2055 TALLOC_CTX
*mem_ctx
,
2056 int argc
, const char **argv
)
2058 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2059 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2060 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2062 if ((argc
< 2) || (argc
> 3)) {
2063 printf("Usage: %s username\n", argv
[0]);
2064 return NT_STATUS_OK
;
2068 sscanf(argv
[2], "%x", &access_mask
);
2070 /* Get sam policy and domain handles */
2072 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2073 MAXIMUM_ALLOWED_ACCESS
,
2076 if (!NT_STATUS_IS_OK(result
))
2079 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2081 MAXIMUM_ALLOWED_ACCESS
,
2085 if (!NT_STATUS_IS_OK(result
))
2088 /* Get handle on user */
2091 struct samr_Ids user_rids
, name_types
;
2092 struct lsa_String lsa_acct_name
;
2094 init_lsa_String(&lsa_acct_name
, argv
[1]);
2096 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2103 if (!NT_STATUS_IS_OK(result
))
2106 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2112 if (!NT_STATUS_IS_OK(result
))
2118 result
= rpccli_samr_DeleteUser(cli
, mem_ctx
,
2121 if (!NT_STATUS_IS_OK(result
))
2124 /* Display results */
2126 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2127 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2128 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2134 /**********************************************************************
2135 * Query user security object
2137 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
2138 TALLOC_CTX
*mem_ctx
,
2139 int argc
, const char **argv
)
2141 struct policy_handle connect_pol
, domain_pol
, user_pol
, *pol
;
2142 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2143 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
2144 uint32 user_rid
= 0;
2145 TALLOC_CTX
*ctx
= NULL
;
2146 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
2147 bool domain
= False
;
2149 ctx
=talloc_init("cmd_samr_query_sec_obj");
2151 if ((argc
< 1) || (argc
> 3)) {
2152 printf("Usage: %s [rid|-d] [sec_info]\n", argv
[0]);
2153 printf("\tSpecify rid for security on user, -d for security on domain\n");
2154 talloc_destroy(ctx
);
2155 return NT_STATUS_OK
;
2159 if (strcmp(argv
[1], "-d") == 0)
2162 sscanf(argv
[1], "%i", &user_rid
);
2166 sec_info
= atoi(argv
[2]);
2169 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2170 MAXIMUM_ALLOWED_ACCESS
,
2173 if (!NT_STATUS_IS_OK(result
))
2176 if (domain
|| user_rid
)
2177 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2179 MAXIMUM_ALLOWED_ACCESS
,
2183 if (!NT_STATUS_IS_OK(result
))
2187 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2189 MAXIMUM_ALLOWED_ACCESS
,
2193 if (!NT_STATUS_IS_OK(result
))
2196 /* Pick which query pol to use */
2206 /* Query SAM security object */
2208 result
= rpccli_samr_QuerySecurity(cli
, mem_ctx
,
2213 if (!NT_STATUS_IS_OK(result
))
2216 display_sec_desc(sec_desc_buf
->sd
);
2218 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2219 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2220 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2222 talloc_destroy(ctx
);
2226 static NTSTATUS
cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client
*cli
,
2227 TALLOC_CTX
*mem_ctx
,
2228 int argc
, const char **argv
)
2230 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2231 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2232 struct samr_PwInfo info
;
2236 printf("Usage: %s rid\n", argv
[0]);
2237 return NT_STATUS_OK
;
2240 sscanf(argv
[1], "%i", &rid
);
2242 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2243 MAXIMUM_ALLOWED_ACCESS
,
2246 if (!NT_STATUS_IS_OK(result
)) {
2250 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2252 MAXIMUM_ALLOWED_ACCESS
,
2256 if (!NT_STATUS_IS_OK(result
)) {
2260 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2262 MAXIMUM_ALLOWED_ACCESS
,
2266 if (!NT_STATUS_IS_OK(result
)) {
2270 result
= rpccli_samr_GetUserPwInfo(cli
, mem_ctx
, &user_pol
, &info
);
2271 if (NT_STATUS_IS_OK(result
)) {
2272 printf("min_password_length: %d\n", info
.min_password_length
);
2274 NDR_PRINT_STRUCT_STRING(mem_ctx
,
2275 samr_PasswordProperties
, &info
.password_properties
));
2279 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2280 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2281 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2286 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
2287 TALLOC_CTX
*mem_ctx
,
2288 int argc
, const char **argv
)
2290 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2291 struct lsa_String domain_name
;
2292 struct samr_PwInfo info
;
2294 if (argc
< 1 || argc
> 3) {
2295 printf("Usage: %s <domain>\n", argv
[0]);
2296 return NT_STATUS_OK
;
2299 init_lsa_String(&domain_name
, argv
[1]);
2301 result
= rpccli_samr_GetDomPwInfo(cli
, mem_ctx
, &domain_name
, &info
);
2303 if (NT_STATUS_IS_OK(result
)) {
2304 printf("min_password_length: %d\n", info
.min_password_length
);
2305 display_password_properties(info
.password_properties
);
2311 /* Look up domain name */
2313 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
2314 TALLOC_CTX
*mem_ctx
,
2315 int argc
, const char **argv
)
2317 struct policy_handle connect_pol
, domain_pol
;
2318 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2319 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2321 struct lsa_String domain_name
;
2322 DOM_SID
*sid
= NULL
;
2325 printf("Usage: %s domain_name\n", argv
[0]);
2326 return NT_STATUS_OK
;
2329 init_lsa_String(&domain_name
, argv
[1]);
2331 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2335 if (!NT_STATUS_IS_OK(result
))
2338 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2344 if (!NT_STATUS_IS_OK(result
))
2347 result
= rpccli_samr_LookupDomain(cli
, mem_ctx
,
2352 if (NT_STATUS_IS_OK(result
)) {
2353 sid_to_fstring(sid_string
, sid
);
2354 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2355 argv
[1], sid_string
);
2358 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2359 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2364 /* Change user password */
2366 static NTSTATUS
cmd_samr_chgpasswd(struct rpc_pipe_client
*cli
,
2367 TALLOC_CTX
*mem_ctx
,
2368 int argc
, const char **argv
)
2370 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2371 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2372 const char *user
, *oldpass
, *newpass
;
2373 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2374 struct samr_Ids rids
, types
;
2375 struct lsa_String lsa_acct_name
;
2378 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2379 return NT_STATUS_INVALID_PARAMETER
;
2386 /* Get sam policy handle */
2388 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2389 MAXIMUM_ALLOWED_ACCESS
,
2392 if (!NT_STATUS_IS_OK(result
)) {
2396 /* Get domain policy handle */
2398 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2404 if (!NT_STATUS_IS_OK(result
)) {
2408 init_lsa_String(&lsa_acct_name
, user
);
2410 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2417 if (!NT_STATUS_IS_OK(result
)) {
2421 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2427 if (!NT_STATUS_IS_OK(result
)) {
2431 /* Change user password */
2432 result
= rpccli_samr_chgpasswd_user(cli
, mem_ctx
,
2437 if (!NT_STATUS_IS_OK(result
)) {
2442 if (is_valid_policy_hnd(&user_pol
)) {
2443 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2445 if (is_valid_policy_hnd(&domain_pol
)) {
2446 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2448 if (is_valid_policy_hnd(&connect_pol
)) {
2449 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2456 /* Change user password */
2458 static NTSTATUS
cmd_samr_chgpasswd2(struct rpc_pipe_client
*cli
,
2459 TALLOC_CTX
*mem_ctx
,
2460 int argc
, const char **argv
)
2462 struct policy_handle connect_pol
, domain_pol
;
2463 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2464 const char *user
, *oldpass
, *newpass
;
2465 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2468 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2469 return NT_STATUS_INVALID_PARAMETER
;
2476 /* Get sam policy handle */
2478 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2479 MAXIMUM_ALLOWED_ACCESS
,
2482 if (!NT_STATUS_IS_OK(result
))
2485 /* Get domain policy handle */
2487 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2493 if (!NT_STATUS_IS_OK(result
))
2496 /* Change user password */
2497 result
= rpccli_samr_chgpasswd_user2(cli
, mem_ctx
, user
, newpass
, oldpass
);
2499 if (!NT_STATUS_IS_OK(result
))
2502 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2503 if (!NT_STATUS_IS_OK(result
)) goto done
;
2505 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2506 if (!NT_STATUS_IS_OK(result
)) goto done
;
2513 /* Change user password */
2515 static NTSTATUS
cmd_samr_chgpasswd3(struct rpc_pipe_client
*cli
,
2516 TALLOC_CTX
*mem_ctx
,
2517 int argc
, const char **argv
)
2519 struct policy_handle connect_pol
, domain_pol
;
2520 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2521 const char *user
, *oldpass
, *newpass
;
2522 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2523 struct samr_DomInfo1
*info
= NULL
;
2524 struct samr_ChangeReject
*reject
= NULL
;
2527 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2528 return NT_STATUS_INVALID_PARAMETER
;
2535 /* Get sam policy handle */
2537 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2538 MAXIMUM_ALLOWED_ACCESS
,
2541 if (!NT_STATUS_IS_OK(result
))
2544 /* Get domain policy handle */
2546 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2552 if (!NT_STATUS_IS_OK(result
))
2555 /* Change user password */
2556 result
= rpccli_samr_chgpasswd_user3(cli
, mem_ctx
,
2563 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
)) {
2565 display_sam_dom_info_1(info
);
2567 switch (reject
->reason
) {
2568 case SAMR_REJECT_TOO_SHORT
:
2569 d_printf("SAMR_REJECT_TOO_SHORT\n");
2571 case SAMR_REJECT_IN_HISTORY
:
2572 d_printf("SAMR_REJECT_IN_HISTORY\n");
2574 case SAMR_REJECT_COMPLEXITY
:
2575 d_printf("SAMR_REJECT_COMPLEXITY\n");
2577 case SAMR_REJECT_OTHER
:
2578 d_printf("SAMR_REJECT_OTHER\n");
2581 d_printf("unknown reject reason: %d\n",
2587 if (!NT_STATUS_IS_OK(result
))
2590 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2591 if (!NT_STATUS_IS_OK(result
)) goto done
;
2593 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2594 if (!NT_STATUS_IS_OK(result
)) goto done
;
2600 static NTSTATUS
cmd_samr_setuserinfo_int(struct rpc_pipe_client
*cli
,
2601 TALLOC_CTX
*mem_ctx
,
2602 int argc
, const char **argv
,
2605 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2606 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
2607 const char *user
, *param
;
2608 uint32_t access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2611 union samr_UserInfo info
;
2612 struct samr_CryptPassword pwd_buf
;
2613 struct samr_CryptPasswordEx pwd_buf_ex
;
2614 uint8_t nt_hash
[16];
2615 uint8_t lm_hash
[16];
2616 DATA_BLOB session_key
;
2617 uint8_t password_expired
= 0;
2620 printf("Usage: %s username level password [password_expired]\n",
2622 return NT_STATUS_INVALID_PARAMETER
;
2626 level
= atoi(argv
[2]);
2630 password_expired
= atoi(argv
[4]);
2633 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2634 if (!NT_STATUS_IS_OK(status
)) {
2638 init_samr_CryptPassword(param
, &session_key
, &pwd_buf
);
2639 init_samr_CryptPasswordEx(param
, &session_key
, &pwd_buf_ex
);
2640 nt_lm_owf_gen(param
, nt_hash
, lm_hash
);
2646 in
= data_blob_const(nt_hash
, 16);
2647 out
= data_blob_talloc_zero(mem_ctx
, 16);
2648 sess_crypt_blob(&out
, &in
, &session_key
, true);
2649 memcpy(nt_hash
, out
.data
, out
.length
);
2653 in
= data_blob_const(lm_hash
, 16);
2654 out
= data_blob_talloc_zero(mem_ctx
, 16);
2655 sess_crypt_blob(&out
, &in
, &session_key
, true);
2656 memcpy(lm_hash
, out
.data
, out
.length
);
2659 memcpy(info
.info18
.nt_pwd
.hash
, nt_hash
, 16);
2660 memcpy(info
.info18
.lm_pwd
.hash
, lm_hash
, 16);
2661 info
.info18
.nt_pwd_active
= true;
2662 info
.info18
.lm_pwd_active
= true;
2663 info
.info18
.password_expired
= password_expired
;
2667 ZERO_STRUCT(info
.info21
);
2669 info
.info21
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2670 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2672 info
.info21
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2673 info
.info21
.password_expired
= password_expired
;
2676 info
.info21
.lm_password_set
= true;
2677 info
.info21
.lm_owf_password
.length
= 16;
2678 info
.info21
.lm_owf_password
.size
= 16;
2680 info
.info21
.nt_password_set
= true;
2681 info
.info21
.nt_owf_password
.length
= 16;
2682 info
.info21
.nt_owf_password
.size
= 16;
2686 in
= data_blob_const(nt_hash
, 16);
2687 out
= data_blob_talloc_zero(mem_ctx
, 16);
2688 sess_crypt_blob(&out
, &in
, &session_key
, true);
2689 info
.info21
.nt_owf_password
.array
=
2690 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2694 in
= data_blob_const(lm_hash
, 16);
2695 out
= data_blob_talloc_zero(mem_ctx
, 16);
2696 sess_crypt_blob(&out
, &in
, &session_key
, true);
2697 info
.info21
.lm_owf_password
.array
=
2698 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2703 ZERO_STRUCT(info
.info23
);
2705 info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2706 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2708 info
.info23
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2709 info
.info23
.info
.password_expired
= password_expired
;
2712 info
.info23
.password
= pwd_buf
;
2716 info
.info24
.password
= pwd_buf
;
2717 info
.info24
.password_expired
= password_expired
;
2721 ZERO_STRUCT(info
.info25
);
2723 info
.info25
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2724 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2726 info
.info25
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2727 info
.info25
.info
.password_expired
= password_expired
;
2730 info
.info25
.password
= pwd_buf_ex
;
2734 info
.info26
.password
= pwd_buf_ex
;
2735 info
.info26
.password_expired
= password_expired
;
2739 return NT_STATUS_INVALID_INFO_CLASS
;
2742 /* Get sam policy handle */
2744 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2745 MAXIMUM_ALLOWED_ACCESS
,
2748 if (!NT_STATUS_IS_OK(status
))
2751 /* Get domain policy handle */
2753 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2759 if (!NT_STATUS_IS_OK(status
))
2762 user_rid
= strtol(user
, NULL
, 0);
2764 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2771 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
) ||
2774 /* Probably this was a user name, try lookupnames */
2775 struct samr_Ids rids
, types
;
2776 struct lsa_String lsa_acct_name
;
2778 init_lsa_String(&lsa_acct_name
, user
);
2780 status
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2786 if (!NT_STATUS_IS_OK(status
)) {
2790 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2795 if (!NT_STATUS_IS_OK(status
)) {
2801 case NDR_SAMR_SETUSERINFO
:
2802 status
= rpccli_samr_SetUserInfo(cli
, mem_ctx
,
2807 case NDR_SAMR_SETUSERINFO2
:
2808 status
= rpccli_samr_SetUserInfo2(cli
, mem_ctx
,
2814 return NT_STATUS_INVALID_PARAMETER
;
2821 static NTSTATUS
cmd_samr_setuserinfo(struct rpc_pipe_client
*cli
,
2822 TALLOC_CTX
*mem_ctx
,
2823 int argc
, const char **argv
)
2825 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2826 NDR_SAMR_SETUSERINFO
);
2829 static NTSTATUS
cmd_samr_setuserinfo2(struct rpc_pipe_client
*cli
,
2830 TALLOC_CTX
*mem_ctx
,
2831 int argc
, const char **argv
)
2833 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2834 NDR_SAMR_SETUSERINFO2
);
2837 static NTSTATUS
cmd_samr_get_dispinfo_idx(struct rpc_pipe_client
*cli
,
2838 TALLOC_CTX
*mem_ctx
,
2839 int argc
, const char **argv
)
2842 struct policy_handle connect_handle
;
2843 struct policy_handle domain_handle
;
2845 struct lsa_String name
;
2848 if (argc
< 2 || argc
> 3) {
2849 printf("Usage: %s name level\n", argv
[0]);
2850 return NT_STATUS_INVALID_PARAMETER
;
2853 init_lsa_String(&name
, argv
[1]);
2856 level
= atoi(argv
[2]);
2859 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2860 SEC_FLAG_MAXIMUM_ALLOWED
,
2863 if (!NT_STATUS_IS_OK(status
)) {
2867 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2869 SEC_FLAG_MAXIMUM_ALLOWED
,
2873 if (!NT_STATUS_IS_OK(status
))
2877 status
= rpccli_samr_GetDisplayEnumerationIndex(cli
, mem_ctx
,
2883 if (NT_STATUS_IS_OK(status
) ||
2884 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2885 printf("idx: %d (0x%08x)\n", idx
, idx
);
2889 if (is_valid_policy_hnd(&domain_handle
)) {
2890 rpccli_samr_Close(cli
, mem_ctx
, &domain_handle
);
2892 if (is_valid_policy_hnd(&connect_handle
)) {
2893 rpccli_samr_Close(cli
, mem_ctx
, &connect_handle
);
2899 /* List of commands exported by this module */
2901 struct cmd_set samr_commands
[] = {
2905 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user info", "" },
2906 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group info", "" },
2907 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user groups", "" },
2908 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user aliases", "" },
2909 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group membership", "" },
2910 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias membership", "" },
2911 { "queryaliasinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias info", "" },
2912 { "deletealias", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete an alias", "" },
2913 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2914 { "querydispinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2915 { "querydispinfo3", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2916 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query domain info", "" },
2917 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain users", "" },
2918 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain groups", "" },
2919 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate alias groups", "" },
2920 { "enumdomains", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_domains
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domains", "" },
2922 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain user", "" },
2923 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain group", "" },
2924 { "createdomalias", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain alias", "" },
2925 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2926 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2927 { "deletedomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain group", "" },
2928 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain user", "" },
2929 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query SAMR security object", "" },
2930 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve domain password info", "" },
2931 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_usrdom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve user domain password info", "" },
2933 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Lookup Domain Name", "" },
2934 { "chgpasswd", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2935 { "chgpasswd2", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2936 { "chgpasswd3", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2937 { "getdispinfoidx", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dispinfo_idx
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Get Display Information Index", "" },
2938 { "setuserinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info", "" },
2939 { "setuserinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info2", "" },