#!/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.
#
# Linux/gen_inetd - 06/14/93
#
#-----------------------------------------------------------------------------
#
GREP=grep
AWK=awk
SORT=sort
if [ -f /etc/inetd.conf ]; then
  $GREP -v '^#' /etc/inetd.conf |
  $SORT > $WORKDIR/etc_inetd.$$
 echo "/etc/inetd.conf" > $WORKDIR/etc_inetd.$$.src
  echo $WORKDIR/etc_inetd.$$
elif [ -f /etc/xinetd.conf ]; then
  includedir=`$GREP "includedir" /etc/xinetd.conf | $GREP -v "^#" |\
              $AWK '{print $2}'`
  if [ -n $includedir ]; then
    cd $includedir
    user="unknown"
    services=`ls $includedir`
    for service in $services
    do
    svc=`$GREP "^service" $service | awk '{print $2}'`
    comment="`$GREP disable $service|$GREP yes`"
    if [ -n "$comment" ]; then 
      comment="#"
    fi
    user=`$GREP user $service| $GREP '=' | $AWK -F\= '{print $2}' |\
    sed -e s"/ //g"`
    socket=`$GREP socket_type $service| $GREP '='|$AWK -F\= '{print $2}' |\
    sed -e "s/ //g"`
    if [ "$socket" = "stream" ]; then
      type="tcp"
      wait="nowait"
    else
      type="udp"
      wait="wait"
    fi 
    internal=`$GREP INTERNAL $service`
    if [ -n "$internal" ]; then
      serverpath=""
      server="internal"
    else
      serverpath=`$GREP server $service|$GREP -v args|$GREP '=' |$AWK -F\= '{print $2}'`
      if [ "$wait" = "nowait" ]; then
        server="/usr/sbin/tcpd"
      else
        server=$serverpath
      fi
     fi
      echo "$comment$svc $socket $type $wait $user $server $serverpath" >>  /tmp/inetd.conf.$$
 done
  fi
# Problems with .....
   cat /tmp/inetd.conf.$$|$GREP -v "^#" | $SORT > $WORKDIR/etc_xinetd.$$
      echo "/etc/xinetd.d" > $WORKDIR/etc_xinetd.$$.src
      echo $WORKDIR/etc_xinetd.$$

fi
