Add support for building PDF's thru FO rather then docbook2latex. Output
[Samba.git] / source / utils / net_rpc_audit.c
blob981dc93fdd7097d9db65c5a1cc2e4af221216f11
1 /*
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 2 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. */
20 #include "includes.h"
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");
36 return -1;
39 /********************************************************************
40 ********************************************************************/
42 static void print_auditing_category(const char *policy, const char *value)
44 fstring padding;
45 int pad_len, col_len = 30;
47 if (policy == NULL) {
48 policy = "Unknown";
50 if (value == NULL) {
51 value = "Invalid";
54 /* calculate padding space for d_printf to look nicer */
55 pad_len = col_len - strlen(policy);
56 padding[pad_len] = 0;
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,
70 TALLOC_CTX *mem_ctx,
71 int argc,
72 const char **argv)
74 POLICY_HND pol;
75 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
76 LSA_INFO_CTR dom;
77 int i;
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,
95 &pol);
97 if (!NT_STATUS_IS_OK(result)) {
98 goto done;
101 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
102 info_class,
103 &dom);
105 if (!NT_STATUS_IS_OK(result)) {
106 goto done;
109 for (i=0; i < dom.info.id2.count1; i++) {
111 const char *val = NULL, *policy = NULL;
113 if (i != audit_category) {
114 continue;
117 val = audit_policy_str(mem_ctx, dom.info.id2.auditsettings[i]);
118 policy = audit_description_str(i);
119 print_auditing_category(policy, val);
122 done:
123 if (!NT_STATUS_IS_OK(result)) {
124 d_printf("failed to get auditing policy: %s\n", nt_errstr(result));
127 return 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,
137 TALLOC_CTX *mem_ctx,
138 int argc,
139 const char **argv)
141 POLICY_HND pol;
142 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
143 LSA_INFO_CTR dom;
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;
169 } else {
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,
176 &pol);
178 if (!NT_STATUS_IS_OK(result)) {
179 goto done;
182 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
183 info_class,
184 &dom);
186 if (!NT_STATUS_IS_OK(result)) {
187 goto done;
190 dom.info.id2.auditsettings[audit_category] = audit_policy;
192 result = rpccli_lsa_set_info_policy(pipe_hnd, mem_ctx, &pol,
193 info_class,
194 dom);
195 if (!NT_STATUS_IS_OK(result)) {
196 goto done;
199 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
200 info_class,
201 &dom);
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);
209 done:
210 if (!NT_STATUS_IS_OK(result)) {
211 d_printf("failed to set audit policy: %s\n", nt_errstr(result));
214 return result;
217 static NTSTATUS rpc_audit_enable_internal_ext(struct rpc_pipe_client *pipe_hnd,
218 TALLOC_CTX *mem_ctx,
219 int argc,
220 const char **argv,
221 BOOL enable)
223 POLICY_HND pol;
224 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
225 LSA_INFO_CTR dom;
227 uint32 info_class = 2;
229 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
230 SEC_RIGHTS_MAXIMUM_ALLOWED,
231 &pol);
233 if (!NT_STATUS_IS_OK(result)) {
234 goto done;
237 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
238 info_class,
239 &dom);
241 if (!NT_STATUS_IS_OK(result)) {
242 goto done;
245 dom.info.id2.auditing_enabled = enable;
247 result = rpccli_lsa_set_info_policy(pipe_hnd, mem_ctx, &pol,
248 info_class,
249 dom);
251 if (!NT_STATUS_IS_OK(result)) {
252 goto done;
255 done:
256 if (!NT_STATUS_IS_OK(result)) {
257 d_printf("failed to %s audit policy: %s\n", enable ? "enable":"disable",
258 nt_errstr(result));
261 return result;
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,
270 TALLOC_CTX *mem_ctx,
271 int argc,
272 const char **argv)
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,
284 TALLOC_CTX *mem_ctx,
285 int argc,
286 const char **argv)
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,
298 TALLOC_CTX *mem_ctx,
299 int argc,
300 const char **argv)
302 POLICY_HND pol;
303 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
304 LSA_INFO_CTR dom;
305 int i;
307 uint32 info_class = 2;
309 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
310 SEC_RIGHTS_MAXIMUM_ALLOWED,
311 &pol);
313 if (!NT_STATUS_IS_OK(result)) {
314 goto done;
317 result = rpccli_lsa_query_info_policy_new(pipe_hnd, mem_ctx, &pol,
318 info_class,
319 &dom);
321 if (!NT_STATUS_IS_OK(result)) {
322 goto done;
325 printf("Auditing:\t\t");
326 switch (dom.info.id2.auditing_enabled) {
327 case True:
328 printf("Enabled");
329 break;
330 case False:
331 printf("Disabled");
332 break;
333 default:
334 printf("unknown (%d)", dom.info.id2.auditing_enabled);
335 break;
337 printf("\n");
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);
348 done:
349 if (!NT_STATUS_IS_OK(result)) {
350 d_printf("failed to list auditing policies: %s\n", nt_errstr(result));
353 return 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},
414 {NULL, NULL}
417 if (argc)
418 return net_run_function(argc, argv, func, net_help_audit);
420 return net_help_audit(argc, argv);