f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#!/sbin/sh
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# CDDL HEADER START
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# The contents of this file are subject to the terms of the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Common Development and Distribution License (the "License").
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# You may not use this file except in compliance with the License.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# or http://www.opensolaris.org/os/licensing.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# See the License for the specific language governing permissions
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# and limitations under the License.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# When distributing Covered Code, include this CDDL HEADER in each
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# If applicable, add the following below this CDDL HEADER, with the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# fields enclosed by brackets "[]" replaced with your own identifying
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# information: Portions Copyright [yyyy] [name of copyright owner]
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# CDDL HEADER END
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby. /lib/svc/share/smf_include.sh
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyLOGADM=/etc/logadm.conf
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyLOGADM_D=${LOGADM%conf}d
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyLS=/usr/bin/ls
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyAWK=/usr/bin/awk
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin MaltbyGREP=/usr/bin/grep
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# This is a temporary service to allow addition (only) to /etc/logadm.conf
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# It is temporary in the sense that logadm(1M) should have its configuration
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# migrated to SMF in the future.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Display error message and exits with error code
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbymsg_exit()
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby{
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby exit_code=$1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby msg=$2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby echo "${msg}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby exit ${exit_code}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# If there is no /etc/logadm.d we can bail
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyif [ ! -d ${LOGADM_D} ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby exit ${SMF_EXIT_OK}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Cache files
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfiles=$(${LS} -t ${LOGADM} ${LOGADM_D}/*)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# If there is no /etc/logadm.conf create it and make sure it has the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# right ownership and permissions.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Make sure this is done AFTER $files is set. Otherwise /etc/logadm.conf will be
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# newer than all files is /etc/logadm.d and they will be skipped.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyif [ ! -f ${LOGADM} ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby touch ${LOGADM}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby chmod 644 ${LOGADM}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby chown root:sys ${LOGADM}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfor f in ${files}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbydo
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # If it is not a file, we skip it.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ ! -f ${f} ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby continue
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # We stop when files at /etc/logadm.d are older than /etc/logadm.conf
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ ${f} = ${LOGADM} ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby break
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # We ignore files that are not owned by root, group sys
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # and have permissions different than 444
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby perm=$(${LS} -l ${f} | ${AWK} '{printf("%s %s:%s", $1, $3, $4)}')
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ $? != 0 ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby msg_exit ${SMF_EXIT_ERR_FATAL} "${perm}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ "${perm}" != "-r--r--r-- root:sys" ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby echo "Unexpected permission/ownership for ${f}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby echo " expected -r--r--r-- root:sys but got ${perm}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby echo " skipping ${f}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby continue
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # Discard comments (lines starting with #)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby ${GREP} -v '^#' ${f} | while read entry
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby do
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby sig=$(echo ${entry} | ${AWK} '{printf("%s\>", $1);}' 2>&1)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ $? != 0 ]; then # only happens if awk(1) fails
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby msg_exit ${SMF_EXIT_ERR_FATAL} "${sig}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby # if ${sig} is null but the previous command succeeded, we skip
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby #
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby if [ ! ${sig} ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby continue;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby fi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby err_msg=$(${GREP} ^${sig} ${LOGADM} 2>&1)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby case $? in
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby '1')
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby echo "${entry}" >> ${LOGADM}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby ;;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby '0')
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby ;;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby msg_exit ${SMF_EXIT_ERR_FATAL} "${err_msg}"
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby esac
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby done
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbydone
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyexit ${SMF_EXIT_OK}
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby