2 Unix SMB/Netbios implementation.
6 Copyright (C) Tim Potter 2000
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 /* Lookup the names */
98 result
= cli_lsa_lookup_names(cli
, mem_ctx
, &pol
, argc
- 1,
99 (const char **)&argv
[1], &sids
,
102 if (!NT_STATUS_IS_OK(result
))
107 for (i
= 0; i
< num_names
; 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
;
132 printf("Usage: %s [sid1 [sid2 [...]]]\n", argv
[0]);
136 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
137 SEC_RIGHTS_MAXIMUM_ALLOWED
,
140 if (!NT_STATUS_IS_OK(result
))
143 /* Convert arguments to sids */
145 sids
= (DOM_SID
*)talloc(mem_ctx
, sizeof(DOM_SID
) * (argc
- 1));
148 printf("could not allocate memory for %d sids\n", argc
- 1);
152 for (i
= 0; i
< argc
- 1; i
++)
153 string_to_sid(&sids
[i
], argv
[i
+ 1]);
155 /* Lookup the SIDs */
157 result
= cli_lsa_lookup_sids(cli
, mem_ctx
, &pol
, argc
- 1, sids
,
158 &names
, &types
, &num_names
);
160 if (!NT_STATUS_IS_OK(result
))
165 for (i
= 0; i
< num_names
; i
++) {
168 sid_to_string(sid_str
, &sids
[i
]);
169 printf("%s %s (%d)\n", sid_str
, names
[i
] ? names
[i
] :
170 "*unknown*", types
[i
]);
177 /* Enumerate list of trusted domains */
179 static NTSTATUS
cmd_lsa_enum_trust_dom(struct cli_state
*cli
,
180 TALLOC_CTX
*mem_ctx
, int argc
,
184 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
185 DOM_SID
*domain_sids
;
192 printf("Usage: %s\n", argv
[0]);
196 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
197 SEC_RIGHTS_MAXIMUM_ALLOWED
,
200 if (!NT_STATUS_IS_OK(result
))
203 /* Lookup list of trusted domains */
205 result
= cli_lsa_enum_trust_dom(cli
, mem_ctx
, &pol
, &enum_ctx
,
206 &num_domains
, &domain_names
,
209 if (!NT_STATUS_IS_OK(result
))
214 for (i
= 0; i
< num_domains
; i
++) {
217 sid_to_string(sid_str
, &domain_sids
[i
]);
218 printf("%s %s\n", domain_names
[i
] ? domain_names
[i
] :
219 "*unknown*", sid_str
);
226 /* Enumerates privileges */
228 static NTSTATUS
cmd_lsa_enum_privilege(struct cli_state
*cli
,
229 TALLOC_CTX
*mem_ctx
, int argc
,
233 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
235 uint32 enum_context
=0;
236 uint32 pref_max_length
=0x1000;
244 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
249 enum_context
=atoi(argv
[1]);
252 pref_max_length
=atoi(argv
[2]);
254 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
255 SEC_RIGHTS_MAXIMUM_ALLOWED
,
258 if (!NT_STATUS_IS_OK(result
))
261 result
= cli_lsa_enum_privilege(cli
, mem_ctx
, &pol
, &enum_context
, pref_max_length
,
262 &count
, &privs_name
, &privs_high
, &privs_low
);
264 if (!NT_STATUS_IS_OK(result
))
268 printf("found %d privileges\n\n", count
);
270 for (i
= 0; i
< count
; i
++) {
271 printf("%s \t\t%d:%d (0x%x:0x%x)\n", privs_name
[i
] ? privs_name
[i
] : "*unknown*",
272 privs_high
[i
], privs_low
[i
], privs_high
[i
], privs_low
[i
]);
279 /* Get privilege name */
281 static NTSTATUS
cmd_lsa_get_dispname(struct cli_state
*cli
,
282 TALLOC_CTX
*mem_ctx
, int argc
,
286 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
289 uint16 lang_id_sys
=0;
294 printf("Usage: %s privilege name\n", argv
[0]);
298 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
299 SEC_RIGHTS_MAXIMUM_ALLOWED
,
302 if (!NT_STATUS_IS_OK(result
))
305 result
= cli_lsa_get_dispname(cli
, mem_ctx
, &pol
, argv
[1], lang_id
, lang_id_sys
, description
, &lang_id_desc
);
307 if (!NT_STATUS_IS_OK(result
))
311 printf("%s -> %s (language: 0x%x)\n", argv
[1], description
, lang_id_desc
);
317 /* Enumerate the LSA SIDS */
319 static NTSTATUS
cmd_lsa_enum_sids(struct cli_state
*cli
,
320 TALLOC_CTX
*mem_ctx
, int argc
,
324 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
326 uint32 enum_context
=0;
327 uint32 pref_max_length
=0x1000;
333 printf("Usage: %s [enum context] [max length]\n", argv
[0]);
338 enum_context
=atoi(argv
[1]);
341 pref_max_length
=atoi(argv
[2]);
343 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
344 SEC_RIGHTS_MAXIMUM_ALLOWED
,
347 if (!NT_STATUS_IS_OK(result
))
350 result
= cli_lsa_enum_sids(cli
, mem_ctx
, &pol
, &enum_context
, pref_max_length
,
353 if (!NT_STATUS_IS_OK(result
))
357 printf("found %d SIDs\n\n", count
);
359 for (i
= 0; i
< count
; i
++) {
362 sid_to_string(sid_str
, &sids
[i
]);
363 printf("%s\n", sid_str
);
370 /* Enumerate the privileges of an SID */
372 static NTSTATUS
cmd_lsa_enum_privsaccounts(struct cli_state
*cli
,
373 TALLOC_CTX
*mem_ctx
, int argc
,
378 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
379 uint32 access_desired
= 0x000f000f;
387 printf("Usage: %s SID\n", argv
[0]);
391 string_to_sid(&sid
, argv
[1]);
393 result
= cli_lsa_open_policy2(cli
, mem_ctx
, True
,
394 SEC_RIGHTS_MAXIMUM_ALLOWED
,
397 if (!NT_STATUS_IS_OK(result
))
400 result
= cli_lsa_open_account(cli
, mem_ctx
, &dom_pol
, &sid
, access_desired
, &user_pol
);
402 if (!NT_STATUS_IS_OK(result
))
405 result
= cli_lsa_enum_privsaccount(cli
, mem_ctx
, &user_pol
, &count
, &set
);
407 if (!NT_STATUS_IS_OK(result
))
411 printf("found %d privileges for SID %s\n\n", count
, argv
[1]);
412 printf("high\tlow\tattribute\n");
414 for (i
= 0; i
< count
; i
++) {
415 printf("%u\t%u\t%u\n", set
[i
].luid
.high
, set
[i
].luid
.low
, set
[i
].attr
);
422 /* Get a privilege value given its name */
424 static NTSTATUS
cmd_lsa_lookupprivvalue(struct cli_state
*cli
,
425 TALLOC_CTX
*mem_ctx
, int argc
,
429 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
433 printf("Usage: %s name\n", argv
[0]);
437 result
= cli_lsa_open_policy2(cli
, mem_ctx
, True
,
438 SEC_RIGHTS_MAXIMUM_ALLOWED
,
441 if (!NT_STATUS_IS_OK(result
))
444 result
= cli_lsa_lookupprivvalue(cli
, mem_ctx
, &pol
, argv
[1], &luid
);
446 if (!NT_STATUS_IS_OK(result
))
450 printf("%u:%u (0x%x:0x%x)\n", luid
.high
, luid
.low
, luid
.high
, luid
.low
);
456 /* Query LSA security object */
458 static NTSTATUS
cmd_lsa_query_secobj(struct cli_state
*cli
,
459 TALLOC_CTX
*mem_ctx
, int argc
,
463 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
465 uint32 sec_info
= 0x00000004; /* ??? */
468 printf("Usage: %s\n", argv
[0]);
472 result
= cli_lsa_open_policy2(cli
, mem_ctx
, True
,
473 SEC_RIGHTS_MAXIMUM_ALLOWED
,
476 if (!NT_STATUS_IS_OK(result
))
479 result
= cli_lsa_query_secobj(cli
, mem_ctx
, &pol
, sec_info
, &sdb
);
481 if (!NT_STATUS_IS_OK(result
))
486 display_sec_desc(sdb
->sec
);
492 /* List of commands exported by this module */
494 struct cmd_set lsarpc_commands
[] = {
498 { "lsaquery", cmd_lsa_query_info_policy
, PIPE_LSARPC
, "Query info policy", "" },
499 { "lookupsids", cmd_lsa_lookup_sids
, PIPE_LSARPC
, "Convert SIDs to names", "" },
500 { "lookupnames", cmd_lsa_lookup_names
, PIPE_LSARPC
, "Convert names to SIDs", "" },
501 { "enumtrust", cmd_lsa_enum_trust_dom
, PIPE_LSARPC
, "Enumerate trusted domains", "" },
502 { "enumprivs", cmd_lsa_enum_privilege
, PIPE_LSARPC
, "Enumerate privileges", "" },
503 { "getdispname", cmd_lsa_get_dispname
, PIPE_LSARPC
, "Get the privilege name", "" },
504 { "lsaenumsid", cmd_lsa_enum_sids
, PIPE_LSARPC
, "Enumerate the LSA SIDS", "" },
505 { "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts
, PIPE_LSARPC
, "Enumerate the privileges of an SID", "" },
506 { "lsalookupprivvalue", cmd_lsa_lookupprivvalue
, PIPE_LSARPC
, "Get a privilege value given its name", "" },
507 { "lsaquerysecobj", cmd_lsa_query_secobj
, PIPE_LSARPC
, "Query LSA security object", "" },