[TAG] Mounting a Samba share

Benjamin A. Okopnik ben at linuxgazette.net
Fri Nov 11 20:15:16 MSK 2005


On Tue, Nov 08, 2005 at 10:17:42PM +0000, Pete Savage wrote:
> Hi,
> A quick mounting question.
> I have recently setup my fstab to allow me to let a normal user mount an
> NFS share.
> I would like to do the same with an SMB or more accurately a CIFS share.
>  The mount.cifs documentation states that there are no options to let
> non-privilaged users mount a cifs share.  However it also states that
> this can be achived giving suid to hte mount.cifs binary.  I have done
> this and checked to see if it was also applied to the mount binary.  I
> still cannot mount a CIFS share with a non-root account.  I get the
> "only root can do that" reply.

Well, I'm usually not a big fan of them, but since you're already
talking SUID binaries...

Item 1: *Remove* the SUID bit from the mount.cifs binary. No use leaving
it around where other people can fall into sin. :) Now, create the
following file:

----- mount-cifs.c -----------------------------
#include <stdlib.h>

int main(){
	if ( system( "/bin/mount /where/my/share/is" ) != 0 ){
			perror( "Mount failed!\n" );
			exit ( 1 );
	}

	return( 0 );
}
----- mount-cifs.c -----------------------------

Edit it to exec your exact 'mount' command - make sure to include the
full path for the executable! - and compile it:

``
cc -o mount-cifs mount-cifs.c
''

Now, as root, change its owner and group appropriately
and make it SUID root (and set the other perms appropriately):

``
chown root.cifs_group mount-cifs
chmod 4750 mount-cifs
''

Now, create a group name (cifs_group, as above, or pick whatever you
like), add the users that you want to allow this privilege, and away you
go. All they've got to do is exec it.

Unmounting it left for the student. Hint: avoid making the above prog
any more complex than this; create an 'umount-cifs' instead.


* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *





More information about the TAG mailing list