<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<title>Printcap Basics</title>
<meta name="GENERATOR" content=
"Modular DocBook HTML Stylesheet Version 1.7">
<link rel="HOME" title=" LPRng Reference Manual" href=
"index.htm">
<link rel="UP" title="Print Spooling Tutorial " href=
"tutorial.htm">
<link rel="PREVIOUS" title=
"Job File Format Conversion with Filters" href=
"jobfileformatconversion.htm">
<link rel="NEXT" title="Banner Printing and the OF filter"
href="x3275.htm">
</head>
<body class="SECT1" bgcolor="#FFFFFF" text="#000000" link=
"#0000FF" vlink="#840084" alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border=
"0" cellpadding="0" cellspacing="0">
<tr>
<th colspan="3" align="center">LPRng Reference Manual: 24
Sep 2004 (For LPRng-3.8.28)</th>
</tr>
<tr>
<td width="10%" align="left" valign="bottom"><a href=
"jobfileformatconversion.htm" accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom">Chapter 4.
Print Spooling Tutorial</td>
<td width="10%" align="right" valign="bottom"><a href=
"x3275.htm" accesskey="N">Next</a></td>
</tr>
</table>
<hr align="LEFT" width="100%">
</div>
<div class="SECT1">
<h1 class="SECT1"><a name="AEN3105">4.11. Printcap
Basics</a></h1>
<p>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.</p>
<p>The <b class="APPLICATION">LPRng</b> server and client
software gets their configuration information from:</p>
<ul>
<li>
<p>Compile time settings which set the default values for
the configuration information.</p>
</li>
<li>
<p>A <tt class="FILENAME">lpd.conf</tt> file that
contains values that override the compile time defaults.
This information can effect the behavior of the <b class=
"APPLICATION">lpd</b> server and clients.</p>
</li>
<li>
<p>Printcap entries which have configuration information
for individual print queues. The information in the
printcap entries for the queue override the <tt class=
"FILENAME">lpd.conf</tt> and compile time defaults. The
system printcap file is read first, followed by the user
printcap file.</p>
</li>
<li>
<p>Command line and environment variable values. These
can be used to override or select particular
configuration information or to select one of a set of
options for use.</p>
</li>
</ul>
<br>
<br>
<p>Each print queue or printer has a name which is used to
look up the printcap information for the printer. The <tt
class="FILENAME">/etc/printcap</tt> file is the default
location for the printcap information, although it can also
be obtained from database servers, or generated by programs.
See the <a href="secnis.htm">Using Programs To Get Printcap
Information</a> section for details.</p>
<p>We will use a more complex printcap file to explore how <b
class="APPLICATION">LPRng</b> gets the printcap information.
Put the following lines in the <tt class=
"FILENAME">/etc/printcap</tt> file:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3128"></a>
<pre class="SCREEN">
# 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
</pre>
</div>
The <tt class="COMMAND">lpc client</tt> command is very
useful to see how <b class="APPLICATION">LPRng</b> uses this
printcap information:
<div class="INFORMALEXAMPLE">
<a name="AEN3132"></a>
<pre class="SCREEN">
<samp class="PROMPT">h4: {214} %</samp> <kbd class=
"USERINPUT">lpc client</kbd>
Config
<samp class="PROMPT">h4: {215} %</samp> <kbd class=
"USERINPUT">lpc client all</kbd>
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=lp@localhost
lp2
:force_localhost
:lp=lp2@localhost
</pre>
</div>
<br>
<br>
<p>The <tt class="COMMAND">lpc client all</tt> command shows
all of the configuration and printcap information, and is the
handiest one for system debugging and diagnostics. The <span
class="emphasis"><i class="EMPHASIS">Name</i></span>
information is the names of the printcap entries that have
been found in the database and is listed in sorted order. The
<span class="emphasis"><i class="EMPHASIS">All</i></span> 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 <a href="printcappath.htm#ALLPC"><var class=
"LITERAL">all</var> Printcap Entry</a> for details.)</p>
<div class="SECT2">
<h2 class="SECT2"><a name="AEN3144">4.11.1. Printcap
Processing Format</a></h2>
<p>Queue or printer names must start with an alphanumeric
character, and contain only alphanumerics, hyphens (<var
class="LITERAL">-</var>) and underscores (<var class=
"LITERAL">_</var>). To avoid known and nasty problems with
sending and receiving print jobs from case sensitive and
case insensitive systems, <b class="APPLICATION">LPRng</b>
brutally lowercases all printcap entry names and printer
names.</p>
<p>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:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3151"></a>
<pre class="SCREEN">
option=string value \n with escapes
flag # equivalent to flag=1
flag@ # equivalent to flag=0
option#value # equivalent to option=value
</pre>
</div>
<br>
<br>
<p>An option will have the last value that occurs in the
printcap entry.</p>
<p>Our example shows the use of the <var class=
"LITERAL">tc</var> (<span class="emphasis"><i class=
"EMPHASIS">t</i></span>ermcap in<span class="emphasis"><i
class="EMPHASIS">c</i></span>lude) facility. The <var
class="LITERAL">:tc</var> value is a list of printcap
entries that should be prefixed to the <span class=
"emphasis"><i class="EMPHASIS">start</i></span> 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 <var class="LITERAL">:tc</var> included entry. For
convenience, the options are displayed in sorted order.</p>
<p>The <b class="APPLICATION">LPRng</b> clients and <b
class="APPLICATION">lpd</b> 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 <b class="APPLICATION">lpd</b> server and
transfer a print job or query to it. The <b class=
"APPLICATION">lpd</b> server needs options that tell it how
to either print a job or forward it to another <b class=
"APPLICATION">lpd</b> server. The <var class=
"LITERAL">:client</var> or <var class=
"LITERAL">:server</var> option marks a printcap entry as
for client or <b class="APPLICATION">lpd</b> server use
only; unmarked entries are used by both server and client.
The <tt class="COMMAND">lpc client</tt> command shows the
printcap information that the <b class=
"APPLICATION">LPRng</b> clients would use. For example,
here is what the <b class="APPLICATION">lpd</b> server
would use:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3173"></a>
<pre class="SCREEN">
<samp class="PROMPT">h4: {216} %</samp> <kbd class=
"USERINPUT">lpc server all</kbd>
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
</pre>
</div>
<br>
<br>
<p>When we select the <var class="LITERAL">server</var>
printcap information, we see that the <var class=
"LITERAL">:sd</var> option has been added, and the <var
class="LITERAL">:lp</var> replaced with new values.</p>
<p>We can use the <var class="LITERAL">:oh</var> (<var
class="LITERAL">o</var>n this <var class=
"LITERAL">h</var>ost) option to mark printcap entries for
use by a selected set of hosts. For example:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3185"></a>
<pre class="SCREEN">
lp:oh=10.0.0.0/255.255.255.0,*.private,!10.0.0.10
:lp=%P@10.0.0.10
</pre>
</div>
<br>
<br>
<p>The <var class="LITERAL">:oh</var> 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 (<var class="LITERAL">!</var>)
inverts the sense of the match, and the entry is used if
the match fails.</p>
<p>Finally, we can use the <var class=
"LITERAL">wildcard</var> facility to cause a default
printcap entry to be used:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3192"></a>
<pre class="SCREEN">
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
</pre>
</div>
<br>
<br>
<p>The <b class="APPLICATION">LPRng</b> 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:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3196"></a>
<pre class="SCREEN">
lp|lp_*
:lp=%P@10.0.0.10
qt|qt_*
:lp=%P@10.0.0.12
</pre>
</div>
<br>
<br>
<p>In the example above the first entry matches <var class=
"LITERAL">lp</var> and all printer names starting with <var
class="LITERAL">lp_</var>, while the second entry matches
<var class="LITERAL">qt</var> and all printer names
starting with <var class="LITERAL">qt_</var>. This can be
useful when setting up a family of spool queues as
discussed in later sections.</p>
</div>
<div class="SECT2">
<h2 class="SECT2"><a name="AEN3203">4.11.2. Printcap
Information From Programs and Databases</a></h2>
<p>There many administrators store system information on a
database server and having programs or utilities get their
configuration information from this server. The use of the
database allows easier system administration and also
centralizes the administration. Rather than build in the
various types of database access, the LPRng software allows
the use of programs to obtain printcap information. This
not only allows any type of database to be used, but also
removes any legal or license restrictions on the
redistribution of the actual software.</p>
<p>We will use very simple example to show how you can use
a program to get printcap information. First, you must
configure the <b class="APPLICATION">LPRng</b> software to
use a program to get the filter information. This is done
by setting a value in the <tt class=
"FILENAME">lpc.conf</tt> file (usually <tt class=
"FILENAME">/etc/lpd.conf</tt> or <tt class=
"FILENAME">/usr/local/etc/lpd.conf</tt>). Copy your <tt
class="FILENAME">lpd.conf</tt> file to <tt class=
"FILENAME">lpd.conf.bak</tt> and then add the following
line to the end of the file:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3213"></a>
<pre class="SCREEN">
printcap_path=|/tmp/getpc
<samp class="PROMPT">h4: {217} %</samp> <kbd class=
"USERINPUT">cd /etc</kbd>
<samp class="PROMPT">h4: {218} %</samp> <kbd class=
"USERINPUT">cp lpd.conf lpd.conf.bak</kbd>
<samp class="PROMPT">h4: {219} %</samp> <kbd class=
"USERINPUT">echo 'printcap_path=|/tmp/getpc' >>lpd.conf</kbd>
</pre>
</div>
<br>
<br>
<p>Next, edit the <tt class="FILENAME">/tmp/getpc</tt> file
and set its values as shown below.</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3223"></a>
<pre class="SCREEN">
set /tmp/getpc:
#!/bin/sh
# /tmp/getpc
echo PROG $0 "$@" >>/tmp/trace
cat >>/tmp/trace
cat <<EOF
lp:lp=test@host
EOF
exit 0
<samp class="PROMPT">h4: {220} %</samp> <kbd class=
"USERINPUT">chmod 755 /tmp/getpc</kbd>
<samp class="PROMPT">h4: {221} %</samp> <kbd class=
"USERINPUT">echo testing | /tmp/getpc -aoption</kbd>
lp:lp=test@host
<samp class="PROMPT">h4: {222} %</samp> <kbd class=
"USERINPUT">cat /tmp/trace</kbd>
PROG /tmp/getpc -aoption
testing
</pre>
</div>
<br>
<br>
<p>After you have tested the <b class=
"APPLICATION">getpc</b> script, use the <tt class=
"COMMAND">lpc client all</tt> command:</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3234"></a>
<pre class="SCREEN">
<samp class="PROMPT">h4: {223} %</samp> <kbd class=
"USERINPUT">lpc client all</kbd>
Config
:lockfile=/var/tmp/LPD/lpd
:lpd_port=2000
:printcap_path=|/tmp/getpc
Names
:lp=lp
All
:lp
Printcap Information
lp
:lp=test@host
<samp class="PROMPT">h4: {224} %</samp> <kbd class=
"USERINPUT">cat /tmp/trace</kbd>
<samp class="PROMPT">h4: {225} %</samp> <kbd class=
"USERINPUT">cat /tmp/trace</kbd>
PROG /tmp/getpc -Pall -aacct -l66 -sstatus \
-t2000-05-05-08:40:51.000 -w80 -x0 -y0 acct
all
PROG /tmp/getpc -Pall -aacct -l66 -sstatus \
-t2000-05-05-08:40:51.000 -w80 -x0 -y0 acct
*
</pre>
</div>
<br>
<br>
<p>As seen from the <tt class="FILENAME">/tmp/trace</tt>
file, the <tt class="COMMAND">getpc</tt> program is invoked
with the standard filter parameters. The <var class=
"LITERAL">-P</var> command line literal is set to the name
of the printcap entry and the name of the entry is written
to the filter's <acronym class="ACRONYM">STDIN</acronym>.
If the entry is not found, then the wildcard printcap entry
will be requested. The <var class="LITERAL">-P</var>
literal is <span class="emphasis"><i class=
"EMPHASIS">not</i></span> set to <var class=
"LITERAL">*</var>, as this has the possibility of opening a
security loophole when a shell script parses the filter's
command line options.</p>
<p>You restore the original <tt class=
"FILENAME">lpd.conf</tt> file to restore the system to
normal operation.</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3252"></a>
<pre class="SCREEN">
<samp class="PROMPT">h4: {226} %</samp> <kbd class=
"USERINPUT">cd /etc</kbd>
<samp class="PROMPT">h4: {227} %</samp> <kbd class=
"USERINPUT">cp lpd.conf.bak lpd.conf</kbd>
</pre>
</div>
<br>
<br>
<p>When using the program method to return information,
special consideration should be given to the <var class=
"LITERAL">all</var> request. If there is not an explicit
<var class="LITERAL">all</var> entry, then the program
should take appropriate steps to enumerate the values in
the database, or report that there is a missing <var class=
"LITERAL">all</var> entry to the appropriate administrative
authority.</p>
</div>
<div class="SECT2">
<h2 class="SECT2"><a name="AEN3262">4.11.3. User Printcap
Information</a></h2>
<p>In addition to the system printcap, each user can define
a private printcap file that will be read after the system
printcap. Users can define <b class="APPLICATION">LPRng</b>
client entries and can augment the system printcap
information.</p>
<p>By default, <tt class="FILENAME">${HOME}/.printcap</tt>
is the the user printcap file. Here is a simple example of
a user printcap file.</p>
<div class="INFORMALEXAMPLE">
<a name="AEN3268"></a>
<pre class="SCREEN">
# remote printer - default
lp:lp=raw@localhost
:ifhp=model=laserjet4
:filter=/usr/local/libexec/filters/ifhp
# direct connection to printer over TCP/IP connection
lp:lp=10.0.0.5%9100
:direct
:ifhp=model=phaser
:filter=/usr/local/libexec/filters/ifhp
</pre>
</div>
<p>The two examples show how a simple printer definition
can be created. The first example shows how to create a
simple way to send a file directly to a remote print queue
after passing it through a filter. This is usually called
<span class="emphasis"><i class="EMPHASIS">client
side</i></span> filtering.</p>
<p>The second example is more interesting. Here we do the
same thing, but we open a connection to the remote port on
a host and send the print job. We do not spool the print
job but send it directly. This is called <span class=
"emphasis"><i class="EMPHASIS">lightweight lpr</i></span>
printing.</p>
<p>While the user printcap file is read after the system
printcap file, the order of printcap entries is modified so
that any entries that appeared in the user printcap file
will appear before entries in the system printcap file.
This allows users to modify the order in which printer
entries are displayed.</p>
</div>
</div>
<div class="NAVFOOTER">
<hr align="LEFT" width="100%">
<table summary="Footer navigation table" width="100%" border=
"0" cellpadding="0" cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href=
"jobfileformatconversion.htm" accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href=
"index.htm" accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href=
"x3275.htm" accesskey="N">Next</a></td>
</tr>
<tr>
<td width="33%" align="left" valign="top">Job File Format
Conversion with Filters</td>
<td width="34%" align="center" valign="top"><a href=
"tutorial.htm" accesskey="U">Up</a></td>
<td width="33%" align="right" valign="top">Banner
Printing and the OF filter</td>
</tr>
</table>
</div>
</body>
</html>
syntax highlighted by Code2HTML, v. 0.9.1