oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Inside Samba: Windows Sharing for the Mac
Pages: 1, 2, 3

Configuring Windows for Printing

Fig. 5 -
The Shared Printer

Now that you have configured Samba to share your printer, it should appear in the Windows Explorer along with the rest of your shares. To install the printer on the Windows machine, double click it in Explorer. A dialog box stating that the server did not have the drivers for the printer should open. Once you've closed the error, you'll be presented with a list of printer drivers available on your system.

If you want basic text printing, select the Generic/Text Only driver from the Generic manufacturer listing. This driver is excellent for debugging purposes, since most printers will handle plain text easily. If you want Postscript printing, select one of the Apple Color LaserWriter drivers from the Apple manufacturer listing. These drivers have the most neutral implementation of Postscript. Once you've selected the desired driver, click OK. The Windows machine should now be able to print to the shared printer on your Macintosh.

It's worth noting that sometimes Windows will send Postscript formatted files that, for some reason, won't print through your printer. I believe this is caused by differences in the way the operating systems handle printing. I resolved this issue by installing the GIMP Print package and writing a short shell script. I then configured Samba to use my shell script as the print command. Below is the script:

# /usr/local/bin/printsmb
# Print script for Postscript files.

/usr/local/bin/ps2pdf13 /tmp/$2
rm /tmp/$2
/usr/bin/lpr -P$1 -r /tmp/$2.pdf

This script makes use of the GIMP Print package's ps2pdf tool, which will convert the Postscript file from the Windows machine into a PDF file. The script then removes the temporary Postscript file and sends the resulting PDF file to the printer using lpr. I placed the script in /usr/local/bin and gave it 0755 permissions with chmod. To use this script with Samba, make the following change to your [printers] section:

. . .
   print command = /usr/local/bin/printsmb %p %s

Now Samba is configured to call the script and pass the desired printer and the temporary file's path as parameters. The script converts the file and prints it. Postscript printing should give you the same capabilities as printing right from your Mac. With Samba sharing your printer, you can easily let Windows clients print through your system. You can even manage their print jobs through the Print Center or the CUPS control center. Samba also allows you to configure a printer driver share so that your Windows machines will automatically download and install the appropriate software to print to your shared printer, bypassing the driver selection dialog box. Such configuration is a bit beyond the scope of this article, but I recommend taking a look through Using Samba, published by O'Reilly and Associates.

The Samba Web Administration Tool

Now that you're familiar with the common configuration options used to create disk and printer shares, I'm going to introduce you to a faster and easier way to work with your Samba configuration file. The Samba distribution includes a web-based tool that allows you to manipulate your Samba settings. Mac OS X includes this tool as well, but it first needs to be enabled.

Enabling SWAT

To enable the Samba Web Administration Tool, you must configure one of the Internet superdaemons that is included with Mac OS X. Mac OS X includes both inetd and xinetd. However, Mac OS X itself only seems to use xinetd. This is the superdaemon that responds for the FTP Sharing features.

Configuring xinetd to launch swat requires just a few steps. You first need to check that your /etc/services file contains a port entry for swat. To do this, enter the following command in the Terminal: cat /etc/services | grep swat. This command should return one result, which will list the swat service as running on port 901/tcp. If you do not get a result for this, add such an entry to your /etc/services file by editing it with pico running under sudo or as root. Add an entry that lists the information above and then save your changes.

Now that your machine knows about the daemon's TCP information, create a file in /etc/xinetd.d with the name swat and put the following in it:

service swat
   disable         = no        
   only_from       =
   socket_type     = stream
   wait            = no
   user            = root
   server          = /usr/sbin/swat
   server_args     = -s /etc/smb.conf
   groups          = yes
   flags           = REUSE

You will need to be the superuser or use the sudo command to create this file in the proper directory. For more information on customizing xinetd, take a look at the man page for xinetd.conf. The only setting you might want to change is the "only_from" entry. The example entry allows access only from the computer itself. You can enter an IP address or network address here to open up access a bit more. Once you have saved your entry, reboot the machine (or HUP the xinetd daemon if you are more Unix savvy).

Using SWAT

Fig. 6 -
The SWAT interface

Once you have xinetd configured to share swat, open up your web browser and enter the address If you are prompted to enter a username and password, enter those of your root user (please note that the root user is disabled by default on Mac OS X. To enable it, enter the command sudo passwd root in the Terminal.). You will see the SWAT entry page as shown in Figure 6. Notice along the top there are several different sections of the tool to use. The Home section has Samba related documentation. On the Globals section, you will find many directives for the [global] section of the smb.conf file. SWAT edits the file for you, allowing you to easily fill in desired fields and then committing changes.

Most of the sections are self-explanatory. At the top you will find a button to Commit Changes and some will have an Advanced button that will show you the more advanced Samba directives. The Status section has buttons that allow you to start, restart, and stop the smbd and nmbd daemons. Remember that you need to restart the daemons after any changes are made to the smb.conf file, whether by SWAT or hand editing. Below the daemon control buttons, you will see a listing of active network connections and individual buttons to force them closed.

The last two sections of SWAT are less often used with Mac OS X. The first is the View section. This section will display your smb.conf file so you can see how SWAT handles the file and makes changes. The last section is the Password section, which allows you to create the encrypted usernames and passwords required by most recent versions of Windows. You shouldn't need to use this tool at all, when you enable a user's Windows access in the System Preferences it generates this information for you.

SWAT is very useful for controlling your Samba daemons and working with their configuration. By making changes to the xinetd configuration file, you can access SWAT remotely using any browser. The various sections of SWAT make it much easier to keep your smb.conf file in order and learn a bit more about its syntax. Once you become more comfortable with the sections of smb.conf, you might choose to edit your configuration by hand, but for those of us in a bit of a rush SWAT is always a great way to go.

Final Thoughts

Now that you're familiar with the configuration of Samba, you should be able to create more advanced shares than the Apple provided GUI tools allow you. Using the SWAT interface will help you keep your configuration error free and easily allow you to restart Samba to see your changes. Overall, Apple has been smart enough to include the best Unix implementation of Windows sharing around and provided all of the necessary tools to get it up and running in a variety of configurations. Samba is invaluable in helping your Mac integrate with a Windows network. Your Windows associates won't even be able to tell the difference.

Jason Deraleau works as a systems administrator by day, IT consultant and technical writer by night, and is the coauthor of the upcoming Running Mac OS X Tiger.

Return to the Mac DevCenter