2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2006 Guenther Deschner
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include "utils/net.h"
23 /********************************************************************
24 ********************************************************************/
26 static int net_help_audit(int argc, const char **argv)
28 d_printf("net rpc audit list View configured Auditing policies\n");
29 d_printf("net rpc audit enable Enable Auditing\n");
30 d_printf("net rpc audit disable Disable Auditing\n");
31 d_printf("net rpc audit get <category> View configured Auditing policy setting\n");
32 d_printf("net rpc audit set <category> <policy> Set Auditing policies\n\n");
33 d_printf("\tcategory can be one of: SYSTEM, LOGON, OBJECT, PRIVILEGE, PROCESS, POLICY, SAM, DIRECTORY or ACCOUNT\n");
34 d_printf("\tpolicy can be one of: SUCCESS, FAILURE, ALL or NONE\n\n");
39 /********************************************************************
40 ********************************************************************/
42 static void print_auditing_category(const char *policy, const char *value)
45 int pad_len, col_len = 30;
54 /* calculate padding space for d_printf to look nicer */
55 pad_len = col_len - strlen(policy);
57 do padding[--pad_len] = ' '; while (pad_len > 0);
59 d_printf("\t%s%s%s\n", policy, padding, value);
63 /********************************************************************
64 ********************************************************************/
66 static NTSTATUS rpc_audit_get_internal(const DOM_SID *domain_sid,
67 const char *domain_name,
68 struct cli_state *cli,
69 struct rpc_pipe_client *pipe_hnd,
75 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
79 uint32 info_class = 2;
80 uint32 audit_category;
82 if (argc < 1 || argc > 2) {
83 d_printf("insufficient arguments\n");
84 net_help_audit(argc, argv);
85 return NT_STATUS_INVALID_PARAMETER;
88 if (!get_audit_category_from_param(argv[0], &audit_category)) {
89 d_printf("invalid auditing category: %s\n", argv[0]);
90 return NT_STATUS_INVALID_PARAMETER;
93 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
94 SEC_RIGHTS_MAXIMUM_ALLOWED,
97 if (!NT_STATUS_IS_OK(result)) {
101 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
105 if (!NT_STATUS_IS_OK(result)) {
109 for (i=0; i < dom.info.id2.count1; i++) {
111 const char *val = NULL, *policy = NULL;
113 if (i != audit_category) {
117 val = audit_policy_str(mem_ctx, dom.info.id2.auditsettings[i]);
118 policy = audit_description_str(i);
119 print_auditing_category(policy, val);
123 if (!NT_STATUS_IS_OK(result)) {
124 d_printf("failed to get auditing policy: %s\n", nt_errstr(result));
130 /********************************************************************
131 ********************************************************************/
133 static NTSTATUS rpc_audit_set_internal(const DOM_SID *domain_sid,
134 const char *domain_name,
135 struct cli_state *cli,
136 struct rpc_pipe_client *pipe_hnd,
142 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
145 uint32 info_class = 2;
146 uint32 audit_policy, audit_category;
148 if (argc < 2 || argc > 3) {
149 d_printf("insufficient arguments\n");
150 net_help_audit(argc, argv);
151 return NT_STATUS_INVALID_PARAMETER;
154 if (!get_audit_category_from_param(argv[0], &audit_category)) {
155 d_printf("invalid auditing category: %s\n", argv[0]);
156 return NT_STATUS_INVALID_PARAMETER;
159 audit_policy = LSA_AUDIT_POLICY_CLEAR;
161 if (strequal(argv[1], "Success")) {
162 audit_policy |= LSA_AUDIT_POLICY_SUCCESS;
163 } else if (strequal(argv[1], "Failure")) {
164 audit_policy |= LSA_AUDIT_POLICY_FAILURE;
165 } else if (strequal(argv[1], "All")) {
166 audit_policy |= LSA_AUDIT_POLICY_ALL;
167 } else if (strequal(argv[1], "None")) {
168 audit_policy = LSA_AUDIT_POLICY_CLEAR;
170 d_printf("invalid auditing policy: %s\n", argv[1]);
171 return NT_STATUS_INVALID_PARAMETER;
174 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
175 SEC_RIGHTS_MAXIMUM_ALLOWED,
178 if (!NT_STATUS_IS_OK(result)) {
182 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
186 if (!NT_STATUS_IS_OK(result)) {
190 dom.info.id2.auditsettings[audit_category] = audit_policy;
192 result = rpccli_lsa_set_info_policy(pipe_hnd, mem_ctx, &pol,
195 if (!NT_STATUS_IS_OK(result)) {
199 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
204 const char *val = audit_policy_str(mem_ctx, dom.info.id2.auditsettings[audit_category]);
205 const char *policy = audit_description_str(audit_category);
206 print_auditing_category(policy, val);
210 if (!NT_STATUS_IS_OK(result)) {
211 d_printf("failed to set audit policy: %s\n", nt_errstr(result));
217 static NTSTATUS rpc_audit_enable_internal_ext(struct rpc_pipe_client *pipe_hnd,
224 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
227 uint32 info_class = 2;
229 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
230 SEC_RIGHTS_MAXIMUM_ALLOWED,
233 if (!NT_STATUS_IS_OK(result)) {
237 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
241 if (!NT_STATUS_IS_OK(result)) {
245 dom.info.id2.auditing_enabled = enable;
247 result = rpccli_lsa_set_info_policy(pipe_hnd, mem_ctx, &pol,
251 if (!NT_STATUS_IS_OK(result)) {
256 if (!NT_STATUS_IS_OK(result)) {
257 d_printf("failed to %s audit policy: %s\n", enable ? "enable":"disable",
263 /********************************************************************
264 ********************************************************************/
266 static NTSTATUS rpc_audit_disable_internal(const DOM_SID *domain_sid,
267 const char *domain_name,
268 struct cli_state *cli,
269 struct rpc_pipe_client *pipe_hnd,
274 return rpc_audit_enable_internal_ext(pipe_hnd, mem_ctx, argc, argv, False);
277 /********************************************************************
278 ********************************************************************/
280 static NTSTATUS rpc_audit_enable_internal(const DOM_SID *domain_sid,
281 const char *domain_name,
282 struct cli_state *cli,
283 struct rpc_pipe_client *pipe_hnd,
288 return rpc_audit_enable_internal_ext(pipe_hnd, mem_ctx, argc, argv, True);
291 /********************************************************************
292 ********************************************************************/
294 static NTSTATUS rpc_audit_list_internal(const DOM_SID *domain_sid,
295 const char *domain_name,
296 struct cli_state *cli,
297 struct rpc_pipe_client *pipe_hnd,
303 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
307 uint32 info_class = 2;
309 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
310 SEC_RIGHTS_MAXIMUM_ALLOWED,
313 if (!NT_STATUS_IS_OK(result)) {
317 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
321 if (!NT_STATUS_IS_OK(result)) {
325 printf("Auditing:\t\t");
326 switch (dom.info.id2.auditing_enabled) {
334 printf("unknown (%d)", dom.info.id2.auditing_enabled);
339 printf("Auditing categories:\t%d\n", dom.info.id2.count1);
340 printf("Auditing settings:\n");
342 for (i=0; i < dom.info.id2.count1; i++) {
343 const char *val = audit_policy_str(mem_ctx, dom.info.id2.auditsettings[i]);
344 const char *policy = audit_description_str(i);
345 print_auditing_category(policy, val);
349 if (!NT_STATUS_IS_OK(result)) {
350 d_printf("failed to list auditing policies: %s\n", nt_errstr(result));
358 /********************************************************************
359 ********************************************************************/
361 static int rpc_audit_get(int argc, const char **argv)
363 return run_rpc_command(NULL, PI_LSARPC, 0,
364 rpc_audit_get_internal, argc, argv);
367 /********************************************************************
368 ********************************************************************/
370 static int rpc_audit_set(int argc, const char **argv)
372 return run_rpc_command(NULL, PI_LSARPC, 0,
373 rpc_audit_set_internal, argc, argv);
376 /********************************************************************
377 ********************************************************************/
379 static int rpc_audit_enable(int argc, const char **argv)
381 return run_rpc_command(NULL, PI_LSARPC, 0,
382 rpc_audit_enable_internal, argc, argv);
385 /********************************************************************
386 ********************************************************************/
388 static int rpc_audit_disable(int argc, const char **argv)
390 return run_rpc_command(NULL, PI_LSARPC, 0,
391 rpc_audit_disable_internal, argc, argv);
394 /********************************************************************
395 ********************************************************************/
397 static int rpc_audit_list(int argc, const char **argv)
399 return run_rpc_command(NULL, PI_LSARPC, 0,
400 rpc_audit_list_internal, argc, argv);
403 /********************************************************************
404 ********************************************************************/
406 int net_rpc_audit(int argc, const char **argv)
408 struct functable func[] = {
409 {"get", rpc_audit_get},
410 {"set", rpc_audit_set},
411 {"enable", rpc_audit_enable},
412 {"disable", rpc_audit_disable},
413 {"list", rpc_audit_list},
418 return net_run_function(argc, argv, func, net_help_audit);
420 return net_help_audit(argc, argv);