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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rpcclient.h"
26 /* Look up domain related information on a remote host */
28 static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli,
29 TALLOC_CTX *mem_ctx, int argc,
33 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
35 fstring sid_str, domain_name;
36 uint32 info_class = 3;
39 printf("Usage: %s [info_class]\n", argv[0]);
44 info_class = atoi(argv[1]);
46 result = cli_lsa_open_policy(cli, mem_ctx, True,
47 SEC_RIGHTS_MAXIMUM_ALLOWED,
50 if (!NT_STATUS_IS_OK(result))
53 /* Lookup info policy */
55 result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
56 domain_name, &dom_sid);
58 if (!NT_STATUS_IS_OK(result))
61 sid_to_string(sid_str, &dom_sid);
64 printf("domain %s has sid %s\n", domain_name, sid_str);
66 printf("could not query info for level %d\n", info_class);
72 /* Resolve a list of names to a list of sids */
74 static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
75 TALLOC_CTX *mem_ctx, int argc,
79 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
85 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
89 result = cli_lsa_open_policy(cli, mem_ctx, True,
90 SEC_RIGHTS_MAXIMUM_ALLOWED,
93 if (!NT_STATUS_IS_OK(result))
96 result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
97 (const char**)(argv + 1), &sids, &types);
99 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
100 NT_STATUS_V(STATUS_SOME_UNMAPPED))
103 result = NT_STATUS_OK;
107 for (i = 0; i < (argc - 1); i++) {
110 sid_to_string(sid_str, &sids[i]);
111 printf("%s %s (%d)\n", argv[i + 1], sid_str,
119 /* Resolve a list of SIDs to a list of names */
121 static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
122 int argc, char **argv)
125 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
133 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
137 result = cli_lsa_open_policy(cli, mem_ctx, True,
138 SEC_RIGHTS_MAXIMUM_ALLOWED,
141 if (!NT_STATUS_IS_OK(result))
144 /* Convert arguments to sids */
146 sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
149 printf("could not allocate memory for %d sids\n", argc - 1);
153 for (i = 0; i < argc - 1; i++)
154 string_to_sid(&sids[i], argv[i + 1]);
156 /* Lookup the SIDs */
158 result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
159 &domains, &names, &types);
161 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
162 NT_STATUS_V(STATUS_SOME_UNMAPPED))
165 result = NT_STATUS_OK;
169 for (i = 0; i < (argc - 1); i++) {
172 sid_to_string(sid_str, &sids[i]);
173 printf("%s %s\\%s (%d)\n", sid_str,
174 domains[i] ? domains[i] : "*unknown*",
175 names[i] ? names[i] : "*unknown*", types[i]);
182 /* Enumerate list of trusted domains */
184 static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
185 TALLOC_CTX *mem_ctx, int argc,
189 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
190 DOM_SID *domain_sids;
193 /* defaults, but may be changed using params */
195 uint32 preferred_maxnum = 5;
196 uint32 num_domains = 0;
200 printf("Usage: %s [preferred max number (%d)] [enum context (0)]\n",
201 argv[0], preferred_maxnum);
205 /* enumeration context */
206 if (argc >= 2 && argv[1]) {
207 preferred_maxnum = atoi(argv[1]);
210 /* preferred maximum number */
211 if (argc == 3 && argv[2]) {
212 enum_ctx = atoi(argv[2]);
215 result = cli_lsa_open_policy(cli, mem_ctx, True,
216 POLICY_VIEW_LOCAL_INFORMATION,
219 if (!NT_STATUS_IS_OK(result))
222 /* Lookup list of trusted domains */
224 result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
225 &preferred_maxnum, &num_domains,
226 &domain_names, &domain_sids);
227 if (!NT_STATUS_IS_OK(result) &&
228 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
229 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
232 /* Print results: list of names and sids returned in this response. */
233 for (i = 0; i < num_domains; i++) {
236 sid_to_string(sid_str, &domain_sids[i]);
237 printf("%s %s\n", domain_names[i] ? domain_names[i] :
238 "*unknown*", sid_str);
245 /* Enumerates privileges */
247 static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli,
248 TALLOC_CTX *mem_ctx, int argc,
252 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
254 uint32 enum_context=0;
255 uint32 pref_max_length=0x1000;
263 printf("Usage: %s [enum context] [max length]\n", argv[0]);
268 enum_context=atoi(argv[1]);
271 pref_max_length=atoi(argv[2]);
273 result = cli_lsa_open_policy(cli, mem_ctx, True,
274 SEC_RIGHTS_MAXIMUM_ALLOWED,
277 if (!NT_STATUS_IS_OK(result))
280 result = cli_lsa_enum_privilege(cli, mem_ctx, &pol, &enum_context, pref_max_length,
281 &count, &privs_name, &privs_high, &privs_low);
283 if (!NT_STATUS_IS_OK(result))
287 printf("found %d privileges\n\n", count);
289 for (i = 0; i < count; i++) {
290 printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name[i] ? privs_name[i] : "*unknown*",
291 privs_high[i], privs_low[i], privs_high[i], privs_low[i]);
298 /* Get privilege name */
300 static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
301 TALLOC_CTX *mem_ctx, int argc,
305 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
308 uint16 lang_id_sys=0;
313 printf("Usage: %s privilege name\n", argv[0]);
317 result = cli_lsa_open_policy(cli, mem_ctx, True,
318 SEC_RIGHTS_MAXIMUM_ALLOWED,
321 if (!NT_STATUS_IS_OK(result))
324 result = cli_lsa_get_dispname(cli, mem_ctx, &pol, argv[1], lang_id, lang_id_sys, description, &lang_id_desc);
326 if (!NT_STATUS_IS_OK(result))
330 printf("%s -> %s (language: 0x%x)\n", argv[1], description, lang_id_desc);
336 /* Enumerate the LSA SIDS */
338 static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli,
339 TALLOC_CTX *mem_ctx, int argc,
343 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
345 uint32 enum_context=0;
346 uint32 pref_max_length=0x1000;
352 printf("Usage: %s [enum context] [max length]\n", argv[0]);
357 enum_context=atoi(argv[1]);
360 pref_max_length=atoi(argv[2]);
362 result = cli_lsa_open_policy(cli, mem_ctx, True,
363 SEC_RIGHTS_MAXIMUM_ALLOWED,
366 if (!NT_STATUS_IS_OK(result))
369 result = cli_lsa_enum_sids(cli, mem_ctx, &pol, &enum_context, pref_max_length,
372 if (!NT_STATUS_IS_OK(result))
376 printf("found %d SIDs\n\n", count);
378 for (i = 0; i < count; i++) {
381 sid_to_string(sid_str, &sids[i]);
382 printf("%s\n", sid_str);
389 /* Enumerate the privileges of an SID */
391 static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli,
392 TALLOC_CTX *mem_ctx, int argc,
397 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
398 uint32 access_desired = 0x000f000f;
406 printf("Usage: %s SID\n", argv[0]);
410 string_to_sid(&sid, argv[1]);
412 result = cli_lsa_open_policy2(cli, mem_ctx, True,
413 SEC_RIGHTS_MAXIMUM_ALLOWED,
416 if (!NT_STATUS_IS_OK(result))
419 result = cli_lsa_open_account(cli, mem_ctx, &dom_pol, &sid, access_desired, &user_pol);
421 if (!NT_STATUS_IS_OK(result))
424 result = cli_lsa_enum_privsaccount(cli, mem_ctx, &user_pol, &count, &set);
426 if (!NT_STATUS_IS_OK(result))
430 printf("found %d privileges for SID %s\n\n", count, argv[1]);
431 printf("high\tlow\tattribute\n");
433 for (i = 0; i < count; i++) {
434 printf("%u\t%u\t%u\n", set[i].luid.high, set[i].luid.low, set[i].attr);
441 /* Get a privilege value given its name */
443 static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli,
444 TALLOC_CTX *mem_ctx, int argc,
448 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
452 printf("Usage: %s name\n", argv[0]);
456 result = cli_lsa_open_policy2(cli, mem_ctx, True,
457 SEC_RIGHTS_MAXIMUM_ALLOWED,
460 if (!NT_STATUS_IS_OK(result))
463 result = cli_lsa_lookupprivvalue(cli, mem_ctx, &pol, argv[1], &luid);
465 if (!NT_STATUS_IS_OK(result))
470 printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
476 /* Query LSA security object */
478 static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli,
479 TALLOC_CTX *mem_ctx, int argc,
483 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
485 uint32 sec_info = 0x00000004; /* ??? */
488 printf("Usage: %s\n", argv[0]);
492 result = cli_lsa_open_policy2(cli, mem_ctx, True,
493 SEC_RIGHTS_MAXIMUM_ALLOWED,
496 if (!NT_STATUS_IS_OK(result))
499 result = cli_lsa_query_secobj(cli, mem_ctx, &pol, sec_info, &sdb);
501 if (!NT_STATUS_IS_OK(result))
506 display_sec_desc(sdb->sec);
512 /* List of commands exported by this module */
514 struct cmd_set lsarpc_commands[] = {
518 { "lsaquery", cmd_lsa_query_info_policy, PIPE_LSARPC, "Query info policy", "" },
519 { "lookupsids", cmd_lsa_lookup_sids, PIPE_LSARPC, "Convert SIDs to names", "" },
520 { "lookupnames", cmd_lsa_lookup_names, PIPE_LSARPC, "Convert names to SIDs", "" },
521 { "enumtrust", cmd_lsa_enum_trust_dom, PIPE_LSARPC, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
522 { "enumprivs", cmd_lsa_enum_privilege, PIPE_LSARPC, "Enumerate privileges", "" },
523 { "getdispname", cmd_lsa_get_dispname, PIPE_LSARPC, "Get the privilege name", "" },
524 { "lsaenumsid", cmd_lsa_enum_sids, PIPE_LSARPC, "Enumerate the LSA SIDS", "" },
525 { "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PIPE_LSARPC, "Enumerate the privileges of an SID", "" },
526 { "lsalookupprivvalue", cmd_lsa_lookupprivvalue, PIPE_LSARPC, "Get a privilege value given its name", "" },
527 { "lsaquerysecobj", cmd_lsa_query_secobj, PIPE_LSARPC, "Query LSA security object", "" },