181ea85a8SBrad Davis#!/bin/sh 281ea85a8SBrad Davis# 381ea85a8SBrad Davis# Copyright (c) 2001 The FreeBSD Project 481ea85a8SBrad Davis# All rights reserved. 581ea85a8SBrad Davis# 681ea85a8SBrad Davis# Redistribution and use in source and binary forms, with or without 781ea85a8SBrad Davis# modification, are permitted provided that the following conditions 881ea85a8SBrad Davis# are met: 981ea85a8SBrad Davis# 1. Redistributions of source code must retain the above copyright 1081ea85a8SBrad Davis# notice, this list of conditions and the following disclaimer. 1181ea85a8SBrad Davis# 2. Redistributions in binary form must reproduce the above copyright 1281ea85a8SBrad Davis# notice, this list of conditions and the following disclaimer in the 1381ea85a8SBrad Davis# documentation and/or other materials provided with the distribution. 1481ea85a8SBrad Davis# 1581ea85a8SBrad Davis# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1681ea85a8SBrad Davis# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1781ea85a8SBrad Davis# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1881ea85a8SBrad Davis# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1981ea85a8SBrad Davis# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2081ea85a8SBrad Davis# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2181ea85a8SBrad Davis# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2281ea85a8SBrad Davis# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2381ea85a8SBrad Davis# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2481ea85a8SBrad Davis# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2581ea85a8SBrad Davis# SUCH DAMAGE. 2681ea85a8SBrad Davis# 2781ea85a8SBrad Davis# 2881ea85a8SBrad Davis 2981ea85a8SBrad Davis# This is a library file, so we only try to do something when sourced. 3081ea85a8SBrad Daviscase "$0" in 3181ea85a8SBrad Davis*/security.functions) exit 0 ;; 3281ea85a8SBrad Davisesac 3381ea85a8SBrad Davis 3481ea85a8SBrad Davis# 3581ea85a8SBrad Davis# Show differences in the output of an audit command 3681ea85a8SBrad Davis# 3781ea85a8SBrad Davis 3881ea85a8SBrad DavisLOG="${security_status_logdir}" 3981ea85a8SBrad Davisrc=0 4081ea85a8SBrad Davis 4181ea85a8SBrad Davis# Usage: COMMAND | check_diff [new_only] LABEL - MSG 4281ea85a8SBrad Davis# COMMAND > TMPFILE; check_diff [new_only] LABEL TMPFILE MSG 4381ea85a8SBrad Davis# if $1 is new_only, show only the 'new' part of the diff. 4481ea85a8SBrad Davis# LABEL is the base name of the ${LOG}/${label}.{today,yesterday} files. 4581ea85a8SBrad Davis 4681ea85a8SBrad Davischeck_diff() { 4781ea85a8SBrad Davis unset IFS 4881ea85a8SBrad Davis rc=0 4981ea85a8SBrad Davis if [ "$1" = "new_only" ]; then 5081ea85a8SBrad Davis shift 5181ea85a8SBrad Davis filter="grep '^[>+][^+]'" 5281ea85a8SBrad Davis else 5381ea85a8SBrad Davis filter="cat" 5481ea85a8SBrad Davis fi 5581ea85a8SBrad Davis label="$1"; shift 5681ea85a8SBrad Davis tmpf="$1"; shift 5781ea85a8SBrad Davis msg="$1"; shift 5881ea85a8SBrad Davis 5981ea85a8SBrad Davis if [ "${tmpf}" = "-" ]; then 6081ea85a8SBrad Davis tmpf=`mktemp -t security` 6181ea85a8SBrad Davis cat > ${tmpf} 6281ea85a8SBrad Davis fi 6381ea85a8SBrad Davis 6481ea85a8SBrad Davis if [ ! -f ${LOG}/${label}.today ]; then 6581ea85a8SBrad Davis rc=1 6681ea85a8SBrad Davis echo "" 6781ea85a8SBrad Davis echo "No ${LOG}/${label}.today" 6881ea85a8SBrad Davis cp ${tmpf} ${LOG}/${label}.today || rc=3 6981ea85a8SBrad Davis fi 7081ea85a8SBrad Davis 7181ea85a8SBrad Davis if ! cmp -s ${LOG}/${label}.today ${tmpf} >/dev/null; then 7281ea85a8SBrad Davis [ $rc -lt 1 ] && rc=1 7381ea85a8SBrad Davis echo "" 7481ea85a8SBrad Davis echo "${msg}" 7581ea85a8SBrad Davis diff ${security_status_diff_flags} ${LOG}/${label}.today \ 7681ea85a8SBrad Davis ${tmpf} | eval "${filter}" 7781ea85a8SBrad Davis mv ${LOG}/${label}.today ${LOG}/${label}.yesterday || rc=3 7881ea85a8SBrad Davis mv ${tmpf} ${LOG}/${label}.today || rc=3 7981ea85a8SBrad Davis fi 8081ea85a8SBrad Davis 8181ea85a8SBrad Davis rm -f ${tmpf} 8281ea85a8SBrad Davis exit ${rc} 8381ea85a8SBrad Davis} 84