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/cli_lsa.h"
28 /* useful function to allow entering a name instead of a SID and
29 * looking it up automatically */
30 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
32 DOM_SID
*sid
, const char *name
)
34 struct policy_handle pol
;
35 enum lsa_SidType
*sid_types
;
39 /* maybe its a raw SID */
40 if (strncmp(name
, "S-", 2) == 0 &&
41 string_to_sid(sid
, name
)) {
45 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
46 SEC_FLAG_MAXIMUM_ALLOWED
,
48 if (!NT_STATUS_IS_OK(result
))
51 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
52 if (!NT_STATUS_IS_OK(result
))
55 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
63 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
65 d_printf("percent_full:\t%d\n", r
->percent_full
);
66 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
67 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
68 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
69 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
70 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
73 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
76 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
77 d_printf("Auditing categories:\t%d\n", r
->count
);
78 d_printf("Auditsettings:\n");
79 for (i
=0; i
<r
->count
; i
++) {
80 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
81 const char *policy
= audit_description_str(i
);
82 d_printf("%s:\t%s\n", policy
, val
);
86 static void display_query_info_3(struct lsa_DomainInfo
*r
)
88 d_printf("Domain Name: %s\n", r
->name
.string
);
89 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
92 static void display_query_info_5(struct lsa_DomainInfo
*r
)
94 d_printf("Domain Name: %s\n", r
->name
.string
);
95 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
98 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
100 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
103 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
105 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
106 d_printf("Log is full: %d\n", r
->log_is_full
);
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", GUID_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
,
154 struct policy_handle pol
;
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_FLAG_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_FLAG_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
,
212 struct policy_handle pol
;
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_FLAG_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
,
260 struct policy_handle pol
;
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_FLAG_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
);
304 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
305 TALLOC_CTX
*mem_ctx
, int argc
,
308 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
311 struct lsa_String
*names
;
312 struct lsa_RefDomainList
*domains
;
313 struct lsa_TransSidArray3 sids
;
318 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
325 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
326 NT_STATUS_HAVE_NO_MEMORY(names
);
328 for (i
=0; i
< num_names
; i
++) {
329 init_lsa_String(&names
[i
], argv
[i
+1]);
332 result
= rpccli_lsa_LookupNames4(cli
, mem_ctx
,
341 if (!NT_STATUS_IS_OK(result
)) {
345 for (i
= 0; i
< sids
.count
; i
++) {
347 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
348 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
349 sid_type_lookup(sids
.sids
[i
].sid_type
),
350 sids
.sids
[i
].sid_type
);
356 /* Resolve a list of SIDs to a list of names */
358 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
359 int argc
, const char **argv
)
361 struct policy_handle pol
;
362 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
366 enum lsa_SidType
*types
;
370 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
374 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
375 SEC_FLAG_MAXIMUM_ALLOWED
,
378 if (!NT_STATUS_IS_OK(result
))
381 /* Convert arguments to sids */
383 sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, argc
- 1);
386 printf("could not allocate memory for %d sids\n", argc
- 1);
390 for (i
= 0; i
< argc
- 1; i
++)
391 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
392 result
= NT_STATUS_INVALID_SID
;
396 /* Lookup the SIDs */
398 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
399 &domains
, &names
, &types
);
401 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
402 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
405 result
= NT_STATUS_OK
;
409 for (i
= 0; i
< (argc
- 1); i
++) {
412 sid_to_fstring(sid_str
, &sids
[i
]);
413 printf("%s %s\\%s (%d)\n", sid_str
,
414 domains
[i
] ? domains
[i
] : "*unknown*",
415 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
418 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
424 /* Resolve a list of SIDs to a list of names */
426 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
428 int argc
, const char **argv
)
430 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
432 struct lsa_SidArray sids
;
433 struct lsa_RefDomainList
*domains
;
434 struct lsa_TransNameArray2 names
;
438 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
444 /* Convert arguments to sids */
446 sids
.num_sids
= argc
-1;
447 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
449 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
453 for (i
= 0; i
< sids
.num_sids
; i
++) {
454 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
455 if (sids
.sids
[i
].sid
== NULL
) {
456 result
= NT_STATUS_NO_MEMORY
;
459 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
460 result
= NT_STATUS_INVALID_SID
;
465 /* Lookup the SIDs */
466 result
= rpccli_lsa_LookupSids3(cli
, mem_ctx
,
475 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
476 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
479 result
= NT_STATUS_OK
;
483 for (i
= 0; i
< count
; i
++) {
486 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
487 printf("%s %s (%d)\n", sid_str
,
488 names
.names
[i
].name
.string
,
489 names
.names
[i
].sid_type
);
497 /* Enumerate list of trusted domains */
499 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
500 TALLOC_CTX
*mem_ctx
, int argc
,
503 struct policy_handle pol
;
504 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
505 struct lsa_DomainList domain_list
;
507 /* defaults, but may be changed using params */
510 uint32_t max_size
= (uint32_t)-1;
513 printf("Usage: %s [enum context (0)]\n", argv
[0]);
517 if (argc
== 2 && argv
[1]) {
518 enum_ctx
= atoi(argv
[2]);
521 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
522 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
525 if (!NT_STATUS_IS_OK(result
))
528 result
= STATUS_MORE_ENTRIES
;
530 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
532 /* Lookup list of trusted domains */
534 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
539 if (!NT_STATUS_IS_OK(result
) &&
540 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
541 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
544 /* Print results: list of names and sids returned in this
546 for (i
= 0; i
< domain_list
.count
; i
++) {
549 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
551 domain_list
.domains
[i
].name
.string
?
552 domain_list
.domains
[i
].name
.string
: "*unknown*",
557 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
562 /* Enumerates privileges */
564 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
565 TALLOC_CTX
*mem_ctx
, int argc
,
568 struct policy_handle pol
;
569 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
570 struct lsa_PrivArray priv_array
;
572 uint32 enum_context
=0;
573 uint32 pref_max_length
=0x1000;
577 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
582 enum_context
=atoi(argv
[1]);
585 pref_max_length
=atoi(argv
[2]);
587 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
588 SEC_FLAG_MAXIMUM_ALLOWED
,
591 if (!NT_STATUS_IS_OK(result
))
594 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
599 if (!NT_STATUS_IS_OK(result
))
603 printf("found %d privileges\n\n", priv_array
.count
);
605 for (i
= 0; i
< priv_array
.count
; i
++) {
606 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
607 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
608 priv_array
.privs
[i
].luid
.high
,
609 priv_array
.privs
[i
].luid
.low
,
610 priv_array
.privs
[i
].luid
.high
,
611 priv_array
.privs
[i
].luid
.low
);
614 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
619 /* Get privilege name */
621 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
622 TALLOC_CTX
*mem_ctx
, int argc
,
625 struct policy_handle pol
;
626 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
629 uint16 lang_id_sys
=0;
631 struct lsa_String lsa_name
;
632 struct lsa_StringLarge
*description
= NULL
;
635 printf("Usage: %s privilege name\n", argv
[0]);
639 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
640 SEC_FLAG_MAXIMUM_ALLOWED
,
643 if (!NT_STATUS_IS_OK(result
))
646 init_lsa_String(&lsa_name
, argv
[1]);
648 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
656 if (!NT_STATUS_IS_OK(result
))
660 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
662 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
667 /* Enumerate the LSA SIDS */
669 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
670 TALLOC_CTX
*mem_ctx
, int argc
,
673 struct policy_handle pol
;
674 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
676 uint32 enum_context
=0;
677 uint32 pref_max_length
=0x1000;
678 struct lsa_SidArray sid_array
;
682 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
687 enum_context
=atoi(argv
[1]);
690 pref_max_length
=atoi(argv
[2]);
692 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
693 SEC_FLAG_MAXIMUM_ALLOWED
,
696 if (!NT_STATUS_IS_OK(result
))
699 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
705 if (!NT_STATUS_IS_OK(result
))
709 printf("found %d SIDs\n\n", sid_array
.num_sids
);
711 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
714 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
715 printf("%s\n", sid_str
);
718 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
723 /* Create a new account */
725 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
726 TALLOC_CTX
*mem_ctx
, int argc
,
729 struct policy_handle dom_pol
;
730 struct policy_handle user_pol
;
731 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
732 uint32 des_access
= 0x000f000f;
737 printf("Usage: %s SID\n", argv
[0]);
741 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
742 if (!NT_STATUS_IS_OK(result
))
745 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
746 SEC_FLAG_MAXIMUM_ALLOWED
,
749 if (!NT_STATUS_IS_OK(result
))
752 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
758 if (!NT_STATUS_IS_OK(result
))
761 printf("Account for SID %s successfully created\n\n", argv
[1]);
762 result
= NT_STATUS_OK
;
764 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
770 /* Enumerate the privileges of an SID */
772 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
773 TALLOC_CTX
*mem_ctx
, int argc
,
776 struct policy_handle dom_pol
;
777 struct policy_handle user_pol
;
778 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
779 uint32 access_desired
= 0x000f000f;
781 struct lsa_PrivilegeSet
*privs
= NULL
;
785 printf("Usage: %s SID\n", argv
[0]);
789 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
790 if (!NT_STATUS_IS_OK(result
))
793 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
794 SEC_FLAG_MAXIMUM_ALLOWED
,
797 if (!NT_STATUS_IS_OK(result
))
800 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
806 if (!NT_STATUS_IS_OK(result
))
809 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
813 if (!NT_STATUS_IS_OK(result
))
817 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
818 printf("high\tlow\tattribute\n");
820 for (i
= 0; i
< privs
->count
; i
++) {
821 printf("%u\t%u\t%u\n",
822 privs
->set
[i
].luid
.high
,
823 privs
->set
[i
].luid
.low
,
824 privs
->set
[i
].attribute
);
827 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
833 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
835 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
836 TALLOC_CTX
*mem_ctx
, int argc
,
839 struct policy_handle dom_pol
;
840 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
842 struct lsa_RightSet rights
;
847 printf("Usage: %s SID\n", argv
[0]);
851 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
852 if (!NT_STATUS_IS_OK(result
))
855 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
856 SEC_FLAG_MAXIMUM_ALLOWED
,
859 if (!NT_STATUS_IS_OK(result
))
862 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
867 if (!NT_STATUS_IS_OK(result
))
870 printf("found %d privileges for SID %s\n", rights
.count
,
871 sid_string_tos(&sid
));
873 for (i
= 0; i
< rights
.count
; i
++) {
874 printf("\t%s\n", rights
.names
[i
].string
);
877 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
883 /* add some privileges to a SID via LsaAddAccountRights */
885 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
886 TALLOC_CTX
*mem_ctx
, int argc
,
889 struct policy_handle dom_pol
;
890 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
891 struct lsa_RightSet rights
;
896 printf("Usage: %s SID [rights...]\n", argv
[0]);
900 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
901 if (!NT_STATUS_IS_OK(result
))
904 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
905 SEC_FLAG_MAXIMUM_ALLOWED
,
908 if (!NT_STATUS_IS_OK(result
))
911 rights
.count
= argc
-2;
912 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
915 return NT_STATUS_NO_MEMORY
;
918 for (i
=0; i
<argc
-2; i
++) {
919 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
922 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
927 if (!NT_STATUS_IS_OK(result
))
930 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
936 /* remove some privileges to a SID via LsaRemoveAccountRights */
938 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
939 TALLOC_CTX
*mem_ctx
, int argc
,
942 struct policy_handle dom_pol
;
943 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
944 struct lsa_RightSet rights
;
949 printf("Usage: %s SID [rights...]\n", argv
[0]);
953 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
954 if (!NT_STATUS_IS_OK(result
))
957 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
958 SEC_FLAG_MAXIMUM_ALLOWED
,
961 if (!NT_STATUS_IS_OK(result
))
964 rights
.count
= argc
-2;
965 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
968 return NT_STATUS_NO_MEMORY
;
971 for (i
=0; i
<argc
-2; i
++) {
972 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
975 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
981 if (!NT_STATUS_IS_OK(result
))
984 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
991 /* Get a privilege value given its name */
993 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
994 TALLOC_CTX
*mem_ctx
, int argc
,
997 struct policy_handle pol
;
998 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
999 struct lsa_LUID luid
;
1000 struct lsa_String name
;
1003 printf("Usage: %s name\n", argv
[0]);
1004 return NT_STATUS_OK
;
1007 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1008 SEC_FLAG_MAXIMUM_ALLOWED
,
1011 if (!NT_STATUS_IS_OK(result
))
1014 init_lsa_String(&name
, argv
[1]);
1016 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1021 if (!NT_STATUS_IS_OK(result
))
1026 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1028 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1033 /* Query LSA security object */
1035 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1036 TALLOC_CTX
*mem_ctx
, int argc
,
1039 struct policy_handle pol
;
1040 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1042 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
1044 if (argc
< 1 || argc
> 2) {
1045 printf("Usage: %s [sec_info]\n", argv
[0]);
1046 return NT_STATUS_OK
;
1049 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1050 SEC_FLAG_MAXIMUM_ALLOWED
,
1054 sscanf(argv
[1], "%x", &sec_info
);
1056 if (!NT_STATUS_IS_OK(result
))
1059 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
1063 if (!NT_STATUS_IS_OK(result
))
1068 display_sec_desc(sdb
->sd
);
1070 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1075 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1076 uint8_t session_key
[16])
1078 char *pwd
, *pwd_old
;
1080 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1081 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1082 DATA_BLOB session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
1084 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key_blob
);
1085 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key_blob
);
1087 d_printf("Password:\t%s\n", pwd
);
1088 d_printf("Old Password:\t%s\n", pwd_old
);
1091 talloc_free(pwd_old
);
1094 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1095 union lsa_TrustedDomainInfo
*info
,
1096 enum lsa_TrustDomInfoEnum info_class
,
1097 uint8_t nt_hash
[16])
1099 switch (info_class
) {
1100 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1101 display_trust_dom_info_4(&info
->password
, nt_hash
);
1104 const char *str
= NULL
;
1105 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1106 lsa_TrustedDomainInfo
,
1109 d_printf("%s\n", str
);
1116 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1117 TALLOC_CTX
*mem_ctx
, int argc
,
1120 struct policy_handle pol
;
1121 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1123 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1124 union lsa_TrustedDomainInfo
*info
= NULL
;
1125 enum lsa_TrustDomInfoEnum info_class
= 1;
1126 uint8_t nt_hash
[16];
1128 if (argc
> 3 || argc
< 2) {
1129 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1130 return NT_STATUS_OK
;
1133 if (!string_to_sid(&dom_sid
, argv
[1]))
1134 return NT_STATUS_NO_MEMORY
;
1137 info_class
= atoi(argv
[2]);
1139 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1141 if (!NT_STATUS_IS_OK(result
))
1144 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1149 if (!NT_STATUS_IS_OK(result
))
1152 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1153 d_fprintf(stderr
, "Could not get pwd hash\n");
1157 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1160 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1165 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1166 TALLOC_CTX
*mem_ctx
, int argc
,
1169 struct policy_handle pol
;
1170 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1171 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1172 union lsa_TrustedDomainInfo
*info
= NULL
;
1173 enum lsa_TrustDomInfoEnum info_class
= 1;
1174 struct lsa_String trusted_domain
;
1175 uint8_t nt_hash
[16];
1177 if (argc
> 3 || argc
< 2) {
1178 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1179 return NT_STATUS_OK
;
1183 info_class
= atoi(argv
[2]);
1185 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1187 if (!NT_STATUS_IS_OK(result
))
1190 init_lsa_String(&trusted_domain
, argv
[1]);
1192 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1197 if (!NT_STATUS_IS_OK(result
))
1200 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1201 d_fprintf(stderr
, "Could not get pwd hash\n");
1205 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1208 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1213 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1214 TALLOC_CTX
*mem_ctx
, int argc
,
1217 struct policy_handle pol
, trustdom_pol
;
1218 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1219 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1220 union lsa_TrustedDomainInfo
*info
= NULL
;
1222 enum lsa_TrustDomInfoEnum info_class
= 1;
1223 uint8_t nt_hash
[16];
1225 if (argc
> 3 || argc
< 2) {
1226 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1227 return NT_STATUS_OK
;
1230 if (!string_to_sid(&dom_sid
, argv
[1]))
1231 return NT_STATUS_NO_MEMORY
;
1235 info_class
= atoi(argv
[2]);
1237 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1239 if (!NT_STATUS_IS_OK(result
))
1242 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1248 if (!NT_STATUS_IS_OK(result
))
1251 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1256 if (!NT_STATUS_IS_OK(result
))
1259 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1260 d_fprintf(stderr
, "Could not get pwd hash\n");
1264 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1267 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1272 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1273 TALLOC_CTX
*mem_ctx
, int argc
,
1276 struct policy_handle pol
;
1277 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1278 const char *servername
= cli
->desthost
;
1279 struct lsa_String
*account_name
= NULL
;
1280 struct lsa_String
*authority_name
= NULL
;
1283 printf("Usage: %s servername\n", argv
[0]);
1284 return NT_STATUS_OK
;
1287 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1288 SEC_FLAG_MAXIMUM_ALLOWED
,
1291 if (!NT_STATUS_IS_OK(result
)) {
1295 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1299 if (!NT_STATUS_IS_OK(result
)) {
1305 printf("Account Name: %s, Authority Name: %s\n",
1306 account_name
->string
, authority_name
? authority_name
->string
:
1309 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1314 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1315 TALLOC_CTX
*mem_ctx
, int argc
,
1318 struct policy_handle dom_pol
, user_pol
;
1319 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1320 struct lsa_PrivilegeSet privs
;
1321 struct lsa_LUIDAttribute
*set
= NULL
;
1328 printf("Usage: %s SID [rights...]\n", argv
[0]);
1329 return NT_STATUS_OK
;
1332 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1333 if (!NT_STATUS_IS_OK(result
)) {
1337 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1338 SEC_FLAG_MAXIMUM_ALLOWED
,
1341 if (!NT_STATUS_IS_OK(result
)) {
1345 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1348 SEC_FLAG_MAXIMUM_ALLOWED
,
1351 if (!NT_STATUS_IS_OK(result
)) {
1355 for (i
=2; i
<argc
; i
++) {
1357 struct lsa_String priv_name
;
1358 struct lsa_LUID luid
;
1360 init_lsa_String(&priv_name
, argv
[i
]);
1362 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1366 if (!NT_STATUS_IS_OK(result
)) {
1371 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1372 struct lsa_LUIDAttribute
,
1375 return NT_STATUS_NO_MEMORY
;
1378 set
[privs
.count
-1].luid
= luid
;
1379 set
[privs
.count
-1].attribute
= 0;
1384 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1388 if (!NT_STATUS_IS_OK(result
)) {
1392 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1393 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1398 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1399 TALLOC_CTX
*mem_ctx
, int argc
,
1402 struct policy_handle dom_pol
, user_pol
;
1403 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1404 struct lsa_PrivilegeSet privs
;
1405 struct lsa_LUIDAttribute
*set
= NULL
;
1412 printf("Usage: %s SID [rights...]\n", argv
[0]);
1413 return NT_STATUS_OK
;
1416 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1417 if (!NT_STATUS_IS_OK(result
)) {
1421 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1422 SEC_FLAG_MAXIMUM_ALLOWED
,
1425 if (!NT_STATUS_IS_OK(result
)) {
1429 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1432 SEC_FLAG_MAXIMUM_ALLOWED
,
1435 if (!NT_STATUS_IS_OK(result
)) {
1439 for (i
=2; i
<argc
; i
++) {
1441 struct lsa_String priv_name
;
1442 struct lsa_LUID luid
;
1444 init_lsa_String(&priv_name
, argv
[i
]);
1446 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1450 if (!NT_STATUS_IS_OK(result
)) {
1455 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1456 struct lsa_LUIDAttribute
,
1459 return NT_STATUS_NO_MEMORY
;
1462 set
[privs
.count
-1].luid
= luid
;
1463 set
[privs
.count
-1].attribute
= 0;
1469 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1474 if (!NT_STATUS_IS_OK(result
)) {
1478 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1479 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1484 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1485 TALLOC_CTX
*mem_ctx
, int argc
,
1489 struct policy_handle handle
, sec_handle
;
1490 struct lsa_String name
;
1493 printf("Usage: %s name\n", argv
[0]);
1494 return NT_STATUS_OK
;
1497 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1499 SEC_FLAG_MAXIMUM_ALLOWED
,
1501 if (!NT_STATUS_IS_OK(status
)) {
1505 init_lsa_String(&name
, argv
[1]);
1507 status
= rpccli_lsa_CreateSecret(cli
, mem_ctx
,
1510 SEC_FLAG_MAXIMUM_ALLOWED
,
1512 if (!NT_STATUS_IS_OK(status
)) {
1517 if (is_valid_policy_hnd(&sec_handle
)) {
1518 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1520 if (is_valid_policy_hnd(&handle
)) {
1521 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1527 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1528 TALLOC_CTX
*mem_ctx
, int argc
,
1532 struct policy_handle handle
, sec_handle
;
1533 struct lsa_String name
;
1536 printf("Usage: %s name\n", argv
[0]);
1537 return NT_STATUS_OK
;
1540 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1542 SEC_FLAG_MAXIMUM_ALLOWED
,
1544 if (!NT_STATUS_IS_OK(status
)) {
1548 init_lsa_String(&name
, argv
[1]);
1550 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1553 SEC_FLAG_MAXIMUM_ALLOWED
,
1555 if (!NT_STATUS_IS_OK(status
)) {
1559 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1561 if (!NT_STATUS_IS_OK(status
)) {
1566 if (is_valid_policy_hnd(&sec_handle
)) {
1567 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1569 if (is_valid_policy_hnd(&handle
)) {
1570 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1576 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1577 TALLOC_CTX
*mem_ctx
, int argc
,
1581 struct policy_handle handle
, sec_handle
;
1582 struct lsa_String name
;
1583 struct lsa_DATA_BUF_PTR new_val
;
1584 NTTIME new_mtime
= 0;
1585 struct lsa_DATA_BUF_PTR old_val
;
1586 NTTIME old_mtime
= 0;
1587 DATA_BLOB session_key
;
1588 DATA_BLOB new_blob
= data_blob_null
;
1589 DATA_BLOB old_blob
= data_blob_null
;
1590 char *new_secret
, *old_secret
;
1593 printf("Usage: %s name\n", argv
[0]);
1594 return NT_STATUS_OK
;
1597 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1599 SEC_FLAG_MAXIMUM_ALLOWED
,
1601 if (!NT_STATUS_IS_OK(status
)) {
1605 init_lsa_String(&name
, argv
[1]);
1607 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1610 SEC_FLAG_MAXIMUM_ALLOWED
,
1612 if (!NT_STATUS_IS_OK(status
)) {
1616 ZERO_STRUCT(new_val
);
1617 ZERO_STRUCT(old_val
);
1619 status
= rpccli_lsa_QuerySecret(cli
, mem_ctx
,
1625 if (!NT_STATUS_IS_OK(status
)) {
1629 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1630 if (!NT_STATUS_IS_OK(status
)) {
1635 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1638 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1641 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1642 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1644 d_printf("new secret: %s\n", new_secret
);
1647 d_printf("old secret: %s\n", old_secret
);
1651 if (is_valid_policy_hnd(&sec_handle
)) {
1652 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1654 if (is_valid_policy_hnd(&handle
)) {
1655 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1661 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1662 TALLOC_CTX
*mem_ctx
, int argc
,
1666 struct policy_handle handle
, sec_handle
;
1667 struct lsa_String name
;
1668 struct lsa_DATA_BUF new_val
;
1669 struct lsa_DATA_BUF old_val
;
1671 DATA_BLOB session_key
;
1674 printf("Usage: %s name secret\n", argv
[0]);
1675 return NT_STATUS_OK
;
1678 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1680 SEC_FLAG_MAXIMUM_ALLOWED
,
1682 if (!NT_STATUS_IS_OK(status
)) {
1686 init_lsa_String(&name
, argv
[1]);
1688 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1691 SEC_FLAG_MAXIMUM_ALLOWED
,
1693 if (!NT_STATUS_IS_OK(status
)) {
1697 ZERO_STRUCT(new_val
);
1698 ZERO_STRUCT(old_val
);
1700 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1701 if (!NT_STATUS_IS_OK(status
)) {
1705 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1707 new_val
.length
= enc_key
.length
;
1708 new_val
.size
= enc_key
.length
;
1709 new_val
.data
= enc_key
.data
;
1711 status
= rpccli_lsa_SetSecret(cli
, mem_ctx
,
1715 if (!NT_STATUS_IS_OK(status
)) {
1720 if (is_valid_policy_hnd(&sec_handle
)) {
1721 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1723 if (is_valid_policy_hnd(&handle
)) {
1724 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1730 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1731 TALLOC_CTX
*mem_ctx
, int argc
,
1735 struct policy_handle handle
;
1736 struct lsa_String name
;
1737 struct lsa_DATA_BUF
*val
;
1738 DATA_BLOB session_key
;
1739 DATA_BLOB blob
= data_blob_null
;
1743 printf("Usage: %s name\n", argv
[0]);
1744 return NT_STATUS_OK
;
1747 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1749 SEC_FLAG_MAXIMUM_ALLOWED
,
1751 if (!NT_STATUS_IS_OK(status
)) {
1755 init_lsa_String(&name
, argv
[1]);
1759 status
= rpccli_lsa_RetrievePrivateData(cli
, mem_ctx
,
1763 if (!NT_STATUS_IS_OK(status
)) {
1767 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1768 if (!NT_STATUS_IS_OK(status
)) {
1773 blob
= data_blob_const(val
->data
, val
->length
);
1776 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1778 d_printf("secret: %s\n", secret
);
1782 if (is_valid_policy_hnd(&handle
)) {
1783 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1789 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1790 TALLOC_CTX
*mem_ctx
, int argc
,
1794 struct policy_handle handle
;
1795 struct lsa_String name
;
1796 struct lsa_DATA_BUF val
;
1797 DATA_BLOB session_key
;
1801 printf("Usage: %s name secret\n", argv
[0]);
1802 return NT_STATUS_OK
;
1805 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1807 SEC_FLAG_MAXIMUM_ALLOWED
,
1809 if (!NT_STATUS_IS_OK(status
)) {
1813 init_lsa_String(&name
, argv
[1]);
1817 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1818 if (!NT_STATUS_IS_OK(status
)) {
1822 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1824 val
.length
= enc_key
.length
;
1825 val
.size
= enc_key
.length
;
1826 val
.data
= enc_key
.data
;
1828 status
= rpccli_lsa_StorePrivateData(cli
, mem_ctx
,
1832 if (!NT_STATUS_IS_OK(status
)) {
1837 if (is_valid_policy_hnd(&handle
)) {
1838 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1844 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
1845 TALLOC_CTX
*mem_ctx
, int argc
,
1849 struct policy_handle handle
, trustdom_handle
;
1851 struct lsa_DomainInfo info
;
1854 printf("Usage: %s name sid\n", argv
[0]);
1855 return NT_STATUS_OK
;
1858 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1860 SEC_FLAG_MAXIMUM_ALLOWED
,
1862 if (!NT_STATUS_IS_OK(status
)) {
1866 init_lsa_StringLarge(&info
.name
, argv
[1]);
1868 string_to_sid(&sid
, argv
[2]);
1870 status
= rpccli_lsa_CreateTrustedDomain(cli
, mem_ctx
,
1873 SEC_FLAG_MAXIMUM_ALLOWED
,
1875 if (!NT_STATUS_IS_OK(status
)) {
1880 if (is_valid_policy_hnd(&trustdom_handle
)) {
1881 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1884 if (is_valid_policy_hnd(&handle
)) {
1885 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1891 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
1892 TALLOC_CTX
*mem_ctx
, int argc
,
1896 struct policy_handle handle
, trustdom_handle
;
1897 struct lsa_String name
;
1898 struct dom_sid
*sid
= NULL
;
1901 printf("Usage: %s name\n", argv
[0]);
1902 return NT_STATUS_OK
;
1905 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1907 SEC_FLAG_MAXIMUM_ALLOWED
,
1909 if (!NT_STATUS_IS_OK(status
)) {
1913 init_lsa_String(&name
, argv
[1]);
1915 status
= rpccli_lsa_OpenTrustedDomainByName(cli
, mem_ctx
,
1918 SEC_FLAG_MAXIMUM_ALLOWED
,
1920 if (NT_STATUS_IS_OK(status
)) {
1925 uint32_t resume_handle
= 0;
1926 struct lsa_DomainList domains
;
1929 status
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
1934 if (!NT_STATUS_IS_OK(status
)) {
1938 for (i
=0; i
< domains
.count
; i
++) {
1939 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
1940 sid
= domains
.domains
[i
].sid
;
1946 return NT_STATUS_INVALID_SID
;
1950 status
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1953 SEC_FLAG_MAXIMUM_ALLOWED
,
1955 if (!NT_STATUS_IS_OK(status
)) {
1960 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1962 if (!NT_STATUS_IS_OK(status
)) {
1967 if (is_valid_policy_hnd(&trustdom_handle
)) {
1968 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1971 if (is_valid_policy_hnd(&handle
)) {
1972 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1979 /* List of commands exported by this module */
1981 struct cmd_set lsarpc_commands
[] = {
1985 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1986 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1987 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1988 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1989 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1990 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1991 { "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)]" },
1992 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1993 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1994 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1995 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
1996 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
1997 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
1998 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
1999 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
2000 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
2001 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
2002 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
2003 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
2004 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2005 { "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", "" },
2006 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2007 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
2008 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
2009 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
2010 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
2011 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
2012 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
2013 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },
2014 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Trusted Domain", "" },
2015 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Trusted Domain", "" },