#!/usr/bin/perl5.8.4
#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
#  bin/rpc.sara
#
#  Does an "rpcinfo -p" on a machine, tries to determine anything interesting
# running there.
#
#  TODO -- verify args
#
# version 1, Mon Mar 20 21:05:44 1995, last mod by wietse
# version 2, Mon Mar  8 23:30:00 1999, last mod by todd
# version 3, Mon Apr 30 23:30:00 2001, last mod by todd
#
require 'config/paths.pl';
require 'perl/misc.pl';

die "usage: $0 target" unless ($#ARGV <= 1);

# fields for sara...
$severity="x";
$status="a";

$target = $ARGV[0];

open(RPC, "$RPCINFO -p $target|");

while (<RPC>) {
	chop;
	($prog, $vers, $proto, $port, $name) = split;
	if ($name eq "rexd" || $prog == 100017)		{ $rexd = 1; }
	if ($name eq "arm")				{ $arm = 1; }
	if ($name eq "bootparam" || $prog == 100026)	{ $bootparamd = 1; }
	if ($name eq "ypserv" || $prog == 100004)	{ $ypserv = 1; }
	if ($name eq "ypbind" || $prog == 100007)	{ $ypbind = 1; }
	if ($name eq "selection_svc" || $prog == 100015){ $s_svc = 1; }
	if ($name eq "nfs" || $prog == 100003)		{ $nfs = 1; }
	if ($name eq "mountd" || $prog == 100005)	{ $mountd = 1; }
	if ($name eq "rusersd" || $prog == 100002)	{ $rusersd = 1; }
	if ($name eq "rstatd" )				{ $rstatd = 1; }
	if ($name eq "netinfobind" || $prog == 200100001){ $netinfobind = 1; }
	if ($name eq "admind" || $prog == 100087)	{ $admind = 1; }
        if ($name eq "status" || $prog == 100024)       { $statd = 1; }
        if ($name eq "amd" || $prog == 300019)		{ $amd = 1; }
	if ($prog == 100083)				{ $ttdbserverd = 1; }
	if ($prog == 100068)				{ $cmsd = 1; }
	if ($name eq "sadmind" || $prog == 100232)	{ $sadmind = 1; }
	if ($name eq "sgi_fam" || $prog == 391002)	{ $fam = 1; }
        if ($name eq "nisd" || $prog == 100300)		{ $nisd =1; }
        if ($prog == 100221)				{ $kcms_serverd = 1; }
        if ($prog == 100235)				{ $cachefsd = 1; }
	if ($prog == 100234)				{ $gssd = 1; }
        if ($name eq "rquoatad")			{ $rquotad = 1; }
	if ($name eq "walld" || $prog == 100008)	{ $walld = 1; }
        if ($name eq "sprayd" || $prog == 100012)	{ $sprayd = 1; }
        if ($name eq "yppasswdd" || $prog == 100009)    { $yppasswdd = 1;}

}
close(RPC);

if ($rexd) {
	$service = "rexd"; $text = "runs rexd"; &sara_print;
}
if ($arm) {
	$service = "arm"; $text = "runs arm"; &sara_print;
}
if ($bootparamd) {
	$service = "bootparam"; $text = "runs bootparam"; &sara_print;
}
if ($ypserv) {
	$service = "ypserv"; $text = "is a NIS server"; &sara_print;
}
if ($ypbind) {
	$service = "ypbind"; $text = "is a NIS client"; &sara_print;
}
if ($rstatd) {
        $service = "rstatd"; $text = "runs rstatd"; &sara_print;
}  
if ($rusersd) {
	$service = "rusersd"; $text = "runs rusersd"; &sara_print;
}
if ($nfs) {
	$service = "nfs"; $text = "runs NFS"; &sara_print;
}
if ($mountd) {
	$service = "mountd"; $text = "runs NFS"; &sara_print;
}
if ($s_svc) {
	$service = "selection_svc"; $text = "runs selection_svc"; &sara_print;
}
if ($admind) {
	$service = "admind"; $text = "runs admind"; &sara_print;
}
if ($statd) {
        $service = "statd"; $text = "runs statd"; &sara_print;
}
if ($amd) {
	$service = "amd"; $text = "runs automounter"; &sara_print;
}
if ($ttdbserverd) {
	$service = "ttdbserverd"; $text = "runs tooltalk"; &sara_print;
}
if ($cmsd) {
	$service ="cmsd"; $text = "runs calendar manager"; &sara_print;
}
if ($sadmind) {
	$service="sadmind"; $text = "runs sadmind"; &sara_print;
}

if ($fam) {
	$service="fam"; $text = "runs sgi_fam"; &sara_print;
}
if ($nisd) {
        $service="nisd"; $text = "runs nisd"; &sara_print;
}

if ($kcms_serverd) {
        $service="kcms_serverd"; $text = "runs kcms_serverd"; &sara_print;
}
if ($cachefsd) {
        $service="cachefsd"; $text = "runs cachefsd"; &sara_print;
}
if ($gssd) {
        $service="gssd"; $text = "runs gssd"; &sara_print;
}

if ($rquotad) {
        $service="rquotad"; $text = "runs rquotad"; &sara_print;
}

if ($walld) {
        $service="walld"; $text = "runs walld"; &sara_print;
}

if ($sprayd) {
        $service="sprayd"; $text = "runs sprayd"; &sara_print;
}

if ($yppasswd) {
        $service="yppasswdd"; $text = "runs yppasswdd"; &sara_print;
} 



# print something out if nothing has happened so far...
# if rpcinfo returns !0, then flag it; else, nothing interesting showed up.
if ($text eq "") {
	$severity="";
	if ($?) { $text="rpcinfo error #$?"; }
	else { $text="No rpcinfo output of interest"; }
	&sara_print();
}
