17c478bd9Sstevel@tonic-gate#! /sbin/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 66927f468Sdp# Common Development and Distribution License (the "License"). 76927f468Sdp# 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# 24*f8994074SJan Friedel# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 25*f8994074SJan Friedel# 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh 287c478bd9Sstevel@tonic-gate 29*f8994074SJan FriedelAUDIT=/usr/sbin/audit 307c478bd9Sstevel@tonic-gateAUDITCONFIG=/usr/sbin/auditconfig 318523fda3SJan FriedelAUDITD=/usr/sbin/auditd 328523fda3SJan FriedelAWK=/usr/bin/awk 338523fda3SJan FriedelEGREP=/usr/bin/egrep 348523fda3SJan FriedelMV=/usr/bin/mv 358523fda3SJan FriedelPKILL=/usr/bin/pkill 368523fda3SJan FriedelSLEEP=/usr/bin/sleep 378523fda3SJan FriedelSVCADM=/usr/sbin/svcadm 388523fda3SJan FriedelSVCCFG=/usr/sbin/svccfg 398523fda3SJan FriedelSVCS=/usr/bin/svcs 407c478bd9Sstevel@tonic-gate 418523fda3SJan FriedelAUDIT_STARTUP=/etc/security/audit_startup 428523fda3SJan FriedelAUDITD_FMRI="system/auditd:default" 437c478bd9Sstevel@tonic-gate 448523fda3SJan Friedel# 458523fda3SJan Friedel# main - the execution starts there. 468523fda3SJan Friedelmain() 478523fda3SJan Friedel{ 488523fda3SJan Friedel # 498523fda3SJan Friedel # Do the basic argument inspection and take the appropriate action. 508523fda3SJan Friedel case "$SMF_METHOD" in 518523fda3SJan Friedel start) 528523fda3SJan Friedel do_common 538523fda3SJan Friedel do_start 548523fda3SJan Friedel ;; 558523fda3SJan Friedel refresh) 568523fda3SJan Friedel do_common 578523fda3SJan Friedel do_refresh 588523fda3SJan Friedel ;; 598523fda3SJan Friedel *) 608523fda3SJan Friedel if [ -z "$SMF_METHOD" ]; then 618523fda3SJan Friedel echo "$0: No SMF method defined." 628523fda3SJan Friedel else 638523fda3SJan Friedel echo "$0: Unsupported SMF method: $SMF_METHOD." 648523fda3SJan Friedel fi 658523fda3SJan Friedel exit $SMF_EXIT_ERR_NOSMF 668523fda3SJan Friedel ;; 678523fda3SJan Friedel esac 688523fda3SJan Friedel} 698523fda3SJan Friedel 708523fda3SJan Friedel# 718523fda3SJan Friedel# do_common - executes all the code common to all supported service methods. 728523fda3SJan Friedeldo_common() 738523fda3SJan Friedel{ 748523fda3SJan Friedel # 758523fda3SJan Friedel # If the audit state is "disabled" auditconfig returns non-zero exit 768523fda3SJan Friedel # status unless the c2audit module is loaded; if c2audit is loaded, 778523fda3SJan Friedel # "disabled" becomes "noaudit" early in the boot cycle and "auditing" 788523fda3SJan Friedel # only after auditd starts. 798523fda3SJan Friedel AUDITCOND="`$AUDITCONFIG -getcond 2>/dev/null`" 807c478bd9Sstevel@tonic-gate if [ $? -ne 0 ]; then 817c478bd9Sstevel@tonic-gate # The decision whether to start 828523fda3SJan Friedel # auditing is driven by bsmconv(1M) / bsmunconv(1M) 838523fda3SJan Friedel echo "$0: Unable to get current kernel auditing condition." 848523fda3SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 858523fda3SJan Friedel exit $SMF_EXIT_MON_OFFLINE 867c478bd9Sstevel@tonic-gate fi 878523fda3SJan Friedel # 888523fda3SJan Friedel # In a non-global zone, auditd is started/refreshed only if the 898523fda3SJan Friedel # "perzone" audit policy has been set. 906927f468Sdp if smf_is_nonglobalzone; then 918523fda3SJan Friedel $AUDITCONFIG -t -getpolicy | \ 928523fda3SJan Friedel $EGREP "perzone|all" 1>/dev/null 2>&1 937c478bd9Sstevel@tonic-gate if [ $? -eq 1 ]; then 94*f8994074SJan Friedel echo "$0: auditd(1M) is not configured to run in" 95*f8994074SJan Friedel echo " a local zone, perzone policy not set" \ 968523fda3SJan Friedel "(see auditconfig(1M))." 978523fda3SJan Friedel $SVCADM disable $AUDITD_FMRI 988523fda3SJan Friedel $SLEEP 5 & 998523fda3SJan Friedel exit $SMF_EXIT_OK 1007c478bd9Sstevel@tonic-gate fi 1017c478bd9Sstevel@tonic-gate fi 102*f8994074SJan Friedel # 103*f8994074SJan Friedel # Validate the audit service configuration 104*f8994074SJan Friedel val_err="`$AUDIT -v 2>&1`" 105*f8994074SJan Friedel if [ $? -ne 0 ]; then 106*f8994074SJan Friedel echo "$0: audit service misconfiguration detected (${val_err})" 107*f8994074SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 108*f8994074SJan Friedel exit $SMF_EXIT_MON_OFFLINE 109*f8994074SJan Friedel fi 1108523fda3SJan Friedel} 1117c478bd9Sstevel@tonic-gate 1128523fda3SJan Friedel# 1138523fda3SJan Friedel# do_start - service start method helper. 1148523fda3SJan Friedeldo_start() 1158523fda3SJan Friedel{ 1168523fda3SJan Friedel # 1178523fda3SJan Friedel # The transition of the audit_startup(1M) has to be performed. 1188523fda3SJan Friedel if [ -f "$AUDIT_STARTUP" ]; then 1197c478bd9Sstevel@tonic-gate 1208523fda3SJan Friedel if [ -x "$AUDIT_STARTUP" ]; then 1218523fda3SJan Friedel $AUDIT_STARTUP 1228523fda3SJan Friedel else 1238523fda3SJan Friedel echo "$0: Unable to execute $AUDIT_STARTUP" 1248523fda3SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 1258523fda3SJan Friedel exit $SMF_EXIT_MON_OFFLINE 1268523fda3SJan Friedel fi 1278523fda3SJan Friedel 1288523fda3SJan Friedel echo "$0: Transition of audit_startup(1M) started." 1298523fda3SJan Friedel 1308523fda3SJan Friedel $MV $AUDIT_STARTUP $AUDIT_STARTUP._transitioned_ 1318523fda3SJan Friedel if [ $? -ne 0 ]; then 1328523fda3SJan Friedel # Unable to perform the backup of $AUDIT_STARTUP 1338523fda3SJan Friedel echo "$0: The $AUDIT_STARTUP was not moved to" 1348523fda3SJan Friedel echo " $AUDIT_STARTUP._transitioned_" 1358523fda3SJan Friedel fi 1368523fda3SJan Friedel 1378523fda3SJan Friedel # 1388523fda3SJan Friedel # Refreshing service to make the newly created properties 1398523fda3SJan Friedel # available for any other consequent svcprop(1). 1408523fda3SJan Friedel $SVCCFG -s $AUDITD_FMRI refresh 1418523fda3SJan Friedel if [ $? -ne 0 ]; then 1428523fda3SJan Friedel echo "$0: Refresh of $AUDITD_FMRI configuration failed." 1438523fda3SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 1448523fda3SJan Friedel exit $SMF_EXIT_ERR_CONFIG 1458523fda3SJan Friedel fi 1468523fda3SJan Friedel 1478523fda3SJan Friedel echo "$0: Transition of audit_startup(1M) finished." 1488523fda3SJan Friedel fi 1498523fda3SJan Friedel 1508523fda3SJan Friedel # 1518523fda3SJan Friedel # Daemon forks, parent exits when child says it's ready. 1528523fda3SJan Friedel exec $AUDITD 1538523fda3SJan Friedel} 1548523fda3SJan Friedel 1558523fda3SJan Friedel# 1568523fda3SJan Friedel# do_refresh - service refresh method helper. 1578523fda3SJan Friedeldo_refresh() 1588523fda3SJan Friedel{ 1598523fda3SJan Friedel # 1608523fda3SJan Friedel # The refresh capability is available only for those systems 1618523fda3SJan Friedel # with already transformed audit_startup(1M) into $AUDITD_FMRI 1628523fda3SJan Friedel # service properties. See do_start() for more information. 1638523fda3SJan Friedel if [ ! -f "$AUDIT_STARTUP" ]; then 1648523fda3SJan Friedel # 1658523fda3SJan Friedel # Find the contract_id. 1668523fda3SJan Friedel contract_id=`$SVCS -l $AUDITD_FMRI | \ 1678523fda3SJan Friedel $AWK '/^contract_id/ {print $2}'` 1688523fda3SJan Friedel if [ -z "${contract_id}" ]; then 1698523fda3SJan Friedel echo "$0: Service $AUDITD_FMRI has no associated" \ 1708523fda3SJan Friedel "contract. Service cannot be refreshed." 1718523fda3SJan Friedel exit $SMF_EXIT_ERR_FATAL 1728523fda3SJan Friedel fi 1738523fda3SJan Friedel # 1748523fda3SJan Friedel # signal to auditd(1M): 1758523fda3SJan Friedel $PKILL -HUP -c ${contract_id} 1768523fda3SJan Friedel if [ $? -ne 0 ]; then 1778523fda3SJan Friedel echo "$0: SIGHUP was not successfully delivered to" \ 1788523fda3SJan Friedel "the related contract (${contract_id}/err:$?)." 1798523fda3SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 1808523fda3SJan Friedel exit $SMF_EXIT_ERR_FATAL 1818523fda3SJan Friedel fi 1828523fda3SJan Friedel $SLEEP 5 & 1838523fda3SJan Friedel else 1848523fda3SJan Friedel echo "$0: Service refresh method not supported on systems" \ 1858523fda3SJan Friedel "without converted audit_startup(1M) into auditd service" \ 1868523fda3SJan Friedel "SMF configuration. Clear the service (svcadm(1M))." 1878523fda3SJan Friedel $SVCADM mark maintenance $AUDITD_FMRI 1888523fda3SJan Friedel exit $SMF_EXIT_ERR_CONFIG 1898523fda3SJan Friedel fi 1908523fda3SJan Friedel} 1918523fda3SJan Friedel 1928523fda3SJan Friedel# 1938523fda3SJan Friedel# Call main() to start the own script execution. 1948523fda3SJan Friedelmain 195