2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 1992-2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 Copyright (C) Elrond 2000,
8 Copyright (C) Tim Potter 2000
9 Copyright (C) Guenther Deschner 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "rpcclient.h"
27 #include "../libcli/auth/libcli_auth.h"
28 #include "../librpc/gen_ndr/ndr_samr.h"
29 #include "../librpc/gen_ndr/ndr_samr_c.h"
30 #include "rpc_client/cli_samr.h"
31 #include "rpc_client/init_samr.h"
32 #include "rpc_client/init_lsa.h"
33 #include "../libcli/security/security.h"
35 extern struct dom_sid domain_sid
;
37 /****************************************************************************
38 display samr_user_info_7 structure
39 ****************************************************************************/
40 static void display_samr_user_info_7(struct samr_UserInfo7
*r
)
42 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
45 /****************************************************************************
46 display samr_user_info_9 structure
47 ****************************************************************************/
48 static void display_samr_user_info_9(struct samr_UserInfo9
*r
)
50 printf("\tPrimary group RID :\tox%x\n", r
->primary_gid
);
53 /****************************************************************************
54 display samr_user_info_16 structure
55 ****************************************************************************/
56 static void display_samr_user_info_16(struct samr_UserInfo16
*r
)
58 printf("\tAcct Flags :\tox%x\n", r
->acct_flags
);
61 /****************************************************************************
62 display samr_user_info_20 structure
63 ****************************************************************************/
64 static void display_samr_user_info_20(struct samr_UserInfo20
*r
)
66 printf("\tRemote Dial :\n");
67 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
71 /****************************************************************************
72 display samr_user_info_21 structure
73 ****************************************************************************/
74 static void display_samr_user_info_21(struct samr_UserInfo21
*r
)
76 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
77 printf("\tFull Name :\t%s\n", r
->full_name
.string
);
78 printf("\tHome Drive :\t%s\n", r
->home_directory
.string
);
79 printf("\tDir Drive :\t%s\n", r
->home_drive
.string
);
80 printf("\tProfile Path:\t%s\n", r
->profile_path
.string
);
81 printf("\tLogon Script:\t%s\n", r
->logon_script
.string
);
82 printf("\tDescription :\t%s\n", r
->description
.string
);
83 printf("\tWorkstations:\t%s\n", r
->workstations
.string
);
84 printf("\tComment :\t%s\n", r
->comment
.string
);
85 printf("\tRemote Dial :\n");
86 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
88 printf("\tLogon Time :\t%s\n",
89 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logon
)));
90 printf("\tLogoff Time :\t%s\n",
91 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logoff
)));
92 printf("\tKickoff Time :\t%s\n",
93 http_timestring(talloc_tos(), nt_time_to_unix(r
->acct_expiry
)));
94 printf("\tPassword last set Time :\t%s\n",
95 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_password_change
)));
96 printf("\tPassword can change Time :\t%s\n",
97 http_timestring(talloc_tos(), nt_time_to_unix(r
->allow_password_change
)));
98 printf("\tPassword must change Time:\t%s\n",
99 http_timestring(talloc_tos(), nt_time_to_unix(r
->force_password_change
)));
101 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
103 printf("\tuser_rid :\t0x%x\n" , r
->rid
); /* User ID */
104 printf("\tgroup_rid:\t0x%x\n" , r
->primary_gid
); /* Group ID */
105 printf("\tacb_info :\t0x%08x\n", r
->acct_flags
); /* Account Control Info */
107 printf("\tfields_present:\t0x%08x\n", r
->fields_present
); /* 0x00ff ffff */
108 printf("\tlogon_divs:\t%d\n", r
->logon_hours
.units_per_week
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
109 printf("\tbad_password_count:\t0x%08x\n", r
->bad_password_count
);
110 printf("\tlogon_count:\t0x%08x\n", r
->logon_count
);
112 printf("\tpadding1[0..7]...\n");
114 if (r
->logon_hours
.bits
) {
115 printf("\tlogon_hrs[0..%d]...\n", r
->logon_hours
.units_per_week
/8);
120 static void display_password_properties(uint32_t password_properties
)
122 printf("password_properties: 0x%08x\n", password_properties
);
124 if (password_properties
& DOMAIN_PASSWORD_COMPLEX
)
125 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
127 if (password_properties
& DOMAIN_PASSWORD_NO_ANON_CHANGE
)
128 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
130 if (password_properties
& DOMAIN_PASSWORD_NO_CLEAR_CHANGE
)
131 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
133 if (password_properties
& DOMAIN_PASSWORD_LOCKOUT_ADMINS
)
134 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
136 if (password_properties
& DOMAIN_PASSWORD_STORE_CLEARTEXT
)
137 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
139 if (password_properties
& DOMAIN_REFUSE_PASSWORD_CHANGE
)
140 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
143 static void display_sam_dom_info_1(struct samr_DomInfo1
*info1
)
145 printf("Minimum password length:\t\t\t%d\n",
146 info1
->min_password_length
);
147 printf("Password uniqueness (remember x passwords):\t%d\n",
148 info1
->password_history_length
);
149 display_password_properties(info1
->password_properties
);
150 printf("password expire in:\t\t\t\t%s\n",
151 display_time(info1
->max_password_age
));
152 printf("Min password age (allow changing in x days):\t%s\n",
153 display_time(info1
->min_password_age
));
156 static void display_sam_dom_info_2(struct samr_DomGeneralInformation
*general
)
158 printf("Domain:\t\t%s\n", general
->domain_name
.string
);
159 printf("Server:\t\t%s\n", general
->primary
.string
);
160 printf("Comment:\t%s\n", general
->oem_information
.string
);
162 printf("Total Users:\t%d\n", general
->num_users
);
163 printf("Total Groups:\t%d\n", general
->num_groups
);
164 printf("Total Aliases:\t%d\n", general
->num_aliases
);
166 printf("Sequence No:\t%llu\n", (unsigned long long)general
->sequence_num
);
168 printf("Force Logoff:\t%d\n",
169 (int)nt_time_to_unix_abs(&general
->force_logoff_time
));
171 printf("Domain Server State:\t0x%x\n", general
->domain_server_state
);
172 printf("Server Role:\t%s\n", server_role_str(general
->role
));
173 printf("Unknown 3:\t0x%x\n", general
->unknown3
);
176 static void display_sam_dom_info_3(struct samr_DomInfo3
*info3
)
178 printf("Force Logoff:\t%d\n",
179 (int)nt_time_to_unix_abs(&info3
->force_logoff_time
));
182 static void display_sam_dom_info_4(struct samr_DomOEMInformation
*oem
)
184 printf("Comment:\t%s\n", oem
->oem_information
.string
);
187 static void display_sam_dom_info_5(struct samr_DomInfo5
*info5
)
189 printf("Domain:\t\t%s\n", info5
->domain_name
.string
);
192 static void display_sam_dom_info_6(struct samr_DomInfo6
*info6
)
194 printf("Server:\t\t%s\n", info6
->primary
.string
);
197 static void display_sam_dom_info_7(struct samr_DomInfo7
*info7
)
199 printf("Server Role:\t%s\n", server_role_str(info7
->role
));
202 static void display_sam_dom_info_8(struct samr_DomInfo8
*info8
)
204 printf("Sequence No:\t%llu\n", (unsigned long long)info8
->sequence_num
);
205 printf("Domain Create Time:\t%s\n",
206 http_timestring(talloc_tos(), nt_time_to_unix(info8
->domain_create_time
)));
209 static void display_sam_dom_info_9(struct samr_DomInfo9
*info9
)
211 printf("Domain Server State:\t0x%x\n", info9
->domain_server_state
);
214 static void display_sam_dom_info_12(struct samr_DomInfo12
*info12
)
216 printf("Bad password lockout duration: %s\n",
217 display_time(info12
->lockout_duration
));
218 printf("Reset Lockout after: %s\n",
219 display_time(info12
->lockout_window
));
220 printf("Lockout after bad attempts: %d\n",
221 info12
->lockout_threshold
);
224 static void display_sam_dom_info_13(struct samr_DomInfo13
*info13
)
226 printf("Sequence No:\t%llu\n", (unsigned long long)info13
->sequence_num
);
227 printf("Domain Create Time:\t%s\n",
228 http_timestring(talloc_tos(), nt_time_to_unix(info13
->domain_create_time
)));
229 printf("Sequence No at last promotion:\t%llu\n",
230 (unsigned long long)info13
->modified_count_at_last_promotion
);
233 static void display_sam_info_1(struct samr_DispEntryGeneral
*r
)
235 printf("index: 0x%x ", r
->idx
);
236 printf("RID: 0x%x ", r
->rid
);
237 printf("acb: 0x%08x ", r
->acct_flags
);
238 printf("Account: %s\t", r
->account_name
.string
);
239 printf("Name: %s\t", r
->full_name
.string
);
240 printf("Desc: %s\n", r
->description
.string
);
243 static void display_sam_info_2(struct samr_DispEntryFull
*r
)
245 printf("index: 0x%x ", r
->idx
);
246 printf("RID: 0x%x ", r
->rid
);
247 printf("acb: 0x%08x ", r
->acct_flags
);
248 printf("Account: %s\t", r
->account_name
.string
);
249 printf("Desc: %s\n", r
->description
.string
);
252 static void display_sam_info_3(struct samr_DispEntryFullGroup
*r
)
254 printf("index: 0x%x ", r
->idx
);
255 printf("RID: 0x%x ", r
->rid
);
256 printf("acb: 0x%08x ", r
->acct_flags
);
257 printf("Account: %s\t", r
->account_name
.string
);
258 printf("Desc: %s\n", r
->description
.string
);
261 static void display_sam_info_4(struct samr_DispEntryAscii
*r
)
263 printf("index: 0x%x ", r
->idx
);
264 printf("Account: %s\n", r
->account_name
.string
);
267 static void display_sam_info_5(struct samr_DispEntryAscii
*r
)
269 printf("index: 0x%x ", r
->idx
);
270 printf("Account: %s\n", r
->account_name
.string
);
273 /****************************************************************************
274 ****************************************************************************/
276 static NTSTATUS
get_domain_handle(struct rpc_pipe_client
*cli
,
279 struct policy_handle
*connect_pol
,
280 uint32_t access_mask
,
281 struct dom_sid
*_domain_sid
,
282 struct policy_handle
*domain_pol
)
284 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
285 NTSTATUS status
= NT_STATUS_INVALID_PARAMETER
, result
;
287 if (strcasecmp_m(sam
, "domain") == 0) {
288 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
294 } else if (strcasecmp_m(sam
, "builtin") == 0) {
295 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
298 discard_const_p(struct dom_sid2
, &global_sid_Builtin
),
303 if (!NT_STATUS_IS_OK(status
)) {
310 /**********************************************************************
311 * Query user information
313 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
315 int argc
, const char **argv
)
317 struct policy_handle connect_pol
, domain_pol
, user_pol
;
318 NTSTATUS status
, result
;
319 uint32 info_level
= 21;
320 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
321 union samr_UserInfo
*info
= NULL
;
323 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
325 if ((argc
< 2) || (argc
> 4)) {
326 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
330 sscanf(argv
[1], "%i", &user_rid
);
333 sscanf(argv
[2], "%i", &info_level
);
336 sscanf(argv
[3], "%x", &access_mask
);
339 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
340 MAXIMUM_ALLOWED_ACCESS
,
342 if (!NT_STATUS_IS_OK(status
)) {
346 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
348 MAXIMUM_ALLOWED_ACCESS
,
352 if (!NT_STATUS_IS_OK(status
)) {
355 if (!NT_STATUS_IS_OK(result
)) {
360 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
366 if (!NT_STATUS_IS_OK(status
)) {
369 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) &&
372 /* Probably this was a user name, try lookupnames */
373 struct samr_Ids rids
, types
;
374 struct lsa_String lsa_acct_name
;
376 init_lsa_String(&lsa_acct_name
, argv
[1]);
378 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
385 if (!NT_STATUS_IS_OK(status
)) {
388 if (NT_STATUS_IS_OK(result
)) {
389 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
395 if (!NT_STATUS_IS_OK(status
)) {
402 if (!NT_STATUS_IS_OK(result
)) {
407 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
412 if (!NT_STATUS_IS_OK(status
)) {
415 if (!NT_STATUS_IS_OK(result
)) {
420 switch (info_level
) {
422 display_samr_user_info_7(&info
->info7
);
425 display_samr_user_info_9(&info
->info9
);
428 display_samr_user_info_16(&info
->info16
);
431 display_samr_user_info_20(&info
->info20
);
434 display_samr_user_info_21(&info
->info21
);
437 printf("Unsupported infolevel: %d\n", info_level
);
441 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
442 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
443 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
449 /****************************************************************************
451 ****************************************************************************/
452 static void display_group_info1(struct samr_GroupInfoAll
*info1
)
454 printf("\tGroup Name:\t%s\n", info1
->name
.string
);
455 printf("\tDescription:\t%s\n", info1
->description
.string
);
456 printf("\tGroup Attribute:%d\n", info1
->attributes
);
457 printf("\tNum Members:%d\n", info1
->num_members
);
460 /****************************************************************************
462 ****************************************************************************/
463 static void display_group_info2(struct lsa_String
*info2
)
465 printf("\tGroup Description:%s\n", info2
->string
);
469 /****************************************************************************
471 ****************************************************************************/
472 static void display_group_info3(struct samr_GroupInfoAttributes
*info3
)
474 printf("\tGroup Attribute:%d\n", info3
->attributes
);
478 /****************************************************************************
480 ****************************************************************************/
481 static void display_group_info4(struct lsa_String
*info4
)
483 printf("\tGroup Description:%s\n", info4
->string
);
486 /****************************************************************************
488 ****************************************************************************/
489 static void display_group_info5(struct samr_GroupInfoAll
*info5
)
491 printf("\tGroup Name:\t%s\n", info5
->name
.string
);
492 printf("\tDescription:\t%s\n", info5
->description
.string
);
493 printf("\tGroup Attribute:%d\n", info5
->attributes
);
494 printf("\tNum Members:%d\n", info5
->num_members
);
497 /****************************************************************************
498 display sam sync structure
499 ****************************************************************************/
500 static void display_group_info(union samr_GroupInfo
*info
,
501 enum samr_GroupInfoEnum level
)
505 display_group_info1(&info
->all
);
508 display_group_info2(&info
->name
);
511 display_group_info3(&info
->attributes
);
514 display_group_info4(&info
->description
);
517 display_group_info5(&info
->all2
);
522 /***********************************************************************
523 * Query group information
525 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
527 int argc
, const char **argv
)
529 struct policy_handle connect_pol
, domain_pol
, group_pol
;
530 NTSTATUS status
, result
;
531 enum samr_GroupInfoEnum info_level
= GROUPINFOALL
;
532 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
533 union samr_GroupInfo
*group_info
= NULL
;
535 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
537 if ((argc
< 2) || (argc
> 4)) {
538 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
542 sscanf(argv
[1], "%i", &group_rid
);
545 info_level
= atoi(argv
[2]);
548 sscanf(argv
[3], "%x", &access_mask
);
550 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
551 MAXIMUM_ALLOWED_ACCESS
,
553 if (!NT_STATUS_IS_OK(status
)) {
557 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
559 MAXIMUM_ALLOWED_ACCESS
,
563 if (!NT_STATUS_IS_OK(status
)) {
566 if (!NT_STATUS_IS_OK(result
)) {
571 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
577 if (!NT_STATUS_IS_OK(status
)) {
580 if (!NT_STATUS_IS_OK(result
)) {
585 status
= dcerpc_samr_QueryGroupInfo(b
, mem_ctx
,
590 if (!NT_STATUS_IS_OK(status
)) {
593 if (!NT_STATUS_IS_OK(result
)) {
598 display_group_info(group_info
, info_level
);
600 dcerpc_samr_Close(b
, mem_ctx
, &group_pol
, &result
);
601 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
602 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
607 /* Query groups a user is a member of */
609 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
611 int argc
, const char **argv
)
613 struct policy_handle connect_pol
,
616 NTSTATUS status
, result
;
618 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
620 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
621 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
623 if ((argc
< 2) || (argc
> 3)) {
624 printf("Usage: %s rid [access mask]\n", argv
[0]);
628 sscanf(argv
[1], "%i", &user_rid
);
631 sscanf(argv
[2], "%x", &access_mask
);
633 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
634 MAXIMUM_ALLOWED_ACCESS
,
636 if (!NT_STATUS_IS_OK(status
)) {
640 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
642 MAXIMUM_ALLOWED_ACCESS
,
646 if (!NT_STATUS_IS_OK(status
)) {
649 if (!NT_STATUS_IS_OK(result
)) {
654 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
661 if (!NT_STATUS_IS_OK(status
)) {
664 if (!NT_STATUS_IS_OK(result
)) {
669 status
= dcerpc_samr_GetGroupsForUser(b
, mem_ctx
,
673 if (!NT_STATUS_IS_OK(status
)) {
676 if (!NT_STATUS_IS_OK(result
)) {
681 for (i
= 0; i
< rid_array
->count
; i
++) {
682 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
683 rid_array
->rids
[i
].rid
,
684 rid_array
->rids
[i
].attributes
);
687 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
688 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
689 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
694 /* Query aliases a user is a member of */
696 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
698 int argc
, const char **argv
)
700 struct policy_handle connect_pol
, domain_pol
;
701 NTSTATUS status
, result
;
702 struct dom_sid
*sids
;
704 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
706 struct lsa_SidArray sid_array
;
707 struct samr_Ids alias_rids
;
708 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
711 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
712 return NT_STATUS_INVALID_PARAMETER
;
718 for (i
=2; i
<argc
; i
++) {
719 struct dom_sid tmp_sid
;
720 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
721 printf("%s is not a legal SID\n", argv
[i
]);
722 return NT_STATUS_INVALID_PARAMETER
;
724 result
= add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
725 if (!NT_STATUS_IS_OK(result
)) {
731 sid_array
.sids
= talloc_zero_array(mem_ctx
, struct lsa_SidPtr
, num_sids
);
732 if (sid_array
.sids
== NULL
)
733 return NT_STATUS_NO_MEMORY
;
735 sid_array
.sids
= NULL
;
738 for (i
=0; i
<num_sids
; i
++) {
739 sid_array
.sids
[i
].sid
= dom_sid_dup(mem_ctx
, &sids
[i
]);
740 if (!sid_array
.sids
[i
].sid
) {
741 return NT_STATUS_NO_MEMORY
;
745 sid_array
.num_sids
= num_sids
;
747 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
748 MAXIMUM_ALLOWED_ACCESS
,
750 if (!NT_STATUS_IS_OK(status
)) {
754 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
759 if (!NT_STATUS_IS_OK(status
)) {
763 status
= dcerpc_samr_GetAliasMembership(b
, mem_ctx
,
768 if (!NT_STATUS_IS_OK(status
)) {
771 if (!NT_STATUS_IS_OK(result
)) {
776 for (i
= 0; i
< alias_rids
.count
; i
++) {
777 printf("\tgroup rid:[0x%x]\n", alias_rids
.ids
[i
]);
780 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
781 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
786 /* Query members of a group */
788 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
790 int argc
, const char **argv
)
792 struct policy_handle connect_pol
, domain_pol
, group_pol
;
793 NTSTATUS status
, result
;
795 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
797 unsigned int old_timeout
;
798 struct samr_RidAttrArray
*rids
= NULL
;
799 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
801 if ((argc
< 2) || (argc
> 3)) {
802 printf("Usage: %s rid [access mask]\n", argv
[0]);
806 sscanf(argv
[1], "%i", &group_rid
);
809 sscanf(argv
[2], "%x", &access_mask
);
811 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
812 MAXIMUM_ALLOWED_ACCESS
,
814 if (!NT_STATUS_IS_OK(status
)) {
818 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
820 MAXIMUM_ALLOWED_ACCESS
,
824 if (!NT_STATUS_IS_OK(status
)) {
827 if (!NT_STATUS_IS_OK(result
)) {
832 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
838 if (!NT_STATUS_IS_OK(status
)) {
841 if (!NT_STATUS_IS_OK(result
)) {
846 /* Make sure to wait for our DC's reply */
847 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
848 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
850 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
855 rpccli_set_timeout(cli
, old_timeout
);
857 if (!NT_STATUS_IS_OK(status
)) {
860 if (!NT_STATUS_IS_OK(result
)) {
865 for (i
= 0; i
< rids
->count
; i
++) {
866 printf("\trid:[0x%x] attr:[0x%x]\n", rids
->rids
[i
],
867 rids
->attributes
[i
]);
870 dcerpc_samr_Close(b
, mem_ctx
, &group_pol
, &result
);
871 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
872 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
877 /* Enumerate domain users */
879 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
881 int argc
, const char **argv
)
883 struct policy_handle connect_pol
;
884 struct policy_handle domain_pol
= { 0, };
885 NTSTATUS status
, result
;
886 uint32 start_idx
, num_dom_users
, i
;
887 struct samr_SamArray
*dom_users
= NULL
;
888 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
889 uint32 acb_mask
= ACB_NORMAL
;
890 uint32_t size
= 0xffff;
891 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
893 if ((argc
< 1) || (argc
> 4)) {
894 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv
[0]);
899 sscanf(argv
[1], "%x", &access_mask
);
903 sscanf(argv
[2], "%x", &acb_mask
);
907 sscanf(argv
[3], "%x", &size
);
910 /* Get sam policy handle */
912 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
913 MAXIMUM_ALLOWED_ACCESS
,
915 if (!NT_STATUS_IS_OK(status
)) {
919 /* Get domain policy handle */
921 status
= get_domain_handle(cli
, mem_ctx
, "domain",
926 if (!NT_STATUS_IS_OK(status
)) {
930 /* Enumerate domain users */
935 status
= dcerpc_samr_EnumDomainUsers(b
, mem_ctx
,
943 if (!NT_STATUS_IS_OK(status
)) {
946 if (NT_STATUS_IS_OK(result
) ||
947 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
949 for (i
= 0; i
< num_dom_users
; i
++)
950 printf("user:[%s] rid:[0x%x]\n",
951 dom_users
->entries
[i
].name
.string
,
952 dom_users
->entries
[i
].idx
);
955 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
958 if (is_valid_policy_hnd(&domain_pol
))
959 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
961 if (is_valid_policy_hnd(&connect_pol
))
962 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
967 /* Enumerate domain groups */
969 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
971 int argc
, const char **argv
)
973 struct policy_handle connect_pol
;
974 struct policy_handle domain_pol
= { 0, };
975 NTSTATUS status
, result
;
976 uint32 start_idx
, num_dom_groups
, i
;
977 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
978 struct samr_SamArray
*dom_groups
= NULL
;
979 uint32_t size
= 0xffff;
980 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
982 if ((argc
< 1) || (argc
> 3)) {
983 printf("Usage: %s [access_mask] [max_size]\n", argv
[0]);
988 sscanf(argv
[1], "%x", &access_mask
);
992 sscanf(argv
[2], "%x", &size
);
995 /* Get sam policy handle */
997 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
998 MAXIMUM_ALLOWED_ACCESS
,
1000 if (!NT_STATUS_IS_OK(status
)) {
1004 /* Get domain policy handle */
1006 status
= get_domain_handle(cli
, mem_ctx
, "domain",
1011 if (!NT_STATUS_IS_OK(status
)) {
1015 /* Enumerate domain groups */
1020 status
= dcerpc_samr_EnumDomainGroups(b
, mem_ctx
,
1027 if (!NT_STATUS_IS_OK(status
)) {
1030 if (NT_STATUS_IS_OK(result
) ||
1031 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1033 for (i
= 0; i
< num_dom_groups
; i
++)
1034 printf("group:[%s] rid:[0x%x]\n",
1035 dom_groups
->entries
[i
].name
.string
,
1036 dom_groups
->entries
[i
].idx
);
1039 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1042 if (is_valid_policy_hnd(&domain_pol
))
1043 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1045 if (is_valid_policy_hnd(&connect_pol
))
1046 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1051 /* Enumerate alias groups */
1053 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
1054 TALLOC_CTX
*mem_ctx
,
1055 int argc
, const char **argv
)
1057 struct policy_handle connect_pol
;
1058 struct policy_handle domain_pol
= { 0, };
1059 NTSTATUS status
, result
;
1060 uint32 start_idx
, num_als_groups
, i
;
1061 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1062 struct samr_SamArray
*als_groups
= NULL
;
1063 uint32_t size
= 0xffff;
1064 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1066 if ((argc
< 2) || (argc
> 4)) {
1067 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv
[0]);
1068 return NT_STATUS_OK
;
1072 sscanf(argv
[2], "%x", &access_mask
);
1076 sscanf(argv
[3], "%x", &size
);
1079 /* Get sam policy handle */
1081 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1082 MAXIMUM_ALLOWED_ACCESS
,
1084 if (!NT_STATUS_IS_OK(status
)) {
1088 /* Get domain policy handle */
1090 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1095 if (!NT_STATUS_IS_OK(status
)) {
1099 /* Enumerate alias groups */
1104 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
1111 if (!NT_STATUS_IS_OK(status
)) {
1114 if (NT_STATUS_IS_OK(result
) ||
1115 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1117 for (i
= 0; i
< num_als_groups
; i
++)
1118 printf("group:[%s] rid:[0x%x]\n",
1119 als_groups
->entries
[i
].name
.string
,
1120 als_groups
->entries
[i
].idx
);
1122 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1125 if (is_valid_policy_hnd(&domain_pol
))
1126 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1128 if (is_valid_policy_hnd(&connect_pol
))
1129 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1134 /* Enumerate domains */
1136 static NTSTATUS
cmd_samr_enum_domains(struct rpc_pipe_client
*cli
,
1137 TALLOC_CTX
*mem_ctx
,
1138 int argc
, const char **argv
)
1140 struct policy_handle connect_pol
;
1141 NTSTATUS status
, result
;
1142 uint32 start_idx
, size
, num_entries
, i
;
1143 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1144 struct samr_SamArray
*sam
= NULL
;
1145 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1147 if ((argc
< 1) || (argc
> 2)) {
1148 printf("Usage: %s [access mask]\n", argv
[0]);
1149 return NT_STATUS_OK
;
1153 sscanf(argv
[1], "%x", &access_mask
);
1156 /* Get sam policy handle */
1158 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1161 if (!NT_STATUS_IS_OK(status
)) {
1165 /* Enumerate alias groups */
1171 status
= dcerpc_samr_EnumDomains(b
, mem_ctx
,
1178 if (!NT_STATUS_IS_OK(status
)) {
1181 if (NT_STATUS_IS_OK(result
) ||
1182 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1184 for (i
= 0; i
< num_entries
; i
++)
1185 printf("name:[%s] idx:[0x%x]\n",
1186 sam
->entries
[i
].name
.string
,
1187 sam
->entries
[i
].idx
);
1189 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1192 if (is_valid_policy_hnd(&connect_pol
)) {
1193 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1200 /* Query alias membership */
1202 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
1203 TALLOC_CTX
*mem_ctx
,
1204 int argc
, const char **argv
)
1206 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1207 NTSTATUS status
, result
;
1208 uint32 alias_rid
, i
;
1209 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1210 struct lsa_SidArray sid_array
;
1211 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1213 if ((argc
< 3) || (argc
> 4)) {
1214 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
1215 return NT_STATUS_OK
;
1218 sscanf(argv
[2], "%i", &alias_rid
);
1221 sscanf(argv
[3], "%x", &access_mask
);
1223 /* Open SAMR handle */
1225 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1226 MAXIMUM_ALLOWED_ACCESS
,
1228 if (!NT_STATUS_IS_OK(status
)) {
1232 /* Open handle on domain */
1234 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1236 MAXIMUM_ALLOWED_ACCESS
,
1239 if (!NT_STATUS_IS_OK(status
)) {
1243 /* Open handle on alias */
1245 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
1251 if (!NT_STATUS_IS_OK(status
)) {
1254 if (!NT_STATUS_IS_OK(result
)) {
1259 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
1263 if (!NT_STATUS_IS_OK(status
)) {
1266 if (!NT_STATUS_IS_OK(result
)) {
1271 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
1274 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
1275 printf("\tsid:[%s]\n", sid_str
);
1278 dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &result
);
1279 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1280 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1285 /* Query alias info */
1287 static NTSTATUS
cmd_samr_query_aliasinfo(struct rpc_pipe_client
*cli
,
1288 TALLOC_CTX
*mem_ctx
,
1289 int argc
, const char **argv
)
1291 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1292 NTSTATUS status
, result
;
1294 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1295 union samr_AliasInfo
*info
= NULL
;
1296 enum samr_AliasInfoEnum level
= ALIASINFOALL
;
1297 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1299 if ((argc
< 3) || (argc
> 4)) {
1300 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1302 return NT_STATUS_OK
;
1305 sscanf(argv
[2], "%i", &alias_rid
);
1308 level
= atoi(argv
[3]);
1312 sscanf(argv
[4], "%x", &access_mask
);
1315 /* Open SAMR handle */
1317 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1318 SEC_FLAG_MAXIMUM_ALLOWED
,
1320 if (!NT_STATUS_IS_OK(status
)) {
1324 /* Open handle on domain */
1326 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1328 SEC_FLAG_MAXIMUM_ALLOWED
,
1331 if (!NT_STATUS_IS_OK(status
)) {
1335 /* Open handle on alias */
1337 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
1343 if (!NT_STATUS_IS_OK(status
)) {
1346 if (!NT_STATUS_IS_OK(result
)) {
1351 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
1356 if (!NT_STATUS_IS_OK(status
)) {
1359 if (!NT_STATUS_IS_OK(result
)) {
1366 printf("Name: %s\n", info
->all
.name
.string
);
1367 printf("Description: %s\n", info
->all
.description
.string
);
1368 printf("Num Members: %d\n", info
->all
.num_members
);
1371 printf("Name: %s\n", info
->name
.string
);
1373 case ALIASINFODESCRIPTION
:
1374 printf("Description: %s\n", info
->description
.string
);
1380 dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &result
);
1381 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1382 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1388 /* Query delete an alias membership */
1390 static NTSTATUS
cmd_samr_delete_alias(struct rpc_pipe_client
*cli
,
1391 TALLOC_CTX
*mem_ctx
,
1392 int argc
, const char **argv
)
1394 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1395 NTSTATUS status
, result
;
1397 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1398 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1401 printf("Usage: %s builtin|domain [rid|name]\n", argv
[0]);
1402 return NT_STATUS_OK
;
1405 alias_rid
= strtoul(argv
[2], NULL
, 10);
1407 /* Open SAMR handle */
1409 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1410 MAXIMUM_ALLOWED_ACCESS
,
1412 if (!NT_STATUS_IS_OK(status
)) {
1416 /* Open handle on domain */
1418 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1420 MAXIMUM_ALLOWED_ACCESS
,
1423 if (!NT_STATUS_IS_OK(status
)) {
1427 /* Open handle on alias */
1429 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
1435 if (!NT_STATUS_IS_OK(status
)) {
1438 if (!NT_STATUS_IS_OK(result
) && (alias_rid
== 0)) {
1439 /* Probably this was a user name, try lookupnames */
1440 struct samr_Ids rids
, types
;
1441 struct lsa_String lsa_acct_name
;
1443 init_lsa_String(&lsa_acct_name
, argv
[2]);
1445 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1452 if (!NT_STATUS_IS_OK(status
)) {
1455 if (NT_STATUS_IS_OK(result
)) {
1456 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
1462 if (!NT_STATUS_IS_OK(status
)) {
1468 status
= dcerpc_samr_DeleteDomAlias(b
, mem_ctx
,
1471 if (!NT_STATUS_IS_OK(status
)) {
1474 if (!NT_STATUS_IS_OK(result
)) {
1479 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1480 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1485 /* Query display info */
1487 static NTSTATUS
cmd_samr_query_dispinfo_internal(struct rpc_pipe_client
*cli
,
1488 TALLOC_CTX
*mem_ctx
,
1489 int argc
, const char **argv
,
1492 struct policy_handle connect_pol
, domain_pol
;
1493 NTSTATUS status
, result
;
1494 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
= 0, i
;
1495 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1496 uint32 info_level
= 1;
1497 union samr_DispInfo info
;
1499 bool got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1500 uint32_t total_size
, returned_size
;
1501 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1504 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1505 return NT_STATUS_OK
;
1509 sscanf(argv
[1], "%i", &info_level
);
1512 sscanf(argv
[2], "%i", &start_idx
);
1515 sscanf(argv
[3], "%i", &max_entries
);
1520 sscanf(argv
[4], "%i", &max_size
);
1525 sscanf(argv
[5], "%x", &access_mask
);
1527 /* Get sam policy handle */
1529 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1530 MAXIMUM_ALLOWED_ACCESS
,
1532 if (!NT_STATUS_IS_OK(status
)) {
1536 /* Get domain policy handle */
1538 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1544 if (!NT_STATUS_IS_OK(status
)) {
1547 if (!NT_STATUS_IS_OK(result
)) {
1552 /* Query display info */
1557 dcerpc_get_query_dispinfo_params(
1558 loop_count
, &max_entries
, &max_size
);
1561 case NDR_SAMR_QUERYDISPLAYINFO
:
1562 status
= dcerpc_samr_QueryDisplayInfo(b
, mem_ctx
,
1573 case NDR_SAMR_QUERYDISPLAYINFO2
:
1574 status
= dcerpc_samr_QueryDisplayInfo2(b
, mem_ctx
,
1586 case NDR_SAMR_QUERYDISPLAYINFO3
:
1587 status
= dcerpc_samr_QueryDisplayInfo3(b
, mem_ctx
,
1600 return NT_STATUS_INVALID_PARAMETER
;
1603 if (!NT_STATUS_IS_OK(status
)) {
1607 if (!NT_STATUS_IS_OK(result
) &&
1608 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
1609 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
1615 switch (info_level
) {
1617 num_entries
= info
.info1
.count
;
1620 num_entries
= info
.info2
.count
;
1623 num_entries
= info
.info3
.count
;
1626 num_entries
= info
.info4
.count
;
1629 num_entries
= info
.info5
.count
;
1635 start_idx
+= num_entries
;
1637 if (num_entries
== 0)
1640 for (i
= 0; i
< num_entries
; i
++) {
1641 switch (info_level
) {
1643 display_sam_info_1(&info
.info1
.entries
[i
]);
1646 display_sam_info_2(&info
.info2
.entries
[i
]);
1649 display_sam_info_3(&info
.info3
.entries
[i
]);
1652 display_sam_info_4(&info
.info4
.entries
[i
]);
1655 display_sam_info_5(&info
.info5
.entries
[i
]);
1659 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1661 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1662 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1667 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1668 TALLOC_CTX
*mem_ctx
,
1669 int argc
, const char **argv
)
1671 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1672 NDR_SAMR_QUERYDISPLAYINFO
);
1675 static NTSTATUS
cmd_samr_query_dispinfo2(struct rpc_pipe_client
*cli
,
1676 TALLOC_CTX
*mem_ctx
,
1677 int argc
, const char **argv
)
1679 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1680 NDR_SAMR_QUERYDISPLAYINFO2
);
1683 static NTSTATUS
cmd_samr_query_dispinfo3(struct rpc_pipe_client
*cli
,
1684 TALLOC_CTX
*mem_ctx
,
1685 int argc
, const char **argv
)
1687 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1688 NDR_SAMR_QUERYDISPLAYINFO3
);
1691 /* Query domain info */
1693 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1694 TALLOC_CTX
*mem_ctx
,
1695 int argc
, const char **argv
)
1697 struct policy_handle connect_pol
, domain_pol
;
1698 NTSTATUS status
, result
;
1699 uint32 switch_level
= 2;
1700 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1701 union samr_DomainInfo
*info
= NULL
;
1702 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1705 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1706 return NT_STATUS_OK
;
1710 sscanf(argv
[1], "%i", &switch_level
);
1713 sscanf(argv
[2], "%x", &access_mask
);
1715 /* Get sam policy handle */
1717 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1718 MAXIMUM_ALLOWED_ACCESS
,
1720 if (!NT_STATUS_IS_OK(status
)) {
1724 /* Get domain policy handle */
1726 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1732 if (!NT_STATUS_IS_OK(status
)) {
1735 if (!NT_STATUS_IS_OK(result
)) {
1740 /* Query domain info */
1742 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
1747 if (!NT_STATUS_IS_OK(status
)) {
1750 if (!NT_STATUS_IS_OK(result
)) {
1755 /* Display domain info */
1757 switch (switch_level
) {
1759 display_sam_dom_info_1(&info
->info1
);
1762 display_sam_dom_info_2(&info
->general
);
1765 display_sam_dom_info_3(&info
->info3
);
1768 display_sam_dom_info_4(&info
->oem
);
1771 display_sam_dom_info_5(&info
->info5
);
1774 display_sam_dom_info_6(&info
->info6
);
1777 display_sam_dom_info_7(&info
->info7
);
1780 display_sam_dom_info_8(&info
->info8
);
1783 display_sam_dom_info_9(&info
->info9
);
1786 display_sam_dom_info_12(&info
->info12
);
1789 display_sam_dom_info_13(&info
->info13
);
1793 printf("cannot display domain info for switch value %d\n",
1800 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1801 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1805 /* Create domain user */
1807 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1808 TALLOC_CTX
*mem_ctx
,
1809 int argc
, const char **argv
)
1811 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1812 NTSTATUS status
, result
;
1813 struct lsa_String acct_name
;
1815 uint32 acct_flags
, user_rid
;
1816 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1817 uint32_t access_granted
= 0;
1818 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1820 if ((argc
< 2) || (argc
> 3)) {
1821 printf("Usage: %s username [access mask]\n", argv
[0]);
1822 return NT_STATUS_OK
;
1825 init_lsa_String(&acct_name
, argv
[1]);
1828 sscanf(argv
[2], "%x", &access_mask
);
1830 /* Get sam policy handle */
1832 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1833 MAXIMUM_ALLOWED_ACCESS
,
1835 if (!NT_STATUS_IS_OK(status
)) {
1839 /* Get domain policy handle */
1841 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1847 if (!NT_STATUS_IS_OK(status
)) {
1850 if (!NT_STATUS_IS_OK(result
)) {
1855 /* Create domain user */
1857 acb_info
= ACB_NORMAL
;
1858 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1859 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1860 SAMR_USER_ACCESS_SET_PASSWORD
|
1861 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1862 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1864 status
= dcerpc_samr_CreateUser2(b
, mem_ctx
,
1873 if (!NT_STATUS_IS_OK(status
)) {
1876 if (!NT_STATUS_IS_OK(result
)) {
1881 status
= dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1882 if (!NT_STATUS_IS_OK(status
)) goto done
;
1884 status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1885 if (!NT_STATUS_IS_OK(status
)) goto done
;
1887 status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1888 if (!NT_STATUS_IS_OK(status
)) goto done
;
1894 /* Create domain group */
1896 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1897 TALLOC_CTX
*mem_ctx
,
1898 int argc
, const char **argv
)
1900 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1901 NTSTATUS status
, result
;
1902 struct lsa_String grp_name
;
1903 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1905 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1907 if ((argc
< 2) || (argc
> 3)) {
1908 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1909 return NT_STATUS_OK
;
1912 init_lsa_String(&grp_name
, argv
[1]);
1915 sscanf(argv
[2], "%x", &access_mask
);
1917 /* Get sam policy handle */
1919 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1920 MAXIMUM_ALLOWED_ACCESS
,
1922 if (!NT_STATUS_IS_OK(status
)) {
1926 /* Get domain policy handle */
1928 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1934 if (!NT_STATUS_IS_OK(status
)) {
1937 if (!NT_STATUS_IS_OK(result
)) {
1942 /* Create domain user */
1943 status
= dcerpc_samr_CreateDomainGroup(b
, mem_ctx
,
1946 MAXIMUM_ALLOWED_ACCESS
,
1950 if (!NT_STATUS_IS_OK(status
)) {
1953 if (!NT_STATUS_IS_OK(result
)) {
1958 status
= dcerpc_samr_Close(b
, mem_ctx
, &group_pol
, &result
);
1959 if (!NT_STATUS_IS_OK(status
)) goto done
;
1961 status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1962 if (!NT_STATUS_IS_OK(status
)) goto done
;
1964 status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1965 if (!NT_STATUS_IS_OK(status
)) goto done
;
1971 /* Create domain alias */
1973 static NTSTATUS
cmd_samr_create_dom_alias(struct rpc_pipe_client
*cli
,
1974 TALLOC_CTX
*mem_ctx
,
1975 int argc
, const char **argv
)
1977 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1978 NTSTATUS status
, result
;
1979 struct lsa_String alias_name
;
1980 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1982 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1984 if ((argc
< 2) || (argc
> 3)) {
1985 printf("Usage: %s aliasname [access mask]\n", argv
[0]);
1986 return NT_STATUS_OK
;
1989 init_lsa_String(&alias_name
, argv
[1]);
1992 sscanf(argv
[2], "%x", &access_mask
);
1994 /* Get sam policy handle */
1996 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
1997 MAXIMUM_ALLOWED_ACCESS
,
1999 if (!NT_STATUS_IS_OK(status
)) {
2003 /* Get domain policy handle */
2005 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2011 if (!NT_STATUS_IS_OK(status
)) {
2014 if (!NT_STATUS_IS_OK(result
)) {
2019 /* Create domain user */
2021 status
= dcerpc_samr_CreateDomAlias(b
, mem_ctx
,
2024 MAXIMUM_ALLOWED_ACCESS
,
2028 if (!NT_STATUS_IS_OK(status
)) {
2031 if (!NT_STATUS_IS_OK(result
)) {
2037 status
= dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &result
);
2038 if (!NT_STATUS_IS_OK(status
)) goto done
;
2040 status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2041 if (!NT_STATUS_IS_OK(status
)) goto done
;
2043 status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2044 if (!NT_STATUS_IS_OK(status
)) goto done
;
2050 /* Lookup sam names */
2052 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
2053 TALLOC_CTX
*mem_ctx
,
2054 int argc
, const char **argv
)
2056 NTSTATUS status
, result
;
2057 struct policy_handle connect_pol
, domain_pol
;
2059 struct samr_Ids rids
, name_types
;
2061 struct lsa_String
*names
= NULL
;
2062 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2065 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
2066 printf("check on the domain SID: S-1-5-21-x-y-z\n");
2067 printf("or check on the builtin SID: S-1-5-32\n");
2068 return NT_STATUS_OK
;
2071 /* Get sam policy and domain handles */
2073 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2074 MAXIMUM_ALLOWED_ACCESS
,
2076 if (!NT_STATUS_IS_OK(status
)) {
2080 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
2082 MAXIMUM_ALLOWED_ACCESS
,
2085 if (!NT_STATUS_IS_OK(status
)) {
2091 num_names
= argc
- 2;
2093 if ((names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
)) == NULL
) {
2094 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2095 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2096 status
= NT_STATUS_NO_MEMORY
;
2100 for (i
= 0; i
< num_names
; i
++) {
2101 init_lsa_String(&names
[i
], argv
[i
+ 2]);
2104 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2111 if (!NT_STATUS_IS_OK(status
)) {
2114 if (!NT_STATUS_IS_OK(result
)) {
2119 /* Display results */
2121 for (i
= 0; i
< num_names
; i
++)
2122 printf("name %s: 0x%x (%d)\n", names
[i
].string
, rids
.ids
[i
],
2125 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2126 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2131 /* Lookup sam rids */
2133 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
2134 TALLOC_CTX
*mem_ctx
,
2135 int argc
, const char **argv
)
2137 NTSTATUS status
, result
;
2138 struct policy_handle connect_pol
, domain_pol
;
2139 uint32_t num_rids
, *rids
;
2140 struct lsa_Strings names
;
2141 struct samr_Ids types
;
2142 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2147 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv
[0]);
2148 return NT_STATUS_OK
;
2151 /* Get sam policy and domain handles */
2153 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2154 MAXIMUM_ALLOWED_ACCESS
,
2156 if (!NT_STATUS_IS_OK(status
)) {
2160 status
= get_domain_handle(cli
, mem_ctx
, argv
[1],
2162 MAXIMUM_ALLOWED_ACCESS
,
2165 if (!NT_STATUS_IS_OK(status
)) {
2171 num_rids
= argc
- 2;
2173 if ((rids
= talloc_array(mem_ctx
, uint32
, num_rids
)) == NULL
) {
2174 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2175 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2176 status
= NT_STATUS_NO_MEMORY
;
2180 for (i
= 0; i
< argc
- 2; i
++)
2181 sscanf(argv
[i
+ 2], "%i", &rids
[i
]);
2183 status
= dcerpc_samr_LookupRids(b
, mem_ctx
,
2190 if (!NT_STATUS_IS_OK(status
)) {
2194 if (!NT_STATUS_IS_OK(result
) &&
2195 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
2198 /* Display results */
2200 for (i
= 0; i
< num_rids
; i
++) {
2201 printf("rid 0x%x: %s (%d)\n",
2202 rids
[i
], names
.names
[i
].string
, types
.ids
[i
]);
2205 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2206 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2211 /* Delete domain group */
2213 static NTSTATUS
cmd_samr_delete_dom_group(struct rpc_pipe_client
*cli
,
2214 TALLOC_CTX
*mem_ctx
,
2215 int argc
, const char **argv
)
2217 NTSTATUS status
, result
;
2218 struct policy_handle connect_pol
, domain_pol
, group_pol
;
2219 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2220 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2222 if ((argc
< 2) || (argc
> 3)) {
2223 printf("Usage: %s groupname\n", argv
[0]);
2224 return NT_STATUS_OK
;
2228 sscanf(argv
[2], "%x", &access_mask
);
2230 /* Get sam policy and domain handles */
2232 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2233 MAXIMUM_ALLOWED_ACCESS
,
2235 if (!NT_STATUS_IS_OK(status
)) {
2239 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2241 MAXIMUM_ALLOWED_ACCESS
,
2245 if (!NT_STATUS_IS_OK(status
)) {
2248 if (!NT_STATUS_IS_OK(result
)) {
2253 /* Get handle on group */
2256 struct samr_Ids group_rids
, name_types
;
2257 struct lsa_String lsa_acct_name
;
2259 init_lsa_String(&lsa_acct_name
, argv
[1]);
2261 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2268 if (!NT_STATUS_IS_OK(status
)) {
2271 if (!NT_STATUS_IS_OK(result
)) {
2276 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2282 if (!NT_STATUS_IS_OK(status
)) {
2285 if (!NT_STATUS_IS_OK(result
)) {
2293 status
= dcerpc_samr_DeleteDomainGroup(b
, mem_ctx
,
2296 if (!NT_STATUS_IS_OK(status
)) {
2299 if (!NT_STATUS_IS_OK(result
)) {
2304 /* Display results */
2306 dcerpc_samr_Close(b
, mem_ctx
, &group_pol
, &result
);
2307 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2308 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2314 /* Delete domain user */
2316 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
2317 TALLOC_CTX
*mem_ctx
,
2318 int argc
, const char **argv
)
2320 NTSTATUS status
, result
;
2321 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2322 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2323 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2325 if ((argc
< 2) || (argc
> 3)) {
2326 printf("Usage: %s username\n", argv
[0]);
2327 return NT_STATUS_OK
;
2331 sscanf(argv
[2], "%x", &access_mask
);
2333 /* Get sam policy and domain handles */
2335 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2336 MAXIMUM_ALLOWED_ACCESS
,
2338 if (!NT_STATUS_IS_OK(status
)) {
2342 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2344 MAXIMUM_ALLOWED_ACCESS
,
2348 if (!NT_STATUS_IS_OK(status
)) {
2351 if (!NT_STATUS_IS_OK(result
)) {
2356 /* Get handle on user */
2359 struct samr_Ids user_rids
, name_types
;
2360 struct lsa_String lsa_acct_name
;
2362 init_lsa_String(&lsa_acct_name
, argv
[1]);
2364 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2371 if (!NT_STATUS_IS_OK(status
)) {
2374 if (!NT_STATUS_IS_OK(result
)) {
2379 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
2385 if (!NT_STATUS_IS_OK(status
)) {
2388 if (!NT_STATUS_IS_OK(result
)) {
2396 status
= dcerpc_samr_DeleteUser(b
, mem_ctx
,
2399 if (!NT_STATUS_IS_OK(status
)) {
2402 if (!NT_STATUS_IS_OK(result
)) {
2407 /* Display results */
2409 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
2410 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2411 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2417 /**********************************************************************
2418 * Query user security object
2420 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
2421 TALLOC_CTX
*mem_ctx
,
2422 int argc
, const char **argv
)
2424 struct policy_handle connect_pol
, domain_pol
, user_pol
, *pol
;
2425 NTSTATUS status
, result
;
2426 uint32 sec_info
= SECINFO_DACL
;
2427 uint32 user_rid
= 0;
2428 TALLOC_CTX
*ctx
= NULL
;
2429 struct sec_desc_buf
*sec_desc_buf
=NULL
;
2430 bool domain
= False
;
2431 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2433 ctx
=talloc_init("cmd_samr_query_sec_obj");
2435 if ((argc
< 1) || (argc
> 3)) {
2436 printf("Usage: %s [rid|-d] [sec_info]\n", argv
[0]);
2437 printf("\tSpecify rid for security on user, -d for security on domain\n");
2438 talloc_destroy(ctx
);
2439 return NT_STATUS_OK
;
2443 if (strcmp(argv
[1], "-d") == 0)
2446 sscanf(argv
[1], "%i", &user_rid
);
2450 sec_info
= atoi(argv
[2]);
2453 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2454 MAXIMUM_ALLOWED_ACCESS
,
2456 if (!NT_STATUS_IS_OK(status
)) {
2460 if (domain
|| user_rid
) {
2461 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2463 MAXIMUM_ALLOWED_ACCESS
,
2467 if (!NT_STATUS_IS_OK(status
)) {
2470 if (!NT_STATUS_IS_OK(result
)) {
2477 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
2479 MAXIMUM_ALLOWED_ACCESS
,
2483 if (!NT_STATUS_IS_OK(status
)) {
2486 if (!NT_STATUS_IS_OK(result
)) {
2492 /* Pick which query pol to use */
2502 /* Query SAM security object */
2504 status
= dcerpc_samr_QuerySecurity(b
, mem_ctx
,
2509 if (!NT_STATUS_IS_OK(status
)) {
2512 if (!NT_STATUS_IS_OK(result
)) {
2517 display_sec_desc(sec_desc_buf
->sd
);
2519 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
2520 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2521 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2523 talloc_destroy(ctx
);
2527 static NTSTATUS
cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client
*cli
,
2528 TALLOC_CTX
*mem_ctx
,
2529 int argc
, const char **argv
)
2531 NTSTATUS status
, result
;
2532 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2533 struct samr_PwInfo info
;
2535 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2538 printf("Usage: %s rid\n", argv
[0]);
2539 return NT_STATUS_OK
;
2542 sscanf(argv
[1], "%i", &rid
);
2544 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2545 MAXIMUM_ALLOWED_ACCESS
,
2547 if (!NT_STATUS_IS_OK(status
)) {
2551 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2553 MAXIMUM_ALLOWED_ACCESS
,
2557 if (!NT_STATUS_IS_OK(status
)) {
2560 if (!NT_STATUS_IS_OK(result
)) {
2565 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
2567 MAXIMUM_ALLOWED_ACCESS
,
2571 if (!NT_STATUS_IS_OK(status
)) {
2574 if (!NT_STATUS_IS_OK(result
)) {
2579 status
= dcerpc_samr_GetUserPwInfo(b
, mem_ctx
,
2583 if (!NT_STATUS_IS_OK(status
)) {
2587 if (NT_STATUS_IS_OK(result
)) {
2588 printf("min_password_length: %d\n", info
.min_password_length
);
2590 NDR_PRINT_STRUCT_STRING(mem_ctx
,
2591 samr_PasswordProperties
, &info
.password_properties
));
2595 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
2596 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2597 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2602 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
2603 TALLOC_CTX
*mem_ctx
,
2604 int argc
, const char **argv
)
2606 NTSTATUS status
, result
;
2607 struct lsa_String domain_name
;
2608 struct samr_PwInfo info
;
2609 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2611 if (argc
< 1 || argc
> 3) {
2612 printf("Usage: %s <domain>\n", argv
[0]);
2613 return NT_STATUS_OK
;
2616 init_lsa_String(&domain_name
, argv
[1]);
2618 status
= dcerpc_samr_GetDomPwInfo(b
, mem_ctx
,
2622 if (!NT_STATUS_IS_OK(status
)) {
2625 if (NT_STATUS_IS_OK(result
)) {
2626 printf("min_password_length: %d\n", info
.min_password_length
);
2627 display_password_properties(info
.password_properties
);
2633 /* Look up domain name */
2635 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
2636 TALLOC_CTX
*mem_ctx
,
2637 int argc
, const char **argv
)
2639 struct policy_handle connect_pol
, domain_pol
;
2640 NTSTATUS status
, result
;
2641 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2643 struct lsa_String domain_name
;
2644 struct dom_sid
*sid
= NULL
;
2645 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2648 printf("Usage: %s domain_name\n", argv
[0]);
2649 return NT_STATUS_OK
;
2652 init_lsa_String(&domain_name
, argv
[1]);
2654 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2657 if (!NT_STATUS_IS_OK(status
)) {
2661 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2667 if (!NT_STATUS_IS_OK(status
)) {
2670 if (!NT_STATUS_IS_OK(result
)) {
2675 status
= dcerpc_samr_LookupDomain(b
, mem_ctx
,
2680 if (!NT_STATUS_IS_OK(status
)) {
2683 if (!NT_STATUS_IS_OK(result
)) {
2688 if (NT_STATUS_IS_OK(result
)) {
2689 sid_to_fstring(sid_string
, sid
);
2690 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2691 argv
[1], sid_string
);
2694 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2695 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2700 /* Change user password */
2702 static NTSTATUS
cmd_samr_chgpasswd(struct rpc_pipe_client
*cli
,
2703 TALLOC_CTX
*mem_ctx
,
2704 int argc
, const char **argv
)
2706 struct policy_handle connect_pol
;
2707 struct policy_handle domain_pol
= { 0, };
2708 struct policy_handle user_pol
= { 0, };
2709 NTSTATUS status
, result
;
2710 const char *user
, *oldpass
, *newpass
;
2711 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2712 struct samr_Ids rids
, types
;
2713 struct lsa_String lsa_acct_name
;
2714 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2717 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2718 return NT_STATUS_INVALID_PARAMETER
;
2725 /* Get sam policy handle */
2727 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2728 MAXIMUM_ALLOWED_ACCESS
,
2730 if (!NT_STATUS_IS_OK(status
)) {
2734 /* Get domain policy handle */
2736 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2742 if (!NT_STATUS_IS_OK(status
)) {
2745 if (!NT_STATUS_IS_OK(result
)) {
2750 init_lsa_String(&lsa_acct_name
, user
);
2752 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2759 if (!NT_STATUS_IS_OK(status
)) {
2762 if (!NT_STATUS_IS_OK(result
)) {
2767 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
2773 if (!NT_STATUS_IS_OK(status
)) {
2776 if (!NT_STATUS_IS_OK(result
)) {
2781 /* Change user password */
2782 status
= rpccli_samr_chgpasswd_user(cli
, mem_ctx
,
2786 if (!NT_STATUS_IS_OK(status
)) {
2791 if (is_valid_policy_hnd(&user_pol
)) {
2792 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
2794 if (is_valid_policy_hnd(&domain_pol
)) {
2795 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2797 if (is_valid_policy_hnd(&connect_pol
)) {
2798 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2805 /* Change user password */
2807 static NTSTATUS
cmd_samr_chgpasswd2(struct rpc_pipe_client
*cli
,
2808 TALLOC_CTX
*mem_ctx
,
2809 int argc
, const char **argv
)
2811 struct policy_handle connect_pol
, domain_pol
;
2812 NTSTATUS status
, result
;
2813 const char *user
, *oldpass
, *newpass
;
2814 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2815 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2818 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2819 return NT_STATUS_INVALID_PARAMETER
;
2826 /* Get sam policy handle */
2828 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2829 MAXIMUM_ALLOWED_ACCESS
,
2831 if (!NT_STATUS_IS_OK(status
)) {
2835 /* Get domain policy handle */
2837 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2843 if (!NT_STATUS_IS_OK(status
)) {
2846 if (!NT_STATUS_IS_OK(result
)) {
2851 /* Change user password */
2852 status
= rpccli_samr_chgpasswd_user2(cli
, mem_ctx
, user
, newpass
, oldpass
);
2854 if (!NT_STATUS_IS_OK(status
)) {
2858 status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2859 if (!NT_STATUS_IS_OK(status
)) goto done
;
2861 status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2862 if (!NT_STATUS_IS_OK(status
)) goto done
;
2869 /* Change user password */
2871 static NTSTATUS
cmd_samr_chgpasswd3(struct rpc_pipe_client
*cli
,
2872 TALLOC_CTX
*mem_ctx
,
2873 int argc
, const char **argv
)
2875 struct policy_handle connect_pol
, domain_pol
;
2876 NTSTATUS status
, result
;
2877 const char *user
, *oldpass
, *newpass
;
2878 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2879 struct samr_DomInfo1
*info
= NULL
;
2880 struct userPwdChangeFailureInformation
*reject
= NULL
;
2881 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2884 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2885 return NT_STATUS_INVALID_PARAMETER
;
2892 /* Get sam policy handle */
2894 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2895 MAXIMUM_ALLOWED_ACCESS
,
2897 if (!NT_STATUS_IS_OK(status
)) {
2901 /* Get domain policy handle */
2903 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2909 if (!NT_STATUS_IS_OK(status
)) {
2912 if (!NT_STATUS_IS_OK(result
)) {
2917 /* Change user password */
2918 status
= rpccli_samr_chgpasswd_user3(cli
, mem_ctx
,
2924 if (!NT_STATUS_IS_OK(status
)) {
2928 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
)) {
2930 display_sam_dom_info_1(info
);
2932 switch (reject
->extendedFailureReason
) {
2933 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT
:
2934 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2936 case SAM_PWD_CHANGE_PWD_IN_HISTORY
:
2937 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2939 case SAM_PWD_CHANGE_NOT_COMPLEX
:
2940 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2943 d_printf("unknown reject reason: %d\n",
2944 reject
->extendedFailureReason
);
2949 if (!NT_STATUS_IS_OK(result
)) {
2954 status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2955 if (!NT_STATUS_IS_OK(status
)) goto done
;
2957 status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2958 if (!NT_STATUS_IS_OK(status
)) goto done
;
2964 static NTSTATUS
cmd_samr_setuserinfo_int(struct rpc_pipe_client
*cli
,
2965 TALLOC_CTX
*mem_ctx
,
2966 int argc
, const char **argv
,
2969 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2970 NTSTATUS status
, result
;
2971 const char *user
, *param
;
2972 uint32_t access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2975 union samr_UserInfo info
;
2976 struct samr_CryptPassword pwd_buf
;
2977 struct samr_CryptPasswordEx pwd_buf_ex
;
2978 uint8_t nt_hash
[16];
2979 uint8_t lm_hash
[16];
2980 DATA_BLOB session_key
;
2981 uint8_t password_expired
= 0;
2982 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2985 printf("Usage: %s username level password [password_expired]\n",
2987 return NT_STATUS_INVALID_PARAMETER
;
2991 level
= atoi(argv
[2]);
2995 password_expired
= atoi(argv
[4]);
2998 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2999 if (!NT_STATUS_IS_OK(status
)) {
3003 init_samr_CryptPassword(param
, &session_key
, &pwd_buf
);
3004 init_samr_CryptPasswordEx(param
, &session_key
, &pwd_buf_ex
);
3005 nt_lm_owf_gen(param
, nt_hash
, lm_hash
);
3011 in
= data_blob_const(nt_hash
, 16);
3012 out
= data_blob_talloc_zero(mem_ctx
, 16);
3013 sess_crypt_blob(&out
, &in
, &session_key
, true);
3014 memcpy(nt_hash
, out
.data
, out
.length
);
3018 in
= data_blob_const(lm_hash
, 16);
3019 out
= data_blob_talloc_zero(mem_ctx
, 16);
3020 sess_crypt_blob(&out
, &in
, &session_key
, true);
3021 memcpy(lm_hash
, out
.data
, out
.length
);
3024 memcpy(info
.info18
.nt_pwd
.hash
, nt_hash
, 16);
3025 memcpy(info
.info18
.lm_pwd
.hash
, lm_hash
, 16);
3026 info
.info18
.nt_pwd_active
= true;
3027 info
.info18
.lm_pwd_active
= true;
3028 info
.info18
.password_expired
= password_expired
;
3032 ZERO_STRUCT(info
.info21
);
3034 info
.info21
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
3035 SAMR_FIELD_LM_PASSWORD_PRESENT
;
3037 info
.info21
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
3038 info
.info21
.password_expired
= password_expired
;
3041 info
.info21
.lm_password_set
= true;
3042 info
.info21
.lm_owf_password
.length
= 16;
3043 info
.info21
.lm_owf_password
.size
= 16;
3045 info
.info21
.nt_password_set
= true;
3046 info
.info21
.nt_owf_password
.length
= 16;
3047 info
.info21
.nt_owf_password
.size
= 16;
3051 in
= data_blob_const(nt_hash
, 16);
3052 out
= data_blob_talloc_zero(mem_ctx
, 16);
3053 sess_crypt_blob(&out
, &in
, &session_key
, true);
3054 info
.info21
.nt_owf_password
.array
=
3055 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
3059 in
= data_blob_const(lm_hash
, 16);
3060 out
= data_blob_talloc_zero(mem_ctx
, 16);
3061 sess_crypt_blob(&out
, &in
, &session_key
, true);
3062 info
.info21
.lm_owf_password
.array
=
3063 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
3068 ZERO_STRUCT(info
.info23
);
3070 info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
3071 SAMR_FIELD_LM_PASSWORD_PRESENT
;
3073 info
.info23
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
3074 info
.info23
.info
.password_expired
= password_expired
;
3077 info
.info23
.password
= pwd_buf
;
3081 info
.info24
.password
= pwd_buf
;
3082 info
.info24
.password_expired
= password_expired
;
3086 ZERO_STRUCT(info
.info25
);
3088 info
.info25
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
3089 SAMR_FIELD_LM_PASSWORD_PRESENT
;
3091 info
.info25
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
3092 info
.info25
.info
.password_expired
= password_expired
;
3095 info
.info25
.password
= pwd_buf_ex
;
3099 info
.info26
.password
= pwd_buf_ex
;
3100 info
.info26
.password_expired
= password_expired
;
3104 return NT_STATUS_INVALID_INFO_CLASS
;
3107 /* Get sam policy handle */
3109 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
3110 MAXIMUM_ALLOWED_ACCESS
,
3112 if (!NT_STATUS_IS_OK(status
)) {
3116 /* Get domain policy handle */
3118 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3125 if (!NT_STATUS_IS_OK(status
))
3127 if (!NT_STATUS_IS_OK(result
)) {
3132 user_rid
= strtol(user
, NULL
, 0);
3134 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
3140 if (!NT_STATUS_IS_OK(status
)) {
3147 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
) ||
3150 /* Probably this was a user name, try lookupnames */
3151 struct samr_Ids rids
, types
;
3152 struct lsa_String lsa_acct_name
;
3154 init_lsa_String(&lsa_acct_name
, user
);
3156 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3163 if (!NT_STATUS_IS_OK(status
)) {
3166 if (!NT_STATUS_IS_OK(result
)) {
3171 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
3177 if (!NT_STATUS_IS_OK(status
)) {
3180 if (!NT_STATUS_IS_OK(result
)) {
3186 case NDR_SAMR_SETUSERINFO
:
3187 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
3193 case NDR_SAMR_SETUSERINFO2
:
3194 status
= dcerpc_samr_SetUserInfo2(b
, mem_ctx
,
3201 return NT_STATUS_INVALID_PARAMETER
;
3203 if (!NT_STATUS_IS_OK(status
)) {
3204 DEBUG(0,("status: %s\n", nt_errstr(status
)));
3207 if (!NT_STATUS_IS_OK(result
)) {
3209 DEBUG(0,("result: %s\n", nt_errstr(status
)));
3216 static NTSTATUS
cmd_samr_setuserinfo(struct rpc_pipe_client
*cli
,
3217 TALLOC_CTX
*mem_ctx
,
3218 int argc
, const char **argv
)
3220 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
3221 NDR_SAMR_SETUSERINFO
);
3224 static NTSTATUS
cmd_samr_setuserinfo2(struct rpc_pipe_client
*cli
,
3225 TALLOC_CTX
*mem_ctx
,
3226 int argc
, const char **argv
)
3228 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
3229 NDR_SAMR_SETUSERINFO2
);
3232 static NTSTATUS
cmd_samr_get_dispinfo_idx(struct rpc_pipe_client
*cli
,
3233 TALLOC_CTX
*mem_ctx
,
3234 int argc
, const char **argv
)
3236 NTSTATUS status
, result
;
3237 struct policy_handle connect_handle
;
3238 struct policy_handle domain_handle
= { 0, };
3240 struct lsa_String name
;
3242 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
3244 if (argc
< 2 || argc
> 3) {
3245 printf("Usage: %s name level\n", argv
[0]);
3246 return NT_STATUS_INVALID_PARAMETER
;
3249 init_lsa_String(&name
, argv
[1]);
3252 level
= atoi(argv
[2]);
3255 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
3256 SEC_FLAG_MAXIMUM_ALLOWED
,
3258 if (!NT_STATUS_IS_OK(status
)) {
3262 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3264 SEC_FLAG_MAXIMUM_ALLOWED
,
3268 if (!NT_STATUS_IS_OK(status
)) {
3271 if (!NT_STATUS_IS_OK(result
)) {
3276 status
= dcerpc_samr_GetDisplayEnumerationIndex(b
, mem_ctx
,
3282 if (!NT_STATUS_IS_OK(status
)) {
3288 if (NT_STATUS_IS_OK(status
) ||
3289 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
3290 printf("idx: %d (0x%08x)\n", idx
, idx
);
3294 if (is_valid_policy_hnd(&domain_handle
)) {
3295 dcerpc_samr_Close(b
, mem_ctx
, &domain_handle
, &result
);
3297 if (is_valid_policy_hnd(&connect_handle
)) {
3298 dcerpc_samr_Close(b
, mem_ctx
, &connect_handle
, &result
);
3304 /* List of commands exported by this module */
3306 struct cmd_set samr_commands
[] = {
3310 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, &ndr_table_samr
, NULL
, "Query user info", "" },
3311 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, &ndr_table_samr
, NULL
, "Query group info", "" },
3312 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, &ndr_table_samr
, NULL
, "Query user groups", "" },
3313 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, &ndr_table_samr
, NULL
, "Query user aliases", "" },
3314 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, &ndr_table_samr
, NULL
, "Query group membership", "" },
3315 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, &ndr_table_samr
, NULL
, "Query alias membership", "" },
3316 { "queryaliasinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasinfo
, NULL
, &ndr_table_samr
, NULL
, "Query alias info", "" },
3317 { "deletealias", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_alias
, NULL
, &ndr_table_samr
, NULL
, "Delete an alias", "" },
3318 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, &ndr_table_samr
, NULL
, "Query display info", "" },
3319 { "querydispinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo2
, NULL
, &ndr_table_samr
, NULL
, "Query display info", "" },
3320 { "querydispinfo3", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo3
, NULL
, &ndr_table_samr
, NULL
, "Query display info", "" },
3321 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, &ndr_table_samr
, NULL
, "Query domain info", "" },
3322 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, &ndr_table_samr
, NULL
, "Enumerate domain users", "" },
3323 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, &ndr_table_samr
, NULL
, "Enumerate domain groups", "" },
3324 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, &ndr_table_samr
, NULL
, "Enumerate alias groups", "" },
3325 { "enumdomains", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_domains
, NULL
, &ndr_table_samr
, NULL
, "Enumerate domains", "" },
3327 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, &ndr_table_samr
, NULL
, "Create domain user", "" },
3328 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, &ndr_table_samr
, NULL
, "Create domain group", "" },
3329 { "createdomalias", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_alias
, NULL
, &ndr_table_samr
, NULL
, "Create domain alias", "" },
3330 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, &ndr_table_samr
, NULL
, "Look up names", "" },
3331 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, &ndr_table_samr
, NULL
, "Look up names", "" },
3332 { "deletedomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_group
, NULL
, &ndr_table_samr
, NULL
, "Delete domain group", "" },
3333 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, &ndr_table_samr
, NULL
, "Delete domain user", "" },
3334 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, &ndr_table_samr
, NULL
, "Query SAMR security object", "" },
3335 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, &ndr_table_samr
, NULL
, "Retrieve domain password info", "" },
3336 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_usrdom_pwinfo
, NULL
, &ndr_table_samr
, NULL
, "Retrieve user domain password info", "" },
3338 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, &ndr_table_samr
, NULL
, "Lookup Domain Name", "" },
3339 { "chgpasswd", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd
, NULL
, &ndr_table_samr
, NULL
, "Change user password", "" },
3340 { "chgpasswd2", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd2
, NULL
, &ndr_table_samr
, NULL
, "Change user password", "" },
3341 { "chgpasswd3", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd3
, NULL
, &ndr_table_samr
, NULL
, "Change user password", "" },
3342 { "getdispinfoidx", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dispinfo_idx
, NULL
, &ndr_table_samr
, NULL
, "Get Display Information Index", "" },
3343 { "setuserinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo
, NULL
, &ndr_table_samr
, NULL
, "Set user info", "" },
3344 { "setuserinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo2
, NULL
, &ndr_table_samr
, NULL
, "Set user info2", "" },