unix - How to mount file system without root access using C program? -
i facing 1 problem. requirement is, need mount nfs
directory normal user. don't want use root
. that, have developed below simple program achieve this. but, not working expected.
my program :
#include<stdio.h> #include<stdlib.h> #include<unistd.h> void usage( char *progname ) { printf("usage : %s {mount|umount}\n",progname); } int main( char argc , char *argv[] ) { if ( argc != 2 ) { usage( argv[0] ); return exit_failure; } if ( strcmp(argv[1] , "mount") == 0 ) { execlp("mount", "mount", "192.168.12.3:/home/share", "/home/share", null); } else if( strcmp(argv[1] , "umount" ) == 0 ) { execlp("umount", "umount", "/home/share", null); } else { usage( argv[0] ); return exit_failure; } return exit_success; }
then,
$ cc mount_share.c -o mount
i set set user id
executable file.
$ chmod u+s mount $ ls -lhrt mount -rwsr-xr-x 1 root root 8.3k jun 4 17:47 mount
then executed mount
normal user, still says error. is,
mount: root can
as of knowledge, should work.
can point out wrong code?
any other way achieve this?
sudo specially designed purpose - allow unprivileged users run privileged command(to delegate authority). in order solve problem have add setuid(0);
, before attempting execlp(3)
Comments
Post a Comment