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
[0].sid
= string_sid_talloc(sids
.sids
, argv
[i
+ 1]);
455 if (!sids
.sids
[0].sid
) {
456 result
= NT_STATUS_INVALID_SID
;
461 /* Lookup the SIDs */
462 result
= rpccli_lsa_LookupSids3(cli
, mem_ctx
,
471 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
472 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
475 result
= NT_STATUS_OK
;
479 for (i
= 0; i
< count
; i
++) {
482 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
483 printf("%s %s (%d)\n", sid_str
,
484 names
.names
[i
].name
.string
,
485 names
.names
[i
].sid_type
);
493 /* Enumerate list of trusted domains */
495 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
496 TALLOC_CTX
*mem_ctx
, int argc
,
499 struct policy_handle pol
;
500 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
501 struct lsa_DomainList domain_list
;
503 /* defaults, but may be changed using params */
506 uint32_t max_size
= (uint32_t)-1;
509 printf("Usage: %s [enum context (0)]\n", argv
[0]);
513 if (argc
== 2 && argv
[1]) {
514 enum_ctx
= atoi(argv
[2]);
517 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
518 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
521 if (!NT_STATUS_IS_OK(result
))
524 result
= STATUS_MORE_ENTRIES
;
526 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
528 /* Lookup list of trusted domains */
530 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
535 if (!NT_STATUS_IS_OK(result
) &&
536 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
537 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
540 /* Print results: list of names and sids returned in this
542 for (i
= 0; i
< domain_list
.count
; i
++) {
545 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
547 domain_list
.domains
[i
].name
.string
?
548 domain_list
.domains
[i
].name
.string
: "*unknown*",
553 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
558 /* Enumerates privileges */
560 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
561 TALLOC_CTX
*mem_ctx
, int argc
,
564 struct policy_handle pol
;
565 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
566 struct lsa_PrivArray priv_array
;
568 uint32 enum_context
=0;
569 uint32 pref_max_length
=0x1000;
573 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
578 enum_context
=atoi(argv
[1]);
581 pref_max_length
=atoi(argv
[2]);
583 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
584 SEC_FLAG_MAXIMUM_ALLOWED
,
587 if (!NT_STATUS_IS_OK(result
))
590 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
595 if (!NT_STATUS_IS_OK(result
))
599 printf("found %d privileges\n\n", priv_array
.count
);
601 for (i
= 0; i
< priv_array
.count
; i
++) {
602 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
603 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
604 priv_array
.privs
[i
].luid
.high
,
605 priv_array
.privs
[i
].luid
.low
,
606 priv_array
.privs
[i
].luid
.high
,
607 priv_array
.privs
[i
].luid
.low
);
610 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
615 /* Get privilege name */
617 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
618 TALLOC_CTX
*mem_ctx
, int argc
,
621 struct policy_handle pol
;
622 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
625 uint16 lang_id_sys
=0;
627 struct lsa_String lsa_name
;
628 struct lsa_StringLarge
*description
= NULL
;
631 printf("Usage: %s privilege name\n", argv
[0]);
635 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
636 SEC_FLAG_MAXIMUM_ALLOWED
,
639 if (!NT_STATUS_IS_OK(result
))
642 init_lsa_String(&lsa_name
, argv
[1]);
644 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
652 if (!NT_STATUS_IS_OK(result
))
656 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
658 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
663 /* Enumerate the LSA SIDS */
665 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
666 TALLOC_CTX
*mem_ctx
, int argc
,
669 struct policy_handle pol
;
670 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
672 uint32 enum_context
=0;
673 uint32 pref_max_length
=0x1000;
674 struct lsa_SidArray sid_array
;
678 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
683 enum_context
=atoi(argv
[1]);
686 pref_max_length
=atoi(argv
[2]);
688 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
689 SEC_FLAG_MAXIMUM_ALLOWED
,
692 if (!NT_STATUS_IS_OK(result
))
695 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
701 if (!NT_STATUS_IS_OK(result
))
705 printf("found %d SIDs\n\n", sid_array
.num_sids
);
707 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
710 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
711 printf("%s\n", sid_str
);
714 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
719 /* Create a new account */
721 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
722 TALLOC_CTX
*mem_ctx
, int argc
,
725 struct policy_handle dom_pol
;
726 struct policy_handle user_pol
;
727 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
728 uint32 des_access
= 0x000f000f;
733 printf("Usage: %s SID\n", argv
[0]);
737 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
738 if (!NT_STATUS_IS_OK(result
))
741 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
742 SEC_FLAG_MAXIMUM_ALLOWED
,
745 if (!NT_STATUS_IS_OK(result
))
748 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
754 if (!NT_STATUS_IS_OK(result
))
757 printf("Account for SID %s successfully created\n\n", argv
[1]);
758 result
= NT_STATUS_OK
;
760 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
766 /* Enumerate the privileges of an SID */
768 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
769 TALLOC_CTX
*mem_ctx
, int argc
,
772 struct policy_handle dom_pol
;
773 struct policy_handle user_pol
;
774 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
775 uint32 access_desired
= 0x000f000f;
777 struct lsa_PrivilegeSet
*privs
= NULL
;
781 printf("Usage: %s SID\n", argv
[0]);
785 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
786 if (!NT_STATUS_IS_OK(result
))
789 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
790 SEC_FLAG_MAXIMUM_ALLOWED
,
793 if (!NT_STATUS_IS_OK(result
))
796 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
802 if (!NT_STATUS_IS_OK(result
))
805 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
809 if (!NT_STATUS_IS_OK(result
))
813 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
814 printf("high\tlow\tattribute\n");
816 for (i
= 0; i
< privs
->count
; i
++) {
817 printf("%u\t%u\t%u\n",
818 privs
->set
[i
].luid
.high
,
819 privs
->set
[i
].luid
.low
,
820 privs
->set
[i
].attribute
);
823 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
829 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
831 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
832 TALLOC_CTX
*mem_ctx
, int argc
,
835 struct policy_handle dom_pol
;
836 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
838 struct lsa_RightSet rights
;
843 printf("Usage: %s SID\n", argv
[0]);
847 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
848 if (!NT_STATUS_IS_OK(result
))
851 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
852 SEC_FLAG_MAXIMUM_ALLOWED
,
855 if (!NT_STATUS_IS_OK(result
))
858 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
863 if (!NT_STATUS_IS_OK(result
))
866 printf("found %d privileges for SID %s\n", rights
.count
,
867 sid_string_tos(&sid
));
869 for (i
= 0; i
< rights
.count
; i
++) {
870 printf("\t%s\n", rights
.names
[i
].string
);
873 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
879 /* add some privileges to a SID via LsaAddAccountRights */
881 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
882 TALLOC_CTX
*mem_ctx
, int argc
,
885 struct policy_handle dom_pol
;
886 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
887 struct lsa_RightSet rights
;
892 printf("Usage: %s SID [rights...]\n", argv
[0]);
896 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
897 if (!NT_STATUS_IS_OK(result
))
900 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
901 SEC_FLAG_MAXIMUM_ALLOWED
,
904 if (!NT_STATUS_IS_OK(result
))
907 rights
.count
= argc
-2;
908 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
911 return NT_STATUS_NO_MEMORY
;
914 for (i
=0; i
<argc
-2; i
++) {
915 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
918 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
923 if (!NT_STATUS_IS_OK(result
))
926 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
932 /* remove some privileges to a SID via LsaRemoveAccountRights */
934 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
935 TALLOC_CTX
*mem_ctx
, int argc
,
938 struct policy_handle dom_pol
;
939 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
940 struct lsa_RightSet rights
;
945 printf("Usage: %s SID [rights...]\n", argv
[0]);
949 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
950 if (!NT_STATUS_IS_OK(result
))
953 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
954 SEC_FLAG_MAXIMUM_ALLOWED
,
957 if (!NT_STATUS_IS_OK(result
))
960 rights
.count
= argc
-2;
961 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
964 return NT_STATUS_NO_MEMORY
;
967 for (i
=0; i
<argc
-2; i
++) {
968 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
971 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
977 if (!NT_STATUS_IS_OK(result
))
980 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
987 /* Get a privilege value given its name */
989 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
990 TALLOC_CTX
*mem_ctx
, int argc
,
993 struct policy_handle pol
;
994 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
995 struct lsa_LUID luid
;
996 struct lsa_String name
;
999 printf("Usage: %s name\n", argv
[0]);
1000 return NT_STATUS_OK
;
1003 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1004 SEC_FLAG_MAXIMUM_ALLOWED
,
1007 if (!NT_STATUS_IS_OK(result
))
1010 init_lsa_String(&name
, argv
[1]);
1012 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1017 if (!NT_STATUS_IS_OK(result
))
1022 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1024 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1029 /* Query LSA security object */
1031 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1032 TALLOC_CTX
*mem_ctx
, int argc
,
1035 struct policy_handle pol
;
1036 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1038 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
1040 if (argc
< 1 || argc
> 2) {
1041 printf("Usage: %s [sec_info]\n", argv
[0]);
1042 return NT_STATUS_OK
;
1045 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1046 SEC_FLAG_MAXIMUM_ALLOWED
,
1050 sscanf(argv
[1], "%x", &sec_info
);
1052 if (!NT_STATUS_IS_OK(result
))
1055 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
1059 if (!NT_STATUS_IS_OK(result
))
1064 display_sec_desc(sdb
->sd
);
1066 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1071 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1072 uint8_t session_key
[16])
1074 char *pwd
, *pwd_old
;
1076 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1077 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1078 DATA_BLOB session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
1080 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key_blob
);
1081 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key_blob
);
1083 d_printf("Password:\t%s\n", pwd
);
1084 d_printf("Old Password:\t%s\n", pwd_old
);
1087 talloc_free(pwd_old
);
1090 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1091 union lsa_TrustedDomainInfo
*info
,
1092 enum lsa_TrustDomInfoEnum info_class
,
1093 uint8_t nt_hash
[16])
1095 switch (info_class
) {
1096 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1097 display_trust_dom_info_4(&info
->password
, nt_hash
);
1100 const char *str
= NULL
;
1101 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1102 lsa_TrustedDomainInfo
,
1105 d_printf("%s\n", str
);
1112 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1113 TALLOC_CTX
*mem_ctx
, int argc
,
1116 struct policy_handle pol
;
1117 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1119 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1120 union lsa_TrustedDomainInfo
*info
= NULL
;
1121 enum lsa_TrustDomInfoEnum info_class
= 1;
1122 uint8_t nt_hash
[16];
1124 if (argc
> 3 || argc
< 2) {
1125 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1126 return NT_STATUS_OK
;
1129 if (!string_to_sid(&dom_sid
, argv
[1]))
1130 return NT_STATUS_NO_MEMORY
;
1133 info_class
= atoi(argv
[2]);
1135 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1137 if (!NT_STATUS_IS_OK(result
))
1140 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1145 if (!NT_STATUS_IS_OK(result
))
1148 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1149 d_fprintf(stderr
, "Could not get pwd hash\n");
1153 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1156 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1161 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1162 TALLOC_CTX
*mem_ctx
, int argc
,
1165 struct policy_handle pol
;
1166 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1167 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1168 union lsa_TrustedDomainInfo
*info
= NULL
;
1169 enum lsa_TrustDomInfoEnum info_class
= 1;
1170 struct lsa_String trusted_domain
;
1171 uint8_t nt_hash
[16];
1173 if (argc
> 3 || argc
< 2) {
1174 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1175 return NT_STATUS_OK
;
1179 info_class
= atoi(argv
[2]);
1181 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1183 if (!NT_STATUS_IS_OK(result
))
1186 init_lsa_String(&trusted_domain
, argv
[1]);
1188 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1193 if (!NT_STATUS_IS_OK(result
))
1196 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1197 d_fprintf(stderr
, "Could not get pwd hash\n");
1201 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1204 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1209 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1210 TALLOC_CTX
*mem_ctx
, int argc
,
1213 struct policy_handle pol
, trustdom_pol
;
1214 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1215 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1216 union lsa_TrustedDomainInfo
*info
= NULL
;
1218 enum lsa_TrustDomInfoEnum info_class
= 1;
1219 uint8_t nt_hash
[16];
1221 if (argc
> 3 || argc
< 2) {
1222 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1223 return NT_STATUS_OK
;
1226 if (!string_to_sid(&dom_sid
, argv
[1]))
1227 return NT_STATUS_NO_MEMORY
;
1231 info_class
= atoi(argv
[2]);
1233 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1235 if (!NT_STATUS_IS_OK(result
))
1238 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1244 if (!NT_STATUS_IS_OK(result
))
1247 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1252 if (!NT_STATUS_IS_OK(result
))
1255 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1256 d_fprintf(stderr
, "Could not get pwd hash\n");
1260 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1263 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1268 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1269 TALLOC_CTX
*mem_ctx
, int argc
,
1272 struct policy_handle pol
;
1273 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1274 const char *servername
= cli
->desthost
;
1275 struct lsa_String
*account_name
= NULL
;
1276 struct lsa_String
*authority_name
= NULL
;
1279 printf("Usage: %s servername\n", argv
[0]);
1280 return NT_STATUS_OK
;
1283 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1284 SEC_FLAG_MAXIMUM_ALLOWED
,
1287 if (!NT_STATUS_IS_OK(result
)) {
1291 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1295 if (!NT_STATUS_IS_OK(result
)) {
1301 printf("Account Name: %s, Authority Name: %s\n",
1302 account_name
->string
, authority_name
? authority_name
->string
:
1305 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1310 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1311 TALLOC_CTX
*mem_ctx
, int argc
,
1314 struct policy_handle dom_pol
, user_pol
;
1315 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1316 struct lsa_PrivilegeSet privs
;
1317 struct lsa_LUIDAttribute
*set
= NULL
;
1324 printf("Usage: %s SID [rights...]\n", argv
[0]);
1325 return NT_STATUS_OK
;
1328 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1329 if (!NT_STATUS_IS_OK(result
)) {
1333 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1334 SEC_FLAG_MAXIMUM_ALLOWED
,
1337 if (!NT_STATUS_IS_OK(result
)) {
1341 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1344 SEC_FLAG_MAXIMUM_ALLOWED
,
1347 if (!NT_STATUS_IS_OK(result
)) {
1351 for (i
=2; i
<argc
; i
++) {
1353 struct lsa_String priv_name
;
1354 struct lsa_LUID luid
;
1356 init_lsa_String(&priv_name
, argv
[i
]);
1358 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1362 if (!NT_STATUS_IS_OK(result
)) {
1367 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1368 struct lsa_LUIDAttribute
,
1371 return NT_STATUS_NO_MEMORY
;
1374 set
[privs
.count
-1].luid
= luid
;
1375 set
[privs
.count
-1].attribute
= 0;
1380 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1384 if (!NT_STATUS_IS_OK(result
)) {
1388 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1389 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1394 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1395 TALLOC_CTX
*mem_ctx
, int argc
,
1398 struct policy_handle dom_pol
, user_pol
;
1399 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1400 struct lsa_PrivilegeSet privs
;
1401 struct lsa_LUIDAttribute
*set
= NULL
;
1408 printf("Usage: %s SID [rights...]\n", argv
[0]);
1409 return NT_STATUS_OK
;
1412 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1413 if (!NT_STATUS_IS_OK(result
)) {
1417 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1418 SEC_FLAG_MAXIMUM_ALLOWED
,
1421 if (!NT_STATUS_IS_OK(result
)) {
1425 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1428 SEC_FLAG_MAXIMUM_ALLOWED
,
1431 if (!NT_STATUS_IS_OK(result
)) {
1435 for (i
=2; i
<argc
; i
++) {
1437 struct lsa_String priv_name
;
1438 struct lsa_LUID luid
;
1440 init_lsa_String(&priv_name
, argv
[i
]);
1442 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1446 if (!NT_STATUS_IS_OK(result
)) {
1451 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1452 struct lsa_LUIDAttribute
,
1455 return NT_STATUS_NO_MEMORY
;
1458 set
[privs
.count
-1].luid
= luid
;
1459 set
[privs
.count
-1].attribute
= 0;
1465 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1470 if (!NT_STATUS_IS_OK(result
)) {
1474 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1475 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1480 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1481 TALLOC_CTX
*mem_ctx
, int argc
,
1485 struct policy_handle handle
, sec_handle
;
1486 struct lsa_String name
;
1489 printf("Usage: %s name\n", argv
[0]);
1490 return NT_STATUS_OK
;
1493 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1495 SEC_FLAG_MAXIMUM_ALLOWED
,
1497 if (!NT_STATUS_IS_OK(status
)) {
1501 init_lsa_String(&name
, argv
[1]);
1503 status
= rpccli_lsa_CreateSecret(cli
, mem_ctx
,
1506 SEC_FLAG_MAXIMUM_ALLOWED
,
1508 if (!NT_STATUS_IS_OK(status
)) {
1513 if (is_valid_policy_hnd(&sec_handle
)) {
1514 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1516 if (is_valid_policy_hnd(&handle
)) {
1517 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1523 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1524 TALLOC_CTX
*mem_ctx
, int argc
,
1528 struct policy_handle handle
, sec_handle
;
1529 struct lsa_String name
;
1532 printf("Usage: %s name\n", argv
[0]);
1533 return NT_STATUS_OK
;
1536 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1538 SEC_FLAG_MAXIMUM_ALLOWED
,
1540 if (!NT_STATUS_IS_OK(status
)) {
1544 init_lsa_String(&name
, argv
[1]);
1546 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1549 SEC_FLAG_MAXIMUM_ALLOWED
,
1551 if (!NT_STATUS_IS_OK(status
)) {
1555 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1557 if (!NT_STATUS_IS_OK(status
)) {
1562 if (is_valid_policy_hnd(&sec_handle
)) {
1563 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1565 if (is_valid_policy_hnd(&handle
)) {
1566 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1572 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1573 TALLOC_CTX
*mem_ctx
, int argc
,
1577 struct policy_handle handle
, sec_handle
;
1578 struct lsa_String name
;
1579 struct lsa_DATA_BUF_PTR new_val
;
1580 NTTIME new_mtime
= 0;
1581 struct lsa_DATA_BUF_PTR old_val
;
1582 NTTIME old_mtime
= 0;
1583 DATA_BLOB session_key
;
1584 DATA_BLOB new_blob
= data_blob_null
;
1585 DATA_BLOB old_blob
= data_blob_null
;
1586 char *new_secret
, *old_secret
;
1589 printf("Usage: %s name\n", argv
[0]);
1590 return NT_STATUS_OK
;
1593 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1595 SEC_FLAG_MAXIMUM_ALLOWED
,
1597 if (!NT_STATUS_IS_OK(status
)) {
1601 init_lsa_String(&name
, argv
[1]);
1603 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1606 SEC_FLAG_MAXIMUM_ALLOWED
,
1608 if (!NT_STATUS_IS_OK(status
)) {
1612 ZERO_STRUCT(new_val
);
1613 ZERO_STRUCT(old_val
);
1615 status
= rpccli_lsa_QuerySecret(cli
, mem_ctx
,
1621 if (!NT_STATUS_IS_OK(status
)) {
1625 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1626 if (!NT_STATUS_IS_OK(status
)) {
1631 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1634 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1637 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1638 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1640 d_printf("new secret: %s\n", new_secret
);
1643 d_printf("old secret: %s\n", old_secret
);
1647 if (is_valid_policy_hnd(&sec_handle
)) {
1648 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1650 if (is_valid_policy_hnd(&handle
)) {
1651 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1657 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1658 TALLOC_CTX
*mem_ctx
, int argc
,
1662 struct policy_handle handle
, sec_handle
;
1663 struct lsa_String name
;
1664 struct lsa_DATA_BUF new_val
;
1665 struct lsa_DATA_BUF old_val
;
1667 DATA_BLOB session_key
;
1670 printf("Usage: %s name secret\n", argv
[0]);
1671 return NT_STATUS_OK
;
1674 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1676 SEC_FLAG_MAXIMUM_ALLOWED
,
1678 if (!NT_STATUS_IS_OK(status
)) {
1682 init_lsa_String(&name
, argv
[1]);
1684 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1687 SEC_FLAG_MAXIMUM_ALLOWED
,
1689 if (!NT_STATUS_IS_OK(status
)) {
1693 ZERO_STRUCT(new_val
);
1694 ZERO_STRUCT(old_val
);
1696 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1697 if (!NT_STATUS_IS_OK(status
)) {
1701 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1703 new_val
.length
= enc_key
.length
;
1704 new_val
.size
= enc_key
.length
;
1705 new_val
.data
= enc_key
.data
;
1707 status
= rpccli_lsa_SetSecret(cli
, mem_ctx
,
1711 if (!NT_STATUS_IS_OK(status
)) {
1716 if (is_valid_policy_hnd(&sec_handle
)) {
1717 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1719 if (is_valid_policy_hnd(&handle
)) {
1720 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1726 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1727 TALLOC_CTX
*mem_ctx
, int argc
,
1731 struct policy_handle handle
;
1732 struct lsa_String name
;
1733 struct lsa_DATA_BUF
*val
;
1734 DATA_BLOB session_key
;
1735 DATA_BLOB blob
= data_blob_null
;
1739 printf("Usage: %s name\n", argv
[0]);
1740 return NT_STATUS_OK
;
1743 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1745 SEC_FLAG_MAXIMUM_ALLOWED
,
1747 if (!NT_STATUS_IS_OK(status
)) {
1751 init_lsa_String(&name
, argv
[1]);
1755 status
= rpccli_lsa_RetrievePrivateData(cli
, mem_ctx
,
1759 if (!NT_STATUS_IS_OK(status
)) {
1763 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1764 if (!NT_STATUS_IS_OK(status
)) {
1769 blob
= data_blob_const(val
->data
, val
->length
);
1772 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1774 d_printf("secret: %s\n", secret
);
1778 if (is_valid_policy_hnd(&handle
)) {
1779 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1785 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1786 TALLOC_CTX
*mem_ctx
, int argc
,
1790 struct policy_handle handle
;
1791 struct lsa_String name
;
1792 struct lsa_DATA_BUF val
;
1793 DATA_BLOB session_key
;
1797 printf("Usage: %s name secret\n", argv
[0]);
1798 return NT_STATUS_OK
;
1801 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1803 SEC_FLAG_MAXIMUM_ALLOWED
,
1805 if (!NT_STATUS_IS_OK(status
)) {
1809 init_lsa_String(&name
, argv
[1]);
1813 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1814 if (!NT_STATUS_IS_OK(status
)) {
1818 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1820 val
.length
= enc_key
.length
;
1821 val
.size
= enc_key
.length
;
1822 val
.data
= enc_key
.data
;
1824 status
= rpccli_lsa_StorePrivateData(cli
, mem_ctx
,
1828 if (!NT_STATUS_IS_OK(status
)) {
1833 if (is_valid_policy_hnd(&handle
)) {
1834 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1840 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
1841 TALLOC_CTX
*mem_ctx
, int argc
,
1845 struct policy_handle handle
, trustdom_handle
;
1846 struct lsa_DomainInfo info
;
1849 printf("Usage: %s name sid\n", argv
[0]);
1850 return NT_STATUS_OK
;
1853 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1855 SEC_FLAG_MAXIMUM_ALLOWED
,
1857 if (!NT_STATUS_IS_OK(status
)) {
1861 init_lsa_StringLarge(&info
.name
, argv
[1]);
1862 info
.sid
= string_sid_talloc(mem_ctx
, argv
[2]);
1864 status
= rpccli_lsa_CreateTrustedDomain(cli
, mem_ctx
,
1867 SEC_FLAG_MAXIMUM_ALLOWED
,
1869 if (!NT_STATUS_IS_OK(status
)) {
1874 if (is_valid_policy_hnd(&trustdom_handle
)) {
1875 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1878 if (is_valid_policy_hnd(&handle
)) {
1879 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1885 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
1886 TALLOC_CTX
*mem_ctx
, int argc
,
1890 struct policy_handle handle
, trustdom_handle
;
1891 struct lsa_String name
;
1892 struct dom_sid
*sid
= NULL
;
1895 printf("Usage: %s name\n", argv
[0]);
1896 return NT_STATUS_OK
;
1899 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1901 SEC_FLAG_MAXIMUM_ALLOWED
,
1903 if (!NT_STATUS_IS_OK(status
)) {
1907 init_lsa_String(&name
, argv
[1]);
1909 status
= rpccli_lsa_OpenTrustedDomainByName(cli
, mem_ctx
,
1912 SEC_FLAG_MAXIMUM_ALLOWED
,
1914 if (NT_STATUS_IS_OK(status
)) {
1919 uint32_t resume_handle
= 0;
1920 struct lsa_DomainList domains
;
1923 status
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
1928 if (!NT_STATUS_IS_OK(status
)) {
1932 for (i
=0; i
< domains
.count
; i
++) {
1933 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
1934 sid
= domains
.domains
[i
].sid
;
1940 return NT_STATUS_INVALID_SID
;
1944 status
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1947 SEC_FLAG_MAXIMUM_ALLOWED
,
1949 if (!NT_STATUS_IS_OK(status
)) {
1954 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1956 if (!NT_STATUS_IS_OK(status
)) {
1961 if (is_valid_policy_hnd(&trustdom_handle
)) {
1962 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1965 if (is_valid_policy_hnd(&handle
)) {
1966 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1973 /* List of commands exported by this module */
1975 struct cmd_set lsarpc_commands
[] = {
1979 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1980 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1981 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1982 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1983 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1984 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1985 { "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)]" },
1986 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1987 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1988 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1989 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
1990 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
1991 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
1992 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
1993 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
1994 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
1995 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
1996 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
1997 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
1998 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1999 { "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", "" },
2000 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2001 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
2002 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
2003 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
2004 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
2005 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
2006 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
2007 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },
2008 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Trusted Domain", "" },
2009 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Trusted Domain", "" },