#!/bin/ksh93 # start/stop the arpwatch daemon for discovering new IP/Ethernet adresses . /lib/svc/share/smf_include.sh ARPWATCH=@CLIENT_BASEDIR@/sbin/arpwatch # Read command line arguments METHOD="$1" # %m INSTANCE="$2" # %i # Set defaults; SMF_FMRI should have been set, but just in case. if [[ -z ${SMF_FMRI} ]]; then [[ -z ${instance} ]] && instance='default' SMF_FMRI="svc:/network/saslauthd:${instance}" fi # Get a single value property. # $1 .. Name of the property to lookup # $2 .. vName, where to store the unescaped value # $3 .. Optional: SMF_FMRI to use (default: ${SMF_FMRI}) # return: 0 .. non-empty value found; 1 .. prop does not exist or is empty # 2 .. missing FMRI 3 .. usage error function getSvcProp { [[ -z $1 || -z $2 ]] && print -u2 "getSvcProp() requires 2 args" && return 3 typeset -n VAL=$2 typeset FMRI=$3 if [[ -z ${FMRI} ]]; then [[ -n ${SMF_FMRI} ]] && FMRI=${SMF_FMRI} || { VAL= ; return 2 ; } fi VAL="${ svcprop -p $1 ${FMRI} 2>/dev/null ; }" [[ ${VAL} == '""' ]] && { VAL= ; return 1 ; } # unescape VAL="${VAL//\\(['"''`';&()|^<>'\n''\t''\'\047])/\1}" # \047 .. squote return 0 } ZN=${ /sbin/zonename ; } [[ ${ZN} == 'global' ]] && ZPPID=1 || ZPPID=${ pgrep -x zsched 2>/dev/null ; } case "${METHOD}" in start) if [[ ! -x "${ARPWATCH}" ]]; then print -u2 "arpwatch not found" exit SMF_EXIT_ERR_FATAL fi unset ARGS; typeset -a ARGS getSvcProp config/all_bogons X [[ $X == 'true' ]] && ARGS+=( '-a' ) getSvcProp config/no_rdns X [[ $X == 'true' ]] && ARGS+=( '-D' ) getSvcProp config/vendors X [[ -n $X ]] && ARGS+=( '-e' "$X" ) getSvcProp config/datafile X if [[ -n $X ]]; then [[ -e "$X" ]] || touch "$X" ARGS+=( '-f' "$X" ) elif [[ ! -e '/var/arpwatch/arp.dat' ]]; then touch '/var/arpwatch/arp.dat' fi getSvcProp config/interface X [[ -n $X ]] && ARGS+=( '-i' "$X" ) getSvcProp config/log_facility X [[ -n $X ]] && ARGS+=( '-l' "$X" ) getSvcProp config/email X [[ -n $X ]] && ARGS+=( '-m' "$X" ) getSvcProp config/no_bogon_check X [[ $X == 'true' ]] && ARGS+=( '-N' ) getSvcProp config/local_nets X if [[ -n $X ]]; then for N in ${X//,/ } ; do ARGS+=( '-n' "$N" ) done fi getSvcProp config/no_promiscuous X [[ $X == 'true' ]] && ARGS+=( '-p' ) getSvcProp config/no_newstations X [[ $X == 'true' ]] && ARGS+=( '-S' ) getSvcProp config/excludes X [[ -n $X ]] && ARGS+=( '-X' "$X" ) print 'Starting arpwatch ...' ${ARPWATCH} "${ARGS[@]}" ;; stop) # Determine PID of process(es) to stop PID=`pgrep -x -P 1 arpwatch` if [[ -n ${PID} ]]; then if kill $${PID} ; then print 'arpwatch stopped' else print 'arpwatch is not running' fi else print 'arpwatch is not running...' fi ;; *) print -u2 "Usage: $0 {start|stop}" ;; esac exit 0