1#! /bin/sh
2
3#  Copyright (c) International Business Machines  Corp., 2002
4#
5#  This program is free software;  you can redistribute it and/or modify
6#  it under the terms of the GNU General Public License as published by
7#  the Free Software Foundation; either version 2 of the License, or
8#  (at your option) any later version.
9#
10#  This program is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13#  the GNU General Public License for more details.
14#
15#  You should have received a copy of the GNU General Public License
16#  along with this program;  if not, write to the Free Software
17#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
20# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
21#		   fixed bugs.
22# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
23#		   Made changes to account for the replacement of syslogd
24#		   with syslog-ng
25#
26##################################################################
27# case 8: Test all the facilities at a particular level.	 #
28#								 #
29# Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL	 #
30# LOG_DAEMON, LOG_AUTH, LOG_LPR.				 #
31# Don't know how to send kernel messages from syslog()   	 #
32#								 #
33# o Create seperate entries in config file for each facility.	 #
34# o Send the message and grep for the entry in log file.	 #
35##################################################################
36
37. syslog-lib.sh || exit 1
38
39syslog_case8()
40{
41	local facility_no=1
42	local facilities="user mail daemon auth lpr"
43
44	tst_resm TINFO "testing all the facilities"
45
46	for facility in $facilities; do
47
48		tst_resm TINFO "Doing facility: $facility..."
49
50		# Create the configuration file specific to this facility
51		# Level is fixed at info.
52		case "$CONFIG_FILE" in
53		/etc/syslog.conf|/etc/rsyslog.conf)
54			echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
55			echo "$facility.info	/var/log/messages" >> $CONFIG_FILE
56			echo "$facility.info	/var/log/maillog" >> $CONFIG_FILE
57			;;
58
59		/etc/syslog-ng/syslog-ng.conf)
60			echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
61			echo "filter f_syslog-$facility { level(info) and facility($facility); };" >> $CONFIG_FILE
62			echo "destination syslog-messages { file(\"/var/log/messages\"); };" >> $CONFIG_FILE
63			echo "destination syslog-mail { file(\"/var/log/maillog\");};" >> $CONFIG_FILE
64			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-mail); };"  >> $CONFIG_FILE
65			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-messages); };"  >> $CONFIG_FILE
66			;;
67
68		esac
69
70		restart_syslog_daemon
71
72		if [ -e /var/log/messages ]; then
73			oldvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
74		else
75			oldvalue=0
76		fi
77
78		if [ -e /var/log/maillog ]; then
79			old_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
80		else
81			old_mail_check=0
82		fi
83
84		# syslogtst has to be called with one more
85				# additional facility argument(1-6)
86		if ! syslogtst 8 $facility_no 2>/dev/null; then
87			status_flag=1
88			return
89		fi
90		sleep 2
91		# check if /var/log/maillog script exists
92		for logf in messages maillog
93		do
94			if [ ! -e /var/log/$logf ]; then
95				tst_resm TBROK "/var/log/$logf no such log file"
96				cleanup 1
97			fi
98		done
99
100		new_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
101		newvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
102		diff=$(( $newvalue - $oldvalue ))
103		mail_check=$(( $new_mail_check - $old_mail_check ))
104
105		if [ $facility = "mail" ]; then
106			if [ $mail_check -ne 1 ]; then
107				tst_resm TFAIL " Facility $facility failed"
108				status_flag=1
109			elif [ $mail_check -eq 1 ]; then
110				tst_resm TPASS " Facility $facility passed"
111			fi
112		elif [ $diff -ne 1 ]; then
113			tst_resm TFAIL " Facility $facility failed"
114			status_flag=1
115		else
116			tst_resm TPASS " Facility $facility passed"
117		fi
118		# Increment the facility_no for next...
119		: $(( facility_no += 1 ))
120	done
121}
122
123tst_resm TINFO " Test all the facilities at a particular level."
124tst_resm TINFO " Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL"
125tst_resm TINFO " LOG_DAEMON, LOG_AUTH, LOG_LPR."
126tst_resm TINFO " Don't know how to send kernel messages from syslog()"
127tst_resm TINFO " o Create seperate entries in config file for each facility."
128tst_resm TINFO " o Send the message and grep for the entry in log file."
129
130setup
131syslog_case8
132cleanup ${status_flag:=0}
133