An experimental Samba module which lets you control execution of Samba actions in your own Python script. The aim of this this project is to rather offer a sample vfs module for those who find Samba's documentation difficult to follow than to be fully functional production ready module. Currently I do not plan to offer constant updates nor compile it for every Samba version.
At the time of updating this code I used Debian 12 and Samba 4.17.12 which used Python 3.11. Both Samba and vfs_python were extracted to my home directory. You may have to adjust those commands to fit for your needs
- Setup build environment.
wget https://gitlab.com/samba-team/samba/-/raw/master/bootstrap/generated-dists/debian12/bootstrap.sh
chmod +x bootstrap.sh
./bootstrap.sh- Make Samba
wget https://download.samba.org/pub/samba/stable/samba-4.17.12.tar.gz
tar -zxf samba-4.17.12.tar.gz
cd samba-4.17.12
./configure
make- Make this vfs_python module
git clone https://github.com/rain1/vfs_python.git
cd $HOME/vfs_python
./configure --with-samba-source=$HOME/samba-4.17.12/source3
make-
Either download already compiled
vfs_python.sofrom releases page or compile it yourself. -
Copy / symlink the resulting
vfs_python.soto/usr/lib/x86_64-linux-gnu/samba/vfs/python.so(or wherever your VFS modules are). -
In your
smb.conf, enablevfs_pythonper share:
[global]
log level = 5 # If you want to see log that debug method in python script produces
[myshare]
path = /tmp
vfs objects = python
python:script = /path/to/your/handler.pyand make sure that the script path is valid.
Take a look at the handler.py to see how it looks like and which Samba calls are supported at treinvent the wheel.he moment (hint: not too many).
When a user performs an action, the corresponding Python function will be called. You can either allow or deny that action by returning a boolean.
The Python script will be imported every time a user connects and is valid for the duration of the connection.
debug function that us used in handler.py is defined in python_importer.c which is why IDEs think it is undefined. Reason for that is that now Samba itself will take care of logging instead of python script having to reinvent the wheel.
This is experimental, my C skills have plenty of room for improvement and if your Python code raises an exception the Samba daemon will crash. I plan to address all those things, but right now it is what it is. Any contribution is greatly appreciated. :)