Bug 245704

Summary: sysutils/fusefs-smbnetfs script to mount using /etc/fstab
Product: Ports & Packages Reporter: David Fullard <dave+freebsd>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: New ---    
Severity: Affects Only Me CC: allanjude, mi, mi, rhurlin, swills
Priority: --- Flags: mi: maintainer-feedback-
Version: Latest   
Hardware: Any   
OS: Any   
Description Flags
mount script none

Description David Fullard 2020-04-17 17:55:04 UTC
Created attachment 213507 [details]
mount script

I've written a short mount script for fusefs-smbnetfs to allow it to be used from /etc/fstab.

I'd like (if possible) to get it added to the sysutils/fusefs-smbnetfs port to allow others to use.

I know in the traditional sense that smbnetfs is supposed to be run per-user, but this would allow all users and processes to be able to use SMB shares. It does require configuration for fstab to be place in /.smb with the smbnetfs.conf, smbnetfs.auth (not required) and a copy of smb.conf (not required as defaults will be used). I've put this config in /usr/local/etc/smbnetfs and created a symlink to /.smb. It's possible to use the `-o config=/path/to/smbnetfs.conf`, but smbnetfs throws a warning about not being able to find smb.conf as it will be looking for it in $USER/.smb. Maybe this is something smbnetfs can be patched to handle.

The attached script is placed into /usr/local/sbin/mount_smbnetfs.

The line to add to /etc/fstab to use the script would then be:

    smbnetfs        /smb            smbnetfs        rw,late,failok,allow_other,mountprog=/usr/local/sbin/mount_smbnetfs     0       0

This would then create /smb as a special mount, allowing all users to browse SMB shares, for example:

    cd /smb/user:pass@host/share

If the smbnetfs.auth file is present and configured, then browsing to /smb/host/share would work.
Comment 1 Mikhail Teterin freebsd_committer 2020-04-17 21:56:58 UTC
The current smbnetfs itself can be used in fstab with the following trick:

-oallow_other   /smb            fusefs  rw,allow_other,failok,uid=105,late,direct_io,mountprog=/usr/local/bin/smbnetfs

That is, instead of "smbnetfs", the first column can contain simply one of the command-line options...

Your approach makes the fstab-entry look better, but is it worth the trouble of implementing at all? And, if it is, the options-parsing code inside smbnetfs itself should, probably, be patched instead.

As for your particular implementation, it would seem that $OPTS ends up containing all of the options in one argument -- instead of there being multiple arguments...

Also, the last line should begin with exec.

I'd do something like this (not tested):


if [ $# -gt 1 -a -n "${1##-*}" ]
        shift # Skip the non-option argument, if there are more than one

exec $SBNETFS "$@"
Comment 2 David Fullard 2020-04-18 00:01:15 UTC
(In reply to Mikhail Teterin from comment #1)
The 'trick' is kind of kludge and took me a long time to Google the solution, where I found it at https://lists.freebsd.org/pipermail/freebsd-fs/2018-February/025800.html.

I thought I would try to simplify it and save others from having to Google for a solution by asking for it to be included since it's not documented anywhere.