xref: /illumos-gate/usr/src/cmd/auditconfig/auditconfig.c (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * auditconfig - set and display audit parameters
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <locale.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <ctype.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <stdarg.h>
377c478bd9Sstevel@tonic-gate #include <unistd.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <sys/param.h>
407c478bd9Sstevel@tonic-gate #include <stdio.h>
417c478bd9Sstevel@tonic-gate #include <string.h>
427c478bd9Sstevel@tonic-gate #include <strings.h>
437c478bd9Sstevel@tonic-gate #include <nlist.h>
447c478bd9Sstevel@tonic-gate #include <fcntl.h>
457c478bd9Sstevel@tonic-gate #include <sys/socket.h>
467c478bd9Sstevel@tonic-gate #include <netdb.h>
477c478bd9Sstevel@tonic-gate #include <netinet/in.h>
487c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
497c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
507c478bd9Sstevel@tonic-gate #include <sys/param.h>
517c478bd9Sstevel@tonic-gate #include <pwd.h>
527c478bd9Sstevel@tonic-gate #include <libintl.h>
537c478bd9Sstevel@tonic-gate #include <zone.h>
54*45916cd2Sjpk #include <tsol/label.h>
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
577c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
587c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
617c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SUNW_OST_OSCMD"
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	AC_ARG_AUDIT			0
657c478bd9Sstevel@tonic-gate #define	AC_ARG_CHKCONF			1
667c478bd9Sstevel@tonic-gate #define	AC_ARG_CONF			2
677c478bd9Sstevel@tonic-gate #define	AC_ARG_GETASID			3	/* same as GETSID */
687c478bd9Sstevel@tonic-gate #define	AC_ARG_GETAUDIT			4
697c478bd9Sstevel@tonic-gate #define	AC_ARG_GETAUID			5
707c478bd9Sstevel@tonic-gate #define	AC_ARG_GETCAR			6
717c478bd9Sstevel@tonic-gate #define	AC_ARG_GETCLASS			7	/* same as GETESTATE */
727c478bd9Sstevel@tonic-gate #define	AC_ARG_GETCOND			8
737c478bd9Sstevel@tonic-gate #define	AC_ARG_GETCWD			9
747c478bd9Sstevel@tonic-gate #define	AC_ARG_GETESTATE		10
757c478bd9Sstevel@tonic-gate #define	AC_ARG_GETKERNSTATE		11
767c478bd9Sstevel@tonic-gate #define	AC_ARG_GETKMASK			12	/* same as GETKERNSTATE */
777c478bd9Sstevel@tonic-gate #define	AC_ARG_GETPINFO			13
787c478bd9Sstevel@tonic-gate #define	AC_ARG_GETPOLICY		14
797c478bd9Sstevel@tonic-gate #define	AC_ARG_GETQBUFSZ		15
807c478bd9Sstevel@tonic-gate #define	AC_ARG_GETQCTRL			16
817c478bd9Sstevel@tonic-gate #define	AC_ARG_GETQDELAY		17
827c478bd9Sstevel@tonic-gate #define	AC_ARG_GETQHIWATER		18
837c478bd9Sstevel@tonic-gate #define	AC_ARG_GETQLOWATER		19
847c478bd9Sstevel@tonic-gate #define	AC_ARG_GETSID			20
857c478bd9Sstevel@tonic-gate #define	AC_ARG_GETSTAT			21
867c478bd9Sstevel@tonic-gate #define	AC_ARG_GETTERMID		22
877c478bd9Sstevel@tonic-gate #define	AC_ARG_GETUSERAUDIT		23	/* only CMW syscall w/out */
887c478bd9Sstevel@tonic-gate #define	AC_ARG_LSEVENT			24
897c478bd9Sstevel@tonic-gate #define	AC_ARG_LSPOLICY			25
907c478bd9Sstevel@tonic-gate #define	AC_ARG_SETASID			26
917c478bd9Sstevel@tonic-gate #define	AC_ARG_SETAUDIT			27
927c478bd9Sstevel@tonic-gate #define	AC_ARG_SETAUID			28
937c478bd9Sstevel@tonic-gate #define	AC_ARG_SETCLASS			29	/* same as SETESTATE */
947c478bd9Sstevel@tonic-gate /*	AC_ARG_SETCOND			30 */
957c478bd9Sstevel@tonic-gate #define	AC_ARG_SETESTATE		31
967c478bd9Sstevel@tonic-gate #define	AC_ARG_SETKERNSTATE		32
977c478bd9Sstevel@tonic-gate #define	AC_ARG_SETKMASK			33	/* same as SETKERNSTATE */
987c478bd9Sstevel@tonic-gate #define	AC_ARG_SETPMASK			34
997c478bd9Sstevel@tonic-gate #define	AC_ARG_SETSMASK			35
1007c478bd9Sstevel@tonic-gate #define	AC_ARG_SETSTAT			36
1017c478bd9Sstevel@tonic-gate #define	AC_ARG_SETPOLICY		37
1027c478bd9Sstevel@tonic-gate #define	AC_ARG_SETQBUFSZ		38
1037c478bd9Sstevel@tonic-gate #define	AC_ARG_SETQCTRL			39
1047c478bd9Sstevel@tonic-gate #define	AC_ARG_SETQDELAY		40
1057c478bd9Sstevel@tonic-gate #define	AC_ARG_SETQHIWATER		41
1067c478bd9Sstevel@tonic-gate #define	AC_ARG_SETQLOWATER		42
1077c478bd9Sstevel@tonic-gate #define	AC_ARG_SETTERMID		43
1087c478bd9Sstevel@tonic-gate #define	AC_ARG_SETUMASK			44
1097c478bd9Sstevel@tonic-gate #define	AC_ARG_SETUSERAUDIT		45
1107c478bd9Sstevel@tonic-gate #define	AC_ARG_GETFSIZE			46
1117c478bd9Sstevel@tonic-gate #define	AC_ARG_SETFSIZE			47
1127c478bd9Sstevel@tonic-gate #define	AC_ARG_GETKAUDIT		48
1137c478bd9Sstevel@tonic-gate #define	AC_ARG_SETKAUDIT		49
1147c478bd9Sstevel@tonic-gate #define	AC_ARG_ACONF			50
1157c478bd9Sstevel@tonic-gate #define	AC_ARG_CHKACONF			51
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	AC_KERN_EVENT 		0
1187c478bd9Sstevel@tonic-gate #define	AC_USER_EVENT 		1
1197c478bd9Sstevel@tonic-gate 
120*45916cd2Sjpk /* defines for policy entry flags: */
121*45916cd2Sjpk 
122*45916cd2Sjpk #define	AC_TSOL 		1	/* policy is TSOL-only */
123*45916cd2Sjpk 
1247c478bd9Sstevel@tonic-gate #define	NONE(s) (!strlen(s) ? gettext("none") : s)
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	ALL_POLICIES   (AUDIT_AHLT|\
1277c478bd9Sstevel@tonic-gate 			AUDIT_ARGE|\
1287c478bd9Sstevel@tonic-gate 			AUDIT_ARGV|\
1297c478bd9Sstevel@tonic-gate 			AUDIT_CNT|\
1307c478bd9Sstevel@tonic-gate 			AUDIT_GROUP|\
1317c478bd9Sstevel@tonic-gate 			AUDIT_PASSWD|\
1327c478bd9Sstevel@tonic-gate 			AUDIT_WINDATA|\
1337c478bd9Sstevel@tonic-gate 			AUDIT_SEQ|\
1347c478bd9Sstevel@tonic-gate 			AUDIT_TRAIL|\
1357c478bd9Sstevel@tonic-gate 			AUDIT_PATH|\
1367c478bd9Sstevel@tonic-gate 			AUDIT_PUBLIC|\
1377c478bd9Sstevel@tonic-gate 			AUDIT_ZONENAME|\
138*45916cd2Sjpk 			AUDIT_PERZONE|\
139*45916cd2Sjpk 			AUDIT_WINDATA_DOWN|\
140*45916cd2Sjpk 			AUDIT_WINDATA_UP)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	NO_POLICIES  (0)
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #define	ONEK 1024
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* This should be defined in <string.h>, but it is not */
1477c478bd9Sstevel@tonic-gate extern int strncasecmp();
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * remove this after the audit.h is fixed
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate struct arg_entry {
1547c478bd9Sstevel@tonic-gate 	char *arg_str;
1557c478bd9Sstevel@tonic-gate 	char *arg_opts;
1567c478bd9Sstevel@tonic-gate 	int auditconfig_cmd;
1577c478bd9Sstevel@tonic-gate };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate struct policy_entry {
1607c478bd9Sstevel@tonic-gate 	char *policy_str;
1617c478bd9Sstevel@tonic-gate 	uint_t policy_mask;
162*45916cd2Sjpk 	uint_t policy_flags;
1637c478bd9Sstevel@tonic-gate 	char *policy_desc;
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate static struct arg_entry arg_table[] = {
1677c478bd9Sstevel@tonic-gate 	{ "-aconf",		"",			AC_ARG_ACONF},
1687c478bd9Sstevel@tonic-gate 	{ "-audit",	"event sorf retval string",	AC_ARG_AUDIT},
1697c478bd9Sstevel@tonic-gate 	{ "-chkaconf",		"",			AC_ARG_CHKACONF},
1707c478bd9Sstevel@tonic-gate 	{ "-chkconf",		"",			AC_ARG_CHKCONF},
1717c478bd9Sstevel@tonic-gate 	{ "-conf",		"",			AC_ARG_CONF},
1727c478bd9Sstevel@tonic-gate 	{ "-getasid",		"",			AC_ARG_GETASID},
1737c478bd9Sstevel@tonic-gate 	{ "-getaudit",		"",			AC_ARG_GETAUDIT},
1747c478bd9Sstevel@tonic-gate 	{ "-getauid",		"",			AC_ARG_GETAUID},
1757c478bd9Sstevel@tonic-gate 	{ "-getcar",		"",			AC_ARG_GETCAR},
1767c478bd9Sstevel@tonic-gate 	{ "-getclass",		"",			AC_ARG_GETCLASS},
1777c478bd9Sstevel@tonic-gate 	{ "-getcond",		"",			AC_ARG_GETCOND},
1787c478bd9Sstevel@tonic-gate 	{ "-getcwd",		"",			AC_ARG_GETCWD},
1797c478bd9Sstevel@tonic-gate 	{ "-getestate",		"event",		AC_ARG_GETESTATE},
1807c478bd9Sstevel@tonic-gate 	{ "-getfsize",		"",			AC_ARG_GETFSIZE},
1817c478bd9Sstevel@tonic-gate 	{ "-getkaudit",		"",			AC_ARG_GETKAUDIT},
1827c478bd9Sstevel@tonic-gate 	{ "-getkernstate",	"",			AC_ARG_GETKERNSTATE},
1837c478bd9Sstevel@tonic-gate 	{ "-getkmask",		"",			AC_ARG_GETKMASK},
1847c478bd9Sstevel@tonic-gate 	{ "-getpinfo",		"",			AC_ARG_GETPINFO},
1857c478bd9Sstevel@tonic-gate 	{ "-getpolicy",		"",			AC_ARG_GETPOLICY},
1867c478bd9Sstevel@tonic-gate 	{ "-getqbufsz",		"",			AC_ARG_GETQBUFSZ},
1877c478bd9Sstevel@tonic-gate 	{ "-getqctrl",		"",			AC_ARG_GETQCTRL},
1887c478bd9Sstevel@tonic-gate 	{ "-getqdelay",		"",			AC_ARG_GETQDELAY},
1897c478bd9Sstevel@tonic-gate 	{ "-getqhiwater",	"",			AC_ARG_GETQHIWATER},
1907c478bd9Sstevel@tonic-gate 	{ "-getqlowater",	"",			AC_ARG_GETQLOWATER},
1917c478bd9Sstevel@tonic-gate 	{ "-getsid",		"",			AC_ARG_GETSID},
1927c478bd9Sstevel@tonic-gate 	{ "-getstat",		"",			AC_ARG_GETSTAT},
1937c478bd9Sstevel@tonic-gate 	{ "-gettermid",		"",			AC_ARG_GETTERMID},
1947c478bd9Sstevel@tonic-gate 	{ "-gettid",		"",			AC_ARG_GETTERMID},
1957c478bd9Sstevel@tonic-gate 	{ "-getuseraudit",	"user",			AC_ARG_GETUSERAUDIT},
1967c478bd9Sstevel@tonic-gate 	{ "-lsevent",		"",			AC_ARG_LSEVENT},
1977c478bd9Sstevel@tonic-gate 	{ "-lspolicy",		"",			AC_ARG_LSPOLICY},
1987c478bd9Sstevel@tonic-gate 	{ "-setasid",		"asid [cmd]",		AC_ARG_SETASID},
1997c478bd9Sstevel@tonic-gate 	{ "-setaudit",	"auid audit_flags termid sid [cmd]",
2007c478bd9Sstevel@tonic-gate 							AC_ARG_SETAUDIT},
2017c478bd9Sstevel@tonic-gate 	{ "-setauid",		"auid [cmd]",		AC_ARG_SETAUID},
2027c478bd9Sstevel@tonic-gate 	{ "-setclass",		"event audit_flags",	AC_ARG_SETCLASS},
2037c478bd9Sstevel@tonic-gate 	{ "-setestate",		"event audit_flags",	AC_ARG_SETESTATE},
2047c478bd9Sstevel@tonic-gate 	{ "-setfsize",		"filesize",		AC_ARG_SETFSIZE},
2057c478bd9Sstevel@tonic-gate 	{ "-setkaudit",		"type IP_address",	AC_ARG_SETKAUDIT},
2067c478bd9Sstevel@tonic-gate 	{ "-setkernstate",	"audit_flags",		AC_ARG_SETKERNSTATE},
2077c478bd9Sstevel@tonic-gate 	{ "-setkmask",		"audit_flags",		AC_ARG_SETKMASK},
2087c478bd9Sstevel@tonic-gate 	{ "-setpmask",	"pid audit_flags [cmd]",	AC_ARG_SETPMASK},
2097c478bd9Sstevel@tonic-gate 	{ "-setpolicy",		"policy_flags",		AC_ARG_SETPOLICY},
2107c478bd9Sstevel@tonic-gate 	{ "-setqbufsz",		"bufsz",		AC_ARG_SETQBUFSZ},
2117c478bd9Sstevel@tonic-gate 	{ "-setqctrl",	"hiwater lowater bufsz delay",	AC_ARG_SETQCTRL},
2127c478bd9Sstevel@tonic-gate 	{ "-setqdelay",		"delay",		AC_ARG_SETQDELAY},
2137c478bd9Sstevel@tonic-gate 	{ "-setqhiwater",	"hiwater",		AC_ARG_SETQHIWATER},
2147c478bd9Sstevel@tonic-gate 	{ "-setqlowater",	"lowater",		AC_ARG_SETQLOWATER},
2157c478bd9Sstevel@tonic-gate 	{ "-setsmask",		"asid audit_flags",	AC_ARG_SETSMASK},
2167c478bd9Sstevel@tonic-gate 	{ "-setstat",		"",			AC_ARG_SETSTAT},
2177c478bd9Sstevel@tonic-gate 	{ "-settid",		"tid [cmd]",		AC_ARG_SETTERMID},
2187c478bd9Sstevel@tonic-gate 	{ "-setumask",		"user audit_flags",	AC_ARG_SETUMASK},
2197c478bd9Sstevel@tonic-gate 	{ "-setuseraudit",	"user audit_flags",	AC_ARG_SETUSERAUDIT}
2207c478bd9Sstevel@tonic-gate };
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate #define	ARG_TBL_SZ (sizeof (arg_table) / sizeof (struct arg_entry))
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate static struct arg_entry arg2_table[] = {
2257c478bd9Sstevel@tonic-gate 	{ "-chkconf",	"",				AC_ARG_CHKCONF},
2267c478bd9Sstevel@tonic-gate 	{ "-conf",	"",				AC_ARG_CONF},
2277c478bd9Sstevel@tonic-gate 	{ "-getcond",	"",				AC_ARG_GETCOND},
2287c478bd9Sstevel@tonic-gate 	{ "-getclass",	"event",			AC_ARG_GETCLASS},
2297c478bd9Sstevel@tonic-gate 	{ "-setclass",	"event audit_flags",		AC_ARG_SETCLASS},
2307c478bd9Sstevel@tonic-gate 	{ "-lsevent",	"",				AC_ARG_LSEVENT},
2317c478bd9Sstevel@tonic-gate 	{ "-lspolicy",	"",				AC_ARG_LSPOLICY},
2327c478bd9Sstevel@tonic-gate 	{ "-getpolicy",	"",				AC_ARG_GETPOLICY},
2337c478bd9Sstevel@tonic-gate 	{ "-setpolicy",	"policy_flags",			AC_ARG_SETPOLICY},
2347c478bd9Sstevel@tonic-gate 	{ "-getstat",	"",				AC_ARG_GETSTAT},
2357c478bd9Sstevel@tonic-gate 	{ "-getpinfo",	"pid",				AC_ARG_GETPINFO},
2367c478bd9Sstevel@tonic-gate 	{ "-setpmask",	"pid audit_flags",		AC_ARG_SETPMASK},
2377c478bd9Sstevel@tonic-gate 	{ "-setsmask",	"asid audit_flags",		AC_ARG_SETSMASK},
2387c478bd9Sstevel@tonic-gate 	{ "-setumask",	"user audit_flags",		AC_ARG_SETUMASK},
2397c478bd9Sstevel@tonic-gate 	{ "-getfsize",	"",				AC_ARG_GETFSIZE},
2407c478bd9Sstevel@tonic-gate 	{ "-setfsize",	"filesize",			AC_ARG_SETFSIZE}
2417c478bd9Sstevel@tonic-gate 	};
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate #define	ARG2_TBL_SZ (sizeof (arg2_table) / sizeof (struct arg_entry))
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate static struct policy_entry policy_table[] = {
246*45916cd2Sjpk 	{"ahlt",	AUDIT_AHLT,	NULL,
247*45916cd2Sjpk 	    "halt machine if it can not record an async event"},
248*45916cd2Sjpk 	{"arge",	AUDIT_ARGE,	NULL,
249*45916cd2Sjpk 	    "include exec environment args in audit recs"},
250*45916cd2Sjpk 	{"argv",	AUDIT_ARGV,	NULL,
251*45916cd2Sjpk 	    "include exec command line args in audit recs"},
252*45916cd2Sjpk 	{"cnt",		AUDIT_CNT,	NULL,
253*45916cd2Sjpk 	    "when no more space, drop recs and keep a cnt"},
254*45916cd2Sjpk 	{"group",	AUDIT_GROUP,	NULL,
255*45916cd2Sjpk 	    "include supplementary groups in audit recs"},
256*45916cd2Sjpk 	{"path",	AUDIT_PATH,	NULL,
257*45916cd2Sjpk 	    "allow multiple paths per event"},
258*45916cd2Sjpk 	{"public",	AUDIT_PUBLIC,	NULL,	"audit public files"},
259*45916cd2Sjpk 	{"seq",		AUDIT_SEQ,	NULL,
260*45916cd2Sjpk 	    "include a sequence number in audit recs"},
261*45916cd2Sjpk 	{"trail",	AUDIT_TRAIL,	NULL,
262*45916cd2Sjpk 	    "include trailer token in audit recs"},
263*45916cd2Sjpk 	{"windata_down",	AUDIT_WINDATA_DOWN,	AC_TSOL,
264*45916cd2Sjpk 		"include downgraded information in audit recs"},
265*45916cd2Sjpk 	{"windata_up",		AUDIT_WINDATA_UP,	AC_TSOL,
266*45916cd2Sjpk 		"include upgraded information in audit recs"},
267*45916cd2Sjpk 	{"zonename",	AUDIT_ZONENAME,	NULL,	"generate zonename token"},
268*45916cd2Sjpk 	{"perzone",	AUDIT_PERZONE,	NULL,
269*45916cd2Sjpk 	    "use a separate queue and auditd per zone"},
270*45916cd2Sjpk 	{"all",		ALL_POLICIES,	NULL,	"all policies"},
271*45916cd2Sjpk 	{"none",	NO_POLICIES,	NULL,	"no policies"}
2727c478bd9Sstevel@tonic-gate 	};
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate #define	POLICY_TBL_SZ (sizeof (policy_table) / sizeof (struct policy_entry))
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate static char *progname;
2777c478bd9Sstevel@tonic-gate 
278*45916cd2Sjpk int	tsol_on;			/* is TSOL installed? */
279*45916cd2Sjpk 
2807c478bd9Sstevel@tonic-gate static au_event_ent_t *egetauevnam();
2817c478bd9Sstevel@tonic-gate static au_event_ent_t *egetauevnum();
2827c478bd9Sstevel@tonic-gate static char *strtolower();
2837c478bd9Sstevel@tonic-gate static int arg_ent_compare();
2847c478bd9Sstevel@tonic-gate static int cond2str();
2857c478bd9Sstevel@tonic-gate static int policy2str();
2867c478bd9Sstevel@tonic-gate static int str2type();
2877c478bd9Sstevel@tonic-gate static int str2policy();
2887c478bd9Sstevel@tonic-gate static int str2ipaddr();
2897c478bd9Sstevel@tonic-gate static int strisflags();
2907c478bd9Sstevel@tonic-gate static int strisipaddr();
2917c478bd9Sstevel@tonic-gate static int strisnum();
2927c478bd9Sstevel@tonic-gate static struct arg_entry *get_arg_ent();
2937c478bd9Sstevel@tonic-gate static struct policy_entry *get_policy_ent();
2947c478bd9Sstevel@tonic-gate static uid_t get_user_id();
2957c478bd9Sstevel@tonic-gate static void chk_event_num();
2967c478bd9Sstevel@tonic-gate static void chk_event_str();
2977c478bd9Sstevel@tonic-gate static void chk_retval();
2987c478bd9Sstevel@tonic-gate static void chk_sorf();
2997c478bd9Sstevel@tonic-gate static void chk_tid();
3007c478bd9Sstevel@tonic-gate static void do_aconf();
3017c478bd9Sstevel@tonic-gate static void do_args();
3027c478bd9Sstevel@tonic-gate static void do_audit();
3037c478bd9Sstevel@tonic-gate static void do_chkaconf();
3047c478bd9Sstevel@tonic-gate static void do_chkconf();
3057c478bd9Sstevel@tonic-gate static void do_conf();
3067c478bd9Sstevel@tonic-gate static void do_getasid();
3077c478bd9Sstevel@tonic-gate static void do_getaudit();
3087c478bd9Sstevel@tonic-gate static void do_getkaudit();
3097c478bd9Sstevel@tonic-gate static void do_setkaudit();
3107c478bd9Sstevel@tonic-gate static void do_getauid();
3117c478bd9Sstevel@tonic-gate static void do_getcar();
3127c478bd9Sstevel@tonic-gate static void do_getclass();
3137c478bd9Sstevel@tonic-gate static void do_getcond();
3147c478bd9Sstevel@tonic-gate static void do_getcwd();
3157c478bd9Sstevel@tonic-gate static void do_getkmask();
3167c478bd9Sstevel@tonic-gate static void do_getpinfo();
3177c478bd9Sstevel@tonic-gate static void do_getpolicy();
3187c478bd9Sstevel@tonic-gate static void do_getqbufsz();
3197c478bd9Sstevel@tonic-gate static void do_getqctrl();
3207c478bd9Sstevel@tonic-gate static void do_getqdelay();
3217c478bd9Sstevel@tonic-gate static void do_getqhiwater();
3227c478bd9Sstevel@tonic-gate static void do_getqlowater();
3237c478bd9Sstevel@tonic-gate static void do_getstat();
3247c478bd9Sstevel@tonic-gate static void do_gettermid();
3257c478bd9Sstevel@tonic-gate static void do_getuseraudit();
3267c478bd9Sstevel@tonic-gate static void do_lsevent();
3277c478bd9Sstevel@tonic-gate static void do_lspolicy();
3287c478bd9Sstevel@tonic-gate static void do_setasid();
3297c478bd9Sstevel@tonic-gate static void do_setaudit();
3307c478bd9Sstevel@tonic-gate static void do_setauid();
3317c478bd9Sstevel@tonic-gate static void do_setclass();
3327c478bd9Sstevel@tonic-gate static void do_setkmask();
3337c478bd9Sstevel@tonic-gate static void do_setpmask();
3347c478bd9Sstevel@tonic-gate static void do_setsmask();
3357c478bd9Sstevel@tonic-gate static void do_setumask();
3367c478bd9Sstevel@tonic-gate static void do_setpolicy();
3377c478bd9Sstevel@tonic-gate static void do_setqbufsz();
3387c478bd9Sstevel@tonic-gate static void do_setqctrl();
3397c478bd9Sstevel@tonic-gate static void do_setqdelay();
3407c478bd9Sstevel@tonic-gate static void do_setqhiwater();
3417c478bd9Sstevel@tonic-gate static void do_setqlowater();
3427c478bd9Sstevel@tonic-gate static void do_setstat();
3437c478bd9Sstevel@tonic-gate static void do_settid();
3447c478bd9Sstevel@tonic-gate static void do_setuseraudit();
3457c478bd9Sstevel@tonic-gate static void do_getfsize();
3467c478bd9Sstevel@tonic-gate static void do_setfsize();
3477c478bd9Sstevel@tonic-gate static void str2mask();
3487c478bd9Sstevel@tonic-gate static void str2tid();
3497c478bd9Sstevel@tonic-gate static void strsplit();
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate static void eauditon();
3527c478bd9Sstevel@tonic-gate static void egetaudit();
3537c478bd9Sstevel@tonic-gate static void egetkaudit();
3547c478bd9Sstevel@tonic-gate static void esetkaudit();
3557c478bd9Sstevel@tonic-gate static void egetauditflagsbin();
3567c478bd9Sstevel@tonic-gate static void egetauid();
3577c478bd9Sstevel@tonic-gate static void esetaudit();
3587c478bd9Sstevel@tonic-gate static void esetauid();
3597c478bd9Sstevel@tonic-gate static void execit();
3607c478bd9Sstevel@tonic-gate static void exit_error(char *, ...);
3617c478bd9Sstevel@tonic-gate static void exit_usage();
3627c478bd9Sstevel@tonic-gate static void parse_args();
3637c478bd9Sstevel@tonic-gate static void print_asid();
3647c478bd9Sstevel@tonic-gate static void print_auid();
3657c478bd9Sstevel@tonic-gate static void print_mask();
3667c478bd9Sstevel@tonic-gate static void print_mask1();
3677c478bd9Sstevel@tonic-gate static void print_stats();
3687c478bd9Sstevel@tonic-gate static void print_tid_ex();
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate int
3717c478bd9Sstevel@tonic-gate main(argc, argv)
3727c478bd9Sstevel@tonic-gate 	int argc;
3737c478bd9Sstevel@tonic-gate 	char **argv;
3747c478bd9Sstevel@tonic-gate {
3757c478bd9Sstevel@tonic-gate 	progname = "auditconfig";
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
3787c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	if (argc == 1) {
3817c478bd9Sstevel@tonic-gate 		exit_usage(0);
3827c478bd9Sstevel@tonic-gate 		exit(0);
3837c478bd9Sstevel@tonic-gate 	}
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	if (argc == 2 &&
3867c478bd9Sstevel@tonic-gate 		(argv[1][0] == '?' ||
3877c478bd9Sstevel@tonic-gate 		strcmp(argv[1], "-h") == 0 ||
3887c478bd9Sstevel@tonic-gate 		strcmp(argv[1], "-?") == 0))
3897c478bd9Sstevel@tonic-gate 		exit_usage(0);
3907c478bd9Sstevel@tonic-gate 
391*45916cd2Sjpk 	tsol_on = is_system_labeled();
392*45916cd2Sjpk 
3937c478bd9Sstevel@tonic-gate 	parse_args(argv);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	do_args(argv);
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	return (0);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate /*
4017c478bd9Sstevel@tonic-gate  * parse_args()
4027c478bd9Sstevel@tonic-gate  *     Desc: Checks command line argument syntax.
4037c478bd9Sstevel@tonic-gate  *     Inputs: Command line argv;
4047c478bd9Sstevel@tonic-gate  *     Returns: If a syntax error is detected, a usage message is printed
4057c478bd9Sstevel@tonic-gate  *              and exit() is called. If a syntax error is not detected,
4067c478bd9Sstevel@tonic-gate  *              parse_args() returns without a value.
4077c478bd9Sstevel@tonic-gate  */
4087c478bd9Sstevel@tonic-gate static void
4097c478bd9Sstevel@tonic-gate parse_args(char **argv)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate 	struct arg_entry *ae;
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
4147c478bd9Sstevel@tonic-gate 	au_mask_t smask;
4157c478bd9Sstevel@tonic-gate 	au_mask_t umask;
4167c478bd9Sstevel@tonic-gate 	uint_t type;
4177c478bd9Sstevel@tonic-gate 	uint_t addr[4];
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	for (++argv; *argv; argv++) {
4207c478bd9Sstevel@tonic-gate 		if ((ae = get_arg_ent(*argv)) == (struct arg_entry *)0) {
4217c478bd9Sstevel@tonic-gate 			exit_usage(1);
4227c478bd9Sstevel@tonic-gate 		}
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 		switch (ae->auditconfig_cmd) {
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 		case AC_ARG_AUDIT:
4277c478bd9Sstevel@tonic-gate 			++argv;
4287c478bd9Sstevel@tonic-gate 			if (!*argv)
4297c478bd9Sstevel@tonic-gate 				exit_usage(1);
4307c478bd9Sstevel@tonic-gate 			if (strisnum(*argv)) {
4317c478bd9Sstevel@tonic-gate 				chk_event_num(AC_USER_EVENT,
4327c478bd9Sstevel@tonic-gate 					(au_event_t)atol(*argv));
4337c478bd9Sstevel@tonic-gate 			} else
4347c478bd9Sstevel@tonic-gate 				chk_event_str(AC_USER_EVENT, *argv);
4357c478bd9Sstevel@tonic-gate 			++argv;
4367c478bd9Sstevel@tonic-gate 			if (!*argv)
4377c478bd9Sstevel@tonic-gate 				exit_usage(1);
4387c478bd9Sstevel@tonic-gate 			chk_sorf(*argv);
4397c478bd9Sstevel@tonic-gate 			++argv;
4407c478bd9Sstevel@tonic-gate 			if (!*argv)
4417c478bd9Sstevel@tonic-gate 				exit_usage(1);
4427c478bd9Sstevel@tonic-gate 			chk_retval(*argv);
4437c478bd9Sstevel@tonic-gate 			++argv;
4447c478bd9Sstevel@tonic-gate 			if (!*argv)
4457c478bd9Sstevel@tonic-gate 				exit_usage(1);
4467c478bd9Sstevel@tonic-gate 			break;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 		case AC_ARG_CHKCONF:
4497c478bd9Sstevel@tonic-gate 			break;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 		case AC_ARG_CONF:
4527c478bd9Sstevel@tonic-gate 			break;
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 		case AC_ARG_ACONF:
4557c478bd9Sstevel@tonic-gate 			break;
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 		case AC_ARG_CHKACONF:
4587c478bd9Sstevel@tonic-gate 			break;
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 		case AC_ARG_GETASID:
4617c478bd9Sstevel@tonic-gate 		case AC_ARG_GETSID:
4627c478bd9Sstevel@tonic-gate 			break;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 		case AC_ARG_GETAUID:
4657c478bd9Sstevel@tonic-gate 			break;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 		case AC_ARG_GETAUDIT:
4687c478bd9Sstevel@tonic-gate 			break;
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKAUDIT:
4717c478bd9Sstevel@tonic-gate 			break;
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCLASS:
4747c478bd9Sstevel@tonic-gate 		case AC_ARG_GETESTATE:
4757c478bd9Sstevel@tonic-gate 			++argv;
4767c478bd9Sstevel@tonic-gate 			if (!*argv)
4777c478bd9Sstevel@tonic-gate 				exit_usage(1);
4787c478bd9Sstevel@tonic-gate 			if (strisnum(*argv))
4797c478bd9Sstevel@tonic-gate 				chk_event_num(AC_KERN_EVENT,
4807c478bd9Sstevel@tonic-gate 					(au_event_t)atol(*argv));
4817c478bd9Sstevel@tonic-gate 			else
4827c478bd9Sstevel@tonic-gate 				chk_event_str(AC_KERN_EVENT, *argv);
4837c478bd9Sstevel@tonic-gate 			break;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCAR:
4867c478bd9Sstevel@tonic-gate 			break;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCOND:
4897c478bd9Sstevel@tonic-gate 			break;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCWD:
4927c478bd9Sstevel@tonic-gate 			break;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKERNSTATE:
4957c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKMASK:
4967c478bd9Sstevel@tonic-gate 			break;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 		case AC_ARG_GETPOLICY:
4997c478bd9Sstevel@tonic-gate 			break;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQBUFSZ:
5027c478bd9Sstevel@tonic-gate 			break;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQCTRL:
5057c478bd9Sstevel@tonic-gate 			break;
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQDELAY:
5087c478bd9Sstevel@tonic-gate 			break;
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQHIWATER:
5117c478bd9Sstevel@tonic-gate 			break;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQLOWATER:
5147c478bd9Sstevel@tonic-gate 			break;
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 		case AC_ARG_GETSTAT:
5177c478bd9Sstevel@tonic-gate 			break;
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 		case AC_ARG_GETTERMID:
5207c478bd9Sstevel@tonic-gate 			break;
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 		case AC_ARG_GETUSERAUDIT:
5237c478bd9Sstevel@tonic-gate 			++argv;
5247c478bd9Sstevel@tonic-gate 			if (!*argv)
5257c478bd9Sstevel@tonic-gate 				exit_usage(1);
5267c478bd9Sstevel@tonic-gate 			break;
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 		case AC_ARG_LSEVENT:
5297c478bd9Sstevel@tonic-gate 			break;
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 		case AC_ARG_LSPOLICY:
5327c478bd9Sstevel@tonic-gate 			break;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 		case AC_ARG_SETASID:
5357c478bd9Sstevel@tonic-gate 			++argv;
5367c478bd9Sstevel@tonic-gate 			if (!*argv)
5377c478bd9Sstevel@tonic-gate 				exit_usage(1);
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 			while (*argv)
5407c478bd9Sstevel@tonic-gate 				++argv;
5417c478bd9Sstevel@tonic-gate 			--argv;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 			break;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 		case AC_ARG_SETAUID:
5467c478bd9Sstevel@tonic-gate 			++argv;
5477c478bd9Sstevel@tonic-gate 			if (!*argv)
5487c478bd9Sstevel@tonic-gate 				exit_usage(1);
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 			while (*argv)
5517c478bd9Sstevel@tonic-gate 				++argv;
5527c478bd9Sstevel@tonic-gate 			--argv;
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 			break;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 		case AC_ARG_SETAUDIT:
5577c478bd9Sstevel@tonic-gate 			++argv;
5587c478bd9Sstevel@tonic-gate 			if (!*argv)
5597c478bd9Sstevel@tonic-gate 				exit_usage(1);
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 			while (*argv)
5627c478bd9Sstevel@tonic-gate 				++argv;
5637c478bd9Sstevel@tonic-gate 			--argv;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 			break;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKAUDIT:
5687c478bd9Sstevel@tonic-gate 			++argv;
5697c478bd9Sstevel@tonic-gate 			if (!*argv)
5707c478bd9Sstevel@tonic-gate 				exit_usage(1);
5717c478bd9Sstevel@tonic-gate 			if (str2type (*argv, &type))
5727c478bd9Sstevel@tonic-gate 				exit_error(gettext(
5737c478bd9Sstevel@tonic-gate 					"Invalid IP address type specified."));
5747c478bd9Sstevel@tonic-gate 			++argv;
5757c478bd9Sstevel@tonic-gate 			if (!*argv)
5767c478bd9Sstevel@tonic-gate 				exit_usage(1);
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 			if (str2ipaddr(*argv, addr, type))
5797c478bd9Sstevel@tonic-gate 				exit_error(gettext(
5807c478bd9Sstevel@tonic-gate 					"Invalid IP address specified."));
5817c478bd9Sstevel@tonic-gate 			break;
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 		case AC_ARG_SETCLASS:
5847c478bd9Sstevel@tonic-gate 		case AC_ARG_SETESTATE:
5857c478bd9Sstevel@tonic-gate 			++argv;
5867c478bd9Sstevel@tonic-gate 			if (!*argv)
5877c478bd9Sstevel@tonic-gate 				exit_usage(1);
5887c478bd9Sstevel@tonic-gate 			if (strisnum(*argv))
5897c478bd9Sstevel@tonic-gate 				chk_event_num(AC_KERN_EVENT,
5907c478bd9Sstevel@tonic-gate 					(au_event_t)atol(*argv));
5917c478bd9Sstevel@tonic-gate 			else
5927c478bd9Sstevel@tonic-gate 				chk_event_str(AC_KERN_EVENT, *argv);
5937c478bd9Sstevel@tonic-gate 			++argv;
5947c478bd9Sstevel@tonic-gate 			if (!*argv)
5957c478bd9Sstevel@tonic-gate 				exit_usage(1);
5967c478bd9Sstevel@tonic-gate 			str2mask(*argv, &pmask);
5977c478bd9Sstevel@tonic-gate 			break;
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKERNSTATE:
6007c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKMASK:
6017c478bd9Sstevel@tonic-gate 			++argv;
6027c478bd9Sstevel@tonic-gate 			if (!*argv)
6037c478bd9Sstevel@tonic-gate 				exit_usage(1);
6047c478bd9Sstevel@tonic-gate 			str2mask(*argv, &pmask);
6057c478bd9Sstevel@tonic-gate 			break;
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 		case AC_ARG_SETPOLICY:
6087c478bd9Sstevel@tonic-gate 			++argv;
6097c478bd9Sstevel@tonic-gate 			if (!*argv)
6107c478bd9Sstevel@tonic-gate 				exit_usage(1);
6117c478bd9Sstevel@tonic-gate 			break;
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 		case AC_ARG_SETSTAT:
6147c478bd9Sstevel@tonic-gate 			break;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 		case AC_ARG_GETPINFO:
6177c478bd9Sstevel@tonic-gate 			++argv;
6187c478bd9Sstevel@tonic-gate 			if (!*argv)
6197c478bd9Sstevel@tonic-gate 				exit_usage(1);
6207c478bd9Sstevel@tonic-gate 			break;
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 		case AC_ARG_SETPMASK:
6237c478bd9Sstevel@tonic-gate 			++argv;
6247c478bd9Sstevel@tonic-gate 			if (!*argv)
6257c478bd9Sstevel@tonic-gate 				exit_usage(1);
6267c478bd9Sstevel@tonic-gate 			++argv;
6277c478bd9Sstevel@tonic-gate 			if (!*argv)
6287c478bd9Sstevel@tonic-gate 				exit_usage(1);
6297c478bd9Sstevel@tonic-gate 			str2mask(*argv, &pmask);
6307c478bd9Sstevel@tonic-gate 			break;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQBUFSZ:
6337c478bd9Sstevel@tonic-gate 			++argv;
6347c478bd9Sstevel@tonic-gate 			if (!*argv)
6357c478bd9Sstevel@tonic-gate 				exit_usage(1);
6367c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6377c478bd9Sstevel@tonic-gate 				exit_error(gettext("Invalid bufsz specified."));
6387c478bd9Sstevel@tonic-gate 			break;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQCTRL:
6417c478bd9Sstevel@tonic-gate 			++argv;
6427c478bd9Sstevel@tonic-gate 			if (!*argv)
6437c478bd9Sstevel@tonic-gate 				exit_usage(1);
6447c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6457c478bd9Sstevel@tonic-gate 				exit_error(gettext(
6467c478bd9Sstevel@tonic-gate 					"Invalid hiwater specified."));
6477c478bd9Sstevel@tonic-gate 			++argv;
6487c478bd9Sstevel@tonic-gate 			if (!*argv)
6497c478bd9Sstevel@tonic-gate 				exit_usage(1);
6507c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6517c478bd9Sstevel@tonic-gate 				exit_error(gettext(
6527c478bd9Sstevel@tonic-gate 					gettext("Invalid lowater specified.")));
6537c478bd9Sstevel@tonic-gate 			++argv;
6547c478bd9Sstevel@tonic-gate 			if (!*argv)
6557c478bd9Sstevel@tonic-gate 				exit_usage(1);
6567c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6577c478bd9Sstevel@tonic-gate 				exit_error(gettext("Invalid bufsz specified."));
6587c478bd9Sstevel@tonic-gate 			++argv;
6597c478bd9Sstevel@tonic-gate 			if (!*argv)
6607c478bd9Sstevel@tonic-gate 				exit_usage(1);
6617c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6627c478bd9Sstevel@tonic-gate 				exit_error(gettext("Invalid delay specified."));
6637c478bd9Sstevel@tonic-gate 			break;
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQDELAY:
6667c478bd9Sstevel@tonic-gate 			++argv;
6677c478bd9Sstevel@tonic-gate 			if (!*argv)
6687c478bd9Sstevel@tonic-gate 				exit_usage(1);
6697c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6707c478bd9Sstevel@tonic-gate 				exit_error(gettext("Invalid delay specified."));
6717c478bd9Sstevel@tonic-gate 			break;
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQHIWATER:
6747c478bd9Sstevel@tonic-gate 			++argv;
6757c478bd9Sstevel@tonic-gate 			if (!*argv)
6767c478bd9Sstevel@tonic-gate 				exit_usage(1);
6777c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6787c478bd9Sstevel@tonic-gate 				exit_error(gettext(
6797c478bd9Sstevel@tonic-gate 					"Invalid hiwater specified."));
6807c478bd9Sstevel@tonic-gate 			break;
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQLOWATER:
6837c478bd9Sstevel@tonic-gate 			++argv;
6847c478bd9Sstevel@tonic-gate 			if (!*argv)
6857c478bd9Sstevel@tonic-gate 				exit_usage(1);
6867c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
6877c478bd9Sstevel@tonic-gate 				exit_error(gettext(
6887c478bd9Sstevel@tonic-gate 					"Invalid lowater specified."));
6897c478bd9Sstevel@tonic-gate 			break;
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 		case AC_ARG_SETTERMID:
6927c478bd9Sstevel@tonic-gate 			++argv;
6937c478bd9Sstevel@tonic-gate 			if (!*argv)
6947c478bd9Sstevel@tonic-gate 				exit_usage(1);
6957c478bd9Sstevel@tonic-gate 			chk_tid(*argv);
6967c478bd9Sstevel@tonic-gate 			break;
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 		case AC_ARG_SETUSERAUDIT:
6997c478bd9Sstevel@tonic-gate 			++argv;
7007c478bd9Sstevel@tonic-gate 			if (!*argv)
7017c478bd9Sstevel@tonic-gate 				exit_usage(1);
7027c478bd9Sstevel@tonic-gate 			++argv;
7037c478bd9Sstevel@tonic-gate 			if (!*argv)
7047c478bd9Sstevel@tonic-gate 				exit_usage(1);
7057c478bd9Sstevel@tonic-gate 			break;
7067c478bd9Sstevel@tonic-gate 		case AC_ARG_SETSMASK:
7077c478bd9Sstevel@tonic-gate 			++argv;
7087c478bd9Sstevel@tonic-gate 			if (!*argv)
7097c478bd9Sstevel@tonic-gate 				exit_usage(1);
7107c478bd9Sstevel@tonic-gate 			++argv;
7117c478bd9Sstevel@tonic-gate 			if (!*argv)
7127c478bd9Sstevel@tonic-gate 				exit_usage(1);
7137c478bd9Sstevel@tonic-gate 			str2mask(*argv, &smask);
7147c478bd9Sstevel@tonic-gate 			break;
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 		case AC_ARG_SETUMASK:
7177c478bd9Sstevel@tonic-gate 			++argv;
7187c478bd9Sstevel@tonic-gate 			if (!*argv)
7197c478bd9Sstevel@tonic-gate 				exit_usage(1);
7207c478bd9Sstevel@tonic-gate 			++argv;
7217c478bd9Sstevel@tonic-gate 			if (!*argv)
7227c478bd9Sstevel@tonic-gate 				exit_usage(1);
7237c478bd9Sstevel@tonic-gate 			str2mask(*argv, &umask);
7247c478bd9Sstevel@tonic-gate 			break;
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 		case AC_ARG_GETFSIZE:
7277c478bd9Sstevel@tonic-gate 			break;
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 		case AC_ARG_SETFSIZE:
7307c478bd9Sstevel@tonic-gate 			++argv;
7317c478bd9Sstevel@tonic-gate 			if (!*argv)
7327c478bd9Sstevel@tonic-gate 				exit_usage(1);
7337c478bd9Sstevel@tonic-gate 			if (!strisnum(*argv))
7347c478bd9Sstevel@tonic-gate 				exit_error(gettext(
7357c478bd9Sstevel@tonic-gate 					"Invalid hiwater specified."));
7367c478bd9Sstevel@tonic-gate 			break;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 		default:
7397c478bd9Sstevel@tonic-gate 			exit_error(gettext("Internal error #1."));
7407c478bd9Sstevel@tonic-gate 			break;
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 		}
7447c478bd9Sstevel@tonic-gate 	}
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate /*
7497c478bd9Sstevel@tonic-gate  * do_args()
7507c478bd9Sstevel@tonic-gate  *     Desc: Do command line arguments in the order in which they appear.
7517c478bd9Sstevel@tonic-gate  */
7527c478bd9Sstevel@tonic-gate static void
7537c478bd9Sstevel@tonic-gate do_args(argv)
7547c478bd9Sstevel@tonic-gate 	char **argv;
7557c478bd9Sstevel@tonic-gate {
7567c478bd9Sstevel@tonic-gate 	struct arg_entry *ae;
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 	for (++argv; *argv; argv++) {
7597c478bd9Sstevel@tonic-gate 		ae = get_arg_ent(*argv);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 		switch (ae->auditconfig_cmd) {
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 		case AC_ARG_AUDIT:
7647c478bd9Sstevel@tonic-gate 			{
7657c478bd9Sstevel@tonic-gate 				char sorf;
7667c478bd9Sstevel@tonic-gate 				int  retval;
7677c478bd9Sstevel@tonic-gate 				char *event_name;
7687c478bd9Sstevel@tonic-gate 				char *audit_str;
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 				++argv;
7717c478bd9Sstevel@tonic-gate 				event_name = *argv;
7727c478bd9Sstevel@tonic-gate 				++argv;
7737c478bd9Sstevel@tonic-gate 				sorf = (char)atoi(*argv);
7747c478bd9Sstevel@tonic-gate 				++argv;
7757c478bd9Sstevel@tonic-gate 				retval = atoi(*argv);
7767c478bd9Sstevel@tonic-gate 				++argv;
7777c478bd9Sstevel@tonic-gate 				audit_str = *argv;
7787c478bd9Sstevel@tonic-gate 				do_audit(event_name, sorf, retval, audit_str);
7797c478bd9Sstevel@tonic-gate 			}
7807c478bd9Sstevel@tonic-gate 			break;
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 		case AC_ARG_CHKCONF:
7837c478bd9Sstevel@tonic-gate 			do_chkconf();
7847c478bd9Sstevel@tonic-gate 			break;
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 		case AC_ARG_CONF:
7877c478bd9Sstevel@tonic-gate 			do_conf();
7887c478bd9Sstevel@tonic-gate 			break;
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 		case AC_ARG_CHKACONF:
7917c478bd9Sstevel@tonic-gate 			do_chkaconf();
7927c478bd9Sstevel@tonic-gate 			break;
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 		case AC_ARG_ACONF:
7957c478bd9Sstevel@tonic-gate 			do_aconf();
7967c478bd9Sstevel@tonic-gate 			break;
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 		case AC_ARG_GETASID:
7997c478bd9Sstevel@tonic-gate 		case AC_ARG_GETSID:
8007c478bd9Sstevel@tonic-gate 			do_getasid();
8017c478bd9Sstevel@tonic-gate 			break;
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 		case AC_ARG_GETAUID:
8047c478bd9Sstevel@tonic-gate 			do_getauid();
8057c478bd9Sstevel@tonic-gate 			break;
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 		case AC_ARG_GETAUDIT:
8087c478bd9Sstevel@tonic-gate 			do_getaudit();
8097c478bd9Sstevel@tonic-gate 			break;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKAUDIT:
8127c478bd9Sstevel@tonic-gate 			do_getkaudit();
8137c478bd9Sstevel@tonic-gate 			break;
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCLASS:
8167c478bd9Sstevel@tonic-gate 		case AC_ARG_GETESTATE:
8177c478bd9Sstevel@tonic-gate 			++argv;
8187c478bd9Sstevel@tonic-gate 			do_getclass(*argv);
8197c478bd9Sstevel@tonic-gate 			break;
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCAR:
8227c478bd9Sstevel@tonic-gate 			do_getcar();
8237c478bd9Sstevel@tonic-gate 			break;
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCOND:
8267c478bd9Sstevel@tonic-gate 			do_getcond();
8277c478bd9Sstevel@tonic-gate 			break;
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 		case AC_ARG_GETCWD:
8307c478bd9Sstevel@tonic-gate 			do_getcwd();
8317c478bd9Sstevel@tonic-gate 			break;
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKERNSTATE:
8347c478bd9Sstevel@tonic-gate 		case AC_ARG_GETKMASK:
8357c478bd9Sstevel@tonic-gate 			do_getkmask();
8367c478bd9Sstevel@tonic-gate 			break;
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 		case AC_ARG_GETPOLICY:
8397c478bd9Sstevel@tonic-gate 			do_getpolicy();
8407c478bd9Sstevel@tonic-gate 			break;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQBUFSZ:
8437c478bd9Sstevel@tonic-gate 			do_getqbufsz();
8447c478bd9Sstevel@tonic-gate 			break;
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQCTRL:
8477c478bd9Sstevel@tonic-gate 			do_getqctrl();
8487c478bd9Sstevel@tonic-gate 			break;
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQDELAY:
8517c478bd9Sstevel@tonic-gate 			do_getqdelay();
8527c478bd9Sstevel@tonic-gate 			break;
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQHIWATER:
8557c478bd9Sstevel@tonic-gate 			do_getqhiwater();
8567c478bd9Sstevel@tonic-gate 			break;
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 		case AC_ARG_GETQLOWATER:
8597c478bd9Sstevel@tonic-gate 			do_getqlowater();
8607c478bd9Sstevel@tonic-gate 			break;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 		case AC_ARG_GETSTAT:
8637c478bd9Sstevel@tonic-gate 			do_getstat();
8647c478bd9Sstevel@tonic-gate 			break;
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 		case AC_ARG_GETTERMID:
8677c478bd9Sstevel@tonic-gate 			do_gettermid();
8687c478bd9Sstevel@tonic-gate 			break;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 		case AC_ARG_GETUSERAUDIT:
8717c478bd9Sstevel@tonic-gate 			++argv;
8727c478bd9Sstevel@tonic-gate 			do_getuseraudit(*argv);
8737c478bd9Sstevel@tonic-gate 			break;
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 		case AC_ARG_LSEVENT:
8767c478bd9Sstevel@tonic-gate 			do_lsevent();
8777c478bd9Sstevel@tonic-gate 			break;
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 		case AC_ARG_LSPOLICY:
8807c478bd9Sstevel@tonic-gate 			do_lspolicy();
8817c478bd9Sstevel@tonic-gate 			break;
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 		case AC_ARG_SETASID:
8847c478bd9Sstevel@tonic-gate 			{
8857c478bd9Sstevel@tonic-gate 				char *sid_str;
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 				++argv;
8887c478bd9Sstevel@tonic-gate 				sid_str = *argv;
8897c478bd9Sstevel@tonic-gate 				++argv;
8907c478bd9Sstevel@tonic-gate 				do_setasid(sid_str, argv);
8917c478bd9Sstevel@tonic-gate 			}
8927c478bd9Sstevel@tonic-gate 			break;
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 		case AC_ARG_SETAUID:
8957c478bd9Sstevel@tonic-gate 			{
8967c478bd9Sstevel@tonic-gate 				char *user;
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 				++argv;
8997c478bd9Sstevel@tonic-gate 				user = *argv;
9007c478bd9Sstevel@tonic-gate 				++argv;
9017c478bd9Sstevel@tonic-gate 				do_setauid(user, argv);
9027c478bd9Sstevel@tonic-gate 			}
9037c478bd9Sstevel@tonic-gate 			break;
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 		case AC_ARG_SETAUDIT:
9067c478bd9Sstevel@tonic-gate 			{
9077c478bd9Sstevel@tonic-gate 				char *user_str;
9087c478bd9Sstevel@tonic-gate 				char *mask_str;
9097c478bd9Sstevel@tonic-gate 				char *tid_str;
9107c478bd9Sstevel@tonic-gate 				char *sid_str;
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 				++argv;
9137c478bd9Sstevel@tonic-gate 				user_str = *argv;
9147c478bd9Sstevel@tonic-gate 				++argv;
9157c478bd9Sstevel@tonic-gate 				mask_str = *argv;
9167c478bd9Sstevel@tonic-gate 				++argv;
9177c478bd9Sstevel@tonic-gate 				tid_str = *argv;
9187c478bd9Sstevel@tonic-gate 				++argv;
9197c478bd9Sstevel@tonic-gate 				sid_str = *argv;
9207c478bd9Sstevel@tonic-gate 				++argv;
9217c478bd9Sstevel@tonic-gate 				do_setaudit(user_str, mask_str,
9227c478bd9Sstevel@tonic-gate 				    tid_str, sid_str, argv);
9237c478bd9Sstevel@tonic-gate 			}
9247c478bd9Sstevel@tonic-gate 			break;
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKAUDIT:
9277c478bd9Sstevel@tonic-gate 			{
9287c478bd9Sstevel@tonic-gate 				char *address_type, *address;
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate 				++argv; address_type = *argv;
9317c478bd9Sstevel@tonic-gate 				++argv; address = *argv;
9327c478bd9Sstevel@tonic-gate 				do_setkaudit(address_type, address);
9337c478bd9Sstevel@tonic-gate 			}
9347c478bd9Sstevel@tonic-gate 			break;
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 		case AC_ARG_SETCLASS:
9377c478bd9Sstevel@tonic-gate 		case AC_ARG_SETESTATE:
9387c478bd9Sstevel@tonic-gate 			{
9397c478bd9Sstevel@tonic-gate 				char *event_str, *audit_flags;
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate 				++argv; event_str = *argv;
9427c478bd9Sstevel@tonic-gate 				++argv; audit_flags = *argv;
9437c478bd9Sstevel@tonic-gate 				do_setclass(event_str, audit_flags);
9447c478bd9Sstevel@tonic-gate 			}
9457c478bd9Sstevel@tonic-gate 			break;
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKERNSTATE:
9487c478bd9Sstevel@tonic-gate 		case AC_ARG_SETKMASK:
9497c478bd9Sstevel@tonic-gate 			++argv;
9507c478bd9Sstevel@tonic-gate 			do_setkmask(*argv);
9517c478bd9Sstevel@tonic-gate 			break;
9527c478bd9Sstevel@tonic-gate 
9537c478bd9Sstevel@tonic-gate 		case AC_ARG_SETPOLICY:
9547c478bd9Sstevel@tonic-gate 			++argv;
9557c478bd9Sstevel@tonic-gate 			do_setpolicy(*argv);
9567c478bd9Sstevel@tonic-gate 			break;
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 		case AC_ARG_GETPINFO:
9597c478bd9Sstevel@tonic-gate 			{
9607c478bd9Sstevel@tonic-gate 				char *pid_str;
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 				++argv;
9637c478bd9Sstevel@tonic-gate 				pid_str = *argv;
9647c478bd9Sstevel@tonic-gate 				do_getpinfo(pid_str);
9657c478bd9Sstevel@tonic-gate 			}
9667c478bd9Sstevel@tonic-gate 			break;
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 		case AC_ARG_SETPMASK:
9697c478bd9Sstevel@tonic-gate 			{
9707c478bd9Sstevel@tonic-gate 				char *pid_str;
9717c478bd9Sstevel@tonic-gate 				char *audit_flags;
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 				++argv;
9747c478bd9Sstevel@tonic-gate 				pid_str = *argv;
9757c478bd9Sstevel@tonic-gate 				++argv;
9767c478bd9Sstevel@tonic-gate 				audit_flags = *argv;
9777c478bd9Sstevel@tonic-gate 				do_setpmask(pid_str, audit_flags);
9787c478bd9Sstevel@tonic-gate 			}
9797c478bd9Sstevel@tonic-gate 			break;
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 		case AC_ARG_SETSTAT:
9827c478bd9Sstevel@tonic-gate 			do_setstat();
9837c478bd9Sstevel@tonic-gate 			break;
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQBUFSZ:
9867c478bd9Sstevel@tonic-gate 			++argv;
9877c478bd9Sstevel@tonic-gate 			do_setqbufsz(*argv);
9887c478bd9Sstevel@tonic-gate 			break;
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQCTRL:
9917c478bd9Sstevel@tonic-gate 			{
9927c478bd9Sstevel@tonic-gate 				char *hiwater, *lowater, *bufsz, *delay;
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 				++argv; hiwater = *argv;
9957c478bd9Sstevel@tonic-gate 				++argv; lowater = *argv;
9967c478bd9Sstevel@tonic-gate 				++argv; bufsz = *argv;
9977c478bd9Sstevel@tonic-gate 				++argv; delay = *argv;
9987c478bd9Sstevel@tonic-gate 				do_setqctrl(hiwater, lowater, bufsz, delay);
9997c478bd9Sstevel@tonic-gate 			}
10007c478bd9Sstevel@tonic-gate 			break;
10017c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQDELAY:
10027c478bd9Sstevel@tonic-gate 			++argv;
10037c478bd9Sstevel@tonic-gate 			do_setqdelay(*argv);
10047c478bd9Sstevel@tonic-gate 			break;
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQHIWATER:
10077c478bd9Sstevel@tonic-gate 			++argv;
10087c478bd9Sstevel@tonic-gate 			do_setqhiwater(*argv);
10097c478bd9Sstevel@tonic-gate 			break;
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 		case AC_ARG_SETQLOWATER:
10127c478bd9Sstevel@tonic-gate 			++argv;
10137c478bd9Sstevel@tonic-gate 			do_setqlowater(*argv);
10147c478bd9Sstevel@tonic-gate 			break;
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 		case AC_ARG_SETTERMID:
10177c478bd9Sstevel@tonic-gate 			++argv;
10187c478bd9Sstevel@tonic-gate 			do_settid(*argv);
10197c478bd9Sstevel@tonic-gate 			break;
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate 		case AC_ARG_SETUSERAUDIT:
10227c478bd9Sstevel@tonic-gate 			{
10237c478bd9Sstevel@tonic-gate 				char *user;
10247c478bd9Sstevel@tonic-gate 				char *aflags;
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 				++argv;
10277c478bd9Sstevel@tonic-gate 				user = *argv;
10287c478bd9Sstevel@tonic-gate 				++argv;
10297c478bd9Sstevel@tonic-gate 				aflags = *argv;
10307c478bd9Sstevel@tonic-gate 				do_setuseraudit(user, aflags);
10317c478bd9Sstevel@tonic-gate 			}
10327c478bd9Sstevel@tonic-gate 			break;
10337c478bd9Sstevel@tonic-gate 		case AC_ARG_SETSMASK:
10347c478bd9Sstevel@tonic-gate 			{
10357c478bd9Sstevel@tonic-gate 				char *asid_str;
10367c478bd9Sstevel@tonic-gate 				char *audit_flags;
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 				++argv;
10397c478bd9Sstevel@tonic-gate 				asid_str = *argv;
10407c478bd9Sstevel@tonic-gate 				++argv;
10417c478bd9Sstevel@tonic-gate 				audit_flags = *argv;
10427c478bd9Sstevel@tonic-gate 				do_setsmask(asid_str, audit_flags);
10437c478bd9Sstevel@tonic-gate 			}
10447c478bd9Sstevel@tonic-gate 			break;
10457c478bd9Sstevel@tonic-gate 		case AC_ARG_SETUMASK:
10467c478bd9Sstevel@tonic-gate 			{
10477c478bd9Sstevel@tonic-gate 				char *auid_str;
10487c478bd9Sstevel@tonic-gate 				char *audit_flags;
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 				++argv;
10517c478bd9Sstevel@tonic-gate 				auid_str = *argv;
10527c478bd9Sstevel@tonic-gate 				++argv;
10537c478bd9Sstevel@tonic-gate 				audit_flags = *argv;
10547c478bd9Sstevel@tonic-gate 				do_setumask(auid_str, audit_flags);
10557c478bd9Sstevel@tonic-gate 			}
10567c478bd9Sstevel@tonic-gate 			break;
10577c478bd9Sstevel@tonic-gate 		case AC_ARG_GETFSIZE:
10587c478bd9Sstevel@tonic-gate 			do_getfsize();
10597c478bd9Sstevel@tonic-gate 			break;
10607c478bd9Sstevel@tonic-gate 		case AC_ARG_SETFSIZE:
10617c478bd9Sstevel@tonic-gate 			++argv;
10627c478bd9Sstevel@tonic-gate 			do_setfsize(*argv);
10637c478bd9Sstevel@tonic-gate 			break;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 		default:
10667c478bd9Sstevel@tonic-gate 			exit_error(gettext("Internal error #2."));
10677c478bd9Sstevel@tonic-gate 			break;
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 		}
10707c478bd9Sstevel@tonic-gate 	}
10717c478bd9Sstevel@tonic-gate 
10727c478bd9Sstevel@tonic-gate }
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate /*
10757c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
10767c478bd9Sstevel@tonic-gate  * set.
10777c478bd9Sstevel@tonic-gate  */
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate static void
10807c478bd9Sstevel@tonic-gate do_chkconf()
10817c478bd9Sstevel@tonic-gate {
10827c478bd9Sstevel@tonic-gate 	register au_event_ent_t *evp;
10837c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
10847c478bd9Sstevel@tonic-gate 	char conf_aflags[256];
10857c478bd9Sstevel@tonic-gate 	char run_aflags[256];
10867c478bd9Sstevel@tonic-gate 	au_stat_t as;
10877c478bd9Sstevel@tonic-gate 	int class;
10887c478bd9Sstevel@tonic-gate 	int			len;
10897c478bd9Sstevel@tonic-gate 	struct au_evclass_map	cmap;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	pmask.am_success = pmask.am_failure = 0;
10927c478bd9Sstevel@tonic-gate 	eauditon(A_GETSTAT, (caddr_t)&as, 0);
10937c478bd9Sstevel@tonic-gate 
10947c478bd9Sstevel@tonic-gate 	setauevent();
10957c478bd9Sstevel@tonic-gate 	if ((evp = getauevent()) == (au_event_ent_t *)NULL) {
10967c478bd9Sstevel@tonic-gate 		(void) exit_error(gettext(
10977c478bd9Sstevel@tonic-gate 			"NO AUDIT EVENTS: Could not read %s\n."),
10987c478bd9Sstevel@tonic-gate 			AUDITEVENTFILE);
10997c478bd9Sstevel@tonic-gate 	}
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate 	setauevent();
11027c478bd9Sstevel@tonic-gate 	while ((evp = getauevent()) != (au_event_ent_t *)NULL) {
11037c478bd9Sstevel@tonic-gate 		cmap.ec_number = evp->ae_number;
11047c478bd9Sstevel@tonic-gate 		len = sizeof (struct au_evclass_map);
11057c478bd9Sstevel@tonic-gate 		if (evp->ae_number <= as.as_numevent)
11067c478bd9Sstevel@tonic-gate 			if (auditon(A_GETCLASS, (caddr_t)&cmap, len) == -1) {
11077c478bd9Sstevel@tonic-gate 				(void) printf("%s(%d):%s",
11087c478bd9Sstevel@tonic-gate 				evp->ae_name, evp->ae_number, gettext(
11097c478bd9Sstevel@tonic-gate "UNKNOWN EVENT: Could not get class for event. Configuration may be bad.\n"));
11107c478bd9Sstevel@tonic-gate 			} else {
11117c478bd9Sstevel@tonic-gate 				class = cmap.ec_class;
11127c478bd9Sstevel@tonic-gate 				if (class != evp->ae_class) {
11137c478bd9Sstevel@tonic-gate 					conf_aflags[0] = run_aflags[0] = '\0';
11147c478bd9Sstevel@tonic-gate 					pmask.am_success = class;
11157c478bd9Sstevel@tonic-gate 					pmask.am_failure = class;
11167c478bd9Sstevel@tonic-gate 					(void) getauditflagschar(run_aflags,
11177c478bd9Sstevel@tonic-gate 						&pmask, 0);
11187c478bd9Sstevel@tonic-gate 					pmask.am_success = evp->ae_class;
11197c478bd9Sstevel@tonic-gate 					pmask.am_failure = evp->ae_class;
11207c478bd9Sstevel@tonic-gate 					(void) getauditflagschar(conf_aflags,
11217c478bd9Sstevel@tonic-gate 						&pmask, 0);
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 					(void) printf(gettext(
11247c478bd9Sstevel@tonic-gate "%s(%d): CLASS MISMATCH: runtime class (%s) != configured class (%s)\n"),
11257c478bd9Sstevel@tonic-gate 					evp->ae_name, evp->ae_number,
11267c478bd9Sstevel@tonic-gate 					NONE(run_aflags), NONE(conf_aflags));
11277c478bd9Sstevel@tonic-gate 				}
11287c478bd9Sstevel@tonic-gate 			}
11297c478bd9Sstevel@tonic-gate 	}
11307c478bd9Sstevel@tonic-gate 	endauevent();
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate }
11337c478bd9Sstevel@tonic-gate 
11347c478bd9Sstevel@tonic-gate /*
11357c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
11367c478bd9Sstevel@tonic-gate  * set.
11377c478bd9Sstevel@tonic-gate  */
11387c478bd9Sstevel@tonic-gate static void
11397c478bd9Sstevel@tonic-gate do_conf()
11407c478bd9Sstevel@tonic-gate {
11417c478bd9Sstevel@tonic-gate 	register au_event_ent_t *evp;
11427c478bd9Sstevel@tonic-gate 	register int i;
11437c478bd9Sstevel@tonic-gate 	au_evclass_map_t ec;
11447c478bd9Sstevel@tonic-gate 	au_stat_t as;
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate 	eauditon(A_GETSTAT, (caddr_t)&as, 0);
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 	i = 0;
11497c478bd9Sstevel@tonic-gate 	setauevent();
11507c478bd9Sstevel@tonic-gate 	while ((evp = getauevent()) != (au_event_ent_t *)NULL) {
11517c478bd9Sstevel@tonic-gate 		if (evp->ae_number <= as.as_numevent) {
11527c478bd9Sstevel@tonic-gate 			++i;
11537c478bd9Sstevel@tonic-gate 			ec.ec_number = evp->ae_number;
11547c478bd9Sstevel@tonic-gate 			ec.ec_class = evp->ae_class;
11557c478bd9Sstevel@tonic-gate 			eauditon(A_SETCLASS, (caddr_t)&ec, (int)sizeof (ec));
11567c478bd9Sstevel@tonic-gate 		}
11577c478bd9Sstevel@tonic-gate 	}
11587c478bd9Sstevel@tonic-gate 	endauevent();
11597c478bd9Sstevel@tonic-gate 	(void) printf(gettext("Configured %d kernel events.\n"), i);
11607c478bd9Sstevel@tonic-gate 
11617c478bd9Sstevel@tonic-gate }
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate /*
11647c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
11657c478bd9Sstevel@tonic-gate  * set.
11667c478bd9Sstevel@tonic-gate  */
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate static void
11697c478bd9Sstevel@tonic-gate do_chkaconf()
11707c478bd9Sstevel@tonic-gate {
11717c478bd9Sstevel@tonic-gate 	char buf[1024];
11727c478bd9Sstevel@tonic-gate 	au_mask_t pmask, kmask;
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate 	if (getacna(buf, sizeof (buf)) < 0) {
11757c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
11767c478bd9Sstevel@tonic-gate 		    gettext("bad non-attributable flags in audit_control\n"));
11777c478bd9Sstevel@tonic-gate 		exit(1);
11787c478bd9Sstevel@tonic-gate 	}
11797c478bd9Sstevel@tonic-gate 
11807c478bd9Sstevel@tonic-gate 	if (getauditflagsbin(buf, &pmask) < 0) {
11817c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
11827c478bd9Sstevel@tonic-gate 		    gettext("bad audit flag value encountered\n"));
11837c478bd9Sstevel@tonic-gate 		exit(1);
11847c478bd9Sstevel@tonic-gate 	}
11857c478bd9Sstevel@tonic-gate 
11867c478bd9Sstevel@tonic-gate 	eauditon(A_GETKMASK, (caddr_t)&kmask, (int)sizeof (kmask));
11877c478bd9Sstevel@tonic-gate 
11887c478bd9Sstevel@tonic-gate 	if ((pmask.am_success != kmask.am_success) ||
11897c478bd9Sstevel@tonic-gate 	    (pmask.am_failure != kmask.am_failure)) {
11907c478bd9Sstevel@tonic-gate 		char kbuf[2048];
11917c478bd9Sstevel@tonic-gate 		if (getauditflagschar(kbuf, &kmask, 0) < 0) {
11927c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
11937c478bd9Sstevel@tonic-gate 			    gettext("bad kernel non-attributable mask\n"));
11947c478bd9Sstevel@tonic-gate 			exit(1);
11957c478bd9Sstevel@tonic-gate 		}
11967c478bd9Sstevel@tonic-gate 		(void) printf(gettext("non-attributable event mismatch "));
11977c478bd9Sstevel@tonic-gate 		(void) printf(gettext("audit_control(%s) kernel(%s)\n"),
11987c478bd9Sstevel@tonic-gate 			buf, kbuf);
11997c478bd9Sstevel@tonic-gate 	}
12007c478bd9Sstevel@tonic-gate }
12017c478bd9Sstevel@tonic-gate 
12027c478bd9Sstevel@tonic-gate /*
12037c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
12047c478bd9Sstevel@tonic-gate  * set.
12057c478bd9Sstevel@tonic-gate  */
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate static void
12087c478bd9Sstevel@tonic-gate do_aconf()
12097c478bd9Sstevel@tonic-gate {
12107c478bd9Sstevel@tonic-gate 	char buf[2048];
12117c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 	if (getacna(buf, sizeof (buf)) < 0) {
12147c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
12157c478bd9Sstevel@tonic-gate 		    gettext("bad non-attributable flags in audit_control\n"));
12167c478bd9Sstevel@tonic-gate 		exit(1);
12177c478bd9Sstevel@tonic-gate 	}
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 	if (getauditflagsbin(buf, &pmask) < 0) {
12207c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
12217c478bd9Sstevel@tonic-gate 		    gettext("bad audit flag value encountered\n"));
12227c478bd9Sstevel@tonic-gate 		exit(1);
12237c478bd9Sstevel@tonic-gate 	}
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	eauditon(A_SETKMASK, (caddr_t)&pmask, (int)sizeof (pmask));
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	(void) printf(gettext("Configured non-attributable events.\n"));
12287c478bd9Sstevel@tonic-gate }
12297c478bd9Sstevel@tonic-gate 
12307c478bd9Sstevel@tonic-gate static void
12317c478bd9Sstevel@tonic-gate do_audit(event, sorf, retval, audit_str)
12327c478bd9Sstevel@tonic-gate 	char *event;
12337c478bd9Sstevel@tonic-gate 	char sorf;
12347c478bd9Sstevel@tonic-gate 	int retval;
12357c478bd9Sstevel@tonic-gate 	char *audit_str;
12367c478bd9Sstevel@tonic-gate {
12377c478bd9Sstevel@tonic-gate 	int rtn;
12387c478bd9Sstevel@tonic-gate 	int rd;
12397c478bd9Sstevel@tonic-gate 	au_event_t event_num;
12407c478bd9Sstevel@tonic-gate 	au_event_ent_t *evp;
12417c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
12427c478bd9Sstevel@tonic-gate 	token_t *tokp;
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate 	egetaudit(&ai, sizeof (ai));
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 	if (strisnum(event)) {
12477c478bd9Sstevel@tonic-gate 		event_num = (au_event_t)atoi(event);
12487c478bd9Sstevel@tonic-gate 		evp = egetauevnum(event_num);
12497c478bd9Sstevel@tonic-gate 	} else
12507c478bd9Sstevel@tonic-gate 		evp = egetauevnam(event);
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	rtn = au_preselect(evp->ae_number, &ai.ai_mask, (int)sorf,
12537c478bd9Sstevel@tonic-gate 		AU_PRS_USECACHE);
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate 	if (rtn == -1)
12567c478bd9Sstevel@tonic-gate 		exit_error("%s\n%s %d\n",
12577c478bd9Sstevel@tonic-gate 			gettext("Check audit event configuration."),
12587c478bd9Sstevel@tonic-gate 			gettext("Could not get audit class for event number"),
12597c478bd9Sstevel@tonic-gate 			evp->ae_number);
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate 	/* record is preselected */
12627c478bd9Sstevel@tonic-gate 	if (rtn == 1) {
12637c478bd9Sstevel@tonic-gate 		if ((rd = au_open()) == -1)
12647c478bd9Sstevel@tonic-gate 			exit_error(gettext(
12657c478bd9Sstevel@tonic-gate 				"Could not get and audit record descriptor\n"));
12667c478bd9Sstevel@tonic-gate 		if ((tokp = au_to_me()) == (token_t *)NULL)
12677c478bd9Sstevel@tonic-gate 			exit_error(gettext(
12687c478bd9Sstevel@tonic-gate 				"Could not allocate subject token\n"));
12697c478bd9Sstevel@tonic-gate 		if (au_write(rd, tokp) == -1)
12707c478bd9Sstevel@tonic-gate exit_error(gettext("Could not construct subject token of audit record\n"));
1271*45916cd2Sjpk 
1272*45916cd2Sjpk 		if (tsol_on) {
1273*45916cd2Sjpk 			if ((tokp = au_to_mylabel()) == (token_t *)NULL)
1274*45916cd2Sjpk 				exit_error(gettext(
1275*45916cd2Sjpk 				    "Could not allocate slabel token\n"));
1276*45916cd2Sjpk 			if (au_write(rd, tokp) == -1)
1277*45916cd2Sjpk exit_error(gettext("Could not construct slabel token of audit record\n"));
1278*45916cd2Sjpk 		}
1279*45916cd2Sjpk 
12807c478bd9Sstevel@tonic-gate 		if ((tokp = au_to_text(audit_str)) == (token_t *)NULL)
12817c478bd9Sstevel@tonic-gate 			exit_error(gettext("Could not allocate text token\n"));
12827c478bd9Sstevel@tonic-gate 		if (au_write(rd, tokp) == -1)
12837c478bd9Sstevel@tonic-gate exit_error(gettext("Could not construct text token of audit record\n"));
12847c478bd9Sstevel@tonic-gate #ifdef _LP64
12857c478bd9Sstevel@tonic-gate 		if ((tokp = au_to_return64(sorf, retval)) == (token_t *)NULL)
12867c478bd9Sstevel@tonic-gate #else
12877c478bd9Sstevel@tonic-gate 		if ((tokp = au_to_return32(sorf, retval)) == (token_t *)NULL)
12887c478bd9Sstevel@tonic-gate #endif
12897c478bd9Sstevel@tonic-gate 			exit_error(gettext(
12907c478bd9Sstevel@tonic-gate 				"Could not allocate return token\n"));
12917c478bd9Sstevel@tonic-gate 		if (au_write(rd, tokp) == -1)
12927c478bd9Sstevel@tonic-gate 			exit_error(gettext(
12937c478bd9Sstevel@tonic-gate 			"Could not construct return token of audit record\n"));
12947c478bd9Sstevel@tonic-gate 		if (au_close(rd, 1, evp->ae_number) == -1)
12957c478bd9Sstevel@tonic-gate 			exit_error(gettext(
12967c478bd9Sstevel@tonic-gate 				"Could not write audit record: %s\n"),
12977c478bd9Sstevel@tonic-gate 					strerror(errno));
12987c478bd9Sstevel@tonic-gate 	}
12997c478bd9Sstevel@tonic-gate }
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate static void
13027c478bd9Sstevel@tonic-gate do_getauid()
13037c478bd9Sstevel@tonic-gate {
13047c478bd9Sstevel@tonic-gate 	au_id_t auid;
13057c478bd9Sstevel@tonic-gate 
13067c478bd9Sstevel@tonic-gate 	egetauid(&auid);
13077c478bd9Sstevel@tonic-gate 	print_auid(auid);
13087c478bd9Sstevel@tonic-gate }
13097c478bd9Sstevel@tonic-gate 
13107c478bd9Sstevel@tonic-gate static void
13117c478bd9Sstevel@tonic-gate do_getaudit()
13127c478bd9Sstevel@tonic-gate {
13137c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 	egetaudit(&ai, sizeof (ai));
13167c478bd9Sstevel@tonic-gate 	print_auid(ai.ai_auid);
13177c478bd9Sstevel@tonic-gate 	print_mask(gettext("process preselection mask"), &ai.ai_mask);
13187c478bd9Sstevel@tonic-gate 	print_tid_ex(&ai.ai_termid);
13197c478bd9Sstevel@tonic-gate 	print_asid(ai.ai_asid);
13207c478bd9Sstevel@tonic-gate }
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate static void
13237c478bd9Sstevel@tonic-gate do_getkaudit()
13247c478bd9Sstevel@tonic-gate {
13257c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
13267c478bd9Sstevel@tonic-gate 
13277c478bd9Sstevel@tonic-gate 	egetkaudit(&ai, sizeof (ai));
13287c478bd9Sstevel@tonic-gate 	print_auid(ai.ai_auid);
13297c478bd9Sstevel@tonic-gate 	print_mask(gettext("process preselection mask"), &ai.ai_mask);
13307c478bd9Sstevel@tonic-gate 	print_tid_ex(&ai.ai_termid);
13317c478bd9Sstevel@tonic-gate 	print_asid(ai.ai_asid);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate /*
13357c478bd9Sstevel@tonic-gate  * per zone if AUDIT_PERZONE set, else only in global zone.
13367c478bd9Sstevel@tonic-gate  */
13377c478bd9Sstevel@tonic-gate 
13387c478bd9Sstevel@tonic-gate static void
13397c478bd9Sstevel@tonic-gate do_setkaudit(t, s)
13407c478bd9Sstevel@tonic-gate 	char *t;
13417c478bd9Sstevel@tonic-gate 	char *s;
13427c478bd9Sstevel@tonic-gate {
13437c478bd9Sstevel@tonic-gate 	uint_t type;
13447c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
13457c478bd9Sstevel@tonic-gate 
13467c478bd9Sstevel@tonic-gate 	egetkaudit(&ai, sizeof (ai));
13477c478bd9Sstevel@tonic-gate 	(void) str2type(t, &type);
13487c478bd9Sstevel@tonic-gate 	(void) str2ipaddr(s, &ai.ai_termid.at_addr[0], type);
13497c478bd9Sstevel@tonic-gate 	ai.ai_termid.at_type = type;
13507c478bd9Sstevel@tonic-gate 	esetkaudit(&ai, sizeof (ai));
13517c478bd9Sstevel@tonic-gate }
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate /*
13547c478bd9Sstevel@tonic-gate  * returns zone-relative root
13557c478bd9Sstevel@tonic-gate  */
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate static void
13587c478bd9Sstevel@tonic-gate do_getcar()
13597c478bd9Sstevel@tonic-gate {
13607c478bd9Sstevel@tonic-gate 	char path[MAXPATHLEN];
13617c478bd9Sstevel@tonic-gate 
13627c478bd9Sstevel@tonic-gate 	eauditon(A_GETCAR, (caddr_t)path, (int)sizeof (path));
13637c478bd9Sstevel@tonic-gate 	(void) printf(gettext("current active root = %s\n"), path);
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate /*
13677c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
13687c478bd9Sstevel@tonic-gate  * set.
13697c478bd9Sstevel@tonic-gate  */
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate static void
13727c478bd9Sstevel@tonic-gate do_getclass(event_str)
13737c478bd9Sstevel@tonic-gate 	char *event_str;
13747c478bd9Sstevel@tonic-gate {
13757c478bd9Sstevel@tonic-gate 	au_evclass_map_t ec;
13767c478bd9Sstevel@tonic-gate 	au_event_ent_t *evp;
13777c478bd9Sstevel@tonic-gate 	au_event_t event_number;
13787c478bd9Sstevel@tonic-gate 	char *event_name;
13797c478bd9Sstevel@tonic-gate 	char desc[256];
13807c478bd9Sstevel@tonic-gate 
13817c478bd9Sstevel@tonic-gate 	if (strisnum(event_str)) {
13827c478bd9Sstevel@tonic-gate 		event_number = atol(event_str);
13837c478bd9Sstevel@tonic-gate 		if ((evp = egetauevnum(event_number)) !=
13847c478bd9Sstevel@tonic-gate 				(au_event_ent_t *)NULL) {
13857c478bd9Sstevel@tonic-gate 			event_number = evp->ae_number;
13867c478bd9Sstevel@tonic-gate 			event_name = evp->ae_name;
13877c478bd9Sstevel@tonic-gate 		} else
13887c478bd9Sstevel@tonic-gate 			event_name = gettext("unknown");
13897c478bd9Sstevel@tonic-gate 	} else {
13907c478bd9Sstevel@tonic-gate 		event_name = event_str;
13917c478bd9Sstevel@tonic-gate 		if ((evp = egetauevnam(event_str)) != (au_event_ent_t *)NULL)
13927c478bd9Sstevel@tonic-gate 			event_number = evp->ae_number;
13937c478bd9Sstevel@tonic-gate 	}
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 	ec.ec_number = event_number;
13967c478bd9Sstevel@tonic-gate 	eauditon(A_GETCLASS, (caddr_t)&ec, 0);
13977c478bd9Sstevel@tonic-gate 
13987c478bd9Sstevel@tonic-gate 	(void) sprintf(desc, gettext("audit class mask for event %s(%d)"),
13997c478bd9Sstevel@tonic-gate 			event_name, event_number);
14007c478bd9Sstevel@tonic-gate 	print_mask1(desc, ec.ec_class);
14017c478bd9Sstevel@tonic-gate }
14027c478bd9Sstevel@tonic-gate 
14037c478bd9Sstevel@tonic-gate /*
14047c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
14057c478bd9Sstevel@tonic-gate  * set.  (AUC_DISABLED is always global, the other states are per zone
14067c478bd9Sstevel@tonic-gate  * if AUDIT_PERZONE is set)
14077c478bd9Sstevel@tonic-gate  */
14087c478bd9Sstevel@tonic-gate 
14097c478bd9Sstevel@tonic-gate static void
14107c478bd9Sstevel@tonic-gate do_getcond()
14117c478bd9Sstevel@tonic-gate {
14127c478bd9Sstevel@tonic-gate 	char cond_str[16];
14137c478bd9Sstevel@tonic-gate 	uint_t cond;
14147c478bd9Sstevel@tonic-gate 
14157c478bd9Sstevel@tonic-gate 	eauditon(A_GETCOND, (caddr_t)&cond, (int)sizeof (cond));
14167c478bd9Sstevel@tonic-gate 
14177c478bd9Sstevel@tonic-gate 	(void) cond2str(cond, cond_str);
14187c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit condition = %s\n"), cond_str);
14197c478bd9Sstevel@tonic-gate }
14207c478bd9Sstevel@tonic-gate 
14217c478bd9Sstevel@tonic-gate /*
14227c478bd9Sstevel@tonic-gate  * returned path is relative to zone root
14237c478bd9Sstevel@tonic-gate  */
14247c478bd9Sstevel@tonic-gate 
14257c478bd9Sstevel@tonic-gate static void
14267c478bd9Sstevel@tonic-gate do_getcwd()
14277c478bd9Sstevel@tonic-gate {
14287c478bd9Sstevel@tonic-gate 	char path[MAXPATHLEN];
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 	eauditon(A_GETCWD, (caddr_t)path, (int)sizeof (path));
14317c478bd9Sstevel@tonic-gate 	(void) printf(gettext("current working directory = %s\n"), path);
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate 
14347c478bd9Sstevel@tonic-gate /*
14357c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
14367c478bd9Sstevel@tonic-gate  * set.
14377c478bd9Sstevel@tonic-gate  */
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate static void
14407c478bd9Sstevel@tonic-gate do_getkmask()
14417c478bd9Sstevel@tonic-gate {
14427c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
14437c478bd9Sstevel@tonic-gate 
14447c478bd9Sstevel@tonic-gate 	eauditon(A_GETKMASK, (caddr_t)&pmask, (int)sizeof (pmask));
14457c478bd9Sstevel@tonic-gate 	print_mask(gettext("audit flags for non-attributable events"), &pmask);
14467c478bd9Sstevel@tonic-gate }
14477c478bd9Sstevel@tonic-gate 
14487c478bd9Sstevel@tonic-gate /*
14497c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
14507c478bd9Sstevel@tonic-gate  * set. (some policies can only be set from the global zone, but all
14517c478bd9Sstevel@tonic-gate  * can be read from anywhere.)
14527c478bd9Sstevel@tonic-gate  */
14537c478bd9Sstevel@tonic-gate 
14547c478bd9Sstevel@tonic-gate static void
14557c478bd9Sstevel@tonic-gate do_getpolicy()
14567c478bd9Sstevel@tonic-gate {
14577c478bd9Sstevel@tonic-gate 	char policy_str[1024];
14587c478bd9Sstevel@tonic-gate 	uint_t policy;
14597c478bd9Sstevel@tonic-gate 
14607c478bd9Sstevel@tonic-gate 	eauditon(A_GETPOLICY, (caddr_t)&policy, 0);
14617c478bd9Sstevel@tonic-gate 	(void) policy2str(policy, policy_str, sizeof (policy_str));
14627c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit policies = %s\n"), policy_str);
14637c478bd9Sstevel@tonic-gate }
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate static void
14667c478bd9Sstevel@tonic-gate do_getpinfo(pid_str)
14677c478bd9Sstevel@tonic-gate 	char *pid_str;
14687c478bd9Sstevel@tonic-gate {
14697c478bd9Sstevel@tonic-gate 	struct auditpinfo_addr ap;
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate 	if (strisnum(pid_str))
14727c478bd9Sstevel@tonic-gate 		ap.ap_pid = (pid_t)atoi(pid_str);
14737c478bd9Sstevel@tonic-gate 	else
14747c478bd9Sstevel@tonic-gate 		exit_usage(1);
14757c478bd9Sstevel@tonic-gate 
14767c478bd9Sstevel@tonic-gate 	eauditon(A_GETPINFO_ADDR, (caddr_t)&ap, sizeof (ap));
14777c478bd9Sstevel@tonic-gate 
14787c478bd9Sstevel@tonic-gate 	print_auid(ap.ap_auid);
14797c478bd9Sstevel@tonic-gate 	print_mask(gettext("process preselection mask"), &(ap.ap_mask));
14807c478bd9Sstevel@tonic-gate 	print_tid_ex(&(ap.ap_termid));
14817c478bd9Sstevel@tonic-gate 	print_asid(ap.ap_asid);
14827c478bd9Sstevel@tonic-gate }
14837c478bd9Sstevel@tonic-gate 
14847c478bd9Sstevel@tonic-gate /*
14857c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
14867c478bd9Sstevel@tonic-gate  * set.
14877c478bd9Sstevel@tonic-gate  */
14887c478bd9Sstevel@tonic-gate 
14897c478bd9Sstevel@tonic-gate static void
14907c478bd9Sstevel@tonic-gate do_getqbufsz()
14917c478bd9Sstevel@tonic-gate {
14927c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
14957c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue buffer size (bytes) = %ld\n"),
14967c478bd9Sstevel@tonic-gate 		qctrl.aq_bufsz);
14977c478bd9Sstevel@tonic-gate }
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate /*
15007c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
15017c478bd9Sstevel@tonic-gate  * set.
15027c478bd9Sstevel@tonic-gate  */
15037c478bd9Sstevel@tonic-gate 
15047c478bd9Sstevel@tonic-gate static void
15057c478bd9Sstevel@tonic-gate do_getqctrl()
15067c478bd9Sstevel@tonic-gate {
15077c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
15087c478bd9Sstevel@tonic-gate 
15097c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
15107c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue hiwater mark (records) = %ld\n"),
15117c478bd9Sstevel@tonic-gate 		qctrl.aq_hiwater);
15127c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue lowater mark (records) = %ld\n"),
15137c478bd9Sstevel@tonic-gate 		qctrl.aq_lowater);
15147c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue buffer size (bytes) = %ld\n"),
15157c478bd9Sstevel@tonic-gate 		qctrl.aq_bufsz);
15167c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue delay (ticks) = %ld\n"),
15177c478bd9Sstevel@tonic-gate 		qctrl.aq_delay);
15187c478bd9Sstevel@tonic-gate }
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate /*
15217c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
15227c478bd9Sstevel@tonic-gate  * set.
15237c478bd9Sstevel@tonic-gate  */
15247c478bd9Sstevel@tonic-gate 
15257c478bd9Sstevel@tonic-gate static void
15267c478bd9Sstevel@tonic-gate do_getqdelay()
15277c478bd9Sstevel@tonic-gate {
15287c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
15297c478bd9Sstevel@tonic-gate 
15307c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
15317c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue delay (ticks) = %ld\n"),
15327c478bd9Sstevel@tonic-gate 		qctrl.aq_delay);
15337c478bd9Sstevel@tonic-gate }
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate /*
15367c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
15377c478bd9Sstevel@tonic-gate  * set.
15387c478bd9Sstevel@tonic-gate  */
15397c478bd9Sstevel@tonic-gate 
15407c478bd9Sstevel@tonic-gate static void
15417c478bd9Sstevel@tonic-gate do_getqhiwater()
15427c478bd9Sstevel@tonic-gate {
15437c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
15447c478bd9Sstevel@tonic-gate 
15457c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
15467c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue hiwater mark (records) = %ld\n"),
15477c478bd9Sstevel@tonic-gate 		qctrl.aq_hiwater);
15487c478bd9Sstevel@tonic-gate }
15497c478bd9Sstevel@tonic-gate 
15507c478bd9Sstevel@tonic-gate /*
15517c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
15527c478bd9Sstevel@tonic-gate  * set.
15537c478bd9Sstevel@tonic-gate  */
15547c478bd9Sstevel@tonic-gate 
15557c478bd9Sstevel@tonic-gate static void
15567c478bd9Sstevel@tonic-gate do_getqlowater()
15577c478bd9Sstevel@tonic-gate {
15587c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
15597c478bd9Sstevel@tonic-gate 
15607c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
15617c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit queue lowater mark (records) = %ld\n"),
15627c478bd9Sstevel@tonic-gate 		qctrl.aq_lowater);
15637c478bd9Sstevel@tonic-gate }
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate static void
15667c478bd9Sstevel@tonic-gate do_getasid()
15677c478bd9Sstevel@tonic-gate {
15687c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
15697c478bd9Sstevel@tonic-gate 
15707c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&ai, sizeof (ai))) {
15717c478bd9Sstevel@tonic-gate 		exit_error(gettext("getaudit_addr(2) failed"));
15727c478bd9Sstevel@tonic-gate 	}
15737c478bd9Sstevel@tonic-gate 	print_asid(ai.ai_asid);
15747c478bd9Sstevel@tonic-gate }
15757c478bd9Sstevel@tonic-gate 
15767c478bd9Sstevel@tonic-gate /*
15777c478bd9Sstevel@tonic-gate  * The stats are for the entire system unless AUDIT_PERZONE is set.
15787c478bd9Sstevel@tonic-gate  */
15797c478bd9Sstevel@tonic-gate 
15807c478bd9Sstevel@tonic-gate static void
15817c478bd9Sstevel@tonic-gate do_getstat()
15827c478bd9Sstevel@tonic-gate {
15837c478bd9Sstevel@tonic-gate 	au_stat_t as;
15847c478bd9Sstevel@tonic-gate 
15857c478bd9Sstevel@tonic-gate 	eauditon(A_GETSTAT, (caddr_t)&as, 0);
15867c478bd9Sstevel@tonic-gate 	print_stats(&as);
15877c478bd9Sstevel@tonic-gate }
15887c478bd9Sstevel@tonic-gate 
15897c478bd9Sstevel@tonic-gate static void
15907c478bd9Sstevel@tonic-gate do_gettermid()
15917c478bd9Sstevel@tonic-gate {
15927c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
15937c478bd9Sstevel@tonic-gate 
15947c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&ai, sizeof (ai))) {
15957c478bd9Sstevel@tonic-gate 		exit_error(gettext("getaudit_addr(2) failed"));
15967c478bd9Sstevel@tonic-gate 	}
15977c478bd9Sstevel@tonic-gate 	print_tid_ex(&ai.ai_termid);
15987c478bd9Sstevel@tonic-gate }
15997c478bd9Sstevel@tonic-gate 
16007c478bd9Sstevel@tonic-gate /*
16017c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
16027c478bd9Sstevel@tonic-gate  * set.
16037c478bd9Sstevel@tonic-gate  */
16047c478bd9Sstevel@tonic-gate 
16057c478bd9Sstevel@tonic-gate static void
16067c478bd9Sstevel@tonic-gate do_getfsize()
16077c478bd9Sstevel@tonic-gate {
16087c478bd9Sstevel@tonic-gate 	au_fstat_t fstat;
16097c478bd9Sstevel@tonic-gate 
16107c478bd9Sstevel@tonic-gate 	eauditon(A_GETFSIZE, (caddr_t)&fstat, 0);
16117c478bd9Sstevel@tonic-gate 	(void) printf(gettext("Maximum file size %d, current file size %d\n"),
16127c478bd9Sstevel@tonic-gate 		fstat.af_filesz, fstat.af_currsz);
16137c478bd9Sstevel@tonic-gate }
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate /*ARGSUSED*/
16167c478bd9Sstevel@tonic-gate static void
16177c478bd9Sstevel@tonic-gate do_getuseraudit(user)
16187c478bd9Sstevel@tonic-gate char *user;
16197c478bd9Sstevel@tonic-gate {
16207c478bd9Sstevel@tonic-gate 	(void) printf(gettext("-getuseraudit supported on SunOS CMW only.\n"));
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate 
16237c478bd9Sstevel@tonic-gate /*
16247c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
16257c478bd9Sstevel@tonic-gate  * set.
16267c478bd9Sstevel@tonic-gate  */
16277c478bd9Sstevel@tonic-gate 
16287c478bd9Sstevel@tonic-gate static void
16297c478bd9Sstevel@tonic-gate do_lsevent()
16307c478bd9Sstevel@tonic-gate {
16317c478bd9Sstevel@tonic-gate 	register au_event_ent_t *evp;
16327c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
16337c478bd9Sstevel@tonic-gate 	char auflags[256];
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate 	setauevent();
16367c478bd9Sstevel@tonic-gate 	if ((evp = getauevent()) == (au_event_ent_t *)NULL) {
16377c478bd9Sstevel@tonic-gate 		(void) exit_error(gettext(
16387c478bd9Sstevel@tonic-gate 			"NO AUDIT EVENTS: Could not read %s\n."),
16397c478bd9Sstevel@tonic-gate 			AUDITEVENTFILE);
16407c478bd9Sstevel@tonic-gate 	}
16417c478bd9Sstevel@tonic-gate 
16427c478bd9Sstevel@tonic-gate 	setauevent();
16437c478bd9Sstevel@tonic-gate 	while ((evp = getauevent()) != (au_event_ent_t *)NULL) {
16447c478bd9Sstevel@tonic-gate 		pmask.am_success = pmask.am_failure = evp->ae_class;
16457c478bd9Sstevel@tonic-gate 		if (getauditflagschar(auflags, &pmask, 0) == -1)
16467c478bd9Sstevel@tonic-gate 			(void) strcpy(auflags, "unknown");
16477c478bd9Sstevel@tonic-gate 		(void) printf("%-30s %5d %s %s\n",
16487c478bd9Sstevel@tonic-gate 			evp->ae_name, evp->ae_number, auflags, evp->ae_desc);
16497c478bd9Sstevel@tonic-gate 	}
16507c478bd9Sstevel@tonic-gate 	endauevent();
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate /*
16547c478bd9Sstevel@tonic-gate  * The returned value is for the global zone unless AUDIT_PERZONE is
16557c478bd9Sstevel@tonic-gate  * set.
16567c478bd9Sstevel@tonic-gate  */
16577c478bd9Sstevel@tonic-gate 
16587c478bd9Sstevel@tonic-gate static void
16597c478bd9Sstevel@tonic-gate do_lspolicy()
16607c478bd9Sstevel@tonic-gate {
16617c478bd9Sstevel@tonic-gate 	int i;
16627c478bd9Sstevel@tonic-gate 
16637c478bd9Sstevel@tonic-gate 	/*
16647c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
16657c478bd9Sstevel@tonic-gate 	 *	Print a properly aligned header.
16667c478bd9Sstevel@tonic-gate 	 */
16677c478bd9Sstevel@tonic-gate 	(void) printf(gettext("policy string    description:\n"));
1668*45916cd2Sjpk 	for (i = 0; i < POLICY_TBL_SZ; i++) {
1669*45916cd2Sjpk 		if ((policy_table[i].policy_flags & AC_TSOL) && !tsol_on)
1670*45916cd2Sjpk 			continue;	/* skip this entry */
1671*45916cd2Sjpk 		(void) printf("%-17s%s\n", policy_table[i].policy_str,
1672*45916cd2Sjpk 		    gettext(policy_table[i].policy_desc));
1673*45916cd2Sjpk 	}
16747c478bd9Sstevel@tonic-gate }
16757c478bd9Sstevel@tonic-gate 
16767c478bd9Sstevel@tonic-gate static void
16777c478bd9Sstevel@tonic-gate do_setasid(sid_str, argv)
16787c478bd9Sstevel@tonic-gate 	char *sid_str;
16797c478bd9Sstevel@tonic-gate 	char **argv;
16807c478bd9Sstevel@tonic-gate {
16817c478bd9Sstevel@tonic-gate 	struct auditinfo_addr ai;
16827c478bd9Sstevel@tonic-gate 
16837c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&ai, sizeof (ai))) {
16847c478bd9Sstevel@tonic-gate 		exit_error(gettext("getaudit_addr(2) failed"));
16857c478bd9Sstevel@tonic-gate 	}
16867c478bd9Sstevel@tonic-gate 	ai.ai_asid = (au_asid_t)atol(sid_str);
16877c478bd9Sstevel@tonic-gate 	if (setaudit_addr(&ai, sizeof (ai))) {
16887c478bd9Sstevel@tonic-gate 		exit_error(gettext("setaudit_addr(2) failed"));
16897c478bd9Sstevel@tonic-gate 	}
16907c478bd9Sstevel@tonic-gate 	execit(argv);
16917c478bd9Sstevel@tonic-gate }
16927c478bd9Sstevel@tonic-gate 
16937c478bd9Sstevel@tonic-gate static void
16947c478bd9Sstevel@tonic-gate do_setaudit(user_str, mask_str, tid_str, sid_str, argv)
16957c478bd9Sstevel@tonic-gate 	char *user_str;
16967c478bd9Sstevel@tonic-gate 	char *mask_str;
16977c478bd9Sstevel@tonic-gate 	char *tid_str;
16987c478bd9Sstevel@tonic-gate 	char *sid_str;
16997c478bd9Sstevel@tonic-gate 	char **argv;
17007c478bd9Sstevel@tonic-gate {
17017c478bd9Sstevel@tonic-gate 	auditinfo_addr_t ai;
17027c478bd9Sstevel@tonic-gate 
17037c478bd9Sstevel@tonic-gate 	ai.ai_auid = (au_id_t)get_user_id(user_str);
17047c478bd9Sstevel@tonic-gate 	str2mask(mask_str, &ai.ai_mask),
17057c478bd9Sstevel@tonic-gate 	str2tid(tid_str, &ai.ai_termid);
17067c478bd9Sstevel@tonic-gate 	ai.ai_asid = (au_asid_t)atol(sid_str);
17077c478bd9Sstevel@tonic-gate 
17087c478bd9Sstevel@tonic-gate 	esetaudit(&ai, sizeof (ai));
17097c478bd9Sstevel@tonic-gate 	execit(argv);
17107c478bd9Sstevel@tonic-gate }
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate static void
17137c478bd9Sstevel@tonic-gate do_setauid(user, argv)
17147c478bd9Sstevel@tonic-gate 	char *user;
17157c478bd9Sstevel@tonic-gate 	char **argv;
17167c478bd9Sstevel@tonic-gate {
17177c478bd9Sstevel@tonic-gate 	au_id_t auid;
17187c478bd9Sstevel@tonic-gate 
17197c478bd9Sstevel@tonic-gate 	auid = get_user_id(user);
17207c478bd9Sstevel@tonic-gate 	esetauid(&auid);
17217c478bd9Sstevel@tonic-gate 	execit(argv);
17227c478bd9Sstevel@tonic-gate }
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate static void
17257c478bd9Sstevel@tonic-gate do_setpmask(pid_str, audit_flags)
17267c478bd9Sstevel@tonic-gate 	char *pid_str;
17277c478bd9Sstevel@tonic-gate 	char *audit_flags;
17287c478bd9Sstevel@tonic-gate {
17297c478bd9Sstevel@tonic-gate 	struct auditpinfo ap;
17307c478bd9Sstevel@tonic-gate 
17317c478bd9Sstevel@tonic-gate 	if (strisnum(pid_str))
17327c478bd9Sstevel@tonic-gate 		ap.ap_pid = (pid_t)atoi(pid_str);
17337c478bd9Sstevel@tonic-gate 	else
17347c478bd9Sstevel@tonic-gate 		exit_usage(1);
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate 	str2mask(audit_flags, &ap.ap_mask);
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	eauditon(A_SETPMASK, (caddr_t)&ap, (int)sizeof (ap));
17397c478bd9Sstevel@tonic-gate }
17407c478bd9Sstevel@tonic-gate 
17417c478bd9Sstevel@tonic-gate static void
17427c478bd9Sstevel@tonic-gate do_setsmask(asid_str, audit_flags)
17437c478bd9Sstevel@tonic-gate 	char *asid_str;
17447c478bd9Sstevel@tonic-gate 	char *audit_flags;
17457c478bd9Sstevel@tonic-gate {
17467c478bd9Sstevel@tonic-gate 	struct auditinfo ainfo;
17477c478bd9Sstevel@tonic-gate 
17487c478bd9Sstevel@tonic-gate 	if (strisnum(asid_str))
17497c478bd9Sstevel@tonic-gate 		ainfo.ai_asid = (pid_t)atoi(asid_str);
17507c478bd9Sstevel@tonic-gate 	else
17517c478bd9Sstevel@tonic-gate 		exit_usage(1);
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate 	str2mask(audit_flags, &ainfo.ai_mask);
17547c478bd9Sstevel@tonic-gate 
17557c478bd9Sstevel@tonic-gate 	eauditon(A_SETSMASK, (caddr_t)&ainfo, (int)sizeof (ainfo));
17567c478bd9Sstevel@tonic-gate }
17577c478bd9Sstevel@tonic-gate 
17587c478bd9Sstevel@tonic-gate static void
17597c478bd9Sstevel@tonic-gate do_setumask(auid_str, audit_flags)
17607c478bd9Sstevel@tonic-gate 	char *auid_str;
17617c478bd9Sstevel@tonic-gate 	char *audit_flags;
17627c478bd9Sstevel@tonic-gate {
17637c478bd9Sstevel@tonic-gate 	struct auditinfo ainfo;
17647c478bd9Sstevel@tonic-gate 
17657c478bd9Sstevel@tonic-gate 	if (strisnum(auid_str))
17667c478bd9Sstevel@tonic-gate 		ainfo.ai_auid = (pid_t)atoi(auid_str);
17677c478bd9Sstevel@tonic-gate 	else
17687c478bd9Sstevel@tonic-gate 		exit_usage(1);
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate 	str2mask(audit_flags, &ainfo.ai_mask);
17717c478bd9Sstevel@tonic-gate 
17727c478bd9Sstevel@tonic-gate 	eauditon(A_SETUMASK, (caddr_t)&ainfo, (int)sizeof (ainfo));
17737c478bd9Sstevel@tonic-gate }
17747c478bd9Sstevel@tonic-gate 
17757c478bd9Sstevel@tonic-gate /*
17767c478bd9Sstevel@tonic-gate  * local zone use is valid if AUDIT_PERZONE is set, otherwise the
17777c478bd9Sstevel@tonic-gate  * syscall returns EPERM.
17787c478bd9Sstevel@tonic-gate  */
17797c478bd9Sstevel@tonic-gate 
17807c478bd9Sstevel@tonic-gate static void
17817c478bd9Sstevel@tonic-gate do_setstat()
17827c478bd9Sstevel@tonic-gate {
17837c478bd9Sstevel@tonic-gate 	au_stat_t as;
17847c478bd9Sstevel@tonic-gate 
17857c478bd9Sstevel@tonic-gate 	as.as_audit	= (uint_t)-1;
17867c478bd9Sstevel@tonic-gate 	as.as_auditctl	= (uint_t)-1;
17877c478bd9Sstevel@tonic-gate 	as.as_dropped	= (uint_t)-1;
17887c478bd9Sstevel@tonic-gate 	as.as_enqueue	= (uint_t)-1;
17897c478bd9Sstevel@tonic-gate 	as.as_generated	= (uint_t)-1;
17907c478bd9Sstevel@tonic-gate 	as.as_kernel	= (uint_t)-1;
17917c478bd9Sstevel@tonic-gate 	as.as_nonattrib	= (uint_t)-1;
17927c478bd9Sstevel@tonic-gate 	as.as_rblocked	= (uint_t)-1;
17937c478bd9Sstevel@tonic-gate 	as.as_totalsize	= (uint_t)-1;
17947c478bd9Sstevel@tonic-gate 	as.as_wblocked	= (uint_t)-1;
17957c478bd9Sstevel@tonic-gate 	as.as_written	= (uint_t)-1;
17967c478bd9Sstevel@tonic-gate 
17977c478bd9Sstevel@tonic-gate 	eauditon(A_SETSTAT, (caddr_t)&as, (int)sizeof (as));
17987c478bd9Sstevel@tonic-gate 	(void) puts(gettext("audit stats reset"));
17997c478bd9Sstevel@tonic-gate }
18007c478bd9Sstevel@tonic-gate 
18017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
18027c478bd9Sstevel@tonic-gate static void
18037c478bd9Sstevel@tonic-gate do_setuseraudit(user, auditflags)
18047c478bd9Sstevel@tonic-gate 	char *user;
18057c478bd9Sstevel@tonic-gate 	char *auditflags;
18067c478bd9Sstevel@tonic-gate {
18077c478bd9Sstevel@tonic-gate 	(void) printf(gettext("-setuseraudit supported on SunOS CMW only.\n"));
18087c478bd9Sstevel@tonic-gate }
18097c478bd9Sstevel@tonic-gate 
18107c478bd9Sstevel@tonic-gate /*
18117c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
18127c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
18137c478bd9Sstevel@tonic-gate  */
18147c478bd9Sstevel@tonic-gate 
18157c478bd9Sstevel@tonic-gate static void
18167c478bd9Sstevel@tonic-gate do_setclass(event_str, audit_flags)
18177c478bd9Sstevel@tonic-gate 	char *event_str;
18187c478bd9Sstevel@tonic-gate 	char *audit_flags;
18197c478bd9Sstevel@tonic-gate {
18207c478bd9Sstevel@tonic-gate 	au_event_t event;
18217c478bd9Sstevel@tonic-gate 	int mask;
18227c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
18237c478bd9Sstevel@tonic-gate 	au_evclass_map_t ec;
18247c478bd9Sstevel@tonic-gate 	au_event_ent_t *evp;
18257c478bd9Sstevel@tonic-gate 
18267c478bd9Sstevel@tonic-gate 	if (strisnum(event_str))
18277c478bd9Sstevel@tonic-gate 		event = (uint_t)atol(event_str);
18287c478bd9Sstevel@tonic-gate 	else {
18297c478bd9Sstevel@tonic-gate 		if ((evp = egetauevnam(event_str)) != (au_event_ent_t *)NULL)
18307c478bd9Sstevel@tonic-gate 			event = evp->ae_number;
18317c478bd9Sstevel@tonic-gate 	}
18327c478bd9Sstevel@tonic-gate 
18337c478bd9Sstevel@tonic-gate 	if (strisnum(audit_flags))
18347c478bd9Sstevel@tonic-gate 		mask = atoi(audit_flags);
18357c478bd9Sstevel@tonic-gate 	else {
18367c478bd9Sstevel@tonic-gate 		str2mask(audit_flags, &pmask);
18377c478bd9Sstevel@tonic-gate 		mask = pmask.am_success | pmask.am_failure;
18387c478bd9Sstevel@tonic-gate 	}
18397c478bd9Sstevel@tonic-gate 
18407c478bd9Sstevel@tonic-gate 	ec.ec_number = event;
18417c478bd9Sstevel@tonic-gate 	ec.ec_class = mask;
18427c478bd9Sstevel@tonic-gate 	eauditon(A_SETCLASS, (caddr_t)&ec, (int)sizeof (ec));
18437c478bd9Sstevel@tonic-gate }
18447c478bd9Sstevel@tonic-gate 
18457c478bd9Sstevel@tonic-gate /*
18467c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
18477c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
18487c478bd9Sstevel@tonic-gate  */
18497c478bd9Sstevel@tonic-gate 
18507c478bd9Sstevel@tonic-gate static void
18517c478bd9Sstevel@tonic-gate do_setkmask(audit_flags)
18527c478bd9Sstevel@tonic-gate char *audit_flags;
18537c478bd9Sstevel@tonic-gate {
18547c478bd9Sstevel@tonic-gate 	au_mask_t pmask;
18557c478bd9Sstevel@tonic-gate 
18567c478bd9Sstevel@tonic-gate 	str2mask(audit_flags, &pmask);
18577c478bd9Sstevel@tonic-gate 	eauditon(A_SETKMASK, (caddr_t)&pmask, (int)sizeof (pmask));
18587c478bd9Sstevel@tonic-gate 	print_mask(gettext("audit flags for non-attributable events"), &pmask);
18597c478bd9Sstevel@tonic-gate }
18607c478bd9Sstevel@tonic-gate 
18617c478bd9Sstevel@tonic-gate /*
18627c478bd9Sstevel@tonic-gate  * ahlt and perzone are global zone only; the other policies are valid
18637c478bd9Sstevel@tonic-gate  * in a local zone if AUDIT_PERZONE is set.  The kernel insures that
18647c478bd9Sstevel@tonic-gate  * a local zone can't change ahlt and perzone (EINVAL).
18657c478bd9Sstevel@tonic-gate  */
18667c478bd9Sstevel@tonic-gate 
18677c478bd9Sstevel@tonic-gate static void
18687c478bd9Sstevel@tonic-gate do_setpolicy(policy_str)
18697c478bd9Sstevel@tonic-gate char *policy_str;
18707c478bd9Sstevel@tonic-gate {
18717c478bd9Sstevel@tonic-gate 	uint_t	policy;
18727c478bd9Sstevel@tonic-gate 
18737c478bd9Sstevel@tonic-gate 	switch (str2policy(policy_str, &policy)) {
18747c478bd9Sstevel@tonic-gate 	case 2:
18757c478bd9Sstevel@tonic-gate 		exit_error(gettext(
18767c478bd9Sstevel@tonic-gate 			"policy (%s) invalid in a local zone."),
18777c478bd9Sstevel@tonic-gate 			policy_str);
18787c478bd9Sstevel@tonic-gate 		break;
18797c478bd9Sstevel@tonic-gate 	default:
18807c478bd9Sstevel@tonic-gate 		exit_error(gettext(
18817c478bd9Sstevel@tonic-gate 		    "Invalid policy (%s) specified."),
18827c478bd9Sstevel@tonic-gate 		    policy_str);
18837c478bd9Sstevel@tonic-gate 		break;
18847c478bd9Sstevel@tonic-gate 	case 0:
18857c478bd9Sstevel@tonic-gate 		eauditon(A_SETPOLICY, (caddr_t)&policy, 0);
18867c478bd9Sstevel@tonic-gate 		break;
18877c478bd9Sstevel@tonic-gate 	}
18887c478bd9Sstevel@tonic-gate }
18897c478bd9Sstevel@tonic-gate 
18907c478bd9Sstevel@tonic-gate /*
18917c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
18927c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
18937c478bd9Sstevel@tonic-gate  */
18947c478bd9Sstevel@tonic-gate 
18957c478bd9Sstevel@tonic-gate static void
18967c478bd9Sstevel@tonic-gate do_setqbufsz(bufsz)
18977c478bd9Sstevel@tonic-gate char *bufsz;
18987c478bd9Sstevel@tonic-gate {
18997c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
19007c478bd9Sstevel@tonic-gate 
19017c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
19027c478bd9Sstevel@tonic-gate 	qctrl.aq_bufsz = atol(bufsz);
19037c478bd9Sstevel@tonic-gate 	eauditon(A_SETQCTRL, (caddr_t)&qctrl, 0);
19047c478bd9Sstevel@tonic-gate }
19057c478bd9Sstevel@tonic-gate 
19067c478bd9Sstevel@tonic-gate /*
19077c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19087c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19097c478bd9Sstevel@tonic-gate  */
19107c478bd9Sstevel@tonic-gate 
19117c478bd9Sstevel@tonic-gate static void
19127c478bd9Sstevel@tonic-gate do_setqctrl(hiwater, lowater, bufsz, delay)
19137c478bd9Sstevel@tonic-gate 	char *hiwater;
19147c478bd9Sstevel@tonic-gate 	char *lowater;
19157c478bd9Sstevel@tonic-gate 	char *bufsz;
19167c478bd9Sstevel@tonic-gate 	char *delay;
19177c478bd9Sstevel@tonic-gate {
19187c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
19197c478bd9Sstevel@tonic-gate 
19207c478bd9Sstevel@tonic-gate 	qctrl.aq_hiwater = atol(hiwater);
19217c478bd9Sstevel@tonic-gate 	qctrl.aq_lowater = atol(lowater);
19227c478bd9Sstevel@tonic-gate 	qctrl.aq_bufsz = atol(bufsz);
19237c478bd9Sstevel@tonic-gate 	qctrl.aq_delay = atol(delay);
19247c478bd9Sstevel@tonic-gate 	eauditon(A_SETQCTRL, (caddr_t)&qctrl, 0);
19257c478bd9Sstevel@tonic-gate }
19267c478bd9Sstevel@tonic-gate 
19277c478bd9Sstevel@tonic-gate /*
19287c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19297c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19307c478bd9Sstevel@tonic-gate  */
19317c478bd9Sstevel@tonic-gate 
19327c478bd9Sstevel@tonic-gate static void
19337c478bd9Sstevel@tonic-gate do_setqdelay(delay)
19347c478bd9Sstevel@tonic-gate char *delay;
19357c478bd9Sstevel@tonic-gate {
19367c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
19377c478bd9Sstevel@tonic-gate 
19387c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
19397c478bd9Sstevel@tonic-gate 	qctrl.aq_delay = atol(delay);
19407c478bd9Sstevel@tonic-gate 	eauditon(A_SETQCTRL, (caddr_t)&qctrl, 0);
19417c478bd9Sstevel@tonic-gate }
19427c478bd9Sstevel@tonic-gate 
19437c478bd9Sstevel@tonic-gate /*
19447c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19457c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19467c478bd9Sstevel@tonic-gate  */
19477c478bd9Sstevel@tonic-gate 
19487c478bd9Sstevel@tonic-gate static void
19497c478bd9Sstevel@tonic-gate do_setqhiwater(hiwater)
19507c478bd9Sstevel@tonic-gate char *hiwater;
19517c478bd9Sstevel@tonic-gate {
19527c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
19537c478bd9Sstevel@tonic-gate 
19547c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
19557c478bd9Sstevel@tonic-gate 	qctrl.aq_hiwater = atol(hiwater);
19567c478bd9Sstevel@tonic-gate 	eauditon(A_SETQCTRL, (caddr_t)&qctrl, 0);
19577c478bd9Sstevel@tonic-gate }
19587c478bd9Sstevel@tonic-gate 
19597c478bd9Sstevel@tonic-gate /*
19607c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19617c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19627c478bd9Sstevel@tonic-gate  */
19637c478bd9Sstevel@tonic-gate 
19647c478bd9Sstevel@tonic-gate static void
19657c478bd9Sstevel@tonic-gate do_setqlowater(lowater)
19667c478bd9Sstevel@tonic-gate 	char *lowater;
19677c478bd9Sstevel@tonic-gate {
19687c478bd9Sstevel@tonic-gate 	struct au_qctrl qctrl;
19697c478bd9Sstevel@tonic-gate 
19707c478bd9Sstevel@tonic-gate 	eauditon(A_GETQCTRL, (caddr_t)&qctrl, 0);
19717c478bd9Sstevel@tonic-gate 	qctrl.aq_lowater = atol(lowater);
19727c478bd9Sstevel@tonic-gate 	eauditon(A_SETQCTRL, (caddr_t)&qctrl, 0);
19737c478bd9Sstevel@tonic-gate }
19747c478bd9Sstevel@tonic-gate 
19757c478bd9Sstevel@tonic-gate /*
19767c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19777c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19787c478bd9Sstevel@tonic-gate  */
19797c478bd9Sstevel@tonic-gate 
19807c478bd9Sstevel@tonic-gate static void
19817c478bd9Sstevel@tonic-gate do_settid(char *tid_str)
19827c478bd9Sstevel@tonic-gate {
19837c478bd9Sstevel@tonic-gate 	struct auditinfo_addr ai;
19847c478bd9Sstevel@tonic-gate 
19857c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&ai, sizeof (ai))) {
19867c478bd9Sstevel@tonic-gate 		exit_error(gettext("getaudit_addr(2) failed"));
19877c478bd9Sstevel@tonic-gate 	}
19887c478bd9Sstevel@tonic-gate 
19897c478bd9Sstevel@tonic-gate 	str2tid(tid_str, &ai.ai_termid);
19907c478bd9Sstevel@tonic-gate 
19917c478bd9Sstevel@tonic-gate 	if (setaudit_addr(&ai, sizeof (ai))) {
19927c478bd9Sstevel@tonic-gate 		exit_error(gettext("setaudit_addr(2) failed"));
19937c478bd9Sstevel@tonic-gate 	}
19947c478bd9Sstevel@tonic-gate }
19957c478bd9Sstevel@tonic-gate 
19967c478bd9Sstevel@tonic-gate /*
19977c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE set:  valid in all zones
19987c478bd9Sstevel@tonic-gate  * AUDIT_PERZONE not set: valid in global zone only
19997c478bd9Sstevel@tonic-gate  */
20007c478bd9Sstevel@tonic-gate 
20017c478bd9Sstevel@tonic-gate static void
20027c478bd9Sstevel@tonic-gate do_setfsize(size)
20037c478bd9Sstevel@tonic-gate 	char *size;
20047c478bd9Sstevel@tonic-gate {
20057c478bd9Sstevel@tonic-gate 	au_fstat_t fstat;
20067c478bd9Sstevel@tonic-gate 
20077c478bd9Sstevel@tonic-gate 	fstat.af_filesz = atol(size);
20087c478bd9Sstevel@tonic-gate 	eauditon(A_SETFSIZE, (caddr_t)&fstat, 0);
20097c478bd9Sstevel@tonic-gate }
20107c478bd9Sstevel@tonic-gate 
20117c478bd9Sstevel@tonic-gate static void
20127c478bd9Sstevel@tonic-gate eauditon(cmd, data, length)
20137c478bd9Sstevel@tonic-gate 	int cmd;
20147c478bd9Sstevel@tonic-gate 	caddr_t data;
20157c478bd9Sstevel@tonic-gate 	int length;
20167c478bd9Sstevel@tonic-gate {
20177c478bd9Sstevel@tonic-gate 	if (auditon(cmd, data, length) == -1)
20187c478bd9Sstevel@tonic-gate 		exit_error(gettext("auditon(2) failed."));
20197c478bd9Sstevel@tonic-gate }
20207c478bd9Sstevel@tonic-gate 
20217c478bd9Sstevel@tonic-gate static void
20227c478bd9Sstevel@tonic-gate egetauid(auid)
20237c478bd9Sstevel@tonic-gate 	au_id_t *auid;
20247c478bd9Sstevel@tonic-gate {
20257c478bd9Sstevel@tonic-gate 	if (getauid(auid) == -1)
20267c478bd9Sstevel@tonic-gate 		exit_error(gettext("getauid(2) failed."));
20277c478bd9Sstevel@tonic-gate }
20287c478bd9Sstevel@tonic-gate 
20297c478bd9Sstevel@tonic-gate static void
20307c478bd9Sstevel@tonic-gate egetaudit(ai, size)
20317c478bd9Sstevel@tonic-gate 	auditinfo_addr_t *ai;
20327c478bd9Sstevel@tonic-gate 	int size;
20337c478bd9Sstevel@tonic-gate {
20347c478bd9Sstevel@tonic-gate 	if (getaudit_addr(ai, size) == -1)
20357c478bd9Sstevel@tonic-gate 		exit_error(gettext("getaudit_addr(2) failed."));
20367c478bd9Sstevel@tonic-gate }
20377c478bd9Sstevel@tonic-gate 
20387c478bd9Sstevel@tonic-gate static void
20397c478bd9Sstevel@tonic-gate egetkaudit(ai, size)
20407c478bd9Sstevel@tonic-gate 	auditinfo_addr_t *ai;
20417c478bd9Sstevel@tonic-gate 	int size;
20427c478bd9Sstevel@tonic-gate {
20437c478bd9Sstevel@tonic-gate 	if (auditon(A_GETKAUDIT, (char *)ai, size) < 0)
20447c478bd9Sstevel@tonic-gate 		exit_error(gettext("auditon: A_GETKAUDIT failed."));
20457c478bd9Sstevel@tonic-gate }
20467c478bd9Sstevel@tonic-gate 
20477c478bd9Sstevel@tonic-gate static void
20487c478bd9Sstevel@tonic-gate esetkaudit(ai, size)
20497c478bd9Sstevel@tonic-gate 	auditinfo_addr_t *ai;
20507c478bd9Sstevel@tonic-gate 	int size;
20517c478bd9Sstevel@tonic-gate {
20527c478bd9Sstevel@tonic-gate 	if (auditon(A_SETKAUDIT, (char *)ai, size) < 0)
20537c478bd9Sstevel@tonic-gate 		exit_error(gettext("auditon: A_SETKAUDIT failed."));
20547c478bd9Sstevel@tonic-gate }
20557c478bd9Sstevel@tonic-gate 
20567c478bd9Sstevel@tonic-gate static void
20577c478bd9Sstevel@tonic-gate egetauditflagsbin(auditflags, pmask)
20587c478bd9Sstevel@tonic-gate 	char *auditflags;
20597c478bd9Sstevel@tonic-gate 	au_mask_t *pmask;
20607c478bd9Sstevel@tonic-gate {
20617c478bd9Sstevel@tonic-gate 	pmask->am_success = pmask->am_failure = 0;
20627c478bd9Sstevel@tonic-gate 
20637c478bd9Sstevel@tonic-gate 	if (strcmp(auditflags, "none") == 0)
20647c478bd9Sstevel@tonic-gate 		return;
20657c478bd9Sstevel@tonic-gate 
20667c478bd9Sstevel@tonic-gate 	if (getauditflagsbin(auditflags, pmask) < 0) {
20677c478bd9Sstevel@tonic-gate 		exit_error(gettext("Could not get audit flags (%s)"),
20687c478bd9Sstevel@tonic-gate 			auditflags);
20697c478bd9Sstevel@tonic-gate 	}
20707c478bd9Sstevel@tonic-gate }
20717c478bd9Sstevel@tonic-gate 
20727c478bd9Sstevel@tonic-gate static au_event_ent_t *
20737c478bd9Sstevel@tonic-gate egetauevnum(event_number)
20747c478bd9Sstevel@tonic-gate 	au_event_t event_number;
20757c478bd9Sstevel@tonic-gate {
20767c478bd9Sstevel@tonic-gate 	au_event_ent_t *evp;
20777c478bd9Sstevel@tonic-gate 
20787c478bd9Sstevel@tonic-gate 	if ((evp = getauevnum(event_number)) == (au_event_ent_t *)NULL)
20797c478bd9Sstevel@tonic-gate 		exit_error(gettext("Could not get audit event %d"),
20807c478bd9Sstevel@tonic-gate 			event_number);
20817c478bd9Sstevel@tonic-gate 
20827c478bd9Sstevel@tonic-gate 	return (evp);
20837c478bd9Sstevel@tonic-gate }
20847c478bd9Sstevel@tonic-gate 
20857c478bd9Sstevel@tonic-gate static au_event_ent_t *
20867c478bd9Sstevel@tonic-gate egetauevnam(event_name)
20877c478bd9Sstevel@tonic-gate 	char *event_name;
20887c478bd9Sstevel@tonic-gate {
20897c478bd9Sstevel@tonic-gate 	register au_event_ent_t *evp;
20907c478bd9Sstevel@tonic-gate 
20917c478bd9Sstevel@tonic-gate 	if ((evp = getauevnam(event_name)) == (au_event_ent_t *)NULL)
20927c478bd9Sstevel@tonic-gate 		exit_error(gettext("Could not get audit event %s"), event_name);
20937c478bd9Sstevel@tonic-gate 
20947c478bd9Sstevel@tonic-gate 	return (evp);
20957c478bd9Sstevel@tonic-gate }
20967c478bd9Sstevel@tonic-gate 
20977c478bd9Sstevel@tonic-gate static void
20987c478bd9Sstevel@tonic-gate esetauid(auid)
20997c478bd9Sstevel@tonic-gate 	au_id_t *auid;
21007c478bd9Sstevel@tonic-gate {
21017c478bd9Sstevel@tonic-gate 	if (setauid(auid) == -1)
21027c478bd9Sstevel@tonic-gate 		exit_error(gettext("setauid(2) failed."));
21037c478bd9Sstevel@tonic-gate }
21047c478bd9Sstevel@tonic-gate 
21057c478bd9Sstevel@tonic-gate static void
21067c478bd9Sstevel@tonic-gate esetaudit(ai, size)
21077c478bd9Sstevel@tonic-gate 	auditinfo_addr_t *ai;
21087c478bd9Sstevel@tonic-gate 	int size;
21097c478bd9Sstevel@tonic-gate {
21107c478bd9Sstevel@tonic-gate 	if (setaudit_addr(ai, size) == -1)
21117c478bd9Sstevel@tonic-gate 		exit_error(gettext("setaudit_addr(2) failed."));
21127c478bd9Sstevel@tonic-gate }
21137c478bd9Sstevel@tonic-gate 
21147c478bd9Sstevel@tonic-gate static uid_t
21157c478bd9Sstevel@tonic-gate get_user_id(user)
21167c478bd9Sstevel@tonic-gate 	char *user;
21177c478bd9Sstevel@tonic-gate {
21187c478bd9Sstevel@tonic-gate 	struct passwd *pwd;
21197c478bd9Sstevel@tonic-gate 	uid_t uid;
21207c478bd9Sstevel@tonic-gate 
21217c478bd9Sstevel@tonic-gate 	setpwent();
21227c478bd9Sstevel@tonic-gate 	if (isdigit(*user)) {
21237c478bd9Sstevel@tonic-gate 		uid = atoi(user);
21247c478bd9Sstevel@tonic-gate 		if ((pwd = getpwuid(uid)) == (struct passwd *)NULL) {
21257c478bd9Sstevel@tonic-gate 			exit_error(gettext("Invalid user: %s"), user);
21267c478bd9Sstevel@tonic-gate 		}
21277c478bd9Sstevel@tonic-gate 	} else {
21287c478bd9Sstevel@tonic-gate 		if ((pwd = getpwnam(user)) == (struct passwd *)NULL) {
21297c478bd9Sstevel@tonic-gate 			exit_error(gettext("Invalid user: %s"), user);
21307c478bd9Sstevel@tonic-gate 		}
21317c478bd9Sstevel@tonic-gate 	}
21327c478bd9Sstevel@tonic-gate 	endpwent();
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 	return (pwd->pw_uid);
21357c478bd9Sstevel@tonic-gate }
21367c478bd9Sstevel@tonic-gate 
21377c478bd9Sstevel@tonic-gate /*
21387c478bd9Sstevel@tonic-gate  * get_arg_ent()
21397c478bd9Sstevel@tonic-gate  *     Inputs: command line argument string
21407c478bd9Sstevel@tonic-gate  *     Returns ptr to policy_entry if found; null, if not found
21417c478bd9Sstevel@tonic-gate  */
21427c478bd9Sstevel@tonic-gate static struct arg_entry *
21437c478bd9Sstevel@tonic-gate get_arg_ent(arg_str)
21447c478bd9Sstevel@tonic-gate 	char *arg_str;
21457c478bd9Sstevel@tonic-gate {
21467c478bd9Sstevel@tonic-gate 	struct arg_entry key;
21477c478bd9Sstevel@tonic-gate 
21487c478bd9Sstevel@tonic-gate 	key.arg_str = arg_str;
21497c478bd9Sstevel@tonic-gate 
21507c478bd9Sstevel@tonic-gate 	return ((struct arg_entry *)bsearch((char *)&key,
21517c478bd9Sstevel@tonic-gate 	    (char *)arg_table, ARG_TBL_SZ, sizeof (struct arg_entry),
21527c478bd9Sstevel@tonic-gate 	    arg_ent_compare));
21537c478bd9Sstevel@tonic-gate }
21547c478bd9Sstevel@tonic-gate 
21557c478bd9Sstevel@tonic-gate /*
21567c478bd9Sstevel@tonic-gate  * arg_ent_compare()
21577c478bd9Sstevel@tonic-gate  *     Compares two command line arguments to determine which is
21587c478bd9Sstevel@tonic-gate  *       lexicographically greater.
21597c478bd9Sstevel@tonic-gate  *     Inputs: two argument map table entry pointers
21607c478bd9Sstevel@tonic-gate  *     Returns: > 1: aep1->arg_str > aep2->arg_str
21617c478bd9Sstevel@tonic-gate  *              < 1: aep1->arg_str < aep2->arg_str
21627c478bd9Sstevel@tonic-gate  *                0: aep1->arg_str = aep->arg_str2
21637c478bd9Sstevel@tonic-gate  */
21647c478bd9Sstevel@tonic-gate static int
21657c478bd9Sstevel@tonic-gate arg_ent_compare(aep1, aep2)
21667c478bd9Sstevel@tonic-gate struct arg_entry *aep1, *aep2;
21677c478bd9Sstevel@tonic-gate {
21687c478bd9Sstevel@tonic-gate 	return (strcmp(aep1->arg_str, aep2->arg_str));
21697c478bd9Sstevel@tonic-gate }
21707c478bd9Sstevel@tonic-gate 
21717c478bd9Sstevel@tonic-gate /*
21727c478bd9Sstevel@tonic-gate  * Convert mask of the following forms:
21737c478bd9Sstevel@tonic-gate  *
21747c478bd9Sstevel@tonic-gate  *    audit_flags (ie. +lo,-ad,pc)
21757c478bd9Sstevel@tonic-gate  *    0xffffffff,0xffffffff
21767c478bd9Sstevel@tonic-gate  *    ffffffff,ffffffff
21777c478bd9Sstevel@tonic-gate  *    20,20
21787c478bd9Sstevel@tonic-gate  */
21797c478bd9Sstevel@tonic-gate static void
21807c478bd9Sstevel@tonic-gate str2mask(mask_str, mp)
21817c478bd9Sstevel@tonic-gate 	char *mask_str;
21827c478bd9Sstevel@tonic-gate 	au_mask_t *mp;
21837c478bd9Sstevel@tonic-gate {
21847c478bd9Sstevel@tonic-gate 
21857c478bd9Sstevel@tonic-gate 	char sp[256];
21867c478bd9Sstevel@tonic-gate 	char fp[256];
21877c478bd9Sstevel@tonic-gate 
21887c478bd9Sstevel@tonic-gate 	mp->am_success = 0;
21897c478bd9Sstevel@tonic-gate 	mp->am_failure = 0;
21907c478bd9Sstevel@tonic-gate 
21917c478bd9Sstevel@tonic-gate 	/*
21927c478bd9Sstevel@tonic-gate 	 * a mask of the form +aa,bb,cc,-dd
21937c478bd9Sstevel@tonic-gate 	 */
21947c478bd9Sstevel@tonic-gate 	if (strisflags(mask_str)) {
21957c478bd9Sstevel@tonic-gate 		egetauditflagsbin(mask_str, mp);
21967c478bd9Sstevel@tonic-gate 	/*
21977c478bd9Sstevel@tonic-gate 	 * a mask of the form 0xffffffff,0xffffffff or 1,1
21987c478bd9Sstevel@tonic-gate 	 */
21997c478bd9Sstevel@tonic-gate 	} else {
22007c478bd9Sstevel@tonic-gate 		strsplit(mask_str, sp, fp, ',');
22017c478bd9Sstevel@tonic-gate 
22027c478bd9Sstevel@tonic-gate 		if (strlen(sp) > (size_t)2 && !strncasecmp(sp, "0x", 2))
22037c478bd9Sstevel@tonic-gate 			(void) sscanf(sp + 2, "%x", &mp->am_success);
22047c478bd9Sstevel@tonic-gate 		else
22057c478bd9Sstevel@tonic-gate 			(void) sscanf(sp, "%u", &mp->am_success);
22067c478bd9Sstevel@tonic-gate 
22077c478bd9Sstevel@tonic-gate 		if (strlen(fp) > (size_t)2 && !strncasecmp(fp, "0x", 2))
22087c478bd9Sstevel@tonic-gate 			(void) sscanf(fp + 2, "%x", &mp->am_failure);
22097c478bd9Sstevel@tonic-gate 		else
22107c478bd9Sstevel@tonic-gate 			(void) sscanf(fp, "%u", &mp->am_failure);
22117c478bd9Sstevel@tonic-gate 	}
22127c478bd9Sstevel@tonic-gate }
22137c478bd9Sstevel@tonic-gate 
22147c478bd9Sstevel@tonic-gate /*
22157c478bd9Sstevel@tonic-gate  * tid_str is major,minor,host  -- host is a name or an ip address
22167c478bd9Sstevel@tonic-gate  */
22177c478bd9Sstevel@tonic-gate 
22187c478bd9Sstevel@tonic-gate static void
22197c478bd9Sstevel@tonic-gate str2tid(char *tid_str, au_tid_addr_t *tp)
22207c478bd9Sstevel@tonic-gate {
22217c478bd9Sstevel@tonic-gate 	char *major_str = (char *)NULL;
22227c478bd9Sstevel@tonic-gate 	char *minor_str = (char *)NULL;
22237c478bd9Sstevel@tonic-gate 	char *host_str = (char *)NULL;
22247c478bd9Sstevel@tonic-gate 	major_t major = 0;
22257c478bd9Sstevel@tonic-gate 	major_t minor = 0;
22267c478bd9Sstevel@tonic-gate 	dev_t dev = 0;
22277c478bd9Sstevel@tonic-gate 	struct hostent *phe;
22287c478bd9Sstevel@tonic-gate 	int err;
22297c478bd9Sstevel@tonic-gate 	uint32_t ibuf;
22307c478bd9Sstevel@tonic-gate 	uint32_t ibuf6[4];
22317c478bd9Sstevel@tonic-gate 
22327c478bd9Sstevel@tonic-gate 	tp->at_port = 0;
22337c478bd9Sstevel@tonic-gate 	tp->at_type = 0;
22347c478bd9Sstevel@tonic-gate 	bzero(tp->at_addr, 16);
22357c478bd9Sstevel@tonic-gate 
22367c478bd9Sstevel@tonic-gate 	major_str = tid_str;
22377c478bd9Sstevel@tonic-gate 	if ((minor_str = strchr(tid_str, ',')) != NULL) {
22387c478bd9Sstevel@tonic-gate 		*minor_str = '\0';
22397c478bd9Sstevel@tonic-gate 		minor_str++;
22407c478bd9Sstevel@tonic-gate 	}
22417c478bd9Sstevel@tonic-gate 
22427c478bd9Sstevel@tonic-gate 	if (minor_str)
22437c478bd9Sstevel@tonic-gate 		if ((host_str = strchr(minor_str, ',')) != NULL) {
22447c478bd9Sstevel@tonic-gate 			*host_str = '\0';
22457c478bd9Sstevel@tonic-gate 			host_str++;
22467c478bd9Sstevel@tonic-gate 		}
22477c478bd9Sstevel@tonic-gate 
22487c478bd9Sstevel@tonic-gate 	if (major_str)
22497c478bd9Sstevel@tonic-gate 		major = (major_t)atoi(major_str);
22507c478bd9Sstevel@tonic-gate 
22517c478bd9Sstevel@tonic-gate 	if (minor_str)
22527c478bd9Sstevel@tonic-gate 		minor = (minor_t)atoi(minor_str);
22537c478bd9Sstevel@tonic-gate 
22547c478bd9Sstevel@tonic-gate 	if ((dev = makedev(major, minor)) != NODEV)
22557c478bd9Sstevel@tonic-gate 		tp->at_port = dev;
22567c478bd9Sstevel@tonic-gate 
22577c478bd9Sstevel@tonic-gate 	if (host_str) {
22587c478bd9Sstevel@tonic-gate 		if (strisipaddr(host_str)) {
22597c478bd9Sstevel@tonic-gate 		    if (inet_pton(AF_INET, host_str, &ibuf)) {
22607c478bd9Sstevel@tonic-gate 			tp->at_addr[0] = ibuf;
22617c478bd9Sstevel@tonic-gate 			tp->at_type = AU_IPv4;
22627c478bd9Sstevel@tonic-gate 		    } else if (inet_pton(AF_INET6, host_str, ibuf6)) {
22637c478bd9Sstevel@tonic-gate 			tp->at_addr[0] = ibuf6[0];
22647c478bd9Sstevel@tonic-gate 			tp->at_addr[1] = ibuf6[1];
22657c478bd9Sstevel@tonic-gate 			tp->at_addr[2] = ibuf6[2];
22667c478bd9Sstevel@tonic-gate 			tp->at_addr[3] = ibuf6[3];
22677c478bd9Sstevel@tonic-gate 			tp->at_type = AU_IPv6;
22687c478bd9Sstevel@tonic-gate 		    }
22697c478bd9Sstevel@tonic-gate 		} else {
22707c478bd9Sstevel@tonic-gate 			phe = getipnodebyname((const void *)host_str,
22717c478bd9Sstevel@tonic-gate 				AF_INET, 0, &err);
22727c478bd9Sstevel@tonic-gate 			if (phe == 0) {
22737c478bd9Sstevel@tonic-gate 				phe = getipnodebyname((const void *)host_str,
22747c478bd9Sstevel@tonic-gate 					AF_INET6, 0, &err);
22757c478bd9Sstevel@tonic-gate 			}
22767c478bd9Sstevel@tonic-gate 
22777c478bd9Sstevel@tonic-gate 			if (phe != NULL) {
22787c478bd9Sstevel@tonic-gate 				if (phe->h_addrtype == AF_INET6) {
22797c478bd9Sstevel@tonic-gate 					/* address is IPv6 (128 bits) */
22807c478bd9Sstevel@tonic-gate 					(void) memcpy(&tp->at_addr[0],
22817c478bd9Sstevel@tonic-gate 						phe->h_addr_list[0], 16);
22827c478bd9Sstevel@tonic-gate 					tp->at_type = AU_IPv6;
22837c478bd9Sstevel@tonic-gate 				} else {
22847c478bd9Sstevel@tonic-gate 					/* address is IPv4 (32 bits) */
22857c478bd9Sstevel@tonic-gate 					(void) memcpy(&tp->at_addr[0],
22867c478bd9Sstevel@tonic-gate 						phe->h_addr_list[0], 4);
22877c478bd9Sstevel@tonic-gate 					tp->at_type = AU_IPv4;
22887c478bd9Sstevel@tonic-gate 				}
22897c478bd9Sstevel@tonic-gate 				freehostent(phe);
22907c478bd9Sstevel@tonic-gate 			}
22917c478bd9Sstevel@tonic-gate 		}
22927c478bd9Sstevel@tonic-gate 	}
22937c478bd9Sstevel@tonic-gate }
22947c478bd9Sstevel@tonic-gate 
22957c478bd9Sstevel@tonic-gate static int
22967c478bd9Sstevel@tonic-gate cond2str(cond, cond_str)
22977c478bd9Sstevel@tonic-gate 	uint_t cond;
22987c478bd9Sstevel@tonic-gate 	char *cond_str;
22997c478bd9Sstevel@tonic-gate {
23007c478bd9Sstevel@tonic-gate 	*cond_str = '\0';
23017c478bd9Sstevel@tonic-gate 
23027c478bd9Sstevel@tonic-gate 	if (cond == AUC_AUDITING) {
23037c478bd9Sstevel@tonic-gate 		(void) strcpy(cond_str, "auditing");
23047c478bd9Sstevel@tonic-gate 		return (0);
23057c478bd9Sstevel@tonic-gate 	}
23067c478bd9Sstevel@tonic-gate 
23077c478bd9Sstevel@tonic-gate 	if ((cond == AUC_NOAUDIT) || (cond == AUC_INIT_AUDIT)) {
23087c478bd9Sstevel@tonic-gate 		(void) strcpy(cond_str, "noaudit");
23097c478bd9Sstevel@tonic-gate 		return (0);
23107c478bd9Sstevel@tonic-gate 	}
23117c478bd9Sstevel@tonic-gate 
23127c478bd9Sstevel@tonic-gate 	if (cond == AUC_UNSET) {
23137c478bd9Sstevel@tonic-gate 		(void) strcpy(cond_str, "unset");
23147c478bd9Sstevel@tonic-gate 		return (0);
23157c478bd9Sstevel@tonic-gate 	}
23167c478bd9Sstevel@tonic-gate 
23177c478bd9Sstevel@tonic-gate 	if (cond == AUC_NOSPACE) {
23187c478bd9Sstevel@tonic-gate 		(void) strcpy(cond_str, "nospace");
23197c478bd9Sstevel@tonic-gate 		return (0);
23207c478bd9Sstevel@tonic-gate 	}
23217c478bd9Sstevel@tonic-gate 
23227c478bd9Sstevel@tonic-gate 	return (1);
23237c478bd9Sstevel@tonic-gate }
23247c478bd9Sstevel@tonic-gate 
23257c478bd9Sstevel@tonic-gate static struct policy_entry *
23267c478bd9Sstevel@tonic-gate get_policy_ent(policy)
23277c478bd9Sstevel@tonic-gate 	char *policy;
23287c478bd9Sstevel@tonic-gate {
23297c478bd9Sstevel@tonic-gate 	int i;
23307c478bd9Sstevel@tonic-gate 
2331*45916cd2Sjpk 	for (i = 0; i < POLICY_TBL_SZ; i++) {
2332*45916cd2Sjpk 		if ((policy_table[i].policy_flags & AC_TSOL) && !tsol_on)
2333*45916cd2Sjpk 			continue;	/* skip this entry */
2334*45916cd2Sjpk 		if (strcmp(strtolower(policy), policy_table[i].policy_str) == 0)
23357c478bd9Sstevel@tonic-gate 			return (&policy_table[i]);
2336*45916cd2Sjpk 	}
23377c478bd9Sstevel@tonic-gate 
23387c478bd9Sstevel@tonic-gate 	return ((struct policy_entry *)NULL);
23397c478bd9Sstevel@tonic-gate }
23407c478bd9Sstevel@tonic-gate 
23417c478bd9Sstevel@tonic-gate static int
23427c478bd9Sstevel@tonic-gate str2policy(char *policy_str, uint_t *policy_mask)
23437c478bd9Sstevel@tonic-gate {
23447c478bd9Sstevel@tonic-gate 	char		*buf;
23457c478bd9Sstevel@tonic-gate 	char		*tok;
23467c478bd9Sstevel@tonic-gate 	char		pfix;
23477c478bd9Sstevel@tonic-gate 	boolean_t	is_all = 0;
23487c478bd9Sstevel@tonic-gate 	uint_t		pm = 0;
23497c478bd9Sstevel@tonic-gate 	uint_t		curp = 0;
23507c478bd9Sstevel@tonic-gate 	struct		policy_entry *pep;
23517c478bd9Sstevel@tonic-gate 
23527c478bd9Sstevel@tonic-gate 	pfix = *policy_str;
23537c478bd9Sstevel@tonic-gate 
23547c478bd9Sstevel@tonic-gate 	if (pfix == '-' || pfix == '+' || pfix == '=')
23557c478bd9Sstevel@tonic-gate 		++policy_str;
23567c478bd9Sstevel@tonic-gate 
23577c478bd9Sstevel@tonic-gate 	if ((buf = strdup(policy_str)) == NULL)
23587c478bd9Sstevel@tonic-gate 		return (1);
23597c478bd9Sstevel@tonic-gate 
23607c478bd9Sstevel@tonic-gate 	for (tok = strtok(buf, ","); tok != NULL;
23617c478bd9Sstevel@tonic-gate 				tok = strtok(NULL, ",")) {
23627c478bd9Sstevel@tonic-gate 		if ((pep = get_policy_ent(tok)) == NULL) {
23637c478bd9Sstevel@tonic-gate 			return (1);
23647c478bd9Sstevel@tonic-gate 		} else {
23657c478bd9Sstevel@tonic-gate 			pm |= pep->policy_mask;
23667c478bd9Sstevel@tonic-gate 			if (pep->policy_mask == ALL_POLICIES)
23677c478bd9Sstevel@tonic-gate 				is_all = 1;
23687c478bd9Sstevel@tonic-gate 		}
23697c478bd9Sstevel@tonic-gate 	}
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate 	free(buf);
23727c478bd9Sstevel@tonic-gate 
23737c478bd9Sstevel@tonic-gate 	if (pfix == '-') {
23747c478bd9Sstevel@tonic-gate 		if (!is_all && (getzoneid() != GLOBAL_ZONEID) &&
23757c478bd9Sstevel@tonic-gate 		    (pm & ~AUDIT_LOCAL))
23767c478bd9Sstevel@tonic-gate 			return (2);
23777c478bd9Sstevel@tonic-gate 
23787c478bd9Sstevel@tonic-gate 		eauditon(A_GETPOLICY, (caddr_t)&curp, 0);
23797c478bd9Sstevel@tonic-gate 		if (getzoneid() != GLOBAL_ZONEID)
23807c478bd9Sstevel@tonic-gate 			curp &= AUDIT_LOCAL;
23817c478bd9Sstevel@tonic-gate 		*policy_mask = curp & ~pm;
23827c478bd9Sstevel@tonic-gate 	} else if (pfix == '+') {
23837c478bd9Sstevel@tonic-gate 		/*
23847c478bd9Sstevel@tonic-gate 		 * if the user is in a local zone and tries ahlt or
23857c478bd9Sstevel@tonic-gate 		 * perzone, that's an error.  But if the user uses "all"
23867c478bd9Sstevel@tonic-gate 		 * then make it work
23877c478bd9Sstevel@tonic-gate 		 */
23887c478bd9Sstevel@tonic-gate 		if (!is_all && (getzoneid() != GLOBAL_ZONEID) &&
23897c478bd9Sstevel@tonic-gate 		    (pm & ~AUDIT_LOCAL))
23907c478bd9Sstevel@tonic-gate 			return (2);
23917c478bd9Sstevel@tonic-gate 		eauditon(A_GETPOLICY, (caddr_t)&curp, 0);
23927c478bd9Sstevel@tonic-gate 		if (getzoneid() != GLOBAL_ZONEID) {
23937c478bd9Sstevel@tonic-gate 			curp &= AUDIT_LOCAL;
23947c478bd9Sstevel@tonic-gate 			if (is_all)
23957c478bd9Sstevel@tonic-gate 				pm &= AUDIT_LOCAL;
23967c478bd9Sstevel@tonic-gate 		}
23977c478bd9Sstevel@tonic-gate 		*policy_mask = curp | pm;
23987c478bd9Sstevel@tonic-gate 	} else {
23997c478bd9Sstevel@tonic-gate 		if (is_all && (getzoneid() != GLOBAL_ZONEID))
24007c478bd9Sstevel@tonic-gate 			pm &= AUDIT_LOCAL;
24017c478bd9Sstevel@tonic-gate 
24027c478bd9Sstevel@tonic-gate 		*policy_mask = pm;
24037c478bd9Sstevel@tonic-gate 	}
24047c478bd9Sstevel@tonic-gate 	return (0);
24057c478bd9Sstevel@tonic-gate }
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate static int
24087c478bd9Sstevel@tonic-gate policy2str(policy, policy_str, len)
24097c478bd9Sstevel@tonic-gate 	uint_t policy;
24107c478bd9Sstevel@tonic-gate 	char *policy_str;
24117c478bd9Sstevel@tonic-gate 	size_t len;
24127c478bd9Sstevel@tonic-gate {
24137c478bd9Sstevel@tonic-gate 	int i, j;
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate 	if (policy == ALL_POLICIES) {
24167c478bd9Sstevel@tonic-gate 		(void) strcpy(policy_str, "all");
24177c478bd9Sstevel@tonic-gate 		return (1);
24187c478bd9Sstevel@tonic-gate 	}
24197c478bd9Sstevel@tonic-gate 
24207c478bd9Sstevel@tonic-gate 	if (policy == NO_POLICIES) {
24217c478bd9Sstevel@tonic-gate 		(void) strcpy(policy_str, "none");
24227c478bd9Sstevel@tonic-gate 		return (1);
24237c478bd9Sstevel@tonic-gate 	}
24247c478bd9Sstevel@tonic-gate 
24257c478bd9Sstevel@tonic-gate 	*policy_str = '\0';
24267c478bd9Sstevel@tonic-gate 
2427*45916cd2Sjpk 	for (i = 0, j = 0; i < POLICY_TBL_SZ; i++) {
2428*45916cd2Sjpk 		if ((policy_table[i].policy_flags & AC_TSOL) && !tsol_on)
2429*45916cd2Sjpk 			continue;	/* skip this entry */
24307c478bd9Sstevel@tonic-gate 		if (policy & policy_table[i].policy_mask &&
24317c478bd9Sstevel@tonic-gate 		    policy_table[i].policy_mask != ALL_POLICIES) {
24327c478bd9Sstevel@tonic-gate 			if (j++)
24337c478bd9Sstevel@tonic-gate 				(void) strcat(policy_str, ",");
24347c478bd9Sstevel@tonic-gate 			(void) strlcat(policy_str,
24357c478bd9Sstevel@tonic-gate 			    policy_table[i].policy_str, len);
24367c478bd9Sstevel@tonic-gate 		}
2437*45916cd2Sjpk 	}
24387c478bd9Sstevel@tonic-gate 
24397c478bd9Sstevel@tonic-gate 	if (*policy_str)
24407c478bd9Sstevel@tonic-gate 		return (0);
24417c478bd9Sstevel@tonic-gate 
24427c478bd9Sstevel@tonic-gate 	return (1);
24437c478bd9Sstevel@tonic-gate }
24447c478bd9Sstevel@tonic-gate 
24457c478bd9Sstevel@tonic-gate 
24467c478bd9Sstevel@tonic-gate static int
24477c478bd9Sstevel@tonic-gate strisnum(s)
24487c478bd9Sstevel@tonic-gate 	char *s;
24497c478bd9Sstevel@tonic-gate {
24507c478bd9Sstevel@tonic-gate 	if (s == (char *)NULL || !*s)
24517c478bd9Sstevel@tonic-gate 		return (0);
24527c478bd9Sstevel@tonic-gate 
24537c478bd9Sstevel@tonic-gate 	for (; *s == '-' || *s == '+'; s++)
24547c478bd9Sstevel@tonic-gate 
24557c478bd9Sstevel@tonic-gate 	if (!*s)
24567c478bd9Sstevel@tonic-gate 		return (0);
24577c478bd9Sstevel@tonic-gate 
24587c478bd9Sstevel@tonic-gate 	for (; *s; s++)
24597c478bd9Sstevel@tonic-gate 		if (!isdigit(*s))
24607c478bd9Sstevel@tonic-gate 			return (0);
24617c478bd9Sstevel@tonic-gate 
24627c478bd9Sstevel@tonic-gate 	return (1);
24637c478bd9Sstevel@tonic-gate }
24647c478bd9Sstevel@tonic-gate 
24657c478bd9Sstevel@tonic-gate static int
24667c478bd9Sstevel@tonic-gate strisflags(s)
24677c478bd9Sstevel@tonic-gate 	char *s;
24687c478bd9Sstevel@tonic-gate {
24697c478bd9Sstevel@tonic-gate 	if (s == (char *)NULL || !*s)
24707c478bd9Sstevel@tonic-gate 		return (0);
24717c478bd9Sstevel@tonic-gate 
24727c478bd9Sstevel@tonic-gate 	for (; *s; s++) {
24737c478bd9Sstevel@tonic-gate 		if (!isalpha(*s) &&
24747c478bd9Sstevel@tonic-gate 			(*s != '+' && *s != '-' && *s != '^' && *s != ','))
24757c478bd9Sstevel@tonic-gate 			return (0);
24767c478bd9Sstevel@tonic-gate 	}
24777c478bd9Sstevel@tonic-gate 
24787c478bd9Sstevel@tonic-gate 	return (1);
24797c478bd9Sstevel@tonic-gate }
24807c478bd9Sstevel@tonic-gate 
24817c478bd9Sstevel@tonic-gate static int
24827c478bd9Sstevel@tonic-gate strisipaddr(s)
24837c478bd9Sstevel@tonic-gate 	char *s;
24847c478bd9Sstevel@tonic-gate {
24857c478bd9Sstevel@tonic-gate 	int dot = 0;
24867c478bd9Sstevel@tonic-gate 	int colon = 0;
24877c478bd9Sstevel@tonic-gate 
24887c478bd9Sstevel@tonic-gate 	/* no string */
24897c478bd9Sstevel@tonic-gate 	if ((s == (char *)NULL) || (!*s))
24907c478bd9Sstevel@tonic-gate 		return (0);
24917c478bd9Sstevel@tonic-gate 
24927c478bd9Sstevel@tonic-gate 	for (; *s; s++) {
24937c478bd9Sstevel@tonic-gate 		if (!(isxdigit(*s) || *s != '.' || *s != ':'))
24947c478bd9Sstevel@tonic-gate 			return (0);
24957c478bd9Sstevel@tonic-gate 		if (*s == '.') dot++;
24967c478bd9Sstevel@tonic-gate 		if (*s == ':') colon++;
24977c478bd9Sstevel@tonic-gate 	}
24987c478bd9Sstevel@tonic-gate 
24997c478bd9Sstevel@tonic-gate 	if (dot && colon)
25007c478bd9Sstevel@tonic-gate 		return (0);
25017c478bd9Sstevel@tonic-gate 
25027c478bd9Sstevel@tonic-gate 	if (!dot && !colon)
25037c478bd9Sstevel@tonic-gate 		return (0);
25047c478bd9Sstevel@tonic-gate 
25057c478bd9Sstevel@tonic-gate 	return (1);
25067c478bd9Sstevel@tonic-gate }
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate static void
25097c478bd9Sstevel@tonic-gate strsplit(s, p1, p2, c)
25107c478bd9Sstevel@tonic-gate 	char *s;
25117c478bd9Sstevel@tonic-gate 	char *p1;
25127c478bd9Sstevel@tonic-gate 	char *p2;
25137c478bd9Sstevel@tonic-gate 	char c;
25147c478bd9Sstevel@tonic-gate {
25157c478bd9Sstevel@tonic-gate 	*p1 = *p2 = '\0';
25167c478bd9Sstevel@tonic-gate 
25177c478bd9Sstevel@tonic-gate 	while (*s != '\0' && *s != c)
25187c478bd9Sstevel@tonic-gate 		*p1++ = *s++;
25197c478bd9Sstevel@tonic-gate 	*p1 = '\0';
25207c478bd9Sstevel@tonic-gate 	s++;
25217c478bd9Sstevel@tonic-gate 
25227c478bd9Sstevel@tonic-gate 	while (*s != '\0')
25237c478bd9Sstevel@tonic-gate 		*p2++ = *s++;
25247c478bd9Sstevel@tonic-gate 	*p2 = '\0';
25257c478bd9Sstevel@tonic-gate }
25267c478bd9Sstevel@tonic-gate 
25277c478bd9Sstevel@tonic-gate static char *
25287c478bd9Sstevel@tonic-gate strtolower(s)
25297c478bd9Sstevel@tonic-gate 	char *s;
25307c478bd9Sstevel@tonic-gate {
25317c478bd9Sstevel@tonic-gate 	char *save;
25327c478bd9Sstevel@tonic-gate 
25337c478bd9Sstevel@tonic-gate 	for (save = s; *s; s++)
25347c478bd9Sstevel@tonic-gate 		(void) tolower(*s);
25357c478bd9Sstevel@tonic-gate 
25367c478bd9Sstevel@tonic-gate 	return (save);
25377c478bd9Sstevel@tonic-gate }
25387c478bd9Sstevel@tonic-gate 
25397c478bd9Sstevel@tonic-gate static void
25407c478bd9Sstevel@tonic-gate chk_event_num(etype, event)
25417c478bd9Sstevel@tonic-gate 	int etype;
25427c478bd9Sstevel@tonic-gate 	au_event_t event;
25437c478bd9Sstevel@tonic-gate {
25447c478bd9Sstevel@tonic-gate 	au_stat_t as;
25457c478bd9Sstevel@tonic-gate 
25467c478bd9Sstevel@tonic-gate 	eauditon(A_GETSTAT, (caddr_t)&as, 0);
25477c478bd9Sstevel@tonic-gate 
25487c478bd9Sstevel@tonic-gate 	if (etype == AC_KERN_EVENT) {
25497c478bd9Sstevel@tonic-gate 		if (event > as.as_numevent) {
25507c478bd9Sstevel@tonic-gate 			exit_error(gettext("Invalid kernel audit event number "
25517c478bd9Sstevel@tonic-gate 			"specified.\n\t%d is outside allowable range 0-%d."),
25527c478bd9Sstevel@tonic-gate 			    event, as.as_numevent);
25537c478bd9Sstevel@tonic-gate 		}
25547c478bd9Sstevel@tonic-gate 	} else  { /* user event */
25557c478bd9Sstevel@tonic-gate 		if (event <= as.as_numevent) {
25567c478bd9Sstevel@tonic-gate 			exit_error(gettext(
25577c478bd9Sstevel@tonic-gate 			"Invalid user level audit event number specified %d."),
25587c478bd9Sstevel@tonic-gate 				event);
25597c478bd9Sstevel@tonic-gate 		}
25607c478bd9Sstevel@tonic-gate 	}
25617c478bd9Sstevel@tonic-gate }
25627c478bd9Sstevel@tonic-gate 
25637c478bd9Sstevel@tonic-gate static void
25647c478bd9Sstevel@tonic-gate chk_event_str(etype, event_str)
25657c478bd9Sstevel@tonic-gate 	int etype;
25667c478bd9Sstevel@tonic-gate 	char *event_str;
25677c478bd9Sstevel@tonic-gate {
25687c478bd9Sstevel@tonic-gate 	au_event_ent_t *evp;
25697c478bd9Sstevel@tonic-gate 	au_stat_t as;
25707c478bd9Sstevel@tonic-gate 
25717c478bd9Sstevel@tonic-gate 	eauditon(A_GETSTAT, (caddr_t)&as, 0);
25727c478bd9Sstevel@tonic-gate 
25737c478bd9Sstevel@tonic-gate 	evp = egetauevnam(event_str);
25747c478bd9Sstevel@tonic-gate 	if (etype == AC_KERN_EVENT && (evp->ae_number > as.as_numevent)) {
25757c478bd9Sstevel@tonic-gate 		exit_error(
25767c478bd9Sstevel@tonic-gate 		    gettext("Invalid kernel audit event string specified.\n"
25777c478bd9Sstevel@tonic-gate 			"\t\"%s\" appears to be a user level event. "
25787c478bd9Sstevel@tonic-gate 			"Check configuration."),
25797c478bd9Sstevel@tonic-gate 		    event_str);
25807c478bd9Sstevel@tonic-gate 	} else if (etype == AC_USER_EVENT &&
25817c478bd9Sstevel@tonic-gate 			(evp->ae_number < as.as_numevent)) {
25827c478bd9Sstevel@tonic-gate 		exit_error(
25837c478bd9Sstevel@tonic-gate 		    gettext("Invalid user audit event string specified.\n"
25847c478bd9Sstevel@tonic-gate 			"\t\"%s\" appears to be a kernel event. "
25857c478bd9Sstevel@tonic-gate 			"Check configuration."),
25867c478bd9Sstevel@tonic-gate 		    event_str);
25877c478bd9Sstevel@tonic-gate 	}
25887c478bd9Sstevel@tonic-gate }
25897c478bd9Sstevel@tonic-gate 
25907c478bd9Sstevel@tonic-gate static void
25917c478bd9Sstevel@tonic-gate chk_sorf(sorf_str)
25927c478bd9Sstevel@tonic-gate 	char *sorf_str;
25937c478bd9Sstevel@tonic-gate {
25947c478bd9Sstevel@tonic-gate 	if (!strisnum(sorf_str))
25957c478bd9Sstevel@tonic-gate 		exit_error(gettext("Invalid sorf specified: %s"), sorf_str);
25967c478bd9Sstevel@tonic-gate }
25977c478bd9Sstevel@tonic-gate 
25987c478bd9Sstevel@tonic-gate static void
25997c478bd9Sstevel@tonic-gate chk_retval(retval_str)
26007c478bd9Sstevel@tonic-gate 	char *retval_str;
26017c478bd9Sstevel@tonic-gate {
26027c478bd9Sstevel@tonic-gate 	if (!strisnum(retval_str))
26037c478bd9Sstevel@tonic-gate 		exit_error(gettext("Invalid retval specified: %s"), retval_str);
26047c478bd9Sstevel@tonic-gate }
26057c478bd9Sstevel@tonic-gate 
26067c478bd9Sstevel@tonic-gate static void
26077c478bd9Sstevel@tonic-gate chk_tid(tid_str)
26087c478bd9Sstevel@tonic-gate 	char *tid_str;
26097c478bd9Sstevel@tonic-gate {
26107c478bd9Sstevel@tonic-gate 	int c;
26117c478bd9Sstevel@tonic-gate 	char *p;
26127c478bd9Sstevel@tonic-gate 
26137c478bd9Sstevel@tonic-gate 	/* need two commas (maj,min,hostname) */
26147c478bd9Sstevel@tonic-gate 
26157c478bd9Sstevel@tonic-gate 
26167c478bd9Sstevel@tonic-gate 	for (p = tid_str, c = 0; *p; p++)
26177c478bd9Sstevel@tonic-gate 		if (*p == ',')
26187c478bd9Sstevel@tonic-gate 			++c;
26197c478bd9Sstevel@tonic-gate 	if (c != 2)
26207c478bd9Sstevel@tonic-gate 		exit_error(gettext("Invalid tid specified: %s"), tid_str);
26217c478bd9Sstevel@tonic-gate }
26227c478bd9Sstevel@tonic-gate 
26237c478bd9Sstevel@tonic-gate static void
26247c478bd9Sstevel@tonic-gate execit(argv)
26257c478bd9Sstevel@tonic-gate 	char **argv;
26267c478bd9Sstevel@tonic-gate {
26277c478bd9Sstevel@tonic-gate 	char *shell;
26287c478bd9Sstevel@tonic-gate 
26297c478bd9Sstevel@tonic-gate 	if (*argv)
26307c478bd9Sstevel@tonic-gate 		(void) execvp(*argv, argv);
26317c478bd9Sstevel@tonic-gate 	else {
26327c478bd9Sstevel@tonic-gate 		if (((shell = getenv("SHELL")) == (char *)NULL) ||
26337c478bd9Sstevel@tonic-gate 			*shell != '/')
26347c478bd9Sstevel@tonic-gate 			shell = "/bin/csh";
26357c478bd9Sstevel@tonic-gate 
26367c478bd9Sstevel@tonic-gate 		(void) execlp(shell, shell, (char *)NULL);
26377c478bd9Sstevel@tonic-gate 	}
26387c478bd9Sstevel@tonic-gate 
26397c478bd9Sstevel@tonic-gate 	exit_error(gettext("exec(2) failed"));
26407c478bd9Sstevel@tonic-gate }
26417c478bd9Sstevel@tonic-gate 
26427c478bd9Sstevel@tonic-gate /*
26437c478bd9Sstevel@tonic-gate  * exit_error()
26447c478bd9Sstevel@tonic-gate  *     Desc: Prints an error message along with corresponding system
26457c478bd9Sstevel@tonic-gate  *                  error number and error message, then exits.
26467c478bd9Sstevel@tonic-gate  *     Inputs: Program name, program error message.
26477c478bd9Sstevel@tonic-gate  */
26487c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
26497c478bd9Sstevel@tonic-gate static void
26507c478bd9Sstevel@tonic-gate exit_error(char *fmt, ...)
26517c478bd9Sstevel@tonic-gate {
26527c478bd9Sstevel@tonic-gate 	va_list args;
26537c478bd9Sstevel@tonic-gate 
26547c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: ", progname);
26557c478bd9Sstevel@tonic-gate 
26567c478bd9Sstevel@tonic-gate 	va_start(args, fmt);
26577c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, args);
26587c478bd9Sstevel@tonic-gate 	va_end(args);
26597c478bd9Sstevel@tonic-gate 
26607c478bd9Sstevel@tonic-gate 	(void) fputc('\n', stderr);
26617c478bd9Sstevel@tonic-gate 	if (errno)
26627c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: error = %s(%d)\n"),
26637c478bd9Sstevel@tonic-gate 			progname, strerror(errno), errno);
26647c478bd9Sstevel@tonic-gate 	(void) fflush(stderr);
26657c478bd9Sstevel@tonic-gate 
26667c478bd9Sstevel@tonic-gate 	exit(1);
26677c478bd9Sstevel@tonic-gate }
26687c478bd9Sstevel@tonic-gate 
26697c478bd9Sstevel@tonic-gate static void
26707c478bd9Sstevel@tonic-gate exit_usage(status)
26717c478bd9Sstevel@tonic-gate 	int status;
26727c478bd9Sstevel@tonic-gate {
26737c478bd9Sstevel@tonic-gate 	FILE *fp;
26747c478bd9Sstevel@tonic-gate 	int i;
26757c478bd9Sstevel@tonic-gate 
26767c478bd9Sstevel@tonic-gate 	fp = (status ? stderr : stdout);
26777c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, gettext("usage: %s option ...\n"), progname);
26787c478bd9Sstevel@tonic-gate 
26797c478bd9Sstevel@tonic-gate 	for (i = 0; i < ARG2_TBL_SZ; i++)
26807c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, " %s %s\n",
26817c478bd9Sstevel@tonic-gate 			arg2_table[i].arg_str, arg2_table[i].arg_opts);
26827c478bd9Sstevel@tonic-gate 
26837c478bd9Sstevel@tonic-gate 	exit(status);
26847c478bd9Sstevel@tonic-gate }
26857c478bd9Sstevel@tonic-gate 
26867c478bd9Sstevel@tonic-gate static void
26877c478bd9Sstevel@tonic-gate print_asid(asid)
26887c478bd9Sstevel@tonic-gate 	au_asid_t asid;
26897c478bd9Sstevel@tonic-gate {
26907c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit session id = %u\n"), asid);
26917c478bd9Sstevel@tonic-gate }
26927c478bd9Sstevel@tonic-gate 
26937c478bd9Sstevel@tonic-gate static void
26947c478bd9Sstevel@tonic-gate print_auid(auid)
26957c478bd9Sstevel@tonic-gate 	au_id_t auid;
26967c478bd9Sstevel@tonic-gate {
26977c478bd9Sstevel@tonic-gate 	struct passwd *pwd;
26987c478bd9Sstevel@tonic-gate 	char *username;
26997c478bd9Sstevel@tonic-gate 
27007c478bd9Sstevel@tonic-gate 	setpwent();
27017c478bd9Sstevel@tonic-gate 	if ((pwd = getpwuid((uid_t)auid)) != (struct passwd *)NULL)
27027c478bd9Sstevel@tonic-gate 		username = pwd->pw_name;
27037c478bd9Sstevel@tonic-gate 	else
27047c478bd9Sstevel@tonic-gate 		username = gettext("unknown");
27057c478bd9Sstevel@tonic-gate 	endpwent();
27067c478bd9Sstevel@tonic-gate 
27077c478bd9Sstevel@tonic-gate 	(void) printf(gettext("audit id = %s(%d)\n"), username, auid);
27087c478bd9Sstevel@tonic-gate }
27097c478bd9Sstevel@tonic-gate 
27107c478bd9Sstevel@tonic-gate static void
27117c478bd9Sstevel@tonic-gate print_mask(desc, pmp)
27127c478bd9Sstevel@tonic-gate 	char *desc;
27137c478bd9Sstevel@tonic-gate 	au_mask_t *pmp;
27147c478bd9Sstevel@tonic-gate {
27157c478bd9Sstevel@tonic-gate 	char auflags[512];
27167c478bd9Sstevel@tonic-gate 
27177c478bd9Sstevel@tonic-gate 	if (getauditflagschar(auflags, pmp, NULL) < 0)
27187c478bd9Sstevel@tonic-gate 		(void) strlcpy(auflags, gettext("unknown"), sizeof (auflags));
27197c478bd9Sstevel@tonic-gate 
27207c478bd9Sstevel@tonic-gate 	(void) printf("%s = %s(0x%x,0x%x)\n",
27217c478bd9Sstevel@tonic-gate 		desc, auflags, pmp->am_success, pmp->am_failure);
27227c478bd9Sstevel@tonic-gate }
27237c478bd9Sstevel@tonic-gate 
27247c478bd9Sstevel@tonic-gate static void
27257c478bd9Sstevel@tonic-gate print_mask1(desc, mask1)
27267c478bd9Sstevel@tonic-gate 	char *desc;
27277c478bd9Sstevel@tonic-gate 	au_class_t	mask1;
27287c478bd9Sstevel@tonic-gate {
27297c478bd9Sstevel@tonic-gate 	(void) printf("%s = 0x%x\n", desc, (int)mask1);
27307c478bd9Sstevel@tonic-gate }
27317c478bd9Sstevel@tonic-gate 
27327c478bd9Sstevel@tonic-gate static void
27337c478bd9Sstevel@tonic-gate print_stats(s)
27347c478bd9Sstevel@tonic-gate 	au_stat_t *s;
27357c478bd9Sstevel@tonic-gate {
27367c478bd9Sstevel@tonic-gate 	int offset[12];   /* used to line the header up correctly */
27377c478bd9Sstevel@tonic-gate 	char buf[512];
27387c478bd9Sstevel@tonic-gate 
27397c478bd9Sstevel@tonic-gate 	(void) sprintf(buf, "%4lu %n%4lu %n%4lu %n%4lu %n%4lu %n%4lu %n%4lu "
27407c478bd9Sstevel@tonic-gate 	    "%n%4lu %n%4lu %n%4lu %n%4lu %n%4lu%n",
27417c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_generated,	&(offset[0]),
27427c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_nonattrib,	&(offset[1]),
27437c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_kernel,	&(offset[2]),
27447c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_audit,	&(offset[3]),
27457c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_auditctl,	&(offset[4]),
27467c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_enqueue,	&(offset[5]),
27477c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_written,	&(offset[6]),
27487c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_wblocked,	&(offset[7]),
27497c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_rblocked,	&(offset[8]),
27507c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_dropped,	&(offset[9]),
27517c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_totalsize / ONEK, &(offset[10]),
27527c478bd9Sstevel@tonic-gate 	    (ulong_t)s->as_memused / ONEK, &(offset[11]));
27537c478bd9Sstevel@tonic-gate 
27547c478bd9Sstevel@tonic-gate 	/*
27557c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
27567c478bd9Sstevel@tonic-gate 	 *	Print a properly aligned header.
27577c478bd9Sstevel@tonic-gate 	 */
27587c478bd9Sstevel@tonic-gate 	(void) printf("%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",
27597c478bd9Sstevel@tonic-gate 		offset[0] - 1,			gettext("gen"),
27607c478bd9Sstevel@tonic-gate 		offset[1] - offset[0] -1,	gettext("nona"),
27617c478bd9Sstevel@tonic-gate 		offset[2] - offset[1] -1,	gettext("kern"),
27627c478bd9Sstevel@tonic-gate 		offset[3] - offset[2] -1,	gettext("aud"),
27637c478bd9Sstevel@tonic-gate 		offset[4] - offset[3] -1,	gettext("ctl"),
27647c478bd9Sstevel@tonic-gate 		offset[5] - offset[4] -1,	gettext("enq"),
27657c478bd9Sstevel@tonic-gate 		offset[6] - offset[5] -1,	gettext("wrtn"),
27667c478bd9Sstevel@tonic-gate 		offset[7] - offset[6] -1,	gettext("wblk"),
27677c478bd9Sstevel@tonic-gate 		offset[8] - offset[7] -1,	gettext("rblk"),
27687c478bd9Sstevel@tonic-gate 		offset[9] - offset[8] -1,	gettext("drop"),
27697c478bd9Sstevel@tonic-gate 		offset[10] - offset[9] -1,	gettext("tot"),
27707c478bd9Sstevel@tonic-gate 		offset[11] - offset[10],	gettext("mem"));
27717c478bd9Sstevel@tonic-gate 
27727c478bd9Sstevel@tonic-gate 	(void) puts(buf);
27737c478bd9Sstevel@tonic-gate }
27747c478bd9Sstevel@tonic-gate 
27757c478bd9Sstevel@tonic-gate static void
27767c478bd9Sstevel@tonic-gate print_tid_ex(tidp)
27777c478bd9Sstevel@tonic-gate 	au_tid_addr_t *tidp;
27787c478bd9Sstevel@tonic-gate {
27797c478bd9Sstevel@tonic-gate 	struct hostent *phe;
27807c478bd9Sstevel@tonic-gate 	char *hostname;
27817c478bd9Sstevel@tonic-gate 	struct in_addr ia;
27827c478bd9Sstevel@tonic-gate 	uint32_t *addr;
27837c478bd9Sstevel@tonic-gate 	int err;
27847c478bd9Sstevel@tonic-gate 	char buf[256];
27857c478bd9Sstevel@tonic-gate 	char *bufp;
27867c478bd9Sstevel@tonic-gate 
27877c478bd9Sstevel@tonic-gate 
27887c478bd9Sstevel@tonic-gate 	/* IPV6 or IPV4 address */
27897c478bd9Sstevel@tonic-gate 	if (tidp->at_type == AU_IPv4) {
27907c478bd9Sstevel@tonic-gate 		if ((phe = gethostbyaddr((char *)&tidp->at_addr[0],
27917c478bd9Sstevel@tonic-gate 					sizeof (tidp->at_addr[0]),
27927c478bd9Sstevel@tonic-gate 					AF_INET)) != (struct hostent *)NULL)
27937c478bd9Sstevel@tonic-gate 			hostname = phe->h_name;
27947c478bd9Sstevel@tonic-gate 		else
27957c478bd9Sstevel@tonic-gate 			hostname = gettext("unknown");
27967c478bd9Sstevel@tonic-gate 
27977c478bd9Sstevel@tonic-gate 		ia.s_addr = tidp->at_addr[0];
27987c478bd9Sstevel@tonic-gate 
27997c478bd9Sstevel@tonic-gate 		(void) printf(gettext(
28007c478bd9Sstevel@tonic-gate 			"terminal id (maj,min,host) = %u,%u,%s(%s)\n"),
28017c478bd9Sstevel@tonic-gate 			major(tidp->at_port), minor(tidp->at_port),
28027c478bd9Sstevel@tonic-gate 			hostname, inet_ntoa(ia));
28037c478bd9Sstevel@tonic-gate 	} else {
28047c478bd9Sstevel@tonic-gate 		addr = &tidp->at_addr[0];
28057c478bd9Sstevel@tonic-gate 		phe = getipnodebyaddr((const void *)addr, 16, AF_INET6, &err);
28067c478bd9Sstevel@tonic-gate 
28077c478bd9Sstevel@tonic-gate 		bzero(buf, sizeof (buf));
28087c478bd9Sstevel@tonic-gate 
28097c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *)addr, buf,
28107c478bd9Sstevel@tonic-gate 						sizeof (buf));
28117c478bd9Sstevel@tonic-gate 		if (phe == (struct hostent *)0) {
28127c478bd9Sstevel@tonic-gate 			bufp = gettext("unknown");
28137c478bd9Sstevel@tonic-gate 		} else
28147c478bd9Sstevel@tonic-gate 			bufp = phe->h_name;
28157c478bd9Sstevel@tonic-gate 
28167c478bd9Sstevel@tonic-gate 		(void) printf(gettext(
28177c478bd9Sstevel@tonic-gate 			"terminal id (maj,min,host) = %u,%u,%s(%s)\n"),
28187c478bd9Sstevel@tonic-gate 			major(tidp->at_port), minor(tidp->at_port),
28197c478bd9Sstevel@tonic-gate 			bufp, buf);
28207c478bd9Sstevel@tonic-gate 		if (phe)
28217c478bd9Sstevel@tonic-gate 			freehostent(phe);
28227c478bd9Sstevel@tonic-gate 	}
28237c478bd9Sstevel@tonic-gate }
28247c478bd9Sstevel@tonic-gate 
28257c478bd9Sstevel@tonic-gate static int
28267c478bd9Sstevel@tonic-gate str2ipaddr(s, addr, type)
28277c478bd9Sstevel@tonic-gate 	char *s;
28287c478bd9Sstevel@tonic-gate 	uint32_t *addr;
28297c478bd9Sstevel@tonic-gate 	uint32_t type;
28307c478bd9Sstevel@tonic-gate {
28317c478bd9Sstevel@tonic-gate 	int j, sl;
28327c478bd9Sstevel@tonic-gate 	char *ss;
28337c478bd9Sstevel@tonic-gate 	unsigned int v;
28347c478bd9Sstevel@tonic-gate 
28357c478bd9Sstevel@tonic-gate 	bzero(addr, 16);
28367c478bd9Sstevel@tonic-gate 	if (strisipaddr(s)) {
28377c478bd9Sstevel@tonic-gate 		if (type == AU_IPv4) {
28387c478bd9Sstevel@tonic-gate 			if (inet_pton(AF_INET, s, addr))
28397c478bd9Sstevel@tonic-gate 				return (0);
28407c478bd9Sstevel@tonic-gate 			return (1);
28417c478bd9Sstevel@tonic-gate 		}
28427c478bd9Sstevel@tonic-gate 		if (type == AU_IPv6) {
28437c478bd9Sstevel@tonic-gate 			if (inet_pton(AF_INET6, s, addr))
28447c478bd9Sstevel@tonic-gate 				return (0);
28457c478bd9Sstevel@tonic-gate 			return (1);
28467c478bd9Sstevel@tonic-gate 		}
28477c478bd9Sstevel@tonic-gate 		return (1);
28487c478bd9Sstevel@tonic-gate 	} else {
28497c478bd9Sstevel@tonic-gate 		if (type == AU_IPv4) {
28507c478bd9Sstevel@tonic-gate 			(void) sscanf(s, "%x", &addr[0]);
28517c478bd9Sstevel@tonic-gate 			return (0);
28527c478bd9Sstevel@tonic-gate 		}
28537c478bd9Sstevel@tonic-gate 		if (type == AU_IPv6) {
28547c478bd9Sstevel@tonic-gate 			sl = strlen(s);
28557c478bd9Sstevel@tonic-gate 			ss = s;
28567c478bd9Sstevel@tonic-gate 			for (j = 3; j >= 0; j--) {
28577c478bd9Sstevel@tonic-gate 				if ((sl - 8) <= 0) {
28587c478bd9Sstevel@tonic-gate 					(void) sscanf(s, "%x", &v);
28597c478bd9Sstevel@tonic-gate 					addr[j] = v;
28607c478bd9Sstevel@tonic-gate 					return (0);
28617c478bd9Sstevel@tonic-gate 				}
28627c478bd9Sstevel@tonic-gate 				ss = &s[sl-8];
28637c478bd9Sstevel@tonic-gate 				(void) sscanf(ss, "%x", &v);
28647c478bd9Sstevel@tonic-gate 				addr[j] = v;
28657c478bd9Sstevel@tonic-gate 				sl -= 8;
28667c478bd9Sstevel@tonic-gate 				*ss = '\0';
28677c478bd9Sstevel@tonic-gate 			}
28687c478bd9Sstevel@tonic-gate 		}
28697c478bd9Sstevel@tonic-gate 		return (0);
28707c478bd9Sstevel@tonic-gate 	}
28717c478bd9Sstevel@tonic-gate }
28727c478bd9Sstevel@tonic-gate 
28737c478bd9Sstevel@tonic-gate static int
28747c478bd9Sstevel@tonic-gate str2type(s, type)
28757c478bd9Sstevel@tonic-gate 	char *s;
28767c478bd9Sstevel@tonic-gate 	uint_t *type;
28777c478bd9Sstevel@tonic-gate {
28787c478bd9Sstevel@tonic-gate 	if (strcmp(s, "ipv6") == 0) {
28797c478bd9Sstevel@tonic-gate 		*type = AU_IPv6;
28807c478bd9Sstevel@tonic-gate 		return (0);
28817c478bd9Sstevel@tonic-gate 	}
28827c478bd9Sstevel@tonic-gate 	if (strcmp(s, "ipv4") == 0) {
28837c478bd9Sstevel@tonic-gate 		*type = AU_IPv4;
28847c478bd9Sstevel@tonic-gate 		return (0);
28857c478bd9Sstevel@tonic-gate 	}
28867c478bd9Sstevel@tonic-gate 
28877c478bd9Sstevel@tonic-gate 	return (1);
28887c478bd9Sstevel@tonic-gate }
2889