#!/bin/sh
#
# This script adds the "-l" argument to "in.ftpd" so that connection
# logging will be enabled.  Refer to in.ftpd(1M) for more information.
#
#SYSTEMS: Solaris, Linux
MSG="# Checking connection logging for the FTP service..."
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  INETD=/etc/inet/inetd.conf
fi
######Linux######
if [ "$SYSTEM" = "Linux" ]; then
  echo ""; echo "$MSG"
  if [ -f /etc/inetd.conf ]; then  #Using /etc/inetd.conf ... fall through to common script
    INETD=/etc/inetd.conf
  elif [ -f /etc/xinetd.conf ]; then  #Using /etc/xinetd.conf ... handle here
    if [ -f /etc/xinetd.d/ftp ]; then   #Ftp is set up...get service name
      CHKL=`cat /etc/xinetd.d/ftp | grep -s "in.ftpd.*[      ]" | grep " \-l"`
      CHKD=`cat /etc/xinetd.d/ftp | grep -s "in.ftpd.*[      ]" | grep " \-d"`
      if [ ! "$CHKL" ]; then
        echo "--WARN-- [FTPD001w] The in.ftpd is NOT being started with the '-l' option."
      fi
      if [ ! "$CHKD" ]; then
        echo "--WARN-- [FTPD001w] The in.ftpd is NOT being started with the '-d' option."
      fi
    fi
    exit 0  #Exit out if xinetd was found and handled here.
  fi
fi
######Common######  #Used for Solaris and Linux where an inetd.conf file was found ($INETD).
CHK=`grep -s "in.ftpd" ${INETD} | grep -v "^#" 2>/dev/null`
CHKL=`echo $CHK | grep -s "in.ftpd.*[      ]" | grep " \-l"`
CHKD=`echo $CHK | grep -s "in.ftpd.*[      ]" | grep " \-d"`
if [ "$CHK" ]; then
  # The FTP service exists, but may not be using the '-l' option.
  if [ ! "$CHKL" ]; then
    echo "--WARN-- [FTPD001w] The in.ftpd is NOT being started with the '-l' option."
  fi
  if [ ! "$CHKD" ]; then
    echo "--WARN-- [FTPD001w] The in.ftpd is NOT being started with the '-d' option."
  fi
fi