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"
27 #include "../libcli/auth/libcli_auth.h"
29 extern DOM_SID domain_sid;
31 /****************************************************************************
32 display samr_user_info_7 structure
33 ****************************************************************************/
34 static void display_samr_user_info_7(struct samr_UserInfo7 *r)
36 printf("\tUser Name :\t%s\n", r->account_name.string);
39 /****************************************************************************
40 display samr_user_info_9 structure
41 ****************************************************************************/
42 static void display_samr_user_info_9(struct samr_UserInfo9 *r)
44 printf("\tPrimary group RID :\tox%x\n", r->primary_gid);
47 /****************************************************************************
48 display samr_user_info_16 structure
49 ****************************************************************************/
50 static void display_samr_user_info_16(struct samr_UserInfo16 *r)
52 printf("\tAcct Flags :\tox%x\n", r->acct_flags);
55 /****************************************************************************
56 display samr_user_info_20 structure
57 ****************************************************************************/
58 static void display_samr_user_info_20(struct samr_UserInfo20 *r)
60 printf("\tRemote Dial :\n");
61 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
65 /****************************************************************************
66 display samr_user_info_21 structure
67 ****************************************************************************/
68 static void display_samr_user_info_21(struct samr_UserInfo21 *r)
70 printf("\tUser Name :\t%s\n", r->account_name.string);
71 printf("\tFull Name :\t%s\n", r->full_name.string);
72 printf("\tHome Drive :\t%s\n", r->home_directory.string);
73 printf("\tDir Drive :\t%s\n", r->home_drive.string);
74 printf("\tProfile Path:\t%s\n", r->profile_path.string);
75 printf("\tLogon Script:\t%s\n", r->logon_script.string);
76 printf("\tDescription :\t%s\n", r->description.string);
77 printf("\tWorkstations:\t%s\n", r->workstations.string);
78 printf("\tComment :\t%s\n", r->comment.string);
79 printf("\tRemote Dial :\n");
80 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
82 printf("\tLogon Time :\t%s\n",
83 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logon)));
84 printf("\tLogoff Time :\t%s\n",
85 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logoff)));
86 printf("\tKickoff Time :\t%s\n",
87 http_timestring(talloc_tos(), nt_time_to_unix(r->acct_expiry)));
88 printf("\tPassword last set Time :\t%s\n",
89 http_timestring(talloc_tos(), nt_time_to_unix(r->last_password_change)));
90 printf("\tPassword can change Time :\t%s\n",
91 http_timestring(talloc_tos(), nt_time_to_unix(r->allow_password_change)));
92 printf("\tPassword must change Time:\t%s\n",
93 http_timestring(talloc_tos(), nt_time_to_unix(r->force_password_change)));
95 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
97 printf("\tuser_rid :\t0x%x\n" , r->rid); /* User ID */
98 printf("\tgroup_rid:\t0x%x\n" , r->primary_gid); /* Group ID */
99 printf("\tacb_info :\t0x%08x\n", r->acct_flags); /* Account Control Info */
101 printf("\tfields_present:\t0x%08x\n", r->fields_present); /* 0x00ff ffff */
102 printf("\tlogon_divs:\t%d\n", r->logon_hours.units_per_week); /* 0x0000 00a8 which is 168 which is num hrs in a week */
103 printf("\tbad_password_count:\t0x%08x\n", r->bad_password_count);
104 printf("\tlogon_count:\t0x%08x\n", r->logon_count);
106 printf("\tpadding1[0..7]...\n");
108 if (r->logon_hours.bits) {
109 printf("\tlogon_hrs[0..%d]...\n", r->logon_hours.units_per_week/8);
114 static void display_password_properties(uint32_t password_properties)
116 printf("password_properties: 0x%08x\n", password_properties);
118 if (password_properties & DOMAIN_PASSWORD_COMPLEX)
119 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
121 if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
122 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
124 if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
125 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
127 if (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)
128 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
130 if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
131 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
133 if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
134 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
137 static void display_sam_dom_info_1(struct samr_DomInfo1 *info1)
139 printf("Minimum password length:\t\t\t%d\n",
140 info1->min_password_length);
141 printf("Password uniqueness (remember x passwords):\t%d\n",
142 info1->password_history_length);
143 display_password_properties(info1->password_properties);
144 printf("password expire in:\t\t\t\t%s\n",
145 display_time(info1->max_password_age));
146 printf("Min password age (allow changing in x days):\t%s\n",
147 display_time(info1->min_password_age));
150 static void display_sam_dom_info_2(struct samr_DomGeneralInformation *general)
152 printf("Domain:\t\t%s\n", general->domain_name.string);
153 printf("Server:\t\t%s\n", general->primary.string);
154 printf("Comment:\t%s\n", general->oem_information.string);
156 printf("Total Users:\t%d\n", general->num_users);
157 printf("Total Groups:\t%d\n", general->num_groups);
158 printf("Total Aliases:\t%d\n", general->num_aliases);
160 printf("Sequence No:\t%llu\n", (unsigned long long)general->sequence_num);
162 printf("Force Logoff:\t%d\n",
163 (int)nt_time_to_unix_abs(&general->force_logoff_time));
165 printf("Domain Server State:\t0x%x\n", general->domain_server_state);
166 printf("Server Role:\t%s\n", server_role_str(general->role));
167 printf("Unknown 3:\t0x%x\n", general->unknown3);
170 static void display_sam_dom_info_3(struct samr_DomInfo3 *info3)
172 printf("Force Logoff:\t%d\n",
173 (int)nt_time_to_unix_abs(&info3->force_logoff_time));
176 static void display_sam_dom_info_4(struct samr_DomOEMInformation *oem)
178 printf("Comment:\t%s\n", oem->oem_information.string);
181 static void display_sam_dom_info_5(struct samr_DomInfo5 *info5)
183 printf("Domain:\t\t%s\n", info5->domain_name.string);
186 static void display_sam_dom_info_6(struct samr_DomInfo6 *info6)
188 printf("Server:\t\t%s\n", info6->primary.string);
191 static void display_sam_dom_info_7(struct samr_DomInfo7 *info7)
193 printf("Server Role:\t%s\n", server_role_str(info7->role));
196 static void display_sam_dom_info_8(struct samr_DomInfo8 *info8)
198 printf("Sequence No:\t%llu\n", (unsigned long long)info8->sequence_num);
199 printf("Domain Create Time:\t%s\n",
200 http_timestring(talloc_tos(), nt_time_to_unix(info8->domain_create_time)));
203 static void display_sam_dom_info_9(struct samr_DomInfo9 *info9)
205 printf("Domain Server State:\t0x%x\n", info9->domain_server_state);
208 static void display_sam_dom_info_12(struct samr_DomInfo12 *info12)
210 printf("Bad password lockout duration: %s\n",
211 display_time(info12->lockout_duration));
212 printf("Reset Lockout after: %s\n",
213 display_time(info12->lockout_window));
214 printf("Lockout after bad attempts: %d\n",
215 info12->lockout_threshold);
218 static void display_sam_dom_info_13(struct samr_DomInfo13 *info13)
220 printf("Sequence No:\t%llu\n", (unsigned long long)info13->sequence_num);
221 printf("Domain Create Time:\t%s\n",
222 http_timestring(talloc_tos(), nt_time_to_unix(info13->domain_create_time)));
223 printf("Sequence No at last promotion:\t%llu\n",
224 (unsigned long long)info13->modified_count_at_last_promotion);
227 static void display_sam_info_1(struct samr_DispEntryGeneral *r)
229 printf("index: 0x%x ", r->idx);
230 printf("RID: 0x%x ", r->rid);
231 printf("acb: 0x%08x ", r->acct_flags);
232 printf("Account: %s\t", r->account_name.string);
233 printf("Name: %s\t", r->full_name.string);
234 printf("Desc: %s\n", r->description.string);
237 static void display_sam_info_2(struct samr_DispEntryFull *r)
239 printf("index: 0x%x ", r->idx);
240 printf("RID: 0x%x ", r->rid);
241 printf("acb: 0x%08x ", r->acct_flags);
242 printf("Account: %s\t", r->account_name.string);
243 printf("Desc: %s\n", r->description.string);
246 static void display_sam_info_3(struct samr_DispEntryFullGroup *r)
248 printf("index: 0x%x ", r->idx);
249 printf("RID: 0x%x ", r->rid);
250 printf("acb: 0x%08x ", r->acct_flags);
251 printf("Account: %s\t", r->account_name.string);
252 printf("Desc: %s\n", r->description.string);
255 static void display_sam_info_4(struct samr_DispEntryAscii *r)
257 printf("index: 0x%x ", r->idx);
258 printf("Account: %s\n", r->account_name.string);
261 static void display_sam_info_5(struct samr_DispEntryAscii *r)
263 printf("index: 0x%x ", r->idx);
264 printf("Account: %s\n", r->account_name.string);
267 /****************************************************************************
268 ****************************************************************************/
270 static NTSTATUS get_domain_handle(struct rpc_pipe_client *cli,
273 struct policy_handle *connect_pol,
274 uint32_t access_mask,
275 struct dom_sid *_domain_sid,
276 struct policy_handle *domain_pol)
279 if (StrCaseCmp(sam, "domain") == 0) {
280 return rpccli_samr_OpenDomain(cli, mem_ctx,
285 } else if (StrCaseCmp(sam, "builtin") == 0) {
286 return rpccli_samr_OpenDomain(cli, mem_ctx,
289 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
293 return NT_STATUS_INVALID_PARAMETER;
296 /**********************************************************************
297 * Query user information
299 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
301 int argc, const char **argv)
303 struct policy_handle connect_pol, domain_pol, user_pol;
304 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
305 uint32 info_level = 21;
306 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
307 union samr_UserInfo *info = NULL;
310 if ((argc < 2) || (argc > 4)) {
311 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
315 sscanf(argv[1], "%i", &user_rid);
318 sscanf(argv[2], "%i", &info_level);
321 sscanf(argv[3], "%x", &access_mask);
324 result = rpccli_try_samr_connects(cli, mem_ctx,
325 MAXIMUM_ALLOWED_ACCESS,
328 if (!NT_STATUS_IS_OK(result))
331 result = rpccli_samr_OpenDomain(cli, mem_ctx,
333 MAXIMUM_ALLOWED_ACCESS,
336 if (!NT_STATUS_IS_OK(result))
339 result = rpccli_samr_OpenUser(cli, mem_ctx,
345 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
348 /* Probably this was a user name, try lookupnames */
349 struct samr_Ids rids, types;
350 struct lsa_String lsa_acct_name;
352 init_lsa_String(&lsa_acct_name, argv[1]);
354 result = rpccli_samr_LookupNames(cli, mem_ctx,
361 if (NT_STATUS_IS_OK(result)) {
362 result = rpccli_samr_OpenUser(cli, mem_ctx,
371 if (!NT_STATUS_IS_OK(result))
374 result = rpccli_samr_QueryUserInfo(cli, mem_ctx,
379 if (!NT_STATUS_IS_OK(result))
382 switch (info_level) {
384 display_samr_user_info_7(&info->info7);
387 display_samr_user_info_9(&info->info9);
390 display_samr_user_info_16(&info->info16);
393 display_samr_user_info_20(&info->info20);
396 display_samr_user_info_21(&info->info21);
399 printf("Unsupported infolevel: %d\n", info_level);
403 rpccli_samr_Close(cli, mem_ctx, &user_pol);
404 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
405 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
411 /****************************************************************************
413 ****************************************************************************/
414 static void display_group_info1(struct samr_GroupInfoAll *info1)
416 printf("\tGroup Name:\t%s\n", info1->name.string);
417 printf("\tDescription:\t%s\n", info1->description.string);
418 printf("\tGroup Attribute:%d\n", info1->attributes);
419 printf("\tNum Members:%d\n", info1->num_members);
422 /****************************************************************************
424 ****************************************************************************/
425 static void display_group_info2(struct lsa_String *info2)
427 printf("\tGroup Description:%s\n", info2->string);
431 /****************************************************************************
433 ****************************************************************************/
434 static void display_group_info3(struct samr_GroupInfoAttributes *info3)
436 printf("\tGroup Attribute:%d\n", info3->attributes);
440 /****************************************************************************
442 ****************************************************************************/
443 static void display_group_info4(struct lsa_String *info4)
445 printf("\tGroup Description:%s\n", info4->string);
448 /****************************************************************************
450 ****************************************************************************/
451 static void display_group_info5(struct samr_GroupInfoAll *info5)
453 printf("\tGroup Name:\t%s\n", info5->name.string);
454 printf("\tDescription:\t%s\n", info5->description.string);
455 printf("\tGroup Attribute:%d\n", info5->attributes);
456 printf("\tNum Members:%d\n", info5->num_members);
459 /****************************************************************************
460 display sam sync structure
461 ****************************************************************************/
462 static void display_group_info(union samr_GroupInfo *info,
463 enum samr_GroupInfoEnum level)
467 display_group_info1(&info->all);
470 display_group_info2(&info->name);
473 display_group_info3(&info->attributes);
476 display_group_info4(&info->description);
479 display_group_info5(&info->all2);
484 /***********************************************************************
485 * Query group information
487 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
489 int argc, const char **argv)
491 struct policy_handle connect_pol, domain_pol, group_pol;
492 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
493 enum samr_GroupInfoEnum info_level = GROUPINFOALL;
494 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
495 union samr_GroupInfo *group_info = NULL;
498 if ((argc < 2) || (argc > 4)) {
499 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
503 sscanf(argv[1], "%i", &group_rid);
506 info_level = atoi(argv[2]);
509 sscanf(argv[3], "%x", &access_mask);
511 result = rpccli_try_samr_connects(cli, mem_ctx,
512 MAXIMUM_ALLOWED_ACCESS,
515 if (!NT_STATUS_IS_OK(result))
518 result = rpccli_samr_OpenDomain(cli, mem_ctx,
520 MAXIMUM_ALLOWED_ACCESS,
524 if (!NT_STATUS_IS_OK(result))
527 result = rpccli_samr_OpenGroup(cli, mem_ctx,
533 if (!NT_STATUS_IS_OK(result))
536 result = rpccli_samr_QueryGroupInfo(cli, mem_ctx,
540 if (!NT_STATUS_IS_OK(result)) {
544 display_group_info(group_info, info_level);
546 rpccli_samr_Close(cli, mem_ctx, &group_pol);
547 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
548 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
553 /* Query groups a user is a member of */
555 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
557 int argc, const char **argv)
559 struct policy_handle connect_pol,
562 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
564 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
566 struct samr_RidWithAttributeArray *rid_array = NULL;
568 if ((argc < 2) || (argc > 3)) {
569 printf("Usage: %s rid [access mask]\n", argv[0]);
573 sscanf(argv[1], "%i", &user_rid);
576 sscanf(argv[2], "%x", &access_mask);
578 result = rpccli_try_samr_connects(cli, mem_ctx,
579 MAXIMUM_ALLOWED_ACCESS,
582 if (!NT_STATUS_IS_OK(result))
585 result = rpccli_samr_OpenDomain(cli, mem_ctx,
587 MAXIMUM_ALLOWED_ACCESS,
588 &domain_sid, &domain_pol);
590 if (!NT_STATUS_IS_OK(result))
593 result = rpccli_samr_OpenUser(cli, mem_ctx,
599 if (!NT_STATUS_IS_OK(result))
602 result = rpccli_samr_GetGroupsForUser(cli, mem_ctx,
606 if (!NT_STATUS_IS_OK(result))
609 for (i = 0; i < rid_array->count; i++) {
610 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
611 rid_array->rids[i].rid,
612 rid_array->rids[i].attributes);
615 rpccli_samr_Close(cli, mem_ctx, &user_pol);
616 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
617 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
622 /* Query aliases a user is a member of */
624 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
626 int argc, const char **argv)
628 struct policy_handle connect_pol, domain_pol;
629 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
632 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
634 struct lsa_SidArray sid_array;
635 struct samr_Ids alias_rids;
638 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
639 return NT_STATUS_INVALID_PARAMETER;
645 for (i=2; i<argc; i++) {
647 if (!string_to_sid(&tmp_sid, argv[i])) {
648 printf("%s is not a legal SID\n", argv[i]);
649 return NT_STATUS_INVALID_PARAMETER;
651 result = add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
652 if (!NT_STATUS_IS_OK(result)) {
658 sid_array.sids = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_SidPtr, num_sids);
659 if (sid_array.sids == NULL)
660 return NT_STATUS_NO_MEMORY;
662 sid_array.sids = NULL;
665 for (i=0; i<num_sids; i++) {
666 sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sids[i]);
667 if (!sid_array.sids[i].sid) {
668 return NT_STATUS_NO_MEMORY;
672 sid_array.num_sids = num_sids;
674 result = rpccli_try_samr_connects(cli, mem_ctx,
675 MAXIMUM_ALLOWED_ACCESS,
678 if (!NT_STATUS_IS_OK(result))
681 result = get_domain_handle(cli, mem_ctx, argv[1],
687 if (!NT_STATUS_IS_OK(result))
690 result = rpccli_samr_GetAliasMembership(cli, mem_ctx,
694 if (!NT_STATUS_IS_OK(result))
697 for (i = 0; i < alias_rids.count; i++) {
698 printf("\tgroup rid:[0x%x]\n", alias_rids.ids[i]);
701 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
702 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
707 /* Query members of a group */
709 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
711 int argc, const char **argv)
713 struct policy_handle connect_pol, domain_pol, group_pol;
714 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
716 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
718 unsigned int old_timeout;
719 struct samr_RidTypeArray *rids = NULL;
721 if ((argc < 2) || (argc > 3)) {
722 printf("Usage: %s rid [access mask]\n", argv[0]);
726 sscanf(argv[1], "%i", &group_rid);
729 sscanf(argv[2], "%x", &access_mask);
731 result = rpccli_try_samr_connects(cli, mem_ctx,
732 MAXIMUM_ALLOWED_ACCESS,
735 if (!NT_STATUS_IS_OK(result))
738 result = rpccli_samr_OpenDomain(cli, mem_ctx,
740 MAXIMUM_ALLOWED_ACCESS,
744 if (!NT_STATUS_IS_OK(result))
747 result = rpccli_samr_OpenGroup(cli, mem_ctx,
753 if (!NT_STATUS_IS_OK(result))
756 /* Make sure to wait for our DC's reply */
757 old_timeout = rpccli_set_timeout(cli, 30000); /* 30 seconds. */
758 rpccli_set_timeout(cli, MAX(30000, old_timeout)); /* At least 30 sec */
760 result = rpccli_samr_QueryGroupMember(cli, mem_ctx,
764 rpccli_set_timeout(cli, old_timeout);
766 if (!NT_STATUS_IS_OK(result))
769 for (i = 0; i < rids->count; i++) {
770 printf("\trid:[0x%x] attr:[0x%x]\n", rids->rids[i],
774 rpccli_samr_Close(cli, mem_ctx, &group_pol);
775 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
776 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
781 /* Enumerate domain users */
783 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
785 int argc, const char **argv)
787 struct policy_handle connect_pol, domain_pol;
788 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
789 uint32 start_idx, num_dom_users, i;
790 struct samr_SamArray *dom_users = NULL;
791 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
792 uint32 acb_mask = ACB_NORMAL;
793 uint32_t size = 0xffff;
795 if ((argc < 1) || (argc > 4)) {
796 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv[0]);
801 sscanf(argv[1], "%x", &access_mask);
805 sscanf(argv[2], "%x", &acb_mask);
809 sscanf(argv[3], "%x", &size);
812 /* Get sam policy handle */
814 result = rpccli_try_samr_connects(cli, mem_ctx,
815 MAXIMUM_ALLOWED_ACCESS,
818 if (!NT_STATUS_IS_OK(result))
821 /* Get domain policy handle */
823 result = get_domain_handle(cli, mem_ctx, "domain",
828 if (!NT_STATUS_IS_OK(result))
831 /* Enumerate domain users */
836 result = rpccli_samr_EnumDomainUsers(cli, mem_ctx,
844 if (NT_STATUS_IS_OK(result) ||
845 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
847 for (i = 0; i < num_dom_users; i++)
848 printf("user:[%s] rid:[0x%x]\n",
849 dom_users->entries[i].name.string,
850 dom_users->entries[i].idx);
853 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
856 if (is_valid_policy_hnd(&domain_pol))
857 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
859 if (is_valid_policy_hnd(&connect_pol))
860 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
865 /* Enumerate domain groups */
867 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
869 int argc, const char **argv)
871 struct policy_handle connect_pol, domain_pol;
872 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
873 uint32 start_idx, num_dom_groups, i;
874 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
875 struct samr_SamArray *dom_groups = NULL;
876 uint32_t size = 0xffff;
878 if ((argc < 1) || (argc > 3)) {
879 printf("Usage: %s [access_mask] [max_size]\n", argv[0]);
884 sscanf(argv[1], "%x", &access_mask);
888 sscanf(argv[2], "%x", &size);
891 /* Get sam policy handle */
893 result = rpccli_try_samr_connects(cli, mem_ctx,
894 MAXIMUM_ALLOWED_ACCESS,
897 if (!NT_STATUS_IS_OK(result))
900 /* Get domain policy handle */
902 result = get_domain_handle(cli, mem_ctx, "domain",
907 if (!NT_STATUS_IS_OK(result))
910 /* Enumerate domain groups */
915 result = rpccli_samr_EnumDomainGroups(cli, mem_ctx,
921 if (NT_STATUS_IS_OK(result) ||
922 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
924 for (i = 0; i < num_dom_groups; i++)
925 printf("group:[%s] rid:[0x%x]\n",
926 dom_groups->entries[i].name.string,
927 dom_groups->entries[i].idx);
930 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
933 if (is_valid_policy_hnd(&domain_pol))
934 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
936 if (is_valid_policy_hnd(&connect_pol))
937 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
942 /* Enumerate alias groups */
944 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
946 int argc, const char **argv)
948 struct policy_handle connect_pol, domain_pol;
949 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
950 uint32 start_idx, num_als_groups, i;
951 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
952 struct samr_SamArray *als_groups = NULL;
953 uint32_t size = 0xffff;
955 if ((argc < 2) || (argc > 4)) {
956 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv[0]);
961 sscanf(argv[2], "%x", &access_mask);
965 sscanf(argv[3], "%x", &size);
968 /* Get sam policy handle */
970 result = rpccli_try_samr_connects(cli, mem_ctx,
971 MAXIMUM_ALLOWED_ACCESS,
974 if (!NT_STATUS_IS_OK(result))
977 /* Get domain policy handle */
979 result = get_domain_handle(cli, mem_ctx, argv[1],
985 if (!NT_STATUS_IS_OK(result))
988 /* Enumerate alias groups */
993 result = rpccli_samr_EnumDomainAliases(cli, mem_ctx,
1000 if (NT_STATUS_IS_OK(result) ||
1001 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1003 for (i = 0; i < num_als_groups; i++)
1004 printf("group:[%s] rid:[0x%x]\n",
1005 als_groups->entries[i].name.string,
1006 als_groups->entries[i].idx);
1008 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1011 if (is_valid_policy_hnd(&domain_pol))
1012 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1014 if (is_valid_policy_hnd(&connect_pol))
1015 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1020 /* Enumerate domains */
1022 static NTSTATUS cmd_samr_enum_domains(struct rpc_pipe_client *cli,
1023 TALLOC_CTX *mem_ctx,
1024 int argc, const char **argv)
1026 struct policy_handle connect_pol;
1027 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1028 uint32 start_idx, size, num_entries, i;
1029 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1030 struct samr_SamArray *sam = NULL;
1032 if ((argc < 1) || (argc > 2)) {
1033 printf("Usage: %s [access mask]\n", argv[0]);
1034 return NT_STATUS_OK;
1038 sscanf(argv[1], "%x", &access_mask);
1041 /* Get sam policy handle */
1043 result = rpccli_try_samr_connects(cli, mem_ctx,
1047 if (!NT_STATUS_IS_OK(result)) {
1051 /* Enumerate alias groups */
1057 result = rpccli_samr_EnumDomains(cli, mem_ctx,
1064 if (NT_STATUS_IS_OK(result) ||
1065 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1067 for (i = 0; i < num_entries; i++)
1068 printf("name:[%s] idx:[0x%x]\n",
1069 sam->entries[i].name.string,
1070 sam->entries[i].idx);
1072 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1075 if (is_valid_policy_hnd(&connect_pol)) {
1076 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1083 /* Query alias membership */
1085 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
1086 TALLOC_CTX *mem_ctx,
1087 int argc, const char **argv)
1089 struct policy_handle connect_pol, domain_pol, alias_pol;
1090 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1091 uint32 alias_rid, i;
1092 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1093 struct lsa_SidArray sid_array;
1095 if ((argc < 3) || (argc > 4)) {
1096 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
1097 return NT_STATUS_OK;
1100 sscanf(argv[2], "%i", &alias_rid);
1103 sscanf(argv[3], "%x", &access_mask);
1105 /* Open SAMR handle */
1107 result = rpccli_try_samr_connects(cli, mem_ctx,
1108 MAXIMUM_ALLOWED_ACCESS,
1111 if (!NT_STATUS_IS_OK(result))
1114 /* Open handle on domain */
1116 result = get_domain_handle(cli, mem_ctx, argv[1],
1118 MAXIMUM_ALLOWED_ACCESS,
1122 if (!NT_STATUS_IS_OK(result))
1125 /* Open handle on alias */
1127 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1132 if (!NT_STATUS_IS_OK(result))
1135 result = rpccli_samr_GetMembersInAlias(cli, mem_ctx,
1139 if (!NT_STATUS_IS_OK(result))
1142 for (i = 0; i < sid_array.num_sids; i++) {
1145 sid_to_fstring(sid_str, sid_array.sids[i].sid);
1146 printf("\tsid:[%s]\n", sid_str);
1149 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1150 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1151 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1156 /* Query alias info */
1158 static NTSTATUS cmd_samr_query_aliasinfo(struct rpc_pipe_client *cli,
1159 TALLOC_CTX *mem_ctx,
1160 int argc, const char **argv)
1162 struct policy_handle connect_pol, domain_pol, alias_pol;
1163 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1165 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1166 union samr_AliasInfo *info = NULL;
1167 enum samr_AliasInfoEnum level = ALIASINFOALL;
1169 if ((argc < 3) || (argc > 4)) {
1170 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1172 return NT_STATUS_OK;
1175 sscanf(argv[2], "%i", &alias_rid);
1178 level = atoi(argv[3]);
1182 sscanf(argv[4], "%x", &access_mask);
1185 /* Open SAMR handle */
1187 result = rpccli_try_samr_connects(cli, mem_ctx,
1188 SEC_FLAG_MAXIMUM_ALLOWED,
1191 if (!NT_STATUS_IS_OK(result)) {
1195 /* Open handle on domain */
1197 result = get_domain_handle(cli, mem_ctx, argv[1],
1199 SEC_FLAG_MAXIMUM_ALLOWED,
1203 if (!NT_STATUS_IS_OK(result)) {
1207 /* Open handle on alias */
1209 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1214 if (!NT_STATUS_IS_OK(result)) {
1218 result = rpccli_samr_QueryAliasInfo(cli, mem_ctx,
1223 if (!NT_STATUS_IS_OK(result)) {
1229 printf("Name: %s\n", info->all.name.string);
1230 printf("Description: %s\n", info->all.description.string);
1231 printf("Num Members: %d\n", info->all.num_members);
1234 printf("Name: %s\n", info->name.string);
1236 case ALIASINFODESCRIPTION:
1237 printf("Description: %s\n", info->description.string);
1243 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1244 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1245 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1251 /* Query delete an alias membership */
1253 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
1254 TALLOC_CTX *mem_ctx,
1255 int argc, const char **argv)
1257 struct policy_handle connect_pol, domain_pol, alias_pol;
1258 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1260 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1263 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
1264 return NT_STATUS_OK;
1267 alias_rid = strtoul(argv[2], NULL, 10);
1269 /* Open SAMR handle */
1271 result = rpccli_try_samr_connects(cli, mem_ctx,
1272 MAXIMUM_ALLOWED_ACCESS,
1275 if (!NT_STATUS_IS_OK(result))
1278 /* Open handle on domain */
1280 result = get_domain_handle(cli, mem_ctx, argv[1],
1282 MAXIMUM_ALLOWED_ACCESS,
1286 if (!NT_STATUS_IS_OK(result))
1289 /* Open handle on alias */
1291 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1296 if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
1297 /* Probably this was a user name, try lookupnames */
1298 struct samr_Ids rids, types;
1299 struct lsa_String lsa_acct_name;
1301 init_lsa_String(&lsa_acct_name, argv[2]);
1303 result = rpccli_samr_LookupNames(cli, mem_ctx,
1310 if (NT_STATUS_IS_OK(result)) {
1311 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1319 result = rpccli_samr_DeleteDomAlias(cli, mem_ctx,
1322 if (!NT_STATUS_IS_OK(result))
1325 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1326 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1331 /* Query display info */
1333 static NTSTATUS cmd_samr_query_dispinfo_internal(struct rpc_pipe_client *cli,
1334 TALLOC_CTX *mem_ctx,
1335 int argc, const char **argv,
1338 struct policy_handle connect_pol, domain_pol;
1339 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1340 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries = 0, i;
1341 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1342 uint32 info_level = 1;
1343 union samr_DispInfo info;
1345 bool got_params = False; /* Use get_query_dispinfo_params() or not? */
1346 uint32_t total_size, returned_size;
1349 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
1350 return NT_STATUS_OK;
1354 sscanf(argv[1], "%i", &info_level);
1357 sscanf(argv[2], "%i", &start_idx);
1360 sscanf(argv[3], "%i", &max_entries);
1365 sscanf(argv[4], "%i", &max_size);
1370 sscanf(argv[5], "%x", &access_mask);
1372 /* Get sam policy handle */
1374 result = rpccli_try_samr_connects(cli, mem_ctx,
1375 MAXIMUM_ALLOWED_ACCESS,
1378 if (!NT_STATUS_IS_OK(result))
1381 /* Get domain policy handle */
1383 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1389 if (!NT_STATUS_IS_OK(result))
1392 /* Query display info */
1397 get_query_dispinfo_params(
1398 loop_count, &max_entries, &max_size);
1401 case NDR_SAMR_QUERYDISPLAYINFO:
1402 result = rpccli_samr_QueryDisplayInfo(cli, mem_ctx,
1412 case NDR_SAMR_QUERYDISPLAYINFO2:
1413 result = rpccli_samr_QueryDisplayInfo2(cli, mem_ctx,
1424 case NDR_SAMR_QUERYDISPLAYINFO3:
1425 result = rpccli_samr_QueryDisplayInfo3(cli, mem_ctx,
1437 return NT_STATUS_INVALID_PARAMETER;
1440 if (!NT_STATUS_IS_OK(result) &&
1441 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
1442 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
1448 switch (info_level) {
1450 num_entries = info.info1.count;
1453 num_entries = info.info2.count;
1456 num_entries = info.info3.count;
1459 num_entries = info.info4.count;
1462 num_entries = info.info5.count;
1468 start_idx += num_entries;
1470 if (num_entries == 0)
1473 for (i = 0; i < num_entries; i++) {
1474 switch (info_level) {
1476 display_sam_info_1(&info.info1.entries[i]);
1479 display_sam_info_2(&info.info2.entries[i]);
1482 display_sam_info_3(&info.info3.entries[i]);
1485 display_sam_info_4(&info.info4.entries[i]);
1488 display_sam_info_5(&info.info5.entries[i]);
1492 } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1494 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1495 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1500 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
1501 TALLOC_CTX *mem_ctx,
1502 int argc, const char **argv)
1504 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1505 NDR_SAMR_QUERYDISPLAYINFO);
1508 static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1509 TALLOC_CTX *mem_ctx,
1510 int argc, const char **argv)
1512 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1513 NDR_SAMR_QUERYDISPLAYINFO2);
1516 static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1517 TALLOC_CTX *mem_ctx,
1518 int argc, const char **argv)
1520 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1521 NDR_SAMR_QUERYDISPLAYINFO3);
1524 /* Query domain info */
1526 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
1527 TALLOC_CTX *mem_ctx,
1528 int argc, const char **argv)
1530 struct policy_handle connect_pol, domain_pol;
1531 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1532 uint32 switch_level = 2;
1533 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1534 union samr_DomainInfo *info = NULL;
1537 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1538 return NT_STATUS_OK;
1542 sscanf(argv[1], "%i", &switch_level);
1545 sscanf(argv[2], "%x", &access_mask);
1547 /* Get sam policy handle */
1549 result = rpccli_try_samr_connects(cli, mem_ctx,
1550 MAXIMUM_ALLOWED_ACCESS,
1553 if (!NT_STATUS_IS_OK(result))
1556 /* Get domain policy handle */
1558 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1564 if (!NT_STATUS_IS_OK(result))
1567 /* Query domain info */
1569 result = rpccli_samr_QueryDomainInfo(cli, mem_ctx,
1574 if (!NT_STATUS_IS_OK(result))
1577 /* Display domain info */
1579 switch (switch_level) {
1581 display_sam_dom_info_1(&info->info1);
1584 display_sam_dom_info_2(&info->general);
1587 display_sam_dom_info_3(&info->info3);
1590 display_sam_dom_info_4(&info->oem);
1593 display_sam_dom_info_5(&info->info5);
1596 display_sam_dom_info_6(&info->info6);
1599 display_sam_dom_info_7(&info->info7);
1602 display_sam_dom_info_8(&info->info8);
1605 display_sam_dom_info_9(&info->info9);
1608 display_sam_dom_info_12(&info->info12);
1611 display_sam_dom_info_13(&info->info13);
1615 printf("cannot display domain info for switch value %d\n",
1622 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1623 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1627 /* Create domain user */
1629 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
1630 TALLOC_CTX *mem_ctx,
1631 int argc, const char **argv)
1633 struct policy_handle connect_pol, domain_pol, user_pol;
1634 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1635 struct lsa_String acct_name;
1637 uint32 acct_flags, user_rid;
1638 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1639 uint32_t access_granted = 0;
1641 if ((argc < 2) || (argc > 3)) {
1642 printf("Usage: %s username [access mask]\n", argv[0]);
1643 return NT_STATUS_OK;
1646 init_lsa_String(&acct_name, argv[1]);
1649 sscanf(argv[2], "%x", &access_mask);
1651 /* Get sam policy handle */
1653 result = rpccli_try_samr_connects(cli, mem_ctx,
1654 MAXIMUM_ALLOWED_ACCESS,
1657 if (!NT_STATUS_IS_OK(result))
1660 /* Get domain policy handle */
1662 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1668 if (!NT_STATUS_IS_OK(result))
1671 /* Create domain user */
1673 acb_info = ACB_NORMAL;
1674 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
1675 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
1676 SAMR_USER_ACCESS_SET_PASSWORD |
1677 SAMR_USER_ACCESS_GET_ATTRIBUTES |
1678 SAMR_USER_ACCESS_SET_ATTRIBUTES;
1680 result = rpccli_samr_CreateUser2(cli, mem_ctx,
1689 if (!NT_STATUS_IS_OK(result))
1692 result = rpccli_samr_Close(cli, mem_ctx, &user_pol);
1693 if (!NT_STATUS_IS_OK(result)) goto done;
1695 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1696 if (!NT_STATUS_IS_OK(result)) goto done;
1698 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1699 if (!NT_STATUS_IS_OK(result)) goto done;
1705 /* Create domain group */
1707 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
1708 TALLOC_CTX *mem_ctx,
1709 int argc, const char **argv)
1711 struct policy_handle connect_pol, domain_pol, group_pol;
1712 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1713 struct lsa_String grp_name;
1714 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1717 if ((argc < 2) || (argc > 3)) {
1718 printf("Usage: %s groupname [access mask]\n", argv[0]);
1719 return NT_STATUS_OK;
1722 init_lsa_String(&grp_name, argv[1]);
1725 sscanf(argv[2], "%x", &access_mask);
1727 /* Get sam policy handle */
1729 result = rpccli_try_samr_connects(cli, mem_ctx,
1730 MAXIMUM_ALLOWED_ACCESS,
1733 if (!NT_STATUS_IS_OK(result))
1736 /* Get domain policy handle */
1738 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1744 if (!NT_STATUS_IS_OK(result))
1747 /* Create domain user */
1748 result = rpccli_samr_CreateDomainGroup(cli, mem_ctx,
1751 MAXIMUM_ALLOWED_ACCESS,
1755 if (!NT_STATUS_IS_OK(result))
1758 result = rpccli_samr_Close(cli, mem_ctx, &group_pol);
1759 if (!NT_STATUS_IS_OK(result)) goto done;
1761 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1762 if (!NT_STATUS_IS_OK(result)) goto done;
1764 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1765 if (!NT_STATUS_IS_OK(result)) goto done;
1771 /* Create domain alias */
1773 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
1774 TALLOC_CTX *mem_ctx,
1775 int argc, const char **argv)
1777 struct policy_handle connect_pol, domain_pol, alias_pol;
1778 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1779 struct lsa_String alias_name;
1780 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1783 if ((argc < 2) || (argc > 3)) {
1784 printf("Usage: %s aliasname [access mask]\n", argv[0]);
1785 return NT_STATUS_OK;
1788 init_lsa_String(&alias_name, argv[1]);
1791 sscanf(argv[2], "%x", &access_mask);
1793 /* Get sam policy handle */
1795 result = rpccli_try_samr_connects(cli, mem_ctx,
1796 MAXIMUM_ALLOWED_ACCESS,
1799 if (!NT_STATUS_IS_OK(result))
1802 /* Get domain policy handle */
1804 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1810 if (!NT_STATUS_IS_OK(result))
1813 /* Create domain user */
1815 result = rpccli_samr_CreateDomAlias(cli, mem_ctx,
1818 MAXIMUM_ALLOWED_ACCESS,
1822 if (!NT_STATUS_IS_OK(result))
1825 result = rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1826 if (!NT_STATUS_IS_OK(result)) goto done;
1828 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1829 if (!NT_STATUS_IS_OK(result)) goto done;
1831 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1832 if (!NT_STATUS_IS_OK(result)) goto done;
1838 /* Lookup sam names */
1840 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
1841 TALLOC_CTX *mem_ctx,
1842 int argc, const char **argv)
1844 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1845 struct policy_handle connect_pol, domain_pol;
1847 struct samr_Ids rids, name_types;
1849 struct lsa_String *names = NULL;;
1852 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1853 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1854 printf("or check on the builtin SID: S-1-5-32\n");
1855 return NT_STATUS_OK;
1858 /* Get sam policy and domain handles */
1860 result = rpccli_try_samr_connects(cli, mem_ctx,
1861 MAXIMUM_ALLOWED_ACCESS,
1864 if (!NT_STATUS_IS_OK(result))
1867 result = get_domain_handle(cli, mem_ctx, argv[1],
1869 MAXIMUM_ALLOWED_ACCESS,
1873 if (!NT_STATUS_IS_OK(result))
1878 num_names = argc - 2;
1880 if ((names = TALLOC_ARRAY(mem_ctx, struct lsa_String, num_names)) == NULL) {
1881 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1882 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1883 result = NT_STATUS_NO_MEMORY;
1887 for (i = 0; i < num_names; i++) {
1888 init_lsa_String(&names[i], argv[i + 2]);
1891 result = rpccli_samr_LookupNames(cli, mem_ctx,
1898 if (!NT_STATUS_IS_OK(result))
1901 /* Display results */
1903 for (i = 0; i < num_names; i++)
1904 printf("name %s: 0x%x (%d)\n", names[i].string, rids.ids[i],
1907 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1908 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1913 /* Lookup sam rids */
1915 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
1916 TALLOC_CTX *mem_ctx,
1917 int argc, const char **argv)
1919 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1920 struct policy_handle connect_pol, domain_pol;
1921 uint32_t num_rids, *rids;
1922 struct lsa_Strings names;
1923 struct samr_Ids types;
1928 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
1929 return NT_STATUS_OK;
1932 /* Get sam policy and domain handles */
1934 result = rpccli_try_samr_connects(cli, mem_ctx,
1935 MAXIMUM_ALLOWED_ACCESS,
1938 if (!NT_STATUS_IS_OK(result))
1941 result = get_domain_handle(cli, mem_ctx, argv[1],
1943 MAXIMUM_ALLOWED_ACCESS,
1947 if (!NT_STATUS_IS_OK(result))
1952 num_rids = argc - 2;
1954 if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
1955 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1956 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1957 result = NT_STATUS_NO_MEMORY;
1961 for (i = 0; i < argc - 2; i++)
1962 sscanf(argv[i + 2], "%i", &rids[i]);
1964 result = rpccli_samr_LookupRids(cli, mem_ctx,
1971 if (!NT_STATUS_IS_OK(result) &&
1972 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1975 /* Display results */
1977 for (i = 0; i < num_rids; i++) {
1978 printf("rid 0x%x: %s (%d)\n",
1979 rids[i], names.names[i].string, types.ids[i]);
1982 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1983 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1988 /* Delete domain group */
1990 static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
1991 TALLOC_CTX *mem_ctx,
1992 int argc, const char **argv)
1994 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1995 struct policy_handle connect_pol, domain_pol, group_pol;
1996 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1998 if ((argc < 2) || (argc > 3)) {
1999 printf("Usage: %s groupname\n", argv[0]);
2000 return NT_STATUS_OK;
2004 sscanf(argv[2], "%x", &access_mask);
2006 /* Get sam policy and domain handles */
2008 result = rpccli_try_samr_connects(cli, mem_ctx,
2009 MAXIMUM_ALLOWED_ACCESS,
2012 if (!NT_STATUS_IS_OK(result))
2015 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2017 MAXIMUM_ALLOWED_ACCESS,
2021 if (!NT_STATUS_IS_OK(result))
2024 /* Get handle on group */
2027 struct samr_Ids group_rids, name_types;
2028 struct lsa_String lsa_acct_name;
2030 init_lsa_String(&lsa_acct_name, argv[1]);
2032 result = rpccli_samr_LookupNames(cli, mem_ctx,
2038 if (!NT_STATUS_IS_OK(result))
2041 result = rpccli_samr_OpenGroup(cli, mem_ctx,
2047 if (!NT_STATUS_IS_OK(result))
2053 result = rpccli_samr_DeleteDomainGroup(cli, mem_ctx,
2056 if (!NT_STATUS_IS_OK(result))
2059 /* Display results */
2061 rpccli_samr_Close(cli, mem_ctx, &group_pol);
2062 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2063 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2069 /* Delete domain user */
2071 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
2072 TALLOC_CTX *mem_ctx,
2073 int argc, const char **argv)
2075 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2076 struct policy_handle connect_pol, domain_pol, user_pol;
2077 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2079 if ((argc < 2) || (argc > 3)) {
2080 printf("Usage: %s username\n", argv[0]);
2081 return NT_STATUS_OK;
2085 sscanf(argv[2], "%x", &access_mask);
2087 /* Get sam policy and domain handles */
2089 result = rpccli_try_samr_connects(cli, mem_ctx,
2090 MAXIMUM_ALLOWED_ACCESS,
2093 if (!NT_STATUS_IS_OK(result))
2096 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2098 MAXIMUM_ALLOWED_ACCESS,
2102 if (!NT_STATUS_IS_OK(result))
2105 /* Get handle on user */
2108 struct samr_Ids user_rids, name_types;
2109 struct lsa_String lsa_acct_name;
2111 init_lsa_String(&lsa_acct_name, argv[1]);
2113 result = rpccli_samr_LookupNames(cli, mem_ctx,
2120 if (!NT_STATUS_IS_OK(result))
2123 result = rpccli_samr_OpenUser(cli, mem_ctx,
2129 if (!NT_STATUS_IS_OK(result))
2135 result = rpccli_samr_DeleteUser(cli, mem_ctx,
2138 if (!NT_STATUS_IS_OK(result))
2141 /* Display results */
2143 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2144 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2145 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2151 /**********************************************************************
2152 * Query user security object
2154 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
2155 TALLOC_CTX *mem_ctx,
2156 int argc, const char **argv)
2158 struct policy_handle connect_pol, domain_pol, user_pol, *pol;
2159 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2160 uint32 sec_info = DACL_SECURITY_INFORMATION;
2161 uint32 user_rid = 0;
2162 TALLOC_CTX *ctx = NULL;
2163 SEC_DESC_BUF *sec_desc_buf=NULL;
2164 bool domain = False;
2166 ctx=talloc_init("cmd_samr_query_sec_obj");
2168 if ((argc < 1) || (argc > 3)) {
2169 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
2170 printf("\tSpecify rid for security on user, -d for security on domain\n");
2171 talloc_destroy(ctx);
2172 return NT_STATUS_OK;
2176 if (strcmp(argv[1], "-d") == 0)
2179 sscanf(argv[1], "%i", &user_rid);
2183 sec_info = atoi(argv[2]);
2186 result = rpccli_try_samr_connects(cli, mem_ctx,
2187 MAXIMUM_ALLOWED_ACCESS,
2190 if (!NT_STATUS_IS_OK(result))
2193 if (domain || user_rid)
2194 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2196 MAXIMUM_ALLOWED_ACCESS,
2200 if (!NT_STATUS_IS_OK(result))
2204 result = rpccli_samr_OpenUser(cli, mem_ctx,
2206 MAXIMUM_ALLOWED_ACCESS,
2210 if (!NT_STATUS_IS_OK(result))
2213 /* Pick which query pol to use */
2223 /* Query SAM security object */
2225 result = rpccli_samr_QuerySecurity(cli, mem_ctx,
2230 if (!NT_STATUS_IS_OK(result))
2233 display_sec_desc(sec_desc_buf->sd);
2235 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2236 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2237 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2239 talloc_destroy(ctx);
2243 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
2244 TALLOC_CTX *mem_ctx,
2245 int argc, const char **argv)
2247 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2248 struct policy_handle connect_pol, domain_pol, user_pol;
2249 struct samr_PwInfo info;
2253 printf("Usage: %s rid\n", argv[0]);
2254 return NT_STATUS_OK;
2257 sscanf(argv[1], "%i", &rid);
2259 result = rpccli_try_samr_connects(cli, mem_ctx,
2260 MAXIMUM_ALLOWED_ACCESS,
2263 if (!NT_STATUS_IS_OK(result)) {
2267 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2269 MAXIMUM_ALLOWED_ACCESS,
2273 if (!NT_STATUS_IS_OK(result)) {
2277 result = rpccli_samr_OpenUser(cli, mem_ctx,
2279 MAXIMUM_ALLOWED_ACCESS,
2283 if (!NT_STATUS_IS_OK(result)) {
2287 result = rpccli_samr_GetUserPwInfo(cli, mem_ctx, &user_pol, &info);
2288 if (NT_STATUS_IS_OK(result)) {
2289 printf("min_password_length: %d\n", info.min_password_length);
2291 NDR_PRINT_STRUCT_STRING(mem_ctx,
2292 samr_PasswordProperties, &info.password_properties));
2296 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2297 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2298 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2303 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
2304 TALLOC_CTX *mem_ctx,
2305 int argc, const char **argv)
2307 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2308 struct lsa_String domain_name;
2309 struct samr_PwInfo info;
2311 if (argc < 1 || argc > 3) {
2312 printf("Usage: %s <domain>\n", argv[0]);
2313 return NT_STATUS_OK;
2316 init_lsa_String(&domain_name, argv[1]);
2318 result = rpccli_samr_GetDomPwInfo(cli, mem_ctx, &domain_name, &info);
2320 if (NT_STATUS_IS_OK(result)) {
2321 printf("min_password_length: %d\n", info.min_password_length);
2322 display_password_properties(info.password_properties);
2328 /* Look up domain name */
2330 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
2331 TALLOC_CTX *mem_ctx,
2332 int argc, const char **argv)
2334 struct policy_handle connect_pol, domain_pol;
2335 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2336 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2338 struct lsa_String domain_name;
2339 DOM_SID *sid = NULL;
2342 printf("Usage: %s domain_name\n", argv[0]);
2343 return NT_STATUS_OK;
2346 init_lsa_String(&domain_name, argv[1]);
2348 result = rpccli_try_samr_connects(cli, mem_ctx,
2352 if (!NT_STATUS_IS_OK(result))
2355 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2361 if (!NT_STATUS_IS_OK(result))
2364 result = rpccli_samr_LookupDomain(cli, mem_ctx,
2369 if (NT_STATUS_IS_OK(result)) {
2370 sid_to_fstring(sid_string, sid);
2371 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2372 argv[1], sid_string);
2375 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2376 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2381 /* Change user password */
2383 static NTSTATUS cmd_samr_chgpasswd(struct rpc_pipe_client *cli,
2384 TALLOC_CTX *mem_ctx,
2385 int argc, const char **argv)
2387 struct policy_handle connect_pol, domain_pol, user_pol;
2388 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2389 const char *user, *oldpass, *newpass;
2390 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2391 struct samr_Ids rids, types;
2392 struct lsa_String lsa_acct_name;
2395 printf("Usage: %s username oldpass newpass\n", argv[0]);
2396 return NT_STATUS_INVALID_PARAMETER;
2403 /* Get sam policy handle */
2405 result = rpccli_try_samr_connects(cli, mem_ctx,
2406 MAXIMUM_ALLOWED_ACCESS,
2409 if (!NT_STATUS_IS_OK(result)) {
2413 /* Get domain policy handle */
2415 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2421 if (!NT_STATUS_IS_OK(result)) {
2425 init_lsa_String(&lsa_acct_name, user);
2427 result = rpccli_samr_LookupNames(cli, mem_ctx,
2434 if (!NT_STATUS_IS_OK(result)) {
2438 result = rpccli_samr_OpenUser(cli, mem_ctx,
2444 if (!NT_STATUS_IS_OK(result)) {
2448 /* Change user password */
2449 result = rpccli_samr_chgpasswd_user(cli, mem_ctx,
2454 if (!NT_STATUS_IS_OK(result)) {
2459 if (is_valid_policy_hnd(&user_pol)) {
2460 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2462 if (is_valid_policy_hnd(&domain_pol)) {
2463 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2465 if (is_valid_policy_hnd(&connect_pol)) {
2466 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2473 /* Change user password */
2475 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
2476 TALLOC_CTX *mem_ctx,
2477 int argc, const char **argv)
2479 struct policy_handle connect_pol, domain_pol;
2480 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2481 const char *user, *oldpass, *newpass;
2482 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2485 printf("Usage: %s username oldpass newpass\n", argv[0]);
2486 return NT_STATUS_INVALID_PARAMETER;
2493 /* Get sam policy handle */
2495 result = rpccli_try_samr_connects(cli, mem_ctx,
2496 MAXIMUM_ALLOWED_ACCESS,
2499 if (!NT_STATUS_IS_OK(result))
2502 /* Get domain policy handle */
2504 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2510 if (!NT_STATUS_IS_OK(result))
2513 /* Change user password */
2514 result = rpccli_samr_chgpasswd_user2(cli, mem_ctx, user, newpass, oldpass);
2516 if (!NT_STATUS_IS_OK(result))
2519 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2520 if (!NT_STATUS_IS_OK(result)) goto done;
2522 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2523 if (!NT_STATUS_IS_OK(result)) goto done;
2530 /* Change user password */
2532 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
2533 TALLOC_CTX *mem_ctx,
2534 int argc, const char **argv)
2536 struct policy_handle connect_pol, domain_pol;
2537 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2538 const char *user, *oldpass, *newpass;
2539 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2540 struct samr_DomInfo1 *info = NULL;
2541 struct userPwdChangeFailureInformation *reject = NULL;
2544 printf("Usage: %s username oldpass newpass\n", argv[0]);
2545 return NT_STATUS_INVALID_PARAMETER;
2552 /* Get sam policy handle */
2554 result = rpccli_try_samr_connects(cli, mem_ctx,
2555 MAXIMUM_ALLOWED_ACCESS,
2558 if (!NT_STATUS_IS_OK(result))
2561 /* Get domain policy handle */
2563 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2569 if (!NT_STATUS_IS_OK(result))
2572 /* Change user password */
2573 result = rpccli_samr_chgpasswd_user3(cli, mem_ctx,
2580 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
2582 display_sam_dom_info_1(info);
2584 switch (reject->extendedFailureReason) {
2585 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT:
2586 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2588 case SAM_PWD_CHANGE_PWD_IN_HISTORY:
2589 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2591 case SAM_PWD_CHANGE_NOT_COMPLEX:
2592 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2595 d_printf("unknown reject reason: %d\n",
2596 reject->extendedFailureReason);
2601 if (!NT_STATUS_IS_OK(result))
2604 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2605 if (!NT_STATUS_IS_OK(result)) goto done;
2607 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2608 if (!NT_STATUS_IS_OK(result)) goto done;
2614 static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
2615 TALLOC_CTX *mem_ctx,
2616 int argc, const char **argv,
2619 struct policy_handle connect_pol, domain_pol, user_pol;
2620 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
2621 const char *user, *param;
2622 uint32_t access_mask = MAXIMUM_ALLOWED_ACCESS;
2625 union samr_UserInfo info;
2626 struct samr_CryptPassword pwd_buf;
2627 struct samr_CryptPasswordEx pwd_buf_ex;
2628 uint8_t nt_hash[16];
2629 uint8_t lm_hash[16];
2630 DATA_BLOB session_key;
2631 uint8_t password_expired = 0;
2634 printf("Usage: %s username level password [password_expired]\n",
2636 return NT_STATUS_INVALID_PARAMETER;
2640 level = atoi(argv[2]);
2644 password_expired = atoi(argv[4]);
2647 status = cli_get_session_key(mem_ctx, cli, &session_key);
2648 if (!NT_STATUS_IS_OK(status)) {
2652 init_samr_CryptPassword(param, &session_key, &pwd_buf);
2653 init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
2654 nt_lm_owf_gen(param, nt_hash, lm_hash);
2660 in = data_blob_const(nt_hash, 16);
2661 out = data_blob_talloc_zero(mem_ctx, 16);
2662 sess_crypt_blob(&out, &in, &session_key, true);
2663 memcpy(nt_hash, out.data, out.length);
2667 in = data_blob_const(lm_hash, 16);
2668 out = data_blob_talloc_zero(mem_ctx, 16);
2669 sess_crypt_blob(&out, &in, &session_key, true);
2670 memcpy(lm_hash, out.data, out.length);
2673 memcpy(info.info18.nt_pwd.hash, nt_hash, 16);
2674 memcpy(info.info18.lm_pwd.hash, lm_hash, 16);
2675 info.info18.nt_pwd_active = true;
2676 info.info18.lm_pwd_active = true;
2677 info.info18.password_expired = password_expired;
2681 ZERO_STRUCT(info.info21);
2683 info.info21.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2684 SAMR_FIELD_LM_PASSWORD_PRESENT;
2686 info.info21.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2687 info.info21.password_expired = password_expired;
2690 info.info21.lm_password_set = true;
2691 info.info21.lm_owf_password.length = 16;
2692 info.info21.lm_owf_password.size = 16;
2694 info.info21.nt_password_set = true;
2695 info.info21.nt_owf_password.length = 16;
2696 info.info21.nt_owf_password.size = 16;
2700 in = data_blob_const(nt_hash, 16);
2701 out = data_blob_talloc_zero(mem_ctx, 16);
2702 sess_crypt_blob(&out, &in, &session_key, true);
2703 info.info21.nt_owf_password.array =
2704 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2708 in = data_blob_const(lm_hash, 16);
2709 out = data_blob_talloc_zero(mem_ctx, 16);
2710 sess_crypt_blob(&out, &in, &session_key, true);
2711 info.info21.lm_owf_password.array =
2712 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2717 ZERO_STRUCT(info.info23);
2719 info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2720 SAMR_FIELD_LM_PASSWORD_PRESENT;
2722 info.info23.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2723 info.info23.info.password_expired = password_expired;
2726 info.info23.password = pwd_buf;
2730 info.info24.password = pwd_buf;
2731 info.info24.password_expired = password_expired;
2735 ZERO_STRUCT(info.info25);
2737 info.info25.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2738 SAMR_FIELD_LM_PASSWORD_PRESENT;
2740 info.info25.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2741 info.info25.info.password_expired = password_expired;
2744 info.info25.password = pwd_buf_ex;
2748 info.info26.password = pwd_buf_ex;
2749 info.info26.password_expired = password_expired;
2753 return NT_STATUS_INVALID_INFO_CLASS;
2756 /* Get sam policy handle */
2758 status = rpccli_try_samr_connects(cli, mem_ctx,
2759 MAXIMUM_ALLOWED_ACCESS,
2762 if (!NT_STATUS_IS_OK(status))
2765 /* Get domain policy handle */
2767 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2773 if (!NT_STATUS_IS_OK(status))
2776 user_rid = strtol(user, NULL, 0);
2778 status = rpccli_samr_OpenUser(cli, mem_ctx,
2785 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER) ||
2788 /* Probably this was a user name, try lookupnames */
2789 struct samr_Ids rids, types;
2790 struct lsa_String lsa_acct_name;
2792 init_lsa_String(&lsa_acct_name, user);
2794 status = rpccli_samr_LookupNames(cli, mem_ctx,
2800 if (!NT_STATUS_IS_OK(status)) {
2804 status = rpccli_samr_OpenUser(cli, mem_ctx,
2809 if (!NT_STATUS_IS_OK(status)) {
2815 case NDR_SAMR_SETUSERINFO:
2816 status = rpccli_samr_SetUserInfo(cli, mem_ctx,
2821 case NDR_SAMR_SETUSERINFO2:
2822 status = rpccli_samr_SetUserInfo2(cli, mem_ctx,
2828 return NT_STATUS_INVALID_PARAMETER;
2835 static NTSTATUS cmd_samr_setuserinfo(struct rpc_pipe_client *cli,
2836 TALLOC_CTX *mem_ctx,
2837 int argc, const char **argv)
2839 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2840 NDR_SAMR_SETUSERINFO);
2843 static NTSTATUS cmd_samr_setuserinfo2(struct rpc_pipe_client *cli,
2844 TALLOC_CTX *mem_ctx,
2845 int argc, const char **argv)
2847 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2848 NDR_SAMR_SETUSERINFO2);
2851 static NTSTATUS cmd_samr_get_dispinfo_idx(struct rpc_pipe_client *cli,
2852 TALLOC_CTX *mem_ctx,
2853 int argc, const char **argv)
2856 struct policy_handle connect_handle;
2857 struct policy_handle domain_handle;
2859 struct lsa_String name;
2862 if (argc < 2 || argc > 3) {
2863 printf("Usage: %s name level\n", argv[0]);
2864 return NT_STATUS_INVALID_PARAMETER;
2867 init_lsa_String(&name, argv[1]);
2870 level = atoi(argv[2]);
2873 status = rpccli_try_samr_connects(cli, mem_ctx,
2874 SEC_FLAG_MAXIMUM_ALLOWED,
2877 if (!NT_STATUS_IS_OK(status)) {
2881 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2883 SEC_FLAG_MAXIMUM_ALLOWED,
2887 if (!NT_STATUS_IS_OK(status))
2891 status = rpccli_samr_GetDisplayEnumerationIndex(cli, mem_ctx,
2897 if (NT_STATUS_IS_OK(status) ||
2898 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
2899 printf("idx: %d (0x%08x)\n", idx, idx);
2903 if (is_valid_policy_hnd(&domain_handle)) {
2904 rpccli_samr_Close(cli, mem_ctx, &domain_handle);
2906 if (is_valid_policy_hnd(&connect_handle)) {
2907 rpccli_samr_Close(cli, mem_ctx, &connect_handle);
2913 /* List of commands exported by this module */
2915 struct cmd_set samr_commands[] = {
2919 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, &ndr_table_samr.syntax_id, NULL, "Query user info", "" },
2920 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, &ndr_table_samr.syntax_id, NULL, "Query group info", "" },
2921 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, &ndr_table_samr.syntax_id, NULL, "Query user groups", "" },
2922 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, &ndr_table_samr.syntax_id, NULL, "Query user aliases", "" },
2923 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query group membership", "" },
2924 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias membership", "" },
2925 { "queryaliasinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias info", "" },
2926 { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Delete an alias", "" },
2927 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2928 { "querydispinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2929 { "querydispinfo3", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2930 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query domain info", "" },
2931 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain users", "" },
2932 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain groups", "" },
2933 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate alias groups", "" },
2934 { "enumdomains", RPC_RTYPE_NTSTATUS, cmd_samr_enum_domains, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domains", "" },
2936 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain user", "" },
2937 { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain group", "" },
2938 { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain alias", "" },
2939 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2940 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2941 { "deletedomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain group", "" },
2942 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain user", "" },
2943 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, &ndr_table_samr.syntax_id, NULL, "Query SAMR security object", "" },
2944 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve domain password info", "" },
2945 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve user domain password info", "" },
2947 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, &ndr_table_samr.syntax_id, NULL, "Lookup Domain Name", "" },
2948 { "chgpasswd", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2949 { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2950 { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2951 { "getdispinfoidx", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispinfo_idx, NULL, &ndr_table_samr.syntax_id, NULL, "Get Display Information Index", "" },
2952 { "setuserinfo", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info", "" },
2953 { "setuserinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info2", "" },