/* * Mount.c (Program to perform 'safe' file system mount/umount * operations without requiring super user permissions.) * Copyright (C) 1992 Don Trimmer, Delta Microsystems, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This notice was shamelessly copied from the GNU General Public * License. That license is included in it's entirety at the end * of this listing. Please note that GNU grants permission to copy * their license statement as long as it is complete and unmodified. * */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** Program: Mount (Umount) *** Purpose: Allow anybody to mount/umount file systems from specified devices, while preventing anybody but 'root' from performing other mount/umount operations. *** Usage: Mount args Umount args args: The arguments normally given to mount or umount. *** Notes: Use the following shell script to build executable: #!/bin/csh # # The following two lines build a test version. To # build the real version, comment out the next two # lines and remove the leading '# ' from the # following two commands: # echo "Compiling test version (echo mount arguments)" cc -DTEST -o Mount Mount.c # echo "Compiling and loading Mount" # cc -o Mount Mount.c echo "Changing Mount ownership and permissions" chown root Mount chmod 4555 Mount echo "Linking Umount to Mount" /bin/rm Umount | echo -n "" ln Mount Umount /bin/ls -l Mount Umount echo "Done!" *** History: 04/08/91: Under development--D. Trimmer 04/08/91: Tested--D. Trimmer 10/19/91: cdrom and pcfs added by W. Kennedy 03/03/92: Removed references to 'smo', added 'uflop' and improved security --D. Trimmer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ #include #include #include #include #include #define CLEAR 0 #define SET 1 #define REEXPLEN 80 #define NEWMOUNTCOM "Mount" #define NEWUMOUNTCOM "Umount" #ifdef TEST # define MOUNTCOM "echo" # define UMOUNTCOM "echo" # define MOUNTPATH "/bin/" # define UMOUNTPATH "/bin/" #else TEST # define MOUNTCOM "mount" # define UMOUNTCOM "umount" # define MOUNTPATH "/usr/etc/" # define UMOUNTPATH "/usr/etc/" #endif TEST /* * "devices" is an array of strings. Each string is a regular * expression which matches a device or directory. If a device * is specified, then the directory on which the device should * be mounted should also be specified: * * Mount /dev/sd3c /tmp * * If only the directory is specified, then the file /etc/fstab * is referenced to determine what file system is normally * mounted on that directory: * * Line in /etc/fstab: /dev/sd3c /tmp 4.2 rw,noauto 0 0 * Mount /tmp */ char devices[][REEXPLEN] = { /* * Make entries in /etc/fstab for each of the following * entries and create directories /cdrom, /pcfs and * /uflop. */ "/cdrom", "/pcfs", "/uflop", "" }; main(argc,argv) int argc; char *argv[]; { int i,j,k; /* Index */ int ValidatedFlag=CLEAR; /* OK to proceed flag */ char Path[MAXPATHLEN]; /* Path of mount/umount */ char Name[MAXPATHLEN]; /* mount or umount */ struct stat stbuf; /* File status structure */ if(getuid() && argc>1) { /* UID not root, so validate permission */ for(i=0;devices[i][0] && !ValidatedFlag;i++) { if(re_comp(devices[i])) { fprintf(stderr, "%s %s (errno=%d)\n", "Can't compile regular expression", devices[i],errno); exit(1); } for(j=1;j * Copyright (C) 19yy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Also add information on how to contact you by electronic and paper mail. * * If the program is interactive, make it output a short notice like this * when it starts in an interactive mode: * * Gnomovision version 69, Copyright (C) 19xx name of author * Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. * This is free software, and you are welcome to redistribute it * under certain conditions; type `show c' for details. * * The hypothetical commands `show w' and `show c' should show the * appropriate parts of the General Public License. Of course, the * commands you use may be called something other than `show w' and `show * c'; they could even be mouse-clicks or menu items--whatever suits your * program. * * You should also get your employer (if you work as a programmer) or your * school, if any, to sign a "copyright disclaimer" for the program, if * necessary. Here a sample; alter the names: * * Yoyodyne, Inc., hereby disclaims all copyright interest in the * program `Gnomovision' (a program to direct compilers to make passes * at assemblers) written by James Hacker. * * , 1 April 1989 * Ty Coon, President of Vice * * That's all there is to it! */