Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8 KiB

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