wafsamba: Fix handling of pyembed/pyext.
[Samba.git] / source3 / rpcclient / cmd_samr.c
blob7730e65c1218cf7ef3f634beac6ff27bf5e3789e
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Andrew Tridgell 1992-2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 Copyright (C) Elrond 2000,
8 Copyright (C) Tim Potter 2000
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/>.
25 #include "includes.h"
26 #include "rpcclient.h"
27 #include "../libcli/auth/libcli_auth.h"
28 #include "../librpc/gen_ndr/ndr_samr.h"
29 #include "../librpc/gen_ndr/cli_samr.h"
30 #include "rpc_client/cli_samr.h"
31 #include "rpc_client/init_samr.h"
32 #include "rpc_client/init_lsa.h"
33 #include "../libcli/security/dom_sid.h"
35 extern struct dom_sid domain_sid;
37 /****************************************************************************
38 display samr_user_info_7 structure
39 ****************************************************************************/
40 static void display_samr_user_info_7(struct samr_UserInfo7 *r)
42 printf("\tUser Name :\t%s\n", r->account_name.string);
45 /****************************************************************************
46 display samr_user_info_9 structure
47 ****************************************************************************/
48 static void display_samr_user_info_9(struct samr_UserInfo9 *r)
50 printf("\tPrimary group RID :\tox%x\n", r->primary_gid);
53 /****************************************************************************
54 display samr_user_info_16 structure
55 ****************************************************************************/
56 static void display_samr_user_info_16(struct samr_UserInfo16 *r)
58 printf("\tAcct Flags :\tox%x\n", r->acct_flags);
61 /****************************************************************************
62 display samr_user_info_20 structure
63 ****************************************************************************/
64 static void display_samr_user_info_20(struct samr_UserInfo20 *r)
66 printf("\tRemote Dial :\n");
67 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
71 /****************************************************************************
72 display samr_user_info_21 structure
73 ****************************************************************************/
74 static void display_samr_user_info_21(struct samr_UserInfo21 *r)
76 printf("\tUser Name :\t%s\n", r->account_name.string);
77 printf("\tFull Name :\t%s\n", r->full_name.string);
78 printf("\tHome Drive :\t%s\n", r->home_directory.string);
79 printf("\tDir Drive :\t%s\n", r->home_drive.string);
80 printf("\tProfile Path:\t%s\n", r->profile_path.string);
81 printf("\tLogon Script:\t%s\n", r->logon_script.string);
82 printf("\tDescription :\t%s\n", r->description.string);
83 printf("\tWorkstations:\t%s\n", r->workstations.string);
84 printf("\tComment :\t%s\n", r->comment.string);
85 printf("\tRemote Dial :\n");
86 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
88 printf("\tLogon Time :\t%s\n",
89 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logon)));
90 printf("\tLogoff Time :\t%s\n",
91 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logoff)));
92 printf("\tKickoff Time :\t%s\n",
93 http_timestring(talloc_tos(), nt_time_to_unix(r->acct_expiry)));
94 printf("\tPassword last set Time :\t%s\n",
95 http_timestring(talloc_tos(), nt_time_to_unix(r->last_password_change)));
96 printf("\tPassword can change Time :\t%s\n",
97 http_timestring(talloc_tos(), nt_time_to_unix(r->allow_password_change)));
98 printf("\tPassword must change Time:\t%s\n",
99 http_timestring(talloc_tos(), nt_time_to_unix(r->force_password_change)));
101 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
103 printf("\tuser_rid :\t0x%x\n" , r->rid); /* User ID */
104 printf("\tgroup_rid:\t0x%x\n" , r->primary_gid); /* Group ID */
105 printf("\tacb_info :\t0x%08x\n", r->acct_flags); /* Account Control Info */
107 printf("\tfields_present:\t0x%08x\n", r->fields_present); /* 0x00ff ffff */
108 printf("\tlogon_divs:\t%d\n", r->logon_hours.units_per_week); /* 0x0000 00a8 which is 168 which is num hrs in a week */
109 printf("\tbad_password_count:\t0x%08x\n", r->bad_password_count);
110 printf("\tlogon_count:\t0x%08x\n", r->logon_count);
112 printf("\tpadding1[0..7]...\n");
114 if (r->logon_hours.bits) {
115 printf("\tlogon_hrs[0..%d]...\n", r->logon_hours.units_per_week/8);
120 static void display_password_properties(uint32_t password_properties)
122 printf("password_properties: 0x%08x\n", password_properties);
124 if (password_properties & DOMAIN_PASSWORD_COMPLEX)
125 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
127 if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
128 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
130 if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
131 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
133 if (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)
134 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
136 if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
137 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
139 if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
140 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
143 static void display_sam_dom_info_1(struct samr_DomInfo1 *info1)
145 printf("Minimum password length:\t\t\t%d\n",
146 info1->min_password_length);
147 printf("Password uniqueness (remember x passwords):\t%d\n",
148 info1->password_history_length);
149 display_password_properties(info1->password_properties);
150 printf("password expire in:\t\t\t\t%s\n",
151 display_time(info1->max_password_age));
152 printf("Min password age (allow changing in x days):\t%s\n",
153 display_time(info1->min_password_age));
156 static void display_sam_dom_info_2(struct samr_DomGeneralInformation *general)
158 printf("Domain:\t\t%s\n", general->domain_name.string);
159 printf("Server:\t\t%s\n", general->primary.string);
160 printf("Comment:\t%s\n", general->oem_information.string);
162 printf("Total Users:\t%d\n", general->num_users);
163 printf("Total Groups:\t%d\n", general->num_groups);
164 printf("Total Aliases:\t%d\n", general->num_aliases);
166 printf("Sequence No:\t%llu\n", (unsigned long long)general->sequence_num);
168 printf("Force Logoff:\t%d\n",
169 (int)nt_time_to_unix_abs(&general->force_logoff_time));
171 printf("Domain Server State:\t0x%x\n", general->domain_server_state);
172 printf("Server Role:\t%s\n", server_role_str(general->role));
173 printf("Unknown 3:\t0x%x\n", general->unknown3);
176 static void display_sam_dom_info_3(struct samr_DomInfo3 *info3)
178 printf("Force Logoff:\t%d\n",
179 (int)nt_time_to_unix_abs(&info3->force_logoff_time));
182 static void display_sam_dom_info_4(struct samr_DomOEMInformation *oem)
184 printf("Comment:\t%s\n", oem->oem_information.string);
187 static void display_sam_dom_info_5(struct samr_DomInfo5 *info5)
189 printf("Domain:\t\t%s\n", info5->domain_name.string);
192 static void display_sam_dom_info_6(struct samr_DomInfo6 *info6)
194 printf("Server:\t\t%s\n", info6->primary.string);
197 static void display_sam_dom_info_7(struct samr_DomInfo7 *info7)
199 printf("Server Role:\t%s\n", server_role_str(info7->role));
202 static void display_sam_dom_info_8(struct samr_DomInfo8 *info8)
204 printf("Sequence No:\t%llu\n", (unsigned long long)info8->sequence_num);
205 printf("Domain Create Time:\t%s\n",
206 http_timestring(talloc_tos(), nt_time_to_unix(info8->domain_create_time)));
209 static void display_sam_dom_info_9(struct samr_DomInfo9 *info9)
211 printf("Domain Server State:\t0x%x\n", info9->domain_server_state);
214 static void display_sam_dom_info_12(struct samr_DomInfo12 *info12)
216 printf("Bad password lockout duration: %s\n",
217 display_time(info12->lockout_duration));
218 printf("Reset Lockout after: %s\n",
219 display_time(info12->lockout_window));
220 printf("Lockout after bad attempts: %d\n",
221 info12->lockout_threshold);
224 static void display_sam_dom_info_13(struct samr_DomInfo13 *info13)
226 printf("Sequence No:\t%llu\n", (unsigned long long)info13->sequence_num);
227 printf("Domain Create Time:\t%s\n",
228 http_timestring(talloc_tos(), nt_time_to_unix(info13->domain_create_time)));
229 printf("Sequence No at last promotion:\t%llu\n",
230 (unsigned long long)info13->modified_count_at_last_promotion);
233 static void display_sam_info_1(struct samr_DispEntryGeneral *r)
235 printf("index: 0x%x ", r->idx);
236 printf("RID: 0x%x ", r->rid);
237 printf("acb: 0x%08x ", r->acct_flags);
238 printf("Account: %s\t", r->account_name.string);
239 printf("Name: %s\t", r->full_name.string);
240 printf("Desc: %s\n", r->description.string);
243 static void display_sam_info_2(struct samr_DispEntryFull *r)
245 printf("index: 0x%x ", r->idx);
246 printf("RID: 0x%x ", r->rid);
247 printf("acb: 0x%08x ", r->acct_flags);
248 printf("Account: %s\t", r->account_name.string);
249 printf("Desc: %s\n", r->description.string);
252 static void display_sam_info_3(struct samr_DispEntryFullGroup *r)
254 printf("index: 0x%x ", r->idx);
255 printf("RID: 0x%x ", r->rid);
256 printf("acb: 0x%08x ", r->acct_flags);
257 printf("Account: %s\t", r->account_name.string);
258 printf("Desc: %s\n", r->description.string);
261 static void display_sam_info_4(struct samr_DispEntryAscii *r)
263 printf("index: 0x%x ", r->idx);
264 printf("Account: %s\n", r->account_name.string);
267 static void display_sam_info_5(struct samr_DispEntryAscii *r)
269 printf("index: 0x%x ", r->idx);
270 printf("Account: %s\n", r->account_name.string);
273 /****************************************************************************
274 ****************************************************************************/
276 static NTSTATUS get_domain_handle(struct rpc_pipe_client *cli,
277 TALLOC_CTX *mem_ctx,
278 const char *sam,
279 struct policy_handle *connect_pol,
280 uint32_t access_mask,
281 struct dom_sid *_domain_sid,
282 struct policy_handle *domain_pol)
285 if (StrCaseCmp(sam, "domain") == 0) {
286 return rpccli_samr_OpenDomain(cli, mem_ctx,
287 connect_pol,
288 access_mask,
289 _domain_sid,
290 domain_pol);
291 } else if (StrCaseCmp(sam, "builtin") == 0) {
292 return rpccli_samr_OpenDomain(cli, mem_ctx,
293 connect_pol,
294 access_mask,
295 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
296 domain_pol);
299 return NT_STATUS_INVALID_PARAMETER;
302 /**********************************************************************
303 * Query user information
305 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
306 TALLOC_CTX *mem_ctx,
307 int argc, const char **argv)
309 struct policy_handle connect_pol, domain_pol, user_pol;
310 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
311 uint32 info_level = 21;
312 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
313 union samr_UserInfo *info = NULL;
314 uint32 user_rid = 0;
316 if ((argc < 2) || (argc > 4)) {
317 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
318 return NT_STATUS_OK;
321 sscanf(argv[1], "%i", &user_rid);
323 if (argc > 2)
324 sscanf(argv[2], "%i", &info_level);
326 if (argc > 3)
327 sscanf(argv[3], "%x", &access_mask);
330 result = rpccli_try_samr_connects(cli, mem_ctx,
331 MAXIMUM_ALLOWED_ACCESS,
332 &connect_pol);
334 if (!NT_STATUS_IS_OK(result))
335 goto done;
337 result = rpccli_samr_OpenDomain(cli, mem_ctx,
338 &connect_pol,
339 MAXIMUM_ALLOWED_ACCESS,
340 &domain_sid,
341 &domain_pol);
342 if (!NT_STATUS_IS_OK(result))
343 goto done;
345 result = rpccli_samr_OpenUser(cli, mem_ctx,
346 &domain_pol,
347 access_mask,
348 user_rid,
349 &user_pol);
351 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
352 (user_rid == 0)) {
354 /* Probably this was a user name, try lookupnames */
355 struct samr_Ids rids, types;
356 struct lsa_String lsa_acct_name;
358 init_lsa_String(&lsa_acct_name, argv[1]);
360 result = rpccli_samr_LookupNames(cli, mem_ctx,
361 &domain_pol,
363 &lsa_acct_name,
364 &rids,
365 &types);
367 if (NT_STATUS_IS_OK(result)) {
368 result = rpccli_samr_OpenUser(cli, mem_ctx,
369 &domain_pol,
370 access_mask,
371 rids.ids[0],
372 &user_pol);
377 if (!NT_STATUS_IS_OK(result))
378 goto done;
380 result = rpccli_samr_QueryUserInfo(cli, mem_ctx,
381 &user_pol,
382 info_level,
383 &info);
385 if (!NT_STATUS_IS_OK(result))
386 goto done;
388 switch (info_level) {
389 case 7:
390 display_samr_user_info_7(&info->info7);
391 break;
392 case 9:
393 display_samr_user_info_9(&info->info9);
394 break;
395 case 16:
396 display_samr_user_info_16(&info->info16);
397 break;
398 case 20:
399 display_samr_user_info_20(&info->info20);
400 break;
401 case 21:
402 display_samr_user_info_21(&info->info21);
403 break;
404 default:
405 printf("Unsupported infolevel: %d\n", info_level);
406 break;
409 rpccli_samr_Close(cli, mem_ctx, &user_pol);
410 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
411 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
413 done:
414 return result;
417 /****************************************************************************
418 display group info
419 ****************************************************************************/
420 static void display_group_info1(struct samr_GroupInfoAll *info1)
422 printf("\tGroup Name:\t%s\n", info1->name.string);
423 printf("\tDescription:\t%s\n", info1->description.string);
424 printf("\tGroup Attribute:%d\n", info1->attributes);
425 printf("\tNum Members:%d\n", info1->num_members);
428 /****************************************************************************
429 display group info
430 ****************************************************************************/
431 static void display_group_info2(struct lsa_String *info2)
433 printf("\tGroup Description:%s\n", info2->string);
437 /****************************************************************************
438 display group info
439 ****************************************************************************/
440 static void display_group_info3(struct samr_GroupInfoAttributes *info3)
442 printf("\tGroup Attribute:%d\n", info3->attributes);
446 /****************************************************************************
447 display group info
448 ****************************************************************************/
449 static void display_group_info4(struct lsa_String *info4)
451 printf("\tGroup Description:%s\n", info4->string);
454 /****************************************************************************
455 display group info
456 ****************************************************************************/
457 static void display_group_info5(struct samr_GroupInfoAll *info5)
459 printf("\tGroup Name:\t%s\n", info5->name.string);
460 printf("\tDescription:\t%s\n", info5->description.string);
461 printf("\tGroup Attribute:%d\n", info5->attributes);
462 printf("\tNum Members:%d\n", info5->num_members);
465 /****************************************************************************
466 display sam sync structure
467 ****************************************************************************/
468 static void display_group_info(union samr_GroupInfo *info,
469 enum samr_GroupInfoEnum level)
471 switch (level) {
472 case 1:
473 display_group_info1(&info->all);
474 break;
475 case 2:
476 display_group_info2(&info->name);
477 break;
478 case 3:
479 display_group_info3(&info->attributes);
480 break;
481 case 4:
482 display_group_info4(&info->description);
483 break;
484 case 5:
485 display_group_info5(&info->all2);
486 break;
490 /***********************************************************************
491 * Query group information
493 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
494 TALLOC_CTX *mem_ctx,
495 int argc, const char **argv)
497 struct policy_handle connect_pol, domain_pol, group_pol;
498 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
499 enum samr_GroupInfoEnum info_level = GROUPINFOALL;
500 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
501 union samr_GroupInfo *group_info = NULL;
502 uint32 group_rid;
504 if ((argc < 2) || (argc > 4)) {
505 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
506 return NT_STATUS_OK;
509 sscanf(argv[1], "%i", &group_rid);
511 if (argc > 2)
512 info_level = atoi(argv[2]);
514 if (argc > 3)
515 sscanf(argv[3], "%x", &access_mask);
517 result = rpccli_try_samr_connects(cli, mem_ctx,
518 MAXIMUM_ALLOWED_ACCESS,
519 &connect_pol);
521 if (!NT_STATUS_IS_OK(result))
522 goto done;
524 result = rpccli_samr_OpenDomain(cli, mem_ctx,
525 &connect_pol,
526 MAXIMUM_ALLOWED_ACCESS,
527 &domain_sid,
528 &domain_pol);
530 if (!NT_STATUS_IS_OK(result))
531 goto done;
533 result = rpccli_samr_OpenGroup(cli, mem_ctx,
534 &domain_pol,
535 access_mask,
536 group_rid,
537 &group_pol);
539 if (!NT_STATUS_IS_OK(result))
540 goto done;
542 result = rpccli_samr_QueryGroupInfo(cli, mem_ctx,
543 &group_pol,
544 info_level,
545 &group_info);
546 if (!NT_STATUS_IS_OK(result)) {
547 goto done;
550 display_group_info(group_info, info_level);
552 rpccli_samr_Close(cli, mem_ctx, &group_pol);
553 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
554 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
555 done:
556 return result;
559 /* Query groups a user is a member of */
561 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
562 TALLOC_CTX *mem_ctx,
563 int argc, const char **argv)
565 struct policy_handle connect_pol,
566 domain_pol,
567 user_pol;
568 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
569 uint32 user_rid;
570 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
571 int i;
572 struct samr_RidWithAttributeArray *rid_array = NULL;
574 if ((argc < 2) || (argc > 3)) {
575 printf("Usage: %s rid [access mask]\n", argv[0]);
576 return NT_STATUS_OK;
579 sscanf(argv[1], "%i", &user_rid);
581 if (argc > 2)
582 sscanf(argv[2], "%x", &access_mask);
584 result = rpccli_try_samr_connects(cli, mem_ctx,
585 MAXIMUM_ALLOWED_ACCESS,
586 &connect_pol);
588 if (!NT_STATUS_IS_OK(result))
589 goto done;
591 result = rpccli_samr_OpenDomain(cli, mem_ctx,
592 &connect_pol,
593 MAXIMUM_ALLOWED_ACCESS,
594 &domain_sid, &domain_pol);
596 if (!NT_STATUS_IS_OK(result))
597 goto done;
599 result = rpccli_samr_OpenUser(cli, mem_ctx,
600 &domain_pol,
601 access_mask,
602 user_rid,
603 &user_pol);
605 if (!NT_STATUS_IS_OK(result))
606 goto done;
608 result = rpccli_samr_GetGroupsForUser(cli, mem_ctx,
609 &user_pol,
610 &rid_array);
612 if (!NT_STATUS_IS_OK(result))
613 goto done;
615 for (i = 0; i < rid_array->count; i++) {
616 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
617 rid_array->rids[i].rid,
618 rid_array->rids[i].attributes);
621 rpccli_samr_Close(cli, mem_ctx, &user_pol);
622 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
623 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
624 done:
625 return result;
628 /* Query aliases a user is a member of */
630 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
631 TALLOC_CTX *mem_ctx,
632 int argc, const char **argv)
634 struct policy_handle connect_pol, domain_pol;
635 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
636 struct dom_sid *sids;
637 uint32_t num_sids;
638 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
639 int i;
640 struct lsa_SidArray sid_array;
641 struct samr_Ids alias_rids;
643 if (argc < 3) {
644 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
645 return NT_STATUS_INVALID_PARAMETER;
648 sids = NULL;
649 num_sids = 0;
651 for (i=2; i<argc; i++) {
652 struct dom_sid tmp_sid;
653 if (!string_to_sid(&tmp_sid, argv[i])) {
654 printf("%s is not a legal SID\n", argv[i]);
655 return NT_STATUS_INVALID_PARAMETER;
657 result = add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
658 if (!NT_STATUS_IS_OK(result)) {
659 return result;
663 if (num_sids) {
664 sid_array.sids = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_SidPtr, num_sids);
665 if (sid_array.sids == NULL)
666 return NT_STATUS_NO_MEMORY;
667 } else {
668 sid_array.sids = NULL;
671 for (i=0; i<num_sids; i++) {
672 sid_array.sids[i].sid = dom_sid_dup(mem_ctx, &sids[i]);
673 if (!sid_array.sids[i].sid) {
674 return NT_STATUS_NO_MEMORY;
678 sid_array.num_sids = num_sids;
680 result = rpccli_try_samr_connects(cli, mem_ctx,
681 MAXIMUM_ALLOWED_ACCESS,
682 &connect_pol);
684 if (!NT_STATUS_IS_OK(result))
685 goto done;
687 result = get_domain_handle(cli, mem_ctx, argv[1],
688 &connect_pol,
689 access_mask,
690 &domain_sid,
691 &domain_pol);
693 if (!NT_STATUS_IS_OK(result))
694 goto done;
696 result = rpccli_samr_GetAliasMembership(cli, mem_ctx,
697 &domain_pol,
698 &sid_array,
699 &alias_rids);
700 if (!NT_STATUS_IS_OK(result))
701 goto done;
703 for (i = 0; i < alias_rids.count; i++) {
704 printf("\tgroup rid:[0x%x]\n", alias_rids.ids[i]);
707 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
708 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
709 done:
710 return result;
713 /* Query members of a group */
715 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
716 TALLOC_CTX *mem_ctx,
717 int argc, const char **argv)
719 struct policy_handle connect_pol, domain_pol, group_pol;
720 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
721 uint32 group_rid;
722 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
723 int i;
724 unsigned int old_timeout;
725 struct samr_RidAttrArray *rids = NULL;
727 if ((argc < 2) || (argc > 3)) {
728 printf("Usage: %s rid [access mask]\n", argv[0]);
729 return NT_STATUS_OK;
732 sscanf(argv[1], "%i", &group_rid);
734 if (argc > 2)
735 sscanf(argv[2], "%x", &access_mask);
737 result = rpccli_try_samr_connects(cli, mem_ctx,
738 MAXIMUM_ALLOWED_ACCESS,
739 &connect_pol);
741 if (!NT_STATUS_IS_OK(result))
742 goto done;
744 result = rpccli_samr_OpenDomain(cli, mem_ctx,
745 &connect_pol,
746 MAXIMUM_ALLOWED_ACCESS,
747 &domain_sid,
748 &domain_pol);
750 if (!NT_STATUS_IS_OK(result))
751 goto done;
753 result = rpccli_samr_OpenGroup(cli, mem_ctx,
754 &domain_pol,
755 access_mask,
756 group_rid,
757 &group_pol);
759 if (!NT_STATUS_IS_OK(result))
760 goto done;
762 /* Make sure to wait for our DC's reply */
763 old_timeout = rpccli_set_timeout(cli, 30000); /* 30 seconds. */
764 rpccli_set_timeout(cli, MAX(30000, old_timeout)); /* At least 30 sec */
766 result = rpccli_samr_QueryGroupMember(cli, mem_ctx,
767 &group_pol,
768 &rids);
770 rpccli_set_timeout(cli, old_timeout);
772 if (!NT_STATUS_IS_OK(result))
773 goto done;
775 for (i = 0; i < rids->count; i++) {
776 printf("\trid:[0x%x] attr:[0x%x]\n", rids->rids[i],
777 rids->attributes[i]);
780 rpccli_samr_Close(cli, mem_ctx, &group_pol);
781 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
782 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
783 done:
784 return result;
787 /* Enumerate domain users */
789 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
790 TALLOC_CTX *mem_ctx,
791 int argc, const char **argv)
793 struct policy_handle connect_pol, domain_pol;
794 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
795 uint32 start_idx, num_dom_users, i;
796 struct samr_SamArray *dom_users = NULL;
797 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
798 uint32 acb_mask = ACB_NORMAL;
799 uint32_t size = 0xffff;
801 if ((argc < 1) || (argc > 4)) {
802 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv[0]);
803 return NT_STATUS_OK;
806 if (argc > 1) {
807 sscanf(argv[1], "%x", &access_mask);
810 if (argc > 2) {
811 sscanf(argv[2], "%x", &acb_mask);
814 if (argc > 3) {
815 sscanf(argv[3], "%x", &size);
818 /* Get sam policy handle */
820 result = rpccli_try_samr_connects(cli, mem_ctx,
821 MAXIMUM_ALLOWED_ACCESS,
822 &connect_pol);
824 if (!NT_STATUS_IS_OK(result))
825 goto done;
827 /* Get domain policy handle */
829 result = get_domain_handle(cli, mem_ctx, "domain",
830 &connect_pol,
831 access_mask,
832 &domain_sid,
833 &domain_pol);
834 if (!NT_STATUS_IS_OK(result))
835 goto done;
837 /* Enumerate domain users */
839 start_idx = 0;
841 do {
842 result = rpccli_samr_EnumDomainUsers(cli, mem_ctx,
843 &domain_pol,
844 &start_idx,
845 acb_mask,
846 &dom_users,
847 size,
848 &num_dom_users);
850 if (NT_STATUS_IS_OK(result) ||
851 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
853 for (i = 0; i < num_dom_users; i++)
854 printf("user:[%s] rid:[0x%x]\n",
855 dom_users->entries[i].name.string,
856 dom_users->entries[i].idx);
859 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
861 done:
862 if (is_valid_policy_hnd(&domain_pol))
863 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
865 if (is_valid_policy_hnd(&connect_pol))
866 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
868 return result;
871 /* Enumerate domain groups */
873 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
874 TALLOC_CTX *mem_ctx,
875 int argc, const char **argv)
877 struct policy_handle connect_pol, domain_pol;
878 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
879 uint32 start_idx, num_dom_groups, i;
880 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
881 struct samr_SamArray *dom_groups = NULL;
882 uint32_t size = 0xffff;
884 if ((argc < 1) || (argc > 3)) {
885 printf("Usage: %s [access_mask] [max_size]\n", argv[0]);
886 return NT_STATUS_OK;
889 if (argc > 1) {
890 sscanf(argv[1], "%x", &access_mask);
893 if (argc > 2) {
894 sscanf(argv[2], "%x", &size);
897 /* Get sam policy handle */
899 result = rpccli_try_samr_connects(cli, mem_ctx,
900 MAXIMUM_ALLOWED_ACCESS,
901 &connect_pol);
903 if (!NT_STATUS_IS_OK(result))
904 goto done;
906 /* Get domain policy handle */
908 result = get_domain_handle(cli, mem_ctx, "domain",
909 &connect_pol,
910 access_mask,
911 &domain_sid,
912 &domain_pol);
913 if (!NT_STATUS_IS_OK(result))
914 goto done;
916 /* Enumerate domain groups */
918 start_idx = 0;
920 do {
921 result = rpccli_samr_EnumDomainGroups(cli, mem_ctx,
922 &domain_pol,
923 &start_idx,
924 &dom_groups,
925 size,
926 &num_dom_groups);
927 if (NT_STATUS_IS_OK(result) ||
928 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
930 for (i = 0; i < num_dom_groups; i++)
931 printf("group:[%s] rid:[0x%x]\n",
932 dom_groups->entries[i].name.string,
933 dom_groups->entries[i].idx);
936 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
938 done:
939 if (is_valid_policy_hnd(&domain_pol))
940 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
942 if (is_valid_policy_hnd(&connect_pol))
943 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
945 return result;
948 /* Enumerate alias groups */
950 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
951 TALLOC_CTX *mem_ctx,
952 int argc, const char **argv)
954 struct policy_handle connect_pol, domain_pol;
955 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
956 uint32 start_idx, num_als_groups, i;
957 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
958 struct samr_SamArray *als_groups = NULL;
959 uint32_t size = 0xffff;
961 if ((argc < 2) || (argc > 4)) {
962 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv[0]);
963 return NT_STATUS_OK;
966 if (argc > 2) {
967 sscanf(argv[2], "%x", &access_mask);
970 if (argc > 3) {
971 sscanf(argv[3], "%x", &size);
974 /* Get sam policy handle */
976 result = rpccli_try_samr_connects(cli, mem_ctx,
977 MAXIMUM_ALLOWED_ACCESS,
978 &connect_pol);
980 if (!NT_STATUS_IS_OK(result))
981 goto done;
983 /* Get domain policy handle */
985 result = get_domain_handle(cli, mem_ctx, argv[1],
986 &connect_pol,
987 access_mask,
988 &domain_sid,
989 &domain_pol);
991 if (!NT_STATUS_IS_OK(result))
992 goto done;
994 /* Enumerate alias groups */
996 start_idx = 0;
998 do {
999 result = rpccli_samr_EnumDomainAliases(cli, mem_ctx,
1000 &domain_pol,
1001 &start_idx,
1002 &als_groups,
1003 size,
1004 &num_als_groups);
1006 if (NT_STATUS_IS_OK(result) ||
1007 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1009 for (i = 0; i < num_als_groups; i++)
1010 printf("group:[%s] rid:[0x%x]\n",
1011 als_groups->entries[i].name.string,
1012 als_groups->entries[i].idx);
1014 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1016 done:
1017 if (is_valid_policy_hnd(&domain_pol))
1018 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1020 if (is_valid_policy_hnd(&connect_pol))
1021 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1023 return result;
1026 /* Enumerate domains */
1028 static NTSTATUS cmd_samr_enum_domains(struct rpc_pipe_client *cli,
1029 TALLOC_CTX *mem_ctx,
1030 int argc, const char **argv)
1032 struct policy_handle connect_pol;
1033 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1034 uint32 start_idx, size, num_entries, i;
1035 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1036 struct samr_SamArray *sam = NULL;
1038 if ((argc < 1) || (argc > 2)) {
1039 printf("Usage: %s [access mask]\n", argv[0]);
1040 return NT_STATUS_OK;
1043 if (argc > 1) {
1044 sscanf(argv[1], "%x", &access_mask);
1047 /* Get sam policy handle */
1049 result = rpccli_try_samr_connects(cli, mem_ctx,
1050 access_mask,
1051 &connect_pol);
1053 if (!NT_STATUS_IS_OK(result)) {
1054 goto done;
1057 /* Enumerate alias groups */
1059 start_idx = 0;
1060 size = 0xffff;
1062 do {
1063 result = rpccli_samr_EnumDomains(cli, mem_ctx,
1064 &connect_pol,
1065 &start_idx,
1066 &sam,
1067 size,
1068 &num_entries);
1070 if (NT_STATUS_IS_OK(result) ||
1071 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1073 for (i = 0; i < num_entries; i++)
1074 printf("name:[%s] idx:[0x%x]\n",
1075 sam->entries[i].name.string,
1076 sam->entries[i].idx);
1078 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1080 done:
1081 if (is_valid_policy_hnd(&connect_pol)) {
1082 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1085 return result;
1089 /* Query alias membership */
1091 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
1092 TALLOC_CTX *mem_ctx,
1093 int argc, const char **argv)
1095 struct policy_handle connect_pol, domain_pol, alias_pol;
1096 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1097 uint32 alias_rid, i;
1098 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1099 struct lsa_SidArray sid_array;
1101 if ((argc < 3) || (argc > 4)) {
1102 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
1103 return NT_STATUS_OK;
1106 sscanf(argv[2], "%i", &alias_rid);
1108 if (argc > 3)
1109 sscanf(argv[3], "%x", &access_mask);
1111 /* Open SAMR handle */
1113 result = rpccli_try_samr_connects(cli, mem_ctx,
1114 MAXIMUM_ALLOWED_ACCESS,
1115 &connect_pol);
1117 if (!NT_STATUS_IS_OK(result))
1118 goto done;
1120 /* Open handle on domain */
1122 result = get_domain_handle(cli, mem_ctx, argv[1],
1123 &connect_pol,
1124 MAXIMUM_ALLOWED_ACCESS,
1125 &domain_sid,
1126 &domain_pol);
1128 if (!NT_STATUS_IS_OK(result))
1129 goto done;
1131 /* Open handle on alias */
1133 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1134 &domain_pol,
1135 access_mask,
1136 alias_rid,
1137 &alias_pol);
1138 if (!NT_STATUS_IS_OK(result))
1139 goto done;
1141 result = rpccli_samr_GetMembersInAlias(cli, mem_ctx,
1142 &alias_pol,
1143 &sid_array);
1145 if (!NT_STATUS_IS_OK(result))
1146 goto done;
1148 for (i = 0; i < sid_array.num_sids; i++) {
1149 fstring sid_str;
1151 sid_to_fstring(sid_str, sid_array.sids[i].sid);
1152 printf("\tsid:[%s]\n", sid_str);
1155 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1156 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1157 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1158 done:
1159 return result;
1162 /* Query alias info */
1164 static NTSTATUS cmd_samr_query_aliasinfo(struct rpc_pipe_client *cli,
1165 TALLOC_CTX *mem_ctx,
1166 int argc, const char **argv)
1168 struct policy_handle connect_pol, domain_pol, alias_pol;
1169 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1170 uint32_t alias_rid;
1171 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1172 union samr_AliasInfo *info = NULL;
1173 enum samr_AliasInfoEnum level = ALIASINFOALL;
1175 if ((argc < 3) || (argc > 4)) {
1176 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1177 argv[0]);
1178 return NT_STATUS_OK;
1181 sscanf(argv[2], "%i", &alias_rid);
1183 if (argc > 2) {
1184 level = atoi(argv[3]);
1187 if (argc > 3) {
1188 sscanf(argv[4], "%x", &access_mask);
1191 /* Open SAMR handle */
1193 result = rpccli_try_samr_connects(cli, mem_ctx,
1194 SEC_FLAG_MAXIMUM_ALLOWED,
1195 &connect_pol);
1197 if (!NT_STATUS_IS_OK(result)) {
1198 goto done;
1201 /* Open handle on domain */
1203 result = get_domain_handle(cli, mem_ctx, argv[1],
1204 &connect_pol,
1205 SEC_FLAG_MAXIMUM_ALLOWED,
1206 &domain_sid,
1207 &domain_pol);
1209 if (!NT_STATUS_IS_OK(result)) {
1210 goto done;
1213 /* Open handle on alias */
1215 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1216 &domain_pol,
1217 access_mask,
1218 alias_rid,
1219 &alias_pol);
1220 if (!NT_STATUS_IS_OK(result)) {
1221 goto done;
1224 result = rpccli_samr_QueryAliasInfo(cli, mem_ctx,
1225 &alias_pol,
1226 level,
1227 &info);
1229 if (!NT_STATUS_IS_OK(result)) {
1230 goto done;
1233 switch (level) {
1234 case ALIASINFOALL:
1235 printf("Name: %s\n", info->all.name.string);
1236 printf("Description: %s\n", info->all.description.string);
1237 printf("Num Members: %d\n", info->all.num_members);
1238 break;
1239 case ALIASINFONAME:
1240 printf("Name: %s\n", info->name.string);
1241 break;
1242 case ALIASINFODESCRIPTION:
1243 printf("Description: %s\n", info->description.string);
1244 break;
1245 default:
1246 break;
1249 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1250 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1251 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1252 done:
1253 return result;
1257 /* Query delete an alias membership */
1259 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
1260 TALLOC_CTX *mem_ctx,
1261 int argc, const char **argv)
1263 struct policy_handle connect_pol, domain_pol, alias_pol;
1264 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1265 uint32 alias_rid;
1266 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1268 if (argc != 3) {
1269 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
1270 return NT_STATUS_OK;
1273 alias_rid = strtoul(argv[2], NULL, 10);
1275 /* Open SAMR handle */
1277 result = rpccli_try_samr_connects(cli, mem_ctx,
1278 MAXIMUM_ALLOWED_ACCESS,
1279 &connect_pol);
1281 if (!NT_STATUS_IS_OK(result))
1282 goto done;
1284 /* Open handle on domain */
1286 result = get_domain_handle(cli, mem_ctx, argv[1],
1287 &connect_pol,
1288 MAXIMUM_ALLOWED_ACCESS,
1289 &domain_sid,
1290 &domain_pol);
1292 if (!NT_STATUS_IS_OK(result))
1293 goto done;
1295 /* Open handle on alias */
1297 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1298 &domain_pol,
1299 access_mask,
1300 alias_rid,
1301 &alias_pol);
1302 if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
1303 /* Probably this was a user name, try lookupnames */
1304 struct samr_Ids rids, types;
1305 struct lsa_String lsa_acct_name;
1307 init_lsa_String(&lsa_acct_name, argv[2]);
1309 result = rpccli_samr_LookupNames(cli, mem_ctx,
1310 &domain_pol,
1312 &lsa_acct_name,
1313 &rids,
1314 &types);
1316 if (NT_STATUS_IS_OK(result)) {
1317 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1318 &domain_pol,
1319 access_mask,
1320 rids.ids[0],
1321 &alias_pol);
1325 result = rpccli_samr_DeleteDomAlias(cli, mem_ctx,
1326 &alias_pol);
1328 if (!NT_STATUS_IS_OK(result))
1329 goto done;
1331 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1332 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1333 done:
1334 return result;
1337 /* Query display info */
1339 static NTSTATUS cmd_samr_query_dispinfo_internal(struct rpc_pipe_client *cli,
1340 TALLOC_CTX *mem_ctx,
1341 int argc, const char **argv,
1342 uint32_t opcode)
1344 struct policy_handle connect_pol, domain_pol;
1345 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1346 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries = 0, i;
1347 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1348 uint32 info_level = 1;
1349 union samr_DispInfo info;
1350 int loop_count = 0;
1351 bool got_params = False; /* Use get_query_dispinfo_params() or not? */
1352 uint32_t total_size, returned_size;
1354 if (argc > 6) {
1355 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
1356 return NT_STATUS_OK;
1359 if (argc >= 2)
1360 sscanf(argv[1], "%i", &info_level);
1362 if (argc >= 3)
1363 sscanf(argv[2], "%i", &start_idx);
1365 if (argc >= 4) {
1366 sscanf(argv[3], "%i", &max_entries);
1367 got_params = True;
1370 if (argc >= 5) {
1371 sscanf(argv[4], "%i", &max_size);
1372 got_params = True;
1375 if (argc >= 6)
1376 sscanf(argv[5], "%x", &access_mask);
1378 /* Get sam policy handle */
1380 result = rpccli_try_samr_connects(cli, mem_ctx,
1381 MAXIMUM_ALLOWED_ACCESS,
1382 &connect_pol);
1384 if (!NT_STATUS_IS_OK(result))
1385 goto done;
1387 /* Get domain policy handle */
1389 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1390 &connect_pol,
1391 access_mask,
1392 &domain_sid,
1393 &domain_pol);
1395 if (!NT_STATUS_IS_OK(result))
1396 goto done;
1398 /* Query display info */
1400 do {
1402 if (!got_params)
1403 get_query_dispinfo_params(
1404 loop_count, &max_entries, &max_size);
1406 switch (opcode) {
1407 case NDR_SAMR_QUERYDISPLAYINFO:
1408 result = rpccli_samr_QueryDisplayInfo(cli, mem_ctx,
1409 &domain_pol,
1410 info_level,
1411 start_idx,
1412 max_entries,
1413 max_size,
1414 &total_size,
1415 &returned_size,
1416 &info);
1417 break;
1418 case NDR_SAMR_QUERYDISPLAYINFO2:
1419 result = rpccli_samr_QueryDisplayInfo2(cli, mem_ctx,
1420 &domain_pol,
1421 info_level,
1422 start_idx,
1423 max_entries,
1424 max_size,
1425 &total_size,
1426 &returned_size,
1427 &info);
1429 break;
1430 case NDR_SAMR_QUERYDISPLAYINFO3:
1431 result = rpccli_samr_QueryDisplayInfo3(cli, mem_ctx,
1432 &domain_pol,
1433 info_level,
1434 start_idx,
1435 max_entries,
1436 max_size,
1437 &total_size,
1438 &returned_size,
1439 &info);
1441 break;
1442 default:
1443 return NT_STATUS_INVALID_PARAMETER;
1446 if (!NT_STATUS_IS_OK(result) &&
1447 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
1448 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
1449 break;
1452 loop_count++;
1454 switch (info_level) {
1455 case 1:
1456 num_entries = info.info1.count;
1457 break;
1458 case 2:
1459 num_entries = info.info2.count;
1460 break;
1461 case 3:
1462 num_entries = info.info3.count;
1463 break;
1464 case 4:
1465 num_entries = info.info4.count;
1466 break;
1467 case 5:
1468 num_entries = info.info5.count;
1469 break;
1470 default:
1471 break;
1474 start_idx += num_entries;
1476 if (num_entries == 0)
1477 break;
1479 for (i = 0; i < num_entries; i++) {
1480 switch (info_level) {
1481 case 1:
1482 display_sam_info_1(&info.info1.entries[i]);
1483 break;
1484 case 2:
1485 display_sam_info_2(&info.info2.entries[i]);
1486 break;
1487 case 3:
1488 display_sam_info_3(&info.info3.entries[i]);
1489 break;
1490 case 4:
1491 display_sam_info_4(&info.info4.entries[i]);
1492 break;
1493 case 5:
1494 display_sam_info_5(&info.info5.entries[i]);
1495 break;
1498 } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1500 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1501 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1502 done:
1503 return result;
1506 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
1507 TALLOC_CTX *mem_ctx,
1508 int argc, const char **argv)
1510 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1511 NDR_SAMR_QUERYDISPLAYINFO);
1514 static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1515 TALLOC_CTX *mem_ctx,
1516 int argc, const char **argv)
1518 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1519 NDR_SAMR_QUERYDISPLAYINFO2);
1522 static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1523 TALLOC_CTX *mem_ctx,
1524 int argc, const char **argv)
1526 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1527 NDR_SAMR_QUERYDISPLAYINFO3);
1530 /* Query domain info */
1532 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
1533 TALLOC_CTX *mem_ctx,
1534 int argc, const char **argv)
1536 struct policy_handle connect_pol, domain_pol;
1537 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1538 uint32 switch_level = 2;
1539 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1540 union samr_DomainInfo *info = NULL;
1542 if (argc > 3) {
1543 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1544 return NT_STATUS_OK;
1547 if (argc > 1)
1548 sscanf(argv[1], "%i", &switch_level);
1550 if (argc > 2)
1551 sscanf(argv[2], "%x", &access_mask);
1553 /* Get sam policy handle */
1555 result = rpccli_try_samr_connects(cli, mem_ctx,
1556 MAXIMUM_ALLOWED_ACCESS,
1557 &connect_pol);
1559 if (!NT_STATUS_IS_OK(result))
1560 goto done;
1562 /* Get domain policy handle */
1564 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1565 &connect_pol,
1566 access_mask,
1567 &domain_sid,
1568 &domain_pol);
1570 if (!NT_STATUS_IS_OK(result))
1571 goto done;
1573 /* Query domain info */
1575 result = rpccli_samr_QueryDomainInfo(cli, mem_ctx,
1576 &domain_pol,
1577 switch_level,
1578 &info);
1580 if (!NT_STATUS_IS_OK(result))
1581 goto done;
1583 /* Display domain info */
1585 switch (switch_level) {
1586 case 1:
1587 display_sam_dom_info_1(&info->info1);
1588 break;
1589 case 2:
1590 display_sam_dom_info_2(&info->general);
1591 break;
1592 case 3:
1593 display_sam_dom_info_3(&info->info3);
1594 break;
1595 case 4:
1596 display_sam_dom_info_4(&info->oem);
1597 break;
1598 case 5:
1599 display_sam_dom_info_5(&info->info5);
1600 break;
1601 case 6:
1602 display_sam_dom_info_6(&info->info6);
1603 break;
1604 case 7:
1605 display_sam_dom_info_7(&info->info7);
1606 break;
1607 case 8:
1608 display_sam_dom_info_8(&info->info8);
1609 break;
1610 case 9:
1611 display_sam_dom_info_9(&info->info9);
1612 break;
1613 case 12:
1614 display_sam_dom_info_12(&info->info12);
1615 break;
1616 case 13:
1617 display_sam_dom_info_13(&info->info13);
1618 break;
1620 default:
1621 printf("cannot display domain info for switch value %d\n",
1622 switch_level);
1623 break;
1626 done:
1628 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1629 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1630 return result;
1633 /* Create domain user */
1635 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
1636 TALLOC_CTX *mem_ctx,
1637 int argc, const char **argv)
1639 struct policy_handle connect_pol, domain_pol, user_pol;
1640 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1641 struct lsa_String acct_name;
1642 uint32 acb_info;
1643 uint32 acct_flags, user_rid;
1644 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1645 uint32_t access_granted = 0;
1647 if ((argc < 2) || (argc > 3)) {
1648 printf("Usage: %s username [access mask]\n", argv[0]);
1649 return NT_STATUS_OK;
1652 init_lsa_String(&acct_name, argv[1]);
1654 if (argc > 2)
1655 sscanf(argv[2], "%x", &access_mask);
1657 /* Get sam policy handle */
1659 result = rpccli_try_samr_connects(cli, mem_ctx,
1660 MAXIMUM_ALLOWED_ACCESS,
1661 &connect_pol);
1663 if (!NT_STATUS_IS_OK(result))
1664 goto done;
1666 /* Get domain policy handle */
1668 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1669 &connect_pol,
1670 access_mask,
1671 &domain_sid,
1672 &domain_pol);
1674 if (!NT_STATUS_IS_OK(result))
1675 goto done;
1677 /* Create domain user */
1679 acb_info = ACB_NORMAL;
1680 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
1681 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
1682 SAMR_USER_ACCESS_SET_PASSWORD |
1683 SAMR_USER_ACCESS_GET_ATTRIBUTES |
1684 SAMR_USER_ACCESS_SET_ATTRIBUTES;
1686 result = rpccli_samr_CreateUser2(cli, mem_ctx,
1687 &domain_pol,
1688 &acct_name,
1689 acb_info,
1690 acct_flags,
1691 &user_pol,
1692 &access_granted,
1693 &user_rid);
1695 if (!NT_STATUS_IS_OK(result))
1696 goto done;
1698 result = rpccli_samr_Close(cli, mem_ctx, &user_pol);
1699 if (!NT_STATUS_IS_OK(result)) goto done;
1701 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1702 if (!NT_STATUS_IS_OK(result)) goto done;
1704 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1705 if (!NT_STATUS_IS_OK(result)) goto done;
1707 done:
1708 return result;
1711 /* Create domain group */
1713 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
1714 TALLOC_CTX *mem_ctx,
1715 int argc, const char **argv)
1717 struct policy_handle connect_pol, domain_pol, group_pol;
1718 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1719 struct lsa_String grp_name;
1720 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1721 uint32_t rid = 0;
1723 if ((argc < 2) || (argc > 3)) {
1724 printf("Usage: %s groupname [access mask]\n", argv[0]);
1725 return NT_STATUS_OK;
1728 init_lsa_String(&grp_name, argv[1]);
1730 if (argc > 2)
1731 sscanf(argv[2], "%x", &access_mask);
1733 /* Get sam policy handle */
1735 result = rpccli_try_samr_connects(cli, mem_ctx,
1736 MAXIMUM_ALLOWED_ACCESS,
1737 &connect_pol);
1739 if (!NT_STATUS_IS_OK(result))
1740 goto done;
1742 /* Get domain policy handle */
1744 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1745 &connect_pol,
1746 access_mask,
1747 &domain_sid,
1748 &domain_pol);
1750 if (!NT_STATUS_IS_OK(result))
1751 goto done;
1753 /* Create domain user */
1754 result = rpccli_samr_CreateDomainGroup(cli, mem_ctx,
1755 &domain_pol,
1756 &grp_name,
1757 MAXIMUM_ALLOWED_ACCESS,
1758 &group_pol,
1759 &rid);
1761 if (!NT_STATUS_IS_OK(result))
1762 goto done;
1764 result = rpccli_samr_Close(cli, mem_ctx, &group_pol);
1765 if (!NT_STATUS_IS_OK(result)) goto done;
1767 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1768 if (!NT_STATUS_IS_OK(result)) goto done;
1770 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1771 if (!NT_STATUS_IS_OK(result)) goto done;
1773 done:
1774 return result;
1777 /* Create domain alias */
1779 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
1780 TALLOC_CTX *mem_ctx,
1781 int argc, const char **argv)
1783 struct policy_handle connect_pol, domain_pol, alias_pol;
1784 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1785 struct lsa_String alias_name;
1786 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1787 uint32_t rid = 0;
1789 if ((argc < 2) || (argc > 3)) {
1790 printf("Usage: %s aliasname [access mask]\n", argv[0]);
1791 return NT_STATUS_OK;
1794 init_lsa_String(&alias_name, argv[1]);
1796 if (argc > 2)
1797 sscanf(argv[2], "%x", &access_mask);
1799 /* Get sam policy handle */
1801 result = rpccli_try_samr_connects(cli, mem_ctx,
1802 MAXIMUM_ALLOWED_ACCESS,
1803 &connect_pol);
1805 if (!NT_STATUS_IS_OK(result))
1806 goto done;
1808 /* Get domain policy handle */
1810 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1811 &connect_pol,
1812 access_mask,
1813 &domain_sid,
1814 &domain_pol);
1816 if (!NT_STATUS_IS_OK(result))
1817 goto done;
1819 /* Create domain user */
1821 result = rpccli_samr_CreateDomAlias(cli, mem_ctx,
1822 &domain_pol,
1823 &alias_name,
1824 MAXIMUM_ALLOWED_ACCESS,
1825 &alias_pol,
1826 &rid);
1828 if (!NT_STATUS_IS_OK(result))
1829 goto done;
1831 result = rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1832 if (!NT_STATUS_IS_OK(result)) goto done;
1834 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1835 if (!NT_STATUS_IS_OK(result)) goto done;
1837 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1838 if (!NT_STATUS_IS_OK(result)) goto done;
1840 done:
1841 return result;
1844 /* Lookup sam names */
1846 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
1847 TALLOC_CTX *mem_ctx,
1848 int argc, const char **argv)
1850 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1851 struct policy_handle connect_pol, domain_pol;
1852 uint32 num_names;
1853 struct samr_Ids rids, name_types;
1854 int i;
1855 struct lsa_String *names = NULL;;
1857 if (argc < 3) {
1858 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1859 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1860 printf("or check on the builtin SID: S-1-5-32\n");
1861 return NT_STATUS_OK;
1864 /* Get sam policy and domain handles */
1866 result = rpccli_try_samr_connects(cli, mem_ctx,
1867 MAXIMUM_ALLOWED_ACCESS,
1868 &connect_pol);
1870 if (!NT_STATUS_IS_OK(result))
1871 goto done;
1873 result = get_domain_handle(cli, mem_ctx, argv[1],
1874 &connect_pol,
1875 MAXIMUM_ALLOWED_ACCESS,
1876 &domain_sid,
1877 &domain_pol);
1879 if (!NT_STATUS_IS_OK(result))
1880 goto done;
1882 /* Look up names */
1884 num_names = argc - 2;
1886 if ((names = TALLOC_ARRAY(mem_ctx, struct lsa_String, num_names)) == NULL) {
1887 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1888 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1889 result = NT_STATUS_NO_MEMORY;
1890 goto done;
1893 for (i = 0; i < num_names; i++) {
1894 init_lsa_String(&names[i], argv[i + 2]);
1897 result = rpccli_samr_LookupNames(cli, mem_ctx,
1898 &domain_pol,
1899 num_names,
1900 names,
1901 &rids,
1902 &name_types);
1904 if (!NT_STATUS_IS_OK(result))
1905 goto done;
1907 /* Display results */
1909 for (i = 0; i < num_names; i++)
1910 printf("name %s: 0x%x (%d)\n", names[i].string, rids.ids[i],
1911 name_types.ids[i]);
1913 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1914 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1915 done:
1916 return result;
1919 /* Lookup sam rids */
1921 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
1922 TALLOC_CTX *mem_ctx,
1923 int argc, const char **argv)
1925 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1926 struct policy_handle connect_pol, domain_pol;
1927 uint32_t num_rids, *rids;
1928 struct lsa_Strings names;
1929 struct samr_Ids types;
1931 int i;
1933 if (argc < 3) {
1934 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
1935 return NT_STATUS_OK;
1938 /* Get sam policy and domain handles */
1940 result = rpccli_try_samr_connects(cli, mem_ctx,
1941 MAXIMUM_ALLOWED_ACCESS,
1942 &connect_pol);
1944 if (!NT_STATUS_IS_OK(result))
1945 goto done;
1947 result = get_domain_handle(cli, mem_ctx, argv[1],
1948 &connect_pol,
1949 MAXIMUM_ALLOWED_ACCESS,
1950 &domain_sid,
1951 &domain_pol);
1953 if (!NT_STATUS_IS_OK(result))
1954 goto done;
1956 /* Look up rids */
1958 num_rids = argc - 2;
1960 if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
1961 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1962 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1963 result = NT_STATUS_NO_MEMORY;
1964 goto done;
1967 for (i = 0; i < argc - 2; i++)
1968 sscanf(argv[i + 2], "%i", &rids[i]);
1970 result = rpccli_samr_LookupRids(cli, mem_ctx,
1971 &domain_pol,
1972 num_rids,
1973 rids,
1974 &names,
1975 &types);
1977 if (!NT_STATUS_IS_OK(result) &&
1978 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1979 goto done;
1981 /* Display results */
1983 for (i = 0; i < num_rids; i++) {
1984 printf("rid 0x%x: %s (%d)\n",
1985 rids[i], names.names[i].string, types.ids[i]);
1988 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1989 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1990 done:
1991 return result;
1994 /* Delete domain group */
1996 static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
1997 TALLOC_CTX *mem_ctx,
1998 int argc, const char **argv)
2000 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2001 struct policy_handle connect_pol, domain_pol, group_pol;
2002 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2004 if ((argc < 2) || (argc > 3)) {
2005 printf("Usage: %s groupname\n", argv[0]);
2006 return NT_STATUS_OK;
2009 if (argc > 2)
2010 sscanf(argv[2], "%x", &access_mask);
2012 /* Get sam policy and domain handles */
2014 result = rpccli_try_samr_connects(cli, mem_ctx,
2015 MAXIMUM_ALLOWED_ACCESS,
2016 &connect_pol);
2018 if (!NT_STATUS_IS_OK(result))
2019 goto done;
2021 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2022 &connect_pol,
2023 MAXIMUM_ALLOWED_ACCESS,
2024 &domain_sid,
2025 &domain_pol);
2027 if (!NT_STATUS_IS_OK(result))
2028 goto done;
2030 /* Get handle on group */
2033 struct samr_Ids group_rids, name_types;
2034 struct lsa_String lsa_acct_name;
2036 init_lsa_String(&lsa_acct_name, argv[1]);
2038 result = rpccli_samr_LookupNames(cli, mem_ctx,
2039 &domain_pol,
2041 &lsa_acct_name,
2042 &group_rids,
2043 &name_types);
2044 if (!NT_STATUS_IS_OK(result))
2045 goto done;
2047 result = rpccli_samr_OpenGroup(cli, mem_ctx,
2048 &domain_pol,
2049 access_mask,
2050 group_rids.ids[0],
2051 &group_pol);
2053 if (!NT_STATUS_IS_OK(result))
2054 goto done;
2057 /* Delete group */
2059 result = rpccli_samr_DeleteDomainGroup(cli, mem_ctx,
2060 &group_pol);
2062 if (!NT_STATUS_IS_OK(result))
2063 goto done;
2065 /* Display results */
2067 rpccli_samr_Close(cli, mem_ctx, &group_pol);
2068 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2069 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2071 done:
2072 return result;
2075 /* Delete domain user */
2077 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
2078 TALLOC_CTX *mem_ctx,
2079 int argc, const char **argv)
2081 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2082 struct policy_handle connect_pol, domain_pol, user_pol;
2083 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2085 if ((argc < 2) || (argc > 3)) {
2086 printf("Usage: %s username\n", argv[0]);
2087 return NT_STATUS_OK;
2090 if (argc > 2)
2091 sscanf(argv[2], "%x", &access_mask);
2093 /* Get sam policy and domain handles */
2095 result = rpccli_try_samr_connects(cli, mem_ctx,
2096 MAXIMUM_ALLOWED_ACCESS,
2097 &connect_pol);
2099 if (!NT_STATUS_IS_OK(result))
2100 goto done;
2102 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2103 &connect_pol,
2104 MAXIMUM_ALLOWED_ACCESS,
2105 &domain_sid,
2106 &domain_pol);
2108 if (!NT_STATUS_IS_OK(result))
2109 goto done;
2111 /* Get handle on user */
2114 struct samr_Ids user_rids, name_types;
2115 struct lsa_String lsa_acct_name;
2117 init_lsa_String(&lsa_acct_name, argv[1]);
2119 result = rpccli_samr_LookupNames(cli, mem_ctx,
2120 &domain_pol,
2122 &lsa_acct_name,
2123 &user_rids,
2124 &name_types);
2126 if (!NT_STATUS_IS_OK(result))
2127 goto done;
2129 result = rpccli_samr_OpenUser(cli, mem_ctx,
2130 &domain_pol,
2131 access_mask,
2132 user_rids.ids[0],
2133 &user_pol);
2135 if (!NT_STATUS_IS_OK(result))
2136 goto done;
2139 /* Delete user */
2141 result = rpccli_samr_DeleteUser(cli, mem_ctx,
2142 &user_pol);
2144 if (!NT_STATUS_IS_OK(result))
2145 goto done;
2147 /* Display results */
2149 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2150 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2151 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2153 done:
2154 return result;
2157 /**********************************************************************
2158 * Query user security object
2160 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
2161 TALLOC_CTX *mem_ctx,
2162 int argc, const char **argv)
2164 struct policy_handle connect_pol, domain_pol, user_pol, *pol;
2165 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2166 uint32 sec_info = SECINFO_DACL;
2167 uint32 user_rid = 0;
2168 TALLOC_CTX *ctx = NULL;
2169 struct sec_desc_buf *sec_desc_buf=NULL;
2170 bool domain = False;
2172 ctx=talloc_init("cmd_samr_query_sec_obj");
2174 if ((argc < 1) || (argc > 3)) {
2175 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
2176 printf("\tSpecify rid for security on user, -d for security on domain\n");
2177 talloc_destroy(ctx);
2178 return NT_STATUS_OK;
2181 if (argc > 1) {
2182 if (strcmp(argv[1], "-d") == 0)
2183 domain = True;
2184 else
2185 sscanf(argv[1], "%i", &user_rid);
2188 if (argc == 3) {
2189 sec_info = atoi(argv[2]);
2192 result = rpccli_try_samr_connects(cli, mem_ctx,
2193 MAXIMUM_ALLOWED_ACCESS,
2194 &connect_pol);
2196 if (!NT_STATUS_IS_OK(result))
2197 goto done;
2199 if (domain || user_rid)
2200 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2201 &connect_pol,
2202 MAXIMUM_ALLOWED_ACCESS,
2203 &domain_sid,
2204 &domain_pol);
2206 if (!NT_STATUS_IS_OK(result))
2207 goto done;
2209 if (user_rid)
2210 result = rpccli_samr_OpenUser(cli, mem_ctx,
2211 &domain_pol,
2212 MAXIMUM_ALLOWED_ACCESS,
2213 user_rid,
2214 &user_pol);
2216 if (!NT_STATUS_IS_OK(result))
2217 goto done;
2219 /* Pick which query pol to use */
2221 pol = &connect_pol;
2223 if (domain)
2224 pol = &domain_pol;
2226 if (user_rid)
2227 pol = &user_pol;
2229 /* Query SAM security object */
2231 result = rpccli_samr_QuerySecurity(cli, mem_ctx,
2232 pol,
2233 sec_info,
2234 &sec_desc_buf);
2236 if (!NT_STATUS_IS_OK(result))
2237 goto done;
2239 display_sec_desc(sec_desc_buf->sd);
2241 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2242 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2243 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2244 done:
2245 talloc_destroy(ctx);
2246 return result;
2249 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
2250 TALLOC_CTX *mem_ctx,
2251 int argc, const char **argv)
2253 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2254 struct policy_handle connect_pol, domain_pol, user_pol;
2255 struct samr_PwInfo info;
2256 uint32_t rid;
2258 if (argc != 2) {
2259 printf("Usage: %s rid\n", argv[0]);
2260 return NT_STATUS_OK;
2263 sscanf(argv[1], "%i", &rid);
2265 result = rpccli_try_samr_connects(cli, mem_ctx,
2266 MAXIMUM_ALLOWED_ACCESS,
2267 &connect_pol);
2269 if (!NT_STATUS_IS_OK(result)) {
2270 goto done;
2273 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2274 &connect_pol,
2275 MAXIMUM_ALLOWED_ACCESS,
2276 &domain_sid,
2277 &domain_pol);
2279 if (!NT_STATUS_IS_OK(result)) {
2280 goto done;
2283 result = rpccli_samr_OpenUser(cli, mem_ctx,
2284 &domain_pol,
2285 MAXIMUM_ALLOWED_ACCESS,
2286 rid,
2287 &user_pol);
2289 if (!NT_STATUS_IS_OK(result)) {
2290 goto done;
2293 result = rpccli_samr_GetUserPwInfo(cli, mem_ctx, &user_pol, &info);
2294 if (NT_STATUS_IS_OK(result)) {
2295 printf("min_password_length: %d\n", info.min_password_length);
2296 printf("%s\n",
2297 NDR_PRINT_STRUCT_STRING(mem_ctx,
2298 samr_PasswordProperties, &info.password_properties));
2301 done:
2302 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2303 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2304 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2306 return result;
2309 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
2310 TALLOC_CTX *mem_ctx,
2311 int argc, const char **argv)
2313 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2314 struct lsa_String domain_name;
2315 struct samr_PwInfo info;
2317 if (argc < 1 || argc > 3) {
2318 printf("Usage: %s <domain>\n", argv[0]);
2319 return NT_STATUS_OK;
2322 init_lsa_String(&domain_name, argv[1]);
2324 result = rpccli_samr_GetDomPwInfo(cli, mem_ctx, &domain_name, &info);
2326 if (NT_STATUS_IS_OK(result)) {
2327 printf("min_password_length: %d\n", info.min_password_length);
2328 display_password_properties(info.password_properties);
2331 return result;
2334 /* Look up domain name */
2336 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
2337 TALLOC_CTX *mem_ctx,
2338 int argc, const char **argv)
2340 struct policy_handle connect_pol, domain_pol;
2341 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2342 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2343 fstring sid_string;
2344 struct lsa_String domain_name;
2345 struct dom_sid *sid = NULL;
2347 if (argc != 2) {
2348 printf("Usage: %s domain_name\n", argv[0]);
2349 return NT_STATUS_OK;
2352 init_lsa_String(&domain_name, argv[1]);
2354 result = rpccli_try_samr_connects(cli, mem_ctx,
2355 access_mask,
2356 &connect_pol);
2358 if (!NT_STATUS_IS_OK(result))
2359 goto done;
2361 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2362 &connect_pol,
2363 access_mask,
2364 &domain_sid,
2365 &domain_pol);
2367 if (!NT_STATUS_IS_OK(result))
2368 goto done;
2370 result = rpccli_samr_LookupDomain(cli, mem_ctx,
2371 &connect_pol,
2372 &domain_name,
2373 &sid);
2375 if (NT_STATUS_IS_OK(result)) {
2376 sid_to_fstring(sid_string, sid);
2377 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2378 argv[1], sid_string);
2381 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2382 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2383 done:
2384 return result;
2387 /* Change user password */
2389 static NTSTATUS cmd_samr_chgpasswd(struct rpc_pipe_client *cli,
2390 TALLOC_CTX *mem_ctx,
2391 int argc, const char **argv)
2393 struct policy_handle connect_pol, domain_pol, user_pol;
2394 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2395 const char *user, *oldpass, *newpass;
2396 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2397 struct samr_Ids rids, types;
2398 struct lsa_String lsa_acct_name;
2400 if (argc < 3) {
2401 printf("Usage: %s username oldpass newpass\n", argv[0]);
2402 return NT_STATUS_INVALID_PARAMETER;
2405 user = argv[1];
2406 oldpass = argv[2];
2407 newpass = argv[3];
2409 /* Get sam policy handle */
2411 result = rpccli_try_samr_connects(cli, mem_ctx,
2412 MAXIMUM_ALLOWED_ACCESS,
2413 &connect_pol);
2415 if (!NT_STATUS_IS_OK(result)) {
2416 goto done;
2419 /* Get domain policy handle */
2421 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2422 &connect_pol,
2423 access_mask,
2424 &domain_sid,
2425 &domain_pol);
2427 if (!NT_STATUS_IS_OK(result)) {
2428 goto done;
2431 init_lsa_String(&lsa_acct_name, user);
2433 result = rpccli_samr_LookupNames(cli, mem_ctx,
2434 &domain_pol,
2436 &lsa_acct_name,
2437 &rids,
2438 &types);
2440 if (!NT_STATUS_IS_OK(result)) {
2441 goto done;
2444 result = rpccli_samr_OpenUser(cli, mem_ctx,
2445 &domain_pol,
2446 access_mask,
2447 rids.ids[0],
2448 &user_pol);
2450 if (!NT_STATUS_IS_OK(result)) {
2451 goto done;
2454 /* Change user password */
2455 result = rpccli_samr_chgpasswd_user(cli, mem_ctx,
2456 &user_pol,
2457 newpass,
2458 oldpass);
2460 if (!NT_STATUS_IS_OK(result)) {
2461 goto done;
2464 done:
2465 if (is_valid_policy_hnd(&user_pol)) {
2466 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2468 if (is_valid_policy_hnd(&domain_pol)) {
2469 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2471 if (is_valid_policy_hnd(&connect_pol)) {
2472 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2475 return result;
2479 /* Change user password */
2481 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
2482 TALLOC_CTX *mem_ctx,
2483 int argc, const char **argv)
2485 struct policy_handle connect_pol, domain_pol;
2486 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2487 const char *user, *oldpass, *newpass;
2488 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2490 if (argc < 3) {
2491 printf("Usage: %s username oldpass newpass\n", argv[0]);
2492 return NT_STATUS_INVALID_PARAMETER;
2495 user = argv[1];
2496 oldpass = argv[2];
2497 newpass = argv[3];
2499 /* Get sam policy handle */
2501 result = rpccli_try_samr_connects(cli, mem_ctx,
2502 MAXIMUM_ALLOWED_ACCESS,
2503 &connect_pol);
2505 if (!NT_STATUS_IS_OK(result))
2506 goto done;
2508 /* Get domain policy handle */
2510 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2511 &connect_pol,
2512 access_mask,
2513 &domain_sid,
2514 &domain_pol);
2516 if (!NT_STATUS_IS_OK(result))
2517 goto done;
2519 /* Change user password */
2520 result = rpccli_samr_chgpasswd_user2(cli, mem_ctx, user, newpass, oldpass);
2522 if (!NT_STATUS_IS_OK(result))
2523 goto done;
2525 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2526 if (!NT_STATUS_IS_OK(result)) goto done;
2528 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2529 if (!NT_STATUS_IS_OK(result)) goto done;
2531 done:
2532 return result;
2536 /* Change user password */
2538 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
2539 TALLOC_CTX *mem_ctx,
2540 int argc, const char **argv)
2542 struct policy_handle connect_pol, domain_pol;
2543 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2544 const char *user, *oldpass, *newpass;
2545 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2546 struct samr_DomInfo1 *info = NULL;
2547 struct userPwdChangeFailureInformation *reject = NULL;
2549 if (argc < 3) {
2550 printf("Usage: %s username oldpass newpass\n", argv[0]);
2551 return NT_STATUS_INVALID_PARAMETER;
2554 user = argv[1];
2555 oldpass = argv[2];
2556 newpass = argv[3];
2558 /* Get sam policy handle */
2560 result = rpccli_try_samr_connects(cli, mem_ctx,
2561 MAXIMUM_ALLOWED_ACCESS,
2562 &connect_pol);
2564 if (!NT_STATUS_IS_OK(result))
2565 goto done;
2567 /* Get domain policy handle */
2569 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2570 &connect_pol,
2571 access_mask,
2572 &domain_sid,
2573 &domain_pol);
2575 if (!NT_STATUS_IS_OK(result))
2576 goto done;
2578 /* Change user password */
2579 result = rpccli_samr_chgpasswd_user3(cli, mem_ctx,
2580 user,
2581 newpass,
2582 oldpass,
2583 &info,
2584 &reject);
2586 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
2588 display_sam_dom_info_1(info);
2590 switch (reject->extendedFailureReason) {
2591 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT:
2592 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2593 break;
2594 case SAM_PWD_CHANGE_PWD_IN_HISTORY:
2595 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2596 break;
2597 case SAM_PWD_CHANGE_NOT_COMPLEX:
2598 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2599 break;
2600 default:
2601 d_printf("unknown reject reason: %d\n",
2602 reject->extendedFailureReason);
2603 break;
2607 if (!NT_STATUS_IS_OK(result))
2608 goto done;
2610 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2611 if (!NT_STATUS_IS_OK(result)) goto done;
2613 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2614 if (!NT_STATUS_IS_OK(result)) goto done;
2616 done:
2617 return result;
2620 static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
2621 TALLOC_CTX *mem_ctx,
2622 int argc, const char **argv,
2623 int opcode)
2625 struct policy_handle connect_pol, domain_pol, user_pol;
2626 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
2627 const char *user, *param;
2628 uint32_t access_mask = MAXIMUM_ALLOWED_ACCESS;
2629 uint32_t level;
2630 uint32_t user_rid;
2631 union samr_UserInfo info;
2632 struct samr_CryptPassword pwd_buf;
2633 struct samr_CryptPasswordEx pwd_buf_ex;
2634 uint8_t nt_hash[16];
2635 uint8_t lm_hash[16];
2636 DATA_BLOB session_key;
2637 uint8_t password_expired = 0;
2639 if (argc < 4) {
2640 printf("Usage: %s username level password [password_expired]\n",
2641 argv[0]);
2642 return NT_STATUS_INVALID_PARAMETER;
2645 user = argv[1];
2646 level = atoi(argv[2]);
2647 param = argv[3];
2649 if (argc >= 5) {
2650 password_expired = atoi(argv[4]);
2653 status = cli_get_session_key(mem_ctx, cli, &session_key);
2654 if (!NT_STATUS_IS_OK(status)) {
2655 return status;
2658 init_samr_CryptPassword(param, &session_key, &pwd_buf);
2659 init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
2660 nt_lm_owf_gen(param, nt_hash, lm_hash);
2662 switch (level) {
2663 case 18:
2665 DATA_BLOB in,out;
2666 in = data_blob_const(nt_hash, 16);
2667 out = data_blob_talloc_zero(mem_ctx, 16);
2668 sess_crypt_blob(&out, &in, &session_key, true);
2669 memcpy(nt_hash, out.data, out.length);
2672 DATA_BLOB in,out;
2673 in = data_blob_const(lm_hash, 16);
2674 out = data_blob_talloc_zero(mem_ctx, 16);
2675 sess_crypt_blob(&out, &in, &session_key, true);
2676 memcpy(lm_hash, out.data, out.length);
2679 memcpy(info.info18.nt_pwd.hash, nt_hash, 16);
2680 memcpy(info.info18.lm_pwd.hash, lm_hash, 16);
2681 info.info18.nt_pwd_active = true;
2682 info.info18.lm_pwd_active = true;
2683 info.info18.password_expired = password_expired;
2685 break;
2686 case 21:
2687 ZERO_STRUCT(info.info21);
2689 info.info21.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2690 SAMR_FIELD_LM_PASSWORD_PRESENT;
2691 if (argc >= 5) {
2692 info.info21.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2693 info.info21.password_expired = password_expired;
2696 info.info21.lm_password_set = true;
2697 info.info21.lm_owf_password.length = 16;
2698 info.info21.lm_owf_password.size = 16;
2700 info.info21.nt_password_set = true;
2701 info.info21.nt_owf_password.length = 16;
2702 info.info21.nt_owf_password.size = 16;
2705 DATA_BLOB in,out;
2706 in = data_blob_const(nt_hash, 16);
2707 out = data_blob_talloc_zero(mem_ctx, 16);
2708 sess_crypt_blob(&out, &in, &session_key, true);
2709 info.info21.nt_owf_password.array =
2710 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2713 DATA_BLOB in,out;
2714 in = data_blob_const(lm_hash, 16);
2715 out = data_blob_talloc_zero(mem_ctx, 16);
2716 sess_crypt_blob(&out, &in, &session_key, true);
2717 info.info21.lm_owf_password.array =
2718 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2721 break;
2722 case 23:
2723 ZERO_STRUCT(info.info23);
2725 info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2726 SAMR_FIELD_LM_PASSWORD_PRESENT;
2727 if (argc >= 5) {
2728 info.info23.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2729 info.info23.info.password_expired = password_expired;
2732 info.info23.password = pwd_buf;
2734 break;
2735 case 24:
2736 info.info24.password = pwd_buf;
2737 info.info24.password_expired = password_expired;
2739 break;
2740 case 25:
2741 ZERO_STRUCT(info.info25);
2743 info.info25.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2744 SAMR_FIELD_LM_PASSWORD_PRESENT;
2745 if (argc >= 5) {
2746 info.info25.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2747 info.info25.info.password_expired = password_expired;
2750 info.info25.password = pwd_buf_ex;
2752 break;
2753 case 26:
2754 info.info26.password = pwd_buf_ex;
2755 info.info26.password_expired = password_expired;
2757 break;
2758 default:
2759 return NT_STATUS_INVALID_INFO_CLASS;
2762 /* Get sam policy handle */
2764 status = rpccli_try_samr_connects(cli, mem_ctx,
2765 MAXIMUM_ALLOWED_ACCESS,
2766 &connect_pol);
2768 if (!NT_STATUS_IS_OK(status))
2769 goto done;
2771 /* Get domain policy handle */
2773 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2774 &connect_pol,
2775 access_mask,
2776 &domain_sid,
2777 &domain_pol);
2779 if (!NT_STATUS_IS_OK(status))
2780 goto done;
2782 user_rid = strtol(user, NULL, 0);
2783 if (user_rid) {
2784 status = rpccli_samr_OpenUser(cli, mem_ctx,
2785 &domain_pol,
2786 access_mask,
2787 user_rid,
2788 &user_pol);
2791 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER) ||
2792 (user_rid == 0)) {
2794 /* Probably this was a user name, try lookupnames */
2795 struct samr_Ids rids, types;
2796 struct lsa_String lsa_acct_name;
2798 init_lsa_String(&lsa_acct_name, user);
2800 status = rpccli_samr_LookupNames(cli, mem_ctx,
2801 &domain_pol,
2803 &lsa_acct_name,
2804 &rids,
2805 &types);
2806 if (!NT_STATUS_IS_OK(status)) {
2807 return status;
2810 status = rpccli_samr_OpenUser(cli, mem_ctx,
2811 &domain_pol,
2812 access_mask,
2813 rids.ids[0],
2814 &user_pol);
2815 if (!NT_STATUS_IS_OK(status)) {
2816 return status;
2820 switch (opcode) {
2821 case NDR_SAMR_SETUSERINFO:
2822 status = rpccli_samr_SetUserInfo(cli, mem_ctx,
2823 &user_pol,
2824 level,
2825 &info);
2826 break;
2827 case NDR_SAMR_SETUSERINFO2:
2828 status = rpccli_samr_SetUserInfo2(cli, mem_ctx,
2829 &user_pol,
2830 level,
2831 &info);
2832 break;
2833 default:
2834 return NT_STATUS_INVALID_PARAMETER;
2837 done:
2838 return status;
2841 static NTSTATUS cmd_samr_setuserinfo(struct rpc_pipe_client *cli,
2842 TALLOC_CTX *mem_ctx,
2843 int argc, const char **argv)
2845 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2846 NDR_SAMR_SETUSERINFO);
2849 static NTSTATUS cmd_samr_setuserinfo2(struct rpc_pipe_client *cli,
2850 TALLOC_CTX *mem_ctx,
2851 int argc, const char **argv)
2853 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2854 NDR_SAMR_SETUSERINFO2);
2857 static NTSTATUS cmd_samr_get_dispinfo_idx(struct rpc_pipe_client *cli,
2858 TALLOC_CTX *mem_ctx,
2859 int argc, const char **argv)
2861 NTSTATUS status;
2862 struct policy_handle connect_handle;
2863 struct policy_handle domain_handle;
2864 uint16_t level = 1;
2865 struct lsa_String name;
2866 uint32_t idx = 0;
2868 if (argc < 2 || argc > 3) {
2869 printf("Usage: %s name level\n", argv[0]);
2870 return NT_STATUS_INVALID_PARAMETER;
2873 init_lsa_String(&name, argv[1]);
2875 if (argc == 3) {
2876 level = atoi(argv[2]);
2879 status = rpccli_try_samr_connects(cli, mem_ctx,
2880 SEC_FLAG_MAXIMUM_ALLOWED,
2881 &connect_handle);
2883 if (!NT_STATUS_IS_OK(status)) {
2884 goto done;
2887 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2888 &connect_handle,
2889 SEC_FLAG_MAXIMUM_ALLOWED,
2890 &domain_sid,
2891 &domain_handle);
2893 if (!NT_STATUS_IS_OK(status))
2894 goto done;
2897 status = rpccli_samr_GetDisplayEnumerationIndex(cli, mem_ctx,
2898 &domain_handle,
2899 level,
2900 &name,
2901 &idx);
2903 if (NT_STATUS_IS_OK(status) ||
2904 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
2905 printf("idx: %d (0x%08x)\n", idx, idx);
2907 done:
2909 if (is_valid_policy_hnd(&domain_handle)) {
2910 rpccli_samr_Close(cli, mem_ctx, &domain_handle);
2912 if (is_valid_policy_hnd(&connect_handle)) {
2913 rpccli_samr_Close(cli, mem_ctx, &connect_handle);
2916 return status;
2919 /* List of commands exported by this module */
2921 struct cmd_set samr_commands[] = {
2923 { "SAMR" },
2925 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, &ndr_table_samr.syntax_id, NULL, "Query user info", "" },
2926 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, &ndr_table_samr.syntax_id, NULL, "Query group info", "" },
2927 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, &ndr_table_samr.syntax_id, NULL, "Query user groups", "" },
2928 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, &ndr_table_samr.syntax_id, NULL, "Query user aliases", "" },
2929 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query group membership", "" },
2930 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias membership", "" },
2931 { "queryaliasinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias info", "" },
2932 { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Delete an alias", "" },
2933 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2934 { "querydispinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2935 { "querydispinfo3", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2936 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query domain info", "" },
2937 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain users", "" },
2938 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain groups", "" },
2939 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate alias groups", "" },
2940 { "enumdomains", RPC_RTYPE_NTSTATUS, cmd_samr_enum_domains, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domains", "" },
2942 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain user", "" },
2943 { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain group", "" },
2944 { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain alias", "" },
2945 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2946 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2947 { "deletedomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain group", "" },
2948 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain user", "" },
2949 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, &ndr_table_samr.syntax_id, NULL, "Query SAMR security object", "" },
2950 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve domain password info", "" },
2951 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve user domain password info", "" },
2953 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, &ndr_table_samr.syntax_id, NULL, "Lookup Domain Name", "" },
2954 { "chgpasswd", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2955 { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2956 { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2957 { "getdispinfoidx", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispinfo_idx, NULL, &ndr_table_samr.syntax_id, NULL, "Get Display Information Index", "" },
2958 { "setuserinfo", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info", "" },
2959 { "setuserinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info2", "" },
2960 { NULL }