#
# Check the nis domain name for being too simple and the ypbind options
#

&pcheck("NIS/YP Checks");

#
# Check to see if YP is turned on
#
if (open(NIS, $ypconfig)) {
	$status = <NIS>;
	chop ($status);
} else {
	&report("ERROR:  Cannot open the $ypconfig file.\n");
	&error;
	exit;
}

if ($status eq "off") {
	&report("INFO:  NIS (Yp) is not enabled on this machine.\n");
	&info;
	exit;
}


#
# Check the ypbind options
#
if (open(YPBIND, $ypbindopt)) {
	$line = <YPBIND>;
	if (!/-s/) {
		do dashs();
	}
	if (!/-ypsetme/) {
		do ypsetme();
	}
	if (/-ypset(\s|$)/) {
		do ypset();
	}
}


#
# Check the NIS domain name for being easily guessable
#
if (open(DOMAIN, $domainname)) {
	$ypdomain = <DOMAIN>;
} else {
	&report("ERROR:  Cannot open the $domainname file.\n");
	&error;
	exit;
}

@hostparts = split(/\./,$hostname);
$baddomain = 0;

foreach $part (@hostparts) {
	if ($hostname eq "$part") {
		$baddomain = 1;
	}
}

if (open(DICT, $dict)) {
	while (<DICT>) {
		chop;
		if ($hostname eq $_) { $baddomain = 1; }
	}
}


if ($baddomain) {
	&report("WARNING:  Your NIS (YP) Domain may not be secure. It\n",
	"\twas found while doing a basic attack to try and guess\n",
	"\tit.  Please change the domain to a non-guessable word.\n");
	&failed;
}

if ($fail) {
	&failed;
} elsif ($warn) {
	&warn;
} else {
	&passed;
}

exit 0;

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

sub dashs {
	&report("WARNING: ypbind is running without -s (secure) set.  The -s\n",
	"\toption will limit yp bindings to secure/prived ports.  This should\n",
	"\tbe set on. in the $ypbindopt file.\n");
	$warn = 1;
}

sub ypsetme {
	&report("WARNING: ypbind is running without -ypsetme set. This option\n",
	"\tprovides some basic security by checking addresses/host names. It\n",
	"\tshould be added to the $ypbindopt file.\n");
	$warn = 1;
}

sub ypset {
	&report("DANGER: ypbind is running with -ypset.  This lets any user\n",
	"\tchange the yp binding.  This should be removed from $ypbindopt.\n");
	$fail = 1;
}
