samba tips for OS X

I had to figure out to make samba work on OS X today, and rather than spend any time looking for existing documents, I worked out my own solution.

I installed the fink package and got version 2.2.5 installed. As usual there was some fumbling around with smbpasswd (doesn’t exist on OS X and the fink package doesn’t create it for you). So I had to pull a make_smbpasswd script from another working samba installation to get that working.

See the MORE link below for details on all the changes.

Then I had to add some stuff to inetd.conf and services, the latter being a stanza in the netinfo database. My love for netinfo being well-documented, I made the changes my own way.

Finally, I had to add 3 lines to inetd.conf (I wonder when Apple will switch to xinetd? and if I switched, what would it wreck?).

I have more fun working with OS X than the other OSes I have worked with, even on the command line. Gotta get that iBook . . . .

make_smbpasswd
Usage: cat /etc/passwd | make_smbpasswd > /sw/share/samba/private/smbpasswd

NB: that line does not wrap. Also, I have no idea who wrote it: it came with the distribution on one of my FreeBSD machines.

#!/bin/sh
awk ‘BEGIN {FS=”:”
printf(“#\n# SMB password file.\n#\n”)
}
{ printf( “%s:%s:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[U ]:LCT-00000000:%s\n”,
$1, $3, $5) }

Making changes to the services information in netinfo:

nidump services / / > services
echo ‘swat 901/tcp’ >> services
niload -m -v services / < services

Enabling samba and swat in inetd.conf:

netbios-ssn stream tcp nowait root /sw/sbin/smbd smbd
netbios-ns dgram udp wait root /sw/sbin/nmbd nmbd
swat stream tcp nowait root /sw/sbin/swat swat

Don’t forget to send a HUP to inetd.

Enabling it as a StartupItem:

host% echo ‘SAMBA=-YES-‘ >> /etc/hostconfig

Making a StartupItem bundle means creating these files or grabbing the bundle from here.

[/System/Library/StartupItems/SAMBA]# find . -print -a -exec cat {} \;
./Resources/English.lproj/Localizable.strings
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist SYSTEM “file://localhost/System/Library/DTDs/PropertyList.dtd”>
<plist version=”0.9″>
<dict>
<key>Starting samba services</key>
<string>Starting samba services</string>
</dict>
</plist>

./SAMBA
#!/bin/sh

. /etc/rc.common

##
# Start up samba services
##

if [ “${SAMBA:=-NO-}” = “-YES-” ]; then

ConsoleMessage “Starting samba services”

/sw/sbin/smbd -D
/sw/sbin/nmbd -D

fi
./StartupParameters.plist
{
Description = “smbd/nmbd daemon”
Provides = (“smb/cifs”);
Requires = (“Resolver”);
OrderPreference = “None”
Messages =
{
start = “Starting samba daemon”
stop = “Stopping samba daemon”
};
}