2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
7 Copyright (C) Guenther Deschner 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #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(struct lsa_AuditLogInfo
*r
)
63 d_printf("percent_full:\t%d\n", r
->percent_full
);
64 d_printf("log_size:\t%d\n", r
->log_size
);
65 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
66 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
67 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
68 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
69 d_printf("unknown:\t%d\n", r
->unknown
);
72 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
75 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
76 d_printf("Auditing categories:\t%d\n", r
->count
);
77 d_printf("Auditsettings:\n");
78 for (i
=0; i
<r
->count
; i
++) {
79 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[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(struct lsa_DomainInfo
*r
)
87 d_printf("Domain Name: %s\n", r
->name
.string
);
88 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
91 static void display_query_info_5(struct lsa_DomainInfo
*r
)
93 d_printf("Domain Name: %s\n", r
->name
.string
);
94 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
97 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
99 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
102 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
104 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
105 d_printf("Log is full: %d\n", r
->log_is_full
);
106 d_printf("Unknown: %d\n", r
->unknown
);
109 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
111 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
112 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
113 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
114 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
115 d_printf("Domain GUID: %s\n", smb_uuid_string(talloc_tos(),
119 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
120 enum lsa_PolicyInfo level
)
124 display_query_info_1(&info
->audit_log
);
127 display_query_info_2(&info
->audit_events
);
130 display_query_info_3(&info
->domain
);
133 display_query_info_5(&info
->account_domain
);
136 display_query_info_10(&info
->auditfullset
);
139 display_query_info_11(&info
->auditfullquery
);
142 display_query_info_12(&info
->dns
);
145 printf("can't display info level: %d\n", level
);
150 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
151 TALLOC_CTX
*mem_ctx
, int argc
,
155 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
156 union lsa_PolicyInformation
*info
= NULL
;
158 uint32 info_class
= 3;
161 printf("Usage: %s [info_class]\n", argv
[0]);
166 info_class
= atoi(argv
[1]);
168 switch (info_class
) {
170 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
171 SEC_RIGHTS_MAXIMUM_ALLOWED
,
174 if (!NT_STATUS_IS_OK(result
))
177 result
= rpccli_lsa_QueryInfoPolicy2(cli
, mem_ctx
,
183 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
184 SEC_RIGHTS_MAXIMUM_ALLOWED
,
187 if (!NT_STATUS_IS_OK(result
))
190 result
= rpccli_lsa_QueryInfoPolicy(cli
, mem_ctx
,
196 if (NT_STATUS_IS_OK(result
)) {
197 display_lsa_query_info(info
, info_class
);
200 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
206 /* Resolve a list of names to a list of sids */
208 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
209 TALLOC_CTX
*mem_ctx
, int argc
,
213 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
215 enum lsa_SidType
*types
;
219 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
223 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
224 SEC_RIGHTS_MAXIMUM_ALLOWED
,
227 if (!NT_STATUS_IS_OK(result
))
230 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
231 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
233 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
234 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
237 result
= NT_STATUS_OK
;
241 for (i
= 0; i
< (argc
- 1); i
++) {
243 sid_to_fstring(sid_str
, &sids
[i
]);
244 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
245 sid_type_lookup(types
[i
]), types
[i
]);
248 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
254 /* Resolve a list of names to a list of sids */
256 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
257 TALLOC_CTX
*mem_ctx
, int argc
,
261 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
263 enum lsa_SidType
*types
;
267 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
271 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
272 SEC_RIGHTS_MAXIMUM_ALLOWED
,
275 if (!NT_STATUS_IS_OK(result
))
278 level
= atoi(argv
[1]);
280 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
281 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
283 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
284 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
287 result
= NT_STATUS_OK
;
291 for (i
= 0; i
< (argc
- 2); i
++) {
293 sid_to_fstring(sid_str
, &sids
[i
]);
294 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
295 sid_type_lookup(types
[i
]), types
[i
]);
298 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
305 /* Resolve a list of SIDs to a list of names */
307 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
308 int argc
, const char **argv
)
311 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
315 enum lsa_SidType
*types
;
319 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
323 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
324 SEC_RIGHTS_MAXIMUM_ALLOWED
,
327 if (!NT_STATUS_IS_OK(result
))
330 /* Convert arguments to sids */
332 sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, argc
- 1);
335 printf("could not allocate memory for %d sids\n", argc
- 1);
339 for (i
= 0; i
< argc
- 1; i
++)
340 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
341 result
= NT_STATUS_INVALID_SID
;
345 /* Lookup the SIDs */
347 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
348 &domains
, &names
, &types
);
350 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
351 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
354 result
= NT_STATUS_OK
;
358 for (i
= 0; i
< (argc
- 1); i
++) {
361 sid_to_fstring(sid_str
, &sids
[i
]);
362 printf("%s %s\\%s (%d)\n", sid_str
,
363 domains
[i
] ? domains
[i
] : "*unknown*",
364 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
367 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
373 /* Enumerate list of trusted domains */
375 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
376 TALLOC_CTX
*mem_ctx
, int argc
,
380 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
381 struct lsa_DomainList domain_list
;
383 /* defaults, but may be changed using params */
386 uint32_t max_size
= (uint32_t)-1;
389 printf("Usage: %s [enum context (0)]\n", argv
[0]);
393 if (argc
== 2 && argv
[1]) {
394 enum_ctx
= atoi(argv
[2]);
397 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
398 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
401 if (!NT_STATUS_IS_OK(result
))
404 result
= STATUS_MORE_ENTRIES
;
406 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
408 /* Lookup list of trusted domains */
410 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
415 if (!NT_STATUS_IS_OK(result
) &&
416 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
417 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
420 /* Print results: list of names and sids returned in this
422 for (i
= 0; i
< domain_list
.count
; i
++) {
425 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
427 domain_list
.domains
[i
].name
.string
?
428 domain_list
.domains
[i
].name
.string
: "*unknown*",
433 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
438 /* Enumerates privileges */
440 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
441 TALLOC_CTX
*mem_ctx
, int argc
,
445 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
446 struct lsa_PrivArray priv_array
;
448 uint32 enum_context
=0;
449 uint32 pref_max_length
=0x1000;
453 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
458 enum_context
=atoi(argv
[1]);
461 pref_max_length
=atoi(argv
[2]);
463 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
464 SEC_RIGHTS_MAXIMUM_ALLOWED
,
467 if (!NT_STATUS_IS_OK(result
))
470 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
475 if (!NT_STATUS_IS_OK(result
))
479 printf("found %d privileges\n\n", priv_array
.count
);
481 for (i
= 0; i
< priv_array
.count
; i
++) {
482 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
483 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
484 priv_array
.privs
[i
].luid
.high
,
485 priv_array
.privs
[i
].luid
.low
,
486 priv_array
.privs
[i
].luid
.high
,
487 priv_array
.privs
[i
].luid
.low
);
490 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
495 /* Get privilege name */
497 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
498 TALLOC_CTX
*mem_ctx
, int argc
,
502 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
505 uint16 lang_id_sys
=0;
507 struct lsa_String lsa_name
;
508 struct lsa_StringLarge
*description
= NULL
;
511 printf("Usage: %s privilege name\n", argv
[0]);
515 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
516 SEC_RIGHTS_MAXIMUM_ALLOWED
,
519 if (!NT_STATUS_IS_OK(result
))
522 init_lsa_String(&lsa_name
, argv
[1]);
524 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
532 if (!NT_STATUS_IS_OK(result
))
536 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
538 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
543 /* Enumerate the LSA SIDS */
545 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
546 TALLOC_CTX
*mem_ctx
, int argc
,
550 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
552 uint32 enum_context
=0;
553 uint32 pref_max_length
=0x1000;
554 struct lsa_SidArray sid_array
;
558 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
563 enum_context
=atoi(argv
[1]);
566 pref_max_length
=atoi(argv
[2]);
568 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
569 SEC_RIGHTS_MAXIMUM_ALLOWED
,
572 if (!NT_STATUS_IS_OK(result
))
575 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
581 if (!NT_STATUS_IS_OK(result
))
585 printf("found %d SIDs\n\n", sid_array
.num_sids
);
587 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
590 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
591 printf("%s\n", sid_str
);
594 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
599 /* Create a new account */
601 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
602 TALLOC_CTX
*mem_ctx
, int argc
,
607 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
608 uint32 des_access
= 0x000f000f;
613 printf("Usage: %s SID\n", argv
[0]);
617 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
618 if (!NT_STATUS_IS_OK(result
))
621 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
622 SEC_RIGHTS_MAXIMUM_ALLOWED
,
625 if (!NT_STATUS_IS_OK(result
))
628 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
634 if (!NT_STATUS_IS_OK(result
))
637 printf("Account for SID %s successfully created\n\n", argv
[1]);
638 result
= NT_STATUS_OK
;
640 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
646 /* Enumerate the privileges of an SID */
648 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
649 TALLOC_CTX
*mem_ctx
, int argc
,
654 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
655 uint32 access_desired
= 0x000f000f;
657 struct lsa_PrivilegeSet
*privs
= NULL
;
661 printf("Usage: %s SID\n", argv
[0]);
665 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
666 if (!NT_STATUS_IS_OK(result
))
669 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
670 SEC_RIGHTS_MAXIMUM_ALLOWED
,
673 if (!NT_STATUS_IS_OK(result
))
676 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
682 if (!NT_STATUS_IS_OK(result
))
685 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
689 if (!NT_STATUS_IS_OK(result
))
693 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
694 printf("high\tlow\tattribute\n");
696 for (i
= 0; i
< privs
->count
; i
++) {
697 printf("%u\t%u\t%u\n",
698 privs
->set
[i
].luid
.high
,
699 privs
->set
[i
].luid
.low
,
700 privs
->set
[i
].attribute
);
703 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
709 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
711 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
712 TALLOC_CTX
*mem_ctx
, int argc
,
716 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
718 struct lsa_RightSet rights
;
723 printf("Usage: %s SID\n", argv
[0]);
727 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
728 if (!NT_STATUS_IS_OK(result
))
731 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
732 SEC_RIGHTS_MAXIMUM_ALLOWED
,
735 if (!NT_STATUS_IS_OK(result
))
738 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
743 if (!NT_STATUS_IS_OK(result
))
746 printf("found %d privileges for SID %s\n", rights
.count
,
747 sid_string_tos(&sid
));
749 for (i
= 0; i
< rights
.count
; i
++) {
750 printf("\t%s\n", rights
.names
[i
].string
);
753 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
759 /* add some privileges to a SID via LsaAddAccountRights */
761 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
762 TALLOC_CTX
*mem_ctx
, int argc
,
766 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
767 struct lsa_RightSet rights
;
772 printf("Usage: %s SID [rights...]\n", argv
[0]);
776 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
777 if (!NT_STATUS_IS_OK(result
))
780 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
781 SEC_RIGHTS_MAXIMUM_ALLOWED
,
784 if (!NT_STATUS_IS_OK(result
))
787 rights
.count
= argc
-2;
788 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
791 return NT_STATUS_NO_MEMORY
;
794 for (i
=0; i
<argc
-1; i
++) {
795 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
798 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
803 if (!NT_STATUS_IS_OK(result
))
806 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
812 /* remove some privileges to a SID via LsaRemoveAccountRights */
814 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
815 TALLOC_CTX
*mem_ctx
, int argc
,
819 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
820 struct lsa_RightSet rights
;
825 printf("Usage: %s SID [rights...]\n", argv
[0]);
829 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
830 if (!NT_STATUS_IS_OK(result
))
833 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
834 SEC_RIGHTS_MAXIMUM_ALLOWED
,
837 if (!NT_STATUS_IS_OK(result
))
840 rights
.count
= argc
-2;
841 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
844 return NT_STATUS_NO_MEMORY
;
847 for (i
=0; i
<argc
-2; i
++) {
848 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
851 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
857 if (!NT_STATUS_IS_OK(result
))
860 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
867 /* Get a privilege value given its name */
869 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
870 TALLOC_CTX
*mem_ctx
, int argc
,
874 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
875 struct lsa_LUID luid
;
876 struct lsa_String name
;
879 printf("Usage: %s name\n", argv
[0]);
883 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
884 SEC_RIGHTS_MAXIMUM_ALLOWED
,
887 if (!NT_STATUS_IS_OK(result
))
890 init_lsa_String(&name
, argv
[1]);
892 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
897 if (!NT_STATUS_IS_OK(result
))
902 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
904 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
909 /* Query LSA security object */
911 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
912 TALLOC_CTX
*mem_ctx
, int argc
,
916 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
918 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
920 if (argc
< 1 || argc
> 2) {
921 printf("Usage: %s [sec_info]\n", argv
[0]);
925 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
926 SEC_RIGHTS_MAXIMUM_ALLOWED
,
930 sscanf(argv
[1], "%x", &sec_info
);
932 if (!NT_STATUS_IS_OK(result
))
935 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
939 if (!NT_STATUS_IS_OK(result
))
944 display_sec_desc(sdb
->sd
);
946 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
951 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
, const char *password
)
955 DATA_BLOB data
= data_blob(NULL
, p
->password
->length
);
956 DATA_BLOB data_old
= data_blob(NULL
, p
->old_password
->length
);
958 memcpy(data
.data
, p
->password
->data
, p
->password
->length
);
959 memcpy(data_old
.data
, p
->old_password
->data
, p
->old_password
->length
);
961 pwd
= decrypt_trustdom_secret(password
, &data
);
962 pwd_old
= decrypt_trustdom_secret(password
, &data_old
);
964 d_printf("Password:\t%s\n", pwd
);
965 d_printf("Old Password:\t%s\n", pwd_old
);
970 data_blob_free(&data
);
971 data_blob_free(&data_old
);
974 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
975 union lsa_TrustedDomainInfo
*info
,
976 enum lsa_TrustDomInfoEnum info_class
,
979 switch (info_class
) {
980 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
981 display_trust_dom_info_4(&info
->password
, pass
);
984 const char *str
= NULL
;
985 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
986 lsa_TrustedDomainInfo
,
989 d_printf("%s\n", str
);
996 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
997 TALLOC_CTX
*mem_ctx
, int argc
,
1001 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1003 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1004 union lsa_TrustedDomainInfo
*info
= NULL
;
1005 enum lsa_TrustDomInfoEnum info_class
= 1;
1007 if (argc
> 3 || argc
< 2) {
1008 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1009 return NT_STATUS_OK
;
1012 if (!string_to_sid(&dom_sid
, argv
[1]))
1013 return NT_STATUS_NO_MEMORY
;
1016 info_class
= atoi(argv
[2]);
1018 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1020 if (!NT_STATUS_IS_OK(result
))
1023 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1028 if (!NT_STATUS_IS_OK(result
))
1031 display_trust_dom_info(mem_ctx
, info
, info_class
, cli
->pwd
.password
);
1034 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1039 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1040 TALLOC_CTX
*mem_ctx
, int argc
,
1044 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1045 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1046 union lsa_TrustedDomainInfo
*info
= NULL
;
1047 enum lsa_TrustDomInfoEnum info_class
= 1;
1048 struct lsa_String trusted_domain
;
1050 if (argc
> 3 || argc
< 2) {
1051 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1052 return NT_STATUS_OK
;
1056 info_class
= atoi(argv
[2]);
1058 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1060 if (!NT_STATUS_IS_OK(result
))
1063 init_lsa_String(&trusted_domain
, argv
[1]);
1065 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1070 if (!NT_STATUS_IS_OK(result
))
1073 display_trust_dom_info(mem_ctx
, info
, info_class
, cli
->pwd
.password
);
1076 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1081 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1082 TALLOC_CTX
*mem_ctx
, int argc
,
1085 POLICY_HND pol
, trustdom_pol
;
1086 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1087 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1088 union lsa_TrustedDomainInfo
*info
= NULL
;
1090 enum lsa_TrustDomInfoEnum info_class
= 1;
1092 if (argc
> 3 || argc
< 2) {
1093 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1094 return NT_STATUS_OK
;
1097 if (!string_to_sid(&dom_sid
, argv
[1]))
1098 return NT_STATUS_NO_MEMORY
;
1102 info_class
= atoi(argv
[2]);
1104 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1106 if (!NT_STATUS_IS_OK(result
))
1109 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1115 if (!NT_STATUS_IS_OK(result
))
1118 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1123 if (!NT_STATUS_IS_OK(result
))
1126 display_trust_dom_info(mem_ctx
, info
, info_class
, cli
->pwd
.password
);
1129 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1134 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1135 TALLOC_CTX
*mem_ctx
, int argc
,
1139 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1140 const char *servername
= cli
->cli
->desthost
;
1141 struct lsa_String
*account_name
= NULL
;
1142 struct lsa_String
*authority_name
= NULL
;
1145 printf("Usage: %s servername\n", argv
[0]);
1146 return NT_STATUS_OK
;
1149 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1150 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1153 if (!NT_STATUS_IS_OK(result
)) {
1157 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1161 if (!NT_STATUS_IS_OK(result
)) {
1167 printf("Account Name: %s, Authority Name: %s\n",
1168 account_name
->string
, authority_name
->string
);
1170 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1175 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1176 TALLOC_CTX
*mem_ctx
, int argc
,
1179 POLICY_HND dom_pol
, user_pol
;
1180 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1181 struct lsa_PrivilegeSet privs
;
1182 struct lsa_LUIDAttribute
*set
= NULL
;
1189 printf("Usage: %s SID [rights...]\n", argv
[0]);
1190 return NT_STATUS_OK
;
1193 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1194 if (!NT_STATUS_IS_OK(result
)) {
1198 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1199 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1202 if (!NT_STATUS_IS_OK(result
)) {
1206 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1209 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1212 if (!NT_STATUS_IS_OK(result
)) {
1216 for (i
=2; i
<argc
; i
++) {
1218 struct lsa_String priv_name
;
1219 struct lsa_LUID luid
;
1221 init_lsa_String(&priv_name
, argv
[i
]);
1223 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1227 if (!NT_STATUS_IS_OK(result
)) {
1232 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1233 struct lsa_LUIDAttribute
,
1236 return NT_STATUS_NO_MEMORY
;
1239 set
[privs
.count
-1].luid
= luid
;
1240 set
[privs
.count
-1].attribute
= 0;
1245 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1249 if (!NT_STATUS_IS_OK(result
)) {
1253 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1254 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1259 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1260 TALLOC_CTX
*mem_ctx
, int argc
,
1263 POLICY_HND dom_pol
, user_pol
;
1264 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1265 struct lsa_PrivilegeSet privs
;
1266 struct lsa_LUIDAttribute
*set
= NULL
;
1273 printf("Usage: %s SID [rights...]\n", argv
[0]);
1274 return NT_STATUS_OK
;
1277 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1278 if (!NT_STATUS_IS_OK(result
)) {
1282 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1283 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1286 if (!NT_STATUS_IS_OK(result
)) {
1290 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1293 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1296 if (!NT_STATUS_IS_OK(result
)) {
1300 for (i
=2; i
<argc
; i
++) {
1302 struct lsa_String priv_name
;
1303 struct lsa_LUID luid
;
1305 init_lsa_String(&priv_name
, argv
[i
]);
1307 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1311 if (!NT_STATUS_IS_OK(result
)) {
1316 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1317 struct lsa_LUIDAttribute
,
1320 return NT_STATUS_NO_MEMORY
;
1323 set
[privs
.count
-1].luid
= luid
;
1324 set
[privs
.count
-1].attribute
= 0;
1330 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1335 if (!NT_STATUS_IS_OK(result
)) {
1339 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1340 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1346 /* List of commands exported by this module */
1348 struct cmd_set lsarpc_commands
[] = {
1352 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, PI_LSARPC
, NULL
, "Query info policy", "" },
1353 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, PI_LSARPC
, NULL
, "Convert SIDs to names", "" },
1354 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, PI_LSARPC
, NULL
, "Convert names to SIDs", "" },
1355 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, PI_LSARPC
, NULL
, "Convert names to SIDs", "" },
1356 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, PI_LSARPC
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
1357 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, PI_LSARPC
, NULL
, "Enumerate privileges", "" },
1358 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, PI_LSARPC
, NULL
, "Get the privilege name", "" },
1359 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, PI_LSARPC
, NULL
, "Enumerate the LSA SIDS", "" },
1360 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, PI_LSARPC
, NULL
, "Create a new lsa account", "" },
1361 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, PI_LSARPC
, NULL
, "Enumerate the privileges of an SID", "" },
1362 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Enumerate the rights of an SID", "" },
1363 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, PI_LSARPC
, NULL
, "Assign a privilege to a SID", "" },
1364 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, PI_LSARPC
, NULL
, "Revoke a privilege from a SID", "" },
1365 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Add rights to an account", "" },
1366 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, PI_LSARPC
, NULL
, "Remove rights from an account", "" },
1367 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, PI_LSARPC
, NULL
, "Get a privilege value given its name", "" },
1368 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, PI_LSARPC
, NULL
, "Query LSA security object", "" },
1369 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, PI_LSARPC
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1370 { "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", "" },
1371 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, PI_LSARPC
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1372 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, PI_LSARPC
, NULL
, "Get username", "" },