Non-root user mount/umount

From: John Williams (williams@uni-duesseldorf.de)
Date: Fri Oct 04 1996 - 10:21:03 CDT


         Before I go any further, I would like to thank those people who answered
my request for help with their responses. There were a number of different
suggestions concerning how I could allow non-root users to mount and
unmount a disk, but I found the following to work on two different Solaris
versions. I am sure that all of you administrators out there will be able
to significantly shorten this file, so please excuse me if this file is a
little verbose.

If I can provide any more information, please send an email to me at:
        williams@uni-duesseldorf.de.

The following files allow non-root users to mount and then umount their
magneto-optical disks on Solaris 4.2. This has been set-up as two commands
because of the problems I had getting the SUN to recognise the umount
command.

This copy of mount_X.c allows X (user) to mount an optical disk at /usr/od.X
Note that mount point for the user had to be created in superuser mode and
the permissions accordingly adjusted to the users permission. A separate
mount point was made for each user to protect the users data.

/*
* mount_X -- Simple program allowing non-root users to mount optical disks
*
* Written by John Williams with help from Mike Fletcher,
* whose email address is fletch@ain.bls.com at time of writing
*
*/

/* $Workfile: mount_X.c $
* $Revision: 1.3 $ */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define MOUNT_NAME "mount_X"

#define MOUNT_POINT "/usr/od.X"

int
#ifdef __STDC__
main(int argc,char **argv)
#else /* !__STDC__ */
main(argc,argv)
        int argc;
        char **argv;
#endif /* !__STDC__! */
{
        uid_t uid;
        gid_t gid;

        uid = getuid(); /* Get real uid and gid of user */
        gid = getgid();

if(strcmp(argv[0],MOUNT_NAME) == 0) {
                                /* Make mount point owned by caller */
        if(chown(MOUNT_POINT,uid,gid) == -1 ) {
        perror( "Can't change ownership at /usr/od.X" );
exit(1);
}

/* Call mount if "mount_X" */
if (execl( "/etc/mount","mount", MOUNT_POINT, NULL) == -1) {
perror( "Can't execute mount command" );

/* Undo what we've just set up */
chown(MOUNT_POINT,0,0);
chmod(MOUNT_POINT,0600);
exit(1);
}
}
/* Should never be reached unless an executed command fails */
exit(1);
}

I then had to compile this using cc mount_X.c, which produces a file called
a.out, which can then be moved using mv a.out mount_X.
As superuser, now perform the following functions:
        (1) mv mount_X to /usr/bin
        (2) chown root.wheel /usr/bin/mount_X
        (3) chmod 4711 /usr/bin/mount_X
>>>>mount_X is now the command for X to mount the optical disk after rebooting.

This copy of umount_X.c allows X (user) to unmount an optical disk from
/usr/od.X.

/*
* umount_X -- Simple program allowing non-root users to
* unmount optical disks
*
* Written by John Williams with help from Mike Fletcher,
* whose email address is fletch@ain.bls.com at time of writing
*
*/

/* $Workfile: umount_X.c $
* $Revision: 1.3 $ */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define UMOUNT_NAME "umount_X"

#define MOUNT_POINT "/usr/od.X"

int
#ifdef __STDC__
main(int argc,char **argv)
#else /* !__STDC__ */
main(argc,argv)
        int argc;
        char **argv;
#endif /* !__STDC__! */
{
        uid_t uid;
        gid_t gid;

        uid = getuid(); /* Get real uid and gid of user */
        gid = getgid();

if(strcmp(argv[0], UMOUNT_NAME ) == 0) {
/* Called as "umount_X" */
execl("/etc/umount","umount", MOUNT_POINT, NULL);
}

/* Should never be reached unless an executed command fails */
exit(1);
}

Once this has been compiled using cc and the file has been moved to umount_X.

As superuser, now perform the following functions:
        (1) umoumt_X to /usr/bin
        (2) chown root.wheel /usr/bin/umount_X
        (3) chmod 4711 /usr/bin/umount_X
>>>>umount_X is now the command for X to mount the optical disk after rebooting.

If you are using Solaris 1.x, make the following changes in /etc/fstab to
include the optical drive, so as superuser enter the following line at the
end of fstab:
/dev/sd3a /usr/od.X 4.2 rw,noauto 0 0
This information can be found in /etc/mtab when the device is mounted.

If you are using Solaris 2.x, make the changes in /etc/vfstab (as
superuser) found in /etc/mnttab once the device has been mounted.

Still as superuser, ensure that all functions are terminated and reboot the
computer, then try the commands out in a shelltool/cmdtool.

Instiute of Cardiac Physiology
Heinrich-Heine-University
40225 Düsseldorf
Ph: (0211) 8112785
Fax: (0211) 8112672



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:11 CDT