home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / eg / wrapsuid < prev   
Text File  |  1994-10-18  |  3KB  |  105 lines

  1. #!/usr/bin/perl
  2. 'di';
  3. 'ig00';
  4. #
  5. # $Header: wrapsuid,v 1.1 90/08/11 13:51:29 lwall Locked $
  6. #
  7. # $Log:    wrapsuid,v $
  8. # Revision 1.1  90/08/11  13:51:29  lwall
  9. # Initial revision
  10.  
  11. $xdev = '-xdev' unless -d '/dev/iop';
  12.  
  13. if ($#ARGV >= 0) {
  14.     @list = @ARGV;
  15.     foreach $name (@ARGV) {
  16.     die "You must use absolute pathnames.\n" unless $name =~ m|^/|;
  17.     }
  18. }
  19. else {
  20.     open(DF,"/etc/mount|") || die "Can't run /etc/mount";
  21.  
  22.     while (<DF>) {
  23.     chop;
  24.     $_ .= <DF> if length($_) < 50;
  25.     @ary = split;
  26.     push(@list,$ary[2]) if ($ary[0] =~ m|^/dev|);
  27.     }
  28. }
  29. $fslist = join(' ',@list);
  30.  
  31. die "Can't find local filesystems" unless $fslist;
  32.  
  33. open(FIND,
  34.   "find $fslist $xdev -type f \\( -perm -04000 -o -perm -02000 \\) -print|");
  35.  
  36. while (<FIND>) {
  37.     chop;
  38.     next unless -T;
  39.     print "Fixing ", $_, "\n";
  40.     ($dir,$file) = m|(.*)/(.*)|;
  41.     chdir $dir || die "Can't chdir to $dir";
  42.     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  43.        $blksize,$blocks) = stat($file);
  44.        die "Can't stat $_" unless $ino;
  45.     chmod $mode & 01777, $file;        # wipe out set[ug]id bits
  46.     rename($file,".$file");
  47.     open(C,">.tmp$$.c") || die "Can't write C program for $_";
  48.     $real = "$dir/.$file";
  49.     print C '
  50. main(argc,argv)
  51. int argc;
  52. char **argv;
  53. {
  54.     execv("' . $real . '",argv);
  55. }
  56. ';
  57.     close C;
  58.     system '/bin/cc', ".tmp$$.c", '-o', $file;
  59.     die "Can't compile new $_" if $?;
  60.     chmod $mode, $file;
  61.     chown $uid, $gid, $file;
  62.     unlink ".tmp$$.c";
  63.     chdir '/';
  64. }
  65. ##############################################################################
  66.  
  67.     # These next few lines are legal in both Perl and nroff.
  68.  
  69. .00;            # finish .ig
  70.  
  71. 'di            \" finish diversion--previous line must be blank
  72. .nr nl 0-1        \" fake up transition to first page again
  73. .nr % 0            \" start at page 1
  74. '; __END__ ############# From here on it's a standard manual page ############
  75. .TH SUIDSCRIPT 1 "July 30, 1990"
  76. .AT 3
  77. .SH NAME
  78. wrapsuid \- puts a compiled C wrapper around a setuid or setgid script
  79. .SH SYNOPSIS
  80. .B wrapsuid [dirlist]
  81. .SH DESCRIPTION
  82. .I Wrapsuid
  83. creates a small C program to execute a script with setuid or setgid privileges
  84. without having to set the setuid or setgid bit on the script, which is
  85. a security problem on many machines.
  86. Specify the list of directories or files that you wish to process.
  87. The names must be absolute pathnames.
  88. With no arguments it will attempt to process all the local directories
  89. for this machine.
  90. The scripts to be processed must have the setuid or setgid bit set.
  91. The wrapsuid program will delete the bits and set them on the wrapper.
  92. .PP
  93. Non-superusers may only process their own files.
  94. .SH ENVIRONMENT
  95. No environment variables are used.
  96. .SH FILES
  97. None.
  98. .SH AUTHOR
  99. Larry Wall
  100. .SH "SEE ALSO"
  101. .SH DIAGNOSTICS
  102. .SH BUGS
  103. .ex
  104.