It is possible to use the include = /somepath/%u.smb.conf in the global section to call a script /somepath/cb0.smb.conf if the user cb0 connects to the samba server.
Unfortunately this does not wotk for me because testparm alway gives me
Can't find include file /somepath/.smb.conf

When I connect to the server I can enter a username and pass but it alway rejects the connection.

I'm using Samba Version 3.2.5

How can I achieve to load a custom user script depending on the user that is connecting ?


You are doing it correctly! However, testparm just doesn't have a username to test with.


METHOD 1. If you can't get samba to do it, install Fail2Ban -- a log file monitoring and security suite (packages available through most Linux distributions software management systems) -- and then configure Fail2Ban to watch the samba log for the login lines, set the number of lines to detect to 1 and set the action to a script that will do whatever it is you want done on login. To accomplish all of this you will need to edit files under /etc/fail2ban and be familiar with regular expressions and the log files you need to watch.

This won't be as clean as a script integrated with samba. For instance, it probably won't be synchronised to the exact moment of user login.

METHOD 2. Again, not as clean, as we'd like. Configure your samba to spit out a log file for each connection. Make directories called "unprocessed" and "processed" and configure samba to dump the per-connection log file to the "unprocessed" directory. Write a cron job or a looping script (sleep 1 or 2 seconds between iterations, perhaps) to loop through the files in the unprocessed directory and do whatever you need done, then mv them to the processed directory.

Possibly if you describe exactly what you want to do in more detail, other people can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.