Powered By BlogNow - Get Your Free Blog

I have moved!

My new blog is at lindsaar.net

All the old content will stay here though. But check out the new blog

¿ 24/9/2007 - Creating home and profile directories automatically in SAMBA and unix

I was playing with samba, unix and LDAP over the past day or two.

Found a situation where I had to create home directories and profile directories for users when they first log in (due to the way the accounts were being created).

Found a solution in samba's pre exec scripts.

Note, this is on a computer with no internet connection, so I would not recommend using this without really knowing what you are doing if this system is on the internet.

in smb.conf:

[home]
root preexec =
/usr/local/scripts/makehome.sh %u

[profile]
root preexec = /usr/local/scripts/makeprofile.sh %u


Then, those two scripts:

[raasdnil@server ~]# cat /usr/local/scripts/makehome.sh
#!/bin/sh
if [ ! -d '/home/$1' ]; then
        mkdir '/home/$1';
        chown -R $1:user '/home/$1';
fi

[
raasdnil@server ~]# cat /usr/local/scripts/makeprofile.sh
#!/bin/sh
if [ ! -d "/usr/samba-shares/profiles/$1" ]; then
        mkdir "/usr/samba-shares/profiles/$1";
        chown -R $1:user "/usr/samba-shares/profiles/$1";
fi

What this does is when the user logs on, it checks to see if a directory exists in the right places.  If it does not, it makes it and then owns it to the user.

Possible problems with this would be passing ../../somedir to get out of the current directory, but the end result would be some directory on the file server read writable for the user (the script exists if the file exists) so there is little chance of damage on this front.

A good idea would be to strip out any illegal characters like ../ from the input just in case.  For a later time.

blogLater

Mikel
Post A Comment! :: Send to a Friend!

About Me

AKA Raasdnil, this site is about web coding, hosting and all other matters that relate to this... especially Ruby on Rails!

Links