#!/bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#
#     Please see the file `COPYING' for the complete copyright notice.
#
# util/mksig - 04/22/93
#
#-----------------------------------------------------------------------------
#

basedir=${TIGERHOMEDIR:=.}

for parm
do
   case $parm in
   -B) basedir=$2; break;;
   esac
done

[ ! -r $basedir/config ] && {
  echo "--ERROR-- [init002e] No 'config' file in \`$basedir'."
  exit 1
}

. $basedir/config

haveallof()
{
  retval=0
  what=$1
  shift
  for file
  do
    eval cmd=\$$file
    [ ! -n "$cmd"  ] && {
      echo "--ERROR-- [init001e] Don't have all required $what (missing $file)"
      retval=1
    }
  done
  return $retval
}

haveallof commands CAT CC || exit 1
haveallof variables BASEDIR TESTLINK WORKDIR

[ ! $TESTEXEC $MD5 ] && {
  echo "Don't see MD5... exiting..."
}

comment="$OS $REV"
DIRLIST="/usr/bin /bin /usr/etc /usr/ucb /usr/sbin /etc /usr/lib /sbin /usr/lbin /usr/mbin /usr/bsd /usr/5bin /usr/sysv"

outfile="signatures.$OS-$REV-$ARCH"

echo "Working..."

{
  echo "#"
  echo "# Signature file for $OS $REV $ARCH, generated `date`"
  echo "#"

  while read file
  do
    indir=
    for dir in $DIRLIST
    do
      [ ! $TESTLINK $dir ] && {
	[ -f $dir/$file -a ! $TESTLINK $dir/$file -a $TESTEXEC $dir/$file ] && {
	  indir=$dir
	  if [ -r $indir/$file ]; then
	    sig=`$MD5 < $indir/$file`
	    echo "Y .       $indir/${file} ${sig} $comment"
	  else
	    echo "# $indir/$file not readable."
	  fi
	}
      }
    done
    
    if [ ! -n "$indir" ]; then
      echo "# $file not found."
    fi
  done <<EOL
sh
csh
ksh
login
su
passwd
in.fingerd
fingerd
in.ftpd
ftpd
in.rexecd
rexecd
in.rlogind
rlogind
in.rshd
rshd
in.telnetd
telnetd
in.tftpd
tftpd
in.uucpd
uucpd
rpc.yppasswdd
rpc.passwd
portmap
ypserv
ypxfrd
ypbind
sendmail
sendmail.mx
rdist
rlogin
rsh
telnet
lpstat
lpc
lpd
lpr
lprm
lpd
rpc.mountd
expreserve
EOL
} > $outfile

$RM -f $WORKDIR/snefru

echo "Signatures stored in $outfile."
