#!/usr/local/bin/perl
#
# $Id: SysAudit.pl,v 1.8 2005/01/20 02:22:27 rdilley Exp $
#
# author: ron dilley
#
# desc: this perl script  audits a system
#
# Copyright (C) 2000  Ron A. Dilley
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ron.dilley@uberadmin.com
#
############################################################################

#
# defines
#
$VERSION = '$Id: SysAudit.pl,v 1.8 2005/01/20 02:22:27 rdilley Exp $';

$TRUE = 1;
$FALSE = 0;
$FAILED = -1;

$APPNAME = "SysAudit";

chop( $TODAY = `/bin/date` );
$VXVA = "/dev/vx";
$ODS = "/dev/md";
chop( $MACHINE = `uname -m` );
$PRTDIAG="/usr/platform/${MACHINE}/sbin/prtdiag";

#
# variables
#
$disk_count = 0;

if ( &main() != $TRUE ) {
  exit( 1 );
}

exit( 0 );

#########################################################
#
# subroutines
#

#
# main routine
#
sub main {
  &show_banner();

  if ( &parse_command_line() != $TRUE ) {
    return $FAILED;
  }

  &load_vfstab();
  &load_prtconf();
  &load_psrinfo();
  &get_disks();

  #
  # display system information
  #
  &show_sectionmarker( "System Information" );
  &show_system();

  #
  # display processor info
  #
  &show_sectionmarker( "Processor Information" );
  &show_psrinfo();

  if ( &has_isainfo() == $TRUE ) {
    #
    # display instructionset information
    #
    &show_sectionmarker( "Instruction Set Architectures" );
    &show_isainfo();
  }

  #
  # display lan information
  #
  &show_sectionmarker( "Ethernet/Network Information" );
  &show_lan();

  #
  # display route information
  #
  &show_sectionmarker( "Routing Information" );
  &show_routes();

  #
  # display inetd information
  #
  &show_sectionmarker( "Inetd Information" );
  &show_inetd();

  if ( &has_tcp_wrappers() ) {
    #
    # display tcp_wrappers information
    #
    &show_sectionmarker( "tcp_wrappers" );
    &show_tcp_wrappers();
  }

  #
  # display rpc information
  #
  &show_sectionmarker( "RPC Information" );
  &show_rpc();

  #
  # if prtdiag exists, display it
  #
  if ( -e $PRTDIAG ) {
    &show_sectionmarker( "System Diagnosic Information" );
    &load_prtdiag();
    &show_prtdiag();
  }

  #
  # if netgroups enabled, display members
  #
  if ( &has_netgroups() ) {
    &show_sectionmarker( "Authorized Netgroups" );
    &show_netgroups();
  }

  #
  # test if script running as root
  #
  if ( &is_root() == $TRUE ) {
    #
    # display disk info and local mount points
    #
    &show_sectionmarker( "Disk Information" );
    &show_slices();
    &show_scsi_info();
    &show_vtoc_info();
  }

  #
  # test for vxva
  #
  if ( &has_vxva() == $TRUE ) {
    #
    # display vxva information
    #
    &show_sectionmarker( "Sun Volume Manager Information" );
    &show_vxva();
  }

  #
  # test for ods
  #
  if ( &has_ods() == $TRUE ) {
    #
    # display ods information
    #
    &show_sectionmarker( "Sun Disk Manager Information" );
    &show_ods();
  }

  #
  # test for raid manager
  #
  if ( &has_raidmanager() == $TRUE ) {
    #
    # display raidmanager information
    #
    &show_sectionmarker( "Solstice Raid Manager Information" );
    &show_raidmanager();
  }

  #
  # display sun printconfig info
  #
  &show_sectionmarker( "Sun Software Node Information" );
  &show_prtconf();

  #
  # display package info
  #
  &show_sectionmarker( "Package Information" );
  &show_packages();

  #
  # test if script running as root
  #
  if ( &is_root() == $TRUE ) {
    #
    # display cron information
    #
    &show_sectionmarker( "cron Information" );
    &show_crons();
  }

  #
  # display rc script information
  #
  &show_sectionmarker( "rcScript Information" );
  &show_rcscripts();

  #
  # test for dns
  #
  if ( &has_dns() ) {
    #
    # display dns information
    #
    &show_sectionmarker( "DNS Information" );
    &show_dns();
  }

  #
  # test for nis+
  #
  if ( &has_nisplus() == $TRUE ) {
    #
    # display nis+ information
    #
    &show_sectionmarker( "NIS+ Information" );
    &show_nisplus();
  }

  return TRUE;
}

