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/ndr_lsa_c.h"
28 #include "rpc_client/cli_lsarpc.h"
29 #include "rpc_client/init_lsa.h"
30 #include "../libcli/security/security.h"
32 /* useful function to allow entering a name instead of a SID and
33 * looking it up automatically */
34 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
36 struct dom_sid
*sid
, const char *name
)
38 struct policy_handle pol
;
39 enum lsa_SidType
*sid_types
;
40 NTSTATUS status
, result
;
42 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
44 /* maybe its a raw SID */
45 if (strncmp(name
, "S-", 2) == 0 &&
46 string_to_sid(sid
, name
)) {
50 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
51 SEC_FLAG_MAXIMUM_ALLOWED
,
53 if (!NT_STATUS_IS_OK(status
))
56 status
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
57 if (!NT_STATUS_IS_OK(status
))
60 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
68 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
70 d_printf("percent_full:\t%d\n", r
->percent_full
);
71 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
72 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
73 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
74 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
75 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
78 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
81 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
82 d_printf("Auditing categories:\t%d\n", r
->count
);
83 d_printf("Auditsettings:\n");
84 for (i
=0; i
<r
->count
; i
++) {
85 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
86 const char *policy
= audit_description_str(i
);
87 d_printf("%s:\t%s\n", policy
, val
);
91 static void display_query_info_3(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_5(struct lsa_DomainInfo
*r
)
99 d_printf("Domain Name: %s\n", r
->name
.string
);
100 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
103 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
105 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
108 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
110 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
111 d_printf("Log is full: %d\n", r
->log_is_full
);
114 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
116 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
117 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
118 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
119 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
120 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
124 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
125 enum lsa_PolicyInfo level
)
129 display_query_info_1(&info
->audit_log
);
132 display_query_info_2(&info
->audit_events
);
135 display_query_info_3(&info
->domain
);
138 display_query_info_5(&info
->account_domain
);
141 display_query_info_10(&info
->auditfullset
);
144 display_query_info_11(&info
->auditfullquery
);
147 display_query_info_12(&info
->dns
);
150 printf("can't display info level: %d\n", level
);
155 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
156 TALLOC_CTX
*mem_ctx
, int argc
,
159 struct policy_handle pol
;
160 NTSTATUS status
, result
;
161 union lsa_PolicyInformation
*info
= NULL
;
162 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
164 uint32_t info_class
= 3;
167 printf("Usage: %s [info_class]\n", argv
[0]);
172 info_class
= atoi(argv
[1]);
174 switch (info_class
) {
176 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
177 SEC_FLAG_MAXIMUM_ALLOWED
,
180 if (!NT_STATUS_IS_OK(status
))
183 status
= dcerpc_lsa_QueryInfoPolicy2(b
, mem_ctx
,
190 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
191 SEC_FLAG_MAXIMUM_ALLOWED
,
194 if (!NT_STATUS_IS_OK(status
))
197 status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
204 if (!NT_STATUS_IS_OK(status
)) {
208 if (NT_STATUS_IS_OK(result
)) {
209 display_lsa_query_info(info
, info_class
);
212 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
218 /* Resolve a list of names to a list of sids */
220 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
221 TALLOC_CTX
*mem_ctx
, int argc
,
224 struct policy_handle pol
;
225 NTSTATUS status
, result
;
226 struct dom_sid
*sids
;
227 enum lsa_SidType
*types
;
229 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
232 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
236 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
237 SEC_FLAG_MAXIMUM_ALLOWED
,
240 if (!NT_STATUS_IS_OK(status
))
243 status
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
244 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
246 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
247 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
250 status
= NT_STATUS_OK
;
254 for (i
= 0; i
< (argc
- 1); i
++) {
256 sid_to_fstring(sid_str
, &sids
[i
]);
257 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
258 sid_type_lookup(types
[i
]), types
[i
]);
261 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
267 /* Resolve a list of names to a list of sids */
269 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
270 TALLOC_CTX
*mem_ctx
, int argc
,
273 struct policy_handle pol
;
274 NTSTATUS status
, result
;
275 struct dom_sid
*sids
;
276 enum lsa_SidType
*types
;
278 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
281 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv
[0]);
285 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
286 SEC_FLAG_MAXIMUM_ALLOWED
,
289 if (!NT_STATUS_IS_OK(status
))
292 level
= atoi(argv
[1]);
294 status
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 2,
295 (const char**)(argv
+ 2), NULL
, level
, &sids
, &types
);
297 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
298 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
301 status
= NT_STATUS_OK
;
305 for (i
= 0; i
< (argc
- 2); i
++) {
307 sid_to_fstring(sid_str
, &sids
[i
]);
308 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
309 sid_type_lookup(types
[i
]), types
[i
]);
312 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
318 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
319 TALLOC_CTX
*mem_ctx
, int argc
,
322 NTSTATUS status
, result
;
325 struct lsa_String
*names
;
326 struct lsa_RefDomainList
*domains
= NULL
;
327 struct lsa_TransSidArray3 sids
;
330 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
333 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
340 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
341 NT_STATUS_HAVE_NO_MEMORY(names
);
343 for (i
=0; i
< num_names
; i
++) {
344 init_lsa_String(&names
[i
], argv
[i
+1]);
347 status
= dcerpc_lsa_LookupNames4(b
, mem_ctx
,
357 if (!NT_STATUS_IS_OK(status
)) {
360 if (!NT_STATUS_IS_OK(result
)) {
364 if (sids
.count
!= num_names
) {
365 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
368 for (i
= 0; i
< sids
.count
; i
++) {
370 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
371 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
372 sid_type_lookup(sids
.sids
[i
].sid_type
),
373 sids
.sids
[i
].sid_type
);
379 /* Resolve a list of SIDs to a list of names */
381 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
382 int argc
, const char **argv
)
384 struct policy_handle pol
;
385 NTSTATUS status
, result
;
386 struct dom_sid
*sids
;
389 enum lsa_SidType
*types
;
391 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
394 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
398 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
399 SEC_FLAG_MAXIMUM_ALLOWED
,
402 if (!NT_STATUS_IS_OK(status
))
405 /* Convert arguments to sids */
407 sids
= talloc_array(mem_ctx
, struct dom_sid
, argc
- 1);
410 printf("could not allocate memory for %d sids\n", argc
- 1);
414 for (i
= 0; i
< argc
- 1; i
++)
415 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
416 status
= NT_STATUS_INVALID_SID
;
420 /* Lookup the SIDs */
422 status
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
423 &domains
, &names
, &types
);
425 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
426 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
429 status
= NT_STATUS_OK
;
433 for (i
= 0; i
< (argc
- 1); i
++) {
436 sid_to_fstring(sid_str
, &sids
[i
]);
437 if (types
[i
] == SID_NAME_DOMAIN
) {
438 printf("%s %s (%d)\n", sid_str
,
439 domains
[i
] ? domains
[i
] : "*unknown*",
442 printf("%s %s\\%s (%d)\n", sid_str
,
443 domains
[i
] ? domains
[i
] : "*unknown*",
444 names
[i
] ? names
[i
] : "*unknown*",
449 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
455 /* Resolve a list of SIDs to a list of names */
457 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
459 int argc
, const char **argv
)
461 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
, result
;
463 struct lsa_SidArray sids
;
464 struct lsa_RefDomainList
*domains
= NULL
;
465 struct lsa_TransNameArray2 names
;
467 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
470 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
476 /* Convert arguments to sids */
478 sids
.num_sids
= argc
-1;
479 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
481 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
485 for (i
= 0; i
< sids
.num_sids
; i
++) {
486 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
487 if (sids
.sids
[i
].sid
== NULL
) {
488 status
= NT_STATUS_NO_MEMORY
;
491 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
492 status
= NT_STATUS_INVALID_SID
;
497 /* Lookup the SIDs */
498 status
= dcerpc_lsa_LookupSids3(b
, mem_ctx
,
507 if (!NT_STATUS_IS_OK(status
)) {
510 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
511 NT_STATUS_V(STATUS_SOME_UNMAPPED
)) {
516 status
= NT_STATUS_OK
;
520 for (i
= 0; i
< names
.count
; i
++) {
523 if (i
>= sids
.num_sids
) {
526 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
527 printf("%s %s (%d)\n", sid_str
,
528 names
.names
[i
].name
.string
,
529 names
.names
[i
].sid_type
);
537 /* Enumerate list of trusted domains */
539 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
540 TALLOC_CTX
*mem_ctx
, int argc
,
543 struct policy_handle pol
;
544 NTSTATUS status
, result
;
545 struct lsa_DomainList domain_list
;
546 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
548 /* defaults, but may be changed using params */
549 uint32_t enum_ctx
= 0;
551 uint32_t max_size
= (uint32_t)-1;
554 printf("Usage: %s [enum context (0)]\n", argv
[0]);
558 if (argc
== 2 && argv
[1]) {
559 enum_ctx
= atoi(argv
[2]);
562 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
563 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
566 if (!NT_STATUS_IS_OK(status
))
569 status
= STATUS_MORE_ENTRIES
;
571 while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
573 /* Lookup list of trusted domains */
575 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
581 if (!NT_STATUS_IS_OK(status
)) {
584 if (!NT_STATUS_IS_OK(result
) &&
585 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
586 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
591 /* Print results: list of names and sids returned in this
593 for (i
= 0; i
< domain_list
.count
; i
++) {
596 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
598 domain_list
.domains
[i
].name
.string
?
599 domain_list
.domains
[i
].name
.string
: "*unknown*",
604 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
609 /* Enumerates privileges */
611 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
612 TALLOC_CTX
*mem_ctx
, int argc
,
615 struct policy_handle pol
;
616 NTSTATUS status
, result
;
617 struct lsa_PrivArray priv_array
;
618 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
620 uint32_t enum_context
=0;
621 uint32_t pref_max_length
=0x1000;
625 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
630 enum_context
=atoi(argv
[1]);
633 pref_max_length
=atoi(argv
[2]);
635 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
636 SEC_FLAG_MAXIMUM_ALLOWED
,
639 if (!NT_STATUS_IS_OK(status
))
642 status
= dcerpc_lsa_EnumPrivs(b
, mem_ctx
,
648 if (!NT_STATUS_IS_OK(status
))
650 if (!NT_STATUS_IS_OK(result
)) {
656 printf("found %d privileges\n\n", priv_array
.count
);
658 for (i
= 0; i
< priv_array
.count
; i
++) {
659 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
660 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
661 priv_array
.privs
[i
].luid
.high
,
662 priv_array
.privs
[i
].luid
.low
,
663 priv_array
.privs
[i
].luid
.high
,
664 priv_array
.privs
[i
].luid
.low
);
667 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
672 /* Get privilege name */
674 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
675 TALLOC_CTX
*mem_ctx
, int argc
,
678 struct policy_handle pol
;
679 NTSTATUS status
, result
;
680 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
683 uint16_t lang_id_sys
=0;
684 uint16_t lang_id_desc
;
685 struct lsa_String lsa_name
;
686 struct lsa_StringLarge
*description
= NULL
;
689 printf("Usage: %s privilege name\n", argv
[0]);
693 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
694 SEC_FLAG_MAXIMUM_ALLOWED
,
697 if (!NT_STATUS_IS_OK(status
))
700 init_lsa_String(&lsa_name
, argv
[1]);
702 status
= dcerpc_lsa_LookupPrivDisplayName(b
, mem_ctx
,
710 if (!NT_STATUS_IS_OK(status
))
712 if (!NT_STATUS_IS_OK(result
)) {
718 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
720 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
725 /* Enumerate the LSA SIDS */
727 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
728 TALLOC_CTX
*mem_ctx
, int argc
,
731 struct policy_handle pol
;
732 NTSTATUS status
, result
;
733 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
735 uint32_t enum_context
=0;
736 uint32_t pref_max_length
=0x1000;
737 struct lsa_SidArray sid_array
;
741 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
746 enum_context
=atoi(argv
[1]);
749 pref_max_length
=atoi(argv
[2]);
751 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
752 SEC_FLAG_MAXIMUM_ALLOWED
,
755 if (!NT_STATUS_IS_OK(status
))
758 status
= dcerpc_lsa_EnumAccounts(b
, mem_ctx
,
764 if (!NT_STATUS_IS_OK(status
))
766 if (!NT_STATUS_IS_OK(result
)) {
772 printf("found %d SIDs\n\n", sid_array
.num_sids
);
774 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
777 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
778 printf("%s\n", sid_str
);
781 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
786 /* Create a new account */
788 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
789 TALLOC_CTX
*mem_ctx
, int argc
,
792 struct policy_handle dom_pol
;
793 struct policy_handle user_pol
;
794 NTSTATUS status
, result
;
795 uint32_t des_access
= 0x000f000f;
796 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
801 printf("Usage: %s SID\n", argv
[0]);
805 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
806 if (!NT_STATUS_IS_OK(status
))
809 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
810 SEC_FLAG_MAXIMUM_ALLOWED
,
813 if (!NT_STATUS_IS_OK(status
))
816 status
= dcerpc_lsa_CreateAccount(b
, mem_ctx
,
822 if (!NT_STATUS_IS_OK(status
))
824 if (!NT_STATUS_IS_OK(result
)) {
829 printf("Account for SID %s successfully created\n\n", argv
[1]);
830 status
= NT_STATUS_OK
;
832 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
838 /* Enumerate the privileges of an SID */
840 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
841 TALLOC_CTX
*mem_ctx
, int argc
,
844 struct policy_handle dom_pol
;
845 struct policy_handle user_pol
;
846 NTSTATUS status
, result
;
847 uint32_t access_desired
= 0x000f000f;
849 struct lsa_PrivilegeSet
*privs
= NULL
;
851 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
854 printf("Usage: %s SID\n", argv
[0]);
858 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
859 if (!NT_STATUS_IS_OK(status
))
862 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
863 SEC_FLAG_MAXIMUM_ALLOWED
,
866 if (!NT_STATUS_IS_OK(status
))
869 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
875 if (!NT_STATUS_IS_OK(status
))
877 if (!NT_STATUS_IS_OK(result
)) {
882 status
= dcerpc_lsa_EnumPrivsAccount(b
, mem_ctx
,
886 if (!NT_STATUS_IS_OK(status
))
888 if (!NT_STATUS_IS_OK(result
)) {
894 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
895 printf("high\tlow\tattribute\n");
897 for (i
= 0; i
< privs
->count
; i
++) {
898 printf("%u\t%u\t%u\n",
899 privs
->set
[i
].luid
.high
,
900 privs
->set
[i
].luid
.low
,
901 privs
->set
[i
].attribute
);
904 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
910 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
912 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
913 TALLOC_CTX
*mem_ctx
, int argc
,
916 struct policy_handle dom_pol
;
917 NTSTATUS status
, result
;
919 struct lsa_RightSet rights
;
920 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
925 printf("Usage: %s SID\n", argv
[0]);
929 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
930 if (!NT_STATUS_IS_OK(status
))
933 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
934 SEC_FLAG_MAXIMUM_ALLOWED
,
937 if (!NT_STATUS_IS_OK(status
))
940 status
= dcerpc_lsa_EnumAccountRights(b
, mem_ctx
,
945 if (!NT_STATUS_IS_OK(status
))
947 if (!NT_STATUS_IS_OK(result
)) {
952 printf("found %d privileges for SID %s\n", rights
.count
,
953 sid_string_tos(&sid
));
955 for (i
= 0; i
< rights
.count
; i
++) {
956 printf("\t%s\n", rights
.names
[i
].string
);
959 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
965 /* add some privileges to a SID via LsaAddAccountRights */
967 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
968 TALLOC_CTX
*mem_ctx
, int argc
,
971 struct policy_handle dom_pol
;
972 NTSTATUS status
, result
;
973 struct lsa_RightSet rights
;
976 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
979 printf("Usage: %s SID [rights...]\n", argv
[0]);
983 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
984 if (!NT_STATUS_IS_OK(status
))
987 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
988 SEC_FLAG_MAXIMUM_ALLOWED
,
991 if (!NT_STATUS_IS_OK(status
))
994 rights
.count
= argc
-2;
995 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
998 return NT_STATUS_NO_MEMORY
;
1001 for (i
=0; i
<argc
-2; i
++) {
1002 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
1005 status
= dcerpc_lsa_AddAccountRights(b
, mem_ctx
,
1010 if (!NT_STATUS_IS_OK(status
))
1012 if (!NT_STATUS_IS_OK(result
)) {
1017 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1023 /* remove some privileges to a SID via LsaRemoveAccountRights */
1025 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
1026 TALLOC_CTX
*mem_ctx
, int argc
,
1029 struct policy_handle dom_pol
;
1030 NTSTATUS status
, result
;
1031 struct lsa_RightSet rights
;
1034 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1037 printf("Usage: %s SID [rights...]\n", argv
[0]);
1038 return NT_STATUS_OK
;
1041 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1042 if (!NT_STATUS_IS_OK(status
))
1045 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1046 SEC_FLAG_MAXIMUM_ALLOWED
,
1049 if (!NT_STATUS_IS_OK(status
))
1052 rights
.count
= argc
-2;
1053 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
1055 if (!rights
.names
) {
1056 return NT_STATUS_NO_MEMORY
;
1059 for (i
=0; i
<argc
-2; i
++) {
1060 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
1063 status
= dcerpc_lsa_RemoveAccountRights(b
, mem_ctx
,
1069 if (!NT_STATUS_IS_OK(status
))
1071 if (!NT_STATUS_IS_OK(result
)) {
1076 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1083 /* Get a privilege value given its name */
1085 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
1086 TALLOC_CTX
*mem_ctx
, int argc
,
1089 struct policy_handle pol
;
1090 NTSTATUS status
, result
;
1091 struct lsa_LUID luid
;
1092 struct lsa_String name
;
1093 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1096 printf("Usage: %s name\n", argv
[0]);
1097 return NT_STATUS_OK
;
1100 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1101 SEC_FLAG_MAXIMUM_ALLOWED
,
1104 if (!NT_STATUS_IS_OK(status
))
1107 init_lsa_String(&name
, argv
[1]);
1109 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1114 if (!NT_STATUS_IS_OK(status
))
1116 if (!NT_STATUS_IS_OK(result
)) {
1123 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1125 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1130 /* Query LSA security object */
1132 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1133 TALLOC_CTX
*mem_ctx
, int argc
,
1136 struct policy_handle pol
;
1137 NTSTATUS status
, result
;
1138 struct sec_desc_buf
*sdb
;
1139 uint32_t sec_info
= SECINFO_DACL
;
1140 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1142 if (argc
< 1 || argc
> 2) {
1143 printf("Usage: %s [sec_info]\n", argv
[0]);
1144 return NT_STATUS_OK
;
1147 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1148 SEC_FLAG_MAXIMUM_ALLOWED
,
1152 sscanf(argv
[1], "%x", &sec_info
);
1154 if (!NT_STATUS_IS_OK(status
))
1157 status
= dcerpc_lsa_QuerySecurity(b
, mem_ctx
,
1162 if (!NT_STATUS_IS_OK(status
))
1164 if (!NT_STATUS_IS_OK(result
)) {
1171 display_sec_desc(sdb
->sd
);
1173 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1178 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1179 DATA_BLOB session_key
)
1181 char *pwd
, *pwd_old
;
1183 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1184 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1186 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key
);
1187 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key
);
1189 d_printf("Password:\t%s\n", pwd
);
1190 d_printf("Old Password:\t%s\n", pwd_old
);
1193 talloc_free(pwd_old
);
1196 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1197 union lsa_TrustedDomainInfo
*info
,
1198 enum lsa_TrustDomInfoEnum info_class
,
1199 DATA_BLOB session_key
)
1201 switch (info_class
) {
1202 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1203 display_trust_dom_info_4(&info
->password
, session_key
);
1206 const char *str
= NULL
;
1207 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1208 lsa_TrustedDomainInfo
,
1211 d_printf("%s\n", str
);
1218 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1219 TALLOC_CTX
*mem_ctx
, int argc
,
1222 struct policy_handle pol
;
1223 NTSTATUS status
, result
;
1224 struct dom_sid dom_sid
;
1225 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1226 union lsa_TrustedDomainInfo
*info
= NULL
;
1227 enum lsa_TrustDomInfoEnum info_class
= 1;
1228 DATA_BLOB session_key
;
1229 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1231 if (argc
> 3 || argc
< 2) {
1232 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1233 return NT_STATUS_OK
;
1236 if (!string_to_sid(&dom_sid
, argv
[1]))
1237 return NT_STATUS_NO_MEMORY
;
1240 info_class
= atoi(argv
[2]);
1242 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1244 if (!NT_STATUS_IS_OK(status
))
1247 status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
1253 if (!NT_STATUS_IS_OK(status
))
1255 if (!NT_STATUS_IS_OK(result
)) {
1260 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1261 if (!NT_STATUS_IS_OK(status
)) {
1262 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1266 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1269 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1274 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1275 TALLOC_CTX
*mem_ctx
, int argc
,
1278 struct policy_handle pol
;
1279 NTSTATUS status
, result
;
1280 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1281 union lsa_TrustedDomainInfo
*info
= NULL
;
1282 enum lsa_TrustDomInfoEnum info_class
= 1;
1283 struct lsa_String trusted_domain
;
1284 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1285 DATA_BLOB session_key
;
1287 if (argc
> 3 || argc
< 2) {
1288 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1289 return NT_STATUS_OK
;
1293 info_class
= atoi(argv
[2]);
1295 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1297 if (!NT_STATUS_IS_OK(status
))
1300 init_lsa_String(&trusted_domain
, argv
[1]);
1302 status
= dcerpc_lsa_QueryTrustedDomainInfoByName(b
, mem_ctx
,
1308 if (!NT_STATUS_IS_OK(status
))
1310 if (!NT_STATUS_IS_OK(result
)) {
1315 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1316 if (!NT_STATUS_IS_OK(status
)) {
1317 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1321 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1324 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1329 static NTSTATUS
cmd_lsa_set_trustdominfo(struct rpc_pipe_client
*cli
,
1330 TALLOC_CTX
*mem_ctx
, int argc
,
1333 struct policy_handle pol
, trustdom_pol
;
1334 NTSTATUS status
, result
;
1335 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1336 union lsa_TrustedDomainInfo info
;
1337 struct dom_sid dom_sid
;
1338 enum lsa_TrustDomInfoEnum info_class
= 1;
1339 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1341 if (argc
> 4 || argc
< 3) {
1342 printf("Usage: %s [sid] [info_class] [value]\n", argv
[0]);
1343 return NT_STATUS_OK
;
1346 if (!string_to_sid(&dom_sid
, argv
[1])) {
1347 return NT_STATUS_NO_MEMORY
;
1351 info_class
= atoi(argv
[2]);
1353 switch (info_class
) {
1354 case 13: /* LSA_TRUSTED_DOMAIN_SUPPORTED_ENCRYPTION_TYPES */
1355 info
.enc_types
.enc_types
= atoi(argv
[3]);
1358 return NT_STATUS_INVALID_PARAMETER
;
1361 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1362 if (!NT_STATUS_IS_OK(status
)) {
1366 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
1372 if (!NT_STATUS_IS_OK(status
)) {
1375 if (!NT_STATUS_IS_OK(result
)) {
1380 status
= dcerpc_lsa_SetInformationTrustedDomain(b
, mem_ctx
,
1385 if (!NT_STATUS_IS_OK(status
)) {
1388 if (!NT_STATUS_IS_OK(result
)) {
1393 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_pol
, &result
);
1394 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1399 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1400 TALLOC_CTX
*mem_ctx
, int argc
,
1403 struct policy_handle pol
, trustdom_pol
;
1404 NTSTATUS status
, result
;
1405 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1406 union lsa_TrustedDomainInfo
*info
= NULL
;
1407 struct dom_sid dom_sid
;
1408 enum lsa_TrustDomInfoEnum info_class
= 1;
1409 DATA_BLOB session_key
;
1410 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1412 if (argc
> 3 || argc
< 2) {
1413 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1414 return NT_STATUS_OK
;
1417 if (!string_to_sid(&dom_sid
, argv
[1]))
1418 return NT_STATUS_NO_MEMORY
;
1422 info_class
= atoi(argv
[2]);
1424 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1426 if (!NT_STATUS_IS_OK(status
))
1429 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
1435 if (!NT_STATUS_IS_OK(status
))
1437 if (!NT_STATUS_IS_OK(result
)) {
1442 status
= dcerpc_lsa_QueryTrustedDomainInfo(b
, mem_ctx
,
1447 if (!NT_STATUS_IS_OK(status
))
1449 if (!NT_STATUS_IS_OK(result
)) {
1454 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1455 if (!NT_STATUS_IS_OK(status
)) {
1456 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1460 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1463 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1468 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1469 TALLOC_CTX
*mem_ctx
, int argc
,
1472 NTSTATUS status
, result
;
1473 const char *servername
= cli
->desthost
;
1474 struct lsa_String
*account_name
= NULL
;
1475 struct lsa_String
*authority_name
= NULL
;
1476 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1479 printf("Usage: %s servername\n", argv
[0]);
1480 return NT_STATUS_OK
;
1483 status
= dcerpc_lsa_GetUserName(b
, mem_ctx
,
1488 if (!NT_STATUS_IS_OK(status
)) {
1491 if (!NT_STATUS_IS_OK(result
)) {
1498 printf("Account Name: %s, Authority Name: %s\n",
1499 account_name
->string
, authority_name
? authority_name
->string
:
1506 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1507 TALLOC_CTX
*mem_ctx
, int argc
,
1510 struct policy_handle dom_pol
, user_pol
;
1511 NTSTATUS status
, result
;
1512 struct lsa_PrivilegeSet privs
;
1513 struct lsa_LUIDAttribute
*set
= NULL
;
1516 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1521 printf("Usage: %s SID [rights...]\n", argv
[0]);
1522 return NT_STATUS_OK
;
1525 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1526 if (!NT_STATUS_IS_OK(status
)) {
1530 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1531 SEC_FLAG_MAXIMUM_ALLOWED
,
1534 if (!NT_STATUS_IS_OK(status
)) {
1538 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1541 SEC_FLAG_MAXIMUM_ALLOWED
,
1544 if (!NT_STATUS_IS_OK(status
)) {
1547 if (!NT_STATUS_IS_OK(result
)) {
1552 for (i
=2; i
<argc
; i
++) {
1554 struct lsa_String priv_name
;
1555 struct lsa_LUID luid
;
1557 init_lsa_String(&priv_name
, argv
[i
]);
1559 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1564 if (!NT_STATUS_IS_OK(status
)) {
1567 if (!NT_STATUS_IS_OK(result
)) {
1573 set
= talloc_realloc(mem_ctx
, set
,
1574 struct lsa_LUIDAttribute
,
1577 return NT_STATUS_NO_MEMORY
;
1580 set
[privs
.count
-1].luid
= luid
;
1581 set
[privs
.count
-1].attribute
= 0;
1586 status
= dcerpc_lsa_AddPrivilegesToAccount(b
, mem_ctx
,
1590 if (!NT_STATUS_IS_OK(status
)) {
1593 if (!NT_STATUS_IS_OK(result
)) {
1598 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1599 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1604 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1605 TALLOC_CTX
*mem_ctx
, int argc
,
1608 struct policy_handle dom_pol
, user_pol
;
1609 NTSTATUS status
, result
;
1610 struct lsa_PrivilegeSet privs
;
1611 struct lsa_LUIDAttribute
*set
= NULL
;
1614 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1619 printf("Usage: %s SID [rights...]\n", argv
[0]);
1620 return NT_STATUS_OK
;
1623 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1624 if (!NT_STATUS_IS_OK(status
)) {
1628 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1629 SEC_FLAG_MAXIMUM_ALLOWED
,
1632 if (!NT_STATUS_IS_OK(status
)) {
1636 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1639 SEC_FLAG_MAXIMUM_ALLOWED
,
1642 if (!NT_STATUS_IS_OK(status
)) {
1645 if (!NT_STATUS_IS_OK(result
)) {
1650 for (i
=2; i
<argc
; i
++) {
1652 struct lsa_String priv_name
;
1653 struct lsa_LUID luid
;
1655 init_lsa_String(&priv_name
, argv
[i
]);
1657 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1662 if (!NT_STATUS_IS_OK(status
)) {
1665 if (!NT_STATUS_IS_OK(result
)) {
1671 set
= talloc_realloc(mem_ctx
, set
,
1672 struct lsa_LUIDAttribute
,
1675 return NT_STATUS_NO_MEMORY
;
1678 set
[privs
.count
-1].luid
= luid
;
1679 set
[privs
.count
-1].attribute
= 0;
1685 status
= dcerpc_lsa_RemovePrivilegesFromAccount(b
, mem_ctx
,
1690 if (!NT_STATUS_IS_OK(status
)) {
1693 if (!NT_STATUS_IS_OK(result
)) {
1698 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1699 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1704 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1705 TALLOC_CTX
*mem_ctx
, int argc
,
1708 NTSTATUS status
, result
;
1709 struct policy_handle handle
, sec_handle
;
1710 struct lsa_String name
;
1711 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1714 printf("Usage: %s name\n", argv
[0]);
1715 return NT_STATUS_OK
;
1718 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1720 SEC_FLAG_MAXIMUM_ALLOWED
,
1722 if (!NT_STATUS_IS_OK(status
)) {
1726 init_lsa_String(&name
, argv
[1]);
1728 status
= dcerpc_lsa_CreateSecret(b
, mem_ctx
,
1731 SEC_FLAG_MAXIMUM_ALLOWED
,
1734 if (!NT_STATUS_IS_OK(status
)) {
1737 if (!NT_STATUS_IS_OK(result
)) {
1743 if (is_valid_policy_hnd(&sec_handle
)) {
1744 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1746 if (is_valid_policy_hnd(&handle
)) {
1747 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1753 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1754 TALLOC_CTX
*mem_ctx
, int argc
,
1757 NTSTATUS status
, result
;
1758 struct policy_handle handle
, sec_handle
;
1759 struct lsa_String name
;
1760 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1763 printf("Usage: %s name\n", argv
[0]);
1764 return NT_STATUS_OK
;
1767 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1769 SEC_FLAG_MAXIMUM_ALLOWED
,
1771 if (!NT_STATUS_IS_OK(status
)) {
1775 init_lsa_String(&name
, argv
[1]);
1777 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1780 SEC_FLAG_MAXIMUM_ALLOWED
,
1783 if (!NT_STATUS_IS_OK(status
)) {
1786 if (!NT_STATUS_IS_OK(result
)) {
1791 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
1794 if (!NT_STATUS_IS_OK(status
)) {
1797 if (!NT_STATUS_IS_OK(result
)) {
1803 if (is_valid_policy_hnd(&sec_handle
)) {
1804 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1806 if (is_valid_policy_hnd(&handle
)) {
1807 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1813 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1814 TALLOC_CTX
*mem_ctx
, int argc
,
1817 NTSTATUS status
, result
;
1818 struct policy_handle handle
, sec_handle
;
1819 struct lsa_String name
;
1820 struct lsa_DATA_BUF_PTR new_val
;
1821 NTTIME new_mtime
= 0;
1822 struct lsa_DATA_BUF_PTR old_val
;
1823 NTTIME old_mtime
= 0;
1824 DATA_BLOB session_key
;
1825 DATA_BLOB new_blob
= data_blob_null
;
1826 DATA_BLOB old_blob
= data_blob_null
;
1827 char *new_secret
, *old_secret
;
1828 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1831 printf("Usage: %s name\n", argv
[0]);
1832 return NT_STATUS_OK
;
1835 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1837 SEC_FLAG_MAXIMUM_ALLOWED
,
1839 if (!NT_STATUS_IS_OK(status
)) {
1843 init_lsa_String(&name
, argv
[1]);
1845 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1848 SEC_FLAG_MAXIMUM_ALLOWED
,
1851 if (!NT_STATUS_IS_OK(status
)) {
1854 if (!NT_STATUS_IS_OK(result
)) {
1859 ZERO_STRUCT(new_val
);
1860 ZERO_STRUCT(old_val
);
1862 status
= dcerpc_lsa_QuerySecret(b
, mem_ctx
,
1869 if (!NT_STATUS_IS_OK(status
)) {
1872 if (!NT_STATUS_IS_OK(result
)) {
1877 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1878 if (!NT_STATUS_IS_OK(status
)) {
1883 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1886 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1889 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1890 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1892 d_printf("new secret: %s\n", new_secret
);
1895 d_printf("old secret: %s\n", old_secret
);
1899 if (is_valid_policy_hnd(&sec_handle
)) {
1900 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1902 if (is_valid_policy_hnd(&handle
)) {
1903 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1909 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1910 TALLOC_CTX
*mem_ctx
, int argc
,
1913 NTSTATUS status
, result
;
1914 struct policy_handle handle
, sec_handle
;
1915 struct lsa_String name
;
1916 struct lsa_DATA_BUF new_val
;
1917 struct lsa_DATA_BUF old_val
;
1919 DATA_BLOB session_key
;
1920 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1923 printf("Usage: %s name secret\n", argv
[0]);
1924 return NT_STATUS_OK
;
1927 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1929 SEC_FLAG_MAXIMUM_ALLOWED
,
1931 if (!NT_STATUS_IS_OK(status
)) {
1935 init_lsa_String(&name
, argv
[1]);
1937 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1940 SEC_FLAG_MAXIMUM_ALLOWED
,
1943 if (!NT_STATUS_IS_OK(status
)) {
1946 if (!NT_STATUS_IS_OK(result
)) {
1951 ZERO_STRUCT(new_val
);
1952 ZERO_STRUCT(old_val
);
1954 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1955 if (!NT_STATUS_IS_OK(status
)) {
1959 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1961 new_val
.length
= enc_key
.length
;
1962 new_val
.size
= enc_key
.length
;
1963 new_val
.data
= enc_key
.data
;
1965 status
= dcerpc_lsa_SetSecret(b
, mem_ctx
,
1970 if (!NT_STATUS_IS_OK(status
)) {
1973 if (!NT_STATUS_IS_OK(result
)) {
1979 if (is_valid_policy_hnd(&sec_handle
)) {
1980 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1982 if (is_valid_policy_hnd(&handle
)) {
1983 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1989 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1990 TALLOC_CTX
*mem_ctx
, int argc
,
1993 NTSTATUS status
, result
;
1994 struct policy_handle handle
;
1995 struct lsa_String name
;
1996 struct lsa_DATA_BUF
*val
;
1997 DATA_BLOB session_key
;
1998 DATA_BLOB blob
= data_blob_null
;
2000 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2003 printf("Usage: %s name\n", argv
[0]);
2004 return NT_STATUS_OK
;
2007 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2009 SEC_FLAG_MAXIMUM_ALLOWED
,
2011 if (!NT_STATUS_IS_OK(status
)) {
2015 init_lsa_String(&name
, argv
[1]);
2019 status
= dcerpc_lsa_RetrievePrivateData(b
, mem_ctx
,
2024 if (!NT_STATUS_IS_OK(status
)) {
2027 if (!NT_STATUS_IS_OK(result
)) {
2032 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2033 if (!NT_STATUS_IS_OK(status
)) {
2038 blob
= data_blob_const(val
->data
, val
->length
);
2041 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
2043 d_printf("secret: %s\n", secret
);
2047 if (is_valid_policy_hnd(&handle
)) {
2048 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2054 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
2055 TALLOC_CTX
*mem_ctx
, int argc
,
2058 NTSTATUS status
, result
;
2059 struct policy_handle handle
;
2060 struct lsa_String name
;
2061 struct lsa_DATA_BUF val
;
2062 DATA_BLOB session_key
;
2064 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2067 printf("Usage: %s name secret\n", argv
[0]);
2068 return NT_STATUS_OK
;
2071 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2073 SEC_FLAG_MAXIMUM_ALLOWED
,
2075 if (!NT_STATUS_IS_OK(status
)) {
2079 init_lsa_String(&name
, argv
[1]);
2083 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2084 if (!NT_STATUS_IS_OK(status
)) {
2088 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
2090 val
.length
= enc_key
.length
;
2091 val
.size
= enc_key
.length
;
2092 val
.data
= enc_key
.data
;
2094 status
= dcerpc_lsa_StorePrivateData(b
, mem_ctx
,
2099 if (!NT_STATUS_IS_OK(status
)) {
2102 if (!NT_STATUS_IS_OK(result
)) {
2108 if (is_valid_policy_hnd(&handle
)) {
2109 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2115 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
2116 TALLOC_CTX
*mem_ctx
, int argc
,
2119 NTSTATUS status
, result
;
2120 struct policy_handle handle
, trustdom_handle
;
2122 struct lsa_DomainInfo info
;
2123 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2126 printf("Usage: %s name sid\n", argv
[0]);
2127 return NT_STATUS_OK
;
2130 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2132 SEC_FLAG_MAXIMUM_ALLOWED
,
2134 if (!NT_STATUS_IS_OK(status
)) {
2138 init_lsa_StringLarge(&info
.name
, argv
[1]);
2140 string_to_sid(&sid
, argv
[2]);
2142 status
= dcerpc_lsa_CreateTrustedDomain(b
, mem_ctx
,
2145 SEC_FLAG_MAXIMUM_ALLOWED
,
2148 if (!NT_STATUS_IS_OK(status
)) {
2151 if (!NT_STATUS_IS_OK(result
)) {
2157 if (is_valid_policy_hnd(&trustdom_handle
)) {
2158 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2161 if (is_valid_policy_hnd(&handle
)) {
2162 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2168 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
2169 TALLOC_CTX
*mem_ctx
, int argc
,
2172 NTSTATUS status
, result
;
2173 struct policy_handle handle
, trustdom_handle
;
2174 struct lsa_String name
;
2175 struct dom_sid
*sid
= NULL
;
2176 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2179 printf("Usage: %s name\n", argv
[0]);
2180 return NT_STATUS_OK
;
2183 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2185 SEC_FLAG_MAXIMUM_ALLOWED
,
2187 if (!NT_STATUS_IS_OK(status
)) {
2191 init_lsa_String(&name
, argv
[1]);
2193 status
= dcerpc_lsa_OpenTrustedDomainByName(b
, mem_ctx
,
2196 SEC_FLAG_MAXIMUM_ALLOWED
,
2199 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
)) {
2204 uint32_t resume_handle
= 0;
2205 struct lsa_DomainList domains
;
2208 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
2214 if (!NT_STATUS_IS_OK(status
)) {
2217 if (!NT_STATUS_IS_OK(result
)) {
2222 for (i
=0; i
< domains
.count
; i
++) {
2223 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
2224 sid
= domains
.domains
[i
].sid
;
2230 return NT_STATUS_INVALID_SID
;
2234 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
2237 SEC_FLAG_MAXIMUM_ALLOWED
,
2240 if (!NT_STATUS_IS_OK(status
)) {
2243 if (!NT_STATUS_IS_OK(result
)) {
2249 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
2252 if (!NT_STATUS_IS_OK(status
)) {
2255 if (!NT_STATUS_IS_OK(result
)) {
2261 if (is_valid_policy_hnd(&trustdom_handle
)) {
2262 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2265 if (is_valid_policy_hnd(&handle
)) {
2266 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2273 /* List of commands exported by this module */
2275 struct cmd_set lsarpc_commands
[] = {
2279 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
, NULL
, "Query info policy", "" },
2280 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2281 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2282 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2283 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2284 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2285 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
2286 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate privileges", "" },
2287 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
, NULL
, "Get the privilege name", "" },
2288 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the LSA SIDS", "" },
2289 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
, NULL
, "Create a new lsa account", "" },
2290 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the privileges of an SID", "" },
2291 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the rights of an SID", "" },
2292 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Assign a privilege to a SID", "" },
2293 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Revoke a privilege from a SID", "" },
2294 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Add rights to an account", "" },
2295 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Remove rights from an account", "" },
2296 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
, NULL
, "Get a privilege value given its name", "" },
2297 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA security object", "" },
2298 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2299 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobyname
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
2300 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2301 { "lsasettrustdominfo", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Set LSA trusted domain info", "" },
2302 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
, NULL
, "Get username", "" },
2303 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Secret", "" },
2304 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Secret", "" },
2305 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Query Secret", "" },
2306 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Set Secret", "" },
2307 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Retrieve Private Data", "" },
2308 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Store Private Data", "" },
2309 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Trusted Domain", "" },
2310 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Trusted Domain", "" },