File: secnis.htm

package info (click to toggle)
lprng 3.8.10-1.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 13,076 kB
  • ctags: 4,348
  • sloc: ansic: 35,394; sh: 10,756; perl: 2,210; makefile: 1,046
file content (481 lines) | stat: -rw-r--r-- 15,633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content="HTML Tidy, see www.w3.org">
    <title>Using Programs To Get Printcap Information</title>
    <meta name="GENERATOR" content=
    "Modular DocBook HTML Stylesheet Version 1.71 ">
    <link rel="HOME" title=" LPRng-HOWTO" href="index.htm">
    <link rel="UP" title="Printcap Database " href=
    "printcapref.htm">
    <link rel="PREVIOUS" title=
    "Management Strategies for Large Installations" href=
    "x6065.htm">
    <link rel="NEXT" title="Lexmark Printers" href="x6175.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-HOWTO: 1 Apr 2002
          (For LPRng-3.8.10)</th>
        </tr>

        <tr>
          <td width="10%" align="left" valign="bottom"><a href=
          "x6065.htm" accesskey="P">Prev</a></td>

          <td width="80%" align="center" valign="bottom">Chapter
          12. Printcap Database</td>

          <td width="10%" align="right" valign="bottom"><a href=
          "x6175.htm" accesskey="N">Next</a></td>
        </tr>
      </table>
      <hr align="LEFT" width="100%">
    </div>

    <div class="SECT1">
      <h1 class="SECT1"><a name="SECNIS">12.18. Using Programs To
      Get Printcap Information</a></h1>

      <p>In the <tt class="FILENAME">lpd.conf</tt> file you can
      specify:</p>

      <div class="INFORMALEXAMPLE">
        <a name="AEN6077"></a>
<pre class="SCREEN">
    printcap_path=|program
</pre>
      </div>
      This will cause the <b class="APPLICATION">LPRng</b> software
      to execute the specified program, which should then provide
      the printcap information. The program is invoked with the
      standard filter options, and has the name of the printcap
      entry provided on <span class="ACRONYM">STDIN</span>. The
      filter should supply the printcap information on <tt class=
      "LITERAL">stdout</tt> and exit with a 0 (success) error code.
      By convention, the printcap name 'all' requests a printcap
      entry that lists all printers.<br>
      <br>

      <p>This technique has been used to interface to the Sun
      Microsystem NIS and NIS+ databases with great success. By
      having the invoked program a simple shell script or front end
      to the <tt class="LITERAL">nismatch</tt> or <tt class=
      "LITERAL">ypmatch</tt> programs, the complexity of
      incorporating vendor specific code is avoided.</p>

      <div class="SECT2">
        <h2 class="SECT2"><a name="AEN6085">12.18.1. How to use NIS
        and <b class="APPLICATION">LPRng</b></a></h2>

        <p>This note is based on material sent to the <a href=
        "maillist.htm">lprng@lprng.com</a> mailing list by Paul
        Haldane <tt class="EMAIL">&lt;<a href=
        "mailto:paul@ucs.ed.ac.uk">paul@ucs.ed.ac.uk</a>&gt;</tt>.</p>

        <p>We generally don't use NIS for printcap files (we've
        moved to hesiod) but I can show you what we've done in the
        past.</p>

        <p>The input to NIS is a normal printcap file:</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6093"></a>
<pre class="SCREEN">
    # Classical printcap entry
    lp23a|lp23|lp|main printhost printer - KB, EUCS front Door:\
            :lp=lp23a@printhost:\
            :sd=/var/spool/lpr/lp23a:
    
    #lprng printcap entry
    lplabel|lpl|TEST - Labels printer:
            :lp=:rm=printhost:rp=lplabel:
            :sd=/var/spool/lpr/lplabel:
            :rg=lpadm:mx=1:
