2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
7 Copyright (C) Guenther Deschner 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpcclient.h"
25 #include "../libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_lsa.h"
27 #include "../librpc/gen_ndr/cli_lsa.h"
28 #include "rpc_client/cli_lsarpc.h"
29 #include "rpc_client/init_lsa.h"
31 /* useful function to allow entering a name instead of a SID and
32 * looking it up automatically */
33 static NTSTATUS name_to_sid(struct rpc_pipe_client *cli,
35 struct dom_sid *sid, const char *name)
37 struct policy_handle pol;
38 enum lsa_SidType *sid_types;
42 /* maybe its a raw SID */
43 if (strncmp(name, "S-", 2) == 0 &&
44 string_to_sid(sid, name)) {
48 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
49 SEC_FLAG_MAXIMUM_ALLOWED,
51 if (!NT_STATUS_IS_OK(result))
54 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, NULL, 1, &sids, &sid_types);
55 if (!NT_STATUS_IS_OK(result))
58 rpccli_lsa_Close(cli, mem_ctx, &pol);
66 static void display_query_info_1(struct lsa_AuditLogInfo *r)
68 d_printf("percent_full:\t%d\n", r->percent_full);
69 d_printf("maximum_log_size:\t%d\n", r->maximum_log_size);
70 d_printf("retention_time:\t%lld\n", (long long)r->retention_time);
71 d_printf("shutdown_in_progress:\t%d\n", r->shutdown_in_progress);
72 d_printf("time_to_shutdown:\t%lld\n", (long long)r->time_to_shutdown);
73 d_printf("next_audit_record:\t%d\n", r->next_audit_record);
76 static void display_query_info_2(struct lsa_AuditEventsInfo *r)
79 d_printf("Auditing enabled:\t%d\n", r->auditing_mode);
80 d_printf("Auditing categories:\t%d\n", r->count);
81 d_printf("Auditsettings:\n");
82 for (i=0; i<r->count; i++) {
83 const char *val = audit_policy_str(talloc_tos(), r->settings[i]);
84 const char *policy = audit_description_str(i);
85 d_printf("%s:\t%s\n", policy, val);
89 static void display_query_info_3(struct lsa_DomainInfo *r)
91 d_printf("Domain Name: %s\n", r->name.string);
92 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
95 static void display_query_info_5(struct lsa_DomainInfo *r)
97 d_printf("Domain Name: %s\n", r->name.string);
98 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
101 static void display_query_info_10(struct lsa_AuditFullSetInfo *r)
103 d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
106 static void display_query_info_11(struct lsa_AuditFullQueryInfo *r)
108 d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
109 d_printf("Log is full: %d\n", r->log_is_full);
112 static void display_query_info_12(struct lsa_DnsDomainInfo *r)
114 d_printf("Domain NetBios Name: %s\n", r->name.string);
115 d_printf("Domain DNS Name: %s\n", r->dns_domain.string);
116 d_printf("Domain Forest Name: %s\n", r->dns_forest.string);
117 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
118 d_printf("Domain GUID: %s\n", GUID_string(talloc_tos(),
122 static void display_lsa_query_info(union lsa_PolicyInformation *info,
123 enum lsa_PolicyInfo level)
127 display_query_info_1(&info->audit_log);
130 display_query_info_2(&info->audit_events);
133 display_query_info_3(&info->domain);
136 display_query_info_5(&info->account_domain);
139 display_query_info_10(&info->auditfullset);
142 display_query_info_11(&info->auditfullquery);
145 display_query_info_12(&info->dns);
148 printf("can't display info level: %d\n", level);
153 static NTSTATUS cmd_lsa_query_info_policy(struct rpc_pipe_client *cli,
154 TALLOC_CTX *mem_ctx, int argc,
157 struct policy_handle pol;
158 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
159 union lsa_PolicyInformation *info = NULL;
161 uint32 info_class = 3;
164 printf("Usage: %s [info_class]\n", argv[0]);
169 info_class = atoi(argv[1]);
171 switch (info_class) {
173 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
174 SEC_FLAG_MAXIMUM_ALLOWED,
177 if (!NT_STATUS_IS_OK(result))
180 result = rpccli_lsa_QueryInfoPolicy2(cli, mem_ctx,
186 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
187 SEC_FLAG_MAXIMUM_ALLOWED,
190 if (!NT_STATUS_IS_OK(result))
193 result = rpccli_lsa_QueryInfoPolicy(cli, mem_ctx,
199 if (NT_STATUS_IS_OK(result)) {
200 display_lsa_query_info(info, info_class);
203 rpccli_lsa_Close(cli, mem_ctx, &pol);
209 /* Resolve a list of names to a list of sids */
211 static NTSTATUS cmd_lsa_lookup_names(struct rpc_pipe_client *cli,
212 TALLOC_CTX *mem_ctx, int argc,
215 struct policy_handle pol;
216 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
217 struct dom_sid *sids;
218 enum lsa_SidType *types;
222 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
226 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
227 SEC_FLAG_MAXIMUM_ALLOWED,
230 if (!NT_STATUS_IS_OK(result))
233 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
234 (const char**)(argv + 1), NULL, 1, &sids, &types);
236 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
237 NT_STATUS_V(STATUS_SOME_UNMAPPED))
240 result = NT_STATUS_OK;
244 for (i = 0; i < (argc - 1); i++) {
246 sid_to_fstring(sid_str, &sids[i]);
247 printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
248 sid_type_lookup(types[i]), types[i]);
251 rpccli_lsa_Close(cli, mem_ctx, &pol);
257 /* Resolve a list of names to a list of sids */
259 static NTSTATUS cmd_lsa_lookup_names_level(struct rpc_pipe_client *cli,
260 TALLOC_CTX *mem_ctx, int argc,
263 struct policy_handle pol;
264 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
265 struct dom_sid *sids;
266 enum lsa_SidType *types;
270 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv[0]);
274 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
275 SEC_FLAG_MAXIMUM_ALLOWED,
278 if (!NT_STATUS_IS_OK(result))
281 level = atoi(argv[1]);
283 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 2,
284 (const char**)(argv + 2), NULL, level, &sids, &types);
286 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
287 NT_STATUS_V(STATUS_SOME_UNMAPPED))
290 result = NT_STATUS_OK;
294 for (i = 0; i < (argc - 2); i++) {
296 sid_to_fstring(sid_str, &sids[i]);
297 printf("%s %s (%s: %d)\n", argv[i + 2], sid_str,
298 sid_type_lookup(types[i]), types[i]);
301 rpccli_lsa_Close(cli, mem_ctx, &pol);
307 static NTSTATUS cmd_lsa_lookup_names4(struct rpc_pipe_client *cli,
308 TALLOC_CTX *mem_ctx, int argc,
311 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
314 struct lsa_String *names;
315 struct lsa_RefDomainList *domains;
316 struct lsa_TransSidArray3 sids;
321 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
328 names = talloc_array(mem_ctx, struct lsa_String, num_names);
329 NT_STATUS_HAVE_NO_MEMORY(names);
331 for (i=0; i < num_names; i++) {
332 init_lsa_String(&names[i], argv[i+1]);
335 result = rpccli_lsa_LookupNames4(cli, mem_ctx,
344 if (!NT_STATUS_IS_OK(result)) {
348 for (i = 0; i < sids.count; i++) {
350 sid_to_fstring(sid_str, sids.sids[i].sid);
351 printf("%s %s (%s: %d)\n", argv[i+1], sid_str,
352 sid_type_lookup(sids.sids[i].sid_type),
353 sids.sids[i].sid_type);
359 /* Resolve a list of SIDs to a list of names */
361 static NTSTATUS cmd_lsa_lookup_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
362 int argc, const char **argv)
364 struct policy_handle pol;
365 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
366 struct dom_sid *sids;
369 enum lsa_SidType *types;
373 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
377 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
378 SEC_FLAG_MAXIMUM_ALLOWED,
381 if (!NT_STATUS_IS_OK(result))
384 /* Convert arguments to sids */
386 sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, argc - 1);
389 printf("could not allocate memory for %d sids\n", argc - 1);
393 for (i = 0; i < argc - 1; i++)
394 if (!string_to_sid(&sids[i], argv[i + 1])) {
395 result = NT_STATUS_INVALID_SID;
399 /* Lookup the SIDs */
401 result = rpccli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
402 &domains, &names, &types);
404 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
405 NT_STATUS_V(STATUS_SOME_UNMAPPED))
408 result = NT_STATUS_OK;
412 for (i = 0; i < (argc - 1); i++) {
415 sid_to_fstring(sid_str, &sids[i]);
416 printf("%s %s\\%s (%d)\n", sid_str,
417 domains[i] ? domains[i] : "*unknown*",
418 names[i] ? names[i] : "*unknown*", types[i]);
421 rpccli_lsa_Close(cli, mem_ctx, &pol);
427 /* Resolve a list of SIDs to a list of names */
429 static NTSTATUS cmd_lsa_lookup_sids3(struct rpc_pipe_client *cli,
431 int argc, const char **argv)
433 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
435 struct lsa_SidArray sids;
436 struct lsa_RefDomainList *domains;
437 struct lsa_TransNameArray2 names;
441 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
447 /* Convert arguments to sids */
449 sids.num_sids = argc-1;
450 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
452 printf("could not allocate memory for %d sids\n", sids.num_sids);
456 for (i = 0; i < sids.num_sids; i++) {
457 sids.sids[i].sid = talloc(sids.sids, struct dom_sid);
458 if (sids.sids[i].sid == NULL) {
459 result = NT_STATUS_NO_MEMORY;
462 if (!string_to_sid(sids.sids[i].sid, argv[i+1])) {
463 result = NT_STATUS_INVALID_SID;
468 /* Lookup the SIDs */
469 result = rpccli_lsa_LookupSids3(cli, mem_ctx,
478 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
479 NT_STATUS_V(STATUS_SOME_UNMAPPED))
482 result = NT_STATUS_OK;
486 for (i = 0; i < count; i++) {
489 sid_to_fstring(sid_str, sids.sids[i].sid);
490 printf("%s %s (%d)\n", sid_str,
491 names.names[i].name.string,
492 names.names[i].sid_type);
500 /* Enumerate list of trusted domains */
502 static NTSTATUS cmd_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
503 TALLOC_CTX *mem_ctx, int argc,
506 struct policy_handle pol;
507 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
508 struct lsa_DomainList domain_list;
510 /* defaults, but may be changed using params */
513 uint32_t max_size = (uint32_t)-1;
516 printf("Usage: %s [enum context (0)]\n", argv[0]);
520 if (argc == 2 && argv[1]) {
521 enum_ctx = atoi(argv[2]);
524 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
525 LSA_POLICY_VIEW_LOCAL_INFORMATION,
528 if (!NT_STATUS_IS_OK(result))
531 result = STATUS_MORE_ENTRIES;
533 while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
535 /* Lookup list of trusted domains */
537 result = rpccli_lsa_EnumTrustDom(cli, mem_ctx,
542 if (!NT_STATUS_IS_OK(result) &&
543 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
544 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
547 /* Print results: list of names and sids returned in this
549 for (i = 0; i < domain_list.count; i++) {
552 sid_to_fstring(sid_str, domain_list.domains[i].sid);
554 domain_list.domains[i].name.string ?
555 domain_list.domains[i].name.string : "*unknown*",
560 rpccli_lsa_Close(cli, mem_ctx, &pol);
565 /* Enumerates privileges */
567 static NTSTATUS cmd_lsa_enum_privilege(struct rpc_pipe_client *cli,
568 TALLOC_CTX *mem_ctx, int argc,
571 struct policy_handle pol;
572 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
573 struct lsa_PrivArray priv_array;
575 uint32 enum_context=0;
576 uint32 pref_max_length=0x1000;
580 printf("Usage: %s [enum context] [max length]\n", argv[0]);
585 enum_context=atoi(argv[1]);
588 pref_max_length=atoi(argv[2]);
590 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
591 SEC_FLAG_MAXIMUM_ALLOWED,
594 if (!NT_STATUS_IS_OK(result))
597 result = rpccli_lsa_EnumPrivs(cli, mem_ctx,
602 if (!NT_STATUS_IS_OK(result))
606 printf("found %d privileges\n\n", priv_array.count);
608 for (i = 0; i < priv_array.count; i++) {
609 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
610 priv_array.privs[i].name.string ? priv_array.privs[i].name.string : "*unknown*",
611 priv_array.privs[i].luid.high,
612 priv_array.privs[i].luid.low,
613 priv_array.privs[i].luid.high,
614 priv_array.privs[i].luid.low);
617 rpccli_lsa_Close(cli, mem_ctx, &pol);
622 /* Get privilege name */
624 static NTSTATUS cmd_lsa_get_dispname(struct rpc_pipe_client *cli,
625 TALLOC_CTX *mem_ctx, int argc,
628 struct policy_handle pol;
629 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
632 uint16 lang_id_sys=0;
634 struct lsa_String lsa_name;
635 struct lsa_StringLarge *description = NULL;
638 printf("Usage: %s privilege name\n", argv[0]);
642 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
643 SEC_FLAG_MAXIMUM_ALLOWED,
646 if (!NT_STATUS_IS_OK(result))
649 init_lsa_String(&lsa_name, argv[1]);
651 result = rpccli_lsa_LookupPrivDisplayName(cli, mem_ctx,
659 if (!NT_STATUS_IS_OK(result))
663 printf("%s -> %s (language: 0x%x)\n", argv[1], description->string, lang_id_desc);
665 rpccli_lsa_Close(cli, mem_ctx, &pol);
670 /* Enumerate the LSA SIDS */
672 static NTSTATUS cmd_lsa_enum_sids(struct rpc_pipe_client *cli,
673 TALLOC_CTX *mem_ctx, int argc,
676 struct policy_handle pol;
677 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
679 uint32 enum_context=0;
680 uint32 pref_max_length=0x1000;
681 struct lsa_SidArray sid_array;
685 printf("Usage: %s [enum context] [max length]\n", argv[0]);
690 enum_context=atoi(argv[1]);
693 pref_max_length=atoi(argv[2]);
695 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
696 SEC_FLAG_MAXIMUM_ALLOWED,
699 if (!NT_STATUS_IS_OK(result))
702 result = rpccli_lsa_EnumAccounts(cli, mem_ctx,
708 if (!NT_STATUS_IS_OK(result))
712 printf("found %d SIDs\n\n", sid_array.num_sids);
714 for (i = 0; i < sid_array.num_sids; i++) {
717 sid_to_fstring(sid_str, sid_array.sids[i].sid);
718 printf("%s\n", sid_str);
721 rpccli_lsa_Close(cli, mem_ctx, &pol);
726 /* Create a new account */
728 static NTSTATUS cmd_lsa_create_account(struct rpc_pipe_client *cli,
729 TALLOC_CTX *mem_ctx, int argc,
732 struct policy_handle dom_pol;
733 struct policy_handle user_pol;
734 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
735 uint32 des_access = 0x000f000f;
740 printf("Usage: %s SID\n", argv[0]);
744 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
745 if (!NT_STATUS_IS_OK(result))
748 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
749 SEC_FLAG_MAXIMUM_ALLOWED,
752 if (!NT_STATUS_IS_OK(result))
755 result = rpccli_lsa_CreateAccount(cli, mem_ctx,
761 if (!NT_STATUS_IS_OK(result))
764 printf("Account for SID %s successfully created\n\n", argv[1]);
765 result = NT_STATUS_OK;
767 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
773 /* Enumerate the privileges of an SID */
775 static NTSTATUS cmd_lsa_enum_privsaccounts(struct rpc_pipe_client *cli,
776 TALLOC_CTX *mem_ctx, int argc,
779 struct policy_handle dom_pol;
780 struct policy_handle user_pol;
781 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
782 uint32 access_desired = 0x000f000f;
784 struct lsa_PrivilegeSet *privs = NULL;
788 printf("Usage: %s SID\n", argv[0]);
792 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
793 if (!NT_STATUS_IS_OK(result))
796 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
797 SEC_FLAG_MAXIMUM_ALLOWED,
800 if (!NT_STATUS_IS_OK(result))
803 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
809 if (!NT_STATUS_IS_OK(result))
812 result = rpccli_lsa_EnumPrivsAccount(cli, mem_ctx,
816 if (!NT_STATUS_IS_OK(result))
820 printf("found %d privileges for SID %s\n\n", privs->count, argv[1]);
821 printf("high\tlow\tattribute\n");
823 for (i = 0; i < privs->count; i++) {
824 printf("%u\t%u\t%u\n",
825 privs->set[i].luid.high,
826 privs->set[i].luid.low,
827 privs->set[i].attribute);
830 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
836 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
838 static NTSTATUS cmd_lsa_enum_acct_rights(struct rpc_pipe_client *cli,
839 TALLOC_CTX *mem_ctx, int argc,
842 struct policy_handle dom_pol;
843 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
845 struct lsa_RightSet rights;
850 printf("Usage: %s SID\n", argv[0]);
854 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
855 if (!NT_STATUS_IS_OK(result))
858 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
859 SEC_FLAG_MAXIMUM_ALLOWED,
862 if (!NT_STATUS_IS_OK(result))
865 result = rpccli_lsa_EnumAccountRights(cli, mem_ctx,
870 if (!NT_STATUS_IS_OK(result))
873 printf("found %d privileges for SID %s\n", rights.count,
874 sid_string_tos(&sid));
876 for (i = 0; i < rights.count; i++) {
877 printf("\t%s\n", rights.names[i].string);
880 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
886 /* add some privileges to a SID via LsaAddAccountRights */
888 static NTSTATUS cmd_lsa_add_acct_rights(struct rpc_pipe_client *cli,
889 TALLOC_CTX *mem_ctx, int argc,
892 struct policy_handle dom_pol;
893 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
894 struct lsa_RightSet rights;
899 printf("Usage: %s SID [rights...]\n", argv[0]);
903 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
904 if (!NT_STATUS_IS_OK(result))
907 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
908 SEC_FLAG_MAXIMUM_ALLOWED,
911 if (!NT_STATUS_IS_OK(result))
914 rights.count = argc-2;
915 rights.names = TALLOC_ARRAY(mem_ctx, struct lsa_StringLarge,
918 return NT_STATUS_NO_MEMORY;
921 for (i=0; i<argc-2; i++) {
922 init_lsa_StringLarge(&rights.names[i], argv[i+2]);
925 result = rpccli_lsa_AddAccountRights(cli, mem_ctx,
930 if (!NT_STATUS_IS_OK(result))
933 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
939 /* remove some privileges to a SID via LsaRemoveAccountRights */
941 static NTSTATUS cmd_lsa_remove_acct_rights(struct rpc_pipe_client *cli,
942 TALLOC_CTX *mem_ctx, int argc,
945 struct policy_handle dom_pol;
946 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
947 struct lsa_RightSet rights;
952 printf("Usage: %s SID [rights...]\n", argv[0]);
956 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
957 if (!NT_STATUS_IS_OK(result))
960 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
961 SEC_FLAG_MAXIMUM_ALLOWED,
964 if (!NT_STATUS_IS_OK(result))
967 rights.count = argc-2;
968 rights.names = TALLOC_ARRAY(mem_ctx, struct lsa_StringLarge,
971 return NT_STATUS_NO_MEMORY;
974 for (i=0; i<argc-2; i++) {
975 init_lsa_StringLarge(&rights.names[i], argv[i+2]);
978 result = rpccli_lsa_RemoveAccountRights(cli, mem_ctx,
984 if (!NT_STATUS_IS_OK(result))
987 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
994 /* Get a privilege value given its name */
996 static NTSTATUS cmd_lsa_lookup_priv_value(struct rpc_pipe_client *cli,
997 TALLOC_CTX *mem_ctx, int argc,
1000 struct policy_handle pol;
1001 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1002 struct lsa_LUID luid;
1003 struct lsa_String name;
1006 printf("Usage: %s name\n", argv[0]);
1007 return NT_STATUS_OK;
1010 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1011 SEC_FLAG_MAXIMUM_ALLOWED,
1014 if (!NT_STATUS_IS_OK(result))
1017 init_lsa_String(&name, argv[1]);
1019 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
1024 if (!NT_STATUS_IS_OK(result))
1029 printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
1031 rpccli_lsa_Close(cli, mem_ctx, &pol);
1036 /* Query LSA security object */
1038 static NTSTATUS cmd_lsa_query_secobj(struct rpc_pipe_client *cli,
1039 TALLOC_CTX *mem_ctx, int argc,
1042 struct policy_handle pol;
1043 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1044 struct sec_desc_buf *sdb;
1045 uint32 sec_info = SECINFO_DACL;
1047 if (argc < 1 || argc > 2) {
1048 printf("Usage: %s [sec_info]\n", argv[0]);
1049 return NT_STATUS_OK;
1052 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1053 SEC_FLAG_MAXIMUM_ALLOWED,
1057 sscanf(argv[1], "%x", &sec_info);
1059 if (!NT_STATUS_IS_OK(result))
1062 result = rpccli_lsa_QuerySecurity(cli, mem_ctx,
1066 if (!NT_STATUS_IS_OK(result))
1071 display_sec_desc(sdb->sd);
1073 rpccli_lsa_Close(cli, mem_ctx, &pol);
1078 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword *p,
1079 uint8_t session_key[16])
1081 char *pwd, *pwd_old;
1083 DATA_BLOB data = data_blob_const(p->password->data, p->password->length);
1084 DATA_BLOB data_old = data_blob_const(p->old_password->data, p->old_password->length);
1085 DATA_BLOB session_key_blob = data_blob_const(session_key, sizeof(session_key));
1087 pwd = sess_decrypt_string(talloc_tos(), &data, &session_key_blob);
1088 pwd_old = sess_decrypt_string(talloc_tos(), &data_old, &session_key_blob);
1090 d_printf("Password:\t%s\n", pwd);
1091 d_printf("Old Password:\t%s\n", pwd_old);
1094 talloc_free(pwd_old);
1097 static void display_trust_dom_info(TALLOC_CTX *mem_ctx,
1098 union lsa_TrustedDomainInfo *info,
1099 enum lsa_TrustDomInfoEnum info_class,
1100 uint8_t nt_hash[16])
1102 switch (info_class) {
1103 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD:
1104 display_trust_dom_info_4(&info->password, nt_hash);
1107 const char *str = NULL;
1108 str = NDR_PRINT_UNION_STRING(mem_ctx,
1109 lsa_TrustedDomainInfo,
1112 d_printf("%s\n", str);
1119 static NTSTATUS cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client *cli,
1120 TALLOC_CTX *mem_ctx, int argc,
1123 struct policy_handle pol;
1124 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1125 struct dom_sid dom_sid;
1126 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1127 union lsa_TrustedDomainInfo *info = NULL;
1128 enum lsa_TrustDomInfoEnum info_class = 1;
1129 uint8_t nt_hash[16];
1131 if (argc > 3 || argc < 2) {
1132 printf("Usage: %s [sid] [info_class]\n", argv[0]);
1133 return NT_STATUS_OK;
1136 if (!string_to_sid(&dom_sid, argv[1]))
1137 return NT_STATUS_NO_MEMORY;
1140 info_class = atoi(argv[2]);
1142 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1144 if (!NT_STATUS_IS_OK(result))
1147 result = rpccli_lsa_QueryTrustedDomainInfoBySid(cli, mem_ctx,
1152 if (!NT_STATUS_IS_OK(result))
1155 if (!rpccli_get_pwd_hash(cli, nt_hash)) {
1156 d_fprintf(stderr, "Could not get pwd hash\n");
1160 display_trust_dom_info(mem_ctx, info, info_class, nt_hash);
1163 rpccli_lsa_Close(cli, mem_ctx, &pol);
1168 static NTSTATUS cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client *cli,
1169 TALLOC_CTX *mem_ctx, int argc,
1172 struct policy_handle pol;
1173 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1174 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1175 union lsa_TrustedDomainInfo *info = NULL;
1176 enum lsa_TrustDomInfoEnum info_class = 1;
1177 struct lsa_String trusted_domain;
1178 uint8_t nt_hash[16];
1180 if (argc > 3 || argc < 2) {
1181 printf("Usage: %s [name] [info_class]\n", argv[0]);
1182 return NT_STATUS_OK;
1186 info_class = atoi(argv[2]);
1188 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1190 if (!NT_STATUS_IS_OK(result))
1193 init_lsa_String(&trusted_domain, argv[1]);
1195 result = rpccli_lsa_QueryTrustedDomainInfoByName(cli, mem_ctx,
1200 if (!NT_STATUS_IS_OK(result))
1203 if (!rpccli_get_pwd_hash(cli, nt_hash)) {
1204 d_fprintf(stderr, "Could not get pwd hash\n");
1208 display_trust_dom_info(mem_ctx, info, info_class, nt_hash);
1211 rpccli_lsa_Close(cli, mem_ctx, &pol);
1216 static NTSTATUS cmd_lsa_query_trustdominfo(struct rpc_pipe_client *cli,
1217 TALLOC_CTX *mem_ctx, int argc,
1220 struct policy_handle pol, trustdom_pol;
1221 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1222 uint32 access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1223 union lsa_TrustedDomainInfo *info = NULL;
1224 struct dom_sid dom_sid;
1225 enum lsa_TrustDomInfoEnum info_class = 1;
1226 uint8_t nt_hash[16];
1228 if (argc > 3 || argc < 2) {
1229 printf("Usage: %s [sid] [info_class]\n", argv[0]);
1230 return NT_STATUS_OK;
1233 if (!string_to_sid(&dom_sid, argv[1]))
1234 return NT_STATUS_NO_MEMORY;
1238 info_class = atoi(argv[2]);
1240 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1242 if (!NT_STATUS_IS_OK(result))
1245 result = rpccli_lsa_OpenTrustedDomain(cli, mem_ctx,
1251 if (!NT_STATUS_IS_OK(result))
1254 result = rpccli_lsa_QueryTrustedDomainInfo(cli, mem_ctx,
1259 if (!NT_STATUS_IS_OK(result))
1262 if (!rpccli_get_pwd_hash(cli, nt_hash)) {
1263 d_fprintf(stderr, "Could not get pwd hash\n");
1267 display_trust_dom_info(mem_ctx, info, info_class, nt_hash);
1270 rpccli_lsa_Close(cli, mem_ctx, &pol);
1275 static NTSTATUS cmd_lsa_get_username(struct rpc_pipe_client *cli,
1276 TALLOC_CTX *mem_ctx, int argc,
1279 struct policy_handle pol;
1280 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1281 const char *servername = cli->desthost;
1282 struct lsa_String *account_name = NULL;
1283 struct lsa_String *authority_name = NULL;
1286 printf("Usage: %s servername\n", argv[0]);
1287 return NT_STATUS_OK;
1290 result = rpccli_lsa_open_policy(cli, mem_ctx, true,
1291 SEC_FLAG_MAXIMUM_ALLOWED,
1294 if (!NT_STATUS_IS_OK(result)) {
1298 result = rpccli_lsa_GetUserName(cli, mem_ctx,
1302 if (!NT_STATUS_IS_OK(result)) {
1308 printf("Account Name: %s, Authority Name: %s\n",
1309 account_name->string, authority_name ? authority_name->string :
1312 rpccli_lsa_Close(cli, mem_ctx, &pol);
1317 static NTSTATUS cmd_lsa_add_priv(struct rpc_pipe_client *cli,
1318 TALLOC_CTX *mem_ctx, int argc,
1321 struct policy_handle dom_pol, user_pol;
1322 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1323 struct lsa_PrivilegeSet privs;
1324 struct lsa_LUIDAttribute *set = NULL;
1331 printf("Usage: %s SID [rights...]\n", argv[0]);
1332 return NT_STATUS_OK;
1335 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
1336 if (!NT_STATUS_IS_OK(result)) {
1340 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1341 SEC_FLAG_MAXIMUM_ALLOWED,
1344 if (!NT_STATUS_IS_OK(result)) {
1348 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
1351 SEC_FLAG_MAXIMUM_ALLOWED,
1354 if (!NT_STATUS_IS_OK(result)) {
1358 for (i=2; i<argc; i++) {
1360 struct lsa_String priv_name;
1361 struct lsa_LUID luid;
1363 init_lsa_String(&priv_name, argv[i]);
1365 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
1369 if (!NT_STATUS_IS_OK(result)) {
1374 set = TALLOC_REALLOC_ARRAY(mem_ctx, set,
1375 struct lsa_LUIDAttribute,
1378 return NT_STATUS_NO_MEMORY;
1381 set[privs.count-1].luid = luid;
1382 set[privs.count-1].attribute = 0;
1387 result = rpccli_lsa_AddPrivilegesToAccount(cli, mem_ctx,
1391 if (!NT_STATUS_IS_OK(result)) {
1395 rpccli_lsa_Close(cli, mem_ctx, &user_pol);
1396 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
1401 static NTSTATUS cmd_lsa_del_priv(struct rpc_pipe_client *cli,
1402 TALLOC_CTX *mem_ctx, int argc,
1405 struct policy_handle dom_pol, user_pol;
1406 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1407 struct lsa_PrivilegeSet privs;
1408 struct lsa_LUIDAttribute *set = NULL;
1415 printf("Usage: %s SID [rights...]\n", argv[0]);
1416 return NT_STATUS_OK;
1419 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
1420 if (!NT_STATUS_IS_OK(result)) {
1424 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1425 SEC_FLAG_MAXIMUM_ALLOWED,
1428 if (!NT_STATUS_IS_OK(result)) {
1432 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
1435 SEC_FLAG_MAXIMUM_ALLOWED,
1438 if (!NT_STATUS_IS_OK(result)) {
1442 for (i=2; i<argc; i++) {
1444 struct lsa_String priv_name;
1445 struct lsa_LUID luid;
1447 init_lsa_String(&priv_name, argv[i]);
1449 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
1453 if (!NT_STATUS_IS_OK(result)) {
1458 set = TALLOC_REALLOC_ARRAY(mem_ctx, set,
1459 struct lsa_LUIDAttribute,
1462 return NT_STATUS_NO_MEMORY;
1465 set[privs.count-1].luid = luid;
1466 set[privs.count-1].attribute = 0;
1472 result = rpccli_lsa_RemovePrivilegesFromAccount(cli, mem_ctx,
1477 if (!NT_STATUS_IS_OK(result)) {
1481 rpccli_lsa_Close(cli, mem_ctx, &user_pol);
1482 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
1487 static NTSTATUS cmd_lsa_create_secret(struct rpc_pipe_client *cli,
1488 TALLOC_CTX *mem_ctx, int argc,
1492 struct policy_handle handle, sec_handle;
1493 struct lsa_String name;
1496 printf("Usage: %s name\n", argv[0]);
1497 return NT_STATUS_OK;
1500 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1502 SEC_FLAG_MAXIMUM_ALLOWED,
1504 if (!NT_STATUS_IS_OK(status)) {
1508 init_lsa_String(&name, argv[1]);
1510 status = rpccli_lsa_CreateSecret(cli, mem_ctx,
1513 SEC_FLAG_MAXIMUM_ALLOWED,
1515 if (!NT_STATUS_IS_OK(status)) {
1520 if (is_valid_policy_hnd(&sec_handle)) {
1521 rpccli_lsa_Close(cli, mem_ctx, &sec_handle);
1523 if (is_valid_policy_hnd(&handle)) {
1524 rpccli_lsa_Close(cli, mem_ctx, &handle);
1530 static NTSTATUS cmd_lsa_delete_secret(struct rpc_pipe_client *cli,
1531 TALLOC_CTX *mem_ctx, int argc,
1535 struct policy_handle handle, sec_handle;
1536 struct lsa_String name;
1539 printf("Usage: %s name\n", argv[0]);
1540 return NT_STATUS_OK;
1543 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1545 SEC_FLAG_MAXIMUM_ALLOWED,
1547 if (!NT_STATUS_IS_OK(status)) {
1551 init_lsa_String(&name, argv[1]);
1553 status = rpccli_lsa_OpenSecret(cli, mem_ctx,
1556 SEC_FLAG_MAXIMUM_ALLOWED,
1558 if (!NT_STATUS_IS_OK(status)) {
1562 status = rpccli_lsa_DeleteObject(cli, mem_ctx,
1564 if (!NT_STATUS_IS_OK(status)) {
1569 if (is_valid_policy_hnd(&sec_handle)) {
1570 rpccli_lsa_Close(cli, mem_ctx, &sec_handle);
1572 if (is_valid_policy_hnd(&handle)) {
1573 rpccli_lsa_Close(cli, mem_ctx, &handle);
1579 static NTSTATUS cmd_lsa_query_secret(struct rpc_pipe_client *cli,
1580 TALLOC_CTX *mem_ctx, int argc,
1584 struct policy_handle handle, sec_handle;
1585 struct lsa_String name;
1586 struct lsa_DATA_BUF_PTR new_val;
1587 NTTIME new_mtime = 0;
1588 struct lsa_DATA_BUF_PTR old_val;
1589 NTTIME old_mtime = 0;
1590 DATA_BLOB session_key;
1591 DATA_BLOB new_blob = data_blob_null;
1592 DATA_BLOB old_blob = data_blob_null;
1593 char *new_secret, *old_secret;
1596 printf("Usage: %s name\n", argv[0]);
1597 return NT_STATUS_OK;
1600 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1602 SEC_FLAG_MAXIMUM_ALLOWED,
1604 if (!NT_STATUS_IS_OK(status)) {
1608 init_lsa_String(&name, argv[1]);
1610 status = rpccli_lsa_OpenSecret(cli, mem_ctx,
1613 SEC_FLAG_MAXIMUM_ALLOWED,
1615 if (!NT_STATUS_IS_OK(status)) {
1619 ZERO_STRUCT(new_val);
1620 ZERO_STRUCT(old_val);
1622 status = rpccli_lsa_QuerySecret(cli, mem_ctx,
1628 if (!NT_STATUS_IS_OK(status)) {
1632 status = cli_get_session_key(mem_ctx, cli, &session_key);
1633 if (!NT_STATUS_IS_OK(status)) {
1638 new_blob = data_blob_const(new_val.buf->data, new_val.buf->length);
1641 old_blob = data_blob_const(old_val.buf->data, old_val.buf->length);
1644 new_secret = sess_decrypt_string(mem_ctx, &new_blob, &session_key);
1645 old_secret = sess_decrypt_string(mem_ctx, &old_blob, &session_key);
1647 d_printf("new secret: %s\n", new_secret);
1650 d_printf("old secret: %s\n", old_secret);
1654 if (is_valid_policy_hnd(&sec_handle)) {
1655 rpccli_lsa_Close(cli, mem_ctx, &sec_handle);
1657 if (is_valid_policy_hnd(&handle)) {
1658 rpccli_lsa_Close(cli, mem_ctx, &handle);
1664 static NTSTATUS cmd_lsa_set_secret(struct rpc_pipe_client *cli,
1665 TALLOC_CTX *mem_ctx, int argc,
1669 struct policy_handle handle, sec_handle;
1670 struct lsa_String name;
1671 struct lsa_DATA_BUF new_val;
1672 struct lsa_DATA_BUF old_val;
1674 DATA_BLOB session_key;
1677 printf("Usage: %s name secret\n", argv[0]);
1678 return NT_STATUS_OK;
1681 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1683 SEC_FLAG_MAXIMUM_ALLOWED,
1685 if (!NT_STATUS_IS_OK(status)) {
1689 init_lsa_String(&name, argv[1]);
1691 status = rpccli_lsa_OpenSecret(cli, mem_ctx,
1694 SEC_FLAG_MAXIMUM_ALLOWED,
1696 if (!NT_STATUS_IS_OK(status)) {
1700 ZERO_STRUCT(new_val);
1701 ZERO_STRUCT(old_val);
1703 status = cli_get_session_key(mem_ctx, cli, &session_key);
1704 if (!NT_STATUS_IS_OK(status)) {
1708 enc_key = sess_encrypt_string(argv[2], &session_key);
1710 new_val.length = enc_key.length;
1711 new_val.size = enc_key.length;
1712 new_val.data = enc_key.data;
1714 status = rpccli_lsa_SetSecret(cli, mem_ctx,
1718 if (!NT_STATUS_IS_OK(status)) {
1723 if (is_valid_policy_hnd(&sec_handle)) {
1724 rpccli_lsa_Close(cli, mem_ctx, &sec_handle);
1726 if (is_valid_policy_hnd(&handle)) {
1727 rpccli_lsa_Close(cli, mem_ctx, &handle);
1733 static NTSTATUS cmd_lsa_retrieve_private_data(struct rpc_pipe_client *cli,
1734 TALLOC_CTX *mem_ctx, int argc,
1738 struct policy_handle handle;
1739 struct lsa_String name;
1740 struct lsa_DATA_BUF *val;
1741 DATA_BLOB session_key;
1742 DATA_BLOB blob = data_blob_null;
1746 printf("Usage: %s name\n", argv[0]);
1747 return NT_STATUS_OK;
1750 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1752 SEC_FLAG_MAXIMUM_ALLOWED,
1754 if (!NT_STATUS_IS_OK(status)) {
1758 init_lsa_String(&name, argv[1]);
1762 status = rpccli_lsa_RetrievePrivateData(cli, mem_ctx,
1766 if (!NT_STATUS_IS_OK(status)) {
1770 status = cli_get_session_key(mem_ctx, cli, &session_key);
1771 if (!NT_STATUS_IS_OK(status)) {
1776 blob = data_blob_const(val->data, val->length);
1779 secret = sess_decrypt_string(mem_ctx, &blob, &session_key);
1781 d_printf("secret: %s\n", secret);
1785 if (is_valid_policy_hnd(&handle)) {
1786 rpccli_lsa_Close(cli, mem_ctx, &handle);
1792 static NTSTATUS cmd_lsa_store_private_data(struct rpc_pipe_client *cli,
1793 TALLOC_CTX *mem_ctx, int argc,
1797 struct policy_handle handle;
1798 struct lsa_String name;
1799 struct lsa_DATA_BUF val;
1800 DATA_BLOB session_key;
1804 printf("Usage: %s name secret\n", argv[0]);
1805 return NT_STATUS_OK;
1808 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1810 SEC_FLAG_MAXIMUM_ALLOWED,
1812 if (!NT_STATUS_IS_OK(status)) {
1816 init_lsa_String(&name, argv[1]);
1820 status = cli_get_session_key(mem_ctx, cli, &session_key);
1821 if (!NT_STATUS_IS_OK(status)) {
1825 enc_key = sess_encrypt_string(argv[2], &session_key);
1827 val.length = enc_key.length;
1828 val.size = enc_key.length;
1829 val.data = enc_key.data;
1831 status = rpccli_lsa_StorePrivateData(cli, mem_ctx,
1835 if (!NT_STATUS_IS_OK(status)) {
1840 if (is_valid_policy_hnd(&handle)) {
1841 rpccli_lsa_Close(cli, mem_ctx, &handle);
1847 static NTSTATUS cmd_lsa_create_trusted_domain(struct rpc_pipe_client *cli,
1848 TALLOC_CTX *mem_ctx, int argc,
1852 struct policy_handle handle, trustdom_handle;
1854 struct lsa_DomainInfo info;
1857 printf("Usage: %s name sid\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_StringLarge(&info.name, argv[1]);
1871 string_to_sid(&sid, argv[2]);
1873 status = rpccli_lsa_CreateTrustedDomain(cli, mem_ctx,
1876 SEC_FLAG_MAXIMUM_ALLOWED,
1878 if (!NT_STATUS_IS_OK(status)) {
1883 if (is_valid_policy_hnd(&trustdom_handle)) {
1884 rpccli_lsa_Close(cli, mem_ctx, &trustdom_handle);
1887 if (is_valid_policy_hnd(&handle)) {
1888 rpccli_lsa_Close(cli, mem_ctx, &handle);
1894 static NTSTATUS cmd_lsa_delete_trusted_domain(struct rpc_pipe_client *cli,
1895 TALLOC_CTX *mem_ctx, int argc,
1899 struct policy_handle handle, trustdom_handle;
1900 struct lsa_String name;
1901 struct dom_sid *sid = NULL;
1904 printf("Usage: %s name\n", argv[0]);
1905 return NT_STATUS_OK;
1908 status = rpccli_lsa_open_policy2(cli, mem_ctx,
1910 SEC_FLAG_MAXIMUM_ALLOWED,
1912 if (!NT_STATUS_IS_OK(status)) {
1916 init_lsa_String(&name, argv[1]);
1918 status = rpccli_lsa_OpenTrustedDomainByName(cli, mem_ctx,
1921 SEC_FLAG_MAXIMUM_ALLOWED,
1923 if (NT_STATUS_IS_OK(status)) {
1928 uint32_t resume_handle = 0;
1929 struct lsa_DomainList domains;
1932 status = rpccli_lsa_EnumTrustDom(cli, mem_ctx,
1937 if (!NT_STATUS_IS_OK(status)) {
1941 for (i=0; i < domains.count; i++) {
1942 if (strequal(domains.domains[i].name.string, argv[1])) {
1943 sid = domains.domains[i].sid;
1949 return NT_STATUS_INVALID_SID;
1953 status = rpccli_lsa_OpenTrustedDomain(cli, mem_ctx,
1956 SEC_FLAG_MAXIMUM_ALLOWED,
1958 if (!NT_STATUS_IS_OK(status)) {
1963 status = rpccli_lsa_DeleteObject(cli, mem_ctx,
1965 if (!NT_STATUS_IS_OK(status)) {
1970 if (is_valid_policy_hnd(&trustdom_handle)) {
1971 rpccli_lsa_Close(cli, mem_ctx, &trustdom_handle);
1974 if (is_valid_policy_hnd(&handle)) {
1975 rpccli_lsa_Close(cli, mem_ctx, &handle);
1982 /* List of commands exported by this module */
1984 struct cmd_set lsarpc_commands[] = {
1988 { "lsaquery", RPC_RTYPE_NTSTATUS, cmd_lsa_query_info_policy, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query info policy", "" },
1989 { "lookupsids", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_sids, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Convert SIDs to names", "" },
1990 { "lookupsids3", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_sids3, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Convert SIDs to names", "" },
1991 { "lookupnames", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Convert names to SIDs", "" },
1992 { "lookupnames4", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names4, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Convert names to SIDs", "" },
1993 { "lookupnames_level", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names_level, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Convert names to SIDs", "" },
1994 { "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)]" },
1995 { "enumprivs", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privilege, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Enumerate privileges", "" },
1996 { "getdispname", RPC_RTYPE_NTSTATUS, cmd_lsa_get_dispname, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Get the privilege name", "" },
1997 { "lsaenumsid", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_sids, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Enumerate the LSA SIDS", "" },
1998 { "lsacreateaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_create_account, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Create a new lsa account", "" },
1999 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privsaccounts, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Enumerate the privileges of an SID", "" },
2000 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_acct_rights, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Enumerate the rights of an SID", "" },
2001 { "lsaaddpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_add_priv, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Assign a privilege to a SID", "" },
2002 { "lsadelpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_del_priv, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Revoke a privilege from a SID", "" },
2003 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_add_acct_rights, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Add rights to an account", "" },
2004 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_remove_acct_rights, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Remove rights from an account", "" },
2005 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_priv_value, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Get a privilege value given its name", "" },
2006 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS, cmd_lsa_query_secobj, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query LSA security object", "" },
2007 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfo, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query LSA trusted domains info (given a SID)", "" },
2008 { "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", "" },
2009 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobysid, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query LSA trusted domains info (given a SID)", "" },
2010 { "getusername", RPC_RTYPE_NTSTATUS, cmd_lsa_get_username, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Get username", "" },
2011 { "createsecret", RPC_RTYPE_NTSTATUS, cmd_lsa_create_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Create Secret", "" },
2012 { "deletesecret", RPC_RTYPE_NTSTATUS, cmd_lsa_delete_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Delete Secret", "" },
2013 { "querysecret", RPC_RTYPE_NTSTATUS, cmd_lsa_query_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Query Secret", "" },
2014 { "setsecret", RPC_RTYPE_NTSTATUS, cmd_lsa_set_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Set Secret", "" },
2015 { "retrieveprivatedata", RPC_RTYPE_NTSTATUS, cmd_lsa_retrieve_private_data, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Retrieve Private Data", "" },
2016 { "storeprivatedata", RPC_RTYPE_NTSTATUS, cmd_lsa_store_private_data, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Store Private Data", "" },
2017 { "createtrustdom", RPC_RTYPE_NTSTATUS, cmd_lsa_create_trusted_domain, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Create Trusted Domain", "" },
2018 { "deletetrustdom", RPC_RTYPE_NTSTATUS, cmd_lsa_delete_trusted_domain, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Delete Trusted Domain", "" },