xref: /titanic_51/usr/src/cmd/auditd/auditd.c (revision 96093503d6c90cc5a0cd2ce8c88e1975be2d00b3)
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
13717b6b380SJan 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();
15017b6b380SJan 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 	DPRINT((dbfp, "mem_test intentional abort (status=%d)\n",
1597c478bd9Sstevel@tonic-gate 	    status));
1607c478bd9Sstevel@tonic-gate 	abort();
1617c478bd9Sstevel@tonic-gate #endif
1627c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "%ld exit status = %d auditing_set = %d\n",
1637c478bd9Sstevel@tonic-gate 	    getpid(), status, auditing_set));
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	if (auditing_set)
1667c478bd9Sstevel@tonic-gate 		(void) auditon(A_SETCOND, (caddr_t)&turn_audit_off,
1677c478bd9Sstevel@tonic-gate 		    (int)sizeof (int));
1687c478bd9Sstevel@tonic-gate 
1698523fda3SJan Friedel #if DEBUG
1708523fda3SJan Friedel 	(void) fclose(dbfp);
1718523fda3SJan Friedel #endif
1728523fda3SJan Friedel 
1737c478bd9Sstevel@tonic-gate 	exit(status);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /* ARGSUSED */
1777883e825Spaulson int
1787c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate 	auditinfo_addr_t	as_null;	/* audit state to set */
1817c478bd9Sstevel@tonic-gate 	au_id_t			auid;
1827c478bd9Sstevel@tonic-gate 	pthread_t		tid;
1837c478bd9Sstevel@tonic-gate 	plugin_t		*p;
1847c478bd9Sstevel@tonic-gate 	pid_t			pid;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #if DEBUG
187dfc7be02SJan Friedel #if MEM_TEST
1887c478bd9Sstevel@tonic-gate 	char	*envp;
189dfc7be02SJan Friedel #endif
1908523fda3SJan Friedel 	if (dbfp == NULL) {
1917c478bd9Sstevel@tonic-gate 		dbfp = __auditd_debug_file_open();
1928523fda3SJan Friedel 	}
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate 	(void) setsid();
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	/* Internationalization */
1977c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1987c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	/*
2017c478bd9Sstevel@tonic-gate 	 * Set the audit host-id.
2027c478bd9Sstevel@tonic-gate 	 */
2037c478bd9Sstevel@tonic-gate 	if (do_sethost() != 0) {
2047c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
2057c478bd9Sstevel@tonic-gate 		auditd_exit(1);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * Turn off all auditing for this process.
2107c478bd9Sstevel@tonic-gate 	 */
2117c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&as_null, sizeof (as_null)) == -1) {
2127c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
21317b6b380SJan Friedel 		auditd_exit(1);
2147c478bd9Sstevel@tonic-gate 	}
2157c478bd9Sstevel@tonic-gate 	as_null.ai_mask.as_success = 0;
2167c478bd9Sstevel@tonic-gate 	as_null.ai_mask.as_failure = 0;
2177c478bd9Sstevel@tonic-gate 	(void) setaudit_addr(&as_null, sizeof (as_null));
2187c478bd9Sstevel@tonic-gate 	auid = AU_NOAUDITID;
2197c478bd9Sstevel@tonic-gate 	(void) setauid(&auid);
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * Set the audit state flag to AUDITING.
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	if (auditon(A_SETCOND, (caddr_t)&turn_audit_on, (int)sizeof (int)) !=
2247c478bd9Sstevel@tonic-gate 	    0) {
2257c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_SETCOND...) failed (exit)\n"));
2267c478bd9Sstevel@tonic-gate 		__audit_dowarn("nostart", "", 0);
22717b6b380SJan Friedel 		auditd_exit(1);
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	block_signals();
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	/*
2337c478bd9Sstevel@tonic-gate 	 * wait for "ready" signal before exit -- for greenline
2347c478bd9Sstevel@tonic-gate 	 */
2357c478bd9Sstevel@tonic-gate 	if (fork()) {
2367c478bd9Sstevel@tonic-gate 		sigset_t	set;
2377c478bd9Sstevel@tonic-gate 		int		signal_caught = 0;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 		(void) sigemptyset(&set);
2407c478bd9Sstevel@tonic-gate 		(void) sigaddset(&set, AU_SIG_DISABLE);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 		while (signal_caught != AU_SIG_DISABLE)
2437c478bd9Sstevel@tonic-gate 			signal_caught = sigwait(&set);
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "init complete:  parent can now exit\n"));
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 		auditd_exit(0);
2487c478bd9Sstevel@tonic-gate 	}
2497c478bd9Sstevel@tonic-gate 	pid = getppid();
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	auditing_set = 1;
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate #if DEBUG && MEM_TEST
2547c478bd9Sstevel@tonic-gate 	envp = getenv("UMEM_DEBUG");
2557c478bd9Sstevel@tonic-gate 	if (envp != NULL)
2567c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "UMEM_DEBUG=%s\n", envp));
2577c478bd9Sstevel@tonic-gate 	envp = getenv("UMEM_LOGGING");
2587c478bd9Sstevel@tonic-gate 	if (envp != NULL)
2597c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "UMEM_LOGGING=%s\n", envp));
2607c478bd9Sstevel@tonic-gate #endif
2617c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd pid=%ld\n", getpid()));
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	/* thread 0 sync */
2647c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&(main_thr.thd_mutex), NULL);
2657c478bd9Sstevel@tonic-gate 	(void) pthread_cond_init(&(main_thr.thd_cv), NULL);
2667c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&plugin_mutex, NULL);
2677c478bd9Sstevel@tonic-gate 	/*
2687c478bd9Sstevel@tonic-gate 	 * Set up a separate thread for signal handling.
2697c478bd9Sstevel@tonic-gate 	 */
2707c478bd9Sstevel@tonic-gate 	if (pthread_create(&tid, NULL, (void *(*)(void *))signal_thread,
2717c478bd9Sstevel@tonic-gate 	    NULL)) {
2727c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
2737c478bd9Sstevel@tonic-gate 		    "auditd can't create a thread\n"));
27417b6b380SJan Friedel 		auditd_exit(1);
2757c478bd9Sstevel@tonic-gate 	}
2767c478bd9Sstevel@tonic-gate 	/*
2777c478bd9Sstevel@tonic-gate 	 * Set the umask so that only audit or other users in the audit group
2787c478bd9Sstevel@tonic-gate 	 * can get to the files created by auditd.
2797c478bd9Sstevel@tonic-gate 	 */
2807c478bd9Sstevel@tonic-gate 	(void) umask(007);
2817c478bd9Sstevel@tonic-gate 
282c900e163Sgww 	if (__logpost("")) {	/* Cannot unlink pointer to audit.log file. */
2837c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "logpost failed\n"));
28417b6b380SJan Friedel 		auditd_exit(1);
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 	/*
2877c478bd9Sstevel@tonic-gate 	 * Here is the main body of the audit daemon.  running == 0 means that
2887c478bd9Sstevel@tonic-gate 	 * after flushing out the audit queue, it is time to exit in response to
2897c478bd9Sstevel@tonic-gate 	 * AU_SIG_DISABLE
2907c478bd9Sstevel@tonic-gate 	 */
2917c478bd9Sstevel@tonic-gate 	while (running) {
2927c478bd9Sstevel@tonic-gate 		/*
2937c478bd9Sstevel@tonic-gate 		 * Read audit_control and create plugin lists.
2947c478bd9Sstevel@tonic-gate 		 *
2957c478bd9Sstevel@tonic-gate 		 * loadauditlist() and auditd_thread_init() are called
2967c478bd9Sstevel@tonic-gate 		 * while under the plugin_mutex lock to avoid a race
2977c478bd9Sstevel@tonic-gate 		 * with unload_plugin().
2987c478bd9Sstevel@tonic-gate 		 */
2997c478bd9Sstevel@tonic-gate 		if (reset_list || reset_file) {
3008523fda3SJan Friedel 			if (reset_list) {
3018523fda3SJan Friedel 				conf_to_kernel();
3028523fda3SJan Friedel 				aconf_to_kernel();
3038523fda3SJan Friedel 				scf_to_kernel_qctrl();
3048523fda3SJan Friedel 				scf_to_kernel_policy();
3057c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_lock(&plugin_mutex);
3067c478bd9Sstevel@tonic-gate 				loadauditlist();
3078523fda3SJan Friedel 			} else {
3088523fda3SJan Friedel 				(void) pthread_mutex_lock(&plugin_mutex);
3098523fda3SJan Friedel 			}
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 			if (auditd_thread_init()) {
3127c478bd9Sstevel@tonic-gate 				auditd_thread_close();
3137c478bd9Sstevel@tonic-gate 				/* continue; wait for audit -s */
3147c478bd9Sstevel@tonic-gate 			}
3157c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&plugin_mutex);
3167c478bd9Sstevel@tonic-gate 			reset_list = 0;
3178523fda3SJan Friedel 
3188523fda3SJan Friedel 			if (reset_list && reset_file) {
3198523fda3SJan Friedel 				(void) printf(gettext("auditd started\n"));
3208523fda3SJan Friedel 			} else {
3218523fda3SJan Friedel 				(void) printf(gettext("auditd refreshed\n"));
3228523fda3SJan Friedel 			}
3237c478bd9Sstevel@tonic-gate 		}
3247c478bd9Sstevel@tonic-gate 		/*
3257c478bd9Sstevel@tonic-gate 		 * tell parent I'm running whether or not the initialization
3267c478bd9Sstevel@tonic-gate 		 * actually worked.  The failure case is to wait for an
3277c478bd9Sstevel@tonic-gate 		 * audit -n or audit -s to fix the problem.
3287c478bd9Sstevel@tonic-gate 		 */
3297c478bd9Sstevel@tonic-gate 		if (pid != 0) {
3307c478bd9Sstevel@tonic-gate 			(void) kill(pid, AU_SIG_DISABLE);
3317c478bd9Sstevel@tonic-gate 			pid = 0;
3327c478bd9Sstevel@tonic-gate 		}
3337c478bd9Sstevel@tonic-gate 		/*
3347c478bd9Sstevel@tonic-gate 		 * thread_signal() signals main (this thread) when
3357c478bd9Sstevel@tonic-gate 		 * it has received a signal.
3367c478bd9Sstevel@tonic-gate 		 */
3377c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "main thread is waiting\n"));
3387c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_lock(&(main_thr.thd_mutex));
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 		if (!(caught_readc || caught_term || caught_alrm ||
3417c478bd9Sstevel@tonic-gate 		    caught_nextd))
3427c478bd9Sstevel@tonic-gate 			(void) pthread_cond_wait(&(main_thr.thd_cv),
3437c478bd9Sstevel@tonic-gate 			    &(main_thr.thd_mutex));
3447c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
3457c478bd9Sstevel@tonic-gate 		/*
3467c478bd9Sstevel@tonic-gate 		 * Got here because a signal came in.
3477c478bd9Sstevel@tonic-gate 		 * Since we may have gotten more than one, we assume a
3487c478bd9Sstevel@tonic-gate 		 * priority scheme with SIGALRM being the most
3497c478bd9Sstevel@tonic-gate 		 * significant.
3507c478bd9Sstevel@tonic-gate 		 */
3517c478bd9Sstevel@tonic-gate 		if (caught_alrm) {
3527c478bd9Sstevel@tonic-gate 			/*
3537c478bd9Sstevel@tonic-gate 			 * We have returned from our timed wait for
3547c478bd9Sstevel@tonic-gate 			 * c2audit to calm down.  We need to really shut
3557c478bd9Sstevel@tonic-gate 			 * down here.
3567c478bd9Sstevel@tonic-gate 			 */
3577c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3587c478bd9Sstevel@tonic-gate 			running = 0;	/* shut down now */
3597c478bd9Sstevel@tonic-gate 		} else if (caught_term) {
3607c478bd9Sstevel@tonic-gate 			/*
3617c478bd9Sstevel@tonic-gate 			 * we are going to shut down, but need to
3627c478bd9Sstevel@tonic-gate 			 * allow time for the audit queues in
3637c478bd9Sstevel@tonic-gate 			 * c2audit and for the threads to empty.
3647c478bd9Sstevel@tonic-gate 			 */
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 			p = plugin_head;
3677c478bd9Sstevel@tonic-gate 			while (p != NULL) {
3687c478bd9Sstevel@tonic-gate 				DPRINT((dbfp, "signalling thread %d\n",
3697c478bd9Sstevel@tonic-gate 				    p->plg_tid));
3707c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_lock(&(p->plg_mutex));
3717c478bd9Sstevel@tonic-gate 				p->plg_removed = 1;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 				if (p->plg_initialized)
3747c478bd9Sstevel@tonic-gate 					(void) pthread_cond_signal(
3757c478bd9Sstevel@tonic-gate 					    &(p->plg_cv));
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 				(void) pthread_mutex_unlock(&(p->plg_mutex));
3787c478bd9Sstevel@tonic-gate 				p = p->plg_next;
3797c478bd9Sstevel@tonic-gate 			}
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3827c478bd9Sstevel@tonic-gate 			caught_readc  = 0;
3837c478bd9Sstevel@tonic-gate 			caught_term = 0;
3847c478bd9Sstevel@tonic-gate 			caught_nextd = 0;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
3877c478bd9Sstevel@tonic-gate 			    "main thread is pausing before exit.\n"));
3887c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_lock(&(main_thr.thd_mutex));
3897c478bd9Sstevel@tonic-gate 			caught_alrm = 0;
3907c478bd9Sstevel@tonic-gate 			(void) alarm(ALRM_TIME);
3917c478bd9Sstevel@tonic-gate 			while (!caught_alrm)
3927c478bd9Sstevel@tonic-gate 				(void) pthread_cond_wait(&(main_thr.thd_cv),
3937c478bd9Sstevel@tonic-gate 				    &(main_thr.thd_mutex));
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 			running = 0;	/* Close down auditing and exit */
3987c478bd9Sstevel@tonic-gate 		} else if (caught_readc) {
3997c478bd9Sstevel@tonic-gate 			/*
4007c478bd9Sstevel@tonic-gate 			 * if both hup and usr1 are caught, the logic in
4017c478bd9Sstevel@tonic-gate 			 * loadauditlist() results in hup winning.  The
4027c478bd9Sstevel@tonic-gate 			 * result will be that the audit file is not rolled
4037c478bd9Sstevel@tonic-gate 			 * over unless audit_control actually changed.
4047c478bd9Sstevel@tonic-gate 			 *
4057c478bd9Sstevel@tonic-gate 			 * They want to reread the audit_control file.
4067c478bd9Sstevel@tonic-gate 			 * Set reset_list which will return us to the
4077c478bd9Sstevel@tonic-gate 			 * main while loop in the main routine.
4087c478bd9Sstevel@tonic-gate 			 */
4097c478bd9Sstevel@tonic-gate 			caught_readc = 0;
4107c478bd9Sstevel@tonic-gate 			reset_list = 1;
4117c478bd9Sstevel@tonic-gate 		} else if (caught_nextd) {
4127c478bd9Sstevel@tonic-gate 			/*
4137c478bd9Sstevel@tonic-gate 			 * This is a special case for the binfile
4147c478bd9Sstevel@tonic-gate 			 * plugin. (audit -n)  NULL out kvlist
4157c478bd9Sstevel@tonic-gate 			 * so binfile won't re-read audit_control
4167c478bd9Sstevel@tonic-gate 			 */
4177c478bd9Sstevel@tonic-gate 			caught_nextd = 0;
4187c478bd9Sstevel@tonic-gate 			reset_file = 1;
4197c478bd9Sstevel@tonic-gate 			if (binfile != NULL) {
4207c478bd9Sstevel@tonic-gate 				_kva_free(binfile->plg_kvlist);
4217c478bd9Sstevel@tonic-gate 				binfile->plg_kvlist = NULL;
4227c478bd9Sstevel@tonic-gate 				binfile->plg_reopen = 1;
4237c478bd9Sstevel@tonic-gate 			}
4247c478bd9Sstevel@tonic-gate 		}
4257c478bd9Sstevel@tonic-gate 	}	/* end while (running) */
4267c478bd9Sstevel@tonic-gate 	auditd_thread_close();
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	auditd_exit(0);
4297c478bd9Sstevel@tonic-gate 	return (0);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * my_sleep - sleep for SLEEP_TIME seconds but only accept the signals
4347c478bd9Sstevel@tonic-gate  *	that we want to accept.  (Premature termination just means the
4357c478bd9Sstevel@tonic-gate  *	caller retries more often, not a big deal.)
4367c478bd9Sstevel@tonic-gate  */
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate static void
4397c478bd9Sstevel@tonic-gate my_sleep()
4407c478bd9Sstevel@tonic-gate {
4417c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd: sleeping for 20 seconds\n"));
4427c478bd9Sstevel@tonic-gate 	/*
4437c478bd9Sstevel@tonic-gate 	 * Set timer to "sleep"
4447c478bd9Sstevel@tonic-gate 	 */
4457c478bd9Sstevel@tonic-gate 	(void) alarm(SLEEP_TIME);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "main thread is waiting for SIGALRM before exit.\n"));
4487c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&(main_thr.thd_mutex));
4497c478bd9Sstevel@tonic-gate 	(void) pthread_cond_wait(&(main_thr.thd_cv), &(main_thr.thd_mutex));
4507c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&(main_thr.thd_mutex));
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	if (caught_term) {
4537c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "normal AU_SIG_DISABLE exit\n"));
4547c478bd9Sstevel@tonic-gate 		/*
4557c478bd9Sstevel@tonic-gate 		 * Exit, as requested.
4567c478bd9Sstevel@tonic-gate 		 */
4577c478bd9Sstevel@tonic-gate 		auditd_thread_close();
4587c478bd9Sstevel@tonic-gate 	}
4597c478bd9Sstevel@tonic-gate 	if (caught_readc)
4607c478bd9Sstevel@tonic-gate 		reset_list = 1;		/* Reread the audit_control file */
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	caught_readc = 0;
4637c478bd9Sstevel@tonic-gate 	caught_nextd = 0;
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate /*
4677c478bd9Sstevel@tonic-gate  * search for $ISA/ in path and replace it with "" if auditd
4687c478bd9Sstevel@tonic-gate  * is 32 bit, else "sparcv9/"  The plugin $ISA must match however
4697c478bd9Sstevel@tonic-gate  * auditd was compiled.
4707c478bd9Sstevel@tonic-gate  */
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate static void
4737c478bd9Sstevel@tonic-gate isa_ified(char *path, char **newpath)
4747c478bd9Sstevel@tonic-gate {
4757c478bd9Sstevel@tonic-gate 	char	*p, *q;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if (((p = strchr(path, '$')) != NULL) &&
4787c478bd9Sstevel@tonic-gate 	    (strncmp("$ISA/", p, 5) == 0)) {
4797c478bd9Sstevel@tonic-gate 		(void) memcpy(*newpath, path, p - path);
4807c478bd9Sstevel@tonic-gate 		q = *newpath + (p - path);
4817c478bd9Sstevel@tonic-gate #ifdef __sparcv9
4827c478bd9Sstevel@tonic-gate 		q += strlcpy(q, "sparcv9/", avail_length);
4837c478bd9Sstevel@tonic-gate #endif
4847c478bd9Sstevel@tonic-gate 		(void) strcpy(q, p + 5);
4857c478bd9Sstevel@tonic-gate 	} else
4867c478bd9Sstevel@tonic-gate 		*newpath = path;
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate /*
4907c478bd9Sstevel@tonic-gate  * init_plugin first searches the existing plugin list to see
4917c478bd9Sstevel@tonic-gate  * if the plugin already has been defined; if not, it creates it
4927c478bd9Sstevel@tonic-gate  * and links it into the list.  It returns a pointer to the found
4937c478bd9Sstevel@tonic-gate  * or created struct.  A change of path in audit_control for a
4947c478bd9Sstevel@tonic-gate  * given plugin will cause a miss.
4957c478bd9Sstevel@tonic-gate  */
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate  * for 64 bits, the path name can grow 3 bytes (minus 5 for the
4987c478bd9Sstevel@tonic-gate  * removed "$ISA" and plus 8 for the added "sparcv9/"
4997c478bd9Sstevel@tonic-gate  */
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate #define	ISA_GROW	8 - 5
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate static plugin_t *
5047c478bd9Sstevel@tonic-gate init_plugin(char *name, kva_t *list, int cnt_flag)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate 	plugin_t	*p, *q;
5077c478bd9Sstevel@tonic-gate 	char		filepath[MAXPATHLEN + 1 + ISA_GROW];
5087c478bd9Sstevel@tonic-gate 	char		*path = filepath;
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	if (*name != '/') {
5117c478bd9Sstevel@tonic-gate #ifdef  __sparcv9
5127c478bd9Sstevel@tonic-gate 		(void) strcpy(filepath, "/usr/lib/security/sparcv9/");
5137c478bd9Sstevel@tonic-gate #else
5147c478bd9Sstevel@tonic-gate 		(void) strcpy(filepath, "/usr/lib/security/");
5157c478bd9Sstevel@tonic-gate #endif
5167c478bd9Sstevel@tonic-gate 		if (strlcat(filepath, name, MAXPATHLEN) >= MAXPATHLEN)
5177c478bd9Sstevel@tonic-gate 			return (NULL);
5187c478bd9Sstevel@tonic-gate 	} else {
5197c478bd9Sstevel@tonic-gate 		if (strlen(name) > MAXPATHLEN + ISA_GROW)
5207c478bd9Sstevel@tonic-gate 			return (NULL);
5217c478bd9Sstevel@tonic-gate 		isa_ified(name, &path);
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate 	p = plugin_head;
5247c478bd9Sstevel@tonic-gate 	q = plugin_head;
5257c478bd9Sstevel@tonic-gate 	while (p != NULL) {
5267c478bd9Sstevel@tonic-gate 		if (p->plg_path != NULL) {
5277c478bd9Sstevel@tonic-gate 			if (strcmp(p->plg_path, path) == 0) {
5287c478bd9Sstevel@tonic-gate 				p->plg_removed = 0;
5297c478bd9Sstevel@tonic-gate 				p->plg_to_be_removed = 0;
5307c478bd9Sstevel@tonic-gate 				p->plg_cnt = cnt_flag;
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 				_kva_free(p->plg_kvlist);
5337c478bd9Sstevel@tonic-gate 				p->plg_kvlist = list;
5347c478bd9Sstevel@tonic-gate 				p->plg_reopen = 1;
5357c478bd9Sstevel@tonic-gate 				DPRINT((dbfp, "reusing %s\n", p->plg_path));
5367c478bd9Sstevel@tonic-gate 				return (p);
5377c478bd9Sstevel@tonic-gate 			}
5387c478bd9Sstevel@tonic-gate 		}
5397c478bd9Sstevel@tonic-gate 		q = p;
5407c478bd9Sstevel@tonic-gate 		p = p->plg_next;
5417c478bd9Sstevel@tonic-gate 	}
5427c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "creating new plugin structure for %s\n", path));
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 	p = malloc(sizeof (plugin_t));
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	if (p == NULL) {
5477c478bd9Sstevel@tonic-gate 		perror("auditd");
5487c478bd9Sstevel@tonic-gate 		return (NULL);
5497c478bd9Sstevel@tonic-gate 	}
5507c478bd9Sstevel@tonic-gate 	if (q == NULL)
5517c478bd9Sstevel@tonic-gate 		plugin_head = p;
5527c478bd9Sstevel@tonic-gate 	else
5537c478bd9Sstevel@tonic-gate 		q->plg_next = p;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	p->plg_next = NULL;
5567c478bd9Sstevel@tonic-gate 	p->plg_initialized = 0;
5577c478bd9Sstevel@tonic-gate 	p->plg_reopen = 1;
5587c478bd9Sstevel@tonic-gate 	p->plg_tid = 0;
5597c478bd9Sstevel@tonic-gate 	p->plg_removed = 0;
5607c478bd9Sstevel@tonic-gate 	p->plg_to_be_removed = 0;
5617c478bd9Sstevel@tonic-gate 	p->plg_tossed = 0;
5627c478bd9Sstevel@tonic-gate 	p->plg_queued = 0;
5637c478bd9Sstevel@tonic-gate 	p->plg_output = 0;
5647c478bd9Sstevel@tonic-gate 	p->plg_sequence = 1;
5657c478bd9Sstevel@tonic-gate 	p->plg_last_seq_out = 0;
5667c478bd9Sstevel@tonic-gate 	p->plg_path = strdup(path);
5677c478bd9Sstevel@tonic-gate 	p->plg_kvlist = list;
5687c478bd9Sstevel@tonic-gate 	p->plg_cnt = cnt_flag;
5697c478bd9Sstevel@tonic-gate 	p->plg_retry_time = SLEEP_TIME;
5707c478bd9Sstevel@tonic-gate 	p->plg_qmax = 0;
5717c478bd9Sstevel@tonic-gate 	p->plg_save_q_copy = NULL;
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "created plugin:  %s\n", path));
5747c478bd9Sstevel@tonic-gate 	return (p);
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate /*
5787c478bd9Sstevel@tonic-gate  * loadauditlist - read the directory list from the audit_control file.
5797c478bd9Sstevel@tonic-gate  *		   to determine if a binary file is to be written.
5807c478bd9Sstevel@tonic-gate  *		 - read the plugin entries from the audit_control file
5817c478bd9Sstevel@tonic-gate  *
5827c478bd9Sstevel@tonic-gate  * globals -
5837c478bd9Sstevel@tonic-gate  *
5847c478bd9Sstevel@tonic-gate  *	plugin queues
5857c478bd9Sstevel@tonic-gate  *
5867c478bd9Sstevel@tonic-gate  * success is when at least one plug in is defined.
5877c478bd9Sstevel@tonic-gate  *
5887c478bd9Sstevel@tonic-gate  * set cnt policy here based on auditconfig setting.  future could
5897c478bd9Sstevel@tonic-gate  * have a policy = {+|-}cnt entry per plugin with auditconfig providing the
5907c478bd9Sstevel@tonic-gate  * default.
5917c478bd9Sstevel@tonic-gate  */
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate static void
5947c478bd9Sstevel@tonic-gate loadauditlist()
5957c478bd9Sstevel@tonic-gate {
5967c478bd9Sstevel@tonic-gate 	char		buf[MAXPATHLEN];
5977c478bd9Sstevel@tonic-gate 	char		*value;
5987c478bd9Sstevel@tonic-gate 	plugin_t	*p;
5997c478bd9Sstevel@tonic-gate 	int		acresult;
6007c478bd9Sstevel@tonic-gate 	int		wait_count = 0;
6017c478bd9Sstevel@tonic-gate 	kva_t		*kvlist;
602*96093503SMarek Pospisil 	uint32_t	policy;
6037c478bd9Sstevel@tonic-gate 	int		cnt_flag;
6047c478bd9Sstevel@tonic-gate 	struct au_qctrl	kqmax;
6057c478bd9Sstevel@tonic-gate 	au_acinfo_t	*ach = NULL;
6067c478bd9Sstevel@tonic-gate 	int		got_dir = 0;
6077c478bd9Sstevel@tonic-gate 	int		have_plugin = 0;
6087c478bd9Sstevel@tonic-gate 	char		*endptr;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	if (auditon(A_GETPOLICY, (char *)&policy, 0) == -1) {
6117c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETPOLICY...) failed (exit)\n"));
6127c478bd9Sstevel@tonic-gate 		__audit_dowarn("auditoff", "", 0);
6137c478bd9Sstevel@tonic-gate 		auditd_thread_close();
61417b6b380SJan Friedel 		auditd_exit(1);
6157c478bd9Sstevel@tonic-gate 	}
6167c478bd9Sstevel@tonic-gate 	cnt_flag = ((policy & AUDIT_CNT) != 0) ? 1 : 0;
6177c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "loadauditlist:  policy is to %s\n", (cnt_flag == 1) ?
6187c478bd9Sstevel@tonic-gate 	    "continue" : "block"));
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate #if DEBUG
6218523fda3SJan Friedel 	if (auditon(A_GETCOND, (caddr_t)&acresult, (int)sizeof (int)) != 0)
6227c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETCOND...) failed (exit)\n"));
6238523fda3SJan Friedel 
6247c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "audit cond = %d (1 is on)\n", acresult));
6258523fda3SJan Friedel #endif
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	if (auditon(A_GETQCTRL, (char *)&kqmax, sizeof (struct au_qctrl)) !=
6297c478bd9Sstevel@tonic-gate 	    0) {
6307c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "auditon(A_GETQCTRL...) failed (exit)\n"));
6317c478bd9Sstevel@tonic-gate 		__audit_dowarn("auditoff", "", 0);
6327c478bd9Sstevel@tonic-gate 		auditd_thread_close();
63317b6b380SJan Friedel 		auditd_exit(1);
6347c478bd9Sstevel@tonic-gate 	}
6357c478bd9Sstevel@tonic-gate 	kqmax.aq_hiwater *= 5;		/* RAM is cheaper in userspace */
6367c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "auditd: reading audit_control\n"));
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 	p = plugin_head;
6397c478bd9Sstevel@tonic-gate 	/*
6407c478bd9Sstevel@tonic-gate 	 * two-step on setting p->plg_removed because the input thread
6417c478bd9Sstevel@tonic-gate 	 * in doorway.c uses p->plg_removed to decide if the plugin is
6427c478bd9Sstevel@tonic-gate 	 * active.
6437c478bd9Sstevel@tonic-gate 	 */
6447c478bd9Sstevel@tonic-gate 	while (p != NULL) {
6458523fda3SJan Friedel 		DPRINT((dbfp, "loadauditlist:  %p, %s previously created\n",
6468523fda3SJan Friedel 		    (void *)p, p->plg_path));
6477c478bd9Sstevel@tonic-gate 		p->plg_to_be_removed = 1;	/* tentative removal */
6487c478bd9Sstevel@tonic-gate 		p = p->plg_next;
6497c478bd9Sstevel@tonic-gate 	}
6507c478bd9Sstevel@tonic-gate 	/*
6517c478bd9Sstevel@tonic-gate 	 * have_plugin may over count by one if both a "dir" entry
6527c478bd9Sstevel@tonic-gate 	 * and a "plugin" entry for binfile are found.  All that
6537c478bd9Sstevel@tonic-gate 	 * matters is that it be zero if no plugin or dir entries
6547c478bd9Sstevel@tonic-gate 	 * are found.
6557c478bd9Sstevel@tonic-gate 	 */
6567c478bd9Sstevel@tonic-gate 	have_plugin = 0;
6577c478bd9Sstevel@tonic-gate 	for (;;) {
6587c478bd9Sstevel@tonic-gate 		/* NULL == use standard path for audit_control */
6597c478bd9Sstevel@tonic-gate 		ach = _openac(NULL);
6607c478bd9Sstevel@tonic-gate 		/*
6617c478bd9Sstevel@tonic-gate 		 * loop until a directory entry is found (0) or eof (-1)
6627c478bd9Sstevel@tonic-gate 		 */
6637c478bd9Sstevel@tonic-gate 		while (((acresult = _getacdir(ach, buf, sizeof (buf))) != 0) &&
6647c478bd9Sstevel@tonic-gate 		    acresult != -1) {
6657c478bd9Sstevel@tonic-gate 		}
6667c478bd9Sstevel@tonic-gate 		if (acresult == 0) {
6677c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
6687c478bd9Sstevel@tonic-gate 			    "loadauditlist: "
6697c478bd9Sstevel@tonic-gate 			    "got binfile via old config syntax\n"));
6707c478bd9Sstevel@tonic-gate 			/*
6717c478bd9Sstevel@tonic-gate 			 * A directory entry was found.
6727c478bd9Sstevel@tonic-gate 			 */
6737c478bd9Sstevel@tonic-gate 			got_dir = 1;
6747c478bd9Sstevel@tonic-gate 			kvlist = _str2kva("name=audit_binfile.so.1",
6757c478bd9Sstevel@tonic-gate 			    "=", ";");
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 			p = init_plugin("audit_binfile.so.1", kvlist, cnt_flag);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 			if (p != NULL) {
6807c478bd9Sstevel@tonic-gate 				binfile = p;
6817c478bd9Sstevel@tonic-gate 				p->plg_qmax = kqmax.aq_hiwater;
6827c478bd9Sstevel@tonic-gate 				have_plugin++;
6837c478bd9Sstevel@tonic-gate 			}
6847c478bd9Sstevel@tonic-gate 		}
6857c478bd9Sstevel@tonic-gate 		/*
6867c478bd9Sstevel@tonic-gate 		 * collect plugin entries.  If there is an entry for
6877c478bd9Sstevel@tonic-gate 		 * binfile.so.1, the parameters from the plugin line
6887c478bd9Sstevel@tonic-gate 		 * override those set above.  For binfile, p_dir is
6897c478bd9Sstevel@tonic-gate 		 * required only if dir wasn't specified elsewhere in
6907c478bd9Sstevel@tonic-gate 		 * audit_control
6917c478bd9Sstevel@tonic-gate 		 */
6927c478bd9Sstevel@tonic-gate 		_rewindac(ach);
6937c478bd9Sstevel@tonic-gate 		while ((acresult = _getacplug(ach, &kvlist)) == 0) {
6947c478bd9Sstevel@tonic-gate 			value = kva_match(kvlist, "name");
6957c478bd9Sstevel@tonic-gate 			if (value == NULL)
6967c478bd9Sstevel@tonic-gate 				break;
6977c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "loadauditlist: have an entry for %s\n",
6987c478bd9Sstevel@tonic-gate 			    value));
6997c478bd9Sstevel@tonic-gate 			p = init_plugin(value, kvlist, cnt_flag);
7007c478bd9Sstevel@tonic-gate 			if (p == NULL)
7017c478bd9Sstevel@tonic-gate 				continue;
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 			if (strstr(value, "/audit_binfile.so") != NULL) {
7047c478bd9Sstevel@tonic-gate 				binfile = p;
7057c478bd9Sstevel@tonic-gate 				if (!got_dir &&
7067c478bd9Sstevel@tonic-gate 				    (kva_match(kvlist, "p_dir") ==
7077c478bd9Sstevel@tonic-gate 				    NULL)) {
7087c478bd9Sstevel@tonic-gate 					__audit_dowarn("getacdir", "",
7097c478bd9Sstevel@tonic-gate 					    wait_count);
7107c478bd9Sstevel@tonic-gate 				}
7117c478bd9Sstevel@tonic-gate 			}
7127c478bd9Sstevel@tonic-gate 			p->plg_qmax = kqmax.aq_hiwater; /* default */
7137c478bd9Sstevel@tonic-gate 			value = kva_match(kvlist, "qsize");
7147c478bd9Sstevel@tonic-gate 			if (value != NULL) {
7157c478bd9Sstevel@tonic-gate 				long	tmp;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 				tmp = strtol(value, &endptr, 10);
7187c478bd9Sstevel@tonic-gate 				if (*endptr == '\0')
7197c478bd9Sstevel@tonic-gate 					p->plg_qmax = tmp;
7207c478bd9Sstevel@tonic-gate 			}
7219697ae98Sgww 			DPRINT((dbfp, "%s queue max = %d\n", p->plg_path,
7229697ae98Sgww 			    p->plg_qmax));
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 			have_plugin++;
7257c478bd9Sstevel@tonic-gate 		}
7267c478bd9Sstevel@tonic-gate 		_endac(ach);
7277c478bd9Sstevel@tonic-gate 		if (have_plugin != 0)
7287c478bd9Sstevel@tonic-gate 			break;
7297c478bd9Sstevel@tonic-gate 		/*
7307c478bd9Sstevel@tonic-gate 		 * there was a problem getting the directory
7317c478bd9Sstevel@tonic-gate 		 * list or remote host info from the audit_control file
7327c478bd9Sstevel@tonic-gate 		 */
7337c478bd9Sstevel@tonic-gate 		wait_count++;
7347c478bd9Sstevel@tonic-gate #if DEBUG
7357c478bd9Sstevel@tonic-gate 		if (wait_count < 2)
7367c478bd9Sstevel@tonic-gate 			DPRINT((dbfp,
7377c478bd9Sstevel@tonic-gate 			    "auditd: problem getting directory "
7387c478bd9Sstevel@tonic-gate 			    "/ or plugin list from audit_control.\n"));
7397c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
7407c478bd9Sstevel@tonic-gate 		__audit_dowarn("getacdir", "", wait_count);
7417c478bd9Sstevel@tonic-gate 		/*
7427c478bd9Sstevel@tonic-gate 		 * sleep for SLEEP_TIME seconds.
7437c478bd9Sstevel@tonic-gate 		 */
7447c478bd9Sstevel@tonic-gate 		my_sleep();
7457c478bd9Sstevel@tonic-gate 	}    /* end for(;;) */
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	p = plugin_head;
7487c478bd9Sstevel@tonic-gate 	while (p != NULL) {
7497c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "loadauditlist: %s remove flag=%d; cnt=%d\n",
7507c478bd9Sstevel@tonic-gate 		    p->plg_path, p->plg_to_be_removed, p->plg_cnt));
7517c478bd9Sstevel@tonic-gate 		p->plg_removed = p->plg_to_be_removed;
7527c478bd9Sstevel@tonic-gate 		p = p->plg_next;
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate /*
7577c478bd9Sstevel@tonic-gate  * block signals -- thread-specific blocking of the signals expected
7587c478bd9Sstevel@tonic-gate  * by the main thread.
7597c478bd9Sstevel@tonic-gate  */
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate static void
7627c478bd9Sstevel@tonic-gate block_signals()
7637c478bd9Sstevel@tonic-gate {
7647c478bd9Sstevel@tonic-gate 	sigset_t	set;
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 	(void) sigfillset(&set);
7677c478bd9Sstevel@tonic-gate 	(void) pthread_sigmask(SIG_BLOCK, &set, NULL);
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate /*
7717c478bd9Sstevel@tonic-gate  * signal_thread is the designated signal catcher.  It wakes up the
7727c478bd9Sstevel@tonic-gate  * main thread whenever it receives a signal and then goes back to
7737c478bd9Sstevel@tonic-gate  * sleep; it does not exit.  The global variables caught_* let
7747c478bd9Sstevel@tonic-gate  * the main thread which signal was received.
7757c478bd9Sstevel@tonic-gate  *
7767c478bd9Sstevel@tonic-gate  * The thread is created with all signals blocked.
7777c478bd9Sstevel@tonic-gate  */
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate static void
7807c478bd9Sstevel@tonic-gate signal_thread()
7817c478bd9Sstevel@tonic-gate {
7827c478bd9Sstevel@tonic-gate 	sigset_t	set;
7837c478bd9Sstevel@tonic-gate 	int		signal_caught;
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "the signal thread is thread %d\n",
7867c478bd9Sstevel@tonic-gate 	    pthread_self()));
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&set);
7897c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, SIGALRM);
7907c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_DISABLE);
7917c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_READ_CONTROL);
7927c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, AU_SIG_NEXT_DIR);
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	for (;;) {
7957c478bd9Sstevel@tonic-gate 		signal_caught = sigwait(&set);
7967c478bd9Sstevel@tonic-gate 		switch (signal_caught) {
7977c478bd9Sstevel@tonic-gate 		case SIGALRM:
7987c478bd9Sstevel@tonic-gate 			caught_alrm++;
7997c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught SIGALRM\n"));
8007c478bd9Sstevel@tonic-gate 			break;
8017c478bd9Sstevel@tonic-gate 		case AU_SIG_DISABLE:
8027c478bd9Sstevel@tonic-gate 			caught_term++;
8037c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_DISABLE\n"));
8047c478bd9Sstevel@tonic-gate 			break;
8057c478bd9Sstevel@tonic-gate 		case AU_SIG_READ_CONTROL:
8067c478bd9Sstevel@tonic-gate 			caught_readc++;
8077c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_READ_CONTROL\n"));
8087c478bd9Sstevel@tonic-gate 			break;
8097c478bd9Sstevel@tonic-gate 		case AU_SIG_NEXT_DIR:
8107c478bd9Sstevel@tonic-gate 			caught_nextd++;
8117c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught AU_SIG_NEXT_DIR\n"));
8127c478bd9Sstevel@tonic-gate 			break;
8137c478bd9Sstevel@tonic-gate 		default:
8147c478bd9Sstevel@tonic-gate 			DPRINT((dbfp, "caught unexpected signal:  %d\n",
8157c478bd9Sstevel@tonic-gate 			    signal_caught));
8167c478bd9Sstevel@tonic-gate 			break;
8177c478bd9Sstevel@tonic-gate 		}
8187c478bd9Sstevel@tonic-gate 		(void) pthread_cond_signal(&(main_thr.thd_cv));
8197c478bd9Sstevel@tonic-gate 	}
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate /*
8237c478bd9Sstevel@tonic-gate  * do_sethost - do auditon(2) to set the audit host-id.
8249697ae98Sgww  *		Returns 0 if success or -1 otherwise.
8257c478bd9Sstevel@tonic-gate  */
8267c478bd9Sstevel@tonic-gate static int
8277c478bd9Sstevel@tonic-gate do_sethost(void)
8287c478bd9Sstevel@tonic-gate {
8299697ae98Sgww 	au_tid_addr_t	*termid;
8307c478bd9Sstevel@tonic-gate 	auditinfo_addr_t	audit_info;
8319697ae98Sgww 	char	msg[512];
8327c478bd9Sstevel@tonic-gate 
8339697ae98Sgww 	if (adt_load_hostname(NULL, (adt_termid_t **)&termid) < 0) {
8349697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to get local "
8359697ae98Sgww 		    "IP address: %s", strerror(errno));
8369697ae98Sgww 		goto fail;
8377c478bd9Sstevel@tonic-gate 	}
8387c478bd9Sstevel@tonic-gate 	/* Get current kernel audit info, and fill in the IP address */
8399697ae98Sgww 	if (auditon(A_GETKAUDIT, (caddr_t)&audit_info,
8409697ae98Sgww 	    sizeof (audit_info)) < 0) {
8419697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to get kernel "
8429697ae98Sgww 		    "audit info: %s", strerror(errno));
8439697ae98Sgww 		goto fail;
8447c478bd9Sstevel@tonic-gate 	}
8457c478bd9Sstevel@tonic-gate 
8469697ae98Sgww 	audit_info.ai_termid = *termid;
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate 	/* Update the kernel audit info with new IP address */
8499697ae98Sgww 	if (auditon(A_SETKAUDIT, (caddr_t)&audit_info,
8509697ae98Sgww 	    sizeof (audit_info)) < 0) {
8519697ae98Sgww 		(void) snprintf(msg, sizeof (msg), "unable to set kernel "
8529697ae98Sgww 		    "audit info: %s", strerror(errno));
8539697ae98Sgww 		goto fail;
8547c478bd9Sstevel@tonic-gate 	}
8557c478bd9Sstevel@tonic-gate 
8569697ae98Sgww 	free(termid);
8577c478bd9Sstevel@tonic-gate 	return (0);
8589697ae98Sgww 
8599697ae98Sgww fail:
8609697ae98Sgww 	free(termid);
8619697ae98Sgww 	__audit_syslog("auditd", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_DAEMON,
8629697ae98Sgww 	    LOG_ALERT, msg);
8639697ae98Sgww 	return (-1);
8647c478bd9Sstevel@tonic-gate }
8658523fda3SJan Friedel 
8668523fda3SJan Friedel /*
8678523fda3SJan Friedel  * conf_to_kernel() - configure the event to class mapping; see also
8688523fda3SJan Friedel  * auditconfig(1M) -conf option.
8698523fda3SJan Friedel  */
8708523fda3SJan Friedel static void
8718523fda3SJan Friedel conf_to_kernel(void)
8728523fda3SJan Friedel {
8738523fda3SJan Friedel 	register au_event_ent_t *evp;
8748523fda3SJan Friedel 	register int 		i;
8758523fda3SJan Friedel 	char			*msg;
8768523fda3SJan Friedel 	au_evclass_map_t 	ec;
8778523fda3SJan Friedel 	au_stat_t 		as;
8788523fda3SJan Friedel 
8798523fda3SJan Friedel 	if (auditon(A_GETSTAT, (caddr_t)&as, 0) != 0) {
8808523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Audit module does not appear "
8818523fda3SJan Friedel 		    "to be loaded."));
88217b6b380SJan Friedel 		err_exit(msg);
8838523fda3SJan Friedel 	}
8848523fda3SJan Friedel 
8858523fda3SJan Friedel 	i = 0;
8868523fda3SJan Friedel 	setauevent();
8878523fda3SJan Friedel 	while ((evp = getauevent()) != NULL) {
8888523fda3SJan Friedel 		if (evp->ae_number <= as.as_numevent) {
8898523fda3SJan Friedel 			++i;
8908523fda3SJan Friedel 			ec.ec_number = evp->ae_number;
8918523fda3SJan Friedel 			ec.ec_class = evp->ae_class;
8928523fda3SJan Friedel 
8938523fda3SJan Friedel 			if (auditon(A_SETCLASS, (caddr_t)&ec,
8948523fda3SJan Friedel 			    (int)sizeof (ec)) != 0) {
8958523fda3SJan Friedel 				(void) asprintf(&msg,
8968523fda3SJan Friedel 				    gettext("Could not configure kernel audit "
8978523fda3SJan Friedel 				    "event to class mappings."));
89817b6b380SJan Friedel 				err_exit(msg);
8998523fda3SJan Friedel 			}
9008523fda3SJan Friedel 		}
9018523fda3SJan Friedel 	}
9028523fda3SJan Friedel 	endauevent();
9038523fda3SJan Friedel 
9048523fda3SJan Friedel 	DPRINT((dbfp, "configured %d kernel events.\n", i));
9058523fda3SJan Friedel }
9068523fda3SJan Friedel 
9078523fda3SJan Friedel /*
9088523fda3SJan Friedel  * aconf_to_kernel() - set the non-attributable audit mask from the
9098523fda3SJan Friedel  * audit_control(4); see also auditconfig(1M) -aconf option.
9108523fda3SJan Friedel  */
9118523fda3SJan Friedel static void
9128523fda3SJan Friedel aconf_to_kernel(void)
9138523fda3SJan Friedel {
9148523fda3SJan Friedel 	char		*msg;
9158523fda3SJan Friedel 	char		buf[2048];
9168523fda3SJan Friedel 	au_mask_t	pmask;
9178523fda3SJan Friedel 
9188523fda3SJan Friedel 	if (getacna(buf, sizeof (buf)) < 0) {
9198523fda3SJan Friedel 		(void) asprintf(&msg,
9208523fda3SJan Friedel 		    gettext("bad non-attributable flags in audit_control(4)"));
92117b6b380SJan Friedel 		err_exit(msg);
9228523fda3SJan Friedel 	}
9238523fda3SJan Friedel 
9248523fda3SJan Friedel 	if (getauditflagsbin(buf, &pmask) < 0) {
9258523fda3SJan Friedel 		(void) asprintf(&msg,
9268523fda3SJan Friedel 		    gettext("bad audit flag value encountered"));
92717b6b380SJan Friedel 		err_exit(msg);
9288523fda3SJan Friedel 	}
9298523fda3SJan Friedel 
9308523fda3SJan Friedel 	if (auditon(A_SETKMASK, (caddr_t)&pmask, (int)sizeof (pmask)) != 0) {
9318523fda3SJan Friedel 		(void) asprintf(&msg,
9328523fda3SJan Friedel 		    gettext("Could not configure non-attributable events."));
93317b6b380SJan Friedel 		err_exit(msg);
9348523fda3SJan Friedel 	}
9358523fda3SJan Friedel 
9368523fda3SJan Friedel 	DPRINT((dbfp, "configured non-attributable events.\n"));
9378523fda3SJan Friedel }
9388523fda3SJan Friedel 
9398523fda3SJan Friedel /*
9408523fda3SJan Friedel  * scf_to_kernel_qctrl() - update the kernel queue control parameters
9418523fda3SJan Friedel  */
9428523fda3SJan Friedel static void
9438523fda3SJan Friedel scf_to_kernel_qctrl(void)
9448523fda3SJan Friedel {
9458523fda3SJan Friedel 	struct au_qctrl	act_qctrl;
9468523fda3SJan Friedel 	struct au_qctrl	cfg_qctrl;
9478523fda3SJan Friedel 	char		*msg;
9488523fda3SJan Friedel 
9498523fda3SJan Friedel 	if (!do_getqctrl_scf(&cfg_qctrl)) {
9508523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Unable to gather audit queue "
9518523fda3SJan Friedel 		    "control parameters from the SMF repository."));
95217b6b380SJan Friedel 		err_exit(msg);
9538523fda3SJan Friedel 	}
9548523fda3SJan Friedel 
9558523fda3SJan Friedel 	DPRINT((dbfp, "will check and set qctrl parameters:\n"));
9568523fda3SJan Friedel 	DPRINT((dbfp, "\thiwater: %d\n", cfg_qctrl.aq_hiwater));
9578523fda3SJan Friedel 	DPRINT((dbfp, "\tlowater: %d\n", cfg_qctrl.aq_lowater));
9588523fda3SJan Friedel 	DPRINT((dbfp, "\tbufsz: %d\n", cfg_qctrl.aq_bufsz));
9598523fda3SJan Friedel 	DPRINT((dbfp, "\tdelay: %ld\n", cfg_qctrl.aq_delay));
9608523fda3SJan Friedel 
9618523fda3SJan Friedel 	if (auditon(A_GETQCTRL, (caddr_t)&act_qctrl, 0) != 0) {
9628523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Could not retrieve "
9638523fda3SJan Friedel 		    "audit queue controls from kernel."));
96417b6b380SJan Friedel 		err_exit(msg);
9658523fda3SJan Friedel 	}
9668523fda3SJan Friedel 
9678523fda3SJan Friedel 	/* overwrite the default (zeros) from the qctrl configuration */
9688523fda3SJan Friedel 	if (cfg_qctrl.aq_hiwater == 0) {
9698523fda3SJan Friedel 		cfg_qctrl.aq_hiwater = act_qctrl.aq_hiwater;
9708523fda3SJan Friedel 		DPRINT((dbfp, "hiwater changed to active value: %u\n",
9718523fda3SJan Friedel 		    cfg_qctrl.aq_hiwater));
9728523fda3SJan Friedel 	}
9738523fda3SJan Friedel 	if (cfg_qctrl.aq_lowater == 0) {
9748523fda3SJan Friedel 		cfg_qctrl.aq_lowater = act_qctrl.aq_lowater;
9758523fda3SJan Friedel 		DPRINT((dbfp, "lowater changed to active value: %u\n",
9768523fda3SJan Friedel 		    cfg_qctrl.aq_lowater));
9778523fda3SJan Friedel 	}
9788523fda3SJan Friedel 	if (cfg_qctrl.aq_bufsz == 0) {
9798523fda3SJan Friedel 		cfg_qctrl.aq_bufsz = act_qctrl.aq_bufsz;
9808523fda3SJan Friedel 		DPRINT((dbfp, "bufsz changed to active value: %u\n",
9818523fda3SJan Friedel 		    cfg_qctrl.aq_bufsz));
9828523fda3SJan Friedel 	}
9838523fda3SJan Friedel 	if (cfg_qctrl.aq_delay == 0) {
9848523fda3SJan Friedel 		cfg_qctrl.aq_delay = act_qctrl.aq_delay;
9858523fda3SJan Friedel 		DPRINT((dbfp, "delay changed to active value: %ld\n",
9868523fda3SJan Friedel 		    cfg_qctrl.aq_delay));
9878523fda3SJan Friedel 	}
9888523fda3SJan Friedel 
9898523fda3SJan Friedel 	if (auditon(A_SETQCTRL, (caddr_t)&cfg_qctrl, 0) != 0) {
9908523fda3SJan Friedel 		(void) asprintf(&msg,
9918523fda3SJan Friedel 		    gettext("Could not configure audit queue controls."));
99217b6b380SJan Friedel 		err_exit(msg);
9938523fda3SJan Friedel 	}
9948523fda3SJan Friedel 
9958523fda3SJan Friedel 	DPRINT((dbfp, "qctrl parameters set\n"));
9968523fda3SJan Friedel }
9978523fda3SJan Friedel 
9988523fda3SJan Friedel /*
9998523fda3SJan Friedel  * scf_to_kernel_policy() - update the audit service policies
10008523fda3SJan Friedel  */
10018523fda3SJan Friedel static void
10028523fda3SJan Friedel scf_to_kernel_policy(void)
10038523fda3SJan Friedel {
10048523fda3SJan Friedel 	uint32_t	policy;
10058523fda3SJan Friedel 	char		*msg;
10068523fda3SJan Friedel 
10078523fda3SJan Friedel 	if (!do_getpolicy_scf(&policy)) {
10088523fda3SJan Friedel 		(void) asprintf(&msg, gettext("Unable to get audit policy "
10098523fda3SJan Friedel 		    "configuration from the SMF repository."));
101017b6b380SJan Friedel 		err_exit(msg);
10118523fda3SJan Friedel 	}
10128523fda3SJan Friedel 
10138523fda3SJan Friedel 	if (auditon(A_SETPOLICY, (caddr_t)&policy, 0) != 0) {
10148523fda3SJan Friedel 		(void) asprintf(&msg,
10158523fda3SJan Friedel 		    gettext("Could not update active policy settings."));
101617b6b380SJan Friedel 		err_exit(msg);
10178523fda3SJan Friedel 	}
10188523fda3SJan Friedel 
10198523fda3SJan Friedel 	DPRINT((dbfp, "kernel policy settings updated\n"));
10208523fda3SJan Friedel }
1021