#!/bin/sh
#
#     tiger - A UN*X security checking system
#     Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#
#    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.
#
# util/mksig - 04/22/93
#
# Script to make signatures for a supported operating system.
#
# 08/28/2003 - jfs - Added ARSC change to use MAJOR instead of REV
# 04/23/2003 - jfs - added missing MD5 definition and check
#                    merged with original (2.2.3) mksig and removed games
#                    added @DEST and @CONFIG definitions
#                    added SunOS dirs
#                    removed CC from needed commands (it is not)
#
#-----------------------------------------------------------------------------
#

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
# MD5 by default is in BINDIR but could be defined on configuration
# too (i.e. not use Tiger's)
[ -z "$MD5" ] && MD5="$BINDIR/md5"

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 MD5 || exit 1
haveallof variables BASEDIR TESTLINK WORKDIR

[ ! $TESTEXEC $MD5 ] && {
  echo "Don't see MD5 (have you compiled Tiger binaries?)... exiting..."
  exit 1
}

comment="$OS $REV"
DIRLIST="/usr/bin /bin /usr/local/bin /usr/sbin /etc /usr/lib /sbin /lib /usr/libexec /usr/local/sbin /usr/X11/bin /usr/games /usr/lib/news/bin /var/lib/games"
# For SunOS
DIRLIST="$DIRLIST /usr/etc /usr/ucb /usr/mbin /usr/bsd /usr/5bin /usr/sysv"


outfile="signatures.$OS-$REV-$ARCH"
MAJOR=`echo $REV | awk -F\. '{print $1}'`

echo "Working..."

{
  echo "#"
  echo "# Signature file for $OS $REV $ARCH, generated `date`"
  echo "#"
  echo "#@DEST=$OS/$MAJOR/$ARCH"
  echo "#@CONFIG=$OS/$MAJOR"

  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
at
atc
bash
cardctl
chage
chfn
chsh
crontab
csh
ct
cu
dm
dos
dump
dumpreg
expreserve
file
fingerd
ftpd
gpasswd
inc
inetd
in.fingerd
in.ftpd
inndstart
in.rexecd
in.rlogind
in.rshd
in.telnetd
in.tftpd
in.uucpd
ksh
lockfile
login
lpc
lpd
lpq
lpr
lprm
lpstat
ls
man
minicom
mount
movemail
mutt
named
netreport
netstat
newgrp
ntpdate
nwsfind
nxterm
passwd
ping
portmap
procmail
ps
pwdb_chkpwd
rcp
rdist
restore
restorefont
restorepalette
restoretextmode
rexecd
rlogin
rlogind
robots
rpc.mountd
rpc.passwd
rpc.yppasswdd
rsh
rshd
rxvt
screen
sendmail
sendmail.mx
seyon
sh
sperl5.00404
ssh
sshd
startinnfeed
su
suidperl
tcpd
tcsh
telnet
telnetd
tftpd
traceroute
umount
userhelper
usernetctl
uucico
uucp
uucpd
uuname
uustat
uux
uuxqt
wall
write
XConsole
xlock
xscreensaver
xterm
Xwrapper
ypbind
ypserv
ypxfrd
zgv
zsh
EOL
} > $outfile

echo "Signatures stored in $outfile."
