#
# Checks the options on various $inetd based services
#

&pcheck("Inetd options");

$match    = 1;	# Rshd address matching
$log      = 1;	# Rshd loggin
$rlmatch  = 1;  # Rlogind address matching
$hostinfo = 1;  # Telnetd suppress host information
$fingerd  = 1;  # Fingerd suppress user info
$flog     = 0;	# Ftpd logging

if (open(INETD, $inetd)) {
	while (<INETD>) {
		@parts = split(/\s+/);

		if (/rshd/) {
			for ($i=7; $i <= $#parts; $i++) {
				if (@parts[$i] eq "-L") { $log = 0; }
				elsif (@parts[$i] eq "-a") { $match = 0; }
			}
		} elsif (/rlogind/) {
			for ($i=7; $i <= $#parts; $i++) {
				if (@parts[$i] eq "-a") { $rlmatch = 0; }
			}
		} elsif (/telnetd/) {
			for ($i=7; $i <= $#parts; $i++) {
				if (@parts[$i] eq "-h") { $hostinfo = 0; }
			}
		} elsif (/fingerd/) {
			for ($i=7; $i <= $#parts; $i++) {
				if (@parts[$i] eq "-S") { $fingerd = 0; }
			}
		} elsif (/ftpd/) {
			for ($i=7; $i <= $#parts; $i++) {
				if (@parts[$i] eq "-l") { $flog++; }
			}
		}
	}
} else {
	&report("ERROR:  Cannot open the $inetd file.\n");
	&error;
	exit;
}

if ($log) {
	&dashl();
}
if ($match) {
	&dasha();
}

if ($rlmatch) {
	&rlmatch();
}

if ($hostinfo) {
	&hostinfo();
}

if ($fingerd) {
	&fingerd();
}

if (! $flog) {
	&flog1();
} elsif ($flog == 1) {
	&flog2();
}

if ($log || $match || $rlmatch || $hostinfo || $fingerd || ($flog > 0)) {
	&warn;
} else {
	&passed;
}

exit 0;

#############################################################################
#
# ERROR/WARNING/INFO Messages
#

sub dashl {
	&report("WARNING:  Rshd is not running with the -L flag.  This flag will syslog\n",
	"\tcommands rshelled to the command.  This is generally a good thing\n",
	"\tto log.\n");
}

sub dasha {
	&report("WARNING:  Rshd is not running with the -a flag.  This flag makes\n",
	"\trshd check the name and address to make sure they match.\n",
	"\tThis is a good thing to have turned on.\n");
}

sub rlmatch {
	&report("WARNING:  Rlogind is not running with the -a flag.  This flag makes\n",
	"\trlogind check the name and address to make sure they match.\n",
	"\tThis is a good thing to have turned on.\n");
}

sub hostinfo {
	&report("WARNING: Telnetd is not running with the -h flag.  This flag will\n",
	"\thide the host information when a telnet connection is made to it.\n",
	"\tThis is helpful if you would like this information to be private.\n");
}

sub fingerd {
	&report("WARNING: Fingerd is not running with the -S flag.  This means that\n",
	"\tremote users can discover any users login status, home directory, and\n",
	"\tshell.  This information is nice to have private.\n");
}

sub flog1 {
	&report("WARNING: Ftpd is not running with the -l option.  This means that\n",
	"\tftpd will not log connections made to it, or any files transfered.\n",
	"\tFor the best logging, add two -l flags after ftpd in the\n",
	"\t$inetd file.\n");
}

sub flog2 {
	&report("WARNING: Ftpd is running with only one -l option.  This means that\n",
	"\talthough connections and login information is logged, the activities\n",
	"\tof the session are not.  To increase this logging, add a second -l\n",
	"\tflag in the $inetd file.\n");
}