#
# display banner info
#
sub show_banner {
  print "$APPNAME v$VERSION\n";
  print "By: Ron Dilley\n";
  print "\n";
  print "$APPNAME comes with ABSOLUTELY NO WARRANTY.\n";
  print "This is free software, and you are welcome\n";
  print "to redistribute it under certain conditions;\n";
  print "See the GNU General Public License for details.\n";
  print "\n";
  print "Generated: $TODAY\n";
  print "\n";

  return $TRUE;
}

#
# display help info
#
sub show_help {
  print "Syntax:\n";
  print "\n";
  print "$APPNAME [options]\n";
  print "\n";
  print "-debug [0-9]   Display debug information during program run\n";
  print "\n";

  return $TRUE;
}

#
# parse command-line arguments
#
sub parse_command_line {
  my ( @args ) = @ARGV;
    
  while( $_ = shift( @args ) ) {
    if ( /^-/ ) {
      if ( /^-debug$/ ) {
	$Config{'debug'} = $TRUE;
	while( substr( $args[0], 0, 1 ) ne '-' && @args > 0 ) {
	  $Config{'debug'} = shift( @args );
	}
      } elsif ( /^-help|-h|-?$/ ) {
	&show_help();
	return $FAILED;
      } else {
	print "WARNING - Unknown argument \[$_\]\n";
      }
    }
  }

  return $TRUE;
}

#
# get disks installed in system
#
sub get_disks {
  my $line;
  my @tmp;

  open( FORMAT, "/usr/sbin/format << EOF 2>&1\n0\nq\nEOF\n |" );

  while( chop( $line = <FORMAT> ) ) {
    if ( index( $line, "$disk_count. " ) > 0 ) {
      @tmp = split( / +/, $line );
      $disks[$disk_count] = $tmp[2];
      $disk_count++;
    }
  }

  close( FORMAT );

  return $TRUE;
}

#
# show slice information for disks installed in system
#
sub show_slices {
  my $slice_count;
  my $line;
  my @tmp;
  my $mount;
  my $disk;

  foreach $disk ( @disks ) {
    $slice_count = 0;

    print "$disk\n";

    open( FORMAT, "/usr/sbin/format -d $disk << EOF 2>&1\npart\nprint\nEOF\n |" );

    while( chop( $line = <FORMAT> ) ) {
      if ( index( $line, "  $slice_count " ) == 0 ) {
	@tmp = split( / +/, $line );

	if ( $tmp[5] eq "-" ) {
	  printf( "\ts%s %-11s %s %-11s %-11s %s%s%s cylinders", $tmp[1], $tmp[2], $tmp[3], $tmp[7], $tmp[8], $tmp[4], $tmp[5], $tmp[6] );
	  foreach $mount ( keys( %mounts ) ) {
	    if ( index( $mounts{$mount}, "$disk\s$slice_count" ) >= 0 ) {
	      print " [$mount]";
	    }
	  }

	  print "\n";
	} else {
	  printf( "\ts%s %-11s\n", $tmp[1], $tmp[2] );
	}

	$slice_count++;
      }
    }

    close( FORMAT );
  }

  return $TRUE;
}

#
# show SCSI information for disks installed in system
#
sub show_scsi_info {
  my $line;
  my @tmp;
  my $disk;

  print "\n";

  foreach $disk ( @disks ) {
    print "$disk\n";

    open( FORMAT, "/usr/sbin/format -d $disk << EOF 2>&1\ninq\nEOF\n |" );

    while( chop( $line = <FORMAT> ) ) {
      foreach $string ( "Vendor:", "Product:", "Revision:" ) {
	if ( index( $line, $string ) >= 0 ) {
	  $tmp = substr( $line, index( $line, $string ) );
	  print "\t$tmp\n";
	}
      }
    }

    print "\n";

    close( FORMAT );
  }

  return $TRUE;
}

#
# show vtoc information for disks installed in system
#
sub show_vtoc_info {
  my $line;
  my @tmp;
  my $disk;

  print "\n";
  print "Physical Disk VTOC Info:\n";
  print "\n";

  foreach $disk ( @disks ) {
    open( PRTVTOC, "/usr/sbin/prtvtoc /dev/rdsk/${disk}s0 |" );
    while( chop( $line = <PRTVTOC> ) ) {
      print "$line\n";
    }
    print "\n";
    close( PRTVTOC );
  }

  print "Mounted Device VTOC Info:\n";
  print "\n";

  foreach $disk ( keys( %mounts ) ) {
    if ( $disk ne "swap" ) {
      open( PRTVTOC, "/usr/sbin/prtvtoc $mounts{$disk} |" );
      while( chop( $line = <PRTVTOC> ) ) {
	print "$line\n";
      }
      print "\n";
      close( PRTVTOC );
    }
  }

  return $TRUE;
}

