#!/sbin/sh
set -a

#  
# Routine checks is node specified in $1 can
# mount path specified in $2.
# Acccuracy is so-so. 
# If return value is 0, it's pretty dependable
# Some failure returns should have been success
# as netgroups and "root" users are not handled.
#  
#  

PATH=$PATH:/usr/etc:/usr/sbin

if [ $# -ne 2 ]
then
  echo "usage: $0 host path" >&2
  exit 1
fi

XTNAME=$1

if [ ! -f $2 -a ! -d $2 ]
then
  echo "path $2 does not exist" >&2
  exit 1
fi

if [ -d $2 ]
then
  DIR=$2
else
  DIR=`dirname $2`
fi

cd $DIR
DIR=`pwd`
DIRS=$DIR

DFCMD=df

if [ "`uname -s`" = "HP-UX" ]
then
  DFCMD=bdf
fi

FS=`$DFCMD $DIR | awk '{print $NF}' | tail -1`

while true
do
  if [ "$DIR" = "/" -o "$DIR" = "$FS" ]
  then
    break
  fi

  DIR=`dirname $DIR`
  DIRS="$DIR $DIRS"
done

for DIR in $DIRS
do
  showmount -e | egrep "$DIR[ 	]" | awk '{print $2}' \
	| egrep "(((^)|(,))$XTNAME((\$)|([, ])))|(everyone)"  > /dev/null
  if [ $? -eq 0 ]
  then
    exit 0
  fi
done

exit 2
