Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: lombardi emanuele <lele@mantegna.casaccia.enea.it>
Subject: Re: Allowing all users to mount CD ROM drive
Date: 1998/06/01	[thread overview]
Message-ID: <357272B4.41C6@mantegna.casaccia.enea.it> (raw)
In-Reply-To: 356d7246.174897098@news.gov.on.ca


here follows a small C program wich allows normal users
to mount CDs:

Emanuele

-- 
 Emanuele Lombardi
 mail:  AMB-GEM-CLIM ENEA Casaccia
        I-00060 S.M. di Galeria (RM) 
        ITALY
 mailto:lele@mantegna.casaccia.enea.it
 tel	+39 6 30483366
 fax	+39 6 30483591




/* 
monta.c
Program to allow users to mount CDROM without the need to be root.
Users can choose among a list of availabel devices (devs) the first
of which is the default one
See the section code referring the -h switch for the usage of monta.

don't forget to chmod 4555 the executeble!

by EMANUELE LOMBARDI lele@mantegna.casaccia.enea.it 
*/


#include <stdio.h>

main(argc,argv,en)
int argc;
char *argv[];
char *en[];
{
#define ARGS    "o:ud:h"
#define NDEVS   2
#define MAXNS   20

  char   *al[MAXNS] = NULL;
  char   *devs[NDEVS],*dev;
  int    umount,ns,i,c,okdev;
  extern int errno;

  setruid(0);

  devs[0]="/dev/rz5c";   /* default device*/
  devs[1]="/dev/gd0c";
  dev=devs[0];

  al[0] = "/usr/sbin/mount";
  al[1] = "-t";
  al[2] = "cdfs";
  al[3] = "-r" ;
  ns=4;

  umount=0;
  while (((c = getopt(argc, argv, ARGS)) != -1))
    switch (c) {
    case 'd':
      okdev=0;
      for (i=0;i<NDEVS;i++){
        if (strcmp(devs[i],optarg)==0) {dev=devs[i];okdev=1;}
      }
      if (okdev==0) {
        fprintf(stderr,"ERROR: device %s NOT available\n",optarg);
        for (i=0;i<NDEVS;i++){fprintf(stderr,"available:
%s\n",devs[i]);}
        exit(1);}
      break;
    case 'o':
      if (ns<MAXNS) {
        al[ns]="-o";ns++;al[ns]=optarg;ns++;} else {
          fprintf(stderr,"ERROR too many options!\n");    
          exit (1);}
        break;
    case 'u':
      umount=1;
      break;
    case 'h':
      fprintf(stderr,"MOUNTS/UMOUNTS CDrom (-t cdfs -r)\n"); 
      fprintf(stderr,"to mount:  %s [-d dev] [-o opts] ... [-o opts]
dir\n",argv[0]);
      fprintf(stderr,"to umount: %s [-d dev] -u\n",argv[0]);
      fprintf(stderr,"defaults:  dev=%s opts=NONE\n",dev);
      for (i=0;i<NDEVS;i++){fprintf(stderr,"available: %s\n",devs[i]);}
      exit (1);
      break;
    default :
    break;
    }
  if (umount==0) {
    al[ns]=dev;ns++;
    if (argc != optind) {al[ns]=argv[argc-1];} 
    else
      {al[ns] = "/cdrom";}
  } else {
    for (i=0;i<=10;i++){al[i]=NULL;}
    al[0]="/usr/sbin/umount";
    al[1]=dev;
    ns=1;}

  for (i=0;i<=ns;i++){fprintf(stderr,"%s ",al[i]);}
  fprintf(stderr,"\n");


  if (execve(al[0],al,en) != 0) {
    fprintf(stderr,"ERROR: errno=%d",errno);
    perror (" ");
    exit(1);
  }
}



  parent reply	other threads:[~1998-06-01  4:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-28  4:00 Allowing all users to mount CD ROM drive Frank Schnekenburger
1998-05-29  4:00 ` Paul Szabo
1998-06-01  4:00 ` lombardi emanuele [this message]
1998-06-01  4:00 ` Mark Taylor
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