home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume25 / indirpch.4 < prev    next >
Encoding:
Text File  |  1991-12-13  |  8.4 KB  |  305 lines

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