Samba auto-mount shares with multiple users

We run net usershare add for you. :wink:

Ok, thx for this clarification! :wink:

I deleted the usershares, and I still can’t get guest access to a share with the same name as the mount directory. I tried adding the rootdelay=30 that berto suggested, but that didn’t fix it either.

I think it’s time to give up. I’ll change my setup on the other PC’s so they will look at different share names. Thanks everyone for your suggestions.

colleagues,

if it was said, sorry in advance. just have seen on top few not correct things:

whole “net” interface to samba config is PERMANENT storage of samba registry settings.

yes, “usershares” are not kept over boot, but that’s because usershares are not permanent by definition.

if net doesn’t provide a “shortcut command” to some setting you are looking for, it can be used to import / change parameters the same way as writing into smb.conf.

see “net conf”
for shares (permanent) see “net shares”

regarding (still present) .conf files - those will go away in next version. until then samba merges all .conf file settings + registry (settings managed through libnet)

1 Like

Actually user shares are persistent across boots. That’s why there can sometimes be orphaned usershares in /var/lib/samba/usershares. We remove usershares when a drive is unmounted and (I think) during shutdown but sometimes (such as an unclean shutdown) they will not be removed properly. If the drive is then disconnected while the system is powered down this can result in orphaned shares:

osmc@rpi2:~$ sudo net usershare info
info_fn: file /var/lib/samba/usershares/hfs is not a well formed usershare file.
info_fn: Error was Path is not a directory.
info_fn: file /var/lib/samba/usershares/fat32 is not a well formed usershare file.
info_fn: Error was Path is not a directory.
info_fn: file /var/lib/samba/usershares/exfat is not a well formed usershare file.
info_fn: Error was Path is not a directory.
info_fn: file /var/lib/samba/usershares/ntfs is not a well formed usershare file.
info_fn: Error was Path is not a directory.

This is harmless because if the mount point they refer to does not exist (eg /media/fat32 is not mounted) then no share will be displayed to the samba client, and next time a drive with the same name is mounted the usershare will be re-added anyway.

That’s why I was suggesting that the usershares were completely cleared with the drive removed before adding the fstab entry so there were no orphaned entries still there.

However Orionn’s problem seems to be that systemd is not mounting the drive from fstab early enough - even with the change in udisks-glue.service to delay it until after local-fs.target, so because udisks-glue mounts the drive instead of systemd a default automount samba share gets added again.

I can’t reproduce this problem on any of my systems - manual fstab mounts work normally as expected with the same mount options Orionn is using, so I don’t really have any idea why his system is so slow at mounting the drive from fstab…

oh

I was not actual then. back in 2013 when we tried to use usershares as an option to provide adhock sharing on zfs filesystems, it worked until reboot.

samba had to be running before mounting of filesystems started on a imported pool - to not miss defined shares on new “foreign” pools - which had the “share = smb” on own properties, but samba had not yet this in /var/… and as samba started, it checked all usershares already defined and those without actual physical path already present, were flagged as NOK and done…

now reading docs - samba is checking the presence on actual remote access.
anyhow for me works as expected, folder is gone, share is gone, folder is back, share is back.

only one confusing thing is that root launched “net usershare list” doesn’t show it. by particular user started the same is fine (shows it). but maybe this is also written in docs.

Yes, I think Samba defers checking for user shares until a client tries to access them or the share list, then it checks the usershares defined in /var/lib/samba/usershares, and creates on the fly those whose directory/mountpoint actually exist and ignores the rest.

Usershares are per user - so shares created by the root user with ‘net usershare add’ will not be seen when querying as the osmc user with ‘net usershare info’ or vica versa.

This is why I said to use ‘sudo net usershare info’ earlier in the thread because our udisks-glue script adds usershares as the root user, and they would not be reported by ‘net usershare info’ as the osmc user.

Ownership (control) of the usershare seems to be based entirely on the ownership of the actual file in /var/lib/samba/usershares/ - if it is owned by osmc then it is osmc’s usershare, etc. There is nothing in the file contents itself to say who the owner of the usershare is. The file is created with the ownership of whoever runs ‘net usershare add’.

One user can not see, delete, or override another users pre-existing usershare using ‘net usershare’.