Next Previous Contents

6. Forwarding Jobs

Our Tutorial Printcap configuration has the following format:

lp:sd=/var/spool/lpd/%P
  :force_localhost
  :lp=/var/tmp/lp
lp2:sd=/var/spool/lpd/%P
  :force_localhost
  :lp=/var/tmp/lp2

Both of these queues cause jobs to be written to /var/tmp/lp and /var/tmp/lp2 respectively. This can be tested by trying the following commands:

cp /dev/null /var/tmp/lp
cp /dev/null /var/tmp/lp2
echo hi | lpr -Plp
echo there | lpr -Plp2

The contents of /var/tmp/lp and /var/tmp/lp2 will now be hi\n and there\n respectively.

Modify the printcap so that it has the following contents, and then execute the indicated commands:


new printcap contents

lp:sd=/var/spool/lpd/%P
  :force_localhost
  :lp=lp2@localhost
lp2:sd=/var/spool/lpd/%P
  :force_localhost
  :lp=/var/tmp/lp2

h4: {172} % checkpc -f
h4: {173} % lpc reread

The lp=lp2@localhost means forward any jobs sent to this queue to the spool queue q2 on localhost . To see if this is true, execute the following commands:

h4: {181} % clearstatus
h4: {182} % cp /dev/null /var/tmp/lp
h4: {183} % cp /dev/null /var/tmp/lp2
h4: {184} % echo hi | lpr
h4: {185} % lpq -ll
Printer: lp@h4 (dest lp2@localhost)
 Queue: no printable jobs in queue
 Status: done job 'papowell@h4+19114' transfer to lp2@localhost at 23:41:44.502
 Status: subserver pid 19116 exit status 'JSUCC' at 23:41:44.524
 Status: lp@h4.private: job 'papowell@h4+19114' printed at 23:41:44.525
 Status: job 'papowell@h4+19114' removed at 23:41:44.536
Printer: lp2@h4
 Queue: 1 printable job
 Server: pid 19117 active
 Unspooler: pid 19118 active
 Status: opening device '/var/tmp/lp' at 23:41:44.557
 Status: printing job 'papowell@h4+19114' at 23:41:44.558
 Status: no banner at 23:41:44.558
 Status: printing data file 'dfA019114h4.private', size 3 at 23:41:44.558
 Rank   Owner/ID                  Class Job Files                 Size Time
active papowell@h4+19114            A 19114 (stdin)                  3 23:41:44

As you can see from the status, the print job was forwarded from lp@h4 to the lp2@h4 queue. What is a little surprising is that the lpq command displays status for both queues. This is because LPRng does recursive status lookups when you specify job forwarding with the RFC1179 protocol This is done using the printcap entries :lp=queue@host or :rp=queue:rm=host format. See Protocol Requests and Replies and Dynamic Routing for more information on problems using recursive status lookup and how recursive status lookup can be modified.

6.1 Printer Name and Server IP Address

Options used:

When an LPRng client such as lpr, lpq, lprm, or lprc needs to communicate with a print server, the only information they normally need is:

  1. The spool queue or remote printer to be used in requests to the lpd print server. This is sometimes referred to as the printer or print queue name.
  2. The IP address or hostname of the print server or remote server. This is sometimes called the remote host or simply server.
  3. Options that control how jobs or commands are transferred to the server host. These options might include encryption and client side job filtering. We will discuss these capabilities later.

LPRng has several ways to specify the printer queue and server information.

Command Line -Pprinter@host

The -P printer@host option specifies both the print queue and server.

lpr -Plaser@10.0.0.1
lpq -Plp@myserver

When used as a command line option, the printcap database will not be consulted for other options or information. This allows LPRng clients to function without a printcap database, and without a lpd print server running on their local host. However, options set in the /etc/lpd.conf/ and the compile time defaults will still be used.

Command Line -Pprinter

This form will cause the LPRng clients to look in the /etc/printcap for a printcap entry with the name or alias printer and use the information in that printcap entry. We will discuss the format of the printcap entry in a moment. Example:

lpr -Plp

PRINTER, LPDEST, and NGPRINTER Environment Variables

If no command line option is specified, the LPRng clients will check for the first defined PRINTER, LPDEST, or NGPRINTER environment variable value and will use the value as though specified as a -P$PRINTER command line option.

If the value has the form printer@host the print queue will be printer on server host and not consult the printcap database. If the value has the form printer then the printcap will be searched for a printer printcap entry. For example:

export PRINTER=laser@10.0.0.1; lpr
export PRINTER=pr; lpr

Default Printer From Printcap

If you do not specify a printer on the command line or in the PRINTER environment variable, then LPRng will search the printcap and use the first valid printcap entry as the printer.

Default Printer When No Printcap

If you do not have a /etc/printcap file, then LPRng will use the default_printer and default_remote_host fallback values set in the /etc/lpd.conf file or by the compile time defaults.

Using the fallback values is usually not a desirable event and may indicate that you have a misconfigured host, so the fallback values are usually set by administrators to missingprinter@localhost to provoke an annoying message for users.

LPD Default Printer

For completeness, there is even a default_printer_when_unknown configuration entry for use by LPD when it is given a printer name not in its printcap database. By default, it will look up this name in the database and treat the job as though it was sent to this printer.

6.2 User Identification

Options used:

When an client program sends a command to the lpd server, it sends the name of the user who is originating the request for service. This name is obtained by looking up the UID of the user running the client in the user information database and using this name; if the name is not found the UID value is used.

The lpr -U name (and for lpq, lprm, and lpc) option allows privileged users to cause the client software to use the name value as the originator rather than the UID information. This allows priviledged users to impersonate other users. This is most useful for programs such as Samba and PCNFS, which need to act as proxies for users.

By default, ROOT (UID 0) is the only user that can masquerade as another user. The allow_user_setting=name,name... configuration option can be used to specify a list of names or UIDs that can also perform masquerading. For example, if the Samba server was running as user samba, then allow_user_setting=samba would allow it to specify the name of print job originator as a remote user, and the remote user would not need a login account on the system.

6.3 LPD Server Runnning on Localhost

Options used:

Workstations for personal use or in extremely simple configurations will always run an lpd server on the localhost. This is the most common situation for the majority of new users, and the default LPRng installation sets the default value of the force_localhost configuration parameter to TRUE or to 1. The lpr lpq lprm and lpc will connect to localhost (usually IP address 127.0.0.1) unless explicitly overridden by the command line -Pprinter@host argument.

Larger sites or organizations which want to use a central print server to handle multiple printers or printer sharing may want the clients to connect directly to the server. This can be done either at compile time using the ./configure --disable-force_localhost option and regenerating the software or by setting the force_localhost flag off in the printcap or lpd.conf file:

# Set force_localhost off, send to
# server 10.0.0.1
lp=lp@10.0.0.1:force_localhost@

Next Previous Contents