home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2815 < prev    next >
Internet Message Format  |  1991-02-19  |  9KB

  1. From: maart@nat.vu.nl (Maarten Litmaath)
  2. Newsgroups: alt.sources
  3. Subject: patch to indir (2.3 --> 2.4)
  4. Message-ID: <1991Feb20.004917.5612@nat.vu.nl>
  5. Date: 19 Feb 91 23:49:17 GMT
  6.  
  7. I've sent these diffs to comp.sources.unix, but as that group has been
  8. rather quiet lately, posting them to alt.sources as well seems justified...
  9.  
  10. Included is a second minor patch to indir (from version 2.3 to 2.4).
  11. Version 2.3 did not support multiple groups (see getgroups(2)).
  12. The new version has this corrected.  Thanks to John M. Sellens
  13. <jmsellens@watdragon.uwaterloo.ca> (and Andy at the same site) for
  14. pointing it out.  He also mentioned that the Makefile and the test
  15. script assumed the installer had `.' in his PATH.  This has been
  16. fixed too.  Finally there are a few cosmetic changes to a few files.
  17.  
  18. To apply the patches below, in the directory containing the sources
  19. of indir 2.3 unpack the shell archive and type:
  20.  
  21.     patch < indir2.4diffs
  22.  
  23. Then check the file `README' and the Makefile.  Type `make' to create
  24. the new version of indir in the current directory.
  25.  
  26. Enjoy.
  27.  
  28. BTW, please note that my email address has changed.
  29.  
  30.                     Maarten Litmaath <maart@nat.vu.nl>
  31.                                 ^^^
  32.  
  33. : This is a shar archive.  Extract with sh, not csh.
  34. : This archive ends with exit, so do not worry about trailing junk.
  35. : --------------------------- cut here --------------------------
  36. PATH=/bin:/usr/bin:/usr/ucb
  37. echo Extracting 'indir2.4diffs'
  38. sed 's/^X//' > 'indir2.4diffs' << '+ END-OF-FILE ''indir2.4diffs'
  39. X*** old/Makefile    Sat Feb  2 07:19:48 1991
  40. X--- Makefile    Sat Feb  2 07:23:38 1991
  41. X***************
  42. X*** 5,11 ****
  43. X  # a few defines for testing purposes; if you test in the current
  44. X  # directory the paths needn't be absolute
  45. X  # the path of indir will be used in #! lines -> max. 32 characters for
  46. X! # #! + name + mandatory option
  47. X  PATH_OF_INDIR    = ./indir
  48. X  TEST_DIRECTORY    = .
  49. X  
  50. X--- 5,11 ----
  51. X  # a few defines for testing purposes; if you test in the current
  52. X  # directory the paths needn't be absolute
  53. X  # the path of indir will be used in #! lines -> max. 32 characters for
  54. X! # #! + name + space (or tab) + mandatory option
  55. X  PATH_OF_INDIR    = ./indir
  56. X  TEST_DIRECTORY    = .
  57. X  
  58. X***************
  59. X*** 21,32 ****
  60. X          $(CC) -O -o indir $(OBJS)
  61. X  
  62. X  exec_ok:
  63. X!         exec_test
  64. X  
  65. X  test:        exec_ok
  66. X          test -f tests_made || PATH_OF_INDIR=$(PATH_OF_INDIR) \
  67. X!             TEST_DIRECTORY=$(TEST_DIRECTORY) make_tests
  68. X!         do_tests
  69. X  
  70. X  lint:
  71. X          lint $(SRCS)
  72. X--- 21,32 ----
  73. X          $(CC) -O -o indir $(OBJS)
  74. X  
  75. X  exec_ok:
  76. X!         ./exec_test
  77. X  
  78. X  test:        exec_ok
  79. X          test -f tests_made || PATH_OF_INDIR=$(PATH_OF_INDIR) \
  80. X!             TEST_DIRECTORY=$(TEST_DIRECTORY) ./make_tests
  81. X!         ./do_tests
  82. X  
  83. X  lint:
  84. X          lint $(SRCS)
  85. X*** old/do_tests    Sat Feb  2 07:18:58 1991
  86. X--- do_tests    Sat Feb  2 07:23:38 1991
  87. X***************
  88. X*** 1,15 ****
  89. X  #!/bin/sh
  90. X  for i in wrong.* ok.*
  91. X  do
  92. X!     echo '' >&2
  93. X!     echo "$ ls -l $i" >&2
  94. X!     ls -l $i >&2
  95. X!     echo "$ cat $i" >&2
  96. X!     cat $i >&2
  97. X!     echo $
  98. X!     echo -n "-- hit return to run $i: " >&2
  99. X      read x
  100. X!     $i file_argument
  101. X!     echo -n "-- hit return to continue: " >&2
  102. X      read x
  103. X  done
  104. X--- 1,18 ----
  105. X  #!/bin/sh
  106. X+ 
  107. X  for i in wrong.* ok.*
  108. X  do
  109. X!     echo ''
  110. X!     echo "$ ls -l $i"
  111. X!     ls -l $i
  112. X!     echo "$ cat $i"
  113. X!     cat $i
  114. X!     echo "$ "
  115. X!     echo -n "-- hit return to run $i: "
  116. X      read x
  117. X!     ./$i file_argument
  118. X!     echo -n "-- hit return to continue: "
  119. X      read x
  120. X  done
  121. X+ 
  122. X+ exit 0
  123. X*** old/indir.c    Sat Feb  2 07:19:48 1991
  124. X--- indir.c    Sat Feb  2 07:23:38 1991
  125. X***************
  126. X*** 1,4 ****
  127. X! static    char    sccsid[] = "@(#)indir.c 2.3 90/03/31 Maarten Litmaath";
  128. X  
  129. X  /*
  130. X   * indir.c
  131. X--- 1,5 ----
  132. X! static    char    sccsid[] =
  133. X!     "@(#)indir.c 2.4 91/02/02 Maarten Litmaath @ CS, VU, Amsterdam";
  134. X  
  135. X  /*
  136. X   * indir.c
  137. X***************
  138. X*** 145,150 ****
  139. X--- 146,152 ----
  140. X          execvp(Interpreter, Newargv);
  141. X  
  142. X      error(E_exec, Prog, Interpreter, File, geterr());
  143. X+     /* NOTREACHED */
  144. X  }
  145. X  
  146. X  
  147. X***************
  148. X*** 270,276 ****
  149. X  char    *f;
  150. X  {
  151. X      struct    stat    stbuf;
  152. X!     int    xmask, pid;
  153. X      uid_t    uid;
  154. X      gid_t    gid;
  155. X      static    int    status = -1, checked = 0;
  156. X--- 272,278 ----
  157. X  char    *f;
  158. X  {
  159. X      struct    stat    stbuf;
  160. X!     int    xmask, pid, groups_member();
  161. X      uid_t    uid;
  162. X      gid_t    gid;
  163. X      static    int    status = -1, checked = 0;
  164. X***************
  165. X*** 301,308 ****
  166. X      gid = Gid_check ? getgid() : getegid();
  167. X  
  168. X      xmask = (Uid == 0) ? (X_USR | X_GRP | X_OTH) :
  169. X!         st->st_uid == uid ? X_USR :
  170. X!         st->st_gid == gid ? X_GRP :
  171. X          X_OTH;
  172. X      /*
  173. X       * Can the invoker really execute the file we're reading from?
  174. X--- 303,311 ----
  175. X      gid = Gid_check ? getgid() : getegid();
  176. X  
  177. X      xmask = (Uid == 0) ? (X_USR | X_GRP | X_OTH) :
  178. X!         (st->st_uid == uid) ? X_USR :
  179. X!         (st->st_gid == gid) ? X_GRP :
  180. X!         groups_member(st->st_gid) ? X_GRP :
  181. X          X_OTH;
  182. X      /*
  183. X       * Can the invoker really execute the file we're reading from?
  184. X***************
  185. X*** 330,335 ****
  186. X--- 333,355 ----
  187. X      while (wait(&w) != pid)
  188. X          ;
  189. X      return ok(w) ? status = 0 : -1;
  190. X+ }
  191. X+ 
  192. X+ 
  193. X+ static    int    groups_member(gid)
  194. X+ int    gid;
  195. X+ {
  196. X+     register
  197. X+     int    *p, ngroups;
  198. X+     int    groups[NGROUPS];
  199. X+ 
  200. X+     if ((ngroups = getgroups(NGROUPS, groups)) < 0)
  201. X+         return 0;
  202. X+     p = groups;
  203. X+         while (--ngroups >= 0)
  204. X+         if (*p++ == gid)
  205. X+             return 1;
  206. X+     return 0;
  207. X  }
  208. X  
  209. X  
  210. X*** old/setuid.txt    Sat Feb  2 07:19:49 1991
  211. X--- setuid.txt    Sat Feb  2 07:23:38 1991
  212. X***************
  213. X*** 1,6 ****
  214. X--- 1,7 ----
  215. X              Setuid Shell Scripts
  216. X              --------------------
  217. X              how to get them safe
  218. X+                  version 1.1
  219. X  
  220. X                Maarten Litmaath
  221. X                (maart@cs.vu.nl)
  222. X***************
  223. X*** 42,54 ****
  224. X  Yes, one needs write permission somewhere on the same device, if one's
  225. X  operating system doesn't support symbolic links.
  226. X  
  227. X! What about the csh command interpreter? Well, 4.2BSD provides us with a csh
  228. X! which has a NEW option: "-b"! Its goal is to avoid just the thing described
  229. X! above: the mnemonic for `b' is `break'; this option prevents following
  230. X! arguments of an exec of /bin/csh from being interpreted as options...
  231. X! The csh refuses to run a setuid shell script unless the option is present...
  232. X  Scheme:
  233. X!     #!/bin/csh -b
  234. X      ...
  235. X  
  236. X      execl("-i", "unimportant", (char *) 0);
  237. X--- 43,54 ----
  238. X  Yes, one needs write permission somewhere on the same device, if one's
  239. X  operating system doesn't support symbolic links.
  240. X  
  241. X! What about the bare `-' option present in modern versions of the Bourne
  242. X! shell?  Its goal is to avoid just the thing described above: this option
  243. X! prevents following arguments of an exec of /bin/sh from being interpreted
  244. X! as options...
  245. X  Scheme:
  246. X!     #!/bin/sh -
  247. X      ...
  248. X  
  249. X      execl("-i", "unimportant", (char *) 0);
  250. X***************
  251. X*** 58,64 ****
  252. X  
  253. X      setuid(0);
  254. X      setgid(0);
  255. X!     execl("/bin/csh", "csh", "-b", "-i", (char *) 0);
  256. X  
  257. X  And indeed the contents of the file "-i" are executed!
  258. X  However, there's still another bug hidden, albeit not for long!
  259. X--- 58,64 ----
  260. X  
  261. X      setuid(0);
  262. X      setgid(0);
  263. X!     execl("/bin/sh", "sh", "-", "-i", (char *) 0);
  264. X  
  265. X  And indeed the contents of the file "-i" are executed!
  266. X  However, there's still another bug hidden, albeit not for long!
  267. X***************
  268. X*** 82,95 ****
  269. X      currently the total length of shell + argument mustn't exceed 32 chars
  270. X      (easily fixed);
  271. X  2)
  272. X!     4.[23]BSD csh is expecting a `-b' flag as the first argument, instead
  273. X!     of the full path (easily fixed);
  274. X  3)
  275. X      the interpreter gets an extra argument;
  276. X  4)
  277. X      the difficulty of maintaining setuid shell scripts increases - if one
  278. X      moves a script, one shouldn't forget to edit it... - editing in turn
  279. X!     could turn off the setuid bits, so one shouldn't forget to chmod(1)
  280. X      the file `back'... - conceptually the solution above isn't `elegant'.
  281. X  
  282. X  How does indir(1) tackle the problems? The script to be executed will look
  283. X--- 82,95 ----
  284. X      currently the total length of shell + argument mustn't exceed 32 chars
  285. X      (easily fixed);
  286. X  2)
  287. X!     when executing a setuid script, 4.[23]BSD csh is expecting a `-b' flag
  288. X!     as the first argument, instead of the full path (easily fixed);
  289. X  3)
  290. X      the interpreter gets an extra argument;
  291. X  4)
  292. X      the difficulty of maintaining setuid shell scripts increases - if one
  293. X      moves a script, one shouldn't forget to edit it... - editing in turn
  294. X!     could turn off the setuid bit, so one shouldn't forget to chmod(1)
  295. X      the file `back'... - conceptually the solution above isn't `elegant'.
  296. X  
  297. X  How does indir(1) tackle the problems? The script to be executed will look
  298. + END-OF-FILE indir2.4diffs
  299. chmod 'u=rw,g=r,o=r' 'indir2.4diffs'
  300. set `wc -c 'indir2.4diffs'`
  301. count=$1
  302. case $count in
  303. 6805)    :;;
  304. *)    echo 'Bad character count in ''indir2.4diffs' >&2
  305.         echo 'Count should be 6805' >&2
  306. esac
  307. exit 0
  308.