#
# Check your rpc services.  Make sure you aren't running bad ones.
#

#
# Initialize Variables that keep track of servers running
#
$info      = 0;
$warn      = 0;
$rexd      = 0;
$mountd    = 0;
$bootparam = 0;
$bootp     = 0;
$rstatd    = 0;
$sprayd    = 0;
$snoopd    = 0;
$rusersd   = 0;
$ypserv    = 0;

#
############################################################################
#

&pcheck("Rpc Services");
$warn  = 0;
$error = 0;
$info  = 0;

if (!(-f $rpcinfo)) {
	&report("ERROR: Cannot find rpcinfo with the path $rpcinfo\n");
	&error;
	exit;
}


if (open(RPC, "$rpcinfo -p localhost |")) {

    while (<RPC>) {

	if ((/rexd/)&&(! $rexd)) {
		&report("DANGER:  You are running rexd on this machine.  Rexd is an insecure\n",
		"\tnetwork service because its method of authentication is very\n",
		"\tweak. Disable it.\n");
		$rexd = 1;
	}

	if ((/mountd/)&&(! $mountd)) {

		@mount_state = `$showmount -e localhost`;

		if (grep(/no exported file systems for localhost/,@mount_state)){
			&report("INFO: You are running mountd, but have no exported filesystems.  If this\n",
			"\tmachine is not a file server, it should probably be disabled.\n");
		}
		$mountd = 1;
	}

	if ((/bootparam/)&&(! $bootparam)) {
		&report("WARNING: You are running bootparam.  This service can be dangerous to\n",
		"\trun if it is not absolutely necessary.  Unless there are clients\n",
		"\tusing bootparam to boot, disable it.\n");
		$bootparam = 1;
	}

	if ((/bootp/)&&(! $bootp)) {
		&report("INFO: You are running bootp.  This is not a security hole in itself\n",
		"\tbut if you are not using it, you should probably disable it.\n");
		$bootp = 1;
	}

	if ((/rstatd/)&&(! $rstatd)) {
		&report("INFO: You are running rstatd.  This service tells people quite a bit about\n",
		"\tthe machine.  Unless you actively use this service, it probably could\n",
		"\tbe disabled.\n");
		$rstatd = 1;
	}

	if ((/sprayd/)&&(! $sprayd)) {
		&report("INFO: You are running sprayd.  Unless you are doing network testing or\n",
		"\tpacket timeing, you probably do not need this enabled.\n");
		$sprayd = 1;
	}

	if ((/snoopd/)&&(! $snoopd)) {
		&report("WARNING: You are running snoopd.  Unless you are actively using it, you\n",
		"\tshould turn it off.  With the wrong permissions, it could let anybody\n",
		"\tsnoop your network traffic.\n");
		$snoopd = 1;
	}

	if ((/rusersd/)&&(! $rusersd)) {
		&report("INFO: You are running rusersd, which will let remote users see who is\n",
		"\ton your system.  If you do not want people to have this information\n",
		"\tyou should probably turn it off.\n");
		$rusersd = 1;
	}

	if ((/ypserv/)&&(! $ypserv)) {
		&report("INFO: You are running ypserv.  Make sure that this machine has a\n",
		"\trandomly chosen NIS domain, rather than a domain with the hostname\n",
		"\ta dictionary word.\n");
		$ypserv = 1;
	}
    }

}

if ($ypserv && $bootparam) {
	&report("WARNING: Running both ypserv and bootparam can be a\n",
	"\tsecurity risk.  If you don't absolutely need both running,\n",
	"\tbootparam should be disabled.\n");
	$warn = 1;
}


if ($rexd) {
	&failed;
} elsif ($bootparam || $snoopd || $warn) {
	&warn;
} elsif ($info || $rusersd || $sprayd || $rstatd || $bootp || $mountd) {
	&info;
} else {
	&passed;
}

exit 0;
