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 strdup("ROLE_STANDALONE");
150 case ROLE_DOMAIN_MEMBER
:
151 return strdup("ROLE_DOMAIN_MEMBER");
153 case ROLE_DOMAIN_BDC
:
154 return strdup("ROLE_DOMAIN_BDC");
156 case ROLE_DOMAIN_PDC
:
157 return strdup("ROLE_DOMAIN_PDC");
160 return 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 cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
304 uint32 access_mask
, POLICY_HND
*connect_pol
)
306 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
308 result
= cli_samr_connect4(cli
, mem_ctx
, access_mask
, connect_pol
);
309 if (!NT_STATUS_IS_OK(result
)) {
310 result
= cli_samr_connect(cli
, mem_ctx
, access_mask
,
316 /**********************************************************************
317 * Query user information
319 static NTSTATUS
cmd_samr_query_user(struct cli_state
*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
->desthost
);
348 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
351 if (!NT_STATUS_IS_OK(result
))
354 result
= cli_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
= cli_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
= cli_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
);
392 /****************************************************************************
394 ****************************************************************************/
395 static void display_group_info1(GROUP_INFO1
*info1
)
399 unistr2_to_ascii(temp
, &info1
->uni_acct_name
, sizeof(temp
)-1);
400 printf("\tGroup Name:\t%s\n", temp
);
401 unistr2_to_ascii(temp
, &info1
->uni_acct_desc
, sizeof(temp
)-1);
402 printf("\tDescription:\t%s\n", temp
);
403 printf("\tunk1:%d\n", info1
->unknown_1
);
404 printf("\tNum Members:%d\n", info1
->num_members
);
407 /****************************************************************************
409 ****************************************************************************/
410 static void display_group_info4(GROUP_INFO4
*info4
)
414 unistr2_to_ascii(desc
, &info4
->uni_acct_desc
, sizeof(desc
)-1);
415 printf("\tGroup Description:%s\n", desc
);
418 /****************************************************************************
419 display sam sync structure
420 ****************************************************************************/
421 static void display_group_info_ctr(GROUP_INFO_CTR
*ctr
)
423 switch (ctr
->switch_value1
) {
425 display_group_info1(&ctr
->group
.info1
);
429 display_group_info4(&ctr
->group
.info4
);
435 /***********************************************************************
436 * Query group information
438 static NTSTATUS
cmd_samr_query_group(struct cli_state
*cli
,
440 int argc
, const char **argv
)
442 POLICY_HND connect_pol
, domain_pol
, group_pol
;
443 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
444 uint32 info_level
= 1;
445 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
446 GROUP_INFO_CTR
*group_ctr
;
450 if ((argc
< 2) || (argc
> 4)) {
451 printf("Usage: %s rid [info level] [access mask]\n", argv
[0]);
455 sscanf(argv
[1], "%i", &group_rid
);
458 sscanf(argv
[2], "%i", &info_level
);
461 sscanf(argv
[3], "%x", &access_mask
);
463 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
466 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
469 if (!NT_STATUS_IS_OK(result
))
472 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
473 MAXIMUM_ALLOWED_ACCESS
,
474 &domain_sid
, &domain_pol
);
476 if (!NT_STATUS_IS_OK(result
))
479 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
481 group_rid
, &group_pol
);
483 if (!NT_STATUS_IS_OK(result
))
486 result
= cli_samr_query_groupinfo(cli
, mem_ctx
, &group_pol
,
487 info_level
, &group_ctr
);
488 if (!NT_STATUS_IS_OK(result
)) {
492 display_group_info_ctr(group_ctr
);
498 /* Query groups a user is a member of */
500 static NTSTATUS
cmd_samr_query_usergroups(struct cli_state
*cli
,
502 int argc
, const char **argv
)
504 POLICY_HND connect_pol
,
507 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
510 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
515 if ((argc
< 2) || (argc
> 3)) {
516 printf("Usage: %s rid [access mask]\n", argv
[0]);
520 sscanf(argv
[1], "%i", &user_rid
);
523 sscanf(argv
[2], "%x", &access_mask
);
525 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
528 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
531 if (!NT_STATUS_IS_OK(result
))
534 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
535 MAXIMUM_ALLOWED_ACCESS
,
536 &domain_sid
, &domain_pol
);
538 if (!NT_STATUS_IS_OK(result
))
541 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
543 user_rid
, &user_pol
);
545 if (!NT_STATUS_IS_OK(result
))
548 result
= cli_samr_query_usergroups(cli
, mem_ctx
, &user_pol
,
549 &num_groups
, &user_gids
);
551 if (!NT_STATUS_IS_OK(result
))
554 for (i
= 0; i
< num_groups
; i
++) {
555 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
556 user_gids
[i
].g_rid
, user_gids
[i
].attr
);
563 /* Query aliases a user is a member of */
565 static NTSTATUS
cmd_samr_query_useraliases(struct cli_state
*cli
,
567 int argc
, const char **argv
)
569 POLICY_HND connect_pol
, domain_pol
;
570 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
571 uint32 user_rid
, num_aliases
, *alias_rids
;
572 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
577 DOM_SID global_sid_Builtin
;
579 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
581 if ((argc
< 3) || (argc
> 4)) {
582 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
586 sscanf(argv
[2], "%i", &user_rid
);
589 sscanf(argv
[3], "%x", &access_mask
);
591 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
594 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
597 if (!NT_STATUS_IS_OK(result
))
600 if (StrCaseCmp(argv
[1], "domain")==0)
601 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
603 &domain_sid
, &domain_pol
);
604 else if (StrCaseCmp(argv
[1], "builtin")==0)
605 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
607 &global_sid_Builtin
, &domain_pol
);
611 if (!NT_STATUS_IS_OK(result
))
614 sid_copy(&tmp_sid
, &domain_sid
);
615 sid_append_rid(&tmp_sid
, user_rid
);
616 init_dom_sid2(&sid
, &tmp_sid
);
618 result
= cli_samr_query_useraliases(cli
, mem_ctx
, &domain_pol
, 1, &sid
, &num_aliases
, &alias_rids
);
620 if (!NT_STATUS_IS_OK(result
))
623 for (i
= 0; i
< num_aliases
; i
++) {
624 printf("\tgroup rid:[0x%x]\n", alias_rids
[i
]);
631 /* Query members of a group */
633 static NTSTATUS
cmd_samr_query_groupmem(struct cli_state
*cli
,
635 int argc
, const char **argv
)
637 POLICY_HND connect_pol
, domain_pol
, group_pol
;
638 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
639 uint32 num_members
, *group_rids
, *group_attrs
, group_rid
;
640 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
644 if ((argc
< 2) || (argc
> 3)) {
645 printf("Usage: %s rid [access mask]\n", argv
[0]);
649 sscanf(argv
[1], "%i", &group_rid
);
652 sscanf(argv
[2], "%x", &access_mask
);
654 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
657 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
660 if (!NT_STATUS_IS_OK(result
))
663 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
664 MAXIMUM_ALLOWED_ACCESS
,
665 &domain_sid
, &domain_pol
);
667 if (!NT_STATUS_IS_OK(result
))
670 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
672 group_rid
, &group_pol
);
674 if (!NT_STATUS_IS_OK(result
))
677 result
= cli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
678 &num_members
, &group_rids
,
681 if (!NT_STATUS_IS_OK(result
))
684 for (i
= 0; i
< num_members
; i
++) {
685 printf("\trid:[0x%x] attr:[0x%x]\n", group_rids
[i
],
693 /* Enumerate domain users */
695 static NTSTATUS
cmd_samr_enum_dom_users(struct cli_state
*cli
,
697 int argc
, const char **argv
)
699 POLICY_HND connect_pol
, domain_pol
;
700 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
701 uint32 start_idx
, size
, num_dom_users
, i
;
704 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
705 uint16 acb_mask
= ACB_NORMAL
;
706 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
708 if ((argc
< 1) || (argc
> 3)) {
709 printf("Usage: %s [access_mask] [acb_mask]\n", argv
[0]);
714 sscanf(argv
[1], "%x", &access_mask
);
717 sscanf(argv
[2], "%hx", &acb_mask
);
719 /* Get sam policy handle */
721 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
724 if (!NT_STATUS_IS_OK(result
))
727 got_connect_pol
= True
;
729 /* Get domain policy handle */
731 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
733 &domain_sid
, &domain_pol
);
735 if (!NT_STATUS_IS_OK(result
))
738 got_domain_pol
= True
;
740 /* Enumerate domain users */
746 result
= cli_samr_enum_dom_users(
747 cli
, mem_ctx
, &domain_pol
, &start_idx
, acb_mask
,
748 size
, &dom_users
, &dom_rids
, &num_dom_users
);
750 if (NT_STATUS_IS_OK(result
) ||
751 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
753 for (i
= 0; i
< num_dom_users
; i
++)
754 printf("user:[%s] rid:[0x%x]\n",
755 dom_users
[i
], dom_rids
[i
]);
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 /* Enumerate domain groups */
772 static NTSTATUS
cmd_samr_enum_dom_groups(struct cli_state
*cli
,
774 int argc
, const char **argv
)
776 POLICY_HND connect_pol
, domain_pol
;
777 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
778 uint32 start_idx
, size
, num_dom_groups
, i
;
779 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
780 struct acct_info
*dom_groups
;
781 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
783 if ((argc
< 1) || (argc
> 2)) {
784 printf("Usage: %s [access_mask]\n", argv
[0]);
789 sscanf(argv
[1], "%x", &access_mask
);
791 /* Get sam policy handle */
793 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
796 if (!NT_STATUS_IS_OK(result
))
799 got_connect_pol
= True
;
801 /* Get domain policy handle */
803 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
805 &domain_sid
, &domain_pol
);
807 if (!NT_STATUS_IS_OK(result
))
810 got_domain_pol
= True
;
812 /* Enumerate domain groups */
818 result
= cli_samr_enum_dom_groups(
819 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
820 &dom_groups
, &num_dom_groups
);
822 if (NT_STATUS_IS_OK(result
) ||
823 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
825 for (i
= 0; i
< num_dom_groups
; i
++)
826 printf("group:[%s] rid:[0x%x]\n",
827 dom_groups
[i
].acct_name
,
831 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
835 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
838 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
843 /* Enumerate alias groups */
845 static NTSTATUS
cmd_samr_enum_als_groups(struct cli_state
*cli
,
847 int argc
, const char **argv
)
849 POLICY_HND connect_pol
, domain_pol
;
850 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
851 uint32 start_idx
, size
, num_als_groups
, i
;
852 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
853 struct acct_info
*als_groups
;
854 DOM_SID global_sid_Builtin
;
855 BOOL got_connect_pol
= False
, got_domain_pol
= False
;
857 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
859 if ((argc
< 2) || (argc
> 3)) {
860 printf("Usage: %s builtin|domain [access mask]\n", argv
[0]);
865 sscanf(argv
[2], "%x", &access_mask
);
867 /* Get sam policy handle */
869 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
872 if (!NT_STATUS_IS_OK(result
))
875 got_connect_pol
= True
;
877 /* Get domain policy handle */
879 if (StrCaseCmp(argv
[1], "domain")==0)
880 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
882 &domain_sid
, &domain_pol
);
883 else if (StrCaseCmp(argv
[1], "builtin")==0)
884 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
886 &global_sid_Builtin
, &domain_pol
);
890 if (!NT_STATUS_IS_OK(result
))
893 got_domain_pol
= True
;
895 /* Enumerate alias groups */
898 size
= 0xffff; /* Number of groups to retrieve */
901 result
= cli_samr_enum_als_groups(
902 cli
, mem_ctx
, &domain_pol
, &start_idx
, size
,
903 &als_groups
, &num_als_groups
);
905 if (NT_STATUS_IS_OK(result
) ||
906 NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
)) {
908 for (i
= 0; i
< num_als_groups
; i
++)
909 printf("group:[%s] rid:[0x%x]\n",
910 als_groups
[i
].acct_name
,
913 } while (NT_STATUS_V(result
) == NT_STATUS_V(STATUS_MORE_ENTRIES
));
917 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
920 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
925 /* Query alias membership */
927 static NTSTATUS
cmd_samr_query_aliasmem(struct cli_state
*cli
,
929 int argc
, const char **argv
)
931 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
932 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
933 uint32 alias_rid
, num_members
, i
;
934 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
936 DOM_SID global_sid_Builtin
;
938 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
940 if ((argc
< 3) || (argc
> 4)) {
941 printf("Usage: %s builtin|domain rid [access mask]\n", argv
[0]);
945 sscanf(argv
[2], "%i", &alias_rid
);
948 sscanf(argv
[3], "%x", &access_mask
);
950 /* Open SAMR handle */
952 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
955 if (!NT_STATUS_IS_OK(result
))
958 /* Open handle on domain */
960 if (StrCaseCmp(argv
[1], "domain")==0)
961 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
962 MAXIMUM_ALLOWED_ACCESS
,
963 &domain_sid
, &domain_pol
);
964 else if (StrCaseCmp(argv
[1], "builtin")==0)
965 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
966 MAXIMUM_ALLOWED_ACCESS
,
967 &global_sid_Builtin
, &domain_pol
);
971 if (!NT_STATUS_IS_OK(result
))
974 /* Open handle on alias */
976 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
978 alias_rid
, &alias_pol
);
979 if (!NT_STATUS_IS_OK(result
))
982 result
= cli_samr_query_aliasmem(cli
, mem_ctx
, &alias_pol
,
983 &num_members
, &alias_sids
);
985 if (!NT_STATUS_IS_OK(result
))
988 for (i
= 0; i
< num_members
; i
++) {
991 sid_to_string(sid_str
, &alias_sids
[i
]);
992 printf("\tsid:[%s]\n", sid_str
);
999 /* Query display info */
1001 static NTSTATUS
cmd_samr_query_dispinfo(struct cli_state
*cli
,
1002 TALLOC_CTX
*mem_ctx
,
1003 int argc
, const char **argv
)
1005 POLICY_HND connect_pol
, domain_pol
;
1006 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1007 uint32 start_idx
=0, max_entries
=250, max_size
= 0xffff, num_entries
, i
;
1008 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1009 uint32 info_level
= 1;
1010 SAM_DISPINFO_CTR ctr
;
1011 SAM_DISPINFO_1 info1
;
1012 SAM_DISPINFO_2 info2
;
1013 SAM_DISPINFO_3 info3
;
1014 SAM_DISPINFO_4 info4
;
1015 SAM_DISPINFO_5 info5
;
1017 BOOL got_params
= False
; /* Use get_query_dispinfo_params() or not? */
1020 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv
[0]);
1021 return NT_STATUS_OK
;
1025 sscanf(argv
[1], "%i", &info_level
);
1028 sscanf(argv
[2], "%i", &start_idx
);
1031 sscanf(argv
[3], "%i", &max_entries
);
1036 sscanf(argv
[4], "%i", &max_size
);
1041 sscanf(argv
[5], "%x", &access_mask
);
1043 /* Get sam policy handle */
1045 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1048 if (!NT_STATUS_IS_OK(result
))
1051 /* Get domain policy handle */
1053 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1055 &domain_sid
, &domain_pol
);
1057 if (!NT_STATUS_IS_OK(result
))
1060 /* Query display info */
1065 switch (info_level
) {
1068 ctr
.sam
.info1
= &info1
;
1072 ctr
.sam
.info2
= &info2
;
1076 ctr
.sam
.info3
= &info3
;
1080 ctr
.sam
.info4
= &info4
;
1084 ctr
.sam
.info5
= &info5
;
1092 get_query_dispinfo_params(
1093 loop_count
, &max_entries
, &max_size
);
1095 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
1096 &start_idx
, info_level
,
1097 &num_entries
, max_entries
,
1102 if (!NT_STATUS_IS_OK(result
) && !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
1105 if (num_entries
== 0)
1108 for (i
= 0; i
< num_entries
; i
++) {
1109 switch (info_level
) {
1111 display_sam_info_1(&ctr
.sam
.info1
->sam
[i
], &ctr
.sam
.info1
->str
[i
]);
1114 display_sam_info_2(&ctr
.sam
.info2
->sam
[i
], &ctr
.sam
.info2
->str
[i
]);
1117 display_sam_info_3(&ctr
.sam
.info3
->sam
[i
], &ctr
.sam
.info3
->str
[i
]);
1120 display_sam_info_4(&ctr
.sam
.info4
->sam
[i
], &ctr
.sam
.info4
->str
[i
]);
1123 display_sam_info_5(&ctr
.sam
.info5
->sam
[i
], &ctr
.sam
.info5
->str
[i
]);
1133 /* Query domain info */
1135 static NTSTATUS
cmd_samr_query_dominfo(struct cli_state
*cli
,
1136 TALLOC_CTX
*mem_ctx
,
1137 int argc
, const char **argv
)
1139 POLICY_HND connect_pol
, domain_pol
;
1140 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1141 uint32 switch_level
= 2;
1142 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1146 printf("Usage: %s [info level] [access mask]\n", argv
[0]);
1147 return NT_STATUS_OK
;
1151 sscanf(argv
[1], "%i", &switch_level
);
1154 sscanf(argv
[2], "%x", &access_mask
);
1156 /* Get sam policy handle */
1158 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1161 if (!NT_STATUS_IS_OK(result
))
1164 /* Get domain policy handle */
1166 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1168 &domain_sid
, &domain_pol
);
1170 if (!NT_STATUS_IS_OK(result
))
1173 /* Query domain info */
1175 result
= cli_samr_query_dom_info(cli
, mem_ctx
, &domain_pol
,
1176 switch_level
, &ctr
);
1178 if (!NT_STATUS_IS_OK(result
))
1181 /* Display domain info */
1183 switch (switch_level
) {
1185 display_sam_unk_info_1(&ctr
.info
.inf1
);
1188 display_sam_unk_info_2(&ctr
.info
.inf2
);
1191 display_sam_unk_info_7(&ctr
.info
.inf7
);
1194 display_sam_unk_info_8(&ctr
.info
.inf8
);
1197 display_sam_unk_info_12(&ctr
.info
.inf12
);
1200 printf("cannot display domain info for switch value %d\n",
1207 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
1208 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1212 /* Create domain user */
1214 static NTSTATUS
cmd_samr_create_dom_user(struct cli_state
*cli
,
1215 TALLOC_CTX
*mem_ctx
,
1216 int argc
, const char **argv
)
1218 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1219 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1220 const char *acct_name
;
1222 uint32 unknown
, user_rid
;
1223 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1225 if ((argc
< 2) || (argc
> 3)) {
1226 printf("Usage: %s username [access mask]\n", argv
[0]);
1227 return NT_STATUS_OK
;
1230 acct_name
= argv
[1];
1233 sscanf(argv
[2], "%x", &access_mask
);
1235 /* Get sam policy handle */
1237 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1240 if (!NT_STATUS_IS_OK(result
))
1243 /* Get domain policy handle */
1245 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1247 &domain_sid
, &domain_pol
);
1249 if (!NT_STATUS_IS_OK(result
))
1252 /* Create domain user */
1254 acb_info
= ACB_NORMAL
;
1255 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
1257 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
1258 acct_name
, acb_info
, unknown
,
1259 &user_pol
, &user_rid
);
1261 if (!NT_STATUS_IS_OK(result
))
1268 /* Create domain group */
1270 static NTSTATUS
cmd_samr_create_dom_group(struct cli_state
*cli
,
1271 TALLOC_CTX
*mem_ctx
,
1272 int argc
, const char **argv
)
1274 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1275 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1276 const char *grp_name
;
1277 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1279 if ((argc
< 2) || (argc
> 3)) {
1280 printf("Usage: %s groupname [access mask]\n", argv
[0]);
1281 return NT_STATUS_OK
;
1287 sscanf(argv
[2], "%x", &access_mask
);
1289 /* Get sam policy handle */
1291 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1294 if (!NT_STATUS_IS_OK(result
))
1297 /* Get domain policy handle */
1299 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1301 &domain_sid
, &domain_pol
);
1303 if (!NT_STATUS_IS_OK(result
))
1306 /* Create domain user */
1308 result
= cli_samr_create_dom_group(cli
, mem_ctx
, &domain_pol
,
1309 grp_name
, MAXIMUM_ALLOWED_ACCESS
,
1312 if (!NT_STATUS_IS_OK(result
))
1319 /* Lookup sam names */
1321 static NTSTATUS
cmd_samr_lookup_names(struct cli_state
*cli
,
1322 TALLOC_CTX
*mem_ctx
,
1323 int argc
, const char **argv
)
1325 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1326 POLICY_HND connect_pol
, domain_pol
;
1327 uint32 flags
= 0x000003e8; /* Unknown */
1328 uint32 num_rids
, num_names
, *name_types
, *rids
;
1331 DOM_SID global_sid_Builtin
;
1333 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
1336 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv
[0]);
1337 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1338 printf("or check on the builtin SID: S-1-5-32\n");
1339 return NT_STATUS_OK
;
1342 /* Get sam policy and domain handles */
1344 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1347 if (!NT_STATUS_IS_OK(result
))
1350 if (StrCaseCmp(argv
[1], "domain")==0)
1351 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1352 MAXIMUM_ALLOWED_ACCESS
,
1353 &domain_sid
, &domain_pol
);
1354 else if (StrCaseCmp(argv
[1], "builtin")==0)
1355 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1356 MAXIMUM_ALLOWED_ACCESS
,
1357 &global_sid_Builtin
, &domain_pol
);
1359 return NT_STATUS_OK
;
1361 if (!NT_STATUS_IS_OK(result
))
1366 num_names
= argc
- 2;
1367 names
= TALLOC_ARRAY(mem_ctx
, const char *, num_names
);
1369 for (i
= 0; i
< argc
- 2; i
++)
1370 names
[i
] = argv
[i
+ 2];
1372 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1373 flags
, num_names
, names
,
1374 &num_rids
, &rids
, &name_types
);
1376 if (!NT_STATUS_IS_OK(result
))
1379 /* Display results */
1381 for (i
= 0; i
< num_names
; i
++)
1382 printf("name %s: 0x%x (%d)\n", names
[i
], rids
[i
],
1389 /* Lookup sam rids */
1391 static NTSTATUS
cmd_samr_lookup_rids(struct cli_state
*cli
,
1392 TALLOC_CTX
*mem_ctx
,
1393 int argc
, const char **argv
)
1395 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1396 POLICY_HND connect_pol
, domain_pol
;
1397 uint32 num_rids
, num_names
, *rids
, *name_types
;
1402 printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv
[0]);
1403 return NT_STATUS_OK
;
1406 /* Get sam policy and domain handles */
1408 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1411 if (!NT_STATUS_IS_OK(result
))
1414 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1415 MAXIMUM_ALLOWED_ACCESS
,
1416 &domain_sid
, &domain_pol
);
1418 if (!NT_STATUS_IS_OK(result
))
1423 num_rids
= argc
- 1;
1424 rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
);
1426 for (i
= 0; i
< argc
- 1; i
++)
1427 sscanf(argv
[i
+ 1], "%i", &rids
[i
]);
1429 result
= cli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
, num_rids
, rids
,
1430 &num_names
, &names
, &name_types
);
1432 if (!NT_STATUS_IS_OK(result
) &&
1433 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
1436 /* Display results */
1438 for (i
= 0; i
< num_names
; i
++)
1439 printf("rid 0x%x: %s (%d)\n", rids
[i
], names
[i
], name_types
[i
]);
1445 /* Delete domain user */
1447 static NTSTATUS
cmd_samr_delete_dom_user(struct cli_state
*cli
,
1448 TALLOC_CTX
*mem_ctx
,
1449 int argc
, const char **argv
)
1451 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1452 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1453 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1455 if ((argc
< 2) || (argc
> 3)) {
1456 printf("Usage: %s username\n", argv
[0]);
1457 return NT_STATUS_OK
;
1461 sscanf(argv
[2], "%x", &access_mask
);
1463 /* Get sam policy and domain handles */
1465 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1468 if (!NT_STATUS_IS_OK(result
))
1471 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1472 MAXIMUM_ALLOWED_ACCESS
,
1473 &domain_sid
, &domain_pol
);
1475 if (!NT_STATUS_IS_OK(result
))
1478 /* Get handle on user */
1481 uint32
*user_rids
, num_rids
, *name_types
;
1482 uint32 flags
= 0x000003e8; /* Unknown */
1484 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1485 flags
, 1, (const char **)&argv
[1],
1486 &num_rids
, &user_rids
,
1489 if (!NT_STATUS_IS_OK(result
))
1492 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1494 user_rids
[0], &user_pol
);
1496 if (!NT_STATUS_IS_OK(result
))
1502 result
= cli_samr_delete_dom_user(cli
, mem_ctx
, &user_pol
);
1504 if (!NT_STATUS_IS_OK(result
))
1507 /* Display results */
1513 /**********************************************************************
1514 * Query user security object
1516 static NTSTATUS
cmd_samr_query_sec_obj(struct cli_state
*cli
,
1517 TALLOC_CTX
*mem_ctx
,
1518 int argc
, const char **argv
)
1520 POLICY_HND connect_pol
, domain_pol
, user_pol
, *pol
;
1521 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1522 uint32 info_level
= 4;
1524 uint32 user_rid
= 0;
1525 TALLOC_CTX
*ctx
= NULL
;
1526 SEC_DESC_BUF
*sec_desc_buf
=NULL
;
1527 BOOL domain
= False
;
1529 ctx
=talloc_init("cmd_samr_query_sec_obj");
1531 if ((argc
< 1) || (argc
> 2)) {
1532 printf("Usage: %s [rid|-d]\n", argv
[0]);
1533 printf("\tSpecify rid for security on user, -d for security on domain\n");
1534 return NT_STATUS_OK
;
1538 if (strcmp(argv
[1], "-d") == 0)
1541 sscanf(argv
[1], "%i", &user_rid
);
1544 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->desthost
);
1546 result
= try_samr_connects(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1549 if (!NT_STATUS_IS_OK(result
))
1552 if (domain
|| user_rid
)
1553 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1554 MAXIMUM_ALLOWED_ACCESS
,
1555 &domain_sid
, &domain_pol
);
1557 if (!NT_STATUS_IS_OK(result
))
1561 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1562 MAXIMUM_ALLOWED_ACCESS
,
1563 user_rid
, &user_pol
);
1565 if (!NT_STATUS_IS_OK(result
))
1568 /* Pick which query pol to use */
1578 /* Query SAM security object */
1580 result
= cli_samr_query_sec_obj(cli
, mem_ctx
, pol
, info_level
, ctx
,
1583 if (!NT_STATUS_IS_OK(result
))
1586 display_sec_desc(sec_desc_buf
->sec
);
1589 talloc_destroy(ctx
);
1593 static NTSTATUS
cmd_samr_get_dom_pwinfo(struct cli_state
*cli
,
1594 TALLOC_CTX
*mem_ctx
,
1595 int argc
, const char **argv
)
1597 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1598 uint16 unk_0
, unk_1
;
1601 printf("Usage: %s\n", argv
[0]);
1602 return NT_STATUS_OK
;
1605 result
= cli_samr_get_dom_pwinfo(cli
, mem_ctx
, &unk_0
, &unk_1
) ;
1607 if (NT_STATUS_IS_OK(result
)) {
1608 printf("unk_0 = 0x%08x\n", unk_0
);
1609 printf("unk_1 = 0x%08x\n", unk_1
);
1615 /* Look up domain name */
1617 static NTSTATUS
cmd_samr_lookup_domain(struct cli_state
*cli
,
1618 TALLOC_CTX
*mem_ctx
,
1619 int argc
, const char **argv
)
1621 POLICY_HND connect_pol
, domain_pol
;
1622 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1623 uint32 access_mask
= MAXIMUM_ALLOWED_ACCESS
;
1624 fstring domain_name
,sid_string
;
1628 printf("Usage: %s domain_name\n", argv
[0]);
1629 return NT_STATUS_OK
;
1632 sscanf(argv
[1], "%s", domain_name
);
1634 result
= try_samr_connects(cli
, mem_ctx
, access_mask
, &connect_pol
);
1636 if (!NT_STATUS_IS_OK(result
))
1639 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1640 access_mask
, &domain_sid
, &domain_pol
);
1642 if (!NT_STATUS_IS_OK(result
))
1645 result
= cli_samr_lookup_domain(
1646 cli
, mem_ctx
, &connect_pol
, domain_name
, &sid
);
1648 sid_to_string(sid_string
,&sid
);
1650 if (NT_STATUS_IS_OK(result
))
1651 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
1652 domain_name
,sid_string
);
1659 /* List of commands exported by this module */
1661 struct cmd_set samr_commands
[] = {
1665 { "queryuser", RPC_RTYPE_NTSTATUS
, cmd_samr_query_user
, NULL
, PI_SAMR
, "Query user info", "" },
1666 { "querygroup", RPC_RTYPE_NTSTATUS
, cmd_samr_query_group
, NULL
, PI_SAMR
, "Query group info", "" },
1667 { "queryusergroups", RPC_RTYPE_NTSTATUS
, cmd_samr_query_usergroups
, NULL
, PI_SAMR
, "Query user groups", "" },
1668 { "queryuseraliases", RPC_RTYPE_NTSTATUS
, cmd_samr_query_useraliases
, NULL
, PI_SAMR
, "Query user aliases", "" },
1669 { "querygroupmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_groupmem
, NULL
, PI_SAMR
, "Query group membership", "" },
1670 { "queryaliasmem", RPC_RTYPE_NTSTATUS
, cmd_samr_query_aliasmem
, NULL
, PI_SAMR
, "Query alias membership", "" },
1671 { "querydispinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dispinfo
, NULL
, PI_SAMR
, "Query display info", "" },
1672 { "querydominfo", RPC_RTYPE_NTSTATUS
, cmd_samr_query_dominfo
, NULL
, PI_SAMR
, "Query domain info", "" },
1673 { "enumdomusers", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_users
, NULL
, PI_SAMR
, "Enumerate domain users", "" },
1674 { "enumdomgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_dom_groups
, NULL
, PI_SAMR
, "Enumerate domain groups", "" },
1675 { "enumalsgroups", RPC_RTYPE_NTSTATUS
, cmd_samr_enum_als_groups
, NULL
, PI_SAMR
, "Enumerate alias groups", "" },
1677 { "createdomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_user
, NULL
, PI_SAMR
, "Create domain user", "" },
1678 { "createdomgroup", RPC_RTYPE_NTSTATUS
, cmd_samr_create_dom_group
, NULL
, PI_SAMR
, "Create domain group", "" },
1679 { "samlookupnames", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_names
, NULL
, PI_SAMR
, "Look up names", "" },
1680 { "samlookuprids", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_rids
, NULL
, PI_SAMR
, "Look up names", "" },
1681 { "deletedomuser", RPC_RTYPE_NTSTATUS
, cmd_samr_delete_dom_user
, NULL
, PI_SAMR
, "Delete domain user", "" },
1682 { "samquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_samr_query_sec_obj
, NULL
, PI_SAMR
, "Query SAMR security object", "" },
1683 { "getdompwinfo", RPC_RTYPE_NTSTATUS
, cmd_samr_get_dom_pwinfo
, NULL
, PI_SAMR
, "Retrieve domain password info", "" },
1685 { "lookupdomain", RPC_RTYPE_NTSTATUS
, cmd_samr_lookup_domain
, NULL
, PI_SAMR
, "Lookup Domain Name", "" },