2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Rafal Szczesniak 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "rpcclient.h"
25 /* useful function to allow entering a name instead of a SID and
26 * looking it up automatically */
27 static NTSTATUS name_to_sid(struct rpc_pipe_client *cli,
29 DOM_SID *sid, const char *name)
32 enum lsa_SidType *sid_types;
36 /* maybe its a raw SID */
37 if (strncmp(name, "S-", 2) == 0 &&
38 string_to_sid(sid, name)) {
42 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
43 SEC_RIGHTS_MAXIMUM_ALLOWED,
45 if (!NT_STATUS_IS_OK(result))
48 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, NULL, 1, &sids, &sid_types);
49 if (!NT_STATUS_IS_OK(result))
52 rpccli_lsa_Close(cli, mem_ctx, &pol);
60 static void display_query_info_1(struct lsa_AuditLogInfo *r)
62 d_printf("percent_full:\t%d\n", r->percent_full);
63 d_printf("log_size:\t%d\n", r->log_size);
64 d_printf("retention_time:\t%lld\n", (long long)r->retention_time);
65 d_printf("shutdown_in_progress:\t%d\n", r->shutdown_in_progress);
66 d_printf("time_to_shutdown:\t%lld\n", (long long)r->time_to_shutdown);
67 d_printf("next_audit_record:\t%d\n", r->next_audit_record);
68 d_printf("unknown:\t%d\n", r->unknown);
71 static void display_query_info_2(struct lsa_AuditEventsInfo *r)
74 d_printf("Auditing enabled:\t%d\n", r->auditing_mode);
75 d_printf("Auditing categories:\t%d\n", r->count);
76 d_printf("Auditsettings:\n");
77 for (i=0; i<r->count; i++) {
78 const char *val = audit_policy_str(talloc_tos(), r->settings[i]);
79 const char *policy = audit_description_str(i);
80 d_printf("%s:\t%s\n", policy, val);
84 static void display_query_info_3(struct lsa_DomainInfo *r)
86 d_printf("Domain Name: %s\n", r->name.string);
87 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
90 static void display_query_info_5(struct lsa_DomainInfo *r)
92 d_printf("Domain Name: %s\n", r->name.string);
93 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
96 static void display_query_info_10(struct lsa_AuditFullSetInfo *r)
98 d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
101 static void display_query_info_11(struct lsa_AuditFullQueryInfo *r)
103 d_printf("Shutdown on full: %d\n", r->shutdown_on_full);
104 d_printf("Log is full: %d\n", r->log_is_full);
105 d_printf("Unknown: %d\n", r->unknown);
108 static void display_query_info_12(struct lsa_DnsDomainInfo *r)
110 d_printf("Domain NetBios Name: %s\n", r->name.string);
111 d_printf("Domain DNS Name: %s\n", r->dns_domain.string);
112 d_printf("Domain Forest Name: %s\n", r->dns_forest.string);
113 d_printf("Domain Sid: %s\n", sid_string_tos(r->sid));
114 d_printf("Domain GUID: %s\n", smb_uuid_string(talloc_tos(),
118 static void display_lsa_query_info(union lsa_PolicyInformation *info,
119 enum lsa_PolicyInfo level)
123 display_query_info_1(&info->audit_log);
126 display_query_info_2(&info->audit_events);
129 display_query_info_3(&info->domain);
132 display_query_info_5(&info->account_domain);
135 display_query_info_10(&info->auditfullset);
138 display_query_info_11(&info->auditfullquery);
141 display_query_info_12(&info->dns);
144 printf("can't display info level: %d\n", level);
149 static NTSTATUS cmd_lsa_query_info_policy(struct rpc_pipe_client *cli,
150 TALLOC_CTX *mem_ctx, int argc,
154 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
155 union lsa_PolicyInformation *info = NULL;
157 uint32 info_class = 3;
160 printf("Usage: %s [info_class]\n", argv[0]);
165 info_class = atoi(argv[1]);
167 switch (info_class) {
169 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
170 SEC_RIGHTS_MAXIMUM_ALLOWED,
173 if (!NT_STATUS_IS_OK(result))
176 result = rpccli_lsa_QueryInfoPolicy2(cli, mem_ctx,
182 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
183 SEC_RIGHTS_MAXIMUM_ALLOWED,
186 if (!NT_STATUS_IS_OK(result))
189 result = rpccli_lsa_QueryInfoPolicy(cli, mem_ctx,
195 if (NT_STATUS_IS_OK(result)) {
196 display_lsa_query_info(info, info_class);
199 rpccli_lsa_Close(cli, mem_ctx, &pol);
205 /* Resolve a list of names to a list of sids */
207 static NTSTATUS cmd_lsa_lookup_names(struct rpc_pipe_client *cli,
208 TALLOC_CTX *mem_ctx, int argc,
212 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
214 enum lsa_SidType *types;
218 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
222 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
223 SEC_RIGHTS_MAXIMUM_ALLOWED,
226 if (!NT_STATUS_IS_OK(result))
229 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
230 (const char**)(argv + 1), NULL, 1, &sids, &types);
232 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
233 NT_STATUS_V(STATUS_SOME_UNMAPPED))
236 result = NT_STATUS_OK;
240 for (i = 0; i < (argc - 1); i++) {
242 sid_to_fstring(sid_str, &sids[i]);
243 printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
244 sid_type_lookup(types[i]), types[i]);
247 rpccli_lsa_Close(cli, mem_ctx, &pol);
253 /* Resolve a list of names to a list of sids */
255 static NTSTATUS cmd_lsa_lookup_names_level(struct rpc_pipe_client *cli,
256 TALLOC_CTX *mem_ctx, int argc,
260 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
262 enum lsa_SidType *types;
266 printf("Usage: %s [level] [name1 [name2 [...]]]\n", argv[0]);
270 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
271 SEC_RIGHTS_MAXIMUM_ALLOWED,
274 if (!NT_STATUS_IS_OK(result))
277 level = atoi(argv[1]);
279 result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 2,
280 (const char**)(argv + 2), NULL, level, &sids, &types);
282 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
283 NT_STATUS_V(STATUS_SOME_UNMAPPED))
286 result = NT_STATUS_OK;
290 for (i = 0; i < (argc - 2); i++) {
292 sid_to_fstring(sid_str, &sids[i]);
293 printf("%s %s (%s: %d)\n", argv[i + 2], sid_str,
294 sid_type_lookup(types[i]), types[i]);
297 rpccli_lsa_Close(cli, mem_ctx, &pol);
304 /* Resolve a list of SIDs to a list of names */
306 static NTSTATUS cmd_lsa_lookup_sids(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
307 int argc, const char **argv)
310 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
314 enum lsa_SidType *types;
318 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
322 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
323 SEC_RIGHTS_MAXIMUM_ALLOWED,
326 if (!NT_STATUS_IS_OK(result))
329 /* Convert arguments to sids */
331 sids = TALLOC_ARRAY(mem_ctx, DOM_SID, argc - 1);
334 printf("could not allocate memory for %d sids\n", argc - 1);
338 for (i = 0; i < argc - 1; i++)
339 if (!string_to_sid(&sids[i], argv[i + 1])) {
340 result = NT_STATUS_INVALID_SID;
344 /* Lookup the SIDs */
346 result = rpccli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
347 &domains, &names, &types);
349 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
350 NT_STATUS_V(STATUS_SOME_UNMAPPED))
353 result = NT_STATUS_OK;
357 for (i = 0; i < (argc - 1); i++) {
360 sid_to_fstring(sid_str, &sids[i]);
361 printf("%s %s\\%s (%d)\n", sid_str,
362 domains[i] ? domains[i] : "*unknown*",
363 names[i] ? names[i] : "*unknown*", types[i]);
366 rpccli_lsa_Close(cli, mem_ctx, &pol);
372 /* Enumerate list of trusted domains */
374 static NTSTATUS cmd_lsa_enum_trust_dom(struct rpc_pipe_client *cli,
375 TALLOC_CTX *mem_ctx, int argc,
379 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
380 struct lsa_DomainList domain_list;
382 /* defaults, but may be changed using params */
385 uint32_t max_size = (uint32_t)-1;
388 printf("Usage: %s [enum context (0)]\n", argv[0]);
392 if (argc == 2 && argv[1]) {
393 enum_ctx = atoi(argv[2]);
396 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
397 POLICY_VIEW_LOCAL_INFORMATION,
400 if (!NT_STATUS_IS_OK(result))
403 result = STATUS_MORE_ENTRIES;
405 while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
407 /* Lookup list of trusted domains */
409 result = rpccli_lsa_EnumTrustDom(cli, mem_ctx,
414 if (!NT_STATUS_IS_OK(result) &&
415 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
416 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
419 /* Print results: list of names and sids returned in this
421 for (i = 0; i < domain_list.count; i++) {
424 sid_to_fstring(sid_str, domain_list.domains[i].sid);
426 domain_list.domains[i].name.string ?
427 domain_list.domains[i].name.string : "*unknown*",
432 rpccli_lsa_Close(cli, mem_ctx, &pol);
437 /* Enumerates privileges */
439 static NTSTATUS cmd_lsa_enum_privilege(struct rpc_pipe_client *cli,
440 TALLOC_CTX *mem_ctx, int argc,
444 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
445 struct lsa_PrivArray priv_array;
447 uint32 enum_context=0;
448 uint32 pref_max_length=0x1000;
452 printf("Usage: %s [enum context] [max length]\n", argv[0]);
457 enum_context=atoi(argv[1]);
460 pref_max_length=atoi(argv[2]);
462 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
463 SEC_RIGHTS_MAXIMUM_ALLOWED,
466 if (!NT_STATUS_IS_OK(result))
469 result = rpccli_lsa_EnumPrivs(cli, mem_ctx,
474 if (!NT_STATUS_IS_OK(result))
478 printf("found %d privileges\n\n", priv_array.count);
480 for (i = 0; i < priv_array.count; i++) {
481 printf("%s \t\t%d:%d (0x%x:0x%x)\n",
482 priv_array.privs[i].name.string ? priv_array.privs[i].name.string : "*unknown*",
483 priv_array.privs[i].luid.high,
484 priv_array.privs[i].luid.low,
485 priv_array.privs[i].luid.high,
486 priv_array.privs[i].luid.low);
489 rpccli_lsa_Close(cli, mem_ctx, &pol);
494 /* Get privilege name */
496 static NTSTATUS cmd_lsa_get_dispname(struct rpc_pipe_client *cli,
497 TALLOC_CTX *mem_ctx, int argc,
501 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
504 uint16 lang_id_sys=0;
506 struct lsa_String lsa_name;
507 struct lsa_StringLarge *description = NULL;
510 printf("Usage: %s privilege name\n", argv[0]);
514 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
515 SEC_RIGHTS_MAXIMUM_ALLOWED,
518 if (!NT_STATUS_IS_OK(result))
521 init_lsa_String(&lsa_name, argv[1]);
523 result = rpccli_lsa_LookupPrivDisplayName(cli, mem_ctx,
531 if (!NT_STATUS_IS_OK(result))
535 printf("%s -> %s (language: 0x%x)\n", argv[1], description->string, lang_id_desc);
537 rpccli_lsa_Close(cli, mem_ctx, &pol);
542 /* Enumerate the LSA SIDS */
544 static NTSTATUS cmd_lsa_enum_sids(struct rpc_pipe_client *cli,
545 TALLOC_CTX *mem_ctx, int argc,
549 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
551 uint32 enum_context=0;
552 uint32 pref_max_length=0x1000;
553 struct lsa_SidArray sid_array;
557 printf("Usage: %s [enum context] [max length]\n", argv[0]);
562 enum_context=atoi(argv[1]);
565 pref_max_length=atoi(argv[2]);
567 result = rpccli_lsa_open_policy(cli, mem_ctx, True,
568 SEC_RIGHTS_MAXIMUM_ALLOWED,
571 if (!NT_STATUS_IS_OK(result))
574 result = rpccli_lsa_EnumAccounts(cli, mem_ctx,
580 if (!NT_STATUS_IS_OK(result))
584 printf("found %d SIDs\n\n", sid_array.num_sids);
586 for (i = 0; i < sid_array.num_sids; i++) {
589 sid_to_fstring(sid_str, sid_array.sids[i].sid);
590 printf("%s\n", sid_str);
593 rpccli_lsa_Close(cli, mem_ctx, &pol);
598 /* Create a new account */
600 static NTSTATUS cmd_lsa_create_account(struct rpc_pipe_client *cli,
601 TALLOC_CTX *mem_ctx, int argc,
606 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
607 uint32 des_access = 0x000f000f;
612 printf("Usage: %s SID\n", argv[0]);
616 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
617 if (!NT_STATUS_IS_OK(result))
620 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
621 SEC_RIGHTS_MAXIMUM_ALLOWED,
624 if (!NT_STATUS_IS_OK(result))
627 result = rpccli_lsa_CreateAccount(cli, mem_ctx,
633 if (!NT_STATUS_IS_OK(result))
636 printf("Account for SID %s successfully created\n\n", argv[1]);
637 result = NT_STATUS_OK;
639 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
645 /* Enumerate the privileges of an SID */
647 static NTSTATUS cmd_lsa_enum_privsaccounts(struct rpc_pipe_client *cli,
648 TALLOC_CTX *mem_ctx, int argc,
653 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
654 uint32 access_desired = 0x000f000f;
656 struct lsa_PrivilegeSet *privs = NULL;
660 printf("Usage: %s SID\n", argv[0]);
664 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
665 if (!NT_STATUS_IS_OK(result))
668 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
669 SEC_RIGHTS_MAXIMUM_ALLOWED,
672 if (!NT_STATUS_IS_OK(result))
675 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
681 if (!NT_STATUS_IS_OK(result))
684 result = rpccli_lsa_EnumPrivsAccount(cli, mem_ctx,
688 if (!NT_STATUS_IS_OK(result))
692 printf("found %d privileges for SID %s\n\n", privs->count, argv[1]);
693 printf("high\tlow\tattribute\n");
695 for (i = 0; i < privs->count; i++) {
696 printf("%u\t%u\t%u\n",
697 privs->set[i].luid.high,
698 privs->set[i].luid.low,
699 privs->set[i].attribute);
702 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
708 /* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
710 static NTSTATUS cmd_lsa_enum_acct_rights(struct rpc_pipe_client *cli,
711 TALLOC_CTX *mem_ctx, int argc,
715 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
717 struct lsa_RightSet rights;
722 printf("Usage: %s SID\n", argv[0]);
726 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
727 if (!NT_STATUS_IS_OK(result))
730 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
731 SEC_RIGHTS_MAXIMUM_ALLOWED,
734 if (!NT_STATUS_IS_OK(result))
737 result = rpccli_lsa_EnumAccountRights(cli, mem_ctx,
742 if (!NT_STATUS_IS_OK(result))
745 printf("found %d privileges for SID %s\n", rights.count,
746 sid_string_tos(&sid));
748 for (i = 0; i < rights.count; i++) {
749 printf("\t%s\n", rights.names[i].string);
752 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
758 /* add some privileges to a SID via LsaAddAccountRights */
760 static NTSTATUS cmd_lsa_add_acct_rights(struct rpc_pipe_client *cli,
761 TALLOC_CTX *mem_ctx, int argc,
765 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
766 struct lsa_RightSet rights;
771 printf("Usage: %s SID [rights...]\n", argv[0]);
775 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
776 if (!NT_STATUS_IS_OK(result))
779 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
780 SEC_RIGHTS_MAXIMUM_ALLOWED,
783 if (!NT_STATUS_IS_OK(result))
786 rights.count = argc-2;
787 rights.names = TALLOC_ARRAY(mem_ctx, struct lsa_StringLarge,
790 return NT_STATUS_NO_MEMORY;
793 for (i=0; i<argc-1; i++) {
794 init_lsa_StringLarge(&rights.names[i], argv[i+2]);
797 result = rpccli_lsa_AddAccountRights(cli, mem_ctx,
802 if (!NT_STATUS_IS_OK(result))
805 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
811 /* remove some privileges to a SID via LsaRemoveAccountRights */
813 static NTSTATUS cmd_lsa_remove_acct_rights(struct rpc_pipe_client *cli,
814 TALLOC_CTX *mem_ctx, int argc,
818 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
823 printf("Usage: %s SID [rights...]\n", argv[0]);
827 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
828 if (!NT_STATUS_IS_OK(result))
831 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
832 SEC_RIGHTS_MAXIMUM_ALLOWED,
835 if (!NT_STATUS_IS_OK(result))
838 result = rpccli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid,
839 False, argc-2, argv+2);
841 if (!NT_STATUS_IS_OK(result))
844 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
851 /* Get a privilege value given its name */
853 static NTSTATUS cmd_lsa_lookup_priv_value(struct rpc_pipe_client *cli,
854 TALLOC_CTX *mem_ctx, int argc,
858 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
859 struct lsa_LUID luid;
860 struct lsa_String name;
863 printf("Usage: %s name\n", argv[0]);
867 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
868 SEC_RIGHTS_MAXIMUM_ALLOWED,
871 if (!NT_STATUS_IS_OK(result))
874 init_lsa_String(&name, argv[1]);
876 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
881 if (!NT_STATUS_IS_OK(result))
886 printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
888 rpccli_lsa_Close(cli, mem_ctx, &pol);
893 /* Query LSA security object */
895 static NTSTATUS cmd_lsa_query_secobj(struct rpc_pipe_client *cli,
896 TALLOC_CTX *mem_ctx, int argc,
900 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
902 uint32 sec_info = DACL_SECURITY_INFORMATION;
904 if (argc < 1 || argc > 2) {
905 printf("Usage: %s [sec_info]\n", argv[0]);
909 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
910 SEC_RIGHTS_MAXIMUM_ALLOWED,
914 sscanf(argv[1], "%x", &sec_info);
916 if (!NT_STATUS_IS_OK(result))
919 result = rpccli_lsa_QuerySecurity(cli, mem_ctx,
923 if (!NT_STATUS_IS_OK(result))
928 display_sec_desc(sdb->sd);
930 rpccli_lsa_Close(cli, mem_ctx, &pol);
935 static void display_trust_dom_info_4(struct lsa_TrustDomainInfoPassword *p, const char *password)
939 DATA_BLOB data = data_blob(NULL, p->password->length);
940 DATA_BLOB data_old = data_blob(NULL, p->old_password->length);
942 memcpy(data.data, p->password->data, p->password->length);
943 memcpy(data_old.data, p->old_password->data, p->old_password->length);
945 pwd = decrypt_trustdom_secret(password, &data);
946 pwd_old = decrypt_trustdom_secret(password, &data_old);
948 d_printf("Password:\t%s\n", pwd);
949 d_printf("Old Password:\t%s\n", pwd_old);
954 data_blob_free(&data);
955 data_blob_free(&data_old);
958 static void display_trust_dom_info(TALLOC_CTX *mem_ctx,
959 union lsa_TrustedDomainInfo *info,
960 enum lsa_TrustDomInfoEnum info_class,
963 switch (info_class) {
964 case LSA_TRUSTED_DOMAIN_INFO_PASSWORD:
965 display_trust_dom_info_4(&info->password, pass);
968 const char *str = NULL;
969 str = NDR_PRINT_UNION_STRING(mem_ctx,
970 lsa_TrustedDomainInfo,
973 d_printf("%s\n", str);
980 static NTSTATUS cmd_lsa_query_trustdominfobysid(struct rpc_pipe_client *cli,
981 TALLOC_CTX *mem_ctx, int argc,
985 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
987 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
988 union lsa_TrustedDomainInfo info;
989 enum lsa_TrustDomInfoEnum info_class = 1;
991 if (argc > 3 || argc < 2) {
992 printf("Usage: %s [sid] [info_class]\n", argv[0]);
996 if (!string_to_sid(&dom_sid, argv[1]))
997 return NT_STATUS_NO_MEMORY;
1000 info_class = atoi(argv[2]);
1002 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1004 if (!NT_STATUS_IS_OK(result))
1007 result = rpccli_lsa_QueryTrustedDomainInfoBySid(cli, mem_ctx,
1012 if (!NT_STATUS_IS_OK(result))
1015 display_trust_dom_info(mem_ctx, &info, info_class, cli->pwd.password);
1018 rpccli_lsa_Close(cli, mem_ctx, &pol);
1023 static NTSTATUS cmd_lsa_query_trustdominfobyname(struct rpc_pipe_client *cli,
1024 TALLOC_CTX *mem_ctx, int argc,
1028 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1029 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
1030 union lsa_TrustedDomainInfo info;
1031 enum lsa_TrustDomInfoEnum info_class = 1;
1032 struct lsa_String trusted_domain;
1034 if (argc > 3 || argc < 2) {
1035 printf("Usage: %s [name] [info_class]\n", argv[0]);
1036 return NT_STATUS_OK;
1040 info_class = atoi(argv[2]);
1042 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1044 if (!NT_STATUS_IS_OK(result))
1047 init_lsa_String(&trusted_domain, argv[1]);
1049 result = rpccli_lsa_QueryTrustedDomainInfoByName(cli, mem_ctx,
1054 if (!NT_STATUS_IS_OK(result))
1057 display_trust_dom_info(mem_ctx, &info, info_class, cli->pwd.password);
1060 rpccli_lsa_Close(cli, mem_ctx, &pol);
1065 static NTSTATUS cmd_lsa_query_trustdominfo(struct rpc_pipe_client *cli,
1066 TALLOC_CTX *mem_ctx, int argc,
1069 POLICY_HND pol, trustdom_pol;
1070 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1071 uint32 access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
1072 union lsa_TrustedDomainInfo info;
1074 enum lsa_TrustDomInfoEnum info_class = 1;
1076 if (argc > 3 || argc < 2) {
1077 printf("Usage: %s [sid] [info_class]\n", argv[0]);
1078 return NT_STATUS_OK;
1081 if (!string_to_sid(&dom_sid, argv[1]))
1082 return NT_STATUS_NO_MEMORY;
1086 info_class = atoi(argv[2]);
1088 result = rpccli_lsa_open_policy2(cli, mem_ctx, True, access_mask, &pol);
1090 if (!NT_STATUS_IS_OK(result))
1093 result = rpccli_lsa_OpenTrustedDomain(cli, mem_ctx,
1099 if (!NT_STATUS_IS_OK(result))
1102 result = rpccli_lsa_QueryTrustedDomainInfo(cli, mem_ctx,
1107 if (!NT_STATUS_IS_OK(result))
1110 display_trust_dom_info(mem_ctx, &info, info_class, cli->pwd.password);
1113 rpccli_lsa_Close(cli, mem_ctx, &pol);
1118 static NTSTATUS cmd_lsa_get_username(struct rpc_pipe_client *cli,
1119 TALLOC_CTX *mem_ctx, int argc,
1123 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1124 const char *servername = cli->cli->desthost;
1125 struct lsa_String *account_name = NULL;
1126 struct lsa_String *authority_name = NULL;
1129 printf("Usage: %s servername\n", argv[0]);
1130 return NT_STATUS_OK;
1133 result = rpccli_lsa_open_policy(cli, mem_ctx, true,
1134 SEC_RIGHTS_MAXIMUM_ALLOWED,
1137 if (!NT_STATUS_IS_OK(result)) {
1141 result = rpccli_lsa_GetUserName(cli, mem_ctx,
1145 if (!NT_STATUS_IS_OK(result)) {
1151 printf("Account Name: %s, Authority Name: %s\n",
1152 account_name->string, authority_name->string);
1154 rpccli_lsa_Close(cli, mem_ctx, &pol);
1159 static NTSTATUS cmd_lsa_add_priv(struct rpc_pipe_client *cli,
1160 TALLOC_CTX *mem_ctx, int argc,
1163 POLICY_HND dom_pol, user_pol;
1164 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1165 struct lsa_PrivilegeSet privs;
1166 struct lsa_LUIDAttribute *set = NULL;
1173 printf("Usage: %s SID [rights...]\n", argv[0]);
1174 return NT_STATUS_OK;
1177 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
1178 if (!NT_STATUS_IS_OK(result)) {
1182 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1183 SEC_RIGHTS_MAXIMUM_ALLOWED,
1186 if (!NT_STATUS_IS_OK(result)) {
1190 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
1193 SEC_RIGHTS_MAXIMUM_ALLOWED,
1196 if (!NT_STATUS_IS_OK(result)) {
1200 for (i=2; i<argc; i++) {
1202 struct lsa_String priv_name;
1203 struct lsa_LUID luid;
1205 init_lsa_String(&priv_name, argv[i]);
1207 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
1211 if (!NT_STATUS_IS_OK(result)) {
1216 set = TALLOC_REALLOC_ARRAY(mem_ctx, set,
1217 struct lsa_LUIDAttribute,
1220 return NT_STATUS_NO_MEMORY;
1223 set[privs.count-1].luid = luid;
1224 set[privs.count-1].attribute = 0;
1229 result = rpccli_lsa_AddPrivilegesToAccount(cli, mem_ctx,
1233 if (!NT_STATUS_IS_OK(result)) {
1237 rpccli_lsa_Close(cli, mem_ctx, &user_pol);
1238 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
1243 static NTSTATUS cmd_lsa_del_priv(struct rpc_pipe_client *cli,
1244 TALLOC_CTX *mem_ctx, int argc,
1247 POLICY_HND dom_pol, user_pol;
1248 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1249 struct lsa_PrivilegeSet privs;
1250 struct lsa_LUIDAttribute *set = NULL;
1257 printf("Usage: %s SID [rights...]\n", argv[0]);
1258 return NT_STATUS_OK;
1261 result = name_to_sid(cli, mem_ctx, &sid, argv[1]);
1262 if (!NT_STATUS_IS_OK(result)) {
1266 result = rpccli_lsa_open_policy2(cli, mem_ctx, True,
1267 SEC_RIGHTS_MAXIMUM_ALLOWED,
1270 if (!NT_STATUS_IS_OK(result)) {
1274 result = rpccli_lsa_OpenAccount(cli, mem_ctx,
1277 SEC_RIGHTS_MAXIMUM_ALLOWED,
1280 if (!NT_STATUS_IS_OK(result)) {
1284 for (i=2; i<argc; i++) {
1286 struct lsa_String priv_name;
1287 struct lsa_LUID luid;
1289 init_lsa_String(&priv_name, argv[i]);
1291 result = rpccli_lsa_LookupPrivValue(cli, mem_ctx,
1295 if (!NT_STATUS_IS_OK(result)) {
1300 set = TALLOC_REALLOC_ARRAY(mem_ctx, set,
1301 struct lsa_LUIDAttribute,
1304 return NT_STATUS_NO_MEMORY;
1307 set[privs.count-1].luid = luid;
1308 set[privs.count-1].attribute = 0;
1314 result = rpccli_lsa_RemovePrivilegesFromAccount(cli, mem_ctx,
1319 if (!NT_STATUS_IS_OK(result)) {
1323 rpccli_lsa_Close(cli, mem_ctx, &user_pol);
1324 rpccli_lsa_Close(cli, mem_ctx, &dom_pol);
1330 /* List of commands exported by this module */
1332 struct cmd_set lsarpc_commands[] = {
1336 { "lsaquery", RPC_RTYPE_NTSTATUS, cmd_lsa_query_info_policy, NULL, PI_LSARPC, NULL, "Query info policy", "" },
1337 { "lookupsids", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_sids, NULL, PI_LSARPC, NULL, "Convert SIDs to names", "" },
1338 { "lookupnames", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names, NULL, PI_LSARPC, NULL, "Convert names to SIDs", "" },
1339 { "lookupnames_level", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_names_level, NULL, PI_LSARPC, NULL, "Convert names to SIDs", "" },
1340 { "enumtrust", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_trust_dom, NULL, PI_LSARPC, NULL, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
1341 { "enumprivs", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privilege, NULL, PI_LSARPC, NULL, "Enumerate privileges", "" },
1342 { "getdispname", RPC_RTYPE_NTSTATUS, cmd_lsa_get_dispname, NULL, PI_LSARPC, NULL, "Get the privilege name", "" },
1343 { "lsaenumsid", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_sids, NULL, PI_LSARPC, NULL, "Enumerate the LSA SIDS", "" },
1344 { "lsacreateaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_create_account, NULL, PI_LSARPC, NULL, "Create a new lsa account", "" },
1345 { "lsaenumprivsaccount", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_privsaccounts, NULL, PI_LSARPC, NULL, "Enumerate the privileges of an SID", "" },
1346 { "lsaenumacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_enum_acct_rights, NULL, PI_LSARPC, NULL, "Enumerate the rights of an SID", "" },
1347 { "lsaaddpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_add_priv, NULL, PI_LSARPC, NULL, "Assign a privilege to a SID", "" },
1348 { "lsadelpriv", RPC_RTYPE_NTSTATUS, cmd_lsa_del_priv, NULL, PI_LSARPC, NULL, "Revoke a privilege from a SID", "" },
1349 { "lsaaddacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_add_acct_rights, NULL, PI_LSARPC, NULL, "Add rights to an account", "" },
1350 { "lsaremoveacctrights", RPC_RTYPE_NTSTATUS, cmd_lsa_remove_acct_rights, NULL, PI_LSARPC, NULL, "Remove rights from an account", "" },
1351 { "lsalookupprivvalue", RPC_RTYPE_NTSTATUS, cmd_lsa_lookup_priv_value, NULL, PI_LSARPC, NULL, "Get a privilege value given its name", "" },
1352 { "lsaquerysecobj", RPC_RTYPE_NTSTATUS, cmd_lsa_query_secobj, NULL, PI_LSARPC, NULL, "Query LSA security object", "" },
1353 { "lsaquerytrustdominfo",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfo, NULL, PI_LSARPC, NULL, "Query LSA trusted domains info (given a SID)", "" },
1354 { "lsaquerytrustdominfobyname",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobyname, NULL, PI_LSARPC, NULL, "Query LSA trusted domains info (given a name), only works for Windows > 2k", "" },
1355 { "lsaquerytrustdominfobysid",RPC_RTYPE_NTSTATUS, cmd_lsa_query_trustdominfobysid, NULL, PI_LSARPC, NULL, "Query LSA trusted domains info (given a SID)", "" },
1356 { "getusername", RPC_RTYPE_NTSTATUS, cmd_lsa_get_username, NULL, PI_LSARPC, NULL, "Get username", "" },