7.1. Print Shares
Samba at heart is not a printing system, but rather a spooling system. Its mantra is, "If Unix can print to it, so can I." To implement this philosophy, it must define a mechanisman external commands or software libraryto use when performing operations such as printing spooled jobs, retrieving a list of jobs in a queue, or pausing a printer.
Figure 7-1 illustrates the process of sending a print job to a Samba printer. The client opens the spool file on the server, writes the file in its entirety, and then closes the file, indicating that the job is ready to be printed.
Figure 7-1. Sending a job to a Samba printer
This series of events has some important implications:
Now it is time to define a share for a printer in the configuration file. A printer in smb.conf is a service section in which the mandatory print ok option has been enabled. The following is a perfectly valid, although largely useless, printer share:
[print-q] print ok = yes
The resulting share appears with a printer icon when viewed from a Windows client, as shown in Figure 7-2.
Figure 7-2. Viewing the print-q printer share from a Windows client
At this point, clients can connect to \\server\print-q and transmit print jobs. However, Samba reverts to default settings for all print-related functions. These defaults may or may not work for you. You can remove this uncertainty by explicitly defining the parameters necessary to handle print jobs.
Recall from Figure 7-1 that the client writes the entire document to the server before Samba can print it. So where is the spooled job written? The path parameter, when used in a print share, defines the directory on disk that will be used to store print jobs while they are being updated. A user must have write access to this directory in order to transmit a job to the Samba printer. Otherwise, the user will receive an error message such as "Disk is Full" or "Access denied."
Your configuration must inform smbd how it is to interact with the server's printing system in order to control what Samba does with a spooled job once the client has finished writing it. There are two means of defining this relationship. The first is to specify a value for the printing parameter in the printer's share definition, thus specifying a set of default commands that will be used to handle various printing operations and control how smbd parses the output from the printing system's lpq (or equivalent command). The printing option accepts a single string from the following list: SYSV, AIX, HPUX, BSD, QNX, PLP, LPRNG, CUPS.
Each one of these case-insensitve values matches a type of printing. For example, SYSV should be selected on systems such as Solaris and IRIX that use System V printing (i.e., lpadmin and lpstat). The AIX, HPUX, and QNX values represent their respective operating systems. The remaining options are matched with the printing system by the same name.
When building Samba, the configure script attempts to determine which printing system is currently installed and set the appropriate defaults. The easiest method of determining which printing interface is being used by default is to define at least one printer, such as the [print-q] share, in smb.conf and parse this file using testparm:
$ testparm -v -s smb.conf 2>&1 | grep 'printing.*=' printing = bsd
It is also possible to see the default printing commands used to communicate with the operating system by explicitly setting the printing value in a print service and reviewing that share with testparm. Let's assume an smb.conf with the printing option set to BSD:
[print-q] print ok = yes printing = bsd
Running testparm on this share reveals the defaults used for BSD Samba print servers:
$ testparm -s smb.conf < ....output deleted....> [print-q] path = /tmp printable = Yes printing = bsd print command = lpr -r -P'%p' %s lpq command = lpq -P'%p' lprm command = lprm -P'%p' %j
The print command is invoked when the client has successfully written the print job to the server. Generally, this hook is used to print the file, but its flexibility allows you to do just about anything you like. For example, you could send a document to a fax machine or convert the job to a new format, such as PDF. In all cases, the print command should remove the original spooled job (%s) after it has been processed. Otherwise, the spool directory (path) eventually runs out of space as jobs continue to pile up. The lpq command and lprm command strings are used respectively to list entries in the print queue and to remove individual jobs.
The %p variable shown in the three printing commands expands to the value of the printer name directive and is available only within a print service. Frequently, this parameter is omitted because its default value is the name of share itself. So in the previous output from testparm, the %p variable would be replaced at runtime with the string print-q. The complete list of variables available in print shares is listed in Table 7-1.
There are more print-related commands than the three shown in the testparm output for the [print-q] service. Table 7-2 gives the list of all the printing hooks and Table 7-3 describes the default values for each printing type.
This is probably a good time to mention how Samba interacts with the Common Unix Printing System (http://www.cups.org).[*] CUPS is currently the only printing library supported by Samba. When the CUPS library has been successfully detected at compile time and the printing option has been set to the string CUPS, the printing commands are bypassed entirely. There is no need to call out to an external program to process print requests; smbd can call the CUPS library functions directly. The default printing values specified in Table 7-3 for printing = cups are used only when Samba has not been compiled to include CUPS library support. We provide more information on Samba and CUPS later in this chapter.