r4231: commiting changes to 3.0.10
[Samba.git] / source / rpcclient / cmd_samr.c
blob3bd55aff0656a6134fdcd2e025679dda579b2782
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
25 #include "includes.h"
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)
35 fstring temp;
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("\tfields_present:\t0x%08x\n", usr->fields_present); /* 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("\tbad_password_count:\t0x%08x\n", usr->bad_password_count);
89 printf("\tlogon_count:\t0x%08x\n", usr->logon_count);
91 printf("\tpadding1[0..7]...\n");
93 if (usr->ptr_logon_hrs) {
94 printf("\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
98 static const char *display_time(NTTIME nttime)
100 static fstring string;
102 float high;
103 float low;
104 int sec;
105 int days, hours, mins, secs;
107 if (nttime.high==0 && nttime.low==0)
108 return "Now";
110 if (nttime.high==0x80000000 && nttime.low==0)
111 return "Never";
113 high = 65536;
114 high = high/10000;
115 high = high*65536;
116 high = high/1000;
117 high = high * (~nttime.high);
119 low = ~nttime.low;
120 low = low/(1000*1000*10);
122 sec=high+low;
124 days=sec/(60*60*24);
125 hours=(sec - (days*60*60*24)) / (60*60);
126 mins=(sec - (days*60*60*24) - (hours*60*60) ) / 60;
127 secs=sec - (days*60*60*24) - (hours*60*60) - (mins*60);
129 fstr_sprintf(string, "%u days, %u hours, %u minutes, %u seconds", days, hours, mins, secs);
130 return (string);
133 static void display_sam_unk_info_1(SAM_UNK_INFO_1 *info1)
136 printf("Minimum password length: %d\n", info1->min_length_password);
137 printf("Password uniqueness (remember x passwords): %d\n", info1->password_history);
138 printf("flag: ");
139 if(info1->flag&&2==2) printf("users must open a session to change password ");
140 printf("\n");
142 printf("password expire in: %s\n", display_time(info1->expire));
143 printf("Min password age (allow changing in x days): %s\n", display_time(info1->min_passwordage));
146 static void display_sam_unk_info_2(SAM_UNK_INFO_2 *info2)
148 fstring name;
150 unistr2_to_ascii(name, &info2->uni_domain, sizeof(name) - 1);
151 printf("Domain:\t%s\n", name);
153 unistr2_to_ascii(name, &info2->uni_server, sizeof(name) - 1);
154 printf("Server:\t%s\n", name);
156 printf("Total Users:\t%d\n", info2->num_domain_usrs);
157 printf("Total Groups:\t%d\n", info2->num_domain_grps);
158 printf("Total Aliases:\t%d\n", info2->num_local_grps);
160 printf("Sequence No:\t%d\n", info2->seq_num);
162 printf("Unknown 0:\t0x%x\n", info2->unknown_0);
163 printf("Unknown 1:\t0x%x\n", info2->unknown_1);
164 printf("Unknown 2:\t0x%x\n", info2->unknown_2);
165 printf("Unknown 3:\t0x%x\n", info2->unknown_3);
166 printf("Unknown 4:\t0x%x\n", info2->unknown_4);
167 printf("Unknown 5:\t0x%x\n", info2->unknown_5);
168 printf("Unknown 6:\t0x%x\n", info2->unknown_6);
171 static void display_sam_info_1(SAM_ENTRY1 *e1, SAM_STR1 *s1)
173 fstring tmp;
175 printf("index: 0x%x ", e1->user_idx);
176 printf("RID: 0x%x ", e1->rid_user);
177 printf("acb: 0x%x ", e1->acb_info);
179 unistr2_to_ascii(tmp, &s1->uni_acct_name, sizeof(tmp)-1);
180 printf("Account: %s\t", tmp);
182 unistr2_to_ascii(tmp, &s1->uni_full_name, sizeof(tmp)-1);
183 printf("Name: %s\t", tmp);
185 unistr2_to_ascii(tmp, &s1->uni_acct_desc, sizeof(tmp)-1);
186 printf("Desc: %s\n", tmp);
189 static void display_sam_info_2(SAM_ENTRY2 *e2, SAM_STR2 *s2)
191 fstring tmp;
193 printf("index: 0x%x ", e2->user_idx);
194 printf("RID: 0x%x ", e2->rid_user);
195 printf("acb: 0x%x ", e2->acb_info);
197 unistr2_to_ascii(tmp, &s2->uni_srv_name, sizeof(tmp)-1);
198 printf("Account: %s\t", tmp);
200 unistr2_to_ascii(tmp, &s2->uni_srv_desc, sizeof(tmp)-1);
201 printf("Name: %s\n", tmp);
205 static void display_sam_info_3(SAM_ENTRY3 *e3, SAM_STR3 *s3)
207 fstring tmp;
209 printf("index: 0x%x ", e3->grp_idx);
210 printf("RID: 0x%x ", e3->rid_grp);
211 printf("attr: 0x%x ", e3->attr);
213 unistr2_to_ascii(tmp, &s3->uni_grp_name, sizeof(tmp)-1);
214 printf("Account: %s\t", tmp);
216 unistr2_to_ascii(tmp, &s3->uni_grp_desc, sizeof(tmp)-1);
217 printf("Name: %s\n", tmp);
221 static void display_sam_info_4(SAM_ENTRY4 *e4, SAM_STR4 *s4)
223 int i;
225 printf("index: %d ", e4->user_idx);
227 printf("Account: ");
228 for (i=0; i<s4->acct_name.str_str_len; i++)
229 printf("%c", s4->acct_name.buffer[i]);
230 printf("\n");
234 static void display_sam_info_5(SAM_ENTRY5 *e5, SAM_STR5 *s5)
236 int i;
238 printf("index: 0x%x ", e5->grp_idx);
240 printf("Account: ");
241 for (i=0; i<s5->grp_name.str_str_len; i++)
242 printf("%c", s5->grp_name.buffer[i]);
243 printf("\n");
247 /****************************************************************************
248 Try samr_connect4 first, then samr_conenct if it fails
249 ****************************************************************************/
250 static NTSTATUS try_samr_connects(struct cli_state *cli, TALLOC_CTX *mem_ctx,
251 uint32 access_mask, POLICY_HND *connect_pol)
253 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
255 result = cli_samr_connect4(cli, mem_ctx, access_mask, connect_pol);
256 if (!NT_STATUS_IS_OK(result)) {
257 result = cli_samr_connect(cli, mem_ctx, access_mask,
258 connect_pol);
260 return result;
263 /**********************************************************************
264 * Query user information
266 static NTSTATUS cmd_samr_query_user(struct cli_state *cli,
267 TALLOC_CTX *mem_ctx,
268 int argc, const char **argv)
270 POLICY_HND connect_pol, domain_pol, user_pol;
271 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
272 uint32 info_level = 21;
273 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
274 SAM_USERINFO_CTR *user_ctr;
275 fstring server;
276 uint32 user_rid;
278 if ((argc < 2) || (argc > 4)) {
279 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
280 return NT_STATUS_OK;
283 sscanf(argv[1], "%i", &user_rid);
285 if (argc > 2)
286 sscanf(argv[2], "%i", &info_level);
288 if (argc > 3)
289 sscanf(argv[3], "%x", &access_mask);
292 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
293 strupper_m(server);
295 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
296 &connect_pol);
298 if (!NT_STATUS_IS_OK(result))
299 goto done;
301 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
302 MAXIMUM_ALLOWED_ACCESS,
303 &domain_sid, &domain_pol);
305 if (!NT_STATUS_IS_OK(result))
306 goto done;
308 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
309 access_mask,
310 user_rid, &user_pol);
312 if (!NT_STATUS_IS_OK(result))
313 goto done;
315 ZERO_STRUCT(user_ctr);
317 result = cli_samr_query_userinfo(cli, mem_ctx, &user_pol,
318 info_level, &user_ctr);
320 if (!NT_STATUS_IS_OK(result))
321 goto done;
323 display_sam_user_info_21(user_ctr->info.id21);
325 done:
326 return result;
329 /****************************************************************************
330 display group info
331 ****************************************************************************/
332 static void display_group_info1(GROUP_INFO1 *info1)
334 fstring temp;
336 unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp)-1);
337 printf("\tGroup Name:\t%s\n", temp);
338 unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1);
339 printf("\tDescription:\t%s\n", temp);
340 printf("\tunk1:%d\n", info1->unknown_1);
341 printf("\tNum Members:%d\n", info1->num_members);
344 /****************************************************************************
345 display group info
346 ****************************************************************************/
347 static void display_group_info4(GROUP_INFO4 *info4)
349 fstring desc;
351 unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc)-1);
352 printf("\tGroup Description:%s\n", desc);
355 /****************************************************************************
356 display sam sync structure
357 ****************************************************************************/
358 static void display_group_info_ctr(GROUP_INFO_CTR *ctr)
360 switch (ctr->switch_value1) {
361 case 1: {
362 display_group_info1(&ctr->group.info1);
363 break;
365 case 4: {
366 display_group_info4(&ctr->group.info4);
367 break;
372 /***********************************************************************
373 * Query group information
375 static NTSTATUS cmd_samr_query_group(struct cli_state *cli,
376 TALLOC_CTX *mem_ctx,
377 int argc, const char **argv)
379 POLICY_HND connect_pol, domain_pol, group_pol;
380 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
381 uint32 info_level = 1;
382 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
383 GROUP_INFO_CTR *group_ctr;
384 fstring server;
385 uint32 group_rid;
387 if ((argc < 2) || (argc > 4)) {
388 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
389 return NT_STATUS_OK;
392 sscanf(argv[1], "%i", &group_rid);
394 if (argc > 2)
395 sscanf(argv[2], "%i", &info_level);
397 if (argc > 3)
398 sscanf(argv[3], "%x", &access_mask);
400 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
401 strupper_m(server);
403 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
404 &connect_pol);
406 if (!NT_STATUS_IS_OK(result))
407 goto done;
409 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
410 MAXIMUM_ALLOWED_ACCESS,
411 &domain_sid, &domain_pol);
413 if (!NT_STATUS_IS_OK(result))
414 goto done;
416 result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
417 access_mask,
418 group_rid, &group_pol);
420 if (!NT_STATUS_IS_OK(result))
421 goto done;
423 result = cli_samr_query_groupinfo(cli, mem_ctx, &group_pol,
424 info_level, &group_ctr);
425 if (!NT_STATUS_IS_OK(result)) {
426 goto done;
429 display_group_info_ctr(group_ctr);
431 done:
432 return result;
435 /* Query groups a user is a member of */
437 static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli,
438 TALLOC_CTX *mem_ctx,
439 int argc, const char **argv)
441 POLICY_HND connect_pol,
442 domain_pol,
443 user_pol;
444 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
445 uint32 num_groups,
446 user_rid;
447 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
448 DOM_GID *user_gids;
449 int i;
450 fstring server;
452 if ((argc < 2) || (argc > 3)) {
453 printf("Usage: %s rid [access mask]\n", argv[0]);
454 return NT_STATUS_OK;
457 sscanf(argv[1], "%i", &user_rid);
459 if (argc > 2)
460 sscanf(argv[2], "%x", &access_mask);
462 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
463 strupper_m(server);
465 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
466 &connect_pol);
468 if (!NT_STATUS_IS_OK(result))
469 goto done;
471 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
472 MAXIMUM_ALLOWED_ACCESS,
473 &domain_sid, &domain_pol);
475 if (!NT_STATUS_IS_OK(result))
476 goto done;
478 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
479 access_mask,
480 user_rid, &user_pol);
482 if (!NT_STATUS_IS_OK(result))
483 goto done;
485 result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
486 &num_groups, &user_gids);
488 if (!NT_STATUS_IS_OK(result))
489 goto done;
491 for (i = 0; i < num_groups; i++) {
492 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
493 user_gids[i].g_rid, user_gids[i].attr);
496 done:
497 return result;
500 /* Query aliases a user is a member of */
502 static NTSTATUS cmd_samr_query_useraliases(struct cli_state *cli,
503 TALLOC_CTX *mem_ctx,
504 int argc, const char **argv)
506 POLICY_HND connect_pol, domain_pol;
507 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
508 uint32 user_rid, num_aliases, *alias_rids;
509 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
510 int i;
511 fstring server;
512 DOM_SID tmp_sid;
513 DOM_SID2 sid;
514 DOM_SID global_sid_Builtin;
516 string_to_sid(&global_sid_Builtin, "S-1-5-32");
518 if ((argc < 3) || (argc > 4)) {
519 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
520 return NT_STATUS_OK;
523 sscanf(argv[2], "%i", &user_rid);
525 if (argc > 3)
526 sscanf(argv[3], "%x", &access_mask);
528 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
529 strupper_m(server);
531 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
532 &connect_pol);
534 if (!NT_STATUS_IS_OK(result))
535 goto done;
537 if (StrCaseCmp(argv[1], "domain")==0)
538 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
539 access_mask,
540 &domain_sid, &domain_pol);
541 else if (StrCaseCmp(argv[1], "builtin")==0)
542 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
543 access_mask,
544 &global_sid_Builtin, &domain_pol);
545 else
546 return NT_STATUS_OK;
548 if (!NT_STATUS_IS_OK(result))
549 goto done;
551 sid_copy(&tmp_sid, &domain_sid);
552 sid_append_rid(&tmp_sid, user_rid);
553 init_dom_sid2(&sid, &tmp_sid);
555 result = cli_samr_query_useraliases(cli, mem_ctx, &domain_pol, 1, &sid, &num_aliases, &alias_rids);
557 if (!NT_STATUS_IS_OK(result))
558 goto done;
560 for (i = 0; i < num_aliases; i++) {
561 printf("\tgroup rid:[0x%x]\n", alias_rids[i]);
564 done:
565 return result;
568 /* Query members of a group */
570 static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli,
571 TALLOC_CTX *mem_ctx,
572 int argc, const char **argv)
574 POLICY_HND connect_pol, domain_pol, group_pol;
575 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
576 uint32 num_members, *group_rids, *group_attrs, group_rid;
577 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
578 int i;
579 fstring server;
581 if ((argc < 2) || (argc > 3)) {
582 printf("Usage: %s rid [access mask]\n", argv[0]);
583 return NT_STATUS_OK;
586 sscanf(argv[1], "%i", &group_rid);
588 if (argc > 2)
589 sscanf(argv[2], "%x", &access_mask);
591 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
592 strupper_m(server);
594 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
595 &connect_pol);
597 if (!NT_STATUS_IS_OK(result))
598 goto done;
600 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
601 MAXIMUM_ALLOWED_ACCESS,
602 &domain_sid, &domain_pol);
604 if (!NT_STATUS_IS_OK(result))
605 goto done;
607 result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
608 access_mask,
609 group_rid, &group_pol);
611 if (!NT_STATUS_IS_OK(result))
612 goto done;
614 result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
615 &num_members, &group_rids,
616 &group_attrs);
618 if (!NT_STATUS_IS_OK(result))
619 goto done;
621 for (i = 0; i < num_members; i++) {
622 printf("\trid:[0x%x] attr:[0x%x]\n", group_rids[i],
623 group_attrs[i]);
626 done:
627 return result;
630 /* Enumerate domain users */
632 static NTSTATUS cmd_samr_enum_dom_users(struct cli_state *cli,
633 TALLOC_CTX *mem_ctx,
634 int argc, const char **argv)
636 POLICY_HND connect_pol, domain_pol;
637 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
638 uint32 start_idx, size, num_dom_users, i;
639 char **dom_users;
640 uint32 *dom_rids;
641 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
642 uint16 acb_mask = ACB_NORMAL;
643 BOOL got_connect_pol = False, got_domain_pol = False;
645 if ((argc < 1) || (argc > 2)) {
646 printf("Usage: %s [access_mask]\n", argv[0]);
647 return NT_STATUS_OK;
650 if (argc > 1)
651 sscanf(argv[1], "%x", &access_mask);
653 /* Get sam policy handle */
655 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
656 &connect_pol);
658 if (!NT_STATUS_IS_OK(result))
659 goto done;
661 got_connect_pol = True;
663 /* Get domain policy handle */
665 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
666 access_mask,
667 &domain_sid, &domain_pol);
669 if (!NT_STATUS_IS_OK(result))
670 goto done;
672 got_domain_pol = True;
674 /* Enumerate domain users */
676 start_idx = 0;
677 size = 0xffff;
679 do {
680 result = cli_samr_enum_dom_users(
681 cli, mem_ctx, &domain_pol, &start_idx, acb_mask,
682 size, &dom_users, &dom_rids, &num_dom_users);
684 if (NT_STATUS_IS_OK(result) ||
685 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
687 for (i = 0; i < num_dom_users; i++)
688 printf("user:[%s] rid:[0x%x]\n",
689 dom_users[i], dom_rids[i]);
692 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
694 done:
695 if (got_domain_pol)
696 cli_samr_close(cli, mem_ctx, &domain_pol);
698 if (got_connect_pol)
699 cli_samr_close(cli, mem_ctx, &connect_pol);
701 return result;
704 /* Enumerate domain groups */
706 static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli,
707 TALLOC_CTX *mem_ctx,
708 int argc, const char **argv)
710 POLICY_HND connect_pol, domain_pol;
711 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
712 uint32 start_idx, size, num_dom_groups, i;
713 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
714 struct acct_info *dom_groups;
715 BOOL got_connect_pol = False, got_domain_pol = False;
717 if ((argc < 1) || (argc > 2)) {
718 printf("Usage: %s [access_mask]\n", argv[0]);
719 return NT_STATUS_OK;
722 if (argc > 1)
723 sscanf(argv[1], "%x", &access_mask);
725 /* Get sam policy handle */
727 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
728 &connect_pol);
730 if (!NT_STATUS_IS_OK(result))
731 goto done;
733 got_connect_pol = True;
735 /* Get domain policy handle */
737 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
738 access_mask,
739 &domain_sid, &domain_pol);
741 if (!NT_STATUS_IS_OK(result))
742 goto done;
744 got_domain_pol = True;
746 /* Enumerate domain groups */
748 start_idx = 0;
749 size = 0xffff;
751 do {
752 result = cli_samr_enum_dom_groups(
753 cli, mem_ctx, &domain_pol, &start_idx, size,
754 &dom_groups, &num_dom_groups);
756 if (NT_STATUS_IS_OK(result) ||
757 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
759 for (i = 0; i < num_dom_groups; i++)
760 printf("group:[%s] rid:[0x%x]\n",
761 dom_groups[i].acct_name,
762 dom_groups[i].rid);
765 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
767 done:
768 if (got_domain_pol)
769 cli_samr_close(cli, mem_ctx, &domain_pol);
771 if (got_connect_pol)
772 cli_samr_close(cli, mem_ctx, &connect_pol);
774 return result;
777 /* Enumerate alias groups */
779 static NTSTATUS cmd_samr_enum_als_groups(struct cli_state *cli,
780 TALLOC_CTX *mem_ctx,
781 int argc, const char **argv)
783 POLICY_HND connect_pol, domain_pol;
784 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
785 uint32 start_idx, size, num_als_groups, i;
786 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
787 struct acct_info *als_groups;
788 DOM_SID global_sid_Builtin;
789 BOOL got_connect_pol = False, got_domain_pol = False;
791 string_to_sid(&global_sid_Builtin, "S-1-5-32");
793 if ((argc < 2) || (argc > 3)) {
794 printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
795 return NT_STATUS_OK;
798 if (argc > 2)
799 sscanf(argv[2], "%x", &access_mask);
801 /* Get sam policy handle */
803 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
804 &connect_pol);
806 if (!NT_STATUS_IS_OK(result))
807 goto done;
809 got_connect_pol = True;
811 /* Get domain policy handle */
813 if (StrCaseCmp(argv[1], "domain")==0)
814 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
815 access_mask,
816 &domain_sid, &domain_pol);
817 else if (StrCaseCmp(argv[1], "builtin")==0)
818 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
819 access_mask,
820 &global_sid_Builtin, &domain_pol);
821 else
822 return NT_STATUS_OK;
824 if (!NT_STATUS_IS_OK(result))
825 goto done;
827 got_domain_pol = True;
829 /* Enumerate alias groups */
831 start_idx = 0;
832 size = 0xffff; /* Number of groups to retrieve */
834 do {
835 result = cli_samr_enum_als_groups(
836 cli, mem_ctx, &domain_pol, &start_idx, size,
837 &als_groups, &num_als_groups);
839 if (NT_STATUS_IS_OK(result) ||
840 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
842 for (i = 0; i < num_als_groups; i++)
843 printf("group:[%s] rid:[0x%x]\n",
844 als_groups[i].acct_name,
845 als_groups[i].rid);
847 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
849 done:
850 if (got_domain_pol)
851 cli_samr_close(cli, mem_ctx, &domain_pol);
853 if (got_connect_pol)
854 cli_samr_close(cli, mem_ctx, &connect_pol);
856 return result;
859 /* Query alias membership */
861 static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli,
862 TALLOC_CTX *mem_ctx,
863 int argc, const char **argv)
865 POLICY_HND connect_pol, domain_pol, alias_pol;
866 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
867 uint32 alias_rid, num_members, i;
868 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
869 DOM_SID *alias_sids;
870 DOM_SID global_sid_Builtin;
872 string_to_sid(&global_sid_Builtin, "S-1-5-32");
874 if ((argc < 3) || (argc > 4)) {
875 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
876 return NT_STATUS_OK;
879 sscanf(argv[2], "%i", &alias_rid);
881 if (argc > 3)
882 sscanf(argv[3], "%x", &access_mask);
884 /* Open SAMR handle */
886 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
887 &connect_pol);
889 if (!NT_STATUS_IS_OK(result))
890 goto done;
892 /* Open handle on domain */
894 if (StrCaseCmp(argv[1], "domain")==0)
895 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
896 MAXIMUM_ALLOWED_ACCESS,
897 &domain_sid, &domain_pol);
898 else if (StrCaseCmp(argv[1], "builtin")==0)
899 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
900 MAXIMUM_ALLOWED_ACCESS,
901 &global_sid_Builtin, &domain_pol);
902 else
903 return NT_STATUS_OK;
905 if (!NT_STATUS_IS_OK(result))
906 goto done;
908 /* Open handle on alias */
910 result = cli_samr_open_alias(cli, mem_ctx, &domain_pol,
911 access_mask,
912 alias_rid, &alias_pol);
913 if (!NT_STATUS_IS_OK(result))
914 goto done;
916 result = cli_samr_query_aliasmem(cli, mem_ctx, &alias_pol,
917 &num_members, &alias_sids);
919 if (!NT_STATUS_IS_OK(result))
920 goto done;
922 for (i = 0; i < num_members; i++) {
923 fstring sid_str;
925 sid_to_string(sid_str, &alias_sids[i]);
926 printf("\tsid:[%s]\n", sid_str);
929 done:
930 return result;
933 /* Query display info */
935 static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
936 TALLOC_CTX *mem_ctx,
937 int argc, const char **argv)
939 POLICY_HND connect_pol, domain_pol;
940 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
941 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries, i;
942 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
943 uint32 info_level = 1;
944 SAM_DISPINFO_CTR ctr;
945 SAM_DISPINFO_1 info1;
946 SAM_DISPINFO_2 info2;
947 SAM_DISPINFO_3 info3;
948 SAM_DISPINFO_4 info4;
949 SAM_DISPINFO_5 info5;
950 int loop_count = 0;
951 BOOL got_params = False; /* Use get_query_dispinfo_params() or not? */
953 if (argc > 5) {
954 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
955 return NT_STATUS_OK;
958 if (argc >= 2)
959 sscanf(argv[1], "%i", &info_level);
961 if (argc >= 3)
962 sscanf(argv[2], "%i", &start_idx);
964 if (argc >= 4) {
965 sscanf(argv[3], "%i", &max_entries);
966 got_params = True;
969 if (argc >= 5) {
970 sscanf(argv[4], "%i", &max_size);
971 got_params = True;
974 if (argc >= 6)
975 sscanf(argv[5], "%x", &access_mask);
977 /* Get sam policy handle */
979 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
980 &connect_pol);
982 if (!NT_STATUS_IS_OK(result))
983 goto done;
985 /* Get domain policy handle */
987 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
988 access_mask,
989 &domain_sid, &domain_pol);
991 if (!NT_STATUS_IS_OK(result))
992 goto done;
994 /* Query display info */
996 ZERO_STRUCT(ctr);
997 ZERO_STRUCT(info1);
999 switch (info_level) {
1000 case 1:
1001 ZERO_STRUCT(info1);
1002 ctr.sam.info1 = &info1;
1003 break;
1004 case 2:
1005 ZERO_STRUCT(info2);
1006 ctr.sam.info2 = &info2;
1007 break;
1008 case 3:
1009 ZERO_STRUCT(info3);
1010 ctr.sam.info3 = &info3;
1011 break;
1012 case 4:
1013 ZERO_STRUCT(info4);
1014 ctr.sam.info4 = &info4;
1015 break;
1016 case 5:
1017 ZERO_STRUCT(info5);
1018 ctr.sam.info5 = &info5;
1019 break;
1023 while(1) {
1025 if (!got_params)
1026 get_query_dispinfo_params(
1027 loop_count, &max_entries, &max_size);
1029 result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
1030 &start_idx, info_level,
1031 &num_entries, max_entries,
1032 max_size, &ctr);
1034 loop_count++;
1036 if (!NT_STATUS_IS_OK(result) && !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
1037 break;
1039 if (num_entries == 0)
1040 break;
1042 for (i = 0; i < num_entries; i++) {
1043 switch (info_level) {
1044 case 1:
1045 display_sam_info_1(&ctr.sam.info1->sam[i], &ctr.sam.info1->str[i]);
1046 break;
1047 case 2:
1048 display_sam_info_2(&ctr.sam.info2->sam[i], &ctr.sam.info2->str[i]);
1049 break;
1050 case 3:
1051 display_sam_info_3(&ctr.sam.info3->sam[i], &ctr.sam.info3->str[i]);
1052 break;
1053 case 4:
1054 display_sam_info_4(&ctr.sam.info4->sam[i], &ctr.sam.info4->str[i]);
1055 break;
1056 case 5:
1057 display_sam_info_5(&ctr.sam.info5->sam[i], &ctr.sam.info5->str[i]);
1058 break;
1063 done:
1064 return result;
1067 /* Query domain info */
1069 static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli,
1070 TALLOC_CTX *mem_ctx,
1071 int argc, const char **argv)
1073 POLICY_HND connect_pol, domain_pol;
1074 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1075 uint32 switch_level = 2;
1076 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1077 SAM_UNK_CTR ctr;
1079 if (argc > 2) {
1080 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1081 return NT_STATUS_OK;
1084 if (argc > 1)
1085 sscanf(argv[1], "%i", &switch_level);
1087 if (argc > 2)
1088 sscanf(argv[2], "%x", &access_mask);
1090 /* Get sam policy handle */
1092 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1093 &connect_pol);
1095 if (!NT_STATUS_IS_OK(result))
1096 goto done;
1098 /* Get domain policy handle */
1100 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1101 access_mask,
1102 &domain_sid, &domain_pol);
1104 if (!NT_STATUS_IS_OK(result))
1105 goto done;
1107 /* Query domain info */
1109 result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
1110 switch_level, &ctr);
1112 if (!NT_STATUS_IS_OK(result))
1113 goto done;
1115 /* Display domain info */
1117 switch (switch_level) {
1118 case 1:
1119 display_sam_unk_info_1(&ctr.info.inf1);
1120 break;
1121 case 2:
1122 display_sam_unk_info_2(&ctr.info.inf2);
1123 break;
1124 default:
1125 printf("cannot display domain info for switch value %d\n",
1126 switch_level);
1127 break;
1130 done:
1132 cli_samr_close(cli, mem_ctx, &domain_pol);
1133 cli_samr_close(cli, mem_ctx, &connect_pol);
1134 return result;
1137 /* Create domain user */
1139 static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli,
1140 TALLOC_CTX *mem_ctx,
1141 int argc, const char **argv)
1143 POLICY_HND connect_pol, domain_pol, user_pol;
1144 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1145 const char *acct_name;
1146 uint16 acb_info;
1147 uint32 unknown, user_rid;
1148 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1150 if ((argc < 2) || (argc > 3)) {
1151 printf("Usage: %s username [access mask]\n", argv[0]);
1152 return NT_STATUS_OK;
1155 acct_name = argv[1];
1157 if (argc > 2)
1158 sscanf(argv[2], "%x", &access_mask);
1160 /* Get sam policy handle */
1162 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1163 &connect_pol);
1165 if (!NT_STATUS_IS_OK(result))
1166 goto done;
1168 /* Get domain policy handle */
1170 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1171 access_mask,
1172 &domain_sid, &domain_pol);
1174 if (!NT_STATUS_IS_OK(result))
1175 goto done;
1177 /* Create domain user */
1179 acb_info = ACB_NORMAL;
1180 unknown = 0xe005000b; /* No idea what this is - a permission mask? */
1182 result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
1183 acct_name, acb_info, unknown,
1184 &user_pol, &user_rid);
1186 if (!NT_STATUS_IS_OK(result))
1187 goto done;
1189 done:
1190 return result;
1193 /* Lookup sam names */
1195 static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
1196 TALLOC_CTX *mem_ctx,
1197 int argc, const char **argv)
1199 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1200 POLICY_HND connect_pol, domain_pol;
1201 uint32 flags = 0x000003e8; /* Unknown */
1202 uint32 num_rids, num_names, *name_types, *rids;
1203 const char **names;
1204 int i;
1205 DOM_SID global_sid_Builtin;
1207 string_to_sid(&global_sid_Builtin, "S-1-5-32");
1209 if (argc < 3) {
1210 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1211 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1212 printf("or check on the builtin SID: S-1-5-32\n");
1213 return NT_STATUS_OK;
1216 /* Get sam policy and domain handles */
1218 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1219 &connect_pol);
1221 if (!NT_STATUS_IS_OK(result))
1222 goto done;
1224 if (StrCaseCmp(argv[1], "domain")==0)
1225 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1226 MAXIMUM_ALLOWED_ACCESS,
1227 &domain_sid, &domain_pol);
1228 else if (StrCaseCmp(argv[1], "builtin")==0)
1229 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1230 MAXIMUM_ALLOWED_ACCESS,
1231 &global_sid_Builtin, &domain_pol);
1232 else
1233 return NT_STATUS_OK;
1235 if (!NT_STATUS_IS_OK(result))
1236 goto done;
1238 /* Look up names */
1240 num_names = argc - 2;
1241 names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
1243 for (i = 0; i < argc - 2; i++)
1244 names[i] = argv[i + 2];
1246 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
1247 flags, num_names, names,
1248 &num_rids, &rids, &name_types);
1250 if (!NT_STATUS_IS_OK(result))
1251 goto done;
1253 /* Display results */
1255 for (i = 0; i < num_names; i++)
1256 printf("name %s: 0x%x (%d)\n", names[i], rids[i],
1257 name_types[i]);
1259 done:
1260 return result;
1263 /* Lookup sam rids */
1265 static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli,
1266 TALLOC_CTX *mem_ctx,
1267 int argc, const char **argv)
1269 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1270 POLICY_HND connect_pol, domain_pol;
1271 uint32 flags = 0x000003e8; /* Unknown */
1272 uint32 num_rids, num_names, *rids, *name_types;
1273 char **names;
1274 int i;
1276 if (argc < 2) {
1277 printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv[0]);
1278 return NT_STATUS_OK;
1281 /* Get sam policy and domain handles */
1283 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1284 &connect_pol);
1286 if (!NT_STATUS_IS_OK(result))
1287 goto done;
1289 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1290 MAXIMUM_ALLOWED_ACCESS,
1291 &domain_sid, &domain_pol);
1293 if (!NT_STATUS_IS_OK(result))
1294 goto done;
1296 /* Look up rids */
1298 num_rids = argc - 1;
1299 rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
1301 for (i = 0; i < argc - 1; i++)
1302 sscanf(argv[i + 1], "%i", &rids[i]);
1304 result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol,
1305 flags, num_rids, rids,
1306 &num_names, &names, &name_types);
1308 if (!NT_STATUS_IS_OK(result))
1309 goto done;
1311 /* Display results */
1313 for (i = 0; i < num_names; i++)
1314 printf("rid 0x%x: %s (%d)\n", rids[i], names[i], name_types[i]);
1316 done:
1317 return result;
1320 /* Delete domain user */
1322 static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli,
1323 TALLOC_CTX *mem_ctx,
1324 int argc, const char **argv)
1326 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1327 POLICY_HND connect_pol, domain_pol, user_pol;
1328 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1330 if ((argc < 2) || (argc > 3)) {
1331 printf("Usage: %s username\n", argv[0]);
1332 return NT_STATUS_OK;
1335 if (argc > 2)
1336 sscanf(argv[2], "%x", &access_mask);
1338 /* Get sam policy and domain handles */
1340 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1341 &connect_pol);
1343 if (!NT_STATUS_IS_OK(result))
1344 goto done;
1346 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1347 MAXIMUM_ALLOWED_ACCESS,
1348 &domain_sid, &domain_pol);
1350 if (!NT_STATUS_IS_OK(result))
1351 goto done;
1353 /* Get handle on user */
1356 uint32 *user_rids, num_rids, *name_types;
1357 uint32 flags = 0x000003e8; /* Unknown */
1359 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
1360 flags, 1, (const char **)&argv[1],
1361 &num_rids, &user_rids,
1362 &name_types);
1364 if (!NT_STATUS_IS_OK(result))
1365 goto done;
1367 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
1368 access_mask,
1369 user_rids[0], &user_pol);
1371 if (!NT_STATUS_IS_OK(result))
1372 goto done;
1375 /* Delete user */
1377 result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
1379 if (!NT_STATUS_IS_OK(result))
1380 goto done;
1382 /* Display results */
1384 done:
1385 return result;
1388 /**********************************************************************
1389 * Query user security object
1391 static NTSTATUS cmd_samr_query_sec_obj(struct cli_state *cli,
1392 TALLOC_CTX *mem_ctx,
1393 int argc, const char **argv)
1395 POLICY_HND connect_pol, domain_pol, user_pol, *pol;
1396 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1397 uint32 info_level = 4;
1398 fstring server;
1399 uint32 user_rid = 0;
1400 TALLOC_CTX *ctx = NULL;
1401 SEC_DESC_BUF *sec_desc_buf=NULL;
1402 BOOL domain = False;
1404 ctx=talloc_init("cmd_samr_query_sec_obj");
1406 if ((argc < 1) || (argc > 2)) {
1407 printf("Usage: %s [rid|-d]\n", argv[0]);
1408 printf("\tSpecify rid for security on user, -d for security on domain\n");
1409 return NT_STATUS_OK;
1412 if (argc > 1) {
1413 if (strcmp(argv[1], "-d") == 0)
1414 domain = True;
1415 else
1416 sscanf(argv[1], "%i", &user_rid);
1419 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1420 strupper_m(server);
1421 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1422 &connect_pol);
1424 if (!NT_STATUS_IS_OK(result))
1425 goto done;
1427 if (domain || user_rid)
1428 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1429 MAXIMUM_ALLOWED_ACCESS,
1430 &domain_sid, &domain_pol);
1432 if (!NT_STATUS_IS_OK(result))
1433 goto done;
1435 if (user_rid)
1436 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
1437 MAXIMUM_ALLOWED_ACCESS,
1438 user_rid, &user_pol);
1440 if (!NT_STATUS_IS_OK(result))
1441 goto done;
1443 /* Pick which query pol to use */
1445 pol = &connect_pol;
1447 if (domain)
1448 pol = &domain_pol;
1450 if (user_rid)
1451 pol = &user_pol;
1453 /* Query SAM security object */
1455 result = cli_samr_query_sec_obj(cli, mem_ctx, pol, info_level, ctx,
1456 &sec_desc_buf);
1458 if (!NT_STATUS_IS_OK(result))
1459 goto done;
1461 display_sec_desc(sec_desc_buf->sec);
1463 done:
1464 talloc_destroy(ctx);
1465 return result;
1468 static NTSTATUS cmd_samr_get_dom_pwinfo(struct cli_state *cli,
1469 TALLOC_CTX *mem_ctx,
1470 int argc, const char **argv)
1472 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1473 uint16 unk_0, unk_1;
1475 if (argc != 1) {
1476 printf("Usage: %s\n", argv[0]);
1477 return NT_STATUS_OK;
1480 result = cli_samr_get_dom_pwinfo(cli, mem_ctx, &unk_0, &unk_1) ;
1482 if (NT_STATUS_IS_OK(result)) {
1483 printf("unk_0 = 0x%08x\n", unk_0);
1484 printf("unk_1 = 0x%08x\n", unk_1);
1487 return result;
1490 /* Look up domain name */
1492 static NTSTATUS cmd_samr_lookup_domain(struct cli_state *cli,
1493 TALLOC_CTX *mem_ctx,
1494 int argc, const char **argv)
1496 POLICY_HND connect_pol, domain_pol;
1497 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1498 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1499 fstring domain_name,sid_string;
1500 DOM_SID sid;
1502 if (argc != 2) {
1503 printf("Usage: %s domain_name\n", argv[0]);
1504 return NT_STATUS_OK;
1507 sscanf(argv[1], "%s", domain_name);
1509 result = try_samr_connects(cli, mem_ctx, access_mask, &connect_pol);
1511 if (!NT_STATUS_IS_OK(result))
1512 goto done;
1514 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1515 access_mask, &domain_sid, &domain_pol);
1517 if (!NT_STATUS_IS_OK(result))
1518 goto done;
1520 result = cli_samr_lookup_domain(
1521 cli, mem_ctx, &connect_pol, domain_name, &sid);
1523 sid_to_string(sid_string,&sid);
1525 if (NT_STATUS_IS_OK(result))
1526 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
1527 domain_name,sid_string);
1529 done:
1530 return result;
1534 /* List of commands exported by this module */
1536 struct cmd_set samr_commands[] = {
1538 { "SAMR" },
1540 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, PI_SAMR, "Query user info", "" },
1541 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, PI_SAMR, "Query group info", "" },
1542 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, PI_SAMR, "Query user groups", "" },
1543 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, PI_SAMR, "Query user aliases", "" },
1544 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, PI_SAMR, "Query group membership", "" },
1545 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, PI_SAMR, "Query alias membership", "" },
1546 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, PI_SAMR, "Query display info", "" },
1547 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, PI_SAMR, "Query domain info", "" },
1548 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, PI_SAMR, "Enumerate domain users", "" },
1549 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, PI_SAMR, "Enumerate domain groups", "" },
1550 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, PI_SAMR, "Enumerate alias groups", "" },
1552 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, PI_SAMR, "Create domain user", "" },
1553 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, PI_SAMR, "Look up names", "" },
1554 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, PI_SAMR, "Look up names", "" },
1555 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, PI_SAMR, "Delete domain user", "" },
1556 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, PI_SAMR, "Query SAMR security object", "" },
1557 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, PI_SAMR, "Retrieve domain password info", "" },
1559 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, PI_SAMR, "Lookup Domain Name", "" },
1560 { NULL }