4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
26 * auditconfig - set and display audit parameters
30 #include <sys/types.h>
36 #include <sys/param.h>
42 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
46 #include <sys/mkdev.h>
47 #include <sys/param.h>
51 #include <libscf_priv.h>
52 #include <tsol/label.h>
53 #include <bsm/libbsm.h>
54 #include <audit_policy.h>
55 #include <audit_scf.h>
109 #define AC_KERN_EVENT 0
110 #define AC_USER_EVENT 1
112 #define NONE(s) (!strlen(s) ? gettext("none") : s)
117 * remove this after the audit.h is fixed
122 enum commands auditconfig_cmd
;
123 boolean_t temporary_allowed
; /* -t allowed for the option */
125 typedef struct arg_entry arg_entry_t
;
127 /* arg_table - command option and usage message table */
128 static arg_entry_t arg_table
[] = {
129 { "-aconf", "", AC_ARG_ACONF
, B_FALSE
},
130 { "-audit", " event sorf retval string", AC_ARG_AUDIT
, B_FALSE
},
131 { "-chkaconf", "", AC_ARG_CHKACONF
, B_FALSE
},
132 { "-chkconf", "", AC_ARG_CHKCONF
, B_FALSE
},
133 { "-conf", "", AC_ARG_CONF
, B_FALSE
},
134 { "-getasid", "", AC_ARG_GETASID
, B_FALSE
},
135 { "-getaudit", "", AC_ARG_GETAUDIT
, B_FALSE
},
136 { "-getauid", "", AC_ARG_GETAUID
, B_FALSE
},
137 { "-getcar", "", AC_ARG_GETCAR
, B_FALSE
},
138 { "-getclass", " event", AC_ARG_GETCLASS
, B_FALSE
},
139 { "-getcond", "", AC_ARG_GETCOND
, B_FALSE
},
140 { "-getcwd", "", AC_ARG_GETCWD
, B_FALSE
},
141 { "-getestate", " event", AC_ARG_GETESTATE
, B_FALSE
},
142 { "-getflags", "", AC_ARG_GETFLAGS
, B_FALSE
},
143 { "-getkaudit", "", AC_ARG_GETKAUDIT
, B_FALSE
},
144 { "-getkmask", "", AC_ARG_GETKMASK
, B_FALSE
},
145 { "-getnaflags", "", AC_ARG_GETNAFLAGS
, B_FALSE
},
146 { "-getpinfo", " pid", AC_ARG_GETPINFO
, B_FALSE
},
147 { "-getplugin", " [plugin]", AC_ARG_GETPLUGIN
, B_FALSE
},
148 { "-getpolicy", "", AC_ARG_GETPOLICY
, B_TRUE
},
149 { "-getqbufsz", "", AC_ARG_GETQBUFSZ
, B_TRUE
},
150 { "-getqctrl", "", AC_ARG_GETQCTRL
, B_TRUE
},
151 { "-getqdelay", "", AC_ARG_GETQDELAY
, B_TRUE
},
152 { "-getqhiwater", "", AC_ARG_GETQHIWATER
, B_TRUE
},
153 { "-getqlowater", "", AC_ARG_GETQLOWATER
, B_TRUE
},
154 { "-getstat", "", AC_ARG_GETSTAT
, B_FALSE
},
155 { "-gettid", "", AC_ARG_GETTERMID
, B_FALSE
},
156 { "-lsevent", "", AC_ARG_LSEVENT
, B_FALSE
},
157 { "-lspolicy", "", AC_ARG_LSPOLICY
, B_FALSE
},
158 { "-setasid", " asid [cmd]", AC_ARG_SETASID
, B_FALSE
},
159 { "-setaudit", " auid audit_flags termid asid [cmd]",
160 AC_ARG_SETAUDIT
, B_FALSE
},
161 { "-setauid", " auid [cmd]", AC_ARG_SETAUID
, B_FALSE
},
162 { "-setclass", " event audit_flags", AC_ARG_SETCLASS
, B_FALSE
},
163 { "-setflags", " audit_flags", AC_ARG_SETFLAGS
, B_FALSE
},
164 { "-setkaudit", " type IP_address", AC_ARG_SETKAUDIT
, B_FALSE
},
165 { "-setkmask", " audit_flags", AC_ARG_SETKMASK
, B_FALSE
},
166 { "-setnaflags", " audit_naflags", AC_ARG_SETNAFLAGS
, B_FALSE
},
167 { "-setplugin", " name active|inactive [attributes [qsize]]",
168 AC_ARG_SETPLUGIN
, B_FALSE
},
169 { "-setpmask", " pid audit_flags", AC_ARG_SETPMASK
, B_FALSE
},
170 { "-setpolicy", " [+|-]policy_flags", AC_ARG_SETPOLICY
, B_TRUE
},
171 { "-setqbufsz", " bufsz", AC_ARG_SETQBUFSZ
, B_TRUE
},
172 { "-setqctrl", " hiwater lowater bufsz delay",
173 AC_ARG_SETQCTRL
, B_TRUE
},
174 { "-setqdelay", " delay", AC_ARG_SETQDELAY
, B_TRUE
},
175 { "-setqhiwater", " hiwater", AC_ARG_SETQHIWATER
, B_TRUE
},
176 { "-setqlowater", " lowater", AC_ARG_SETQLOWATER
, B_TRUE
},
177 { "-setsmask", " asid audit_flags", AC_ARG_SETSMASK
, B_FALSE
},
178 { "-setstat", "", AC_ARG_SETSTAT
, B_FALSE
},
179 { "-setumask", " user audit_flags", AC_ARG_SETUMASK
, B_FALSE
},
180 { "-t", "", AC_ARG_SET_TEMPORARY
, B_FALSE
},
183 #define ARG_TBL_SZ (sizeof (arg_table) / sizeof (arg_entry_t))
185 char *progname
= "auditconfig";
188 * temporary_set true to get/set only kernel settings,
189 * false to get/set kernel settings and service properties
191 static boolean_t temporary_set
= B_FALSE
;
193 static au_event_ent_t
*egetauevnam(char *event_name
);
194 static au_event_ent_t
*egetauevnum(au_event_t event_number
);
195 static int arg_ent_compare(const void *aep1
, const void *aep2
);
196 static char *cond2str(void);
197 static int policy2str(uint32_t policy
, char *policy_str
, size_t len
);
198 static int str2type(char *s
, uint_t
*type
);
199 static int str2policy(char *policy_str
, uint32_t *policy_mask
);
200 static int str2ipaddr(char *s
, uint32_t *addr
, uint32_t type
);
201 static int strisipaddr(char *s
);
202 static int strisnum(char *s
);
203 static arg_entry_t
*get_arg_ent(char *arg_str
);
204 static uid_t
get_user_id(char *user
);
205 static void chk_arg_len(char *argv
, uint_t len
);
206 static void chk_event_num(int etype
, au_event_t event
);
207 static void chk_event_str(int etype
, char *event_str
);
208 static void chk_known_plugin(char *plugin_str
);
209 static void chk_retval(char *retval_str
);
210 static void chk_sorf(char *sorf_str
);
211 static void do_aconf(void);
212 static void do_args(char **argv
, au_mask_t
*mask
);
213 static void do_audit(char *, char, int, char *);
214 static void do_chkaconf(void);
215 static void do_chkconf(void);
216 static void do_conf(void);
217 static void do_getasid(void);
218 static void do_getaudit(void);
219 static void do_getkaudit(void);
220 static void do_setkaudit(char *t
, char *s
);
221 static void do_getauid(void);
222 static void do_getcar(void);
223 static void do_getclass(char *event_str
);
224 static void do_getcond(void);
225 static void do_getcwd(void);
226 static void do_getflags(void);
227 static void do_getkmask(void);
228 static void do_getnaflags(void);
229 static void do_getpinfo(char *pid_str
);
230 static void do_getplugin(char *plugin_str
);
231 static void do_getpolicy(void);
232 static void do_getqbufsz(void);
233 static void do_getqctrl(void);
234 static void do_getqdelay(void);
235 static void do_getqhiwater(void);
236 static void do_getqlowater(void);
237 static void do_getstat(void);
238 static void do_gettermid(void);
239 static void do_lsevent(void);
240 static void do_lspolicy(void);
241 static void do_setasid(char *sid_str
, char **argv
);
242 static void do_setaudit(char *user_str
, char *mask_str
, char *tid_str
,
243 char *sid_str
, char **argv
);
244 static void do_setauid(char *user
, char **argv
);
245 static void do_setclass(char *event_str
, au_mask_t
*mask
);
246 static void do_setflags(char *audit_flags
, au_mask_t
*amask
);
247 static void do_setkmask(au_mask_t
*pmask
);
248 static void do_setnaflags(char *audit_naflags
, au_mask_t
*namask
);
249 static void do_setpmask(char *pid_str
, au_mask_t
*mask
);
250 static void do_setsmask(char *asid_str
, au_mask_t
*mask
);
251 static void do_setumask(char *auid_str
, au_mask_t
*mask
);
252 static void do_setplugin(char *plugin_str
, boolean_t plugin_state
,
253 char *plugin_attr
, int plugin_qsize
);
254 static void do_setpolicy(char *policy_str
);
255 static void do_setqbufsz(char *bufsz
);
256 static void do_setqctrl(char *hiwater
, char *lowater
, char *bufsz
, char *delay
);
257 static void do_setqdelay(char *delay
);
258 static void do_setqhiwater(char *hiwater
);
259 static void do_setqlowater(char *lowater
);
260 static void do_setstat(void);
261 static void str2tid(char *tid_str
, au_tid_addr_t
*tp
);
263 static void eauditon(int cmd
, caddr_t data
, int length
);
264 static void echkflags(char *auditflags
, au_mask_t
*mask
);
265 static void egetaudit(auditinfo_addr_t
*ai
, int size
);
266 static void egetauditflagsbin(char *auditflags
, au_mask_t
*pmask
);
267 static void egetauid(au_id_t
*auid
);
268 static void egetkaudit(auditinfo_addr_t
*ai
, int size
);
269 static void esetaudit(auditinfo_addr_t
*ai
, int size
);
270 static void esetauid(au_id_t
*auid
);
271 static void esetkaudit(auditinfo_addr_t
*ai
, int size
);
272 static void execit(char **argv
);
273 static void exit_error(char *fmt
, ...);
274 static void exit_usage(int status
);
275 static void parse_args(int argc
, char **argv
, au_mask_t
*mask
);
276 static void print_asid(au_asid_t asid
);
277 static void print_auid(au_id_t auid
);
278 static void print_mask(char *desc
, au_mask_t
*pmp
);
279 static void print_plugin(char *plugin_name
, kva_t
*plugin_kva
);
280 static void print_tid_ex(au_tid_addr_t
*tidp
);
282 #if !defined(TEXT_DOMAIN)
283 #define TEXT_DOMAIN "SUNW_OST_OSCMD"
287 main(int argc
, char **argv
)
289 au_mask_t mask
; /* for options manipulating flags */
291 (void) setlocale(LC_ALL
, "");
292 (void) textdomain(TEXT_DOMAIN
);
299 (argv
[1][0] == '?' ||
300 strcmp(argv
[1], "-h") == 0 ||
301 strcmp(argv
[1], "-?") == 0)) {
305 parse_args(argc
, argv
, &mask
);
306 do_args(argv
, &mask
);
313 * Desc: Checks command line argument syntax.
314 * Inputs: Command line argv;
315 * Returns: If a syntax error is detected, a usage message is printed
316 * and exit() is called. If a syntax error is not detected,
317 * parse_args() returns without a value.
320 parse_args(int argc
, char **argv
, au_mask_t
*mask
)
327 for (++argv
; *argv
; argv
++) {
328 if ((ae
= get_arg_ent(*argv
)) == NULL
) {
332 switch (ae
->auditconfig_cmd
) {
338 if (strisnum(*argv
)) {
339 chk_event_num(AC_USER_EVENT
,
340 (au_event_t
)atol(*argv
));
342 chk_event_str(AC_USER_EVENT
, *argv
);
360 case AC_ARG_CHKACONF
:
363 case AC_ARG_GETAUDIT
:
364 case AC_ARG_GETKAUDIT
:
367 case AC_ARG_GETCLASS
:
368 case AC_ARG_GETESTATE
:
372 if (strisnum(*argv
)) {
373 chk_event_num(AC_KERN_EVENT
,
374 (au_event_t
)atol(*argv
));
376 chk_event_str(AC_KERN_EVENT
, *argv
);
383 case AC_ARG_GETFLAGS
:
384 case AC_ARG_GETKMASK
:
385 case AC_ARG_GETNAFLAGS
:
388 case AC_ARG_GETPLUGIN
:
389 if (*++argv
== NULL
) {
393 if (get_arg_ent(*argv
) != NULL
) {
396 chk_arg_len(*argv
, PLUGIN_MAXBUF
);
397 chk_known_plugin(*argv
);
401 case AC_ARG_GETPOLICY
:
402 case AC_ARG_GETQBUFSZ
:
403 case AC_ARG_GETQCTRL
:
404 case AC_ARG_GETQDELAY
:
405 case AC_ARG_GETQHIWATER
:
406 case AC_ARG_GETQLOWATER
:
408 case AC_ARG_GETTERMID
:
410 case AC_ARG_LSPOLICY
:
415 case AC_ARG_SETAUDIT
:
426 case AC_ARG_SETKAUDIT
:
430 if (str2type (*argv
, &type
))
432 "Invalid IP address type specified."));
437 if (str2ipaddr(*argv
, addr
, type
))
439 gettext("Invalid IP address specified."));
442 case AC_ARG_SETCLASS
:
447 chk_event_num(AC_KERN_EVENT
,
448 (au_event_t
)atol(*argv
));
450 chk_event_str(AC_KERN_EVENT
, *argv
);
454 echkflags(*argv
, mask
);
457 case AC_ARG_SETFLAGS
:
461 chk_arg_len(*argv
, PRESELECTION_MAXBUF
);
462 echkflags(*argv
, mask
);
465 case AC_ARG_SETKMASK
:
469 echkflags(*argv
, mask
);
472 case AC_ARG_SETNAFLAGS
:
476 chk_arg_len(*argv
, PRESELECTION_MAXBUF
);
477 echkflags(*argv
, mask
);
480 case AC_ARG_SETPLUGIN
:
481 if (*++argv
== NULL
|| get_arg_ent(*argv
) != NULL
) {
484 chk_known_plugin(*argv
);
485 chk_arg_len(*argv
, PLUGIN_MAXBUF
);
486 if (*++argv
== NULL
|| strcmp(*argv
, "active") != 0 &&
487 strcmp(*argv
, "inactive") != 0) {
490 if (*++argv
== NULL
|| get_arg_ent(*argv
) != NULL
) {
494 chk_arg_len(*argv
, PLUGIN_MAXATT
);
495 if (*++argv
== NULL
|| get_arg_ent(*argv
) != NULL
) {
499 if (atoi(*argv
) < 0) {
500 exit_error(gettext("Incorrect qsize specified "
505 case AC_ARG_SETPOLICY
:
514 case AC_ARG_GETPINFO
:
520 case AC_ARG_SETPMASK
:
527 echkflags(*argv
, mask
);
530 case AC_ARG_SETQBUFSZ
:
534 if (!strisnum(*argv
))
535 exit_error(gettext("Invalid bufsz specified."));
538 case AC_ARG_SETQCTRL
:
542 if (!strisnum(*argv
))
544 gettext("Invalid hiwater specified."));
548 if (!strisnum(*argv
))
550 gettext("Invalid lowater specified."));
554 if (!strisnum(*argv
))
555 exit_error(gettext("Invalid bufsz specified."));
559 if (!strisnum(*argv
))
560 exit_error(gettext("Invalid delay specified."));
563 case AC_ARG_SETQDELAY
:
567 if (!strisnum(*argv
))
568 exit_error(gettext("Invalid delay specified."));
571 case AC_ARG_SETQHIWATER
:
575 if (!strisnum(*argv
)) {
577 gettext("Invalid hiwater specified."));
581 case AC_ARG_SETQLOWATER
:
585 if (!strisnum(*argv
)) {
587 gettext("Invalid lowater specified."));
591 case AC_ARG_SETSMASK
:
592 case AC_ARG_SETUMASK
:
599 echkflags(*argv
, mask
);
602 case AC_ARG_SET_TEMPORARY
:
603 /* Do not accept single -t option. */
606 gettext("Only the -t option specified "
607 "(it is not a standalone option)."));
609 temporary_set
= B_TRUE
;
613 exit_error(gettext("Internal error #1."));
621 * do_args() - do command line arguments in the order in which they appear.
622 * Function return values returned by the underlying functions; the semantics
623 * they should follow is to return B_TRUE on successful execution, B_FALSE
627 do_args(char **argv
, au_mask_t
*mask
)
631 for (++argv
; *argv
; argv
++) {
632 ae
= get_arg_ent(*argv
);
634 switch (ae
->auditconfig_cmd
) {
646 sorf
= (char)atoi(*argv
);
648 retval
= atoi(*argv
);
651 do_audit(event_name
, sorf
, retval
, audit_str
);
663 case AC_ARG_CHKACONF
:
679 case AC_ARG_GETAUDIT
:
683 case AC_ARG_GETKAUDIT
:
687 case AC_ARG_GETCLASS
:
688 case AC_ARG_GETESTATE
:
705 case AC_ARG_GETFLAGS
:
709 case AC_ARG_GETKMASK
:
713 case AC_ARG_GETNAFLAGS
:
717 case AC_ARG_GETPLUGIN
:
719 char *plugin_str
= NULL
;
723 if (get_arg_ent(*argv
) != NULL
) {
732 do_getplugin(plugin_str
);
736 case AC_ARG_GETPOLICY
:
740 case AC_ARG_GETQBUFSZ
:
744 case AC_ARG_GETQCTRL
:
748 case AC_ARG_GETQDELAY
:
752 case AC_ARG_GETQHIWATER
:
756 case AC_ARG_GETQLOWATER
:
764 case AC_ARG_GETTERMID
:
772 case AC_ARG_LSPOLICY
:
783 do_setasid(sid_str
, argv
);
794 do_setauid(user
, argv
);
798 case AC_ARG_SETAUDIT
:
814 do_setaudit(user_str
, mask_str
, tid_str
,
819 case AC_ARG_SETKAUDIT
:
821 char *address_type
, *address
;
823 ++argv
; address_type
= *argv
;
824 ++argv
; address
= *argv
;
825 do_setkaudit(address_type
, address
);
829 case AC_ARG_SETCLASS
:
835 do_setclass(event_str
, mask
);
841 case AC_ARG_SETFLAGS
:
843 do_setflags(*argv
, mask
);
846 case AC_ARG_SETKMASK
:
851 case AC_ARG_SETNAFLAGS
:
853 do_setnaflags(*argv
, mask
);
856 case AC_ARG_SETPLUGIN
:
858 char *plugin_str
= NULL
;
859 boolean_t plugin_state
= B_FALSE
;
860 char *plugin_att
= NULL
;
861 int plugin_qsize
= -1;
863 plugin_str
= *++argv
;
864 if (strcmp(*++argv
, "active") == 0) {
865 plugin_state
= B_TRUE
;
867 if (*++argv
!= NULL
&&
868 get_arg_ent(*argv
) == NULL
) {
870 if (*++argv
!= NULL
&&
871 get_arg_ent(*argv
) == NULL
) {
872 plugin_qsize
= atoi(*argv
);
880 do_setplugin(plugin_str
, plugin_state
,
881 plugin_att
, plugin_qsize
);
885 case AC_ARG_SETPOLICY
:
890 case AC_ARG_GETPINFO
:
896 do_getpinfo(pid_str
);
900 case AC_ARG_SETPMASK
:
906 do_setpmask(pid_str
, mask
);
916 case AC_ARG_SETQBUFSZ
:
921 case AC_ARG_SETQCTRL
:
923 char *hiwater
, *lowater
, *bufsz
, *delay
;
925 ++argv
; hiwater
= *argv
;
926 ++argv
; lowater
= *argv
;
927 ++argv
; bufsz
= *argv
;
928 ++argv
; delay
= *argv
;
929 do_setqctrl(hiwater
, lowater
, bufsz
, delay
);
932 case AC_ARG_SETQDELAY
:
937 case AC_ARG_SETQHIWATER
:
939 do_setqhiwater(*argv
);
942 case AC_ARG_SETQLOWATER
:
944 do_setqlowater(*argv
);
947 case AC_ARG_SETSMASK
:
953 do_setsmask(asid_str
, mask
);
958 case AC_ARG_SETUMASK
:
964 do_setumask(auid_str
, mask
);
969 case AC_ARG_SET_TEMPORARY
:
973 exit_error(gettext("Internal error #2."));
980 * do_chkconf() - the returned value is for the global zone unless AUDIT_PERZONE
986 register au_event_ent_t
*evp
;
988 char conf_aflags
[256];
989 char run_aflags
[256];
993 struct au_evclass_map cmap
;
995 pmask
.am_success
= pmask
.am_failure
= 0;
996 eauditon(A_GETSTAT
, (caddr_t
)&as
, 0);
999 if (getauevent() == NULL
) {
1000 exit_error(gettext("NO AUDIT EVENTS: Could not read %s\n."),
1005 while ((evp
= getauevent()) != NULL
) {
1006 cmap
.ec_number
= evp
->ae_number
;
1007 len
= sizeof (struct au_evclass_map
);
1008 if (evp
->ae_number
<= as
.as_numevent
) {
1009 if (auditon(A_GETCLASS
, (caddr_t
)&cmap
, len
) == -1) {
1010 (void) printf("%s(%hu):%s",
1011 evp
->ae_name
, evp
->ae_number
,
1012 gettext("UNKNOWN EVENT: Could not get "
1013 "class for event. Configuration may "
1016 class = cmap
.ec_class
;
1017 if (class != evp
->ae_class
) {
1018 conf_aflags
[0] = run_aflags
[0] = '\0';
1019 pmask
.am_success
= class;
1020 pmask
.am_failure
= class;
1021 (void) getauditflagschar(run_aflags
,
1023 pmask
.am_success
= evp
->ae_class
;
1024 pmask
.am_failure
= evp
->ae_class
;
1025 (void) getauditflagschar(conf_aflags
,
1028 (void) printf(gettext(
1029 "%s(%hu): CLASS MISMATCH: "
1030 "runtime class (%s) != "
1031 "configured class (%s)\n"),
1032 evp
->ae_name
, evp
->ae_number
,
1043 * do_conf() - configure the kernel events. The value returned to the user is
1044 * for the global zone unless AUDIT_PERZONE is set.
1049 register au_event_ent_t
*evp
;
1051 au_evclass_map_t ec
;
1054 eauditon(A_GETSTAT
, (caddr_t
)&as
, 0);
1058 while ((evp
= getauevent()) != NULL
) {
1059 if (evp
->ae_number
<= as
.as_numevent
) {
1061 ec
.ec_number
= evp
->ae_number
;
1062 ec
.ec_class
= evp
->ae_class
;
1063 eauditon(A_SETCLASS
, (caddr_t
)&ec
, sizeof (ec
));
1067 (void) printf(gettext("Configured %d kernel events.\n"), i
);
1072 * do_chkaconf() - report a mismatch if the runtime class mask of a kernel audit
1073 * event does not match the configured class mask. The value returned to the
1074 * user is for the global zone unless AUDIT_PERZONE is set.
1080 au_mask_t pmask
, kmask
;
1082 if (!do_getnaflags_scf(&namask_cfg
) || namask_cfg
== NULL
) {
1083 exit_error(gettext("Could not get configured value."));
1085 egetauditflagsbin(namask_cfg
, &pmask
);
1087 eauditon(A_GETKMASK
, (caddr_t
)&kmask
, sizeof (kmask
));
1089 if ((pmask
.am_success
!= kmask
.am_success
) ||
1090 (pmask
.am_failure
!= kmask
.am_failure
)) {
1092 if (getauditflagschar(kbuf
, &kmask
, 0) < 0) {
1094 (void) fprintf(stderr
,
1095 gettext("bad kernel non-attributable mask\n"));
1099 gettext("non-attributable event flags mismatch:\n"));
1100 (void) printf(gettext("active non-attributable audit flags "
1102 (void) printf(gettext("configured non-attributable audit flags "
1103 "= %s\n"), namask_cfg
);
1109 * do_aconf - configures the non-attributable events. The value returned to the
1110 * user is for the global zone unless AUDIT_PERZONE is set.
1118 if (!do_getnaflags_scf(&namask_cfg
) || namask_cfg
== NULL
) {
1119 exit_error(gettext("Could not get configured value."));
1121 egetauditflagsbin(namask_cfg
, &namask
);
1124 eauditon(A_SETKMASK
, (caddr_t
)&namask
, sizeof (namask
));
1125 (void) printf(gettext("Configured non-attributable event mask.\n"));
1129 * do_audit() - construct an audit record for audit event event using the
1130 * process's audit characteristics containing a text token string audit_str. The
1131 * return token is constructed from the success/failure flag sort. Returned
1132 * value retval is an errno value.
1135 do_audit(char *event
, char sorf
, int retval
, char *audit_str
)
1139 au_event_t event_num
;
1140 au_event_ent_t
*evp
;
1141 auditinfo_addr_t ai
;
1144 egetaudit(&ai
, sizeof (ai
));
1146 if (strisnum(event
)) {
1147 event_num
= (au_event_t
)atoi(event
);
1148 evp
= egetauevnum(event_num
);
1150 evp
= egetauevnam(event
);
1153 rtn
= au_preselect(evp
->ae_number
, &ai
.ai_mask
, (int)sorf
,
1157 exit_error("%s\n%s %hu\n",
1158 gettext("Check audit event configuration."),
1159 gettext("Could not get audit class for event number"),
1163 /* record is preselected */
1165 if ((rd
= au_open()) == -1) {
1167 "Could not get and audit record descriptor\n"));
1169 if ((tokp
= au_to_me()) == NULL
) {
1171 gettext("Could not allocate subject token\n"));
1173 if (au_write(rd
, tokp
) == -1) {
1174 exit_error(gettext("Could not construct subject token "
1175 "of audit record\n"));
1177 if (is_system_labeled()) {
1178 if ((tokp
= au_to_mylabel()) == NULL
) {
1180 "Could not allocate label token\n"));
1182 if (au_write(rd
, tokp
) == -1) {
1183 exit_error(gettext("Could not "
1184 "construct label token of audit record\n"));
1188 if ((tokp
= au_to_text(audit_str
)) == NULL
)
1189 exit_error(gettext("Could not allocate text token\n"));
1190 if (au_write(rd
, tokp
) == -1)
1191 exit_error(gettext("Could not construct text token of "
1194 if ((tokp
= au_to_return64(sorf
, retval
)) == NULL
)
1196 if ((tokp
= au_to_return32(sorf
, retval
)) == NULL
)
1199 gettext("Could not allocate return token\n"));
1200 if (au_write(rd
, tokp
) == -1) {
1201 exit_error(gettext("Could not construct return token "
1202 "of audit record\n"));
1204 if (au_close(rd
, 1, evp
->ae_number
) == -1) {
1206 gettext("Could not write audit record: %s\n"),
1213 * do_getauid() - print the audit id of the current process.
1225 * do_getaudit() - print the audit characteristics of the current process.
1230 auditinfo_addr_t ai
;
1232 egetaudit(&ai
, sizeof (ai
));
1233 print_auid(ai
.ai_auid
);
1234 print_mask(gettext("process preselection mask"), &ai
.ai_mask
);
1235 print_tid_ex(&ai
.ai_termid
);
1236 print_asid(ai
.ai_asid
);
1240 * do_getkaudit() - print the audit characteristics of the current zone.
1245 auditinfo_addr_t ai
;
1247 egetkaudit(&ai
, sizeof (ai
));
1248 print_auid(ai
.ai_auid
);
1249 print_mask(gettext("process preselection mask"), &ai
.ai_mask
);
1250 print_tid_ex(&ai
.ai_termid
);
1251 print_asid(ai
.ai_asid
);
1255 * do_setkaudit() - set IP address_type/address of machine to specified values;
1256 * valid per zone if AUDIT_PERZONE is set, else only in global zone.
1259 do_setkaudit(char *t
, char *s
)
1262 auditinfo_addr_t ai
;
1264 egetkaudit(&ai
, sizeof (ai
));
1265 (void) str2type(t
, &type
);
1266 (void) str2ipaddr(s
, &ai
.ai_termid
.at_addr
[0], type
);
1267 ai
.ai_termid
.at_type
= type
;
1268 esetkaudit(&ai
, sizeof (ai
));
1272 * do_getcar() - print the zone-relative root
1277 char path
[MAXPATHLEN
];
1279 eauditon(A_GETCAR
, (caddr_t
)path
, sizeof (path
));
1280 (void) printf(gettext("current active root = %s\n"), path
);
1284 * do_getclass() - print the preselection mask associated with the specified
1285 * kernel audit event. The displayed value is for the global zone unless
1286 * AUDIT_PERZONE is set.
1289 do_getclass(char *event_str
)
1291 au_evclass_map_t ec
;
1292 au_event_ent_t
*evp
;
1293 au_event_t event_number
;
1296 if (strisnum(event_str
)) {
1297 event_number
= atol(event_str
);
1298 if ((evp
= egetauevnum(event_number
)) != NULL
) {
1299 event_number
= evp
->ae_number
;
1300 event_name
= evp
->ae_name
;
1302 event_name
= gettext("unknown");
1305 event_name
= event_str
;
1306 if ((evp
= egetauevnam(event_str
)) != NULL
) {
1307 event_number
= evp
->ae_number
;
1311 ec
.ec_number
= event_number
;
1312 eauditon(A_GETCLASS
, (caddr_t
)&ec
, 0);
1314 (void) printf(gettext("audit class mask for event %s(%hu) = 0x%x\n"),
1315 event_name
, event_number
, ec
.ec_class
);
1319 * do_getcond() - the printed value is for the global zone unless
1320 * AUDIT_PERZONE is set. (AUC_DISABLED is always global, the other states are
1321 * per zone if AUDIT_PERZONE is set)
1326 (void) printf(gettext("audit condition = %s\n"), cond2str());
1330 * do_getcwd() - the printed path is relative to the current zone root
1335 char path
[MAXPATHLEN
];
1337 eauditon(A_GETCWD
, (caddr_t
)path
, sizeof (path
));
1338 (void) printf(gettext("current working directory = %s\n"), path
);
1342 * do_getflags() - the printed value is for the global zone unless AUDIT_PERZONE
1351 eauditon(A_GETAMASK
, (caddr_t
)&amask
, sizeof (amask
));
1352 print_mask(gettext("active user default audit flags"), &amask
);
1354 if (!do_getflags_scf(&amask_cfg
) || amask_cfg
== NULL
) {
1355 exit_error(gettext("Could not get configured value."));
1357 egetauditflagsbin(amask_cfg
, &amask
);
1358 print_mask(gettext("configured user default audit flags"), &amask
);
1363 * do_getkmask() - the printed value is for the global zone unless AUDIT_PERZONE
1371 eauditon(A_GETKMASK
, (caddr_t
)&pmask
, sizeof (pmask
));
1372 print_mask(gettext("active non-attributable audit flags"), &pmask
);
1376 * do_getnaflags() - the printed value is for the global zone unless
1377 * AUDIT_PERZONE is set.
1385 eauditon(A_GETKMASK
, (caddr_t
)&namask
, sizeof (namask
));
1386 print_mask(gettext("active non-attributable audit flags"), &namask
);
1388 if (!do_getnaflags_scf(&namask_cfg
) || namask_cfg
== NULL
) {
1389 exit_error(gettext("Could not get configured value."));
1391 egetauditflagsbin(namask_cfg
, &namask
);
1392 print_mask(gettext("configured non-attributable audit flags"), &namask
);
1397 * do_getpolicy() - print active and configured kernel audit policy relative to
1403 char policy_str
[1024];
1406 if (!temporary_set
) {
1407 if (!do_getpolicy_scf(&policy
)) {
1408 exit_error(gettext("Could not get configured values."));
1410 (void) policy2str(policy
, policy_str
, sizeof (policy_str
));
1411 (void) printf(gettext("configured audit policies = %s\n"),
1415 eauditon(A_GETPOLICY
, (caddr_t
)&policy
, 0);
1416 (void) policy2str(policy
, policy_str
, sizeof (policy_str
));
1417 (void) printf(gettext("active audit policies = %s\n"), policy_str
);
1422 * do_getpinfo() - print the audit ID, preselection mask, terminal ID, and
1423 * audit session ID for the specified process.
1426 do_getpinfo(char *pid_str
)
1428 struct auditpinfo_addr ap
;
1430 if (strisnum(pid_str
))
1431 ap
.ap_pid
= (pid_t
)atoi(pid_str
);
1435 eauditon(A_GETPINFO_ADDR
, (caddr_t
)&ap
, sizeof (ap
));
1437 print_auid(ap
.ap_auid
);
1438 print_mask(gettext("process preselection mask"), &(ap
.ap_mask
));
1439 print_tid_ex(&(ap
.ap_termid
));
1440 print_asid(ap
.ap_asid
);
1444 * do_getplugin() - print plugin configuration.
1447 do_getplugin(char *plugin_str
)
1449 scf_plugin_kva_node_t
*plugin_kva_ll
;
1450 scf_plugin_kva_node_t
*plugin_kva_ll_head
;
1452 if (!do_getpluginconfig_scf(plugin_str
, &plugin_kva_ll
)) {
1453 exit_error(gettext("Could not get plugin configuration."));
1456 plugin_kva_ll_head
= plugin_kva_ll
;
1458 while (plugin_kva_ll
!= NULL
) {
1459 print_plugin(plugin_kva_ll
->plugin_name
,
1460 plugin_kva_ll
->plugin_kva
);
1461 plugin_kva_ll
= plugin_kva_ll
->next
;
1462 if (plugin_kva_ll
!= NULL
) {
1463 (void) printf("\n");
1466 plugin_kva_ll_free(plugin_kva_ll_head
);
1470 * do_getqbufsz() - print the active and configured audit queue write buffer
1471 * size relative to the current zone.
1476 struct au_qctrl qctrl
;
1478 if (!temporary_set
) {
1479 if (!do_getqbufsz_scf(&qctrl
.aq_bufsz
)) {
1480 exit_error(gettext("Could not get configured value."));
1483 if (qctrl
.aq_bufsz
== 0) {
1484 (void) printf(gettext(
1485 "no configured audit queue buffer size\n"));
1487 (void) printf(gettext("configured audit queue "
1488 "buffer size (bytes) = %d\n"), qctrl
.aq_bufsz
);
1492 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
1493 (void) printf(gettext("active audit queue buffer size (bytes) = %d\n"),
1498 * do_getqctrl() - print the configured and active audit queue write buffer
1499 * size, audit queue hiwater mark, audit queue lowater mark, audit queue prod
1500 * interval (ticks) relative to the current zone.
1505 struct au_qctrl qctrl
;
1507 if (!temporary_set
) {
1508 if (!do_getqctrl_scf(&qctrl
)) {
1509 exit_error(gettext("Could not get configured values."));
1512 if (qctrl
.aq_hiwater
== 0) {
1513 (void) printf(gettext(
1514 "no configured audit queue hiwater mark\n"));
1516 (void) printf(gettext("configured audit queue "
1517 "hiwater mark (records) = %d\n"), qctrl
.aq_hiwater
);
1519 if (qctrl
.aq_lowater
== 0) {
1520 (void) printf(gettext(
1521 "no configured audit queue lowater mark\n"));
1523 (void) printf(gettext("configured audit queue "
1524 "lowater mark (records) = %d\n"), qctrl
.aq_lowater
);
1526 if (qctrl
.aq_bufsz
== 0) {
1527 (void) printf(gettext(
1528 "no configured audit queue buffer size\n"));
1530 (void) printf(gettext("configured audit queue "
1531 "buffer size (bytes) = %d\n"), qctrl
.aq_bufsz
);
1533 if (qctrl
.aq_delay
== 0) {
1534 (void) printf(gettext(
1535 "no configured audit queue delay\n"));
1537 (void) printf(gettext("configured audit queue "
1538 "delay (ticks) = %ld\n"), qctrl
.aq_delay
);
1542 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
1543 (void) printf(gettext("active audit queue hiwater mark "
1544 "(records) = %d\n"), qctrl
.aq_hiwater
);
1545 (void) printf(gettext("active audit queue lowater mark "
1546 "(records) = %d\n"), qctrl
.aq_lowater
);
1547 (void) printf(gettext("active audit queue buffer size (bytes) = %d\n"),
1549 (void) printf(gettext("active audit queue delay (ticks) = %ld\n"),
1554 * do_getqdelay() - print, relative to the current zone, the configured and
1555 * active interval at which audit queue is prodded to start output.
1560 struct au_qctrl qctrl
;
1562 if (!temporary_set
) {
1563 if (!do_getqdelay_scf(&qctrl
.aq_delay
)) {
1564 exit_error(gettext("Could not get configured value."));
1567 if (qctrl
.aq_delay
== 0) {
1568 (void) printf(gettext(
1569 "no configured audit queue delay\n"));
1571 (void) printf(gettext("configured audit queue "
1572 "delay (ticks) = %ld\n"), qctrl
.aq_delay
);
1576 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
1577 (void) printf(gettext("active audit queue delay (ticks) = %ld\n"),
1582 * do_getqhiwater() - print, relative to the current zone, the high water
1583 * point in undelivered audit records when audit generation will block.
1586 do_getqhiwater(void)
1588 struct au_qctrl qctrl
;
1590 if (!temporary_set
) {
1591 if (!do_getqhiwater_scf(&qctrl
.aq_hiwater
)) {
1592 exit_error(gettext("Could not get configured value."));
1595 if (qctrl
.aq_hiwater
== 0) {
1596 (void) printf(gettext(
1597 "no configured audit queue hiwater mark\n"));
1599 (void) printf(gettext("configured audit queue "
1600 "hiwater mark (records) = %d\n"), qctrl
.aq_hiwater
);
1604 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
1605 (void) printf(gettext("active audit queue hiwater mark "
1606 "(records) = %d\n"), qctrl
.aq_hiwater
);
1610 * do_getqlowater() - print, relative to the current zone, the low water point
1611 * in undelivered audit records where blocked processes will resume.
1614 do_getqlowater(void)
1616 struct au_qctrl qctrl
;
1618 if (!temporary_set
) {
1619 if (!do_getqlowater_scf(&qctrl
.aq_lowater
)) {
1620 exit_error(gettext("Could not get configured value."));
1623 if (qctrl
.aq_lowater
== 0) {
1624 (void) printf(gettext(
1625 "no configured audit queue lowater mark\n"));
1627 (void) printf(gettext("configured audit queue "
1628 "lowater mark (records) = %d\n"), qctrl
.aq_lowater
);
1632 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
1633 (void) printf(gettext("active audit queue lowater mark "
1634 "(records) = %d\n"), qctrl
.aq_lowater
);
1638 * do_getasid() - print out the audit session-ID.
1643 auditinfo_addr_t ai
;
1645 if (getaudit_addr(&ai
, sizeof (ai
))) {
1646 exit_error(gettext("getaudit_addr(2) failed"));
1648 print_asid(ai
.ai_asid
);
1652 * do_getstat() - the printed statistics are for the entire system unless
1653 * AUDIT_PERZONE is set.
1659 int offset
[12]; /* used to line the header up correctly */
1662 eauditon(A_GETSTAT
, (caddr_t
)&as
, 0);
1663 (void) sprintf(buf
, "%4lu %n%4lu %n%4lu %n%4lu %n%4lu %n%4lu %n%4lu "
1664 "%n%4lu %n%4lu %n%4lu %n%4lu %n%4lu%n",
1665 (ulong_t
)as
.as_generated
, &(offset
[0]),
1666 (ulong_t
)as
.as_nonattrib
, &(offset
[1]),
1667 (ulong_t
)as
.as_kernel
, &(offset
[2]),
1668 (ulong_t
)as
.as_audit
, &(offset
[3]),
1669 (ulong_t
)as
.as_auditctl
, &(offset
[4]),
1670 (ulong_t
)as
.as_enqueue
, &(offset
[5]),
1671 (ulong_t
)as
.as_written
, &(offset
[6]),
1672 (ulong_t
)as
.as_wblocked
, &(offset
[7]),
1673 (ulong_t
)as
.as_rblocked
, &(offset
[8]),
1674 (ulong_t
)as
.as_dropped
, &(offset
[9]),
1675 (ulong_t
)as
.as_totalsize
/ ONEK
, &(offset
[10]),
1676 (ulong_t
)as
.as_memused
/ ONEK
, &(offset
[11]));
1680 * Print a properly aligned header.
1682 (void) printf("%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",
1683 offset
[0] - 1, gettext("gen"),
1684 offset
[1] - offset
[0] -1, gettext("nona"),
1685 offset
[2] - offset
[1] -1, gettext("kern"),
1686 offset
[3] - offset
[2] -1, gettext("aud"),
1687 offset
[4] - offset
[3] -1, gettext("ctl"),
1688 offset
[5] - offset
[4] -1, gettext("enq"),
1689 offset
[6] - offset
[5] -1, gettext("wrtn"),
1690 offset
[7] - offset
[6] -1, gettext("wblk"),
1691 offset
[8] - offset
[7] -1, gettext("rblk"),
1692 offset
[9] - offset
[8] -1, gettext("drop"),
1693 offset
[10] - offset
[9] -1, gettext("tot"),
1694 offset
[11] - offset
[10], gettext("mem"));
1696 (void) printf("%s\n", buf
);
1700 * do_gettermid() - print audit terminal ID for current process.
1705 auditinfo_addr_t ai
;
1707 if (getaudit_addr(&ai
, sizeof (ai
))) {
1708 exit_error(gettext("getaudit_addr(2) failed"));
1710 print_tid_ex(&ai
.ai_termid
);
1714 * do_lsevent() - display the active kernel and user level audit event
1715 * information. The printed events are for the global zone unless AUDIT_PERZONE
1721 register au_event_ent_t
*evp
;
1726 if (getauevent() == NULL
) {
1727 exit_error(gettext("NO AUDIT EVENTS: Could not read %s\n."),
1732 while ((evp
= getauevent()) != NULL
) {
1733 pmask
.am_success
= pmask
.am_failure
= evp
->ae_class
;
1734 if (getauditflagschar(auflags
, &pmask
, 0) == -1)
1735 (void) strcpy(auflags
, "unknown");
1736 (void) printf("%-30s %5hu %s %s\n",
1737 evp
->ae_name
, evp
->ae_number
, auflags
, evp
->ae_desc
);
1743 * do_lspolicy() - display the kernel audit policies with a description of each
1744 * policy. The printed value is for the global zone unless AUDIT_PERZONE is set.
1753 * Print a properly aligned header.
1755 (void) printf(gettext("policy string description:\n"));
1756 for (i
= 0; i
< POLICY_TBL_SZ
; i
++) {
1757 (void) printf("%-17s%s\n", policy_table
[i
].policy_str
,
1758 gettext(policy_table
[i
].policy_desc
));
1763 * do_setasid() - execute shell or cmd with specified session-ID.
1766 do_setasid(char *sid_str
, char **argv
)
1768 struct auditinfo_addr ai
;
1770 if (getaudit_addr(&ai
, sizeof (ai
))) {
1771 exit_error(gettext("getaudit_addr(2) failed"));
1773 ai
.ai_asid
= (au_asid_t
)atol(sid_str
);
1774 if (setaudit_addr(&ai
, sizeof (ai
))) {
1775 exit_error(gettext("setaudit_addr(2) failed"));
1781 * do_setaudit() - execute shell or cmd with specified audit characteristics.
1784 do_setaudit(char *user_str
, char *mask_str
, char *tid_str
, char *sid_str
,
1787 auditinfo_addr_t ai
;
1789 ai
.ai_auid
= (au_id_t
)get_user_id(user_str
);
1790 egetauditflagsbin(mask_str
, &ai
.ai_mask
),
1791 str2tid(tid_str
, &ai
.ai_termid
);
1792 ai
.ai_asid
= (au_asid_t
)atol(sid_str
);
1794 esetaudit(&ai
, sizeof (ai
));
1799 * do_setauid() - execute shell or cmd with specified audit-ID.
1802 do_setauid(char *user
, char **argv
)
1806 auid
= get_user_id(user
);
1812 * do_setpmask() - set the preselection mask of the specified process; valid
1813 * per zone if AUDIT_PERZONE is set, else only in global zone.
1816 do_setpmask(char *pid_str
, au_mask_t
*mask
)
1818 struct auditpinfo ap
;
1820 if (strisnum(pid_str
)) {
1821 ap
.ap_pid
= (pid_t
)atoi(pid_str
);
1826 ap
.ap_mask
.am_success
= mask
->am_success
;
1827 ap
.ap_mask
.am_failure
= mask
->am_failure
;
1829 eauditon(A_SETPMASK
, (caddr_t
)&ap
, sizeof (ap
));
1833 * do_setsmask() - set the preselection mask of all processes with the specified
1834 * audit session-ID; valid per zone if AUDIT_PERZONE is set, else only in global
1838 do_setsmask(char *asid_str
, au_mask_t
*mask
)
1840 struct auditinfo ainfo
;
1842 if (strisnum(asid_str
)) {
1843 ainfo
.ai_asid
= (au_asid_t
)atoi(asid_str
);
1848 ainfo
.ai_mask
.am_success
= mask
->am_success
;
1849 ainfo
.ai_mask
.am_failure
= mask
->am_failure
;
1851 eauditon(A_SETSMASK
, (caddr_t
)&ainfo
, sizeof (ainfo
));
1855 * do_setumask() - set the preselection mask of all processes with the
1856 * specified audit-ID; valid per zone if AUDIT_PERZONE is set, else only in
1860 do_setumask(char *auid_str
, au_mask_t
*mask
)
1862 struct auditinfo ainfo
;
1864 if (strisnum(auid_str
)) {
1865 ainfo
.ai_auid
= (au_id_t
)atoi(auid_str
);
1870 ainfo
.ai_mask
.am_success
= mask
->am_success
;
1871 ainfo
.ai_mask
.am_failure
= mask
->am_failure
;
1873 eauditon(A_SETUMASK
, (caddr_t
)&ainfo
, sizeof (ainfo
));
1877 * do_setstat() - reset audit statistics counters; local zone use is valid if
1878 * AUDIT_PERZONE is set, otherwise the syscall returns EPERM.
1885 as
.as_audit
= (uint_t
)-1;
1886 as
.as_auditctl
= (uint_t
)-1;
1887 as
.as_dropped
= (uint_t
)-1;
1888 as
.as_enqueue
= (uint_t
)-1;
1889 as
.as_generated
= (uint_t
)-1;
1890 as
.as_kernel
= (uint_t
)-1;
1891 as
.as_nonattrib
= (uint_t
)-1;
1892 as
.as_rblocked
= (uint_t
)-1;
1893 as
.as_totalsize
= (uint_t
)-1;
1894 as
.as_wblocked
= (uint_t
)-1;
1895 as
.as_written
= (uint_t
)-1;
1897 eauditon(A_SETSTAT
, (caddr_t
)&as
, sizeof (as
));
1898 (void) printf("%s\n", gettext("audit stats reset"));
1902 * do_setclass() - map the kernel event event_str to the classes specified by
1903 * audit flags (mask); valid per zone if AUDIT_PERZONE is set, else only in
1907 do_setclass(char *event_str
, au_mask_t
*mask
)
1910 au_evclass_map_t ec
;
1911 au_event_ent_t
*evp
;
1913 if (strisnum(event_str
)) {
1914 event
= (uint_t
)atol(event_str
);
1916 if ((evp
= egetauevnam(event_str
)) != NULL
) {
1917 event
= evp
->ae_number
;
1921 ec
.ec_number
= event
;
1922 ec
.ec_class
= (mask
->am_success
| mask
->am_failure
);
1924 eauditon(A_SETCLASS
, (caddr_t
)&ec
, sizeof (ec
));
1928 * do_setflags() - set configured and active default user preselection masks;
1929 * valid per zone if AUDIT_PERZONE is set, else only in global zone.
1932 do_setflags(char *audit_flags
, au_mask_t
*amask
)
1934 eauditon(A_SETAMASK
, (caddr_t
)amask
, sizeof (*amask
));
1936 if (!do_setflags_scf(audit_flags
)) {
1937 print_mask(gettext("active user default audit flags"), amask
);
1938 exit_error(gettext("Could not store configuration value."));
1940 print_mask(gettext("user default audit flags"), amask
);
1944 * do_setkmask() - set non-attributable audit flags of machine; valid per zone
1945 * if AUDIT_PERZONE is set, else only in global zone.
1948 do_setkmask(au_mask_t
*pmask
)
1950 eauditon(A_SETKMASK
, (caddr_t
)pmask
, sizeof (*pmask
));
1951 print_mask(gettext("active non-attributable audit flags"), pmask
);
1955 * do_setnaflags() - set configured and active non-attributable selection flags
1956 * of machine; valid per zone if AUDIT_PERZONE is set, else only in global zone.
1959 do_setnaflags(char *audit_naflags
, au_mask_t
*namask
)
1961 eauditon(A_SETKMASK
, (caddr_t
)namask
, sizeof (*namask
));
1963 if (!do_setnaflags_scf(audit_naflags
)) {
1965 gettext("active non-attributable audit flags"), namask
);
1966 exit_error(gettext("Could not store configuration value."));
1968 print_mask(gettext("non-attributable audit flags"), namask
);
1972 * do_setplugin() - set the given plugin plugin_str configuration values.
1975 do_setplugin(char *plugin_str
, boolean_t plugin_state
, char *plugin_attr
,
1978 if (!do_setpluginconfig_scf(plugin_str
, plugin_state
, plugin_attr
,
1980 exit_error(gettext("Could not set plugin configuration."));
1985 * do_setpolicy() - set the active and configured kernel audit policy; active
1986 * values can be changed per zone if AUDIT_PERZONE is set, else only in global
1989 * ahlt and perzone are global zone only. The kernel ensures that a local zone
1990 * can't change ahlt and perzone (EINVAL).
1993 do_setpolicy(char *policy_str
)
1995 uint32_t policy
= 0;
1997 switch (str2policy(policy_str
, &policy
)) {
1999 if (!temporary_set
) {
2000 if (!do_getpolicy_scf(&policy
)) {
2001 exit_error(gettext("Unable to get current "
2002 "policy values from the SMF repository"));
2004 (void) str2policy(policy_str
, &policy
);
2006 if (!do_setpolicy_scf(policy
)) {
2007 exit_error(gettext("Could not store "
2008 "configuration values."));
2011 eauditon(A_SETPOLICY
, (caddr_t
)&policy
, 0);
2014 exit_error(gettext("policy (%s) invalid in a local zone."),
2018 exit_error(gettext("Invalid policy (%s) specified."),
2025 * do_setqbufsz() - set the active and configured audit queue write buffer size
2026 * (bytes); active values can be changed per zone if AUDIT_PERZONE is set, else
2027 * only in global zone.
2030 do_setqbufsz(char *bufsz
)
2032 struct au_qctrl qctrl
;
2034 if (!temporary_set
) {
2035 qctrl
.aq_bufsz
= (size_t)atol(bufsz
);
2036 if (!do_setqbufsz_scf(&qctrl
.aq_bufsz
)) {
2038 "Could not store configuration value."));
2040 if (qctrl
.aq_bufsz
== 0) {
2045 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
2046 qctrl
.aq_bufsz
= (size_t)atol(bufsz
);
2047 eauditon(A_SETQCTRL
, (caddr_t
)&qctrl
, 0);
2051 * do_setqctrl() - set the active and configured audit queue write buffer size
2052 * (bytes), hiwater audit record count, lowater audit record count, and wakeup
2053 * interval (ticks); active values can be changed per zone if AUDIT_PERZONE is
2054 * set, else only in global zone.
2057 do_setqctrl(char *hiwater
, char *lowater
, char *bufsz
, char *delay
)
2059 struct au_qctrl qctrl
;
2061 qctrl
.aq_hiwater
= (size_t)atol(hiwater
);
2062 qctrl
.aq_lowater
= (size_t)atol(lowater
);
2063 qctrl
.aq_bufsz
= (size_t)atol(bufsz
);
2064 qctrl
.aq_delay
= (clock_t)atol(delay
);
2066 if (!temporary_set
) {
2067 struct au_qctrl qctrl_act
;
2069 if (!do_setqctrl_scf(&qctrl
)) {
2071 "Could not store configuration values."));
2074 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl_act
, 0);
2075 if (qctrl
.aq_hiwater
== 0) {
2076 qctrl
.aq_hiwater
= qctrl_act
.aq_hiwater
;
2078 if (qctrl
.aq_lowater
== 0) {
2079 qctrl
.aq_lowater
= qctrl_act
.aq_lowater
;
2081 if (qctrl
.aq_bufsz
== 0) {
2082 qctrl
.aq_bufsz
= qctrl_act
.aq_bufsz
;
2084 if (qctrl
.aq_delay
== 0) {
2085 qctrl
.aq_delay
= qctrl_act
.aq_delay
;
2089 eauditon(A_SETQCTRL
, (caddr_t
)&qctrl
, 0);
2093 * do_setqdelay() - set the active and configured audit queue wakeup interval
2094 * (ticks); active values can be changed per zone if AUDIT_PERZONE is set, else
2095 * only in global zone.
2098 do_setqdelay(char *delay
)
2100 struct au_qctrl qctrl
;
2102 if (!temporary_set
) {
2103 qctrl
.aq_delay
= (clock_t)atol(delay
);
2104 if (!do_setqdelay_scf(&qctrl
.aq_delay
)) {
2106 "Could not store configuration value."));
2108 if (qctrl
.aq_delay
== 0) {
2113 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
2114 qctrl
.aq_delay
= (clock_t)atol(delay
);
2115 eauditon(A_SETQCTRL
, (caddr_t
)&qctrl
, 0);
2119 * do_setqhiwater() - sets the active and configured number of undelivered audit
2120 * records in the audit queue at which audit record generation blocks; active
2121 * values can be changed per zone if AUDIT_PERZONE is set, else only in global
2125 do_setqhiwater(char *hiwater
)
2127 struct au_qctrl qctrl
;
2129 if (!temporary_set
) {
2130 qctrl
.aq_hiwater
= (size_t)atol(hiwater
);
2131 if (!do_setqhiwater_scf(&qctrl
.aq_hiwater
)) {
2133 "Could not store configuration value."));
2135 if (qctrl
.aq_hiwater
== 0) {
2140 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
2141 qctrl
.aq_hiwater
= (size_t)atol(hiwater
);
2142 eauditon(A_SETQCTRL
, (caddr_t
)&qctrl
, 0);
2146 * do_setqlowater() - set the active and configured number of undelivered audit
2147 * records in the audit queue at which blocked auditing processes unblock;
2148 * active values can be changed per zone if AUDIT_PERZONE is set, else only in
2152 do_setqlowater(char *lowater
)
2154 struct au_qctrl qctrl
;
2156 if (!temporary_set
) {
2157 qctrl
.aq_lowater
= (size_t)atol(lowater
);
2158 if (!do_setqlowater_scf(&qctrl
.aq_lowater
)) {
2160 "Could not store configuration value."));
2162 if (qctrl
.aq_lowater
== 0) {
2167 eauditon(A_GETQCTRL
, (caddr_t
)&qctrl
, 0);
2168 qctrl
.aq_lowater
= (size_t)atol(lowater
);
2169 eauditon(A_SETQCTRL
, (caddr_t
)&qctrl
, 0);
2173 eauditon(int cmd
, caddr_t data
, int length
)
2175 if (auditon(cmd
, data
, length
) == -1)
2176 exit_error(gettext("auditon(2) failed."));
2180 egetauid(au_id_t
*auid
)
2182 if (getauid(auid
) == -1)
2183 exit_error(gettext("getauid(2) failed."));
2187 egetaudit(auditinfo_addr_t
*ai
, int size
)
2189 if (getaudit_addr(ai
, size
) == -1)
2190 exit_error(gettext("getaudit_addr(2) failed."));
2194 egetkaudit(auditinfo_addr_t
*ai
, int size
)
2196 if (auditon(A_GETKAUDIT
, (char *)ai
, size
) < 0)
2197 exit_error(gettext("auditon: A_GETKAUDIT failed."));
2201 esetkaudit(auditinfo_addr_t
*ai
, int size
)
2203 if (auditon(A_SETKAUDIT
, (char *)ai
, size
) < 0)
2204 exit_error(gettext("auditon: A_SETKAUDIT failed."));
2208 egetauditflagsbin(char *auditflags
, au_mask_t
*pmask
)
2210 if (strcmp(auditflags
, "none") == 0) {
2211 pmask
->am_success
= pmask
->am_failure
= 0;
2215 if (getauditflagsbin(auditflags
, pmask
) < 0) {
2216 exit_error(gettext("Could not get audit flags (%s)"),
2222 echkflags(char *auditflags
, au_mask_t
*mask
)
2227 if (!__chkflags(auditflags
, mask
, B_FALSE
, &err
)) {
2229 while (*err_ptr
!= ',' && *err_ptr
!= '\0') {
2233 exit_error(gettext("Unknown audit flags and/or prefixes "
2234 "encountered: %s"), err
);
2238 static au_event_ent_t
*
2239 egetauevnum(au_event_t event_number
)
2241 au_event_ent_t
*evp
;
2243 if ((evp
= getauevnum(event_number
)) == NULL
) {
2244 exit_error(gettext("Could not get audit event %hu"),
2251 static au_event_ent_t
*
2252 egetauevnam(char *event_name
)
2254 register au_event_ent_t
*evp
;
2256 if ((evp
= getauevnam(event_name
)) == NULL
)
2257 exit_error(gettext("Could not get audit event %s"), event_name
);
2263 esetauid(au_id_t
*auid
)
2265 if (setauid(auid
) == -1)
2266 exit_error(gettext("setauid(2) failed."));
2270 esetaudit(auditinfo_addr_t
*ai
, int size
)
2272 if (setaudit_addr(ai
, size
) == -1)
2273 exit_error(gettext("setaudit_addr(2) failed."));
2277 get_user_id(char *user
)
2282 if (isdigit(*user
)) {
2284 if ((pwd
= getpwuid(uid
)) == NULL
) {
2285 exit_error(gettext("Invalid user: %s"), user
);
2288 if ((pwd
= getpwnam(user
)) == NULL
) {
2289 exit_error(gettext("Invalid user: %s"), user
);
2293 return (pwd
->pw_uid
);
2298 * Inputs: command line argument string
2299 * Returns ptr to struct arg_entry if found; null, if not found
2301 static arg_entry_t
*
2302 get_arg_ent(char *arg_str
)
2306 key
.arg_str
= arg_str
;
2308 return ((arg_entry_t
*)bsearch((char *)&key
, (char *)arg_table
,
2309 ARG_TBL_SZ
, sizeof (arg_entry_t
), arg_ent_compare
));
2314 * Compares two command line arguments to determine which is
2315 * lexicographically greater.
2316 * Inputs: two argument map table entry pointers
2317 * Returns: > 1: aep1->arg_str > aep2->arg_str
2318 * < 1: aep1->arg_str < aep2->arg_str
2319 * 0: aep1->arg_str = aep->arg_str2
2322 arg_ent_compare(const void *aep1
, const void *aep2
)
2324 return (strcmp(((arg_entry_t
*)aep1
)->arg_str
,
2325 ((arg_entry_t
*)aep2
)->arg_str
));
2329 * tid_str is major,minor,host -- host is a name or an ip address
2332 str2tid(char *tid_str
, au_tid_addr_t
*tp
)
2336 char *host_str
= NULL
;
2340 struct hostent
*phe
;
2347 bzero(tp
->at_addr
, 16);
2349 major_str
= tid_str
;
2350 if ((minor_str
= strchr(tid_str
, ',')) != NULL
) {
2356 if ((host_str
= strchr(minor_str
, ',')) != NULL
) {
2363 major
= (major_t
)atoi(major_str
);
2366 minor
= (minor_t
)atoi(minor_str
);
2368 if ((dev
= makedev(major
, minor
)) != NODEV
)
2372 if (strisipaddr(host_str
)) {
2373 if (inet_pton(AF_INET
, host_str
, &ibuf
)) {
2374 tp
->at_addr
[0] = ibuf
;
2375 tp
->at_type
= AU_IPv4
;
2376 } else if (inet_pton(AF_INET6
, host_str
, ibuf6
)) {
2377 tp
->at_addr
[0] = ibuf6
[0];
2378 tp
->at_addr
[1] = ibuf6
[1];
2379 tp
->at_addr
[2] = ibuf6
[2];
2380 tp
->at_addr
[3] = ibuf6
[3];
2381 tp
->at_type
= AU_IPv6
;
2384 phe
= getipnodebyname((const void *)host_str
,
2387 phe
= getipnodebyname((const void *)host_str
,
2392 if (phe
->h_addrtype
== AF_INET6
) {
2393 /* address is IPv6 (128 bits) */
2394 (void) memcpy(&tp
->at_addr
[0],
2395 phe
->h_addr_list
[0], 16);
2396 tp
->at_type
= AU_IPv6
;
2398 /* address is IPv4 (32 bits) */
2399 (void) memcpy(&tp
->at_addr
[0],
2400 phe
->h_addr_list
[0], 4);
2401 tp
->at_type
= AU_IPv4
;
2414 eauditon(A_GETCOND
, (caddr_t
)&cond
, sizeof (cond
));
2419 return ("auditing");
2422 case AUC_INIT_AUDIT
:
2442 str2policy(char *policy_str
, uint32_t *policy_mask
)
2447 boolean_t is_all
= B_FALSE
;
2453 if (pfix
== '-' || pfix
== '+' || pfix
== '=')
2456 if ((buf
= strdup(policy_str
)) == NULL
)
2459 for (tok
= strtok(buf
, ","); tok
!= NULL
; tok
= strtok(NULL
, ",")) {
2461 if (((tok_pm
= get_policy(tok
)) == 0) &&
2462 ((strcasecmp(tok
, "none") != 0))) {
2467 if (tok_pm
== ALL_POLICIES
) {
2474 /* reuse policy mask if already set to some value */
2475 if (*policy_mask
!= 0) {
2476 curp
= *policy_mask
;
2478 (void) auditon(A_GETPOLICY
, (caddr_t
)&curp
, 0);
2483 (getzoneid() != GLOBAL_ZONEID
) &&
2484 (pm
& ~AUDIT_LOCAL
)) {
2488 if (getzoneid() != GLOBAL_ZONEID
)
2489 curp
&= AUDIT_LOCAL
;
2490 *policy_mask
= curp
& ~pm
;
2492 } else if (pfix
== '+') {
2494 * In a local zone, accept specifying "all", but not
2495 * individually specifying global-zone only policies.
2496 * Limit to all locally allowed, so system call doesn't
2500 (getzoneid() != GLOBAL_ZONEID
) &&
2501 (pm
& ~AUDIT_LOCAL
)) {
2505 if (getzoneid() != GLOBAL_ZONEID
) {
2506 curp
&= AUDIT_LOCAL
;
2511 *policy_mask
= curp
| pm
;
2515 * In a local zone, accept specifying "all", but not
2516 * individually specifying global-zone only policies.
2517 * Limit to all locally allowed, so system call doesn't
2521 (getzoneid() != GLOBAL_ZONEID
) &&
2522 (pm
& ~AUDIT_LOCAL
)) {
2526 if (is_all
&& (getzoneid() != GLOBAL_ZONEID
)) {
2535 policy2str(uint32_t policy
, char *policy_str
, size_t len
)
2539 if (policy
== ALL_POLICIES
) {
2540 (void) strcpy(policy_str
, "all");
2544 if (policy
== NO_POLICIES
) {
2545 (void) strcpy(policy_str
, "none");
2551 for (i
= 0, j
= 0; i
< POLICY_TBL_SZ
; i
++) {
2552 if (policy
& policy_table
[i
].policy_mask
&&
2553 policy_table
[i
].policy_mask
!= ALL_POLICIES
) {
2555 (void) strcat(policy_str
, ",");
2557 (void) strlcat(policy_str
, policy_table
[i
].policy_str
,
2572 if (s
== NULL
|| !*s
)
2575 for (; *s
== '-' || *s
== '+'; s
++)
2588 strisipaddr(char *s
)
2594 if ((s
== NULL
) || (!*s
))
2598 if (!(isxdigit(*s
) || *s
!= '.' || *s
!= ':'))
2616 chk_arg_len(char *argv
, uint_t len
)
2618 if ((strlen(argv
) + 1) > len
) {
2619 *(argv
+ len
- 1) = '\0';
2620 exit_error(gettext("Argument too long (%s..)."), argv
);
2625 chk_event_num(int etype
, au_event_t event
)
2629 eauditon(A_GETSTAT
, (caddr_t
)&as
, 0);
2631 if (etype
== AC_KERN_EVENT
) {
2632 if (event
> as
.as_numevent
) {
2634 "Invalid kernel audit event number specified.\n"
2635 "\t%hu is outside allowable range 0-%d."),
2636 event
, as
.as_numevent
);
2640 if (event
<= as
.as_numevent
) {
2641 exit_error(gettext("Invalid user level audit event "
2642 "number specified %hu."), event
);
2648 chk_event_str(int etype
, char *event_str
)
2650 au_event_ent_t
*evp
;
2653 eauditon(A_GETSTAT
, (caddr_t
)&as
, 0);
2655 evp
= egetauevnam(event_str
);
2656 if (etype
== AC_KERN_EVENT
&& (evp
->ae_number
> as
.as_numevent
)) {
2658 "Invalid kernel audit event string specified.\n"
2659 "\t\"%s\" appears to be a user level event. "
2660 "Check configuration."), event_str
);
2661 } else if (etype
== AC_USER_EVENT
&&
2662 (evp
->ae_number
< as
.as_numevent
)) {
2664 "Invalid user audit event string specified.\n"
2665 "\t\"%s\" appears to be a kernel event. "
2666 "Check configuration."), event_str
);
2671 chk_known_plugin(char *plugin_str
)
2673 if ((strlen(plugin_str
) + 1) > PLUGIN_MAXBUF
) {
2674 exit_error(gettext("Plugin name too long.\n"));
2677 if (!plugin_avail_scf(plugin_str
)) {
2678 exit_error(gettext("No such plugin configured: %s"),
2684 chk_sorf(char *sorf_str
)
2686 if (!strisnum(sorf_str
))
2687 exit_error(gettext("Invalid sorf specified: %s"), sorf_str
);
2691 chk_retval(char *retval_str
)
2693 if (!strisnum(retval_str
))
2694 exit_error(gettext("Invalid retval specified: %s"), retval_str
);
2700 char *args
, *args_pos
;
2706 /* concatenate argument array to be passed to sh -c "..." */
2707 for (argv_pos
= argv
; *argv_pos
; argv_pos
++)
2708 len
+= strlen(*argv_pos
) + 1;
2710 if ((args
= malloc(len
+ 1)) == NULL
)
2712 gettext("Allocation for command/arguments failed"));
2715 for (argv_pos
= argv
; *argv_pos
; argv_pos
++) {
2716 n
+= snprintf(args_pos
, len
- n
, "%s ", *argv_pos
);
2717 args_pos
= args
+ n
;
2719 /* strip the last space */
2720 args
[strlen(args
)] = '\0';
2722 (void) execl("/bin/sh", "sh", "-c", args
, NULL
);
2724 (void) execl("/bin/sh", "sh", NULL
);
2727 exit_error(gettext("exec(2) failed"));
2731 exit_usage(int status
)
2736 fp
= (status
? stderr
: stdout
);
2737 (void) fprintf(fp
, gettext("usage: %s option ...\n"), progname
);
2739 for (i
= 0; i
< ARG_TBL_SZ
; i
++) {
2740 /* skip the -t option; it's not a standalone option */
2741 if (arg_table
[i
].auditconfig_cmd
== AC_ARG_SET_TEMPORARY
) {
2745 (void) fprintf(fp
, " %s%s%s\n",
2746 arg_table
[i
].arg_str
, arg_table
[i
].arg_opts
,
2747 (arg_table
[i
].temporary_allowed
? " [-t]" : ""));
2754 print_asid(au_asid_t asid
)
2756 (void) printf(gettext("audit session id = %u\n"), asid
);
2760 print_auid(au_id_t auid
)
2765 if ((pwd
= getpwuid((uid_t
)auid
)) != NULL
)
2766 username
= pwd
->pw_name
;
2768 username
= gettext("unknown");
2770 (void) printf(gettext("audit id = %s(%d)\n"), username
, auid
);
2774 print_mask(char *desc
, au_mask_t
*pmp
)
2778 if (getauditflagschar(auflags
, pmp
, NULL
) < 0)
2779 (void) strlcpy(auflags
, gettext("unknown"), sizeof (auflags
));
2781 (void) printf("%s = %s(0x%x,0x%x)\n",
2782 desc
, auflags
, pmp
->am_success
, pmp
->am_failure
);
2786 print_plugin(char *plugin_name
, kva_t
*plugin_kva
)
2788 char att_str
[PLUGIN_MAXATT
];
2789 boolean_t plugin_active
;
2794 if ((active_str
= kva_match(plugin_kva
, "active")) == NULL
) {
2795 (void) printf(gettext("Audit service configuration error: "
2796 "\"active\" property not found\n"));
2800 plugin_active
= (boolean_t
)atoi(active_str
);
2801 qsize_ptr
= kva_match(plugin_kva
, "qsize");
2802 qsize
= atoi(qsize_ptr
== NULL
? "-1" : qsize_ptr
);
2804 (void) printf(gettext("Plugin: %s (%s)\n"), plugin_name
,
2805 plugin_active
? "active" : "inactive");
2807 free_static_att_kva(plugin_kva
);
2809 switch (_kva2str(plugin_kva
, att_str
, PLUGIN_MAXATT
, "=", ";")) {
2811 (void) printf(gettext("\tAttributes: %s\n"), att_str
);
2814 exit_error(gettext("Internal error - buffer size too small."));
2817 exit_error(gettext("Internal error."));
2822 (void) printf(gettext("\tQueue size: %d %s\n"), qsize
,
2823 qsize
== -1 ? "(internal error: value not available)" : "");
2828 print_tid_ex(au_tid_addr_t
*tidp
)
2830 struct hostent
*phe
;
2835 char buf
[INET6_ADDRSTRLEN
];
2839 /* IPV6 or IPV4 address */
2840 if (tidp
->at_type
== AU_IPv4
) {
2841 if ((phe
= gethostbyaddr((char *)&tidp
->at_addr
[0],
2842 sizeof (tidp
->at_addr
[0]), AF_INET
)) != NULL
) {
2843 hostname
= phe
->h_name
;
2845 hostname
= gettext("unknown");
2848 ia
.s_addr
= tidp
->at_addr
[0];
2850 (void) printf(gettext(
2851 "terminal id (maj,min,host) = %lu,%lu,%s(%s)\n"),
2852 major(tidp
->at_port
), minor(tidp
->at_port
),
2853 hostname
, inet_ntoa(ia
));
2855 addr
= &tidp
->at_addr
[0];
2856 phe
= getipnodebyaddr((const void *)addr
, 16, AF_INET6
, &err
);
2858 bzero(buf
, sizeof (buf
));
2860 (void) inet_ntop(AF_INET6
, (void *)addr
, buf
, sizeof (buf
));
2862 bufp
= gettext("unknown");
2867 (void) printf(gettext(
2868 "terminal id (maj,min,host) = %lu,%lu,%s(%s)\n"),
2869 major(tidp
->at_port
), minor(tidp
->at_port
),
2878 str2ipaddr(char *s
, uint32_t *addr
, uint32_t type
)
2885 if (strisipaddr(s
)) {
2886 if (type
== AU_IPv4
) {
2887 if (inet_pton(AF_INET
, s
, addr
)) {
2891 } else if (type
== AU_IPv6
) {
2892 if (inet_pton(AF_INET6
, s
, addr
))
2898 if (type
== AU_IPv4
) {
2899 (void) sscanf(s
, "%x", &addr
[0]);
2901 } else if (type
== AU_IPv6
) {
2904 for (j
= 3; j
>= 0; j
--) {
2905 if ((sl
- 8) <= 0) {
2906 (void) sscanf(s
, "%x", &v
);
2911 (void) sscanf(ss
, "%x", &v
);
2922 str2type(char *s
, uint_t
*type
)
2924 if (strcmp(s
, "ipv6") == 0) {
2928 if (strcmp(s
, "ipv4") == 0) {
2937 * exit_error() - print an error message along with corresponding system error
2938 * number and error message, then exit. Inputs - program error format and
2943 exit_error(char *fmt
, ...)
2947 va_start(args
, fmt
);
2948 prt_error_va(fmt
, args
);