xref: /titanic_51/usr/src/cmd/logadm/logadm-upgrade (revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa)
1*f6e214c7SGavin Maltby#!/sbin/sh
2*f6e214c7SGavin Maltby#
3*f6e214c7SGavin Maltby# CDDL HEADER START
4*f6e214c7SGavin Maltby#
5*f6e214c7SGavin Maltby# The contents of this file are subject to the terms of the
6*f6e214c7SGavin Maltby# Common Development and Distribution License (the "License").
7*f6e214c7SGavin Maltby# You may not use this file except in compliance with the License.
8*f6e214c7SGavin Maltby#
9*f6e214c7SGavin Maltby# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*f6e214c7SGavin Maltby# or http://www.opensolaris.org/os/licensing.
11*f6e214c7SGavin Maltby# See the License for the specific language governing permissions
12*f6e214c7SGavin Maltby# and limitations under the License.
13*f6e214c7SGavin Maltby#
14*f6e214c7SGavin Maltby# When distributing Covered Code, include this CDDL HEADER in each
15*f6e214c7SGavin Maltby# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*f6e214c7SGavin Maltby# If applicable, add the following below this CDDL HEADER, with the
17*f6e214c7SGavin Maltby# fields enclosed by brackets "[]" replaced with your own identifying
18*f6e214c7SGavin Maltby# information: Portions Copyright [yyyy] [name of copyright owner]
19*f6e214c7SGavin Maltby#
20*f6e214c7SGavin Maltby# CDDL HEADER END
21*f6e214c7SGavin Maltby#
22*f6e214c7SGavin Maltby#
23*f6e214c7SGavin Maltby# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*f6e214c7SGavin Maltby#
25*f6e214c7SGavin Maltby
26*f6e214c7SGavin Maltby. /lib/svc/share/smf_include.sh
27*f6e214c7SGavin Maltby
28*f6e214c7SGavin MaltbyLOGADM=/etc/logadm.conf
29*f6e214c7SGavin MaltbyLOGADM_D=${LOGADM%conf}d
30*f6e214c7SGavin MaltbyLS=/usr/bin/ls
31*f6e214c7SGavin MaltbyAWK=/usr/bin/awk
32*f6e214c7SGavin MaltbyGREP=/usr/bin/grep
33*f6e214c7SGavin Maltby
34*f6e214c7SGavin Maltby#
35*f6e214c7SGavin Maltby# This is a temporary service to allow addition (only) to /etc/logadm.conf
36*f6e214c7SGavin Maltby# It is temporary in the sense that logadm(1M) should have its configuration
37*f6e214c7SGavin Maltby# migrated to SMF in the future.
38*f6e214c7SGavin Maltby#
39*f6e214c7SGavin Maltby
40*f6e214c7SGavin Maltby#
41*f6e214c7SGavin Maltby# Display error message and exits with error code
42*f6e214c7SGavin Maltby#
43*f6e214c7SGavin Maltbymsg_exit()
44*f6e214c7SGavin Maltby{
45*f6e214c7SGavin Maltby	exit_code=$1
46*f6e214c7SGavin Maltby	msg=$2
47*f6e214c7SGavin Maltby
48*f6e214c7SGavin Maltby	echo "${msg}"
49*f6e214c7SGavin Maltby	exit ${exit_code}
50*f6e214c7SGavin Maltby}
51*f6e214c7SGavin Maltby
52*f6e214c7SGavin Maltby#
53*f6e214c7SGavin Maltby# If there is no /etc/logadm.d we can bail
54*f6e214c7SGavin Maltby#
55*f6e214c7SGavin Maltbyif [ ! -d ${LOGADM_D} ]; then
56*f6e214c7SGavin Maltby	exit ${SMF_EXIT_OK}
57*f6e214c7SGavin Maltbyfi
58*f6e214c7SGavin Maltby
59*f6e214c7SGavin Maltby#
60*f6e214c7SGavin Maltby# Cache files
61*f6e214c7SGavin Maltby#
62*f6e214c7SGavin Maltbyfiles=$(${LS} -t  ${LOGADM} ${LOGADM_D}/*)
63*f6e214c7SGavin Maltby
64*f6e214c7SGavin Maltby#
65*f6e214c7SGavin Maltby# If there is no /etc/logadm.conf create it and make sure it has the
66*f6e214c7SGavin Maltby# right ownership and permissions.
67*f6e214c7SGavin Maltby# Make sure this is done AFTER $files is set. Otherwise /etc/logadm.conf will be
68*f6e214c7SGavin Maltby# newer than all files is /etc/logadm.d and they will be skipped.
69*f6e214c7SGavin Maltby#
70*f6e214c7SGavin Maltbyif [ ! -f ${LOGADM} ]; then
71*f6e214c7SGavin Maltby	touch ${LOGADM}
72*f6e214c7SGavin Maltby	chmod 644 ${LOGADM}
73*f6e214c7SGavin Maltby	chown root:sys ${LOGADM}
74*f6e214c7SGavin Maltbyfi
75*f6e214c7SGavin Maltby
76*f6e214c7SGavin Maltbyfor f in ${files}
77*f6e214c7SGavin Maltbydo
78*f6e214c7SGavin Maltby	#
79*f6e214c7SGavin Maltby	# If it is not a file, we skip it.
80*f6e214c7SGavin Maltby	#
81*f6e214c7SGavin Maltby	if [ ! -f ${f} ]; then
82*f6e214c7SGavin Maltby		continue
83*f6e214c7SGavin Maltby	fi
84*f6e214c7SGavin Maltby
85*f6e214c7SGavin Maltby	#
86*f6e214c7SGavin Maltby	# We stop when files at /etc/logadm.d are older than /etc/logadm.conf
87*f6e214c7SGavin Maltby	#
88*f6e214c7SGavin Maltby	if [ ${f} = ${LOGADM} ]; then
89*f6e214c7SGavin Maltby		break
90*f6e214c7SGavin Maltby	fi
91*f6e214c7SGavin Maltby
92*f6e214c7SGavin Maltby	#
93*f6e214c7SGavin Maltby	# We ignore files that are not owned by root, group sys
94*f6e214c7SGavin Maltby	# and have permissions different than 444
95*f6e214c7SGavin Maltby	#
96*f6e214c7SGavin Maltby	perm=$(${LS} -l ${f} | ${AWK} '{printf("%s %s:%s", $1, $3, $4)}')
97*f6e214c7SGavin Maltby	if [ $? != 0 ]; then
98*f6e214c7SGavin Maltby		msg_exit ${SMF_EXIT_ERR_FATAL} "${perm}"
99*f6e214c7SGavin Maltby	fi
100*f6e214c7SGavin Maltby	if [ "${perm}" != "-r--r--r-- root:sys" ]; then
101*f6e214c7SGavin Maltby		echo "Unexpected permission/ownership for ${f}"
102*f6e214c7SGavin Maltby		echo "    expected -r--r--r-- root:sys but got ${perm}"
103*f6e214c7SGavin Maltby		echo "    skipping ${f}"
104*f6e214c7SGavin Maltby		continue
105*f6e214c7SGavin Maltby	fi
106*f6e214c7SGavin Maltby
107*f6e214c7SGavin Maltby	#
108*f6e214c7SGavin Maltby	# Discard comments (lines starting with #)
109*f6e214c7SGavin Maltby	#
110*f6e214c7SGavin Maltby	${GREP} -v '^#' ${f} | while read entry
111*f6e214c7SGavin Maltby	do
112*f6e214c7SGavin Maltby		sig=$(echo ${entry} | ${AWK} '{printf("%s\>", $1);}' 2>&1)
113*f6e214c7SGavin Maltby		if [ $? != 0 ]; then # only happens if awk(1) fails
114*f6e214c7SGavin Maltby			msg_exit ${SMF_EXIT_ERR_FATAL} "${sig}"
115*f6e214c7SGavin Maltby		fi
116*f6e214c7SGavin Maltby
117*f6e214c7SGavin Maltby		#
118*f6e214c7SGavin Maltby		# if ${sig} is null but the previous command succeeded, we skip
119*f6e214c7SGavin Maltby		#
120*f6e214c7SGavin Maltby		if [ ! ${sig} ]; then
121*f6e214c7SGavin Maltby			continue;
122*f6e214c7SGavin Maltby		fi
123*f6e214c7SGavin Maltby
124*f6e214c7SGavin Maltby		err_msg=$(${GREP} ^${sig} ${LOGADM} 2>&1)
125*f6e214c7SGavin Maltby		case $? in
126*f6e214c7SGavin Maltby		'1')
127*f6e214c7SGavin Maltby			echo "${entry}" >> ${LOGADM}
128*f6e214c7SGavin Maltby			;;
129*f6e214c7SGavin Maltby		'0')
130*f6e214c7SGavin Maltby			;;
131*f6e214c7SGavin Maltby		*)
132*f6e214c7SGavin Maltby			msg_exit ${SMF_EXIT_ERR_FATAL} "${err_msg}"
133*f6e214c7SGavin Maltby		esac
134*f6e214c7SGavin Maltby	done
135*f6e214c7SGavin Maltbydone
136*f6e214c7SGavin Maltby
137*f6e214c7SGavin Maltbyexit ${SMF_EXIT_OK}
138*f6e214c7SGavin Maltby
139