xref: /titanic_52/usr/src/cmd/audit_warn/audit_warn.sh (revision f89940742f5d14dde79b69b98a414dd7b7f585c7)
17c478bd9Sstevel@tonic-gate#! /bin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
61a578a15Spaulson# Common Development and Distribution License (the "License").
71a578a15Spaulson# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*f8994074SJan Friedel# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate# This shell script warns the administrator when there are problems or
277c478bd9Sstevel@tonic-gate# potential problems with the audit daemon.  The default script sends
287c478bd9Sstevel@tonic-gate# a message to the machine console in the case where there
297c478bd9Sstevel@tonic-gate# is no audit space available.  It has comments in a few places where
307c478bd9Sstevel@tonic-gate# additional actions might be appropriate (eg. clearing some space).
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate#---------------------------------------------------------------------------
337c478bd9Sstevel@tonic-gate# send mail and generate syslog output
347c478bd9Sstevel@tonic-gate#
357c478bd9Sstevel@tonic-gate# $MESSAGE and $SUBJECT are set by the caller
367c478bd9Sstevel@tonic-gate#
377c478bd9Sstevel@tonic-gate# edit this function to omit syslog or mail output.
387c478bd9Sstevel@tonic-gate#---------------------------------------------------------------------------
397c478bd9Sstevel@tonic-gatesend_msg() {
407c478bd9Sstevel@tonic-gate	MAILER=/usr/bin/mailx
417c478bd9Sstevel@tonic-gate	SED=/usr/bin/sed
427c478bd9Sstevel@tonic-gate	LOGCMD="$LOGGER -p daemon.alert"
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate	ADDRESS=audit_warn		# standard alias for audit alerts
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate	# turn off redirect to /dev/null to see sendmail output
477c478bd9Sstevel@tonic-gate	/usr/lib/sendmail -bv $ADDRESS > /dev/null
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate	if [ $? -ne 0 ]
507c478bd9Sstevel@tonic-gate	then
517c478bd9Sstevel@tonic-gate		$LOGCMD "The $ADDRESS mail alias is not defined"
527c478bd9Sstevel@tonic-gate		ADDRESS=root
537c478bd9Sstevel@tonic-gate	fi
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate	if [ -z "$COUNT" -o "0$COUNT" -eq 1 ]
567c478bd9Sstevel@tonic-gate	then
577c478bd9Sstevel@tonic-gate		echo "$0: $MESSAGE" | $MAILER -s "$SUBJECT" $ADDRESS
587c478bd9Sstevel@tonic-gate	fi
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate	STRIPPEDMSG=`echo "$MESSAGE" | $SED -e "s/\n/ /g"`
617c478bd9Sstevel@tonic-gate	$LOGCMD $STRIPPEDMSG
627c478bd9Sstevel@tonic-gate}
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate# If you change this script, script debug should first be done via the
657c478bd9Sstevel@tonic-gate# command line, so input errors are output via "echo," but syslog
667c478bd9Sstevel@tonic-gate# debug messages are better for testing from auditd since the echo
677c478bd9Sstevel@tonic-gate# output would be lost.  For testing with auditd, replace
687c478bd9Sstevel@tonic-gate# 'DEBUG_OUT="echo"' with 'DEBUG_OUT="$LOGGER -p daemon.debug"'
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gateLOGGER="/usr/bin/logger"
717c478bd9Sstevel@tonic-gateDEBUG_OUT="echo"
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate# Check usage
747c478bd9Sstevel@tonic-gateif [ "$#" -lt "1" -o "$#" -gt "5" ]
757c478bd9Sstevel@tonic-gatethen
767c478bd9Sstevel@tonic-gate	$DEBUG_OUT "Usage: $0 <option> [<args>]"
777c478bd9Sstevel@tonic-gate	exit 1
787c478bd9Sstevel@tonic-gatefi
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate# Process args
817c478bd9Sstevel@tonic-gatewhile [ -n "$1" ]
827c478bd9Sstevel@tonic-gatedo
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate	SUBJECT="AUDIT DAEMON WARNING ($1)"
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate	case "$1" in
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate	"soft" )	# Check soft arg
897c478bd9Sstevel@tonic-gate			# One audit filesystem has filled to the soft limit
90*f8994074SJan Friedel			# that is configured in the audit service.
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate			if [ ! -n "$2" ]
937c478bd9Sstevel@tonic-gate			then
947c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need filename arg with 'soft'!"
957c478bd9Sstevel@tonic-gate				exit 1
967c478bd9Sstevel@tonic-gate			else
977c478bd9Sstevel@tonic-gate				FILE=$2
987c478bd9Sstevel@tonic-gate			fi
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate			# Set message
1017c478bd9Sstevel@tonic-gate			MESSAGE="Soft limit exceeded in file $FILE."
1027c478bd9Sstevel@tonic-gate			send_msg
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate			break
1057c478bd9Sstevel@tonic-gate			;;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	"allsoft" )	# Check all soft arg
1087c478bd9Sstevel@tonic-gate			# All the audit filesystems have filled to the soft
109*f8994074SJan Friedel			# limit set up in the audit service configuration.
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate			# Set message
1127c478bd9Sstevel@tonic-gate			MESSAGE="Soft limit exceeded on all filesystems."
1137c478bd9Sstevel@tonic-gate			send_msg
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate			break
1167c478bd9Sstevel@tonic-gate			;;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate	"hard" )	# Check hard arg
1197c478bd9Sstevel@tonic-gate			# One audit filesystem has filled completely.
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate			if [ ! -n "$2" ]
1227c478bd9Sstevel@tonic-gate			then
1237c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need filename arg with 'hard'!"
1247c478bd9Sstevel@tonic-gate				exit 1
1257c478bd9Sstevel@tonic-gate			else
1267c478bd9Sstevel@tonic-gate				FILE=$2
1277c478bd9Sstevel@tonic-gate			fi
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate			# Set message
1307c478bd9Sstevel@tonic-gate			MESSAGE="Hard limit exceeded in file $FILE."
1317c478bd9Sstevel@tonic-gate			send_msg
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate			break
1347c478bd9Sstevel@tonic-gate			;;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate	"allhard" )	# Check all hard arg
1377c478bd9Sstevel@tonic-gate			# All the audit filesystems have filled completely.
1387c478bd9Sstevel@tonic-gate			# The audit daemon will remain in a loop sleeping
1397c478bd9Sstevel@tonic-gate			# and checking for space until some space is freed.
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate			if [ ! -n "$2" ]
1427c478bd9Sstevel@tonic-gate			then
1437c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need count arg with 'allhard'!"
1447c478bd9Sstevel@tonic-gate				exit 1
1457c478bd9Sstevel@tonic-gate			else
1467c478bd9Sstevel@tonic-gate				COUNT=$2
1477c478bd9Sstevel@tonic-gate			fi
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate			# Set message
1507c478bd9Sstevel@tonic-gate			MESSAGE="Hard limit exceeded on all filesystems. (count=$COUNT)"
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate			send_msg
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate			# This might be a place to make space in the
1557c478bd9Sstevel@tonic-gate			# audit file systems.
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate			break
1587c478bd9Sstevel@tonic-gate			;;
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate	"ebusy" )	# Check ebusy arg
1617c478bd9Sstevel@tonic-gate			# The audit daemon is already running and can not
1627c478bd9Sstevel@tonic-gate			# be started more than once.
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate			# Set message
1657c478bd9Sstevel@tonic-gate			MESSAGE="The audit daemon is already running on this system."
1667c478bd9Sstevel@tonic-gate			send_msg
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate			break
1697c478bd9Sstevel@tonic-gate			;;
1707c478bd9Sstevel@tonic-gate
171c900e163Sgww	"tmpfile" )	# Check tmpfile arg
172c900e163Sgww			# The tmpfile used by the audit daemon (binfile) could
173c900e163Sgww			# not be opened even unlinked or symlinked.
174c900e163Sgww			# This error will cause the audit daemon to exit at
175c900e163Sgww			# start.  If it occurs later the audit daemon will
176c900e163Sgww			# attempt to carry on.
1777c478bd9Sstevel@tonic-gate
178c900e163Sgww			if [ ! -n "$2" ]
179c900e163Sgww			then
180c900e163Sgww				$DEBUG_OUT "$0: Need error string arg with 'tmpfile'!"
181c900e163Sgww				exit 1
182c900e163Sgww			else
183c900e163Sgww				ERROR=$2
184c900e163Sgww			fi
1857c478bd9Sstevel@tonic-gate			# Set message
186c900e163Sgww			MESSAGE="The audit daemon is unable to update /var/run, error=$ERROR.\n This implies a serious problem."
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate			send_msg
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate			break
1917c478bd9Sstevel@tonic-gate			;;
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate	"nostart" )	# Check no start arg
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate			# auditd attempts to set the audit state; if
1967c478bd9Sstevel@tonic-gate			# it fails, it exits with a "nostart" code.
1977c478bd9Sstevel@tonic-gate			# The most likely cause is that the kernel
1987c478bd9Sstevel@tonic-gate			# audit module did not load due to a
1997c478bd9Sstevel@tonic-gate			# configuration error.  auditd is not running.
2007c478bd9Sstevel@tonic-gate			#
2017c478bd9Sstevel@tonic-gate			# The audit daemon can not be started until
2027c478bd9Sstevel@tonic-gate			# the error is corrected and the system is
2037c478bd9Sstevel@tonic-gate			# rebooted.
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate			MESSAGE="audit failed to start because it cannot read or\
2067c478bd9Sstevel@tonic-gate write the system's audit state. This may be due to a configuration error.\n\n\
2077c478bd9Sstevel@tonic-gateMust reboot to start auditing!"
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate			send_msg
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate			break
2127c478bd9Sstevel@tonic-gate			;;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate	"auditoff" )	# Check audit off arg
2157c478bd9Sstevel@tonic-gate			# Someone besides the audit daemon called the
2167c478bd9Sstevel@tonic-gate			# system call auditon to "turn auditing off"
2177c478bd9Sstevel@tonic-gate			# by setting the state to AUC_NOAUDIT.  This
2187c478bd9Sstevel@tonic-gate			# will cause the audit daemon to exit.
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate			# Set message
2217c478bd9Sstevel@tonic-gate			MESSAGE="Auditing has been turned off unexpectedly."
2227c478bd9Sstevel@tonic-gate			send_msg
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate			break
2257c478bd9Sstevel@tonic-gate			;;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate	"postsigterm" )	# Check post sigterm arg
2287c478bd9Sstevel@tonic-gate			# While the audit daemon was trying to shutdown
2297c478bd9Sstevel@tonic-gate			# in an orderly fashion (corresponding to audit -t)
2307c478bd9Sstevel@tonic-gate			# it got another signal or an error.  Some records
2317c478bd9Sstevel@tonic-gate			# may not have been written.
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate			# Set message
2347c478bd9Sstevel@tonic-gate			MESSAGE="Received some signal or error while writing\
2357c478bd9Sstevel@tonic-gate audit records after SIGTERM.  Some audit records may have been lost."
2367c478bd9Sstevel@tonic-gate			send_msg
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate			break
2397c478bd9Sstevel@tonic-gate			;;
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate	"plugin" )	# Check plugin arg
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate			# There is a problem loading a plugin or a plugin
2447c478bd9Sstevel@tonic-gate			# has reported a serious error.
2457c478bd9Sstevel@tonic-gate			# Output from the plugin is either blocked or halted.
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate			if [ ! -n "$2" ]
2487c478bd9Sstevel@tonic-gate			then
2497c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need plugin name arg with 'plugin'!"
2507c478bd9Sstevel@tonic-gate				exit 1
2517c478bd9Sstevel@tonic-gate			else
2527c478bd9Sstevel@tonic-gate				PLUGNAME=$2
2537c478bd9Sstevel@tonic-gate			fi
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate			if [ ! -n "$3" ]
2567c478bd9Sstevel@tonic-gate			then
2577c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need error arg with 'plugin'!"
2587c478bd9Sstevel@tonic-gate				exit 1
2597c478bd9Sstevel@tonic-gate			else
2607c478bd9Sstevel@tonic-gate				ERROR=$3
2617c478bd9Sstevel@tonic-gate			fi
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate			if [ ! -n "$4" ]
2647c478bd9Sstevel@tonic-gate			then
2657c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need text arg with 'plugin'!"
2667c478bd9Sstevel@tonic-gate				exit 1
2677c478bd9Sstevel@tonic-gate			else
2687c478bd9Sstevel@tonic-gate				TEXT=$4
2697c478bd9Sstevel@tonic-gate			fi
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate			if [ ! -n "$5" ]
2727c478bd9Sstevel@tonic-gate			then
2737c478bd9Sstevel@tonic-gate				$DEBUG_OUT "$0: Need count arg with 'plugin'!"
2747c478bd9Sstevel@tonic-gate				exit 1
2757c478bd9Sstevel@tonic-gate			else
2767c478bd9Sstevel@tonic-gate				COUNT=$5
2771a578a15Spaulson				if [ $COUNT -eq 1 ]; then
2781a578a15Spaulson					S=""
2791a578a15Spaulson				else
2801a578a15Spaulson					S="s"
2811a578a15Spaulson				fi
2827c478bd9Sstevel@tonic-gate			fi
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate			# Set message
2857c478bd9Sstevel@tonic-gate			MESSAGE="The audit daemon has experienced the\
2867c478bd9Sstevel@tonic-gate following problem with loading or executing plugins:\n\n\
2877c478bd9Sstevel@tonic-gate$PLUGNAME: $ERROR\n\
2887c478bd9Sstevel@tonic-gate$TEXT\n\
2891a578a15SpaulsonThis message has been displayed $COUNT time$S."
2907c478bd9Sstevel@tonic-gate			send_msg
2917c478bd9Sstevel@tonic-gate			break
2927c478bd9Sstevel@tonic-gate			;;
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate	* )		# Check other args
2957c478bd9Sstevel@tonic-gate			$DEBUG_OUT "$0: Arg not recognized: $1"
2967c478bd9Sstevel@tonic-gate			exit 1
2977c478bd9Sstevel@tonic-gate			;;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate	esac
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate	shift
3027c478bd9Sstevel@tonic-gatedone
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gateexit 0
305