Samba - Samba as a PDC for Windows XP Pro on FreeBSD

2003-06-17

This describes the process to build Samba on FreeBSD including the scripts and program modifications necessary for automation.I. Enable Quotas
(see 1-2 Enable Quotas on FreeBSD)
Note: Quota support through Samba is horrible at best. When a user exceeds his quota, on logout when the profile is saved he will get an error stating his profile cannot be saved along with an over quota message. A better way to regulate space is the Profile Limits in WindowsXP. The FreeBSD quotas work well as a backup in case the XP Profile fails. To set the Profile Quota size use gpedit.msc and go to User Configuration, Administrative Templates, User Profiles, Limit profile size.

II. Install Samba

# cd /usr/ports/net/samba
# make install

Edit your smb.conf file (see 0-0 smb.conf)
To start Samba run /usr/local/etc/rc.d/samba.sh start
You should be able to tail the logfile to see if its up.

III. Scripts

#!/usr/local/bin/expect
#
# Benjamin Bryan
# June 17, 2003
# This script adds user to /etc/passwd and Samba database.
# Usage: ./addsmbuser.sh username "full name" password

set timeout 15

set username [lindex $argv 0]
set name [lindex $argv 1]
set pass [lindex $argv 2]

spawn adduser
expect "sername:"
send "$usernamer"
expect "ame:"
send "$namer"
expect "ault):"
send "r"
expect ":"
send "usersr"
expect "[]:"
send "r"
expect "default]:"
send "r"
expect ":"
send "r"
expect ":"
send "r"
expect ":"
send "yesr"
expect ":"
send "nor"
expect ":"
send "nor"
expect "password:"
send "$passr"
expect "again:"
send "$passr"
expect "creation"
send "yesr"
expect "(yes/no):"
send "yesr"
expect "#"

spawn smbpasswd -a $username
expect "password:"
send "$passr"
expect "password:"
send "$passr"
expect "#"
#!/usr/local/bin/expect
#
# Benjamin Bryan
# June 15, 2003
# This script adds machine accounts to /etc/passwd.
# Note: a modified version of pw is required.  pw_user.c
# - char const     *notch = gecos ? ":!@" : " ,t:+?%$^()!@~*?<>=|\/\"";
# + char const     *notch = gecos ? ":!@" : " ,t:+?%^()!@~*?<>=|\/\"";
#
# This will allow the $ to be used for machine accounts.  Without this
# all changes would have to be made by hand.
# Group smbclient must exist.
#
# Usage: ./addmachine.sh machinename$

set timeout 1

set username [lindex $argv 0]

spawn adduser
expect "sername:"
send "$usernamer"
expect "ame:"
send "$usernamer"
expect "ault):"
send "r"
expect ":"
send "smbclientr"
expect "[]:"
send "r"
expect "default]:"
send "r"
expect ":"
send "r"
expect ":"
send "noner"
expect ":"
send "nor"
expect ":"
send "r"
expect "(yes/no):"
send "yesr"
expect "#"
#!/usr/local/bin/expect
#
# Benjamin Bryan
# June 15, 2003
#
# This script adds a machine account already in /etc/passwd to the samba
# database.
#
# Usage: ./addmachinesamba.sh machinename
# (note the lack of a $)

set username [lindex $argv 0]

spawn smbpasswd -m -a $username
expect "#"
#!/usr/local/bin/expect
# Benjamin Bryan
# June 18, 2003
#
# script to remove samba users and pulverize all their files.
# usage: ./removesmbuser.sh almostagoner

set timeout 15

set username [lindex $argv 0]

spawn rmuser
expect "user"
send "$usernamer"
expect "remove"
send "yesr"
expect "home"
send "yesr"
expect "#"

spawn smbpasswd -x $username
expect "#"

exit 1