1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<html>
4  <head>
5    <meta name="generator" content="HTML Tidy, see www.w3.org">
6    <title>Printcap Basics</title>
7    <meta name="GENERATOR" content=
8    "Modular DocBook HTML Stylesheet Version 1.7">
9    <link rel="HOME" title=" LPRng Reference Manual" href=
10    "index.htm">
11    <link rel="UP" title="Print Spooling Tutorial " href=
12    "tutorial.htm">
13    <link rel="PREVIOUS" title=
14    "Job File Format Conversion with Filters" href=
15    "jobfileformatconversion.htm">
16    <link rel="NEXT" title="Banner Printing and the OF filter"
17    href="x3273.htm">
18  </head>
19
20  <body class="SECT1" bgcolor="#FFFFFF" text="#000000" link=
21  "#0000FF" vlink="#840084" alink="#0000FF">
22    <div class="NAVHEADER">
23      <table summary="Header navigation table" width="100%" border=
24      "0" cellpadding="0" cellspacing="0">
25        <tr>
26          <th colspan="3" align="center">LPRng Reference Manual: 5
27          Sep 2003 (For LPRng-3.8.22)</th>
28        </tr>
29
30        <tr>
31          <td width="10%" align="left" valign="bottom"><a href=
32          "jobfileformatconversion.htm" accesskey="P">Prev</a></td>
33
34          <td width="80%" align="center" valign="bottom">Chapter 4.
35          Print Spooling Tutorial</td>
36
37          <td width="10%" align="right" valign="bottom"><a href=
38          "x3273.htm" accesskey="N">Next</a></td>
39        </tr>
40      </table>
41      <hr align="LEFT" width="100%">
42    </div>
43
44    <div class="SECT1">
45      <h1 class="SECT1"><a name="AEN3103">4.11. Printcap
46      Basics</a></h1>
47
48      <p>In the previous sections we have used simple printcap
49      entries to define how to set up filters and pass parameters
50      to them. We will now examine the printcap database in more
51      detail.</p>
52
53      <p>The <b class="APPLICATION">LPRng</b> server and client
54      software gets their configuration information from:</p>
55
56      <ul>
57        <li>
58          <p>Compile time settings which set the default values for
59          the configuration information.</p>
60        </li>
61
62        <li>
63          <p>A <tt class="FILENAME">lpd.conf</tt> file that
64          contains values that override the compile time defaults.
65          This information can effect the behavior of the <b class=
66          "APPLICATION">lpd</b> server and clients.</p>
67        </li>
68
69        <li>
70          <p>Printcap entries which have configuration information
71          for individual print queues. The information in the
72          printcap entries for the queue override the <tt class=
73          "FILENAME">lpd.conf</tt> and compile time defaults. The
74          system printcap file is read first, followed by the user
75          printcap file.</p>
76        </li>
77
78        <li>
79          <p>Command line and environment variable values. These
80          can be used to override or select particular
81          configuration information or to select one of a set of
82          options for use.</p>
83        </li>
84      </ul>
85      <br>
86      <br>
87
88      <p>Each print queue or printer has a name which is used to
89      look up the printcap information for the printer. The <tt
90      class="FILENAME">/etc/printcap</tt> file is the default
91      location for the printcap information, although it can also
92      be obtained from database servers, or generated by programs.
93      See the <a href="secnis.htm">Using Programs To Get Printcap
94      Information</a> section for details.</p>
95
96      <p>We will use a more complex printcap file to explore how <b
97      class="APPLICATION">LPRng</b> gets the printcap information.
98      Put the following lines in the <tt class=
99      "FILENAME">/etc/printcap</tt> file:</p>
100
101      <div class="INFORMALEXAMPLE">
102        <a name="AEN3126"></a>
103<pre class="SCREEN">
104    # client entry
105    lp:tc=.client
106    lp2:tc=.client
107    .client:
108      :lp=%P@localhost
109      :force_localhost
110    
111    lp:server
112      :cm=The Main Print Queue
113      :lp=/tmp/lp
114      :tc=.common
115    
116    lp2:server
117      :cm=The Second Print Queue
118      :lp=/tmp/lp2
119      :tc=.common
120    
121    .common:
122      :sd=/var/spool/lpd/%P
123      :mx=0
124</pre>
125      </div>
126      The <tt class="COMMAND">lpc client</tt> command is very
127      useful to see how <b class="APPLICATION">LPRng</b> uses this
128      printcap information: 
129
130      <div class="INFORMALEXAMPLE">
131        <a name="AEN3130"></a>
132<pre class="SCREEN">
133    <samp class="PROMPT">h4: {214} %</samp> <kbd class=
134"USERINPUT">lpc client</kbd>
135    Config
136    <samp class="PROMPT">h4: {215} %</samp> <kbd class=
137"USERINPUT">lpc client all</kbd>
138    Config
139     :lpd_port=2000
140     :printcap_path=/var/tmp/LPD/printcap
141    
142    Names
143     :.client=.client
144     :.common=.common
145     :lp=lp
146     :lp2=lp2
147     :main=lp
148    
149    All
150     :lp
151     :lp2
152    
153    Printcap Information
154    lp|main
155     :force_localhost
156     :lp=lp@localhost
157    lp2
158     :force_localhost
159     :lp=lp2@localhost
160</pre>
161      </div>
162      <br>
163      <br>
164
165      <p>The <tt class="COMMAND">lpc client all</tt> command shows
166      all of the configuration and printcap information, and is the
167      handiest one for system debugging and diagnostics. The <span
168      class="emphasis"><i class="EMPHASIS">Name</i></span>
169      information is the names of the printcap entries that have
170      been found in the database and is listed in sorted order. The
171      <span class="emphasis"><i class="EMPHASIS">All</i></span> are
172      entries that correspond to actual queues or printers and are
173      listed in the order that they appear in the printcap or
174      according to an order specified by the system administrator.
175      (See the <a href="printcappath.htm#ALLPC"><var class=
176      "LITERAL">all</var> Printcap Entry</a> for details.)</p>
177
178      <div class="SECT2">
179        <h2 class="SECT2"><a name="AEN3142">4.11.1. Printcap
180        Processing Format</a></h2>
181
182        <p>Queue or printer names must start with an alphanumeric
183        character, and contain only alphanumerics, hyphens (<var
184        class="LITERAL">-</var>) and underscores (<var class=
185        "LITERAL">_</var>). To avoid known and nasty problems with
186        sending and receiving print jobs from case sensitive and
187        case insensitive systems, <b class="APPLICATION">LPRng</b>
188        brutally lowercases all printcap entry names and printer
189        names.</p>
190
191        <p>The printcap file is processed by reading it line by
192        line and composing the individual printcap entries. Each
193        entry has an name and one or more aliases. The entries in
194        the printcap assign values to options. These can have the
195        format:</p>
196
197        <div class="INFORMALEXAMPLE">
198          <a name="AEN3149"></a>
199<pre class="SCREEN">
200    option=string value \n with escapes
201    flag         # equivalent to flag=1
202    flag@        # equivalent to flag=0
203    option#value # equivalent to option=value
204</pre>
205        </div>
206        <br>
207        <br>
208
209        <p>An option will have the last value that occurs in the
210        printcap entry.</p>
211
212        <p>Our example shows the use of the <var class=
213        "LITERAL">tc</var> (<span class="emphasis"><i class=
214        "EMPHASIS">t</i></span>ermcap in<span class="emphasis"><i
215        class="EMPHASIS">c</i></span>lude) facility. The <var
216        class="LITERAL">:tc</var> value is a list of printcap
217        entries that should be prefixed to the <span class=
218        "emphasis"><i class="EMPHASIS">start</i></span> of the
219        printcap entry in which it appears. This allows options to
220        be set in the printcap entry which will override the values
221        in the <var class="LITERAL">:tc</var> included entry. For
222        convenience, the options are displayed in sorted order.</p>
223
224        <p>The <b class="APPLICATION">LPRng</b> clients and <b
225        class="APPLICATION">lpd</b> server may require a different
226        set of options for the same spool queue. The clients
227        require options whose values tell the clients how the
228        contact the <b class="APPLICATION">lpd</b> server and
229        transfer a print job or query to it. The <b class=
230        "APPLICATION">lpd</b> server needs options that tell it how
231        to either print a job or forward it to another <b class=
232        "APPLICATION">lpd</b> server. The <var class=
233        "LITERAL">:client</var> or <var class=
234        "LITERAL">:server</var> option marks a printcap entry as
235        for client or <b class="APPLICATION">lpd</b> server use
236        only; unmarked entries are used by both server and client.
237        The <tt class="COMMAND">lpc client</tt> command shows the
238        printcap information that the <b class=
239        "APPLICATION">LPRng</b> clients would use. For example,
240        here is what the <b class="APPLICATION">lpd</b> server
241        would use:</p>
242
243        <div class="INFORMALEXAMPLE">
244          <a name="AEN3171"></a>
245<pre class="SCREEN">
246    <samp class="PROMPT">h4: {216} %</samp> <kbd class=
247"USERINPUT">lpc server all</kbd>
248    Config
249     :lpd_port=2000
250     :printcap_path=/var/tmp/LPD/printcap
251    
252    Names
253     :.client=.client
254     :.common=.common
255     :lp=lp
256     :lp2=lp2
257     :main=lp
258    
259    All
260     :lp
261     :lp2
262    
263    Printcap Information
264    lp|main
265     :cm=The Main Print Queue
266     :force_localhost
267     :lp=/tmp/lp
268     :mx=0
269     :sd=/var/spool/lpd/%P
270     :server
271    lp2
272     :cm=The Second Print Queue
273     :force_localhost
274     :lp=/tmp/lp2
275     :mx=0
276     :sd=/var/spool/lpd/%P
277     :server
278</pre>
279        </div>
280        <br>
281        <br>
282
283        <p>When we select the <var class="LITERAL">server</var>
284        printcap information, we see that the <var class=
285        "LITERAL">:sd</var> option has been added, and the <var
286        class="LITERAL">:lp</var> replaced with new values.</p>
287
288        <p>We can use the <var class="LITERAL">:oh</var> (<var
289        class="LITERAL">o</var>n this <var class=
290        "LITERAL">h</var>ost) option to mark printcap entries for
291        use by a selected set of hosts. For example:</p>
292
293        <div class="INFORMALEXAMPLE">
294          <a name="AEN3183"></a>
295<pre class="SCREEN">
296    lp:oh=10.0.0.0/255.255.255.0,*.private,!10.0.0.10
297      :lp=%P@10.0.0.10
298</pre>
299        </div>
300        <br>
301        <br>
302
303        <p>The <var class="LITERAL">:oh</var> option takes a list
304        of IP addresses and masks or glob patterns, and applies
305        these to the IP addresses or list of Fully Qualified Domain
306        Names for the current host. If there is a for at least one
307        IP address or pattern in the list match then the entry is
308        used. An exclamation mark (<var class="LITERAL">!</var>)
309        inverts the sense of the match, and the entry is used if
310        the match fails.</p>
311
312        <p>Finally, we can use the <var class=
313        "LITERAL">wildcard</var> facility to cause a default
314        printcap entry to be used:</p>
315
316        <div class="INFORMALEXAMPLE">
317          <a name="AEN3190"></a>
318<pre class="SCREEN">
319    lp|*:cm=Wildcard Alias - %P=lp, %Q=wanted
320      :lp=%P@10.0.0.10
321    *:cm=Wildcard Name- %P=wanted, %Q=wanted
322      :lp=%P@10.0.0.10
323</pre>
324        </div>
325        <br>
326        <br>
327
328        <p>The <b class="APPLICATION">LPRng</b> software first
329        searches the printcap information for an exact match. If
330        none is found then it searches for the first wildcard entry
331        that matches the printer name. If the wildcard is used as
332        an alias, then the printcap entry is simply selected for
333        use, with the printer name and queue name selected as shown
334        above. We can also use partial matching as well:</p>
335
336        <div class="INFORMALEXAMPLE">
337          <a name="AEN3194"></a>
338<pre class="SCREEN">
339    lp|lp_*
340      :lp=%P@10.0.0.10
341    qt|qt_*
342      :lp=%P@10.0.0.12
343</pre>
344        </div>
345        <br>
346        <br>
347
348        <p>In the example above the first entry matches <var class=
349        "LITERAL">lp</var> and all printer names starting with <var
350        class="LITERAL">lp_</var>, while the second entry matches
351        <var class="LITERAL">qt</var> and all printer names
352        starting with <var class="LITERAL">qt_</var>. This can be
353        useful when setting up a family of spool queues as
354        discussed in later sections.</p>
355      </div>
356
357      <div class="SECT2">
358        <h2 class="SECT2"><a name="AEN3201">4.11.2. Printcap
359        Information From Programs and Databases</a></h2>
360
361        <p>There many administrators store system information on a
362        database server and having programs or utilities get their
363        configuration information from this server. The use of the
364        database allows easier system administration and also
365        centralizes the administration. Rather than build in the
366        various types of database access, the LPRng software allows
367        the use of programs to obtain printcap information. This
368        not only allows any type of database to be used, but also
369        removes any legal or license restrictions on the
370        redistribution of the actual software.</p>
371
372        <p>We will use very simple example to show how you can use
373        a program to get printcap information. First, you must
374        configure the <b class="APPLICATION">LPRng</b> software to
375        use a program to get the filter information. This is done
376        by setting a value in the <tt class=
377        "FILENAME">lpc.conf</tt> file (usually <tt class=
378        "FILENAME">/etc/lpd.conf</tt> or <tt class=
379        "FILENAME">/usr/local/etc/lpd.conf</tt>). Copy your <tt
380        class="FILENAME">lpd.conf</tt> file to <tt class=
381        "FILENAME">lpd.conf.bak</tt> and then add the following
382        line to the end of the file:</p>
383
384        <div class="INFORMALEXAMPLE">
385          <a name="AEN3211"></a>
386<pre class="SCREEN">
387    printcap_path=|/tmp/getpc
388    
389    <samp class="PROMPT">h4: {217} %</samp> <kbd class=
390"USERINPUT">cd /etc</kbd>
391    <samp class="PROMPT">h4: {218} %</samp> <kbd class=
392"USERINPUT">cp lpd.conf lpd.conf.bak</kbd>
393    <samp class="PROMPT">h4: {219} %</samp> <kbd class=
394"USERINPUT">echo 'printcap_path=|/tmp/getpc' &gt;&gt;lpd.conf</kbd>
395</pre>
396        </div>
397        <br>
398        <br>
399
400        <p>Next, edit the <tt class="FILENAME">/tmp/getpc</tt> file
401        and set its values as shown below.</p>
402
403        <div class="INFORMALEXAMPLE">
404          <a name="AEN3221"></a>
405<pre class="SCREEN">
406    set /tmp/getpc:
407    
408      #!/bin/sh
409      # /tmp/getpc
410      echo PROG $0 "$@" &gt;&gt;/tmp/trace
411      cat &gt;&gt;/tmp/trace
412      cat &lt;&lt;EOF
413      lp:lp=test@host
414      EOF
415      exit 0
416    
417    <samp class="PROMPT">h4: {220} %</samp> <kbd class=
418"USERINPUT">chmod 755 /tmp/getpc</kbd>
419    <samp class="PROMPT">h4: {221} %</samp> <kbd class=
420"USERINPUT">echo testing | /tmp/getpc -aoption</kbd>
421    lp:lp=test@host
422    <samp class="PROMPT">h4: {222} %</samp> <kbd class=
423"USERINPUT">cat /tmp/trace</kbd>
424    PROG /tmp/getpc -aoption
425    testing
426</pre>
427        </div>
428        <br>
429        <br>
430
431        <p>After you have tested the <b class=
432        "APPLICATION">getpc</b> script, use the <tt class=
433        "COMMAND">lpc client all</tt> command:</p>
434
435        <div class="INFORMALEXAMPLE">
436          <a name="AEN3232"></a>
437<pre class="SCREEN">
438    <samp class="PROMPT">h4: {223} %</samp> <kbd class=
439"USERINPUT">lpc client all</kbd>
440    Config
441     :lockfile=/var/tmp/LPD/lpd
442     :lpd_port=2000
443     :printcap_path=|/tmp/getpc
444    
445    Names
446     :lp=lp
447    
448    All
449     :lp
450    
451    Printcap Information
452    lp
453     :lp=test@host
454    <samp class="PROMPT">h4: {224} %</samp> <kbd class=
455"USERINPUT">cat /tmp/trace</kbd>
456    <samp class="PROMPT">h4: {225} %</samp> <kbd class=
457"USERINPUT">cat /tmp/trace</kbd>
458    PROG /tmp/getpc -Pall -aacct -l66 -sstatus \
459      -t2000-05-05-08:40:51.000 -w80 -x0 -y0 acct
460    all
461    PROG /tmp/getpc -Pall -aacct -l66 -sstatus \
462      -t2000-05-05-08:40:51.000 -w80 -x0 -y0 acct
463    *
464</pre>
465        </div>
466        <br>
467        <br>
468
469        <p>As seen from the <tt class="FILENAME">/tmp/trace</tt>
470        file, the <tt class="COMMAND">getpc</tt> program is invoked
471        with the standard filter parameters. The <var class=
472        "LITERAL">-P</var> command line literal is set to the name
473        of the printcap entry and the name of the entry is written
474        to the filter's <acronym class="ACRONYM">STDIN</acronym>.
475        If the entry is not found, then the wildcard printcap entry
476        will be requested. The <var class="LITERAL">-P</var>
477        literal is <span class="emphasis"><i class=
478        "EMPHASIS">not</i></span> set to <var class=
479        "LITERAL">*</var>, as this has the possibility of opening a
480        security loophole when a shell script parses the filter's
481        command line options.</p>
482
483        <p>You restore the original <tt class=
484        "FILENAME">lpd.conf</tt> file to restore the system to
485        normal operation.</p>
486
487        <div class="INFORMALEXAMPLE">
488          <a name="AEN3250"></a>
489<pre class="SCREEN">
490    <samp class="PROMPT">h4: {226} %</samp> <kbd class=
491"USERINPUT">cd /etc</kbd>
492    <samp class="PROMPT">h4: {227} %</samp> <kbd class=
493"USERINPUT">cp lpd.conf.bak lpd.conf</kbd>
494</pre>
495        </div>
496        <br>
497        <br>
498
499        <p>When using the program method to return information,
500        special consideration should be given to the <var class=
501        "LITERAL">all</var> request. If there is not an explicit
502        <var class="LITERAL">all</var> entry, then the program
503        should take appropriate steps to enumerate the values in
504        the database, or report that there is a missing <var class=
505        "LITERAL">all</var> entry to the appropriate administrative
506        authority.</p>
507      </div>
508
509      <div class="SECT2">
510        <h2 class="SECT2"><a name="AEN3260">4.11.3. User Printcap
511        Information</a></h2>
512
513        <p>In addition to the system printcap, each user can define
514        a private printcap file that will be read after the system
515        printcap. Users can define <b class="APPLICATION">LPRng</b>
516        client entries and can augment the system printcap
517        information.</p>
518
519        <p>By default, <tt class="FILENAME">${HOME}/.printcap</tt>
520        is the the user printcap file. Here is a simple example of
521        a user printcap file.</p>
522
523        <div class="INFORMALEXAMPLE">
524          <a name="AEN3266"></a>
525<pre class="SCREEN">
526    # remote printer - default
527    lp:lp=raw@localhost
528      :ifhp=model=laserjet4
529      :filter=/usr/local/libexec/filters/ifhp
530    # direct connection to printer over TCP/IP connection
531    lp:lp=10.0.0.5%9100
532      :direct
533      :ifhp=model=phaser
534      :filter=/usr/local/libexec/filters/ifhp
535</pre>
536        </div>
537
538        <p>The two examples show how a simple printer definition
539        can be created. The first example shows how to create a
540        simple way to send a file directly to a remote print queue
541        after passing it through a filter. This is usually called
542        <span class="emphasis"><i class="EMPHASIS">client
543        side</i></span> filtering.</p>
544
545        <p>The second example is more interesting. Here we do the
546        same thing, but we open a connection to the remote port on
547        a host and send the print job. We do not spool the print
548        job but send it directly. This is called <span class=
549        "emphasis"><i class="EMPHASIS">lightweight lpr</i></span>
550        printing.</p>
551
552        <p>While the user printcap file is read after the system
553        printcap file, the order of printcap entries is modified so
554        that any entries that appeared in the user printcap file
555        will appear before entries in the system printcap file.
556        This allows users to modify the order in which printer
557        entries are displayed.</p>
558      </div>
559    </div>
560
561    <div class="NAVFOOTER">
562      <hr align="LEFT" width="100%">
563
564      <table summary="Footer navigation table" width="100%" border=
565      "0" cellpadding="0" cellspacing="0">
566        <tr>
567          <td width="33%" align="left" valign="top"><a href=
568          "jobfileformatconversion.htm" accesskey="P">Prev</a></td>
569
570          <td width="34%" align="center" valign="top"><a href=
571          "index.htm" accesskey="H">Home</a></td>
572
573          <td width="33%" align="right" valign="top"><a href=
574          "x3273.htm" accesskey="N">Next</a></td>
575        </tr>
576
577        <tr>
578          <td width="33%" align="left" valign="top">Job File Format
579          Conversion with Filters</td>
580
581          <td width="34%" align="center" valign="top"><a href=
582          "tutorial.htm" accesskey="U">Up</a></td>
583
584          <td width="33%" align="right" valign="top">Banner
585          Printing and the OF filter</td>
586        </tr>
587      </table>
588    </div>
589  </body>
590</html>
591
592