Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: klaus@axp4.physik.fu-berlin.de (Wolfram Klaus)
Subject: Re: Non root access to CD-ROM
Date: 1997/02/04	[thread overview]
Message-ID: <klaus.855044552@axp4.physik.fu-berlin.de> (raw)
In-Reply-To: Pine.OSF.3.95.970204110412.22916D-100000@cyllene.uwa.edu.au


Barney Dalton <barneyd@cyllene.uwa.edu.au> 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 <sys/mount.h>
#include <cdfs/cdfsmount.h>
#include <pwd.h>
#include <stdio.h>

#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 *******************
*************************************************************************



      reply	other threads:[~1997-02-04  5:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-04  5:00 Non root access to CD-ROM Barney Dalton
1997-02-04  5:00 ` Wolfram Klaus [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox