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;
36 fstring sid_str, domain_name="", dns_name="", forest_name="";
37 uint32 info_class = 3;
40 printf("Usage: %s [info_class]\n", argv[0]);
45 info_class = atoi(argv[1]);
47 /* Lookup info policy */
50 result = cli_lsa_open_policy2(cli, mem_ctx, True,
51 SEC_RIGHTS_MAXIMUM_ALLOWED,
54 if (!NT_STATUS_IS_OK(result))
56 result = cli_lsa_query_info_policy2(cli, mem_ctx, &pol,
57 info_class, domain_name,
58 dns_name, forest_name,
62 result = cli_lsa_open_policy(cli, mem_ctx, True,
63 SEC_RIGHTS_MAXIMUM_ALLOWED,
66 if (!NT_STATUS_IS_OK(result))
68 result = cli_lsa_query_info_policy(cli, mem_ctx, &pol,
69 info_class, domain_name,
73 if (!NT_STATUS_IS_OK(result))
76 sid_to_string(sid_str, &dom_sid);
79 printf("domain %s has sid %s\n", domain_name, sid_str);
81 printf("could not query info for level %d\n", info_class);
84 printf("domain dns name is %s\n", dns_name);
86 printf("forest name is %s\n", forest_name);
88 if (info_class == 12) {
90 uint32 *data1 = (uint32 *) dom_guid.info;
91 uint16 *data2 = (uint16 *) &dom_guid.info[4];
92 uint16 *data3 = (uint16 *) &dom_guid.info[6];
93 printf("domain GUID is %08x-%04x-%04x", *data1,*data2,*data3);
94 printf("-%02x%02x-", dom_guid.info[8], dom_guid.info[9]);
95 for (i=10;i<GUID_SIZE;i++)
96 printf("%02x", dom_guid.info[i]);
103 /* Resolve a list of names to a list of sids */
105 static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
106 TALLOC_CTX *mem_ctx, int argc,
110 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
116 printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
120 result = cli_lsa_open_policy(cli, mem_ctx, True,
121 SEC_RIGHTS_MAXIMUM_ALLOWED,
124 if (!NT_STATUS_IS_OK(result))
127 result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
128 (const char**)(argv + 1), &sids, &types);
130 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
131 NT_STATUS_V(STATUS_SOME_UNMAPPED))
134 result = NT_STATUS_OK;
138 for (i = 0; i < (argc - 1); i++) {
140 sid_to_string(sid_str, &sids[i]);
141 printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
142 sid_type_lookup(types[i]), types[i]);
149 /* Resolve a list of SIDs to a list of names */
151 static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
152 int argc, char **argv)
155 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
163 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
167 result = cli_lsa_open_policy(cli, mem_ctx, True,
168 SEC_RIGHTS_MAXIMUM_ALLOWED,
171 if (!NT_STATUS_IS_OK(result))
174 /* Convert arguments to sids */
176 sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
179 printf("could not allocate memory for %d sids\n", argc - 1);
183 for (i = 0; i < argc - 1; i++)
184 string_to_sid(&sids[i], argv[i + 1]);
186 /* Lookup the SIDs */
188 result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
189 &domains, &names, &types);
191 if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
192 NT_STATUS_V(STATUS_SOME_UNMAPPED))
195 result = NT_STATUS_OK;
199 for (i = 0; i < (argc - 1); i++) {
202 sid_to_string(sid_str, &sids[i]);
203 printf("%s %s\\%s (%d)\n", sid_str,
204 domains[i] ? domains[i] : "*unknown*",
205 names[i] ? names[i] : "*unknown*", types[i]);
212 /* Enumerate list of trusted domains */
214 static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
215 TALLOC_CTX *mem_ctx, int argc,
219 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
220 DOM_SID *domain_sids;
223 /* defaults, but may be changed using params */
225 uint32 num_domains = 0;
229 printf("Usage: %s [enum context (0)]\n", argv[0]);
233 if (argc == 2 && argv[1]) {
234 enum_ctx = atoi(argv[2]);
237 result = cli_lsa_open_policy(cli, mem_ctx, True,
238 POLICY_VIEW_LOCAL_INFORMATION,
241 if (!NT_STATUS_IS_OK(result))
244 /* Lookup list of trusted domains */
246 result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
248 &domain_names, &domain_sids);
249 if (!NT_STATUS_IS_OK(result) &&
250 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
251 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
254 /* Print results: list of names and sids returned in this response. */
255 for (i = 0; i < num_domains; i++) {
258 sid_to_string(sid_str, &domain_sids[i]);
259 printf("%s %s\n", domain_names[i] ? domain_names[i] :
260 "*unknown*", sid_str);
267 /* Enumerates privileges */
269 static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli,
270 TALLOC_CTX *mem_ctx, int argc,
274 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
276 uint32 enum_context=0;
277 uint32 pref_max_length=0x1000;
285 printf("Usage: %s [enum context] [max length]\n", argv[0]);
290 enum_context=atoi(argv[1]);
293 pref_max_length=atoi(argv[2]);
295 result = cli_lsa_open_policy(cli, mem_ctx, True,
296 SEC_RIGHTS_MAXIMUM_ALLOWED,
299 if (!NT_STATUS_IS_OK(result))
302 result = cli_lsa_enum_privilege(cli, mem_ctx, &pol, &enum_context, pref_max_length,
303 &count, &privs_name, &privs_high, &privs_low);
305 if (!NT_STATUS_IS_OK(result))
309 printf("found %d privileges\n\n", count);
311 for (i = 0; i < count; i++) {
312 printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name[i] ? privs_name[i] : "*unknown*",
313 privs_high[i], privs_low[i], privs_high[i], privs_low[i]);
320 /* Get privilege name */
322 static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
323 TALLOC_CTX *mem_ctx, int argc,
327 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
330 uint16 lang_id_sys=0;
335 printf("Usage: %s privilege name\n", argv[0]);
339 result = cli_lsa_open_policy(cli, mem_ctx, True,
340 SEC_RIGHTS_MAXIMUM_ALLOWED,
343 if (!NT_STATUS_IS_OK(result))
346 result = cli_lsa_get_dispname(cli, mem_ctx, &pol, argv[1], lang_id, lang_id_sys, description, &lang_id_desc);
348 if (!NT_STATUS_IS_OK(result))
352 printf("%s -> %s (language: 0x%x)\n", argv[1], description, lang_id_desc);
358 /* Enumerate the LSA SIDS */
360 static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli,
361 TALLOC_CTX *mem_ctx, int argc,
365 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
367 uint32 enum_context=0;
368 uint32 pref_max_length=0x1000;
374 printf("Usage: %s [enum context] [max length]\n", argv[0]);
379 enum_context=atoi(argv[1]);
382 pref_max_length=atoi(argv[2]);
384 result = cli_lsa_open_policy(cli, mem_ctx, True,
385 SEC_RIGHTS_MAXIMUM_ALLOWED,
388 if (!NT_STATUS_IS_OK(result))
391 result = cli_lsa_enum_sids(cli, mem_ctx, &pol, &enum_context, pref_max_length,
394 if (!NT_STATUS_IS_OK(result))
398 printf("found %d SIDs\n\n", count);
400 for (i = 0; i < count; i++) {
403 sid_to_string(sid_str, &sids[i]);
404 printf("%s\n", sid_str);
411 /* Enumerate the privileges of an SID */
413 static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli,
414 TALLOC_CTX *mem_ctx, int argc,
419 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
420 uint32 access_desired = 0x000f000f;
428 printf("Usage: %s SID\n", argv[0]);
432 string_to_sid(&sid, argv[1]);
434 result = cli_lsa_open_policy2(cli, mem_ctx, True,
435 SEC_RIGHTS_MAXIMUM_ALLOWED,
438 if (!NT_STATUS_IS_OK(result))
441 result = cli_lsa_open_account(cli, mem_ctx, &dom_pol, &sid, access_desired, &user_pol);
443 if (!NT_STATUS_IS_OK(result))
446 result = cli_lsa_enum_privsaccount(cli, mem_ctx, &user_pol, &count, &set);
448 if (!NT_STATUS_IS_OK(result))
452 printf("found %d privileges for SID %s\n\n", count, argv[1]);
453 printf("high\tlow\tattribute\n");
455 for (i = 0; i < count; i++) {
456 printf("%u\t%u\t%u\n", set[i].luid.high, set[i].luid.low, set[i].attr);
463 /* Get a privilege value given its name */
465 static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli,
466 TALLOC_CTX *mem_ctx, int argc,
470 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
474 printf("Usage: %s name\n", argv[0]);
478 result = cli_lsa_open_policy2(cli, mem_ctx, True,
479 SEC_RIGHTS_MAXIMUM_ALLOWED,
482 if (!NT_STATUS_IS_OK(result))
485 result = cli_lsa_lookupprivvalue(cli, mem_ctx, &pol, argv[1], &luid);
487 if (!NT_STATUS_IS_OK(result))
492 printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
498 /* Query LSA security object */
500 static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli,
501 TALLOC_CTX *mem_ctx, int argc,
505 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
507 uint32 sec_info = 0x00000004; /* ??? */
510 printf("Usage: %s\n", argv[0]);
514 result = cli_lsa_open_policy2(cli, mem_ctx, True,
515 SEC_RIGHTS_MAXIMUM_ALLOWED,
518 if (!NT_STATUS_IS_OK(result))
521 result = cli_lsa_query_secobj(cli, mem_ctx, &pol, sec_info, &sdb);
523 if (!NT_STATUS_IS_OK(result))
528 display_sec_desc(sdb->sec);
534 /* List of commands exported by this module */
536 struct cmd_set lsarpc_commands[] = {
540 { "lsaquery", cmd_lsa_query_info_policy, PIPE_LSARPC, "Query info policy", "" },
541 { "lookupsids", cmd_lsa_lookup_sids, PIPE_LSARPC, "Convert SIDs to names", "" },
542 { "lookupnames", cmd_lsa_lookup_names, PIPE_LSARPC, "Convert names to SIDs", "" },
543 { "enumtrust", cmd_lsa_enum_trust_dom, PIPE_LSARPC, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
544 { "enumprivs", cmd_lsa_enum_privilege, PIPE_LSARPC, "Enumerate privileges", "" },
545 { "getdispname", cmd_lsa_get_dispname, PIPE_LSARPC, "Get the privilege name", "" },
546 { "lsaenumsid", cmd_lsa_enum_sids, PIPE_LSARPC, "Enumerate the LSA SIDS", "" },
547 { "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PIPE_LSARPC, "Enumerate the privileges of an SID", "" },
548 { "lsalookupprivvalue", cmd_lsa_lookupprivvalue, PIPE_LSARPC, "Get a privilege value given its name", "" },
549 { "lsaquerysecobj", cmd_lsa_query_secobj, PIPE_LSARPC, "Query LSA security object", "" },