#!/bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#     Copyright (C) 2004 Ryan Bradetich
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2, or (at your option)
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#     Please see the file `COPYING' for the complete copyright notice.
#
# Tru64/5/gen_mounts - 03/31/2004
#
#-----------------------------------------------------------------------------
#

dirname()
{
  _path="$1"

  saveifs=$IFS
  IFS=/
  set X $_path
  IFS=$saveifs

  shift

  if [ $# -eq 1 ]; then
    _dirname='/'
  else
    _dirname=
    while [ $# -ne 1 ]
    do
      _dirname="$_dirname/$1"
      shift
    done
  fi
  
  echo "$_dirname"
}
  
LOCAL_ONLY=$1
CHKRO=$2

ronly()
{
  RO=1
  case "$1" in
    *[!a-zA-Z]ro[!a-zA-Z]*) RO=0
      ;;
  esac
  return $RO
}

localfs()
{
  LOCAL=1
  [ "$1" = "advfs" ] && LOCAL=0
  [ "$1" = "procfs" ] && LOCAL=1
  return $LOCAL
}

# If run directly do this, just in case:
[ -z "$GETFS" ] && GETFS=`which mount`
[ -z "$BASENAME" ] && BASENAME=`which basename`

$GETFS  |
while read fs o mtpoint t fstype opts
do
  PRINT=1
  [ "$CHKRO" = "rw" ] && { ronly "$opts" && PRINT=0; }
  [ "$LOCAL_ONLY" = "local" ] && { localfs "$fstype" || PRINT=0; }
  [ "$PRINT" = "1" ] && {
    dir=`dirname $fs`
    file=`$BASENAME $fs`
    rfs="$dir/r$file"
    echo "$mtpoint $fstype $fs"
  }
done

