home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume22 / cdmount2 / part01 next >
Encoding:
Text File  |  1991-08-21  |  13.0 KB  |  405 lines

  1. Newsgroups: comp.sources.misc
  2. From: Kent Landfield <kent@sparky.imd.sterling.com>
  3. Subject:  v22i030:  cdmount2 - Giving general users access to CDROM, Part01/01
  4. Message-ID: <1991Aug20.051242.29798@sparky.IMD.Sterling.COM>
  5. Date: Tue, 20 Aug 1991 05:12:42 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Md4-Signature: e43011514499eee8d6a959da50c643a3
  8.  
  9. Submitted-by: Kent Landfield <kent@sparky.imd.sterling.com>
  10. Posting-number: Volume 22, Issue 30
  11. Archive-name: cdmount2/part01
  12. Environment: SUN, CDROM
  13. Supersedes: cdmount: Volume 22, Issue 28
  14.  
  15. Boy when I want to be dumb... This is an updated version of the cdmount
  16. utilities with a few 747 sized security holes fixed.  The following 
  17. changes were made in this version.
  18.  
  19. - Made the nosuid option mandatory,
  20. - Enforced a standard PATH.  mount will do, as root, an 
  21.   execlp("mount_hsfs"), and a user can cause his own version 
  22.   of mount_hsfs to be run.
  23. - Restrict the directories the disk can be mounted on to /cdrom.  
  24.   It would be dangerous to let people mount filesystems on /etc 
  25.   or /usr/bin, for instance.
  26.  
  27. If you are using cdmount, *please* replace it with this much more 
  28. secure version.  The idea was to not give away the store... :-)
  29. It is truly amazing how much trouble a person can generate over
  30. a lunch hour...
  31.  
  32.  -Kent+
  33. ---
  34. #! /bin/sh
  35. # into a shell via "sh file" or similar.  To overwrite existing files,
  36. # type "sh file -c".
  37. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  38. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  39. # Contents:  README Makefile cdmount.1 cdmount.c cdumount.1
  40. # Wrapped by kent@sparky on Mon Aug 19 23:46:23 1991
  41. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  42. echo If this archive is complete, you will see the following message:
  43. echo '          "shar: End of archive 1 (of 1)."'
  44. if test -f 'README' -a "${1}" != "-c" ; then 
  45.   echo shar: Will not clobber existing file \"'README'\"
  46. else
  47.   echo shar: Extracting \"'README'\" \(1186 characters\)
  48.   sed "s/^X//" >'README' <<'END_OF_FILE'
  49. XThis directory contains sources for the administrator to allow general
  50. Xusers to mount and access CD-ROMs without having to know the root
  51. Xpassword.  Mount is limited to root so the cdmount and cdumount commands
  52. Xare needed to insure greater usability of the cdplayers and better overall
  53. Xsecurity. 
  54. X
  55. XThis software is Copyright (c) 1991 by Kent Landfield.
  56. X
  57. XPermission is hereby granted to copy, distribute or otherwise
  58. Xuse any part of this package as long as you do not try to make
  59. Xmoney from it or pretend that you wrote it.  This copyright
  60. Xnotice must be maintained in any copy made.
  61. X
  62. XUse of this software constitutes acceptance for use in an AS IS
  63. Xcondition. There are NO warranties with regard to this software.
  64. XIn no event shall the author be liable for any damages whatsoever
  65. Xarising out of or in connection with the use or performance of this
  66. Xsoftware.  Any use of this software is at the user's own risk.
  67. X
  68. X If you make modifications to this software that you feel
  69. X increases it usefulness for the rest of the community, please
  70. X email the changes, enhancements, bug fixes as well as any and
  71. X all ideas to me.
  72. X
  73. X             Kent Landfield
  74. X             kent@sparky.imd.sterling.com
  75. X
  76. END_OF_FILE
  77.   if test 1186 -ne `wc -c <'README'`; then
  78.     echo shar: \"'README'\" unpacked with wrong size!
  79.   fi
  80.   # end of 'README'
  81. fi
  82. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  83.   echo shar: Will not clobber existing file \"'Makefile'\"
  84. else
  85.   echo shar: Extracting \"'Makefile'\" \(1938 characters\)
  86.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  87. X##########################################################
  88. X#
  89. X#       @(#)Makefile    1.1 8/17/91 - CDmount
  90. X#
  91. X# This software is Copyright (c) 1991 by Kent Landfield.
  92. X#
  93. X# Permission is hereby granted to copy, distribute or otherwise
  94. X# use any part of this package as long as you do not try to make
  95. X# money from it or pretend that you wrote it.  This copyright
  96. X# notice must be maintained in any copy made.
  97. X#
  98. X# Use of this software constitutes acceptance for use in an AS IS
  99. X# condition. There are NO warranties with regard to this software.
  100. X# In no event shall the author be liable for any damages whatsoever
  101. X# arising out of or in connection with the use or performance of this
  102. X# software.  Any use of this software is at the user's own risk.
  103. X#
  104. X#  If you make modifications to this software that you feel
  105. X#  increases it usefulness for the rest of the community, please
  106. X#  email the changes, enhancements, bug fixes as well as any and
  107. X#  all ideas to me. This software is going to be maintained and
  108. X#  enhanced as deemed necessary by the community.
  109. X#
  110. X#               Kent Landfield
  111. X#               sparky!kent
  112. X#               kent@sparky.imd.sterling.com
  113. X#
  114. X##########################################################
  115. X
  116. XDESTDIR=/usr/local/bin
  117. XMANDIR=/usr/man/manl
  118. X
  119. Xall: cdmount cdumount 
  120. X
  121. Xcdmount: 
  122. X    $(CC) $(CFLAGS) -o cdmount cdmount.c 
  123. X
  124. Xcdumount: cdmount.c
  125. X    chown root cdmount
  126. X    chgrp bin cdmount
  127. X    chmod u+s cdmount
  128. X    rm -f cdumount
  129. X    ln cdmount cdumount
  130. X
  131. Xinstall: all
  132. X    @echo "install according to local conventions"
  133. X    install -c -s -o root -g bin -m 6755 cdmount $(DESTDIR)
  134. X    rm -f $(DESTDIR)/cdumount
  135. X    ln $(DESTDIR)/cdmount $(DESTDIR)/cdumount
  136. X    install -c -o bin -g bin -m 0644 cdmount.1 $(MANDIR)/cdmount.l
  137. X    install -c -o bin -g bin -m 0644 cdumount.1 $(MANDIR)/cdumount.l
  138. X    
  139. Xclean:
  140. X    rm -f cdmount cdumount
  141. X
  142. Xprint:
  143. X    cprint Makefile | lpr -Plw
  144. X    cprint README | lpr -Plw
  145. X    cprint cdmount.c | lpr -Plw
  146. X    psroff -man cdmount.1
  147. X    psroff -man cdumount.1
  148. END_OF_FILE
  149.   if test 1938 -ne `wc -c <'Makefile'`; then
  150.     echo shar: \"'Makefile'\" unpacked with wrong size!
  151.   fi
  152.   # end of 'Makefile'
  153. fi
  154. if test -f 'cdmount.1' -a "${1}" != "-c" ; then 
  155.   echo shar: Will not clobber existing file \"'cdmount.1'\"
  156. else
  157.   echo shar: Extracting \"'cdmount.1'\" \(702 characters\)
  158.   sed "s/^X//" >'cdmount.1' <<'END_OF_FILE'
  159. X'br "@(#)cdmount.1    1.2 8/19/91"
  160. X.TH CDMOUNT 1 LOCAL
  161. X.SH NAME
  162. Xcdmount  \- Mount a CD-ROM without being superuser
  163. X.SH SYNOPSIS
  164. X.B cdmount
  165. X[
  166. X.B \-dhv
  167. X]
  168. X.SH DESCRIPTION
  169. X.I cdmount
  170. Xallows a user who is not the superuser to mount a CD-ROM.  The 
  171. XCD is mounted on the directory /cdrom.  The mount point /cdrom
  172. Xmust be a directory and not a symbolic link to a directory. The 
  173. XCD is mounted as readonly so the user cannot write to the CD.
  174. X.SH OPTIONS
  175. X.IP "-d" 6
  176. XDebugging, shows the mount command without executing it.
  177. X.IP "-h"
  178. XMount an ISO 9660 Standard or High Sierra Standard CD_ROM Filesystem.
  179. X.IP "-v"
  180. X.SH AUTHOR
  181. XKent Landfield <kent@sparky.imd.sterling.com>
  182. X.SH "SEE ALSO"
  183. Xcdumount(1), fstab(5), mount(8)
  184. END_OF_FILE
  185.   if test 702 -ne `wc -c <'cdmount.1'`; then
  186.     echo shar: \"'cdmount.1'\" unpacked with wrong size!
  187.   fi
  188.   # end of 'cdmount.1'
  189. fi
  190. if test -f 'cdmount.c' -a "${1}" != "-c" ; then 
  191.   echo shar: Will not clobber existing file \"'cdmount.c'\"
  192. else
  193.   echo shar: Extracting \"'cdmount.c'\" \(4539 characters\)
  194.   sed "s/^X//" >'cdmount.c' <<'END_OF_FILE'
  195. X/*
  196. X**  Subsystem:   User Level mount for CD-ROM
  197. X**  File Name:   cdmount.c
  198. X**                                                        
  199. X** This software is Copyright (c) 1991 by Kent Landfield.
  200. X**
  201. X** Permission is hereby granted to copy, distribute or otherwise 
  202. X** use any part of this package as long as you do not try to make 
  203. X** money from it or pretend that you wrote it.  This copyright 
  204. X** notice must be maintained in any copy made.
  205. X**
  206. X** Use of this software constitutes acceptance for use in an AS IS 
  207. X** condition. There are NO warranties with regard to this software.  
  208. X** In no event shall the author be liable for any damages whatsoever 
  209. X** arising out of or in connection with the use or performance of this 
  210. X** software.  Any use of this software is at the user's own risk.
  211. X**
  212. X**  If you make modifications to this software that you feel 
  213. X**  increases it usefulness for the rest of the community, please 
  214. X**  email the changes, enhancements, bug fixes as well as any and 
  215. X**  all ideas to me. This software is going to be maintained and 
  216. X**  enhanced as deemed necessary by the community.
  217. X**              
  218. X**              Kent Landfield
  219. X**              sparky!kent
  220. X**              kent@sparky.imd.sterling.com
  221. X*/
  222. X#if !defined(lint) && !defined(SABER)
  223. Xstatic char SID[] = "@(#)cdmount.c    1.2 8/19/91";
  224. X#endif
  225. X
  226. X#include <stdio.h>
  227. X#include <sys/types.h>
  228. X#include <sys/stat.h>
  229. X
  230. X#define MNTPOINT "/cdrom"
  231. X
  232. Xvoid usage(progname)
  233. Xchar *progname;
  234. X{
  235. X    (void) fprintf(stderr, "\nusage: %s [ -dhv ]\
  236. X\n\noptions:\n\
  237. X      -d   show the mount command without executing it\n\
  238. X      -h   mount an ISO 9660 or High Sierra CD_ROM Filesystem\n\
  239. X      -v   show the mount command and execute it\n\
  240. X\n", progname);
  241. X}
  242. X
  243. Xint main(argc, argv)
  244. Xint argc;
  245. Xchar **argv;
  246. X{
  247. X    int getopt();
  248. X    char *strrchr();
  249. X
  250. X    extern char *optarg;
  251. X    extern int optind;
  252. X    extern int opterr;
  253. X
  254. X    char *cp;
  255. X    char cmd[256];
  256. X    int rc;
  257. X    int debug;
  258. X    int iso9660;
  259. X    struct stat stb;
  260. X
  261. X    if ((cp = strrchr(argv[0],'/')) != NULL)
  262. X        ++cp;
  263. X    else 
  264. X        cp = argv[0];
  265. X
  266. X    /*
  267. X    ** Setup IFS for system() protection...
  268. X    */
  269. X    if (putenv("IFS= \t\n") != 0) {
  270. X         (void) fprintf(stderr,"%s: IFS putenv failed...\n", cp);
  271. X         return(1);
  272. X    }
  273. X
  274. X    /*
  275. X    ** Setup PATH for execlp() protection...
  276. X    */
  277. X    if (putenv("PATH=/etc:/usr/etc:/bin:/usr/bin") != 0) {
  278. X         (void) fprintf(stderr,"%s: PATH putenv failed...\n", cp);
  279. X         return(1);
  280. X    }
  281. X
  282. X    /*
  283. X    ** If the user is requesting to mount a CD..
  284. X    */
  285. X    if (strcmp(cp, "cdmount") == 0) {
  286. X        iso9660 = 0;
  287. X        opterr = 0;
  288. X        debug = 0;
  289. X        /*
  290. X        ** Assure that the mount point is there and in a 
  291. X        ** directory and not a symbolic link ..
  292. X        */
  293. X        if (lstat(MNTPOINT, &stb) != 0) {
  294. X            (void) fprintf(stderr, "%s: mount point missing\n", MNTPOINT);
  295. X            return(1);
  296. X        }
  297. X        if ((stb.st_mode & S_IFMT) != S_IFDIR) {
  298. X            (void) fprintf(stderr, "%s: invalid mount point\n", MNTPOINT);
  299. X            return(1);
  300. X        }
  301. X
  302. X        if (argc > 1) {
  303. X           while ((rc = getopt(argc, argv, "dhv")) != EOF) {
  304. X              switch (rc) {
  305. X                  case 'd':     /* debugging - does not run command. */
  306. X                      debug = 1;
  307. X                      break;
  308. X                  case 'v':     /* verbose - runs command. */
  309. X                      debug = 2;
  310. X                      break;
  311. X                  case 'h':
  312. X                      /*
  313. X                      ** mount an ISO 9660 Standard or High
  314. X                      ** Sierra Standard CD-ROM filesystem.
  315. X                      */
  316. X                      iso9660++;
  317. X                      break;
  318. X                  default:
  319. X                      usage(cp);
  320. X                      return(1);
  321. X              }
  322. X           }   
  323. X        }   
  324. X
  325. X        /* build the command line.. */
  326. X        
  327. X        (void) sprintf(cmd, "/etc/mount -r %s -o nosuid /dev/sr0 %s",
  328. X                       iso9660 ? "-t hsfs" : "", MNTPOINT);
  329. X        if (debug) 
  330. X            (void) fprintf(stderr, "%s\n", cmd);
  331. X        if (debug != 1)
  332. X            rc = system(cmd);
  333. X    }
  334. X
  335. X    /*
  336. X    ** The user is requesting to dismount a CD...
  337. X    */
  338. X    else if (strcmp(cp, "cdumount") == 0) {
  339. X        rc = system("/etc/umount /dev/sr0 && /usr/bin/eject /dev/sr0 2>/dev/null");
  340. X    }
  341. X
  342. X    /*
  343. X    ** Improperly named/linked executables, I'm confused...
  344. X    */
  345. X    else {
  346. X        (void) fprintf(stderr, "%s: I don't know who I am... ? \n", cp);
  347. X        rc = 1;
  348. X    }
  349. X    return(rc >> 8);
  350. X}
  351. END_OF_FILE
  352.   if test 4539 -ne `wc -c <'cdmount.c'`; then
  353.     echo shar: \"'cdmount.c'\" unpacked with wrong size!
  354.   fi
  355.   # end of 'cdmount.c'
  356. fi
  357. if test -f 'cdumount.1' -a "${1}" != "-c" ; then 
  358.   echo shar: Will not clobber existing file \"'cdumount.1'\"
  359. else
  360.   echo shar: Extracting \"'cdumount.1'\" \(388 characters\)
  361.   sed "s/^X//" >'cdumount.1' <<'END_OF_FILE'
  362. X'br "@(#)cdumount.1    1.1 8/17/91" 
  363. X.TH CDUMOUNT 1 LOCAL
  364. X.SH NAME
  365. Xcdumount  \- Unount a CD-ROM without being superuser
  366. X.SH SYNOPSIS
  367. X.B cdumount
  368. X.SH DESCRIPTION
  369. X.I cdumount
  370. Xallows a user who is not the superuser to unmount a CD-ROM.  The CD is
  371. Xejected after it is successfully unmounted.
  372. X.SH AUTHOR
  373. XKent Landfield <kent@sparky.imd.sterling.com>
  374. X.SH "SEE ALSO"
  375. Xcdmount(1), fstab(5), mount(8)
  376. END_OF_FILE
  377.   if test 388 -ne `wc -c <'cdumount.1'`; then
  378.     echo shar: \"'cdumount.1'\" unpacked with wrong size!
  379.   fi
  380.   # end of 'cdumount.1'
  381. fi
  382. echo shar: End of archive 1 \(of 1\).
  383. cp /dev/null ark1isdone
  384. MISSING=""
  385. for I in 1 ; do
  386.     if test ! -f ark${I}isdone ; then
  387.     MISSING="${MISSING} ${I}"
  388.     fi
  389. done
  390. if test "${MISSING}" = "" ; then
  391.     echo You have the archive.
  392.     rm -f ark[1-9]isdone
  393. else
  394.     echo You still must unpack the following archives:
  395.     echo "        " ${MISSING}
  396. fi
  397. exit 0
  398. exit 0 # Just in case...
  399. -- 
  400. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  401. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  402. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  403. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  404.