Re-add support for the samr parameters string.
[ira/wip.git] / source / rpcclient / cmd_samr.c
1 /*
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4
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
10
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.
15
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.
20
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/>.
23 */
24
25 #include "includes.h"
26 #include "rpcclient.h"
27
28 extern DOM_SID domain_sid;
29
30 /****************************************************************************
31  display samr_user_info_7 structure
32  ****************************************************************************/
33 static void display_samr_user_info_7(struct samr_UserInfo7 *r)
34 {
35         printf("\tUser Name   :\t%s\n", r->account_name.string);
36 }
37
38 /****************************************************************************
39  display samr_user_info_9 structure
40  ****************************************************************************/
41 static void display_samr_user_info_9(struct samr_UserInfo9 *r)
42 {
43         printf("\tPrimary group RID   :\tox%x\n", r->primary_gid);
44 }
45
46 /****************************************************************************
47  display samr_user_info_16 structure
48  ****************************************************************************/
49 static void display_samr_user_info_16(struct samr_UserInfo16 *r)
50 {
51         printf("\tAcct Flags   :\tox%x\n", r->acct_flags);
52 }
53
54 /****************************************************************************
55  display samr_user_info_20 structure
56  ****************************************************************************/
57 static void display_samr_user_info_20(struct samr_UserInfo20 *r)
58 {
59         printf("\tRemote Dial :\n");
60         dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
61 }
62
63
64 /****************************************************************************
65  display samr_user_info_21 structure
66  ****************************************************************************/
67 static void display_samr_user_info_21(struct samr_UserInfo21 *r)
68 {
69         printf("\tUser Name   :\t%s\n", r->account_name.string);
70         printf("\tFull Name   :\t%s\n", r->full_name.string);
71         printf("\tHome Drive  :\t%s\n", r->home_directory.string);
72         printf("\tDir Drive   :\t%s\n", r->home_drive.string);
73         printf("\tProfile Path:\t%s\n", r->profile_path.string);
74         printf("\tLogon Script:\t%s\n", r->logon_script.string);
75         printf("\tDescription :\t%s\n", r->description.string);
76         printf("\tWorkstations:\t%s\n", r->workstations.string);
77         printf("\tComment     :\t%s\n", r->comment.string);
78         printf("\tRemote Dial :\n");
79         dump_data(0, (uint8_t *)r->parameters.array, r->parameters.length*2);
80
81         printf("\tLogon Time               :\t%s\n",
82                http_timestring(nt_time_to_unix(r->last_logon)));
83         printf("\tLogoff Time              :\t%s\n",
84                http_timestring(nt_time_to_unix(r->last_logoff)));
85         printf("\tKickoff Time             :\t%s\n",
86                http_timestring(nt_time_to_unix(r->acct_expiry)));
87         printf("\tPassword last set Time   :\t%s\n",
88                http_timestring(nt_time_to_unix(r->last_password_change)));
89         printf("\tPassword can change Time :\t%s\n",
90                http_timestring(nt_time_to_unix(r->allow_password_change)));
91         printf("\tPassword must change Time:\t%s\n",
92                http_timestring(nt_time_to_unix(r->force_password_change)));
93
94         printf("\tunknown_2[0..31]...\n"); /* user passwords? */
95
96         printf("\tuser_rid :\t0x%x\n"  , r->rid); /* User ID */
97         printf("\tgroup_rid:\t0x%x\n"  , r->primary_gid); /* Group ID */
98         printf("\tacb_info :\t0x%08x\n", r->acct_flags); /* Account Control Info */
99
100         printf("\tfields_present:\t0x%08x\n", r->fields_present); /* 0x00ff ffff */
101         printf("\tlogon_divs:\t%d\n", r->logon_hours.units_per_week); /* 0x0000 00a8 which is 168 which is num hrs in a week */
102         printf("\tbad_password_count:\t0x%08x\n", r->bad_password_count);
103         printf("\tlogon_count:\t0x%08x\n", r->logon_count);
104
105         printf("\tpadding1[0..7]...\n");
106
107         if (r->logon_hours.bits) {
108                 printf("\tlogon_hrs[0..%d]...\n", r->logon_hours.units_per_week/8);
109         }
110 }
111
112
113 static void display_password_properties(uint32_t password_properties)
114 {
115         printf("password_properties: 0x%08x\n", password_properties);
116
117         if (password_properties & DOMAIN_PASSWORD_COMPLEX)
118                 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
119
120         if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
121                 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
122
123         if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
124                 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
125
126         if (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)
127                 printf("\tDOMAIN_PASSWORD_LOCKOUT_ADMINS\n");
128
129         if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
130                 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
131
132         if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
133                 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
134 }
135
136 static void display_sam_dom_info_1(struct samr_DomInfo1 *info1)
137 {
138         printf("Minimum password length:\t\t\t%d\n",
139                 info1->min_password_length);
140         printf("Password uniqueness (remember x passwords):\t%d\n",
141                 info1->password_history_length);
142         display_password_properties(info1->password_properties);
143         printf("password expire in:\t\t\t\t%s\n",
144                 display_time(info1->max_password_age));
145         printf("Min password age (allow changing in x days):\t%s\n",
146                 display_time(info1->min_password_age));
147 }
148
149 static void display_sam_dom_info_2(struct samr_DomInfo2 *info2)
150 {
151         printf("Domain:\t\t%s\n", info2->domain_name.string);
152         printf("Server:\t\t%s\n", info2->primary.string);
153         printf("Comment:\t%s\n", info2->comment.string);
154
155         printf("Total Users:\t%d\n", info2->num_users);
156         printf("Total Groups:\t%d\n", info2->num_groups);
157         printf("Total Aliases:\t%d\n", info2->num_aliases);
158
159         printf("Sequence No:\t%llu\n", (unsigned long long)info2->sequence_num);
160
161         printf("Force Logoff:\t%d\n",
162                 (int)nt_time_to_unix_abs(&info2->force_logoff_time));
163
164         printf("Unknown 2:\t0x%x\n", info2->unknown2);
165         printf("Server Role:\t%s\n", server_role_str(info2->role));
166         printf("Unknown 3:\t0x%x\n", info2->unknown3);
167 }
168
169 static void display_sam_dom_info_3(struct samr_DomInfo3 *info3)
170 {
171         printf("Force Logoff:\t%d\n",
172                 (int)nt_time_to_unix_abs(&info3->force_logoff_time));
173 }
174
175 static void display_sam_dom_info_4(struct samr_DomInfo4 *info4)
176 {
177         printf("Comment:\t%s\n", info4->comment.string);
178 }
179
180 static void display_sam_dom_info_5(struct samr_DomInfo5 *info5)
181 {
182         printf("Domain:\t\t%s\n", info5->domain_name.string);
183 }
184
185 static void display_sam_dom_info_6(struct samr_DomInfo6 *info6)
186 {
187         printf("Server:\t\t%s\n", info6->primary.string);
188 }
189
190 static void display_sam_dom_info_7(struct samr_DomInfo7 *info7)
191 {
192         printf("Server Role:\t%s\n", server_role_str(info7->role));
193 }
194
195 static void display_sam_dom_info_8(struct samr_DomInfo8 *info8)
196 {
197         printf("Sequence No:\t%llu\n", (unsigned long long)info8->sequence_num);
198         printf("Domain Create Time:\t%s\n",
199                 http_timestring(nt_time_to_unix(info8->domain_create_time)));
200 }
201
202 static void display_sam_dom_info_9(struct samr_DomInfo9 *info9)
203 {
204         printf("unknown:\t%d (0x%08x)\n", info9->unknown, info9->unknown);
205 }
206
207 static void display_sam_dom_info_12(struct samr_DomInfo12 *info12)
208 {
209         printf("Bad password lockout duration:               %s\n",
210                 display_time(info12->lockout_duration));
211         printf("Reset Lockout after:                         %s\n",
212                 display_time(info12->lockout_window));
213         printf("Lockout after bad attempts:                  %d\n",
214                 info12->lockout_threshold);
215 }
216
217 static void display_sam_dom_info_13(struct samr_DomInfo13 *info13)
218 {
219         printf("Sequence No:\t%llu\n", (unsigned long long)info13->sequence_num);
220         printf("Domain Create Time:\t%s\n",
221                 http_timestring(nt_time_to_unix(info13->domain_create_time)));
222         printf("Unknown1:\t%d\n", info13->unknown1);
223         printf("Unknown2:\t%d\n", info13->unknown2);
224
225 }
226
227 static void display_sam_info_1(struct samr_DispEntryGeneral *r)
228 {
229         printf("index: 0x%x ", r->idx);
230         printf("RID: 0x%x ", r->rid);
231         printf("acb: 0x%08x ", r->acct_flags);
232         printf("Account: %s\t", r->account_name.string);
233         printf("Name: %s\t", r->full_name.string);
234         printf("Desc: %s\n", r->description.string);
235 }
236
237 static void display_sam_info_2(struct samr_DispEntryFull *r)
238 {
239         printf("index: 0x%x ", r->idx);
240         printf("RID: 0x%x ", r->rid);
241         printf("acb: 0x%08x ", r->acct_flags);
242         printf("Account: %s\t", r->account_name.string);
243         printf("Desc: %s\n", r->description.string);
244 }
245
246 static void display_sam_info_3(struct samr_DispEntryFullGroup *r)
247 {
248         printf("index: 0x%x ", r->idx);
249         printf("RID: 0x%x ", r->rid);
250         printf("acb: 0x%08x ", r->acct_flags);
251         printf("Account: %s\t", r->account_name.string);
252         printf("Desc: %s\n", r->description.string);
253 }
254
255 static void display_sam_info_4(struct samr_DispEntryAscii *r)
256 {
257         printf("index: 0x%x ", r->idx);
258         printf("Account: %s\n", r->account_name.string);
259 }
260
261 static void display_sam_info_5(struct samr_DispEntryAscii *r)
262 {
263         printf("index: 0x%x ", r->idx);
264         printf("Account: %s\n", r->account_name.string);
265 }
266
267 /****************************************************************************
268  Try samr_connect4 first, then samr_connect2 if it fails
269  ****************************************************************************/
270 static NTSTATUS try_samr_connects(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
271                                   uint32 access_mask, POLICY_HND *connect_pol)
272 {
273         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
274
275         result = rpccli_samr_Connect4(cli, mem_ctx,
276                                       cli->cli->desthost,
277                                       SAMR_CONNECT_W2K,
278                                       access_mask,
279                                       connect_pol);
280         if (!NT_STATUS_IS_OK(result)) {
281                 result = rpccli_samr_Connect2(cli, mem_ctx,
282                                               cli->cli->desthost,
283                                               access_mask,
284                                               connect_pol);
285         }
286         return result;
287 }
288
289 /**********************************************************************
290  * Query user information
291  */
292 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
293                                     TALLOC_CTX *mem_ctx,
294                                     int argc, const char **argv)
295 {
296         POLICY_HND connect_pol, domain_pol, user_pol;
297         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
298         uint32 info_level = 21;
299         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
300         union samr_UserInfo *info = NULL;
301         fstring server;
302         uint32 user_rid = 0;
303
304         if ((argc < 2) || (argc > 4)) {
305                 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
306                 return NT_STATUS_OK;
307         }
308
309         sscanf(argv[1], "%i", &user_rid);
310
311         if (argc > 2)
312                 sscanf(argv[2], "%i", &info_level);
313
314         if (argc > 3)
315                 sscanf(argv[3], "%x", &access_mask);
316
317
318         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
319         strupper_m(server);
320
321         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
322                                    &connect_pol);
323
324         if (!NT_STATUS_IS_OK(result))
325                 goto done;
326
327         result = rpccli_samr_OpenDomain(cli, mem_ctx,
328                                         &connect_pol,
329                                         MAXIMUM_ALLOWED_ACCESS,
330                                         &domain_sid,
331                                         &domain_pol);
332         if (!NT_STATUS_IS_OK(result))
333                 goto done;
334
335         result = rpccli_samr_OpenUser(cli, mem_ctx,
336                                       &domain_pol,
337                                       access_mask,
338                                       user_rid,
339                                       &user_pol);
340
341         if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
342             (user_rid == 0)) {
343
344                 /* Probably this was a user name, try lookupnames */
345                 struct samr_Ids rids, types;
346                 struct lsa_String lsa_acct_name;
347
348                 init_lsa_String(&lsa_acct_name, argv[1]);
349
350                 result = rpccli_samr_LookupNames(cli, mem_ctx,
351                                                  &domain_pol,
352                                                  1,
353                                                  &lsa_acct_name,
354                                                  &rids,
355                                                  &types);
356
357                 if (NT_STATUS_IS_OK(result)) {
358                         result = rpccli_samr_OpenUser(cli, mem_ctx,
359                                                       &domain_pol,
360                                                       access_mask,
361                                                       rids.ids[0],
362                                                       &user_pol);
363                 }
364         }
365
366
367         if (!NT_STATUS_IS_OK(result))
368                 goto done;
369
370         result = rpccli_samr_QueryUserInfo(cli, mem_ctx,
371                                            &user_pol,
372                                            info_level,
373                                            &info);
374
375         if (!NT_STATUS_IS_OK(result))
376                 goto done;
377
378         switch (info_level) {
379         case 7:
380                 display_samr_user_info_7(&info->info7);
381                 break;
382         case 9:
383                 display_samr_user_info_9(&info->info9);
384                 break;
385         case 16:
386                 display_samr_user_info_16(&info->info16);
387                 break;
388         case 20:
389                 display_samr_user_info_20(&info->info20);
390                 break;
391         case 21:
392                 display_samr_user_info_21(&info->info21);
393                 break;
394         default:
395                 printf("Unsupported infolevel: %d\n", info_level);
396                 break;
397         }
398
399         rpccli_samr_Close(cli, mem_ctx, &user_pol);
400         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
401         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
402
403 done:
404         return result;
405 }
406
407 /****************************************************************************
408  display group info
409  ****************************************************************************/
410 static void display_group_info1(struct samr_GroupInfoAll *info1)
411 {
412         printf("\tGroup Name:\t%s\n", info1->name.string);
413         printf("\tDescription:\t%s\n", info1->description.string);
414         printf("\tGroup Attribute:%d\n", info1->attributes);
415         printf("\tNum Members:%d\n", info1->num_members);
416 }
417
418 /****************************************************************************
419  display group info
420  ****************************************************************************/
421 static void display_group_info2(struct lsa_String *info2)
422 {
423         printf("\tGroup Description:%s\n", info2->string);
424 }
425
426
427 /****************************************************************************
428  display group info
429  ****************************************************************************/
430 static void display_group_info3(struct samr_GroupInfoAttributes *info3)
431 {
432         printf("\tGroup Attribute:%d\n", info3->attributes);
433 }
434
435
436 /****************************************************************************
437  display group info
438  ****************************************************************************/
439 static void display_group_info4(struct lsa_String *info4)
440 {
441         printf("\tGroup Description:%s\n", info4->string);
442 }
443
444 /****************************************************************************
445  display group info
446  ****************************************************************************/
447 static void display_group_info5(struct samr_GroupInfoAll *info5)
448 {
449         printf("\tGroup Name:\t%s\n", info5->name.string);
450         printf("\tDescription:\t%s\n", info5->description.string);
451         printf("\tGroup Attribute:%d\n", info5->attributes);
452         printf("\tNum Members:%d\n", info5->num_members);
453 }
454
455 /****************************************************************************
456  display sam sync structure
457  ****************************************************************************/
458 static void display_group_info(union samr_GroupInfo *info,
459                                enum samr_GroupInfoEnum level)
460 {
461         switch (level) {
462                 case 1:
463                         display_group_info1(&info->all);
464                         break;
465                 case 2:
466                         display_group_info2(&info->name);
467                         break;
468                 case 3:
469                         display_group_info3(&info->attributes);
470                         break;
471                 case 4:
472                         display_group_info4(&info->description);
473                         break;
474                 case 5:
475                         display_group_info5(&info->all2);
476                         break;
477         }
478 }
479
480 /***********************************************************************
481  * Query group information
482  */
483 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
484                                      TALLOC_CTX *mem_ctx,
485                                      int argc, const char **argv)
486 {
487         POLICY_HND connect_pol, domain_pol, group_pol;
488         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
489         enum samr_GroupInfoEnum info_level = GROUPINFOALL;
490         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
491         union samr_GroupInfo *group_info = NULL;
492         fstring                 server;
493         uint32 group_rid;
494
495         if ((argc < 2) || (argc > 4)) {
496                 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
497                 return NT_STATUS_OK;
498         }
499
500         sscanf(argv[1], "%i", &group_rid);
501
502         if (argc > 2)
503                 info_level = atoi(argv[2]);
504
505         if (argc > 3)
506                 sscanf(argv[3], "%x", &access_mask);
507
508         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
509         strupper_m(server);
510
511         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
512                                    &connect_pol);
513
514         if (!NT_STATUS_IS_OK(result))
515                 goto done;
516
517         result = rpccli_samr_OpenDomain(cli, mem_ctx,
518                                         &connect_pol,
519                                         MAXIMUM_ALLOWED_ACCESS,
520                                         &domain_sid,
521                                         &domain_pol);
522
523         if (!NT_STATUS_IS_OK(result))
524                 goto done;
525
526         result = rpccli_samr_OpenGroup(cli, mem_ctx,
527                                        &domain_pol,
528                                        access_mask,
529                                        group_rid,
530                                        &group_pol);
531
532         if (!NT_STATUS_IS_OK(result))
533                 goto done;
534
535         result = rpccli_samr_QueryGroupInfo(cli, mem_ctx,
536                                             &group_pol,
537                                             info_level,
538                                             &group_info);
539         if (!NT_STATUS_IS_OK(result)) {
540                 goto done;
541         }
542
543         display_group_info(group_info, info_level);
544
545         rpccli_samr_Close(cli, mem_ctx, &group_pol);
546         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
547         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
548 done:
549         return result;
550 }
551
552 /* Query groups a user is a member of */
553
554 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
555                                           TALLOC_CTX *mem_ctx,
556                                           int argc, const char **argv)
557 {
558         POLICY_HND              connect_pol,
559                                 domain_pol,
560                                 user_pol;
561         NTSTATUS                result = NT_STATUS_UNSUCCESSFUL;
562         uint32                  user_rid;
563         uint32                  access_mask = MAXIMUM_ALLOWED_ACCESS;
564         int                     i;
565         fstring                 server;
566         struct samr_RidWithAttributeArray *rid_array = NULL;
567
568         if ((argc < 2) || (argc > 3)) {
569                 printf("Usage: %s rid [access mask]\n", argv[0]);
570                 return NT_STATUS_OK;
571         }
572
573         sscanf(argv[1], "%i", &user_rid);
574
575         if (argc > 2)
576                 sscanf(argv[2], "%x", &access_mask);
577
578         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
579         strupper_m(server);
580
581         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
582                                    &connect_pol);
583
584         if (!NT_STATUS_IS_OK(result))
585                 goto done;
586
587         result = rpccli_samr_OpenDomain(cli, mem_ctx,
588                                         &connect_pol,
589                                         MAXIMUM_ALLOWED_ACCESS,
590                                         &domain_sid, &domain_pol);
591
592         if (!NT_STATUS_IS_OK(result))
593                 goto done;
594
595         result = rpccli_samr_OpenUser(cli, mem_ctx,
596                                       &domain_pol,
597                                       access_mask,
598                                       user_rid,
599                                       &user_pol);
600
601         if (!NT_STATUS_IS_OK(result))
602                 goto done;
603
604         result = rpccli_samr_GetGroupsForUser(cli, mem_ctx,
605                                               &user_pol,
606                                               &rid_array);
607
608         if (!NT_STATUS_IS_OK(result))
609                 goto done;
610
611         for (i = 0; i < rid_array->count; i++) {
612                 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
613                        rid_array->rids[i].rid,
614                        rid_array->rids[i].attributes);
615         }
616
617         rpccli_samr_Close(cli, mem_ctx, &user_pol);
618         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
619         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
620  done:
621         return result;
622 }
623
624 /* Query aliases a user is a member of */
625
626 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
627                                            TALLOC_CTX *mem_ctx,
628                                            int argc, const char **argv)
629 {
630         POLICY_HND              connect_pol, domain_pol;
631         NTSTATUS                result = NT_STATUS_UNSUCCESSFUL;
632         DOM_SID                *sids;
633         size_t                     num_sids;
634         uint32                  access_mask = MAXIMUM_ALLOWED_ACCESS;
635         int                     i;
636         fstring                 server;
637         struct lsa_SidArray sid_array;
638         struct samr_Ids alias_rids;
639
640         if (argc < 3) {
641                 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
642                 return NT_STATUS_INVALID_PARAMETER;
643         }
644
645         sids = NULL;
646         num_sids = 0;
647
648         for (i=2; i<argc; i++) {
649                 DOM_SID tmp_sid;
650                 if (!string_to_sid(&tmp_sid, argv[i])) {
651                         printf("%s is not a legal SID\n", argv[i]);
652                         return NT_STATUS_INVALID_PARAMETER;
653                 }
654                 result = add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
655                 if (!NT_STATUS_IS_OK(result)) {
656                         return result;
657                 }
658         }
659
660         if (num_sids) {
661                 sid_array.sids = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_SidPtr, num_sids);
662                 if (sid_array.sids == NULL)
663                         return NT_STATUS_NO_MEMORY;
664         } else {
665                 sid_array.sids = NULL;
666         }
667
668         for (i=0; i<num_sids; i++) {
669                 sid_array.sids[i].sid = sid_dup_talloc(mem_ctx, &sids[i]);
670                 if (!sid_array.sids[i].sid) {
671                         return NT_STATUS_NO_MEMORY;
672                 }
673         }
674
675         sid_array.num_sids = num_sids;
676
677         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
678         strupper_m(server);
679
680         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
681                                    &connect_pol);
682
683         if (!NT_STATUS_IS_OK(result))
684                 goto done;
685
686         if (StrCaseCmp(argv[1], "domain")==0)
687                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
688                                                 &connect_pol,
689                                                 access_mask,
690                                                 &domain_sid, &domain_pol);
691         else if (StrCaseCmp(argv[1], "builtin")==0)
692                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
693                                                 &connect_pol,
694                                                 access_mask,
695                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
696                                                 &domain_pol);
697         else {
698                 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
699                 return NT_STATUS_INVALID_PARAMETER;
700         }
701
702         if (!NT_STATUS_IS_OK(result))
703                 goto done;
704
705         result = rpccli_samr_GetAliasMembership(cli, mem_ctx,
706                                                 &domain_pol,
707                                                 &sid_array,
708                                                 &alias_rids);
709         if (!NT_STATUS_IS_OK(result))
710                 goto done;
711
712         for (i = 0; i < alias_rids.count; i++) {
713                 printf("\tgroup rid:[0x%x]\n", alias_rids.ids[i]);
714         }
715
716         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
717         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
718  done:
719         return result;
720 }
721
722 /* Query members of a group */
723
724 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
725                                         TALLOC_CTX *mem_ctx,
726                                         int argc, const char **argv)
727 {
728         POLICY_HND connect_pol, domain_pol, group_pol;
729         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
730         uint32 group_rid;
731         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
732         int i;
733         fstring                 server;
734         unsigned int old_timeout;
735         struct samr_RidTypeArray *rids = NULL;
736
737         if ((argc < 2) || (argc > 3)) {
738                 printf("Usage: %s rid [access mask]\n", argv[0]);
739                 return NT_STATUS_OK;
740         }
741
742         sscanf(argv[1], "%i", &group_rid);
743
744         if (argc > 2)
745                 sscanf(argv[2], "%x", &access_mask);
746
747         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
748         strupper_m(server);
749
750         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
751                                    &connect_pol);
752
753         if (!NT_STATUS_IS_OK(result))
754                 goto done;
755
756         result = rpccli_samr_OpenDomain(cli, mem_ctx,
757                                         &connect_pol,
758                                         MAXIMUM_ALLOWED_ACCESS,
759                                         &domain_sid,
760                                         &domain_pol);
761
762         if (!NT_STATUS_IS_OK(result))
763                 goto done;
764
765         result = rpccli_samr_OpenGroup(cli, mem_ctx,
766                                        &domain_pol,
767                                        access_mask,
768                                        group_rid,
769                                        &group_pol);
770
771         if (!NT_STATUS_IS_OK(result))
772                 goto done;
773
774         /* Make sure to wait for our DC's reply */
775         old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000)); /* 30 seconds. */
776
777         result = rpccli_samr_QueryGroupMember(cli, mem_ctx,
778                                               &group_pol,
779                                               &rids);
780
781         cli_set_timeout(cli->cli, old_timeout);
782
783         if (!NT_STATUS_IS_OK(result))
784                 goto done;
785
786         for (i = 0; i < rids->count; i++) {
787                 printf("\trid:[0x%x] attr:[0x%x]\n", rids->rids[i],
788                        rids->types[i]);
789         }
790
791         rpccli_samr_Close(cli, mem_ctx, &group_pol);
792         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
793         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
794  done:
795         return result;
796 }
797
798 /* Enumerate domain users */
799
800 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
801                                         TALLOC_CTX *mem_ctx,
802                                         int argc, const char **argv)
803 {
804         POLICY_HND connect_pol, domain_pol;
805         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
806         uint32 start_idx, size, num_dom_users, i;
807         struct samr_SamArray *dom_users = NULL;
808         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
809         uint32 acb_mask = ACB_NORMAL;
810         bool got_connect_pol = False, got_domain_pol = False;
811
812         if ((argc < 1) || (argc > 3)) {
813                 printf("Usage: %s [access_mask] [acb_mask]\n", argv[0]);
814                 return NT_STATUS_OK;
815         }
816
817         if (argc > 1)
818                 sscanf(argv[1], "%x", &access_mask);
819
820         if (argc > 2)
821                 sscanf(argv[2], "%x", &acb_mask);
822
823         /* Get sam policy handle */
824
825         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
826                                    &connect_pol);
827
828         if (!NT_STATUS_IS_OK(result))
829                 goto done;
830
831         got_connect_pol = True;
832
833         /* Get domain policy handle */
834
835         result = rpccli_samr_OpenDomain(cli, mem_ctx,
836                                         &connect_pol,
837                                         access_mask,
838                                         &domain_sid,
839                                         &domain_pol);
840
841         if (!NT_STATUS_IS_OK(result))
842                 goto done;
843
844         got_domain_pol = True;
845
846         /* Enumerate domain users */
847
848         start_idx = 0;
849         size = 0xffff;
850
851         do {
852                 result = rpccli_samr_EnumDomainUsers(cli, mem_ctx,
853                                                      &domain_pol,
854                                                      &start_idx,
855                                                      acb_mask,
856                                                      &dom_users,
857                                                      size,
858                                                      &num_dom_users);
859
860                 if (NT_STATUS_IS_OK(result) ||
861                     NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
862
863                         for (i = 0; i < num_dom_users; i++)
864                                printf("user:[%s] rid:[0x%x]\n",
865                                        dom_users->entries[i].name.string,
866                                        dom_users->entries[i].idx);
867                 }
868
869         } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
870
871  done:
872         if (got_domain_pol)
873                 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
874
875         if (got_connect_pol)
876                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
877
878         return result;
879 }
880
881 /* Enumerate domain groups */
882
883 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
884                                          TALLOC_CTX *mem_ctx,
885                                          int argc, const char **argv)
886 {
887         POLICY_HND connect_pol, domain_pol;
888         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
889         uint32 start_idx, size, num_dom_groups, i;
890         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
891         struct samr_SamArray *dom_groups = NULL;
892         bool got_connect_pol = False, got_domain_pol = False;
893
894         if ((argc < 1) || (argc > 2)) {
895                 printf("Usage: %s [access_mask]\n", argv[0]);
896                 return NT_STATUS_OK;
897         }
898
899         if (argc > 1)
900                 sscanf(argv[1], "%x", &access_mask);
901
902         /* Get sam policy handle */
903
904         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
905                                    &connect_pol);
906
907         if (!NT_STATUS_IS_OK(result))
908                 goto done;
909
910         got_connect_pol = True;
911
912         /* Get domain policy handle */
913
914         result = rpccli_samr_OpenDomain(cli, mem_ctx,
915                                         &connect_pol,
916                                         access_mask,
917                                         &domain_sid,
918                                         &domain_pol);
919
920         if (!NT_STATUS_IS_OK(result))
921                 goto done;
922
923         got_domain_pol = True;
924
925         /* Enumerate domain groups */
926
927         start_idx = 0;
928         size = 0xffff;
929
930         do {
931                 result = rpccli_samr_EnumDomainGroups(cli, mem_ctx,
932                                                       &domain_pol,
933                                                       &start_idx,
934                                                       &dom_groups,
935                                                       size,
936                                                       &num_dom_groups);
937                 if (NT_STATUS_IS_OK(result) ||
938                     NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
939
940                         for (i = 0; i < num_dom_groups; i++)
941                                 printf("group:[%s] rid:[0x%x]\n",
942                                        dom_groups->entries[i].name.string,
943                                        dom_groups->entries[i].idx);
944                 }
945
946         } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
947
948  done:
949         if (got_domain_pol)
950                 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
951
952         if (got_connect_pol)
953                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
954
955         return result;
956 }
957
958 /* Enumerate alias groups */
959
960 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
961                                          TALLOC_CTX *mem_ctx,
962                                          int argc, const char **argv)
963 {
964         POLICY_HND connect_pol, domain_pol;
965         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
966         uint32 start_idx, size, num_als_groups, i;
967         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
968         struct samr_SamArray *als_groups = NULL;
969         bool got_connect_pol = False, got_domain_pol = False;
970
971         if ((argc < 2) || (argc > 3)) {
972                 printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
973                 return NT_STATUS_OK;
974         }
975
976         if (argc > 2)
977                 sscanf(argv[2], "%x", &access_mask);
978
979         /* Get sam policy handle */
980
981         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
982                                    &connect_pol);
983
984         if (!NT_STATUS_IS_OK(result))
985                 goto done;
986
987         got_connect_pol = True;
988
989         /* Get domain policy handle */
990
991         if (StrCaseCmp(argv[1], "domain")==0)
992                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
993                                                 &connect_pol,
994                                                 access_mask,
995                                                 &domain_sid,
996                                                 &domain_pol);
997         else if (StrCaseCmp(argv[1], "builtin")==0)
998                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
999                                                 &connect_pol,
1000                                                 access_mask,
1001                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
1002                                                 &domain_pol);
1003         else
1004                 return NT_STATUS_OK;
1005
1006         if (!NT_STATUS_IS_OK(result))
1007                 goto done;
1008
1009         got_domain_pol = True;
1010
1011         /* Enumerate alias groups */
1012
1013         start_idx = 0;
1014         size = 0xffff;          /* Number of groups to retrieve */
1015
1016         do {
1017                 result = rpccli_samr_EnumDomainAliases(cli, mem_ctx,
1018                                                        &domain_pol,
1019                                                        &start_idx,
1020                                                        &als_groups,
1021                                                        size,
1022                                                        &num_als_groups);
1023
1024                 if (NT_STATUS_IS_OK(result) ||
1025                     NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1026
1027                         for (i = 0; i < num_als_groups; i++)
1028                                 printf("group:[%s] rid:[0x%x]\n",
1029                                        als_groups->entries[i].name.string,
1030                                        als_groups->entries[i].idx);
1031                 }
1032         } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1033
1034  done:
1035         if (got_domain_pol)
1036                 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1037
1038         if (got_connect_pol)
1039                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1040
1041         return result;
1042 }
1043
1044 /* Enumerate domains */
1045
1046 static NTSTATUS cmd_samr_enum_domains(struct rpc_pipe_client *cli,
1047                                       TALLOC_CTX *mem_ctx,
1048                                       int argc, const char **argv)
1049 {
1050         POLICY_HND connect_pol;
1051         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1052         uint32 start_idx, size, num_entries, i;
1053         uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1054         bool got_connect_pol = false;
1055         struct samr_SamArray *sam = NULL;
1056
1057         if ((argc < 1) || (argc > 2)) {
1058                 printf("Usage: %s [access mask]\n", argv[0]);
1059                 return NT_STATUS_OK;
1060         }
1061
1062         if (argc > 1) {
1063                 sscanf(argv[1], "%x", &access_mask);
1064         }
1065
1066         /* Get sam policy handle */
1067
1068         result = try_samr_connects(cli, mem_ctx,
1069                                    access_mask,
1070                                    &connect_pol);
1071
1072         if (!NT_STATUS_IS_OK(result)) {
1073                 goto done;
1074         }
1075
1076         got_connect_pol = true;
1077
1078         /* Enumerate alias groups */
1079
1080         start_idx = 0;
1081         size = 0xffff;
1082
1083         do {
1084                 result = rpccli_samr_EnumDomains(cli, mem_ctx,
1085                                                  &connect_pol,
1086                                                  &start_idx,
1087                                                  &sam,
1088                                                  size,
1089                                                  &num_entries);
1090
1091                 if (NT_STATUS_IS_OK(result) ||
1092                     NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
1093
1094                         for (i = 0; i < num_entries; i++)
1095                                 printf("name:[%s] idx:[0x%x]\n",
1096                                        sam->entries[i].name.string,
1097                                        sam->entries[i].idx);
1098                 }
1099         } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
1100
1101  done:
1102         if (got_connect_pol) {
1103                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1104         }
1105
1106         return result;
1107 }
1108
1109
1110 /* Query alias membership */
1111
1112 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
1113                                         TALLOC_CTX *mem_ctx,
1114                                         int argc, const char **argv)
1115 {
1116         POLICY_HND connect_pol, domain_pol, alias_pol;
1117         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1118         uint32 alias_rid, i;
1119         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1120         struct lsa_SidArray sid_array;
1121
1122         if ((argc < 3) || (argc > 4)) {
1123                 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
1124                 return NT_STATUS_OK;
1125         }
1126
1127         sscanf(argv[2], "%i", &alias_rid);
1128
1129         if (argc > 3)
1130                 sscanf(argv[3], "%x", &access_mask);
1131
1132         /* Open SAMR handle */
1133
1134         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1135                                    &connect_pol);
1136
1137         if (!NT_STATUS_IS_OK(result))
1138                 goto done;
1139
1140         /* Open handle on domain */
1141
1142         if (StrCaseCmp(argv[1], "domain")==0)
1143                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1144                                                 &connect_pol,
1145                                                 MAXIMUM_ALLOWED_ACCESS,
1146                                                 &domain_sid,
1147                                                 &domain_pol);
1148         else if (StrCaseCmp(argv[1], "builtin")==0)
1149                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1150                                                 &connect_pol,
1151                                                 MAXIMUM_ALLOWED_ACCESS,
1152                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
1153                                                 &domain_pol);
1154         else
1155                 return NT_STATUS_OK;
1156
1157         if (!NT_STATUS_IS_OK(result))
1158                 goto done;
1159
1160         /* Open handle on alias */
1161
1162         result = rpccli_samr_OpenAlias(cli, mem_ctx,
1163                                        &domain_pol,
1164                                        access_mask,
1165                                        alias_rid,
1166                                        &alias_pol);
1167         if (!NT_STATUS_IS_OK(result))
1168                 goto done;
1169
1170         result = rpccli_samr_GetMembersInAlias(cli, mem_ctx,
1171                                                &alias_pol,
1172                                                &sid_array);
1173
1174         if (!NT_STATUS_IS_OK(result))
1175                 goto done;
1176
1177         for (i = 0; i < sid_array.num_sids; i++) {
1178                 fstring sid_str;
1179
1180                 sid_to_fstring(sid_str, sid_array.sids[i].sid);
1181                 printf("\tsid:[%s]\n", sid_str);
1182         }
1183
1184         rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1185         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1186         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1187  done:
1188         return result;
1189 }
1190
1191 /* Query alias info */
1192
1193 static NTSTATUS cmd_samr_query_aliasinfo(struct rpc_pipe_client *cli,
1194                                          TALLOC_CTX *mem_ctx,
1195                                          int argc, const char **argv)
1196 {
1197         POLICY_HND connect_pol, domain_pol, alias_pol;
1198         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1199         uint32_t alias_rid;
1200         uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1201         union samr_AliasInfo *info = NULL;
1202         enum samr_AliasInfoEnum level = ALIASINFOALL;
1203
1204         if ((argc < 3) || (argc > 4)) {
1205                 printf("Usage: %s builtin|domain rid [level] [access mask]\n",
1206                         argv[0]);
1207                 return NT_STATUS_OK;
1208         }
1209
1210         sscanf(argv[2], "%i", &alias_rid);
1211
1212         if (argc > 2) {
1213                 level = atoi(argv[3]);
1214         }
1215
1216         if (argc > 3) {
1217                 sscanf(argv[4], "%x", &access_mask);
1218         }
1219
1220         /* Open SAMR handle */
1221
1222         result = try_samr_connects(cli, mem_ctx,
1223                                    SEC_FLAG_MAXIMUM_ALLOWED,
1224                                    &connect_pol);
1225
1226         if (!NT_STATUS_IS_OK(result)) {
1227                 goto done;
1228         }
1229
1230         /* Open handle on domain */
1231
1232         if (strequal(argv[1], "domain")) {
1233
1234                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1235                                                 &connect_pol,
1236                                                 SEC_FLAG_MAXIMUM_ALLOWED,
1237                                                 &domain_sid,
1238                                                 &domain_pol);
1239
1240         } else if (strequal(argv[1], "builtin")) {
1241
1242                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1243                                                 &connect_pol,
1244                                                 SEC_FLAG_MAXIMUM_ALLOWED,
1245                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
1246                                                 &domain_pol);
1247
1248         } else {
1249                 return NT_STATUS_OK;
1250         }
1251
1252         if (!NT_STATUS_IS_OK(result)) {
1253                 goto done;
1254         }
1255
1256         /* Open handle on alias */
1257
1258         result = rpccli_samr_OpenAlias(cli, mem_ctx,
1259                                        &domain_pol,
1260                                        access_mask,
1261                                        alias_rid,
1262                                        &alias_pol);
1263         if (!NT_STATUS_IS_OK(result)) {
1264                 goto done;
1265         }
1266
1267         result = rpccli_samr_QueryAliasInfo(cli, mem_ctx,
1268                                             &alias_pol,
1269                                             level,
1270                                             &info);
1271
1272         if (!NT_STATUS_IS_OK(result)) {
1273                 goto done;
1274         }
1275
1276         switch (level) {
1277                 case ALIASINFOALL:
1278                         printf("Name: %s\n", info->all.name.string);
1279                         printf("Description: %s\n", info->all.description.string);
1280                         printf("Num Members: %d\n", info->all.num_members);
1281                         break;
1282                 case ALIASINFONAME:
1283                         printf("Name: %s\n", info->name.string);
1284                         break;
1285                 case ALIASINFODESCRIPTION:
1286                         printf("Description: %s\n", info->description.string);
1287                         break;
1288                 default:
1289                         break;
1290         }
1291
1292         rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1293         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1294         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1295  done:
1296         return result;
1297 }
1298
1299
1300 /* Query delete an alias membership */
1301
1302 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
1303                                       TALLOC_CTX *mem_ctx,
1304                                       int argc, const char **argv)
1305 {
1306         POLICY_HND connect_pol, domain_pol, alias_pol;
1307         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1308         uint32 alias_rid;
1309         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1310
1311         if (argc != 3) {
1312                 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
1313                 return NT_STATUS_OK;
1314         }
1315
1316         alias_rid = strtoul(argv[2], NULL, 10);
1317
1318         /* Open SAMR handle */
1319
1320         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1321                                    &connect_pol);
1322
1323         if (!NT_STATUS_IS_OK(result))
1324                 goto done;
1325
1326         /* Open handle on domain */
1327
1328         if (StrCaseCmp(argv[1], "domain")==0)
1329                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1330                                                 &connect_pol,
1331                                                 MAXIMUM_ALLOWED_ACCESS,
1332                                                 &domain_sid,
1333                                                 &domain_pol);
1334         else if (StrCaseCmp(argv[1], "builtin")==0)
1335                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1336                                                 &connect_pol,
1337                                                 MAXIMUM_ALLOWED_ACCESS,
1338                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
1339                                                 &domain_pol);
1340         else
1341                 return NT_STATUS_INVALID_PARAMETER;
1342
1343         if (!NT_STATUS_IS_OK(result))
1344                 goto done;
1345
1346         /* Open handle on alias */
1347
1348         result = rpccli_samr_OpenAlias(cli, mem_ctx,
1349                                        &domain_pol,
1350                                        access_mask,
1351                                        alias_rid,
1352                                        &alias_pol);
1353         if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
1354                 /* Probably this was a user name, try lookupnames */
1355                 struct samr_Ids rids, types;
1356                 struct lsa_String lsa_acct_name;
1357
1358                 init_lsa_String(&lsa_acct_name, argv[2]);
1359
1360                 result = rpccli_samr_LookupNames(cli, mem_ctx,
1361                                                  &domain_pol,
1362                                                  1,
1363                                                  &lsa_acct_name,
1364                                                  &rids,
1365                                                  &types);
1366
1367                 if (NT_STATUS_IS_OK(result)) {
1368                         result = rpccli_samr_OpenAlias(cli, mem_ctx,
1369                                                        &domain_pol,
1370                                                        access_mask,
1371                                                        rids.ids[0],
1372                                                        &alias_pol);
1373                 }
1374         }
1375
1376         result = rpccli_samr_DeleteDomAlias(cli, mem_ctx,
1377                                             &alias_pol);
1378
1379         if (!NT_STATUS_IS_OK(result))
1380                 goto done;
1381
1382         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1383         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1384  done:
1385         return result;
1386 }
1387
1388 /* Query display info */
1389
1390 static NTSTATUS cmd_samr_query_dispinfo_internal(struct rpc_pipe_client *cli,
1391                                                  TALLOC_CTX *mem_ctx,
1392                                                  int argc, const char **argv,
1393                                                  uint32_t opcode)
1394 {
1395         POLICY_HND connect_pol, domain_pol;
1396         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1397         uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries = 0, i;
1398         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1399         uint32 info_level = 1;
1400         union samr_DispInfo info;
1401         int loop_count = 0;
1402         bool got_params = False; /* Use get_query_dispinfo_params() or not? */
1403         uint32_t total_size, returned_size;
1404
1405         if (argc > 6) {
1406                 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
1407                 return NT_STATUS_OK;
1408         }
1409
1410         if (argc >= 2)
1411                 sscanf(argv[1], "%i", &info_level);
1412
1413         if (argc >= 3)
1414                 sscanf(argv[2], "%i", &start_idx);
1415
1416         if (argc >= 4) {
1417                 sscanf(argv[3], "%i", &max_entries);
1418                 got_params = True;
1419         }
1420
1421         if (argc >= 5) {
1422                 sscanf(argv[4], "%i", &max_size);
1423                 got_params = True;
1424         }
1425
1426         if (argc >= 6)
1427                 sscanf(argv[5], "%x", &access_mask);
1428
1429         /* Get sam policy handle */
1430
1431         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1432                                    &connect_pol);
1433
1434         if (!NT_STATUS_IS_OK(result))
1435                 goto done;
1436
1437         /* Get domain policy handle */
1438
1439         result = rpccli_samr_OpenDomain(cli, mem_ctx,
1440                                         &connect_pol,
1441                                         access_mask,
1442                                         &domain_sid,
1443                                         &domain_pol);
1444
1445         if (!NT_STATUS_IS_OK(result))
1446                 goto done;
1447
1448         /* Query display info */
1449
1450         do {
1451
1452                 if (!got_params)
1453                         get_query_dispinfo_params(
1454                                 loop_count, &max_entries, &max_size);
1455
1456                 switch (opcode) {
1457                 case NDR_SAMR_QUERYDISPLAYINFO:
1458                         result = rpccli_samr_QueryDisplayInfo(cli, mem_ctx,
1459                                                               &domain_pol,
1460                                                               info_level,
1461                                                               start_idx,
1462                                                               max_entries,
1463                                                               max_size,
1464                                                               &total_size,
1465                                                               &returned_size,
1466                                                               &info);
1467                         break;
1468                 case NDR_SAMR_QUERYDISPLAYINFO2:
1469                         result = rpccli_samr_QueryDisplayInfo2(cli, mem_ctx,
1470                                                                &domain_pol,
1471                                                                info_level,
1472                                                                start_idx,
1473                                                                max_entries,
1474                                                                max_size,
1475                                                                &total_size,
1476                                                                &returned_size,
1477                                                                &info);
1478
1479                         break;
1480                 case NDR_SAMR_QUERYDISPLAYINFO3:
1481                         result = rpccli_samr_QueryDisplayInfo3(cli, mem_ctx,
1482                                                                &domain_pol,
1483                                                                info_level,
1484                                                                start_idx,
1485                                                                max_entries,
1486                                                                max_size,
1487                                                                &total_size,
1488                                                                &returned_size,
1489                                                                &info);
1490
1491                         break;
1492                 default:
1493                         return NT_STATUS_INVALID_PARAMETER;
1494                 }
1495
1496                 if (!NT_STATUS_IS_OK(result) &&
1497                     !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
1498                     !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
1499                         break;
1500                 }
1501
1502                 loop_count++;
1503
1504                 switch (info_level) {
1505                         case 1:
1506                                 num_entries = info.info1.count;
1507                                 break;
1508                         case 2:
1509                                 num_entries = info.info2.count;
1510                                 break;
1511                         case 3:
1512                                 num_entries = info.info3.count;
1513                                 break;
1514                         case 4:
1515                                 num_entries = info.info4.count;
1516                                 break;
1517                         case 5:
1518                                 num_entries = info.info5.count;
1519                                 break;
1520                         default:
1521                                 break;
1522                 }
1523
1524                 start_idx += num_entries;
1525
1526                 if (num_entries == 0)
1527                         break;
1528
1529                 for (i = 0; i < num_entries; i++) {
1530                         switch (info_level) {
1531                         case 1:
1532                                 display_sam_info_1(&info.info1.entries[i]);
1533                                 break;
1534                         case 2:
1535                                 display_sam_info_2(&info.info2.entries[i]);
1536                                 break;
1537                         case 3:
1538                                 display_sam_info_3(&info.info3.entries[i]);
1539                                 break;
1540                         case 4:
1541                                 display_sam_info_4(&info.info4.entries[i]);
1542                                 break;
1543                         case 5:
1544                                 display_sam_info_5(&info.info5.entries[i]);
1545                                 break;
1546                         }
1547                 }
1548         } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1549
1550         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1551         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1552  done:
1553         return result;
1554 }
1555
1556 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
1557                                         TALLOC_CTX *mem_ctx,
1558                                         int argc, const char **argv)
1559 {
1560         return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1561                                                 NDR_SAMR_QUERYDISPLAYINFO);
1562 }
1563
1564 static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
1565                                          TALLOC_CTX *mem_ctx,
1566                                          int argc, const char **argv)
1567 {
1568         return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1569                                                 NDR_SAMR_QUERYDISPLAYINFO2);
1570 }
1571
1572 static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
1573                                          TALLOC_CTX *mem_ctx,
1574                                          int argc, const char **argv)
1575 {
1576         return cmd_samr_query_dispinfo_internal(cli, mem_ctx, argc, argv,
1577                                                 NDR_SAMR_QUERYDISPLAYINFO3);
1578 }
1579
1580 /* Query domain info */
1581
1582 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
1583                                        TALLOC_CTX *mem_ctx,
1584                                        int argc, const char **argv)
1585 {
1586         POLICY_HND connect_pol, domain_pol;
1587         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1588         uint32 switch_level = 2;
1589         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1590         union samr_DomainInfo *info = NULL;
1591
1592         if (argc > 3) {
1593                 printf("Usage: %s [info level] [access mask]\n", argv[0]);
1594                 return NT_STATUS_OK;
1595         }
1596
1597         if (argc > 1)
1598                 sscanf(argv[1], "%i", &switch_level);
1599
1600         if (argc > 2)
1601                 sscanf(argv[2], "%x", &access_mask);
1602
1603         /* Get sam policy handle */
1604
1605         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1606                                    &connect_pol);
1607
1608         if (!NT_STATUS_IS_OK(result))
1609                 goto done;
1610
1611         /* Get domain policy handle */
1612
1613         result = rpccli_samr_OpenDomain(cli, mem_ctx,
1614                                         &connect_pol,
1615                                         access_mask,
1616                                         &domain_sid,
1617                                         &domain_pol);
1618
1619         if (!NT_STATUS_IS_OK(result))
1620                 goto done;
1621
1622         /* Query domain info */
1623
1624         result = rpccli_samr_QueryDomainInfo(cli, mem_ctx,
1625                                              &domain_pol,
1626                                              switch_level,
1627                                              &info);
1628
1629         if (!NT_STATUS_IS_OK(result))
1630                 goto done;
1631
1632         /* Display domain info */
1633
1634         switch (switch_level) {
1635         case 1:
1636                 display_sam_dom_info_1(&info->info1);
1637                 break;
1638         case 2:
1639                 display_sam_dom_info_2(&info->info2);
1640                 break;
1641         case 3:
1642                 display_sam_dom_info_3(&info->info3);
1643                 break;
1644         case 4:
1645                 display_sam_dom_info_4(&info->info4);
1646                 break;
1647         case 5:
1648                 display_sam_dom_info_5(&info->info5);
1649                 break;
1650         case 6:
1651                 display_sam_dom_info_6(&info->info6);
1652                 break;
1653         case 7:
1654                 display_sam_dom_info_7(&info->info7);
1655                 break;
1656         case 8:
1657                 display_sam_dom_info_8(&info->info8);
1658                 break;
1659         case 9:
1660                 display_sam_dom_info_9(&info->info9);
1661                 break;
1662         case 12:
1663                 display_sam_dom_info_12(&info->info12);
1664                 break;
1665         case 13:
1666                 display_sam_dom_info_13(&info->info13);
1667                 break;
1668
1669         default:
1670                 printf("cannot display domain info for switch value %d\n",
1671                        switch_level);
1672                 break;
1673         }
1674
1675  done:
1676
1677         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1678         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1679         return result;
1680 }
1681
1682 /* Create domain user */
1683
1684 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
1685                                          TALLOC_CTX *mem_ctx,
1686                                          int argc, const char **argv)
1687 {
1688         POLICY_HND connect_pol, domain_pol, user_pol;
1689         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1690         struct lsa_String acct_name;
1691         uint32 acb_info;
1692         uint32 acct_flags, user_rid;
1693         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1694         uint32_t access_granted = 0;
1695
1696         if ((argc < 2) || (argc > 3)) {
1697                 printf("Usage: %s username [access mask]\n", argv[0]);
1698                 return NT_STATUS_OK;
1699         }
1700
1701         init_lsa_String(&acct_name, argv[1]);
1702
1703         if (argc > 2)
1704                 sscanf(argv[2], "%x", &access_mask);
1705
1706         /* Get sam policy handle */
1707
1708         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1709                                    &connect_pol);
1710
1711         if (!NT_STATUS_IS_OK(result))
1712                 goto done;
1713
1714         /* Get domain policy handle */
1715
1716         result = rpccli_samr_OpenDomain(cli, mem_ctx,
1717                                         &connect_pol,
1718                                         access_mask,
1719                                         &domain_sid,
1720                                         &domain_pol);
1721
1722         if (!NT_STATUS_IS_OK(result))
1723                 goto done;
1724
1725         /* Create domain user */
1726
1727         acb_info = ACB_NORMAL;
1728         acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
1729                      SEC_STD_WRITE_DAC | SEC_STD_DELETE |
1730                      SAMR_USER_ACCESS_SET_PASSWORD |
1731                      SAMR_USER_ACCESS_GET_ATTRIBUTES |
1732                      SAMR_USER_ACCESS_SET_ATTRIBUTES;
1733
1734         result = rpccli_samr_CreateUser2(cli, mem_ctx,
1735                                          &domain_pol,
1736                                          &acct_name,
1737                                          acb_info,
1738                                          acct_flags,
1739                                          &user_pol,
1740                                          &access_granted,
1741                                          &user_rid);
1742
1743         if (!NT_STATUS_IS_OK(result))
1744                 goto done;
1745
1746         result = rpccli_samr_Close(cli, mem_ctx, &user_pol);
1747         if (!NT_STATUS_IS_OK(result)) goto done;
1748
1749         result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1750         if (!NT_STATUS_IS_OK(result)) goto done;
1751
1752         result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1753         if (!NT_STATUS_IS_OK(result)) goto done;
1754
1755  done:
1756         return result;
1757 }
1758
1759 /* Create domain group */
1760
1761 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
1762                                           TALLOC_CTX *mem_ctx,
1763                                           int argc, const char **argv)
1764 {
1765         POLICY_HND connect_pol, domain_pol, group_pol;
1766         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1767         struct lsa_String grp_name;
1768         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1769         uint32_t rid = 0;
1770
1771         if ((argc < 2) || (argc > 3)) {
1772                 printf("Usage: %s groupname [access mask]\n", argv[0]);
1773                 return NT_STATUS_OK;
1774         }
1775
1776         init_lsa_String(&grp_name, argv[1]);
1777
1778         if (argc > 2)
1779                 sscanf(argv[2], "%x", &access_mask);
1780
1781         /* Get sam policy handle */
1782
1783         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1784                                    &connect_pol);
1785
1786         if (!NT_STATUS_IS_OK(result))
1787                 goto done;
1788
1789         /* Get domain policy handle */
1790
1791         result = rpccli_samr_OpenDomain(cli, mem_ctx,
1792                                         &connect_pol,
1793                                         access_mask,
1794                                         &domain_sid,
1795                                         &domain_pol);
1796
1797         if (!NT_STATUS_IS_OK(result))
1798                 goto done;
1799
1800         /* Create domain user */
1801         result = rpccli_samr_CreateDomainGroup(cli, mem_ctx,
1802                                                &domain_pol,
1803                                                &grp_name,
1804                                                MAXIMUM_ALLOWED_ACCESS,
1805                                                &group_pol,
1806                                                &rid);
1807
1808         if (!NT_STATUS_IS_OK(result))
1809                 goto done;
1810
1811         result = rpccli_samr_Close(cli, mem_ctx, &group_pol);
1812         if (!NT_STATUS_IS_OK(result)) goto done;
1813
1814         result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1815         if (!NT_STATUS_IS_OK(result)) goto done;
1816
1817         result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1818         if (!NT_STATUS_IS_OK(result)) goto done;
1819
1820  done:
1821         return result;
1822 }
1823
1824 /* Create domain alias */
1825
1826 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
1827                                           TALLOC_CTX *mem_ctx,
1828                                           int argc, const char **argv)
1829 {
1830         POLICY_HND connect_pol, domain_pol, alias_pol;
1831         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1832         struct lsa_String alias_name;
1833         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
1834         uint32_t rid = 0;
1835
1836         if ((argc < 2) || (argc > 3)) {
1837                 printf("Usage: %s aliasname [access mask]\n", argv[0]);
1838                 return NT_STATUS_OK;
1839         }
1840
1841         init_lsa_String(&alias_name, argv[1]);
1842
1843         if (argc > 2)
1844                 sscanf(argv[2], "%x", &access_mask);
1845
1846         /* Get sam policy handle */
1847
1848         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1849                                    &connect_pol);
1850
1851         if (!NT_STATUS_IS_OK(result))
1852                 goto done;
1853
1854         /* Get domain policy handle */
1855
1856         result = rpccli_samr_OpenDomain(cli, mem_ctx,
1857                                         &connect_pol,
1858                                         access_mask,
1859                                         &domain_sid,
1860                                         &domain_pol);
1861
1862         if (!NT_STATUS_IS_OK(result))
1863                 goto done;
1864
1865         /* Create domain user */
1866
1867         result = rpccli_samr_CreateDomAlias(cli, mem_ctx,
1868                                             &domain_pol,
1869                                             &alias_name,
1870                                             MAXIMUM_ALLOWED_ACCESS,
1871                                             &alias_pol,
1872                                             &rid);
1873
1874         if (!NT_STATUS_IS_OK(result))
1875                 goto done;
1876
1877         result = rpccli_samr_Close(cli, mem_ctx, &alias_pol);
1878         if (!NT_STATUS_IS_OK(result)) goto done;
1879
1880         result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1881         if (!NT_STATUS_IS_OK(result)) goto done;
1882
1883         result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1884         if (!NT_STATUS_IS_OK(result)) goto done;
1885
1886  done:
1887         return result;
1888 }
1889
1890 /* Lookup sam names */
1891
1892 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
1893                                       TALLOC_CTX *mem_ctx,
1894                                       int argc, const char **argv)
1895 {
1896         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1897         POLICY_HND connect_pol, domain_pol;
1898         uint32 num_names;
1899         struct samr_Ids rids, name_types;
1900         int i;
1901         struct lsa_String *names = NULL;;
1902
1903         if (argc < 3) {
1904                 printf("Usage: %s  domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
1905                 printf("check on the domain SID: S-1-5-21-x-y-z\n");
1906                 printf("or check on the builtin SID: S-1-5-32\n");
1907                 return NT_STATUS_OK;
1908         }
1909
1910         /* Get sam policy and domain handles */
1911
1912         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1913                                    &connect_pol);
1914
1915         if (!NT_STATUS_IS_OK(result))
1916                 goto done;
1917
1918         if (StrCaseCmp(argv[1], "domain")==0)
1919                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1920                                                 &connect_pol,
1921                                                 MAXIMUM_ALLOWED_ACCESS,
1922                                                 &domain_sid,
1923                                                 &domain_pol);
1924         else if (StrCaseCmp(argv[1], "builtin")==0)
1925                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
1926                                                 &connect_pol,
1927                                                 MAXIMUM_ALLOWED_ACCESS,
1928                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
1929                                                 &domain_pol);
1930         else
1931                 return NT_STATUS_OK;
1932
1933         if (!NT_STATUS_IS_OK(result))
1934                 goto done;
1935
1936         /* Look up names */
1937
1938         num_names = argc - 2;
1939
1940         if ((names = TALLOC_ARRAY(mem_ctx, struct lsa_String, num_names)) == NULL) {
1941                 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1942                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1943                 result = NT_STATUS_NO_MEMORY;
1944                 goto done;
1945         }
1946
1947         for (i = 0; i < num_names; i++) {
1948                 init_lsa_String(&names[i], argv[i + 2]);
1949         }
1950
1951         result = rpccli_samr_LookupNames(cli, mem_ctx,
1952                                          &domain_pol,
1953                                          num_names,
1954                                          names,
1955                                          &rids,
1956                                          &name_types);
1957
1958         if (!NT_STATUS_IS_OK(result))
1959                 goto done;
1960
1961         /* Display results */
1962
1963         for (i = 0; i < num_names; i++)
1964                 printf("name %s: 0x%x (%d)\n", names[i].string, rids.ids[i],
1965                        name_types.ids[i]);
1966
1967         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
1968         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
1969  done:
1970         return result;
1971 }
1972
1973 /* Lookup sam rids */
1974
1975 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
1976                                      TALLOC_CTX *mem_ctx,
1977                                      int argc, const char **argv)
1978 {
1979         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1980         POLICY_HND connect_pol, domain_pol;
1981         uint32_t num_rids, *rids;
1982         struct lsa_Strings names;
1983         struct samr_Ids types;
1984
1985         int i;
1986
1987         if (argc < 3) {
1988                 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
1989                 return NT_STATUS_OK;
1990         }
1991
1992         /* Get sam policy and domain handles */
1993
1994         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1995                                    &connect_pol);
1996
1997         if (!NT_STATUS_IS_OK(result))
1998                 goto done;
1999
2000         if (StrCaseCmp(argv[1], "domain")==0)
2001                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2002                                                 &connect_pol,
2003                                                 MAXIMUM_ALLOWED_ACCESS,
2004                                                 &domain_sid,
2005                                                 &domain_pol);
2006         else if (StrCaseCmp(argv[1], "builtin")==0)
2007                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2008                                                 &connect_pol,
2009                                                 MAXIMUM_ALLOWED_ACCESS,
2010                                                 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
2011                                                 &domain_pol);
2012         else
2013                 return NT_STATUS_OK;
2014
2015         if (!NT_STATUS_IS_OK(result))
2016                 goto done;
2017
2018         /* Look up rids */
2019
2020         num_rids = argc - 2;
2021
2022         if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
2023                 rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2024                 rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2025                 result = NT_STATUS_NO_MEMORY;
2026                 goto done;
2027         }
2028
2029         for (i = 0; i < argc - 2; i++)
2030                 sscanf(argv[i + 2], "%i", &rids[i]);
2031
2032         result = rpccli_samr_LookupRids(cli, mem_ctx,
2033                                         &domain_pol,
2034                                         num_rids,
2035                                         rids,
2036                                         &names,
2037                                         &types);
2038
2039         if (!NT_STATUS_IS_OK(result) &&
2040             !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
2041                 goto done;
2042
2043         /* Display results */
2044
2045         for (i = 0; i < num_rids; i++) {
2046                 printf("rid 0x%x: %s (%d)\n",
2047                         rids[i], names.names[i].string, types.ids[i]);
2048         }
2049
2050         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2051         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2052  done:
2053         return result;
2054 }
2055
2056 /* Delete domain group */
2057
2058 static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
2059                                          TALLOC_CTX *mem_ctx,
2060                                          int argc, const char **argv)
2061 {
2062         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2063         POLICY_HND connect_pol, domain_pol, group_pol;
2064         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2065
2066         if ((argc < 2) || (argc > 3)) {
2067                 printf("Usage: %s groupname\n", argv[0]);
2068                 return NT_STATUS_OK;
2069         }
2070
2071         if (argc > 2)
2072                 sscanf(argv[2], "%x", &access_mask);
2073
2074         /* Get sam policy and domain handles */
2075
2076         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2077                                    &connect_pol);
2078
2079         if (!NT_STATUS_IS_OK(result))
2080                 goto done;
2081
2082         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2083                                         &connect_pol,
2084                                         MAXIMUM_ALLOWED_ACCESS,
2085                                         &domain_sid,
2086                                         &domain_pol);
2087
2088         if (!NT_STATUS_IS_OK(result))
2089                 goto done;
2090
2091         /* Get handle on group */
2092
2093         {
2094                 struct samr_Ids group_rids, name_types;
2095                 struct lsa_String lsa_acct_name;
2096
2097                 init_lsa_String(&lsa_acct_name, argv[1]);
2098
2099                 result = rpccli_samr_LookupNames(cli, mem_ctx,
2100                                                  &domain_pol,
2101                                                  1,
2102                                                  &lsa_acct_name,
2103                                                  &group_rids,
2104                                                  &name_types);
2105                 if (!NT_STATUS_IS_OK(result))
2106                         goto done;
2107
2108                 result = rpccli_samr_OpenGroup(cli, mem_ctx,
2109                                                &domain_pol,
2110                                                access_mask,
2111                                                group_rids.ids[0],
2112                                                &group_pol);
2113
2114                 if (!NT_STATUS_IS_OK(result))
2115                         goto done;
2116         }
2117
2118         /* Delete group */
2119
2120         result = rpccli_samr_DeleteDomainGroup(cli, mem_ctx,
2121                                                &group_pol);
2122
2123         if (!NT_STATUS_IS_OK(result))
2124                 goto done;
2125
2126         /* Display results */
2127
2128         rpccli_samr_Close(cli, mem_ctx, &group_pol);
2129         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2130         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2131
2132  done:
2133         return result;
2134 }
2135
2136 /* Delete domain user */
2137
2138 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
2139                                          TALLOC_CTX *mem_ctx,
2140                                          int argc, const char **argv)
2141 {
2142         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2143         POLICY_HND connect_pol, domain_pol, user_pol;
2144         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2145
2146         if ((argc < 2) || (argc > 3)) {
2147                 printf("Usage: %s username\n", argv[0]);
2148                 return NT_STATUS_OK;
2149         }
2150
2151         if (argc > 2)
2152                 sscanf(argv[2], "%x", &access_mask);
2153
2154         /* Get sam policy and domain handles */
2155
2156         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2157                                    &connect_pol);
2158
2159         if (!NT_STATUS_IS_OK(result))
2160                 goto done;
2161
2162         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2163                                         &connect_pol,
2164                                         MAXIMUM_ALLOWED_ACCESS,
2165                                         &domain_sid,
2166                                         &domain_pol);
2167
2168         if (!NT_STATUS_IS_OK(result))
2169                 goto done;
2170
2171         /* Get handle on user */
2172
2173         {
2174                 struct samr_Ids user_rids, name_types;
2175                 struct lsa_String lsa_acct_name;
2176
2177                 init_lsa_String(&lsa_acct_name, argv[1]);
2178
2179                 result = rpccli_samr_LookupNames(cli, mem_ctx,
2180                                                  &domain_pol,
2181                                                  1,
2182                                                  &lsa_acct_name,
2183                                                  &user_rids,
2184                                                  &name_types);
2185
2186                 if (!NT_STATUS_IS_OK(result))
2187                         goto done;
2188
2189                 result = rpccli_samr_OpenUser(cli, mem_ctx,
2190                                               &domain_pol,
2191                                               access_mask,
2192                                               user_rids.ids[0],
2193                                               &user_pol);
2194
2195                 if (!NT_STATUS_IS_OK(result))
2196                         goto done;
2197         }
2198
2199         /* Delete user */
2200
2201         result = rpccli_samr_DeleteUser(cli, mem_ctx,
2202                                         &user_pol);
2203
2204         if (!NT_STATUS_IS_OK(result))
2205                 goto done;
2206
2207         /* Display results */
2208
2209         rpccli_samr_Close(cli, mem_ctx, &user_pol);
2210         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2211         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2212
2213  done:
2214         return result;
2215 }
2216
2217 /**********************************************************************
2218  * Query user security object
2219  */
2220 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
2221                                     TALLOC_CTX *mem_ctx,
2222                                     int argc, const char **argv)
2223 {
2224         POLICY_HND connect_pol, domain_pol, user_pol, *pol;
2225         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2226         uint32 sec_info = DACL_SECURITY_INFORMATION;
2227         fstring server;
2228         uint32 user_rid = 0;
2229         TALLOC_CTX *ctx = NULL;
2230         SEC_DESC_BUF *sec_desc_buf=NULL;
2231         bool domain = False;
2232
2233         ctx=talloc_init("cmd_samr_query_sec_obj");
2234
2235         if ((argc < 1) || (argc > 3)) {
2236                 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
2237                 printf("\tSpecify rid for security on user, -d for security on domain\n");
2238                 talloc_destroy(ctx);
2239                 return NT_STATUS_OK;
2240         }
2241
2242         if (argc > 1) {
2243                 if (strcmp(argv[1], "-d") == 0)
2244                         domain = True;
2245                 else
2246                         sscanf(argv[1], "%i", &user_rid);
2247         }
2248
2249         if (argc == 3) {
2250                 sec_info = atoi(argv[2]);
2251         }
2252
2253         slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
2254         strupper_m(server);
2255         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2256                                    &connect_pol);
2257
2258         if (!NT_STATUS_IS_OK(result))
2259                 goto done;
2260
2261         if (domain || user_rid)
2262                 result = rpccli_samr_OpenDomain(cli, mem_ctx,
2263                                                 &connect_pol,
2264                                                 MAXIMUM_ALLOWED_ACCESS,
2265                                                 &domain_sid,
2266                                                 &domain_pol);
2267
2268         if (!NT_STATUS_IS_OK(result))
2269                 goto done;
2270
2271         if (user_rid)
2272                 result = rpccli_samr_OpenUser(cli, mem_ctx,
2273                                               &domain_pol,
2274                                               MAXIMUM_ALLOWED_ACCESS,
2275                                               user_rid,
2276                                               &user_pol);
2277
2278         if (!NT_STATUS_IS_OK(result))
2279                 goto done;
2280
2281         /* Pick which query pol to use */
2282
2283         pol = &connect_pol;
2284
2285         if (domain)
2286                 pol = &domain_pol;
2287
2288         if (user_rid)
2289                 pol = &user_pol;
2290
2291         /* Query SAM security object */
2292
2293         result = rpccli_samr_QuerySecurity(cli, mem_ctx,
2294                                            pol,
2295                                            sec_info,
2296                                            &sec_desc_buf);
2297
2298         if (!NT_STATUS_IS_OK(result))
2299                 goto done;
2300
2301         display_sec_desc(sec_desc_buf->sd);
2302
2303         rpccli_samr_Close(cli, mem_ctx, &user_pol);
2304         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2305         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2306 done:
2307         talloc_destroy(ctx);
2308         return result;
2309 }
2310
2311 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
2312                                            TALLOC_CTX *mem_ctx,
2313                                            int argc, const char **argv)
2314 {
2315         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2316         POLICY_HND connect_pol, domain_pol, user_pol;
2317         struct samr_PwInfo info;
2318         uint32_t rid;
2319
2320         if (argc != 2) {
2321                 printf("Usage: %s rid\n", argv[0]);
2322                 return NT_STATUS_OK;
2323         }
2324
2325         sscanf(argv[1], "%i", &rid);
2326
2327         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2328                                    &connect_pol);
2329
2330         if (!NT_STATUS_IS_OK(result)) {
2331                 goto done;
2332         }
2333
2334         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2335                                         &connect_pol,
2336                                         MAXIMUM_ALLOWED_ACCESS,
2337                                         &domain_sid,
2338                                         &domain_pol);
2339
2340         if (!NT_STATUS_IS_OK(result)) {
2341                 goto done;
2342         }
2343
2344         result = rpccli_samr_OpenUser(cli, mem_ctx,
2345                                       &domain_pol,
2346                                       MAXIMUM_ALLOWED_ACCESS,
2347                                       rid,
2348                                       &user_pol);
2349
2350         if (!NT_STATUS_IS_OK(result)) {
2351                 goto done;
2352         }
2353
2354         result = rpccli_samr_GetUserPwInfo(cli, mem_ctx, &user_pol, &info);
2355         if (NT_STATUS_IS_OK(result)) {
2356                 printf("min_password_length: %d\n", info.min_password_length);
2357                 printf("%s\n",
2358                         NDR_PRINT_STRUCT_STRING(mem_ctx,
2359                                 samr_PasswordProperties, &info.password_properties));
2360         }
2361
2362  done:
2363         rpccli_samr_Close(cli, mem_ctx, &user_pol);
2364         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2365         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2366
2367         return result;
2368 }
2369
2370 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
2371                                         TALLOC_CTX *mem_ctx,
2372                                         int argc, const char **argv)
2373 {
2374         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2375         struct lsa_String domain_name;
2376         struct samr_PwInfo info;
2377
2378         if (argc < 1 || argc > 3) {
2379                 printf("Usage: %s <domain>\n", argv[0]);
2380                 return NT_STATUS_OK;
2381         }
2382
2383         init_lsa_String(&domain_name, argv[1]);
2384
2385         result = rpccli_samr_GetDomPwInfo(cli, mem_ctx, &domain_name, &info);
2386
2387         if (NT_STATUS_IS_OK(result)) {
2388                 printf("min_password_length: %d\n", info.min_password_length);
2389                 display_password_properties(info.password_properties);
2390         }
2391
2392         return result;
2393 }
2394
2395 /* Look up domain name */
2396
2397 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
2398                                        TALLOC_CTX *mem_ctx,
2399                                        int argc, const char **argv)
2400 {
2401         POLICY_HND connect_pol, domain_pol;
2402         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2403         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2404         fstring sid_string;
2405         struct lsa_String domain_name;
2406         DOM_SID *sid = NULL;
2407
2408         if (argc != 2) {
2409                 printf("Usage: %s domain_name\n", argv[0]);
2410                 return NT_STATUS_OK;
2411         }
2412
2413         init_lsa_String(&domain_name, argv[1]);
2414
2415         result = try_samr_connects(cli, mem_ctx, access_mask, &connect_pol);
2416
2417         if (!NT_STATUS_IS_OK(result))
2418                 goto done;
2419
2420         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2421                                         &connect_pol,
2422                                         access_mask,
2423                                         &domain_sid,
2424                                         &domain_pol);
2425
2426         if (!NT_STATUS_IS_OK(result))
2427                 goto done;
2428
2429         result = rpccli_samr_LookupDomain(cli, mem_ctx,
2430                                           &connect_pol,
2431                                           &domain_name,
2432                                           &sid);
2433
2434         if (NT_STATUS_IS_OK(result)) {
2435                 sid_to_fstring(sid_string, sid);
2436                 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
2437                        argv[1], sid_string);
2438         }
2439
2440         rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2441         rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2442 done:
2443         return result;
2444 }
2445
2446 /* Change user password */
2447
2448 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
2449                                     TALLOC_CTX *mem_ctx,
2450                                     int argc, const char **argv)
2451 {
2452         POLICY_HND connect_pol, domain_pol;
2453         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2454         const char *user, *oldpass, *newpass;
2455         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2456
2457         if (argc < 3) {
2458                 printf("Usage: %s username oldpass newpass\n", argv[0]);
2459                 return NT_STATUS_INVALID_PARAMETER;
2460         }
2461
2462         user = argv[1];
2463         oldpass = argv[2];
2464         newpass = argv[3];
2465
2466         /* Get sam policy handle */
2467
2468         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2469                                    &connect_pol);
2470
2471         if (!NT_STATUS_IS_OK(result))
2472                 goto done;
2473
2474         /* Get domain policy handle */
2475
2476         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2477                                         &connect_pol,
2478                                         access_mask,
2479                                         &domain_sid,
2480                                         &domain_pol);
2481
2482         if (!NT_STATUS_IS_OK(result))
2483                 goto done;
2484
2485         /* Change user password */
2486         result = rpccli_samr_chgpasswd_user(cli, mem_ctx, user, newpass, oldpass);
2487
2488         if (!NT_STATUS_IS_OK(result))
2489                 goto done;
2490
2491         result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2492         if (!NT_STATUS_IS_OK(result)) goto done;
2493
2494         result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2495         if (!NT_STATUS_IS_OK(result)) goto done;
2496
2497  done:
2498         return result;
2499 }
2500
2501
2502 /* Change user password */
2503
2504 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
2505                                     TALLOC_CTX *mem_ctx,
2506                                     int argc, const char **argv)
2507 {
2508         POLICY_HND connect_pol, domain_pol;
2509         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2510         const char *user, *oldpass, *newpass;
2511         uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
2512         struct samr_DomInfo1 *info = NULL;
2513         struct samr_ChangeReject *reject = NULL;
2514
2515         if (argc < 3) {
2516                 printf("Usage: %s username oldpass newpass\n", argv[0]);
2517                 return NT_STATUS_INVALID_PARAMETER;
2518         }
2519
2520         user = argv[1];
2521         oldpass = argv[2];
2522         newpass = argv[3];
2523
2524         /* Get sam policy handle */
2525
2526         result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
2527                                    &connect_pol);
2528
2529         if (!NT_STATUS_IS_OK(result))
2530                 goto done;
2531
2532         /* Get domain policy handle */
2533
2534         result = rpccli_samr_OpenDomain(cli, mem_ctx,
2535                                         &connect_pol,
2536                                         access_mask,
2537                                         &domain_sid,
2538                                         &domain_pol);
2539
2540         if (!NT_STATUS_IS_OK(result))
2541                 goto done;
2542
2543         /* Change user password */
2544         result = rpccli_samr_chgpasswd3(cli, mem_ctx,
2545                                         user,
2546                                         newpass,
2547                                         oldpass,
2548                                         &info,
2549                                         &reject);
2550
2551         if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
2552
2553                 display_sam_dom_info_1(info);
2554
2555                 switch (reject->reason) {
2556                         case SAMR_REJECT_TOO_SHORT:
2557                                 d_printf("SAMR_REJECT_TOO_SHORT\n");
2558                                 break;
2559                         case SAMR_REJECT_IN_HISTORY:
2560                                 d_printf("SAMR_REJECT_IN_HISTORY\n");
2561                                 break;
2562                         case SAMR_REJECT_COMPLEXITY:
2563                                 d_printf("SAMR_REJECT_COMPLEXITY\n");
2564                                 break;
2565                         case SAMR_REJECT_OTHER:
2566                                 d_printf("SAMR_REJECT_OTHER\n");
2567                                 break;
2568                         default:
2569                                 d_printf("unknown reject reason: %d\n",
2570                                         reject->reason);
2571                                 break;
2572                 }
2573         }
2574
2575         if (!NT_STATUS_IS_OK(result))
2576                 goto done;
2577
2578         result = rpccli_samr_Close(cli, mem_ctx, &domain_pol);
2579         if (!NT_STATUS_IS_OK(result)) goto done;
2580
2581         result = rpccli_samr_Close(cli, mem_ctx, &connect_pol);
2582         if (!NT_STATUS_IS_OK(result)) goto done;
2583
2584  done:
2585         return result;
2586 }
2587
2588 /* List of commands exported by this module */
2589
2590 struct cmd_set samr_commands[] = {
2591
2592         { "SAMR" },
2593
2594         { "queryuser",  RPC_RTYPE_NTSTATUS, cmd_samr_query_user,                NULL, PI_SAMR, NULL,    "Query user info",         "" },
2595         { "querygroup",         RPC_RTYPE_NTSTATUS, cmd_samr_query_group,               NULL, PI_SAMR, NULL,    "Query group info",        "" },
2596         { "queryusergroups",    RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups,  NULL, PI_SAMR, NULL,    "Query user groups",       "" },
2597         { "queryuseraliases",   RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases,         NULL, PI_SAMR, NULL,    "Query user aliases",      "" },
2598         { "querygroupmem",      RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem,    NULL, PI_SAMR, NULL,    "Query group membership",  "" },
2599         { "queryaliasmem",      RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem,    NULL, PI_SAMR, NULL,    "Query alias membership",  "" },
2600         { "queryaliasinfo",     RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasinfo,   NULL, PI_SAMR, NULL,    "Query alias info",       "" },
2601         { "deletealias",        RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias,      NULL, PI_SAMR, NULL,    "Delete an alias",  "" },
2602         { "querydispinfo",      RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo,    NULL, PI_SAMR, NULL,    "Query display info",      "" },
2603         { "querydispinfo2",     RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2,   NULL, PI_SAMR, NULL,    "Query display info",      "" },
2604         { "querydispinfo3",     RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3,   NULL, PI_SAMR, NULL,    "Query display info",      "" },
2605         { "querydominfo",       RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo,     NULL, PI_SAMR, NULL,    "Query domain info",       "" },
2606         { "enumdomusers",       RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users,       NULL, PI_SAMR, NULL, "Enumerate domain users", "" },
2607         { "enumdomgroups",      RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups,       NULL, PI_SAMR, NULL,        "Enumerate domain groups", "" },
2608         { "enumalsgroups",      RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups,       NULL, PI_SAMR, NULL,        "Enumerate alias groups",  "" },
2609         { "enumdomains",        RPC_RTYPE_NTSTATUS, cmd_samr_enum_domains,          NULL, PI_SAMR, NULL,        "Enumerate domains",  "" },
2610
2611         { "createdomuser",      RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user,       NULL, PI_SAMR, NULL,        "Create domain user",      "" },
2612         { "createdomgroup",     RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group,      NULL, PI_SAMR, NULL,        "Create domain group",     "" },
2613         { "createdomalias",     RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias,      NULL, PI_SAMR, NULL,        "Create domain alias",     "" },
2614         { "samlookupnames",     RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names,          NULL, PI_SAMR, NULL,        "Look up names",           "" },
2615         { "samlookuprids",      RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids,           NULL, PI_SAMR, NULL,        "Look up names",           "" },
2616         { "deletedomgroup",     RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group,      NULL, PI_SAMR, NULL,        "Delete domain group",     "" },
2617         { "deletedomuser",      RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user,       NULL, PI_SAMR, NULL,        "Delete domain user",      "" },
2618         { "samquerysecobj",     RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj,         NULL, PI_SAMR, NULL, "Query SAMR security object",   "" },
2619         { "getdompwinfo",       RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo,        NULL, PI_SAMR, NULL, "Retrieve domain password info", "" },
2620         { "getusrdompwinfo",    RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo,     NULL, PI_SAMR, NULL, "Retrieve user domain password info", "" },
2621
2622         { "lookupdomain",       RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain,         NULL, PI_SAMR, NULL, "Lookup Domain Name", "" },
2623         { "chgpasswd2",         RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2,            NULL, PI_SAMR, NULL, "Change user password", "" },
2624         { "chgpasswd3",         RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3,            NULL, PI_SAMR, NULL, "Change user password", "" },
2625         { NULL }
2626 };