Section 7.1. Print Shares

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:

  • The smbd daemon can hand the spooled job over to the server's printing system only after the entire file has been transmitted.

  • The spooled job must be in a format that can be sent directly to the Unix print queue. Generally, this means no special Windows meta formats.

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.

There are two other possible printing values: NT and OS2. These are useful only when the printer in question is located on a remote Windows NT variant or an OS/2 server running a BSD printing service. Because this setup is fairly uncommon, it is possible that support for these lpd variants will be removed in a future Samba release.

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.

Many implementations of lpr or other print utilities create a copy of the original job in its own spool directory (e.g., /var/spool/lpd). In these cases, the server requires twice the amount space as the size of the original print job. If this becomes a problem, consider placing the Samba spool directory on a different disk partition from the print system's spool directory. You can also define the min print space option in the Samba print share to require a specific amount of free space (in kilobytes) before Samba will accept a document for a given printer. If less than this amount is available, the client receives a "disk full" error message.

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.

Table 7-1. Printing variables




The page count of the print job (available only when printing from clients running Windows NT and later operating systems).

%f, %s

The full pathname of the spool file on the Samba server.


The name of the print job as sent by the client.


The number of the print job (for use with lprm, lppause, and lpresume).


The name of the Unix printer.


The size in bytes of the spool file.

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.

Table 7-2. Printing commands





lppause command


Command to pause an individual print job in the queue.


lpq command


Command to retrieve a listing of jobs in the queue.


lpresume command


Command to resume a pause print job.


lprm command


Command to remove an individual print job from the queue.


print command


Command to send a spooled job to the printer.


queue pause command


Command to pause an entire queue.


queue resume command


Command to resume a paused queue.


Table 7-3. Default printing command values based on printing types

Printing type



print command = lpr -r -P'%p' %s

lpq command = lpq -P'%p'

lprm command = lprm -P'%p' %j


print command = lpr -r -P'%p' %s

lpq command = lpq -P'%p'

lprm command = lprm -P'%p' %j

queue pause command = lpc stop '%p'

queue resume command = lpc start '%p'

lppause command = lpc hold '%p' %j

lpresume command = lpc release '%p' %j

CUPS (when there is no library support)

print command = lpr -P'%p' %s; rm %s

lpq command = lpq -P'%p'

lprm command = lprm -P'%p' %j

queue pause command = disable '%p'

queue resume command = enable '%p'

lppause command = lp -i '%p-%j' -H hold

lpresume command = lp -i '%p-%j' -H resume


print command = lp -c -d%p %s; rm %s

lpq command = lpstat -o%p

lprm command = cancel %p-%j

queue pause command = disable %p

queue resume command = enable %p


(same as SYSV with the following two additions)

lppause command = lp -i '%p-%j' -H hold

lpresume command = lp -i '%p-%j' -H resume


print command = lp -r -P%p %s

lpq command = lpq -P%p

lprm command = lprm -P%p %j

This is probably a good time to mention how Samba interacts with the Common Unix Printing System ([*] 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.

[*] Michael Sweet, the author of CUPS, has also written a book entitled CUPS: Common Unix Printing System (SAMS Publishing).

Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2004
Pages: 135 © 2008-2017.
If you may any questions please contact us: