home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / SUSER.PL < prev    next >
Text File  |  1995-04-11  |  733b  |  33 lines

  1. #
  2. # Find if these commands would all run with root privileges.
  3. #
  4.  
  5. sub suser {
  6.     local(@path) = @_;
  7.     local($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks);
  8.  
  9.     while ($> != 0 && $#path >= $[) {
  10.         if ((($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat(@path[0])) == 0) {
  11.             return(0);
  12.         } elsif ($uid != 0 || ($mode & 04000) == 0) {
  13.             return(0);
  14.         }
  15.         shift @path;
  16.     }
  17.     return(1);
  18. }
  19.  
  20. #
  21. # Stand-alone mode
  22. #
  23. if ($running_under_satan == 0) {
  24.  
  25.     warn 'suser.pl running in stand-alone mode';
  26.  
  27.     die "usage $0 file\n" unless $#ARGV == 0;
  28.  
  29.     print &suser($ARGV[0]) ? "Root privileged\n" : "Unprivileged\n";
  30. }
  31.  
  32. 1;
  33.