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 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 */
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 enum_context
=0;
621 uint32 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 lang_id_sys
=0;
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 enum_context
=0;
736 uint32 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 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 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 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 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 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 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 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 struct policy_handle pol
;
1473 NTSTATUS status
, result
;
1474 const char *servername
= cli
->desthost
;
1475 struct lsa_String
*account_name
= NULL
;
1476 struct lsa_String
*authority_name
= NULL
;
1477 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1480 printf("Usage: %s servername\n", argv
[0]);
1481 return NT_STATUS_OK
;
1484 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1485 SEC_FLAG_MAXIMUM_ALLOWED
,
1488 if (!NT_STATUS_IS_OK(status
)) {
1492 status
= dcerpc_lsa_GetUserName(b
, mem_ctx
,
1497 if (!NT_STATUS_IS_OK(status
)) {
1500 if (!NT_STATUS_IS_OK(result
)) {
1507 printf("Account Name: %s, Authority Name: %s\n",
1508 account_name
->string
, authority_name
? authority_name
->string
:
1511 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1516 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1517 TALLOC_CTX
*mem_ctx
, int argc
,
1520 struct policy_handle dom_pol
, user_pol
;
1521 NTSTATUS status
, result
;
1522 struct lsa_PrivilegeSet privs
;
1523 struct lsa_LUIDAttribute
*set
= NULL
;
1526 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1531 printf("Usage: %s SID [rights...]\n", argv
[0]);
1532 return NT_STATUS_OK
;
1535 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1536 if (!NT_STATUS_IS_OK(status
)) {
1540 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1541 SEC_FLAG_MAXIMUM_ALLOWED
,
1544 if (!NT_STATUS_IS_OK(status
)) {
1548 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1551 SEC_FLAG_MAXIMUM_ALLOWED
,
1554 if (!NT_STATUS_IS_OK(status
)) {
1557 if (!NT_STATUS_IS_OK(result
)) {
1562 for (i
=2; i
<argc
; i
++) {
1564 struct lsa_String priv_name
;
1565 struct lsa_LUID luid
;
1567 init_lsa_String(&priv_name
, argv
[i
]);
1569 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1574 if (!NT_STATUS_IS_OK(status
)) {
1577 if (!NT_STATUS_IS_OK(result
)) {
1583 set
= talloc_realloc(mem_ctx
, set
,
1584 struct lsa_LUIDAttribute
,
1587 return NT_STATUS_NO_MEMORY
;
1590 set
[privs
.count
-1].luid
= luid
;
1591 set
[privs
.count
-1].attribute
= 0;
1596 status
= dcerpc_lsa_AddPrivilegesToAccount(b
, mem_ctx
,
1600 if (!NT_STATUS_IS_OK(status
)) {
1603 if (!NT_STATUS_IS_OK(result
)) {
1608 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1609 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1614 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1615 TALLOC_CTX
*mem_ctx
, int argc
,
1618 struct policy_handle dom_pol
, user_pol
;
1619 NTSTATUS status
, result
;
1620 struct lsa_PrivilegeSet privs
;
1621 struct lsa_LUIDAttribute
*set
= NULL
;
1624 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1629 printf("Usage: %s SID [rights...]\n", argv
[0]);
1630 return NT_STATUS_OK
;
1633 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1634 if (!NT_STATUS_IS_OK(status
)) {
1638 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1639 SEC_FLAG_MAXIMUM_ALLOWED
,
1642 if (!NT_STATUS_IS_OK(status
)) {
1646 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1649 SEC_FLAG_MAXIMUM_ALLOWED
,
1652 if (!NT_STATUS_IS_OK(status
)) {
1655 if (!NT_STATUS_IS_OK(result
)) {
1660 for (i
=2; i
<argc
; i
++) {
1662 struct lsa_String priv_name
;
1663 struct lsa_LUID luid
;
1665 init_lsa_String(&priv_name
, argv
[i
]);
1667 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1672 if (!NT_STATUS_IS_OK(status
)) {
1675 if (!NT_STATUS_IS_OK(result
)) {
1681 set
= talloc_realloc(mem_ctx
, set
,
1682 struct lsa_LUIDAttribute
,
1685 return NT_STATUS_NO_MEMORY
;
1688 set
[privs
.count
-1].luid
= luid
;
1689 set
[privs
.count
-1].attribute
= 0;
1695 status
= dcerpc_lsa_RemovePrivilegesFromAccount(b
, mem_ctx
,
1700 if (!NT_STATUS_IS_OK(status
)) {
1703 if (!NT_STATUS_IS_OK(result
)) {
1708 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1709 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1714 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1715 TALLOC_CTX
*mem_ctx
, int argc
,
1718 NTSTATUS status
, result
;
1719 struct policy_handle handle
, sec_handle
;
1720 struct lsa_String name
;
1721 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1724 printf("Usage: %s name\n", argv
[0]);
1725 return NT_STATUS_OK
;
1728 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1730 SEC_FLAG_MAXIMUM_ALLOWED
,
1732 if (!NT_STATUS_IS_OK(status
)) {
1736 init_lsa_String(&name
, argv
[1]);
1738 status
= dcerpc_lsa_CreateSecret(b
, mem_ctx
,
1741 SEC_FLAG_MAXIMUM_ALLOWED
,
1744 if (!NT_STATUS_IS_OK(status
)) {
1747 if (!NT_STATUS_IS_OK(result
)) {
1753 if (is_valid_policy_hnd(&sec_handle
)) {
1754 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1756 if (is_valid_policy_hnd(&handle
)) {
1757 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1763 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1764 TALLOC_CTX
*mem_ctx
, int argc
,
1767 NTSTATUS status
, result
;
1768 struct policy_handle handle
, sec_handle
;
1769 struct lsa_String name
;
1770 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1773 printf("Usage: %s name\n", argv
[0]);
1774 return NT_STATUS_OK
;
1777 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1779 SEC_FLAG_MAXIMUM_ALLOWED
,
1781 if (!NT_STATUS_IS_OK(status
)) {
1785 init_lsa_String(&name
, argv
[1]);
1787 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1790 SEC_FLAG_MAXIMUM_ALLOWED
,
1793 if (!NT_STATUS_IS_OK(status
)) {
1796 if (!NT_STATUS_IS_OK(result
)) {
1801 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
1804 if (!NT_STATUS_IS_OK(status
)) {
1807 if (!NT_STATUS_IS_OK(result
)) {
1813 if (is_valid_policy_hnd(&sec_handle
)) {
1814 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1816 if (is_valid_policy_hnd(&handle
)) {
1817 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1823 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1824 TALLOC_CTX
*mem_ctx
, int argc
,
1827 NTSTATUS status
, result
;
1828 struct policy_handle handle
, sec_handle
;
1829 struct lsa_String name
;
1830 struct lsa_DATA_BUF_PTR new_val
;
1831 NTTIME new_mtime
= 0;
1832 struct lsa_DATA_BUF_PTR old_val
;
1833 NTTIME old_mtime
= 0;
1834 DATA_BLOB session_key
;
1835 DATA_BLOB new_blob
= data_blob_null
;
1836 DATA_BLOB old_blob
= data_blob_null
;
1837 char *new_secret
, *old_secret
;
1838 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1841 printf("Usage: %s name\n", argv
[0]);
1842 return NT_STATUS_OK
;
1845 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1847 SEC_FLAG_MAXIMUM_ALLOWED
,
1849 if (!NT_STATUS_IS_OK(status
)) {
1853 init_lsa_String(&name
, argv
[1]);
1855 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1858 SEC_FLAG_MAXIMUM_ALLOWED
,
1861 if (!NT_STATUS_IS_OK(status
)) {
1864 if (!NT_STATUS_IS_OK(result
)) {
1869 ZERO_STRUCT(new_val
);
1870 ZERO_STRUCT(old_val
);
1872 status
= dcerpc_lsa_QuerySecret(b
, mem_ctx
,
1879 if (!NT_STATUS_IS_OK(status
)) {
1882 if (!NT_STATUS_IS_OK(result
)) {
1887 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1888 if (!NT_STATUS_IS_OK(status
)) {
1893 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1896 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1899 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1900 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1902 d_printf("new secret: %s\n", new_secret
);
1905 d_printf("old secret: %s\n", old_secret
);
1909 if (is_valid_policy_hnd(&sec_handle
)) {
1910 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1912 if (is_valid_policy_hnd(&handle
)) {
1913 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1919 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1920 TALLOC_CTX
*mem_ctx
, int argc
,
1923 NTSTATUS status
, result
;
1924 struct policy_handle handle
, sec_handle
;
1925 struct lsa_String name
;
1926 struct lsa_DATA_BUF new_val
;
1927 struct lsa_DATA_BUF old_val
;
1929 DATA_BLOB session_key
;
1930 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1933 printf("Usage: %s name secret\n", argv
[0]);
1934 return NT_STATUS_OK
;
1937 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1939 SEC_FLAG_MAXIMUM_ALLOWED
,
1941 if (!NT_STATUS_IS_OK(status
)) {
1945 init_lsa_String(&name
, argv
[1]);
1947 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1950 SEC_FLAG_MAXIMUM_ALLOWED
,
1953 if (!NT_STATUS_IS_OK(status
)) {
1956 if (!NT_STATUS_IS_OK(result
)) {
1961 ZERO_STRUCT(new_val
);
1962 ZERO_STRUCT(old_val
);
1964 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1965 if (!NT_STATUS_IS_OK(status
)) {
1969 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1971 new_val
.length
= enc_key
.length
;
1972 new_val
.size
= enc_key
.length
;
1973 new_val
.data
= enc_key
.data
;
1975 status
= dcerpc_lsa_SetSecret(b
, mem_ctx
,
1980 if (!NT_STATUS_IS_OK(status
)) {
1983 if (!NT_STATUS_IS_OK(result
)) {
1989 if (is_valid_policy_hnd(&sec_handle
)) {
1990 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1992 if (is_valid_policy_hnd(&handle
)) {
1993 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1999 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
2000 TALLOC_CTX
*mem_ctx
, int argc
,
2003 NTSTATUS status
, result
;
2004 struct policy_handle handle
;
2005 struct lsa_String name
;
2006 struct lsa_DATA_BUF
*val
;
2007 DATA_BLOB session_key
;
2008 DATA_BLOB blob
= data_blob_null
;
2010 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2013 printf("Usage: %s name\n", argv
[0]);
2014 return NT_STATUS_OK
;
2017 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2019 SEC_FLAG_MAXIMUM_ALLOWED
,
2021 if (!NT_STATUS_IS_OK(status
)) {
2025 init_lsa_String(&name
, argv
[1]);
2029 status
= dcerpc_lsa_RetrievePrivateData(b
, mem_ctx
,
2034 if (!NT_STATUS_IS_OK(status
)) {
2037 if (!NT_STATUS_IS_OK(result
)) {
2042 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2043 if (!NT_STATUS_IS_OK(status
)) {
2048 blob
= data_blob_const(val
->data
, val
->length
);
2051 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
2053 d_printf("secret: %s\n", secret
);
2057 if (is_valid_policy_hnd(&handle
)) {
2058 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2064 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
2065 TALLOC_CTX
*mem_ctx
, int argc
,
2068 NTSTATUS status
, result
;
2069 struct policy_handle handle
;
2070 struct lsa_String name
;
2071 struct lsa_DATA_BUF val
;
2072 DATA_BLOB session_key
;
2074 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2077 printf("Usage: %s name secret\n", argv
[0]);
2078 return NT_STATUS_OK
;
2081 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2083 SEC_FLAG_MAXIMUM_ALLOWED
,
2085 if (!NT_STATUS_IS_OK(status
)) {
2089 init_lsa_String(&name
, argv
[1]);
2093 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2094 if (!NT_STATUS_IS_OK(status
)) {
2098 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
2100 val
.length
= enc_key
.length
;
2101 val
.size
= enc_key
.length
;
2102 val
.data
= enc_key
.data
;
2104 status
= dcerpc_lsa_StorePrivateData(b
, mem_ctx
,
2109 if (!NT_STATUS_IS_OK(status
)) {
2112 if (!NT_STATUS_IS_OK(result
)) {
2118 if (is_valid_policy_hnd(&handle
)) {
2119 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2125 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
2126 TALLOC_CTX
*mem_ctx
, int argc
,
2129 NTSTATUS status
, result
;
2130 struct policy_handle handle
, trustdom_handle
;
2132 struct lsa_DomainInfo info
;
2133 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2136 printf("Usage: %s name sid\n", argv
[0]);
2137 return NT_STATUS_OK
;
2140 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2142 SEC_FLAG_MAXIMUM_ALLOWED
,
2144 if (!NT_STATUS_IS_OK(status
)) {
2148 init_lsa_StringLarge(&info
.name
, argv
[1]);
2150 string_to_sid(&sid
, argv
[2]);
2152 status
= dcerpc_lsa_CreateTrustedDomain(b
, mem_ctx
,
2155 SEC_FLAG_MAXIMUM_ALLOWED
,
2158 if (!NT_STATUS_IS_OK(status
)) {
2161 if (!NT_STATUS_IS_OK(result
)) {
2167 if (is_valid_policy_hnd(&trustdom_handle
)) {
2168 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2171 if (is_valid_policy_hnd(&handle
)) {
2172 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2178 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
2179 TALLOC_CTX
*mem_ctx
, int argc
,
2182 NTSTATUS status
, result
;
2183 struct policy_handle handle
, trustdom_handle
;
2184 struct lsa_String name
;
2185 struct dom_sid
*sid
= NULL
;
2186 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2189 printf("Usage: %s name\n", argv
[0]);
2190 return NT_STATUS_OK
;
2193 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2195 SEC_FLAG_MAXIMUM_ALLOWED
,
2197 if (!NT_STATUS_IS_OK(status
)) {
2201 init_lsa_String(&name
, argv
[1]);
2203 status
= dcerpc_lsa_OpenTrustedDomainByName(b
, mem_ctx
,
2206 SEC_FLAG_MAXIMUM_ALLOWED
,
2209 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
)) {
2214 uint32_t resume_handle
= 0;
2215 struct lsa_DomainList domains
;
2218 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
2224 if (!NT_STATUS_IS_OK(status
)) {
2227 if (!NT_STATUS_IS_OK(result
)) {
2232 for (i
=0; i
< domains
.count
; i
++) {
2233 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
2234 sid
= domains
.domains
[i
].sid
;
2240 return NT_STATUS_INVALID_SID
;
2244 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
2247 SEC_FLAG_MAXIMUM_ALLOWED
,
2250 if (!NT_STATUS_IS_OK(status
)) {
2253 if (!NT_STATUS_IS_OK(result
)) {
2259 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
2262 if (!NT_STATUS_IS_OK(status
)) {
2265 if (!NT_STATUS_IS_OK(result
)) {
2271 if (is_valid_policy_hnd(&trustdom_handle
)) {
2272 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2275 if (is_valid_policy_hnd(&handle
)) {
2276 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2283 /* List of commands exported by this module */
2285 struct cmd_set lsarpc_commands
[] = {
2289 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
, NULL
, "Query info policy", "" },
2290 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2291 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2292 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2293 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2294 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2295 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
2296 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate privileges", "" },
2297 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
, NULL
, "Get the privilege name", "" },
2298 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the LSA SIDS", "" },
2299 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
, NULL
, "Create a new lsa account", "" },
2300 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the privileges of an SID", "" },
2301 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the rights of an SID", "" },
2302 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Assign a privilege to a SID", "" },
2303 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Revoke a privilege from a SID", "" },
2304 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Add rights to an account", "" },
2305 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Remove rights from an account", "" },
2306 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
, NULL
, "Get a privilege value given its name", "" },
2307 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA security object", "" },
2308 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2309 { "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", "" },
2310 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2311 { "lsasettrustdominfo", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Set LSA trusted domain info", "" },
2312 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
, NULL
, "Get username", "" },
2313 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Secret", "" },
2314 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Secret", "" },
2315 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Query Secret", "" },
2316 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Set Secret", "" },
2317 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Retrieve Private Data", "" },
2318 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Store Private Data", "" },
2319 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Trusted Domain", "" },
2320 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Trusted Domain", "" },