#
# load vfstab for refrence
#
sub load_vfstab {
  my $line;
  my @tmp;

  open( VFSTAB, "/etc/vfstab" );

  while( chop( $line = <VFSTAB> ) ) {
    if ( index( $line, "/dev/" ) == 0 ) {
      @tmp = split( /\t+/, $line );
      if ( $tmp[3] eq "ufs" | $tmp[3] eq "vxfs" ) {
	$mounts{$tmp[2]} = $tmp[1];
      } elsif( $tmp[3] eq "swap" ) {
	$mounts{$tmp[3]} = $tmp[0];
      }
    }
  }

  close( VFSTAB );

  return $TRUE;
}

#
# load sun node configuration
#
sub load_prtconf {
  my $line;
  my @tmp;
  my $line_count;

  $line_count = 0;

  open( PRTCONF, "/usr/sbin/prtconf |" );

  while( $line = <PRTCONF> ) {
    chop( $line );

    if ( index( $line, "SUNW\," ) == 0 ) {
      $hardwaredesc = $line;
    }

    $prtconf[$line_count] = $line;
    $line_count++;
  }

  close( PRTCONF );

  return $TRUE;    
}

#
# load processor info
#
sub load_psrinfo {
  my $line;
  my @tmp;
  my $line_count;

  $line_count = 0;

  open( PSRINFO, "/usr/sbin/psrinfo -v |" );

  while( $line = <PSRINFO> ) {
    chop( $line );
    push( @procinfo, $line );
  }

  close( PSRINFO );

  return $TRUE;
}

#
# load prtdiag info
#
sub load_prtdiag {
  my $line;

  open( PRTDIAG, "$PRTDIAG |" );

  while( $line = <PRTDIAG> ) {
    chop( $line );
    push( @prtdiag, $line );
  }

  close( PRTDIAG );

  return $TRUE;
}

#
# load raidmgr devices
#
sub load_raid_arrays {

  return $TRUE;
}

#
# display prtdiag
#
sub show_prtdiag {
  foreach ( @prtdiag ) {
    print "$_\n";
  }

  return $TRUE;
}

#
# display processor info
#
sub show_psrinfo {
  foreach ( @procinfo ) {
    print "$_\n";
  }

  return $TRUE;
}

#
# display sun printconfig info
#
sub show_prtconf {
  foreach ( @prtconf ) {
    print "$_\n";
  }

  return $TRUE;
}

#
# display section marker
#
sub show_sectionmarker {
  my ( $title ) = @_;

  print "\n";
  print "***********************************************************************\n";
  print "*\n";
  print "* $title\n";
  print "*\n";
  print "***********************************************************************\n";
  print "\n";

  return $TRUE;
}

#
# display package information
#
sub show_packages {
  my $pkg;
  my $cat;
  my $ver;
  my $line;

  open( PKGINFO, "/bin/pkginfo -l |" );

  while( chop( $line = <PKGINFO> ) ) {
    if ( index( $line, "   PKGINST:  " ) == 0 ) {
      $pkg = substr( $line, 13 );
    } elsif( index( $line, "  CATEGORY:  " ) == 0 ) {
      $cat = substr( $line, 13 );
    } elsif( index( $line, "   VERSION:  " ) == 0 ) {
      $ver = substr( $line, 13 );
      printf( "%-13s %-22s %s\n", $pkg, $cat, $ver );
    }
  }

  close( PKGINFO );

  return $TRUE;
}

#
# display ethernet information
#
sub show_lan {
  my $line;
  my @tmp;

  open( IFCONFIG, "/sbin/ifconfig -a |" );
  while( $line = <IFCONFIG> ) {
    chomp( $line );
    print "$line\n";
  }
  close( IFCONFIG );

  return $TRUE;
}

#
# display route information
#
sub show_routes {
  my $line;

  open( NETSTAT, "/bin/netstat -rn |" );
  while( $line = <NETSTAT> ) {
    chomp( $line );
    print "$line\n";
  }
  close( NETSTAT );

  return $TRUE;
}

