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/cli_samr.h"
30 extern DOM_SID domain_sid
;
32 /****************************************************************************
33 display samr_user_info_7 structure
34 ****************************************************************************/
35 static void display_samr_user_info_7(struct samr_UserInfo7
*r
)
37 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
40 /****************************************************************************
41 display samr_user_info_9 structure
42 ****************************************************************************/
43 static void display_samr_user_info_9(struct samr_UserInfo9
*r
)
45 printf("\tPrimary group RID :\tox%x\n", r
->primary_gid
);
48 /****************************************************************************
49 display samr_user_info_16 structure
50 ****************************************************************************/
51 static void display_samr_user_info_16(struct samr_UserInfo16
*r
)
53 printf("\tAcct Flags :\tox%x\n", r
->acct_flags
);
56 /****************************************************************************
57 display samr_user_info_20 structure
58 ****************************************************************************/
59 static void display_samr_user_info_20(struct samr_UserInfo20
*r
)
61 printf("\tRemote Dial :\n");
62 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
66 /****************************************************************************
67 display samr_user_info_21 structure
68 ****************************************************************************/
69 static void display_samr_user_info_21(struct samr_UserInfo21
*r
)
71 printf("\tUser Name :\t%s\n", r
->account_name
.string
);
72 printf("\tFull Name :\t%s\n", r
->full_name
.string
);
73 printf("\tHome Drive :\t%s\n", r
->home_directory
.string
);
74 printf("\tDir Drive :\t%s\n", r
->home_drive
.string
);
75 printf("\tProfile Path:\t%s\n", r
->profile_path
.string
);
76 printf("\tLogon Script:\t%s\n", r
->logon_script
.string
);
77 printf("\tDescription :\t%s\n", r
->description
.string
);
78 printf("\tWorkstations:\t%s\n", r
->workstations
.string
);
79 printf("\tComment :\t%s\n", r
->comment
.string
);
80 printf("\tRemote Dial :\n");
81 dump_data(0, (uint8_t *)r
->parameters
.array
, r
->parameters
.length
*2);
83 printf("\tLogon Time :\t%s\n",
84 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logon
)));
85 printf("\tLogoff Time :\t%s\n",
86 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_logoff
)));
87 printf("\tKickoff Time :\t%s\n",
88 http_timestring(talloc_tos(), nt_time_to_unix(r
->acct_expiry
)));
89 printf("\tPassword last set Time :\t%s\n",
90 http_timestring(talloc_tos(), nt_time_to_unix(r
->last_password_change
)));
91 printf("\tPassword can change Time :\t%s\n",
92 http_timestring(talloc_tos(), nt_time_to_unix(r
->allow_password_change
)));
93 printf("\tPassword must change Time:\t%s\n",
94 http_timestring(talloc_tos(), nt_time_to_unix(r
->force_password_change
)));
96 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
98 printf("\tuser_rid :\t0x%x\n" , r
->rid
); /* User ID */
99 printf("\tgroup_rid:\t0x%x\n" , r
->primary_gid
); /* Group ID */
100 printf("\tacb_info :\t0x%08x\n", r
->acct_flags
); /* Account Control Info */
102 printf("\tfields_present:\t0x%08x\n", r
->fields_present
); /* 0x00ff ffff */
103 printf("\tlogon_divs:\t%d\n", r
->logon_hours
.units_per_week
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
104 printf("\tbad_password_count:\t0x%08x\n", r
->bad_password_count
);
105 printf("\tlogon_count:\t0x%08x\n", r
->logon_count
);
107 printf("\tpadding1[0..7]...\n");
109 if (r
->logon_hours
.bits
) {
110 printf("\tlogon_hrs[0..%d]...\n", r
->logon_hours
.units_per_week
/8);
115 static void display_password_properties(uint32_t password_properties
)
117 printf("password_properties: 0x%08x\n", password_properties
);
119 if (password_properties
& DOMAIN_PASSWORD_COMPLEX
)
120 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
122 if (password_properties
& DOMAIN_PASSWORD_NO_ANON_CHANGE
)
123 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
125 if (password_properties
& DOMAIN_PASSWORD_NO_CLEAR_CHANGE
)
126 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
128 if (password_properties
& DOMAIN_PASSWORD_LOCKOUT_ADMINS
)
129 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
131 if (password_properties
& DOMAIN_PASSWORD_STORE_CLEARTEXT
)
132 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
134 if (password_properties
& DOMAIN_REFUSE_PASSWORD_CHANGE
)
135 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
138 static void display_sam_dom_info_1(struct samr_DomInfo1
*info1
)
140 printf("Minimum password length:\t\t\t%d\n",
141 info1
->min_password_length
);
142 printf("Password uniqueness (remember x passwords):\t%d\n",
143 info1
->password_history_length
);
144 display_password_properties(info1
->password_properties
);
145 printf("password expire in:\t\t\t\t%s\n",
146 display_time(info1
->max_password_age
));
147 printf("Min password age (allow changing in x days):\t%s\n",
148 display_time(info1
->min_password_age
));
151 static void display_sam_dom_info_2(struct samr_DomGeneralInformation
*general
)
153 printf("Domain:\t\t%s\n", general
->domain_name
.string
);
154 printf("Server:\t\t%s\n", general
->primary
.string
);
155 printf("Comment:\t%s\n", general
->oem_information
.string
);
157 printf("Total Users:\t%d\n", general
->num_users
);
158 printf("Total Groups:\t%d\n", general
->num_groups
);
159 printf("Total Aliases:\t%d\n", general
->num_aliases
);
161 printf("Sequence No:\t%llu\n", (unsigned long long)general
->sequence_num
);
163 printf("Force Logoff:\t%d\n",
164 (int)nt_time_to_unix_abs(&general
->force_logoff_time
));
166 printf("Domain Server State:\t0x%x\n", general
->domain_server_state
);
167 printf("Server Role:\t%s\n", server_role_str(general
->role
));
168 printf("Unknown 3:\t0x%x\n", general
->unknown3
);
171 static void display_sam_dom_info_3(struct samr_DomInfo3
*info3
)
173 printf("Force Logoff:\t%d\n",
174 (int)nt_time_to_unix_abs(&info3
->force_logoff_time
));
177 static void display_sam_dom_info_4(struct samr_DomOEMInformation
*oem
)
179 printf("Comment:\t%s\n", oem
->oem_information
.string
);
182 static void display_sam_dom_info_5(struct samr_DomInfo5
*info5
)
184 printf("Domain:\t\t%s\n", info5
->domain_name
.string
);
187 static void display_sam_dom_info_6(struct samr_DomInfo6
*info6
)
189 printf("Server:\t\t%s\n", info6
->primary
.string
);
192 static void display_sam_dom_info_7(struct samr_DomInfo7
*info7
)
194 printf("Server Role:\t%s\n", server_role_str(info7
->role
));
197 static void display_sam_dom_info_8(struct samr_DomInfo8
*info8
)
199 printf("Sequence No:\t%llu\n", (unsigned long long)info8
->sequence_num
);
200 printf("Domain Create Time:\t%s\n",
201 http_timestring(talloc_tos(), nt_time_to_unix(info8
->domain_create_time
)));
204 static void display_sam_dom_info_9(struct samr_DomInfo9
*info9
)
206 printf("Domain Server State:\t0x%x\n", info9
->domain_server_state
);
209 static void display_sam_dom_info_12(struct samr_DomInfo12
*info12
)
211 printf("Bad password lockout duration: %s\n",
212 display_time(info12
->lockout_duration
));
213 printf("Reset Lockout after: %s\n",
214 display_time(info12
->lockout_window
));
215 printf("Lockout after bad attempts: %d\n",
216 info12
->lockout_threshold
);
219 static void display_sam_dom_info_13(struct samr_DomInfo13
*info13
)
221 printf("Sequence No:\t%llu\n", (unsigned long long)info13
->sequence_num
);
222 printf("Domain Create Time:\t%s\n",
223 http_timestring(talloc_tos(), nt_time_to_unix(info13
->domain_create_time
)));
224 printf("Sequence No at last promotion:\t%llu\n",
225 (unsigned long long)info13
->modified_count_at_last_promotion
);
228 static void display_sam_info_1(struct samr_DispEntryGeneral
*r
)
230 printf("index: 0x%x ", r
->idx
);
231 printf("RID: 0x%x ", r
->rid
);
232 printf("acb: 0x%08x ", r
->acct_flags
);
233 printf("Account: %s\t", r
->account_name
.string
);
234 printf("Name: %s\t", r
->full_name
.string
);
235 printf("Desc: %s\n", r
->description
.string
);
238 static void display_sam_info_2(struct samr_DispEntryFull
*r
)
240 printf("index: 0x%x ", r
->idx
);
241 printf("RID: 0x%x ", r
->rid
);
242 printf("acb: 0x%08x ", r
->acct_flags
);
243 printf("Account: %s\t", r
->account_name
.string
);
244 printf("Desc: %s\n", r
->description
.string
);
247 static void display_sam_info_3(struct samr_DispEntryFullGroup
*r
)
249 printf("index: 0x%x ", r
->idx
);
250 printf("RID: 0x%x ", r
->rid
);
251 printf("acb: 0x%08x ", r
->acct_flags
);
252 printf("Account: %s\t", r
->account_name
.string
);
253 printf("Desc: %s\n", r
->description
.string
);
256 static void display_sam_info_4(struct samr_DispEntryAscii
*r
)
258 printf("index: 0x%x ", r
->idx
);
259 printf("Account: %s\n", r
->account_name
.string
);
262 static void display_sam_info_5(struct samr_DispEntryAscii
*r
)
264 printf("index: 0x%x ", r
->idx
);
265 printf("Account: %s\n", r
->account_name
.string
);
268 /****************************************************************************
269 ****************************************************************************/
271 static NTSTATUS
get_domain_handle(struct rpc_pipe_client
*cli
,
274 struct policy_handle
*connect_pol
,
275 uint32_t access_mask
,
276 struct dom_sid
*_domain_sid
,
277 struct policy_handle
*domain_pol
)
280 if (StrCaseCmp(sam
, "domain") == 0) {
281 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
286 } else if (StrCaseCmp(sam
, "builtin") == 0) {
287 return rpccli_samr_OpenDomain(cli
, mem_ctx
,
290 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
294 return NT_STATUS_INVALID_PARAMETER
;
297 /**********************************************************************
298 * Query user information
300 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
302 int argc
, const char **argv
)
304 struct policy_handle connect_pol
, domain_pol
, user_pol
;
305 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
306 uint32 info_level
= 21;
307 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
308 union samr_UserInfo
*info
= NULL
;
311 if ((argc
< 2) || (argc
> 4)) {
312 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
316 sscanf(argv
[1], "%i", &user_rid
);
319 sscanf(argv
[2], "%i", &info_level
);
322 sscanf(argv
[3], "%x", &access_mask
);
325 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
326 MAXIMUM_ALLOWED_ACCESS
,
329 if (!NT_STATUS_IS_OK(result
))
332 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
334 MAXIMUM_ALLOWED_ACCESS
,
337 if (!NT_STATUS_IS_OK(result
))
340 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
346 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) &&
349 /* Probably this was a user name, try lookupnames */
350 struct samr_Ids rids
, types
;
351 struct lsa_String lsa_acct_name
;
353 init_lsa_String(&lsa_acct_name
, argv
[1]);
355 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
362 if (NT_STATUS_IS_OK(result
)) {
363 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
372 if (!NT_STATUS_IS_OK(result
))
375 result
= rpccli_samr_QueryUserInfo(cli
, mem_ctx
,
380 if (!NT_STATUS_IS_OK(result
))
383 switch (info_level
) {
385 display_samr_user_info_7(&info
->info7
);
388 display_samr_user_info_9(&info
->info9
);
391 display_samr_user_info_16(&info
->info16
);
394 display_samr_user_info_20(&info
->info20
);
397 display_samr_user_info_21(&info
->info21
);
400 printf("Unsupported infolevel: %d\n", info_level
);
404 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
405 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
406 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
412 /****************************************************************************
414 ****************************************************************************/
415 static void display_group_info1(struct samr_GroupInfoAll
*info1
)
417 printf("\tGroup Name:\t%s\n", info1
->name
.string
);
418 printf("\tDescription:\t%s\n", info1
->description
.string
);
419 printf("\tGroup Attribute:%d\n", info1
->attributes
);
420 printf("\tNum Members:%d\n", info1
->num_members
);
423 /****************************************************************************
425 ****************************************************************************/
426 static void display_group_info2(struct lsa_String
*info2
)
428 printf("\tGroup Description:%s\n", info2
->string
);
432 /****************************************************************************
434 ****************************************************************************/
435 static void display_group_info3(struct samr_GroupInfoAttributes
*info3
)
437 printf("\tGroup Attribute:%d\n", info3
->attributes
);
441 /****************************************************************************
443 ****************************************************************************/
444 static void display_group_info4(struct lsa_String
*info4
)
446 printf("\tGroup Description:%s\n", info4
->string
);
449 /****************************************************************************
451 ****************************************************************************/
452 static void display_group_info5(struct samr_GroupInfoAll
*info5
)
454 printf("\tGroup Name:\t%s\n", info5
->name
.string
);
455 printf("\tDescription:\t%s\n", info5
->description
.string
);
456 printf("\tGroup Attribute:%d\n", info5
->attributes
);
457 printf("\tNum Members:%d\n", info5
->num_members
);
460 /****************************************************************************
461 display sam sync structure
462 ****************************************************************************/
463 static void display_group_info(union samr_GroupInfo
*info
,
464 enum samr_GroupInfoEnum level
)
468 display_group_info1(&info
->all
);
471 display_group_info2(&info
->name
);
474 display_group_info3(&info
->attributes
);
477 display_group_info4(&info
->description
);
480 display_group_info5(&info
->all2
);
485 /***********************************************************************
486 * Query group information
488 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
490 int argc
, const char **argv
)
492 struct policy_handle connect_pol
, domain_pol
, group_pol
;
493 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
494 enum samr_GroupInfoEnum info_level
= GROUPINFOALL
;
495 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
496 union samr_GroupInfo
*group_info
= NULL
;
499 if ((argc
< 2) || (argc
> 4)) {
500 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
504 sscanf(argv
[1], "%i", &group_rid
);
507 info_level
= atoi(argv
[2]);
510 sscanf(argv
[3], "%x", &access_mask
);
512 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
513 MAXIMUM_ALLOWED_ACCESS
,
516 if (!NT_STATUS_IS_OK(result
))
519 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
521 MAXIMUM_ALLOWED_ACCESS
,
525 if (!NT_STATUS_IS_OK(result
))
528 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
534 if (!NT_STATUS_IS_OK(result
))
537 result
= rpccli_samr_QueryGroupInfo(cli
, mem_ctx
,
541 if (!NT_STATUS_IS_OK(result
)) {
545 display_group_info(group_info
, info_level
);
547 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
548 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
549 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
554 /* Query groups a user is a member of */
556 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
558 int argc
, const char **argv
)
560 struct policy_handle connect_pol
,
563 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
565 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
567 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
569 if ((argc
< 2) || (argc
> 3)) {
570 printf("Usage: %s rid [access mask]\n", argv
[0]);
574 sscanf(argv
[1], "%i", &user_rid
);
577 sscanf(argv
[2], "%x", &access_mask
);
579 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
580 MAXIMUM_ALLOWED_ACCESS
,
583 if (!NT_STATUS_IS_OK(result
))
586 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
588 MAXIMUM_ALLOWED_ACCESS
,
589 &domain_sid
, &domain_pol
);
591 if (!NT_STATUS_IS_OK(result
))
594 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
600 if (!NT_STATUS_IS_OK(result
))
603 result
= rpccli_samr_GetGroupsForUser(cli
, mem_ctx
,
607 if (!NT_STATUS_IS_OK(result
))
610 for (i
= 0; i
< rid_array
->count
; i
++) {
611 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
612 rid_array
->rids
[i
].rid
,
613 rid_array
->rids
[i
].attributes
);
616 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
617 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
618 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
623 /* Query aliases a user is a member of */
625 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
627 int argc
, const char **argv
)
629 struct policy_handle connect_pol
, domain_pol
;
630 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
633 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
635 struct lsa_SidArray sid_array
;
636 struct samr_Ids alias_rids
;
639 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
640 return NT_STATUS_INVALID_PARAMETER
;
646 for (i
=2; i
<argc
; i
++) {
648 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
649 printf("%s is not a legal SID\n", argv
[i
]);
650 return NT_STATUS_INVALID_PARAMETER
;
652 result
= add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
653 if (!NT_STATUS_IS_OK(result
)) {
659 sid_array
.sids
= TALLOC_ZERO_ARRAY(mem_ctx
, struct lsa_SidPtr
, num_sids
);
660 if (sid_array
.sids
== NULL
)
661 return NT_STATUS_NO_MEMORY
;
663 sid_array
.sids
= NULL
;
666 for (i
=0; i
<num_sids
; i
++) {
667 sid_array
.sids
[i
].sid
= sid_dup_talloc(mem_ctx
, &sids
[i
]);
668 if (!sid_array
.sids
[i
].sid
) {
669 return NT_STATUS_NO_MEMORY
;
673 sid_array
.num_sids
= num_sids
;
675 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
676 MAXIMUM_ALLOWED_ACCESS
,
679 if (!NT_STATUS_IS_OK(result
))
682 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
688 if (!NT_STATUS_IS_OK(result
))
691 result
= rpccli_samr_GetAliasMembership(cli
, mem_ctx
,
695 if (!NT_STATUS_IS_OK(result
))
698 for (i
= 0; i
< alias_rids
.count
; i
++) {
699 printf("\tgroup rid:[0x%x]\n", alias_rids
.ids
[i
]);
702 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
703 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
708 /* Query members of a group */
710 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
712 int argc
, const char **argv
)
714 struct policy_handle connect_pol
, domain_pol
, group_pol
;
715 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
717 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
719 unsigned int old_timeout
;
720 struct samr_RidTypeArray
*rids
= NULL
;
722 if ((argc
< 2) || (argc
> 3)) {
723 printf("Usage: %s rid [access mask]\n", argv
[0]);
727 sscanf(argv
[1], "%i", &group_rid
);
730 sscanf(argv
[2], "%x", &access_mask
);
732 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
733 MAXIMUM_ALLOWED_ACCESS
,
736 if (!NT_STATUS_IS_OK(result
))
739 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
741 MAXIMUM_ALLOWED_ACCESS
,
745 if (!NT_STATUS_IS_OK(result
))
748 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
754 if (!NT_STATUS_IS_OK(result
))
757 /* Make sure to wait for our DC's reply */
758 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
759 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
761 result
= rpccli_samr_QueryGroupMember(cli
, mem_ctx
,
765 rpccli_set_timeout(cli
, old_timeout
);
767 if (!NT_STATUS_IS_OK(result
))
770 for (i
= 0; i
< rids
->count
; i
++) {
771 printf("\trid:[0x%x] attr:[0x%x]\n", rids
->rids
[i
],
775 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
776 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
777 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
782 /* Enumerate domain users */
784 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
786 int argc
, const char **argv
)
788 struct policy_handle connect_pol
, domain_pol
;
789 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
790 uint32 start_idx
, num_dom_users
, i
;
791 struct samr_SamArray
*dom_users
= NULL
;
792 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
793 uint32 acb_mask
= ACB_NORMAL
;
794 uint32_t size
= 0xffff;
796 if ((argc
< 1) || (argc
> 4)) {
797 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv
[0]);
802 sscanf(argv
[1], "%x", &access_mask
);
806 sscanf(argv
[2], "%x", &acb_mask
);
810 sscanf(argv
[3], "%x", &size
);
813 /* Get sam policy handle */
815 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
816 MAXIMUM_ALLOWED_ACCESS
,
819 if (!NT_STATUS_IS_OK(result
))
822 /* Get domain policy handle */
824 result
= get_domain_handle(cli
, mem_ctx
, "domain",
829 if (!NT_STATUS_IS_OK(result
))
832 /* Enumerate domain users */
837 result
= rpccli_samr_EnumDomainUsers(cli
, mem_ctx
,
845 if (NT_STATUS_IS_OK(result
) ||
846 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
848 for (i
= 0; i
< num_dom_users
; i
++)
849 printf("user:[%s] rid:[0x%x]\n",
850 dom_users
->entries
[i
].name
.string
,
851 dom_users
->entries
[i
].idx
);
854 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
857 if (is_valid_policy_hnd(&domain_pol
))
858 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
860 if (is_valid_policy_hnd(&connect_pol
))
861 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
866 /* Enumerate domain groups */
868 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
870 int argc
, const char **argv
)
872 struct policy_handle connect_pol
, domain_pol
;
873 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
874 uint32 start_idx
, num_dom_groups
, i
;
875 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
876 struct samr_SamArray
*dom_groups
= NULL
;
877 uint32_t size
= 0xffff;
879 if ((argc
< 1) || (argc
> 3)) {
880 printf("Usage: %s [access_mask] [max_size]\n", argv
[0]);
885 sscanf(argv
[1], "%x", &access_mask
);
889 sscanf(argv
[2], "%x", &size
);
892 /* Get sam policy handle */
894 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
895 MAXIMUM_ALLOWED_ACCESS
,
898 if (!NT_STATUS_IS_OK(result
))
901 /* Get domain policy handle */
903 result
= get_domain_handle(cli
, mem_ctx
, "domain",
908 if (!NT_STATUS_IS_OK(result
))
911 /* Enumerate domain groups */
916 result
= rpccli_samr_EnumDomainGroups(cli
, mem_ctx
,
922 if (NT_STATUS_IS_OK(result
) ||
923 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
925 for (i
= 0; i
< num_dom_groups
; i
++)
926 printf("group:[%s] rid:[0x%x]\n",
927 dom_groups
->entries
[i
].name
.string
,
928 dom_groups
->entries
[i
].idx
);
931 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
934 if (is_valid_policy_hnd(&domain_pol
))
935 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
937 if (is_valid_policy_hnd(&connect_pol
))
938 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
943 /* Enumerate alias groups */
945 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
947 int argc
, const char **argv
)
949 struct policy_handle connect_pol
, domain_pol
;
950 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
951 uint32 start_idx
, num_als_groups
, i
;
952 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
953 struct samr_SamArray
*als_groups
= NULL
;
954 uint32_t size
= 0xffff;
956 if ((argc
< 2) || (argc
> 4)) {
957 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv
[0]);
962 sscanf(argv
[2], "%x", &access_mask
);
966 sscanf(argv
[3], "%x", &size
);
969 /* Get sam policy handle */
971 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
972 MAXIMUM_ALLOWED_ACCESS
,
975 if (!NT_STATUS_IS_OK(result
))
978 /* Get domain policy handle */
980 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
986 if (!NT_STATUS_IS_OK(result
))
989 /* Enumerate alias groups */
994 result
= rpccli_samr_EnumDomainAliases(cli
, mem_ctx
,
1001 if (NT_STATUS_IS_OK(result
) ||
1002 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1004 for (i
= 0; i
< num_als_groups
; i
++)
1005 printf("group:[%s] rid:[0x%x]\n",
1006 als_groups
->entries
[i
].name
.string
,
1007 als_groups
->entries
[i
].idx
);
1009 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1012 if (is_valid_policy_hnd(&domain_pol
))
1013 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1015 if (is_valid_policy_hnd(&connect_pol
))
1016 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1021 /* Enumerate domains */
1023 static NTSTATUS
cmd_samr_enum_domains(struct rpc_pipe_client
*cli
,
1024 TALLOC_CTX
*mem_ctx
,
1025 int argc
, const char **argv
)
1027 struct policy_handle connect_pol
;
1028 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1029 uint32 start_idx
, size
, num_entries
, i
;
1030 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1031 struct samr_SamArray
*sam
= NULL
;
1033 if ((argc
< 1) || (argc
> 2)) {
1034 printf("Usage: %s [access mask]\n", argv
[0]);
1035 return NT_STATUS_OK
;
1039 sscanf(argv
[1], "%x", &access_mask
);
1042 /* Get sam policy handle */
1044 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1048 if (!NT_STATUS_IS_OK(result
)) {
1052 /* Enumerate alias groups */
1058 result
= rpccli_samr_EnumDomains(cli
, mem_ctx
,
1065 if (NT_STATUS_IS_OK(result
) ||
1066 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
1068 for (i
= 0; i
< num_entries
; i
++)
1069 printf("name:[%s] idx:[0x%x]\n",
1070 sam
->entries
[i
].name
.string
,
1071 sam
->entries
[i
].idx
);
1073 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
1076 if (is_valid_policy_hnd(&connect_pol
)) {
1077 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1084 /* Query alias membership */
1086 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
1087 TALLOC_CTX
*mem_ctx
,
1088 int argc
, const char **argv
)
1090 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1091 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1092 uint32 alias_rid
, i
;
1093 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1094 struct lsa_SidArray sid_array
;
1096 if ((argc
< 3) || (argc
> 4)) {
1097 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
1098 return NT_STATUS_OK
;
1101 sscanf(argv
[2], "%i", &alias_rid
);
1104 sscanf(argv
[3], "%x", &access_mask
);
1106 /* Open SAMR handle */
1108 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1109 MAXIMUM_ALLOWED_ACCESS
,
1112 if (!NT_STATUS_IS_OK(result
))
1115 /* Open handle on domain */
1117 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1119 MAXIMUM_ALLOWED_ACCESS
,
1123 if (!NT_STATUS_IS_OK(result
))
1126 /* Open handle on alias */
1128 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1133 if (!NT_STATUS_IS_OK(result
))
1136 result
= rpccli_samr_GetMembersInAlias(cli
, mem_ctx
,
1140 if (!NT_STATUS_IS_OK(result
))
1143 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
1146 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
1147 printf("\tsid:[%s]\n", sid_str
);
1150 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1151 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1152 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1157 /* Query alias info */
1159 static NTSTATUS
cmd_samr_query_aliasinfo(struct rpc_pipe_client
*cli
,
1160 TALLOC_CTX
*mem_ctx
,
1161 int argc
, const char **argv
)
1163 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1164 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1166 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1167 union samr_AliasInfo
*info
= NULL
;
1168 enum samr_AliasInfoEnum level
= ALIASINFOALL
;
1170 if ((argc
< 3) || (argc
> 4)) {
1171 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1173 return NT_STATUS_OK
;
1176 sscanf(argv
[2], "%i", &alias_rid
);
1179 level
= atoi(argv
[3]);
1183 sscanf(argv
[4], "%x", &access_mask
);
1186 /* Open SAMR handle */
1188 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1189 SEC_FLAG_MAXIMUM_ALLOWED
,
1192 if (!NT_STATUS_IS_OK(result
)) {
1196 /* Open handle on domain */
1198 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1200 SEC_FLAG_MAXIMUM_ALLOWED
,
1204 if (!NT_STATUS_IS_OK(result
)) {
1208 /* Open handle on alias */
1210 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1215 if (!NT_STATUS_IS_OK(result
)) {
1219 result
= rpccli_samr_QueryAliasInfo(cli
, mem_ctx
,
1224 if (!NT_STATUS_IS_OK(result
)) {
1230 printf("Name: %s\n", info
->all
.name
.string
);
1231 printf("Description: %s\n", info
->all
.description
.string
);
1232 printf("Num Members: %d\n", info
->all
.num_members
);
1235 printf("Name: %s\n", info
->name
.string
);
1237 case ALIASINFODESCRIPTION
:
1238 printf("Description: %s\n", info
->description
.string
);
1244 rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1245 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1246 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1252 /* Query delete an alias membership */
1254 static NTSTATUS
cmd_samr_delete_alias(struct rpc_pipe_client
*cli
,
1255 TALLOC_CTX
*mem_ctx
,
1256 int argc
, const char **argv
)
1258 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1259 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1261 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1264 printf("Usage: %s builtin|domain [rid|name]\n", argv
[0]);
1265 return NT_STATUS_OK
;
1268 alias_rid
= strtoul(argv
[2], NULL
, 10);
1270 /* Open SAMR handle */
1272 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1273 MAXIMUM_ALLOWED_ACCESS
,
1276 if (!NT_STATUS_IS_OK(result
))
1279 /* Open handle on domain */
1281 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1283 MAXIMUM_ALLOWED_ACCESS
,
1287 if (!NT_STATUS_IS_OK(result
))
1290 /* Open handle on alias */
1292 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1297 if (!NT_STATUS_IS_OK(result
) && (alias_rid
== 0)) {
1298 /* Probably this was a user name, try lookupnames */
1299 struct samr_Ids rids
, types
;
1300 struct lsa_String lsa_acct_name
;
1302 init_lsa_String(&lsa_acct_name
, argv
[2]);
1304 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1311 if (NT_STATUS_IS_OK(result
)) {
1312 result
= rpccli_samr_OpenAlias(cli
, mem_ctx
,
1320 result
= rpccli_samr_DeleteDomAlias(cli
, mem_ctx
,
1323 if (!NT_STATUS_IS_OK(result
))
1326 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1327 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1332 /* Query display info */
1334 static NTSTATUS
cmd_samr_query_dispinfo_internal(struct rpc_pipe_client
*cli
,
1335 TALLOC_CTX
*mem_ctx
,
1336 int argc
, const char **argv
,
1339 struct policy_handle connect_pol
, domain_pol
;
1340 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1341 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
= 0, i
;
1342 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1343 uint32 info_level
= 1;
1344 union samr_DispInfo info
;
1346 bool got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1347 uint32_t total_size
, returned_size
;
1350 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1351 return NT_STATUS_OK
;
1355 sscanf(argv
[1], "%i", &info_level
);
1358 sscanf(argv
[2], "%i", &start_idx
);
1361 sscanf(argv
[3], "%i", &max_entries
);
1366 sscanf(argv
[4], "%i", &max_size
);
1371 sscanf(argv
[5], "%x", &access_mask
);
1373 /* Get sam policy handle */
1375 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1376 MAXIMUM_ALLOWED_ACCESS
,
1379 if (!NT_STATUS_IS_OK(result
))
1382 /* Get domain policy handle */
1384 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1390 if (!NT_STATUS_IS_OK(result
))
1393 /* Query display info */
1398 get_query_dispinfo_params(
1399 loop_count
, &max_entries
, &max_size
);
1402 case NDR_SAMR_QUERYDISPLAYINFO
:
1403 result
= rpccli_samr_QueryDisplayInfo(cli
, mem_ctx
,
1413 case NDR_SAMR_QUERYDISPLAYINFO2
:
1414 result
= rpccli_samr_QueryDisplayInfo2(cli
, mem_ctx
,
1425 case NDR_SAMR_QUERYDISPLAYINFO3
:
1426 result
= rpccli_samr_QueryDisplayInfo3(cli
, mem_ctx
,
1438 return NT_STATUS_INVALID_PARAMETER
;
1441 if (!NT_STATUS_IS_OK(result
) &&
1442 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
1443 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
1449 switch (info_level
) {
1451 num_entries
= info
.info1
.count
;
1454 num_entries
= info
.info2
.count
;
1457 num_entries
= info
.info3
.count
;
1460 num_entries
= info
.info4
.count
;
1463 num_entries
= info
.info5
.count
;
1469 start_idx
+= num_entries
;
1471 if (num_entries
== 0)
1474 for (i
= 0; i
< num_entries
; i
++) {
1475 switch (info_level
) {
1477 display_sam_info_1(&info
.info1
.entries
[i
]);
1480 display_sam_info_2(&info
.info2
.entries
[i
]);
1483 display_sam_info_3(&info
.info3
.entries
[i
]);
1486 display_sam_info_4(&info
.info4
.entries
[i
]);
1489 display_sam_info_5(&info
.info5
.entries
[i
]);
1493 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1495 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1496 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1501 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1502 TALLOC_CTX
*mem_ctx
,
1503 int argc
, const char **argv
)
1505 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1506 NDR_SAMR_QUERYDISPLAYINFO
);
1509 static NTSTATUS
cmd_samr_query_dispinfo2(struct rpc_pipe_client
*cli
,
1510 TALLOC_CTX
*mem_ctx
,
1511 int argc
, const char **argv
)
1513 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1514 NDR_SAMR_QUERYDISPLAYINFO2
);
1517 static NTSTATUS
cmd_samr_query_dispinfo3(struct rpc_pipe_client
*cli
,
1518 TALLOC_CTX
*mem_ctx
,
1519 int argc
, const char **argv
)
1521 return cmd_samr_query_dispinfo_internal(cli
, mem_ctx
, argc
, argv
,
1522 NDR_SAMR_QUERYDISPLAYINFO3
);
1525 /* Query domain info */
1527 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1528 TALLOC_CTX
*mem_ctx
,
1529 int argc
, const char **argv
)
1531 struct policy_handle connect_pol
, domain_pol
;
1532 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1533 uint32 switch_level
= 2;
1534 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1535 union samr_DomainInfo
*info
= NULL
;
1538 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1539 return NT_STATUS_OK
;
1543 sscanf(argv
[1], "%i", &switch_level
);
1546 sscanf(argv
[2], "%x", &access_mask
);
1548 /* Get sam policy handle */
1550 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1551 MAXIMUM_ALLOWED_ACCESS
,
1554 if (!NT_STATUS_IS_OK(result
))
1557 /* Get domain policy handle */
1559 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1565 if (!NT_STATUS_IS_OK(result
))
1568 /* Query domain info */
1570 result
= rpccli_samr_QueryDomainInfo(cli
, mem_ctx
,
1575 if (!NT_STATUS_IS_OK(result
))
1578 /* Display domain info */
1580 switch (switch_level
) {
1582 display_sam_dom_info_1(&info
->info1
);
1585 display_sam_dom_info_2(&info
->general
);
1588 display_sam_dom_info_3(&info
->info3
);
1591 display_sam_dom_info_4(&info
->oem
);
1594 display_sam_dom_info_5(&info
->info5
);
1597 display_sam_dom_info_6(&info
->info6
);
1600 display_sam_dom_info_7(&info
->info7
);
1603 display_sam_dom_info_8(&info
->info8
);
1606 display_sam_dom_info_9(&info
->info9
);
1609 display_sam_dom_info_12(&info
->info12
);
1612 display_sam_dom_info_13(&info
->info13
);
1616 printf("cannot display domain info for switch value %d\n",
1623 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1624 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1628 /* Create domain user */
1630 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1631 TALLOC_CTX
*mem_ctx
,
1632 int argc
, const char **argv
)
1634 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1635 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1636 struct lsa_String acct_name
;
1638 uint32 acct_flags
, user_rid
;
1639 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1640 uint32_t access_granted
= 0;
1642 if ((argc
< 2) || (argc
> 3)) {
1643 printf("Usage: %s username [access mask]\n", argv
[0]);
1644 return NT_STATUS_OK
;
1647 init_lsa_String(&acct_name
, argv
[1]);
1650 sscanf(argv
[2], "%x", &access_mask
);
1652 /* Get sam policy handle */
1654 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1655 MAXIMUM_ALLOWED_ACCESS
,
1658 if (!NT_STATUS_IS_OK(result
))
1661 /* Get domain policy handle */
1663 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1669 if (!NT_STATUS_IS_OK(result
))
1672 /* Create domain user */
1674 acb_info
= ACB_NORMAL
;
1675 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1676 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1677 SAMR_USER_ACCESS_SET_PASSWORD
|
1678 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1679 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1681 result
= rpccli_samr_CreateUser2(cli
, mem_ctx
,
1690 if (!NT_STATUS_IS_OK(result
))
1693 result
= rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
1694 if (!NT_STATUS_IS_OK(result
)) goto done
;
1696 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1697 if (!NT_STATUS_IS_OK(result
)) goto done
;
1699 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1700 if (!NT_STATUS_IS_OK(result
)) goto done
;
1706 /* Create domain group */
1708 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1709 TALLOC_CTX
*mem_ctx
,
1710 int argc
, const char **argv
)
1712 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1713 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1714 struct lsa_String grp_name
;
1715 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1718 if ((argc
< 2) || (argc
> 3)) {
1719 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1720 return NT_STATUS_OK
;
1723 init_lsa_String(&grp_name
, argv
[1]);
1726 sscanf(argv
[2], "%x", &access_mask
);
1728 /* Get sam policy handle */
1730 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1731 MAXIMUM_ALLOWED_ACCESS
,
1734 if (!NT_STATUS_IS_OK(result
))
1737 /* Get domain policy handle */
1739 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1745 if (!NT_STATUS_IS_OK(result
))
1748 /* Create domain user */
1749 result
= rpccli_samr_CreateDomainGroup(cli
, mem_ctx
,
1752 MAXIMUM_ALLOWED_ACCESS
,
1756 if (!NT_STATUS_IS_OK(result
))
1759 result
= rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
1760 if (!NT_STATUS_IS_OK(result
)) goto done
;
1762 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1763 if (!NT_STATUS_IS_OK(result
)) goto done
;
1765 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1766 if (!NT_STATUS_IS_OK(result
)) goto done
;
1772 /* Create domain alias */
1774 static NTSTATUS
cmd_samr_create_dom_alias(struct rpc_pipe_client
*cli
,
1775 TALLOC_CTX
*mem_ctx
,
1776 int argc
, const char **argv
)
1778 struct policy_handle connect_pol
, domain_pol
, alias_pol
;
1779 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1780 struct lsa_String alias_name
;
1781 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1784 if ((argc
< 2) || (argc
> 3)) {
1785 printf("Usage: %s aliasname [access mask]\n", argv
[0]);
1786 return NT_STATUS_OK
;
1789 init_lsa_String(&alias_name
, argv
[1]);
1792 sscanf(argv
[2], "%x", &access_mask
);
1794 /* Get sam policy handle */
1796 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1797 MAXIMUM_ALLOWED_ACCESS
,
1800 if (!NT_STATUS_IS_OK(result
))
1803 /* Get domain policy handle */
1805 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
1811 if (!NT_STATUS_IS_OK(result
))
1814 /* Create domain user */
1816 result
= rpccli_samr_CreateDomAlias(cli
, mem_ctx
,
1819 MAXIMUM_ALLOWED_ACCESS
,
1823 if (!NT_STATUS_IS_OK(result
))
1826 result
= rpccli_samr_Close(cli
, mem_ctx
, &alias_pol
);
1827 if (!NT_STATUS_IS_OK(result
)) goto done
;
1829 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1830 if (!NT_STATUS_IS_OK(result
)) goto done
;
1832 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1833 if (!NT_STATUS_IS_OK(result
)) goto done
;
1839 /* Lookup sam names */
1841 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
1842 TALLOC_CTX
*mem_ctx
,
1843 int argc
, const char **argv
)
1845 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1846 struct policy_handle connect_pol
, domain_pol
;
1848 struct samr_Ids rids
, name_types
;
1850 struct lsa_String
*names
= NULL
;;
1853 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1854 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1855 printf("or check on the builtin SID: S-1-5-32\n");
1856 return NT_STATUS_OK
;
1859 /* Get sam policy and domain handles */
1861 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1862 MAXIMUM_ALLOWED_ACCESS
,
1865 if (!NT_STATUS_IS_OK(result
))
1868 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1870 MAXIMUM_ALLOWED_ACCESS
,
1874 if (!NT_STATUS_IS_OK(result
))
1879 num_names
= argc
- 2;
1881 if ((names
= TALLOC_ARRAY(mem_ctx
, struct lsa_String
, num_names
)) == NULL
) {
1882 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1883 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1884 result
= NT_STATUS_NO_MEMORY
;
1888 for (i
= 0; i
< num_names
; i
++) {
1889 init_lsa_String(&names
[i
], argv
[i
+ 2]);
1892 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
1899 if (!NT_STATUS_IS_OK(result
))
1902 /* Display results */
1904 for (i
= 0; i
< num_names
; i
++)
1905 printf("name %s: 0x%x (%d)\n", names
[i
].string
, rids
.ids
[i
],
1908 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1909 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1914 /* Lookup sam rids */
1916 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
1917 TALLOC_CTX
*mem_ctx
,
1918 int argc
, const char **argv
)
1920 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1921 struct policy_handle connect_pol
, domain_pol
;
1922 uint32_t num_rids
, *rids
;
1923 struct lsa_Strings names
;
1924 struct samr_Ids types
;
1929 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1930 return NT_STATUS_OK
;
1933 /* Get sam policy and domain handles */
1935 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
1936 MAXIMUM_ALLOWED_ACCESS
,
1939 if (!NT_STATUS_IS_OK(result
))
1942 result
= get_domain_handle(cli
, mem_ctx
, argv
[1],
1944 MAXIMUM_ALLOWED_ACCESS
,
1948 if (!NT_STATUS_IS_OK(result
))
1953 num_rids
= argc
- 2;
1955 if ((rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
)) == NULL
) {
1956 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1957 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1958 result
= NT_STATUS_NO_MEMORY
;
1962 for (i
= 0; i
< argc
- 2; i
++)
1963 sscanf(argv
[i
+ 2], "%i", &rids
[i
]);
1965 result
= rpccli_samr_LookupRids(cli
, mem_ctx
,
1972 if (!NT_STATUS_IS_OK(result
) &&
1973 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1976 /* Display results */
1978 for (i
= 0; i
< num_rids
; i
++) {
1979 printf("rid 0x%x: %s (%d)\n",
1980 rids
[i
], names
.names
[i
].string
, types
.ids
[i
]);
1983 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
1984 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
1989 /* Delete domain group */
1991 static NTSTATUS
cmd_samr_delete_dom_group(struct rpc_pipe_client
*cli
,
1992 TALLOC_CTX
*mem_ctx
,
1993 int argc
, const char **argv
)
1995 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1996 struct policy_handle connect_pol
, domain_pol
, group_pol
;
1997 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1999 if ((argc
< 2) || (argc
> 3)) {
2000 printf("Usage: %s groupname\n", argv
[0]);
2001 return NT_STATUS_OK
;
2005 sscanf(argv
[2], "%x", &access_mask
);
2007 /* Get sam policy and domain handles */
2009 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2010 MAXIMUM_ALLOWED_ACCESS
,
2013 if (!NT_STATUS_IS_OK(result
))
2016 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2018 MAXIMUM_ALLOWED_ACCESS
,
2022 if (!NT_STATUS_IS_OK(result
))
2025 /* Get handle on group */
2028 struct samr_Ids group_rids
, name_types
;
2029 struct lsa_String lsa_acct_name
;
2031 init_lsa_String(&lsa_acct_name
, argv
[1]);
2033 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2039 if (!NT_STATUS_IS_OK(result
))
2042 result
= rpccli_samr_OpenGroup(cli
, mem_ctx
,
2048 if (!NT_STATUS_IS_OK(result
))
2054 result
= rpccli_samr_DeleteDomainGroup(cli
, mem_ctx
,
2057 if (!NT_STATUS_IS_OK(result
))
2060 /* Display results */
2062 rpccli_samr_Close(cli
, mem_ctx
, &group_pol
);
2063 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2064 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2070 /* Delete domain user */
2072 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
2073 TALLOC_CTX
*mem_ctx
,
2074 int argc
, const char **argv
)
2076 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2077 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2078 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2080 if ((argc
< 2) || (argc
> 3)) {
2081 printf("Usage: %s username\n", argv
[0]);
2082 return NT_STATUS_OK
;
2086 sscanf(argv
[2], "%x", &access_mask
);
2088 /* Get sam policy and domain handles */
2090 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2091 MAXIMUM_ALLOWED_ACCESS
,
2094 if (!NT_STATUS_IS_OK(result
))
2097 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2099 MAXIMUM_ALLOWED_ACCESS
,
2103 if (!NT_STATUS_IS_OK(result
))
2106 /* Get handle on user */
2109 struct samr_Ids user_rids
, name_types
;
2110 struct lsa_String lsa_acct_name
;
2112 init_lsa_String(&lsa_acct_name
, argv
[1]);
2114 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2121 if (!NT_STATUS_IS_OK(result
))
2124 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2130 if (!NT_STATUS_IS_OK(result
))
2136 result
= rpccli_samr_DeleteUser(cli
, mem_ctx
,
2139 if (!NT_STATUS_IS_OK(result
))
2142 /* Display results */
2144 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2145 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2146 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2152 /**********************************************************************
2153 * Query user security object
2155 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
2156 TALLOC_CTX
*mem_ctx
,
2157 int argc
, const char **argv
)
2159 struct policy_handle connect_pol
, domain_pol
, user_pol
, *pol
;
2160 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2161 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
2162 uint32 user_rid
= 0;
2163 TALLOC_CTX
*ctx
= NULL
;
2164 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
2165 bool domain
= False
;
2167 ctx
=talloc_init("cmd_samr_query_sec_obj");
2169 if ((argc
< 1) || (argc
> 3)) {
2170 printf("Usage: %s [rid|-d] [sec_info]\n", argv
[0]);
2171 printf("\tSpecify rid for security on user, -d for security on domain\n");
2172 talloc_destroy(ctx
);
2173 return NT_STATUS_OK
;
2177 if (strcmp(argv
[1], "-d") == 0)
2180 sscanf(argv
[1], "%i", &user_rid
);
2184 sec_info
= atoi(argv
[2]);
2187 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2188 MAXIMUM_ALLOWED_ACCESS
,
2191 if (!NT_STATUS_IS_OK(result
))
2194 if (domain
|| user_rid
)
2195 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2197 MAXIMUM_ALLOWED_ACCESS
,
2201 if (!NT_STATUS_IS_OK(result
))
2205 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2207 MAXIMUM_ALLOWED_ACCESS
,
2211 if (!NT_STATUS_IS_OK(result
))
2214 /* Pick which query pol to use */
2224 /* Query SAM security object */
2226 result
= rpccli_samr_QuerySecurity(cli
, mem_ctx
,
2231 if (!NT_STATUS_IS_OK(result
))
2234 display_sec_desc(sec_desc_buf
->sd
);
2236 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2237 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2238 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2240 talloc_destroy(ctx
);
2244 static NTSTATUS
cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client
*cli
,
2245 TALLOC_CTX
*mem_ctx
,
2246 int argc
, const char **argv
)
2248 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2249 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2250 struct samr_PwInfo info
;
2254 printf("Usage: %s rid\n", argv
[0]);
2255 return NT_STATUS_OK
;
2258 sscanf(argv
[1], "%i", &rid
);
2260 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2261 MAXIMUM_ALLOWED_ACCESS
,
2264 if (!NT_STATUS_IS_OK(result
)) {
2268 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2270 MAXIMUM_ALLOWED_ACCESS
,
2274 if (!NT_STATUS_IS_OK(result
)) {
2278 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2280 MAXIMUM_ALLOWED_ACCESS
,
2284 if (!NT_STATUS_IS_OK(result
)) {
2288 result
= rpccli_samr_GetUserPwInfo(cli
, mem_ctx
, &user_pol
, &info
);
2289 if (NT_STATUS_IS_OK(result
)) {
2290 printf("min_password_length: %d\n", info
.min_password_length
);
2292 NDR_PRINT_STRUCT_STRING(mem_ctx
,
2293 samr_PasswordProperties
, &info
.password_properties
));
2297 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2298 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2299 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2304 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
2305 TALLOC_CTX
*mem_ctx
,
2306 int argc
, const char **argv
)
2308 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2309 struct lsa_String domain_name
;
2310 struct samr_PwInfo info
;
2312 if (argc
< 1 || argc
> 3) {
2313 printf("Usage: %s <domain>\n", argv
[0]);
2314 return NT_STATUS_OK
;
2317 init_lsa_String(&domain_name
, argv
[1]);
2319 result
= rpccli_samr_GetDomPwInfo(cli
, mem_ctx
, &domain_name
, &info
);
2321 if (NT_STATUS_IS_OK(result
)) {
2322 printf("min_password_length: %d\n", info
.min_password_length
);
2323 display_password_properties(info
.password_properties
);
2329 /* Look up domain name */
2331 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
2332 TALLOC_CTX
*mem_ctx
,
2333 int argc
, const char **argv
)
2335 struct policy_handle connect_pol
, domain_pol
;
2336 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2337 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2339 struct lsa_String domain_name
;
2340 DOM_SID
*sid
= NULL
;
2343 printf("Usage: %s domain_name\n", argv
[0]);
2344 return NT_STATUS_OK
;
2347 init_lsa_String(&domain_name
, argv
[1]);
2349 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2353 if (!NT_STATUS_IS_OK(result
))
2356 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2362 if (!NT_STATUS_IS_OK(result
))
2365 result
= rpccli_samr_LookupDomain(cli
, mem_ctx
,
2370 if (NT_STATUS_IS_OK(result
)) {
2371 sid_to_fstring(sid_string
, sid
);
2372 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2373 argv
[1], sid_string
);
2376 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2377 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2382 /* Change user password */
2384 static NTSTATUS
cmd_samr_chgpasswd(struct rpc_pipe_client
*cli
,
2385 TALLOC_CTX
*mem_ctx
,
2386 int argc
, const char **argv
)
2388 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2389 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2390 const char *user
, *oldpass
, *newpass
;
2391 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2392 struct samr_Ids rids
, types
;
2393 struct lsa_String lsa_acct_name
;
2396 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2397 return NT_STATUS_INVALID_PARAMETER
;
2404 /* Get sam policy handle */
2406 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2407 MAXIMUM_ALLOWED_ACCESS
,
2410 if (!NT_STATUS_IS_OK(result
)) {
2414 /* Get domain policy handle */
2416 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2422 if (!NT_STATUS_IS_OK(result
)) {
2426 init_lsa_String(&lsa_acct_name
, user
);
2428 result
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2435 if (!NT_STATUS_IS_OK(result
)) {
2439 result
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2445 if (!NT_STATUS_IS_OK(result
)) {
2449 /* Change user password */
2450 result
= rpccli_samr_chgpasswd_user(cli
, mem_ctx
,
2455 if (!NT_STATUS_IS_OK(result
)) {
2460 if (is_valid_policy_hnd(&user_pol
)) {
2461 rpccli_samr_Close(cli
, mem_ctx
, &user_pol
);
2463 if (is_valid_policy_hnd(&domain_pol
)) {
2464 rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2466 if (is_valid_policy_hnd(&connect_pol
)) {
2467 rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2474 /* Change user password */
2476 static NTSTATUS
cmd_samr_chgpasswd2(struct rpc_pipe_client
*cli
,
2477 TALLOC_CTX
*mem_ctx
,
2478 int argc
, const char **argv
)
2480 struct policy_handle connect_pol
, domain_pol
;
2481 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2482 const char *user
, *oldpass
, *newpass
;
2483 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2486 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2487 return NT_STATUS_INVALID_PARAMETER
;
2494 /* Get sam policy handle */
2496 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2497 MAXIMUM_ALLOWED_ACCESS
,
2500 if (!NT_STATUS_IS_OK(result
))
2503 /* Get domain policy handle */
2505 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2511 if (!NT_STATUS_IS_OK(result
))
2514 /* Change user password */
2515 result
= rpccli_samr_chgpasswd_user2(cli
, mem_ctx
, user
, newpass
, oldpass
);
2517 if (!NT_STATUS_IS_OK(result
))
2520 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2521 if (!NT_STATUS_IS_OK(result
)) goto done
;
2523 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2524 if (!NT_STATUS_IS_OK(result
)) goto done
;
2531 /* Change user password */
2533 static NTSTATUS
cmd_samr_chgpasswd3(struct rpc_pipe_client
*cli
,
2534 TALLOC_CTX
*mem_ctx
,
2535 int argc
, const char **argv
)
2537 struct policy_handle connect_pol
, domain_pol
;
2538 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2539 const char *user
, *oldpass
, *newpass
;
2540 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2541 struct samr_DomInfo1
*info
= NULL
;
2542 struct userPwdChangeFailureInformation
*reject
= NULL
;
2545 printf("Usage: %s username oldpass newpass\n", argv
[0]);
2546 return NT_STATUS_INVALID_PARAMETER
;
2553 /* Get sam policy handle */
2555 result
= rpccli_try_samr_connects(cli
, mem_ctx
,
2556 MAXIMUM_ALLOWED_ACCESS
,
2559 if (!NT_STATUS_IS_OK(result
))
2562 /* Get domain policy handle */
2564 result
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2570 if (!NT_STATUS_IS_OK(result
))
2573 /* Change user password */
2574 result
= rpccli_samr_chgpasswd_user3(cli
, mem_ctx
,
2581 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
)) {
2583 display_sam_dom_info_1(info
);
2585 switch (reject
->extendedFailureReason
) {
2586 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT
:
2587 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2589 case SAM_PWD_CHANGE_PWD_IN_HISTORY
:
2590 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2592 case SAM_PWD_CHANGE_NOT_COMPLEX
:
2593 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2596 d_printf("unknown reject reason: %d\n",
2597 reject
->extendedFailureReason
);
2602 if (!NT_STATUS_IS_OK(result
))
2605 result
= rpccli_samr_Close(cli
, mem_ctx
, &domain_pol
);
2606 if (!NT_STATUS_IS_OK(result
)) goto done
;
2608 result
= rpccli_samr_Close(cli
, mem_ctx
, &connect_pol
);
2609 if (!NT_STATUS_IS_OK(result
)) goto done
;
2615 static NTSTATUS
cmd_samr_setuserinfo_int(struct rpc_pipe_client
*cli
,
2616 TALLOC_CTX
*mem_ctx
,
2617 int argc
, const char **argv
,
2620 struct policy_handle connect_pol
, domain_pol
, user_pol
;
2621 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
2622 const char *user
, *param
;
2623 uint32_t access_mask
= MAXIMUM_ALLOWED_ACCESS
;
2626 union samr_UserInfo info
;
2627 struct samr_CryptPassword pwd_buf
;
2628 struct samr_CryptPasswordEx pwd_buf_ex
;
2629 uint8_t nt_hash
[16];
2630 uint8_t lm_hash
[16];
2631 DATA_BLOB session_key
;
2632 uint8_t password_expired
= 0;
2635 printf("Usage: %s username level password [password_expired]\n",
2637 return NT_STATUS_INVALID_PARAMETER
;
2641 level
= atoi(argv
[2]);
2645 password_expired
= atoi(argv
[4]);
2648 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2649 if (!NT_STATUS_IS_OK(status
)) {
2653 init_samr_CryptPassword(param
, &session_key
, &pwd_buf
);
2654 init_samr_CryptPasswordEx(param
, &session_key
, &pwd_buf_ex
);
2655 nt_lm_owf_gen(param
, nt_hash
, lm_hash
);
2661 in
= data_blob_const(nt_hash
, 16);
2662 out
= data_blob_talloc_zero(mem_ctx
, 16);
2663 sess_crypt_blob(&out
, &in
, &session_key
, true);
2664 memcpy(nt_hash
, out
.data
, out
.length
);
2668 in
= data_blob_const(lm_hash
, 16);
2669 out
= data_blob_talloc_zero(mem_ctx
, 16);
2670 sess_crypt_blob(&out
, &in
, &session_key
, true);
2671 memcpy(lm_hash
, out
.data
, out
.length
);
2674 memcpy(info
.info18
.nt_pwd
.hash
, nt_hash
, 16);
2675 memcpy(info
.info18
.lm_pwd
.hash
, lm_hash
, 16);
2676 info
.info18
.nt_pwd_active
= true;
2677 info
.info18
.lm_pwd_active
= true;
2678 info
.info18
.password_expired
= password_expired
;
2682 ZERO_STRUCT(info
.info21
);
2684 info
.info21
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2685 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2687 info
.info21
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2688 info
.info21
.password_expired
= password_expired
;
2691 info
.info21
.lm_password_set
= true;
2692 info
.info21
.lm_owf_password
.length
= 16;
2693 info
.info21
.lm_owf_password
.size
= 16;
2695 info
.info21
.nt_password_set
= true;
2696 info
.info21
.nt_owf_password
.length
= 16;
2697 info
.info21
.nt_owf_password
.size
= 16;
2701 in
= data_blob_const(nt_hash
, 16);
2702 out
= data_blob_talloc_zero(mem_ctx
, 16);
2703 sess_crypt_blob(&out
, &in
, &session_key
, true);
2704 info
.info21
.nt_owf_password
.array
=
2705 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2709 in
= data_blob_const(lm_hash
, 16);
2710 out
= data_blob_talloc_zero(mem_ctx
, 16);
2711 sess_crypt_blob(&out
, &in
, &session_key
, true);
2712 info
.info21
.lm_owf_password
.array
=
2713 (uint16_t *)talloc_memdup(mem_ctx
, out
.data
, 16);
2718 ZERO_STRUCT(info
.info23
);
2720 info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2721 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2723 info
.info23
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2724 info
.info23
.info
.password_expired
= password_expired
;
2727 info
.info23
.password
= pwd_buf
;
2731 info
.info24
.password
= pwd_buf
;
2732 info
.info24
.password_expired
= password_expired
;
2736 ZERO_STRUCT(info
.info25
);
2738 info
.info25
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
2739 SAMR_FIELD_LM_PASSWORD_PRESENT
;
2741 info
.info25
.info
.fields_present
|= SAMR_FIELD_EXPIRED_FLAG
;
2742 info
.info25
.info
.password_expired
= password_expired
;
2745 info
.info25
.password
= pwd_buf_ex
;
2749 info
.info26
.password
= pwd_buf_ex
;
2750 info
.info26
.password_expired
= password_expired
;
2754 return NT_STATUS_INVALID_INFO_CLASS
;
2757 /* Get sam policy handle */
2759 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2760 MAXIMUM_ALLOWED_ACCESS
,
2763 if (!NT_STATUS_IS_OK(status
))
2766 /* Get domain policy handle */
2768 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2774 if (!NT_STATUS_IS_OK(status
))
2777 user_rid
= strtol(user
, NULL
, 0);
2779 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2786 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
) ||
2789 /* Probably this was a user name, try lookupnames */
2790 struct samr_Ids rids
, types
;
2791 struct lsa_String lsa_acct_name
;
2793 init_lsa_String(&lsa_acct_name
, user
);
2795 status
= rpccli_samr_LookupNames(cli
, mem_ctx
,
2801 if (!NT_STATUS_IS_OK(status
)) {
2805 status
= rpccli_samr_OpenUser(cli
, mem_ctx
,
2810 if (!NT_STATUS_IS_OK(status
)) {
2816 case NDR_SAMR_SETUSERINFO
:
2817 status
= rpccli_samr_SetUserInfo(cli
, mem_ctx
,
2822 case NDR_SAMR_SETUSERINFO2
:
2823 status
= rpccli_samr_SetUserInfo2(cli
, mem_ctx
,
2829 return NT_STATUS_INVALID_PARAMETER
;
2836 static NTSTATUS
cmd_samr_setuserinfo(struct rpc_pipe_client
*cli
,
2837 TALLOC_CTX
*mem_ctx
,
2838 int argc
, const char **argv
)
2840 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2841 NDR_SAMR_SETUSERINFO
);
2844 static NTSTATUS
cmd_samr_setuserinfo2(struct rpc_pipe_client
*cli
,
2845 TALLOC_CTX
*mem_ctx
,
2846 int argc
, const char **argv
)
2848 return cmd_samr_setuserinfo_int(cli
, mem_ctx
, argc
, argv
,
2849 NDR_SAMR_SETUSERINFO2
);
2852 static NTSTATUS
cmd_samr_get_dispinfo_idx(struct rpc_pipe_client
*cli
,
2853 TALLOC_CTX
*mem_ctx
,
2854 int argc
, const char **argv
)
2857 struct policy_handle connect_handle
;
2858 struct policy_handle domain_handle
;
2860 struct lsa_String name
;
2863 if (argc
< 2 || argc
> 3) {
2864 printf("Usage: %s name level\n", argv
[0]);
2865 return NT_STATUS_INVALID_PARAMETER
;
2868 init_lsa_String(&name
, argv
[1]);
2871 level
= atoi(argv
[2]);
2874 status
= rpccli_try_samr_connects(cli
, mem_ctx
,
2875 SEC_FLAG_MAXIMUM_ALLOWED
,
2878 if (!NT_STATUS_IS_OK(status
)) {
2882 status
= rpccli_samr_OpenDomain(cli
, mem_ctx
,
2884 SEC_FLAG_MAXIMUM_ALLOWED
,
2888 if (!NT_STATUS_IS_OK(status
))
2892 status
= rpccli_samr_GetDisplayEnumerationIndex(cli
, mem_ctx
,
2898 if (NT_STATUS_IS_OK(status
) ||
2899 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2900 printf("idx: %d (0x%08x)\n", idx
, idx
);
2904 if (is_valid_policy_hnd(&domain_handle
)) {
2905 rpccli_samr_Close(cli
, mem_ctx
, &domain_handle
);
2907 if (is_valid_policy_hnd(&connect_handle
)) {
2908 rpccli_samr_Close(cli
, mem_ctx
, &connect_handle
);
2914 /* List of commands exported by this module */
2916 struct cmd_set samr_commands
[] = {
2920 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user info", "" },
2921 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group info", "" },
2922 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user groups", "" },
2923 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query user aliases", "" },
2924 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query group membership", "" },
2925 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias membership", "" },
2926 { "queryaliasinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query alias info", "" },
2927 { "deletealias", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete an alias", "" },
2928 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2929 { "querydispinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2930 { "querydispinfo3", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query display info", "" },
2931 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query domain info", "" },
2932 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain users", "" },
2933 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domain groups", "" },
2934 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate alias groups", "" },
2935 { "enumdomains", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_domains
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Enumerate domains", "" },
2937 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain user", "" },
2938 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain group", "" },
2939 { "createdomalias", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_alias
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Create domain alias", "" },
2940 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2941 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Look up names", "" },
2942 { "deletedomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_group
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain group", "" },
2943 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Delete domain user", "" },
2944 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Query SAMR security object", "" },
2945 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve domain password info", "" },
2946 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_usrdom_pwinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Retrieve user domain password info", "" },
2948 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Lookup Domain Name", "" },
2949 { "chgpasswd", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2950 { "chgpasswd2", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2951 { "chgpasswd3", RPC_RTYPE_NTSTATUS
, cmd_samr_chgpasswd3
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Change user password", "" },
2952 { "getdispinfoidx", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dispinfo_idx
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Get Display Information Index", "" },
2953 { "setuserinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info", "" },
2954 { "setuserinfo2", RPC_RTYPE_NTSTATUS
, cmd_samr_setuserinfo2
, NULL
, &ndr_table_samr
.syntax_id
, NULL
, "Set user info2", "" },