Skip to content

rain1/vfs_python

 
 

Repository files navigation

vfs_python

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.

Compiling

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

  1. Setup build environment.
wget https://gitlab.com/samba-team/samba/-/raw/master/bootstrap/generated-dists/debian12/bootstrap.sh
chmod +x bootstrap.sh
./bootstrap.sh
  1. 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
  1. 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

Installation

  1. Either download already compiled vfs_python.so from releases page or compile it yourself.

  2. Copy / symlink the resulting vfs_python.so to /usr/lib/x86_64-linux-gnu/samba/vfs/python.so (or wherever your VFS modules are).

  3. In your smb.conf, enable vfs_python per 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.py

and make sure that the script path is valid.

The Python code

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.

Current status

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. :)

About

Write Samba VFS modules in Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 57.4%
  • Shell 30.2%
  • Makefile 8.8%
  • Python 3.6%