xref: /illumos-gate/usr/src/cmd/auditd/auditd.c (revision 17b6b3808f6f7a84408070a1a441854f7e70b784)
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
59697ae98Sgww  * Common Development and Distribution License (the "License").
69697ae98Sgww  * 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 /*
22c900e163Sgww  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /* Audit daemon server */
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * These routines make up the audit daemon server.  This daemon, called
297c478bd9Sstevel@tonic-gate  * auditd, handles the user level parts of auditing.  It receives buffered
307c478bd9Sstevel@tonic-gate  * audit records (usually one or more per buffer, potentially less than
317c478bd9Sstevel@tonic-gate  * one) and passes them to one or more plugins for processing.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * The major interrupts are AU_SIG_READ_CONTROL (start over),
347c478bd9Sstevel@tonic-gate  * AU_SIG_DISABLE (start shutting down), SIGALRM (quit), and
357c478bd9Sstevel@tonic-gate  * AU_SIG_NEXT_DIR (start a new audit log file). SIGTERM (the implementation
367c478bd9Sstevel@tonic-gate  * value of AU_SIG_DISABLE) is also used for the child to tell the parent
377c478bd9Sstevel@tonic-gate  * that audit is ready.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * Configuration data comes from /etc/security/audit_control and the auditon
407c478bd9Sstevel@tonic-gate  * system call.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * The major errors are EBUSY (auditing is already in use) and EINTR
437c478bd9Sstevel@tonic-gate  * (one of the above signals was received).  File space errors are
447c478bd9Sstevel@tonic-gate  * handled by the audit_binfile plugin
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
478523fda3SJan Friedel /* #define	DEBUG    - define for debug messages to be generated */
488523fda3SJan Friedel /* #define	MEM_TEST - define to generate core dump on exit */
497c478bd9Sstevel@tonic-gate #define	DEBUG		0
508523fda3SJan Friedel #define	MEM_TEST	0
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <assert.h>
539697ae98Sgww #include <bsm/adt.h>
547c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
557c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
567c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
577c478bd9Sstevel@tonic-gate #include <fcntl.h>
587c478bd9Sstevel@tonic-gate #include <libintl.h>
597c478bd9Sstevel@tonic-gate #include <locale.h>
607c478bd9Sstevel@tonic-gate #include <netdb.h>
617c478bd9Sstevel@tonic-gate #include <pwd.h>
627c478bd9Sstevel@tonic-gate #include <secdb.h>
637c478bd9Sstevel@tonic-gate #include <signal.h>
647c478bd9Sstevel@tonic-gate #include <stdio.h>
657c478bd9Sstevel@tonic-gate #include <stdlib.h>
667c478bd9Sstevel@tonic-gate #include <string.h>
679697ae98Sgww #include <syslog.h>
687c478bd9Sstevel@tonic-gate #include <errno.h>
697c478bd9Sstevel@tonic-gate #include <sys/file.h>
707c478bd9Sstevel@tonic-gate #include <sys/param.h>
717c478bd9Sstevel@tonic-gate #include <sys/stat.h>
727c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
737c478bd9Sstevel@tonic-gate #include <sys/time.h>
747c478bd9Sstevel@tonic-gate #include <sys/types.h>
757c478bd9Sstevel@tonic-gate #include <sys/wait.h>
767c478bd9Sstevel@tonic-gate #include <termios.h>
777c478bd9Sstevel@tonic-gate #include <unistd.h>
787c478bd9Sstevel@tonic-gate #include "plugin.h"
797c478bd9Sstevel@tonic-gate #include "audit_sig_infc.h"
807c478bd9Sstevel@tonic-gate #include <audit_plugin.h>
818523fda3SJan Friedel #include <audit_scf.h>
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
847c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SUNW_OST_OSCMD"
857c478bd9Sstevel@tonic-gate #endif
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * After we get a AU_SIG_DISABLE, we want to set a timer for 2 seconds
887c478bd9Sstevel@tonic-gate  * and let c2audit write as many records as it can until the timer
897c478bd9Sstevel@tonic-gate  * goes off(at which point it returns to auditd with SIGALRM).  If any
907c478bd9Sstevel@tonic-gate  * other signals are received during that time, we call
917c478bd9Sstevel@tonic-gate  * __audit_dowarn() to indicate that the queue may not have been fully
927c478bd9Sstevel@tonic-gate  * flushed.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	ALRM_TIME	2
957c478bd9Sstevel@tonic-gate #define	SLEEP_TIME	20	/* # of seconds to sleep in all hard loop */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate static plugin_t	*binfile = NULL;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate static int	turn_audit_on  = AUC_AUDITING;
1007c478bd9Sstevel@tonic-gate static int	turn_audit_off = AUC_NOAUDIT;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static int	running = 1;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * GLOBALS:
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate plugin_t		*plugin_head = NULL;
1087c478bd9Sstevel@tonic-gate static thr_data_t	main_thr;	/* auditd thread (0) */
1097c478bd9Sstevel@tonic-gate pthread_mutex_t		plugin_mutex;	/* for plugin_t list */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate static int	caught_alrm = 0;	/* number of SIGALRMs pending */
1127c478bd9Sstevel@tonic-gate static int	caught_readc = 0;	/* number of AU_SIG_READ_CONTROLs */
1137c478bd9Sstevel@tonic-gate static int	caught_term = 0;	/* number of AU_SIG_DISABLEs pending */
1147c478bd9Sstevel@tonic-gate static int	caught_nextd = 0;	/* number of AU_SIG_NEXT_DIRs pending */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate static int	reset_list = 1;	/* 1 to re-read audit_control */
1177c478bd9Sstevel@tonic-gate static int	reset_file = 1; /* 1 to close/open binary log */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate static int	auditing_set = 0;	/* 1 if auditon(A_SETCOND, on... */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate static void	my_sleep();
1227c478bd9Sstevel@tonic-gate static void	signal_thread();
1237c478bd9Sstevel@tonic-gate static void	loadauditlist();
1247c478bd9Sstevel@tonic-gate static void	block_signals();
1257c478bd9Sstevel@tonic-gate static int	do_sethost();
1267c478bd9Sstevel@tonic-gate 
1278523fda3SJan Friedel static void	conf_to_kernel();
1288523fda3SJan Friedel static void	aconf_to_kernel();
1298523fda3SJan Friedel static void	scf_to_kernel_qctrl();
1308523fda3SJan Friedel static void	scf_to_kernel_policy();
1318523fda3SJan Friedel 
1328523fda3SJan Friedel /*
1338523fda3SJan Friedel  * err_exit() - exit function after the unsuccessful call to auditon();
1348523fda3SJan Friedel  * prints_out / saves_via_syslog the necessary error messages.
1358523fda3SJan Friedel  */
1368523fda3SJan Friedel static void
137*17b6b380SJan Friedel err_exit(char *msg)
1388523fda3SJan Friedel {
1398523fda3SJan Friedel 	if (msg != NULL) {
1408523fda3SJan Friedel 		DPRINT((dbfp, "%s\n", msg));
1418523fda3SJan Friedel 		__audit_syslog("auditd", LOG_PID | LOG_CONS | LOG_NOWAIT,
1428523fda3SJan Friedel 		    LOG_DAEMON, LOG_ALERT, msg);
1438523fda3SJan Friedel 		free(msg);
1448523fda3SJan Friedel 	} else {
1458523fda3SJan Friedel 		DPRINT((dbfp, "the memory allocation failed\n"));
1468523fda3SJan Friedel 		__audit_syslog("auditd", LOG_PID | LOG_CONS | LOG_NOWAIT,
1478523fda3SJan Friedel 		    LOG_DAEMON, LOG_ALERT, gettext("no memory"));
1488523fda3SJan Friedel 	}
1498523fda3SJan Friedel 	auditd_thread_close();
150*17b6b380SJan Friedel 	auditd_exit(1);
1518523fda3SJan Friedel }
1528523fda3SJan Friedel 
1537c478bd9Sstevel@tonic-gate /* common exit function */
1547c478bd9Sstevel@tonic-gate void
1557c478bd9Sstevel@tonic-gate auditd_exit(int status)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate #if MEM_TEST
1587c478bd9Sstevel@tonic-gate 	sigset_t	set;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "mem_test intentional abort (status=%d)\n",
1617c478bd9Sstevel@tonic-gate 	    status));
1627c478bd9Sstevel@tonic-gate 	abort();
1637c478bd9Sstevel@tonic-gate #endif
1647c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "%ld exit status = %d auditing_set = %d\n",
1657c478bd9Sstevel@tonic-gate 	    getpid(), status, auditing_set));
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (auditing_set)
1687c478bd9Sstevel@tonic-gate 		(void) auditon(A_SETCOND, (caddr_t)&turn_audit_off,
1697c478bd9Sstevel@tonic-gate 		    (int)sizeof (int));
1707c478bd9Sstevel@tonic-gate 
1718523fda3SJan Friedel #if DEBUG
1728523fda3SJan Friedel 	(void) fclose(dbfp);
1738523fda3SJan Friedel #endif
1748523fda3SJan Friedel 
1757c478bd9Sstevel@tonic-gate 	exit(status);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /* ARGSUSED */
1797883e825Spaulson int
1807c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	auditinfo_addr_t	as_null;	/* audit state to set */
1837c478bd9Sstevel@tonic-gate 	au_id_t			auid;
1847c478bd9Sstevel@tonic-gate 	pthread_t		tid;
1857c478bd9Sstevel@tonic-gate 	plugin_t		*p;
1867c478bd9Sstevel@tonic-gate 	pid_t			pid;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate #if DEBUG
1897c478bd9Sstevel@tonic-gate 	/* LINTED */
1907c478bd9Sstevel@tonic-gate 	char			*envp;
1918523fda3SJan Friedel 	if (dbfp == NULL) {
1927c478bd9Sstevel@tonic-gate 		dbfp = __auditd_debug_file_open();
1938523fda3SJan Friedel 	}
1947c478bd9Sstevel@tonic-gate #endif
1957c478bd9Sstevel@tonic-gate 	(void) setsid();
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/* Internationalization */
1987c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1997c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * Set the audit host-id.
2037c478bd9Sstevel@tonic-gate 	 */
2047c478bd9Sstevel@tonic-gate 	if (do_sethost() != 0) {
2057c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
2067c478bd9Sstevel@tonic-gate 		auditd_exit(1);
2077c478bd9Sstevel@tonic-gate 	}
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	/*
2107c478bd9Sstevel@tonic-gate 	 * Turn off all auditing for this process.
2117c478bd9Sstevel@tonic-gate 	 */
2127c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&as_null, sizeof (as_null)) == -1) {
2137c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
214*17b6b380SJan Friedel 		auditd_exit(1);
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 	as_null.ai_mask.as_success = 0;
2177c478bd9Sstevel@tonic-gate 	as_null.ai_mask.as_failure = 0;
2187c478bd9Sstevel@tonic-gate 	(void) setaudit_addr(&as_null, sizeof (as_null));
2197c478bd9Sstevel@tonic-gate 	auid = AU_NOAUDITID;
2207c478bd9Sstevel@tonic-gate 	(void) setauid(&auid);
2217c478bd9Sstevel@tonic-gate 	/*
2227c478bd9Sstevel@tonic-gate 	 * Set the audit state flag to AUDITING.
2237c478bd9Sstevel@tonic-gate 	 */
2247c478bd9Sstevel@tonic-gate 	if (auditon(A_SETCOND, (caddr_t)&turn_audit_on, (int)sizeof (int)) !=
2257c478bd9Sstevel@tonic-gate 	    0) {
2267c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_SETCOND...) failed (exit)\n"));
2277c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
228*17b6b380SJan Friedel 		auditd_exit(1);
2297c478bd9Sstevel@tonic-gate 	}
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	block_signals();
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	/*
2347c478bd9Sstevel@tonic-gate 	 * wait for "ready" signal before exit -- for greenline
2357c478bd9Sstevel@tonic-gate 	 */
2367c478bd9Sstevel@tonic-gate 	if (fork()) {
2377c478bd9Sstevel@tonic-gate 		sigset_t	set;
2387c478bd9Sstevel@tonic-gate 		int		signal_caught = 0;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 		(void) sigemptyset(&set);
2417c478bd9Sstevel@tonic-gate 		(void) sigaddset(&set, AU_SIG_DISABLE);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 		while (signal_caught != AU_SIG_DISABLE)
2447c478bd9Sstevel@tonic-gate 			signal_caught = sigwait(&set);
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "init complete:  parent can now exit\n"));
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 		auditd_exit(0);
2497c478bd9Sstevel@tonic-gate 	}
2507c478bd9Sstevel@tonic-gate 	pid = getppid();
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	auditing_set = 1;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate #if DEBUG && MEM_TEST
2557c478bd9Sstevel@tonic-gate 	envp = getenv("UMEM_DEBUG");
2567c478bd9Sstevel@tonic-gate 	if (envp != NULL)
2577c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "UMEM_DEBUG=%s\n", envp));
2587c478bd9Sstevel@tonic-gate 	envp = getenv("UMEM_LOGGING");
2597c478bd9Sstevel@tonic-gate 	if (envp != NULL)
2607c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "UMEM_LOGGING=%s\n", envp));
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd pid=%ld\n", getpid()));
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/* thread 0 sync */
2657c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&(main_thr.thd_mutex), NULL);
2667c478bd9Sstevel@tonic-gate 	(void) pthread_cond_init(&(main_thr.thd_cv), NULL);
2677c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&plugin_mutex, NULL);
2687c478bd9Sstevel@tonic-gate 	/*
2697c478bd9Sstevel@tonic-gate 	 * Set up a separate thread for signal handling.
2707c478bd9Sstevel@tonic-gate 	 */
2717c478bd9Sstevel@tonic-gate 	if (pthread_create(&tid, NULL, (void *(*)(void *))signal_thread,
2727c478bd9Sstevel@tonic-gate 	    NULL)) {
2737c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
2747c478bd9Sstevel@tonic-gate 		    "auditd can't create a thread\n"));
275*17b6b380SJan Friedel 		auditd_exit(1);
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 	/*
2787c478bd9Sstevel@tonic-gate 	 * Set the umask so that only audit or other users in the audit group
2797c478bd9Sstevel@tonic-gate 	 * can get to the files created by auditd.
2807c478bd9Sstevel@tonic-gate 	 */
2817c478bd9Sstevel@tonic-gate 	(void) umask(007);
2827c478bd9Sstevel@tonic-gate 
283c900e163Sgww 	if (__logpost("")) {	/* Cannot unlink pointer to audit.log file. */
2847c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "logpost failed\n"));
285*17b6b380SJan Friedel 		auditd_exit(1);
2867c478bd9Sstevel@tonic-gate 	}
2877c478bd9Sstevel@tonic-gate 	/*
2887c478bd9Sstevel@tonic-gate 	 * Here is the main body of the audit daemon.  running == 0 means that
2897c478bd9Sstevel@tonic-gate 	 * after flushing out the audit queue, it is time to exit in response to
2907c478bd9Sstevel@tonic-gate 	 * AU_SIG_DISABLE
2917c478bd9Sstevel@tonic-gate 	 */
2927c478bd9Sstevel@tonic-gate 	while (running) {
2937c478bd9Sstevel@tonic-gate 		/*
2947c478bd9Sstevel@tonic-gate 		 * Read audit_control and create plugin lists.
2957c478bd9Sstevel@tonic-gate 		 *
2967c478bd9Sstevel@tonic-gate 		 * loadauditlist() and auditd_thread_init() are called
2977c478bd9Sstevel@tonic-gate 		 * while under the plugin_mutex lock to avoid a race
2987c478bd9Sstevel@tonic-gate 		 * with unload_plugin().
2997c478bd9Sstevel@tonic-gate 		 */
3007c478bd9Sstevel@tonic-gate 		if (reset_list || reset_file) {
3018523fda3SJan Friedel 			if (reset_list) {
3028523fda3SJan Friedel 				conf_to_kernel();
3038523fda3SJan Friedel 				aconf_to_kernel();
3048523fda3SJan Friedel 				scf_to_kernel_qctrl();
3058523fda3SJan Friedel 				scf_to_kernel_policy();
3067c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_lock(&plugin_mutex);
3077c478bd9Sstevel@tonic-gate 				loadauditlist();
3088523fda3SJan Friedel 			} else {
3098523fda3SJan Friedel 				(void) pthread_mutex_lock(&plugin_mutex);
3108523fda3SJan Friedel 			}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 			if (auditd_thread_init()) {
3137c478bd9Sstevel@tonic-gate 				auditd_thread_close();
3147c478bd9Sstevel@tonic-gate 				/* continue; wait for audit -s */
3157c478bd9Sstevel@tonic-gate 			}
3167c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&plugin_mutex);
3177c478bd9Sstevel@tonic-gate 			reset_list = 0;
3188523fda3SJan Friedel 
3198523fda3SJan Friedel 			if (reset_list && reset_file) {
3208523fda3SJan Friedel 				(void) printf(gettext("auditd started\n"));
3218523fda3SJan Friedel 			} else {
3228523fda3SJan Friedel 				(void) printf(gettext("auditd refreshed\n"));
3238523fda3SJan Friedel 			}
3247c478bd9Sstevel@tonic-gate 		}
3257c478bd9Sstevel@tonic-gate 		/*
3267c478bd9Sstevel@tonic-gate 		 * tell parent I'm running whether or not the initialization
3277c478bd9Sstevel@tonic-gate 		 * actually worked.  The failure case is to wait for an
3287c478bd9Sstevel@tonic-gate 		 * audit -n or audit -s to fix the problem.
3297c478bd9Sstevel@tonic-gate 		 */
3307c478bd9Sstevel@tonic-gate 		if (pid != 0) {
3317c478bd9Sstevel@tonic-gate 			(void) kill(pid, AU_SIG_DISABLE);
3327c478bd9Sstevel@tonic-gate 			pid = 0;
3337c478bd9Sstevel@tonic-gate 		}
3347c478bd9Sstevel@tonic-gate 		/*
3357c478bd9Sstevel@tonic-gate 		 * thread_signal() signals main (this thread) when
3367c478bd9Sstevel@tonic-gate 		 * it has received a signal.
3377c478bd9Sstevel@tonic-gate 		 */
3387c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "main thread is waiting\n"));
3397c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_lock(&(main_thr.thd_mutex));
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 		if (!(caught_readc || caught_term || caught_alrm ||
3427c478bd9Sstevel@tonic-gate 		    caught_nextd))
3437c478bd9Sstevel@tonic-gate 			(void) pthread_cond_wait(&(main_thr.thd_cv),
3447c478bd9Sstevel@tonic-gate 			    &(main_thr.thd_mutex));
3457c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
3467c478bd9Sstevel@tonic-gate 		/*
3477c478bd9Sstevel@tonic-gate 		 * Got here because a signal came in.
3487c478bd9Sstevel@tonic-gate 		 * Since we may have gotten more than one, we assume a
3497c478bd9Sstevel@tonic-gate 		 * priority scheme with SIGALRM being the most
3507c478bd9Sstevel@tonic-gate 		 * significant.
3517c478bd9Sstevel@tonic-gate 		 */
3527c478bd9Sstevel@tonic-gate 		if (caught_alrm) {
3537c478bd9Sstevel@tonic-gate 			/*
3547c478bd9Sstevel@tonic-gate 			 * We have returned from our timed wait for
3557c478bd9Sstevel@tonic-gate 			 * c2audit to calm down.  We need to really shut
3567c478bd9Sstevel@tonic-gate 			 * down here.
3577c478bd9Sstevel@tonic-gate 			 */
3587c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3597c478bd9Sstevel@tonic-gate 			running = 0;	/* shut down now */
3607c478bd9Sstevel@tonic-gate 		} else if (caught_term) {
3617c478bd9Sstevel@tonic-gate 			/*
3627c478bd9Sstevel@tonic-gate 			 * we are going to shut down, but need to
3637c478bd9Sstevel@tonic-gate 			 * allow time for the audit queues in
3647c478bd9Sstevel@tonic-gate 			 * c2audit and for the threads to empty.
3657c478bd9Sstevel@tonic-gate 			 */
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 			p = plugin_head;
3687c478bd9Sstevel@tonic-gate 			while (p != NULL) {
3697c478bd9Sstevel@tonic-gate 				DPRINT((dbfp, "signalling thread %d\n",
3707c478bd9Sstevel@tonic-gate 				    p->plg_tid));
3717c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_lock(&(p->plg_mutex));
3727c478bd9Sstevel@tonic-gate 				p->plg_removed = 1;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 				if (p->plg_initialized)
3757c478bd9Sstevel@tonic-gate 					(void) pthread_cond_signal(
3767c478bd9Sstevel@tonic-gate 					    &(p->plg_cv));
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_unlock(&(p->plg_mutex));
3797c478bd9Sstevel@tonic-gate 				p = p->plg_next;
3807c478bd9Sstevel@tonic-gate 			}
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3837c478bd9Sstevel@tonic-gate 			caught_readc  = 0;
3847c478bd9Sstevel@tonic-gate 			caught_term = 0;
3857c478bd9Sstevel@tonic-gate 			caught_nextd = 0;
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
3887c478bd9Sstevel@tonic-gate 			    "main thread is pausing before exit.\n"));
3897c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_lock(&(main_thr.thd_mutex));
3907c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3917c478bd9Sstevel@tonic-gate 			(void) alarm(ALRM_TIME);
3927c478bd9Sstevel@tonic-gate 			while (!caught_alrm)
3937c478bd9Sstevel@tonic-gate 				(void) pthread_cond_wait(&(main_thr.thd_cv),
3947c478bd9Sstevel@tonic-gate 				    &(main_thr.thd_mutex));
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 			running = 0;	/* Close down auditing and exit */
3997c478bd9Sstevel@tonic-gate 		} else if (caught_readc) {
4007c478bd9Sstevel@tonic-gate 			/*
4017c478bd9Sstevel@tonic-gate 			 * if both hup and usr1 are caught, the logic in
4027c478bd9Sstevel@tonic-gate 			 * loadauditlist() results in hup winning.  The
4037c478bd9Sstevel@tonic-gate 			 * result will be that the audit file is not rolled
4047c478bd9Sstevel@tonic-gate 			 * over unless audit_control actually changed.
4057c478bd9Sstevel@tonic-gate 			 *
4067c478bd9Sstevel@tonic-gate 			 * They want to reread the audit_control file.
4077c478bd9Sstevel@tonic-gate 			 * Set reset_list which will return us to the
4087c478bd9Sstevel@tonic-gate 			 * main while loop in the main routine.
4097c478bd9Sstevel@tonic-gate 			 */
4107c478bd9Sstevel@tonic-gate 			caught_readc = 0;
4117c478bd9Sstevel@tonic-gate 			reset_list = 1;
4127c478bd9Sstevel@tonic-gate 		} else if (caught_nextd) {
4137c478bd9Sstevel@tonic-gate 			/*
4147c478bd9Sstevel@tonic-gate 			 * This is a special case for the binfile
4157c478bd9Sstevel@tonic-gate 			 * plugin. (audit -n)  NULL out kvlist
4167c478bd9Sstevel@tonic-gate 			 * so binfile won't re-read audit_control
4177c478bd9Sstevel@tonic-gate 			 */
4187c478bd9Sstevel@tonic-gate 			caught_nextd = 0;
4197c478bd9Sstevel@tonic-gate 			reset_file = 1;
4207c478bd9Sstevel@tonic-gate 			if (binfile != NULL) {
4217c478bd9Sstevel@tonic-gate 				_kva_free(binfile->plg_kvlist);
4227c478bd9Sstevel@tonic-gate 				binfile->plg_kvlist = NULL;
4237c478bd9Sstevel@tonic-gate 				binfile->plg_reopen = 1;
4247c478bd9Sstevel@tonic-gate 			}
4257c478bd9Sstevel@tonic-gate 		}
4267c478bd9Sstevel@tonic-gate 	}	/* end while (running) */
4277c478bd9Sstevel@tonic-gate 	auditd_thread_close();
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	auditd_exit(0);
4307c478bd9Sstevel@tonic-gate 	return (0);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate /*
4347c478bd9Sstevel@tonic-gate  * my_sleep - sleep for SLEEP_TIME seconds but only accept the signals
4357c478bd9Sstevel@tonic-gate  *	that we want to accept.  (Premature termination just means the
4367c478bd9Sstevel@tonic-gate  *	caller retries more often, not a big deal.)
4377c478bd9Sstevel@tonic-gate  */
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate static void
4407c478bd9Sstevel@tonic-gate my_sleep()
4417c478bd9Sstevel@tonic-gate {
4427c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd: sleeping for 20 seconds\n"));
4437c478bd9Sstevel@tonic-gate 	/*
4447c478bd9Sstevel@tonic-gate 	 * Set timer to "sleep"
4457c478bd9Sstevel@tonic-gate 	 */
4467c478bd9Sstevel@tonic-gate 	(void) alarm(SLEEP_TIME);
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "main thread is waiting for SIGALRM before exit.\n"));
4497c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&(main_thr.thd_mutex));
4507c478bd9Sstevel@tonic-gate 	(void) pthread_cond_wait(&(main_thr.thd_cv), &(main_thr.thd_mutex));
4517c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	if (caught_term) {
4547c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "normal AU_SIG_DISABLE exit\n"));
4557c478bd9Sstevel@tonic-gate 		/*
4567c478bd9Sstevel@tonic-gate 		 * Exit, as requested.
4577c478bd9Sstevel@tonic-gate 		 */
4587c478bd9Sstevel@tonic-gate 		auditd_thread_close();
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 	if (caught_readc)
4617c478bd9Sstevel@tonic-gate 		reset_list = 1;		/* Reread the audit_control file */
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	caught_readc = 0;
4647c478bd9Sstevel@tonic-gate 	caught_nextd = 0;
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate  * search for $ISA/ in path and replace it with "" if auditd
4697c478bd9Sstevel@tonic-gate  * is 32 bit, else "sparcv9/"  The plugin $ISA must match however
4707c478bd9Sstevel@tonic-gate  * auditd was compiled.
4717c478bd9Sstevel@tonic-gate  */
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate static void
4747c478bd9Sstevel@tonic-gate isa_ified(char *path, char **newpath)
4757c478bd9Sstevel@tonic-gate {
4767c478bd9Sstevel@tonic-gate 	char	*p, *q;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	if (((p = strchr(path, '$')) != NULL) &&
4797c478bd9Sstevel@tonic-gate 	    (strncmp("$ISA/", p, 5) == 0)) {
4807c478bd9Sstevel@tonic-gate 		(void) memcpy(*newpath, path, p - path);
4817c478bd9Sstevel@tonic-gate 		q = *newpath + (p - path);
4827c478bd9Sstevel@tonic-gate #ifdef __sparcv9
4837c478bd9Sstevel@tonic-gate 		q += strlcpy(q, "sparcv9/", avail_length);
4847c478bd9Sstevel@tonic-gate #endif
4857c478bd9Sstevel@tonic-gate 		(void) strcpy(q, p + 5);
4867c478bd9Sstevel@tonic-gate 	} else
4877c478bd9Sstevel@tonic-gate 		*newpath = path;
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate /*
4917c478bd9Sstevel@tonic-gate  * init_plugin first searches the existing plugin list to see
4927c478bd9Sstevel@tonic-gate  * if the plugin already has been defined; if not, it creates it
4937c478bd9Sstevel@tonic-gate  * and links it into the list.  It returns a pointer to the found
4947c478bd9Sstevel@tonic-gate  * or created struct.  A change of path in audit_control for a
4957c478bd9Sstevel@tonic-gate  * given plugin will cause a miss.
4967c478bd9Sstevel@tonic-gate  */
4977c478bd9Sstevel@tonic-gate /*
4987c478bd9Sstevel@tonic-gate  * for 64 bits, the path name can grow 3 bytes (minus 5 for the
4997c478bd9Sstevel@tonic-gate  * removed "$ISA" and plus 8 for the added "sparcv9/"
5007c478bd9Sstevel@tonic-gate  */
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate #define	ISA_GROW	8 - 5
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate static plugin_t *
5057c478bd9Sstevel@tonic-gate init_plugin(char *name, kva_t *list, int cnt_flag)
5067c478bd9Sstevel@tonic-gate {
5077c478bd9Sstevel@tonic-gate 	plugin_t	*p, *q;
5087c478bd9Sstevel@tonic-gate 	char		filepath[MAXPATHLEN + 1 + ISA_GROW];
5097c478bd9Sstevel@tonic-gate 	char		*path = filepath;
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	if (*name != '/') {
5127c478bd9Sstevel@tonic-gate #ifdef  __sparcv9
5137c478bd9Sstevel@tonic-gate 		(void) strcpy(filepath, "/usr/lib/security/sparcv9/");
5147c478bd9Sstevel@tonic-gate #else
5157c478bd9Sstevel@tonic-gate 		(void) strcpy(filepath, "/usr/lib/security/");
5167c478bd9Sstevel@tonic-gate #endif
5177c478bd9Sstevel@tonic-gate 		if (strlcat(filepath, name, MAXPATHLEN) >= MAXPATHLEN)
5187c478bd9Sstevel@tonic-gate 			return (NULL);
5197c478bd9Sstevel@tonic-gate 	} else {
5207c478bd9Sstevel@tonic-gate 		if (strlen(name) > MAXPATHLEN + ISA_GROW)
5217c478bd9Sstevel@tonic-gate 			return (NULL);
5227c478bd9Sstevel@tonic-gate 		isa_ified(name, &path);
5237c478bd9Sstevel@tonic-gate 	}
5247c478bd9Sstevel@tonic-gate 	p = plugin_head;
5257c478bd9Sstevel@tonic-gate 	q = plugin_head;
5267c478bd9Sstevel@tonic-gate 	while (p != NULL) {
5277c478bd9Sstevel@tonic-gate 		if (p->plg_path != NULL) {
5287c478bd9Sstevel@tonic-gate 			if (strcmp(p->plg_path, path) == 0) {
5297c478bd9Sstevel@tonic-gate 				p->plg_removed = 0;
5307c478bd9Sstevel@tonic-gate 				p->plg_to_be_removed = 0;
5317c478bd9Sstevel@tonic-gate 				p->plg_cnt = cnt_flag;
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 				_kva_free(p->plg_kvlist);
5347c478bd9Sstevel@tonic-gate 				p->plg_kvlist = list;
5357c478bd9Sstevel@tonic-gate 				p->plg_reopen = 1;
5367c478bd9Sstevel@tonic-gate 				DPRINT((dbfp, "reusing %s\n", p->plg_path));
5377c478bd9Sstevel@tonic-gate 				return (p);
5387c478bd9Sstevel@tonic-gate 			}
5397c478bd9Sstevel@tonic-gate 		}
5407c478bd9Sstevel@tonic-gate 		q = p;
5417c478bd9Sstevel@tonic-gate 		p = p->plg_next;
5427c478bd9Sstevel@tonic-gate 	}
5437c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "creating new plugin structure for %s\n", path));
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	p = malloc(sizeof (plugin_t));
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 	if (p == NULL) {
5487c478bd9Sstevel@tonic-gate 		perror("auditd");
5497c478bd9Sstevel@tonic-gate 		return (NULL);
5507c478bd9Sstevel@tonic-gate 	}
5517c478bd9Sstevel@tonic-gate 	if (q == NULL)
5527c478bd9Sstevel@tonic-gate 		plugin_head = p;
5537c478bd9Sstevel@tonic-gate 	else
5547c478bd9Sstevel@tonic-gate 		q->plg_next = p;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	p->plg_next = NULL;
5577c478bd9Sstevel@tonic-gate 	p->plg_initialized = 0;
5587c478bd9Sstevel@tonic-gate 	p->plg_reopen = 1;
5597c478bd9Sstevel@tonic-gate 	p->plg_tid = 0;
5607c478bd9Sstevel@tonic-gate 	p->plg_removed = 0;
5617c478bd9Sstevel@tonic-gate 	p->plg_to_be_removed = 0;
5627c478bd9Sstevel@tonic-gate 	p->plg_tossed = 0;
5637c478bd9Sstevel@tonic-gate 	p->plg_queued = 0;
5647c478bd9Sstevel@tonic-gate 	p->plg_output = 0;
5657c478bd9Sstevel@tonic-gate 	p->plg_sequence = 1;
5667c478bd9Sstevel@tonic-gate 	p->plg_last_seq_out = 0;
5677c478bd9Sstevel@tonic-gate 	p->plg_path = strdup(path);
5687c478bd9Sstevel@tonic-gate 	p->plg_kvlist = list;
5697c478bd9Sstevel@tonic-gate 	p->plg_cnt = cnt_flag;
5707c478bd9Sstevel@tonic-gate 	p->plg_retry_time = SLEEP_TIME;
5717c478bd9Sstevel@tonic-gate 	p->plg_qmax = 0;
5727c478bd9Sstevel@tonic-gate 	p->plg_save_q_copy = NULL;
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "created plugin:  %s\n", path));
5757c478bd9Sstevel@tonic-gate 	return (p);
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate  * loadauditlist - read the directory list from the audit_control file.
5807c478bd9Sstevel@tonic-gate  *		   to determine if a binary file is to be written.
5817c478bd9Sstevel@tonic-gate  *		 - read the plugin entries from the audit_control file
5827c478bd9Sstevel@tonic-gate  *
5837c478bd9Sstevel@tonic-gate  * globals -
5847c478bd9Sstevel@tonic-gate  *
5857c478bd9Sstevel@tonic-gate  *	plugin queues
5867c478bd9Sstevel@tonic-gate  *
5877c478bd9Sstevel@tonic-gate  * success is when at least one plug in is defined.
5887c478bd9Sstevel@tonic-gate  *
5897c478bd9Sstevel@tonic-gate  * set cnt policy here based on auditconfig setting.  future could
5907c478bd9Sstevel@tonic-gate  * have a policy = {+|-}cnt entry per plugin with auditconfig providing the
5917c478bd9Sstevel@tonic-gate  * default.
5927c478bd9Sstevel@tonic-gate  */
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate static void
5957c478bd9Sstevel@tonic-gate loadauditlist()
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate 	char		buf[MAXPATHLEN];
5987c478bd9Sstevel@tonic-gate 	char		*value;
5997c478bd9Sstevel@tonic-gate 	plugin_t	*p;
6007c478bd9Sstevel@tonic-gate 	int		acresult;
6017c478bd9Sstevel@tonic-gate 	int		wait_count = 0;
6027c478bd9Sstevel@tonic-gate 	kva_t		*kvlist;
6037c478bd9Sstevel@tonic-gate 	long		policy;
6047c478bd9Sstevel@tonic-gate 	int		cnt_flag;
6057c478bd9Sstevel@tonic-gate 	struct au_qctrl	kqmax;
6067c478bd9Sstevel@tonic-gate 	au_acinfo_t	*ach = NULL;
6077c478bd9Sstevel@tonic-gate 	int		got_dir = 0;
6087c478bd9Sstevel@tonic-gate 	int		have_plugin = 0;
6097c478bd9Sstevel@tonic-gate 	char		*endptr;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	if (auditon(A_GETPOLICY, (char *)&policy, 0) == -1) {
6127c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETPOLICY...) failed (exit)\n"));
6137c478bd9Sstevel@tonic-gate 		__audit_dowarn("auditoff", "", 0);
6147c478bd9Sstevel@tonic-gate 		auditd_thread_close();
615*17b6b380SJan Friedel 		auditd_exit(1);
6167c478bd9Sstevel@tonic-gate 	}
6177c478bd9Sstevel@tonic-gate 	cnt_flag = ((policy & AUDIT_CNT) != 0) ? 1 : 0;
6187c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "loadauditlist:  policy is to %s\n", (cnt_flag == 1) ?
6197c478bd9Sstevel@tonic-gate 	    "continue" : "block"));
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate #if DEBUG
6228523fda3SJan Friedel 	if (auditon(A_GETCOND, (caddr_t)&acresult, (int)sizeof (int)) != 0)
6237c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETCOND...) failed (exit)\n"));
6248523fda3SJan Friedel 
6257c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "audit cond = %d (1 is on)\n", acresult));
6268523fda3SJan Friedel #endif
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	if (auditon(A_GETQCTRL, (char *)&kqmax, sizeof (struct au_qctrl)) !=
6307c478bd9Sstevel@tonic-gate 	    0) {
6317c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETQCTRL...) failed (exit)\n"));
6327c478bd9Sstevel@tonic-gate 		__audit_dowarn("auditoff", "", 0);
6337c478bd9Sstevel@tonic-gate 		auditd_thread_close();
634*17b6b380SJan Friedel 		auditd_exit(1);
6357c478bd9Sstevel@tonic-gate 	}
6367c478bd9Sstevel@tonic-gate 	kqmax.aq_hiwater *= 5;		/* RAM is cheaper in userspace */
6377c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd: reading audit_control\n"));
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 	p = plugin_head;
6407c478bd9Sstevel@tonic-gate 	/*
6417c478bd9Sstevel@tonic-gate 	 * two-step on setting p->plg_removed because the input thread
6427c478bd9Sstevel@tonic-gate 	 * in doorway.c uses p->plg_removed to decide if the plugin is
6437c478bd9Sstevel@tonic-gate 	 * active.
6447c478bd9Sstevel@tonic-gate 	 */
6457c478bd9Sstevel@tonic-gate 	while (p != NULL) {
6468523fda3SJan Friedel 		DPRINT((dbfp, "loadauditlist:  %p, %s previously created\n",
6478523fda3SJan Friedel 		    (void *)p, p->plg_path));
6487c478bd9Sstevel@tonic-gate 		p->plg_to_be_removed = 1;	/* tentative removal */
6497c478bd9Sstevel@tonic-gate 		p = p->plg_next;
6507c478bd9Sstevel@tonic-gate 	}
6517c478bd9Sstevel@tonic-gate 	/*
6527c478bd9Sstevel@tonic-gate 	 * have_plugin may over count by one if both a "dir" entry
6537c478bd9Sstevel@tonic-gate 	 * and a "plugin" entry for binfile are found.  All that
6547c478bd9Sstevel@tonic-gate 	 * matters is that it be zero if no plugin or dir entries
6557c478bd9Sstevel@tonic-gate 	 * are found.
6567c478bd9Sstevel@tonic-gate 	 */
6577c478bd9Sstevel@tonic-gate 	have_plugin = 0;
6587c478bd9Sstevel@tonic-gate 	for (;;) {
6597c478bd9Sstevel@tonic-gate 		/* NULL == use standard path for audit_control */
6607c478bd9Sstevel@tonic-gate 		ach = _openac(NULL);
6617c478bd9Sstevel@tonic-gate 		/*
6627c478bd9Sstevel@tonic-gate 		 * loop until a directory entry is found (0) or eof (-1)
6637c478bd9Sstevel@tonic-gate 		 */
6647c478bd9Sstevel@tonic-gate 		while (((acresult = _getacdir(ach, buf, sizeof (buf))) != 0) &&
6657c478bd9Sstevel@tonic-gate 		    acresult != -1) {
6667c478bd9Sstevel@tonic-gate 		}
6677c478bd9Sstevel@tonic-gate 		if (acresult == 0) {
6687c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
6697c478bd9Sstevel@tonic-gate 			    "loadauditlist: "
6707c478bd9Sstevel@tonic-gate 			    "got binfile via old config syntax\n"));
6717c478bd9Sstevel@tonic-gate 			/*
6727c478bd9Sstevel@tonic-gate 			 * A directory entry was found.
6737c478bd9Sstevel@tonic-gate 			 */
6747c478bd9Sstevel@tonic-gate 			got_dir = 1;
6757c478bd9Sstevel@tonic-gate 			kvlist = _str2kva("name=audit_binfile.so.1",
6767c478bd9Sstevel@tonic-gate 			    "=", ";");
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate 			p = init_plugin("audit_binfile.so.1", kvlist, cnt_flag);
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 			if (p != NULL) {
6817c478bd9Sstevel@tonic-gate 				binfile = p;
6827c478bd9Sstevel@tonic-gate 				p->plg_qmax = kqmax.aq_hiwater;
6837c478bd9Sstevel@tonic-gate 				have_plugin++;
6847c478bd9Sstevel@tonic-gate 			}
6857c478bd9Sstevel@tonic-gate 		}
6867c478bd9Sstevel@tonic-gate 		/*
6877c478bd9Sstevel@tonic-gate 		 * collect plugin entries.  If there is an entry for
6887c478bd9Sstevel@tonic-gate 		 * binfile.so.1, the parameters from the plugin line
6897c478bd9Sstevel@tonic-gate 		 * override those set above.  For binfile, p_dir is
6907c478bd9Sstevel@tonic-gate 		 * required only if dir wasn't specified elsewhere in
6917c478bd9Sstevel@tonic-gate 		 * audit_control
6927c478bd9Sstevel@tonic-gate 		 */
6937c478bd9Sstevel@tonic-gate 		_rewindac(ach);
6947c478bd9Sstevel@tonic-gate 		while ((acresult = _getacplug(ach, &kvlist)) == 0) {
6957c478bd9Sstevel@tonic-gate 			value = kva_match(kvlist, "name");
6967c478bd9Sstevel@tonic-gate 			if (value == NULL)
6977c478bd9Sstevel@tonic-gate 				break;
6987c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "loadauditlist: have an entry for %s\n",
6997c478bd9Sstevel@tonic-gate 			    value));
7007c478bd9Sstevel@tonic-gate 			p = init_plugin(value, kvlist, cnt_flag);
7017c478bd9Sstevel@tonic-gate 			if (p == NULL)
7027c478bd9Sstevel@tonic-gate 				continue;
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 			if (strstr(value, "/audit_binfile.so") != NULL) {
7057c478bd9Sstevel@tonic-gate 				binfile = p;
7067c478bd9Sstevel@tonic-gate 				if (!got_dir &&
7077c478bd9Sstevel@tonic-gate 				    (kva_match(kvlist, "p_dir") ==
7087c478bd9Sstevel@tonic-gate 				    NULL)) {
7097c478bd9Sstevel@tonic-gate 					__audit_dowarn("getacdir", "",
7107c478bd9Sstevel@tonic-gate 					    wait_count);
7117c478bd9Sstevel@tonic-gate 				}
7127c478bd9Sstevel@tonic-gate 			}
7137c478bd9Sstevel@tonic-gate 			p->plg_qmax = kqmax.aq_hiwater; /* default */
7147c478bd9Sstevel@tonic-gate 			value = kva_match(kvlist, "qsize");
7157c478bd9Sstevel@tonic-gate 			if (value != NULL) {
7167c478bd9Sstevel@tonic-gate 				long	tmp;
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 				tmp = strtol(value, &endptr, 10);
7197c478bd9Sstevel@tonic-gate 				if (*endptr == '\0')
7207c478bd9Sstevel@tonic-gate 					p->plg_qmax = tmp;
7217c478bd9Sstevel@tonic-gate 			}
7229697ae98Sgww 			DPRINT((dbfp, "%s queue max = %d\n", p->plg_path,
7239697ae98Sgww 			    p->plg_qmax));
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 			have_plugin++;
7267c478bd9Sstevel@tonic-gate 		}
7277c478bd9Sstevel@tonic-gate 		_endac(ach);
7287c478bd9Sstevel@tonic-gate 		if (have_plugin != 0)
7297c478bd9Sstevel@tonic-gate 			break;
7307c478bd9Sstevel@tonic-gate 		/*
7317c478bd9Sstevel@tonic-gate 		 * there was a problem getting the directory
7327c478bd9Sstevel@tonic-gate 		 * list or remote host info from the audit_control file
7337c478bd9Sstevel@tonic-gate 		 */
7347c478bd9Sstevel@tonic-gate 		wait_count++;
7357c478bd9Sstevel@tonic-gate #if DEBUG
7367c478bd9Sstevel@tonic-gate 		if (wait_count < 2)
7377c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
7387c478bd9Sstevel@tonic-gate 			    "auditd: problem getting directory "
7397c478bd9Sstevel@tonic-gate 			    "/ or plugin list from audit_control.\n"));
7407c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
7417c478bd9Sstevel@tonic-gate 		__audit_dowarn("getacdir", "", wait_count);
7427c478bd9Sstevel@tonic-gate 		/*
7437c478bd9Sstevel@tonic-gate 		 * sleep for SLEEP_TIME seconds.
7447c478bd9Sstevel@tonic-gate 		 */
7457c478bd9Sstevel@tonic-gate 		my_sleep();
7467c478bd9Sstevel@tonic-gate 	}    /* end for(;;) */
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 	p = plugin_head;
7497c478bd9Sstevel@tonic-gate 	while (p != NULL) {
7507c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "loadauditlist: %s remove flag=%d; cnt=%d\n",
7517c478bd9Sstevel@tonic-gate 		    p->plg_path, p->plg_to_be_removed, p->plg_cnt));
7527c478bd9Sstevel@tonic-gate 		p->plg_removed = p->plg_to_be_removed;
7537c478bd9Sstevel@tonic-gate 		p = p->plg_next;
7547c478bd9Sstevel@tonic-gate 	}
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate /*
7587c478bd9Sstevel@tonic-gate  * block signals -- thread-specific blocking of the signals expected
7597c478bd9Sstevel@tonic-gate  * by the main thread.
7607c478bd9Sstevel@tonic-gate  */
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate static void
7637c478bd9Sstevel@tonic-gate block_signals()
7647c478bd9Sstevel@tonic-gate {
7657c478bd9Sstevel@tonic-gate 	sigset_t	set;
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	(void) sigfillset(&set);
7687c478bd9Sstevel@tonic-gate 	(void) pthread_sigmask(SIG_BLOCK, &set, NULL);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate /*
7727c478bd9Sstevel@tonic-gate  * signal_thread is the designated signal catcher.  It wakes up the
7737c478bd9Sstevel@tonic-gate  * main thread whenever it receives a signal and then goes back to
7747c478bd9Sstevel@tonic-gate  * sleep; it does not exit.  The global variables caught_* let
7757c478bd9Sstevel@tonic-gate  * the main thread which signal was received.
7767c478bd9Sstevel@tonic-gate  *
7777c478bd9Sstevel@tonic-gate  * The thread is created with all signals blocked.
7787c478bd9Sstevel@tonic-gate  */
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate static void
7817c478bd9Sstevel@tonic-gate signal_thread()
7827c478bd9Sstevel@tonic-gate {
7837c478bd9Sstevel@tonic-gate 	sigset_t	set;
7847c478bd9Sstevel@tonic-gate 	int		signal_caught;
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "the signal thread is thread %d\n",
7877c478bd9Sstevel@tonic-gate 	    pthread_self()));
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&set);
7907c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, SIGALRM);
7917c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_DISABLE);
7927c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_READ_CONTROL);
7937c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_NEXT_DIR);
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 	for (;;) {
7967c478bd9Sstevel@tonic-gate 		signal_caught = sigwait(&set);
7977c478bd9Sstevel@tonic-gate 		switch (signal_caught) {
7987c478bd9Sstevel@tonic-gate 		case SIGALRM:
7997c478bd9Sstevel@tonic-gate 			caught_alrm++;
8007c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught SIGALRM\n"));
8017c478bd9Sstevel@tonic-gate 			break;
8027c478bd9Sstevel@tonic-gate 		case AU_SIG_DISABLE:
8037c478bd9Sstevel@tonic-gate 			caught_term++;
8047c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_DISABLE\n"));
8057c478bd9Sstevel@tonic-gate 			break;
8067c478bd9Sstevel@tonic-gate 		case AU_SIG_READ_CONTROL:
8077c478bd9Sstevel@tonic-gate 			caught_readc++;
8087c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_READ_CONTROL\n"));
8097c478bd9Sstevel@tonic-gate 			break;
8107c478bd9Sstevel@tonic-gate 		case AU_SIG_NEXT_DIR:
8117c478bd9Sstevel@tonic-gate 			caught_nextd++;
8127c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_NEXT_DIR\n"));
8137c478bd9Sstevel@tonic-gate 			break;
8147c478bd9Sstevel@tonic-gate 		default:
8157c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught unexpected signal:  %d\n",
8167c478bd9Sstevel@tonic-gate 			    signal_caught));
8177c478bd9Sstevel@tonic-gate 			break;
8187c478bd9Sstevel@tonic-gate 		}
8197c478bd9Sstevel@tonic-gate 		(void) pthread_cond_signal(&(main_thr.thd_cv));
8207c478bd9Sstevel@tonic-gate 	}
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate /*
8247c478bd9Sstevel@tonic-gate  * do_sethost - do auditon(2) to set the audit host-id.
8259697ae98Sgww  *		Returns 0 if success or -1 otherwise.
8267c478bd9Sstevel@tonic-gate  */
8277c478bd9Sstevel@tonic-gate static int
8287c478bd9Sstevel@tonic-gate do_sethost(void)
8297c478bd9Sstevel@tonic-gate {
8309697ae98Sgww 	au_tid_addr_t	*termid;
8317c478bd9Sstevel@tonic-gate 	auditinfo_addr_t	audit_info;
8329697ae98Sgww 	char	msg[512];
8337c478bd9Sstevel@tonic-gate 
8349697ae98Sgww 	if (adt_load_hostname(NULL, (adt_termid_t **)&termid) < 0) {
8359697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to get local "
8369697ae98Sgww 		    "IP address: %s", strerror(errno));
8379697ae98Sgww 		goto fail;
8387c478bd9Sstevel@tonic-gate 	}
8397c478bd9Sstevel@tonic-gate 	/* Get current kernel audit info, and fill in the IP address */
8409697ae98Sgww 	if (auditon(A_GETKAUDIT, (caddr_t)&audit_info,
8419697ae98Sgww 	    sizeof (audit_info)) < 0) {
8429697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to get kernel "
8439697ae98Sgww 		    "audit info: %s", strerror(errno));
8449697ae98Sgww 		goto fail;
8457c478bd9Sstevel@tonic-gate 	}
8467c478bd9Sstevel@tonic-gate 
8479697ae98Sgww 	audit_info.ai_termid = *termid;
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 	/* Update the kernel audit info with new IP address */
8509697ae98Sgww 	if (auditon(A_SETKAUDIT, (caddr_t)&audit_info,
8519697ae98Sgww 	    sizeof (audit_info)) < 0) {
8529697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to set kernel "
8539697ae98Sgww 		    "audit info: %s", strerror(errno));
8549697ae98Sgww 		goto fail;
8557c478bd9Sstevel@tonic-gate 	}
8567c478bd9Sstevel@tonic-gate 
8579697ae98Sgww 	free(termid);
8587c478bd9Sstevel@tonic-gate 	return (0);
8599697ae98Sgww 
8609697ae98Sgww fail:
8619697ae98Sgww 	free(termid);
8629697ae98Sgww 	__audit_syslog("auditd", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_DAEMON,
8639697ae98Sgww 	    LOG_ALERT, msg);
8649697ae98Sgww 	return (-1);
8657c478bd9Sstevel@tonic-gate }
8668523fda3SJan Friedel 
8678523fda3SJan Friedel /*
8688523fda3SJan Friedel  * conf_to_kernel() - configure the event to class mapping; see also
8698523fda3SJan Friedel  * auditconfig(1M) -conf option.
8708523fda3SJan Friedel  */
8718523fda3SJan Friedel static void
8728523fda3SJan Friedel conf_to_kernel(void)
8738523fda3SJan Friedel {
8748523fda3SJan Friedel 	register au_event_ent_t *evp;
8758523fda3SJan Friedel 	register int 		i;
8768523fda3SJan Friedel 	char			*msg;
8778523fda3SJan Friedel 	au_evclass_map_t 	ec;
8788523fda3SJan Friedel 	au_stat_t 		as;
8798523fda3SJan Friedel 
8808523fda3SJan Friedel 	if (auditon(A_GETSTAT, (caddr_t)&as, 0) != 0) {
8818523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Audit module does not appear "
8828523fda3SJan Friedel 		    "to be loaded."));
883*17b6b380SJan Friedel 		err_exit(msg);
8848523fda3SJan Friedel 	}
8858523fda3SJan Friedel 
8868523fda3SJan Friedel 	i = 0;
8878523fda3SJan Friedel 	setauevent();
8888523fda3SJan Friedel 	while ((evp = getauevent()) != NULL) {
8898523fda3SJan Friedel 		if (evp->ae_number <= as.as_numevent) {
8908523fda3SJan Friedel 			++i;
8918523fda3SJan Friedel 			ec.ec_number = evp->ae_number;
8928523fda3SJan Friedel 			ec.ec_class = evp->ae_class;
8938523fda3SJan Friedel 
8948523fda3SJan Friedel 			if (auditon(A_SETCLASS, (caddr_t)&ec,
8958523fda3SJan Friedel 			    (int)sizeof (ec)) != 0) {
8968523fda3SJan Friedel 				(void) asprintf(&msg,
8978523fda3SJan Friedel 				    gettext("Could not configure kernel audit "
8988523fda3SJan Friedel 				    "event to class mappings."));
899*17b6b380SJan Friedel 				err_exit(msg);
9008523fda3SJan Friedel 			}
9018523fda3SJan Friedel 		}
9028523fda3SJan Friedel 	}
9038523fda3SJan Friedel 	endauevent();
9048523fda3SJan Friedel 
9058523fda3SJan Friedel 	DPRINT((dbfp, "configured %d kernel events.\n", i));
9068523fda3SJan Friedel }
9078523fda3SJan Friedel 
9088523fda3SJan Friedel /*
9098523fda3SJan Friedel  * aconf_to_kernel() - set the non-attributable audit mask from the
9108523fda3SJan Friedel  * audit_control(4); see also auditconfig(1M) -aconf option.
9118523fda3SJan Friedel  */
9128523fda3SJan Friedel static void
9138523fda3SJan Friedel aconf_to_kernel(void)
9148523fda3SJan Friedel {
9158523fda3SJan Friedel 	char		*msg;
9168523fda3SJan Friedel 	char		buf[2048];
9178523fda3SJan Friedel 	au_mask_t	pmask;
9188523fda3SJan Friedel 
9198523fda3SJan Friedel 	if (getacna(buf, sizeof (buf)) < 0) {
9208523fda3SJan Friedel 		(void) asprintf(&msg,
9218523fda3SJan Friedel 		    gettext("bad non-attributable flags in audit_control(4)"));
922*17b6b380SJan Friedel 		err_exit(msg);
9238523fda3SJan Friedel 	}
9248523fda3SJan Friedel 
9258523fda3SJan Friedel 	if (getauditflagsbin(buf, &pmask) < 0) {
9268523fda3SJan Friedel 		(void) asprintf(&msg,
9278523fda3SJan Friedel 		    gettext("bad audit flag value encountered"));
928*17b6b380SJan Friedel 		err_exit(msg);
9298523fda3SJan Friedel 	}
9308523fda3SJan Friedel 
9318523fda3SJan Friedel 	if (auditon(A_SETKMASK, (caddr_t)&pmask, (int)sizeof (pmask)) != 0) {
9328523fda3SJan Friedel 		(void) asprintf(&msg,
9338523fda3SJan Friedel 		    gettext("Could not configure non-attributable events."));
934*17b6b380SJan Friedel 		err_exit(msg);
9358523fda3SJan Friedel 	}
9368523fda3SJan Friedel 
9378523fda3SJan Friedel 	DPRINT((dbfp, "configured non-attributable events.\n"));
9388523fda3SJan Friedel }
9398523fda3SJan Friedel 
9408523fda3SJan Friedel /*
9418523fda3SJan Friedel  * scf_to_kernel_qctrl() - update the kernel queue control parameters
9428523fda3SJan Friedel  */
9438523fda3SJan Friedel static void
9448523fda3SJan Friedel scf_to_kernel_qctrl(void)
9458523fda3SJan Friedel {
9468523fda3SJan Friedel 	struct au_qctrl	act_qctrl;
9478523fda3SJan Friedel 	struct au_qctrl	cfg_qctrl;
9488523fda3SJan Friedel 	char		*msg;
9498523fda3SJan Friedel 
9508523fda3SJan Friedel 	if (!do_getqctrl_scf(&cfg_qctrl)) {
9518523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Unable to gather audit queue "
9528523fda3SJan Friedel 		    "control parameters from the SMF repository."));
953*17b6b380SJan Friedel 		err_exit(msg);
9548523fda3SJan Friedel 	}
9558523fda3SJan Friedel 
9568523fda3SJan Friedel 	DPRINT((dbfp, "will check and set qctrl parameters:\n"));
9578523fda3SJan Friedel 	DPRINT((dbfp, "\thiwater: %d\n", cfg_qctrl.aq_hiwater));
9588523fda3SJan Friedel 	DPRINT((dbfp, "\tlowater: %d\n", cfg_qctrl.aq_lowater));
9598523fda3SJan Friedel 	DPRINT((dbfp, "\tbufsz: %d\n", cfg_qctrl.aq_bufsz));
9608523fda3SJan Friedel 	DPRINT((dbfp, "\tdelay: %ld\n", cfg_qctrl.aq_delay));
9618523fda3SJan Friedel 
9628523fda3SJan Friedel 	if (auditon(A_GETQCTRL, (caddr_t)&act_qctrl, 0) != 0) {
9638523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Could not retrieve "
9648523fda3SJan Friedel 		    "audit queue controls from kernel."));
965*17b6b380SJan Friedel 		err_exit(msg);
9668523fda3SJan Friedel 	}
9678523fda3SJan Friedel 
9688523fda3SJan Friedel 	/* overwrite the default (zeros) from the qctrl configuration */
9698523fda3SJan Friedel 	if (cfg_qctrl.aq_hiwater == 0) {
9708523fda3SJan Friedel 		cfg_qctrl.aq_hiwater = act_qctrl.aq_hiwater;
9718523fda3SJan Friedel 		DPRINT((dbfp, "hiwater changed to active value: %u\n",
9728523fda3SJan Friedel 		    cfg_qctrl.aq_hiwater));
9738523fda3SJan Friedel 	}
9748523fda3SJan Friedel 	if (cfg_qctrl.aq_lowater == 0) {
9758523fda3SJan Friedel 		cfg_qctrl.aq_lowater = act_qctrl.aq_lowater;
9768523fda3SJan Friedel 		DPRINT((dbfp, "lowater changed to active value: %u\n",
9778523fda3SJan Friedel 		    cfg_qctrl.aq_lowater));
9788523fda3SJan Friedel 	}
9798523fda3SJan Friedel 	if (cfg_qctrl.aq_bufsz == 0) {
9808523fda3SJan Friedel 		cfg_qctrl.aq_bufsz = act_qctrl.aq_bufsz;
9818523fda3SJan Friedel 		DPRINT((dbfp, "bufsz changed to active value: %u\n",
9828523fda3SJan Friedel 		    cfg_qctrl.aq_bufsz));
9838523fda3SJan Friedel 	}
9848523fda3SJan Friedel 	if (cfg_qctrl.aq_delay == 0) {
9858523fda3SJan Friedel 		cfg_qctrl.aq_delay = act_qctrl.aq_delay;
9868523fda3SJan Friedel 		DPRINT((dbfp, "delay changed to active value: %ld\n",
9878523fda3SJan Friedel 		    cfg_qctrl.aq_delay));
9888523fda3SJan Friedel 	}
9898523fda3SJan Friedel 
9908523fda3SJan Friedel 	if (auditon(A_SETQCTRL, (caddr_t)&cfg_qctrl, 0) != 0) {
9918523fda3SJan Friedel 		(void) asprintf(&msg,
9928523fda3SJan Friedel 		    gettext("Could not configure audit queue controls."));
993*17b6b380SJan Friedel 		err_exit(msg);
9948523fda3SJan Friedel 	}
9958523fda3SJan Friedel 
9968523fda3SJan Friedel 	DPRINT((dbfp, "qctrl parameters set\n"));
9978523fda3SJan Friedel }
9988523fda3SJan Friedel 
9998523fda3SJan Friedel /*
10008523fda3SJan Friedel  * scf_to_kernel_policy() - update the audit service policies
10018523fda3SJan Friedel  */
10028523fda3SJan Friedel static void
10038523fda3SJan Friedel scf_to_kernel_policy(void)
10048523fda3SJan Friedel {
10058523fda3SJan Friedel 	uint32_t	policy;
10068523fda3SJan Friedel 	char		*msg;
10078523fda3SJan Friedel 
10088523fda3SJan Friedel 	if (!do_getpolicy_scf(&policy)) {
10098523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Unable to get audit policy "
10108523fda3SJan Friedel 		    "configuration from the SMF repository."));
1011*17b6b380SJan Friedel 		err_exit(msg);
10128523fda3SJan Friedel 	}
10138523fda3SJan Friedel 
10148523fda3SJan Friedel 	if (auditon(A_SETPOLICY, (caddr_t)&policy, 0) != 0) {
10158523fda3SJan Friedel 		(void) asprintf(&msg,
10168523fda3SJan Friedel 		    gettext("Could not update active policy settings."));
1017*17b6b380SJan Friedel 		err_exit(msg);
10188523fda3SJan Friedel 	}
10198523fda3SJan Friedel 
10208523fda3SJan Friedel 	DPRINT((dbfp, "kernel policy settings updated\n"));
10218523fda3SJan Friedel }
1022