From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,bcf8115704584248 X-Google-Attributes: gidfee84,public From: klaus@axp4.physik.fu-berlin.de (Wolfram Klaus) Subject: Re: Non root access to CD-ROM Date: 1997/02/04 Message-ID: #1/1 X-Deja-AN: 214331309 references: organization: Freie Universitaet Berlin x-access: 16 17 19 newsgroups: comp.unix.osf.osf1 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 ************************************************************************* ************ Linux ... the choice of a GNU generation ******************* *************************************************************************