vermaden / automount

Simple devd(8) based automounter for FreeBSD
66 stars 20 forks source link

Permissions don't work for exFAT #17

Closed outpaddling closed 4 years ago

outpaddling commented 4 years ago

Permissons do not get set properly when mounting an exFAT USB stick. Oddly, they get set after the drive is unmounted:

<<<ROOT@mako.acadix>>> /home/bacon 1031 # cat /usr/local/etc/automount.conf
FM='/usr/local/bin/pcmanfm'
MNT_GROUP='operator'
MNT_MODE='770'

After mount:

<<<ROOT@mako.acadix>>> /home/bacon 1031 # dir /media/
total 136
  4 drwxr-xr-x   3 root  wheel        512 Jan  9 19:21 .
  4 drwxr-xr-x  21 root  wheel       1024 Jan  9 18:58 ..
128 drwxr-xr-x   1 root  operator  131072 Dec 31  1969 da0s1

After unmount:

<<<ROOT@mako.acadix>>> /home/bacon 1031 # dir /media/
total 12
4 drwxr-xr-x   3 root  wheel   512 Jan  9 19:21 .
4 drwxr-xr-x  21 root  wheel  1024 Jan  9 18:58 ..
4 drwxrwx---   2 root  wheel   512 Jan  9 19:21 da0s1

FAT32 drives get set to proper permissions upon mounting.

auerlab commented 4 years ago

The problem is hard-coded umasks under the exfat case. There's a similar issue for msdosfs.

Here's a fix that respects MNT_MODE:

--- automount.orig  2020-01-16 11:46:56.550185000 -0600
+++ automount   2020-01-16 12:04:53.615976000 -0600
@@ -498,14 +498,17 @@
         FS_CHECK_CMD='fsck_msdosfs'
         FS_CHECK_ARGS="-C -y"
         FS_MOUNT_CMD='mount_msdosfs'
-        FS_MOUNT_ARGS="-o longnames -m 644 -M ${MNT_MODE} -D ${FAT_CODEPAGE} -L ${FAT_ENCODING} -u ${UID} -g ${GID} ${OPTS} ${LARGE} ${DEV} ${MNT}"
+        FS_FILE_PERMS=`printf "%03o" $((0${MNT_MODE} & 0666))`
+        FS_MOUNT_ARGS="-o longnames -m ${FS_FILE_PERMS} -M ${MNT_MODE} -D ${FAT_CODEPAGE} -L ${FAT_ENCODING} -u ${UID} -g ${GID} ${OPTS} ${LARGE} ${DEV} ${MNT}"
         ;;
       (${FS_TYPE_EXFAT})
         # sysutils/fusefs-exfat
         FS_CHECK_CMD='fsck.exfat'
         FS_CHECK_ARGS="-y"
         FS_MOUNT_CMD='mount.exfat'
-        FS_MOUNT_ARGS="-o uid=${UID} -o gid=${GID} -o dmask=022 -o fmask=133 ${OPTS} ${DEV} ${MNT}"
+        FS_MOUNT_DMASK=`printf "%03o" $((~0${MNT_MODE} & 0777))`
+        FS_MOUNT_FMASK=`printf "%03o" $((0${FS_MOUNT_DMASK} | 0111))`
+        FS_MOUNT_ARGS="-o uid=${UID} -o gid=${GID} -o dmask=${FS_MOUNT_DMASK} -o fmask=${FS_MOUNT_FMASK} ${OPTS} ${DEV} ${MNT}"
         ;;
       (${FS_TYPE_NTFS})
         # sysutils/fusefs-ntfs
outpaddling commented 4 years ago

Auerlab is me, BTW.

It occurred to me since that we might also consider splitting MNT_MODE into separate directory and file modes. I don't personally foresee much value in it, but it might head off a future feature request.

vermaden commented 4 years ago

Fixed along with several other things :)

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=246026

Regards.