Auto create home dirs with Samba

If you’re using Samba to provide network shares to your users, it might be usefull to autmatically create the their homedir when they access it the first time. This can be done by adding this line to the [homes] directive :

root preexec = /usr/local/sbin/mkhomedir.sh %U

This is the mkhomedir.sh script itself :

#!/bin/bash

if [ ! -e /storage_users/DOMAIN/$1 ]; then
mkdir /storage_users/DOMAIN/$1
chown $1:"DOMAIN+Domain Admins" /storage_users/DOMAIN/$1
fi
exit 0