4.21. Printcap Basics

In the previous sections we have used simple printcap entries to define how to set up filters and pass parameters to them. We will now examine the printcap database in more detail.

There are three ways that the LPRng server and client software gets their configuration information.



Each print queue or printer has a name which is used to look up the printcap information for the printer. The /etc/printcap file is the default location for the printcap information, although it can also be obtained from database servers, or generated by programs. See the Using Programs To Get Printcap Information section for details.

We will use a more complex printcap file to explore how LPRng gets the printcap information. Put the following lines in the /etc/printcap file:

    # client entry
    lp:tc=.client
    lp2:tc=.client
    .client:
      :lp=%P@localhost
      :force_localhost
    
    lp:server
      :cm=The Main Print Queue
      :lp=/tmp/lp
      :tc=.common
    
    lp2:server
      :cm=The Second Print Queue
      :lp=/tmp/lp2
      :tc=.common
    
    .common:
      :sd=/var/spool/lpd/%P
      :mx=0
The lpc client command is very useful to see how LPRng uses this printcap information:
    h4: {224} % lpc client
    Config
    h4: {225} % lpc client all
    Config
     :lpd_port=2000
     :printcap_path=/var/tmp/LPD/printcap
    
    Names
     :.client=.client
     :.common=.common
     :lp=lp
     :lp2=lp2
     :main=lp
    
    All
     :lp
     :lp2
    
    Printcap Information
    lp|main
     :force_localhost
     :lp=%P@localhost
    lp2
     :force_localhost
     :lp=%P@localhost


The lpc client command shows the values in the lpc.conf file; since we have not entered any values in this file, we have no entries printed.

The lpc client all command shows all of the configuration and printcap information, and is the handiest one for system debugging and diagnostics. The Name information is the names of the printcap entries that have been found in the database and is listed in sorted order. The All are entries that correspond to actual queues or printers and are listed in the order that they appear in the printcap or according to an order specified by the system administrator. (See the all Printcap Entry for details.)

Queue or printer names must start with an alphanumeric character, and contain only alphanumerics, hyphens (-) and underscores (_). To avoid known and nasty problems with sending and receiving print jobs from case sensitive and case insensitive systems, LPRng brutally lowercases all printcap entry names and printer names.

The printcap file is processed by reading it line by line and composing the individual printcap entries. Each entry has an name and one or more aliases. The entries in the printcap assign values to options. These can have the format:

    option=string value \n with escapes
    flag         # equivalent to flag=1
    flag@        # equivalent to flag=0
    option#value # equivalent to option=value


An option will have the last value that occurs in the printcap entry.

Our example shows the use of the tc (termcap include) facility. The :tc value is a list of printcap entries that should be prefixed to the start of the printcap entry in which it appears. This allows options to be set in the printcap entry which will override the values in the :tc included entry. For convenience, the options are displayed in sorted order.

The LPRng clients and lpd server may require a different set of options for the same spool queue. The clients require options whose values tell the clients how the contact the lpd server and transfer a print job or query to it. The lpd server needs options that tell it how to either print a job or forward it to another lpd server. The :client or :server option marks a printcap entry as for client or lpd server use only; unmarked entries are used by both server and client. The lpc client command shows the printcap information that the LPRng clients would use. For example, here is what the lpd server would use:

    h4: {226} % lpc server all
    Config
     :lpd_port=2000
     :printcap_path=/var/tmp/LPD/printcap
    
    Names
     :.client=.client
     :.common=.common
     :lp=lp
     :lp2=lp2
     :main=lp
    
    All
     :lp
     :lp2
    
    Printcap Information
    lp|main
     :cm=The Main Print Queue
     :force_localhost
     :lp=/tmp/lp
     :mx=0
     :sd=/var/spool/lpd/%P
     :server
    lp2
     :cm=The Second Print Queue
     :force_localhost
     :lp=/tmp/lp2
     :mx=0
     :sd=/var/spool/lpd/%P
     :server


When we select the server printcap information, we see that the :sd option has been added, and the :lp replaced with new values.

We can use the :oh (on this host) option to mark printcap entries for use by a selected set of hosts. For example:

    lp:oh=10.0.0.0/255.255.255.0,*.private,!10.0.0.10
      :lp=%P@10.0.0.10


The :oh option takes a list of IP addresses and masks or glob patterns, and applies these to the IP addresses or list of Fully Qualified Domain Names for the current host. If there is a for at least one IP address or pattern in the list match then the entry is used. An exclamation mark (!) inverts the sense of the match, and the entry is used if the match fails.

Finally, we can use the wildcard facility to cause a default printcap entry to be used:

    lp|*:cm=Wildcard Alias - %P=lp, %Q=wanted
      :lp=%P@10.0.0.10
    *:cm=Wildcard Name- %P=wanted, %Q=wanted
      :lp=%P@10.0.0.10


The LPRng software first searches the printcap information for an exact match. If none is found then it searches for the first wildcard entry that matches the printer name. If the wildcard is used as an alias, then the printcap entry is simply selected for use, with the printer name and queue name selected as shown above. We can also use partial matching as well:

    lp|lp_*
      :lp=%P@10.0.0.10
    qt|qt_*
      :lp=%P@10.0.0.12


In the example above the first entry matches lp and all printer names starting with lp_, while the second entry matches qt and all printer names starting with qt_. This can be useful when setting up a family of spool queues as discussed in later sections.