2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
7 Copyright (C) Guenther Deschner 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpcclient.h"
25 #include "../libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_lsa.h"
27 #include "../librpc/gen_ndr/cli_lsa.h"
28 #include "rpc_client/cli_lsarpc.h"
30 /* useful function to allow entering a name instead of a SID and
31 * looking it up automatically */
32 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
34 struct dom_sid
*sid
, const char *name
)
36 struct policy_handle pol
;
37 enum lsa_SidType
*sid_types
;
41 /* maybe its a raw SID */
42 if (strncmp(name
, "S-", 2) == 0 &&
43 string_to_sid(sid
, name
)) {
47 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
48 SEC_FLAG_MAXIMUM_ALLOWED
,
50 if (!NT_STATUS_IS_OK(result
))
53 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
54 if (!NT_STATUS_IS_OK(result
))
57 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
65 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
67 d_printf("percent_full:\t%d\n", r
->percent_full
);
68 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
69 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
70 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
71 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
72 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
75 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
78 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
79 d_printf("Auditing categories:\t%d\n", r
->count
);
80 d_printf("Auditsettings:\n");
81 for (i
=0; i
<r
->count
; i
++) {
82 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
83 const char *policy
= audit_description_str(i
);
84 d_printf("%s:\t%s\n", policy
, val
);
88 static void display_query_info_3(struct lsa_DomainInfo
*r
)
90 d_printf("Domain Name: %s\n", r
->name
.string
);
91 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
94 static void display_query_info_5(struct lsa_DomainInfo
*r
)
96 d_printf("Domain Name: %s\n", r
->name
.string
);
97 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
100 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
102 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
105 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
107 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
108 d_printf("Log is full: %d\n", r
->log_is_full
);
111 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
113 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
114 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
115 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
116 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
117 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
121 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
122 enum lsa_PolicyInfo level
)
126 display_query_info_1(&info
->audit_log
);
129 display_query_info_2(&info
->audit_events
);
132 display_query_info_3(&info
->domain
);
135 display_query_info_5(&info
->account_domain
);
138 display_query_info_10(&info
->auditfullset
);
141 display_query_info_11(&info
->auditfullquery
);
144 display_query_info_12(&info
->dns
);
147 printf("can't display info level: %d\n", level
);
152 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
153 TALLOC_CTX
*mem_ctx
, int argc
,
156 struct policy_handle pol
;
157 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
158 union lsa_PolicyInformation
*info
= NULL
;
160 uint32 info_class
= 3;
163 printf("Usage: %s [info_class]\n", argv
[0]);
168 info_class
= atoi(argv
[1]);
170 switch (info_class
) {
172 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
173 SEC_FLAG_MAXIMUM_ALLOWED
,
176 if (!NT_STATUS_IS_OK(result
))
179 result
= rpccli_lsa_QueryInfoPolicy2(cli
, mem_ctx
,
185 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
186 SEC_FLAG_MAXIMUM_ALLOWED
,
189 if (!NT_STATUS_IS_OK(result
))
192 result
= rpccli_lsa_QueryInfoPolicy(cli
, mem_ctx
,
198 if (NT_STATUS_IS_OK(result
)) {
199 display_lsa_query_info(info
, info_class
);
202 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
208 /* Resolve a list of names to a list of sids */
210 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
211 TALLOC_CTX
*mem_ctx
, int argc
,
214 struct policy_handle pol
;
215 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
216 struct dom_sid
*sids
;
217 enum lsa_SidType
*types
;
221 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
225 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
226 SEC_FLAG_MAXIMUM_ALLOWED
,
229 if (!NT_STATUS_IS_OK(result
))
232 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
233 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
235 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
236 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
239 result
= NT_STATUS_OK
;
243 for (i
= 0; i
< (argc
- 1); i
++) {
245 sid_to_fstring(sid_str
, &sids
[i
]);
246 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
247 sid_type_lookup(types
[i
]), types
[i
]);
250 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
256 /* Resolve a list of names to a list of sids */
258 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
259 TALLOC_CTX
*mem_ctx
, int argc
,
262 struct policy_handle pol
;
263 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
264 struct dom_sid
*sids
;
265 enum lsa_SidType
*types
;
269 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
273 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
274 SEC_FLAG_MAXIMUM_ALLOWED
,
277 if (!NT_STATUS_IS_OK(result
))
280 level
= atoi(argv
[1]);
282 result
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
283 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
285 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
286 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
289 result
= NT_STATUS_OK
;
293 for (i
= 0; i
< (argc
- 2); i
++) {
295 sid_to_fstring(sid_str
, &sids
[i
]);
296 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
297 sid_type_lookup(types
[i
]), types
[i
]);
300 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
306 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
307 TALLOC_CTX
*mem_ctx
, int argc
,
310 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
313 struct lsa_String
*names
;
314 struct lsa_RefDomainList
*domains
;
315 struct lsa_TransSidArray3 sids
;
320 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
327 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
328 NT_STATUS_HAVE_NO_MEMORY(names
);
330 for (i
=0; i
< num_names
; i
++) {
331 init_lsa_String(&names
[i
], argv
[i
+1]);
334 result
= rpccli_lsa_LookupNames4(cli
, mem_ctx
,
343 if (!NT_STATUS_IS_OK(result
)) {
347 for (i
= 0; i
< sids
.count
; i
++) {
349 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
350 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
351 sid_type_lookup(sids
.sids
[i
].sid_type
),
352 sids
.sids
[i
].sid_type
);
358 /* Resolve a list of SIDs to a list of names */
360 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
361 int argc
, const char **argv
)
363 struct policy_handle pol
;
364 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
365 struct dom_sid
*sids
;
368 enum lsa_SidType
*types
;
372 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
376 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
377 SEC_FLAG_MAXIMUM_ALLOWED
,
380 if (!NT_STATUS_IS_OK(result
))
383 /* Convert arguments to sids */
385 sids
= TALLOC_ARRAY(mem_ctx
, struct dom_sid
, argc
- 1);
388 printf("could not allocate memory for %d sids\n", argc
- 1);
392 for (i
= 0; i
< argc
- 1; i
++)
393 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
394 result
= NT_STATUS_INVALID_SID
;
398 /* Lookup the SIDs */
400 result
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
401 &domains
, &names
, &types
);
403 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
404 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
407 result
= NT_STATUS_OK
;
411 for (i
= 0; i
< (argc
- 1); i
++) {
414 sid_to_fstring(sid_str
, &sids
[i
]);
415 printf("%s %s\\%s (%d)\n", sid_str
,
416 domains
[i
] ? domains
[i
] : "*unknown*",
417 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
420 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
426 /* Resolve a list of SIDs to a list of names */
428 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
430 int argc
, const char **argv
)
432 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
434 struct lsa_SidArray sids
;
435 struct lsa_RefDomainList
*domains
;
436 struct lsa_TransNameArray2 names
;
440 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
446 /* Convert arguments to sids */
448 sids
.num_sids
= argc
-1;
449 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
451 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
455 for (i
= 0; i
< sids
.num_sids
; i
++) {
456 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
457 if (sids
.sids
[i
].sid
== NULL
) {
458 result
= NT_STATUS_NO_MEMORY
;
461 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
462 result
= NT_STATUS_INVALID_SID
;
467 /* Lookup the SIDs */
468 result
= rpccli_lsa_LookupSids3(cli
, mem_ctx
,
477 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
478 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
481 result
= NT_STATUS_OK
;
485 for (i
= 0; i
< count
; i
++) {
488 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
489 printf("%s %s (%d)\n", sid_str
,
490 names
.names
[i
].name
.string
,
491 names
.names
[i
].sid_type
);
499 /* Enumerate list of trusted domains */
501 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
502 TALLOC_CTX
*mem_ctx
, int argc
,
505 struct policy_handle pol
;
506 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
507 struct lsa_DomainList domain_list
;
509 /* defaults, but may be changed using params */
512 uint32_t max_size
= (uint32_t)-1;
515 printf("Usage: %s [enum context (0)]\n", argv
[0]);
519 if (argc
== 2 && argv
[1]) {
520 enum_ctx
= atoi(argv
[2]);
523 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
524 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
527 if (!NT_STATUS_IS_OK(result
))
530 result
= STATUS_MORE_ENTRIES
;
532 while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
534 /* Lookup list of trusted domains */
536 result
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
541 if (!NT_STATUS_IS_OK(result
) &&
542 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
543 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
546 /* Print results: list of names and sids returned in this
548 for (i
= 0; i
< domain_list
.count
; i
++) {
551 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
553 domain_list
.domains
[i
].name
.string
?
554 domain_list
.domains
[i
].name
.string
: "*unknown*",
559 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
564 /* Enumerates privileges */
566 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
567 TALLOC_CTX
*mem_ctx
, int argc
,
570 struct policy_handle pol
;
571 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
572 struct lsa_PrivArray priv_array
;
574 uint32 enum_context
=0;
575 uint32 pref_max_length
=0x1000;
579 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
584 enum_context
=atoi(argv
[1]);
587 pref_max_length
=atoi(argv
[2]);
589 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
590 SEC_FLAG_MAXIMUM_ALLOWED
,
593 if (!NT_STATUS_IS_OK(result
))
596 result
= rpccli_lsa_EnumPrivs(cli
, mem_ctx
,
601 if (!NT_STATUS_IS_OK(result
))
605 printf("found %d privileges\n\n", priv_array
.count
);
607 for (i
= 0; i
< priv_array
.count
; i
++) {
608 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
609 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
610 priv_array
.privs
[i
].luid
.high
,
611 priv_array
.privs
[i
].luid
.low
,
612 priv_array
.privs
[i
].luid
.high
,
613 priv_array
.privs
[i
].luid
.low
);
616 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
621 /* Get privilege name */
623 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
624 TALLOC_CTX
*mem_ctx
, int argc
,
627 struct policy_handle pol
;
628 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
631 uint16 lang_id_sys
=0;
633 struct lsa_String lsa_name
;
634 struct lsa_StringLarge
*description
= NULL
;
637 printf("Usage: %s privilege name\n", argv
[0]);
641 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
642 SEC_FLAG_MAXIMUM_ALLOWED
,
645 if (!NT_STATUS_IS_OK(result
))
648 init_lsa_String(&lsa_name
, argv
[1]);
650 result
= rpccli_lsa_LookupPrivDisplayName(cli
, mem_ctx
,
658 if (!NT_STATUS_IS_OK(result
))
662 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
664 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
669 /* Enumerate the LSA SIDS */
671 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
672 TALLOC_CTX
*mem_ctx
, int argc
,
675 struct policy_handle pol
;
676 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
678 uint32 enum_context
=0;
679 uint32 pref_max_length
=0x1000;
680 struct lsa_SidArray sid_array
;
684 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
689 enum_context
=atoi(argv
[1]);
692 pref_max_length
=atoi(argv
[2]);
694 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
695 SEC_FLAG_MAXIMUM_ALLOWED
,
698 if (!NT_STATUS_IS_OK(result
))
701 result
= rpccli_lsa_EnumAccounts(cli
, mem_ctx
,
707 if (!NT_STATUS_IS_OK(result
))
711 printf("found %d SIDs\n\n", sid_array
.num_sids
);
713 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
716 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
717 printf("%s\n", sid_str
);
720 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
725 /* Create a new account */
727 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
728 TALLOC_CTX
*mem_ctx
, int argc
,
731 struct policy_handle dom_pol
;
732 struct policy_handle user_pol
;
733 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
734 uint32 des_access
= 0x000f000f;
739 printf("Usage: %s SID\n", argv
[0]);
743 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
744 if (!NT_STATUS_IS_OK(result
))
747 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
748 SEC_FLAG_MAXIMUM_ALLOWED
,
751 if (!NT_STATUS_IS_OK(result
))
754 result
= rpccli_lsa_CreateAccount(cli
, mem_ctx
,
760 if (!NT_STATUS_IS_OK(result
))
763 printf("Account for SID %s successfully created\n\n", argv
[1]);
764 result
= NT_STATUS_OK
;
766 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
772 /* Enumerate the privileges of an SID */
774 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
775 TALLOC_CTX
*mem_ctx
, int argc
,
778 struct policy_handle dom_pol
;
779 struct policy_handle user_pol
;
780 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
781 uint32 access_desired
= 0x000f000f;
783 struct lsa_PrivilegeSet
*privs
= NULL
;
787 printf("Usage: %s SID\n", argv
[0]);
791 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
792 if (!NT_STATUS_IS_OK(result
))
795 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
796 SEC_FLAG_MAXIMUM_ALLOWED
,
799 if (!NT_STATUS_IS_OK(result
))
802 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
808 if (!NT_STATUS_IS_OK(result
))
811 result
= rpccli_lsa_EnumPrivsAccount(cli
, mem_ctx
,
815 if (!NT_STATUS_IS_OK(result
))
819 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
820 printf("high\tlow\tattribute\n");
822 for (i
= 0; i
< privs
->count
; i
++) {
823 printf("%u\t%u\t%u\n",
824 privs
->set
[i
].luid
.high
,
825 privs
->set
[i
].luid
.low
,
826 privs
->set
[i
].attribute
);
829 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
835 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
837 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
838 TALLOC_CTX
*mem_ctx
, int argc
,
841 struct policy_handle dom_pol
;
842 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
844 struct lsa_RightSet rights
;
849 printf("Usage: %s SID\n", argv
[0]);
853 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
854 if (!NT_STATUS_IS_OK(result
))
857 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
858 SEC_FLAG_MAXIMUM_ALLOWED
,
861 if (!NT_STATUS_IS_OK(result
))
864 result
= rpccli_lsa_EnumAccountRights(cli
, mem_ctx
,
869 if (!NT_STATUS_IS_OK(result
))
872 printf("found %d privileges for SID %s\n", rights
.count
,
873 sid_string_tos(&sid
));
875 for (i
= 0; i
< rights
.count
; i
++) {
876 printf("\t%s\n", rights
.names
[i
].string
);
879 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
885 /* add some privileges to a SID via LsaAddAccountRights */
887 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
888 TALLOC_CTX
*mem_ctx
, int argc
,
891 struct policy_handle dom_pol
;
892 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
893 struct lsa_RightSet rights
;
898 printf("Usage: %s SID [rights...]\n", argv
[0]);
902 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
903 if (!NT_STATUS_IS_OK(result
))
906 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
907 SEC_FLAG_MAXIMUM_ALLOWED
,
910 if (!NT_STATUS_IS_OK(result
))
913 rights
.count
= argc
-2;
914 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
917 return NT_STATUS_NO_MEMORY
;
920 for (i
=0; i
<argc
-2; i
++) {
921 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
924 result
= rpccli_lsa_AddAccountRights(cli
, mem_ctx
,
929 if (!NT_STATUS_IS_OK(result
))
932 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
938 /* remove some privileges to a SID via LsaRemoveAccountRights */
940 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
941 TALLOC_CTX
*mem_ctx
, int argc
,
944 struct policy_handle dom_pol
;
945 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
946 struct lsa_RightSet rights
;
951 printf("Usage: %s SID [rights...]\n", argv
[0]);
955 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
956 if (!NT_STATUS_IS_OK(result
))
959 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
960 SEC_FLAG_MAXIMUM_ALLOWED
,
963 if (!NT_STATUS_IS_OK(result
))
966 rights
.count
= argc
-2;
967 rights
.names
= TALLOC_ARRAY(mem_ctx
, struct lsa_StringLarge
,
970 return NT_STATUS_NO_MEMORY
;
973 for (i
=0; i
<argc
-2; i
++) {
974 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
977 result
= rpccli_lsa_RemoveAccountRights(cli
, mem_ctx
,
983 if (!NT_STATUS_IS_OK(result
))
986 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
993 /* Get a privilege value given its name */
995 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
996 TALLOC_CTX
*mem_ctx
, int argc
,
999 struct policy_handle pol
;
1000 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1001 struct lsa_LUID luid
;
1002 struct lsa_String name
;
1005 printf("Usage: %s name\n", argv
[0]);
1006 return NT_STATUS_OK
;
1009 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1010 SEC_FLAG_MAXIMUM_ALLOWED
,
1013 if (!NT_STATUS_IS_OK(result
))
1016 init_lsa_String(&name
, argv
[1]);
1018 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1023 if (!NT_STATUS_IS_OK(result
))
1028 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1030 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1035 /* Query LSA security object */
1037 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1038 TALLOC_CTX
*mem_ctx
, int argc
,
1041 struct policy_handle pol
;
1042 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1043 struct sec_desc_buf
*sdb
;
1044 uint32 sec_info
= SECINFO_DACL
;
1046 if (argc
< 1 || argc
> 2) {
1047 printf("Usage: %s [sec_info]\n", argv
[0]);
1048 return NT_STATUS_OK
;
1051 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1052 SEC_FLAG_MAXIMUM_ALLOWED
,
1056 sscanf(argv
[1], "%x", &sec_info
);
1058 if (!NT_STATUS_IS_OK(result
))
1061 result
= rpccli_lsa_QuerySecurity(cli
, mem_ctx
,
1065 if (!NT_STATUS_IS_OK(result
))
1070 display_sec_desc(sdb
->sd
);
1072 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1077 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1078 uint8_t session_key
[16])
1080 char *pwd
, *pwd_old
;
1082 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1083 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1084 DATA_BLOB session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
1086 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key_blob
);
1087 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key_blob
);
1089 d_printf("Password:\t%s\n", pwd
);
1090 d_printf("Old Password:\t%s\n", pwd_old
);
1093 talloc_free(pwd_old
);
1096 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1097 union lsa_TrustedDomainInfo
*info
,
1098 enum lsa_TrustDomInfoEnum info_class
,
1099 uint8_t nt_hash
[16])
1101 switch (info_class
) {
1102 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1103 display_trust_dom_info_4(&info
->password
, nt_hash
);
1106 const char *str
= NULL
;
1107 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1108 lsa_TrustedDomainInfo
,
1111 d_printf("%s\n", str
);
1118 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1119 TALLOC_CTX
*mem_ctx
, int argc
,
1122 struct policy_handle pol
;
1123 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1124 struct dom_sid dom_sid
;
1125 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1126 union lsa_TrustedDomainInfo
*info
= NULL
;
1127 enum lsa_TrustDomInfoEnum info_class
= 1;
1128 uint8_t nt_hash
[16];
1130 if (argc
> 3 || argc
< 2) {
1131 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1132 return NT_STATUS_OK
;
1135 if (!string_to_sid(&dom_sid
, argv
[1]))
1136 return NT_STATUS_NO_MEMORY
;
1139 info_class
= atoi(argv
[2]);
1141 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1143 if (!NT_STATUS_IS_OK(result
))
1146 result
= rpccli_lsa_QueryTrustedDomainInfoBySid(cli
, mem_ctx
,
1151 if (!NT_STATUS_IS_OK(result
))
1154 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1155 d_fprintf(stderr
, "Could not get pwd hash\n");
1159 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1162 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1167 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1168 TALLOC_CTX
*mem_ctx
, int argc
,
1171 struct policy_handle pol
;
1172 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1173 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1174 union lsa_TrustedDomainInfo
*info
= NULL
;
1175 enum lsa_TrustDomInfoEnum info_class
= 1;
1176 struct lsa_String trusted_domain
;
1177 uint8_t nt_hash
[16];
1179 if (argc
> 3 || argc
< 2) {
1180 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1181 return NT_STATUS_OK
;
1185 info_class
= atoi(argv
[2]);
1187 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1189 if (!NT_STATUS_IS_OK(result
))
1192 init_lsa_String(&trusted_domain
, argv
[1]);
1194 result
= rpccli_lsa_QueryTrustedDomainInfoByName(cli
, mem_ctx
,
1199 if (!NT_STATUS_IS_OK(result
))
1202 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1203 d_fprintf(stderr
, "Could not get pwd hash\n");
1207 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1210 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1215 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1216 TALLOC_CTX
*mem_ctx
, int argc
,
1219 struct policy_handle pol
, trustdom_pol
;
1220 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1221 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1222 union lsa_TrustedDomainInfo
*info
= NULL
;
1223 struct dom_sid dom_sid
;
1224 enum lsa_TrustDomInfoEnum info_class
= 1;
1225 uint8_t nt_hash
[16];
1227 if (argc
> 3 || argc
< 2) {
1228 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1229 return NT_STATUS_OK
;
1232 if (!string_to_sid(&dom_sid
, argv
[1]))
1233 return NT_STATUS_NO_MEMORY
;
1237 info_class
= atoi(argv
[2]);
1239 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1241 if (!NT_STATUS_IS_OK(result
))
1244 result
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1250 if (!NT_STATUS_IS_OK(result
))
1253 result
= rpccli_lsa_QueryTrustedDomainInfo(cli
, mem_ctx
,
1258 if (!NT_STATUS_IS_OK(result
))
1261 if (!rpccli_get_pwd_hash(cli
, nt_hash
)) {
1262 d_fprintf(stderr
, "Could not get pwd hash\n");
1266 display_trust_dom_info(mem_ctx
, info
, info_class
, nt_hash
);
1269 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1274 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1275 TALLOC_CTX
*mem_ctx
, int argc
,
1278 struct policy_handle pol
;
1279 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1280 const char *servername
= cli
->desthost
;
1281 struct lsa_String
*account_name
= NULL
;
1282 struct lsa_String
*authority_name
= NULL
;
1285 printf("Usage: %s servername\n", argv
[0]);
1286 return NT_STATUS_OK
;
1289 result
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1290 SEC_FLAG_MAXIMUM_ALLOWED
,
1293 if (!NT_STATUS_IS_OK(result
)) {
1297 result
= rpccli_lsa_GetUserName(cli
, mem_ctx
,
1301 if (!NT_STATUS_IS_OK(result
)) {
1307 printf("Account Name: %s, Authority Name: %s\n",
1308 account_name
->string
, authority_name
? authority_name
->string
:
1311 rpccli_lsa_Close(cli
, mem_ctx
, &pol
);
1316 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1317 TALLOC_CTX
*mem_ctx
, int argc
,
1320 struct policy_handle dom_pol
, user_pol
;
1321 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1322 struct lsa_PrivilegeSet privs
;
1323 struct lsa_LUIDAttribute
*set
= NULL
;
1330 printf("Usage: %s SID [rights...]\n", argv
[0]);
1331 return NT_STATUS_OK
;
1334 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1335 if (!NT_STATUS_IS_OK(result
)) {
1339 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1340 SEC_FLAG_MAXIMUM_ALLOWED
,
1343 if (!NT_STATUS_IS_OK(result
)) {
1347 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1350 SEC_FLAG_MAXIMUM_ALLOWED
,
1353 if (!NT_STATUS_IS_OK(result
)) {
1357 for (i
=2; i
<argc
; i
++) {
1359 struct lsa_String priv_name
;
1360 struct lsa_LUID luid
;
1362 init_lsa_String(&priv_name
, argv
[i
]);
1364 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1368 if (!NT_STATUS_IS_OK(result
)) {
1373 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1374 struct lsa_LUIDAttribute
,
1377 return NT_STATUS_NO_MEMORY
;
1380 set
[privs
.count
-1].luid
= luid
;
1381 set
[privs
.count
-1].attribute
= 0;
1386 result
= rpccli_lsa_AddPrivilegesToAccount(cli
, mem_ctx
,
1390 if (!NT_STATUS_IS_OK(result
)) {
1394 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1395 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1400 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1401 TALLOC_CTX
*mem_ctx
, int argc
,
1404 struct policy_handle dom_pol
, user_pol
;
1405 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1406 struct lsa_PrivilegeSet privs
;
1407 struct lsa_LUIDAttribute
*set
= NULL
;
1414 printf("Usage: %s SID [rights...]\n", argv
[0]);
1415 return NT_STATUS_OK
;
1418 result
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1419 if (!NT_STATUS_IS_OK(result
)) {
1423 result
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1424 SEC_FLAG_MAXIMUM_ALLOWED
,
1427 if (!NT_STATUS_IS_OK(result
)) {
1431 result
= rpccli_lsa_OpenAccount(cli
, mem_ctx
,
1434 SEC_FLAG_MAXIMUM_ALLOWED
,
1437 if (!NT_STATUS_IS_OK(result
)) {
1441 for (i
=2; i
<argc
; i
++) {
1443 struct lsa_String priv_name
;
1444 struct lsa_LUID luid
;
1446 init_lsa_String(&priv_name
, argv
[i
]);
1448 result
= rpccli_lsa_LookupPrivValue(cli
, mem_ctx
,
1452 if (!NT_STATUS_IS_OK(result
)) {
1457 set
= TALLOC_REALLOC_ARRAY(mem_ctx
, set
,
1458 struct lsa_LUIDAttribute
,
1461 return NT_STATUS_NO_MEMORY
;
1464 set
[privs
.count
-1].luid
= luid
;
1465 set
[privs
.count
-1].attribute
= 0;
1471 result
= rpccli_lsa_RemovePrivilegesFromAccount(cli
, mem_ctx
,
1476 if (!NT_STATUS_IS_OK(result
)) {
1480 rpccli_lsa_Close(cli
, mem_ctx
, &user_pol
);
1481 rpccli_lsa_Close(cli
, mem_ctx
, &dom_pol
);
1486 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1487 TALLOC_CTX
*mem_ctx
, int argc
,
1491 struct policy_handle handle
, sec_handle
;
1492 struct lsa_String name
;
1495 printf("Usage: %s name\n", argv
[0]);
1496 return NT_STATUS_OK
;
1499 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1501 SEC_FLAG_MAXIMUM_ALLOWED
,
1503 if (!NT_STATUS_IS_OK(status
)) {
1507 init_lsa_String(&name
, argv
[1]);
1509 status
= rpccli_lsa_CreateSecret(cli
, mem_ctx
,
1512 SEC_FLAG_MAXIMUM_ALLOWED
,
1514 if (!NT_STATUS_IS_OK(status
)) {
1519 if (is_valid_policy_hnd(&sec_handle
)) {
1520 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1522 if (is_valid_policy_hnd(&handle
)) {
1523 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1529 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1530 TALLOC_CTX
*mem_ctx
, int argc
,
1534 struct policy_handle handle
, sec_handle
;
1535 struct lsa_String name
;
1538 printf("Usage: %s name\n", argv
[0]);
1539 return NT_STATUS_OK
;
1542 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1544 SEC_FLAG_MAXIMUM_ALLOWED
,
1546 if (!NT_STATUS_IS_OK(status
)) {
1550 init_lsa_String(&name
, argv
[1]);
1552 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1555 SEC_FLAG_MAXIMUM_ALLOWED
,
1557 if (!NT_STATUS_IS_OK(status
)) {
1561 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1563 if (!NT_STATUS_IS_OK(status
)) {
1568 if (is_valid_policy_hnd(&sec_handle
)) {
1569 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1571 if (is_valid_policy_hnd(&handle
)) {
1572 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1578 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1579 TALLOC_CTX
*mem_ctx
, int argc
,
1583 struct policy_handle handle
, sec_handle
;
1584 struct lsa_String name
;
1585 struct lsa_DATA_BUF_PTR new_val
;
1586 NTTIME new_mtime
= 0;
1587 struct lsa_DATA_BUF_PTR old_val
;
1588 NTTIME old_mtime
= 0;
1589 DATA_BLOB session_key
;
1590 DATA_BLOB new_blob
= data_blob_null
;
1591 DATA_BLOB old_blob
= data_blob_null
;
1592 char *new_secret
, *old_secret
;
1595 printf("Usage: %s name\n", argv
[0]);
1596 return NT_STATUS_OK
;
1599 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1601 SEC_FLAG_MAXIMUM_ALLOWED
,
1603 if (!NT_STATUS_IS_OK(status
)) {
1607 init_lsa_String(&name
, argv
[1]);
1609 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1612 SEC_FLAG_MAXIMUM_ALLOWED
,
1614 if (!NT_STATUS_IS_OK(status
)) {
1618 ZERO_STRUCT(new_val
);
1619 ZERO_STRUCT(old_val
);
1621 status
= rpccli_lsa_QuerySecret(cli
, mem_ctx
,
1627 if (!NT_STATUS_IS_OK(status
)) {
1631 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1632 if (!NT_STATUS_IS_OK(status
)) {
1637 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1640 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1643 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1644 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1646 d_printf("new secret: %s\n", new_secret
);
1649 d_printf("old secret: %s\n", old_secret
);
1653 if (is_valid_policy_hnd(&sec_handle
)) {
1654 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1656 if (is_valid_policy_hnd(&handle
)) {
1657 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1663 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1664 TALLOC_CTX
*mem_ctx
, int argc
,
1668 struct policy_handle handle
, sec_handle
;
1669 struct lsa_String name
;
1670 struct lsa_DATA_BUF new_val
;
1671 struct lsa_DATA_BUF old_val
;
1673 DATA_BLOB session_key
;
1676 printf("Usage: %s name secret\n", argv
[0]);
1677 return NT_STATUS_OK
;
1680 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1682 SEC_FLAG_MAXIMUM_ALLOWED
,
1684 if (!NT_STATUS_IS_OK(status
)) {
1688 init_lsa_String(&name
, argv
[1]);
1690 status
= rpccli_lsa_OpenSecret(cli
, mem_ctx
,
1693 SEC_FLAG_MAXIMUM_ALLOWED
,
1695 if (!NT_STATUS_IS_OK(status
)) {
1699 ZERO_STRUCT(new_val
);
1700 ZERO_STRUCT(old_val
);
1702 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1703 if (!NT_STATUS_IS_OK(status
)) {
1707 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1709 new_val
.length
= enc_key
.length
;
1710 new_val
.size
= enc_key
.length
;
1711 new_val
.data
= enc_key
.data
;
1713 status
= rpccli_lsa_SetSecret(cli
, mem_ctx
,
1717 if (!NT_STATUS_IS_OK(status
)) {
1722 if (is_valid_policy_hnd(&sec_handle
)) {
1723 rpccli_lsa_Close(cli
, mem_ctx
, &sec_handle
);
1725 if (is_valid_policy_hnd(&handle
)) {
1726 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1732 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1733 TALLOC_CTX
*mem_ctx
, int argc
,
1737 struct policy_handle handle
;
1738 struct lsa_String name
;
1739 struct lsa_DATA_BUF
*val
;
1740 DATA_BLOB session_key
;
1741 DATA_BLOB blob
= data_blob_null
;
1745 printf("Usage: %s name\n", argv
[0]);
1746 return NT_STATUS_OK
;
1749 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1751 SEC_FLAG_MAXIMUM_ALLOWED
,
1753 if (!NT_STATUS_IS_OK(status
)) {
1757 init_lsa_String(&name
, argv
[1]);
1761 status
= rpccli_lsa_RetrievePrivateData(cli
, mem_ctx
,
1765 if (!NT_STATUS_IS_OK(status
)) {
1769 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1770 if (!NT_STATUS_IS_OK(status
)) {
1775 blob
= data_blob_const(val
->data
, val
->length
);
1778 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1780 d_printf("secret: %s\n", secret
);
1784 if (is_valid_policy_hnd(&handle
)) {
1785 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1791 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1792 TALLOC_CTX
*mem_ctx
, int argc
,
1796 struct policy_handle handle
;
1797 struct lsa_String name
;
1798 struct lsa_DATA_BUF val
;
1799 DATA_BLOB session_key
;
1803 printf("Usage: %s name secret\n", argv
[0]);
1804 return NT_STATUS_OK
;
1807 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1809 SEC_FLAG_MAXIMUM_ALLOWED
,
1811 if (!NT_STATUS_IS_OK(status
)) {
1815 init_lsa_String(&name
, argv
[1]);
1819 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1820 if (!NT_STATUS_IS_OK(status
)) {
1824 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1826 val
.length
= enc_key
.length
;
1827 val
.size
= enc_key
.length
;
1828 val
.data
= enc_key
.data
;
1830 status
= rpccli_lsa_StorePrivateData(cli
, mem_ctx
,
1834 if (!NT_STATUS_IS_OK(status
)) {
1839 if (is_valid_policy_hnd(&handle
)) {
1840 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1846 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
1847 TALLOC_CTX
*mem_ctx
, int argc
,
1851 struct policy_handle handle
, trustdom_handle
;
1853 struct lsa_DomainInfo info
;
1856 printf("Usage: %s name sid\n", argv
[0]);
1857 return NT_STATUS_OK
;
1860 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1862 SEC_FLAG_MAXIMUM_ALLOWED
,
1864 if (!NT_STATUS_IS_OK(status
)) {
1868 init_lsa_StringLarge(&info
.name
, argv
[1]);
1870 string_to_sid(&sid
, argv
[2]);
1872 status
= rpccli_lsa_CreateTrustedDomain(cli
, mem_ctx
,
1875 SEC_FLAG_MAXIMUM_ALLOWED
,
1877 if (!NT_STATUS_IS_OK(status
)) {
1882 if (is_valid_policy_hnd(&trustdom_handle
)) {
1883 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1886 if (is_valid_policy_hnd(&handle
)) {
1887 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1893 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
1894 TALLOC_CTX
*mem_ctx
, int argc
,
1898 struct policy_handle handle
, trustdom_handle
;
1899 struct lsa_String name
;
1900 struct dom_sid
*sid
= NULL
;
1903 printf("Usage: %s name\n", argv
[0]);
1904 return NT_STATUS_OK
;
1907 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1909 SEC_FLAG_MAXIMUM_ALLOWED
,
1911 if (!NT_STATUS_IS_OK(status
)) {
1915 init_lsa_String(&name
, argv
[1]);
1917 status
= rpccli_lsa_OpenTrustedDomainByName(cli
, mem_ctx
,
1920 SEC_FLAG_MAXIMUM_ALLOWED
,
1922 if (NT_STATUS_IS_OK(status
)) {
1927 uint32_t resume_handle
= 0;
1928 struct lsa_DomainList domains
;
1931 status
= rpccli_lsa_EnumTrustDom(cli
, mem_ctx
,
1936 if (!NT_STATUS_IS_OK(status
)) {
1940 for (i
=0; i
< domains
.count
; i
++) {
1941 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
1942 sid
= domains
.domains
[i
].sid
;
1948 return NT_STATUS_INVALID_SID
;
1952 status
= rpccli_lsa_OpenTrustedDomain(cli
, mem_ctx
,
1955 SEC_FLAG_MAXIMUM_ALLOWED
,
1957 if (!NT_STATUS_IS_OK(status
)) {
1962 status
= rpccli_lsa_DeleteObject(cli
, mem_ctx
,
1964 if (!NT_STATUS_IS_OK(status
)) {
1969 if (is_valid_policy_hnd(&trustdom_handle
)) {
1970 rpccli_lsa_Close(cli
, mem_ctx
, &trustdom_handle
);
1973 if (is_valid_policy_hnd(&handle
)) {
1974 rpccli_lsa_Close(cli
, mem_ctx
, &handle
);
1981 /* List of commands exported by this module */
1983 struct cmd_set lsarpc_commands
[] = {
1987 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
1988 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1989 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
1990 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1991 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1992 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
1993 { "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)]" },
1994 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
1995 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
1996 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
1997 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
1998 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
1999 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
2000 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
2001 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
2002 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
2003 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
2004 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
2005 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
2006 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2007 { "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", "" },
2008 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2009 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
2010 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
2011 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
2012 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
2013 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
2014 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
2015 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },
2016 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Trusted Domain", "" },
2017 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Trusted Domain", "" },