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
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "rpcclient.h"
28 extern DOM_SID domain_sid
;
30 /****************************************************************************
31 display sam_user_info_7 structure
32 ****************************************************************************/
33 static void display_sam_user_info_7(SAM_USER_INFO_7
*usr
)
37 unistr2_to_ascii(temp
, &usr
->uni_name
, sizeof(temp
)-1);
38 printf("\tUser Name :\t%s\n", temp
);
41 /****************************************************************************
42 display sam_user_info_21 structure
43 ****************************************************************************/
44 static void display_sam_user_info_21(SAM_USER_INFO_21
*usr
)
48 unistr2_to_ascii(temp
, &usr
->uni_user_name
, sizeof(temp
)-1);
49 printf("\tUser Name :\t%s\n", temp
);
51 unistr2_to_ascii(temp
, &usr
->uni_full_name
, sizeof(temp
)-1);
52 printf("\tFull Name :\t%s\n", temp
);
54 unistr2_to_ascii(temp
, &usr
->uni_home_dir
, sizeof(temp
)-1);
55 printf("\tHome Drive :\t%s\n", temp
);
57 unistr2_to_ascii(temp
, &usr
->uni_dir_drive
, sizeof(temp
)-1);
58 printf("\tDir Drive :\t%s\n", temp
);
60 unistr2_to_ascii(temp
, &usr
->uni_profile_path
, sizeof(temp
)-1);
61 printf("\tProfile Path:\t%s\n", temp
);
63 unistr2_to_ascii(temp
, &usr
->uni_logon_script
, sizeof(temp
)-1);
64 printf("\tLogon Script:\t%s\n", temp
);
66 unistr2_to_ascii(temp
, &usr
->uni_acct_desc
, sizeof(temp
)-1);
67 printf("\tDescription :\t%s\n", temp
);
69 unistr2_to_ascii(temp
, &usr
->uni_workstations
, sizeof(temp
)-1);
70 printf("\tWorkstations:\t%s\n", temp
);
72 unistr2_to_ascii(temp
, &usr
->uni_unknown_str
, sizeof(temp
)-1);
73 printf("\tUnknown Str :\t%s\n", temp
);
75 unistr2_to_ascii(temp
, &usr
->uni_munged_dial
, sizeof(temp
)-1);
76 printf("\tRemote Dial :\t%s\n", temp
);
78 printf("\tLogon Time :\t%s\n",
79 http_timestring(nt_time_to_unix(&usr
->logon_time
)));
80 printf("\tLogoff Time :\t%s\n",
81 http_timestring(nt_time_to_unix(&usr
->logoff_time
)));
82 printf("\tKickoff Time :\t%s\n",
83 http_timestring(nt_time_to_unix(&usr
->kickoff_time
)));
84 printf("\tPassword last set Time :\t%s\n",
85 http_timestring(nt_time_to_unix(&usr
->pass_last_set_time
)));
86 printf("\tPassword can change Time :\t%s\n",
87 http_timestring(nt_time_to_unix(&usr
->pass_can_change_time
)));
88 printf("\tPassword must change Time:\t%s\n",
89 http_timestring(nt_time_to_unix(&usr
->pass_must_change_time
)));
91 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
93 printf("\tuser_rid :\t0x%x\n" , usr
->user_rid
); /* User ID */
94 printf("\tgroup_rid:\t0x%x\n" , usr
->group_rid
); /* Group ID */
95 printf("\tacb_info :\t0x%04x\n", usr
->acb_info
); /* Account Control Info */
97 printf("\tfields_present:\t0x%08x\n", usr
->fields_present
); /* 0x00ff ffff */
98 printf("\tlogon_divs:\t%d\n", usr
->logon_divs
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
99 printf("\tbad_password_count:\t0x%08x\n", usr
->bad_password_count
);
100 printf("\tlogon_count:\t0x%08x\n", usr
->logon_count
);
102 printf("\tpadding1[0..7]...\n");
104 if (usr
->ptr_logon_hrs
) {
105 printf("\tlogon_hrs[0..%d]...\n", usr
->logon_hrs
.len
);
109 static const char *display_time(NTTIME nttime
)
111 static fstring string
;
116 int days
, hours
, mins
, secs
;
118 if (nttime
.high
==0 && nttime
.low
==0)
121 if (nttime
.high
==0x80000000 && nttime
.low
==0)
128 high
= high
* (~nttime
.high
);
131 low
= low
/(1000*1000*10);
136 hours
=(sec
- (days
*60*60*24)) / (60*60);
137 mins
=(sec
- (days
*60*60*24) - (hours
*60*60) ) / 60;
138 secs
=sec
- (days
*60*60*24) - (hours
*60*60) - (mins
*60);
140 fstr_sprintf(string
, "%u days, %u hours, %u minutes, %u seconds", days
, hours
, mins
, secs
);
144 static const char* server_role_str(uint32 server_role
)
146 switch(server_role
) {
147 case ROLE_STANDALONE
:
148 return SMB_STRDUP("ROLE_STANDALONE");
150 case ROLE_DOMAIN_MEMBER
:
151 return SMB_STRDUP("ROLE_DOMAIN_MEMBER");
153 case ROLE_DOMAIN_BDC
:
154 return SMB_STRDUP("ROLE_DOMAIN_BDC");
156 case ROLE_DOMAIN_PDC
:
157 return SMB_STRDUP("ROLE_DOMAIN_PDC");
160 return SMB_STRDUP("Unknown -- internal error?");
165 static void display_sam_unk_info_1(SAM_UNK_INFO_1
*info1
)
168 printf("Minimum password length: %d\n", info1
->min_length_password
);
169 printf("Password uniqueness (remember x passwords): %d\n", info1
->password_history
);
171 if(info1
->flag
&&2==2) printf("users must open a session to change password ");
174 printf("password expire in: %s\n", display_time(info1
->expire
));
175 printf("Min password age (allow changing in x days): %s\n", display_time(info1
->min_passwordage
));
178 static void display_sam_unk_info_2(SAM_UNK_INFO_2
*info2
)
182 unistr2_to_ascii(name
, &info2
->uni_domain
, sizeof(name
) - 1);
183 printf("Domain:\t\t%s\n", name
);
185 unistr2_to_ascii(name
, &info2
->uni_server
, sizeof(name
) - 1);
186 printf("Server:\t\t%s\n", name
);
188 unistr2_to_ascii(name
, &info2
->uni_comment
, sizeof(name
) - 1);
189 printf("Comment:\t%s\n", name
);
191 printf("Total Users:\t%d\n", info2
->num_domain_usrs
);
192 printf("Total Groups:\t%d\n", info2
->num_domain_grps
);
193 printf("Total Aliases:\t%d\n", info2
->num_local_grps
);
195 printf("Sequence No:\t%d\n", info2
->seq_num
.low
);
197 printf("Force Logoff:\t%d\n", (int)nt_time_to_unix_abs(&info2
->logout
));
199 printf("Unknown 4:\t0x%x\n", info2
->unknown_4
);
200 printf("Server Role:\t%s\n", server_role_str(info2
->server_role
));
201 printf("Unknown 6:\t0x%x\n", info2
->unknown_6
);
204 static void display_sam_unk_info_7(SAM_UNK_INFO_7
*info7
)
206 printf("Server Role:\t%s\n", server_role_str(info7
->server_role
));
209 static void display_sam_unk_info_8(SAM_UNK_INFO_8
*info8
)
211 printf("Sequence No:\t%d\n", info8
->seq_num
.low
);
212 printf("Domain Create Time:\t%s\n",
213 http_timestring(nt_time_to_unix(&info8
->domain_create_time
)));
217 static void display_sam_unk_info_12(SAM_UNK_INFO_12
*info12
)
219 printf("Bad password lockout duration: %s\n", display_time(info12
->duration
));
220 printf("Reset Lockout after: %s\n", display_time(info12
->reset_count
));
221 printf("Lockout after bad attempts: %d\n", info12
->bad_attempt_lockout
);
224 static void display_sam_info_1(SAM_ENTRY1
*e1
, SAM_STR1
*s1
)
228 printf("index: 0x%x ", e1
->user_idx
);
229 printf("RID: 0x%x ", e1
->rid_user
);
230 printf("acb: 0x%x ", e1
->acb_info
);
232 unistr2_to_ascii(tmp
, &s1
->uni_acct_name
, sizeof(tmp
)-1);
233 printf("Account: %s\t", tmp
);
235 unistr2_to_ascii(tmp
, &s1
->uni_full_name
, sizeof(tmp
)-1);
236 printf("Name: %s\t", tmp
);
238 unistr2_to_ascii(tmp
, &s1
->uni_acct_desc
, sizeof(tmp
)-1);
239 printf("Desc: %s\n", tmp
);
242 static void display_sam_info_2(SAM_ENTRY2
*e2
, SAM_STR2
*s2
)
246 printf("index: 0x%x ", e2
->user_idx
);
247 printf("RID: 0x%x ", e2
->rid_user
);
248 printf("acb: 0x%x ", e2
->acb_info
);
250 unistr2_to_ascii(tmp
, &s2
->uni_srv_name
, sizeof(tmp
)-1);
251 printf("Account: %s\t", tmp
);
253 unistr2_to_ascii(tmp
, &s2
->uni_srv_desc
, sizeof(tmp
)-1);
254 printf("Name: %s\n", tmp
);
258 static void display_sam_info_3(SAM_ENTRY3
*e3
, SAM_STR3
*s3
)
262 printf("index: 0x%x ", e3
->grp_idx
);
263 printf("RID: 0x%x ", e3
->rid_grp
);
264 printf("attr: 0x%x ", e3
->attr
);
266 unistr2_to_ascii(tmp
, &s3
->uni_grp_name
, sizeof(tmp
)-1);
267 printf("Account: %s\t", tmp
);
269 unistr2_to_ascii(tmp
, &s3
->uni_grp_desc
, sizeof(tmp
)-1);
270 printf("Name: %s\n", tmp
);
274 static void display_sam_info_4(SAM_ENTRY4
*e4
, SAM_STR4
*s4
)
278 printf("index: %d ", e4
->user_idx
);
281 for (i
=0; i
<s4
->acct_name
.str_str_len
; i
++)
282 printf("%c", s4
->acct_name
.buffer
[i
]);
287 static void display_sam_info_5(SAM_ENTRY5
*e5
, SAM_STR5
*s5
)
291 printf("index: 0x%x ", e5
->grp_idx
);
294 for (i
=0; i
<s5
->grp_name
.str_str_len
; i
++)
295 printf("%c", s5
->grp_name
.buffer
[i
]);
300 /****************************************************************************
301 Try samr_connect4 first, then samr_conenct if it fails
302 ****************************************************************************/
303 static NTSTATUS
try_samr_connects(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
304 uint32 access_mask
, POLICY_HND
*connect_pol
)
306 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
308 result
= rpccli_samr_connect4(cli
, mem_ctx
, access_mask
, connect_pol
);
309 if (!NT_STATUS_IS_OK(result
)) {
310 result
= rpccli_samr_connect(cli
, mem_ctx
, access_mask
,
316 /**********************************************************************
317 * Query user information
319 static NTSTATUS
cmd_samr_query_user(struct rpc_pipe_client
*cli
,
321 int argc
, const char **argv
)
323 POLICY_HND connect_pol
, domain_pol
, user_pol
;
324 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
325 uint32 info_level
= 21;
326 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
327 SAM_USERINFO_CTR
*user_ctr
;
331 if ((argc
< 2) || (argc
> 4)) {
332 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
336 sscanf(argv
[1], "%i", &user_rid
);
339 sscanf(argv
[2], "%i", &info_level
);
342 sscanf(argv
[3], "%x", &access_mask
);
345 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
348 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
351 if (!NT_STATUS_IS_OK(result
))
354 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
355 MAXIMUM_ALLOWED_ACCESS
,
356 &domain_sid
, &domain_pol
);
358 if (!NT_STATUS_IS_OK(result
))
361 result
= rpccli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
363 user_rid
, &user_pol
);
365 if (!NT_STATUS_IS_OK(result
))
368 ZERO_STRUCT(user_ctr
);
370 result
= rpccli_samr_query_userinfo(cli
, mem_ctx
, &user_pol
,
371 info_level
, &user_ctr
);
373 if (!NT_STATUS_IS_OK(result
))
376 switch (user_ctr
->switch_value
) {
378 display_sam_user_info_21(user_ctr
->info
.id21
);
381 display_sam_user_info_7(user_ctr
->info
.id7
);
384 printf("Unsupported infolevel: %d\n", info_level
);
388 rpccli_samr_close(cli
, mem_ctx
, &user_pol
);
389 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
390 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
396 /****************************************************************************
398 ****************************************************************************/
399 static void display_group_info1(GROUP_INFO1
*info1
)
403 unistr2_to_ascii(temp
, &info1
->uni_acct_name
, sizeof(temp
)-1);
404 printf("\tGroup Name:\t%s\n", temp
);
405 unistr2_to_ascii(temp
, &info1
->uni_acct_desc
, sizeof(temp
)-1);
406 printf("\tDescription:\t%s\n", temp
);
407 printf("\tunk1:%d\n", info1
->unknown_1
);
408 printf("\tNum Members:%d\n", info1
->num_members
);
411 /****************************************************************************
413 ****************************************************************************/
414 static void display_group_info4(GROUP_INFO4
*info4
)
418 unistr2_to_ascii(desc
, &info4
->uni_acct_desc
, sizeof(desc
)-1);
419 printf("\tGroup Description:%s\n", desc
);
422 /****************************************************************************
423 display sam sync structure
424 ****************************************************************************/
425 static void display_group_info_ctr(GROUP_INFO_CTR
*ctr
)
427 switch (ctr
->switch_value1
) {
429 display_group_info1(&ctr
->group
.info1
);
433 display_group_info4(&ctr
->group
.info4
);
439 /***********************************************************************
440 * Query group information
442 static NTSTATUS
cmd_samr_query_group(struct rpc_pipe_client
*cli
,
444 int argc
, const char **argv
)
446 POLICY_HND connect_pol
, domain_pol
, group_pol
;
447 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
448 uint32 info_level
= 1;
449 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
450 GROUP_INFO_CTR
*group_ctr
;
454 if ((argc
< 2) || (argc
> 4)) {
455 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
459 sscanf(argv
[1], "%i", &group_rid
);
462 sscanf(argv
[2], "%i", &info_level
);
465 sscanf(argv
[3], "%x", &access_mask
);
467 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
470 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
473 if (!NT_STATUS_IS_OK(result
))
476 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
477 MAXIMUM_ALLOWED_ACCESS
,
478 &domain_sid
, &domain_pol
);
480 if (!NT_STATUS_IS_OK(result
))
483 result
= rpccli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
485 group_rid
, &group_pol
);
487 if (!NT_STATUS_IS_OK(result
))
490 result
= rpccli_samr_query_groupinfo(cli
, mem_ctx
, &group_pol
,
491 info_level
, &group_ctr
);
492 if (!NT_STATUS_IS_OK(result
)) {
496 display_group_info_ctr(group_ctr
);
498 rpccli_samr_close(cli
, mem_ctx
, &group_pol
);
499 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
500 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
505 /* Query groups a user is a member of */
507 static NTSTATUS
cmd_samr_query_usergroups(struct rpc_pipe_client
*cli
,
509 int argc
, const char **argv
)
511 POLICY_HND connect_pol
,
514 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
517 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
522 if ((argc
< 2) || (argc
> 3)) {
523 printf("Usage: %s rid [access mask]\n", argv
[0]);
527 sscanf(argv
[1], "%i", &user_rid
);
530 sscanf(argv
[2], "%x", &access_mask
);
532 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
535 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
538 if (!NT_STATUS_IS_OK(result
))
541 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
542 MAXIMUM_ALLOWED_ACCESS
,
543 &domain_sid
, &domain_pol
);
545 if (!NT_STATUS_IS_OK(result
))
548 result
= rpccli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
550 user_rid
, &user_pol
);
552 if (!NT_STATUS_IS_OK(result
))
555 result
= rpccli_samr_query_usergroups(cli
, mem_ctx
, &user_pol
,
556 &num_groups
, &user_gids
);
558 if (!NT_STATUS_IS_OK(result
))
561 for (i
= 0; i
< num_groups
; i
++) {
562 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
563 user_gids
[i
].g_rid
, user_gids
[i
].attr
);
566 rpccli_samr_close(cli
, mem_ctx
, &user_pol
);
567 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
568 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
573 /* Query aliases a user is a member of */
575 static NTSTATUS
cmd_samr_query_useraliases(struct rpc_pipe_client
*cli
,
577 int argc
, const char **argv
)
579 POLICY_HND connect_pol
, domain_pol
;
580 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
583 uint32 num_aliases
, *alias_rids
;
584 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
590 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
591 return NT_STATUS_INVALID_PARAMETER
;
597 for (i
=2; i
<argc
; i
++) {
599 if (!string_to_sid(&tmp_sid
, argv
[i
])) {
600 printf("%s is not a legal SID\n", argv
[i
]);
601 return NT_STATUS_INVALID_PARAMETER
;
603 add_sid_to_array(mem_ctx
, &tmp_sid
, &sids
, &num_sids
);
606 sid2
= TALLOC_ARRAY(mem_ctx
, DOM_SID2
, num_sids
);
608 return NT_STATUS_NO_MEMORY
;
610 for (i
=0; i
<num_sids
; i
++) {
611 sid_copy(&sid2
[i
].sid
, &sids
[i
]);
612 sid2
[i
].num_auths
= sid2
[i
].sid
.num_auths
;
615 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
618 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
621 if (!NT_STATUS_IS_OK(result
))
624 if (StrCaseCmp(argv
[1], "domain")==0)
625 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
627 &domain_sid
, &domain_pol
);
628 else if (StrCaseCmp(argv
[1], "builtin")==0)
629 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
634 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv
[0]);
635 return NT_STATUS_INVALID_PARAMETER
;
638 if (!NT_STATUS_IS_OK(result
))
641 result
= rpccli_samr_query_useraliases(cli
, mem_ctx
, &domain_pol
,
643 &num_aliases
, &alias_rids
);
645 if (!NT_STATUS_IS_OK(result
))
648 for (i
= 0; i
< num_aliases
; i
++) {
649 printf("\tgroup rid:[0x%x]\n", alias_rids
[i
]);
652 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
653 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
658 /* Query members of a group */
660 static NTSTATUS
cmd_samr_query_groupmem(struct rpc_pipe_client
*cli
,
662 int argc
, const char **argv
)
664 POLICY_HND connect_pol
, domain_pol
, group_pol
;
665 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
666 uint32 num_members
, *group_rids
, *group_attrs
, group_rid
;
667 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
671 if ((argc
< 2) || (argc
> 3)) {
672 printf("Usage: %s rid [access mask]\n", argv
[0]);
676 sscanf(argv
[1], "%i", &group_rid
);
679 sscanf(argv
[2], "%x", &access_mask
);
681 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
684 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
687 if (!NT_STATUS_IS_OK(result
))
690 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
691 MAXIMUM_ALLOWED_ACCESS
,
692 &domain_sid
, &domain_pol
);
694 if (!NT_STATUS_IS_OK(result
))
697 result
= rpccli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
699 group_rid
, &group_pol
);
701 if (!NT_STATUS_IS_OK(result
))
704 result
= rpccli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
705 &num_members
, &group_rids
,
708 if (!NT_STATUS_IS_OK(result
))
711 for (i
= 0; i
< num_members
; i
++) {
712 printf("\trid:[0x%x] attr:[0x%x]\n", group_rids
[i
],
716 rpccli_samr_close(cli
, mem_ctx
, &group_pol
);
717 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
718 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
723 /* Enumerate domain users */
725 static NTSTATUS
cmd_samr_enum_dom_users(struct rpc_pipe_client
*cli
,
727 int argc
, const char **argv
)
729 POLICY_HND connect_pol
, domain_pol
;
730 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
731 uint32 start_idx
, size
, num_dom_users
, i
;
734 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
735 uint16 acb_mask
= ACB_NORMAL
;
736 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
738 if ((argc
< 1) || (argc
> 3)) {
739 printf("Usage: %s [access_mask] [acb_mask]\n", argv
[0]);
744 sscanf(argv
[1], "%x", &access_mask
);
747 sscanf(argv
[2], "%hx", &acb_mask
);
749 /* Get sam policy handle */
751 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
754 if (!NT_STATUS_IS_OK(result
))
757 got_connect_pol
= True
;
759 /* Get domain policy handle */
761 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
763 &domain_sid
, &domain_pol
);
765 if (!NT_STATUS_IS_OK(result
))
768 got_domain_pol
= True
;
770 /* Enumerate domain users */
776 result
= rpccli_samr_enum_dom_users(
777 cli
, mem_ctx
, &domain_pol
, &start_idx
, acb_mask
,
778 size
, &dom_users
, &dom_rids
, &num_dom_users
);
780 if (NT_STATUS_IS_OK(result
) ||
781 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
783 for (i
= 0; i
< num_dom_users
; i
++)
784 printf("user:[%s] rid:[0x%x]\n",
785 dom_users
[i
], dom_rids
[i
]);
788 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
792 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
795 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
800 /* Enumerate domain groups */
802 static NTSTATUS
cmd_samr_enum_dom_groups(struct rpc_pipe_client
*cli
,
804 int argc
, const char **argv
)
806 POLICY_HND connect_pol
, domain_pol
;
807 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
808 uint32 start_idx
, size
, num_dom_groups
, i
;
809 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
810 struct acct_info
*dom_groups
;
811 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
813 if ((argc
< 1) || (argc
> 2)) {
814 printf("Usage: %s [access_mask]\n", argv
[0]);
819 sscanf(argv
[1], "%x", &access_mask
);
821 /* Get sam policy handle */
823 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
826 if (!NT_STATUS_IS_OK(result
))
829 got_connect_pol
= True
;
831 /* Get domain policy handle */
833 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
835 &domain_sid
, &domain_pol
);
837 if (!NT_STATUS_IS_OK(result
))
840 got_domain_pol
= True
;
842 /* Enumerate domain groups */
848 result
= rpccli_samr_enum_dom_groups(
849 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
850 &dom_groups
, &num_dom_groups
);
852 if (NT_STATUS_IS_OK(result
) ||
853 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
855 for (i
= 0; i
< num_dom_groups
; i
++)
856 printf("group:[%s] rid:[0x%x]\n",
857 dom_groups
[i
].acct_name
,
861 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
865 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
868 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
873 /* Enumerate alias groups */
875 static NTSTATUS
cmd_samr_enum_als_groups(struct rpc_pipe_client
*cli
,
877 int argc
, const char **argv
)
879 POLICY_HND connect_pol
, domain_pol
;
880 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
881 uint32 start_idx
, size
, num_als_groups
, i
;
882 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
883 struct acct_info
*als_groups
;
884 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
886 if ((argc
< 2) || (argc
> 3)) {
887 printf("Usage: %s builtin|domain [access mask]\n", argv
[0]);
892 sscanf(argv
[2], "%x", &access_mask
);
894 /* Get sam policy handle */
896 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
899 if (!NT_STATUS_IS_OK(result
))
902 got_connect_pol
= True
;
904 /* Get domain policy handle */
906 if (StrCaseCmp(argv
[1], "domain")==0)
907 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
909 &domain_sid
, &domain_pol
);
910 else if (StrCaseCmp(argv
[1], "builtin")==0)
911 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
913 &global_sid_Builtin
, &domain_pol
);
917 if (!NT_STATUS_IS_OK(result
))
920 got_domain_pol
= True
;
922 /* Enumerate alias groups */
925 size
= 0xffff; /* Number of groups to retrieve */
928 result
= rpccli_samr_enum_als_groups(
929 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
930 &als_groups
, &num_als_groups
);
932 if (NT_STATUS_IS_OK(result
) ||
933 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
935 for (i
= 0; i
< num_als_groups
; i
++)
936 printf("group:[%s] rid:[0x%x]\n",
937 als_groups
[i
].acct_name
,
940 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
944 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
947 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
952 /* Query alias membership */
954 static NTSTATUS
cmd_samr_query_aliasmem(struct rpc_pipe_client
*cli
,
956 int argc
, const char **argv
)
958 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
959 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
960 uint32 alias_rid
, num_members
, i
;
961 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
964 if ((argc
< 3) || (argc
> 4)) {
965 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
969 sscanf(argv
[2], "%i", &alias_rid
);
972 sscanf(argv
[3], "%x", &access_mask
);
974 /* Open SAMR handle */
976 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
979 if (!NT_STATUS_IS_OK(result
))
982 /* Open handle on domain */
984 if (StrCaseCmp(argv
[1], "domain")==0)
985 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
986 MAXIMUM_ALLOWED_ACCESS
,
987 &domain_sid
, &domain_pol
);
988 else if (StrCaseCmp(argv
[1], "builtin")==0)
989 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
990 MAXIMUM_ALLOWED_ACCESS
,
991 &global_sid_Builtin
, &domain_pol
);
995 if (!NT_STATUS_IS_OK(result
))
998 /* Open handle on alias */
1000 result
= rpccli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
1002 alias_rid
, &alias_pol
);
1003 if (!NT_STATUS_IS_OK(result
))
1006 result
= rpccli_samr_query_aliasmem(cli
, mem_ctx
, &alias_pol
,
1007 &num_members
, &alias_sids
);
1009 if (!NT_STATUS_IS_OK(result
))
1012 for (i
= 0; i
< num_members
; i
++) {
1015 sid_to_string(sid_str
, &alias_sids
[i
]);
1016 printf("\tsid:[%s]\n", sid_str
);
1019 rpccli_samr_close(cli
, mem_ctx
, &alias_pol
);
1020 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1021 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1026 /* Query display info */
1028 static NTSTATUS
cmd_samr_query_dispinfo(struct rpc_pipe_client
*cli
,
1029 TALLOC_CTX
*mem_ctx
,
1030 int argc
, const char **argv
)
1032 POLICY_HND connect_pol
, domain_pol
;
1033 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1034 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
, i
;
1035 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1036 uint32 info_level
= 1;
1037 SAM_DISPINFO_CTR ctr
;
1038 SAM_DISPINFO_1 info1
;
1039 SAM_DISPINFO_2 info2
;
1040 SAM_DISPINFO_3 info3
;
1041 SAM_DISPINFO_4 info4
;
1042 SAM_DISPINFO_5 info5
;
1044 BOOL got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1047 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1048 return NT_STATUS_OK
;
1052 sscanf(argv
[1], "%i", &info_level
);
1055 sscanf(argv
[2], "%i", &start_idx
);
1058 sscanf(argv
[3], "%i", &max_entries
);
1063 sscanf(argv
[4], "%i", &max_size
);
1068 sscanf(argv
[5], "%x", &access_mask
);
1070 /* Get sam policy handle */
1072 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1075 if (!NT_STATUS_IS_OK(result
))
1078 /* Get domain policy handle */
1080 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1082 &domain_sid
, &domain_pol
);
1084 if (!NT_STATUS_IS_OK(result
))
1087 /* Query display info */
1092 switch (info_level
) {
1095 ctr
.sam
.info1
= &info1
;
1099 ctr
.sam
.info2
= &info2
;
1103 ctr
.sam
.info3
= &info3
;
1107 ctr
.sam
.info4
= &info4
;
1111 ctr
.sam
.info5
= &info5
;
1119 get_query_dispinfo_params(
1120 loop_count
, &max_entries
, &max_size
);
1122 result
= rpccli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
1123 &start_idx
, info_level
,
1124 &num_entries
, max_entries
,
1129 if (NT_STATUS_IS_ERR(result
))
1132 if (num_entries
== 0)
1135 for (i
= 0; i
< num_entries
; i
++) {
1136 switch (info_level
) {
1138 display_sam_info_1(&ctr
.sam
.info1
->sam
[i
], &ctr
.sam
.info1
->str
[i
]);
1141 display_sam_info_2(&ctr
.sam
.info2
->sam
[i
], &ctr
.sam
.info2
->str
[i
]);
1144 display_sam_info_3(&ctr
.sam
.info3
->sam
[i
], &ctr
.sam
.info3
->str
[i
]);
1147 display_sam_info_4(&ctr
.sam
.info4
->sam
[i
], &ctr
.sam
.info4
->str
[i
]);
1150 display_sam_info_5(&ctr
.sam
.info5
->sam
[i
], &ctr
.sam
.info5
->str
[i
]);
1154 } while ( NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1156 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1157 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1162 /* Query domain info */
1164 static NTSTATUS
cmd_samr_query_dominfo(struct rpc_pipe_client
*cli
,
1165 TALLOC_CTX
*mem_ctx
,
1166 int argc
, const char **argv
)
1168 POLICY_HND connect_pol
, domain_pol
;
1169 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1170 uint32 switch_level
= 2;
1171 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1175 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1176 return NT_STATUS_OK
;
1180 sscanf(argv
[1], "%i", &switch_level
);
1183 sscanf(argv
[2], "%x", &access_mask
);
1185 /* Get sam policy handle */
1187 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1190 if (!NT_STATUS_IS_OK(result
))
1193 /* Get domain policy handle */
1195 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1197 &domain_sid
, &domain_pol
);
1199 if (!NT_STATUS_IS_OK(result
))
1202 /* Query domain info */
1204 result
= rpccli_samr_query_dom_info(cli
, mem_ctx
, &domain_pol
,
1205 switch_level
, &ctr
);
1207 if (!NT_STATUS_IS_OK(result
))
1210 /* Display domain info */
1212 switch (switch_level
) {
1214 display_sam_unk_info_1(&ctr
.info
.inf1
);
1217 display_sam_unk_info_2(&ctr
.info
.inf2
);
1220 display_sam_unk_info_7(&ctr
.info
.inf7
);
1223 display_sam_unk_info_8(&ctr
.info
.inf8
);
1226 display_sam_unk_info_12(&ctr
.info
.inf12
);
1229 printf("cannot display domain info for switch value %d\n",
1236 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1237 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1241 /* Create domain user */
1243 static NTSTATUS
cmd_samr_create_dom_user(struct rpc_pipe_client
*cli
,
1244 TALLOC_CTX
*mem_ctx
,
1245 int argc
, const char **argv
)
1247 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1248 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1249 const char *acct_name
;
1251 uint32 unknown
, user_rid
;
1252 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1254 if ((argc
< 2) || (argc
> 3)) {
1255 printf("Usage: %s username [access mask]\n", argv
[0]);
1256 return NT_STATUS_OK
;
1259 acct_name
= argv
[1];
1262 sscanf(argv
[2], "%x", &access_mask
);
1264 /* Get sam policy handle */
1266 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1269 if (!NT_STATUS_IS_OK(result
))
1272 /* Get domain policy handle */
1274 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1276 &domain_sid
, &domain_pol
);
1278 if (!NT_STATUS_IS_OK(result
))
1281 /* Create domain user */
1283 acb_info
= ACB_NORMAL
;
1284 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
1286 result
= rpccli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
1287 acct_name
, acb_info
, unknown
,
1288 &user_pol
, &user_rid
);
1290 if (!NT_STATUS_IS_OK(result
))
1293 result
= rpccli_samr_close(cli
, mem_ctx
, &user_pol
);
1294 if (!NT_STATUS_IS_OK(result
)) goto done
;
1296 result
= rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1297 if (!NT_STATUS_IS_OK(result
)) goto done
;
1299 result
= rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1300 if (!NT_STATUS_IS_OK(result
)) goto done
;
1306 /* Create domain group */
1308 static NTSTATUS
cmd_samr_create_dom_group(struct rpc_pipe_client
*cli
,
1309 TALLOC_CTX
*mem_ctx
,
1310 int argc
, const char **argv
)
1312 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1313 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1314 const char *grp_name
;
1315 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1317 if ((argc
< 2) || (argc
> 3)) {
1318 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1319 return NT_STATUS_OK
;
1325 sscanf(argv
[2], "%x", &access_mask
);
1327 /* Get sam policy handle */
1329 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1332 if (!NT_STATUS_IS_OK(result
))
1335 /* Get domain policy handle */
1337 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1339 &domain_sid
, &domain_pol
);
1341 if (!NT_STATUS_IS_OK(result
))
1344 /* Create domain user */
1346 result
= rpccli_samr_create_dom_group(cli
, mem_ctx
, &domain_pol
,
1347 grp_name
, MAXIMUM_ALLOWED_ACCESS
,
1350 if (!NT_STATUS_IS_OK(result
))
1353 result
= rpccli_samr_close(cli
, mem_ctx
, &group_pol
);
1354 if (!NT_STATUS_IS_OK(result
)) goto done
;
1356 result
= rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1357 if (!NT_STATUS_IS_OK(result
)) goto done
;
1359 result
= rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1360 if (!NT_STATUS_IS_OK(result
)) goto done
;
1366 /* Lookup sam names */
1368 static NTSTATUS
cmd_samr_lookup_names(struct rpc_pipe_client
*cli
,
1369 TALLOC_CTX
*mem_ctx
,
1370 int argc
, const char **argv
)
1372 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1373 POLICY_HND connect_pol
, domain_pol
;
1374 uint32 flags
= 0x000003e8; /* Unknown */
1375 uint32 num_rids
, num_names
, *name_types
, *rids
;
1380 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1381 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1382 printf("or check on the builtin SID: S-1-5-32\n");
1383 return NT_STATUS_OK
;
1386 /* Get sam policy and domain handles */
1388 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1391 if (!NT_STATUS_IS_OK(result
))
1394 if (StrCaseCmp(argv
[1], "domain")==0)
1395 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1396 MAXIMUM_ALLOWED_ACCESS
,
1397 &domain_sid
, &domain_pol
);
1398 else if (StrCaseCmp(argv
[1], "builtin")==0)
1399 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1400 MAXIMUM_ALLOWED_ACCESS
,
1401 &global_sid_Builtin
, &domain_pol
);
1403 return NT_STATUS_OK
;
1405 if (!NT_STATUS_IS_OK(result
))
1410 num_names
= argc
- 2;
1411 names
= TALLOC_ARRAY(mem_ctx
, const char *, num_names
);
1413 for (i
= 0; i
< argc
- 2; i
++)
1414 names
[i
] = argv
[i
+ 2];
1416 result
= rpccli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1417 flags
, num_names
, names
,
1418 &num_rids
, &rids
, &name_types
);
1420 if (!NT_STATUS_IS_OK(result
))
1423 /* Display results */
1425 for (i
= 0; i
< num_names
; i
++)
1426 printf("name %s: 0x%x (%d)\n", names
[i
], rids
[i
],
1429 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1430 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1435 /* Lookup sam rids */
1437 static NTSTATUS
cmd_samr_lookup_rids(struct rpc_pipe_client
*cli
,
1438 TALLOC_CTX
*mem_ctx
,
1439 int argc
, const char **argv
)
1441 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1442 POLICY_HND connect_pol
, domain_pol
;
1443 uint32 num_rids
, num_names
, *rids
, *name_types
;
1448 printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1449 return NT_STATUS_OK
;
1452 /* Get sam policy and domain handles */
1454 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1457 if (!NT_STATUS_IS_OK(result
))
1460 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1461 MAXIMUM_ALLOWED_ACCESS
,
1462 &domain_sid
, &domain_pol
);
1464 if (!NT_STATUS_IS_OK(result
))
1469 num_rids
= argc
- 1;
1470 rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
);
1472 for (i
= 0; i
< argc
- 1; i
++)
1473 sscanf(argv
[i
+ 1], "%i", &rids
[i
]);
1475 result
= rpccli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
, num_rids
, rids
,
1476 &num_names
, &names
, &name_types
);
1478 if (!NT_STATUS_IS_OK(result
) &&
1479 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1482 /* Display results */
1484 for (i
= 0; i
< num_names
; i
++)
1485 printf("rid 0x%x: %s (%d)\n", rids
[i
], names
[i
], name_types
[i
]);
1487 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1488 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1493 /* Delete domain user */
1495 static NTSTATUS
cmd_samr_delete_dom_user(struct rpc_pipe_client
*cli
,
1496 TALLOC_CTX
*mem_ctx
,
1497 int argc
, const char **argv
)
1499 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1500 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1501 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1503 if ((argc
< 2) || (argc
> 3)) {
1504 printf("Usage: %s username\n", argv
[0]);
1505 return NT_STATUS_OK
;
1509 sscanf(argv
[2], "%x", &access_mask
);
1511 /* Get sam policy and domain handles */
1513 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1516 if (!NT_STATUS_IS_OK(result
))
1519 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1520 MAXIMUM_ALLOWED_ACCESS
,
1521 &domain_sid
, &domain_pol
);
1523 if (!NT_STATUS_IS_OK(result
))
1526 /* Get handle on user */
1529 uint32
*user_rids
, num_rids
, *name_types
;
1530 uint32 flags
= 0x000003e8; /* Unknown */
1532 result
= rpccli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1533 flags
, 1, (const char **)&argv
[1],
1534 &num_rids
, &user_rids
,
1537 if (!NT_STATUS_IS_OK(result
))
1540 result
= rpccli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1542 user_rids
[0], &user_pol
);
1544 if (!NT_STATUS_IS_OK(result
))
1550 result
= rpccli_samr_delete_dom_user(cli
, mem_ctx
, &user_pol
);
1552 if (!NT_STATUS_IS_OK(result
))
1555 /* Display results */
1557 rpccli_samr_close(cli
, mem_ctx
, &user_pol
);
1558 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1559 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1565 /**********************************************************************
1566 * Query user security object
1568 static NTSTATUS
cmd_samr_query_sec_obj(struct rpc_pipe_client
*cli
,
1569 TALLOC_CTX
*mem_ctx
,
1570 int argc
, const char **argv
)
1572 POLICY_HND connect_pol
, domain_pol
, user_pol
, *pol
;
1573 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1574 uint32 info_level
= 4;
1576 uint32 user_rid
= 0;
1577 TALLOC_CTX
*ctx
= NULL
;
1578 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
1579 BOOL domain
= False
;
1581 ctx
=talloc_init("cmd_samr_query_sec_obj");
1583 if ((argc
< 1) || (argc
> 2)) {
1584 printf("Usage: %s [rid|-d]\n", argv
[0]);
1585 printf("\tSpecify rid for security on user, -d for security on domain\n");
1586 return NT_STATUS_OK
;
1590 if (strcmp(argv
[1], "-d") == 0)
1593 sscanf(argv
[1], "%i", &user_rid
);
1596 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
1598 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1601 if (!NT_STATUS_IS_OK(result
))
1604 if (domain
|| user_rid
)
1605 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1606 MAXIMUM_ALLOWED_ACCESS
,
1607 &domain_sid
, &domain_pol
);
1609 if (!NT_STATUS_IS_OK(result
))
1613 result
= rpccli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1614 MAXIMUM_ALLOWED_ACCESS
,
1615 user_rid
, &user_pol
);
1617 if (!NT_STATUS_IS_OK(result
))
1620 /* Pick which query pol to use */
1630 /* Query SAM security object */
1632 result
= rpccli_samr_query_sec_obj(cli
, mem_ctx
, pol
, info_level
, ctx
,
1635 if (!NT_STATUS_IS_OK(result
))
1638 display_sec_desc(sec_desc_buf
->sec
);
1640 rpccli_samr_close(cli
, mem_ctx
, &user_pol
);
1641 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1642 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1644 talloc_destroy(ctx
);
1648 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct rpc_pipe_client
*cli
,
1649 TALLOC_CTX
*mem_ctx
,
1650 int argc
, const char **argv
)
1652 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1653 uint16 unk_0
, unk_1
;
1656 printf("Usage: %s\n", argv
[0]);
1657 return NT_STATUS_OK
;
1660 result
= rpccli_samr_get_dom_pwinfo(cli
, mem_ctx
, &unk_0
, &unk_1
) ;
1662 if (NT_STATUS_IS_OK(result
)) {
1663 printf("unk_0 = 0x%08x\n", unk_0
);
1664 printf("unk_1 = 0x%08x\n", unk_1
);
1670 /* Look up domain name */
1672 static NTSTATUS
cmd_samr_lookup_domain(struct rpc_pipe_client
*cli
,
1673 TALLOC_CTX
*mem_ctx
,
1674 int argc
, const char **argv
)
1676 POLICY_HND connect_pol
, domain_pol
;
1677 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1678 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1679 fstring domain_name
,sid_string
;
1683 printf("Usage: %s domain_name\n", argv
[0]);
1684 return NT_STATUS_OK
;
1687 sscanf(argv
[1], "%s", domain_name
);
1689 result
= try_samr_connects(cli
, mem_ctx
, access_mask
, &connect_pol
);
1691 if (!NT_STATUS_IS_OK(result
))
1694 result
= rpccli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1695 access_mask
, &domain_sid
, &domain_pol
);
1697 if (!NT_STATUS_IS_OK(result
))
1700 result
= rpccli_samr_lookup_domain(
1701 cli
, mem_ctx
, &connect_pol
, domain_name
, &sid
);
1703 sid_to_string(sid_string
,&sid
);
1705 if (NT_STATUS_IS_OK(result
))
1706 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
1707 domain_name
,sid_string
);
1709 rpccli_samr_close(cli
, mem_ctx
, &domain_pol
);
1710 rpccli_samr_close(cli
, mem_ctx
, &connect_pol
);
1716 /* List of commands exported by this module */
1718 struct cmd_set samr_commands
[] = {
1722 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, PI_SAMR
, NULL
, "Query user info", "" },
1723 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, PI_SAMR
, NULL
, "Query group info", "" },
1724 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, PI_SAMR
, NULL
, "Query user groups", "" },
1725 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, PI_SAMR
, NULL
, "Query user aliases", "" },
1726 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, PI_SAMR
, NULL
, "Query group membership", "" },
1727 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, PI_SAMR
, NULL
, "Query alias membership", "" },
1728 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, PI_SAMR
, NULL
, "Query display info", "" },
1729 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, PI_SAMR
, NULL
, "Query domain info", "" },
1730 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, PI_SAMR
, NULL
, "Enumerate domain users", "" },
1731 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, PI_SAMR
, NULL
, "Enumerate domain groups", "" },
1732 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, PI_SAMR
, NULL
, "Enumerate alias groups", "" },
1734 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, PI_SAMR
, NULL
, "Create domain user", "" },
1735 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, PI_SAMR
, NULL
, "Create domain group", "" },
1736 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, PI_SAMR
, NULL
, "Look up names", "" },
1737 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, PI_SAMR
, NULL
, "Look up names", "" },
1738 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, PI_SAMR
, NULL
, "Delete domain user", "" },
1739 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, PI_SAMR
, NULL
, "Query SAMR security object", "" },
1740 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, PI_SAMR
, NULL
, "Retrieve domain password info", "" },
1742 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, PI_SAMR
, NULL
, "Lookup Domain Name", "" },