2006-07-18 19:49:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# setroubleshoot This starts and stops setroubleshoot daemon
|
|
|
|
#
|
2006-07-21 13:42:14 +00:00
|
|
|
# chkconfig: 345 13 87
|
2006-07-18 19:49:13 +00:00
|
|
|
# description: This starts the SELinux Troubleshooting Daemon
|
|
|
|
#
|
|
|
|
# processname: /usr/sbin/setroubleshootd
|
|
|
|
# config: /etc/setroubleshoot/setroubleshoot.cfg
|
|
|
|
# pidfile: /var/run/setroubleshoot.pid
|
|
|
|
#
|
2007-09-08 19:51:52 +00:00
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: lsb-setroubleshootd
|
2008-09-09 20:07:26 +00:00
|
|
|
# Required-Start: $local_fs $syslog $network $named $messagebus
|
|
|
|
# Required-Stop: $local_fs $syslog $network $named $messagebus
|
2007-09-08 19:51:52 +00:00
|
|
|
# Default-Start: 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: start and stop SELinux Troubleshooting Daemon
|
|
|
|
# Description: controls operation of the SELinux Troubleshooting Daemon
|
|
|
|
# (setroubleshootd) which listens for SELinux AVC denial messages
|
|
|
|
# analyzes it and provides a friendly interpretation.
|
|
|
|
### END INIT INFO
|
|
|
|
|
2006-07-18 19:49:13 +00:00
|
|
|
# Return values according to LSB for all commands but status:
|
2007-09-08 19:51:52 +00:00
|
|
|
# 0 success
|
|
|
|
# 1 generic or unspecified error (current practice)
|
|
|
|
# 2 invalid or excess argument(s)
|
|
|
|
# 3 unimplemented feature (for example, "reload")
|
|
|
|
# 4 user had insufficient privilege
|
|
|
|
# 5 program is not installed
|
|
|
|
# 6 program is not configured
|
|
|
|
# 7 program is not running
|
|
|
|
|
|
|
|
# Command argument
|
|
|
|
# start start the service
|
|
|
|
# stop stop the service
|
|
|
|
# restart stop and restart the service if the service is already running, otherwise start the service
|
|
|
|
# try-restart restart the service if the service is already running
|
|
|
|
# reload cause the configuration of the service to be reloaded without actually stopping and restarting the service
|
|
|
|
# force-reload cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running
|
|
|
|
# status print the current status of the service
|
|
|
|
|
|
|
|
# start, stop, restart, force-reload, and status actions must be supported
|
|
|
|
# reload and the try-restart actions are optional.
|
|
|
|
# the init script.
|
|
|
|
|
2006-07-18 19:49:13 +00:00
|
|
|
PATH=/sbin:/bin:/usr/bin:/usr/sbin
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/init.d/functions
|
|
|
|
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=0
|
|
|
|
prog="setroubleshootd"
|
|
|
|
|
2008-01-15 20:53:13 +00:00
|
|
|
usage(){
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart|try-restart|condrestart|reload|force-reload|cleardb [test][verbose]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
command=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
[ $command ] || (usage; exit 3)
|
|
|
|
|
|
|
|
# look for extra options
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
arg=$1
|
|
|
|
case "$arg" in
|
|
|
|
test)
|
|
|
|
EXTRAOPTIONS="$EXTRAOPTIONS -c audit.text_protocol_socket_path=/tmp/audispd_events"
|
|
|
|
;;
|
|
|
|
verbose)
|
|
|
|
EXTRAOPTIONS="$EXTRAOPTIONS -V"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown arg $arg"
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2008-01-11 17:16:40 +00:00
|
|
|
rhstatus(){
|
|
|
|
status $prog
|
|
|
|
RETVAL=$?
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow status as non-root and also if SELinux is disabled
|
2008-01-15 20:53:13 +00:00
|
|
|
if [ "$command" = status ]; then
|
2008-01-11 17:16:40 +00:00
|
|
|
rhstatus
|
|
|
|
RETVAL=$?
|
|
|
|
exit $RETVAL
|
|
|
|
fi
|
|
|
|
|
2006-08-06 00:22:32 +00:00
|
|
|
# Silently exit is SELinux is not enabled
|
2006-08-21 15:18:36 +00:00
|
|
|
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || exit 1
|
2006-08-06 00:22:32 +00:00
|
|
|
|
2006-07-18 19:49:13 +00:00
|
|
|
# Check that we are root ... so non-root users stop here
|
2008-01-11 17:16:40 +00:00
|
|
|
if test `id -u` != 0; then
|
|
|
|
echo "You must be root"
|
|
|
|
exit 4
|
|
|
|
fi
|
2006-07-18 19:49:13 +00:00
|
|
|
|
|
|
|
start(){
|
|
|
|
echo -n $"Starting $prog: "
|
|
|
|
unset HOME MAIL USER USERNAME
|
2006-08-21 15:18:36 +00:00
|
|
|
daemon $prog "$EXTRAOPTIONS"
|
2006-07-18 19:49:13 +00:00
|
|
|
RETVAL=$?
|
|
|
|
echo
|
|
|
|
if test $RETVAL = 0 ; then
|
2006-09-15 20:52:45 +00:00
|
|
|
touch /var/lock/subsys/$prog
|
2006-07-18 19:49:13 +00:00
|
|
|
fi
|
2007-09-24 20:58:48 +00:00
|
|
|
if test $RETVAL = 3 ; then
|
|
|
|
echo -n $"Cannot start $prog: SELinux not enabled"
|
|
|
|
fi
|
2006-07-18 19:49:13 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(){
|
|
|
|
echo -n $"Stopping $prog: "
|
2006-08-21 15:18:36 +00:00
|
|
|
killproc $prog
|
2006-07-18 19:49:13 +00:00
|
|
|
RETVAL=$?
|
|
|
|
echo
|
2006-09-15 20:52:45 +00:00
|
|
|
rm -f /var/lock/subsys/$prog
|
2006-07-18 19:49:13 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
reload(){
|
|
|
|
echo -n $"Reloading configuration: "
|
2006-08-21 15:18:36 +00:00
|
|
|
killproc $prog -HUP
|
2006-07-18 19:49:13 +00:00
|
|
|
RETVAL=$?
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
restart(){
|
|
|
|
stop
|
|
|
|
start
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
|
|
|
return $RETVAL
|
2006-07-18 19:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
condrestart(){
|
2006-09-15 20:52:45 +00:00
|
|
|
[ -e /var/lock/subsys/$prog ] && restart
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=0
|
|
|
|
return $RETVAL
|
2006-07-18 19:49:13 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 19:44:14 +00:00
|
|
|
cleardb(){
|
|
|
|
running=0
|
2006-09-15 20:52:45 +00:00
|
|
|
[ -e /var/lock/subsys/$prog ] && running=1
|
2006-08-21 19:44:14 +00:00
|
|
|
[ $running == 1 ] && stop
|
|
|
|
echo $"Clearing database"
|
|
|
|
rm -f /var/lib/setroubleshoot/database.xml
|
2007-12-28 16:17:01 +00:00
|
|
|
rm -f /var/lib/setroubleshoot/audit_listener_database.xml
|
2006-08-21 19:44:14 +00:00
|
|
|
[ $running == 1 ] && start
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=0
|
|
|
|
return $RETVAL
|
2006-08-21 19:44:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 19:49:13 +00:00
|
|
|
# See how we were called.
|
2008-01-15 20:53:13 +00:00
|
|
|
case "$command" in
|
2006-07-18 19:49:13 +00:00
|
|
|
start)
|
|
|
|
start
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
|
|
|
status)
|
2008-01-11 17:16:40 +00:00
|
|
|
rhstatus
|
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
2007-09-08 19:51:52 +00:00
|
|
|
force-reload|reload)
|
2006-07-18 19:49:13 +00:00
|
|
|
reload
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
2007-09-08 19:51:52 +00:00
|
|
|
try-restart|condrestart)
|
2006-07-18 19:49:13 +00:00
|
|
|
condrestart
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-07-18 19:49:13 +00:00
|
|
|
;;
|
2006-08-21 19:44:14 +00:00
|
|
|
cleardb)
|
|
|
|
cleardb
|
2008-01-11 17:16:40 +00:00
|
|
|
RETVAL=$?
|
2006-08-21 19:44:14 +00:00
|
|
|
;;
|
2006-07-18 19:49:13 +00:00
|
|
|
*)
|
2008-01-15 20:53:13 +00:00
|
|
|
usage
|
2006-07-18 19:49:13 +00:00
|
|
|
RETVAL=3
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|