</pre>
        </div>
        <br>
        <br>

        <p>To build the NIS printcap.byname map we add the
        following to the NIS makefile (along the other bits and
        pieces that the makefile needs to know about a new
        map).</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6096"></a>
<pre class="SCREEN">
    PRINTCAP=${sysconfdir}/printcap
    # warning : [  ] is actually [&lt;space&gt;&lt;tab&gt;] in the script
    printcap.time: $(PRINTCAP) Makefile
      if [ -f $(PRINTCAP) ]; then \
        sed &lt; $(PRINTCAP) \
          -e 's/[   ][  ]*$$//' -e '/\\$$/s/\\$$/ /' \
        | awk '$$1 ~ /^#/{next;} $$1 ~ /^[:|]/ {printf "%s", $$0; next;} \
            {printf "\n%s", $$0 }' \
        | sed -e 's/[   ]*:[  ]*:/:/g' -e 's/[  ]*|[  ]*/|/g' \
          -e '/^[   ]*$$/d' &gt; .printcap.$$$$; \
        cat .printcap.$$$$; \
        if [ $$? = 0 -a -s .printcap.$$$$ ]; then \
          awk &lt;.printcap.$$$$ '{ FS=":"; OFS="\t"; } { \
              n = split($$1, names, "|"); \
              for (i=1; i&lt;=n; i++) \
                  if (length(names[i]) &gt; 0 \
                  &amp;&amp; names[i] !~ /[ \t]/) \
                      print names[i], $$0; \
          }' | $(MAKEDBM) - $(YPDBDIR)/$(DOM)/printcap.byname; \
          awk &lt;.printcap.$$$$ '{ FS=":"; OFS="\t"; } { \
              n = split($$1, names, "|"); \
              if (n &amp;&amp; length(names[1]) &gt; 0 &amp;&amp; names[1] !~ /[ \t]/) \
                  print names[1], $$0; \
          }' | $(MAKEDBM) - $(YPDBDIR)/$(DOM)/printcap.bykey; \
          rm -f .printcap.$$$$; \
          touch printcap.time; echo "updated printcap"; \
        fi \
      fi
      @if [ ! $(NOPUSH) -a -f $(PRINTCAP) ]; then \
          $(YPPUSH) printcap.byname; \
          $(YPPUSH) printcap.bykey; \
          touch printcap.time; echo "pushed printcap"; \
      fi
</pre>
        </div>
        <br>
        <br>

        <p>To specify that you want YP database rather than file
        access, use the following entry in your <tt class=
        "FILENAME">/etc/lpd.conf</tt> file:</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6100"></a>
<pre class="SCREEN">
    printcap_path |/usr/local/libexec/pcfilter
</pre>
        </div>
        <br>
        <br>

        <p>Put the following shell script in
        /usr/local/libexec/pcfilter</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6103"></a>
<pre class="SCREEN">
    #!/bin/sh
    #/usr/local/libexec/filters/pcfilter
    read key
    # specify the full pathname to the ypmatch program
    # the location depends on the version of Solaris or your
    # system install
    /full/pathname/to/ypmatch "$key" printcap.byname
</pre>
        </div>
        <br>
        <br>

        <p>You can test this by using:</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6106"></a>
<pre class="SCREEN">
    <tt class="PROMPT">h4: {314} #</tt> <tt class=
"USERINPUT"><b>lpc client pr</b></tt>
    pr
     :lp=pr@server
    <tt class="PROMPT">h4: {315} #</tt> <tt class=
"USERINPUT"><b>lpc server pr</b></tt>
    pr
     :lp=pr@server
</pre>
        </div>
        <br>
        <br>
      </div>

      <div class="SECT2">
        <h2 class="SECT2"><a name="AEN6112">12.18.2. How to use NIS
        and <b class="APPLICATION">LPRng</b> - Sven
        Rudolph</a></h2>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6116"></a>
