#
# Check portmap, rpcbind, and portmap options
#

&pcheck("Portmapper");

$pmapopt = "/etc/config/portmap.options";

#
# Initialize Variables that keep track of servers running
#
$rpcbind   = 0;
$error     = 0;
$warn      = 0;
$info      = 0;

if ((-x $rpcbind) && (-x $portmap)) {
	&report("INFO: You have both rpcbind and portmap executable, which means that rpcbind\n",
	"\twill get executed upon booting.  Portmap has a better verbose log\n",
	"\toption, and you may wish to run that.  Rpcbind can be disabled by\n",
	"\tmaking it non-executable.  Another option is running the public\n",
	"\tdomain portmap, available at ftp.win.tue.nl in the /pub/security\n",
	"\tdirectory. (If possible, run that, as it fixes other problems in\n",
	"\tthe generic portmap program.)\n");
	$rpcbind = 1;
}

if (open(PMAPOPT, $pmapopt)) {
	$options = <PMAPOPT>;
	if (!($options =~ /-a/)) {
		&report("WARNING: Your portmap is not restricted.  It is generally a good idea to\n",
		"\tlimit the portmap access to your local network.  This can be done\n",
		"\tby using the -a option in the $pmapopt file, and specifying\n",
		"\ta net mask to restrict limitations to.\n");
		$warn = 1;
	}
	if (!($options =~ /-v/)) {
		&report("WARNING: Your portmap is not set to log failed or refused connections.\n",
		"\tThis can be done by adding the -v option to $pmapopt.\n",
		"\tNote: If you are using rpcbind in place of portmap,\n",
		"\tit will log every request\n",
		"\tto portmap.\n");
		$warn = 1;
	}
} else {

	$coolportmap = 0;
	if (open(PMAP, "$strings $portmap|")) {
		while (<PMAP>) {
			if (/portmap\.c\s+5\.4\s+\(Berkeley\)/) {
				$coolportmap = 1;
			}
		}
	
		if (($coolportmap) && (! $rpcbind)) {
			&report("INFO: You are running portmap_3.  Good.\n");
			$info = 1;
		} else {
			&report("ERROR:  Cannot open the $pmapopt file.\n");
			$error = 1;
		}
	} else {
		&report("ERROR:  Cannot do a strings on $portmap.\n");
		$error = 1;
	}
}

if ($error) {
	&error;
} elsif ($warn || $rpcbind) {
	&warn;
} elsif ($info) {
	&info;
} else {
	&passed;
}
		

exit 0;
