Section 7.4. The printers Service

7.4. 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.

  • Check for an explicitly defined share in smb.conf. If a match is found, authorize this request against this share.

  • Check for the [homes] service. If this share exists, look up the requested share name in the local system's list of accounts (e.g., /etc/passwd or users in an LDAP directory). If the search succeeds, create a copy of the [homes] share named for the user found and use this new share for the connection request.

  • If the [printers] share is defined, look up the requested share name in the printcap name. If a match is found, create a copy of the [printers] share named for the printer found and use this as the service in response to the client's request.

  • Fall back to the default service if one is defined.

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:

  1. Inform smbd as to where it can find the list of system printers by defining the printcap name global parameter. This value varies depending on the default printing value.

  2. Define the [printers] service in smb.conf.

  3. Specify whether smbd should create all of the dynamic print shares at startup (allowing them to be browsed) or create them upon demand.

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 Table 7-4 for various printing systems and the associated printcap name value assigned by default.

Table 7-4. Special printcap name values

Value of printing option

Default printcap name







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.

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: