Bug 5598

Summary: /sbin/mount.smb needs better permission flexibility
Product: [Retired] Red Hat Linux Reporter: regs
Component: sambaAssignee: Trond Eivind Glomsrxd <teg>
Status: CLOSED RAWHIDE QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: 6.0CC: dave
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-11-11 21:07:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description regs 1999-10-05 19:09:39 UTC
Currently, you can only specify 'ro' or 'rw' in /etc/fstab
to set a mounted smb share's permissions (555 and 755
respectively).  There is no way to set it to 775, 777, 600,
or any other valid value.

Find below a diff and full script (that includes the bug
fix from bug #3239 for USER and PASSWORD order and the
$USER bug from bug #3290) that implements a 'perms' option
that allows said flexibility.

------ BEGIN DIFF ------
--- mount.smb.old       Tue Oct  5 13:44:54 1999
+++ /sbin/mount.smb     Tue Oct  5 14:00:54 1999
@@ -4,6 +4,24 @@
 #
 # Adapted from mount.smb by Greg Galperin, MAR99
<grg.edu>
 #
+# Adapted to take the perms option by Ari Gordon-
Schlosberg, OCT99
+#                                       <regs>
+#
+# Options:
+#              (Permissions, use only of the three)
+#              ro      -       read-only (perms 555)
+#              rw      -       read-write (perms 755)
+#              perms   -       in octal format, like 775
or 600
+#
+#              (Ownership, one or both or none)
+#              uid     -       user share should be
mounted as.
+#              gid     -       group share should be
mounted as.
+#
+# Sample /etc/fstab options (field 4) entries:
+#
+# uid=0,gid=99,ro              -       user root, group
nobody, perms 555
+# uid=foo,gid=users,perms=770  -       user foo, group
users, perms 770
+

 if [ $# != 4 -o "$3" != "-o" ]; then
        echo "unsupported commandline $0 $*"
@@ -14,21 +32,25 @@
 for arg in `echo $4 | tr ',' ' '`; do
         case "$arg" in
          "rw")
-             COMMAND="$COMMAND -f755 -d755"
+             PERMS=" -f755 -d755"
              ;;
          "ro")
-             COMMAND="$COMMAND -f555 -d555"
+             PERMS=" -f555 -d555"
+             ;;
+         perms=*)
+             PERMS=`echo $arg | cut -d '=' -f 2`
+             PERMS=" -f$PERMS -d$PERMS"
              ;;
           gid=*)
               MGID=`echo $arg | cut -d '=' -f 2`
-              COMMAND="$COMMAND -g$MGID"
+              MGID=" -g$MGID"
               ;;
           uid=*)
               MUID=`echo $arg | cut -d '=' -f 2`
-             COMMAND="$COMMAND -u$MUID"
+             MUID=" -u$MUID"
              ;;
          user=*)
-             USER="-U `echo $arg | cut -d '=' -f 2-`"
+             SMBUSER="-U `echo $arg | cut -d '=' -f 2-`"
              ;;
           passwd=*)
               PASSWD=`echo $arg | cut -d '=' -f 2-`
@@ -38,8 +60,10 @@
        esac
 done

+COMMAND="$COMMAND $PERMS $MUID $MGID"
+
 if [ -n "$PASSWD" ]; then
-      exec smbmount "$1" $USER $PASSWD -c "$COMMAND"
+      exec smbmount "$1" $PASSWD $SMBUSER -c "$COMMAND"
 else
-      exec smbmount "$1" -N $USER -c "$COMMAND"
+      exec smbmount "$1" -N $SMBUSER -c "$COMMAND"
 fi
------ END DIFF -----

------ BEGIN mount.smb ------
#!/bin/sh
#
# by Bill Nottingham <notting>
#
# Adapted from mount.smb by Greg Galperin, MAR99
<grg.edu>
#
# Adapted to take the perms option by Ari Gordon-
Schlosberg, OCT99
#                                        <regs>
#
# Options:
#               (Permissions, use only of the three)
#               ro      -       read-only (perms 555)
#               rw      -       read-write (perms 755)
#               perms   -       in octal format, like 775
or 600
#
#               (Ownership, one or both or none)
#               uid     -       user share should be
mounted as.
#               gid     -       group share should be
mounted as.
#
# Sample /etc/fstab options (field 4) entries:
#
# uid=0,gid=99,ro               -       user root, group
nobody, perms 555
# uid=foo,gid=users,perms=770   -       user foo, group
users, perms 770


