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("maximum_log_size:\t%d\n", r
->maximum_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
);
71 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
74 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
75 d_printf("Auditing categories:\t%d\n", r
->count
);
76 d_printf("Auditsettings:\n");
77 for (i
=0; i
<r
->count
; i
++) {
78 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
79 const char *policy
= audit_description_str(i
);
80 d_printf("%s:\t%s\n", policy
, val
);
84 static void display_query_info_3(struct lsa_DomainInfo
*r
)
86 d_printf("Domain Name: %s\n", r
->name
.string
);
87 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
90 static void display_query_info_5(struct lsa_DomainInfo
*r
)
92 d_printf("Domain Name: %s\n", r
->name
.string
);
93 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
96 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
98 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
101 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
103 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
104 d_printf("Log is full: %d\n", r
->log_is_full
);
107 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
109 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
110 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
111 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
112 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
113 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
117 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
118 enum lsa_PolicyInfo level
)
122 display_query_info_1(&info
->audit_log
);
125 display_query_info_2(&info
->audit_events
);
128 display_query_info_3(&info
->domain
);
131 display_query_info_5(&info
->account_domain
);
134 display_query_info_10(&info
->auditfullset
);
137 display_query_info_11(&info
->auditfullquery
);
140 display_query_info_12(&info
->dns
);
143 printf("can't display info level: %d\n", level
);
148 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
149 TALLOC_CTX
*mem_ctx
, int argc
,
153 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
154 union lsa_PolicyInformation
*info
= NULL
;
156 uint32 info_class
= 3;
159 printf("Usage: %s [info_class]\n", argv
[0]);
164 info_class
= atoi(argv
[1]);
166 switch (info_class
) {
168 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
169 SEC_RIGHTS_MAXIMUM_ALLOWED
,
172 if (!NT_STATUS_IS_OK(result
))
175 result
= rpccli_lsa_QueryInfoPolicy2(cli
, mem_ctx
,
181 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
182 SEC_RIGHTS_MAXIMUM_ALLOWED
,
185 if (!NT_STATUS_IS_OK(result
))
188 result
= rpccli_lsa_QueryInfoPolicy(cli
, mem_ctx
,
194 if (NT_STATUS_IS_OK(result
)) {
195 display_lsa_query_info(info
, info_class
);
198 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
204 /* Resolve a list of names to a list of sids */
206 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
207 TALLOC_CTX
*mem_ctx
, int argc
,
211 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
213 enum lsa_SidType
*types
;
217 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
221 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
222 SEC_RIGHTS_MAXIMUM_ALLOWED
,
225 if (!NT_STATUS_IS_OK(result
))
228 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
229 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
231 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
232 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
235 result
= NT_STATUS_OK
;
239 for (i
= 0; i
< (argc
- 1); i
++) {
241 sid_to_fstring(sid_str
, &sids
[i
]);
242 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
243 sid_type_lookup(types
[i
]), types
[i
]);
246 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
252 /* Resolve a list of names to a list of sids */
254 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
255 TALLOC_CTX
*mem_ctx
, int argc
,
259 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
261 enum lsa_SidType
*types
;
265 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
269 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
270 SEC_RIGHTS_MAXIMUM_ALLOWED
,
273 if (!NT_STATUS_IS_OK(result
))
276 level
= atoi(argv
[1]);
278 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
279 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
281 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
282 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
285 result
= NT_STATUS_OK
;
289 for (i
= 0; i
< (argc
- 2); i
++) {
291 sid_to_fstring(sid_str
, &sids
[i
]);
292 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
293 sid_type_lookup(types
[i
]), types
[i
]);
296 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
303 /* Resolve a list of SIDs to a list of names */
305 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
306 int argc
, const char **argv
)
309 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
313 enum lsa_SidType
*types
;
317 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
321 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
322 SEC_RIGHTS_MAXIMUM_ALLOWED
,
325 if (!NT_STATUS_IS_OK(result
))
328 /* Convert arguments to sids */
330 sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, argc
- 1);
333 printf("could not allocate memory for %d sids\n", argc
- 1);
337 for (i
= 0; i
< argc
- 1; i
++)
338 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
339 result
= NT_STATUS_INVALID_SID
;
343 /* Lookup the SIDs */
345 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
346 &domains
, &names
, &types
);
348 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
349 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
352 result
= NT_STATUS_OK
;
356 for (i
= 0; i
< (argc
- 1); i
++) {
359 sid_to_fstring(sid_str
, &sids
[i
]);
360 printf("%s %s\\%s (%d)\n", sid_str
,
361 domains
[i
] ? domains
[i
] : "*unknown*",
362 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
365 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
371 /* Enumerate list of trusted domains */
373 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
374 TALLOC_CTX
*mem_ctx
, int argc
,
378 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
379 struct lsa_DomainList domain_list
;
381 /* defaults, but may be changed using params */
384 uint32_t max_size
= (uint32_t)-1;
387 printf("Usage: %s [enum context (0)]\n", argv
[0]);
391 if (argc
== 2 && argv
[1]) {
392 enum_ctx
= atoi(argv
[2]);
395 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
396 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
399 if (!NT_STATUS_IS_OK(result
))
402 result
= STATUS_MORE_ENTRIES
;
404 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
406 /* Lookup list of trusted domains */
408 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
413 if (!NT_STATUS_IS_OK(result
) &&
414 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
415 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
418 /* Print results: list of names and sids returned in this
420 for (i
= 0; i
< domain_list
.count
; i
++) {
423 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
425 domain_list
.domains
[i
].name
.string
?
426 domain_list
.domains
[i
].name
.string
: "*unknown*",
431 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
436 /* Enumerates privileges */
438 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
439 TALLOC_CTX
*mem_ctx
, int argc
,
443 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
444 struct lsa_PrivArray priv_array
;
446 uint32 enum_context
=0;
447 uint32 pref_max_length
=0x1000;
451 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
456 enum_context
=atoi(argv
[1]);
459 pref_max_length
=atoi(argv
[2]);
461 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
462 SEC_RIGHTS_MAXIMUM_ALLOWED
,
465 if (!NT_STATUS_IS_OK(result
))
468 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
473 if (!NT_STATUS_IS_OK(result
))
477 printf("found %d privileges\n\n", priv_array
.count
);
479 for (i
= 0; i
< priv_array
.count
; i
++) {
480 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
481 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
482 priv_array
.privs
[i
].luid
.high
,
483 priv_array
.privs
[i
].luid
.low
,
484 priv_array
.privs
[i
].luid
.high
,
485 priv_array
.privs
[i
].luid
.low
);
488 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
493 /* Get privilege name */
495 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
496 TALLOC_CTX
*mem_ctx
, int argc
,
500 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
503 uint16 lang_id_sys
=0;
505 struct lsa_String lsa_name
;
506 struct lsa_StringLarge
*description
= NULL
;
509 printf("Usage: %s privilege name\n", argv
[0]);
513 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
514 SEC_RIGHTS_MAXIMUM_ALLOWED
,
517 if (!NT_STATUS_IS_OK(result
))
520 init_lsa_String(&lsa_name
, argv
[1]);
522 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
530 if (!NT_STATUS_IS_OK(result
))
534 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
536 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
541 /* Enumerate the LSA SIDS */
543 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
544 TALLOC_CTX
*mem_ctx
, int argc
,
548 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
550 uint32 enum_context
=0;
551 uint32 pref_max_length
=0x1000;
552 struct lsa_SidArray sid_array
;
556 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
561 enum_context
=atoi(argv
[1]);
564 pref_max_length
=atoi(argv
[2]);
566 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
567 SEC_RIGHTS_MAXIMUM_ALLOWED
,
570 if (!NT_STATUS_IS_OK(result
))
573 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
579 if (!NT_STATUS_IS_OK(result
))
583 printf("found %d SIDs\n\n", sid_array
.num_sids
);
585 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
588 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
589 printf("%s\n", sid_str
);
592 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
597 /* Create a new account */
599 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
600 TALLOC_CTX
*mem_ctx
, int argc
,
605 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
606 uint32 des_access
= 0x000f000f;
611 printf("Usage: %s SID\n", argv
[0]);
615 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
616 if (!NT_STATUS_IS_OK(result
))
619 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
620 SEC_RIGHTS_MAXIMUM_ALLOWED
,
623 if (!NT_STATUS_IS_OK(result
))
626 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
632 if (!NT_STATUS_IS_OK(result
))
635 printf("Account for SID %s successfully created\n\n", argv
[1]);
636 result
= NT_STATUS_OK
;
638 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
644 /* Enumerate the privileges of an SID */
646 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
647 TALLOC_CTX
*mem_ctx
, int argc
,
652 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
653 uint32 access_desired
= 0x000f000f;
655 struct lsa_PrivilegeSet
*privs
= NULL
;
659 printf("Usage: %s SID\n", argv
[0]);
663 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
664 if (!NT_STATUS_IS_OK(result
))
667 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
668 SEC_RIGHTS_MAXIMUM_ALLOWED
,
671 if (!NT_STATUS_IS_OK(result
))
674 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
680 if (!NT_STATUS_IS_OK(result
))
683 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
687 if (!NT_STATUS_IS_OK(result
))
691 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
692 printf("high\tlow\tattribute\n");
694 for (i
= 0; i
< privs
->count
; i
++) {
695 printf("%u\t%u\t%u\n",
696 privs
->set
[i
].luid
.high
,
697 privs
->set
[i
].luid
.low
,
698 privs
->set
[i
].attribute
);
701 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
707 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
709 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
710 TALLOC_CTX
*mem_ctx
, int argc
,
714 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
716 struct lsa_RightSet rights
;
721 printf("Usage: %s SID\n", argv
[0]);
725 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
726 if (!NT_STATUS_IS_OK(result
))
729 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
730 SEC_RIGHTS_MAXIMUM_ALLOWED
,
733 if (!NT_STATUS_IS_OK(result
))
736 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
741 if (!NT_STATUS_IS_OK(result
))
744 printf("found %d privileges for SID %s\n", rights
.count
,
745 sid_string_tos(&sid
));
747 for (i
= 0; i
< rights
.count
; i
++) {
748 printf("\t%s\n", rights
.names
[i
].string
);
751 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
757 /* add some privileges to a SID via LsaAddAccountRights */
759 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
760 TALLOC_CTX
*mem_ctx
, int argc
,
764 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
765 struct lsa_RightSet rights
;
770 printf("Usage: %s SID [rights...]\n", argv
[0]);
774 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
775 if (!NT_STATUS_IS_OK(result
))
778 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
779 SEC_RIGHTS_MAXIMUM_ALLOWED
,
782 if (!NT_STATUS_IS_OK(result
))
785 rights
.count
= argc
-2;
786 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
789 return NT_STATUS_NO_MEMORY
;
792 for (i
=0; i
<argc
-2; i
++) {
793 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
796 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
801 if (!NT_STATUS_IS_OK(result
))
804 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
810 /* remove some privileges to a SID via LsaRemoveAccountRights */
812 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
813 TALLOC_CTX
*mem_ctx
, int argc
,
817 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
818 struct lsa_RightSet rights
;
823 printf("Usage: %s SID [rights...]\n", argv
[0]);
827 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
828 if (!NT_STATUS_IS_OK(result
))
831 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
832 SEC_RIGHTS_MAXIMUM_ALLOWED
,
835 if (!NT_STATUS_IS_OK(result
))
838 rights
.count
= argc
-2;
839 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
842 return NT_STATUS_NO_MEMORY
;
845 for (i
=0; i
<argc
-2; i
++) {
846 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
849 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
855 if (!NT_STATUS_IS_OK(result
))
858 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
865 /* Get a privilege value given its name */
867 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
868 TALLOC_CTX
*mem_ctx
, int argc
,
872 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
873 struct lsa_LUID luid
;
874 struct lsa_String name
;
877 printf("Usage: %s name\n", argv
[0]);
881 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
882 SEC_RIGHTS_MAXIMUM_ALLOWED
,
885 if (!NT_STATUS_IS_OK(result
))
888 init_lsa_String(&name
, argv
[1]);
890 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
895 if (!NT_STATUS_IS_OK(result
))
900 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
902 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
907 /* Query LSA security object */
909 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
910 TALLOC_CTX
*mem_ctx
, int argc
,
914 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
916 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
918 if (argc
< 1 || argc
> 2) {
919 printf("Usage: %s [sec_info]\n", argv
[0]);
923 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
924 SEC_RIGHTS_MAXIMUM_ALLOWED
,
928 sscanf(argv
[1], "%x", &sec_info
);
930 if (!NT_STATUS_IS_OK(result
))
933 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
937 if (!NT_STATUS_IS_OK(result
))
942 display_sec_desc(sdb
->sd
);
944 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
949 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
954 DATA_BLOB data
= data_blob(NULL
, p
->password
->length
);
955 DATA_BLOB data_old
= data_blob(NULL
, p
->old_password
->length
);
957 memcpy(data
.data
, p
->password
->data
, p
->password
->length
);
958 memcpy(data_old
.data
, p
->old_password
->data
, p
->old_password
->length
);
960 pwd
= decrypt_trustdom_secret(nt_hash
, &data
);
961 pwd_old
= decrypt_trustdom_secret(nt_hash
, &data_old
);
963 d_printf("Password:\t%s\n", pwd
);
964 d_printf("Old Password:\t%s\n", pwd_old
);
969 data_blob_free(&data
);
970 data_blob_free(&data_old
);
973 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
974 union lsa_TrustedDomainInfo
*info
,
975 enum lsa_TrustDomInfoEnum info_class
,
978 switch (info_class
) {
979 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
980 display_trust_dom_info_4(&info
->password
, nt_hash
);
983 const char *str
= NULL
;
984 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
985 lsa_TrustedDomainInfo
,
988 d_printf("%s\n", str
);
995 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
996 TALLOC_CTX
*mem_ctx
, int argc
,
1000 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1002 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1003 union lsa_TrustedDomainInfo
*info
= NULL
;
1004 enum lsa_TrustDomInfoEnum info_class
= 1;
1005 uint8_t nt_hash
[16];
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 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1032 d_fprintf(stderr
, "Could not get pwd hash\n");
1036 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1039 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1044 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1045 TALLOC_CTX
*mem_ctx
, int argc
,
1049 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1050 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1051 union lsa_TrustedDomainInfo
*info
= NULL
;
1052 enum lsa_TrustDomInfoEnum info_class
= 1;
1053 struct lsa_String trusted_domain
;
1054 uint8_t nt_hash
[16];
1056 if (argc
> 3 || argc
< 2) {
1057 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1058 return NT_STATUS_OK
;
1062 info_class
= atoi(argv
[2]);
1064 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1066 if (!NT_STATUS_IS_OK(result
))
1069 init_lsa_String(&trusted_domain
, argv
[1]);
1071 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1076 if (!NT_STATUS_IS_OK(result
))
1079 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1080 d_fprintf(stderr
, "Could not get pwd hash\n");
1084 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1087 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1092 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1093 TALLOC_CTX
*mem_ctx
, int argc
,
1096 POLICY_HND pol
, trustdom_pol
;
1097 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1098 uint32 access_mask
= SEC_RIGHTS_MAXIMUM_ALLOWED
;
1099 union lsa_TrustedDomainInfo
*info
= NULL
;
1101 enum lsa_TrustDomInfoEnum info_class
= 1;
1102 uint8_t nt_hash
[16];
1104 if (argc
> 3 || argc
< 2) {
1105 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1106 return NT_STATUS_OK
;
1109 if (!string_to_sid(&dom_sid
, argv
[1]))
1110 return NT_STATUS_NO_MEMORY
;
1114 info_class
= atoi(argv
[2]);
1116 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1118 if (!NT_STATUS_IS_OK(result
))
1121 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1127 if (!NT_STATUS_IS_OK(result
))
1130 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1135 if (!NT_STATUS_IS_OK(result
))
1138 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1139 d_fprintf(stderr
, "Could not get pwd hash\n");
1143 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1146 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1151 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1152 TALLOC_CTX
*mem_ctx
, int argc
,
1156 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1157 const char *servername
= cli
->desthost
;
1158 struct lsa_String
*account_name
= NULL
;
1159 struct lsa_String
*authority_name
= NULL
;
1162 printf("Usage: %s servername\n", argv
[0]);
1163 return NT_STATUS_OK
;
1166 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1167 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1170 if (!NT_STATUS_IS_OK(result
)) {
1174 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1178 if (!NT_STATUS_IS_OK(result
)) {
1184 printf("Account Name: %s, Authority Name: %s\n",
1185 account_name
->string
, authority_name
? authority_name
->string
:
1188 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1193 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1194 TALLOC_CTX
*mem_ctx
, int argc
,
1197 POLICY_HND dom_pol
, user_pol
;
1198 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1199 struct lsa_PrivilegeSet privs
;
1200 struct lsa_LUIDAttribute
*set
= NULL
;
1207 printf("Usage: %s SID [rights...]\n", argv
[0]);
1208 return NT_STATUS_OK
;
1211 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1212 if (!NT_STATUS_IS_OK(result
)) {
1216 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1217 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1220 if (!NT_STATUS_IS_OK(result
)) {
1224 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1227 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1230 if (!NT_STATUS_IS_OK(result
)) {
1234 for (i
=2; i
<argc
; i
++) {
1236 struct lsa_String priv_name
;
1237 struct lsa_LUID luid
;
1239 init_lsa_String(&priv_name
, argv
[i
]);
1241 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1245 if (!NT_STATUS_IS_OK(result
)) {
1250 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1251 struct lsa_LUIDAttribute
,
1254 return NT_STATUS_NO_MEMORY
;
1257 set
[privs
.count
-1].luid
= luid
;
1258 set
[privs
.count
-1].attribute
= 0;
1263 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1267 if (!NT_STATUS_IS_OK(result
)) {
1271 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1272 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1277 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1278 TALLOC_CTX
*mem_ctx
, int argc
,
1281 POLICY_HND dom_pol
, user_pol
;
1282 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1283 struct lsa_PrivilegeSet privs
;
1284 struct lsa_LUIDAttribute
*set
= NULL
;
1291 printf("Usage: %s SID [rights...]\n", argv
[0]);
1292 return NT_STATUS_OK
;
1295 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1296 if (!NT_STATUS_IS_OK(result
)) {
1300 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1301 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1304 if (!NT_STATUS_IS_OK(result
)) {
1308 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1311 SEC_RIGHTS_MAXIMUM_ALLOWED
,
1314 if (!NT_STATUS_IS_OK(result
)) {
1318 for (i
=2; i
<argc
; i
++) {
1320 struct lsa_String priv_name
;
1321 struct lsa_LUID luid
;
1323 init_lsa_String(&priv_name
, argv
[i
]);
1325 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1329 if (!NT_STATUS_IS_OK(result
)) {
1334 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1335 struct lsa_LUIDAttribute
,
1338 return NT_STATUS_NO_MEMORY
;
1341 set
[privs
.count
-1].luid
= luid
;
1342 set
[privs
.count
-1].attribute
= 0;
1348 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1353 if (!NT_STATUS_IS_OK(result
)) {
1357 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1358 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1364 /* List of commands exported by this module */
1366 struct cmd_set lsarpc_commands
[] = {
1370 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1371 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1372 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1373 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1374 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
1375 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1376 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1377 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1378 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
1379 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
1380 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
1381 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
1382 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
1383 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
1384 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
1385 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
1386 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
1387 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1388 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobyname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
1389 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1390 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },