#!/usr/local/bin/perl
#
# Find out some stuff about NFS using showmount: world-wide exports,
# boot clients.  Should not bother to do this when rpc.rip fails.
#
 
if ($#ARGV != 0) {
        print "Usage $0 target\n";
        exit(1);
        }

$target=$ARGV[0];
($service = $0) =~ s@^.*/([^\/\.]*)\..*$@$1@;

$status="a";
#
# we don't make value judgements here
#

# require these packages:
require "misc.pl";
require "paths.pl";
require "fix_hostname.pl";

$severity="x";
$service_output="";

open(SM, "$SHOWMOUNT -e $target|");

while (<SM>) {
	next if ($_ =~ /^export list/);
	chop;
	($files, $hosts) = split;
	@hosts = split(",", $hosts);
	for $host (@hosts) {
		$host =~ tr/A-Z/a-z/;
		if ($host eq "\(everyone\)") {
			$trustee="$files@$target";
			$trusted="root@ANY";
			$service_output="$target ANY";
			$text="$target exports $files to everyone";
			}
		else {
			$fqdn = &fix_hostname($host ,$target);
			# if the host doesn't really exist, it could
			# be a netgroup or something... try to complete
			# hostname if not FQDN, etc., then try to resolve.
			# If everything fails, just output what we can:
			if ($fqdn eq "") {
				$status="u";
				$trustee="$files@$target";
				$trusted="root@$host";
				$service_output="$target $host";
				$text="$target exports $files to $host, but we can't verify that $host exists";
				}
			else {
				$host = $fqdn;
				$status="a";
				$trustee="$files@$target";
				$trusted="root@$host";
				$service_output="$target $host";
				$text="$target exports $files to $host";
				}
			}
		&satan_print();
		$print_flag = 1;
		}
	}

# print something out if nothing has happened so far...
if (!$print_flag) {
	$severity="";
	$text="Not running showmount or other error";
	&satan_print();
	}
