2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2006,2008 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, see <http://www.gnu.org/licenses/>. */
20 #include "utils/net.h"
22 /********************************************************************
23 ********************************************************************/
25 static int net_help_audit(int argc
, const char **argv
)
27 d_printf("net rpc audit list View configured Auditing policies\n");
28 d_printf("net rpc audit enable Enable Auditing\n");
29 d_printf("net rpc audit disable Disable Auditing\n");
30 d_printf("net rpc audit get <category> View configured Auditing policy setting\n");
31 d_printf("net rpc audit set <category> <policy> Set Auditing policies\n\n");
32 d_printf("\tcategory can be one of: SYSTEM, LOGON, OBJECT, PRIVILEGE, PROCESS, POLICY, SAM, DIRECTORY or ACCOUNT\n");
33 d_printf("\tpolicy can be one of: SUCCESS, FAILURE, ALL or NONE\n\n");
38 /********************************************************************
39 ********************************************************************/
41 static void print_auditing_category(const char *policy
, const char *value
)
44 int pad_len
, col_len
= 30;
53 /* calculate padding space for d_printf to look nicer */
54 pad_len
= col_len
- strlen(policy
);
56 do padding
[--pad_len
] = ' '; while (pad_len
> 0);
58 d_printf("\t%s%s%s\n", policy
, padding
, value
);
61 /********************************************************************
62 ********************************************************************/
64 static NTSTATUS
rpc_audit_get_internal(const DOM_SID
*domain_sid
,
65 const char *domain_name
,
66 struct cli_state
*cli
,
67 struct rpc_pipe_client
*pipe_hnd
,
73 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
74 union lsa_PolicyInformation
*info
= NULL
;
76 uint32_t audit_category
;
78 if (argc
< 1 || argc
> 2) {
79 d_printf("insufficient arguments\n");
80 net_help_audit(argc
, argv
);
81 return NT_STATUS_INVALID_PARAMETER
;
84 if (!get_audit_category_from_param(argv
[0], &audit_category
)) {
85 d_printf("invalid auditing category: %s\n", argv
[0]);
86 return NT_STATUS_INVALID_PARAMETER
;
89 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
90 SEC_RIGHTS_MAXIMUM_ALLOWED
,
93 if (!NT_STATUS_IS_OK(result
)) {
97 result
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
99 LSA_POLICY_INFO_AUDIT_EVENTS
,
102 if (!NT_STATUS_IS_OK(result
)) {
106 for (i
=0; i
< info
->audit_events
.count
; i
++) {
108 const char *val
= NULL
, *policy
= NULL
;
110 if (i
!= audit_category
) {
114 val
= audit_policy_str(mem_ctx
, info
->audit_events
.settings
[i
]);
115 policy
= audit_description_str(i
);
116 print_auditing_category(policy
, val
);
120 if (!NT_STATUS_IS_OK(result
)) {
121 d_printf("failed to get auditing policy: %s\n",
128 /********************************************************************
129 ********************************************************************/
131 static NTSTATUS
rpc_audit_set_internal(const DOM_SID
*domain_sid
,
132 const char *domain_name
,
133 struct cli_state
*cli
,
134 struct rpc_pipe_client
*pipe_hnd
,
140 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
141 union lsa_PolicyInformation
*info
= NULL
;
142 uint32_t audit_policy
, audit_category
;
144 if (argc
< 2 || argc
> 3) {
145 d_printf("insufficient arguments\n");
146 net_help_audit(argc
, argv
);
147 return NT_STATUS_INVALID_PARAMETER
;
150 if (!get_audit_category_from_param(argv
[0], &audit_category
)) {
151 d_printf("invalid auditing category: %s\n", argv
[0]);
152 return NT_STATUS_INVALID_PARAMETER
;
155 audit_policy
= LSA_AUDIT_POLICY_CLEAR
;
157 if (strequal(argv
[1], "Success")) {
158 audit_policy
|= LSA_AUDIT_POLICY_SUCCESS
;
159 } else if (strequal(argv
[1], "Failure")) {
160 audit_policy
|= LSA_AUDIT_POLICY_FAILURE
;
161 } else if (strequal(argv
[1], "All")) {
162 audit_policy
|= LSA_AUDIT_POLICY_ALL
;
163 } else if (strequal(argv
[1], "None")) {
164 audit_policy
= LSA_AUDIT_POLICY_CLEAR
;
166 d_printf("invalid auditing policy: %s\n", argv
[1]);
167 return NT_STATUS_INVALID_PARAMETER
;
170 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
171 SEC_RIGHTS_MAXIMUM_ALLOWED
,
174 if (!NT_STATUS_IS_OK(result
)) {
178 result
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
180 LSA_POLICY_INFO_AUDIT_EVENTS
,
183 if (!NT_STATUS_IS_OK(result
)) {
187 info
->audit_events
.settings
[audit_category
] = audit_policy
;
189 result
= rpccli_lsa_SetInfoPolicy(pipe_hnd
, mem_ctx
,
191 LSA_POLICY_INFO_AUDIT_EVENTS
,
194 if (!NT_STATUS_IS_OK(result
)) {
198 result
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
200 LSA_POLICY_INFO_AUDIT_EVENTS
,
203 const char *val
= audit_policy_str(mem_ctx
, info
->audit_events
.settings
[audit_category
]);
204 const char *policy
= audit_description_str(audit_category
);
205 print_auditing_category(policy
, val
);
209 if (!NT_STATUS_IS_OK(result
)) {
210 d_printf("failed to set audit policy: %s\n", nt_errstr(result
));
216 /********************************************************************
217 ********************************************************************/
219 static NTSTATUS
rpc_audit_enable_internal_ext(struct rpc_pipe_client
*pipe_hnd
,
226 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
227 union lsa_PolicyInformation
*info
= NULL
;
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_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
239 LSA_POLICY_INFO_AUDIT_EVENTS
,
241 if (!NT_STATUS_IS_OK(result
)) {
245 info
->audit_events
.auditing_mode
= enable
;
247 result
= rpccli_lsa_SetInfoPolicy(pipe_hnd
, mem_ctx
,
249 LSA_POLICY_INFO_AUDIT_EVENTS
,
252 if (!NT_STATUS_IS_OK(result
)) {
257 if (!NT_STATUS_IS_OK(result
)) {
258 d_printf("failed to %s audit policy: %s\n",
259 enable
? "enable":"disable", nt_errstr(result
));
265 /********************************************************************
266 ********************************************************************/
268 static NTSTATUS
rpc_audit_disable_internal(const DOM_SID
*domain_sid
,
269 const char *domain_name
,
270 struct cli_state
*cli
,
271 struct rpc_pipe_client
*pipe_hnd
,
276 return rpc_audit_enable_internal_ext(pipe_hnd
, mem_ctx
, argc
, argv
,
280 /********************************************************************
281 ********************************************************************/
283 static NTSTATUS
rpc_audit_enable_internal(const DOM_SID
*domain_sid
,
284 const char *domain_name
,
285 struct cli_state
*cli
,
286 struct rpc_pipe_client
*pipe_hnd
,
291 return rpc_audit_enable_internal_ext(pipe_hnd
, mem_ctx
, argc
, argv
,
295 /********************************************************************
296 ********************************************************************/
298 static NTSTATUS
rpc_audit_list_internal(const DOM_SID
*domain_sid
,
299 const char *domain_name
,
300 struct cli_state
*cli
,
301 struct rpc_pipe_client
*pipe_hnd
,
307 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
308 union lsa_PolicyInformation
*info
= NULL
;
311 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
312 SEC_RIGHTS_MAXIMUM_ALLOWED
,
315 if (!NT_STATUS_IS_OK(result
)) {
319 result
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
321 LSA_POLICY_INFO_AUDIT_EVENTS
,
323 if (!NT_STATUS_IS_OK(result
)) {
327 printf("Auditing:\t\t");
328 switch (info
->audit_events
.auditing_mode
) {
336 printf("unknown (%d)", info
->audit_events
.auditing_mode
);
341 printf("Auditing categories:\t%d\n", info
->audit_events
.count
);
342 printf("Auditing settings:\n");
344 for (i
=0; i
< info
->audit_events
.count
; i
++) {
345 const char *val
= audit_policy_str(mem_ctx
, info
->audit_events
.settings
[i
]);
346 const char *policy
= audit_description_str(i
);
347 print_auditing_category(policy
, val
);
351 if (!NT_STATUS_IS_OK(result
)) {
352 d_printf("failed to list auditing policies: %s\n",
359 /********************************************************************
360 ********************************************************************/
362 static int rpc_audit_get(int argc
, const char **argv
)
364 return run_rpc_command(NULL
, PI_LSARPC
, 0,
365 rpc_audit_get_internal
, argc
, argv
);
368 /********************************************************************
369 ********************************************************************/
371 static int rpc_audit_set(int argc
, const char **argv
)
373 return run_rpc_command(NULL
, PI_LSARPC
, 0,
374 rpc_audit_set_internal
, argc
, argv
);
377 /********************************************************************
378 ********************************************************************/
380 static int rpc_audit_enable(int argc
, const char **argv
)
382 return run_rpc_command(NULL
, PI_LSARPC
, 0,
383 rpc_audit_enable_internal
, argc
, argv
);
386 /********************************************************************
387 ********************************************************************/
389 static int rpc_audit_disable(int argc
, const char **argv
)
391 return run_rpc_command(NULL
, PI_LSARPC
, 0,
392 rpc_audit_disable_internal
, argc
, argv
);
395 /********************************************************************
396 ********************************************************************/
398 static int rpc_audit_list(int argc
, const char **argv
)
400 return run_rpc_command(NULL
, PI_LSARPC
, 0,
401 rpc_audit_list_internal
, argc
, argv
);
404 /********************************************************************
405 ********************************************************************/
407 int net_rpc_audit(int argc
, const char **argv
)
409 struct functable func
[] = {
410 {"get", rpc_audit_get
},
411 {"set", rpc_audit_set
},
412 {"enable", rpc_audit_enable
},
413 {"disable", rpc_audit_disable
},
414 {"list", rpc_audit_list
},
419 return net_run_function(argc
, argv
, func
, net_help_audit
);
421 return net_help_audit(argc
, argv
);