<pre class="SCREEN">
     Date: Wed, 11 Sep 1996 00:11:02 +0200
    From: Sven Rudolph &lt;sr1@os.inf.tu-dresden.de&gt;
    To: lprng@lprng.com
    Subject: Using :oh=server: with NIS
</pre>
        </div>
        <br>
        <br>

        <p>When I use a cluster-wide printcap, I want the entries
        for each printer to appear, e.g.:</p>

        <div class="INFORMALEXAMPLE">
          <a name="AEN6119"></a>
<pre class="SCREEN">
    ---------- start of printcap snippet
    lp1
     :lp=lp1@server
    lp2
     :lp=lp2@server
    lp1
     :server:oh=servername
     :sd=/var/spool/lpd/lp1
     :lp=/dev/lp1
     :mx=0
    ---------- end of printcap snippet
</pre>
        </div>
        <br>
        <br>

        <p>When I create a NIS map out of this the printer name is
        used as a key and must be unique. The NIS makedbm will drop
        all but the last entry for each printer. This makes the
        printer on the clients unavailable. I solved this by a hack
        where the second entry is called lp1.server and the NIS
        client script has to request the right entry.</p>

        <ol type="1">
          <li>
            <p>Assumptions</p>

            <p>Perl is available at the YP server in <tt class=
            "COMMAND">/usr/bin/perl</tt>. A Bourne Shell is
            available at all clients in <tt class=
            "COMMAND">/bin/sh</tt> The printcap that is to be
            exported is in <tt class="FILENAME">/etc/printcap</tt>.
            The printcap is written in the new format. In the
            examples the printer is called lp1.</p>
          </li>

          <li>
            <p>Add the following to your YP <tt class=
            "FILENAME">Makefile</tt> (<tt class=
            "FILENAME">/var/yp/Makefile</tt>) on the YP server
            (these lines are for Debian GNU/Linux, other systems
            might require other modifications):</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6133"></a>
<pre class="SCREEN">
    ---------- start of /var/yp/Makefile snippet
    PRINTCAP  = /etc/printcap
    printcap: $(PRINTCAP)
        @echo "Updating $@..."
        $(CAT) $(PRINTCAP) | \
            /usr/lib/yp/normalize_printcap | $(DBLOAD) -i $(PRINTCAP) \
            -o $(YPMAPDIR)/$@ - $@
        @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
        @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
    ---------- end of /var/yp/Makefile snippet
</pre>
            </div>
            <br>
            <br>
          </li>

          <li>
            <p>Install the programs <b class=
            "APPLICATION">match_printcap</b> and <b class=
            "APPLICATION">normalize_printcap</b> in the <tt class=
            "FILENAME">/usr/lib/yp</tt> directory; <b class=
            "APPLICATION">normalize_printcap</b> is only required
            on the YP server. The <b class=
            "APPLICATION">normalize_printcap</b> processes only the
            <b class="APPLICATION">LPRng</b> printcap format.</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6143"></a>
