r10396: fix build breakage after an incomplete merge from 3.0
[Samba.git] / source / rpcclient / cmd_lsarpc.c
blobb01f63924774b878e582a744440db8d54c7585c0
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "rpcclient.h"
27 /* useful function to allow entering a name instead of a SID and
28 * looking it up automatically */
29 static NTSTATUS name_to_sid(struct cli_state *cli,
30 TALLOC_CTX *mem_ctx,
31 DOM_SID *sid, const char *name)
33 POLICY_HND pol;
34 uint32 *sid_types;
35 NTSTATUS result;
36 DOM_SID *sids;
38 /* maybe its a raw SID */
39 if (strncmp(name, "S-", 2) == 0 &&
40 string_to_sid(sid, name)) {
41 return NT_STATUS_OK;
44 result = cli_lsa_open_policy(cli, mem_ctx, True,
45 SEC_RIGHTS_MAXIMUM_ALLOWED,
46 &pol);
47 if (!NT_STATUS_IS_OK(result))
48 goto done;
50 result = cli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, &sids, &sid_types);
51 if (!NT_STATUS_IS_OK(result))
52 goto done;
54 cli_lsa_close(cli, mem_ctx, &pol);
56 *sid = sids[0];
58 done:
59 return result;
63 /* Look up domain related information on a remote host */
65 static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli,
66 TALLOC_CTX *mem_ctx, int argc,
67 const char **argv)
69 POLICY_HND pol;
70 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
71 DOM_SID *dom_sid;
72 struct uuid *dom_guid;
73 fstring sid_str;
74 char *domain_name = NULL;
75 char *dns_name = NULL;
76 char *forest_name = NULL;
78 uint32 info_class = 3;
80 if (argc > 2) {
81 printf("Usage: %s [info_class]\n", argv[0]);
82 return NT_STATUS_OK;
85 if (argc == 2)
86 info_class = atoi(argv[1]);
88 /* Lookup info policy */
89 switch (info_class) {
90 case 12:
91 result = cli_lsa_open_policy2(cli, mem_ctx, True,
92 SEC_RIGHTS_MAXIMUM_ALLOWED,
93 &pol);
95 if (!NT_STATUS_IS_OK(result))
96 goto done;
97 result = cli_lsa_query_info_policy2(cli, mem_ctx, &pol,
98 info_class, &domain_name,
99 &dns_name, &forest_name,
100 &dom_guid, &dom_sid);
101 break;
102 default:
103 result = cli_lsa_open_policy(cli, mem_ctx, True,
104 SEC_RIGHTS_MAXIMUM_ALLOWED,
105 &pol);
107 if (!NT_STATUS_IS_OK(result))
108 goto done;
109 result = cli_lsa_query_info_policy(cli, mem_ctx, &pol,
110 info_class, &domain_name,
111 &dom_sid);
114 if (!NT_STATUS_IS_OK(result))
115 goto done;
117 sid_to_string(sid_str, dom_sid);
119 if (domain_name)
120 printf("domain %s has sid %s\n", domain_name, sid_str);
121 else
122 printf("could not query info for level %d\n", info_class);
124 if (dns_name)
125 printf("domain dns name is %s\n", dns_name);
126 if (forest_name)
127 printf("forest name is %s\n", forest_name);
129 if (info_class == 12) {
130 printf("domain GUID is ");
131 smb_uuid_string_static(*dom_guid);
133 done:
134 return result;
137 /* Resolve a list of names to a list of sids */
139 static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
140 TALLOC_CTX *mem_ctx, int argc,
141 const char **argv)
143 POLICY_HND pol;
144 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
145 DOM_SID *sids;
146 uint32 *types;
147 int i;
149 if (argc == 1) {
150 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
151 return NT_STATUS_OK;
154 result = cli_lsa_open_policy(cli, mem_ctx, True,
155 SEC_RIGHTS_MAXIMUM_ALLOWED,
156 &pol);
158 if (!NT_STATUS_IS_OK(result))
159 goto done;
161 result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
162 (const char**)(argv + 1), &sids, &types);
164 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
165 NT_STATUS_V(STATUS_SOME_UNMAPPED))
166 goto done;
168 result = NT_STATUS_OK;
170 /* Print results */
172 for (i = 0; i < (argc - 1); i++) {
173 fstring sid_str;
174 sid_to_string(sid_str, &sids[i]);
175 printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
176 sid_type_lookup(types[i]), types[i]);
179 cli_lsa_close(cli, mem_ctx, &pol);
181 done:
182 return result;
185 /* Resolve a list of SIDs to a list of names */
187 static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
188 int argc, const char **argv)
190 POLICY_HND pol;
191 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
192 DOM_SID *sids;
193 char **domains;
194 char **names;
195 uint32 *types;
196 int i;
198 if (argc == 1) {
199 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
200 return NT_STATUS_OK;
203 result = cli_lsa_open_policy(cli, mem_ctx, True,
204 SEC_RIGHTS_MAXIMUM_ALLOWED,
205 &pol);
207 if (!NT_STATUS_IS_OK(result))
208 goto done;
210 /* Convert arguments to sids */
212 sids = TALLOC_ARRAY(mem_ctx, DOM_SID, argc - 1);
214 if (!sids) {
215 printf("could not allocate memory for %d sids\n", argc - 1);
216 goto done;
219 for (i = 0; i < argc - 1; i++)
220 if (!string_to_sid(&sids[i], argv[i + 1])) {
221 result = NT_STATUS_INVALID_SID;
222 goto done;
225 /* Lookup the SIDs */
227 result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
228 &domains, &names, &types);
230 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
231 NT_STATUS_V(STATUS_SOME_UNMAPPED))
232 goto done;
234 result = NT_STATUS_OK;
236 /* Print results */
238 for (i = 0; i < (argc - 1); i++) {
239 fstring sid_str;
241 sid_to_string(sid_str, &sids[i]);
242 printf("%s %s\\%s (%d)\n", sid_str,
243 domains[i] ? domains[i] : "*unknown*",
244 names[i] ? names[i] : "*unknown*", types[i]);
247 cli_lsa_close(cli, mem_ctx, &pol);
249 done:
250 return result;
253 /* Enumerate list of trusted domains */
255 static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
256 TALLOC_CTX *mem_ctx, int argc,
257 const char **argv)
259 POLICY_HND pol;
260 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
261 DOM_SID *domain_sids;
262 char **domain_names;
264 /* defaults, but may be changed using params */
265 uint32 enum_ctx = 0;
266 uint32 num_domains = 0;
267 int i;
269 if (argc > 2) {
270 printf("Usage: %s [enum context (0)]\n", argv[0]);
271 return NT_STATUS_OK;
274 if (argc == 2 && argv[1]) {
275 enum_ctx = atoi(argv[2]);
278 result = cli_lsa_open_policy(cli, mem_ctx, True,
279 POLICY_VIEW_LOCAL_INFORMATION,
280 &pol);
282 if (!NT_STATUS_IS_OK(result))
283 goto done;
285 result = STATUS_MORE_ENTRIES;
287 while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
289 /* Lookup list of trusted domains */
291 result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
292 &num_domains,
293 &domain_names, &domain_sids);
294 if (!NT_STATUS_IS_OK(result) &&
295 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
296 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
297 goto done;
299 /* Print results: list of names and sids returned in this
300 * response. */
301 for (i = 0; i < num_domains; i++) {
302 fstring sid_str;
304 sid_to_string(sid_str, &domain_sids[i]);
305 printf("%s %s\n", domain_names[i] ? domain_names[i] :
306 "*unknown*", sid_str);
310 done:
311 return result;
314 /* Enumerates privileges */
316 static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli,
317 TALLOC_CTX *mem_ctx, int argc,
318 const char **argv)
320 POLICY_HND pol;
321 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
323 uint32 enum_context=0;
324 uint32 pref_max_length=0x1000;
325 uint32 count=0;
326 char **privs_name;
327 uint32 *privs_high;
328 uint32 *privs_low;
329 int i;
331 if (argc > 3) {
332 printf("Usage: %s [enum context] [max length]\n", argv[0]);
333 return NT_STATUS_OK;
336 if (argc>=2)
337 enum_context=atoi(argv[1]);
339 if (argc==3)
340 pref_max_length=atoi(argv[2]);
342 result = cli_lsa_open_policy(cli, mem_ctx, True,
343 SEC_RIGHTS_MAXIMUM_ALLOWED,
344 &pol);
346 if (!NT_STATUS_IS_OK(result))
347 goto done;
349 result = cli_lsa_enum_privilege(cli, mem_ctx, &pol, &enum_context, pref_max_length,
350 &count, &privs_name, &privs_high, &privs_low);
352 if (!NT_STATUS_IS_OK(result))
353 goto done;
355 /* Print results */
356 printf("found %d privileges\n\n", count);
358 for (i = 0; i < count; i++) {
359 printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name[i] ? privs_name[i] : "*unknown*",
360 privs_high[i], privs_low[i], privs_high[i], privs_low[i]);
363 done:
364 return result;
367 /* Get privilege name */
369 static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
370 TALLOC_CTX *mem_ctx, int argc,
371 const char **argv)
373 POLICY_HND pol;
374 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
376 uint16 lang_id=0;
377 uint16 lang_id_sys=0;
378 uint16 lang_id_desc;
379 fstring description;
381 if (argc != 2) {
382 printf("Usage: %s privilege name\n", argv[0]);
383 return NT_STATUS_OK;
386 result = cli_lsa_open_policy(cli, mem_ctx, True,
387 SEC_RIGHTS_MAXIMUM_ALLOWED,
388 &pol);
390 if (!NT_STATUS_IS_OK(result))
391 goto done;
393 result = cli_lsa_get_dispname(cli, mem_ctx, &pol, argv[1], lang_id, lang_id_sys, description, &lang_id_desc);
395 if (!NT_STATUS_IS_OK(result))
396 goto done;
398 /* Print results */
399 printf("%s -> %s (language: 0x%x)\n", argv[1], description, lang_id_desc);
401 done:
402 return result;
405 /* Enumerate the LSA SIDS */
407 static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli,
408 TALLOC_CTX *mem_ctx, int argc,
409 const char **argv)
411 POLICY_HND pol;
412 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
414 uint32 enum_context=0;
415 uint32 pref_max_length=0x1000;
416 DOM_SID *sids;
417 uint32 count=0;
418 int i;
420 if (argc > 3) {
421 printf("Usage: %s [enum context] [max length]\n", argv[0]);
422 return NT_STATUS_OK;
425 if (argc>=2)
426 enum_context=atoi(argv[1]);
428 if (argc==3)
429 pref_max_length=atoi(argv[2]);
431 result = cli_lsa_open_policy(cli, mem_ctx, True,
432 SEC_RIGHTS_MAXIMUM_ALLOWED,
433 &pol);
435 if (!NT_STATUS_IS_OK(result))
436 goto done;
438 result = cli_lsa_enum_sids(cli, mem_ctx, &pol, &enum_context, pref_max_length,
439 &count, &sids);
441 if (!NT_STATUS_IS_OK(result))
442 goto done;
444 /* Print results */
445 printf("found %d SIDs\n\n", count);
447 for (i = 0; i < count; i++) {
448 fstring sid_str;
450 sid_to_string(sid_str, &sids[i]);
451 printf("%s\n", sid_str);
454 done:
455 return result;
458 /* Create a new account */
460 static NTSTATUS cmd_lsa_create_account(struct cli_state *cli,
461 TALLOC_CTX *mem_ctx, int argc,
462 const char **argv)
464 POLICY_HND dom_pol;
465 POLICY_HND user_pol;
466 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
467 uint32 des_access = 0x000f000f;
469 DOM_SID sid;
471 if (argc != 2 ) {
472 printf("Usage: %s SID\n", argv[0]);
473 return NT_STATUS_OK;
476 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
477 if (!NT_STATUS_IS_OK(result))
478 goto done;
480 result = cli_lsa_open_policy2(cli, mem_ctx, True,
481 SEC_RIGHTS_MAXIMUM_ALLOWED,
482 &dom_pol);
484 if (!NT_STATUS_IS_OK(result))
485 goto done;
487 result = cli_lsa_create_account(cli, mem_ctx, &dom_pol, &sid, des_access, &user_pol);
489 if (!NT_STATUS_IS_OK(result))
490 goto done;
492 printf("Account for SID %s successfully created\n\n", argv[1]);
493 result = NT_STATUS_OK;
495 done:
496 return result;
500 /* Enumerate the privileges of an SID */
502 static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli,
503 TALLOC_CTX *mem_ctx, int argc,
504 const char **argv)
506 POLICY_HND dom_pol;
507 POLICY_HND user_pol;
508 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
509 uint32 access_desired = 0x000f000f;
511 DOM_SID sid;
512 uint32 count=0;
513 LUID_ATTR *set;
514 int i;
516 if (argc != 2 ) {
517 printf("Usage: %s SID\n", argv[0]);
518 return NT_STATUS_OK;
521 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
522 if (!NT_STATUS_IS_OK(result))
523 goto done;
525 result = cli_lsa_open_policy2(cli, mem_ctx, True,
526 SEC_RIGHTS_MAXIMUM_ALLOWED,
527 &dom_pol);
529 if (!NT_STATUS_IS_OK(result))
530 goto done;
532 result = cli_lsa_open_account(cli, mem_ctx, &dom_pol, &sid, access_desired, &user_pol);
534 if (!NT_STATUS_IS_OK(result))
535 goto done;
537 result = cli_lsa_enum_privsaccount(cli, mem_ctx, &user_pol, &count, &set);
539 if (!NT_STATUS_IS_OK(result))
540 goto done;
542 /* Print results */
543 printf("found %d privileges for SID %s\n\n", count, argv[1]);
544 printf("high\tlow\tattribute\n");
546 for (i = 0; i < count; i++) {
547 printf("%u\t%u\t%u\n", set[i].luid.high, set[i].luid.low, set[i].attr);
550 done:
551 return result;
555 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
557 static NTSTATUS cmd_lsa_enum_acct_rights(struct cli_state *cli,
558 TALLOC_CTX *mem_ctx, int argc,
559 const char **argv)
561 POLICY_HND dom_pol;
562 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
564 DOM_SID sid;
565 uint32 count;
566 char **rights;
568 int i;
570 if (argc != 2 ) {
571 printf("Usage: %s SID\n", argv[0]);
572 return NT_STATUS_OK;
575 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
576 if (!NT_STATUS_IS_OK(result))
577 goto done;
579 result = cli_lsa_open_policy2(cli, mem_ctx, True,
580 SEC_RIGHTS_MAXIMUM_ALLOWED,
581 &dom_pol);
583 if (!NT_STATUS_IS_OK(result))
584 goto done;
586 result = cli_lsa_enum_account_rights(cli, mem_ctx, &dom_pol, &sid, &count, &rights);
588 if (!NT_STATUS_IS_OK(result))
589 goto done;
591 printf("found %d privileges for SID %s\n", count, sid_string_static(&sid));
593 for (i = 0; i < count; i++) {
594 printf("\t%s\n", rights[i]);
597 done:
598 return result;
602 /* add some privileges to a SID via LsaAddAccountRights */
604 static NTSTATUS cmd_lsa_add_acct_rights(struct cli_state *cli,
605 TALLOC_CTX *mem_ctx, int argc,
606 const char **argv)
608 POLICY_HND dom_pol;
609 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
611 DOM_SID sid;
613 if (argc < 3 ) {
614 printf("Usage: %s SID [rights...]\n", argv[0]);
615 return NT_STATUS_OK;
618 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
619 if (!NT_STATUS_IS_OK(result))
620 goto done;
622 result = cli_lsa_open_policy2(cli, mem_ctx, True,
623 SEC_RIGHTS_MAXIMUM_ALLOWED,
624 &dom_pol);
626 if (!NT_STATUS_IS_OK(result))
627 goto done;
629 result = cli_lsa_add_account_rights(cli, mem_ctx, &dom_pol, sid,
630 argc-2, argv+2);
632 if (!NT_STATUS_IS_OK(result))
633 goto done;
635 done:
636 return result;
640 /* remove some privileges to a SID via LsaRemoveAccountRights */
642 static NTSTATUS cmd_lsa_remove_acct_rights(struct cli_state *cli,
643 TALLOC_CTX *mem_ctx, int argc,
644 const char **argv)
646 POLICY_HND dom_pol;
647 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
649 DOM_SID sid;
651 if (argc < 3 ) {
652 printf("Usage: %s SID [rights...]\n", argv[0]);
653 return NT_STATUS_OK;
656 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
657 if (!NT_STATUS_IS_OK(result))
658 goto done;
660 result = cli_lsa_open_policy2(cli, mem_ctx, True,
661 SEC_RIGHTS_MAXIMUM_ALLOWED,
662 &dom_pol);
664 if (!NT_STATUS_IS_OK(result))
665 goto done;
667 result = cli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid,
668 False, argc-2, argv+2);
670 if (!NT_STATUS_IS_OK(result))
671 goto done;
673 done:
674 return result;
678 /* Get a privilege value given its name */
680 static NTSTATUS cmd_lsa_lookup_priv_value(struct cli_state *cli,
681 TALLOC_CTX *mem_ctx, int argc,
682 const char **argv)
684 POLICY_HND pol;
685 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
686 LUID luid;
688 if (argc != 2 ) {
689 printf("Usage: %s name\n", argv[0]);
690 return NT_STATUS_OK;
693 result = cli_lsa_open_policy2(cli, mem_ctx, True,
694 SEC_RIGHTS_MAXIMUM_ALLOWED,
695 &pol);
697 if (!NT_STATUS_IS_OK(result))
698 goto done;
700 result = cli_lsa_lookup_priv_value(cli, mem_ctx, &pol, argv[1], &luid);
702 if (!NT_STATUS_IS_OK(result))
703 goto done;
705 /* Print results */
707 printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
709 done:
710 return result;
713 /* Query LSA security object */
715 static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli,
716 TALLOC_CTX *mem_ctx, int argc,
717 const char **argv)
719 POLICY_HND pol;
720 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
721 SEC_DESC_BUF *sdb;
722 uint32 sec_info = 0x00000004; /* ??? */
724 if (argc != 1 ) {
725 printf("Usage: %s\n", argv[0]);
726 return NT_STATUS_OK;
729 result = cli_lsa_open_policy2(cli, mem_ctx, True,
730 SEC_RIGHTS_MAXIMUM_ALLOWED,
731 &pol);
733 if (!NT_STATUS_IS_OK(result))
734 goto done;
736 result = cli_lsa_query_secobj(cli, mem_ctx, &pol, sec_info, &sdb);
738 if (!NT_STATUS_IS_OK(result))
739 goto done;
741 /* Print results */
743 display_sec_desc(sdb->sec);
745 done:
746 return result;
749 static void display_trust_dom_info_1(TRUSTED_DOMAIN_INFO_NAME *n)
751 printf("NetBIOS Name:\t%s\n", unistr2_static(&n->netbios_name.unistring));
754 static void display_trust_dom_info_3(TRUSTED_DOMAIN_INFO_POSIX_OFFSET *p)
756 printf("Posix Offset:\t%d\n", p->posix_offset);
759 static void display_trust_dom_info_4(TRUSTED_DOMAIN_INFO_PASSWORD *p, const char *password)
761 char *pwd, *pwd_old;
763 DATA_BLOB data = data_blob(NULL, p->password.length);
764 DATA_BLOB data_old = data_blob(NULL, p->old_password.length);
766 memcpy(data.data, p->password.data, p->password.length);
767 data.length = p->password.length;
769 memcpy(data_old.data, p->old_password.data, p->old_password.length);
770 data_old.length = p->old_password.length;
772 pwd = decrypt_trustdom_secret(password, &data);
773 pwd_old = decrypt_trustdom_secret(password, &data_old);
775 d_printf("Password:\t%s\n", pwd);
776 d_printf("Old Password:\t%s\n", pwd_old);
778 SAFE_FREE(pwd);
779 SAFE_FREE(pwd_old);
781 data_blob_free(&data);
782 data_blob_free(&data_old);
785 static void display_trust_dom_info(LSA_TRUSTED_DOMAIN_INFO *info, uint32 info_class, const char *pass)
787 switch (info_class) {
788 case 1:
789 display_trust_dom_info_1(&info->name);
790 break;
791 case 3:
792 display_trust_dom_info_3(&info->posix_offset);
793 break;
794 case 4:
795 display_trust_dom_info_4(&info->password, pass);
796 break;
797 default:
798 printf("unsupported info-class: %d\n", info_class);
799 break;
803 static NTSTATUS cmd_lsa_query_trustdominfobysid(struct cli_state *cli,
804 TALLOC_CTX *mem_ctx, int argc,
805 const char **argv)
807 POLICY_HND pol;
808 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
809 DOM_SID dom_sid;
810 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
811 LSA_TRUSTED_DOMAIN_INFO *info;
813 uint32 info_class = 1;
815 if (argc > 3 || argc < 2) {
816 printf("Usage: %s [sid] [info_class]\n", argv[0]);
817 return NT_STATUS_OK;
820 if (!string_to_sid(&dom_sid, argv[1]))
821 return NT_STATUS_NO_MEMORY;
823 if (argc == 3)
824 info_class = atoi(argv[2]);
826 result = cli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
828 if (!NT_STATUS_IS_OK(result))
829 goto done;
831 result = cli_lsa_query_trusted_domain_info_by_sid(cli, mem_ctx, &pol,
832 info_class, &dom_sid, &info);
834 if (!NT_STATUS_IS_OK(result))
835 goto done;
837 display_trust_dom_info(info, info_class, cli->pwd.password);
839 done:
840 if (&pol)
841 cli_lsa_close(cli, mem_ctx, &pol);
843 return result;
846 static NTSTATUS cmd_lsa_query_trustdominfobyname(struct cli_state *cli,
847 TALLOC_CTX *mem_ctx, int argc,
848 const char **argv)
850 POLICY_HND pol;
851 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
852 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
853 LSA_TRUSTED_DOMAIN_INFO *info;
854 uint32 info_class = 1;
856 if (argc > 3 || argc < 2) {
857 printf("Usage: %s [name] [info_class]\n", argv[0]);
858 return NT_STATUS_OK;
861 if (argc == 3)
862 info_class = atoi(argv[2]);
864 result = cli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
866 if (!NT_STATUS_IS_OK(result))
867 goto done;
869 result = cli_lsa_query_trusted_domain_info_by_name(cli, mem_ctx, &pol,
870 info_class, argv[1], &info);
872 if (!NT_STATUS_IS_OK(result))
873 goto done;
875 display_trust_dom_info(info, info_class, cli->pwd.password);
877 done:
878 if (&pol)
879 cli_lsa_close(cli, mem_ctx, &pol);
881 return result;
884 static NTSTATUS cmd_lsa_query_trustdominfo(struct cli_state *cli,
885 TALLOC_CTX *mem_ctx, int argc,
886 const char **argv)
888 POLICY_HND pol, trustdom_pol;
889 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
890 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
891 LSA_TRUSTED_DOMAIN_INFO *info;
892 DOM_SID dom_sid;
893 uint32 info_class = 1;
895 if (argc > 3 || argc < 2) {
896 printf("Usage: %s [sid] [info_class]\n", argv[0]);
897 return NT_STATUS_OK;
900 if (!string_to_sid(&dom_sid, argv[1]))
901 return NT_STATUS_NO_MEMORY;
904 if (argc == 3)
905 info_class = atoi(argv[2]);
907 result = cli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
909 if (!NT_STATUS_IS_OK(result))
910 goto done;
912 result = cli_lsa_open_trusted_domain(cli, mem_ctx, &pol,
913 &dom_sid, access_mask, &trustdom_pol);
915 if (!NT_STATUS_IS_OK(result))
916 goto done;
918 result = cli_lsa_query_trusted_domain_info(cli, mem_ctx, &trustdom_pol,
919 info_class, &dom_sid, &info);
921 if (!NT_STATUS_IS_OK(result))
922 goto done;
924 display_trust_dom_info(info, info_class, cli->pwd.password);
926 done:
927 if (&pol)
928 cli_lsa_close(cli, mem_ctx, &pol);
930 return result;
935 /* List of commands exported by this module */
937 struct cmd_set lsarpc_commands[] = {
939 { "LSARPC" },
941 { "lsaquery", RPC_RTYPE_NTSTATUS, cmd_lsa_query_info_policy, NULL, PI_LSARPC, "Query info policy", "" },
942 { "lookupsids", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_sids, NULL, PI_LSARPC, "Convert SIDs to names", "" },
943 { "lookupnames", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names, NULL, PI_LSARPC, "Convert names to SIDs", "" },
944 { "enumtrust", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_trust_dom, NULL, PI_LSARPC, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
945 { "enumprivs", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privilege, NULL, PI_LSARPC, "Enumerate privileges", "" },
946 { "getdispname", RPC_RTYPE_NTSTATUS, cmd_lsa_get_dispname, NULL, PI_LSARPC, "Get the privilege name", "" },
947 { "lsaenumsid", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_sids, NULL, PI_LSARPC, "Enumerate the LSA SIDS", "" },
948 { "lsacreateaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_create_account, NULL, PI_LSARPC, "Create a new lsa account", "" },
949 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privsaccounts, NULL, PI_LSARPC, "Enumerate the privileges of an SID", "" },
950 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_acct_rights, NULL, PI_LSARPC, "Enumerate the rights of an SID", "" },
951 #if 0
952 { "lsaaddpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_add_priv, NULL, PI_LSARPC, "Assign a privilege to a SID", "" },
953 { "lsadelpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_del_priv, NULL, PI_LSARPC, "Revoke a privilege from a SID", "" },
954 #endif
955 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_add_acct_rights, NULL, PI_LSARPC, "Add rights to an account", "" },
956 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_remove_acct_rights, NULL, PI_LSARPC, "Remove rights from an account", "" },
957 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_priv_value, NULL, PI_LSARPC, "Get a privilege value given its name", "" },
958 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS, cmd_lsa_query_secobj, NULL, PI_LSARPC, "Query LSA security object", "" },
959 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfo, NULL, PI_LSARPC, "Query LSA trusted domains info (given a SID)", "" },
960 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobyname, NULL, PI_LSARPC, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
961 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobysid, NULL, PI_LSARPC, "Query LSA trusted domains info (given a SID)", "" },
963 { NULL }