#
# display inetd information
#
sub show_inetd {
  my $line;

  open( INETD, "/etc/inet/inetd.conf" );
  while( $line = <INETD> ) {
    $line =~ s/\#.*//g;
    $line =~ s/^\s+//g;
    chomp( $line );
    if ( $line ne "" ) {
      print "$line\n";
    }
  }
  close( INETD );

  return $TRUE;
}

#
# display rpc information
#
sub show_rpc {
  my $line;

  open( RPCINFO, "/bin/rpcinfo |" );
  while( $line = <RPCINFO> ) {
    chomp( $line );
    print "$line\n";
  }
  close( RPCINFO );

  return $TRUE;
}

#
# display system information
#
sub show_system {
  chop( $nodename = `/sbin/uname -n` );
  chop( $procname = `/sbin/uname -p` );
  chop( $hardname = `/sbin/uname -m` );
  chop( $osname = `/sbin/uname -s` );
  chop( $osrel = `/sbin/uname -r` );
  chop( $osver = `/sbin/uname -v` );
  chop( $domainname = `/bin/domainname` );
  print "     Node Name: $nodename\n";
  print "   Domain Name: $domainname\n";
  print "Processor Type: $procname\n";
  print " Hardware Name: $hardname\n";
  print " Hardware Desc: $hardwaredesc\n";
  print "       OS Name: $osname\n";
  print "    OS Release: $osrel\n";
  print "    OS Version: $osver\n";

  return $TRUE;
}

#
# display cron information
#
sub show_crons {
  my $line;

  chdir( "/var/spool/cron/crontabs" );

  while( $line = <*> ) {
    if ( $line =~ /.au$/ ) {
      # do nothing
    } else {
      print "\n$line\n";
      print "-----------------------------------------------------------------------\n";

      open( CRONTAB, $line );

      while( chop( $line = <CRONTAB> ) ) {
	if ( index( $line, "#" ) != 0 && index( $line, " " ) != 0 ) {
	  print "$line\n";
	}
      }

      close( CRONTAB );
    }
  }

  return $TRUE;
}

#
# display rcscript information
#
sub show_rcscripts {
  my $line;
  my @tmp;

  chdir( "/etc" );

  while( $line = <rc?.d> ) {
    print "Run-Level: " . substr( $line, 2, 1 ) . "\n";

    chdir( "/etc/$line" );

    open( RUNLEVEL, "/usr/bin/ls -l |" );

    while( chop( $line = <RUNLEVEL> ) ) {
      @tmp = split( / +|\t+/, $line );
      if ( index( $tmp[8], "K" ) == 0 || index( $tmp[8], "S" ) == 0 ) {
	if( index( $tmp[0], "l" ) == 0 ) {
	  print "\t$tmp[8] $tmp[9] $tmp[10]\n";
	} elsif( index( $tmp[0], "-" ) == 0 ) {
	  print "\t$tmp[8]\n";
	}
      }
    }

    close( RUNLEVEL );

    print "\n";
  }

  return $TRUE;
}

