#
# Check the sendmail.cf for expn and vrfy allows..
#

&pcheck("Sendmail");

$SIG{"ALRM"} = "Hungup";
alarm(10);

pipe(P1,P2);

if (!($child =  fork())) {
	if (-x $sendmail) {
		$output = `$sendmail $sendmailop`;
		if ($output =~ /8.(6.(10|11)|7)/) {
			print P2 "INFO: Running a good version of sendmail.\n";
		} else {
			print P2 "FAILURE: Not running a good version of sendmail. Upgrade to sendmail 8.6.11.\n";
		}
	}
	exit;
}

$results = <P1>;
&report($results);

if ($results =~ /^FAILURE/) {
	&failed;
	exit;
}

$noexpn = 1;
$novrfy = 1;
$restrictqrun = 1;
$authwarnings = 1;

if (open(SENDMAILCF, $sendmailcf)) {
	while (<SENDMAILCF>) {
		next unless (/^Op/);
		chop;

		($op,$flags) = unpack("a2a80",$_);
		@flags = split(/,/,$flags);

		foreach $flag (@flags) {
			if ($flag eq "noexpn") {
				$noexpn = 0;
			} elsif ($flag eq "novrfy") {
				$novrfy = 0;
			} elsif ($flag eq "restrictqrun") {
				$restrictqrun = 0;
			} elsif ($flag eq "authwarnings") {
				$authwarnings = 0;
			}
		}
			
	}
} else {
	&report("WARNING:  Couldn't open the $sendmailcf file.\n");
	&warn;
	exit;
}

close (SENDMAILCF);

if ($authwarnings) {
	&report("WARNING:  Sendmail does not have the \"authwarnings\" flag\n",
	"\tset.  This flag will ensure that sendmail will log\n",
	"\tattempts to expn, vrfy, or do other actions with\n",
	"\tsendmail that you may not want people to do.  To\n",
	"\tfix this,  add authwarnings to the Op line.\n");
}

if ($noexpn) {
	&report("WARNING:  Sendmail does not have the \"noexpn\" flag\n",
	"\tset.  This flag keeps remote users from expanding\n",
	"\tlocal mail addresses and looking for users on the\n",
	"\tsystem. To fix this, add noexpn to the Op line.\n");
}

if ($novrfy) {
	&report("WARNING:  Sendmail does not have the \"novrfy\" flag\n",
	"\tset.  This flag keeps remote users from verifying\n",
	"\tlocal mail addresses and looking for users on the\n",
	"\tsystem. To fix this, add novrfy to the Op line.\n");
}

if ($restrictqrun) {
	&report("WARNING:  Sendmail does not have the \"restrictqrun\" flag\n",
	"\tset.  This flag keeps local users from running the mail\n",
	"\tqueue. To fix this, add restrictqrun to the Op line.\n");
}

if ($noexpn || $novrfy || $restrictqrun) {
	&warn;
} else {
	&info;
}

exit 0;


sub Hungup {
	kill 9,$child;
	&report("FAILURE: The test on sendmail hung and had to be terminated.\n",
	"\tThis means that you are probably running the wrong version of\n",
	"\tsendmail, or its badly misconfigured.  You should be running\n",
	"\tEric Allman's sendmail, and should check your configuration.\n");
	&failed;
	exit;
}
