2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
7 Copyright (C) Guenther Deschner 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpcclient.h"
25 #include "../libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_lsa.h"
27 #include "../librpc/gen_ndr/ndr_lsa_c.h"
28 #include "rpc_client/cli_lsarpc.h"
29 #include "rpc_client/init_lsa.h"
30 #include "../libcli/security/security.h"
32 /* useful function to allow entering a name instead of a SID and
33 * looking it up automatically */
34 static NTSTATUS
name_to_sid(struct rpc_pipe_client
*cli
,
36 struct dom_sid
*sid
, const char *name
)
38 struct policy_handle pol
;
39 enum lsa_SidType
*sid_types
;
40 NTSTATUS status
, result
;
42 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
44 /* maybe its a raw SID */
45 if (strncmp(name
, "S-", 2) == 0 &&
46 string_to_sid(sid
, name
)) {
50 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
51 SEC_FLAG_MAXIMUM_ALLOWED
,
53 if (!NT_STATUS_IS_OK(status
))
56 status
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, 1, &name
, NULL
, 1, &sids
, &sid_types
);
57 if (!NT_STATUS_IS_OK(status
))
60 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
68 static void display_query_info_1(struct lsa_AuditLogInfo
*r
)
70 d_printf("percent_full:\t%d\n", r
->percent_full
);
71 d_printf("maximum_log_size:\t%d\n", r
->maximum_log_size
);
72 d_printf("retention_time:\t%lld\n", (long long)r
->retention_time
);
73 d_printf("shutdown_in_progress:\t%d\n", r
->shutdown_in_progress
);
74 d_printf("time_to_shutdown:\t%lld\n", (long long)r
->time_to_shutdown
);
75 d_printf("next_audit_record:\t%d\n", r
->next_audit_record
);
78 static void display_query_info_2(struct lsa_AuditEventsInfo
*r
)
81 d_printf("Auditing enabled:\t%d\n", r
->auditing_mode
);
82 d_printf("Auditing categories:\t%d\n", r
->count
);
83 d_printf("Auditsettings:\n");
84 for (i
=0; i
<r
->count
; i
++) {
85 const char *val
= audit_policy_str(talloc_tos(), r
->settings
[i
]);
86 const char *policy
= audit_description_str(i
);
87 d_printf("%s:\t%s\n", policy
, val
);
91 static void display_query_info_3(struct lsa_DomainInfo
*r
)
93 d_printf("Domain Name: %s\n", r
->name
.string
);
94 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
97 static void display_query_info_5(struct lsa_DomainInfo
*r
)
99 d_printf("Domain Name: %s\n", r
->name
.string
);
100 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
103 static void display_query_info_10(struct lsa_AuditFullSetInfo
*r
)
105 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
108 static void display_query_info_11(struct lsa_AuditFullQueryInfo
*r
)
110 d_printf("Shutdown on full: %d\n", r
->shutdown_on_full
);
111 d_printf("Log is full: %d\n", r
->log_is_full
);
114 static void display_query_info_12(struct lsa_DnsDomainInfo
*r
)
116 d_printf("Domain NetBios Name: %s\n", r
->name
.string
);
117 d_printf("Domain DNS Name: %s\n", r
->dns_domain
.string
);
118 d_printf("Domain Forest Name: %s\n", r
->dns_forest
.string
);
119 d_printf("Domain Sid: %s\n", sid_string_tos(r
->sid
));
120 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
124 static void display_lsa_query_info(union lsa_PolicyInformation
*info
,
125 enum lsa_PolicyInfo level
)
129 display_query_info_1(&info
->audit_log
);
132 display_query_info_2(&info
->audit_events
);
135 display_query_info_3(&info
->domain
);
138 display_query_info_5(&info
->account_domain
);
141 display_query_info_10(&info
->auditfullset
);
144 display_query_info_11(&info
->auditfullquery
);
147 display_query_info_12(&info
->dns
);
150 printf("can't display info level: %d\n", level
);
155 static NTSTATUS
cmd_lsa_query_info_policy(struct rpc_pipe_client
*cli
,
156 TALLOC_CTX
*mem_ctx
, int argc
,
159 struct policy_handle pol
;
160 NTSTATUS status
, result
;
161 union lsa_PolicyInformation
*info
= NULL
;
162 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
164 uint32_t info_class
= 3;
167 printf("Usage: %s [info_class]\n", argv
[0]);
172 info_class
= atoi(argv
[1]);
174 switch (info_class
) {
176 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
177 SEC_FLAG_MAXIMUM_ALLOWED
,
180 if (!NT_STATUS_IS_OK(status
))
183 status
= dcerpc_lsa_QueryInfoPolicy2(b
, mem_ctx
,
190 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
191 SEC_FLAG_MAXIMUM_ALLOWED
,
194 if (!NT_STATUS_IS_OK(status
))
197 status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
204 if (!NT_STATUS_IS_OK(status
)) {
208 if (NT_STATUS_IS_OK(result
)) {
209 display_lsa_query_info(info
, info_class
);
212 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
218 /* Resolve a list of names to a list of sids */
220 static NTSTATUS
cmd_lsa_lookup_names(struct rpc_pipe_client
*cli
,
221 TALLOC_CTX
*mem_ctx
, int argc
,
224 struct policy_handle pol
;
225 NTSTATUS status
, result
;
226 struct dom_sid
*sids
;
227 enum lsa_SidType
*types
;
229 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
232 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
236 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
237 SEC_FLAG_MAXIMUM_ALLOWED
,
240 if (!NT_STATUS_IS_OK(status
))
243 status
= rpccli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
244 (const char**)(argv
+ 1), NULL
, 1, &sids
, &types
);
246 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
247 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
250 status
= NT_STATUS_OK
;
254 for (i
= 0; i
< (argc
- 1); i
++) {
256 sid_to_fstring(sid_str
, &sids
[i
]);
257 printf("%s %s (%s: %d)\n", argv
[i
+ 1], sid_str
,
258 sid_type_lookup(types
[i
]), types
[i
]);
261 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
267 /* Resolve a list of names to a list of sids */
269 static NTSTATUS
cmd_lsa_lookup_names_level(struct rpc_pipe_client
*cli
,
270 TALLOC_CTX
*mem_ctx
, int argc
,
273 struct policy_handle pol
;
274 NTSTATUS status
, result
;
275 struct dom_sid
*sids
= NULL
;
276 enum lsa_SidType
*types
= NULL
;
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
,
288 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
))
303 status
= NT_STATUS_OK
;
307 for (i
= 0; i
< (argc
- 2); i
++) {
309 sid_to_fstring(sid_str
, &sids
[i
]);
310 printf("%s %s (%s: %d)\n", argv
[i
+ 2], sid_str
,
311 sid_type_lookup(types
[i
]), types
[i
]);
314 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
320 static NTSTATUS
cmd_lsa_lookup_names4(struct rpc_pipe_client
*cli
,
321 TALLOC_CTX
*mem_ctx
, int argc
,
324 NTSTATUS status
, result
;
327 struct lsa_String
*names
;
328 struct lsa_RefDomainList
*domains
= NULL
;
329 struct lsa_TransSidArray3 sids
;
332 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
335 printf("Usage: %s [name1 [name2 [...]]]\n", argv
[0]);
342 names
= talloc_array(mem_ctx
, struct lsa_String
, num_names
);
343 NT_STATUS_HAVE_NO_MEMORY(names
);
345 for (i
=0; i
< num_names
; i
++) {
346 init_lsa_String(&names
[i
], argv
[i
+1]);
349 status
= dcerpc_lsa_LookupNames4(b
, mem_ctx
,
359 if (!NT_STATUS_IS_OK(status
)) {
362 if (!NT_STATUS_IS_OK(result
)) {
366 if (sids
.count
!= num_names
) {
367 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
370 for (i
= 0; i
< sids
.count
; i
++) {
372 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
373 printf("%s %s (%s: %d)\n", argv
[i
+1], sid_str
,
374 sid_type_lookup(sids
.sids
[i
].sid_type
),
375 sids
.sids
[i
].sid_type
);
381 /* Resolve a list of SIDs to a list of names */
383 static NTSTATUS
cmd_lsa_lookup_sids(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
384 int argc
, const char **argv
)
386 struct policy_handle pol
;
387 NTSTATUS status
, result
;
388 struct dom_sid
*sids
;
391 enum lsa_SidType
*types
;
393 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
396 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
400 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
401 SEC_FLAG_MAXIMUM_ALLOWED
,
404 if (!NT_STATUS_IS_OK(status
))
407 /* Convert arguments to sids */
409 sids
= talloc_array(mem_ctx
, struct dom_sid
, argc
- 1);
412 printf("could not allocate memory for %d sids\n", argc
- 1);
416 for (i
= 0; i
< argc
- 1; i
++)
417 if (!string_to_sid(&sids
[i
], argv
[i
+ 1])) {
418 status
= NT_STATUS_INVALID_SID
;
422 /* Lookup the SIDs */
424 status
= rpccli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
425 &domains
, &names
, &types
);
427 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
428 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
431 status
= NT_STATUS_OK
;
435 for (i
= 0; i
< (argc
- 1); i
++) {
438 sid_to_fstring(sid_str
, &sids
[i
]);
439 if (types
[i
] == SID_NAME_DOMAIN
) {
440 printf("%s %s (%d)\n", sid_str
,
441 domains
[i
] ? domains
[i
] : "*unknown*",
444 printf("%s %s\\%s (%d)\n", sid_str
,
445 domains
[i
] ? domains
[i
] : "*unknown*",
446 names
[i
] ? names
[i
] : "*unknown*",
451 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
457 static NTSTATUS
cmd_lsa_lookup_sids_level(struct rpc_pipe_client
*cli
,
458 TALLOC_CTX
*mem_ctx
, int argc
,
461 struct policy_handle pol
;
462 NTSTATUS status
, result
;
463 struct dom_sid
*sids
= NULL
;
464 char **domains
= NULL
;
466 enum lsa_SidType
*types
= NULL
;
468 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
471 printf("Usage: %s [level] [sid1 [sid2 [...]]]\n", argv
[0]);
475 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
476 SEC_FLAG_MAXIMUM_ALLOWED
,
478 if (!NT_STATUS_IS_OK(status
)) {
482 level
= atoi(argv
[1]);
484 /* Convert arguments to sids */
486 sids
= talloc_array(mem_ctx
, struct dom_sid
, argc
- 2);
488 printf("could not allocate memory for %d sids\n", argc
- 2);
492 for (i
= 0; i
< argc
- 2; i
++) {
493 if (!string_to_sid(&sids
[i
], argv
[i
+ 2])) {
494 status
= NT_STATUS_INVALID_SID
;
499 /* Lookup the SIDs */
501 status
= dcerpc_lsa_lookup_sids_generic(cli
->binding_handle
,
512 if (!NT_STATUS_IS_OK(status
)) {
517 if (!NT_STATUS_IS_OK(status
) && NT_STATUS_V(status
) !=
518 NT_STATUS_V(STATUS_SOME_UNMAPPED
))
523 status
= NT_STATUS_OK
;
527 for (i
= 0; i
< (argc
- 2); i
++) {
530 sid_to_fstring(sid_str
, &sids
[i
]);
531 if (types
[i
] == SID_NAME_DOMAIN
) {
532 printf("%s %s (%d)\n", sid_str
,
533 domains
[i
] ? domains
[i
] : "*unknown*",
536 printf("%s %s\\%s (%d)\n", sid_str
,
537 domains
[i
] ? domains
[i
] : "*unknown*",
538 names
[i
] ? names
[i
] : "*unknown*",
543 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
549 /* Resolve a list of SIDs to a list of names */
551 static NTSTATUS
cmd_lsa_lookup_sids3(struct rpc_pipe_client
*cli
,
553 int argc
, const char **argv
)
555 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
, result
;
557 struct lsa_SidArray sids
;
558 struct lsa_RefDomainList
*domains
= NULL
;
559 struct lsa_TransNameArray2 names
;
561 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
564 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
570 /* Convert arguments to sids */
572 sids
.num_sids
= argc
-1;
573 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
575 printf("could not allocate memory for %d sids\n", sids
.num_sids
);
579 for (i
= 0; i
< sids
.num_sids
; i
++) {
580 sids
.sids
[i
].sid
= talloc(sids
.sids
, struct dom_sid
);
581 if (sids
.sids
[i
].sid
== NULL
) {
582 status
= NT_STATUS_NO_MEMORY
;
585 if (!string_to_sid(sids
.sids
[i
].sid
, argv
[i
+1])) {
586 status
= NT_STATUS_INVALID_SID
;
591 /* Lookup the SIDs */
592 status
= dcerpc_lsa_LookupSids3(b
, mem_ctx
,
601 if (!NT_STATUS_IS_OK(status
)) {
604 if (!NT_STATUS_IS_OK(result
) && NT_STATUS_V(result
) !=
605 NT_STATUS_V(STATUS_SOME_UNMAPPED
)) {
610 status
= NT_STATUS_OK
;
614 for (i
= 0; i
< names
.count
; i
++) {
617 if (i
>= sids
.num_sids
) {
620 sid_to_fstring(sid_str
, sids
.sids
[i
].sid
);
621 printf("%s %s (%d)\n", sid_str
,
622 names
.names
[i
].name
.string
,
623 names
.names
[i
].sid_type
);
631 /* Enumerate list of trusted domains */
633 static NTSTATUS
cmd_lsa_enum_trust_dom(struct rpc_pipe_client
*cli
,
634 TALLOC_CTX
*mem_ctx
, int argc
,
637 struct policy_handle pol
;
638 NTSTATUS status
, result
;
639 struct lsa_DomainList domain_list
;
640 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
642 /* defaults, but may be changed using params */
643 uint32_t enum_ctx
= 0;
645 uint32_t max_size
= (uint32_t)-1;
648 printf("Usage: %s [enum context (0)]\n", argv
[0]);
652 if (argc
== 2 && argv
[1]) {
653 enum_ctx
= atoi(argv
[2]);
656 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
657 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
660 if (!NT_STATUS_IS_OK(status
))
663 status
= STATUS_MORE_ENTRIES
;
665 while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
667 /* Lookup list of trusted domains */
669 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
675 if (!NT_STATUS_IS_OK(status
)) {
678 if (!NT_STATUS_IS_OK(result
) &&
679 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
680 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
685 /* Print results: list of names and sids returned in this
687 for (i
= 0; i
< domain_list
.count
; i
++) {
690 sid_to_fstring(sid_str
, domain_list
.domains
[i
].sid
);
692 domain_list
.domains
[i
].name
.string
?
693 domain_list
.domains
[i
].name
.string
: "*unknown*",
698 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
703 /* Enumerates privileges */
705 static NTSTATUS
cmd_lsa_enum_privilege(struct rpc_pipe_client
*cli
,
706 TALLOC_CTX
*mem_ctx
, int argc
,
709 struct policy_handle pol
;
710 NTSTATUS status
, result
;
711 struct lsa_PrivArray priv_array
;
712 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
714 uint32_t enum_context
=0;
715 uint32_t pref_max_length
=0x1000;
719 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
724 enum_context
=atoi(argv
[1]);
727 pref_max_length
=atoi(argv
[2]);
729 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
730 SEC_FLAG_MAXIMUM_ALLOWED
,
733 if (!NT_STATUS_IS_OK(status
))
736 status
= dcerpc_lsa_EnumPrivs(b
, mem_ctx
,
742 if (!NT_STATUS_IS_OK(status
))
744 if (!NT_STATUS_IS_OK(result
)) {
750 printf("found %d privileges\n\n", priv_array
.count
);
752 for (i
= 0; i
< priv_array
.count
; i
++) {
753 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
754 priv_array
.privs
[i
].name
.string
? priv_array
.privs
[i
].name
.string
: "*unknown*",
755 priv_array
.privs
[i
].luid
.high
,
756 priv_array
.privs
[i
].luid
.low
,
757 priv_array
.privs
[i
].luid
.high
,
758 priv_array
.privs
[i
].luid
.low
);
761 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
766 /* Get privilege name */
768 static NTSTATUS
cmd_lsa_get_dispname(struct rpc_pipe_client
*cli
,
769 TALLOC_CTX
*mem_ctx
, int argc
,
772 struct policy_handle pol
;
773 NTSTATUS status
, result
;
774 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
777 uint16_t lang_id_sys
=0;
778 uint16_t lang_id_desc
;
779 struct lsa_String lsa_name
;
780 struct lsa_StringLarge
*description
= NULL
;
783 printf("Usage: %s privilege name\n", argv
[0]);
787 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
788 SEC_FLAG_MAXIMUM_ALLOWED
,
791 if (!NT_STATUS_IS_OK(status
))
794 init_lsa_String(&lsa_name
, argv
[1]);
796 status
= dcerpc_lsa_LookupPrivDisplayName(b
, mem_ctx
,
804 if (!NT_STATUS_IS_OK(status
))
806 if (!NT_STATUS_IS_OK(result
)) {
812 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
->string
, lang_id_desc
);
814 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
819 /* Enumerate the LSA SIDS */
821 static NTSTATUS
cmd_lsa_enum_sids(struct rpc_pipe_client
*cli
,
822 TALLOC_CTX
*mem_ctx
, int argc
,
825 struct policy_handle pol
;
826 NTSTATUS status
, result
;
827 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
829 uint32_t enum_context
=0;
830 uint32_t pref_max_length
=0x1000;
831 struct lsa_SidArray sid_array
;
835 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
840 enum_context
=atoi(argv
[1]);
843 pref_max_length
=atoi(argv
[2]);
845 status
= rpccli_lsa_open_policy(cli
, mem_ctx
, True
,
846 SEC_FLAG_MAXIMUM_ALLOWED
,
849 if (!NT_STATUS_IS_OK(status
))
852 status
= dcerpc_lsa_EnumAccounts(b
, mem_ctx
,
858 if (!NT_STATUS_IS_OK(status
))
860 if (!NT_STATUS_IS_OK(result
)) {
866 printf("found %d SIDs\n\n", sid_array
.num_sids
);
868 for (i
= 0; i
< sid_array
.num_sids
; i
++) {
871 sid_to_fstring(sid_str
, sid_array
.sids
[i
].sid
);
872 printf("%s\n", sid_str
);
875 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
880 /* Create a new account */
882 static NTSTATUS
cmd_lsa_create_account(struct rpc_pipe_client
*cli
,
883 TALLOC_CTX
*mem_ctx
, int argc
,
886 struct policy_handle dom_pol
;
887 struct policy_handle user_pol
;
888 NTSTATUS status
, result
;
889 uint32_t des_access
= 0x000f000f;
890 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
895 printf("Usage: %s SID\n", argv
[0]);
899 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
900 if (!NT_STATUS_IS_OK(status
))
903 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
904 SEC_FLAG_MAXIMUM_ALLOWED
,
907 if (!NT_STATUS_IS_OK(status
))
910 status
= dcerpc_lsa_CreateAccount(b
, mem_ctx
,
916 if (!NT_STATUS_IS_OK(status
))
918 if (!NT_STATUS_IS_OK(result
)) {
923 printf("Account for SID %s successfully created\n\n", argv
[1]);
924 status
= NT_STATUS_OK
;
926 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
932 /* Enumerate the privileges of an SID */
934 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct rpc_pipe_client
*cli
,
935 TALLOC_CTX
*mem_ctx
, int argc
,
938 struct policy_handle dom_pol
;
939 struct policy_handle user_pol
;
940 NTSTATUS status
, result
;
941 uint32_t access_desired
= 0x000f000f;
943 struct lsa_PrivilegeSet
*privs
= NULL
;
945 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
948 printf("Usage: %s SID\n", argv
[0]);
952 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
953 if (!NT_STATUS_IS_OK(status
))
956 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
957 SEC_FLAG_MAXIMUM_ALLOWED
,
960 if (!NT_STATUS_IS_OK(status
))
963 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
969 if (!NT_STATUS_IS_OK(status
))
971 if (!NT_STATUS_IS_OK(result
)) {
976 status
= dcerpc_lsa_EnumPrivsAccount(b
, mem_ctx
,
980 if (!NT_STATUS_IS_OK(status
))
982 if (!NT_STATUS_IS_OK(result
)) {
988 printf("found %d privileges for SID %s\n\n", privs
->count
, argv
[1]);
989 printf("high\tlow\tattribute\n");
991 for (i
= 0; i
< privs
->count
; i
++) {
992 printf("%u\t%u\t%u\n",
993 privs
->set
[i
].luid
.high
,
994 privs
->set
[i
].luid
.low
,
995 privs
->set
[i
].attribute
);
998 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1004 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
1006 static NTSTATUS
cmd_lsa_enum_acct_rights(struct rpc_pipe_client
*cli
,
1007 TALLOC_CTX
*mem_ctx
, int argc
,
1010 struct policy_handle dom_pol
;
1011 NTSTATUS status
, result
;
1013 struct lsa_RightSet rights
;
1014 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1019 printf("Usage: %s SID\n", argv
[0]);
1020 return NT_STATUS_OK
;
1023 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1024 if (!NT_STATUS_IS_OK(status
))
1027 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1028 SEC_FLAG_MAXIMUM_ALLOWED
,
1031 if (!NT_STATUS_IS_OK(status
))
1034 status
= dcerpc_lsa_EnumAccountRights(b
, mem_ctx
,
1039 if (!NT_STATUS_IS_OK(status
))
1041 if (!NT_STATUS_IS_OK(result
)) {
1046 printf("found %d privileges for SID %s\n", rights
.count
,
1047 sid_string_tos(&sid
));
1049 for (i
= 0; i
< rights
.count
; i
++) {
1050 printf("\t%s\n", rights
.names
[i
].string
);
1053 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1059 /* add some privileges to a SID via LsaAddAccountRights */
1061 static NTSTATUS
cmd_lsa_add_acct_rights(struct rpc_pipe_client
*cli
,
1062 TALLOC_CTX
*mem_ctx
, int argc
,
1065 struct policy_handle dom_pol
;
1066 NTSTATUS status
, result
;
1067 struct lsa_RightSet rights
;
1070 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1073 printf("Usage: %s SID [rights...]\n", argv
[0]);
1074 return NT_STATUS_OK
;
1077 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1078 if (!NT_STATUS_IS_OK(status
))
1081 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1082 SEC_FLAG_MAXIMUM_ALLOWED
,
1085 if (!NT_STATUS_IS_OK(status
))
1088 rights
.count
= argc
-2;
1089 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
1091 if (!rights
.names
) {
1092 return NT_STATUS_NO_MEMORY
;
1095 for (i
=0; i
<argc
-2; i
++) {
1096 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
1099 status
= dcerpc_lsa_AddAccountRights(b
, mem_ctx
,
1104 if (!NT_STATUS_IS_OK(status
))
1106 if (!NT_STATUS_IS_OK(result
)) {
1111 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1117 /* remove some privileges to a SID via LsaRemoveAccountRights */
1119 static NTSTATUS
cmd_lsa_remove_acct_rights(struct rpc_pipe_client
*cli
,
1120 TALLOC_CTX
*mem_ctx
, int argc
,
1123 struct policy_handle dom_pol
;
1124 NTSTATUS status
, result
;
1125 struct lsa_RightSet rights
;
1128 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1131 printf("Usage: %s SID [rights...]\n", argv
[0]);
1132 return NT_STATUS_OK
;
1135 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1136 if (!NT_STATUS_IS_OK(status
))
1139 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1140 SEC_FLAG_MAXIMUM_ALLOWED
,
1143 if (!NT_STATUS_IS_OK(status
))
1146 rights
.count
= argc
-2;
1147 rights
.names
= talloc_array(mem_ctx
, struct lsa_StringLarge
,
1149 if (!rights
.names
) {
1150 return NT_STATUS_NO_MEMORY
;
1153 for (i
=0; i
<argc
-2; i
++) {
1154 init_lsa_StringLarge(&rights
.names
[i
], argv
[i
+2]);
1157 status
= dcerpc_lsa_RemoveAccountRights(b
, mem_ctx
,
1163 if (!NT_STATUS_IS_OK(status
))
1165 if (!NT_STATUS_IS_OK(result
)) {
1170 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1177 /* Get a privilege value given its name */
1179 static NTSTATUS
cmd_lsa_lookup_priv_value(struct rpc_pipe_client
*cli
,
1180 TALLOC_CTX
*mem_ctx
, int argc
,
1183 struct policy_handle pol
;
1184 NTSTATUS status
, result
;
1185 struct lsa_LUID luid
;
1186 struct lsa_String name
;
1187 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1190 printf("Usage: %s name\n", argv
[0]);
1191 return NT_STATUS_OK
;
1194 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1195 SEC_FLAG_MAXIMUM_ALLOWED
,
1198 if (!NT_STATUS_IS_OK(status
))
1201 init_lsa_String(&name
, argv
[1]);
1203 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1208 if (!NT_STATUS_IS_OK(status
))
1210 if (!NT_STATUS_IS_OK(result
)) {
1217 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
1219 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1224 /* Query LSA security object */
1226 static NTSTATUS
cmd_lsa_query_secobj(struct rpc_pipe_client
*cli
,
1227 TALLOC_CTX
*mem_ctx
, int argc
,
1230 struct policy_handle pol
;
1231 NTSTATUS status
, result
;
1232 struct sec_desc_buf
*sdb
;
1233 uint32_t sec_info
= SECINFO_DACL
;
1234 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1236 if (argc
< 1 || argc
> 2) {
1237 printf("Usage: %s [sec_info]\n", argv
[0]);
1238 return NT_STATUS_OK
;
1241 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1242 SEC_FLAG_MAXIMUM_ALLOWED
,
1246 sscanf(argv
[1], "%x", &sec_info
);
1248 if (!NT_STATUS_IS_OK(status
))
1251 status
= dcerpc_lsa_QuerySecurity(b
, mem_ctx
,
1256 if (!NT_STATUS_IS_OK(status
))
1258 if (!NT_STATUS_IS_OK(result
)) {
1265 display_sec_desc(sdb
->sd
);
1267 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1272 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword
*p
,
1273 DATA_BLOB session_key
)
1275 char *pwd
, *pwd_old
;
1277 DATA_BLOB data
= data_blob_const(p
->password
->data
, p
->password
->length
);
1278 DATA_BLOB data_old
= data_blob_const(p
->old_password
->data
, p
->old_password
->length
);
1280 pwd
= sess_decrypt_string(talloc_tos(), &data
, &session_key
);
1281 pwd_old
= sess_decrypt_string(talloc_tos(), &data_old
, &session_key
);
1283 d_printf("Password:\t%s\n", pwd
);
1284 d_printf("Old Password:\t%s\n", pwd_old
);
1287 talloc_free(pwd_old
);
1290 static void display_trust_dom_info(TALLOC_CTX
*mem_ctx
,
1291 union lsa_TrustedDomainInfo
*info
,
1292 enum lsa_TrustDomInfoEnum info_class
,
1293 DATA_BLOB session_key
)
1295 switch (info_class
) {
1296 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD
:
1297 display_trust_dom_info_4(&info
->password
, session_key
);
1300 const char *str
= NULL
;
1301 str
= NDR_PRINT_UNION_STRING(mem_ctx
,
1302 lsa_TrustedDomainInfo
,
1305 d_printf("%s\n", str
);
1312 static NTSTATUS
cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client
*cli
,
1313 TALLOC_CTX
*mem_ctx
, int argc
,
1316 struct policy_handle pol
;
1317 NTSTATUS status
, result
;
1318 struct dom_sid dom_sid
;
1319 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1320 union lsa_TrustedDomainInfo
*info
= NULL
;
1321 enum lsa_TrustDomInfoEnum info_class
= 1;
1322 DATA_BLOB session_key
;
1323 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1325 if (argc
> 3 || argc
< 2) {
1326 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1327 return NT_STATUS_OK
;
1330 if (!string_to_sid(&dom_sid
, argv
[1]))
1331 return NT_STATUS_NO_MEMORY
;
1334 info_class
= atoi(argv
[2]);
1336 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1338 if (!NT_STATUS_IS_OK(status
))
1341 status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
1347 if (!NT_STATUS_IS_OK(status
))
1349 if (!NT_STATUS_IS_OK(result
)) {
1354 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1355 if (!NT_STATUS_IS_OK(status
)) {
1356 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1360 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1363 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1368 static NTSTATUS
cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client
*cli
,
1369 TALLOC_CTX
*mem_ctx
, int argc
,
1372 struct policy_handle pol
;
1373 NTSTATUS status
, result
;
1374 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1375 union lsa_TrustedDomainInfo
*info
= NULL
;
1376 enum lsa_TrustDomInfoEnum info_class
= 1;
1377 struct lsa_String trusted_domain
;
1378 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1379 DATA_BLOB session_key
;
1381 if (argc
> 3 || argc
< 2) {
1382 printf("Usage: %s [name] [info_class]\n", argv
[0]);
1383 return NT_STATUS_OK
;
1387 info_class
= atoi(argv
[2]);
1389 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1391 if (!NT_STATUS_IS_OK(status
))
1394 init_lsa_String(&trusted_domain
, argv
[1]);
1396 status
= dcerpc_lsa_QueryTrustedDomainInfoByName(b
, mem_ctx
,
1402 if (!NT_STATUS_IS_OK(status
))
1404 if (!NT_STATUS_IS_OK(result
)) {
1409 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1410 if (!NT_STATUS_IS_OK(status
)) {
1411 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1415 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1418 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1423 static NTSTATUS
cmd_lsa_set_trustdominfo(struct rpc_pipe_client
*cli
,
1424 TALLOC_CTX
*mem_ctx
, int argc
,
1427 struct policy_handle pol
, trustdom_pol
;
1428 NTSTATUS status
, result
;
1429 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1430 union lsa_TrustedDomainInfo info
;
1431 struct dom_sid dom_sid
;
1432 enum lsa_TrustDomInfoEnum info_class
= 1;
1433 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1435 if (argc
> 4 || argc
< 3) {
1436 printf("Usage: %s [sid] [info_class] [value]\n", argv
[0]);
1437 return NT_STATUS_OK
;
1440 if (!string_to_sid(&dom_sid
, argv
[1])) {
1441 return NT_STATUS_NO_MEMORY
;
1445 info_class
= atoi(argv
[2]);
1447 switch (info_class
) {
1448 case 13: /* LSA_TRUSTED_DOMAIN_SUPPORTED_ENCRYPTION_TYPES */
1449 info
.enc_types
.enc_types
= atoi(argv
[3]);
1452 return NT_STATUS_INVALID_PARAMETER
;
1455 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1456 if (!NT_STATUS_IS_OK(status
)) {
1460 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
1466 if (!NT_STATUS_IS_OK(status
)) {
1469 if (!NT_STATUS_IS_OK(result
)) {
1474 status
= dcerpc_lsa_SetInformationTrustedDomain(b
, mem_ctx
,
1479 if (!NT_STATUS_IS_OK(status
)) {
1482 if (!NT_STATUS_IS_OK(result
)) {
1487 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_pol
, &result
);
1488 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1493 static NTSTATUS
cmd_lsa_query_trustdominfo(struct rpc_pipe_client
*cli
,
1494 TALLOC_CTX
*mem_ctx
, int argc
,
1497 struct policy_handle pol
, trustdom_pol
;
1498 NTSTATUS status
, result
;
1499 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1500 union lsa_TrustedDomainInfo
*info
= NULL
;
1501 struct dom_sid dom_sid
;
1502 enum lsa_TrustDomInfoEnum info_class
= 1;
1503 DATA_BLOB session_key
;
1504 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1506 if (argc
> 3 || argc
< 2) {
1507 printf("Usage: %s [sid] [info_class]\n", argv
[0]);
1508 return NT_STATUS_OK
;
1511 if (!string_to_sid(&dom_sid
, argv
[1]))
1512 return NT_STATUS_NO_MEMORY
;
1516 info_class
= atoi(argv
[2]);
1518 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
, access_mask
, &pol
);
1520 if (!NT_STATUS_IS_OK(status
))
1523 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
1529 if (!NT_STATUS_IS_OK(status
))
1531 if (!NT_STATUS_IS_OK(result
)) {
1536 status
= dcerpc_lsa_QueryTrustedDomainInfo(b
, mem_ctx
,
1541 if (!NT_STATUS_IS_OK(status
))
1543 if (!NT_STATUS_IS_OK(result
)) {
1548 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1549 if (!NT_STATUS_IS_OK(status
)) {
1550 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(status
)));
1554 display_trust_dom_info(mem_ctx
, info
, info_class
, session_key
);
1557 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
1562 static NTSTATUS
cmd_lsa_get_username(struct rpc_pipe_client
*cli
,
1563 TALLOC_CTX
*mem_ctx
, int argc
,
1566 NTSTATUS status
, result
;
1567 const char *servername
= cli
->desthost
;
1568 struct lsa_String
*account_name
= NULL
;
1569 struct lsa_String
*authority_name
= NULL
;
1570 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1573 printf("Usage: %s servername\n", argv
[0]);
1574 return NT_STATUS_OK
;
1577 status
= dcerpc_lsa_GetUserName(b
, mem_ctx
,
1582 if (!NT_STATUS_IS_OK(status
)) {
1585 if (!NT_STATUS_IS_OK(result
)) {
1592 printf("Account Name: %s, Authority Name: %s\n",
1593 account_name
->string
, authority_name
? authority_name
->string
:
1600 static NTSTATUS
cmd_lsa_add_priv(struct rpc_pipe_client
*cli
,
1601 TALLOC_CTX
*mem_ctx
, int argc
,
1604 struct policy_handle dom_pol
, user_pol
;
1605 NTSTATUS status
, result
;
1606 struct lsa_PrivilegeSet privs
;
1607 struct lsa_LUIDAttribute
*set
= NULL
;
1610 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1615 printf("Usage: %s SID [rights...]\n", argv
[0]);
1616 return NT_STATUS_OK
;
1619 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1620 if (!NT_STATUS_IS_OK(status
)) {
1624 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1625 SEC_FLAG_MAXIMUM_ALLOWED
,
1628 if (!NT_STATUS_IS_OK(status
)) {
1632 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1635 SEC_FLAG_MAXIMUM_ALLOWED
,
1638 if (!NT_STATUS_IS_OK(status
)) {
1641 if (!NT_STATUS_IS_OK(result
)) {
1646 for (i
=2; i
<argc
; i
++) {
1648 struct lsa_String priv_name
;
1649 struct lsa_LUID luid
;
1651 init_lsa_String(&priv_name
, argv
[i
]);
1653 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1658 if (!NT_STATUS_IS_OK(status
)) {
1661 if (!NT_STATUS_IS_OK(result
)) {
1667 set
= talloc_realloc(mem_ctx
, set
,
1668 struct lsa_LUIDAttribute
,
1671 return NT_STATUS_NO_MEMORY
;
1674 set
[privs
.count
-1].luid
= luid
;
1675 set
[privs
.count
-1].attribute
= 0;
1680 status
= dcerpc_lsa_AddPrivilegesToAccount(b
, mem_ctx
,
1684 if (!NT_STATUS_IS_OK(status
)) {
1687 if (!NT_STATUS_IS_OK(result
)) {
1692 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1693 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1698 static NTSTATUS
cmd_lsa_del_priv(struct rpc_pipe_client
*cli
,
1699 TALLOC_CTX
*mem_ctx
, int argc
,
1702 struct policy_handle dom_pol
, user_pol
;
1703 NTSTATUS status
, result
;
1704 struct lsa_PrivilegeSet privs
;
1705 struct lsa_LUIDAttribute
*set
= NULL
;
1708 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1713 printf("Usage: %s SID [rights...]\n", argv
[0]);
1714 return NT_STATUS_OK
;
1717 status
= name_to_sid(cli
, mem_ctx
, &sid
, argv
[1]);
1718 if (!NT_STATUS_IS_OK(status
)) {
1722 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
, True
,
1723 SEC_FLAG_MAXIMUM_ALLOWED
,
1726 if (!NT_STATUS_IS_OK(status
)) {
1730 status
= dcerpc_lsa_OpenAccount(b
, mem_ctx
,
1733 SEC_FLAG_MAXIMUM_ALLOWED
,
1736 if (!NT_STATUS_IS_OK(status
)) {
1739 if (!NT_STATUS_IS_OK(result
)) {
1744 for (i
=2; i
<argc
; i
++) {
1746 struct lsa_String priv_name
;
1747 struct lsa_LUID luid
;
1749 init_lsa_String(&priv_name
, argv
[i
]);
1751 status
= dcerpc_lsa_LookupPrivValue(b
, mem_ctx
,
1756 if (!NT_STATUS_IS_OK(status
)) {
1759 if (!NT_STATUS_IS_OK(result
)) {
1765 set
= talloc_realloc(mem_ctx
, set
,
1766 struct lsa_LUIDAttribute
,
1769 return NT_STATUS_NO_MEMORY
;
1772 set
[privs
.count
-1].luid
= luid
;
1773 set
[privs
.count
-1].attribute
= 0;
1779 status
= dcerpc_lsa_RemovePrivilegesFromAccount(b
, mem_ctx
,
1784 if (!NT_STATUS_IS_OK(status
)) {
1787 if (!NT_STATUS_IS_OK(result
)) {
1792 dcerpc_lsa_Close(b
, mem_ctx
, &user_pol
, &result
);
1793 dcerpc_lsa_Close(b
, mem_ctx
, &dom_pol
, &result
);
1798 static NTSTATUS
cmd_lsa_create_secret(struct rpc_pipe_client
*cli
,
1799 TALLOC_CTX
*mem_ctx
, int argc
,
1802 NTSTATUS status
, result
;
1803 struct policy_handle handle
, sec_handle
;
1804 struct lsa_String name
;
1805 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1808 printf("Usage: %s name\n", argv
[0]);
1809 return NT_STATUS_OK
;
1812 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1814 SEC_FLAG_MAXIMUM_ALLOWED
,
1816 if (!NT_STATUS_IS_OK(status
)) {
1820 init_lsa_String(&name
, argv
[1]);
1822 status
= dcerpc_lsa_CreateSecret(b
, mem_ctx
,
1825 SEC_FLAG_MAXIMUM_ALLOWED
,
1828 if (!NT_STATUS_IS_OK(status
)) {
1831 if (!NT_STATUS_IS_OK(result
)) {
1837 if (is_valid_policy_hnd(&sec_handle
)) {
1838 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1840 if (is_valid_policy_hnd(&handle
)) {
1841 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1847 static NTSTATUS
cmd_lsa_delete_secret(struct rpc_pipe_client
*cli
,
1848 TALLOC_CTX
*mem_ctx
, int argc
,
1851 NTSTATUS status
, result
;
1852 struct policy_handle handle
, sec_handle
;
1853 struct lsa_String name
;
1854 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1857 printf("Usage: %s name\n", argv
[0]);
1858 return NT_STATUS_OK
;
1861 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1863 SEC_FLAG_MAXIMUM_ALLOWED
,
1865 if (!NT_STATUS_IS_OK(status
)) {
1869 init_lsa_String(&name
, argv
[1]);
1871 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1874 SEC_FLAG_MAXIMUM_ALLOWED
,
1877 if (!NT_STATUS_IS_OK(status
)) {
1880 if (!NT_STATUS_IS_OK(result
)) {
1885 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
1888 if (!NT_STATUS_IS_OK(status
)) {
1891 if (!NT_STATUS_IS_OK(result
)) {
1897 if (is_valid_policy_hnd(&sec_handle
)) {
1898 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1900 if (is_valid_policy_hnd(&handle
)) {
1901 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
1907 static NTSTATUS
cmd_lsa_query_secret(struct rpc_pipe_client
*cli
,
1908 TALLOC_CTX
*mem_ctx
, int argc
,
1911 NTSTATUS status
, result
;
1912 struct policy_handle handle
, sec_handle
;
1913 struct lsa_String name
;
1914 struct lsa_DATA_BUF_PTR new_val
;
1915 NTTIME new_mtime
= 0;
1916 struct lsa_DATA_BUF_PTR old_val
;
1917 NTTIME old_mtime
= 0;
1918 DATA_BLOB session_key
;
1919 DATA_BLOB new_blob
= data_blob_null
;
1920 DATA_BLOB old_blob
= data_blob_null
;
1921 char *new_secret
, *old_secret
;
1922 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1925 printf("Usage: %s name\n", argv
[0]);
1926 return NT_STATUS_OK
;
1929 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
1931 SEC_FLAG_MAXIMUM_ALLOWED
,
1933 if (!NT_STATUS_IS_OK(status
)) {
1937 init_lsa_String(&name
, argv
[1]);
1939 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
1942 SEC_FLAG_MAXIMUM_ALLOWED
,
1945 if (!NT_STATUS_IS_OK(status
)) {
1948 if (!NT_STATUS_IS_OK(result
)) {
1953 ZERO_STRUCT(new_val
);
1954 ZERO_STRUCT(old_val
);
1956 status
= dcerpc_lsa_QuerySecret(b
, mem_ctx
,
1963 if (!NT_STATUS_IS_OK(status
)) {
1966 if (!NT_STATUS_IS_OK(result
)) {
1971 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
1972 if (!NT_STATUS_IS_OK(status
)) {
1977 new_blob
= data_blob_const(new_val
.buf
->data
, new_val
.buf
->length
);
1980 old_blob
= data_blob_const(old_val
.buf
->data
, old_val
.buf
->length
);
1983 new_secret
= sess_decrypt_string(mem_ctx
, &new_blob
, &session_key
);
1984 old_secret
= sess_decrypt_string(mem_ctx
, &old_blob
, &session_key
);
1986 d_printf("new secret: %s\n", new_secret
);
1989 d_printf("old secret: %s\n", old_secret
);
1993 if (is_valid_policy_hnd(&sec_handle
)) {
1994 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
1996 if (is_valid_policy_hnd(&handle
)) {
1997 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2003 static NTSTATUS
cmd_lsa_set_secret(struct rpc_pipe_client
*cli
,
2004 TALLOC_CTX
*mem_ctx
, int argc
,
2007 NTSTATUS status
, result
;
2008 struct policy_handle handle
, sec_handle
;
2009 struct lsa_String name
;
2010 struct lsa_DATA_BUF new_val
;
2011 struct lsa_DATA_BUF old_val
;
2013 DATA_BLOB session_key
;
2014 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2017 printf("Usage: %s name secret\n", argv
[0]);
2018 return NT_STATUS_OK
;
2021 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2023 SEC_FLAG_MAXIMUM_ALLOWED
,
2025 if (!NT_STATUS_IS_OK(status
)) {
2029 init_lsa_String(&name
, argv
[1]);
2031 status
= dcerpc_lsa_OpenSecret(b
, mem_ctx
,
2034 SEC_FLAG_MAXIMUM_ALLOWED
,
2037 if (!NT_STATUS_IS_OK(status
)) {
2040 if (!NT_STATUS_IS_OK(result
)) {
2045 ZERO_STRUCT(new_val
);
2046 ZERO_STRUCT(old_val
);
2048 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2049 if (!NT_STATUS_IS_OK(status
)) {
2053 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
2055 new_val
.length
= enc_key
.length
;
2056 new_val
.size
= enc_key
.length
;
2057 new_val
.data
= enc_key
.data
;
2059 status
= dcerpc_lsa_SetSecret(b
, mem_ctx
,
2064 if (!NT_STATUS_IS_OK(status
)) {
2067 if (!NT_STATUS_IS_OK(result
)) {
2073 if (is_valid_policy_hnd(&sec_handle
)) {
2074 dcerpc_lsa_Close(b
, mem_ctx
, &sec_handle
, &result
);
2076 if (is_valid_policy_hnd(&handle
)) {
2077 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2083 static NTSTATUS
cmd_lsa_retrieve_private_data(struct rpc_pipe_client
*cli
,
2084 TALLOC_CTX
*mem_ctx
, int argc
,
2087 NTSTATUS status
, result
;
2088 struct policy_handle handle
;
2089 struct lsa_String name
;
2090 struct lsa_DATA_BUF
*val
;
2091 DATA_BLOB session_key
;
2092 DATA_BLOB blob
= data_blob_null
;
2094 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2097 printf("Usage: %s name\n", argv
[0]);
2098 return NT_STATUS_OK
;
2101 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2103 SEC_FLAG_MAXIMUM_ALLOWED
,
2105 if (!NT_STATUS_IS_OK(status
)) {
2109 init_lsa_String(&name
, argv
[1]);
2113 status
= dcerpc_lsa_RetrievePrivateData(b
, mem_ctx
,
2118 if (!NT_STATUS_IS_OK(status
)) {
2121 if (!NT_STATUS_IS_OK(result
)) {
2126 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2127 if (!NT_STATUS_IS_OK(status
)) {
2132 blob
= data_blob_const(val
->data
, val
->length
);
2135 secret
= sess_decrypt_string(mem_ctx
, &blob
, &session_key
);
2137 d_printf("secret: %s\n", secret
);
2141 if (is_valid_policy_hnd(&handle
)) {
2142 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2148 static NTSTATUS
cmd_lsa_store_private_data(struct rpc_pipe_client
*cli
,
2149 TALLOC_CTX
*mem_ctx
, int argc
,
2152 NTSTATUS status
, result
;
2153 struct policy_handle handle
;
2154 struct lsa_String name
;
2155 struct lsa_DATA_BUF val
;
2156 DATA_BLOB session_key
;
2158 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2161 printf("Usage: %s name secret\n", argv
[0]);
2162 return NT_STATUS_OK
;
2165 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2167 SEC_FLAG_MAXIMUM_ALLOWED
,
2169 if (!NT_STATUS_IS_OK(status
)) {
2173 init_lsa_String(&name
, argv
[1]);
2177 status
= cli_get_session_key(mem_ctx
, cli
, &session_key
);
2178 if (!NT_STATUS_IS_OK(status
)) {
2182 enc_key
= sess_encrypt_string(argv
[2], &session_key
);
2184 val
.length
= enc_key
.length
;
2185 val
.size
= enc_key
.length
;
2186 val
.data
= enc_key
.data
;
2188 status
= dcerpc_lsa_StorePrivateData(b
, mem_ctx
,
2193 if (!NT_STATUS_IS_OK(status
)) {
2196 if (!NT_STATUS_IS_OK(result
)) {
2202 if (is_valid_policy_hnd(&handle
)) {
2203 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2209 static NTSTATUS
cmd_lsa_create_trusted_domain(struct rpc_pipe_client
*cli
,
2210 TALLOC_CTX
*mem_ctx
, int argc
,
2213 NTSTATUS status
, result
;
2214 struct policy_handle handle
, trustdom_handle
;
2216 struct lsa_DomainInfo info
;
2217 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2220 printf("Usage: %s name sid\n", argv
[0]);
2221 return NT_STATUS_OK
;
2224 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2226 SEC_FLAG_MAXIMUM_ALLOWED
,
2228 if (!NT_STATUS_IS_OK(status
)) {
2232 init_lsa_StringLarge(&info
.name
, argv
[1]);
2234 string_to_sid(&sid
, argv
[2]);
2236 status
= dcerpc_lsa_CreateTrustedDomain(b
, mem_ctx
,
2239 SEC_FLAG_MAXIMUM_ALLOWED
,
2242 if (!NT_STATUS_IS_OK(status
)) {
2245 if (!NT_STATUS_IS_OK(result
)) {
2251 if (is_valid_policy_hnd(&trustdom_handle
)) {
2252 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2255 if (is_valid_policy_hnd(&handle
)) {
2256 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2262 static NTSTATUS
cmd_lsa_delete_trusted_domain(struct rpc_pipe_client
*cli
,
2263 TALLOC_CTX
*mem_ctx
, int argc
,
2266 NTSTATUS status
, result
;
2267 struct policy_handle handle
, trustdom_handle
;
2268 struct lsa_String name
;
2269 struct dom_sid
*sid
= NULL
;
2270 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
2273 printf("Usage: %s name\n", argv
[0]);
2274 return NT_STATUS_OK
;
2277 status
= rpccli_lsa_open_policy2(cli
, mem_ctx
,
2279 SEC_FLAG_MAXIMUM_ALLOWED
,
2281 if (!NT_STATUS_IS_OK(status
)) {
2285 init_lsa_String(&name
, argv
[1]);
2287 status
= dcerpc_lsa_OpenTrustedDomainByName(b
, mem_ctx
,
2290 SEC_FLAG_MAXIMUM_ALLOWED
,
2293 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
)) {
2298 uint32_t resume_handle
= 0;
2299 struct lsa_DomainList domains
;
2302 status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
2308 if (!NT_STATUS_IS_OK(status
)) {
2311 if (!NT_STATUS_IS_OK(result
)) {
2316 for (i
=0; i
< domains
.count
; i
++) {
2317 if (strequal(domains
.domains
[i
].name
.string
, argv
[1])) {
2318 sid
= domains
.domains
[i
].sid
;
2324 return NT_STATUS_INVALID_SID
;
2328 status
= dcerpc_lsa_OpenTrustedDomain(b
, mem_ctx
,
2331 SEC_FLAG_MAXIMUM_ALLOWED
,
2334 if (!NT_STATUS_IS_OK(status
)) {
2337 if (!NT_STATUS_IS_OK(result
)) {
2343 status
= dcerpc_lsa_DeleteObject(b
, mem_ctx
,
2346 if (!NT_STATUS_IS_OK(status
)) {
2349 if (!NT_STATUS_IS_OK(result
)) {
2355 if (is_valid_policy_hnd(&trustdom_handle
)) {
2356 dcerpc_lsa_Close(b
, mem_ctx
, &trustdom_handle
, &result
);
2359 if (is_valid_policy_hnd(&handle
)) {
2360 dcerpc_lsa_Close(b
, mem_ctx
, &handle
, &result
);
2367 /* List of commands exported by this module */
2369 struct cmd_set lsarpc_commands
[] = {
2373 { "lsaquery", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_info_policy
, NULL
, &ndr_table_lsarpc
, NULL
, "Query info policy", "" },
2374 { "lookupsids", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2375 { "lookupsids3", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids3
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2376 { "lookupsids_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_sids_level
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert SIDs to names", "" },
2377 { "lookupnames", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2378 { "lookupnames4", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names4
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2379 { "lookupnames_level", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_names_level
, NULL
, &ndr_table_lsarpc
, NULL
, "Convert names to SIDs", "" },
2380 { "enumtrust", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_trust_dom
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
2381 { "enumprivs", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privilege
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate privileges", "" },
2382 { "getdispname", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_dispname
, NULL
, &ndr_table_lsarpc
, NULL
, "Get the privilege name", "" },
2383 { "lsaenumsid", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_sids
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the LSA SIDS", "" },
2384 { "lsacreateaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_account
, NULL
, &ndr_table_lsarpc
, NULL
, "Create a new lsa account", "" },
2385 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_privsaccounts
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the privileges of an SID", "" },
2386 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_enum_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Enumerate the rights of an SID", "" },
2387 { "lsaaddpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Assign a privilege to a SID", "" },
2388 { "lsadelpriv", RPC_RTYPE_NTSTATUS
, cmd_lsa_del_priv
, NULL
, &ndr_table_lsarpc
, NULL
, "Revoke a privilege from a SID", "" },
2389 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_add_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Add rights to an account", "" },
2390 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS
, cmd_lsa_remove_acct_rights
, NULL
, &ndr_table_lsarpc
, NULL
, "Remove rights from an account", "" },
2391 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS
, cmd_lsa_lookup_priv_value
, NULL
, &ndr_table_lsarpc
, NULL
, "Get a privilege value given its name", "" },
2392 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secobj
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA security object", "" },
2393 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2394 { "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", "" },
2395 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS
, cmd_lsa_query_trustdominfobysid
, NULL
, &ndr_table_lsarpc
, NULL
, "Query LSA trusted domains info (given a SID)", "" },
2396 { "lsasettrustdominfo", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_trustdominfo
, NULL
, &ndr_table_lsarpc
, NULL
, "Set LSA trusted domain info", "" },
2397 { "getusername", RPC_RTYPE_NTSTATUS
, cmd_lsa_get_username
, NULL
, &ndr_table_lsarpc
, NULL
, "Get username", "" },
2398 { "createsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Secret", "" },
2399 { "deletesecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Secret", "" },
2400 { "querysecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_query_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Query Secret", "" },
2401 { "setsecret", RPC_RTYPE_NTSTATUS
, cmd_lsa_set_secret
, NULL
, &ndr_table_lsarpc
, NULL
, "Set Secret", "" },
2402 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_retrieve_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Retrieve Private Data", "" },
2403 { "storeprivatedata", RPC_RTYPE_NTSTATUS
, cmd_lsa_store_private_data
, NULL
, &ndr_table_lsarpc
, NULL
, "Store Private Data", "" },
2404 { "createtrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_create_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Create Trusted Domain", "" },
2405 { "deletetrustdom", RPC_RTYPE_NTSTATUS
, cmd_lsa_delete_trusted_domain
, NULL
, &ndr_table_lsarpc
, NULL
, "Delete Trusted Domain", "" },