Feb. 15, 2011, 4:52 a.m.
posted by lime
The [printers] Service
Defining individual print shares for each queue on a large print server can be tedious. To alleviate this problem, Samba provides a mechanism to dynamically create printer shares for every queue known by the host operating system. This special share named [printers] is very similar to the [homes] share. Here's how it works.
When Samba receives a request to connect to a share, it performs the following series of checks to locate the share definition.
As we mentioned earlier, you can't define a user and a printer with the same name; Samba will never find the printer if both [homes] and [printers] exist in smb.conf. If you accidentally send print jobs to a file share, you will see spooled jobs accumulate in the top-level directory of the share.
Configuring the [printers] share involves three steps:
The printcap name parameter is indirectly linked to the printing option. In its generic form, printcap name refers to the text file that contains the list of system printers, such as /etc/printcap. When used with certain printing systems, however, smbd can query the print service directly. Samba provides defaults that work most of the time; see Figure for various printing systems and the associated printcap name value assigned by default.
If the list of systems printers changes, you can make Samba reload all its configuration options (and thereby discover the changes in printers) through the usual mechanism of sending the smbd process a hangup signal (SIGHUP). But to save you the trouble of restarting smbd, the server can instead be instructed to periodically reparses the contents of the printcap name based on the printcap cache time global option. This parameter accepts an integer value specifying the number of seconds for which the cached list of printer names should be considered valid. In Samba 3.0.20 or greater, the printcap cache time default is 750 seconds.
In some cases, it is preferrable to export a subset of system printers when using a printing type other than CUPS. This can be done by pointing Samba to a custom printcap file that contains the list of printer you wish to share (e.g., printcap name = /etc/samba/printcap).
The [printers] share is defined just like a normal printer. The only real requirement is to use the variables rather than hard-coded values for changeable values such as printer names.
Finally, if [global] contains load printers = yes (the default value), all of the printers defined in the printcap name file are parsed and made available for browsing when Samba is launched. Otherwise, clients may request a printer using its UNC path but may not browse for the printer.
Our resulting smb.conf now looks like:
[global] printing = bsd printcap name = /etc/printcap printcap cache time = 1800 print command = /usr/bin/lpr -P%p %s; /bin/rm %s lpq command = /usr/bin/lpq -P%p lprm command = /usr/bin/lprm -P%p %j queue pause command = /usr/sbin/lpc stop %p queue resume command = /usr/sbin/lpc start %p [printers] print ok = yes path = /var/spool/samba
Before we can test the [printers] share, we need a working /etc/printcap file. Here are our example printer configurations. If you need a refresher on the various fields in each printer entry, refer to the printcap manpage.
hp2100:rm=rain:rp=hp2100: slate:rm=rain:rp=slate: quest:rm=rain:rp=quest:
Once Samba is started, we can browse the server and see all three printers:
$ bin/smbclient -L localhost -N Anonymous login successful Domain=[VALE] OS=[Unix] Server=[Samba 3.0.22] Sharename Type Comment ----- ---- ------- IPC$ IPC IPC Service (Samba 3.0.22) hp2100 Printer hp2100 slate Printer slate quest Printer quest ...
Clients will be able to connect to any one of these printers just as if it had been explicitly defined it in smb.conf.