/* * Mounts on unmounts a ISO-9660 CD-ROM: essentially * mount -t cdfs -o noversion /dev/rz4c /cdrom * or * umount /cdrom * Does not take any arguments (so is safe) ... * * by Hugues Talbot 10 Jan 1996 * Modified PSz 12 Nov 96 * * Note possible problem report at V4.0D below. */ /* Man page (created by PSz on 11 Mar 97) * Put this into /usr/local/man/man1/cdmount.1 or similar. * ----- .TH cdmount 1 "" .ds n 5 .SH NAME \fBcdmount\fR, \fBcdumount\fR - mounts or unmounts a CD-ROM to /cdrom .SH SYNOPSIS \fBcdmount\fR .br \fBcdumount\fR .br .SH DESCRIPTION The \fBcdmount\fR command allows a (non-root) user to mount a CD-ROM on /cdrom. It finds the CD drive device, and works similarly to the command .PP \fBmount\fR -t cdfs -o noversion /dev/rz4c /cdrom .PP The options used by \fBcdmount\fR are appropriate to the most common CD-ROM disks, but they may not be suitable in all cases. Please see your system administrator if you your disk needs different options. .PP The \fBcdumount\fR command allows a (non-root) user to unmount a CD-ROM from /cdrom. It works similarly to the command .PP \fBumount\fR /cdrom .PP .SH SEE ALSO \fBmount\fR(8), \fBcdfs\fR(4) * ----- */ #include #include #include #include #include #include #define DIR "/cdrom" char *pgm; doerror( int res ) { if (errno == 0 && res != 0) errno = res; if (errno) { perror(pgm); } exit(errno); } main ( int argc, char *argv[] ) { int res; pgm = argv[0]; if ( argc != 1 ) { fprintf (stderr, "%s: No arguments allowed\n", pgm); exit(1); } if ( strcmp(pgm,"cdmount") == 0 ) { struct stat stdat; struct cdfs_args cddat; char *devs[] = { "/dev/rz4c", "/dev/rz5c", NULL }; char **devp, *dev; for ( devp = devs; *devp != NULL; devp++ ) { dev = *devp; /* printf("Trying device %s\n", dev); */ res = lstat(dev, &stdat); if ( res || errno ) { errno = 0; continue; } /* printf("st_rdev is %d = 0x%08x\n", stdat.st_rdev, stdat.st_rdev); */ /* * Device numbers are 0x0800002 + SCSI_ID * 0x0400 * How to tell a CD drive (as different from a disk)? * Use #include ; ioctl (fd, DEVGETINFO, ... )? */ if ( (stdat.st_rdev&0x0fff00ff) != 0x00800002 ) continue; /* printf("Using device %s\n", dev); */ cddat.fspec = dev; cddat.exflags = 0; cddat.exroot = 0; cddat.flags = M_NOVERSION /*| M_RRIP*/; cddat.version = 0; cddat.default_uid = 999; cddat.default_gid = 999; /* dummy user by default... */ cddat.default_fmode = 0555; cddat.default_dmode = 0555; cddat.map_uid_ct = 0; cddat.map_uid = NULL; cddat.map_gid_ct = 0; cddat.map_gid = NULL; printf ("Executing: mount -t cdfs -o noversion %s %s\n", dev, DIR); res = mount(MOUNT_CDFS, DIR, M_RDONLY | M_NOSUID | M_NODEV, &cddat); doerror(res); } fprintf (stderr, "%s: No CD-ROM device found\n", pgm); exit(1); } else if ( strcmp(pgm,"cdumount") == 0 ) { printf ("Executing: umount %s\n", DIR); res = umount(DIR, 0); doerror(res); } else { fprintf (stderr, "%s: Only cdmount or cdumount allowed\n", pgm); exit(1); } return errno; } /* Possible problem at V4.0D (with a solution) --- From - Wed May 20 13:55:56 1998 Newsgroups: comp.unix.osf.osf1 Path: metro!munnari.OZ.AU!news.ecn.ou.edu!news.ecn.uoknor.edu!news.eng.convex.com!cs.utexas.edu!utnut!utinfo!mark From: mark@cita.toronto.edu (Mark Bartelt) Subject: GACK! DU 4.0d mount() now looks at real (not effective) uid! X-Nntp-Posting-Host: rorqual.cita.utoronto.ca Message-ID: Sender: nntp@campus-news-reading.utoronto.ca (News) Reply-To: mark@cita.utoronto.ca Organization: Canadian Institute for Theoretical Astrophysics Date: Tue, 19 May 1998 18:03:41 GMT Lines: 45 Xref: metro comp.unix.osf.osf1:24234 OK, gang, here's yet another thing that works fine under all previous versions of Digital UNIX (up to and including 3.2c) but which fails under 4.0d + patchkit#1 ... People here have to read a lot of data off CDs, so instead of giving everyone the root password, or setting the suid bit on /usr/sbin/mount, we've been using a suid-root wrapper program, which does nothing more than an execl() to do ... mount -t cdfs -o ro,nosuid,rrip,noversion /dev/cd /cd Now, under 4.0d, when a non-root user attempts to do this, it fails, giving the following message: mount: Can't load cdfs module It's nothing weird about the wrapper program itself, though: If I make mount setuid-root (which I *don't* want to do, for the obvious reasons), and a non-root user tries mounting the CD by issuing the above "mount" command directly, that fails as well, in exactly the same way. The mount() manpage does say that Except for [execptions snipped] ... the calling process must have superuser privilege. However, it looks like something deep down inside the bowels of the kernel is now looking at the real uid, whereas prior to 4.0d it looked at the effective uid. I consider this a bug (if it's inadvertent) or else a serious misfeature (if it's intentional). Are there any DECfolks who might care to comment as to whether this change was supposed to have happened with 4.0d, or whether it was an accident? And, more important ... Other than giving everyone the root password, how (if at all) *can* we permit people to mount and unmount their own CDs under 4.0d? Mark Bartelt 416/978-5619 Canadian Institute for mark@cita.utoronto.ca Theoretical Astrophysics http://www.cita.utoronto.ca/~mark "Nur eine Waffel taugt!" -- Parsifal, in an Eggo commercial --- From - Wed May 20 13:56:13 1998 Path: metro!munnari.OZ.AU!news.ecn.ou.edu!news.ecn.uoknor.edu!feed1.news.erols.com!feed2.news.erols.com!erols!news.maxwell.syr.edu!scanner.worldgate.com!rover.ucs.ualberta.ca!news.ucalgary.ca!acs1.acs.ucalgary.ca!patchkov From: patchkov@acs1.acs.ucalgary.ca (Serguei Patchkovskii) Newsgroups: comp.unix.osf.osf1 Subject: Re: GACK! DU 4.0d mount() now looks at real (not effective) uid! Date: 19 May 1998 21:17:58 GMT Organization: The University of Calgary Lines: 11 Message-ID: <6jssu6$lls@ds2.acs.ucalgary.ca> References: NNTP-Posting-Host: patchkov@acs1.acs.ucalgary.ca X-Newsreader: TIN [version 1.2 PL2] Xref: metro comp.unix.osf.osf1:24238 Mark Bartelt (mark@cita.toronto.edu) wrote: : And, more important ... Other than giving everyone the root : password, how (if at all) *can* we permit people to mount and : unmount their own CDs under 4.0d? Why not insert setuid(geteuid()) ; setgid(getegid()) ; before calling execl? Assuming that you already clean up the environment (which you should do anyway), this will not be any more dangerous than it is now... /Serge.P --- */ /* And another posted solution... maybe I should also use statfs ? From: klaus@axp4.physik.fu-berlin.de (Wolfram Klaus) Newsgroups: comp.unix.osf.osf1 Subject: Re: Non root access to CD-ROM Date: 4 Feb 97 08:22:32 GMT Organization: Freie Universitaet Berlin Message-ID: References: Barney Dalton writes: >Hi, >Is there anyway for a non-root user to mount and read a CD_ROM under >digital unix 3.2. >thanks >barney Not directly. Since our users here wanted to be able to mount a cdrom without the sysop I wrote a little program that does the mount. It has to be installed as suid root, of course. It checks whether something is mounted on /cdrom (I now found out a much more direct way of testing this, but was too lazy to change the code. Basically it is about using getmntinfo instead of statfs). If nothing is mounted it mounts /dev/rz4c and writes the uid of the caller to a temporary file. A second call of the program by the same user will unmount the CDROM. If someone else calls the program while the CDROM is mounted he"ll be informed that user x is using the cdrom drive. Here is the code: --- #include #include #include #include #define FLAG M_RDONLY|M_NOSUID|M_NODEV|M_LOWERCASE|M_DROPVERS|M_RRIP #define UID_FILE "/tmp/cdrom.uid" main(int argc, char *argv[]) { FILE *uid; struct statfs stat; statfs( "/cdrom/.", &stat, sizeof(struct statfs) ); if (stat.f_type==MOUNT_CDFS) { uid=fopen(UID_FILE,"r"); if( uid!=NULL ) { uid_t mounted_id; fscanf(uid,"%d",&mounted_id); fclose(uid); if ( mounted_id==getuid() ) { if (0==umount("/cdrom",0)) { unlink(UID_FILE); printf("CDROM unmounted\n"); exit(-1); } else { perror(argv[0]); exit(-2); } } else { struct passwd *m_user=getpwuid(mounted_id); printf("CDROM currently used by %s\n", m_user->pw_name); exit(1); } } else { printf("CDROM currently used by root\n"); exit(1); } } else { struct cdfs_args data; data.fspec="/dev/rz4c"; data.flags=FLAG; if (0==mount(MOUNT_CDFS, "/cdrom", FLAG, (caddr_t) &data)) { uid=fopen(UID_FILE,"w"); fprintf(uid,"%d",getuid()); fclose(uid); printf("CDROM mounted on /cdrom\n"); exit(0); } else { perror(argv[0]); exit(2); } } } --- And here is something like a man page --- ..TH cdrom 1 "" ..ds n 5 ..SH NAME \fBcdrom\fR - mounts or unmounts ISO-cdrom to /cdrom ..SH SYNOPSIS \fBcdrom\fR ..br ..SH DESCRIPTION \fBcdrom\fR lets a user mount an ISO-cdrom on /cdrom. If the CDROM-drive is currently used by another user, you will be informed and no attempt to mount the CDROM will de made. To unmount the CDROM enter \fBcdrom\fR again. If the CDROM contains Rockridge extensions, these will be used. ..SH SEE ALSO \fBmount\fR(8), \fBcdfs\fR(4) ..\"# ..\"# The following sets edit modes for GNU EMACS ..\"# Local Variables: ..\"# mode:nroff ..\"# fill-column:79 ..\"# End: --- -- Wolfram Klaus (klaus@physik.fu-berlin.de) FU Berlin, FB Physik */