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"
27 /* useful function to allow entering a name instead of a SID and
28 * looking it up automatically */
29 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
31 DOM_SID
*sid
, const char *name
)
33 struct policy_handle pol
;
34 enum lsa_SidType
*sid_types
;
38 /* maybe its a raw SID */
39 if (strncmp(name
, "S-", 2) == 0 &&
40 string_to_sid(sid
, name
)) {
44 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
45 SEC_FLAG_MAXIMUM_ALLOWED
,
47 if (!NT_STATUS_IS_OK(result
))
50 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
51 if (!NT_STATUS_IS_OK(result
))
54 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
62 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
64 d_printf("percent_full:\t%d\n", r
->percent_full
);
65 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
66 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
67 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
68 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
69 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
72 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
75 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
76 d_printf("Auditing categories:\t%d\n", r
->count
);
77 d_printf("Auditsettings:\n");
78 for (i
=0; i
<r
->count
; i
++) {
79 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
80 const char *policy
= audit_description_str(i
);
81 d_printf("%s:\t%s\n", policy
, val
);
85 static void display_query_info_3(struct lsa_DomainInfo
*r
)
87 d_printf("Domain Name: %s\n", r
->name
.string
);
88 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
91 static void display_query_info_5(struct lsa_DomainInfo
*r
)
93 d_printf("Domain Name: %s\n", r
->name
.string
);
94 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
97 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
99 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
102 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
104 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
105 d_printf("Log is full: %d\n", r
->log_is_full
);
108 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
110 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
111 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
112 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
113 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
114 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
118 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
119 enum lsa_PolicyInfo level
)
123 display_query_info_1(&info
->audit_log
);
126 display_query_info_2(&info
->audit_events
);
129 display_query_info_3(&info
->domain
);
132 display_query_info_5(&info
->account_domain
);
135 display_query_info_10(&info
->auditfullset
);
138 display_query_info_11(&info
->auditfullquery
);
141 display_query_info_12(&info
->dns
);
144 printf("can't display info level: %d\n", level
);
149 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
150 TALLOC_CTX
*mem_ctx
, int argc
,
153 struct policy_handle pol
;
154 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
155 union lsa_PolicyInformation
*info
= NULL
;
157 uint32 info_class
= 3;
160 printf("Usage: %s [info_class]\n", argv
[0]);
165 info_class
= atoi(argv
[1]);
167 switch (info_class
) {
169 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
170 SEC_FLAG_MAXIMUM_ALLOWED
,
173 if (!NT_STATUS_IS_OK(result
))
176 result
= rpccli_lsa_QueryInfoPolicy2(cli
, mem_ctx
,
182 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
183 SEC_FLAG_MAXIMUM_ALLOWED
,
186 if (!NT_STATUS_IS_OK(result
))
189 result
= rpccli_lsa_QueryInfoPolicy(cli
, mem_ctx
,
195 if (NT_STATUS_IS_OK(result
)) {
196 display_lsa_query_info(info
, info_class
);
199 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
205 /* Resolve a list of names to a list of sids */
207 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
208 TALLOC_CTX
*mem_ctx
, int argc
,
211 struct policy_handle pol
;
212 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
214 enum lsa_SidType
*types
;
218 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
222 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
223 SEC_FLAG_MAXIMUM_ALLOWED
,
226 if (!NT_STATUS_IS_OK(result
))
229 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
230 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
232 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
233 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
236 result
= NT_STATUS_OK
;
240 for (i
= 0; i
< (argc
- 1); i
++) {
242 sid_to_fstring(sid_str
, &sids
[i
]);
243 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
244 sid_type_lookup(types
[i
]), types
[i
]);
247 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
253 /* Resolve a list of names to a list of sids */
255 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
256 TALLOC_CTX
*mem_ctx
, int argc
,
259 struct policy_handle pol
;
260 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
262 enum lsa_SidType
*types
;
266 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
270 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
271 SEC_FLAG_MAXIMUM_ALLOWED
,
274 if (!NT_STATUS_IS_OK(result
))
277 level
= atoi(argv
[1]);
279 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
280 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
282 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
283 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
286 result
= NT_STATUS_OK
;
290 for (i
= 0; i
< (argc
- 2); i
++) {
292 sid_to_fstring(sid_str
, &sids
[i
]);
293 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
294 sid_type_lookup(types
[i
]), types
[i
]);
297 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
303 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
304 TALLOC_CTX
*mem_ctx
, int argc
,
307 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
310 struct lsa_String
*names
;
311 struct lsa_RefDomainList
*domains
;
312 struct lsa_TransSidArray3 sids
;
317 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
324 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
325 NT_STATUS_HAVE_NO_MEMORY(names
);
327 for (i
=0; i
< num_names
; i
++) {
328 init_lsa_String(&names
[i
], argv
[i
+1]);
331 result
= rpccli_lsa_LookupNames4(cli
, mem_ctx
,
340 if (!NT_STATUS_IS_OK(result
)) {
344 for (i
= 0; i
< sids
.count
; i
++) {
346 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
347 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
348 sid_type_lookup(sids
.sids
[i
].sid_type
),
349 sids
.sids
[i
].sid_type
);
355 /* Resolve a list of SIDs to a list of names */
357 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
358 int argc
, const char **argv
)
360 struct policy_handle pol
;
361 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
365 enum lsa_SidType
*types
;
369 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
373 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
374 SEC_FLAG_MAXIMUM_ALLOWED
,
377 if (!NT_STATUS_IS_OK(result
))
380 /* Convert arguments to sids */
382 sids
= TALLOC_ARRAY(mem_ctx
, DOM_SID
, argc
- 1);
385 printf("could not allocate memory for %d sids\n", argc
- 1);
389 for (i
= 0; i
< argc
- 1; i
++)
390 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
391 result
= NT_STATUS_INVALID_SID
;
395 /* Lookup the SIDs */
397 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
398 &domains
, &names
, &types
);
400 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
401 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
404 result
= NT_STATUS_OK
;
408 for (i
= 0; i
< (argc
- 1); i
++) {
411 sid_to_fstring(sid_str
, &sids
[i
]);
412 printf("%s %s\\%s (%d)\n", sid_str
,
413 domains
[i
] ? domains
[i
] : "*unknown*",
414 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
417 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
423 /* Resolve a list of SIDs to a list of names */
425 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
427 int argc
, const char **argv
)
429 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
431 struct lsa_SidArray sids
;
432 struct lsa_RefDomainList
*domains
;
433 struct lsa_TransNameArray2 names
;
437 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
443 /* Convert arguments to sids */
445 sids
.num_sids
= argc
-1;
446 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
448 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
452 for (i
= 0; i
< sids
.num_sids
; i
++) {
453 sids
.sids
[0].sid
= string_sid_talloc(sids
.sids
, argv
[i
+ 1]);
454 if (!sids
.sids
[0].sid
) {
455 result
= NT_STATUS_INVALID_SID
;
460 /* Lookup the SIDs */
461 result
= rpccli_lsa_LookupSids3(cli
, mem_ctx
,
470 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
471 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
474 result
= NT_STATUS_OK
;
478 for (i
= 0; i
< count
; i
++) {
481 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
482 printf("%s %s (%d)\n", sid_str
,
483 names
.names
[i
].name
.string
,
484 names
.names
[i
].sid_type
);
492 /* Enumerate list of trusted domains */
494 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
495 TALLOC_CTX
*mem_ctx
, int argc
,
498 struct policy_handle pol
;
499 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
500 struct lsa_DomainList domain_list
;
502 /* defaults, but may be changed using params */
505 uint32_t max_size
= (uint32_t)-1;
508 printf("Usage: %s [enum context (0)]\n", argv
[0]);
512 if (argc
== 2 && argv
[1]) {
513 enum_ctx
= atoi(argv
[2]);
516 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
517 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
520 if (!NT_STATUS_IS_OK(result
))
523 result
= STATUS_MORE_ENTRIES
;
525 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
527 /* Lookup list of trusted domains */
529 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
534 if (!NT_STATUS_IS_OK(result
) &&
535 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
536 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
539 /* Print results: list of names and sids returned in this
541 for (i
= 0; i
< domain_list
.count
; i
++) {
544 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
546 domain_list
.domains
[i
].name
.string
?
547 domain_list
.domains
[i
].name
.string
: "*unknown*",
552 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
557 /* Enumerates privileges */
559 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
560 TALLOC_CTX
*mem_ctx
, int argc
,
563 struct policy_handle pol
;
564 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
565 struct lsa_PrivArray priv_array
;
567 uint32 enum_context
=0;
568 uint32 pref_max_length
=0x1000;
572 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
577 enum_context
=atoi(argv
[1]);
580 pref_max_length
=atoi(argv
[2]);
582 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
583 SEC_FLAG_MAXIMUM_ALLOWED
,
586 if (!NT_STATUS_IS_OK(result
))
589 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
594 if (!NT_STATUS_IS_OK(result
))
598 printf("found %d privileges\n\n", priv_array
.count
);
600 for (i
= 0; i
< priv_array
.count
; i
++) {
601 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
602 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
603 priv_array
.privs
[i
].luid
.high
,
604 priv_array
.privs
[i
].luid
.low
,
605 priv_array
.privs
[i
].luid
.high
,
606 priv_array
.privs
[i
].luid
.low
);
609 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
614 /* Get privilege name */
616 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
617 TALLOC_CTX
*mem_ctx
, int argc
,
620 struct policy_handle pol
;
621 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
624 uint16 lang_id_sys
=0;
626 struct lsa_String lsa_name
;
627 struct lsa_StringLarge
*description
= NULL
;
630 printf("Usage: %s privilege name\n", argv
[0]);
634 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
635 SEC_FLAG_MAXIMUM_ALLOWED
,
638 if (!NT_STATUS_IS_OK(result
))
641 init_lsa_String(&lsa_name
, argv
[1]);
643 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
651 if (!NT_STATUS_IS_OK(result
))
655 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
657 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
662 /* Enumerate the LSA SIDS */
664 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
665 TALLOC_CTX
*mem_ctx
, int argc
,
668 struct policy_handle pol
;
669 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
671 uint32 enum_context
=0;
672 uint32 pref_max_length
=0x1000;
673 struct lsa_SidArray sid_array
;
677 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
682 enum_context
=atoi(argv
[1]);
685 pref_max_length
=atoi(argv
[2]);
687 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
688 SEC_FLAG_MAXIMUM_ALLOWED
,
691 if (!NT_STATUS_IS_OK(result
))
694 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
700 if (!NT_STATUS_IS_OK(result
))
704 printf("found %d SIDs\n\n", sid_array
.num_sids
);
706 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
709 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
710 printf("%s\n", sid_str
);
713 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
718 /* Create a new account */
720 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
721 TALLOC_CTX
*mem_ctx
, int argc
,
724 struct policy_handle dom_pol
;
725 struct policy_handle user_pol
;
726 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
727 uint32 des_access
= 0x000f000f;
732 printf("Usage: %s SID\n", argv
[0]);
736 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
737 if (!NT_STATUS_IS_OK(result
))
740 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
741 SEC_FLAG_MAXIMUM_ALLOWED
,
744 if (!NT_STATUS_IS_OK(result
))
747 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
753 if (!NT_STATUS_IS_OK(result
))
756 printf("Account for SID %s successfully created\n\n", argv
[1]);
757 result
= NT_STATUS_OK
;
759 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
765 /* Enumerate the privileges of an SID */
767 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
768 TALLOC_CTX
*mem_ctx
, int argc
,
771 struct policy_handle dom_pol
;
772 struct policy_handle user_pol
;
773 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
774 uint32 access_desired
= 0x000f000f;
776 struct lsa_PrivilegeSet
*privs
= NULL
;
780 printf("Usage: %s SID\n", argv
[0]);
784 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
785 if (!NT_STATUS_IS_OK(result
))
788 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
789 SEC_FLAG_MAXIMUM_ALLOWED
,
792 if (!NT_STATUS_IS_OK(result
))
795 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
801 if (!NT_STATUS_IS_OK(result
))
804 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
808 if (!NT_STATUS_IS_OK(result
))
812 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
813 printf("high\tlow\tattribute\n");
815 for (i
= 0; i
< privs
->count
; i
++) {
816 printf("%u\t%u\t%u\n",
817 privs
->set
[i
].luid
.high
,
818 privs
->set
[i
].luid
.low
,
819 privs
->set
[i
].attribute
);
822 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
828 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
830 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
831 TALLOC_CTX
*mem_ctx
, int argc
,
834 struct policy_handle dom_pol
;
835 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
837 struct lsa_RightSet rights
;
842 printf("Usage: %s SID\n", argv
[0]);
846 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
847 if (!NT_STATUS_IS_OK(result
))
850 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
851 SEC_FLAG_MAXIMUM_ALLOWED
,
854 if (!NT_STATUS_IS_OK(result
))
857 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
862 if (!NT_STATUS_IS_OK(result
))
865 printf("found %d privileges for SID %s\n", rights
.count
,
866 sid_string_tos(&sid
));
868 for (i
= 0; i
< rights
.count
; i
++) {
869 printf("\t%s\n", rights
.names
[i
].string
);
872 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
878 /* add some privileges to a SID via LsaAddAccountRights */
880 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
881 TALLOC_CTX
*mem_ctx
, int argc
,
884 struct policy_handle dom_pol
;
885 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
886 struct lsa_RightSet rights
;
891 printf("Usage: %s SID [rights...]\n", argv
[0]);
895 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
896 if (!NT_STATUS_IS_OK(result
))
899 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
900 SEC_FLAG_MAXIMUM_ALLOWED
,
903 if (!NT_STATUS_IS_OK(result
))
906 rights
.count
= argc
-2;
907 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
910 return NT_STATUS_NO_MEMORY
;
913 for (i
=0; i
<argc
-2; i
++) {
914 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
917 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
922 if (!NT_STATUS_IS_OK(result
))
925 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
931 /* remove some privileges to a SID via LsaRemoveAccountRights */
933 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
934 TALLOC_CTX
*mem_ctx
, int argc
,
937 struct policy_handle dom_pol
;
938 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
939 struct lsa_RightSet rights
;
944 printf("Usage: %s SID [rights...]\n", argv
[0]);
948 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
949 if (!NT_STATUS_IS_OK(result
))
952 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
953 SEC_FLAG_MAXIMUM_ALLOWED
,
956 if (!NT_STATUS_IS_OK(result
))
959 rights
.count
= argc
-2;
960 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
963 return NT_STATUS_NO_MEMORY
;
966 for (i
=0; i
<argc
-2; i
++) {
967 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
970 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
976 if (!NT_STATUS_IS_OK(result
))
979 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
986 /* Get a privilege value given its name */
988 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
989 TALLOC_CTX
*mem_ctx
, int argc
,
992 struct policy_handle pol
;
993 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
994 struct lsa_LUID luid
;
995 struct lsa_String name
;
998 printf("Usage: %s name\n", argv
[0]);
1002 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1003 SEC_FLAG_MAXIMUM_ALLOWED
,
1006 if (!NT_STATUS_IS_OK(result
))
1009 init_lsa_String(&name
, argv
[1]);
1011 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1016 if (!NT_STATUS_IS_OK(result
))
1021 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1023 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1028 /* Query LSA security object */
1030 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1031 TALLOC_CTX
*mem_ctx
, int argc
,
1034 struct policy_handle pol
;
1035 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1037 uint32 sec_info
= DACL_SECURITY_INFORMATION
;
1039 if (argc
< 1 || argc
> 2) {
1040 printf("Usage: %s [sec_info]\n", argv
[0]);
1041 return NT_STATUS_OK
;
1044 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1045 SEC_FLAG_MAXIMUM_ALLOWED
,
1049 sscanf(argv
[1], "%x", &sec_info
);
1051 if (!NT_STATUS_IS_OK(result
))
1054 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
1058 if (!NT_STATUS_IS_OK(result
))
1063 display_sec_desc(sdb
->sd
);
1065 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1070 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1071 uint8_t session_key
[16])
1073 char *pwd
, *pwd_old
;
1075 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1076 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1077 DATA_BLOB session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
1079 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key_blob
);
1080 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key_blob
);
1082 d_printf("Password:\t%s\n", pwd
);
1083 d_printf("Old Password:\t%s\n", pwd_old
);
1086 talloc_free(pwd_old
);
1089 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1090 union lsa_TrustedDomainInfo
*info
,
1091 enum lsa_TrustDomInfoEnum info_class
,
1092 uint8_t nt_hash
[16])
1094 switch (info_class
) {
1095 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1096 display_trust_dom_info_4(&info
->password
, nt_hash
);
1099 const char *str
= NULL
;
1100 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1101 lsa_TrustedDomainInfo
,
1104 d_printf("%s\n", str
);
1111 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1112 TALLOC_CTX
*mem_ctx
, int argc
,
1115 struct policy_handle pol
;
1116 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1118 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1119 union lsa_TrustedDomainInfo
*info
= NULL
;
1120 enum lsa_TrustDomInfoEnum info_class
= 1;
1121 uint8_t nt_hash
[16];
1123 if (argc
> 3 || argc
< 2) {
1124 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1125 return NT_STATUS_OK
;
1128 if (!string_to_sid(&dom_sid
, argv
[1]))
1129 return NT_STATUS_NO_MEMORY
;
1132 info_class
= atoi(argv
[2]);
1134 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1136 if (!NT_STATUS_IS_OK(result
))
1139 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1144 if (!NT_STATUS_IS_OK(result
))
1147 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1148 d_fprintf(stderr
, "Could not get pwd hash\n");
1152 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1155 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1160 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1161 TALLOC_CTX
*mem_ctx
, int argc
,
1164 struct policy_handle pol
;
1165 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1166 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1167 union lsa_TrustedDomainInfo
*info
= NULL
;
1168 enum lsa_TrustDomInfoEnum info_class
= 1;
1169 struct lsa_String trusted_domain
;
1170 uint8_t nt_hash
[16];
1172 if (argc
> 3 || argc
< 2) {
1173 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1174 return NT_STATUS_OK
;
1178 info_class
= atoi(argv
[2]);
1180 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1182 if (!NT_STATUS_IS_OK(result
))
1185 init_lsa_String(&trusted_domain
, argv
[1]);
1187 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1192 if (!NT_STATUS_IS_OK(result
))
1195 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1196 d_fprintf(stderr
, "Could not get pwd hash\n");
1200 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1203 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1208 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1209 TALLOC_CTX
*mem_ctx
, int argc
,
1212 struct policy_handle pol
, trustdom_pol
;
1213 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1214 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1215 union lsa_TrustedDomainInfo
*info
= NULL
;
1217 enum lsa_TrustDomInfoEnum info_class
= 1;
1218 uint8_t nt_hash
[16];
1220 if (argc
> 3 || argc
< 2) {
1221 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1222 return NT_STATUS_OK
;
1225 if (!string_to_sid(&dom_sid
, argv
[1]))
1226 return NT_STATUS_NO_MEMORY
;
1230 info_class
= atoi(argv
[2]);
1232 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1234 if (!NT_STATUS_IS_OK(result
))
1237 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1243 if (!NT_STATUS_IS_OK(result
))
1246 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1251 if (!NT_STATUS_IS_OK(result
))
1254 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1255 d_fprintf(stderr
, "Could not get pwd hash\n");
1259 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1262 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1267 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1268 TALLOC_CTX
*mem_ctx
, int argc
,
1271 struct policy_handle pol
;
1272 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1273 const char *servername
= cli
->desthost
;
1274 struct lsa_String
*account_name
= NULL
;
1275 struct lsa_String
*authority_name
= NULL
;
1278 printf("Usage: %s servername\n", argv
[0]);
1279 return NT_STATUS_OK
;
1282 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1283 SEC_FLAG_MAXIMUM_ALLOWED
,
1286 if (!NT_STATUS_IS_OK(result
)) {
1290 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1294 if (!NT_STATUS_IS_OK(result
)) {
1300 printf("Account Name: %s, Authority Name: %s\n",
1301 account_name
->string
, authority_name
? authority_name
->string
:
1304 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1309 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1310 TALLOC_CTX
*mem_ctx
, int argc
,
1313 struct policy_handle dom_pol
, user_pol
;
1314 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1315 struct lsa_PrivilegeSet privs
;
1316 struct lsa_LUIDAttribute
*set
= NULL
;
1323 printf("Usage: %s SID [rights...]\n", argv
[0]);
1324 return NT_STATUS_OK
;
1327 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1328 if (!NT_STATUS_IS_OK(result
)) {
1332 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1333 SEC_FLAG_MAXIMUM_ALLOWED
,
1336 if (!NT_STATUS_IS_OK(result
)) {
1340 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1343 SEC_FLAG_MAXIMUM_ALLOWED
,
1346 if (!NT_STATUS_IS_OK(result
)) {
1350 for (i
=2; i
<argc
; i
++) {
1352 struct lsa_String priv_name
;
1353 struct lsa_LUID luid
;
1355 init_lsa_String(&priv_name
, argv
[i
]);
1357 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1361 if (!NT_STATUS_IS_OK(result
)) {
1366 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1367 struct lsa_LUIDAttribute
,
1370 return NT_STATUS_NO_MEMORY
;
1373 set
[privs
.count
-1].luid
= luid
;
1374 set
[privs
.count
-1].attribute
= 0;
1379 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1383 if (!NT_STATUS_IS_OK(result
)) {
1387 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1388 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1393 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1394 TALLOC_CTX
*mem_ctx
, int argc
,
1397 struct policy_handle dom_pol
, user_pol
;
1398 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1399 struct lsa_PrivilegeSet privs
;
1400 struct lsa_LUIDAttribute
*set
= NULL
;
1407 printf("Usage: %s SID [rights...]\n", argv
[0]);
1408 return NT_STATUS_OK
;
1411 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1412 if (!NT_STATUS_IS_OK(result
)) {
1416 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1417 SEC_FLAG_MAXIMUM_ALLOWED
,
1420 if (!NT_STATUS_IS_OK(result
)) {
1424 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1427 SEC_FLAG_MAXIMUM_ALLOWED
,
1430 if (!NT_STATUS_IS_OK(result
)) {
1434 for (i
=2; i
<argc
; i
++) {
1436 struct lsa_String priv_name
;
1437 struct lsa_LUID luid
;
1439 init_lsa_String(&priv_name
, argv
[i
]);
1441 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1445 if (!NT_STATUS_IS_OK(result
)) {
1450 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1451 struct lsa_LUIDAttribute
,
1454 return NT_STATUS_NO_MEMORY
;
1457 set
[privs
.count
-1].luid
= luid
;
1458 set
[privs
.count
-1].attribute
= 0;
1464 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1469 if (!NT_STATUS_IS_OK(result
)) {
1473 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1474 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1479 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1480 TALLOC_CTX
*mem_ctx
, int argc
,
1484 struct policy_handle handle
, sec_handle
;
1485 struct lsa_String name
;
1488 printf("Usage: %s name\n", argv
[0]);
1489 return NT_STATUS_OK
;
1492 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1494 SEC_FLAG_MAXIMUM_ALLOWED
,
1496 if (!NT_STATUS_IS_OK(status
)) {
1500 init_lsa_String(&name
, argv
[1]);
1502 status
= rpccli_lsa_CreateSecret(cli
, mem_ctx
,
1505 SEC_FLAG_MAXIMUM_ALLOWED
,
1507 if (!NT_STATUS_IS_OK(status
)) {
1512 if (is_valid_policy_hnd(&sec_handle
)) {
1513 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1515 if (is_valid_policy_hnd(&handle
)) {
1516 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1522 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1523 TALLOC_CTX
*mem_ctx
, int argc
,
1527 struct policy_handle handle
, sec_handle
;
1528 struct lsa_String name
;
1531 printf("Usage: %s name\n", argv
[0]);
1532 return NT_STATUS_OK
;
1535 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1537 SEC_FLAG_MAXIMUM_ALLOWED
,
1539 if (!NT_STATUS_IS_OK(status
)) {
1543 init_lsa_String(&name
, argv
[1]);
1545 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1548 SEC_FLAG_MAXIMUM_ALLOWED
,
1550 if (!NT_STATUS_IS_OK(status
)) {
1554 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1556 if (!NT_STATUS_IS_OK(status
)) {
1561 if (is_valid_policy_hnd(&sec_handle
)) {
1562 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1564 if (is_valid_policy_hnd(&handle
)) {
1565 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1571 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1572 TALLOC_CTX
*mem_ctx
, int argc
,
1576 struct policy_handle handle
, sec_handle
;
1577 struct lsa_String name
;
1578 struct lsa_DATA_BUF_PTR new_val
;
1579 NTTIME new_mtime
= 0;
1580 struct lsa_DATA_BUF_PTR old_val
;
1581 NTTIME old_mtime
= 0;
1582 DATA_BLOB session_key
;
1583 DATA_BLOB new_blob
= data_blob_null
;
1584 DATA_BLOB old_blob
= data_blob_null
;
1585 char *new_secret
, *old_secret
;
1588 printf("Usage: %s name\n", argv
[0]);
1589 return NT_STATUS_OK
;
1592 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1594 SEC_FLAG_MAXIMUM_ALLOWED
,
1596 if (!NT_STATUS_IS_OK(status
)) {
1600 init_lsa_String(&name
, argv
[1]);
1602 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1605 SEC_FLAG_MAXIMUM_ALLOWED
,
1607 if (!NT_STATUS_IS_OK(status
)) {
1611 ZERO_STRUCT(new_val
);
1612 ZERO_STRUCT(old_val
);
1614 status
= rpccli_lsa_QuerySecret(cli
, mem_ctx
,
1620 if (!NT_STATUS_IS_OK(status
)) {
1624 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1625 if (!NT_STATUS_IS_OK(status
)) {
1630 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1633 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1636 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1637 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1639 d_printf("new secret: %s\n", new_secret
);
1642 d_printf("old secret: %s\n", old_secret
);
1646 if (is_valid_policy_hnd(&sec_handle
)) {
1647 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1649 if (is_valid_policy_hnd(&handle
)) {
1650 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1656 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1657 TALLOC_CTX
*mem_ctx
, int argc
,
1661 struct policy_handle handle
, sec_handle
;
1662 struct lsa_String name
;
1663 struct lsa_DATA_BUF new_val
;
1664 struct lsa_DATA_BUF old_val
;
1666 DATA_BLOB session_key
;
1669 printf("Usage: %s name secret\n", argv
[0]);
1670 return NT_STATUS_OK
;
1673 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1675 SEC_FLAG_MAXIMUM_ALLOWED
,
1677 if (!NT_STATUS_IS_OK(status
)) {
1681 init_lsa_String(&name
, argv
[1]);
1683 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1686 SEC_FLAG_MAXIMUM_ALLOWED
,
1688 if (!NT_STATUS_IS_OK(status
)) {
1692 ZERO_STRUCT(new_val
);
1693 ZERO_STRUCT(old_val
);
1695 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1696 if (!NT_STATUS_IS_OK(status
)) {
1700 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1702 new_val
.length
= enc_key
.length
;
1703 new_val
.size
= enc_key
.length
;
1704 new_val
.data
= enc_key
.data
;
1706 status
= rpccli_lsa_SetSecret(cli
, mem_ctx
,
1710 if (!NT_STATUS_IS_OK(status
)) {
1715 if (is_valid_policy_hnd(&sec_handle
)) {
1716 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1718 if (is_valid_policy_hnd(&handle
)) {
1719 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1725 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1726 TALLOC_CTX
*mem_ctx
, int argc
,
1730 struct policy_handle handle
;
1731 struct lsa_String name
;
1732 struct lsa_DATA_BUF
*val
;
1733 DATA_BLOB session_key
;
1738 printf("Usage: %s name\n", argv
[0]);
1739 return NT_STATUS_OK
;
1742 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1744 SEC_FLAG_MAXIMUM_ALLOWED
,
1746 if (!NT_STATUS_IS_OK(status
)) {
1750 init_lsa_String(&name
, argv
[1]);
1754 status
= rpccli_lsa_RetrievePrivateData(cli
, mem_ctx
,
1758 if (!NT_STATUS_IS_OK(status
)) {
1762 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1763 if (!NT_STATUS_IS_OK(status
)) {
1768 blob
= data_blob_const(val
->data
, val
->length
);
1771 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1773 d_printf("secret: %s\n", secret
);
1777 if (is_valid_policy_hnd(&handle
)) {
1778 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1784 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1785 TALLOC_CTX
*mem_ctx
, int argc
,
1789 struct policy_handle handle
;
1790 struct lsa_String name
;
1791 struct lsa_DATA_BUF val
;
1792 DATA_BLOB session_key
;
1796 printf("Usage: %s name secret\n", argv
[0]);
1797 return NT_STATUS_OK
;
1800 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1802 SEC_FLAG_MAXIMUM_ALLOWED
,
1804 if (!NT_STATUS_IS_OK(status
)) {
1808 init_lsa_String(&name
, argv
[1]);
1812 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1813 if (!NT_STATUS_IS_OK(status
)) {
1817 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1819 val
.length
= enc_key
.length
;
1820 val
.size
= enc_key
.length
;
1821 val
.data
= enc_key
.data
;
1823 status
= rpccli_lsa_StorePrivateData(cli
, mem_ctx
,
1827 if (!NT_STATUS_IS_OK(status
)) {
1832 if (is_valid_policy_hnd(&handle
)) {
1833 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1840 /* List of commands exported by this module */
1842 struct cmd_set lsarpc_commands
[] = {
1846 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1847 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1848 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1849 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1850 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1851 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1852 { "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)]" },
1853 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1854 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1855 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1856 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
1857 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
1858 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
1859 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
1860 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
1861 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
1862 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
1863 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
1864 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
1865 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1866 { "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", "" },
1867 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
1868 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
1869 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
1870 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
1871 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
1872 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
1873 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
1874 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },