2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 1992-2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 Copyright (C) Elrond 2000,
8 Copyright (C) Tim Potter 2000
9 Copyright (C) Guenther Deschner 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "rpcclient.h"
28 extern DOM_SID domain_sid;
30 /****************************************************************************
31 display samr_user_info_7 structure
32 ****************************************************************************/
33 static void display_samr_user_info_7(struct samr_UserInfo7 *r)
35 printf("\tUser Name :\t%s\n", r->account_name.string);
38 /****************************************************************************
39 display samr_user_info_9 structure
40 ****************************************************************************/
41 static void display_samr_user_info_9(struct samr_UserInfo9 *r)
43 printf("\tPrimary group RID :\tox%x\n", r->primary_gid);
46 /****************************************************************************
47 display samr_user_info_16 structure
48 ****************************************************************************/
49 static void display_samr_user_info_16(struct samr_UserInfo16 *r)
51 printf("\tAcct Flags :\tox%x\n", r->acct_flags);
54 /****************************************************************************
55 display samr_user_info_20 structure
56 ****************************************************************************/
57 static void display_samr_user_info_20(struct samr_UserInfo20 *r)
59 printf("\tRemote Dial :\n");
60 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
64 /****************************************************************************
65 display samr_user_info_21 structure
66 ****************************************************************************/
67 static void display_samr_user_info_21(struct samr_UserInfo21 *r)
69 printf("\tUser Name :\t%s\n", r->account_name.string);
70 printf("\tFull Name :\t%s\n", r->full_name.string);
71 printf("\tHome Drive :\t%s\n", r->home_directory.string);
72 printf("\tDir Drive :\t%s\n", r->home_drive.string);
73 printf("\tProfile Path:\t%s\n", r->profile_path.string);
74 printf("\tLogon Script:\t%s\n", r->logon_script.string);
75 printf("\tDescription :\t%s\n", r->description.string);
76 printf("\tWorkstations:\t%s\n", r->workstations.string);
77 printf("\tComment :\t%s\n", r->comment.string);
78 printf("\tRemote Dial :\n");
79 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
81 printf("\tLogon Time :\t%s\n",
82 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logon)));
83 printf("\tLogoff Time :\t%s\n",
84 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logoff)));
85 printf("\tKickoff Time :\t%s\n",
86 http_timestring(talloc_tos(), nt_time_to_unix(r->acct_expiry)));
87 printf("\tPassword last set Time :\t%s\n",
88 http_timestring(talloc_tos(), nt_time_to_unix(r->last_password_change)));
89 printf("\tPassword can change Time :\t%s\n",
90 http_timestring(talloc_tos(), nt_time_to_unix(r->allow_password_change)));
91 printf("\tPassword must change Time:\t%s\n",
92 http_timestring(talloc_tos(), nt_time_to_unix(r->force_password_change)));
94 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
96 printf("\tuser_rid :\t0x%x\n" , r->rid); /* User ID */
97 printf("\tgroup_rid:\t0x%x\n" , r->primary_gid); /* Group ID */
98 printf("\tacb_info :\t0x%08x\n", r->acct_flags); /* Account Control Info */
100 printf("\tfields_present:\t0x%08x\n", r->fields_present); /* 0x00ff ffff */
101 printf("\tlogon_divs:\t%d\n", r->logon_hours.units_per_week); /* 0x0000 00a8 which is 168 which is num hrs in a week */
102 printf("\tbad_password_count:\t0x%08x\n", r->bad_password_count);
103 printf("\tlogon_count:\t0x%08x\n", r->logon_count);
105 printf("\tpadding1[0..7]...\n");
107 if (r->logon_hours.bits) {
108 printf("\tlogon_hrs[0..%d]...\n", r->logon_hours.units_per_week/8);
113 static void display_password_properties(uint32_t password_properties)
115 printf("password_properties: 0x%08x\n", password_properties);
117 if (password_properties & DOMAIN_PASSWORD_COMPLEX)
118 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
120 if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
121 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
123 if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
124 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
126 if (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)
127 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
129 if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
130 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
132 if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
133 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
136 static void display_sam_dom_info_1(struct samr_DomInfo1 *info1)
138 printf("Minimum password length:\t\t\t%d\n",
139 info1->min_password_length);
140 printf("Password uniqueness (remember x passwords):\t%d\n",
141 info1->password_history_length);
142 display_password_properties(info1->password_properties);
143 printf("password expire in:\t\t\t\t%s\n",
144 display_time(info1->max_password_age));
145 printf("Min password age (allow changing in x days):\t%s\n",
146 display_time(info1->min_password_age));
149 static void display_sam_dom_info_2(struct samr_DomGeneralInformation *general)
151 printf("Domain:\t\t%s\n", general->domain_name.string);
152 printf("Server:\t\t%s\n", general->primary.string);
153 printf("Comment:\t%s\n", general->oem_information.string);
155 printf("Total Users:\t%d\n", general->num_users);
156 printf("Total Groups:\t%d\n", general->num_groups);
157 printf("Total Aliases:\t%d\n", general->num_aliases);
159 printf("Sequence No:\t%llu\n", (unsigned long long)general->sequence_num);
161 printf("Force Logoff:\t%d\n",
162 (int)nt_time_to_unix_abs(&general->force_logoff_time));
164 printf("Domain Server State:\t0x%x\n", general->domain_server_state);
165 printf("Server Role:\t%s\n", server_role_str(general->role));
166 printf("Unknown 3:\t0x%x\n", general->unknown3);
169 static void display_sam_dom_info_3(struct samr_DomInfo3 *info3)
171 printf("Force Logoff:\t%d\n",
172 (int)nt_time_to_unix_abs(&info3->force_logoff_time));
175 static void display_sam_dom_info_4(struct samr_DomOEMInformation *oem)
177 printf("Comment:\t%s\n", oem->oem_information.string);
180 static void display_sam_dom_info_5(struct samr_DomInfo5 *info5)
182 printf("Domain:\t\t%s\n", info5->domain_name.string);
185 static void display_sam_dom_info_6(struct samr_DomInfo6 *info6)
187 printf("Server:\t\t%s\n", info6->primary.string);
190 static void display_sam_dom_info_7(struct samr_DomInfo7 *info7)
192 printf("Server Role:\t%s\n", server_role_str(info7->role));
195 static void display_sam_dom_info_8(struct samr_DomInfo8 *info8)
197 printf("Sequence No:\t%llu\n", (unsigned long long)info8->sequence_num);
198 printf("Domain Create Time:\t%s\n",
199 http_timestring(talloc_tos(), nt_time_to_unix(info8->domain_create_time)));
202 static void display_sam_dom_info_9(struct samr_DomInfo9 *info9)
204 printf("Domain Server State:\t0x%x\n", info9->domain_server_state);
207 static void display_sam_dom_info_12(struct samr_DomInfo12 *info12)
209 printf("Bad password lockout duration: %s\n",
210 display_time(info12->lockout_duration));
211 printf("Reset Lockout after: %s\n",
212 display_time(info12->lockout_window));
213 printf("Lockout after bad attempts: %d\n",
214 info12->lockout_threshold);
217 static void display_sam_dom_info_13(struct samr_DomInfo13 *info13)
219 printf("Sequence No:\t%llu\n", (unsigned long long)info13->sequence_num);
220 printf("Domain Create Time:\t%s\n",
221 http_timestring(talloc_tos(), nt_time_to_unix(info13->domain_create_time)));
222 printf("Sequence No at last promotion:\t%llu\n",
223 (unsigned long long)info13->modified_count_at_last_promotion);
226 static void display_sam_info_1(struct samr_DispEntryGeneral *r)
228 printf("index: 0x%x ", r->idx);
229 printf("RID: 0x%x ", r->rid);
230 printf("acb: 0x%08x ", r->acct_flags);
231 printf("Account: %s\t", r->account_name.string);
232 printf("Name: %s\t", r->full_name.string);
233 printf("Desc: %s\n", r->description.string);
236 static void display_sam_info_2(struct samr_DispEntryFull *r)
238 printf("index: 0x%x ", r->idx);
239 printf("RID: 0x%x ", r->rid);
240 printf("acb: 0x%08x ", r->acct_flags);
241 printf("Account: %s\t", r->account_name.string);
242 printf("Desc: %s\n", r->description.string);
245 static void display_sam_info_3(struct samr_DispEntryFullGroup *r)
247 printf("index: 0x%x ", r->idx);
248 printf("RID: 0x%x ", r->rid);
249 printf("acb: 0x%08x ", r->acct_flags);
250 printf("Account: %s\t", r->account_name.string);
251 printf("Desc: %s\n", r->description.string);
254 static void display_sam_info_4(struct samr_DispEntryAscii *r)
256 printf("index: 0x%x ", r->idx);
257 printf("Account: %s\n", r->account_name.string);
260 static void display_sam_info_5(struct samr_DispEntryAscii *r)
262 printf("index: 0x%x ", r->idx);
263 printf("Account: %s\n", r->account_name.string);
266 /****************************************************************************
267 ****************************************************************************/
269 static NTSTATUS get_domain_handle(struct rpc_pipe_client *cli,
272 struct policy_handle *connect_pol,
273 uint32_t access_mask,
274 struct dom_sid *_domain_sid,
275 struct policy_handle *domain_pol)
278 if (StrCaseCmp(sam, "domain") == 0) {
279 return rpccli_samr_OpenDomain(cli, mem_ctx,
284 } else if (StrCaseCmp(sam, "builtin") == 0) {
285 return rpccli_samr_OpenDomain(cli, mem_ctx,
288 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
292 return NT_STATUS_INVALID_PARAMETER;
295 /**********************************************************************
296 * Query user information
298 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
300 int argc, const char **argv)
302 struct policy_handle connect_pol, domain_pol, user_pol;
303 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
304 uint32 info_level = 21;
305 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
306 union samr_UserInfo *info = NULL;
309 if ((argc < 2) || (argc > 4)) {
310 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
314 sscanf(argv[1], "%i", &user_rid);
317 sscanf(argv[2], "%i", &info_level);
320 sscanf(argv[3], "%x", &access_mask);
323 result = rpccli_try_samr_connects(cli, mem_ctx,
324 MAXIMUM_ALLOWED_ACCESS,
327 if (!NT_STATUS_IS_OK(result))
330 result = rpccli_samr_OpenDomain(cli, mem_ctx,
332 MAXIMUM_ALLOWED_ACCESS,
335 if (!NT_STATUS_IS_OK(result))
338 result = rpccli_samr_OpenUser(cli, mem_ctx,
344 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
347 /* Probably this was a user name, try lookupnames */
348 struct samr_Ids rids, types;
349 struct lsa_String lsa_acct_name;
351 init_lsa_String(&lsa_acct_name, argv[1]);
353 result = rpccli_samr_LookupNames(cli, mem_ctx,
360 if (NT_STATUS_IS_OK(result)) {
361 result = rpccli_samr_OpenUser(cli, mem_ctx,
370 if (!NT_STATUS_IS_OK(result))
373 result = rpccli_samr_QueryUserInfo(cli, mem_ctx,
378 if (!NT_STATUS_IS_OK(result))
381 switch (info_level) {
383 display_samr_user_info_7(&info->info7);
386 display_samr_user_info_9(&info->info9);
389 display_samr_user_info_16(&info->info16);
392 display_samr_user_info_20(&info->info20);
395 display_samr_user_info_21(&info->info21);
398 printf("Unsupported infolevel: %d\n", info_level);
402 rpccli_samr_Close(cli, mem_ctx, &user_pol);
403 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
404 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
410 /****************************************************************************
412 ****************************************************************************/
413 static void display_group_info1(struct samr_GroupInfoAll *info1)
415 printf("\tGroup Name:\t%s\n", info1->name.string);
416 printf("\tDescription:\t%s\n", info1->description.string);
417 printf("\tGroup Attribute:%d\n", info1->attributes);
418 printf("\tNum Members:%d\n", info1->num_members);
421 /****************************************************************************
423 ****************************************************************************/
424 static void display_group_info2(struct lsa_String *info2)
426 printf("\tGroup Description:%s\n", info2->string);
430 /****************************************************************************
432 ****************************************************************************/
433 static void display_group_info3(struct samr_GroupInfoAttributes *info3)
435 printf("\tGroup Attribute:%d\n", info3->attributes);
439 /****************************************************************************
441 ****************************************************************************/
442 static void display_group_info4(struct lsa_String *info4)
444 printf("\tGroup Description:%s\n", info4->string);
447 /****************************************************************************
449 ****************************************************************************/
450 static void display_group_info5(struct samr_GroupInfoAll *info5)
452 printf("\tGroup Name:\t%s\n", info5->name.string);
453 printf("\tDescription:\t%s\n", info5->description.string);
454 printf("\tGroup Attribute:%d\n", info5->attributes);
455 printf("\tNum Members:%d\n", info5->num_members);
458 /****************************************************************************
459 display sam sync structure
460 ****************************************************************************/
461 static void display_group_info(union samr_GroupInfo *info,
462 enum samr_GroupInfoEnum level)
466 display_group_info1(&info->all);
469 display_group_info2(&info->name);
472 display_group_info3(&info->attributes);
475 display_group_info4(&info->description);
478 display_group_info5(&info->all2);
483 /***********************************************************************
484 * Query group information
486 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
488 int argc, const char **argv)
490 struct policy_handle connect_pol, domain_pol, group_pol;
491 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
492 enum samr_GroupInfoEnum info_level = GROUPINFOALL;
493 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
494 union samr_GroupInfo *group_info = NULL;
497 if ((argc < 2) || (argc > 4)) {
498 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
502 sscanf(argv[1], "%i", &group_rid);
505 info_level = atoi(argv[2]);
508 sscanf(argv[3], "%x", &access_mask);
510 result = rpccli_try_samr_connects(cli, mem_ctx,
511 MAXIMUM_ALLOWED_ACCESS,
514 if (!NT_STATUS_IS_OK(result))
517 result = rpccli_samr_OpenDomain(cli, mem_ctx,
519 MAXIMUM_ALLOWED_ACCESS,
523 if (!NT_STATUS_IS_OK(result))
526 result = rpccli_samr_OpenGroup(cli, mem_ctx,
532 if (!NT_STATUS_IS_OK(result))
535 result = rpccli_samr_QueryGroupInfo(cli, mem_ctx,
539 if (!NT_STATUS_IS_OK(result)) {
543 display_group_info(group_info, info_level);
545 rpccli_samr_Close(cli, mem_ctx, &group_pol);
546 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
547 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
552 /* Query groups a user is a member of */
554 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
556 int argc, const char **argv)
558 struct policy_handle connect_pol,
561 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
563 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
565 struct samr_RidWithAttributeArray *rid_array = NULL;
567 if ((argc < 2) || (argc > 3)) {
568 printf("Usage: %s rid [access mask]\n", argv[0]);
572 sscanf(argv[1], "%i", &user_rid);
575 sscanf(argv[2], "%x", &access_mask);
577 result = rpccli_try_samr_connects(cli, mem_ctx,
578 MAXIMUM_ALLOWED_ACCESS,
581 if (!NT_STATUS_IS_OK(result))
584 result = rpccli_samr_OpenDomain(cli, mem_ctx,
586 MAXIMUM_ALLOWED_ACCESS,
587 &domain_sid, &domain_pol);
589 if (!NT_STATUS_IS_OK(result))
592 result = rpccli_samr_OpenUser(cli, mem_ctx,
598 if (!NT_STATUS_IS_OK(result))
601 result = rpccli_samr_GetGroupsForUser(cli, mem_ctx,
605 if (!NT_STATUS_IS_OK(result))
608 for (i = 0; i < rid_array->count; i++) {
609 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
610 rid_array->rids[i].rid,
611 rid_array->rids[i].attributes);
614 rpccli_samr_Close(cli, mem_ctx, &user_pol);
615 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
616 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
621 /* Query aliases a user is a member of */
623 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
625 int argc, const char **argv)
627 struct policy_handle connect_pol, domain_pol;
628 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
631 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
633 struct lsa_SidArray sid_array;
634 struct samr_Ids alias_rids;
637 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
638 return NT_STATUS_INVALID_PARAMETER;
644 for (i=2; i<argc; i++) {
646 if (!string_to_sid(&tmp_sid, argv[i])) {
647 printf("%s is not a legal SID\n", argv[i]);
648 return NT_STATUS_INVALID_PARAMETER;
650 result = add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
651 if (!NT_STATUS_IS_OK(result)) {
657 sid_array.sids = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_SidPtr, num_sids);
658 if (sid_array.sids == NULL)
659 return NT_STATUS_NO_MEMORY;
661 sid_array.sids = NULL;
664 for (i=0; i<num_sids; i++) {
665 sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sids[i]);
666 if (!sid_array.sids[i].sid) {
667 return NT_STATUS_NO_MEMORY;
671 sid_array.num_sids = num_sids;
673 result = rpccli_try_samr_connects(cli, mem_ctx,
674 MAXIMUM_ALLOWED_ACCESS,
677 if (!NT_STATUS_IS_OK(result))
680 result = get_domain_handle(cli, mem_ctx, argv[1],
686 if (!NT_STATUS_IS_OK(result))
689 result = rpccli_samr_GetAliasMembership(cli, mem_ctx,
693 if (!NT_STATUS_IS_OK(result))
696 for (i = 0; i < alias_rids.count; i++) {
697 printf("\tgroup rid:[0x%x]\n", alias_rids.ids[i]);
700 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
701 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
706 /* Query members of a group */
708 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
710 int argc, const char **argv)
712 struct policy_handle connect_pol, domain_pol, group_pol;
713 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
715 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
717 unsigned int old_timeout;
718 struct samr_RidTypeArray *rids = NULL;
720 if ((argc < 2) || (argc > 3)) {
721 printf("Usage: %s rid [access mask]\n", argv[0]);
725 sscanf(argv[1], "%i", &group_rid);
728 sscanf(argv[2], "%x", &access_mask);
730 result = rpccli_try_samr_connects(cli, mem_ctx,
731 MAXIMUM_ALLOWED_ACCESS,
734 if (!NT_STATUS_IS_OK(result))
737 result = rpccli_samr_OpenDomain(cli, mem_ctx,
739 MAXIMUM_ALLOWED_ACCESS,
743 if (!NT_STATUS_IS_OK(result))
746 result = rpccli_samr_OpenGroup(cli, mem_ctx,
752 if (!NT_STATUS_IS_OK(result))
755 /* Make sure to wait for our DC's reply */
756 old_timeout = rpccli_set_timeout(cli, 30000); /* 30 seconds. */
757 rpccli_set_timeout(cli, MAX(30000, old_timeout)); /* At least 30 sec */
759 result = rpccli_samr_QueryGroupMember(cli, mem_ctx,
763 rpccli_set_timeout(cli, old_timeout);
765 if (!NT_STATUS_IS_OK(result))
768 for (i = 0; i < rids->count; i++) {
769 printf("\trid:[0x%x] attr:[0x%x]\n", rids->rids[i],
773 rpccli_samr_Close(cli, mem_ctx, &group_pol);
774 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
775 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
780 /* Enumerate domain users */
782 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
784 int argc, const char **argv)
786 struct policy_handle connect_pol, domain_pol;
787 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
788 uint32 start_idx, size, num_dom_users, i;
789 struct samr_SamArray *dom_users = NULL;
790 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
791 uint32 acb_mask = ACB_NORMAL;
793 if ((argc < 1) || (argc > 3)) {
794 printf("Usage: %s [access_mask] [acb_mask]\n", argv[0]);
799 sscanf(argv[1], "%x", &access_mask);
802 sscanf(argv[2], "%x", &acb_mask);
804 /* Get sam policy handle */
806 result = rpccli_try_samr_connects(cli, mem_ctx,
807 MAXIMUM_ALLOWED_ACCESS,
810 if (!NT_STATUS_IS_OK(result))
813 /* Get domain policy handle */
815 result = rpccli_samr_OpenDomain(cli, mem_ctx,
821 if (!NT_STATUS_IS_OK(result))
824 /* Enumerate domain users */
830 result = rpccli_samr_EnumDomainUsers(cli, mem_ctx,
838 if (NT_STATUS_IS_OK(result) ||
839 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
841 for (i = 0; i < num_dom_users; i++)
842 printf("user:[%s] rid:[0x%x]\n",
843 dom_users->entries[i].name.string,
844 dom_users->entries[i].idx);
847 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
850 if (is_valid_policy_hnd(&domain_pol))
851 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
853 if (is_valid_policy_hnd(&connect_pol))
854 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
859 /* Enumerate domain groups */
861 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
863 int argc, const char **argv)
865 struct policy_handle connect_pol, domain_pol;
866 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
867 uint32 start_idx, size, num_dom_groups, i;
868 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
869 struct samr_SamArray *dom_groups = NULL;
871 if ((argc < 1) || (argc > 2)) {
872 printf("Usage: %s [access_mask]\n", argv[0]);
877 sscanf(argv[1], "%x", &access_mask);
879 /* Get sam policy handle */
881 result = rpccli_try_samr_connects(cli, mem_ctx,
882 MAXIMUM_ALLOWED_ACCESS,
885 if (!NT_STATUS_IS_OK(result))
888 /* Get domain policy handle */
890 result = rpccli_samr_OpenDomain(cli, mem_ctx,
896 if (!NT_STATUS_IS_OK(result))
899 /* Enumerate domain groups */
905 result = rpccli_samr_EnumDomainGroups(cli, mem_ctx,
911 if (NT_STATUS_IS_OK(result) ||
912 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
914 for (i = 0; i < num_dom_groups; i++)
915 printf("group:[%s] rid:[0x%x]\n",
916 dom_groups->entries[i].name.string,
917 dom_groups->entries[i].idx);
920 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
923 if (is_valid_policy_hnd(&domain_pol))
924 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
926 if (is_valid_policy_hnd(&connect_pol))
927 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
932 /* Enumerate alias groups */
934 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
936 int argc, const char **argv)
938 struct policy_handle connect_pol, domain_pol;
939 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
940 uint32 start_idx, size, num_als_groups, i;
941 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
942 struct samr_SamArray *als_groups = NULL;
944 if ((argc < 2) || (argc > 3)) {
945 printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
950 sscanf(argv[2], "%x", &access_mask);
952 /* Get sam policy handle */
954 result = rpccli_try_samr_connects(cli, mem_ctx,
955 MAXIMUM_ALLOWED_ACCESS,
958 if (!NT_STATUS_IS_OK(result))
961 /* Get domain policy handle */
963 result = get_domain_handle(cli, mem_ctx, argv[1],
969 if (!NT_STATUS_IS_OK(result))
972 /* Enumerate alias groups */
975 size = 0xffff; /* Number of groups to retrieve */
978 result = rpccli_samr_EnumDomainAliases(cli, mem_ctx,
985 if (NT_STATUS_IS_OK(result) ||
986 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
988 for (i = 0; i < num_als_groups; i++)
989 printf("group:[%s] rid:[0x%x]\n",
990 als_groups->entries[i].name.string,
991 als_groups->entries[i].idx);
993 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
996 if (is_valid_policy_hnd(&domain_pol))
997 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
999 if (is_valid_policy_hnd(&connect_pol))
1000 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1005 /* Enumerate domains */
1007 static NTSTATUS cmd_samr_enum_domains(struct rpc_pipe_client *cli,
1008 TALLOC_CTX *mem_ctx,
1009 int argc, const char **argv)
1011 struct policy_handle connect_pol;
1012 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1013 uint32 start_idx, size, num_entries, i;
1014 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1015 struct samr_SamArray *sam = NULL;
1017 if ((argc < 1) || (argc > 2)) {
1018 printf("Usage: %s [access mask]\n", argv[0]);
1019 return NT_STATUS_OK;
1023 sscanf(argv[1], "%x", &access_mask);
1026 /* Get sam policy handle */
1028 result = rpccli_try_samr_connects(cli, mem_ctx,
1032 if (!NT_STATUS_IS_OK(result)) {
1036 /* Enumerate alias groups */
1042 result = rpccli_samr_EnumDomains(cli, mem_ctx,
1049 if (NT_STATUS_IS_OK(result) ||
1050 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1052 for (i = 0; i < num_entries; i++)
1053 printf("name:[%s] idx:[0x%x]\n",
1054 sam->entries[i].name.string,
1055 sam->entries[i].idx);
1057 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1060 if (is_valid_policy_hnd(&connect_pol)) {
1061 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1068 /* Query alias membership */
1070 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
1071 TALLOC_CTX *mem_ctx,
1072 int argc, const char **argv)
1074 struct policy_handle connect_pol, domain_pol, alias_pol;
1075 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1076 uint32 alias_rid, i;
1077 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1078 struct lsa_SidArray sid_array;
1080 if ((argc < 3) || (argc > 4)) {
1081 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
1082 return NT_STATUS_OK;
1085 sscanf(argv[2], "%i", &alias_rid);
1088 sscanf(argv[3], "%x", &access_mask);
1090 /* Open SAMR handle */
1092 result = rpccli_try_samr_connects(cli, mem_ctx,
1093 MAXIMUM_ALLOWED_ACCESS,
1096 if (!NT_STATUS_IS_OK(result))
1099 /* Open handle on domain */
1101 result = get_domain_handle(cli, mem_ctx, argv[1],
1103 MAXIMUM_ALLOWED_ACCESS,
1107 if (!NT_STATUS_IS_OK(result))
1110 /* Open handle on alias */
1112 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1117 if (!NT_STATUS_IS_OK(result))
1120 result = rpccli_samr_GetMembersInAlias(cli, mem_ctx,
1124 if (!NT_STATUS_IS_OK(result))
1127 for (i = 0; i < sid_array.num_sids; i++) {
1130 sid_to_fstring(sid_str, sid_array.sids[i].sid);
1131 printf("\tsid:[%s]\n", sid_str);
1134 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1135 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1136 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1141 /* Query alias info */
1143 static NTSTATUS cmd_samr_query_aliasinfo(struct rpc_pipe_client *cli,
1144 TALLOC_CTX *mem_ctx,
1145 int argc, const char **argv)
1147 struct policy_handle connect_pol, domain_pol, alias_pol;
1148 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1150 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1151 union samr_AliasInfo *info = NULL;
1152 enum samr_AliasInfoEnum level = ALIASINFOALL;
1154 if ((argc < 3) || (argc > 4)) {
1155 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1157 return NT_STATUS_OK;
1160 sscanf(argv[2], "%i", &alias_rid);
1163 level = atoi(argv[3]);
1167 sscanf(argv[4], "%x", &access_mask);
1170 /* Open SAMR handle */
1172 result = rpccli_try_samr_connects(cli, mem_ctx,
1173 SEC_FLAG_MAXIMUM_ALLOWED,
1176 if (!NT_STATUS_IS_OK(result)) {
1180 /* Open handle on domain */
1182 result = get_domain_handle(cli, mem_ctx, argv[1],
1184 SEC_FLAG_MAXIMUM_ALLOWED,
1188 if (!NT_STATUS_IS_OK(result)) {
1192 /* Open handle on alias */
1194 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1199 if (!NT_STATUS_IS_OK(result)) {
1203 result = rpccli_samr_QueryAliasInfo(cli, mem_ctx,
1208 if (!NT_STATUS_IS_OK(result)) {
1214 printf("Name: %s\n", info->all.name.string);
1215 printf("Description: %s\n", info->all.description.string);
1216 printf("Num Members: %d\n", info->all.num_members);
1219 printf("Name: %s\n", info->name.string);
1221 case ALIASINFODESCRIPTION:
1222 printf("Description: %s\n", info->description.string);
1228 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1229 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1230 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1236 /* Query delete an alias membership */
1238 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
1239 TALLOC_CTX *mem_ctx,
1240 int argc, const char **argv)
1242 struct policy_handle connect_pol, domain_pol, alias_pol;
1243 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1245 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1248 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
1249 return NT_STATUS_OK;
1252 alias_rid = strtoul(argv[2], NULL, 10);
1254 /* Open SAMR handle */
1256 result = rpccli_try_samr_connects(cli, mem_ctx,
1257 MAXIMUM_ALLOWED_ACCESS,
1260 if (!NT_STATUS_IS_OK(result))
1263 /* Open handle on domain */
1265 result = get_domain_handle(cli, mem_ctx, argv[1],
1267 MAXIMUM_ALLOWED_ACCESS,
1271 if (!NT_STATUS_IS_OK(result))
1274 /* Open handle on alias */
1276 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1281 if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
1282 /* Probably this was a user name, try lookupnames */
1283 struct samr_Ids rids, types;
1284 struct lsa_String lsa_acct_name;
1286 init_lsa_String(&lsa_acct_name, argv[2]);
1288 result = rpccli_samr_LookupNames(cli, mem_ctx,
1295 if (NT_STATUS_IS_OK(result)) {
1296 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1304 result = rpccli_samr_DeleteDomAlias(cli, mem_ctx,
1307 if (!NT_STATUS_IS_OK(result))
1310 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1311 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1316 /* Query display info */
1318 static NTSTATUS cmd_samr_query_dispinfo_internal(struct rpc_pipe_client *cli,
1319 TALLOC_CTX *mem_ctx,
1320 int argc, const char **argv,
1323 struct policy_handle connect_pol, domain_pol;
1324 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1325 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries = 0, i;
1326 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1327 uint32 info_level = 1;
1328 union samr_DispInfo info;
1330 bool got_params = False; /* Use get_query_dispinfo_params() or not? */
1331 uint32_t total_size, returned_size;
1334 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
1335 return NT_STATUS_OK;
1339 sscanf(argv[1], "%i", &info_level);
1342 sscanf(argv[2], "%i", &start_idx);
1345 sscanf(argv[3], "%i", &max_entries);
1350 sscanf(argv[4], "%i", &max_size);
1355 sscanf(argv[5], "%x", &access_mask);
1357 /* Get sam policy handle */
1359 result = rpccli_try_samr_connects(cli, mem_ctx,
1360 MAXIMUM_ALLOWED_ACCESS,
1363 if (!NT_STATUS_IS_OK(result))
1366 /* Get domain policy handle */
1368 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1374 if (!NT_STATUS_IS_OK(result))
1377 /* Query display info */
1382 get_query_dispinfo_params(
1383 loop_count, &max_entries, &max_size);
1386 case NDR_SAMR_QUERYDISPLAYINFO:
1387 result = rpccli_samr_QueryDisplayInfo(cli, mem_ctx,
1397 case NDR_SAMR_QUERYDISPLAYINFO2:
1398 result = rpccli_samr_QueryDisplayInfo2(cli, mem_ctx,
1409 case NDR_SAMR_QUERYDISPLAYINFO3:
1410 result = rpccli_samr_QueryDisplayInfo3(cli, mem_ctx,
1422 return NT_STATUS_INVALID_PARAMETER;
1425 if (!NT_STATUS_IS_OK(result) &&
1426 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
1427 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
1433 switch (info_level) {
1435 num_entries = info.info1.count;
1438 num_entries = info.info2.count;
1441 num_entries = info.info3.count;
1444 num_entries = info.info4.count;
1447 num_entries = info.info5.count;
1453 start_idx += num_entries;
1455 if (num_entries == 0)
1458 for (i = 0; i < num_entries; i++) {
1459 switch (info_level) {
1461 display_sam_info_1(&info.info1.entries[i]);
1464 display_sam_info_2(&info.info2.entries[i]);
1467 display_sam_info_3(&info.info3.entries[i]);
1470 display_sam_info_4(&info.info4.entries[i]);
1473 display_sam_info_5(&info.info5.entries[i]);
1477 } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1479 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1480 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1485 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
1486 TALLOC_CTX *mem_ctx,
1487 int argc, const char **argv)
1489 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1490 NDR_SAMR_QUERYDISPLAYINFO);
1493 static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1494 TALLOC_CTX *mem_ctx,
1495 int argc, const char **argv)
1497 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1498 NDR_SAMR_QUERYDISPLAYINFO2);
1501 static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1502 TALLOC_CTX *mem_ctx,
1503 int argc, const char **argv)
1505 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1506 NDR_SAMR_QUERYDISPLAYINFO3);
1509 /* Query domain info */
1511 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
1512 TALLOC_CTX *mem_ctx,
1513 int argc, const char **argv)
1515 struct policy_handle connect_pol, domain_pol;
1516 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1517 uint32 switch_level = 2;
1518 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1519 union samr_DomainInfo *info = NULL;
1522 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1523 return NT_STATUS_OK;
1527 sscanf(argv[1], "%i", &switch_level);
1530 sscanf(argv[2], "%x", &access_mask);
1532 /* Get sam policy handle */
1534 result = rpccli_try_samr_connects(cli, mem_ctx,
1535 MAXIMUM_ALLOWED_ACCESS,
1538 if (!NT_STATUS_IS_OK(result))
1541 /* Get domain policy handle */
1543 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1549 if (!NT_STATUS_IS_OK(result))
1552 /* Query domain info */
1554 result = rpccli_samr_QueryDomainInfo(cli, mem_ctx,
1559 if (!NT_STATUS_IS_OK(result))
1562 /* Display domain info */
1564 switch (switch_level) {
1566 display_sam_dom_info_1(&info->info1);
1569 display_sam_dom_info_2(&info->general);
1572 display_sam_dom_info_3(&info->info3);
1575 display_sam_dom_info_4(&info->oem);
1578 display_sam_dom_info_5(&info->info5);
1581 display_sam_dom_info_6(&info->info6);
1584 display_sam_dom_info_7(&info->info7);
1587 display_sam_dom_info_8(&info->info8);
1590 display_sam_dom_info_9(&info->info9);
1593 display_sam_dom_info_12(&info->info12);
1596 display_sam_dom_info_13(&info->info13);
1600 printf("cannot display domain info for switch value %d\n",
1607 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1608 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1612 /* Create domain user */
1614 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
1615 TALLOC_CTX *mem_ctx,
1616 int argc, const char **argv)
1618 struct policy_handle connect_pol, domain_pol, user_pol;
1619 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1620 struct lsa_String acct_name;
1622 uint32 acct_flags, user_rid;
1623 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1624 uint32_t access_granted = 0;
1626 if ((argc < 2) || (argc > 3)) {
1627 printf("Usage: %s username [access mask]\n", argv[0]);
1628 return NT_STATUS_OK;
1631 init_lsa_String(&acct_name, argv[1]);
1634 sscanf(argv[2], "%x", &access_mask);
1636 /* Get sam policy handle */
1638 result = rpccli_try_samr_connects(cli, mem_ctx,
1639 MAXIMUM_ALLOWED_ACCESS,
1642 if (!NT_STATUS_IS_OK(result))
1645 /* Get domain policy handle */
1647 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1653 if (!NT_STATUS_IS_OK(result))
1656 /* Create domain user */
1658 acb_info = ACB_NORMAL;
1659 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
1660 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
1661 SAMR_USER_ACCESS_SET_PASSWORD |
1662 SAMR_USER_ACCESS_GET_ATTRIBUTES |
1663 SAMR_USER_ACCESS_SET_ATTRIBUTES;
1665 result = rpccli_samr_CreateUser2(cli, mem_ctx,
1674 if (!NT_STATUS_IS_OK(result))
1677 result = rpccli_samr_Close(cli, mem_ctx, &user_pol);
1678 if (!NT_STATUS_IS_OK(result)) goto done;
1680 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1681 if (!NT_STATUS_IS_OK(result)) goto done;
1683 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1684 if (!NT_STATUS_IS_OK(result)) goto done;
1690 /* Create domain group */
1692 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
1693 TALLOC_CTX *mem_ctx,
1694 int argc, const char **argv)
1696 struct policy_handle connect_pol, domain_pol, group_pol;
1697 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1698 struct lsa_String grp_name;
1699 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1702 if ((argc < 2) || (argc > 3)) {
1703 printf("Usage: %s groupname [access mask]\n", argv[0]);
1704 return NT_STATUS_OK;
1707 init_lsa_String(&grp_name, argv[1]);
1710 sscanf(argv[2], "%x", &access_mask);
1712 /* Get sam policy handle */
1714 result = rpccli_try_samr_connects(cli, mem_ctx,
1715 MAXIMUM_ALLOWED_ACCESS,
1718 if (!NT_STATUS_IS_OK(result))
1721 /* Get domain policy handle */
1723 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1729 if (!NT_STATUS_IS_OK(result))
1732 /* Create domain user */
1733 result = rpccli_samr_CreateDomainGroup(cli, mem_ctx,
1736 MAXIMUM_ALLOWED_ACCESS,
1740 if (!NT_STATUS_IS_OK(result))
1743 result = rpccli_samr_Close(cli, mem_ctx, &group_pol);
1744 if (!NT_STATUS_IS_OK(result)) goto done;
1746 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1747 if (!NT_STATUS_IS_OK(result)) goto done;
1749 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1750 if (!NT_STATUS_IS_OK(result)) goto done;
1756 /* Create domain alias */
1758 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
1759 TALLOC_CTX *mem_ctx,
1760 int argc, const char **argv)
1762 struct policy_handle connect_pol, domain_pol, alias_pol;
1763 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1764 struct lsa_String alias_name;
1765 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1768 if ((argc < 2) || (argc > 3)) {
1769 printf("Usage: %s aliasname [access mask]\n", argv[0]);
1770 return NT_STATUS_OK;
1773 init_lsa_String(&alias_name, argv[1]);
1776 sscanf(argv[2], "%x", &access_mask);
1778 /* Get sam policy handle */
1780 result = rpccli_try_samr_connects(cli, mem_ctx,
1781 MAXIMUM_ALLOWED_ACCESS,
1784 if (!NT_STATUS_IS_OK(result))
1787 /* Get domain policy handle */
1789 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1795 if (!NT_STATUS_IS_OK(result))
1798 /* Create domain user */
1800 result = rpccli_samr_CreateDomAlias(cli, mem_ctx,
1803 MAXIMUM_ALLOWED_ACCESS,
1807 if (!NT_STATUS_IS_OK(result))
1810 result = rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1811 if (!NT_STATUS_IS_OK(result)) goto done;
1813 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1814 if (!NT_STATUS_IS_OK(result)) goto done;
1816 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1817 if (!NT_STATUS_IS_OK(result)) goto done;
1823 /* Lookup sam names */
1825 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
1826 TALLOC_CTX *mem_ctx,
1827 int argc, const char **argv)
1829 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1830 struct policy_handle connect_pol, domain_pol;
1832 struct samr_Ids rids, name_types;
1834 struct lsa_String *names = NULL;;
1837 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1838 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1839 printf("or check on the builtin SID: S-1-5-32\n");
1840 return NT_STATUS_OK;
1843 /* Get sam policy and domain handles */
1845 result = rpccli_try_samr_connects(cli, mem_ctx,
1846 MAXIMUM_ALLOWED_ACCESS,
1849 if (!NT_STATUS_IS_OK(result))
1852 result = get_domain_handle(cli, mem_ctx, argv[1],
1854 MAXIMUM_ALLOWED_ACCESS,
1858 if (!NT_STATUS_IS_OK(result))
1863 num_names = argc - 2;
1865 if ((names = TALLOC_ARRAY(mem_ctx, struct lsa_String, num_names)) == NULL) {
1866 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1867 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1868 result = NT_STATUS_NO_MEMORY;
1872 for (i = 0; i < num_names; i++) {
1873 init_lsa_String(&names[i], argv[i + 2]);
1876 result = rpccli_samr_LookupNames(cli, mem_ctx,
1883 if (!NT_STATUS_IS_OK(result))
1886 /* Display results */
1888 for (i = 0; i < num_names; i++)
1889 printf("name %s: 0x%x (%d)\n", names[i].string, rids.ids[i],
1892 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1893 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1898 /* Lookup sam rids */
1900 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
1901 TALLOC_CTX *mem_ctx,
1902 int argc, const char **argv)
1904 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1905 struct policy_handle connect_pol, domain_pol;
1906 uint32_t num_rids, *rids;
1907 struct lsa_Strings names;
1908 struct samr_Ids types;
1913 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
1914 return NT_STATUS_OK;
1917 /* Get sam policy and domain handles */
1919 result = rpccli_try_samr_connects(cli, mem_ctx,
1920 MAXIMUM_ALLOWED_ACCESS,
1923 if (!NT_STATUS_IS_OK(result))
1926 result = get_domain_handle(cli, mem_ctx, argv[1],
1928 MAXIMUM_ALLOWED_ACCESS,
1932 if (!NT_STATUS_IS_OK(result))
1937 num_rids = argc - 2;
1939 if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
1940 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1941 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1942 result = NT_STATUS_NO_MEMORY;
1946 for (i = 0; i < argc - 2; i++)
1947 sscanf(argv[i + 2], "%i", &rids[i]);
1949 result = rpccli_samr_LookupRids(cli, mem_ctx,
1956 if (!NT_STATUS_IS_OK(result) &&
1957 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1960 /* Display results */
1962 for (i = 0; i < num_rids; i++) {
1963 printf("rid 0x%x: %s (%d)\n",
1964 rids[i], names.names[i].string, types.ids[i]);
1967 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1968 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1973 /* Delete domain group */
1975 static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
1976 TALLOC_CTX *mem_ctx,
1977 int argc, const char **argv)
1979 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1980 struct policy_handle connect_pol, domain_pol, group_pol;
1981 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1983 if ((argc < 2) || (argc > 3)) {
1984 printf("Usage: %s groupname\n", argv[0]);
1985 return NT_STATUS_OK;
1989 sscanf(argv[2], "%x", &access_mask);
1991 /* Get sam policy and domain handles */
1993 result = rpccli_try_samr_connects(cli, mem_ctx,
1994 MAXIMUM_ALLOWED_ACCESS,
1997 if (!NT_STATUS_IS_OK(result))
2000 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2002 MAXIMUM_ALLOWED_ACCESS,
2006 if (!NT_STATUS_IS_OK(result))
2009 /* Get handle on group */
2012 struct samr_Ids group_rids, name_types;
2013 struct lsa_String lsa_acct_name;
2015 init_lsa_String(&lsa_acct_name, argv[1]);
2017 result = rpccli_samr_LookupNames(cli, mem_ctx,
2023 if (!NT_STATUS_IS_OK(result))
2026 result = rpccli_samr_OpenGroup(cli, mem_ctx,
2032 if (!NT_STATUS_IS_OK(result))
2038 result = rpccli_samr_DeleteDomainGroup(cli, mem_ctx,
2041 if (!NT_STATUS_IS_OK(result))
2044 /* Display results */
2046 rpccli_samr_Close(cli, mem_ctx, &group_pol);
2047 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2048 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2054 /* Delete domain user */
2056 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
2057 TALLOC_CTX *mem_ctx,
2058 int argc, const char **argv)
2060 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2061 struct policy_handle connect_pol, domain_pol, user_pol;
2062 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2064 if ((argc < 2) || (argc > 3)) {
2065 printf("Usage: %s username\n", argv[0]);
2066 return NT_STATUS_OK;
2070 sscanf(argv[2], "%x", &access_mask);
2072 /* Get sam policy and domain handles */
2074 result = rpccli_try_samr_connects(cli, mem_ctx,
2075 MAXIMUM_ALLOWED_ACCESS,
2078 if (!NT_STATUS_IS_OK(result))
2081 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2083 MAXIMUM_ALLOWED_ACCESS,
2087 if (!NT_STATUS_IS_OK(result))
2090 /* Get handle on user */
2093 struct samr_Ids user_rids, name_types;
2094 struct lsa_String lsa_acct_name;
2096 init_lsa_String(&lsa_acct_name, argv[1]);
2098 result = rpccli_samr_LookupNames(cli, mem_ctx,
2105 if (!NT_STATUS_IS_OK(result))
2108 result = rpccli_samr_OpenUser(cli, mem_ctx,
2114 if (!NT_STATUS_IS_OK(result))
2120 result = rpccli_samr_DeleteUser(cli, mem_ctx,
2123 if (!NT_STATUS_IS_OK(result))
2126 /* Display results */
2128 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2129 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2130 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2136 /**********************************************************************
2137 * Query user security object
2139 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
2140 TALLOC_CTX *mem_ctx,
2141 int argc, const char **argv)
2143 struct policy_handle connect_pol, domain_pol, user_pol, *pol;
2144 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2145 uint32 sec_info = DACL_SECURITY_INFORMATION;
2146 uint32 user_rid = 0;
2147 TALLOC_CTX *ctx = NULL;
2148 SEC_DESC_BUF *sec_desc_buf=NULL;
2149 bool domain = False;
2151 ctx=talloc_init("cmd_samr_query_sec_obj");
2153 if ((argc < 1) || (argc > 3)) {
2154 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
2155 printf("\tSpecify rid for security on user, -d for security on domain\n");
2156 talloc_destroy(ctx);
2157 return NT_STATUS_OK;
2161 if (strcmp(argv[1], "-d") == 0)
2164 sscanf(argv[1], "%i", &user_rid);
2168 sec_info = atoi(argv[2]);
2171 result = rpccli_try_samr_connects(cli, mem_ctx,
2172 MAXIMUM_ALLOWED_ACCESS,
2175 if (!NT_STATUS_IS_OK(result))
2178 if (domain || user_rid)
2179 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2181 MAXIMUM_ALLOWED_ACCESS,
2185 if (!NT_STATUS_IS_OK(result))
2189 result = rpccli_samr_OpenUser(cli, mem_ctx,
2191 MAXIMUM_ALLOWED_ACCESS,
2195 if (!NT_STATUS_IS_OK(result))
2198 /* Pick which query pol to use */
2208 /* Query SAM security object */
2210 result = rpccli_samr_QuerySecurity(cli, mem_ctx,
2215 if (!NT_STATUS_IS_OK(result))
2218 display_sec_desc(sec_desc_buf->sd);
2220 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2221 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2222 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2224 talloc_destroy(ctx);
2228 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
2229 TALLOC_CTX *mem_ctx,
2230 int argc, const char **argv)
2232 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2233 struct policy_handle connect_pol, domain_pol, user_pol;
2234 struct samr_PwInfo info;
2238 printf("Usage: %s rid\n", argv[0]);
2239 return NT_STATUS_OK;
2242 sscanf(argv[1], "%i", &rid);
2244 result = rpccli_try_samr_connects(cli, mem_ctx,
2245 MAXIMUM_ALLOWED_ACCESS,
2248 if (!NT_STATUS_IS_OK(result)) {
2252 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2254 MAXIMUM_ALLOWED_ACCESS,
2258 if (!NT_STATUS_IS_OK(result)) {
2262 result = rpccli_samr_OpenUser(cli, mem_ctx,
2264 MAXIMUM_ALLOWED_ACCESS,
2268 if (!NT_STATUS_IS_OK(result)) {
2272 result = rpccli_samr_GetUserPwInfo(cli, mem_ctx, &user_pol, &info);
2273 if (NT_STATUS_IS_OK(result)) {
2274 printf("min_password_length: %d\n", info.min_password_length);
2276 NDR_PRINT_STRUCT_STRING(mem_ctx,
2277 samr_PasswordProperties, &info.password_properties));
2281 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2282 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2283 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2288 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
2289 TALLOC_CTX *mem_ctx,
2290 int argc, const char **argv)
2292 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2293 struct lsa_String domain_name;
2294 struct samr_PwInfo info;
2296 if (argc < 1 || argc > 3) {
2297 printf("Usage: %s <domain>\n", argv[0]);
2298 return NT_STATUS_OK;
2301 init_lsa_String(&domain_name, argv[1]);
2303 result = rpccli_samr_GetDomPwInfo(cli, mem_ctx, &domain_name, &info);
2305 if (NT_STATUS_IS_OK(result)) {
2306 printf("min_password_length: %d\n", info.min_password_length);
2307 display_password_properties(info.password_properties);
2313 /* Look up domain name */
2315 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
2316 TALLOC_CTX *mem_ctx,
2317 int argc, const char **argv)
2319 struct policy_handle connect_pol, domain_pol;
2320 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2321 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2323 struct lsa_String domain_name;
2324 DOM_SID *sid = NULL;
2327 printf("Usage: %s domain_name\n", argv[0]);
2328 return NT_STATUS_OK;
2331 init_lsa_String(&domain_name, argv[1]);
2333 result = rpccli_try_samr_connects(cli, mem_ctx,
2337 if (!NT_STATUS_IS_OK(result))
2340 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2346 if (!NT_STATUS_IS_OK(result))
2349 result = rpccli_samr_LookupDomain(cli, mem_ctx,
2354 if (NT_STATUS_IS_OK(result)) {
2355 sid_to_fstring(sid_string, sid);
2356 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2357 argv[1], sid_string);
2360 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2361 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2366 /* Change user password */
2368 static NTSTATUS cmd_samr_chgpasswd(struct rpc_pipe_client *cli,
2369 TALLOC_CTX *mem_ctx,
2370 int argc, const char **argv)
2372 struct policy_handle connect_pol, domain_pol, user_pol;
2373 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2374 const char *user, *oldpass, *newpass;
2375 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2376 struct samr_Ids rids, types;
2377 struct lsa_String lsa_acct_name;
2380 printf("Usage: %s username oldpass newpass\n", argv[0]);
2381 return NT_STATUS_INVALID_PARAMETER;
2388 /* Get sam policy handle */
2390 result = rpccli_try_samr_connects(cli, mem_ctx,
2391 MAXIMUM_ALLOWED_ACCESS,
2394 if (!NT_STATUS_IS_OK(result)) {
2398 /* Get domain policy handle */
2400 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2406 if (!NT_STATUS_IS_OK(result)) {
2410 init_lsa_String(&lsa_acct_name, user);
2412 result = rpccli_samr_LookupNames(cli, mem_ctx,
2419 if (!NT_STATUS_IS_OK(result)) {
2423 result = rpccli_samr_OpenUser(cli, mem_ctx,
2429 if (!NT_STATUS_IS_OK(result)) {
2433 /* Change user password */
2434 result = rpccli_samr_chgpasswd_user(cli, mem_ctx,
2439 if (!NT_STATUS_IS_OK(result)) {
2444 if (is_valid_policy_hnd(&user_pol)) {
2445 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2447 if (is_valid_policy_hnd(&domain_pol)) {
2448 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2450 if (is_valid_policy_hnd(&connect_pol)) {
2451 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2458 /* Change user password */
2460 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
2461 TALLOC_CTX *mem_ctx,
2462 int argc, const char **argv)
2464 struct policy_handle connect_pol, domain_pol;
2465 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2466 const char *user, *oldpass, *newpass;
2467 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2470 printf("Usage: %s username oldpass newpass\n", argv[0]);
2471 return NT_STATUS_INVALID_PARAMETER;
2478 /* Get sam policy handle */
2480 result = rpccli_try_samr_connects(cli, mem_ctx,
2481 MAXIMUM_ALLOWED_ACCESS,
2484 if (!NT_STATUS_IS_OK(result))
2487 /* Get domain policy handle */
2489 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2495 if (!NT_STATUS_IS_OK(result))
2498 /* Change user password */
2499 result = rpccli_samr_chgpasswd_user2(cli, mem_ctx, user, newpass, oldpass);
2501 if (!NT_STATUS_IS_OK(result))
2504 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2505 if (!NT_STATUS_IS_OK(result)) goto done;
2507 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2508 if (!NT_STATUS_IS_OK(result)) goto done;
2515 /* Change user password */
2517 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
2518 TALLOC_CTX *mem_ctx,
2519 int argc, const char **argv)
2521 struct policy_handle connect_pol, domain_pol;
2522 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2523 const char *user, *oldpass, *newpass;
2524 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2525 struct samr_DomInfo1 *info = NULL;
2526 struct samr_ChangeReject *reject = NULL;
2529 printf("Usage: %s username oldpass newpass\n", argv[0]);
2530 return NT_STATUS_INVALID_PARAMETER;
2537 /* Get sam policy handle */
2539 result = rpccli_try_samr_connects(cli, mem_ctx,
2540 MAXIMUM_ALLOWED_ACCESS,
2543 if (!NT_STATUS_IS_OK(result))
2546 /* Get domain policy handle */
2548 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2554 if (!NT_STATUS_IS_OK(result))
2557 /* Change user password */
2558 result = rpccli_samr_chgpasswd_user3(cli, mem_ctx,
2565 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
2567 display_sam_dom_info_1(info);
2569 switch (reject->reason) {
2570 case SAMR_REJECT_TOO_SHORT:
2571 d_printf("SAMR_REJECT_TOO_SHORT\n");
2573 case SAMR_REJECT_IN_HISTORY:
2574 d_printf("SAMR_REJECT_IN_HISTORY\n");
2576 case SAMR_REJECT_COMPLEXITY:
2577 d_printf("SAMR_REJECT_COMPLEXITY\n");
2579 case SAMR_REJECT_OTHER:
2580 d_printf("SAMR_REJECT_OTHER\n");
2583 d_printf("unknown reject reason: %d\n",
2589 if (!NT_STATUS_IS_OK(result))
2592 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2593 if (!NT_STATUS_IS_OK(result)) goto done;
2595 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2596 if (!NT_STATUS_IS_OK(result)) goto done;
2602 static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
2603 TALLOC_CTX *mem_ctx,
2604 int argc, const char **argv,
2607 struct policy_handle connect_pol, domain_pol, user_pol;
2608 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
2609 const char *user, *param;
2610 uint32_t access_mask = MAXIMUM_ALLOWED_ACCESS;
2613 union samr_UserInfo info;
2614 struct samr_CryptPassword pwd_buf;
2615 struct samr_CryptPasswordEx pwd_buf_ex;
2616 uint8_t nt_hash[16];
2617 uint8_t lm_hash[16];
2618 DATA_BLOB session_key;
2619 uint8_t password_expired = 0;
2622 printf("Usage: %s username level password [password_expired]\n",
2624 return NT_STATUS_INVALID_PARAMETER;
2628 level = atoi(argv[2]);
2632 password_expired = atoi(argv[4]);
2635 status = cli_get_session_key(mem_ctx, cli, &session_key);
2636 if (!NT_STATUS_IS_OK(status)) {
2640 init_samr_CryptPassword(param, &session_key, &pwd_buf);
2641 init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
2642 nt_lm_owf_gen(param, nt_hash, lm_hash);
2648 in = data_blob_const(nt_hash, 16);
2649 out = data_blob_talloc_zero(mem_ctx, 16);
2650 sess_crypt_blob(&out, &in, &session_key, true);
2651 memcpy(nt_hash, out.data, out.length);
2655 in = data_blob_const(lm_hash, 16);
2656 out = data_blob_talloc_zero(mem_ctx, 16);
2657 sess_crypt_blob(&out, &in, &session_key, true);
2658 memcpy(lm_hash, out.data, out.length);
2661 memcpy(info.info18.nt_pwd.hash, nt_hash, 16);
2662 memcpy(info.info18.lm_pwd.hash, lm_hash, 16);
2663 info.info18.nt_pwd_active = true;
2664 info.info18.lm_pwd_active = true;
2665 info.info18.password_expired = password_expired;
2669 ZERO_STRUCT(info.info21);
2671 info.info21.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2672 SAMR_FIELD_LM_PASSWORD_PRESENT;
2674 info.info21.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2675 info.info21.password_expired = password_expired;
2678 info.info21.lm_password_set = true;
2679 info.info21.lm_owf_password.length = 16;
2680 info.info21.lm_owf_password.size = 16;
2682 info.info21.nt_password_set = true;
2683 info.info21.nt_owf_password.length = 16;
2684 info.info21.nt_owf_password.size = 16;
2688 in = data_blob_const(nt_hash, 16);
2689 out = data_blob_talloc_zero(mem_ctx, 16);
2690 sess_crypt_blob(&out, &in, &session_key, true);
2691 info.info21.nt_owf_password.array =
2692 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2696 in = data_blob_const(lm_hash, 16);
2697 out = data_blob_talloc_zero(mem_ctx, 16);
2698 sess_crypt_blob(&out, &in, &session_key, true);
2699 info.info21.lm_owf_password.array =
2700 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2705 ZERO_STRUCT(info.info23);
2707 info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2708 SAMR_FIELD_LM_PASSWORD_PRESENT;
2710 info.info23.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2711 info.info23.info.password_expired = password_expired;
2714 info.info23.password = pwd_buf;
2718 info.info24.password = pwd_buf;
2719 info.info24.password_expired = password_expired;
2723 ZERO_STRUCT(info.info25);
2725 info.info25.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2726 SAMR_FIELD_LM_PASSWORD_PRESENT;
2728 info.info25.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2729 info.info25.info.password_expired = password_expired;
2732 info.info25.password = pwd_buf_ex;
2736 info.info26.password = pwd_buf_ex;
2737 info.info26.password_expired = password_expired;
2741 return NT_STATUS_INVALID_INFO_CLASS;
2744 /* Get sam policy handle */
2746 status = rpccli_try_samr_connects(cli, mem_ctx,
2747 MAXIMUM_ALLOWED_ACCESS,
2750 if (!NT_STATUS_IS_OK(status))
2753 /* Get domain policy handle */
2755 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2761 if (!NT_STATUS_IS_OK(status))
2764 user_rid = strtol(user, NULL, 0);
2766 status = rpccli_samr_OpenUser(cli, mem_ctx,
2773 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER) ||
2776 /* Probably this was a user name, try lookupnames */
2777 struct samr_Ids rids, types;
2778 struct lsa_String lsa_acct_name;
2780 init_lsa_String(&lsa_acct_name, user);
2782 status = rpccli_samr_LookupNames(cli, mem_ctx,
2788 if (!NT_STATUS_IS_OK(status)) {
2792 status = rpccli_samr_OpenUser(cli, mem_ctx,
2797 if (!NT_STATUS_IS_OK(status)) {
2803 case NDR_SAMR_SETUSERINFO:
2804 status = rpccli_samr_SetUserInfo(cli, mem_ctx,
2809 case NDR_SAMR_SETUSERINFO2:
2810 status = rpccli_samr_SetUserInfo2(cli, mem_ctx,
2816 return NT_STATUS_INVALID_PARAMETER;
2823 static NTSTATUS cmd_samr_setuserinfo(struct rpc_pipe_client *cli,
2824 TALLOC_CTX *mem_ctx,
2825 int argc, const char **argv)
2827 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2828 NDR_SAMR_SETUSERINFO);
2831 static NTSTATUS cmd_samr_setuserinfo2(struct rpc_pipe_client *cli,
2832 TALLOC_CTX *mem_ctx,
2833 int argc, const char **argv)
2835 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2836 NDR_SAMR_SETUSERINFO2);
2839 static NTSTATUS cmd_samr_get_dispinfo_idx(struct rpc_pipe_client *cli,
2840 TALLOC_CTX *mem_ctx,
2841 int argc, const char **argv)
2844 struct policy_handle connect_handle;
2845 struct policy_handle domain_handle;
2847 struct lsa_String name;
2850 if (argc < 2 || argc > 3) {
2851 printf("Usage: %s name level\n", argv[0]);
2852 return NT_STATUS_INVALID_PARAMETER;
2855 init_lsa_String(&name, argv[1]);
2858 level = atoi(argv[2]);
2861 status = rpccli_try_samr_connects(cli, mem_ctx,
2862 SEC_RIGHTS_MAXIMUM_ALLOWED,
2865 if (!NT_STATUS_IS_OK(status)) {
2869 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2871 SEC_RIGHTS_MAXIMUM_ALLOWED,
2875 if (!NT_STATUS_IS_OK(status))
2879 status = rpccli_samr_GetDisplayEnumerationIndex(cli, mem_ctx,
2885 if (NT_STATUS_IS_OK(status) ||
2886 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
2887 printf("idx: %d (0x%08x)\n", idx, idx);
2891 if (is_valid_policy_hnd(&domain_handle)) {
2892 rpccli_samr_Close(cli, mem_ctx, &domain_handle);
2894 if (is_valid_policy_hnd(&connect_handle)) {
2895 rpccli_samr_Close(cli, mem_ctx, &connect_handle);
2901 /* List of commands exported by this module */
2903 struct cmd_set samr_commands[] = {
2907 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, &ndr_table_samr.syntax_id, NULL, "Query user info", "" },
2908 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, &ndr_table_samr.syntax_id, NULL, "Query group info", "" },
2909 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, &ndr_table_samr.syntax_id, NULL, "Query user groups", "" },
2910 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, &ndr_table_samr.syntax_id, NULL, "Query user aliases", "" },
2911 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query group membership", "" },
2912 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias membership", "" },
2913 { "queryaliasinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias info", "" },
2914 { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Delete an alias", "" },
2915 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2916 { "querydispinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2917 { "querydispinfo3", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2918 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query domain info", "" },
2919 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain users", "" },
2920 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain groups", "" },
2921 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate alias groups", "" },
2922 { "enumdomains", RPC_RTYPE_NTSTATUS, cmd_samr_enum_domains, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domains", "" },
2924 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain user", "" },
2925 { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain group", "" },
2926 { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain alias", "" },
2927 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2928 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2929 { "deletedomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain group", "" },
2930 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain user", "" },
2931 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, &ndr_table_samr.syntax_id, NULL, "Query SAMR security object", "" },
2932 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve domain password info", "" },
2933 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve user domain password info", "" },
2935 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, &ndr_table_samr.syntax_id, NULL, "Lookup Domain Name", "" },
2936 { "chgpasswd", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2937 { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2938 { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2939 { "getdispinfoidx", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispinfo_idx, NULL, &ndr_table_samr.syntax_id, NULL, "Get Display Information Index", "" },
2940 { "setuserinfo", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info", "" },
2941 { "setuserinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info2", "" },