Operating System - HP-UX
1827809 Members
2024 Online
109969 Solutions
New Discussion

Re: Using Mount / UnMount Commands in Shell Scrips

 
SOLVED
Go to solution
udayabaskaran
New Member

Using Mount / UnMount Commands in Shell Scrips

My intention is to write a script/exe which will mount and unmount optical disks.
This script has to be executed by a non root user. The script is owned by root and i have given suid. When this executes i see the disk getting mounted. But during umount it says "permision denied for /etc/mnttab".
when i do a "bdf" i can see the disk mounted and entry is there in "/etc/mnttab" also.

I have created a c program and gave the same permissions and tested. still i get the same error.

What's wrong with the approach? How to get the umount to work. The effective user id is root in both scenarios.
10 REPLIES 10
A. Clay Stephenson
Acclaimed Contributor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi:

You need to be very clear here. In your C program, are you using the umount() system call or are you simply do something like
system("umount filesys1"); I would use the system call itself and if it returns a non-zero value then examine errno. It is very important to know what errno is set to. My best guess is that for some reason your setuid is not working as you expect.

It would also help to know what OS you are running and the type of filesystem. Are you using pfs_mount/pfs_umount? Are you running OmniStorage?


If it ain't broke, I can fix that.
Olav Baadsvik
Esteemed Contributor
Solution

Re: Using Mount / UnMount Commands in Shell Scrips

Hi,

Here is a couple of programs I wrote some time
ago after getting tired of doing su every
time I wanted to mount/unmount a cd.
I would think you can use this for your
purpose. As you see the device-file and
mount-point is hardcoded. You can easily
rewrite the programs to take these as
arguments.

/* Program that gives a regular user the ability to mount a cd.
. Compile the program
. Make root the owner of the executable.
. chmod 4755 executable
Olav Baadsvik Oslo Norway.
*/
#include
#include
#include
#include

main ()
{
int ios;
struct cdfs_args cda;
char buf[128];

setuid(geteuid());
setgid(getegid());

cda.fspec="/dev/dsk/cdrom";

ios=sysfs(GETFSIND, MNTTYPE_CDFS);
/* printf ("sysfs for %s er 0x%x\n", cda.fspec, ios); */

sysfs(GETFSTYP, ios, buf);
/* printf ("sysfs fstyp er >%s<\n", buf); */

ios = mount ( cda.fspec, "/CDROM",
( MS_DATA|MS_RDONLY),
MNTTYPE_CDFS,&cda, sizeof(cda) );

/* printf ("ios=%d\n", ios); */
if (ios) perror ("cdmount");
}

Here is the unmout-code:
#include
#include
#include

main ()

{
setuid(geteuid());
setgid(getegid());
umount("/CDROM");
}


Regards
Olav


Robin Wakefield
Honored Contributor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi,

I thought mount ignores the effective user id, and *always* uses the real user id to determine privileges.

Rgds, Robin.
Ravi_8
Honored Contributor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi,
umount doesn't use suid, it uses effective uid
never give up
A. Clay Stephenson
Acclaimed Contributor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi:

I just wrote a 3-minute setuid C program that mounted and unmounted a filesystem with absolutely no problem as a regular user.

I also used my dangerous version of a setuid wrapper which does a setuid and then can exec a command and it worked as well.

e.g.

cemexec root /usr/sbin/umount /filesys1
cemexec root /usr/sbin/mount /filesys1

Both of these worked exactly as expected.


If it ain't broke, I can fix that.
Douglas Arneson
Occasional Advisor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi,

We use a simple script that is owned by root:sys and executable by all with access to the shell. The scripts even run by cron.

The cdoff script:
umount /dev/dsk/c0t2d0
unount /dev/dsk/c0t2d1
umount /dev/dsk/c0t2d2

The cdon script is just the opposite of cdoff. mount instead of umount.

Simple, works for us as the users have to change CDs once a month as new CDs are distributed.


HTH,

Doug
Heiner E. Lennackers
Respected Contributor

Re: Using Mount / UnMount Commands in Shell Scrips

Hi,

maybe you should consider of using sudo, downloadable at http://hpux.cs.utah.edu/

Heiner
if this makes any sense to you, you have a BIG problem
Ken Stallings
Advisor

Re: Using Mount / UnMount Commands in Shell Scrips

I agree with the sudo approach. You also get the ability to specify exactly what options are allowed to the command for better security.
Ulrich Deiters
Frequent Advisor

Re: Using Mount / UnMount Commands in Shell Scrips

The attached script enables me to mout or unmount various exchangeable media. It uses ssh to control the access; users wanting to use the script must have their public ssh key entered into root's access control file.
Bruno Dostie
Advisor

Re: Using Mount / UnMount Commands in Shell Scrips


create file name:
vi /usr/bin/mountcd

#!/usr/bin/sh

/usr/sbin/mount /dev/dsk/... /mountdir


save file,

chown root /usr/bin/mountcd
chgrp sys /usr/bin/mountcd

chmod 4555 /usr/bin/mountcd

" root user to execute file"

Regards

Bruno
DOSB