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
;
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 for (i
= 0; i
< sids
.count
; i
++) {
366 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
367 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
368 sid_type_lookup(sids
.sids
[i
].sid_type
),
369 sids
.sids
[i
].sid_type
);
375 /* Resolve a list of SIDs to a list of names */
377 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
378 int argc
, const char **argv
)
380 struct policy_handle pol
;
381 NTSTATUS status
, result
;
382 struct dom_sid
*sids
;
385 enum lsa_SidType
*types
;
387 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
390 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
394 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
395 SEC_FLAG_MAXIMUM_ALLOWED
,
398 if (!NT_STATUS_IS_OK(status
))
401 /* Convert arguments to sids */
403 sids
= talloc_array(mem_ctx
, struct dom_sid
, argc
- 1);
406 printf("could not allocate memory for %d sids\n", argc
- 1);
410 for (i
= 0; i
< argc
- 1; i
++)
411 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
412 status
= NT_STATUS_INVALID_SID
;
416 /* Lookup the SIDs */
418 status
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
419 &domains
, &names
, &types
);
421 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
422 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
425 status
= NT_STATUS_OK
;
429 for (i
= 0; i
< (argc
- 1); i
++) {
432 sid_to_fstring(sid_str
, &sids
[i
]);
433 printf("%s %s\\%s (%d)\n", sid_str
,
434 domains
[i
] ? domains
[i
] : "*unknown*",
435 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
438 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
444 /* Resolve a list of SIDs to a list of names */
446 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
448 int argc
, const char **argv
)
450 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
, result
;
452 struct lsa_SidArray sids
;
453 struct lsa_RefDomainList
*domains
;
454 struct lsa_TransNameArray2 names
;
456 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
459 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
465 /* Convert arguments to sids */
467 sids
.num_sids
= argc
-1;
468 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
470 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
474 for (i
= 0; i
< sids
.num_sids
; i
++) {
475 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
476 if (sids
.sids
[i
].sid
== NULL
) {
477 status
= NT_STATUS_NO_MEMORY
;
480 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
481 status
= NT_STATUS_INVALID_SID
;
486 /* Lookup the SIDs */
487 status
= dcerpc_lsa_LookupSids3(b
, mem_ctx
,
496 if (!NT_STATUS_IS_OK(status
)) {
499 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
500 NT_STATUS_V(STATUS_SOME_UNMAPPED
)) {
505 status
= NT_STATUS_OK
;
509 for (i
= 0; i
< count
; i
++) {
512 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
513 printf("%s %s (%d)\n", sid_str
,
514 names
.names
[i
].name
.string
,
515 names
.names
[i
].sid_type
);
523 /* Enumerate list of trusted domains */
525 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
526 TALLOC_CTX
*mem_ctx
, int argc
,
529 struct policy_handle pol
;
530 NTSTATUS status
, result
;
531 struct lsa_DomainList domain_list
;
532 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
534 /* defaults, but may be changed using params */
537 uint32_t max_size
= (uint32_t)-1;
540 printf("Usage: %s [enum context (0)]\n", argv
[0]);
544 if (argc
== 2 && argv
[1]) {
545 enum_ctx
= atoi(argv
[2]);
548 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
549 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
552 if (!NT_STATUS_IS_OK(status
))
555 status
= STATUS_MORE_ENTRIES
;
557 while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
559 /* Lookup list of trusted domains */
561 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
567 if (!NT_STATUS_IS_OK(status
)) {
570 if (!NT_STATUS_IS_OK(result
) &&
571 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
572 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
577 /* Print results: list of names and sids returned in this
579 for (i
= 0; i
< domain_list
.count
; i
++) {
582 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
584 domain_list
.domains
[i
].name
.string
?
585 domain_list
.domains
[i
].name
.string
: "*unknown*",
590 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
595 /* Enumerates privileges */
597 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
598 TALLOC_CTX
*mem_ctx
, int argc
,
601 struct policy_handle pol
;
602 NTSTATUS status
, result
;
603 struct lsa_PrivArray priv_array
;
604 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
606 uint32 enum_context
=0;
607 uint32 pref_max_length
=0x1000;
611 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
616 enum_context
=atoi(argv
[1]);
619 pref_max_length
=atoi(argv
[2]);
621 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
622 SEC_FLAG_MAXIMUM_ALLOWED
,
625 if (!NT_STATUS_IS_OK(status
))
628 status
= dcerpc_lsa_EnumPrivs(b
, mem_ctx
,
634 if (!NT_STATUS_IS_OK(status
))
636 if (!NT_STATUS_IS_OK(result
)) {
642 printf("found %d privileges\n\n", priv_array
.count
);
644 for (i
= 0; i
< priv_array
.count
; i
++) {
645 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
646 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
647 priv_array
.privs
[i
].luid
.high
,
648 priv_array
.privs
[i
].luid
.low
,
649 priv_array
.privs
[i
].luid
.high
,
650 priv_array
.privs
[i
].luid
.low
);
653 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
658 /* Get privilege name */
660 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
661 TALLOC_CTX
*mem_ctx
, int argc
,
664 struct policy_handle pol
;
665 NTSTATUS status
, result
;
666 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
669 uint16 lang_id_sys
=0;
671 struct lsa_String lsa_name
;
672 struct lsa_StringLarge
*description
= NULL
;
675 printf("Usage: %s privilege name\n", argv
[0]);
679 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
680 SEC_FLAG_MAXIMUM_ALLOWED
,
683 if (!NT_STATUS_IS_OK(status
))
686 init_lsa_String(&lsa_name
, argv
[1]);
688 status
= dcerpc_lsa_LookupPrivDisplayName(b
, mem_ctx
,
696 if (!NT_STATUS_IS_OK(status
))
698 if (!NT_STATUS_IS_OK(result
)) {
704 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
706 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
711 /* Enumerate the LSA SIDS */
713 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
714 TALLOC_CTX
*mem_ctx
, int argc
,
717 struct policy_handle pol
;
718 NTSTATUS status
, result
;
719 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
721 uint32 enum_context
=0;
722 uint32 pref_max_length
=0x1000;
723 struct lsa_SidArray sid_array
;
727 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
732 enum_context
=atoi(argv
[1]);
735 pref_max_length
=atoi(argv
[2]);
737 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
738 SEC_FLAG_MAXIMUM_ALLOWED
,
741 if (!NT_STATUS_IS_OK(status
))
744 status
= dcerpc_lsa_EnumAccounts(b
, mem_ctx
,
750 if (!NT_STATUS_IS_OK(status
))
752 if (!NT_STATUS_IS_OK(result
)) {
758 printf("found %d SIDs\n\n", sid_array
.num_sids
);
760 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
763 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
764 printf("%s\n", sid_str
);
767 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
772 /* Create a new account */
774 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
775 TALLOC_CTX
*mem_ctx
, int argc
,
778 struct policy_handle dom_pol
;
779 struct policy_handle user_pol
;
780 NTSTATUS status
, result
;
781 uint32 des_access
= 0x000f000f;
782 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
787 printf("Usage: %s SID\n", argv
[0]);
791 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
792 if (!NT_STATUS_IS_OK(status
))
795 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
796 SEC_FLAG_MAXIMUM_ALLOWED
,
799 if (!NT_STATUS_IS_OK(status
))
802 status
= dcerpc_lsa_CreateAccount(b
, mem_ctx
,
808 if (!NT_STATUS_IS_OK(status
))
810 if (!NT_STATUS_IS_OK(result
)) {
815 printf("Account for SID %s successfully created\n\n", argv
[1]);
816 status
= NT_STATUS_OK
;
818 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
824 /* Enumerate the privileges of an SID */
826 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
827 TALLOC_CTX
*mem_ctx
, int argc
,
830 struct policy_handle dom_pol
;
831 struct policy_handle user_pol
;
832 NTSTATUS status
, result
;
833 uint32 access_desired
= 0x000f000f;
835 struct lsa_PrivilegeSet
*privs
= NULL
;
837 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
840 printf("Usage: %s SID\n", argv
[0]);
844 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
845 if (!NT_STATUS_IS_OK(status
))
848 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
849 SEC_FLAG_MAXIMUM_ALLOWED
,
852 if (!NT_STATUS_IS_OK(status
))
855 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
861 if (!NT_STATUS_IS_OK(status
))
863 if (!NT_STATUS_IS_OK(result
)) {
868 status
= dcerpc_lsa_EnumPrivsAccount(b
, mem_ctx
,
872 if (!NT_STATUS_IS_OK(status
))
874 if (!NT_STATUS_IS_OK(result
)) {
880 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
881 printf("high\tlow\tattribute\n");
883 for (i
= 0; i
< privs
->count
; i
++) {
884 printf("%u\t%u\t%u\n",
885 privs
->set
[i
].luid
.high
,
886 privs
->set
[i
].luid
.low
,
887 privs
->set
[i
].attribute
);
890 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
896 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
898 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
899 TALLOC_CTX
*mem_ctx
, int argc
,
902 struct policy_handle dom_pol
;
903 NTSTATUS status
, result
;
905 struct lsa_RightSet rights
;
906 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
911 printf("Usage: %s SID\n", argv
[0]);
915 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
916 if (!NT_STATUS_IS_OK(status
))
919 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
920 SEC_FLAG_MAXIMUM_ALLOWED
,
923 if (!NT_STATUS_IS_OK(status
))
926 status
= dcerpc_lsa_EnumAccountRights(b
, mem_ctx
,
931 if (!NT_STATUS_IS_OK(status
))
933 if (!NT_STATUS_IS_OK(result
)) {
938 printf("found %d privileges for SID %s\n", rights
.count
,
939 sid_string_tos(&sid
));
941 for (i
= 0; i
< rights
.count
; i
++) {
942 printf("\t%s\n", rights
.names
[i
].string
);
945 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
951 /* add some privileges to a SID via LsaAddAccountRights */
953 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
954 TALLOC_CTX
*mem_ctx
, int argc
,
957 struct policy_handle dom_pol
;
958 NTSTATUS status
, result
;
959 struct lsa_RightSet rights
;
962 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
965 printf("Usage: %s SID [rights...]\n", argv
[0]);
969 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
970 if (!NT_STATUS_IS_OK(status
))
973 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
974 SEC_FLAG_MAXIMUM_ALLOWED
,
977 if (!NT_STATUS_IS_OK(status
))
980 rights
.count
= argc
-2;
981 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
984 return NT_STATUS_NO_MEMORY
;
987 for (i
=0; i
<argc
-2; i
++) {
988 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
991 status
= dcerpc_lsa_AddAccountRights(b
, mem_ctx
,
996 if (!NT_STATUS_IS_OK(status
))
998 if (!NT_STATUS_IS_OK(result
)) {
1003 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1009 /* remove some privileges to a SID via LsaRemoveAccountRights */
1011 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
1012 TALLOC_CTX
*mem_ctx
, int argc
,
1015 struct policy_handle dom_pol
;
1016 NTSTATUS status
, result
;
1017 struct lsa_RightSet rights
;
1020 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1023 printf("Usage: %s SID [rights...]\n", argv
[0]);
1024 return NT_STATUS_OK
;
1027 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1028 if (!NT_STATUS_IS_OK(status
))
1031 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1032 SEC_FLAG_MAXIMUM_ALLOWED
,
1035 if (!NT_STATUS_IS_OK(status
))
1038 rights
.count
= argc
-2;
1039 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
1041 if (!rights
.names
) {
1042 return NT_STATUS_NO_MEMORY
;
1045 for (i
=0; i
<argc
-2; i
++) {
1046 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
1049 status
= dcerpc_lsa_RemoveAccountRights(b
, mem_ctx
,
1055 if (!NT_STATUS_IS_OK(status
))
1057 if (!NT_STATUS_IS_OK(result
)) {
1062 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1069 /* Get a privilege value given its name */
1071 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
1072 TALLOC_CTX
*mem_ctx
, int argc
,
1075 struct policy_handle pol
;
1076 NTSTATUS status
, result
;
1077 struct lsa_LUID luid
;
1078 struct lsa_String name
;
1079 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1082 printf("Usage: %s name\n", argv
[0]);
1083 return NT_STATUS_OK
;
1086 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1087 SEC_FLAG_MAXIMUM_ALLOWED
,
1090 if (!NT_STATUS_IS_OK(status
))
1093 init_lsa_String(&name
, argv
[1]);
1095 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1100 if (!NT_STATUS_IS_OK(status
))
1102 if (!NT_STATUS_IS_OK(result
)) {
1109 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1111 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1116 /* Query LSA security object */
1118 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1119 TALLOC_CTX
*mem_ctx
, int argc
,
1122 struct policy_handle pol
;
1123 NTSTATUS status
, result
;
1124 struct sec_desc_buf
*sdb
;
1125 uint32 sec_info
= SECINFO_DACL
;
1126 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1128 if (argc
< 1 || argc
> 2) {
1129 printf("Usage: %s [sec_info]\n", argv
[0]);
1130 return NT_STATUS_OK
;
1133 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1134 SEC_FLAG_MAXIMUM_ALLOWED
,
1138 sscanf(argv
[1], "%x", &sec_info
);
1140 if (!NT_STATUS_IS_OK(status
))
1143 status
= dcerpc_lsa_QuerySecurity(b
, mem_ctx
,
1148 if (!NT_STATUS_IS_OK(status
))
1150 if (!NT_STATUS_IS_OK(result
)) {
1157 display_sec_desc(sdb
->sd
);
1159 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1164 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1165 DATA_BLOB session_key
)
1167 char *pwd
, *pwd_old
;
1169 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1170 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1172 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key
);
1173 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key
);
1175 d_printf("Password:\t%s\n", pwd
);
1176 d_printf("Old Password:\t%s\n", pwd_old
);
1179 talloc_free(pwd_old
);
1182 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1183 union lsa_TrustedDomainInfo
*info
,
1184 enum lsa_TrustDomInfoEnum info_class
,
1185 DATA_BLOB session_key
)
1187 switch (info_class
) {
1188 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1189 display_trust_dom_info_4(&info
->password
, session_key
);
1192 const char *str
= NULL
;
1193 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1194 lsa_TrustedDomainInfo
,
1197 d_printf("%s\n", str
);
1204 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1205 TALLOC_CTX
*mem_ctx
, int argc
,
1208 struct policy_handle pol
;
1209 NTSTATUS status
, result
;
1210 struct dom_sid dom_sid
;
1211 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1212 union lsa_TrustedDomainInfo
*info
= NULL
;
1213 enum lsa_TrustDomInfoEnum info_class
= 1;
1214 DATA_BLOB session_key
;
1215 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1217 if (argc
> 3 || argc
< 2) {
1218 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1219 return NT_STATUS_OK
;
1222 if (!string_to_sid(&dom_sid
, argv
[1]))
1223 return NT_STATUS_NO_MEMORY
;
1226 info_class
= atoi(argv
[2]);
1228 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1230 if (!NT_STATUS_IS_OK(status
))
1233 status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
1239 if (!NT_STATUS_IS_OK(status
))
1241 if (!NT_STATUS_IS_OK(result
)) {
1246 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1247 if (!NT_STATUS_IS_OK(status
)) {
1248 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1252 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1255 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1260 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1261 TALLOC_CTX
*mem_ctx
, int argc
,
1264 struct policy_handle pol
;
1265 NTSTATUS status
, result
;
1266 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1267 union lsa_TrustedDomainInfo
*info
= NULL
;
1268 enum lsa_TrustDomInfoEnum info_class
= 1;
1269 struct lsa_String trusted_domain
;
1270 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1271 DATA_BLOB session_key
;
1273 if (argc
> 3 || argc
< 2) {
1274 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1275 return NT_STATUS_OK
;
1279 info_class
= atoi(argv
[2]);
1281 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1283 if (!NT_STATUS_IS_OK(status
))
1286 init_lsa_String(&trusted_domain
, argv
[1]);
1288 status
= dcerpc_lsa_QueryTrustedDomainInfoByName(b
, mem_ctx
,
1294 if (!NT_STATUS_IS_OK(status
))
1296 if (!NT_STATUS_IS_OK(result
)) {
1301 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1302 if (!NT_STATUS_IS_OK(status
)) {
1303 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1307 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1310 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1315 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1316 TALLOC_CTX
*mem_ctx
, int argc
,
1319 struct policy_handle pol
, trustdom_pol
;
1320 NTSTATUS status
, result
;
1321 uint32 access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1322 union lsa_TrustedDomainInfo
*info
= NULL
;
1323 struct dom_sid dom_sid
;
1324 enum lsa_TrustDomInfoEnum info_class
= 1;
1325 DATA_BLOB session_key
;
1326 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1328 if (argc
> 3 || argc
< 2) {
1329 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1330 return NT_STATUS_OK
;
1333 if (!string_to_sid(&dom_sid
, argv
[1]))
1334 return NT_STATUS_NO_MEMORY
;
1338 info_class
= atoi(argv
[2]);
1340 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1342 if (!NT_STATUS_IS_OK(status
))
1345 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
1351 if (!NT_STATUS_IS_OK(status
))
1353 if (!NT_STATUS_IS_OK(result
)) {
1358 status
= dcerpc_lsa_QueryTrustedDomainInfo(b
, mem_ctx
,
1363 if (!NT_STATUS_IS_OK(status
))
1365 if (!NT_STATUS_IS_OK(result
)) {
1370 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1371 if (!NT_STATUS_IS_OK(status
)) {
1372 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1376 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1379 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1384 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1385 TALLOC_CTX
*mem_ctx
, int argc
,
1388 struct policy_handle pol
;
1389 NTSTATUS status
, result
;
1390 const char *servername
= cli
->desthost
;
1391 struct lsa_String
*account_name
= NULL
;
1392 struct lsa_String
*authority_name
= NULL
;
1393 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1396 printf("Usage: %s servername\n", argv
[0]);
1397 return NT_STATUS_OK
;
1400 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, true,
1401 SEC_FLAG_MAXIMUM_ALLOWED
,
1404 if (!NT_STATUS_IS_OK(status
)) {
1408 status
= dcerpc_lsa_GetUserName(b
, mem_ctx
,
1413 if (!NT_STATUS_IS_OK(status
)) {
1416 if (!NT_STATUS_IS_OK(result
)) {
1423 printf("Account Name: %s, Authority Name: %s\n",
1424 account_name
->string
, authority_name
? authority_name
->string
:
1427 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1432 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1433 TALLOC_CTX
*mem_ctx
, int argc
,
1436 struct policy_handle dom_pol
, user_pol
;
1437 NTSTATUS status
, result
;
1438 struct lsa_PrivilegeSet privs
;
1439 struct lsa_LUIDAttribute
*set
= NULL
;
1442 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1447 printf("Usage: %s SID [rights...]\n", argv
[0]);
1448 return NT_STATUS_OK
;
1451 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1452 if (!NT_STATUS_IS_OK(status
)) {
1456 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1457 SEC_FLAG_MAXIMUM_ALLOWED
,
1460 if (!NT_STATUS_IS_OK(status
)) {
1464 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1467 SEC_FLAG_MAXIMUM_ALLOWED
,
1470 if (!NT_STATUS_IS_OK(status
)) {
1473 if (!NT_STATUS_IS_OK(result
)) {
1478 for (i
=2; i
<argc
; i
++) {
1480 struct lsa_String priv_name
;
1481 struct lsa_LUID luid
;
1483 init_lsa_String(&priv_name
, argv
[i
]);
1485 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1490 if (!NT_STATUS_IS_OK(status
)) {
1493 if (!NT_STATUS_IS_OK(result
)) {
1499 set
= talloc_realloc(mem_ctx
, set
,
1500 struct lsa_LUIDAttribute
,
1503 return NT_STATUS_NO_MEMORY
;
1506 set
[privs
.count
-1].luid
= luid
;
1507 set
[privs
.count
-1].attribute
= 0;
1512 status
= dcerpc_lsa_AddPrivilegesToAccount(b
, mem_ctx
,
1516 if (!NT_STATUS_IS_OK(status
)) {
1519 if (!NT_STATUS_IS_OK(result
)) {
1524 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1525 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1530 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1531 TALLOC_CTX
*mem_ctx
, int argc
,
1534 struct policy_handle dom_pol
, user_pol
;
1535 NTSTATUS status
, result
;
1536 struct lsa_PrivilegeSet privs
;
1537 struct lsa_LUIDAttribute
*set
= NULL
;
1540 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1545 printf("Usage: %s SID [rights...]\n", argv
[0]);
1546 return NT_STATUS_OK
;
1549 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1550 if (!NT_STATUS_IS_OK(status
)) {
1554 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1555 SEC_FLAG_MAXIMUM_ALLOWED
,
1558 if (!NT_STATUS_IS_OK(status
)) {
1562 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1565 SEC_FLAG_MAXIMUM_ALLOWED
,
1568 if (!NT_STATUS_IS_OK(status
)) {
1571 if (!NT_STATUS_IS_OK(result
)) {
1576 for (i
=2; i
<argc
; i
++) {
1578 struct lsa_String priv_name
;
1579 struct lsa_LUID luid
;
1581 init_lsa_String(&priv_name
, argv
[i
]);
1583 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1588 if (!NT_STATUS_IS_OK(status
)) {
1591 if (!NT_STATUS_IS_OK(result
)) {
1597 set
= talloc_realloc(mem_ctx
, set
,
1598 struct lsa_LUIDAttribute
,
1601 return NT_STATUS_NO_MEMORY
;
1604 set
[privs
.count
-1].luid
= luid
;
1605 set
[privs
.count
-1].attribute
= 0;
1611 status
= dcerpc_lsa_RemovePrivilegesFromAccount(b
, mem_ctx
,
1616 if (!NT_STATUS_IS_OK(status
)) {
1619 if (!NT_STATUS_IS_OK(result
)) {
1624 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1625 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1630 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1631 TALLOC_CTX
*mem_ctx
, int argc
,
1634 NTSTATUS status
, result
;
1635 struct policy_handle handle
, sec_handle
;
1636 struct lsa_String name
;
1637 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1640 printf("Usage: %s name\n", argv
[0]);
1641 return NT_STATUS_OK
;
1644 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1646 SEC_FLAG_MAXIMUM_ALLOWED
,
1648 if (!NT_STATUS_IS_OK(status
)) {
1652 init_lsa_String(&name
, argv
[1]);
1654 status
= dcerpc_lsa_CreateSecret(b
, mem_ctx
,
1657 SEC_FLAG_MAXIMUM_ALLOWED
,
1660 if (!NT_STATUS_IS_OK(status
)) {
1663 if (!NT_STATUS_IS_OK(result
)) {
1669 if (is_valid_policy_hnd(&sec_handle
)) {
1670 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1672 if (is_valid_policy_hnd(&handle
)) {
1673 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1679 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1680 TALLOC_CTX
*mem_ctx
, int argc
,
1683 NTSTATUS status
, result
;
1684 struct policy_handle handle
, sec_handle
;
1685 struct lsa_String name
;
1686 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1689 printf("Usage: %s name\n", argv
[0]);
1690 return NT_STATUS_OK
;
1693 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1695 SEC_FLAG_MAXIMUM_ALLOWED
,
1697 if (!NT_STATUS_IS_OK(status
)) {
1701 init_lsa_String(&name
, argv
[1]);
1703 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1706 SEC_FLAG_MAXIMUM_ALLOWED
,
1709 if (!NT_STATUS_IS_OK(status
)) {
1712 if (!NT_STATUS_IS_OK(result
)) {
1717 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
1720 if (!NT_STATUS_IS_OK(status
)) {
1723 if (!NT_STATUS_IS_OK(result
)) {
1729 if (is_valid_policy_hnd(&sec_handle
)) {
1730 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1732 if (is_valid_policy_hnd(&handle
)) {
1733 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1739 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1740 TALLOC_CTX
*mem_ctx
, int argc
,
1743 NTSTATUS status
, result
;
1744 struct policy_handle handle
, sec_handle
;
1745 struct lsa_String name
;
1746 struct lsa_DATA_BUF_PTR new_val
;
1747 NTTIME new_mtime
= 0;
1748 struct lsa_DATA_BUF_PTR old_val
;
1749 NTTIME old_mtime
= 0;
1750 DATA_BLOB session_key
;
1751 DATA_BLOB new_blob
= data_blob_null
;
1752 DATA_BLOB old_blob
= data_blob_null
;
1753 char *new_secret
, *old_secret
;
1754 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1757 printf("Usage: %s name\n", argv
[0]);
1758 return NT_STATUS_OK
;
1761 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1763 SEC_FLAG_MAXIMUM_ALLOWED
,
1765 if (!NT_STATUS_IS_OK(status
)) {
1769 init_lsa_String(&name
, argv
[1]);
1771 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1774 SEC_FLAG_MAXIMUM_ALLOWED
,
1777 if (!NT_STATUS_IS_OK(status
)) {
1780 if (!NT_STATUS_IS_OK(result
)) {
1785 ZERO_STRUCT(new_val
);
1786 ZERO_STRUCT(old_val
);
1788 status
= dcerpc_lsa_QuerySecret(b
, mem_ctx
,
1795 if (!NT_STATUS_IS_OK(status
)) {
1798 if (!NT_STATUS_IS_OK(result
)) {
1803 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1804 if (!NT_STATUS_IS_OK(status
)) {
1809 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1812 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1815 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1816 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1818 d_printf("new secret: %s\n", new_secret
);
1821 d_printf("old secret: %s\n", old_secret
);
1825 if (is_valid_policy_hnd(&sec_handle
)) {
1826 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1828 if (is_valid_policy_hnd(&handle
)) {
1829 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1835 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
1836 TALLOC_CTX
*mem_ctx
, int argc
,
1839 NTSTATUS status
, result
;
1840 struct policy_handle handle
, sec_handle
;
1841 struct lsa_String name
;
1842 struct lsa_DATA_BUF new_val
;
1843 struct lsa_DATA_BUF old_val
;
1845 DATA_BLOB session_key
;
1846 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1849 printf("Usage: %s name secret\n", argv
[0]);
1850 return NT_STATUS_OK
;
1853 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1855 SEC_FLAG_MAXIMUM_ALLOWED
,
1857 if (!NT_STATUS_IS_OK(status
)) {
1861 init_lsa_String(&name
, argv
[1]);
1863 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1866 SEC_FLAG_MAXIMUM_ALLOWED
,
1869 if (!NT_STATUS_IS_OK(status
)) {
1872 if (!NT_STATUS_IS_OK(result
)) {
1877 ZERO_STRUCT(new_val
);
1878 ZERO_STRUCT(old_val
);
1880 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1881 if (!NT_STATUS_IS_OK(status
)) {
1885 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
1887 new_val
.length
= enc_key
.length
;
1888 new_val
.size
= enc_key
.length
;
1889 new_val
.data
= enc_key
.data
;
1891 status
= dcerpc_lsa_SetSecret(b
, mem_ctx
,
1896 if (!NT_STATUS_IS_OK(status
)) {
1899 if (!NT_STATUS_IS_OK(result
)) {
1905 if (is_valid_policy_hnd(&sec_handle
)) {
1906 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1908 if (is_valid_policy_hnd(&handle
)) {
1909 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1915 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
1916 TALLOC_CTX
*mem_ctx
, int argc
,
1919 NTSTATUS status
, result
;
1920 struct policy_handle handle
;
1921 struct lsa_String name
;
1922 struct lsa_DATA_BUF
*val
;
1923 DATA_BLOB session_key
;
1924 DATA_BLOB blob
= data_blob_null
;
1926 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1929 printf("Usage: %s name\n", argv
[0]);
1930 return NT_STATUS_OK
;
1933 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1935 SEC_FLAG_MAXIMUM_ALLOWED
,
1937 if (!NT_STATUS_IS_OK(status
)) {
1941 init_lsa_String(&name
, argv
[1]);
1945 status
= dcerpc_lsa_RetrievePrivateData(b
, mem_ctx
,
1950 if (!NT_STATUS_IS_OK(status
)) {
1953 if (!NT_STATUS_IS_OK(result
)) {
1958 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1959 if (!NT_STATUS_IS_OK(status
)) {
1964 blob
= data_blob_const(val
->data
, val
->length
);
1967 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
1969 d_printf("secret: %s\n", secret
);
1973 if (is_valid_policy_hnd(&handle
)) {
1974 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1980 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
1981 TALLOC_CTX
*mem_ctx
, int argc
,
1984 NTSTATUS status
, result
;
1985 struct policy_handle handle
;
1986 struct lsa_String name
;
1987 struct lsa_DATA_BUF val
;
1988 DATA_BLOB session_key
;
1990 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1993 printf("Usage: %s name secret\n", argv
[0]);
1994 return NT_STATUS_OK
;
1997 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1999 SEC_FLAG_MAXIMUM_ALLOWED
,
2001 if (!NT_STATUS_IS_OK(status
)) {
2005 init_lsa_String(&name
, argv
[1]);
2009 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2010 if (!NT_STATUS_IS_OK(status
)) {
2014 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
2016 val
.length
= enc_key
.length
;
2017 val
.size
= enc_key
.length
;
2018 val
.data
= enc_key
.data
;
2020 status
= dcerpc_lsa_StorePrivateData(b
, mem_ctx
,
2025 if (!NT_STATUS_IS_OK(status
)) {
2028 if (!NT_STATUS_IS_OK(result
)) {
2034 if (is_valid_policy_hnd(&handle
)) {
2035 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2041 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
2042 TALLOC_CTX
*mem_ctx
, int argc
,
2045 NTSTATUS status
, result
;
2046 struct policy_handle handle
, trustdom_handle
;
2048 struct lsa_DomainInfo info
;
2049 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2052 printf("Usage: %s name sid\n", argv
[0]);
2053 return NT_STATUS_OK
;
2056 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2058 SEC_FLAG_MAXIMUM_ALLOWED
,
2060 if (!NT_STATUS_IS_OK(status
)) {
2064 init_lsa_StringLarge(&info
.name
, argv
[1]);
2066 string_to_sid(&sid
, argv
[2]);
2068 status
= dcerpc_lsa_CreateTrustedDomain(b
, mem_ctx
,
2071 SEC_FLAG_MAXIMUM_ALLOWED
,
2074 if (!NT_STATUS_IS_OK(status
)) {
2077 if (!NT_STATUS_IS_OK(result
)) {
2083 if (is_valid_policy_hnd(&trustdom_handle
)) {
2084 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2087 if (is_valid_policy_hnd(&handle
)) {
2088 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2094 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
2095 TALLOC_CTX
*mem_ctx
, int argc
,
2098 NTSTATUS status
, result
;
2099 struct policy_handle handle
, trustdom_handle
;
2100 struct lsa_String name
;
2101 struct dom_sid
*sid
= NULL
;
2102 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2105 printf("Usage: %s name\n", argv
[0]);
2106 return NT_STATUS_OK
;
2109 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2111 SEC_FLAG_MAXIMUM_ALLOWED
,
2113 if (!NT_STATUS_IS_OK(status
)) {
2117 init_lsa_String(&name
, argv
[1]);
2119 status
= dcerpc_lsa_OpenTrustedDomainByName(b
, mem_ctx
,
2122 SEC_FLAG_MAXIMUM_ALLOWED
,
2125 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
)) {
2130 uint32_t resume_handle
= 0;
2131 struct lsa_DomainList domains
;
2134 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
2140 if (!NT_STATUS_IS_OK(status
)) {
2143 if (!NT_STATUS_IS_OK(result
)) {
2148 for (i
=0; i
< domains
.count
; i
++) {
2149 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
2150 sid
= domains
.domains
[i
].sid
;
2156 return NT_STATUS_INVALID_SID
;
2160 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
2163 SEC_FLAG_MAXIMUM_ALLOWED
,
2166 if (!NT_STATUS_IS_OK(status
)) {
2169 if (!NT_STATUS_IS_OK(result
)) {
2175 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
2178 if (!NT_STATUS_IS_OK(status
)) {
2181 if (!NT_STATUS_IS_OK(result
)) {
2187 if (is_valid_policy_hnd(&trustdom_handle
)) {
2188 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2191 if (is_valid_policy_hnd(&handle
)) {
2192 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2199 /* List of commands exported by this module */
2201 struct cmd_set lsarpc_commands
[] = {
2205 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query info policy", "" },
2206 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
2207 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert SIDs to names", "" },
2208 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
2209 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
2210 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Convert names to SIDs", "" },
2211 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
2212 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate privileges", "" },
2213 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get the privilege name", "" },
2214 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the LSA SIDS", "" },
2215 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create a new lsa account", "" },
2216 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the privileges of an SID", "" },
2217 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Enumerate the rights of an SID", "" },
2218 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Assign a privilege to a SID", "" },
2219 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Revoke a privilege from a SID", "" },
2220 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Add rights to an account", "" },
2221 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Remove rights from an account", "" },
2222 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get a privilege value given its name", "" },
2223 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA security object", "" },
2224 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2225 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobyname
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
2226 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2227 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Get username", "" },
2228 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Secret", "" },
2229 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Secret", "" },
2230 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Query Secret", "" },
2231 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Set Secret", "" },
2232 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Retrieve Private Data", "" },
2233 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Store Private Data", "" },
2234 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Create Trusted Domain", "" },
2235 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
.syntax_id
, NULL
, "Delete Trusted Domain", "" },