home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Subsystem: User Level mount for CD-ROM
- ** File Name: cdmount.c
- **
- ** This software is Copyright (c) 1991 by Kent Landfield.
- **
- ** Permission is hereby granted to copy, distribute or otherwise
- ** use any part of this package as long as you do not try to make
- ** money from it or pretend that you wrote it. This copyright
- ** notice must be maintained in any copy made.
- **
- ** Use of this software constitutes acceptance for use in an AS IS
- ** condition. There are NO warranties with regard to this software.
- ** In no event shall the author be liable for any damages whatsoever
- ** arising out of or in connection with the use or performance of this
- ** software. Any use of this software is at the user's own risk.
- **
- ** If you make modifications to this software that you feel
- ** increases it usefulness for the rest of the community, please
- ** email the changes, enhancements, bug fixes as well as any and
- ** all ideas to me. This software is going to be maintained and
- ** enhanced as deemed necessary by the community.
- **
- ** Kent Landfield
- ** sparky!kent
- ** kent@sparky.imd.sterling.com
- */
- #if !defined(lint) && !defined(SABER)
- static char SID[] = "@(#)cdmount.c 1.1 8/17/91";
- #endif
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- void usage(progname)
- char *progname;
- {
- (void) fprintf(stderr, "\nusage: %s [ -dhnv ] [ -m mountpoint ]\
- \n\noptions:\n\
- -d show the mount command without executing it\n\
- -h mount an ISO 9660 or High Sierra CD_ROM Filesystem\n\
- -n no setuid execution allowed\n\
- -v show the mount command and execute it\n\
- \n\
- -m mountpoint\n\
- mount the cd at another location than the default\n\
- location of /cdrom\n\
- \n", progname);
- }
-
- int main(argc, argv)
- int argc;
- char **argv;
- {
- int getopt();
- char *strrchr();
-
- extern char *optarg;
- extern int optind;
- extern int opterr;
-
- char *cp;
- char *mntpoint;
- char cmd[256];
- int rc;
- int debug;
- int nosuid;
- int iso9660;
- struct stat stb;
-
- if ((cp = strrchr(argv[0],'/')) != NULL)
- ++cp;
- else
- cp = argv[0];
-
- /*
- ** Setup IFS for system() protection...
- */
- if (putenv("IFS= \t\n") != 0) {
- (void) fprintf(stderr,"%s: putenv failed...\n", cp);
- return(1);
- }
-
- /*
- ** If the user is requesting to mount a CD..
- */
- if (strcmp(cp, "cdmount") == 0) {
- mntpoint = "/cdrom";
- nosuid = 0;
- iso9660 = 0;
- opterr = 0;
- debug = 0;
-
- if (argc > 1) {
- while ((rc = getopt(argc, argv, "dnhvm:")) != EOF) {
- switch (rc) {
- case 'd': /* debugging - does not run command. */
- debug = 1;
- break;
- case 'v': /* verbose - runs command. */
- debug = 2;
- break;
- case 'n':
- /*
- ** No setuid executables
- */
- nosuid++;
- break;
- case 'h':
- /*
- ** mount an ISO 9660 Standard or High
- ** Sierra Standard CD-ROM filesystem.
- */
- iso9660++;
- break;
- case 'm':
- /*
- ** get the optional mount point with
- ** minimual checking for sanity..
- */
- mntpoint = optarg;
- if (stat(mntpoint, &stb) != 0) {
- (void) fprintf(stderr, "%s: mount point missing\n",
- mntpoint);
- return(1);
- }
- if ((stb.st_mode & S_IFMT) != S_IFDIR) {
- (void) fprintf(stderr, "%s: invalid mount point\n",
- mntpoint);
- return(1);
- }
- break;
- default:
- usage(cp);
- return(1);
- }
- }
- }
-
- /* build the command line.. */
-
- (void) sprintf(cmd, "/etc/mount -r %s %s /dev/sr0 %s",
- iso9660 ? "-t hsfs" : "",
- nosuid ? "-o nosuid" : "",
- mntpoint);
- if (debug)
- (void) fprintf(stderr, "%s\n", cmd);
- if (debug != 1)
- rc = system(cmd);
- }
-
- /*
- ** The user is requesting to dismount a CD...
- */
- else if (strcmp(cp, "cdumount") == 0) {
- rc = system("/etc/umount /dev/sr0 && /usr/bin/eject /dev/sr0 2>/dev/null");
- }
-
- /*
- ** Improperly named/linked executables, I'm confused...
- */
- else {
- (void) fprintf(stderr, "%s: I don't know who I am... ? \n", cp);
- rc = 1;
- }
- return(rc >> 8);
- }
-