s4:registry - "LDB backend" - don't test for "0" as string termination on binary...
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_samr.c
blobe21a57fba7a3137cf9693d7bbda265d25862fd29
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/cli_samr.h"
30 extern DOM_SID domain_sid;
32 /****************************************************************************
33 display samr_user_info_7 structure
34 ****************************************************************************/
35 static void display_samr_user_info_7(struct samr_UserInfo7 *r)
37 printf("\tUser Name :\t%s\n", r->account_name.string);
40 /****************************************************************************
41 display samr_user_info_9 structure
42 ****************************************************************************/
43 static void display_samr_user_info_9(struct samr_UserInfo9 *r)
45 printf("\tPrimary group RID :\tox%x\n", r->primary_gid);
48 /****************************************************************************
49 display samr_user_info_16 structure
50 ****************************************************************************/
51 static void display_samr_user_info_16(struct samr_UserInfo16 *r)
53 printf("\tAcct Flags :\tox%x\n", r->acct_flags);
56 /****************************************************************************
57 display samr_user_info_20 structure
58 ****************************************************************************/
59 static void display_samr_user_info_20(struct samr_UserInfo20 *r)
61 printf("\tRemote Dial :\n");
62 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
66 /****************************************************************************
67 display samr_user_info_21 structure
68 ****************************************************************************/
69 static void display_samr_user_info_21(struct samr_UserInfo21 *r)
71 printf("\tUser Name :\t%s\n", r->account_name.string);
72 printf("\tFull Name :\t%s\n", r->full_name.string);
73 printf("\tHome Drive :\t%s\n", r->home_directory.string);
74 printf("\tDir Drive :\t%s\n", r->home_drive.string);
75 printf("\tProfile Path:\t%s\n", r->profile_path.string);
76 printf("\tLogon Script:\t%s\n", r->logon_script.string);
77 printf("\tDescription :\t%s\n", r->description.string);
78 printf("\tWorkstations:\t%s\n", r->workstations.string);
79 printf("\tComment :\t%s\n", r->comment.string);
80 printf("\tRemote Dial :\n");
81 dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
83 printf("\tLogon Time :\t%s\n",
84 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logon)));
85 printf("\tLogoff Time :\t%s\n",
86 http_timestring(talloc_tos(), nt_time_to_unix(r->last_logoff)));
87 printf("\tKickoff Time :\t%s\n",
88 http_timestring(talloc_tos(), nt_time_to_unix(r->acct_expiry)));
89 printf("\tPassword last set Time :\t%s\n",
90 http_timestring(talloc_tos(), nt_time_to_unix(r->last_password_change)));
91 printf("\tPassword can change Time :\t%s\n",
92 http_timestring(talloc_tos(), nt_time_to_unix(r->allow_password_change)));
93 printf("\tPassword must change Time:\t%s\n",
94 http_timestring(talloc_tos(), nt_time_to_unix(r->force_password_change)));
96 printf("\tunknown_2[0..31]...\n"); /* user passwords? */
98 printf("\tuser_rid :\t0x%x\n" , r->rid); /* User ID */
99 printf("\tgroup_rid:\t0x%x\n" , r->primary_gid); /* Group ID */
100 printf("\tacb_info :\t0x%08x\n", r->acct_flags); /* Account Control Info */
102 printf("\tfields_present:\t0x%08x\n", r->fields_present); /* 0x00ff ffff */
103 printf("\tlogon_divs:\t%d\n", r->logon_hours.units_per_week); /* 0x0000 00a8 which is 168 which is num hrs in a week */
104 printf("\tbad_password_count:\t0x%08x\n", r->bad_password_count);
105 printf("\tlogon_count:\t0x%08x\n", r->logon_count);
107 printf("\tpadding1[0..7]...\n");
109 if (r->logon_hours.bits) {
110 printf("\tlogon_hrs[0..%d]...\n", r->logon_hours.units_per_week/8);
115 static void display_password_properties(uint32_t password_properties)
117 printf("password_properties: 0x%08x\n", password_properties);
119 if (password_properties & DOMAIN_PASSWORD_COMPLEX)
120 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
122 if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
123 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
125 if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
126 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
128 if (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)
129 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
131 if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
132 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
134 if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
135 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
138 static void display_sam_dom_info_1(struct samr_DomInfo1 *info1)
140 printf("Minimum password length:\t\t\t%d\n",
141 info1->min_password_length);
142 printf("Password uniqueness (remember x passwords):\t%d\n",
143 info1->password_history_length);
144 display_password_properties(info1->password_properties);
145 printf("password expire in:\t\t\t\t%s\n",
146 display_time(info1->max_password_age));
147 printf("Min password age (allow changing in x days):\t%s\n",
148 display_time(info1->min_password_age));
151 static void display_sam_dom_info_2(struct samr_DomGeneralInformation *general)
153 printf("Domain:\t\t%s\n", general->domain_name.string);
154 printf("Server:\t\t%s\n", general->primary.string);
155 printf("Comment:\t%s\n", general->oem_information.string);
157 printf("Total Users:\t%d\n", general->num_users);
158 printf("Total Groups:\t%d\n", general->num_groups);
159 printf("Total Aliases:\t%d\n", general->num_aliases);
161 printf("Sequence No:\t%llu\n", (unsigned long long)general->sequence_num);
163 printf("Force Logoff:\t%d\n",
164 (int)nt_time_to_unix_abs(&general->force_logoff_time));
166 printf("Domain Server State:\t0x%x\n", general->domain_server_state);
167 printf("Server Role:\t%s\n", server_role_str(general->role));
168 printf("Unknown 3:\t0x%x\n", general->unknown3);
171 static void display_sam_dom_info_3(struct samr_DomInfo3 *info3)
173 printf("Force Logoff:\t%d\n",
174 (int)nt_time_to_unix_abs(&info3->force_logoff_time));
177 static void display_sam_dom_info_4(struct samr_DomOEMInformation *oem)
179 printf("Comment:\t%s\n", oem->oem_information.string);
182 static void display_sam_dom_info_5(struct samr_DomInfo5 *info5)
184 printf("Domain:\t\t%s\n", info5->domain_name.string);
187 static void display_sam_dom_info_6(struct samr_DomInfo6 *info6)
189 printf("Server:\t\t%s\n", info6->primary.string);
192 static void display_sam_dom_info_7(struct samr_DomInfo7 *info7)
194 printf("Server Role:\t%s\n", server_role_str(info7->role));
197 static void display_sam_dom_info_8(struct samr_DomInfo8 *info8)
199 printf("Sequence No:\t%llu\n", (unsigned long long)info8->sequence_num);
200 printf("Domain Create Time:\t%s\n",
201 http_timestring(talloc_tos(), nt_time_to_unix(info8->domain_create_time)));
204 static void display_sam_dom_info_9(struct samr_DomInfo9 *info9)
206 printf("Domain Server State:\t0x%x\n", info9->domain_server_state);
209 static void display_sam_dom_info_12(struct samr_DomInfo12 *info12)
211 printf("Bad password lockout duration: %s\n",
212 display_time(info12->lockout_duration));
213 printf("Reset Lockout after: %s\n",
214 display_time(info12->lockout_window));
215 printf("Lockout after bad attempts: %d\n",
216 info12->lockout_threshold);
219 static void display_sam_dom_info_13(struct samr_DomInfo13 *info13)
221 printf("Sequence No:\t%llu\n", (unsigned long long)info13->sequence_num);
222 printf("Domain Create Time:\t%s\n",
223 http_timestring(talloc_tos(), nt_time_to_unix(info13->domain_create_time)));
224 printf("Sequence No at last promotion:\t%llu\n",
225 (unsigned long long)info13->modified_count_at_last_promotion);
228 static void display_sam_info_1(struct samr_DispEntryGeneral *r)
230 printf("index: 0x%x ", r->idx);
231 printf("RID: 0x%x ", r->rid);
232 printf("acb: 0x%08x ", r->acct_flags);
233 printf("Account: %s\t", r->account_name.string);
234 printf("Name: %s\t", r->full_name.string);
235 printf("Desc: %s\n", r->description.string);
238 static void display_sam_info_2(struct samr_DispEntryFull *r)
240 printf("index: 0x%x ", r->idx);
241 printf("RID: 0x%x ", r->rid);
242 printf("acb: 0x%08x ", r->acct_flags);
243 printf("Account: %s\t", r->account_name.string);
244 printf("Desc: %s\n", r->description.string);
247 static void display_sam_info_3(struct samr_DispEntryFullGroup *r)
249 printf("index: 0x%x ", r->idx);
250 printf("RID: 0x%x ", r->rid);
251 printf("acb: 0x%08x ", r->acct_flags);
252 printf("Account: %s\t", r->account_name.string);
253 printf("Desc: %s\n", r->description.string);
256 static void display_sam_info_4(struct samr_DispEntryAscii *r)
258 printf("index: 0x%x ", r->idx);
259 printf("Account: %s\n", r->account_name.string);
262 static void display_sam_info_5(struct samr_DispEntryAscii *r)
264 printf("index: 0x%x ", r->idx);
265 printf("Account: %s\n", r->account_name.string);
268 /****************************************************************************
269 ****************************************************************************/
271 static NTSTATUS get_domain_handle(struct rpc_pipe_client *cli,
272 TALLOC_CTX *mem_ctx,
273 const char *sam,
274 struct policy_handle *connect_pol,
275 uint32_t access_mask,
276 struct dom_sid *_domain_sid,
277 struct policy_handle *domain_pol)
280 if (StrCaseCmp(sam, "domain") == 0) {
281 return rpccli_samr_OpenDomain(cli, mem_ctx,
282 connect_pol,
283 access_mask,
284 _domain_sid,
285 domain_pol);
286 } else if (StrCaseCmp(sam, "builtin") == 0) {
287 return rpccli_samr_OpenDomain(cli, mem_ctx,
288 connect_pol,
289 access_mask,
290 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
291 domain_pol);
294 return NT_STATUS_INVALID_PARAMETER;
297 /**********************************************************************
298 * Query user information
300 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
301 TALLOC_CTX *mem_ctx,
302 int argc, const char **argv)
304 struct policy_handle connect_pol, domain_pol, user_pol;
305 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
306 uint32 info_level = 21;
307 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
308 union samr_UserInfo *info = NULL;
309 uint32 user_rid = 0;
311 if ((argc < 2) || (argc > 4)) {
312 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
313 return NT_STATUS_OK;
316 sscanf(argv[1], "%i", &user_rid);
318 if (argc > 2)
319 sscanf(argv[2], "%i", &info_level);
321 if (argc > 3)
322 sscanf(argv[3], "%x", &access_mask);
325 result = rpccli_try_samr_connects(cli, mem_ctx,
326 MAXIMUM_ALLOWED_ACCESS,
327 &connect_pol);
329 if (!NT_STATUS_IS_OK(result))
330 goto done;
332 result = rpccli_samr_OpenDomain(cli, mem_ctx,
333 &connect_pol,
334 MAXIMUM_ALLOWED_ACCESS,
335 &domain_sid,
336 &domain_pol);
337 if (!NT_STATUS_IS_OK(result))
338 goto done;
340 result = rpccli_samr_OpenUser(cli, mem_ctx,
341 &domain_pol,
342 access_mask,
343 user_rid,
344 &user_pol);
346 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
347 (user_rid == 0)) {
349 /* Probably this was a user name, try lookupnames */
350 struct samr_Ids rids, types;
351 struct lsa_String lsa_acct_name;
353 init_lsa_String(&lsa_acct_name, argv[1]);
355 result = rpccli_samr_LookupNames(cli, mem_ctx,
356 &domain_pol,
358 &lsa_acct_name,
359 &rids,
360 &types);
362 if (NT_STATUS_IS_OK(result)) {
363 result = rpccli_samr_OpenUser(cli, mem_ctx,
364 &domain_pol,
365 access_mask,
366 rids.ids[0],
367 &user_pol);
372 if (!NT_STATUS_IS_OK(result))
373 goto done;
375 result = rpccli_samr_QueryUserInfo(cli, mem_ctx,
376 &user_pol,
377 info_level,
378 &info);
380 if (!NT_STATUS_IS_OK(result))
381 goto done;
383 switch (info_level) {
384 case 7:
385 display_samr_user_info_7(&info->info7);
386 break;
387 case 9:
388 display_samr_user_info_9(&info->info9);
389 break;
390 case 16:
391 display_samr_user_info_16(&info->info16);
392 break;
393 case 20:
394 display_samr_user_info_20(&info->info20);
395 break;
396 case 21:
397 display_samr_user_info_21(&info->info21);
398 break;
399 default:
400 printf("Unsupported infolevel: %d\n", info_level);
401 break;
404 rpccli_samr_Close(cli, mem_ctx, &user_pol);
405 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
406 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
408 done:
409 return result;
412 /****************************************************************************
413 display group info
414 ****************************************************************************/
415 static void display_group_info1(struct samr_GroupInfoAll *info1)
417 printf("\tGroup Name:\t%s\n", info1->name.string);
418 printf("\tDescription:\t%s\n", info1->description.string);
419 printf("\tGroup Attribute:%d\n", info1->attributes);
420 printf("\tNum Members:%d\n", info1->num_members);
423 /****************************************************************************
424 display group info
425 ****************************************************************************/
426 static void display_group_info2(struct lsa_String *info2)
428 printf("\tGroup Description:%s\n", info2->string);
432 /****************************************************************************
433 display group info
434 ****************************************************************************/
435 static void display_group_info3(struct samr_GroupInfoAttributes *info3)
437 printf("\tGroup Attribute:%d\n", info3->attributes);
441 /****************************************************************************
442 display group info
443 ****************************************************************************/
444 static void display_group_info4(struct lsa_String *info4)
446 printf("\tGroup Description:%s\n", info4->string);
449 /****************************************************************************
450 display group info
451 ****************************************************************************/
452 static void display_group_info5(struct samr_GroupInfoAll *info5)
454 printf("\tGroup Name:\t%s\n", info5->name.string);
455 printf("\tDescription:\t%s\n", info5->description.string);
456 printf("\tGroup Attribute:%d\n", info5->attributes);
457 printf("\tNum Members:%d\n", info5->num_members);
460 /****************************************************************************
461 display sam sync structure
462 ****************************************************************************/
463 static void display_group_info(union samr_GroupInfo *info,
464 enum samr_GroupInfoEnum level)
466 switch (level) {
467 case 1:
468 display_group_info1(&info->all);
469 break;
470 case 2:
471 display_group_info2(&info->name);
472 break;
473 case 3:
474 display_group_info3(&info->attributes);
475 break;
476 case 4:
477 display_group_info4(&info->description);
478 break;
479 case 5:
480 display_group_info5(&info->all2);
481 break;
485 /***********************************************************************
486 * Query group information
488 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
489 TALLOC_CTX *mem_ctx,
490 int argc, const char **argv)
492 struct policy_handle connect_pol, domain_pol, group_pol;
493 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
494 enum samr_GroupInfoEnum info_level = GROUPINFOALL;
495 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
496 union samr_GroupInfo *group_info = NULL;
497 uint32 group_rid;
499 if ((argc < 2) || (argc > 4)) {
500 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
501 return NT_STATUS_OK;
504 sscanf(argv[1], "%i", &group_rid);
506 if (argc > 2)
507 info_level = atoi(argv[2]);
509 if (argc > 3)
510 sscanf(argv[3], "%x", &access_mask);
512 result = rpccli_try_samr_connects(cli, mem_ctx,
513 MAXIMUM_ALLOWED_ACCESS,
514 &connect_pol);
516 if (!NT_STATUS_IS_OK(result))
517 goto done;
519 result = rpccli_samr_OpenDomain(cli, mem_ctx,
520 &connect_pol,
521 MAXIMUM_ALLOWED_ACCESS,
522 &domain_sid,
523 &domain_pol);
525 if (!NT_STATUS_IS_OK(result))
526 goto done;
528 result = rpccli_samr_OpenGroup(cli, mem_ctx,
529 &domain_pol,
530 access_mask,
531 group_rid,
532 &group_pol);
534 if (!NT_STATUS_IS_OK(result))
535 goto done;
537 result = rpccli_samr_QueryGroupInfo(cli, mem_ctx,
538 &group_pol,
539 info_level,
540 &group_info);
541 if (!NT_STATUS_IS_OK(result)) {
542 goto done;
545 display_group_info(group_info, info_level);
547 rpccli_samr_Close(cli, mem_ctx, &group_pol);
548 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
549 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
550 done:
551 return result;
554 /* Query groups a user is a member of */
556 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
557 TALLOC_CTX *mem_ctx,
558 int argc, const char **argv)
560 struct policy_handle connect_pol,
561 domain_pol,
562 user_pol;
563 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
564 uint32 user_rid;
565 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
566 int i;
567 struct samr_RidWithAttributeArray *rid_array = NULL;
569 if ((argc < 2) || (argc > 3)) {
570 printf("Usage: %s rid [access mask]\n", argv[0]);
571 return NT_STATUS_OK;
574 sscanf(argv[1], "%i", &user_rid);
576 if (argc > 2)
577 sscanf(argv[2], "%x", &access_mask);
579 result = rpccli_try_samr_connects(cli, mem_ctx,
580 MAXIMUM_ALLOWED_ACCESS,
581 &connect_pol);
583 if (!NT_STATUS_IS_OK(result))
584 goto done;
586 result = rpccli_samr_OpenDomain(cli, mem_ctx,
587 &connect_pol,
588 MAXIMUM_ALLOWED_ACCESS,
589 &domain_sid, &domain_pol);
591 if (!NT_STATUS_IS_OK(result))
592 goto done;
594 result = rpccli_samr_OpenUser(cli, mem_ctx,
595 &domain_pol,
596 access_mask,
597 user_rid,
598 &user_pol);
600 if (!NT_STATUS_IS_OK(result))
601 goto done;
603 result = rpccli_samr_GetGroupsForUser(cli, mem_ctx,
604 &user_pol,
605 &rid_array);
607 if (!NT_STATUS_IS_OK(result))
608 goto done;
610 for (i = 0; i < rid_array->count; i++) {
611 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
612 rid_array->rids[i].rid,
613 rid_array->rids[i].attributes);
616 rpccli_samr_Close(cli, mem_ctx, &user_pol);
617 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
618 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
619 done:
620 return result;
623 /* Query aliases a user is a member of */
625 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
626 TALLOC_CTX *mem_ctx,
627 int argc, const char **argv)
629 struct policy_handle connect_pol, domain_pol;
630 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
631 DOM_SID *sids;
632 size_t num_sids;
633 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
634 int i;
635 struct lsa_SidArray sid_array;
636 struct samr_Ids alias_rids;
638 if (argc < 3) {
639 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
640 return NT_STATUS_INVALID_PARAMETER;
643 sids = NULL;
644 num_sids = 0;
646 for (i=2; i<argc; i++) {
647 DOM_SID tmp_sid;
648 if (!string_to_sid(&tmp_sid, argv[i])) {
649 printf("%s is not a legal SID\n", argv[i]);
650 return NT_STATUS_INVALID_PARAMETER;
652 result = add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
653 if (!NT_STATUS_IS_OK(result)) {
654 return result;
658 if (num_sids) {
659 sid_array.sids = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_SidPtr, num_sids);
660 if (sid_array.sids == NULL)
661 return NT_STATUS_NO_MEMORY;
662 } else {
663 sid_array.sids = NULL;
666 for (i=0; i<num_sids; i++) {
667 sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sids[i]);
668 if (!sid_array.sids[i].sid) {
669 return NT_STATUS_NO_MEMORY;
673 sid_array.num_sids = num_sids;
675 result = rpccli_try_samr_connects(cli, mem_ctx,
676 MAXIMUM_ALLOWED_ACCESS,
677 &connect_pol);
679 if (!NT_STATUS_IS_OK(result))
680 goto done;
682 result = get_domain_handle(cli, mem_ctx, argv[1],
683 &connect_pol,
684 access_mask,
685 &domain_sid,
686 &domain_pol);
688 if (!NT_STATUS_IS_OK(result))
689 goto done;
691 result = rpccli_samr_GetAliasMembership(cli, mem_ctx,
692 &domain_pol,
693 &sid_array,
694 &alias_rids);
695 if (!NT_STATUS_IS_OK(result))
696 goto done;
698 for (i = 0; i < alias_rids.count; i++) {
699 printf("\tgroup rid:[0x%x]\n", alias_rids.ids[i]);
702 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
703 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
704 done:
705 return result;
708 /* Query members of a group */
710 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
711 TALLOC_CTX *mem_ctx,
712 int argc, const char **argv)
714 struct policy_handle connect_pol, domain_pol, group_pol;
715 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
716 uint32 group_rid;
717 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
718 int i;
719 unsigned int old_timeout;
720 struct samr_RidTypeArray *rids = NULL;
722 if ((argc < 2) || (argc > 3)) {
723 printf("Usage: %s rid [access mask]\n", argv[0]);
724 return NT_STATUS_OK;
727 sscanf(argv[1], "%i", &group_rid);
729 if (argc > 2)
730 sscanf(argv[2], "%x", &access_mask);
732 result = rpccli_try_samr_connects(cli, mem_ctx,
733 MAXIMUM_ALLOWED_ACCESS,
734 &connect_pol);
736 if (!NT_STATUS_IS_OK(result))
737 goto done;
739 result = rpccli_samr_OpenDomain(cli, mem_ctx,
740 &connect_pol,
741 MAXIMUM_ALLOWED_ACCESS,
742 &domain_sid,
743 &domain_pol);
745 if (!NT_STATUS_IS_OK(result))
746 goto done;
748 result = rpccli_samr_OpenGroup(cli, mem_ctx,
749 &domain_pol,
750 access_mask,
751 group_rid,
752 &group_pol);
754 if (!NT_STATUS_IS_OK(result))
755 goto done;
757 /* Make sure to wait for our DC's reply */
758 old_timeout = rpccli_set_timeout(cli, 30000); /* 30 seconds. */
759 rpccli_set_timeout(cli, MAX(30000, old_timeout)); /* At least 30 sec */
761 result = rpccli_samr_QueryGroupMember(cli, mem_ctx,
762 &group_pol,
763 &rids);
765 rpccli_set_timeout(cli, old_timeout);
767 if (!NT_STATUS_IS_OK(result))
768 goto done;
770 for (i = 0; i < rids->count; i++) {
771 printf("\trid:[0x%x] attr:[0x%x]\n", rids->rids[i],
772 rids->types[i]);
775 rpccli_samr_Close(cli, mem_ctx, &group_pol);
776 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
777 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
778 done:
779 return result;
782 /* Enumerate domain users */
784 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
785 TALLOC_CTX *mem_ctx,
786 int argc, const char **argv)
788 struct policy_handle connect_pol, domain_pol;
789 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
790 uint32 start_idx, num_dom_users, i;
791 struct samr_SamArray *dom_users = NULL;
792 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
793 uint32 acb_mask = ACB_NORMAL;
794 uint32_t size = 0xffff;
796 if ((argc < 1) || (argc > 4)) {
797 printf("Usage: %s [access_mask] [acb_mask] [size]\n", argv[0]);
798 return NT_STATUS_OK;
801 if (argc > 1) {
802 sscanf(argv[1], "%x", &access_mask);
805 if (argc > 2) {
806 sscanf(argv[2], "%x", &acb_mask);
809 if (argc > 3) {
810 sscanf(argv[3], "%x", &size);
813 /* Get sam policy handle */
815 result = rpccli_try_samr_connects(cli, mem_ctx,
816 MAXIMUM_ALLOWED_ACCESS,
817 &connect_pol);
819 if (!NT_STATUS_IS_OK(result))
820 goto done;
822 /* Get domain policy handle */
824 result = get_domain_handle(cli, mem_ctx, "domain",
825 &connect_pol,
826 access_mask,
827 &domain_sid,
828 &domain_pol);
829 if (!NT_STATUS_IS_OK(result))
830 goto done;
832 /* Enumerate domain users */
834 start_idx = 0;
836 do {
837 result = rpccli_samr_EnumDomainUsers(cli, mem_ctx,
838 &domain_pol,
839 &start_idx,
840 acb_mask,
841 &dom_users,
842 size,
843 &num_dom_users);
845 if (NT_STATUS_IS_OK(result) ||
846 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
848 for (i = 0; i < num_dom_users; i++)
849 printf("user:[%s] rid:[0x%x]\n",
850 dom_users->entries[i].name.string,
851 dom_users->entries[i].idx);
854 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
856 done:
857 if (is_valid_policy_hnd(&domain_pol))
858 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
860 if (is_valid_policy_hnd(&connect_pol))
861 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
863 return result;
866 /* Enumerate domain groups */
868 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
869 TALLOC_CTX *mem_ctx,
870 int argc, const char **argv)
872 struct policy_handle connect_pol, domain_pol;
873 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
874 uint32 start_idx, num_dom_groups, i;
875 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
876 struct samr_SamArray *dom_groups = NULL;
877 uint32_t size = 0xffff;
879 if ((argc < 1) || (argc > 3)) {
880 printf("Usage: %s [access_mask] [max_size]\n", argv[0]);
881 return NT_STATUS_OK;
884 if (argc > 1) {
885 sscanf(argv[1], "%x", &access_mask);
888 if (argc > 2) {
889 sscanf(argv[2], "%x", &size);
892 /* Get sam policy handle */
894 result = rpccli_try_samr_connects(cli, mem_ctx,
895 MAXIMUM_ALLOWED_ACCESS,
896 &connect_pol);
898 if (!NT_STATUS_IS_OK(result))
899 goto done;
901 /* Get domain policy handle */
903 result = get_domain_handle(cli, mem_ctx, "domain",
904 &connect_pol,
905 access_mask,
906 &domain_sid,
907 &domain_pol);
908 if (!NT_STATUS_IS_OK(result))
909 goto done;
911 /* Enumerate domain groups */
913 start_idx = 0;
915 do {
916 result = rpccli_samr_EnumDomainGroups(cli, mem_ctx,
917 &domain_pol,
918 &start_idx,
919 &dom_groups,
920 size,
921 &num_dom_groups);
922 if (NT_STATUS_IS_OK(result) ||
923 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
925 for (i = 0; i < num_dom_groups; i++)
926 printf("group:[%s] rid:[0x%x]\n",
927 dom_groups->entries[i].name.string,
928 dom_groups->entries[i].idx);
931 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
933 done:
934 if (is_valid_policy_hnd(&domain_pol))
935 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
937 if (is_valid_policy_hnd(&connect_pol))
938 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
940 return result;
943 /* Enumerate alias groups */
945 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
946 TALLOC_CTX *mem_ctx,
947 int argc, const char **argv)
949 struct policy_handle connect_pol, domain_pol;
950 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
951 uint32 start_idx, num_als_groups, i;
952 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
953 struct samr_SamArray *als_groups = NULL;
954 uint32_t size = 0xffff;
956 if ((argc < 2) || (argc > 4)) {
957 printf("Usage: %s builtin|domain [access mask] [max_size]\n", argv[0]);
958 return NT_STATUS_OK;
961 if (argc > 2) {
962 sscanf(argv[2], "%x", &access_mask);
965 if (argc > 3) {
966 sscanf(argv[3], "%x", &size);
969 /* Get sam policy handle */
971 result = rpccli_try_samr_connects(cli, mem_ctx,
972 MAXIMUM_ALLOWED_ACCESS,
973 &connect_pol);
975 if (!NT_STATUS_IS_OK(result))
976 goto done;
978 /* Get domain policy handle */
980 result = get_domain_handle(cli, mem_ctx, argv[1],
981 &connect_pol,
982 access_mask,
983 &domain_sid,
984 &domain_pol);
986 if (!NT_STATUS_IS_OK(result))
987 goto done;
989 /* Enumerate alias groups */
991 start_idx = 0;
993 do {
994 result = rpccli_samr_EnumDomainAliases(cli, mem_ctx,
995 &domain_pol,
996 &start_idx,
997 &als_groups,
998 size,
999 &num_als_groups);
1001 if (NT_STATUS_IS_OK(result) ||
1002 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1004 for (i = 0; i < num_als_groups; i++)
1005 printf("group:[%s] rid:[0x%x]\n",
1006 als_groups->entries[i].name.string,
1007 als_groups->entries[i].idx);
1009 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1011 done:
1012 if (is_valid_policy_hnd(&domain_pol))
1013 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1015 if (is_valid_policy_hnd(&connect_pol))
1016 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1018 return result;
1021 /* Enumerate domains */
1023 static NTSTATUS cmd_samr_enum_domains(struct rpc_pipe_client *cli,
1024 TALLOC_CTX *mem_ctx,
1025 int argc, const char **argv)
1027 struct policy_handle connect_pol;
1028 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1029 uint32 start_idx, size, num_entries, i;
1030 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1031 struct samr_SamArray *sam = NULL;
1033 if ((argc < 1) || (argc > 2)) {
1034 printf("Usage: %s [access mask]\n", argv[0]);
1035 return NT_STATUS_OK;
1038 if (argc > 1) {
1039 sscanf(argv[1], "%x", &access_mask);
1042 /* Get sam policy handle */
1044 result = rpccli_try_samr_connects(cli, mem_ctx,
1045 access_mask,
1046 &connect_pol);
1048 if (!NT_STATUS_IS_OK(result)) {
1049 goto done;
1052 /* Enumerate alias groups */
1054 start_idx = 0;
1055 size = 0xffff;
1057 do {
1058 result = rpccli_samr_EnumDomains(cli, mem_ctx,
1059 &connect_pol,
1060 &start_idx,
1061 &sam,
1062 size,
1063 &num_entries);
1065 if (NT_STATUS_IS_OK(result) ||
1066 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1068 for (i = 0; i < num_entries; i++)
1069 printf("name:[%s] idx:[0x%x]\n",
1070 sam->entries[i].name.string,
1071 sam->entries[i].idx);
1073 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1075 done:
1076 if (is_valid_policy_hnd(&connect_pol)) {
1077 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1080 return result;
1084 /* Query alias membership */
1086 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
1087 TALLOC_CTX *mem_ctx,
1088 int argc, const char **argv)
1090 struct policy_handle connect_pol, domain_pol, alias_pol;
1091 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1092 uint32 alias_rid, i;
1093 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1094 struct lsa_SidArray sid_array;
1096 if ((argc < 3) || (argc > 4)) {
1097 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
1098 return NT_STATUS_OK;
1101 sscanf(argv[2], "%i", &alias_rid);
1103 if (argc > 3)
1104 sscanf(argv[3], "%x", &access_mask);
1106 /* Open SAMR handle */
1108 result = rpccli_try_samr_connects(cli, mem_ctx,
1109 MAXIMUM_ALLOWED_ACCESS,
1110 &connect_pol);
1112 if (!NT_STATUS_IS_OK(result))
1113 goto done;
1115 /* Open handle on domain */
1117 result = get_domain_handle(cli, mem_ctx, argv[1],
1118 &connect_pol,
1119 MAXIMUM_ALLOWED_ACCESS,
1120 &domain_sid,
1121 &domain_pol);
1123 if (!NT_STATUS_IS_OK(result))
1124 goto done;
1126 /* Open handle on alias */
1128 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1129 &domain_pol,
1130 access_mask,
1131 alias_rid,
1132 &alias_pol);
1133 if (!NT_STATUS_IS_OK(result))
1134 goto done;
1136 result = rpccli_samr_GetMembersInAlias(cli, mem_ctx,
1137 &alias_pol,
1138 &sid_array);
1140 if (!NT_STATUS_IS_OK(result))
1141 goto done;
1143 for (i = 0; i < sid_array.num_sids; i++) {
1144 fstring sid_str;
1146 sid_to_fstring(sid_str, sid_array.sids[i].sid);
1147 printf("\tsid:[%s]\n", sid_str);
1150 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1151 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1152 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1153 done:
1154 return result;
1157 /* Query alias info */
1159 static NTSTATUS cmd_samr_query_aliasinfo(struct rpc_pipe_client *cli,
1160 TALLOC_CTX *mem_ctx,
1161 int argc, const char **argv)
1163 struct policy_handle connect_pol, domain_pol, alias_pol;
1164 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1165 uint32_t alias_rid;
1166 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1167 union samr_AliasInfo *info = NULL;
1168 enum samr_AliasInfoEnum level = ALIASINFOALL;
1170 if ((argc < 3) || (argc > 4)) {
1171 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1172 argv[0]);
1173 return NT_STATUS_OK;
1176 sscanf(argv[2], "%i", &alias_rid);
1178 if (argc > 2) {
1179 level = atoi(argv[3]);
1182 if (argc > 3) {
1183 sscanf(argv[4], "%x", &access_mask);
1186 /* Open SAMR handle */
1188 result = rpccli_try_samr_connects(cli, mem_ctx,
1189 SEC_FLAG_MAXIMUM_ALLOWED,
1190 &connect_pol);
1192 if (!NT_STATUS_IS_OK(result)) {
1193 goto done;
1196 /* Open handle on domain */
1198 result = get_domain_handle(cli, mem_ctx, argv[1],
1199 &connect_pol,
1200 SEC_FLAG_MAXIMUM_ALLOWED,
1201 &domain_sid,
1202 &domain_pol);
1204 if (!NT_STATUS_IS_OK(result)) {
1205 goto done;
1208 /* Open handle on alias */
1210 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1211 &domain_pol,
1212 access_mask,
1213 alias_rid,
1214 &alias_pol);
1215 if (!NT_STATUS_IS_OK(result)) {
1216 goto done;
1219 result = rpccli_samr_QueryAliasInfo(cli, mem_ctx,
1220 &alias_pol,
1221 level,
1222 &info);
1224 if (!NT_STATUS_IS_OK(result)) {
1225 goto done;
1228 switch (level) {
1229 case ALIASINFOALL:
1230 printf("Name: %s\n", info->all.name.string);
1231 printf("Description: %s\n", info->all.description.string);
1232 printf("Num Members: %d\n", info->all.num_members);
1233 break;
1234 case ALIASINFONAME:
1235 printf("Name: %s\n", info->name.string);
1236 break;
1237 case ALIASINFODESCRIPTION:
1238 printf("Description: %s\n", info->description.string);
1239 break;
1240 default:
1241 break;
1244 rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1245 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1246 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1247 done:
1248 return result;
1252 /* Query delete an alias membership */
1254 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
1255 TALLOC_CTX *mem_ctx,
1256 int argc, const char **argv)
1258 struct policy_handle connect_pol, domain_pol, alias_pol;
1259 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1260 uint32 alias_rid;
1261 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1263 if (argc != 3) {
1264 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
1265 return NT_STATUS_OK;
1268 alias_rid = strtoul(argv[2], NULL, 10);
1270 /* Open SAMR handle */
1272 result = rpccli_try_samr_connects(cli, mem_ctx,
1273 MAXIMUM_ALLOWED_ACCESS,
1274 &connect_pol);
1276 if (!NT_STATUS_IS_OK(result))
1277 goto done;
1279 /* Open handle on domain */
1281 result = get_domain_handle(cli, mem_ctx, argv[1],
1282 &connect_pol,
1283 MAXIMUM_ALLOWED_ACCESS,
1284 &domain_sid,
1285 &domain_pol);
1287 if (!NT_STATUS_IS_OK(result))
1288 goto done;
1290 /* Open handle on alias */
1292 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1293 &domain_pol,
1294 access_mask,
1295 alias_rid,
1296 &alias_pol);
1297 if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
1298 /* Probably this was a user name, try lookupnames */
1299 struct samr_Ids rids, types;
1300 struct lsa_String lsa_acct_name;
1302 init_lsa_String(&lsa_acct_name, argv[2]);
1304 result = rpccli_samr_LookupNames(cli, mem_ctx,
1305 &domain_pol,
1307 &lsa_acct_name,
1308 &rids,
1309 &types);
1311 if (NT_STATUS_IS_OK(result)) {
1312 result = rpccli_samr_OpenAlias(cli, mem_ctx,
1313 &domain_pol,
1314 access_mask,
1315 rids.ids[0],
1316 &alias_pol);
1320 result = rpccli_samr_DeleteDomAlias(cli, mem_ctx,
1321 &alias_pol);
1323 if (!NT_STATUS_IS_OK(result))
1324 goto done;
1326 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1327 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1328 done:
1329 return result;
1332 /* Query display info */
1334 static NTSTATUS cmd_samr_query_dispinfo_internal(struct rpc_pipe_client *cli,
1335 TALLOC_CTX *mem_ctx,
1336 int argc, const char **argv,
1337 uint32_t opcode)
1339 struct policy_handle connect_pol, domain_pol;
1340 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1341 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries = 0, i;
1342 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1343 uint32 info_level = 1;
1344 union samr_DispInfo info;
1345 int loop_count = 0;
1346 bool got_params = False; /* Use get_query_dispinfo_params() or not? */
1347 uint32_t total_size, returned_size;
1349 if (argc > 6) {
1350 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
1351 return NT_STATUS_OK;
1354 if (argc >= 2)
1355 sscanf(argv[1], "%i", &info_level);
1357 if (argc >= 3)
1358 sscanf(argv[2], "%i", &start_idx);
1360 if (argc >= 4) {
1361 sscanf(argv[3], "%i", &max_entries);
1362 got_params = True;
1365 if (argc >= 5) {
1366 sscanf(argv[4], "%i", &max_size);
1367 got_params = True;
1370 if (argc >= 6)
1371 sscanf(argv[5], "%x", &access_mask);
1373 /* Get sam policy handle */
1375 result = rpccli_try_samr_connects(cli, mem_ctx,
1376 MAXIMUM_ALLOWED_ACCESS,
1377 &connect_pol);
1379 if (!NT_STATUS_IS_OK(result))
1380 goto done;
1382 /* Get domain policy handle */
1384 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1385 &connect_pol,
1386 access_mask,
1387 &domain_sid,
1388 &domain_pol);
1390 if (!NT_STATUS_IS_OK(result))
1391 goto done;
1393 /* Query display info */
1395 do {
1397 if (!got_params)
1398 get_query_dispinfo_params(
1399 loop_count, &max_entries, &max_size);
1401 switch (opcode) {
1402 case NDR_SAMR_QUERYDISPLAYINFO:
1403 result = rpccli_samr_QueryDisplayInfo(cli, mem_ctx,
1404 &domain_pol,
1405 info_level,
1406 start_idx,
1407 max_entries,
1408 max_size,
1409 &total_size,
1410 &returned_size,
1411 &info);
1412 break;
1413 case NDR_SAMR_QUERYDISPLAYINFO2:
1414 result = rpccli_samr_QueryDisplayInfo2(cli, mem_ctx,
1415 &domain_pol,
1416 info_level,
1417 start_idx,
1418 max_entries,
1419 max_size,
1420 &total_size,
1421 &returned_size,
1422 &info);
1424 break;
1425 case NDR_SAMR_QUERYDISPLAYINFO3:
1426 result = rpccli_samr_QueryDisplayInfo3(cli, mem_ctx,
1427 &domain_pol,
1428 info_level,
1429 start_idx,
1430 max_entries,
1431 max_size,
1432 &total_size,
1433 &returned_size,
1434 &info);
1436 break;
1437 default:
1438 return NT_STATUS_INVALID_PARAMETER;
1441 if (!NT_STATUS_IS_OK(result) &&
1442 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
1443 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
1444 break;
1447 loop_count++;
1449 switch (info_level) {
1450 case 1:
1451 num_entries = info.info1.count;
1452 break;
1453 case 2:
1454 num_entries = info.info2.count;
1455 break;
1456 case 3:
1457 num_entries = info.info3.count;
1458 break;
1459 case 4:
1460 num_entries = info.info4.count;
1461 break;
1462 case 5:
1463 num_entries = info.info5.count;
1464 break;
1465 default:
1466 break;
1469 start_idx += num_entries;
1471 if (num_entries == 0)
1472 break;
1474 for (i = 0; i < num_entries; i++) {
1475 switch (info_level) {
1476 case 1:
1477 display_sam_info_1(&info.info1.entries[i]);
1478 break;
1479 case 2:
1480 display_sam_info_2(&info.info2.entries[i]);
1481 break;
1482 case 3:
1483 display_sam_info_3(&info.info3.entries[i]);
1484 break;
1485 case 4:
1486 display_sam_info_4(&info.info4.entries[i]);
1487 break;
1488 case 5:
1489 display_sam_info_5(&info.info5.entries[i]);
1490 break;
1493 } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1495 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1496 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1497 done:
1498 return result;
1501 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
1502 TALLOC_CTX *mem_ctx,
1503 int argc, const char **argv)
1505 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1506 NDR_SAMR_QUERYDISPLAYINFO);
1509 static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1510 TALLOC_CTX *mem_ctx,
1511 int argc, const char **argv)
1513 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1514 NDR_SAMR_QUERYDISPLAYINFO2);
1517 static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1518 TALLOC_CTX *mem_ctx,
1519 int argc, const char **argv)
1521 return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1522 NDR_SAMR_QUERYDISPLAYINFO3);
1525 /* Query domain info */
1527 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
1528 TALLOC_CTX *mem_ctx,
1529 int argc, const char **argv)
1531 struct policy_handle connect_pol, domain_pol;
1532 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1533 uint32 switch_level = 2;
1534 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1535 union samr_DomainInfo *info = NULL;
1537 if (argc > 3) {
1538 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1539 return NT_STATUS_OK;
1542 if (argc > 1)
1543 sscanf(argv[1], "%i", &switch_level);
1545 if (argc > 2)
1546 sscanf(argv[2], "%x", &access_mask);
1548 /* Get sam policy handle */
1550 result = rpccli_try_samr_connects(cli, mem_ctx,
1551 MAXIMUM_ALLOWED_ACCESS,
1552 &connect_pol);
1554 if (!NT_STATUS_IS_OK(result))
1555 goto done;
1557 /* Get domain policy handle */
1559 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1560 &connect_pol,
1561 access_mask,
1562 &domain_sid,
1563 &domain_pol);
1565 if (!NT_STATUS_IS_OK(result))
1566 goto done;
1568 /* Query domain info */
1570 result = rpccli_samr_QueryDomainInfo(cli, mem_ctx,
1571 &domain_pol,
1572 switch_level,
1573 &info);
1575 if (!NT_STATUS_IS_OK(result))
1576 goto done;
1578 /* Display domain info */
1580 switch (switch_level) {
1581 case 1:
1582 display_sam_dom_info_1(&info->info1);
1583 break;
1584 case 2:
1585 display_sam_dom_info_2(&info->general);
1586 break;
1587 case 3:
1588 display_sam_dom_info_3(&info->info3);
1589 break;
1590 case 4:
1591 display_sam_dom_info_4(&info->oem);
1592 break;
1593 case 5:
1594 display_sam_dom_info_5(&info->info5);
1595 break;
1596 case 6:
1597 display_sam_dom_info_6(&info->info6);
1598 break;
1599 case 7:
1600 display_sam_dom_info_7(&info->info7);
1601 break;
1602 case 8:
1603 display_sam_dom_info_8(&info->info8);
1604 break;
1605 case 9:
1606 display_sam_dom_info_9(&info->info9);
1607 break;
1608 case 12:
1609 display_sam_dom_info_12(&info->info12);
1610 break;
1611 case 13:
1612 display_sam_dom_info_13(&info->info13);
1613 break;
1615 default:
1616 printf("cannot display domain info for switch value %d\n",
1617 switch_level);
1618 break;
1621 done:
1623 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1624 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1625 return result;
1628 /* Create domain user */
1630 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
1631 TALLOC_CTX *mem_ctx,
1632 int argc, const char **argv)
1634 struct policy_handle connect_pol, domain_pol, user_pol;
1635 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1636 struct lsa_String acct_name;
1637 uint32 acb_info;
1638 uint32 acct_flags, user_rid;
1639 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1640 uint32_t access_granted = 0;
1642 if ((argc < 2) || (argc > 3)) {
1643 printf("Usage: %s username [access mask]\n", argv[0]);
1644 return NT_STATUS_OK;
1647 init_lsa_String(&acct_name, argv[1]);
1649 if (argc > 2)
1650 sscanf(argv[2], "%x", &access_mask);
1652 /* Get sam policy handle */
1654 result = rpccli_try_samr_connects(cli, mem_ctx,
1655 MAXIMUM_ALLOWED_ACCESS,
1656 &connect_pol);
1658 if (!NT_STATUS_IS_OK(result))
1659 goto done;
1661 /* Get domain policy handle */
1663 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1664 &connect_pol,
1665 access_mask,
1666 &domain_sid,
1667 &domain_pol);
1669 if (!NT_STATUS_IS_OK(result))
1670 goto done;
1672 /* Create domain user */
1674 acb_info = ACB_NORMAL;
1675 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
1676 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
1677 SAMR_USER_ACCESS_SET_PASSWORD |
1678 SAMR_USER_ACCESS_GET_ATTRIBUTES |
1679 SAMR_USER_ACCESS_SET_ATTRIBUTES;
1681 result = rpccli_samr_CreateUser2(cli, mem_ctx,
1682 &domain_pol,
1683 &acct_name,
1684 acb_info,
1685 acct_flags,
1686 &user_pol,
1687 &access_granted,
1688 &user_rid);
1690 if (!NT_STATUS_IS_OK(result))
1691 goto done;
1693 result = rpccli_samr_Close(cli, mem_ctx, &user_pol);
1694 if (!NT_STATUS_IS_OK(result)) goto done;
1696 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1697 if (!NT_STATUS_IS_OK(result)) goto done;
1699 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1700 if (!NT_STATUS_IS_OK(result)) goto done;
1702 done:
1703 return result;
1706 /* Create domain group */
1708 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
1709 TALLOC_CTX *mem_ctx,
1710 int argc, const char **argv)
1712 struct policy_handle connect_pol, domain_pol, group_pol;
1713 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1714 struct lsa_String grp_name;
1715 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1716 uint32_t rid = 0;
1718 if ((argc < 2) || (argc > 3)) {
1719 printf("Usage: %s groupname [access mask]\n", argv[0]);
1720 return NT_STATUS_OK;
1723 init_lsa_String(&grp_name, argv[1]);
1725 if (argc > 2)
1726 sscanf(argv[2], "%x", &access_mask);
1728 /* Get sam policy handle */
1730 result = rpccli_try_samr_connects(cli, mem_ctx,
1731 MAXIMUM_ALLOWED_ACCESS,
1732 &connect_pol);
1734 if (!NT_STATUS_IS_OK(result))
1735 goto done;
1737 /* Get domain policy handle */
1739 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1740 &connect_pol,
1741 access_mask,
1742 &domain_sid,
1743 &domain_pol);
1745 if (!NT_STATUS_IS_OK(result))
1746 goto done;
1748 /* Create domain user */
1749 result = rpccli_samr_CreateDomainGroup(cli, mem_ctx,
1750 &domain_pol,
1751 &grp_name,
1752 MAXIMUM_ALLOWED_ACCESS,
1753 &group_pol,
1754 &rid);
1756 if (!NT_STATUS_IS_OK(result))
1757 goto done;
1759 result = rpccli_samr_Close(cli, mem_ctx, &group_pol);
1760 if (!NT_STATUS_IS_OK(result)) goto done;
1762 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1763 if (!NT_STATUS_IS_OK(result)) goto done;
1765 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1766 if (!NT_STATUS_IS_OK(result)) goto done;
1768 done:
1769 return result;
1772 /* Create domain alias */
1774 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
1775 TALLOC_CTX *mem_ctx,
1776 int argc, const char **argv)
1778 struct policy_handle connect_pol, domain_pol, alias_pol;
1779 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1780 struct lsa_String alias_name;
1781 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1782 uint32_t rid = 0;
1784 if ((argc < 2) || (argc > 3)) {
1785 printf("Usage: %s aliasname [access mask]\n", argv[0]);
1786 return NT_STATUS_OK;
1789 init_lsa_String(&alias_name, argv[1]);
1791 if (argc > 2)
1792 sscanf(argv[2], "%x", &access_mask);
1794 /* Get sam policy handle */
1796 result = rpccli_try_samr_connects(cli, mem_ctx,
1797 MAXIMUM_ALLOWED_ACCESS,
1798 &connect_pol);
1800 if (!NT_STATUS_IS_OK(result))
1801 goto done;
1803 /* Get domain policy handle */
1805 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1806 &connect_pol,
1807 access_mask,
1808 &domain_sid,
1809 &domain_pol);
1811 if (!NT_STATUS_IS_OK(result))
1812 goto done;
1814 /* Create domain user */
1816 result = rpccli_samr_CreateDomAlias(cli, mem_ctx,
1817 &domain_pol,
1818 &alias_name,
1819 MAXIMUM_ALLOWED_ACCESS,
1820 &alias_pol,
1821 &rid);
1823 if (!NT_STATUS_IS_OK(result))
1824 goto done;
1826 result = rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1827 if (!NT_STATUS_IS_OK(result)) goto done;
1829 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1830 if (!NT_STATUS_IS_OK(result)) goto done;
1832 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1833 if (!NT_STATUS_IS_OK(result)) goto done;
1835 done:
1836 return result;
1839 /* Lookup sam names */
1841 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
1842 TALLOC_CTX *mem_ctx,
1843 int argc, const char **argv)
1845 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1846 struct policy_handle connect_pol, domain_pol;
1847 uint32 num_names;
1848 struct samr_Ids rids, name_types;
1849 int i;
1850 struct lsa_String *names = NULL;;
1852 if (argc < 3) {
1853 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1854 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1855 printf("or check on the builtin SID: S-1-5-32\n");
1856 return NT_STATUS_OK;
1859 /* Get sam policy and domain handles */
1861 result = rpccli_try_samr_connects(cli, mem_ctx,
1862 MAXIMUM_ALLOWED_ACCESS,
1863 &connect_pol);
1865 if (!NT_STATUS_IS_OK(result))
1866 goto done;
1868 result = get_domain_handle(cli, mem_ctx, argv[1],
1869 &connect_pol,
1870 MAXIMUM_ALLOWED_ACCESS,
1871 &domain_sid,
1872 &domain_pol);
1874 if (!NT_STATUS_IS_OK(result))
1875 goto done;
1877 /* Look up names */
1879 num_names = argc - 2;
1881 if ((names = TALLOC_ARRAY(mem_ctx, struct lsa_String, num_names)) == NULL) {
1882 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1883 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1884 result = NT_STATUS_NO_MEMORY;
1885 goto done;
1888 for (i = 0; i < num_names; i++) {
1889 init_lsa_String(&names[i], argv[i + 2]);
1892 result = rpccli_samr_LookupNames(cli, mem_ctx,
1893 &domain_pol,
1894 num_names,
1895 names,
1896 &rids,
1897 &name_types);
1899 if (!NT_STATUS_IS_OK(result))
1900 goto done;
1902 /* Display results */
1904 for (i = 0; i < num_names; i++)
1905 printf("name %s: 0x%x (%d)\n", names[i].string, rids.ids[i],
1906 name_types.ids[i]);
1908 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1909 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1910 done:
1911 return result;
1914 /* Lookup sam rids */
1916 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
1917 TALLOC_CTX *mem_ctx,
1918 int argc, const char **argv)
1920 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1921 struct policy_handle connect_pol, domain_pol;
1922 uint32_t num_rids, *rids;
1923 struct lsa_Strings names;
1924 struct samr_Ids types;
1926 int i;
1928 if (argc < 3) {
1929 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
1930 return NT_STATUS_OK;
1933 /* Get sam policy and domain handles */
1935 result = rpccli_try_samr_connects(cli, mem_ctx,
1936 MAXIMUM_ALLOWED_ACCESS,
1937 &connect_pol);
1939 if (!NT_STATUS_IS_OK(result))
1940 goto done;
1942 result = get_domain_handle(cli, mem_ctx, argv[1],
1943 &connect_pol,
1944 MAXIMUM_ALLOWED_ACCESS,
1945 &domain_sid,
1946 &domain_pol);
1948 if (!NT_STATUS_IS_OK(result))
1949 goto done;
1951 /* Look up rids */
1953 num_rids = argc - 2;
1955 if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
1956 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1957 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1958 result = NT_STATUS_NO_MEMORY;
1959 goto done;
1962 for (i = 0; i < argc - 2; i++)
1963 sscanf(argv[i + 2], "%i", &rids[i]);
1965 result = rpccli_samr_LookupRids(cli, mem_ctx,
1966 &domain_pol,
1967 num_rids,
1968 rids,
1969 &names,
1970 &types);
1972 if (!NT_STATUS_IS_OK(result) &&
1973 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
1974 goto done;
1976 /* Display results */
1978 for (i = 0; i < num_rids; i++) {
1979 printf("rid 0x%x: %s (%d)\n",
1980 rids[i], names.names[i].string, types.ids[i]);
1983 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1984 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1985 done:
1986 return result;
1989 /* Delete domain group */
1991 static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
1992 TALLOC_CTX *mem_ctx,
1993 int argc, const char **argv)
1995 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1996 struct policy_handle connect_pol, domain_pol, group_pol;
1997 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1999 if ((argc < 2) || (argc > 3)) {
2000 printf("Usage: %s groupname\n", argv[0]);
2001 return NT_STATUS_OK;
2004 if (argc > 2)
2005 sscanf(argv[2], "%x", &access_mask);
2007 /* Get sam policy and domain handles */
2009 result = rpccli_try_samr_connects(cli, mem_ctx,
2010 MAXIMUM_ALLOWED_ACCESS,
2011 &connect_pol);
2013 if (!NT_STATUS_IS_OK(result))
2014 goto done;
2016 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2017 &connect_pol,
2018 MAXIMUM_ALLOWED_ACCESS,
2019 &domain_sid,
2020 &domain_pol);
2022 if (!NT_STATUS_IS_OK(result))
2023 goto done;
2025 /* Get handle on group */
2028 struct samr_Ids group_rids, name_types;
2029 struct lsa_String lsa_acct_name;
2031 init_lsa_String(&lsa_acct_name, argv[1]);
2033 result = rpccli_samr_LookupNames(cli, mem_ctx,
2034 &domain_pol,
2036 &lsa_acct_name,
2037 &group_rids,
2038 &name_types);
2039 if (!NT_STATUS_IS_OK(result))
2040 goto done;
2042 result = rpccli_samr_OpenGroup(cli, mem_ctx,
2043 &domain_pol,
2044 access_mask,
2045 group_rids.ids[0],
2046 &group_pol);
2048 if (!NT_STATUS_IS_OK(result))
2049 goto done;
2052 /* Delete group */
2054 result = rpccli_samr_DeleteDomainGroup(cli, mem_ctx,
2055 &group_pol);
2057 if (!NT_STATUS_IS_OK(result))
2058 goto done;
2060 /* Display results */
2062 rpccli_samr_Close(cli, mem_ctx, &group_pol);
2063 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2064 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2066 done:
2067 return result;
2070 /* Delete domain user */
2072 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
2073 TALLOC_CTX *mem_ctx,
2074 int argc, const char **argv)
2076 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2077 struct policy_handle connect_pol, domain_pol, user_pol;
2078 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2080 if ((argc < 2) || (argc > 3)) {
2081 printf("Usage: %s username\n", argv[0]);
2082 return NT_STATUS_OK;
2085 if (argc > 2)
2086 sscanf(argv[2], "%x", &access_mask);
2088 /* Get sam policy and domain handles */
2090 result = rpccli_try_samr_connects(cli, mem_ctx,
2091 MAXIMUM_ALLOWED_ACCESS,
2092 &connect_pol);
2094 if (!NT_STATUS_IS_OK(result))
2095 goto done;
2097 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2098 &connect_pol,
2099 MAXIMUM_ALLOWED_ACCESS,
2100 &domain_sid,
2101 &domain_pol);
2103 if (!NT_STATUS_IS_OK(result))
2104 goto done;
2106 /* Get handle on user */
2109 struct samr_Ids user_rids, name_types;
2110 struct lsa_String lsa_acct_name;
2112 init_lsa_String(&lsa_acct_name, argv[1]);
2114 result = rpccli_samr_LookupNames(cli, mem_ctx,
2115 &domain_pol,
2117 &lsa_acct_name,
2118 &user_rids,
2119 &name_types);
2121 if (!NT_STATUS_IS_OK(result))
2122 goto done;
2124 result = rpccli_samr_OpenUser(cli, mem_ctx,
2125 &domain_pol,
2126 access_mask,
2127 user_rids.ids[0],
2128 &user_pol);
2130 if (!NT_STATUS_IS_OK(result))
2131 goto done;
2134 /* Delete user */
2136 result = rpccli_samr_DeleteUser(cli, mem_ctx,
2137 &user_pol);
2139 if (!NT_STATUS_IS_OK(result))
2140 goto done;
2142 /* Display results */
2144 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2145 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2146 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2148 done:
2149 return result;
2152 /**********************************************************************
2153 * Query user security object
2155 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
2156 TALLOC_CTX *mem_ctx,
2157 int argc, const char **argv)
2159 struct policy_handle connect_pol, domain_pol, user_pol, *pol;
2160 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2161 uint32 sec_info = DACL_SECURITY_INFORMATION;
2162 uint32 user_rid = 0;
2163 TALLOC_CTX *ctx = NULL;
2164 SEC_DESC_BUF *sec_desc_buf=NULL;
2165 bool domain = False;
2167 ctx=talloc_init("cmd_samr_query_sec_obj");
2169 if ((argc < 1) || (argc > 3)) {
2170 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
2171 printf("\tSpecify rid for security on user, -d for security on domain\n");
2172 talloc_destroy(ctx);
2173 return NT_STATUS_OK;
2176 if (argc > 1) {
2177 if (strcmp(argv[1], "-d") == 0)
2178 domain = True;
2179 else
2180 sscanf(argv[1], "%i", &user_rid);
2183 if (argc == 3) {
2184 sec_info = atoi(argv[2]);
2187 result = rpccli_try_samr_connects(cli, mem_ctx,
2188 MAXIMUM_ALLOWED_ACCESS,
2189 &connect_pol);
2191 if (!NT_STATUS_IS_OK(result))
2192 goto done;
2194 if (domain || user_rid)
2195 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2196 &connect_pol,
2197 MAXIMUM_ALLOWED_ACCESS,
2198 &domain_sid,
2199 &domain_pol);
2201 if (!NT_STATUS_IS_OK(result))
2202 goto done;
2204 if (user_rid)
2205 result = rpccli_samr_OpenUser(cli, mem_ctx,
2206 &domain_pol,
2207 MAXIMUM_ALLOWED_ACCESS,
2208 user_rid,
2209 &user_pol);
2211 if (!NT_STATUS_IS_OK(result))
2212 goto done;
2214 /* Pick which query pol to use */
2216 pol = &connect_pol;
2218 if (domain)
2219 pol = &domain_pol;
2221 if (user_rid)
2222 pol = &user_pol;
2224 /* Query SAM security object */
2226 result = rpccli_samr_QuerySecurity(cli, mem_ctx,
2227 pol,
2228 sec_info,
2229 &sec_desc_buf);
2231 if (!NT_STATUS_IS_OK(result))
2232 goto done;
2234 display_sec_desc(sec_desc_buf->sd);
2236 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2237 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2238 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2239 done:
2240 talloc_destroy(ctx);
2241 return result;
2244 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
2245 TALLOC_CTX *mem_ctx,
2246 int argc, const char **argv)
2248 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2249 struct policy_handle connect_pol, domain_pol, user_pol;
2250 struct samr_PwInfo info;
2251 uint32_t rid;
2253 if (argc != 2) {
2254 printf("Usage: %s rid\n", argv[0]);
2255 return NT_STATUS_OK;
2258 sscanf(argv[1], "%i", &rid);
2260 result = rpccli_try_samr_connects(cli, mem_ctx,
2261 MAXIMUM_ALLOWED_ACCESS,
2262 &connect_pol);
2264 if (!NT_STATUS_IS_OK(result)) {
2265 goto done;
2268 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2269 &connect_pol,
2270 MAXIMUM_ALLOWED_ACCESS,
2271 &domain_sid,
2272 &domain_pol);
2274 if (!NT_STATUS_IS_OK(result)) {
2275 goto done;
2278 result = rpccli_samr_OpenUser(cli, mem_ctx,
2279 &domain_pol,
2280 MAXIMUM_ALLOWED_ACCESS,
2281 rid,
2282 &user_pol);
2284 if (!NT_STATUS_IS_OK(result)) {
2285 goto done;
2288 result = rpccli_samr_GetUserPwInfo(cli, mem_ctx, &user_pol, &info);
2289 if (NT_STATUS_IS_OK(result)) {
2290 printf("min_password_length: %d\n", info.min_password_length);
2291 printf("%s\n",
2292 NDR_PRINT_STRUCT_STRING(mem_ctx,
2293 samr_PasswordProperties, &info.password_properties));
2296 done:
2297 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2298 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2299 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2301 return result;
2304 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
2305 TALLOC_CTX *mem_ctx,
2306 int argc, const char **argv)
2308 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2309 struct lsa_String domain_name;
2310 struct samr_PwInfo info;
2312 if (argc < 1 || argc > 3) {
2313 printf("Usage: %s <domain>\n", argv[0]);
2314 return NT_STATUS_OK;
2317 init_lsa_String(&domain_name, argv[1]);
2319 result = rpccli_samr_GetDomPwInfo(cli, mem_ctx, &domain_name, &info);
2321 if (NT_STATUS_IS_OK(result)) {
2322 printf("min_password_length: %d\n", info.min_password_length);
2323 display_password_properties(info.password_properties);
2326 return result;
2329 /* Look up domain name */
2331 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
2332 TALLOC_CTX *mem_ctx,
2333 int argc, const char **argv)
2335 struct policy_handle connect_pol, domain_pol;
2336 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2337 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2338 fstring sid_string;
2339 struct lsa_String domain_name;
2340 DOM_SID *sid = NULL;
2342 if (argc != 2) {
2343 printf("Usage: %s domain_name\n", argv[0]);
2344 return NT_STATUS_OK;
2347 init_lsa_String(&domain_name, argv[1]);
2349 result = rpccli_try_samr_connects(cli, mem_ctx,
2350 access_mask,
2351 &connect_pol);
2353 if (!NT_STATUS_IS_OK(result))
2354 goto done;
2356 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2357 &connect_pol,
2358 access_mask,
2359 &domain_sid,
2360 &domain_pol);
2362 if (!NT_STATUS_IS_OK(result))
2363 goto done;
2365 result = rpccli_samr_LookupDomain(cli, mem_ctx,
2366 &connect_pol,
2367 &domain_name,
2368 &sid);
2370 if (NT_STATUS_IS_OK(result)) {
2371 sid_to_fstring(sid_string, sid);
2372 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2373 argv[1], sid_string);
2376 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2377 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2378 done:
2379 return result;
2382 /* Change user password */
2384 static NTSTATUS cmd_samr_chgpasswd(struct rpc_pipe_client *cli,
2385 TALLOC_CTX *mem_ctx,
2386 int argc, const char **argv)
2388 struct policy_handle connect_pol, domain_pol, user_pol;
2389 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2390 const char *user, *oldpass, *newpass;
2391 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2392 struct samr_Ids rids, types;
2393 struct lsa_String lsa_acct_name;
2395 if (argc < 3) {
2396 printf("Usage: %s username oldpass newpass\n", argv[0]);
2397 return NT_STATUS_INVALID_PARAMETER;
2400 user = argv[1];
2401 oldpass = argv[2];
2402 newpass = argv[3];
2404 /* Get sam policy handle */
2406 result = rpccli_try_samr_connects(cli, mem_ctx,
2407 MAXIMUM_ALLOWED_ACCESS,
2408 &connect_pol);
2410 if (!NT_STATUS_IS_OK(result)) {
2411 goto done;
2414 /* Get domain policy handle */
2416 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2417 &connect_pol,
2418 access_mask,
2419 &domain_sid,
2420 &domain_pol);
2422 if (!NT_STATUS_IS_OK(result)) {
2423 goto done;
2426 init_lsa_String(&lsa_acct_name, user);
2428 result = rpccli_samr_LookupNames(cli, mem_ctx,
2429 &domain_pol,
2431 &lsa_acct_name,
2432 &rids,
2433 &types);
2435 if (!NT_STATUS_IS_OK(result)) {
2436 goto done;
2439 result = rpccli_samr_OpenUser(cli, mem_ctx,
2440 &domain_pol,
2441 access_mask,
2442 rids.ids[0],
2443 &user_pol);
2445 if (!NT_STATUS_IS_OK(result)) {
2446 goto done;
2449 /* Change user password */
2450 result = rpccli_samr_chgpasswd_user(cli, mem_ctx,
2451 &user_pol,
2452 newpass,
2453 oldpass);
2455 if (!NT_STATUS_IS_OK(result)) {
2456 goto done;
2459 done:
2460 if (is_valid_policy_hnd(&user_pol)) {
2461 rpccli_samr_Close(cli, mem_ctx, &user_pol);
2463 if (is_valid_policy_hnd(&domain_pol)) {
2464 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2466 if (is_valid_policy_hnd(&connect_pol)) {
2467 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2470 return result;
2474 /* Change user password */
2476 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
2477 TALLOC_CTX *mem_ctx,
2478 int argc, const char **argv)
2480 struct policy_handle connect_pol, domain_pol;
2481 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2482 const char *user, *oldpass, *newpass;
2483 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2485 if (argc < 3) {
2486 printf("Usage: %s username oldpass newpass\n", argv[0]);
2487 return NT_STATUS_INVALID_PARAMETER;
2490 user = argv[1];
2491 oldpass = argv[2];
2492 newpass = argv[3];
2494 /* Get sam policy handle */
2496 result = rpccli_try_samr_connects(cli, mem_ctx,
2497 MAXIMUM_ALLOWED_ACCESS,
2498 &connect_pol);
2500 if (!NT_STATUS_IS_OK(result))
2501 goto done;
2503 /* Get domain policy handle */
2505 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2506 &connect_pol,
2507 access_mask,
2508 &domain_sid,
2509 &domain_pol);
2511 if (!NT_STATUS_IS_OK(result))
2512 goto done;
2514 /* Change user password */
2515 result = rpccli_samr_chgpasswd_user2(cli, mem_ctx, user, newpass, oldpass);
2517 if (!NT_STATUS_IS_OK(result))
2518 goto done;
2520 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2521 if (!NT_STATUS_IS_OK(result)) goto done;
2523 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2524 if (!NT_STATUS_IS_OK(result)) goto done;
2526 done:
2527 return result;
2531 /* Change user password */
2533 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
2534 TALLOC_CTX *mem_ctx,
2535 int argc, const char **argv)
2537 struct policy_handle connect_pol, domain_pol;
2538 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2539 const char *user, *oldpass, *newpass;
2540 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2541 struct samr_DomInfo1 *info = NULL;
2542 struct userPwdChangeFailureInformation *reject = NULL;
2544 if (argc < 3) {
2545 printf("Usage: %s username oldpass newpass\n", argv[0]);
2546 return NT_STATUS_INVALID_PARAMETER;
2549 user = argv[1];
2550 oldpass = argv[2];
2551 newpass = argv[3];
2553 /* Get sam policy handle */
2555 result = rpccli_try_samr_connects(cli, mem_ctx,
2556 MAXIMUM_ALLOWED_ACCESS,
2557 &connect_pol);
2559 if (!NT_STATUS_IS_OK(result))
2560 goto done;
2562 /* Get domain policy handle */
2564 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2565 &connect_pol,
2566 access_mask,
2567 &domain_sid,
2568 &domain_pol);
2570 if (!NT_STATUS_IS_OK(result))
2571 goto done;
2573 /* Change user password */
2574 result = rpccli_samr_chgpasswd_user3(cli, mem_ctx,
2575 user,
2576 newpass,
2577 oldpass,
2578 &info,
2579 &reject);
2581 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
2583 display_sam_dom_info_1(info);
2585 switch (reject->extendedFailureReason) {
2586 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT:
2587 d_printf("SAM_PWD_CHANGE_PASSWORD_TOO_SHORT\n");
2588 break;
2589 case SAM_PWD_CHANGE_PWD_IN_HISTORY:
2590 d_printf("SAM_PWD_CHANGE_PWD_IN_HISTORY\n");
2591 break;
2592 case SAM_PWD_CHANGE_NOT_COMPLEX:
2593 d_printf("SAM_PWD_CHANGE_NOT_COMPLEX\n");
2594 break;
2595 default:
2596 d_printf("unknown reject reason: %d\n",
2597 reject->extendedFailureReason);
2598 break;
2602 if (!NT_STATUS_IS_OK(result))
2603 goto done;
2605 result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2606 if (!NT_STATUS_IS_OK(result)) goto done;
2608 result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2609 if (!NT_STATUS_IS_OK(result)) goto done;
2611 done:
2612 return result;
2615 static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
2616 TALLOC_CTX *mem_ctx,
2617 int argc, const char **argv,
2618 int opcode)
2620 struct policy_handle connect_pol, domain_pol, user_pol;
2621 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
2622 const char *user, *param;
2623 uint32_t access_mask = MAXIMUM_ALLOWED_ACCESS;
2624 uint32_t level;
2625 uint32_t user_rid;
2626 union samr_UserInfo info;
2627 struct samr_CryptPassword pwd_buf;
2628 struct samr_CryptPasswordEx pwd_buf_ex;
2629 uint8_t nt_hash[16];
2630 uint8_t lm_hash[16];
2631 DATA_BLOB session_key;
2632 uint8_t password_expired = 0;
2634 if (argc < 4) {
2635 printf("Usage: %s username level password [password_expired]\n",
2636 argv[0]);
2637 return NT_STATUS_INVALID_PARAMETER;
2640 user = argv[1];
2641 level = atoi(argv[2]);
2642 param = argv[3];
2644 if (argc >= 5) {
2645 password_expired = atoi(argv[4]);
2648 status = cli_get_session_key(mem_ctx, cli, &session_key);
2649 if (!NT_STATUS_IS_OK(status)) {
2650 return status;
2653 init_samr_CryptPassword(param, &session_key, &pwd_buf);
2654 init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
2655 nt_lm_owf_gen(param, nt_hash, lm_hash);
2657 switch (level) {
2658 case 18:
2660 DATA_BLOB in,out;
2661 in = data_blob_const(nt_hash, 16);
2662 out = data_blob_talloc_zero(mem_ctx, 16);
2663 sess_crypt_blob(&out, &in, &session_key, true);
2664 memcpy(nt_hash, out.data, out.length);
2667 DATA_BLOB in,out;
2668 in = data_blob_const(lm_hash, 16);
2669 out = data_blob_talloc_zero(mem_ctx, 16);
2670 sess_crypt_blob(&out, &in, &session_key, true);
2671 memcpy(lm_hash, out.data, out.length);
2674 memcpy(info.info18.nt_pwd.hash, nt_hash, 16);
2675 memcpy(info.info18.lm_pwd.hash, lm_hash, 16);
2676 info.info18.nt_pwd_active = true;
2677 info.info18.lm_pwd_active = true;
2678 info.info18.password_expired = password_expired;
2680 break;
2681 case 21:
2682 ZERO_STRUCT(info.info21);
2684 info.info21.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2685 SAMR_FIELD_LM_PASSWORD_PRESENT;
2686 if (argc >= 5) {
2687 info.info21.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2688 info.info21.password_expired = password_expired;
2691 info.info21.lm_password_set = true;
2692 info.info21.lm_owf_password.length = 16;
2693 info.info21.lm_owf_password.size = 16;
2695 info.info21.nt_password_set = true;
2696 info.info21.nt_owf_password.length = 16;
2697 info.info21.nt_owf_password.size = 16;
2700 DATA_BLOB in,out;
2701 in = data_blob_const(nt_hash, 16);
2702 out = data_blob_talloc_zero(mem_ctx, 16);
2703 sess_crypt_blob(&out, &in, &session_key, true);
2704 info.info21.nt_owf_password.array =
2705 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2708 DATA_BLOB in,out;
2709 in = data_blob_const(lm_hash, 16);
2710 out = data_blob_talloc_zero(mem_ctx, 16);
2711 sess_crypt_blob(&out, &in, &session_key, true);
2712 info.info21.lm_owf_password.array =
2713 (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
2716 break;
2717 case 23:
2718 ZERO_STRUCT(info.info23);
2720 info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2721 SAMR_FIELD_LM_PASSWORD_PRESENT;
2722 if (argc >= 5) {
2723 info.info23.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2724 info.info23.info.password_expired = password_expired;
2727 info.info23.password = pwd_buf;
2729 break;
2730 case 24:
2731 info.info24.password = pwd_buf;
2732 info.info24.password_expired = password_expired;
2734 break;
2735 case 25:
2736 ZERO_STRUCT(info.info25);
2738 info.info25.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
2739 SAMR_FIELD_LM_PASSWORD_PRESENT;
2740 if (argc >= 5) {
2741 info.info25.info.fields_present |= SAMR_FIELD_EXPIRED_FLAG;
2742 info.info25.info.password_expired = password_expired;
2745 info.info25.password = pwd_buf_ex;
2747 break;
2748 case 26:
2749 info.info26.password = pwd_buf_ex;
2750 info.info26.password_expired = password_expired;
2752 break;
2753 default:
2754 return NT_STATUS_INVALID_INFO_CLASS;
2757 /* Get sam policy handle */
2759 status = rpccli_try_samr_connects(cli, mem_ctx,
2760 MAXIMUM_ALLOWED_ACCESS,
2761 &connect_pol);
2763 if (!NT_STATUS_IS_OK(status))
2764 goto done;
2766 /* Get domain policy handle */
2768 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2769 &connect_pol,
2770 access_mask,
2771 &domain_sid,
2772 &domain_pol);
2774 if (!NT_STATUS_IS_OK(status))
2775 goto done;
2777 user_rid = strtol(user, NULL, 0);
2778 if (user_rid) {
2779 status = rpccli_samr_OpenUser(cli, mem_ctx,
2780 &domain_pol,
2781 access_mask,
2782 user_rid,
2783 &user_pol);
2786 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER) ||
2787 (user_rid == 0)) {
2789 /* Probably this was a user name, try lookupnames */
2790 struct samr_Ids rids, types;
2791 struct lsa_String lsa_acct_name;
2793 init_lsa_String(&lsa_acct_name, user);
2795 status = rpccli_samr_LookupNames(cli, mem_ctx,
2796 &domain_pol,
2798 &lsa_acct_name,
2799 &rids,
2800 &types);
2801 if (!NT_STATUS_IS_OK(status)) {
2802 return status;
2805 status = rpccli_samr_OpenUser(cli, mem_ctx,
2806 &domain_pol,
2807 access_mask,
2808 rids.ids[0],
2809 &user_pol);
2810 if (!NT_STATUS_IS_OK(status)) {
2811 return status;
2815 switch (opcode) {
2816 case NDR_SAMR_SETUSERINFO:
2817 status = rpccli_samr_SetUserInfo(cli, mem_ctx,
2818 &user_pol,
2819 level,
2820 &info);
2821 break;
2822 case NDR_SAMR_SETUSERINFO2:
2823 status = rpccli_samr_SetUserInfo2(cli, mem_ctx,
2824 &user_pol,
2825 level,
2826 &info);
2827 break;
2828 default:
2829 return NT_STATUS_INVALID_PARAMETER;
2832 done:
2833 return status;
2836 static NTSTATUS cmd_samr_setuserinfo(struct rpc_pipe_client *cli,
2837 TALLOC_CTX *mem_ctx,
2838 int argc, const char **argv)
2840 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2841 NDR_SAMR_SETUSERINFO);
2844 static NTSTATUS cmd_samr_setuserinfo2(struct rpc_pipe_client *cli,
2845 TALLOC_CTX *mem_ctx,
2846 int argc, const char **argv)
2848 return cmd_samr_setuserinfo_int(cli, mem_ctx, argc, argv,
2849 NDR_SAMR_SETUSERINFO2);
2852 static NTSTATUS cmd_samr_get_dispinfo_idx(struct rpc_pipe_client *cli,
2853 TALLOC_CTX *mem_ctx,
2854 int argc, const char **argv)
2856 NTSTATUS status;
2857 struct policy_handle connect_handle;
2858 struct policy_handle domain_handle;
2859 uint16_t level = 1;
2860 struct lsa_String name;
2861 uint32_t idx = 0;
2863 if (argc < 2 || argc > 3) {
2864 printf("Usage: %s name level\n", argv[0]);
2865 return NT_STATUS_INVALID_PARAMETER;
2868 init_lsa_String(&name, argv[1]);
2870 if (argc == 3) {
2871 level = atoi(argv[2]);
2874 status = rpccli_try_samr_connects(cli, mem_ctx,
2875 SEC_FLAG_MAXIMUM_ALLOWED,
2876 &connect_handle);
2878 if (!NT_STATUS_IS_OK(status)) {
2879 goto done;
2882 status = rpccli_samr_OpenDomain(cli, mem_ctx,
2883 &connect_handle,
2884 SEC_FLAG_MAXIMUM_ALLOWED,
2885 &domain_sid,
2886 &domain_handle);
2888 if (!NT_STATUS_IS_OK(status))
2889 goto done;
2892 status = rpccli_samr_GetDisplayEnumerationIndex(cli, mem_ctx,
2893 &domain_handle,
2894 level,
2895 &name,
2896 &idx);
2898 if (NT_STATUS_IS_OK(status) ||
2899 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
2900 printf("idx: %d (0x%08x)\n", idx, idx);
2902 done:
2904 if (is_valid_policy_hnd(&domain_handle)) {
2905 rpccli_samr_Close(cli, mem_ctx, &domain_handle);
2907 if (is_valid_policy_hnd(&connect_handle)) {
2908 rpccli_samr_Close(cli, mem_ctx, &connect_handle);
2911 return status;
2914 /* List of commands exported by this module */
2916 struct cmd_set samr_commands[] = {
2918 { "SAMR" },
2920 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, &ndr_table_samr.syntax_id, NULL, "Query user info", "" },
2921 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, &ndr_table_samr.syntax_id, NULL, "Query group info", "" },
2922 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, &ndr_table_samr.syntax_id, NULL, "Query user groups", "" },
2923 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, &ndr_table_samr.syntax_id, NULL, "Query user aliases", "" },
2924 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query group membership", "" },
2925 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias membership", "" },
2926 { "queryaliasinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query alias info", "" },
2927 { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Delete an alias", "" },
2928 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2929 { "querydispinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2930 { "querydispinfo3", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3, NULL, &ndr_table_samr.syntax_id, NULL, "Query display info", "" },
2931 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, &ndr_table_samr.syntax_id, NULL, "Query domain info", "" },
2932 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain users", "" },
2933 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domain groups", "" },
2934 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate alias groups", "" },
2935 { "enumdomains", RPC_RTYPE_NTSTATUS, cmd_samr_enum_domains, NULL, &ndr_table_samr.syntax_id, NULL, "Enumerate domains", "" },
2937 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain user", "" },
2938 { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain group", "" },
2939 { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, &ndr_table_samr.syntax_id, NULL, "Create domain alias", "" },
2940 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2941 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, &ndr_table_samr.syntax_id, NULL, "Look up names", "" },
2942 { "deletedomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain group", "" },
2943 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, &ndr_table_samr.syntax_id, NULL, "Delete domain user", "" },
2944 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, &ndr_table_samr.syntax_id, NULL, "Query SAMR security object", "" },
2945 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve domain password info", "" },
2946 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Retrieve user domain password info", "" },
2948 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, &ndr_table_samr.syntax_id, NULL, "Lookup Domain Name", "" },
2949 { "chgpasswd", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2950 { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2951 { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, &ndr_table_samr.syntax_id, NULL, "Change user password", "" },
2952 { "getdispinfoidx", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispinfo_idx, NULL, &ndr_table_samr.syntax_id, NULL, "Get Display Information Index", "" },
2953 { "setuserinfo", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info", "" },
2954 { "setuserinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_setuserinfo2, NULL, &ndr_table_samr.syntax_id, NULL, "Set user info2", "" },
2955 { NULL }