4.22. Printcap Information From Programs and Databases

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.

We will use very simple example to show how you can use a program to get printcap information. First, you must configure the LPRng software to use a program to get the filter information. This is done by setting a value in the lpc.conf file (usually /etc/lpd.conf or /usr/local/etc/lpd.conf). Copy your lpd.conf file to lpd.conf.bak and then add the following line to the end of the file:

    printcap_path=|/tmp/getpc
    
    h4: {222} % cd /etc
    h4: {223} % cp lpd.conf lpd.conf.bak
    h4: {224} % echo 'printcap_path=|/tmp/getpc' >>lpd.conf


Next, edit the /tmp/getpc file and set its values as shown below.

    set /tmp/getpc:
    
      #!/bin/sh
      # /tmp/getpc
      echo PROG $0 "$@" >>/tmp/trace
      cat >>/tmp/trace
      cat <<EOF
      lp:lp=test@host
      EOF
      exit 0
    
    h4: {225} % chmod 755 /tmp/getpc
    h4: {226} % echo testing | /tmp/getpc -aoption
    lp:lp=test@host
    h4: {227} % cat /tmp/trace
    PROG /tmp/getpc -aoption
    testing


After you have tested the getpc script, use the lpc client all command:

    h4: {228} % lpc client all
    Config
     :lockfile=/var/tmp/LPD/lpd
     :lpd_port=2000
     :printcap_path=|/tmp/getpc
    
    Names
     :lp=lp
    
    All
     :lp
    
    Printcap Information
    lp
     :lp=test@host
    h4: {229} % cat /tmp/trace
    h4: {230} % cat /tmp/trace
    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
    *


As seen from the /tmp/trace file, the getpc program is invoked with the standard filter parameters. The -P command line literal is set to the name of the printcap entry and the name of the entry is written to the filter's STDIN. If the entry is not found, then the wildcard printcap entry will be requested. The -P literal is not set to *, as this has the possibility of opening a security loophole when a shell script parses the filter's command line options.

You restore the original lpd.conf file to restore the system to normal operation.

    h4: {231} % cd /etc
    h4: {232} % cp lpd.conf.bak lpd.conf


When using the program method to return information, special consideration should be given to the all request. If there is not an explicit all entry, then the program should take appropriate steps to enumerate the values in the database, or report that there is a missing all entry to the appropriate administrative authority.