A printer shared by the Samba server shows up in the list of shares offered in the Network Neighborhood. If the printer is registered on the client machine and the client has the correct printer driver installed, the client can effortlessly send print jobs to a printer attached to a Samba server. Figure 10-1 shows a Samba printer as it appears in the Network Neighborhood of a Windows client.
To administer printers with Samba, you should understand the basic process by which printing takes place on a network. On the client system, the application software prints by utilizing the system's printer driver for the printer that will be creating the actual output. It is the printer driver software running on the client system that translates the application's high-level calls into a stream of binary data specific to the model of printer in use. In the case of a serial, parallel, or USB printer, the data is stored in a temporary file in the local system's printer queue and then sent through the respective port directly to the printer. For a network printer, the file is sent over the network.
TIP
Sending a print job to a printer on a Samba server involves four steps:
lpr -r -Pprinter file
This command tells lpr to retrieve the name of the printer in the system configuration file (/etc/printcap) and interpret the rules it finds there to decide how to process the data and which physical device to send it to. Note that because the -r option has been specified, the file will be deleted after it has been printed. Of course, the file removed is just a copy stored on the Samba server; the original document on the client is unaffected.
The process is similar on System V Unix. Here, printing and deleting become a compound command:
lp -dprinter -s file; rm file
Let's start with a simple yet illustrative printing share. Assuming that you're on a Linux system and you have a printer called netprinter listed in the printer capabilities file, the following addition to your smb.conf file makes the printer accessible through the network:
[printer1] printable = yes print command = /usr/bin/lpr -P%p -r %s printer = netprinter printing = BSD path = /var/tmp
The variable %s in the print command option is replaced with the name of the file to be printed when Samba executes the command. There are four Samba configuration-file variables specifically for use with printing options. They are shown in Table 10-1.
Variable |
Definition |
---|---|
%s |
The full pathname of the file on the Samba server to be printed |
%f |
The name of the file itself (without the preceding path) on the Samba server to be printed |
%p |
The name of the Unix printer to use |
%j |
The number of the print job (for use with lprm, lppause, and lpresume) |
[printer1] printing = SYSV print command = lp -d%p -s %s; rm %s
Here are a few important items to remember about printing shares:
You must put printable = yes in all printer shares (even [printers]) so that Samba knows they are printer shares. If you forget, the shares will be unusable for printing and will instead be treated as disk shares.
[deskjet] printable = yes path = /var/spool/samba/print valid users = elizabeth cozy jack heather alexander lina emerald
All the other share accessibility options work for printing shares as well.
If a share named [printers] is in the configuration file, Samba will automatically read in your printer capabilities file and create a printing share for each printer that appears in the file. For example, if the Samba server had lp, pcl, and ps printers in its printer capabilities file, Samba would provide three printer shares with those names, each configured with the options in the [printers] share.
Here is an example [printers] share for a Linux system. Some of these options are already defaults; however, we have listed them anyway for illustrative purposes:
[printers] printable = yes printing = BSD printcap name = /etc/printcap print command = /usr/bin/lpr -P%p -r %s path = /var/spool/lpd/tmp min print space = 2000
After running testparm and restarting the Samba daemons, you can check to make sure everything is set up correctly by using smbclient to send a file to the printer. Connect to the printer using the command:
# smbclient /server/printshare
and then use the print command to print a file:
smb: /> print textfile
TIP
When you print something through the Samba server via smbclient, the following actions should occur:
The job appears (briefly) in the Samba spool directory specified by the path.
The job disappears from the spool directory that Samba used.
If smbclient cannot print, you can reset the print command option to collect debugging information:
print command = echo "printed %s on %p" >>/tmp/printlog
A common problem with Samba printer configuration is forgetting to use the full pathnames for commands. Another frequent problem is not having the correct permissions on the spooling directory.[1] As usual, check your Samba log files and system log files for error messages. If you use BSD printing, you can change the lp keyword in the printer's printcap entry to something other than /dev/null, allowing you to collect error messages from the printing system.
TIP
More information on debugging printers is in the file docs/textdocs/Printing.txt in the Samba source distribution. The Unix print systems are covered in detail in Æleen Frisch's Essential Systems Administration (published by O'Reilly).
With Samba preinstalled with Mac OS X, sharing access to a printer among Windows clients is easy. First, of course, you should set up local access using the Print Center application (located in /Applications/Utilities). Under the Printers menu, select Add Printer..., and make the appropriate selection from the pop-up menu. For example, if the printer is directly attached, select USB; if the printer is powered on, it should appear in the list. Choose the printer, and press the Add button.
Edit /etc/smb.conf, uncommenting the [printers] share and making any additional configuration changes you feel are necessary. Finally, enable the Samba startup item as described in Chapter 2, either by checking Windows File Sharing in Sharing Preferences or by manually editing /etc/hostconfig. Now your printer can be used by remote Windows clients.
On Mac OS X and some other BSD-based systems, you can test your configuration using smbutil. The following will send the file named print_test_file to the printer named printshare on the server bsdserver :
% smbutil print //bsdserver/printshare print_test_file
Now that Samba is offering a workable printer, you can set up your access to it on a Windows client. Browse through the Samba server in the Network Neighborhood. It should now show each printer that is available. For example, in Figure 10-1, we saw a printer called lp.
Next, you need to have the Windows client recognize the printer. Double-click the printer icon to get started. If you try to select an uninstalled printer (as you just did), Windows will ask you if it should help configure it for the Windows system. Click the Yes or OK button, and the Printer Wizard will open.
If you are installing a printer on Windows 95/98/Me, the first thing the wizard will ask is whether you need to print from DOS. Let's assume you don't, so choose the "No" radio button and press the Next > button to get to the manufacturer/model window, as shown in Figure 10-2.
Click the Next > or OK button. On Windows 95/98/Me, the Printer Wizard asks you to name the printer. On Windows NT/2000/XP, you need to right-click the printer's icon and select Properties to assign the printer a name. Figure 10-3 shows how we've named our printer to show that it's shared by the mixtec Samba server.
Finally, on Windows 95/98/Me the Printing Wizard asks if it should print a test page. Click the "Yes" radio button, then the Finish button, and you should be presented with the dialog box shown in Figure 10-4. On Windows NT/2000/XP, the printer test function is also accessed through the printer's Properties dialog box.
Sharing printers on Windows is not unlike sharing files. In fact, it is a little simpler. Open the Control Panel, then double-click the Printers icon to open the Printers window. Right-click the icon for the printer you want to share, and select Sharing.... This opens the dialog box shown in Figure 10-5 for a Windows 98 system, or Figure 10-6 on a Windows 2000 system. (The dialog box appears slightly different on other Windows versions, but functions almost identically.)
TIP
On Windows 95/98/Me systems, you may need to run file sharing in share-level (rather than user-level) access control mode to access a shared printer from Samba. To check or set this mode, go to Control Panel, then double-click on Network, then click on the Access Control tab. More detailed information on this can be found in Chapter 5.
The Samba distribution comes with three programs that assist with printing on shared printers. The smbprint program works with systems that use the BSD printing system, smbprint.sysv works with systems that use System V printing, and smbspool works with systems that use the Common Unix Printing System (CUPS). In the following sections we show you how to install printers for each system.
The BSD printing system is used by many Unix variants, including Red Hat Linux. With BSD printing, all the printers on the system have an entry in the /etc/printcap file, which is the database of printer capabilities used by the lpd line printer daemon and other programs that assist with printing. The Red Hat Linux implementation is a bit different in that /etc/printcap is a machine-generated file, which is re-created every time the lpd daemon is restarted by the /etc/rc.d/init.d/lpd script. Instead of editing /etc/printcap, we will add an entry for our printer in /etc/printcap.local, which the system automatically includes verbatim when creating /etc/printcap.
TIP
Here is the entry we added to our /etc/printcap.local file to support our Hewlett-Packard DeskJet 932C printer, which is shared by maya, a Windows 98 system:
lp|maya-hp932c:\ :cm=HP 932C on maya:\ :sd=/var/spool/lpd/maya:\ :af=/var/spool/lpd/maya/acct:\ :if=/usr/local/samba/bin/smbprint:\ :mx=0:\ :lp=/dev/null:
Go to your Samba source distribution's root directory, and install the smbprint program like this:
# cp examples/printing/smbprint /usr/local/samba/bin
We next create the printer's spool directory:
# cd /var/spool/lpd # mkdir maya # chown lp:lp maya # chmod 700 maya
# cd maya # >.config # chown lp:lp .config # chmod 600 .config
Use your preferred text editor to edit the .config file, and enter three lines, like this:
server=maya service=hp password=""
Finally, restart the printer daemon:
# /etc/rc.d/init.d/lpd restart
You can now try printing something. Run the following command:
$ lpr textfile
If you have everything set up correctly, the file prints on the shared printer. If you get "stair stepping" of text, caused by the printer not returning to the left margin at the beginning of every line, modify the if keyword in your printcap entry to run smbprint with the -t option.
Sending print jobs from a System V Unix system is a little easier than with the BSD system. Here, you need to edit the smbprint.sysv script in the examples/printing directory of the Samba distribution and do the following:
CUPS[2] uses a set of modules, called backends, to send print jobs to various destinations, such as local printers attached to parallel, serial, or Universal Serial Bus (USB) ports, or over the network using Unix line printer daemon (LPD) protocol, Internet Printing Protocol (IPP), AppleTalk Printer Access Protocol (PAP), and so on. The software package does not come with a backend for SMB; the Samba suite includes the smbspool utility for this purpose.
# ln -s /usr/local/samba/bin/smbspool /usr/lib/cups/backend/smb
# lpadmin -p hp932c -E -v smb://maya/hp932c -D "HP 932C on maya"
smb://[username[:password]@][workgroup/]server/printshare
The lpadmin command makes changes to /etc/cups/printers.conf and sends a HUP signal to the cupsd daemon, resulting in the creation of a local raw printer spool. In this example, print data is passed in raw format to the Windows system, which has the necessary printer drivers and printer description files to format the data appropriately. The -D option is used to give the printer a comment string.
$ lpr -P hp932c textfile
You should now be set up to use the printer from any application on the Unix system.
Table 10-2 summarizes the Samba printing options.
Option |
Parameters |
Function |
Default |
Scope |
---|---|---|---|---|
printing |
bsd, sysv, cups, hpux, aix, qnx, plp, softq, or lprng |
Printing system type of the Samba host |
System-dependent |
Share |
printable (print ok) |
boolean |
Marks a share as a printing share |
no |
Share |
printer (printer name) |
string (Unix printer name) |
Name for the printer that is shown to clients |
System-dependent |
Share |
lpq cache time |
numeric (time in seconds) |
Amount of time in seconds that Samba will cache the printer queue status |
10 |
Global |
postscript |
boolean |
Treats all print jobs as PostScript by prefixing %! at the beginning of each file |
no |
Share |
load printers |
boolean |
If yes, automatically loads each printer in the printcap file as printing shares |
yes |
Global |
print command |
string (shell command) |
Unix command to perform printing |
See below |
Share |
lpq command |
string (shell command) |
Unix command to return the status of the printing queue |
See below |
Share |
lprm command |
string (shell command) |
Unix command to remove a job from the printing queue |
See below |
Share |
lppause command |
string (shell command) |
Unix command to pause a job on the printing queue |
See below |
Share |
lpresume command |
string (shell command) |
Unix command to resume a paused job on the printing queue |
See below |
Share |
printcap name (printcap) |
string (filename) |
Location of the printer capabilities file |
System-dependent |
Global |
min print space |
numeric (size in kilobytes) |
Minimum amount of free disk space that must be present to print |
0 |
Share |
queuepause command |
string (shell command) |
Unix command to pause a queue |
See below |
Share |
queueresume command |
string (shell command) |
Unix command to resume a queue |
See below |
Share |
The printing configuration option tells Samba which printing system to use. There are several different families of commands to control printing and print statusing. Samba supports seven different types, as shown in Table 10-3.
Variable |
Definition |
---|---|
BSD |
Berkeley Unix system |
SYSV |
System V |
CUPS |
Common Unix Printing System |
AIX |
IBM's AIX operating system |
HPUX |
Hewlett-Packard Unix |
QNX |
QNX Realtime Operating System |
LPRNG |
LPR Next Generation |
SOFTQ |
SOFTQ system |
PLP |
Portable Line Printer |
The value for this option must be one of these seven selections. For example:
printing = SYSV
Setting the printing configuration option automatically sets at least three other printing options for the service in question: print command, lpq command, and lprm command. If you are running Samba on a system that doesn't support any of the printing styles listed in Table 10-3, simply set the commands for each of these manually.
The printable option must be set to yes to flag a share as a printing service. If this option is not set, the share will be treated as a disk share instead. You can set the option as follows:
[printer1] printable = yes
The option, also called printer name, specifies the name of the printer on the server to which the share points. This option has no default and should be set explicitly in the configuration file, even though Unix systems themselves often recognize a default name such as lp for a printer. For example:
[deskjet] printer = hpdkjet1
The global lpq cache time option allows you to set the number of seconds for which Samba will remember the current printer status. After this time elapses, Samba will issue an lpq command (or whatever command you specify with the lpq command option) to get a more up-to-date status that it can report to users. This defaults to 10 seconds, but can be increased if your lpq command takes an unusually long time to run or you have lots of clients. A time setting of 0 disables caching of queue status. The following example resets the time to 30 seconds:
[deskjet] lpq cache time = 30
The postscript option forces the printer to treat all data sent to it as PostScript. It does this by prefixing the characters %! to the beginning of the first line of each job. It is normally used with PCs that insert a ^D (control-D or "end-of-file" mark) in front of the first line of a PostScript file. It will not, obviously, turn a non-PostScript printer into a PostScript one. The default value of this options is no. You can override it as follows:
[deskjet] postscript = yes
The load printers option tells Samba to create shares for all known printer names and load those shares into the browse list. Samba will create and list a printer share for each printer name in /etc/printcap (or the system equivalent). For example, if your printcap file looks like this:[3]
lp:\ :sd=/var/spool/lpd/lp:\ spool directory :mx#0:\ maximum file size (none) :sh:\ supress burst header (no) :lp=/dev/lp1:\ device name for output :if=/var/spool/lpd/lp/filter: text filter laser:\ :sd=/var/spool/lpd/laser:\ spool directory :mx#0:\ maximum file size (none) :sh:\ supress burst header (no) :lp=/dev/laser:\ device name for output :if=/var/spool/lpd/lp/filter: text filter
the shares [lp] and [laser] are automatically created as valid print shares when Samba is started. Both shares borrow the configuration options specified in the [printers] section to configure themselves and are available in the browse list for the Samba server. The default value for this option is yes. If you prefer to specify each printer explicitly in your configuration file, use the following:
[global] load printers = no
lpq command = /usr/ucb/lpq %p
This would set lpq command to use /usr/ucb/lpq. Similarly:
lprm command = /usr/local/bin/lprm -P%p %j
The default values for each option are dependent on the value of the printing option. Table 10-4 shows the default commands for each printing option. The most popular printing system is BSD.
Option |
BSD, AIX, PLP, LPRNG |
SYSV, HPUX |
QNX |
SOFTQ |
---|---|---|---|---|
print command |
lpr -r -P%p %s |
lp -c -d%p %s; rm %s |
lp -r -P%p %s |
lp -d%p -s %s; rm %s |
lpq command |
lpq -P%p |
lpstat -o%p |
lpq -P%p |
lpstat -o%p |
lprm command |
lprm -P%p %j |
cancel %p-%j |
cancel %p-%j |
cancel %p-%j |
lppause command |
lp -i %p-%j -H hold (SYSV only) |
None |
None |
None |
lpresume command |
lp -i %p-%j -H resume (SYSV only) |
None |
None |
qstat -s -j%j -r |
print command = /usr/local/lpr -P%p %s; /bin/rm %s
With a bit of judicious programming, these smb.conf options can also be used for debugging:
print command = cat %s >>/tmp/printlog; lpr -r -P%p %s
lp|print1|My Printer 1 print2|My Printer 2 print3|My Printer 3
If the printcap name option (also called printcap) appears in a printing share, Samba uses the file specified as the system printer capabilities file (normally /etc/printcap). However, you can reset it to a file consisting of only the printers you want to share over the network. The value must be the filename (with its complete path specified) of a printer capabilities file on the server:
[deskjet] printcap name = /usr/local/samba/lib/printcap
[global] printing = cups printcap name = cups
The min print space option sets the amount of space that must be available on the disk that contains the spool directory if printing is to be allowed. Setting it to zero (the default) turns the check off; setting it to any other number sets the amount of free space in kilobytes required. This option helps to avoid having print jobs fill up the remaining disk space on the server, which can cause other processes to fail:
[deskjet] min print space = 4000
[1] If you are using Linux, you can use the checkpc command to check for this type of error.
[2] CUPS is open source software (http://www.opensource.org) developed by Easy Software Products. For more information, visit http://www.cups.org.
[3] We have placed annotated comments off to the right in case you've never dealt with this file before.