#
# test to see if script was run as root
#
sub is_root {
  chop( $username = `/usr/ucb/whoami` );

  if ( $username eq "root" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# test to see if vxva is running
#
sub has_vxva {
  if ( -e $VXVA && -e "/usr/sbin/vxprint" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# display vxva information
#
sub show_vxva {
  my $line;
  my @tmp;

  open( VXPRINT, "/usr/sbin/vxprint |" );
  
  while( chop( $line = <VXPRINT> ) ) {
    print "$line\n";
  }

  close( VXPRINT );

  #
  # show volume manager mounts
  #
  print "\nVolume Manager Mounts:\n\n";

  foreach ( keys( %mounts ) ) {
    if ( index( $mounts{$_}, "/dev/vx/" ) == 0 ) {
      print "$mounts{$_}\t$_\n";
    }
  }

  return $TRUE;
}

#
# test to see if ods is running
#
sub has_ods {
  if ( -e $ODS && -e "/usr/opt/SUNWmd/sbin/metastat" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# display ods information
#
sub show_ods {
  my $line;
  my @tmp;

  #
  # show meta device info
  #
  print "MetaDevice Info:\n";
  print "----------------\n";
  print "\n";
  open( METASTAT, "/usr/opt/SUNWmd/sbin/metastat |" );
  while( chop( $line = <METASTAT> ) ) {
    print "$line\n";
  }
  close( METASTAT );
  print "\n";

  #
  # show metadb info
  #
  print "MetaDB Info:\n";
  print "------------\n";
  print "\n";
  open( METADB, "/usr/opt/SUNWmd/sbin/metadb -i |" );
  while( chop( $line = <METADB> ) ) {
    print "$line\n";
  }
  close( METADB );
  print "\n";  

  #
  # show volume manager mounts
  #
  print "Disk Suite Mounts:\n";
  print "------------------\n";
  print "\n";
  foreach ( keys( %mounts ) ) {
    if ( index( $mounts{$_}, "/dev/md/" ) == 0 ) {
      print "$mounts{$_}\t$_\n";
    }
  }
  return $TRUE;
}

#
# test to see if raid manager is installed
#
sub has_raidmanager {
  if ( &safe_system( "pkginfo SUNWosar > /dev/null 2>&1" ) == $TRUE ) {
    if ( ! -e "/usr/sbin/osa/lad" ) {
      return $FALSE;
    }

    if ( ! -e "/usr/sbin/osa/nvutil" ) {
      return $FALSE;
    }

    if ( ! -e "/usr/sbin/osa/healthck" ) {
      return $FALSE;
    }

    if ( ! -e "/usr/sbin/osa/drivutil" ) {
      return $FALSE;
    }

    if ( ! -e "/usr/sbin/osa/storutil" ) {
      return $FALSE;
    }

    if ( ! -e "/usr/sbin/osa/raidutil" ) {
      return $FALSE;
    }

    return $TRUE;
  }

  return $FALSE;
}

#
# display raid manager information
#
sub show_raidmanager {
  my $line;
  my $dev;
  my @controllers;

  print "RAID Controllers\n";
  print "----------------\n";
  print "\n";

  open( LAD, "/usr/sbin/osa/lad |" );
  while( $line = <LAD> ) {
    chop( $line );
    print "$line\n";
    ( $dev ) = ( split( / +/, $line ) )[0];
    push( @controllers, $dev );
  }
  close( LAD );
  print "\n";

  print "RAID Controller NVRAM Status\n";
  print "----------------------------\n";
  print "\n";

  open( NVUTIL, "/usr/sbin/osa/nvutil -v |" );
  while( $line = <NVUTIL> ) {
    chop( $line );
    if ( ! ( $line =~ /^nvutil/ ) ) {
      print "$line\n";
    }
  }
  close( NVUTIL );

  foreach $dev ( @controllers ) {
    print "\n";
    print "RAID Controller Info: $dev\n";
    print "------------------------------\n";

    # get raid controller health status
    open( HEALTHCK, "/usr/sbin/osa/healthck $dev |" );
    while( $line = <HEALTHCK> ) {
      chop( $line );
      if ( ! ( $line =~ /^healthck/ ) ) {
	print "$line\n";
      }
    }
    close( HEALTHCK );

    # get raid controller drive info
    open( DRIVUTIL, "/usr/sbin/osa/drivutil -d $dev |" );
        while( $line = <DRIVUTIL> ) {
      chop( $line );
      if ( ! ( $line =~ /^drivutil/ ) ) {
	print "$line\n";
      }
    }
    close( DRIVUTIL );

    # display independant controller info
    open( STORVUTIL, "/usr/sbin/osa/storutil -c $dev -d |" );
    while( $line = <STORUTIL> ) {
      chop( $line );
      if ( ! ( $line =~ /^storutil/ ) ) {
	print "$line\n";
      }
    }
    close( STORUTIL );

    # display lun info
    open( RAIDUTIL, "/usr/sbin/osa/raidutil -c $dev -i |" );
    while( $line = <RAIDUTIL> ) {
      chop( $line );
      if ( ! ( $line =~ /^raidutil/ ) ) {
	print "$line\n";
      }
    }
    close( RAIDUTIL );
  }
  return $TRUE;
}

#
# has netgroups
#
sub has_netgroups {
  my $line;

  open( NSSWITCH, "/etc/nsswitch.conf" );

  while( $line = <NSSWITCH> ) {
    chop( $line );
    if ( $line =~ /^passwd\:.*compat.*/ ) {
      return $TRUE;
    }
  }

  close( NSSWITCH );

  return $FALSE;
}

#
# display netgroups
#
sub show_netgroups {
  my $line;

  open( PASSWD, "/etc/passwd" );

  while( $line = <PASSWD> ) {
    chop( $line );
    if ( $line =~ /^\+\@/ ) {
      print "$line\n";
    }
  }

  close( PASSWD );

  return $TRUE;
}

#
# has tcp_wrappers
#
sub has_tcp_wrappers {
  if ( -f "/etc/hosts.allow" && -f "/etc/hosts.deny" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# display hosts.allow/hosts.deny
#
sub show_tcp_wrappers {
  my $line;

  if ( open( CFGFILE, "/etc/hosts.allow" ) != $TRUE ) {
    return $FAILED;
  }

  print "hosts.allow:\n";
  print "\n";
  while ( $line = <CFGFILE> ) {
    chomp( $line );
    print "$line\n";
  }
  close( CFGFILE );
  print "\n";

  if ( open( CFGFILE, "/etc/hosts.deny" ) != $TRUE ) {
    return $FAILED;
  }  
  print "hosts.deny:\n";
  print "\n";
  while ( $line = <CFGFILE> ) {
    chomp( $line );
    print "$line\n";
  }
  close( CFGFILE );
  print "\n";

  return $TRUE;
}

#
# test for multiple instructionset support
#
sub has_isainfo {
  if ( -e "/bin/isainfo" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# display instructionset support information
#
sub show_isainfo {
  my $line;

  open( ISAINFO, "/bin/isainfo -v |" );

  while( $line = <ISAINFO> ) {
    chop( $line );
    print "$line\n";
  }

  close( ISAINFO );
}

#
# test for dns
#
sub has_dns {
  if ( -e "/etc/named.boot" || -e "/etc/named.conf" ) {
    return $TRUE;
  }
  
  return $FALSE;
}

#
# display dns information
#
sub show_dns {
  my $line;

  if ( -e "/etc/named.boot" ) {
    # bind 4.x
    open( CONFIG, "/etc/named.boot" );
    while( $line = <CONFIG> ) {
      $line =~ s/\;.*//g;
      $line =~ s/^\s+//g;
      chomp( $line );
      if ( $line ne "" ) {
	print "$line\n";
      }
    }
    close( CONFIG );
  } else {
    #bind 8.x
    open( CONFIG, "/etc/named.conf" );
    while( $line = <CONFIG> ) {
      $line =~ s/\;.*//g;
      $line =~ s/^\s+//g;
      chomp( $line );
      if ( $line ne "" ) {
	print "$line\n";
      }
    }
    close( CONFIG );
  }

  print "\n";

  return $TRUE;
}

#
# test for nis+
#
sub has_nisplus {
  if ( -d "/var/nis/data" ) {
    return $TRUE;
  }

  return $FALSE;
}

#
# display nis+ information
#
sub show_nisplus {
  my $line;
  my @tmp;
  my $dir;

  $dir = $domainname;

  open( NISDIR, "/bin/nisls -lR $dir |" );

  while( chop( $line = <NISDIR> ) ) {
    @tmp = split( / +/, $line );

    if ( index( $tmp[0], "$domianname\.\:" ) >= 0 ) {
      chop( $dir = $tmp[0] );
      print "\n$dir\n";
    } elsif ( $tmp[0] ne "" ) {
      $nisobjects{"$tmp[8]\.$dir"} = substr( $tmp[0], 0, 1 );
      print "\t" . substr( $tmp[0], 0, 1 ) . " $tmp[8]\n";
    }
  }

  close( NISDIR );

  return $TRUE;
}

### ~/Projects/Perl/Modules/safe_system.pl
#
# @(#)safe_system.pl	1.2 [02/01/00 - 12:02:55]
#
#  author: ron dilley
#    desc: this perl function does a system call with
#          extended error checks
#
#    type: function
#    args: $command
# returns: $TRUE on no error, $FAILED on error
#   notes: Requires $Config{'debug'} to enable/disable verbose messages
#
############################################################################

sub safe_system {
  my( $command ) = @_;
  my( $ret );

  if ( ( $ret = ( 0xffff & system( $command ) ) ) != $FALSE ) {
    if ( $ret == 0xff00 ) {
      if ( $Config{'debug'} ) {
	print "DEBUG - Unable to execute command \[$!\]\n";
      }
    } elsif ( $ret > 0x80 ) {
      if ( $Config{'debug'} ) {
	$ret >>= 8;
	print "DEBUG - Command returned non-zero exit status \[$ret\]\n";
      }
    } else {
      if ( $Config{'debug'} ) {
	if ( $ret & 0x80 ) {
	  $ret &= ~0x80;
	  print "DEBUG - Command coredumped\n";
	}
	print "DEBUG - Command received signal \[$ret\]\n";
      }
    }
    return $FAILED;
  }

  return $TRUE;
}

#
### ~/Projects/Perl/Modules/safe_system.pl