<pre class="SCREEN">
    ---------- start of /usr/lib/yp/normalize_printcap
    #! /usr/bin/perl
    $debug = 0;
    $line = "";
    $new = "";
    while (&lt;&gt;) {
        chomp;
        next if ( /^\s*\#.*/ );
        s/^\s*$//;
        next if ( $_ eq '' );
        print "new: " . $_ . "\n" if $debug;;
        if (/^\s/) { # continuation line
            $line = $line.$_;
            print "continued: $line\n" if $debug;
            next;
        } else {
            $line =~ s/\s+\:/:/g;
            $line =~ s/\:\s+/:/g;
            $line =~ s/\:\s*\:/:/g;
            print "line: $line\n" if $debug;
            push(@lines, $line) if $line;
            $line = $_;
        }
    }
    $line =~ s/\s+\:/:/g;
    $line =~ s/\:\s+/:/g;
    $line =~ s/\:\s*\:/:/g;
    push(@lines,$line) if $line;
    @lines = sort(@lines);
    foreach $line (@lines) {
        ($printers) = split(/\:/,$line);
        @printers = split(/\|/,$printers);
        foreach $printer (@printers) {
          $num{$printer}++;
          push(@allprinters,$printer);
          print "allprinters: @allprinters\n" if $debug;
          print $printer."_".$num{$printer}."\t$line\n";
        }
    }
    @pr = keys %num;
    print "printers @pr\n" if $debug;
    if ($#allprinters &gt;=0) {
        print "all_1\tall:all=".join(",",@pr)."\n";
    }
    ---------- end of /usr/lib/yp/normalize_printcap
</pre>
            </div>
            &#13;<br>
            <br>

            <p>The result of processing the sample printcap file
            is:</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6146"></a>
<pre class="SCREEN">
    lp1_1 lp1:lp=lp1@server
    lp1_2 lp1:server:oh=servername:sd=/var/spool/lpd/lp1:lp=/dev/lp1:mx=0
    lp2_1 lp2:lp=lp2@server
    all_1 all:all=lp1,lp2
</pre>
            </div>
            <br>
            <br>

            <p>Observe that each of the real printer entries has a
            key consisting of the printer name with a numerical
            suffix. This leads to the following method of
            extracting the printcap information using <tt class=
            "LITERAL">ypmatch</tt>:</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6150"></a>
<pre class="SCREEN">
    ---------- start of /usr/lib/yp/match_printcap
    #!/bin/sh
    read p
    n=1
    # specify the full pathname to ypmatch - this depends on your
    # OS version and installation
    while /full/pathname/to/ypmatch "${p}_${n}" printcap 2&gt;/dev/null; do
        n=`expr $n + 1`
    done
    ---------- end of /usr/lib/yp/match_printcap
</pre>
            </div>
            <br>
            <br>
          </li>

          <li>
            <p>Now test the YP arrangement:</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6154"></a>
<pre class="SCREEN">
    <tt class="PROMPT">h4: {316} #</tt>  cd /var/yp; make
        # this should create the printcap map
    <tt class="PROMPT">h4: {317} #</tt>  ypcat printcap
        # should provide the whole normalized printcap
    <tt class=
"PROMPT">h4: {318} #</tt>  echo lp1 |/usr/lib/yp/match_printcap
        # yields lp1 printcap
</pre>
            </div>
            <br>
            <br>
          </li>

          <li>
            <p>Modify the <tt class="LITERAL">printcap_path</tt>
            entry in the <tt class="FILENAME">lpd.conf</tt>
            file:</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6163"></a>
<pre class="SCREEN">
    printcap_path=|/usr/lib/yp/match_printcap
</pre>
            </div>
            <br>
            <br>
          </li>

          <li>
            <p>Test the use of the printcap path entry:</p>

            <div class="INFORMALEXAMPLE">
              <a name="AEN6167"></a>
<pre class="SCREEN">
    <tt class=
"PROMPT">h4: {319} #</tt>  lpc client lp1 # shows the printcap for lp1
    <tt class=
"PROMPT">h4: {320} #</tt>  lpc server lp1 # shows the printcap for lp1
</pre>
            </div>
            <br>
            <br>
          </li>

          <li>
            <p>Restart the lpd server and check to see that it
            accesses the right printcap information. Use the same
            <b class="APPLICATION">lpq</b> command, and then try
            <tt class="COMMAND">lpc printcap lp1</tt>.</p>
          </li>
        </ol>
        <br>
        <br>
      </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=
          "x6065.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=
          "x6175.htm" accesskey="N">Next</a></td>
        </tr>

        <tr>
          <td width="33%" align="left" valign="top">Management
          Strategies for Large Installations</td>

          <td width="34%" align="center" valign="top"><a href=
          "printcapref.htm" accesskey="U">Up</a></td>

          <td width="33%" align="right" valign="top">Lexmark
          Printers</td>
        </tr>
      </table>
    </div>
  </body>
</html>