if [ $# != 4 -o "$3" != "-o" ]; then
        echo "unsupported commandline $0 $*"
        exit -1
fi

COMMAND="mount $2"
for arg in `echo $4 | tr ',' ' '`; do
        case "$arg" in
          "rw")
              PERMS=" -f755 -d755"
              ;;
          "ro")
              PERMS=" -f555 -d555"
              ;;
          perms=*)
              PERMS=`echo $arg | cut -d '=' -f 2`
              PERMS=" -f$PERMS -d$PERMS"
              ;;
          gid=*)
              MGID=`echo $arg | cut -d '=' -f 2`
              MGID=" -g$MGID"
              ;;
          uid=*)
              MUID=`echo $arg | cut -d '=' -f 2`
              MUID=" -u$MUID"
              ;;
          user=*)
              SMBUSER="-U `echo $arg | cut -d '=' -f 2-`"
              ;;
          passwd=*)
              PASSWD=`echo $arg | cut -d '=' -f 2-`
              ;;
           *)
             ;;
        esac
done

COMMAND="$COMMAND $PERMS $MUID $MGID"

if [ -n "$PASSWD" ]; then
      exec smbmount "$1" $PASSWD $SMBUSER -c "$COMMAND"
else
      exec smbmount "$1" -N $SMBUSER -c "$COMMAND"
fi
------ END mount.smb ------

Comment 1 Bill Nottingham 1999-10-05 19:14:59 UTC
This won't work with the most recent samba releases
(2.0.5+), because smbmount no longer takes *any*
permission arguments.

Comment 2 regs 1999-10-05 19:36:59 UTC
From the samba.org cvs tree:

new smbmount and smbmnt code that is compatible with /bin/mount so you
can do:
	mount -t smb -o user=USER,passwd=PASSWORD //server/share /path

it also supports the following options:

        user=<arg>                      SMB username
        passwd=<arg>                    SMB password
        netbiosname=<arg>               source NetBIOS name
        uid=<arg>                       mount uid or username
        gid=<arg>                       mount gid or groupname
        port=<arg>                      remote SMB port number
        fmask=<arg>                     file umask
        dmask=<arg>                     directory umask
        debug=<arg>                     debug level
        ip=<arg>                        destination host or IP address
        workgroup=<arg>                 workgroup on destination
        sockopt=<arg>                   TCP socket options
        scope=<arg>                     NetBIOS scope
        guest                           don't prompt for a password
        ro                              mount read-only
        rw                              mount read-write

---- cut ----

Does 6.1 support this semantic and allow for setting umasks
in /etc/fstab?  If so, that's great.  My only issue is that I want to
be able to set the permissions on the mounted share in fstab... I
don't care if it's a mask or explicit permissions.

Comment 3 Bill Nottingham 1999-10-05 19:40:59 UTC
when is that as of?

Comment 4 regs 1999-10-05 19:51:59 UTC
Take a look at http://samba.org/cgi-
bin/cvsweb/samba/source/client/smbmnt.c?rev=1.6.2.3&content-
type=text/x-cvsweb-markup

Full revision history available at http://samba.org/cgi-
bin/cvsweb/samba/source/client/smbmnt.c

Comment 5 Bill Nottingham 1999-10-05 20:09:59 UTC
No, we're shipping base 2.0.5a + a couple of small patches.
We'll probably have this available in Raw Hide as soon
as 2.0.6 ships - we may upgrade it sooner, but I can't be
sure.

Comment 6 regs 1999-10-05 20:16:59 UTC
Sounds good to me.  However, are you saying that with the current
semantic (that I assume shipped with 6.1 (my 6.1 box is sitting at
home, not connected to the network for the first time in <I>months</I>
(it never fails, does it?))) there is no way to set permissions from
fstab?  If so, I would think that this would qualify for an errata
posting, there not even being a workaround with the stock packages.

Comment 7 Bill Nottingham 1999-10-21 17:44:59 UTC
*** Bug 6173 has been marked as a duplicate of this bug. ***

There appears to be an new version of the smbmount program
in this distribution which seems to not allow setting of
uid, gid, file mode, or dir mode.  To make matters worse,
the smbmount man page lists the options for the old version.
What gives?  Is smbmnt used at all now?  How to I send it
options?

Regards,

Dave Del Signore

Comment 8 Bill Nottingham 1999-11-11 21:04:59 UTC
This should be fixed in samba-2.0.6-1, which will be in the
next Raw Hide release....