Is there a possibility to temporarily share a directory per Samba?
With Python 3 i can serve the current directory per HTTP using:
python -m http.server.
I'd like to do the same thing with Samba.
There doesn't appear to be a way to create an ad-hoc share similar to the way
exportfs does it for NFS on Linux and
share does it on Solaris. Reasons may vary but you could technically do something like described in the page for Running Multiple Servers on the same machine and with the custom
smb.conf accomplish what you need to do.
Personally if you want to have a share dynamic you might want to share your home directory and use dynamic home shares via samba discussed in many places including Ubuntu forums, and Samba mailing list.
Depending on how old your samba daemon is, and the config options used when it was built, you may still have the option of defining a "dynamic" share in your smb.conf, pointed at say /var/dynamic/, see below, and then simply adding a symbolic link to the directories you temporarily want to share into the directory.
This hack require the wide links option to be set to yes, to allow samba to follow links outside of the shares root. Unfortunately a couple of years back the Samba crew tweaked their default config to prevent wide shares, as it could be exploited. Google for: Samba and "wide links" for the history and work arounds.
[dynamic] comment = Somewhere to park dynamic shares path = /var/dynamic read only = Yes inherit acls = Yes follow symlinks = yes wide links = yes
A quick test should see if your good e.g.
mkdir -p /var/dynamic/test cd /var/dynamic ln -s test a_link ln -s /tmp/ tmp_test
Lets say you want to quickly share /somefolder to someuser temporary readonly.
Add a system user:
useradd -r someuser
Often by default the folder is other-readable (check with ls -ld /somefolder), if you need to force it:
chmod -R o+r /somefolder
Add the user to samba with some password like:
smbpasswd -a someuser
Quickly edit smb.conf and add at the bottom
[someshare] path = /somefolder read list = someuser
exit, save, and finally run
smbcontrol smbd reload-config
Obviously you may want to remove the "someshare" section once done and rerun the reload-config command.
Disclaimer: i didnt fully test this but i was amazed how simple the answer to the question could be. You can possibly skip some steps and dive straight into editing of smb.conf if you already have some user with existing samba access - exactly what i just ran into.