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"
25 #include "../libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_lsa.h"
27 #include "../librpc/gen_ndr/cli_lsa.h"
28 #include "rpc_client/cli_lsarpc.h"
29 #include "rpc_client/init_lsa.h"
30 #include "../libcli/security/security.h"
32 /* useful function to allow entering a name instead of a SID and
33 * looking it up automatically */
34 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
36 struct dom_sid
*sid
, const char *name
)
38 struct policy_handle pol
;
39 enum lsa_SidType
*sid_types
;
43 /* maybe its a raw SID */
44 if (strncmp(name
, "S-", 2) == 0 &&
45 string_to_sid(sid
, name
)) {
49 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
50 SEC_FLAG_MAXIMUM_ALLOWED
,
52 if (!NT_STATUS_IS_OK(result
))
55 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
56 if (!NT_STATUS_IS_OK(result
))
59 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
67 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
69 d_printf("percent_full:\t%d\n", r
->percent_full
);
70 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
71 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
72 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
73 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
74 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
77 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
80 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
81 d_printf("Auditing categories:\t%d\n", r
->count
);
82 d_printf("Auditsettings:\n");
83 for (i
=0; i
<r
->count
; i
++) {
84 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
85 const char *policy
= audit_description_str(i
);
86 d_printf("%s:\t%s\n", policy
, val
);
90 static void display_query_info_3(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_5(struct lsa_DomainInfo
*r
)
98 d_printf("Domain Name: %s\n", r
->name
.string
);
99 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
102 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
104 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
107 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
109 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
110 d_printf("Log is full: %d\n", r
->log_is_full
);
113 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
115 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
116 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
117 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
118 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
119 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
123 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
124 enum lsa_PolicyInfo level
)
128 display_query_info_1(&info
->audit_log
);
131 display_query_info_2(&info
->audit_events
);
134 display_query_info_3(&info
->domain
);
137 display_query_info_5(&info
->account_domain
);
140 display_query_info_10(&info
->auditfullset
);
143 display_query_info_11(&info
->auditfullquery
);
146 display_query_info_12(&info
->dns
);
149 printf("can't display info level: %d\n", level
);
154 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
155 TALLOC_CTX
*mem_ctx
, int argc
,
158 struct policy_handle pol
;
159 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
160 union lsa_PolicyInformation
*info
= NULL
;
162 uint32 info_class
= 3;
165 printf("Usage: %s [info_class]\n", argv
[0]);
170 info_class
= atoi(argv
[1]);
172 switch (info_class
) {
174 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
175 SEC_FLAG_MAXIMUM_ALLOWED
,
178 if (!NT_STATUS_IS_OK(result
))
181 result
= rpccli_lsa_QueryInfoPolicy2(cli
, mem_ctx
,
187 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
188 SEC_FLAG_MAXIMUM_ALLOWED
,
191 if (!NT_STATUS_IS_OK(result
))
194 result
= rpccli_lsa_QueryInfoPolicy(cli
, mem_ctx
,
200 if (NT_STATUS_IS_OK(result
)) {
201 display_lsa_query_info(info
, info_class
);
204 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
210 /* Resolve a list of names to a list of sids */
212 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
213 TALLOC_CTX
*mem_ctx
, int argc
,
216 struct policy_handle pol
;
217 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
218 struct dom_sid
*sids
;
219 enum lsa_SidType
*types
;
223 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
227 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
228 SEC_FLAG_MAXIMUM_ALLOWED
,
231 if (!NT_STATUS_IS_OK(result
))
234 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
235 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
237 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
238 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
241 result
= NT_STATUS_OK
;
245 for (i
= 0; i
< (argc
- 1); i
++) {
247 sid_to_fstring(sid_str
, &sids
[i
]);
248 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
249 sid_type_lookup(types
[i
]), types
[i
]);
252 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
258 /* Resolve a list of names to a list of sids */
260 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
261 TALLOC_CTX
*mem_ctx
, int argc
,
264 struct policy_handle pol
;
265 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
266 struct dom_sid
*sids
;
267 enum lsa_SidType
*types
;
271 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
275 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
276 SEC_FLAG_MAXIMUM_ALLOWED
,
279 if (!NT_STATUS_IS_OK(result
))
282 level
= atoi(argv
[1]);
284 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
285 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
287 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
288 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
291 result
= NT_STATUS_OK
;
295 for (i
= 0; i
< (argc
- 2); i
++) {
297 sid_to_fstring(sid_str
, &sids
[i
]);
298 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
299 sid_type_lookup(types
[i
]), types
[i
]);
302 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
308 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
309 TALLOC_CTX
*mem_ctx
, int argc
,
312 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
315 struct lsa_String
*names
;
316 struct lsa_RefDomainList
*domains
;
317 struct lsa_TransSidArray3 sids
;
322 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
329 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
330 NT_STATUS_HAVE_NO_MEMORY(names
);
332 for (i
=0; i
< num_names
; i
++) {
333 init_lsa_String(&names
[i
], argv
[i
+1]);
336 result
= rpccli_lsa_LookupNames4(cli
, mem_ctx
,
345 if (!NT_STATUS_IS_OK(result
)) {
349 for (i
= 0; i
< sids
.count
; i
++) {
351 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
352 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
353 sid_type_lookup(sids
.sids
[i
].sid_type
),
354 sids
.sids
[i
].sid_type
);
360 /* Resolve a list of SIDs to a list of names */
362 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
363 int argc
, const char **argv
)
365 struct policy_handle pol
;
366 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
367 struct dom_sid
*sids
;
370 enum lsa_SidType
*types
;
374 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
378 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
379 SEC_FLAG_MAXIMUM_ALLOWED
,
382 if (!NT_STATUS_IS_OK(result
))
385 /* Convert arguments to sids */
387 sids
= TALLOC_ARRAY(mem_ctx
, struct dom_sid
, argc
- 1);
390 printf("could not allocate memory for %d sids\n", argc
- 1);
394 for (i
= 0; i
< argc
- 1; i
++)
395 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
396 result
= NT_STATUS_INVALID_SID
;
400 /* Lookup the SIDs */
402 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
403 &domains
, &names
, &types
);
405 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
406 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
409 result
= NT_STATUS_OK
;
413 for (i
= 0; i
< (argc
- 1); i
++) {
416 sid_to_fstring(sid_str
, &sids
[i
]);
417 printf("%s %s\\%s (%d)\n", sid_str
,
418 domains
[i
] ? domains
[i
] : "*unknown*",
419 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
422 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
428 /* Resolve a list of SIDs to a list of names */
430 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
432 int argc
, const char **argv
)
434 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
436 struct lsa_SidArray sids
;
437 struct lsa_RefDomainList
*domains
;
438 struct lsa_TransNameArray2 names
;
442 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
448 /* Convert arguments to sids */
450 sids
.num_sids
= argc
-1;
451 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
453 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
457 for (i
= 0; i
< sids
.num_sids
; i
++) {
458 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
459 if (sids
.sids
[i
].sid
== NULL
) {
460 result
= NT_STATUS_NO_MEMORY
;
463 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
464 result
= NT_STATUS_INVALID_SID
;
469 /* Lookup the SIDs */
470 result
= rpccli_lsa_LookupSids3(cli
, mem_ctx
,
479 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
480 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
483 result
= NT_STATUS_OK
;
487 for (i
= 0; i
< count
; i
++) {
490 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
491 printf("%s %s (%d)\n", sid_str
,
492 names
.names
[i
].name
.string
,
493 names
.names
[i
].sid_type
);
501 /* Enumerate list of trusted domains */
503 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
504 TALLOC_CTX
*mem_ctx
, int argc
,
507 struct policy_handle pol
;
508 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
509 struct lsa_DomainList domain_list
;
511 /* defaults, but may be changed using params */
514 uint32_t max_size
= (uint32_t)-1;
517 printf("Usage: %s [enum context (0)]\n", argv
[0]);
521 if (argc
== 2 && argv
[1]) {
522 enum_ctx
= atoi(argv
[2]);
525 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
526 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
529 if (!NT_STATUS_IS_OK(result
))
532 result
= STATUS_MORE_ENTRIES
;
534 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
536 /* Lookup list of trusted domains */
538 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
543 if (!NT_STATUS_IS_OK(result
) &&
544 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
545 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
548 /* Print results: list of names and sids returned in this
550 for (i
= 0; i
< domain_list
.count
; i
++) {
553 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
555 domain_list
.domains
[i
].name
.string
?
556 domain_list
.domains
[i
].name
.string
: "*unknown*",
561 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
566 /* Enumerates privileges */
568 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
569 TALLOC_CTX
*mem_ctx
, int argc
,
572 struct policy_handle pol
;
573 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
574 struct lsa_PrivArray priv_array
;
576 uint32 enum_context
=0;
577 uint32 pref_max_length
=0x1000;
581 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
586 enum_context
=atoi(argv
[1]);
589 pref_max_length
=atoi(argv
[2]);
591 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
592 SEC_FLAG_MAXIMUM_ALLOWED
,
595 if (!NT_STATUS_IS_OK(result
))
598 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
603 if (!NT_STATUS_IS_OK(result
))
607 printf("found %d privileges\n\n", priv_array
.count
);
609 for (i
= 0; i
< priv_array
.count
; i
++) {
610 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
611 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
612 priv_array
.privs
[i
].luid
.high
,
613 priv_array
.privs
[i
].luid
.low
,
614 priv_array
.privs
[i
].luid
.high
,
615 priv_array
.privs
[i
].luid
.low
);
618 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
623 /* Get privilege name */
625 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
626 TALLOC_CTX
*mem_ctx
, int argc
,
629 struct policy_handle pol
;
630 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
633 uint16 lang_id_sys
=0;
635 struct lsa_String lsa_name
;
636 struct lsa_StringLarge
*description
= NULL
;
639 printf("Usage: %s privilege name\n", argv
[0]);
643 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
644 SEC_FLAG_MAXIMUM_ALLOWED
,
647 if (!NT_STATUS_IS_OK(result
))
650 init_lsa_String(&lsa_name
, argv
[1]);
652 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
660 if (!NT_STATUS_IS_OK(result
))
664 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
666 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
671 /* Enumerate the LSA SIDS */
673 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
674 TALLOC_CTX
*mem_ctx
, int argc
,
677 struct policy_handle pol
;
678 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
680 uint32 enum_context
=0;
681 uint32 pref_max_length
=0x1000;
682 struct lsa_SidArray sid_array
;
686 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
691 enum_context
=atoi(argv
[1]);
694 pref_max_length
=atoi(argv
[2]);
696 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
697 SEC_FLAG_MAXIMUM_ALLOWED
,
700 if (!NT_STATUS_IS_OK(result
))
703 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
709 if (!NT_STATUS_IS_OK(result
))
713 printf("found %d SIDs\n\n", sid_array
.num_sids
);
715 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
718 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
719 printf("%s\n", sid_str
);
722 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
727 /* Create a new account */
729 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
730 TALLOC_CTX
*mem_ctx
, int argc
,
733 struct policy_handle dom_pol
;
734 struct policy_handle user_pol
;
735 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
736 uint32 des_access
= 0x000f000f;
741 printf("Usage: %s SID\n", argv
[0]);
745 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
746 if (!NT_STATUS_IS_OK(result
))
749 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
750 SEC_FLAG_MAXIMUM_ALLOWED
,
753 if (!NT_STATUS_IS_OK(result
))
756 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
762 if (!NT_STATUS_IS_OK(result
))
765 printf("Account for SID %s successfully created\n\n", argv
[1]);
766 result
= NT_STATUS_OK
;
768 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
774 /* Enumerate the privileges of an SID */
776 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
777 TALLOC_CTX
*mem_ctx
, int argc
,
780 struct policy_handle dom_pol
;
781 struct policy_handle user_pol
;
782 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
783 uint32 access_desired
= 0x000f000f;
785 struct lsa_PrivilegeSet
*privs
= NULL
;
789 printf("Usage: %s SID\n", argv
[0]);
793 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
794 if (!NT_STATUS_IS_OK(result
))
797 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
798 SEC_FLAG_MAXIMUM_ALLOWED
,
801 if (!NT_STATUS_IS_OK(result
))
804 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
810 if (!NT_STATUS_IS_OK(result
))
813 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
817 if (!NT_STATUS_IS_OK(result
))
821 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
822 printf("high\tlow\tattribute\n");
824 for (i
= 0; i
< privs
->count
; i
++) {
825 printf("%u\t%u\t%u\n",
826 privs
->set
[i
].luid
.high
,
827 privs
->set
[i
].luid
.low
,
828 privs
->set
[i
].attribute
);
831 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
837 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
839 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
840 TALLOC_CTX
*mem_ctx
, int argc
,
843 struct policy_handle dom_pol
;
844 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
846 struct lsa_RightSet rights
;
851 printf("Usage: %s SID\n", argv
[0]);
855 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
856 if (!NT_STATUS_IS_OK(result
))
859 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
860 SEC_FLAG_MAXIMUM_ALLOWED
,
863 if (!NT_STATUS_IS_OK(result
))
866 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
871 if (!NT_STATUS_IS_OK(result
))
874 printf("found %d privileges for SID %s\n", rights
.count
,
875 sid_string_tos(&sid
));
877 for (i
= 0; i
< rights
.count
; i
++) {
878 printf("\t%s\n", rights
.names
[i
].string
);
881 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
887 /* add some privileges to a SID via LsaAddAccountRights */
889 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
890 TALLOC_CTX
*mem_ctx
, int argc
,
893 struct policy_handle dom_pol
;
894 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
895 struct lsa_RightSet rights
;
900 printf("Usage: %s SID [rights...]\n", argv
[0]);
904 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
905 if (!NT_STATUS_IS_OK(result
))
908 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
909 SEC_FLAG_MAXIMUM_ALLOWED
,
912 if (!NT_STATUS_IS_OK(result
))
915 rights
.count
= argc
-2;
916 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
919 return NT_STATUS_NO_MEMORY
;
922 for (i
=0; i
<argc
-2; i
++) {
923 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
926 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
931 if (!NT_STATUS_IS_OK(result
))
934 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
940 /* remove some privileges to a SID via LsaRemoveAccountRights */
942 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
943 TALLOC_CTX
*mem_ctx
, int argc
,
946 struct policy_handle dom_pol
;
947 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
948 struct lsa_RightSet rights
;
953 printf("Usage: %s SID [rights...]\n", argv
[0]);
957 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
958 if (!NT_STATUS_IS_OK(result
))
961 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
962 SEC_FLAG_MAXIMUM_ALLOWED
,
965 if (!NT_STATUS_IS_OK(result
))
968 rights
.count
= argc
-2;
969 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
972 return NT_STATUS_NO_MEMORY
;
975 for (i
=0; i
<argc
-2; i
++) {
976 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
979 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
985 if (!NT_STATUS_IS_OK(result
))
988 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
995 /* Get a privilege value given its name */
997 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
998 TALLOC_CTX
*mem_ctx
, int argc
,
1001 struct policy_handle pol
;
1002 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1003 struct lsa_LUID luid
;
1004 struct lsa_String name
;
1007 printf("Usage: %s name\n", argv
[0]);
1008 return NT_STATUS_OK
;
1011 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1012 SEC_FLAG_MAXIMUM_ALLOWED
,
1015 if (!NT_STATUS_IS_OK(result
))
1018 init_lsa_String(&name
, argv
[1]);
1020 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1025 if (!NT_STATUS_IS_OK(result
))
1030 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1032 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1037 /* Query LSA security object */
1039 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1040 TALLOC_CTX
*mem_ctx
, int argc
,
1043 struct policy_handle pol
;
1044 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1045 struct sec_desc_buf
*sdb
;
1046 uint32 sec_info
= SECINFO_DACL
;
1048 if (argc
< 1 || argc
> 2) {
1049 printf("Usage: %s [sec_info]\n", argv
[0]);
1050 return NT_STATUS_OK
;
1053 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1054 SEC_FLAG_MAXIMUM_ALLOWED
,
1058 sscanf(argv
[1], "%x", &sec_info
);
1060 if (!NT_STATUS_IS_OK(result
))
1063 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
1067 if (!NT_STATUS_IS_OK(result
))
1072 display_sec_desc(sdb
->sd
);
1074 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1079 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1080 uint8_t session_key
[16])
1082 char *pwd
, *pwd_old
;
1084 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1085 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1086 DATA_BLOB session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
1088 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key_blob
);
1089 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key_blob
);
1091 d_printf("Password:\t%s\n", pwd
);
1092 d_printf("Old Password:\t%s\n", pwd_old
);
1095 talloc_free(pwd_old
);
1098 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1099 union lsa_TrustedDomainInfo
*info
,
1100 enum lsa_TrustDomInfoEnum info_class
,
1101 uint8_t nt_hash
[16])
1103 switch (info_class
) {
1104 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1105 display_trust_dom_info_4(&info
->password
, nt_hash
);
1108 const char *str
= NULL
;
1109 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1110 lsa_TrustedDomainInfo
,
1113 d_printf("%s\n", str
);
1120 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1121 TALLOC_CTX
*mem_ctx
, int argc
,
1124 struct policy_handle pol
;
1125 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1126 struct dom_sid dom_sid
;
1127 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1128 union lsa_TrustedDomainInfo
*info
= NULL
;
1129 enum lsa_TrustDomInfoEnum info_class
= 1;
1130 uint8_t nt_hash
[16];
1132 if (argc
> 3 || argc
< 2) {
1133 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1134 return NT_STATUS_OK
;
1137 if (!string_to_sid(&dom_sid
, argv
[1]))
1138 return NT_STATUS_NO_MEMORY
;
1141 info_class
= atoi(argv
[2]);
1143 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1145 if (!NT_STATUS_IS_OK(result
))
1148 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1153 if (!NT_STATUS_IS_OK(result
))
1156 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1157 d_fprintf(stderr
, "Could not get pwd hash\n");
1161 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1164 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1169 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1170 TALLOC_CTX
*mem_ctx
, int argc
,
1173 struct policy_handle pol
;
1174 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1175 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1176 union lsa_TrustedDomainInfo
*info
= NULL
;
1177 enum lsa_TrustDomInfoEnum info_class
= 1;
1178 struct lsa_String trusted_domain
;
1179 uint8_t nt_hash
[16];
1181 if (argc
> 3 || argc
< 2) {
1182 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1183 return NT_STATUS_OK
;
1187 info_class
= atoi(argv
[2]);
1189 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1191 if (!NT_STATUS_IS_OK(result
))
1194 init_lsa_String(&trusted_domain
, argv
[1]);
1196 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1201 if (!NT_STATUS_IS_OK(result
))
1204 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1205 d_fprintf(stderr
, "Could not get pwd hash\n");
1209 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1212 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1217 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1218 TALLOC_CTX
*mem_ctx
, int argc
,
1221 struct policy_handle pol
, trustdom_pol
;
1222 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1223 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1224 union lsa_TrustedDomainInfo
*info
= NULL
;
1225 struct dom_sid dom_sid
;
1226 enum lsa_TrustDomInfoEnum info_class
= 1;
1227 uint8_t nt_hash
[16];
1229 if (argc
> 3 || argc
< 2) {
1230 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1231 return NT_STATUS_OK
;
1234 if (!string_to_sid(&dom_sid
, argv
[1]))
1235 return NT_STATUS_NO_MEMORY
;
1239 info_class
= atoi(argv
[2]);
1241 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1243 if (!NT_STATUS_IS_OK(result
))
1246 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1252 if (!NT_STATUS_IS_OK(result
))
1255 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1260 if (!NT_STATUS_IS_OK(result
))
1263 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1264 d_fprintf(stderr
, "Could not get pwd hash\n");
1268 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1271 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1276 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1277 TALLOC_CTX
*mem_ctx
, int argc
,
1280 struct policy_handle pol
;
1281 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1282 const char *servername
= cli
->desthost
;
1283 struct lsa_String
*account_name
= NULL
;
1284 struct lsa_String
*authority_name
= NULL
;
1287 printf("Usage: %s servername\n", argv
[0]);
1288 return NT_STATUS_OK
;
1291 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1292 SEC_FLAG_MAXIMUM_ALLOWED
,
1295 if (!NT_STATUS_IS_OK(result
)) {
1299 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1303 if (!NT_STATUS_IS_OK(result
)) {
1309 printf("Account Name: %s, Authority Name: %s\n",
1310 account_name
->string
, authority_name
? authority_name
->string
:
1313 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1318 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1319 TALLOC_CTX
*mem_ctx
, int argc
,
1322 struct policy_handle dom_pol
, user_pol
;
1323 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1324 struct lsa_PrivilegeSet privs
;
1325 struct lsa_LUIDAttribute
*set
= NULL
;
1332 printf("Usage: %s SID [rights...]\n", argv
[0]);
1333 return NT_STATUS_OK
;
1336 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1337 if (!NT_STATUS_IS_OK(result
)) {
1341 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1342 SEC_FLAG_MAXIMUM_ALLOWED
,
1345 if (!NT_STATUS_IS_OK(result
)) {
1349 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1352 SEC_FLAG_MAXIMUM_ALLOWED
,
1355 if (!NT_STATUS_IS_OK(result
)) {
1359 for (i
=2; i
<argc
; i
++) {
1361 struct lsa_String priv_name
;
1362 struct lsa_LUID luid
;
1364 init_lsa_String(&priv_name
, argv
[i
]);
1366 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1370 if (!NT_STATUS_IS_OK(result
)) {
1375 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1376 struct lsa_LUIDAttribute
,
1379 return NT_STATUS_NO_MEMORY
;
1382 set
[privs
.count
-1].luid
= luid
;
1383 set
[privs
.count
-1].attribute
= 0;
1388 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1392 if (!NT_STATUS_IS_OK(result
)) {
1396 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1397 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1402 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1403 TALLOC_CTX
*mem_ctx
, int argc
,
1406 struct policy_handle dom_pol
, user_pol
;
1407 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1408 struct lsa_PrivilegeSet privs
;
1409 struct lsa_LUIDAttribute
*set
= NULL
;
1416 printf("Usage: %s SID [rights...]\n", argv
[0]);
1417 return NT_STATUS_OK
;
1420 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1421 if (!NT_STATUS_IS_OK(result
)) {
1425 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1426 SEC_FLAG_MAXIMUM_ALLOWED
,
1429 if (!NT_STATUS_IS_OK(result
)) {
1433 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1436 SEC_FLAG_MAXIMUM_ALLOWED
,
1439 if (!NT_STATUS_IS_OK(result
)) {
1443 for (i
=2; i
<argc
; i
++) {
1445 struct lsa_String priv_name
;
1446 struct lsa_LUID luid
;
1448 init_lsa_String(&priv_name
, argv
[i
]);
1450 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1454 if (!NT_STATUS_IS_OK(result
)) {
1459 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1460 struct lsa_LUIDAttribute
,
1463 return NT_STATUS_NO_MEMORY
;
1466 set
[privs
.count
-1].luid
= luid
;
1467 set
[privs
.count
-1].attribute
= 0;
1473 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1478 if (!NT_STATUS_IS_OK(result
)) {
1482 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1483 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1488 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1489 TALLOC_CTX
*mem_ctx
, int argc
,
1493 struct policy_handle handle
, sec_handle
;
1494 struct lsa_String name
;
1497 printf("Usage: %s name\n", argv
[0]);
1498 return NT_STATUS_OK
;
1501 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1503 SEC_FLAG_MAXIMUM_ALLOWED
,
1505 if (!NT_STATUS_IS_OK(status
)) {
1509 init_lsa_String(&name
, argv
[1]);
1511 status
= rpccli_lsa_CreateSecret(cli
, mem_ctx
,
1514 SEC_FLAG_MAXIMUM_ALLOWED
,
1516 if (!NT_STATUS_IS_OK(status
)) {
1521 if (is_valid_policy_hnd(&sec_handle
)) {
1522 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1524 if (is_valid_policy_hnd(&handle
)) {
1525 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1531 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1532 TALLOC_CTX
*mem_ctx
, int argc
,
1536 struct policy_handle handle
, sec_handle
;
1537 struct lsa_String name
;
1540 printf("Usage: %s name\n", argv
[0]);
1541 return NT_STATUS_OK
;
1544 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1546 SEC_FLAG_MAXIMUM_ALLOWED
,
1548 if (!NT_STATUS_IS_OK(status
)) {
1552 init_lsa_String(&name
, argv
[1]);
1554 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1557 SEC_FLAG_MAXIMUM_ALLOWED
,
1559 if (!NT_STATUS_IS_OK(status
)) {
1563 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1565 if (!NT_STATUS_IS_OK(status
)) {
1570 if (is_valid_policy_hnd(&sec_handle
)) {
1571 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1573 if (is_valid_policy_hnd(&handle
)) {
1574 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1580 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1581 TALLOC_CTX
*mem_ctx
, int argc
,
1585 struct policy_handle handle
, sec_handle
;
1586 struct lsa_String name
;
1587 struct lsa_DATA_BUF_PTR new_val
;
1588 NTTIME new_mtime
= 0;
1589 struct lsa_DATA_BUF_PTR old_val
;
1590 NTTIME old_mtime
= 0;
1591 DATA_BLOB session_key
;
1592 DATA_BLOB new_blob
= data_blob_null
;
1593 DATA_BLOB old_blob
= data_blob_null
;
1594 char *new_secret
, *old_secret
;
1597 printf("Usage: %s name\n", argv
[0]);
1598 return NT_STATUS_OK
;
1601 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1603 SEC_FLAG_MAXIMUM_ALLOWED
,
1605 if (!NT_STATUS_IS_OK(status
)) {
1609 init_lsa_String(&name
, argv
[1]);
1611 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1614 SEC_FLAG_MAXIMUM_ALLOWED
,
1616 if (!NT_STATUS_IS_OK(status
)) {
1620 ZERO_STRUCT(new_val
);
1621 ZERO_STRUCT(old_val
);
1623 status
= rpccli_lsa_QuerySecret(cli
, mem_ctx
,
1629 if (!NT_STATUS_IS_OK(status
)) {
1633 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1634 if (!NT_STATUS_IS_OK(status
)) {
1639 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1642 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1645 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1646 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1648 d_printf("new secret: %s\n", new_secret
);
1651 d_printf("old secret: %s\n", old_secret
);
1655 if (is_valid_policy_hnd(&sec_handle
)) {
1656 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1658 if (is_valid_policy_hnd(&handle
)) {
1659 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1665 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1666 TALLOC_CTX
*mem_ctx
, int argc
,
1670 struct policy_handle handle
, sec_handle
;
1671 struct lsa_String name
;
1672 struct lsa_DATA_BUF new_val
;
1673 struct lsa_DATA_BUF old_val
;
1675 DATA_BLOB session_key
;
1678 printf("Usage: %s name secret\n", argv
[0]);
1679 return NT_STATUS_OK
;
1682 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1684 SEC_FLAG_MAXIMUM_ALLOWED
,
1686 if (!NT_STATUS_IS_OK(status
)) {
1690 init_lsa_String(&name
, argv
[1]);
1692 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1695 SEC_FLAG_MAXIMUM_ALLOWED
,
1697 if (!NT_STATUS_IS_OK(status
)) {
1701 ZERO_STRUCT(new_val
);
1702 ZERO_STRUCT(old_val
);
1704 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1705 if (!NT_STATUS_IS_OK(status
)) {
1709 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1711 new_val
.length
= enc_key
.length
;
1712 new_val
.size
= enc_key
.length
;
1713 new_val
.data
= enc_key
.data
;
1715 status
= rpccli_lsa_SetSecret(cli
, mem_ctx
,
1719 if (!NT_STATUS_IS_OK(status
)) {
1724 if (is_valid_policy_hnd(&sec_handle
)) {
1725 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1727 if (is_valid_policy_hnd(&handle
)) {
1728 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1734 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1735 TALLOC_CTX
*mem_ctx
, int argc
,
1739 struct policy_handle handle
;
1740 struct lsa_String name
;
1741 struct lsa_DATA_BUF
*val
;
1742 DATA_BLOB session_key
;
1743 DATA_BLOB blob
= data_blob_null
;
1747 printf("Usage: %s name\n", argv
[0]);
1748 return NT_STATUS_OK
;
1751 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1753 SEC_FLAG_MAXIMUM_ALLOWED
,
1755 if (!NT_STATUS_IS_OK(status
)) {
1759 init_lsa_String(&name
, argv
[1]);
1763 status
= rpccli_lsa_RetrievePrivateData(cli
, mem_ctx
,
1767 if (!NT_STATUS_IS_OK(status
)) {
1771 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1772 if (!NT_STATUS_IS_OK(status
)) {
1777 blob
= data_blob_const(val
->data
, val
->length
);
1780 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1782 d_printf("secret: %s\n", secret
);
1786 if (is_valid_policy_hnd(&handle
)) {
1787 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1793 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1794 TALLOC_CTX
*mem_ctx
, int argc
,
1798 struct policy_handle handle
;
1799 struct lsa_String name
;
1800 struct lsa_DATA_BUF val
;
1801 DATA_BLOB session_key
;
1805 printf("Usage: %s name secret\n", argv
[0]);
1806 return NT_STATUS_OK
;
1809 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1811 SEC_FLAG_MAXIMUM_ALLOWED
,
1813 if (!NT_STATUS_IS_OK(status
)) {
1817 init_lsa_String(&name
, argv
[1]);
1821 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1822 if (!NT_STATUS_IS_OK(status
)) {
1826 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1828 val
.length
= enc_key
.length
;
1829 val
.size
= enc_key
.length
;
1830 val
.data
= enc_key
.data
;
1832 status
= rpccli_lsa_StorePrivateData(cli
, mem_ctx
,
1836 if (!NT_STATUS_IS_OK(status
)) {
1841 if (is_valid_policy_hnd(&handle
)) {
1842 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1848 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
1849 TALLOC_CTX
*mem_ctx
, int argc
,
1853 struct policy_handle handle
, trustdom_handle
;
1855 struct lsa_DomainInfo info
;
1858 printf("Usage: %s name sid\n", argv
[0]);
1859 return NT_STATUS_OK
;
1862 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1864 SEC_FLAG_MAXIMUM_ALLOWED
,
1866 if (!NT_STATUS_IS_OK(status
)) {
1870 init_lsa_StringLarge(&info
.name
, argv
[1]);
1872 string_to_sid(&sid
, argv
[2]);
1874 status
= rpccli_lsa_CreateTrustedDomain(cli
, mem_ctx
,
1877 SEC_FLAG_MAXIMUM_ALLOWED
,
1879 if (!NT_STATUS_IS_OK(status
)) {
1884 if (is_valid_policy_hnd(&trustdom_handle
)) {
1885 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1888 if (is_valid_policy_hnd(&handle
)) {
1889 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1895 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
1896 TALLOC_CTX
*mem_ctx
, int argc
,
1900 struct policy_handle handle
, trustdom_handle
;
1901 struct lsa_String name
;
1902 struct dom_sid
*sid
= NULL
;
1905 printf("Usage: %s name\n", argv
[0]);
1906 return NT_STATUS_OK
;
1909 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1911 SEC_FLAG_MAXIMUM_ALLOWED
,
1913 if (!NT_STATUS_IS_OK(status
)) {
1917 init_lsa_String(&name
, argv
[1]);
1919 status
= rpccli_lsa_OpenTrustedDomainByName(cli
, mem_ctx
,
1922 SEC_FLAG_MAXIMUM_ALLOWED
,
1924 if (NT_STATUS_IS_OK(status
)) {
1929 uint32_t resume_handle
= 0;
1930 struct lsa_DomainList domains
;
1933 status
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
1938 if (!NT_STATUS_IS_OK(status
)) {
1942 for (i
=0; i
< domains
.count
; i
++) {
1943 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
1944 sid
= domains
.domains
[i
].sid
;
1950 return NT_STATUS_INVALID_SID
;
1954 status
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1957 SEC_FLAG_MAXIMUM_ALLOWED
,
1959 if (!NT_STATUS_IS_OK(status
)) {
1964 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1966 if (!NT_STATUS_IS_OK(status
)) {
1971 if (is_valid_policy_hnd(&trustdom_handle
)) {
1972 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1975 if (is_valid_policy_hnd(&handle
)) {
1976 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1983 /* List of commands exported by this module */
1985 struct cmd_set lsarpc_commands
[] = {
1989 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1990 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1991 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1992 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1993 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1994 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1995 { "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)]" },
1996 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1997 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1998 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1999 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
2000 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
2001 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
2002 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
2003 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
2004 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
2005 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
2006 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
2007 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
2008 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2009 { "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", "" },
2010 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2011 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
2012 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
2013 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
2014 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
2015 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
2016 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
2017 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },
2018 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Trusted Domain", "" },
2019 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Trusted Domain", "" },