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_21 structure
32 ****************************************************************************/
33 static void display_sam_user_info_21(SAM_USER_INFO_21
*usr
)
37 unistr2_to_ascii(temp
, &usr
->uni_user_name
, sizeof(temp
)-1);
38 printf("\tUser Name :\t%s\n", temp
);
40 unistr2_to_ascii(temp
, &usr
->uni_full_name
, sizeof(temp
)-1);
41 printf("\tFull Name :\t%s\n", temp
);
43 unistr2_to_ascii(temp
, &usr
->uni_home_dir
, sizeof(temp
)-1);
44 printf("\tHome Drive :\t%s\n", temp
);
46 unistr2_to_ascii(temp
, &usr
->uni_dir_drive
, sizeof(temp
)-1);
47 printf("\tDir Drive :\t%s\n", temp
);
49 unistr2_to_ascii(temp
, &usr
->uni_profile_path
, sizeof(temp
)-1);
50 printf("\tProfile Path:\t%s\n", temp
);
52 unistr2_to_ascii(temp
, &usr
->uni_logon_script
, sizeof(temp
)-1);
53 printf("\tLogon Script:\t%s\n", temp
);
55 unistr2_to_ascii(temp
, &usr
->uni_acct_desc
, sizeof(temp
)-1);
56 printf("\tDescription :\t%s\n", temp
);
58 unistr2_to_ascii(temp
, &usr
->uni_workstations
, sizeof(temp
)-1);
59 printf("\tWorkstations:\t%s\n", temp
);
61 unistr2_to_ascii(temp
, &usr
->uni_unknown_str
, sizeof(temp
)-1);
62 printf("\tUnknown Str :\t%s\n", temp
);
64 unistr2_to_ascii(temp
, &usr
->uni_munged_dial
, sizeof(temp
)-1);
65 printf("\tRemote Dial :\t%s\n", temp
);
67 printf("\tLogon Time :\t%s\n",
68 http_timestring(nt_time_to_unix(&usr
->logon_time
)));
69 printf("\tLogoff Time :\t%s\n",
70 http_timestring(nt_time_to_unix(&usr
->logoff_time
)));
71 printf("\tKickoff Time :\t%s\n",
72 http_timestring(nt_time_to_unix(&usr
->kickoff_time
)));
73 printf("\tPassword last set Time :\t%s\n",
74 http_timestring(nt_time_to_unix(&usr
->pass_last_set_time
)));
75 printf("\tPassword can change Time :\t%s\n",
76 http_timestring(nt_time_to_unix(&usr
->pass_can_change_time
)));
77 printf("\tPassword must change Time:\t%s\n",
78 http_timestring(nt_time_to_unix(&usr
->pass_must_change_time
)));
80 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
82 printf("\tuser_rid :\t0x%x\n" , usr
->user_rid
); /* User ID */
83 printf("\tgroup_rid:\t0x%x\n" , usr
->group_rid
); /* Group ID */
84 printf("\tacb_info :\t0x%04x\n", usr
->acb_info
); /* Account Control Info */
86 printf("\tunknown_3:\t0x%08x\n", usr
->unknown_3
); /* 0x00ff ffff */
87 printf("\tlogon_divs:\t%d\n", usr
->logon_divs
); /* 0x0000 00a8 which is 168 which is num hrs in a week */
88 printf("\tunknown_5:\t0x%08x\n", usr
->unknown_5
); /* 0x0002 0000 */
90 printf("\tpadding1[0..7]...\n");
92 if (usr
->ptr_logon_hrs
) {
93 printf("\tlogon_hrs[0..%d]...\n", usr
->logon_hrs
.len
);
97 static char *display_time(NTTIME nttime
)
99 static fstring string
;
104 int days
, hours
, mins
, secs
;
106 if (nttime
.high
==0 && nttime
.low
==0)
109 if (nttime
.high
==0x80000000 && nttime
.low
==0)
116 high
= high
* (~nttime
.high
);
119 low
= low
/(1000*1000*10);
124 hours
=(sec
- (days
*60*60*24)) / (60*60);
125 mins
=(sec
- (days
*60*60*24) - (hours
*60*60) ) / 60;
126 secs
=sec
- (days
*60*60*24) - (hours
*60*60) - (mins
*60);
128 snprintf(string
, sizeof(string
)-1, "%u days, %u hours, %u minutes, %u seconds", days
, hours
, mins
, secs
);
132 static void display_sam_unk_info_1(SAM_UNK_INFO_1
*info1
)
135 printf("Minimum password length: %d\n", info1
->min_length_password
);
136 printf("Password uniqueness (remember x passwords): %d\n", info1
->password_history
);
138 if(info1
->flag
&&2==2) printf("users must open a session to change password ");
141 printf("password expire in: %s\n", display_time(info1
->expire
));
142 printf("Min password age (allow changing in x days): %s\n", display_time(info1
->min_passwordage
));
145 static void display_sam_unk_info_2(SAM_UNK_INFO_2
*info2
)
149 unistr2_to_ascii(name
, &info2
->uni_domain
, sizeof(name
) - 1);
150 printf("Domain:\t%s\n", name
);
152 unistr2_to_ascii(name
, &info2
->uni_server
, sizeof(name
) - 1);
153 printf("Server:\t%s\n", name
);
155 printf("Total Users:\t%d\n", info2
->num_domain_usrs
);
156 printf("Total Groups:\t%d\n", info2
->num_domain_grps
);
157 printf("Total Aliases:\t%d\n", info2
->num_local_grps
);
159 printf("Sequence No:\t%d\n", info2
->seq_num
);
161 printf("Unknown 0:\t0x%x\n", info2
->unknown_0
);
162 printf("Unknown 1:\t0x%x\n", info2
->unknown_1
);
163 printf("Unknown 2:\t0x%x\n", info2
->unknown_2
);
164 printf("Unknown 3:\t0x%x\n", info2
->unknown_3
);
165 printf("Unknown 4:\t0x%x\n", info2
->unknown_4
);
166 printf("Unknown 5:\t0x%x\n", info2
->unknown_5
);
167 printf("Unknown 6:\t0x%x\n", info2
->unknown_6
);
170 static void display_sam_info_1(SAM_ENTRY1
*e1
, SAM_STR1
*s1
)
174 printf("index: 0x%x ", e1
->user_idx
);
175 printf("RID: 0x%x ", e1
->rid_user
);
176 printf("acb: 0x%x ", e1
->acb_info
);
178 unistr2_to_ascii(tmp
, &s1
->uni_acct_name
, sizeof(tmp
)-1);
179 printf("Account: %s\t", tmp
);
181 unistr2_to_ascii(tmp
, &s1
->uni_full_name
, sizeof(tmp
)-1);
182 printf("Name: %s\t", tmp
);
184 unistr2_to_ascii(tmp
, &s1
->uni_acct_desc
, sizeof(tmp
)-1);
185 printf("Desc: %s\n", tmp
);
188 static void display_sam_info_2(SAM_ENTRY2
*e2
, SAM_STR2
*s2
)
192 printf("index: 0x%x ", e2
->user_idx
);
193 printf("RID: 0x%x ", e2
->rid_user
);
194 printf("acb: 0x%x ", e2
->acb_info
);
196 unistr2_to_ascii(tmp
, &s2
->uni_srv_name
, sizeof(tmp
)-1);
197 printf("Account: %s\t", tmp
);
199 unistr2_to_ascii(tmp
, &s2
->uni_srv_desc
, sizeof(tmp
)-1);
200 printf("Name: %s\n", tmp
);
204 static void display_sam_info_3(SAM_ENTRY3
*e3
, SAM_STR3
*s3
)
208 printf("index: 0x%x ", e3
->grp_idx
);
209 printf("RID: 0x%x ", e3
->rid_grp
);
210 printf("attr: 0x%x ", e3
->attr
);
212 unistr2_to_ascii(tmp
, &s3
->uni_grp_name
, sizeof(tmp
)-1);
213 printf("Account: %s\t", tmp
);
215 unistr2_to_ascii(tmp
, &s3
->uni_grp_desc
, sizeof(tmp
)-1);
216 printf("Name: %s\n", tmp
);
220 static void display_sam_info_4(SAM_ENTRY4
*e4
, SAM_STR4
*s4
)
224 printf("index: %d ", e4
->user_idx
);
227 for (i
=0; i
<s4
->acct_name
.str_str_len
; i
++)
228 printf("%c", s4
->acct_name
.buffer
[i
]);
233 static void display_sam_info_5(SAM_ENTRY5
*e5
, SAM_STR5
*s5
)
237 printf("index: 0x%x ", e5
->grp_idx
);
240 for (i
=0; i
<s5
->grp_name
.str_str_len
; i
++)
241 printf("%c", s5
->grp_name
.buffer
[i
]);
246 /**********************************************************************
247 * Query user information
249 static NTSTATUS
cmd_samr_query_user(struct cli_state
*cli
,
251 int argc
, char **argv
)
253 POLICY_HND connect_pol
, domain_pol
, user_pol
;
254 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
255 uint32 info_level
= 21;
256 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
257 SAM_USERINFO_CTR
*user_ctr
;
261 if ((argc
< 2) || (argc
> 4)) {
262 printf("Usage: %s rid [info level] [access mask] \n", argv
[0]);
266 sscanf(argv
[1], "%i", &user_rid
);
269 sscanf(argv
[2], "%i", &info_level
);
272 sscanf(argv
[3], "%x", &access_mask
);
275 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
278 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
281 if (!NT_STATUS_IS_OK(result
))
284 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
285 MAXIMUM_ALLOWED_ACCESS
,
286 &domain_sid
, &domain_pol
);
288 if (!NT_STATUS_IS_OK(result
))
291 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
293 user_rid
, &user_pol
);
295 if (!NT_STATUS_IS_OK(result
))
298 ZERO_STRUCT(user_ctr
);
300 result
= cli_samr_query_userinfo(cli
, mem_ctx
, &user_pol
,
301 info_level
, &user_ctr
);
303 if (!NT_STATUS_IS_OK(result
))
306 display_sam_user_info_21(user_ctr
->info
.id21
);
312 /****************************************************************************
314 ****************************************************************************/
315 static void display_group_info1(GROUP_INFO1
*info1
)
319 unistr2_to_ascii(temp
, &info1
->uni_acct_name
, sizeof(temp
)-1);
320 printf("\tGroup Name:\t%s\n", temp
);
321 unistr2_to_ascii(temp
, &info1
->uni_acct_desc
, sizeof(temp
)-1);
322 printf("\tDescription:\t%s\n", temp
);
323 printf("\tunk1:%d\n", info1
->unknown_1
);
324 printf("\tNum Members:%d\n", info1
->num_members
);
327 /****************************************************************************
329 ****************************************************************************/
330 static void display_group_info4(GROUP_INFO4
*info4
)
334 unistr2_to_ascii(desc
, &info4
->uni_acct_desc
, sizeof(desc
)-1);
335 printf("\tGroup Description:%s\n", desc
);
338 /****************************************************************************
339 display sam sync structure
340 ****************************************************************************/
341 static void display_group_info_ctr(GROUP_INFO_CTR
*ctr
)
343 switch (ctr
->switch_value1
) {
345 display_group_info1(&ctr
->group
.info1
);
349 display_group_info4(&ctr
->group
.info4
);
355 /***********************************************************************
356 * Query group information
358 static NTSTATUS
cmd_samr_query_group(struct cli_state
*cli
,
360 int argc
, char **argv
)
362 POLICY_HND connect_pol
, domain_pol
, group_pol
;
363 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
364 uint32 info_level
= 1;
365 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
366 GROUP_INFO_CTR group_ctr
;
370 if ((argc
< 2) || (argc
> 4)) {
371 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
375 sscanf(argv
[1], "%i", &group_rid
);
378 sscanf(argv
[2], "%i", &info_level
);
381 sscanf(argv
[3], "%x", &access_mask
);
383 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
386 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
389 if (!NT_STATUS_IS_OK(result
))
392 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
393 MAXIMUM_ALLOWED_ACCESS
,
394 &domain_sid
, &domain_pol
);
396 if (!NT_STATUS_IS_OK(result
))
399 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
401 group_rid
, &group_pol
);
403 if (!NT_STATUS_IS_OK(result
))
406 ZERO_STRUCT(group_ctr
);
408 result
= cli_samr_query_groupinfo(cli
, mem_ctx
, &group_pol
,
409 info_level
, &group_ctr
);
410 if (!NT_STATUS_IS_OK(result
)) {
414 display_group_info_ctr(&group_ctr
);
420 /* Query groups a user is a member of */
422 static NTSTATUS
cmd_samr_query_usergroups(struct cli_state
*cli
,
424 int argc
, char **argv
)
426 POLICY_HND connect_pol
,
429 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
432 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
437 if ((argc
< 2) || (argc
> 3)) {
438 printf("Usage: %s rid [access mask]\n", argv
[0]);
442 sscanf(argv
[1], "%i", &user_rid
);
445 sscanf(argv
[2], "%x", &access_mask
);
447 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
450 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
453 if (!NT_STATUS_IS_OK(result
))
456 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
457 MAXIMUM_ALLOWED_ACCESS
,
458 &domain_sid
, &domain_pol
);
460 if (!NT_STATUS_IS_OK(result
))
463 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
465 user_rid
, &user_pol
);
467 if (!NT_STATUS_IS_OK(result
))
470 result
= cli_samr_query_usergroups(cli
, mem_ctx
, &user_pol
,
471 &num_groups
, &user_gids
);
473 if (!NT_STATUS_IS_OK(result
))
476 for (i
= 0; i
< num_groups
; i
++) {
477 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
478 user_gids
[i
].g_rid
, user_gids
[i
].attr
);
485 /* Query aliases a user is a member of */
487 static NTSTATUS
cmd_samr_query_useraliases(struct cli_state
*cli
,
489 int argc
, char **argv
)
491 POLICY_HND connect_pol
, domain_pol
;
492 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
493 uint32 user_rid
, num_aliases
, *alias_rids
;
494 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
499 DOM_SID global_sid_Builtin
;
501 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
503 if ((argc
< 3) || (argc
> 4)) {
504 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
508 sscanf(argv
[2], "%i", &user_rid
);
511 sscanf(argv
[3], "%x", &access_mask
);
513 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
516 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
519 if (!NT_STATUS_IS_OK(result
))
522 if (StrCaseCmp(argv
[1], "domain")==0)
523 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
525 &domain_sid
, &domain_pol
);
526 else if (StrCaseCmp(argv
[1], "builtin")==0)
527 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
529 &global_sid_Builtin
, &domain_pol
);
533 if (!NT_STATUS_IS_OK(result
))
536 sid_copy(&tmp_sid
, &domain_sid
);
537 sid_append_rid(&tmp_sid
, user_rid
);
538 init_dom_sid2(&sid
, &tmp_sid
);
540 result
= cli_samr_query_useraliases(cli
, mem_ctx
, &domain_pol
, 1, &sid
, &num_aliases
, &alias_rids
);
542 if (!NT_STATUS_IS_OK(result
))
545 for (i
= 0; i
< num_aliases
; i
++) {
546 printf("\tgroup rid:[0x%x]\n", alias_rids
[i
]);
553 /* Query members of a group */
555 static NTSTATUS
cmd_samr_query_groupmem(struct cli_state
*cli
,
557 int argc
, char **argv
)
559 POLICY_HND connect_pol
, domain_pol
, group_pol
;
560 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
561 uint32 num_members
, *group_rids
, *group_attrs
, group_rid
;
562 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
566 if ((argc
< 2) || (argc
> 3)) {
567 printf("Usage: %s rid [access mask]\n", argv
[0]);
571 sscanf(argv
[1], "%i", &group_rid
);
574 sscanf(argv
[2], "%x", &access_mask
);
576 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
579 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
582 if (!NT_STATUS_IS_OK(result
))
585 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
586 MAXIMUM_ALLOWED_ACCESS
,
587 &domain_sid
, &domain_pol
);
589 if (!NT_STATUS_IS_OK(result
))
592 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
594 group_rid
, &group_pol
);
596 if (!NT_STATUS_IS_OK(result
))
599 result
= cli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
600 &num_members
, &group_rids
,
603 if (!NT_STATUS_IS_OK(result
))
606 for (i
= 0; i
< num_members
; i
++) {
607 printf("\trid:[0x%x] attr:[0x%x]\n", group_rids
[i
],
615 /* Enumerate domain groups */
617 static NTSTATUS
cmd_samr_enum_dom_groups(struct cli_state
*cli
,
619 int argc
, char **argv
)
621 POLICY_HND connect_pol
, domain_pol
;
622 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
623 uint32 start_idx
, size
, num_dom_groups
, i
;
624 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
625 struct acct_info
*dom_groups
;
626 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
628 if ((argc
< 1) || (argc
> 2)) {
629 printf("Usage: %s [access_mask]\n", argv
[0]);
634 sscanf(argv
[1], "%x", &access_mask
);
636 /* Get sam policy handle */
638 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
641 if (!NT_STATUS_IS_OK(result
))
644 got_connect_pol
= True
;
646 /* Get domain policy handle */
648 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
650 &domain_sid
, &domain_pol
);
652 if (!NT_STATUS_IS_OK(result
))
655 got_domain_pol
= True
;
657 /* Enumerate domain groups */
663 result
= cli_samr_enum_dom_groups(
664 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
665 &dom_groups
, &num_dom_groups
);
667 if (NT_STATUS_IS_OK(result
) ||
668 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
670 for (i
= 0; i
< num_dom_groups
; i
++)
671 printf("group:[%s] rid:[0x%x]\n",
672 dom_groups
[i
].acct_name
,
676 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
680 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
683 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
688 /* Enumerate alias groups */
690 static NTSTATUS
cmd_samr_enum_als_groups(struct cli_state
*cli
,
692 int argc
, char **argv
)
694 POLICY_HND connect_pol
, domain_pol
;
695 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
696 uint32 start_idx
, size
, num_als_groups
, i
;
697 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
698 struct acct_info
*als_groups
;
699 DOM_SID global_sid_Builtin
;
700 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
702 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
704 if ((argc
< 2) || (argc
> 3)) {
705 printf("Usage: %s builtin|domain [access mask]\n", argv
[0]);
710 sscanf(argv
[2], "%x", &access_mask
);
712 /* Get sam policy handle */
714 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
717 if (!NT_STATUS_IS_OK(result
))
720 got_connect_pol
= True
;
722 /* Get domain policy handle */
724 if (StrCaseCmp(argv
[1], "domain")==0)
725 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
727 &domain_sid
, &domain_pol
);
728 else if (StrCaseCmp(argv
[1], "builtin")==0)
729 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
731 &global_sid_Builtin
, &domain_pol
);
735 if (!NT_STATUS_IS_OK(result
))
738 got_domain_pol
= True
;
740 /* Enumerate alias groups */
743 size
= 0xffff; /* Number of groups to retrieve */
746 result
= cli_samr_enum_als_groups(
747 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
748 &als_groups
, &num_als_groups
);
750 if (NT_STATUS_IS_OK(result
) ||
751 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
753 for (i
= 0; i
< num_als_groups
; i
++)
754 printf("group:[%s] rid:[0x%x]\n",
755 als_groups
[i
].acct_name
,
758 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
762 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
765 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
770 /* Query alias membership */
772 static NTSTATUS
cmd_samr_query_aliasmem(struct cli_state
*cli
,
774 int argc
, char **argv
)
776 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
777 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
778 uint32 alias_rid
, num_members
, i
;
779 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
781 DOM_SID global_sid_Builtin
;
783 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
785 if ((argc
< 3) || (argc
> 4)) {
786 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
790 sscanf(argv
[2], "%i", &alias_rid
);
793 sscanf(argv
[3], "%x", &access_mask
);
795 /* Open SAMR handle */
797 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
800 if (!NT_STATUS_IS_OK(result
))
803 /* Open handle on domain */
805 if (StrCaseCmp(argv
[1], "domain")==0)
806 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
807 MAXIMUM_ALLOWED_ACCESS
,
808 &domain_sid
, &domain_pol
);
809 else if (StrCaseCmp(argv
[1], "builtin")==0)
810 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
811 MAXIMUM_ALLOWED_ACCESS
,
812 &global_sid_Builtin
, &domain_pol
);
816 if (!NT_STATUS_IS_OK(result
))
819 /* Open handle on alias */
821 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
823 alias_rid
, &alias_pol
);
824 if (!NT_STATUS_IS_OK(result
))
827 result
= cli_samr_query_aliasmem(cli
, mem_ctx
, &alias_pol
,
828 &num_members
, &alias_sids
);
830 if (!NT_STATUS_IS_OK(result
))
833 for (i
= 0; i
< num_members
; i
++) {
836 sid_to_string(sid_str
, &alias_sids
[i
]);
837 printf("\tsid:[%s]\n", sid_str
);
844 /* Query display info */
846 static NTSTATUS
cmd_samr_query_dispinfo(struct cli_state
*cli
,
848 int argc
, char **argv
)
850 POLICY_HND connect_pol
, domain_pol
;
851 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
852 uint32 start_idx
=0, max_entries
=250, num_entries
, i
;
853 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
854 uint32 info_level
= 1;
855 SAM_DISPINFO_CTR ctr
;
856 SAM_DISPINFO_1 info1
;
857 SAM_DISPINFO_2 info2
;
858 SAM_DISPINFO_3 info3
;
859 SAM_DISPINFO_4 info4
;
860 SAM_DISPINFO_5 info5
;
863 printf("Usage: %s [info level] [start index] [max entries] [access mask]\n", argv
[0]);
868 sscanf(argv
[1], "%i", &info_level
);
871 sscanf(argv
[2], "%i", &start_idx
);
874 sscanf(argv
[3], "%i", &max_entries
);
877 sscanf(argv
[4], "%x", &access_mask
);
879 /* Get sam policy handle */
881 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
, &connect_pol
);
883 if (!NT_STATUS_IS_OK(result
))
886 /* Get domain policy handle */
888 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
890 &domain_sid
, &domain_pol
);
892 if (!NT_STATUS_IS_OK(result
))
895 /* Query display info */
900 switch (info_level
) {
903 ctr
.sam
.info1
= &info1
;
907 ctr
.sam
.info2
= &info2
;
911 ctr
.sam
.info3
= &info3
;
915 ctr
.sam
.info4
= &info4
;
919 ctr
.sam
.info5
= &info5
;
926 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
927 &start_idx
, info_level
,
928 &num_entries
, max_entries
, &ctr
);
930 if (!NT_STATUS_IS_OK(result
) && !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
933 if (num_entries
== 0)
936 for (i
= 0; i
< num_entries
; i
++) {
937 switch (info_level
) {
939 display_sam_info_1(&ctr
.sam
.info1
->sam
[i
], &ctr
.sam
.info1
->str
[i
]);
942 display_sam_info_2(&ctr
.sam
.info2
->sam
[i
], &ctr
.sam
.info2
->str
[i
]);
945 display_sam_info_3(&ctr
.sam
.info3
->sam
[i
], &ctr
.sam
.info3
->str
[i
]);
948 display_sam_info_4(&ctr
.sam
.info4
->sam
[i
], &ctr
.sam
.info4
->str
[i
]);
951 display_sam_info_5(&ctr
.sam
.info5
->sam
[i
], &ctr
.sam
.info5
->str
[i
]);
961 /* Query domain info */
963 static NTSTATUS
cmd_samr_query_dominfo(struct cli_state
*cli
,
965 int argc
, char **argv
)
967 POLICY_HND connect_pol
, domain_pol
;
968 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
969 uint32 switch_level
= 2;
970 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
974 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
979 sscanf(argv
[1], "%i", &switch_level
);
982 sscanf(argv
[2], "%x", &access_mask
);
984 /* Get sam policy handle */
986 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
989 if (!NT_STATUS_IS_OK(result
))
992 /* Get domain policy handle */
994 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
996 &domain_sid
, &domain_pol
);
998 if (!NT_STATUS_IS_OK(result
))
1001 /* Query domain info */
1003 result
= cli_samr_query_dom_info(cli
, mem_ctx
, &domain_pol
,
1004 switch_level
, &ctr
);
1006 if (!NT_STATUS_IS_OK(result
))
1009 /* Display domain info */
1011 switch (switch_level
) {
1013 display_sam_unk_info_1(&ctr
.info
.inf1
);
1016 display_sam_unk_info_2(&ctr
.info
.inf2
);
1019 printf("cannot display domain info for switch value %d\n",
1026 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
1027 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1031 /* Create domain user */
1033 static NTSTATUS
cmd_samr_create_dom_user(struct cli_state
*cli
,
1034 TALLOC_CTX
*mem_ctx
,
1035 int argc
, char **argv
)
1037 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1038 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1041 uint32 unknown
, user_rid
;
1042 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1044 if ((argc
< 2) || (argc
> 3)) {
1045 printf("Usage: %s username [access mask]\n", argv
[0]);
1046 return NT_STATUS_OK
;
1049 acct_name
= argv
[1];
1052 sscanf(argv
[2], "%x", &access_mask
);
1054 /* Get sam policy handle */
1056 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1059 if (!NT_STATUS_IS_OK(result
))
1062 /* Get domain policy handle */
1064 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1066 &domain_sid
, &domain_pol
);
1068 if (!NT_STATUS_IS_OK(result
))
1071 /* Create domain user */
1073 acb_info
= ACB_NORMAL
;
1074 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
1076 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
1077 acct_name
, acb_info
, unknown
,
1078 &user_pol
, &user_rid
);
1080 if (!NT_STATUS_IS_OK(result
))
1087 /* Lookup sam names */
1089 static NTSTATUS
cmd_samr_lookup_names(struct cli_state
*cli
,
1090 TALLOC_CTX
*mem_ctx
,
1091 int argc
, char **argv
)
1093 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1094 POLICY_HND connect_pol
, domain_pol
;
1095 uint32 flags
= 0x000003e8; /* Unknown */
1096 uint32 num_rids
, num_names
, *name_types
, *rids
;
1099 DOM_SID global_sid_Builtin
;
1101 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
1104 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1105 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1106 printf("or check on the builtin SID: S-1-5-32\n");
1107 return NT_STATUS_OK
;
1110 /* Get sam policy and domain handles */
1112 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1115 if (!NT_STATUS_IS_OK(result
))
1118 if (StrCaseCmp(argv
[1], "domain")==0)
1119 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1120 MAXIMUM_ALLOWED_ACCESS
,
1121 &domain_sid
, &domain_pol
);
1122 else if (StrCaseCmp(argv
[1], "builtin")==0)
1123 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1124 MAXIMUM_ALLOWED_ACCESS
,
1125 &global_sid_Builtin
, &domain_pol
);
1127 return NT_STATUS_OK
;
1129 if (!NT_STATUS_IS_OK(result
))
1134 num_names
= argc
- 2;
1135 names
= (const char **)talloc(mem_ctx
, sizeof(char *) * num_names
);
1137 for (i
= 0; i
< argc
- 2; i
++)
1138 names
[i
] = argv
[i
+ 2];
1140 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1141 flags
, num_names
, names
,
1142 &num_rids
, &rids
, &name_types
);
1144 if (!NT_STATUS_IS_OK(result
))
1147 /* Display results */
1149 for (i
= 0; i
< num_names
; i
++)
1150 printf("name %s: 0x%x (%d)\n", names
[i
], rids
[i
],
1157 /* Lookup sam rids */
1159 static NTSTATUS
cmd_samr_lookup_rids(struct cli_state
*cli
,
1160 TALLOC_CTX
*mem_ctx
,
1161 int argc
, char **argv
)
1163 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1164 POLICY_HND connect_pol
, domain_pol
;
1165 uint32 flags
= 0x000003e8; /* Unknown */
1166 uint32 num_rids
, num_names
, *rids
, *name_types
;
1171 printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1172 return NT_STATUS_OK
;
1175 /* Get sam policy and domain handles */
1177 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1180 if (!NT_STATUS_IS_OK(result
))
1183 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1184 MAXIMUM_ALLOWED_ACCESS
,
1185 &domain_sid
, &domain_pol
);
1187 if (!NT_STATUS_IS_OK(result
))
1192 num_rids
= argc
- 1;
1193 rids
= (uint32
*)talloc(mem_ctx
, sizeof(uint32
) * num_rids
);
1195 for (i
= 0; i
< argc
- 1; i
++)
1196 sscanf(argv
[i
+ 1], "%i", &rids
[i
]);
1198 result
= cli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
,
1199 flags
, num_rids
, rids
,
1200 &num_names
, &names
, &name_types
);
1202 if (!NT_STATUS_IS_OK(result
))
1205 /* Display results */
1207 for (i
= 0; i
< num_names
; i
++)
1208 printf("rid 0x%x: %s (%d)\n", rids
[i
], names
[i
], name_types
[i
]);
1214 /* Delete domain user */
1216 static NTSTATUS
cmd_samr_delete_dom_user(struct cli_state
*cli
,
1217 TALLOC_CTX
*mem_ctx
,
1218 int argc
, char **argv
)
1220 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1221 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1222 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1224 if ((argc
< 2) || (argc
> 3)) {
1225 printf("Usage: %s username\n", argv
[0]);
1226 return NT_STATUS_OK
;
1230 sscanf(argv
[2], "%x", &access_mask
);
1232 /* Get sam policy and domain handles */
1234 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1237 if (!NT_STATUS_IS_OK(result
))
1240 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1241 MAXIMUM_ALLOWED_ACCESS
,
1242 &domain_sid
, &domain_pol
);
1244 if (!NT_STATUS_IS_OK(result
))
1247 /* Get handle on user */
1250 uint32
*user_rids
, num_rids
, *name_types
;
1251 uint32 flags
= 0x000003e8; /* Unknown */
1253 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1254 flags
, 1, (const char **)&argv
[1],
1255 &num_rids
, &user_rids
,
1258 if (!NT_STATUS_IS_OK(result
))
1261 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1263 user_rids
[0], &user_pol
);
1265 if (!NT_STATUS_IS_OK(result
))
1271 result
= cli_samr_delete_dom_user(cli
, mem_ctx
, &user_pol
);
1273 if (!NT_STATUS_IS_OK(result
))
1276 /* Display results */
1282 /**********************************************************************
1283 * Query user security object
1285 static NTSTATUS
cmd_samr_query_sec_obj(struct cli_state
*cli
,
1286 TALLOC_CTX
*mem_ctx
,
1287 int argc
, char **argv
)
1289 POLICY_HND connect_pol
, domain_pol
, user_pol
, *pol
;
1290 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1291 uint32 info_level
= 4;
1293 uint32 user_rid
= 0;
1294 TALLOC_CTX
*ctx
= NULL
;
1295 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
1296 BOOL domain
= False
;
1300 if ((argc
< 1) || (argc
> 2)) {
1301 printf("Usage: %s [rid|-d]\n", argv
[0]);
1302 printf("\tSpecify rid for security on user, -d for security on domain\n");
1303 return NT_STATUS_OK
;
1307 if (strcmp(argv
[1], "-d") == 0)
1310 sscanf(argv
[1], "%i", &user_rid
);
1313 slprintf (server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1315 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1318 if (!NT_STATUS_IS_OK(result
))
1321 if (domain
|| user_rid
)
1322 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1323 MAXIMUM_ALLOWED_ACCESS
,
1324 &domain_sid
, &domain_pol
);
1326 if (!NT_STATUS_IS_OK(result
))
1330 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1331 MAXIMUM_ALLOWED_ACCESS
,
1332 user_rid
, &user_pol
);
1334 if (!NT_STATUS_IS_OK(result
))
1337 /* Pick which query pol to use */
1347 /* Query SAM security object */
1349 result
= cli_samr_query_sec_obj(cli
, mem_ctx
, pol
, info_level
, ctx
,
1352 if (!NT_STATUS_IS_OK(result
))
1355 display_sec_desc(sec_desc_buf
->sec
);
1358 talloc_destroy(ctx
);
1362 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct cli_state
*cli
,
1363 TALLOC_CTX
*mem_ctx
,
1364 int argc
, char **argv
)
1366 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1367 uint16 unk_0
, unk_1
, unk_2
;
1370 printf("Usage: %s\n", argv
[0]);
1371 return NT_STATUS_OK
;
1374 result
= cli_samr_get_dom_pwinfo(cli
, mem_ctx
, &unk_0
, &unk_1
, &unk_2
);
1376 if (NT_STATUS_IS_OK(result
)) {
1377 printf("unk_0 = 0x%08x\n", unk_0
);
1378 printf("unk_1 = 0x%08x\n", unk_1
);
1379 printf("unk_2 = 0x%08x\n", unk_2
);
1386 /* List of commands exported by this module */
1388 struct cmd_set samr_commands
[] = {
1392 { "queryuser", cmd_samr_query_user
, PIPE_SAMR
, "Query user info", "" },
1393 { "querygroup", cmd_samr_query_group
, PIPE_SAMR
, "Query group info", "" },
1394 { "queryusergroups", cmd_samr_query_usergroups
, PIPE_SAMR
, "Query user groups", "" },
1395 { "queryuseraliases", cmd_samr_query_useraliases
, PIPE_SAMR
, "Query user aliases", "" },
1396 { "querygroupmem", cmd_samr_query_groupmem
, PIPE_SAMR
, "Query group membership", "" },
1397 { "queryaliasmem", cmd_samr_query_aliasmem
, PIPE_SAMR
, "Query alias membership", "" },
1398 { "querydispinfo", cmd_samr_query_dispinfo
, PIPE_SAMR
, "Query display info", "" },
1399 { "querydominfo", cmd_samr_query_dominfo
, PIPE_SAMR
, "Query domain info", "" },
1400 { "enumdomgroups", cmd_samr_enum_dom_groups
, PIPE_SAMR
, "Enumerate domain groups", "" },
1401 { "enumalsgroups", cmd_samr_enum_als_groups
, PIPE_SAMR
, "Enumerate alias groups", "" },
1403 { "createdomuser", cmd_samr_create_dom_user
, PIPE_SAMR
, "Create domain user", "" },
1404 { "samlookupnames", cmd_samr_lookup_names
, PIPE_SAMR
, "Look up names", "" },
1405 { "samlookuprids", cmd_samr_lookup_rids
, PIPE_SAMR
, "Look up names", "" },
1406 { "deletedomuser", cmd_samr_delete_dom_user
, PIPE_SAMR
, "Delete domain user", "" },
1407 { "samquerysecobj", cmd_samr_query_sec_obj
, PIPE_SAMR
, "Query SAMR security object", "" },
1408 { "getdompwinfo", cmd_samr_get_dom_pwinfo
, PIPE_SAMR
, "Retrieve domain password info", "" },