2 Unix SMB/CIFS implementation.
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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "rpcclient.h"
26 /* useful function to allow entering a name instead of a SID and
27 * looking it up automatically */
28 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
30 DOM_SID
*sid
, const char *name
)
33 enum lsa_SidType
*sid_types
;
37 /* maybe its a raw SID */
38 if (strncmp(name
, "S-", 2) == 0 &&
39 string_to_sid(sid
, name
)) {
43 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
44 SEC_RIGHTS_MAXIMUM_ALLOWED
,
46 if (!NT_STATUS_IS_OK(result
))
49 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
50 if (!NT_STATUS_IS_OK(result
))
53 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
61 static void display_query_info_1(DOM_QUERY_1 d
)
63 d_printf("percent_full:\t%d\n", d
.percent_full
);
64 d_printf("log_size:\t%d\n", d
.log_size
);
65 d_printf("retention_time:\t%lld\n", (long long)d
.retention_time
);
66 d_printf("shutdown_in_progress:\t%d\n", d
.shutdown_in_progress
);
67 d_printf("time_to_shutdown:\t%lld\n", (long long)d
.time_to_shutdown
);
68 d_printf("next_audit_record:\t%d\n", d
.next_audit_record
);
69 d_printf("unknown:\t%d\n", d
.unknown
);
72 static void display_query_info_2(DOM_QUERY_2 d
, TALLOC_CTX
*mem_ctx
)
75 d_printf("Auditing enabled:\t%d\n", d
.auditing_enabled
);
76 d_printf("Auditing categories:\t%d\n", d
.count1
);
77 d_printf("Auditsettings:\n");
78 for (i
=0; i
<d
.count1
; i
++) {
79 const char *val
= audit_policy_str(mem_ctx
, d
.auditsettings
[i
]);
80 const char *policy
= audit_description_str(i
);
81 d_printf("%s:\t%s\n", policy
, val
);
85 static void display_query_info_3(DOM_QUERY_3 d
)
89 unistr2_to_ascii(name
, &d
.uni_domain_name
, d
.uni_dom_max_len
);
91 d_printf("Domain Name: %s\n", name
);
92 d_printf("Domain Sid: %s\n", sid_string_static(&d
.dom_sid
.sid
));
95 static void display_query_info_5(DOM_QUERY_5 d
)
99 unistr2_to_ascii(name
, &d
.uni_domain_name
, d
.uni_dom_max_len
);
101 d_printf("Domain Name: %s\n", name
);
102 d_printf("Domain Sid: %s\n", sid_string_static(&d
.dom_sid
.sid
));
105 static void display_query_info_10(DOM_QUERY_10 d
)
107 d_printf("Shutdown on full: %d\n", d
.shutdown_on_full
);
110 static void display_query_info_11(DOM_QUERY_11 d
)
112 d_printf("Shutdown on full: %d\n", d
.shutdown_on_full
);
113 d_printf("Log is full: %d\n", d
.log_is_full
);
114 d_printf("Unknown: %d\n", d
.unknown
);
117 static void display_query_info_12(DOM_QUERY_12 d
)
119 fstring dom_name
, dns_dom_name
, forest_name
;
121 unistr2_to_ascii(dom_name
, &d
.uni_nb_dom_name
, d
.hdr_nb_dom_name
.uni_max_len
);
122 unistr2_to_ascii(dns_dom_name
, &d
.uni_dns_dom_name
, d
.hdr_dns_dom_name
.uni_max_len
);
123 unistr2_to_ascii(forest_name
, &d
.uni_forest_name
, d
.hdr_forest_name
.uni_max_len
);
125 d_printf("Domain NetBios Name: %s\n", dom_name
);
126 d_printf("Domain DNS Name: %s\n", dns_dom_name
);
127 d_printf("Domain Forest Name: %s\n", forest_name
);
128 d_printf("Domain Sid: %s\n", sid_string_static(&d
.dom_sid
.sid
));
129 d_printf("Domain GUID: %s\n", smb_uuid_string_static(d
.dom_guid
));
135 static void display_lsa_query_info(LSA_INFO_CTR
*dom
, TALLOC_CTX
*mem_ctx
)
137 switch (dom
->info_class
) {
139 display_query_info_1(dom
->info
.id1
);
142 display_query_info_2(dom
->info
.id2
, mem_ctx
);
145 display_query_info_3(dom
->info
.id3
);
148 display_query_info_5(dom
->info
.id5
);
151 display_query_info_10(dom
->info
.id10
);
154 display_query_info_11(dom
->info
.id11
);
157 display_query_info_12(dom
->info
.id12
);
160 printf("can't display info level: %d\n", dom
->info_class
);
165 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
166 TALLOC_CTX
*mem_ctx
, int argc
,
170 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
173 uint32 info_class
= 3;
176 printf("Usage: %s [info_class]\n", argv
[0]);
181 info_class
= atoi(argv
[1]);
183 switch (info_class
) {
185 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
186 SEC_RIGHTS_MAXIMUM_ALLOWED
,
189 if (!NT_STATUS_IS_OK(result
))
192 result
= rpccli_lsa_query_info_policy2_new(cli
, mem_ctx
, &pol
,
196 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
197 SEC_RIGHTS_MAXIMUM_ALLOWED
,
200 if (!NT_STATUS_IS_OK(result
))
203 result
= rpccli_lsa_query_info_policy_new(cli
, mem_ctx
, &pol
,
208 display_lsa_query_info(&dom
, mem_ctx
);
210 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
216 /* Resolve a list of names to a list of sids */
218 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
219 TALLOC_CTX
*mem_ctx
, int argc
,
223 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
225 enum lsa_SidType
*types
;
229 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
233 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
234 SEC_RIGHTS_MAXIMUM_ALLOWED
,
237 if (!NT_STATUS_IS_OK(result
))
240 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
241 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
243 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
244 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
247 result
= NT_STATUS_OK
;
251 for (i
= 0; i
< (argc
- 1); i
++) {
253 sid_to_string(sid_str
, &sids
[i
]);
254 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
255 sid_type_lookup(types
[i
]), types
[i
]);
258 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
264 /* Resolve a list of names to a list of sids */
266 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
267 TALLOC_CTX
*mem_ctx
, int argc
,
271 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
273 enum lsa_SidType
*types
;
277 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
281 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
282 SEC_RIGHTS_MAXIMUM_ALLOWED
,
285 if (!NT_STATUS_IS_OK(result
))
288 level
= atoi(argv
[1]);
290 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
291 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
293 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
294 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
297 result
= NT_STATUS_OK
;
301 for (i
= 0; i
< (argc
- 2); i
++) {
303 sid_to_string(sid_str
, &sids
[i
]);
304 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
305 sid_type_lookup(types
[i
]), types
[i
]);
308 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
315 /* Resolve a list of SIDs to a list of names */
317 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
318 int argc
, const char **argv
)
321 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
325 enum lsa_SidType
*types
;
329 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
333 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
334 SEC_RIGHTS_MAXIMUM_ALLOWED
,
337 if (!NT_STATUS_IS_OK(result
))
340 /* Convert arguments to sids */
342 sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, argc
- 1);
345 printf("could not allocate memory for %d sids\n", argc
- 1);
349 for (i
= 0; i
< argc
- 1; i
++)
350 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
351 result
= NT_STATUS_INVALID_SID
;
355 /* Lookup the SIDs */
357 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
358 &domains
, &names
, &types
);
360 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
361 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
364 result
= NT_STATUS_OK
;
368 for (i
= 0; i
< (argc
- 1); i
++) {
371 sid_to_string(sid_str
, &sids
[i
]);
372 printf("%s %s\\%s (%d)\n", sid_str
,
373 domains
[i
] ? domains
[i
] : "*unknown*",
374 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
377 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
383 /* Enumerate list of trusted domains */
385 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
386 TALLOC_CTX
*mem_ctx
, int argc
,
390 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
391 DOM_SID
*domain_sids
;
394 /* defaults, but may be changed using params */
396 uint32 num_domains
= 0;
400 printf("Usage: %s [enum context (0)]\n", argv
[0]);
404 if (argc
== 2 && argv
[1]) {
405 enum_ctx
= atoi(argv
[2]);
408 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
409 POLICY_VIEW_LOCAL_INFORMATION
,
412 if (!NT_STATUS_IS_OK(result
))
415 result
= STATUS_MORE_ENTRIES
;
417 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
419 /* Lookup list of trusted domains */
421 result
= rpccli_lsa_enum_trust_dom(cli
, mem_ctx
, &pol
, &enum_ctx
,
423 &domain_names
, &domain_sids
);
424 if (!NT_STATUS_IS_OK(result
) &&
425 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
426 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
429 /* Print results: list of names and sids returned in this
431 for (i
= 0; i
< num_domains
; i
++) {
434 sid_to_string(sid_str
, &domain_sids
[i
]);
435 printf("%s %s\n", domain_names
[i
] ? domain_names
[i
] :
436 "*unknown*", sid_str
);
440 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
445 /* Enumerates privileges */
447 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
448 TALLOC_CTX
*mem_ctx
, int argc
,
452 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
454 uint32 enum_context
=0;
455 uint32 pref_max_length
=0x1000;
463 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
468 enum_context
=atoi(argv
[1]);
471 pref_max_length
=atoi(argv
[2]);
473 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
474 SEC_RIGHTS_MAXIMUM_ALLOWED
,
477 if (!NT_STATUS_IS_OK(result
))
480 result
= rpccli_lsa_enum_privilege(cli
, mem_ctx
, &pol
, &enum_context
, pref_max_length
,
481 &count
, &privs_name
, &privs_high
, &privs_low
);
483 if (!NT_STATUS_IS_OK(result
))
487 printf("found %d privileges\n\n", count
);
489 for (i
= 0; i
< count
; i
++) {
490 printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name
[i
] ? privs_name
[i
] : "*unknown*",
491 privs_high
[i
], privs_low
[i
], privs_high
[i
], privs_low
[i
]);
494 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
499 /* Get privilege name */
501 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
502 TALLOC_CTX
*mem_ctx
, int argc
,
506 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
509 uint16 lang_id_sys
=0;
514 printf("Usage: %s privilege name\n", argv
[0]);
518 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
519 SEC_RIGHTS_MAXIMUM_ALLOWED
,
522 if (!NT_STATUS_IS_OK(result
))
525 result
= rpccli_lsa_get_dispname(cli
, mem_ctx
, &pol
, argv
[1], lang_id
, lang_id_sys
, description
, &lang_id_desc
);
527 if (!NT_STATUS_IS_OK(result
))
531 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
, lang_id_desc
);
533 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
538 /* Enumerate the LSA SIDS */
540 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
541 TALLOC_CTX
*mem_ctx
, int argc
,
545 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
547 uint32 enum_context
=0;
548 uint32 pref_max_length
=0x1000;
554 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
559 enum_context
=atoi(argv
[1]);
562 pref_max_length
=atoi(argv
[2]);
564 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
565 SEC_RIGHTS_MAXIMUM_ALLOWED
,
568 if (!NT_STATUS_IS_OK(result
))
571 result
= rpccli_lsa_enum_sids(cli
, mem_ctx
, &pol
, &enum_context
, pref_max_length
,
574 if (!NT_STATUS_IS_OK(result
))
578 printf("found %d SIDs\n\n", count
);
580 for (i
= 0; i
< count
; i
++) {
583 sid_to_string(sid_str
, &sids
[i
]);
584 printf("%s\n", sid_str
);
587 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
592 /* Create a new account */
594 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
595 TALLOC_CTX
*mem_ctx
, int argc
,
600 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
601 uint32 des_access
= 0x000f000f;
606 printf("Usage: %s SID\n", argv
[0]);
610 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
611 if (!NT_STATUS_IS_OK(result
))
614 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
615 SEC_RIGHTS_MAXIMUM_ALLOWED
,
618 if (!NT_STATUS_IS_OK(result
))
621 result
= rpccli_lsa_create_account(cli
, mem_ctx
, &dom_pol
, &sid
, des_access
, &user_pol
);
623 if (!NT_STATUS_IS_OK(result
))
626 printf("Account for SID %s successfully created\n\n", argv
[1]);
627 result
= NT_STATUS_OK
;
629 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
635 /* Enumerate the privileges of an SID */
637 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
638 TALLOC_CTX
*mem_ctx
, int argc
,
643 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
644 uint32 access_desired
= 0x000f000f;
652 printf("Usage: %s SID\n", argv
[0]);
656 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
657 if (!NT_STATUS_IS_OK(result
))
660 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
661 SEC_RIGHTS_MAXIMUM_ALLOWED
,
664 if (!NT_STATUS_IS_OK(result
))
667 result
= rpccli_lsa_open_account(cli
, mem_ctx
, &dom_pol
, &sid
, access_desired
, &user_pol
);
669 if (!NT_STATUS_IS_OK(result
))
672 result
= rpccli_lsa_enum_privsaccount(cli
, mem_ctx
, &user_pol
, &count
, &set
);
674 if (!NT_STATUS_IS_OK(result
))
678 printf("found %d privileges for SID %s\n\n", count
, argv
[1]);
679 printf("high\tlow\tattribute\n");
681 for (i
= 0; i
< count
; i
++) {
682 printf("%u\t%u\t%u\n", set
[i
].luid
.high
, set
[i
].luid
.low
, set
[i
].attr
);
685 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
691 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
693 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
694 TALLOC_CTX
*mem_ctx
, int argc
,
698 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
707 printf("Usage: %s SID\n", argv
[0]);
711 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
712 if (!NT_STATUS_IS_OK(result
))
715 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
716 SEC_RIGHTS_MAXIMUM_ALLOWED
,
719 if (!NT_STATUS_IS_OK(result
))
722 result
= rpccli_lsa_enum_account_rights(cli
, mem_ctx
, &dom_pol
, &sid
, &count
, &rights
);
724 if (!NT_STATUS_IS_OK(result
))
727 printf("found %d privileges for SID %s\n", count
, sid_string_static(&sid
));
729 for (i
= 0; i
< count
; i
++) {
730 printf("\t%s\n", rights
[i
]);
733 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
739 /* add some privileges to a SID via LsaAddAccountRights */
741 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
742 TALLOC_CTX
*mem_ctx
, int argc
,
746 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
751 printf("Usage: %s SID [rights...]\n", argv
[0]);
755 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
756 if (!NT_STATUS_IS_OK(result
))
759 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
760 SEC_RIGHTS_MAXIMUM_ALLOWED
,
763 if (!NT_STATUS_IS_OK(result
))
766 result
= rpccli_lsa_add_account_rights(cli
, mem_ctx
, &dom_pol
, sid
,
769 if (!NT_STATUS_IS_OK(result
))
772 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
778 /* remove some privileges to a SID via LsaRemoveAccountRights */
780 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
781 TALLOC_CTX
*mem_ctx
, int argc
,
785 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
790 printf("Usage: %s SID [rights...]\n", argv
[0]);
794 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
795 if (!NT_STATUS_IS_OK(result
))
798 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
799 SEC_RIGHTS_MAXIMUM_ALLOWED
,
802 if (!NT_STATUS_IS_OK(result
))
805 result
= rpccli_lsa_remove_account_rights(cli
, mem_ctx
, &dom_pol
, sid
,
806 False
, argc
-2, argv
+2);
808 if (!NT_STATUS_IS_OK(result
))
811 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
818 /* Get a privilege value given its name */
820 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
821 TALLOC_CTX
*mem_ctx
, int argc
,
825 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
829 printf("Usage: %s name\n", argv
[0]);
833 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
834 SEC_RIGHTS_MAXIMUM_ALLOWED
,
837 if (!NT_STATUS_IS_OK(result
))
840 result
= rpccli_lsa_lookup_priv_value(cli
, mem_ctx
, &pol
, argv
[1], &luid
);
842 if (!NT_STATUS_IS_OK(result
))
847 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
849 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
854 /* Query LSA security object */
856 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
857 TALLOC_CTX
*mem_ctx
, int argc
,
861 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
863 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
865 if (argc
< 1 || argc
> 2) {
866 printf("Usage: %s [sec_info]\n", argv
[0]);
870 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
871 SEC_RIGHTS_MAXIMUM_ALLOWED
,
875 sscanf(argv
[1], "%x", &sec_info
);
877 if (!NT_STATUS_IS_OK(result
))
880 result
= rpccli_lsa_query_secobj(cli
, mem_ctx
, &pol
, sec_info
, &sdb
);
882 if (!NT_STATUS_IS_OK(result
))
887 display_sec_desc(sdb
->sd
);
889 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
894 static void display_trust_dom_info_1(TRUSTED_DOMAIN_INFO_NAME
*n
)
896 printf("NetBIOS Name:\t%s\n", unistr2_static(&n
->netbios_name
.unistring
));
899 static void display_trust_dom_info_3(TRUSTED_DOMAIN_INFO_POSIX_OFFSET
*p
)
901 printf("Posix Offset:\t%08x (%d)\n", p
->posix_offset
, p
->posix_offset
);
904 static void display_trust_dom_info_4(TRUSTED_DOMAIN_INFO_PASSWORD
*p
, const char *password
)
908 DATA_BLOB data
= data_blob(NULL
, p
->password
.length
);
909 DATA_BLOB data_old
= data_blob(NULL
, p
->old_password
.length
);
911 memcpy(data
.data
, p
->password
.data
, p
->password
.length
);
912 memcpy(data_old
.data
, p
->old_password
.data
, p
->old_password
.length
);
914 pwd
= decrypt_trustdom_secret(password
, &data
);
915 pwd_old
= decrypt_trustdom_secret(password
, &data_old
);
917 d_printf("Password:\t%s\n", pwd
);
918 d_printf("Old Password:\t%s\n", pwd_old
);
923 data_blob_free(&data
);
924 data_blob_free(&data_old
);
927 static void display_trust_dom_info_6(TRUSTED_DOMAIN_INFO_EX
*i
)
929 printf("Domain Name:\t\t%s\n", unistr2_static(&i
->domain_name
.unistring
));
930 printf("NetBIOS Name:\t\t%s\n", unistr2_static(&i
->netbios_name
.unistring
));
931 printf("SID:\t\t\t%s\n", sid_string_static(&i
->sid
.sid
));
932 printf("Trust Direction:\t0x%08x\n", i
->trust_direction
);
933 printf("Trust Type:\t\t0x%08x\n", i
->trust_type
);
934 printf("Trust Attributes:\t0x%08x\n", i
->trust_attributes
);
938 static void display_trust_dom_info(LSA_TRUSTED_DOMAIN_INFO
*info
, uint32 info_class
, const char *pass
)
940 switch (info_class
) {
942 display_trust_dom_info_1(&info
->name
);
945 display_trust_dom_info_3(&info
->posix_offset
);
948 display_trust_dom_info_4(&info
->password
, pass
);
951 display_trust_dom_info_6(&info
->info_ex
);
954 printf("unsupported info-class: %d\n", info_class
);
959 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
960 TALLOC_CTX
*mem_ctx
, int argc
,
964 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
966 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
967 LSA_TRUSTED_DOMAIN_INFO
*info
;
969 uint32 info_class
= 1;
971 if (argc
> 3 || argc
< 2) {
972 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
976 if (!string_to_sid(&dom_sid
, argv
[1]))
977 return NT_STATUS_NO_MEMORY
;
980 info_class
= atoi(argv
[2]);
982 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
984 if (!NT_STATUS_IS_OK(result
))
987 result
= rpccli_lsa_query_trusted_domain_info_by_sid(cli
, mem_ctx
, &pol
,
988 info_class
, &dom_sid
, &info
);
990 if (!NT_STATUS_IS_OK(result
))
993 display_trust_dom_info(info
, info_class
, cli
->pwd
.password
);
997 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1002 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1003 TALLOC_CTX
*mem_ctx
, int argc
,
1007 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1008 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1009 LSA_TRUSTED_DOMAIN_INFO
*info
;
1010 uint32 info_class
= 1;
1012 if (argc
> 3 || argc
< 2) {
1013 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1014 return NT_STATUS_OK
;
1018 info_class
= atoi(argv
[2]);
1020 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1022 if (!NT_STATUS_IS_OK(result
))
1025 result
= rpccli_lsa_query_trusted_domain_info_by_name(cli
, mem_ctx
, &pol
,
1026 info_class
, argv
[1], &info
);
1028 if (!NT_STATUS_IS_OK(result
))
1031 display_trust_dom_info(info
, info_class
, cli
->pwd
.password
);
1035 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1040 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1041 TALLOC_CTX
*mem_ctx
, int argc
,
1044 POLICY_HND pol
, trustdom_pol
;
1045 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1046 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1047 LSA_TRUSTED_DOMAIN_INFO
*info
;
1049 uint32 info_class
= 1;
1051 if (argc
> 3 || argc
< 2) {
1052 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1053 return NT_STATUS_OK
;
1056 if (!string_to_sid(&dom_sid
, argv
[1]))
1057 return NT_STATUS_NO_MEMORY
;
1061 info_class
= atoi(argv
[2]);
1063 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1065 if (!NT_STATUS_IS_OK(result
))
1068 result
= rpccli_lsa_open_trusted_domain(cli
, mem_ctx
, &pol
,
1069 &dom_sid
, access_mask
, &trustdom_pol
);
1071 if (!NT_STATUS_IS_OK(result
))
1074 result
= rpccli_lsa_query_trusted_domain_info(cli
, mem_ctx
, &trustdom_pol
,
1077 if (!NT_STATUS_IS_OK(result
))
1080 display_trust_dom_info(info
, info_class
, cli
->pwd
.password
);
1084 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1091 /* List of commands exported by this module */
1093 struct cmd_set lsarpc_commands
[] = {
1097 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, PI_LSARPC
, NULL
, "Query info policy", "" },
1098 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, PI_LSARPC
, NULL
, "Convert SIDs to names", "" },
1099 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, PI_LSARPC
, NULL
, "Convert names to SIDs", "" },
1100 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, PI_LSARPC
, NULL
, "Convert names to SIDs", "" },
1101 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, PI_LSARPC
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
1102 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, PI_LSARPC
, NULL
, "Enumerate privileges", "" },
1103 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, PI_LSARPC
, NULL
, "Get the privilege name", "" },
1104 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, PI_LSARPC
, NULL
, "Enumerate the LSA SIDS", "" },
1105 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, PI_LSARPC
, NULL
, "Create a new lsa account", "" },
1106 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, PI_LSARPC
, NULL
, "Enumerate the privileges of an SID", "" },
1107 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Enumerate the rights of an SID", "" },
1109 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, PI_LSARPC
, "Assign a privilege to a SID", "" },
1110 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, PI_LSARPC
, "Revoke a privilege from a SID", "" },
1112 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Add rights to an account", "" },
1113 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Remove rights from an account", "" },
1114 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, PI_LSARPC
, NULL
, "Get a privilege value given its name", "" },
1115 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, PI_LSARPC
, NULL
, "Query LSA security object", "" },
1116 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, PI_LSARPC
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1117 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobyname
, NULL
, PI_LSARPC
, NULL
, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
1118 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, PI_LSARPC
, NULL
, "Query LSA trusted domains info (given a SID)", "" },