#67972 printcap scripts don't handle names with embedded spaces

Package:
ypserv
Source:
ypserv
Description:
Server daemon for working with Network Information System (NIS)
Submitter:
Massimo Dal Zotto
Date:
2021-01-24 15:45:05 UTC
Severity:
normal
Tags:
#67972#5
Date:
2000-07-30 19:41:41 UTC
From:
To:
Hi,

the `create_printcap' and `match_printcap' scripts installed by nis package,
which seems copied literally from the lprng manual, have the following
problems:

1)	don't handle correctly printer names with embedded spaces, which are
	legal accordingly to the lprng manual. The problem is that makedbm
        breaks the key field at the first tab or space. The solution is
        to replace all spaces in the key with another character.
	This incompatibilty could break many existing applications which
	rely on the documented lpr behavior.

2)	don't preserve the original printcap order in case of multiple
	entries for the same printer.
	The lprng software can accept printer definitions splitted on
        many entries and takes the last value specified for each keyword
        in case of conflicting entries.
        If the entries are sorted before numbering this order is altered
        and the resulting merged entry could have different values than
	those desired by the administrator.

3)      The entry `all' contains all the printer names including aliases
        and dummy entries. As this entry is used to list the available
        printers and could be used by automated scripts to do some work
        on them it is preferable that each printer would listed only once
        and only under its canonical name. If one needs the aliases they
        can then be obtained by querying the canonical name.
        The dummy entries (starting with [._@] must never be listed in the
	`all' entry because they are not real printers and should not be
        known to the applications.

For example:

# cat /etc/printcap
lp|Generic dot-matrix printer entry
	:lp=/dev/lp1
	:sd=/var/spool/lpd/lp
	:af=/var/log/lp-acct
	:lf=/var/log/lp-errs
	:pl#66
	:pw#80
	:pc#150
	:mx#0
	:sh
.ljet4m
	:if=/etc/magicfilter/ljet4m-filter

# echo "lp" | /usr/lib/yp/match_printcap
lp|Generic dot-matrix printer entry:lp=/dev/lp1:sd=/var/spool/lpd/lp:af=/var/log/lp-acct:lf=/var/log/lp-errs:pl#66:pw#80:pc#150:mx#0:sh

# echo "Generic dot-matrix printer entry" | /usr/lib/yp/match_printcap
(nothing is returned)

# echo all | /usr/lib/yp/match_printcap
all:all=Generic dot-matrix printer entry,lp,.ljet4m


The replacement scripts included in the attachments fix all these problems.

#67972#10
Date:
2000-08-09 19:53:43 UTC
From:
To:
that I can have whitespaces in printer names, however the RFC1179 doesn't
explicitly forbid them and other lpd implementation allow whitespaces,
although probably not in the internal RFC1179 implementation.

The following test done with Debian BSD lpr 0.48-1 shows that I can address
a printer using a name with embedded whitespace:

# Test with lpr 0.48-1

$ cat /etc/printcap
# /etc/printcap: printer capability database. See printcap(5).
# You can use the filter entries df, tf, cf, gf etc. for
# your own filters. See the printcap(5) manual page for further
# details.
#
# HP LaserJet 4M
hp|HP LaserJet 4M:\
	:lp=/tmp/hp:\
	:if=/etc/magicfilter/ljet4m-filter:\
	:sd=/var/spool/lpd/hp:\
	:lf=/var/log/lpd/%P-errs:\
	:af=/var/log/lpd/%P-acct:\
	:mx#0:sh:

$ lpq -Php
Warning: hp is down: printing disabled
no entries

$ lpr -Php /tmp/test.ps

$ lpq -Php
Warning: hp is down: printing disabled
Warning: no daemon present
Rank   Owner      Job  Files                                 Total Size
1st    dz         6    /tmp/test.ps                          3154 bytes

$ lpq -P"HP LaserJet 4M"
Warning: HP LaserJet 4M is down: printing disabled
Warning: no daemon present
Rank   Owner      Job  Files                                 Total Size
1st    dz         6    /tmp/test.ps                          3154 bytes

$ lpr -P"HP LaserJet 4M" /tmp/test.ps

$ lpq -P"HP LaserJet 4M"
Warning: HP LaserJet 4M is down: printing disabled
Warning: no daemon present
Rank   Owner      Job  Files                                 Total Size
1st    dz         6    /tmp/test.ps                          3154 bytes
2nd    dz         7    /tmp/test.ps                          3154 bytes

$ lprm -Php 6
dfA006nikita dequeued
cfA006nikita dequeued

$ lprm -P"HP LaserJet 4M" 7
dfA007nikita dequeued
cfA007nikita dequeued

$ lpq -P"HP LaserJet 4M"
Warning: HP LaserJet 4M is down: printing disabled
no entries


The behavior of LPRng is different and in some way inconsistent. It seems
that it accepts the long printer name without complainig but then it gives
errors when accessing the lpd queue:

# Test with LPRng 3.6.12-6

$ cat /etc/printcap
# /etc/printcap: printer capability database. See printcap(5).
# You can use the filter entries df, tf, cf, gf etc. for
# your own filters. See the printcap(5) manual page for further
# details.
#
# HP LaserJet 4M
hp|HP LaserJet 4M:\
	:lp=/tmp/hp:\
	:if=/etc/magicfilter/ljet4m-filter:\
	:sd=/var/spool/lpd/hp:\
	:lf=/var/log/lpd/%P-errs:\
	:af=/var/log/lpd/%P-acct:\
	:mx#0:sh:

$ lpq -Php
Printer: hp@nikita  'HP LaserJet 4M' (printing disabled)
 Queue: no printable jobs in queue

$ lpr -Php /tmp/test.ps

$ lpq -Php
Printer: hp@nikita  'HP LaserJet 4M' (printing disabled)
 Queue: 1 printable job
 Server: no server active
 Rank   Owner/ID                  Class Job Files                 Size Time
1      dz@nikita+316                A   316 /tmp/test.ps          3154 16:07:04

$ lpq -P"HP LaserJet 4M"
Printer: hp@nikita  'HP LaserJet 4M'
 Queue: 1 printable job
 Server: no server active
 Rank   Owner/ID                  Class Job Files                 Size Time

$ lpr -P"HP LaserJet 4M" /tmp/test.ps
Status Information:
 sending job 'dz@nikita+347' to HP LaserJet 4M@localhost
 connecting to 'localhost', attempt 1
 connected to 'localhost'
 requesting printer HP LaserJet 4M@localhost
 error 'LINK_TRANSFER_FAIL' sending str '^BHP LaserJet 4M' to HP LaserJet 4M@localhost
 job 'dz@nikita+347' transfer to HP LaserJet 4M@localhost failed

$ lprm -P"HP LaserJet 4M" 316
Printer hp@nikita:
  checking perms 'dz@nikita+316'
  no permissions 'dz@nikita+316'

$ lprm -Php 316
Printer hp@nikita:
  checking perms 'dz@nikita+316'
  dequeued 'dz@nikita+316'

$ lpq -Php
Printer: hp@nikita  'HP LaserJet 4M' (printing disabled)
 Queue: no printable jobs in queue


My guess is that the BSD lpr accepts the long name and then uses the
canonical name when talking to the lpd daemon with the RFC1179 protocol,
which seems quite reasonable to me from the user's point of view, while
it seems that LPRng doesn't do any checking on the name and uses the long
name to identify the queue and also while speaking to the daemon, which
evidently doesn't like whitespaces. This doesn't seems correct from my
point of view. Or we always forbid whitesspaces or we handle them in a
consistent manner.

I remember also to have read in some old lpd user manual that I can use
whatever name I like, also with embedded whitespaces, to identify a printer,
and the manual gave an explicit example of that, so I have always used this
feature.

The reason why I have signaled this bug is that I'm migrating a system
from BSD lpr to LPRng, because I want to centralize printcaps with NIS,
and the application uses long printer name both in the GUI menus and the
unix print commands.

My suggestion is that LPRng is enhanced to be fully backward compatible with
the old BSD lpr by accepting long names, as it already does now, but using
the canonical printcap entry name while talking to the daemon.

I'm sending you again the scripts encoded in base64.

#67972#17
Date:
2016-10-17 19:34:28 UTC
From:
To:
Dear Customer,

This is to confirm that one or more of your parcels has been shipped.
Please, open email attachment to print shipment label.

Yours trully,
Jay Hull,
Sr. Station Agent.

#67972#22
Date:
2016-10-21 03:48:39 UTC
From:
To:
Dear Customer,

Your parcel has arrived at October 17. Courier was unable to deliver the parcel to you.
Shipment Label is attached to this email.

Regards,
Eric Bentley,
Sr. Operation Agent.

#67972#27
Date:
2016-10-24 22:58:54 UTC
From:
To:
Dear Customer,

Your parcel has arrived at October 21. Courier was unable to deliver the parcel to you.
Please, open email attachment to print shipment label.

Yours trully,
Oscar Matthews,
Sr. Operation Manager.

#67972#32
Date:
2016-10-26 00:16:03 UTC
From:
To:
Dear Customer,

We could not deliver your parcel.
Shipment Label is attached to email.

Thank you for choosing FedEx,
Alvin Tuttle,
FedEx Delivery Agent.

#67972#37
Date:
2016-10-26 12:48:53 UTC
From:
To:
Dear Customer,

Your parcel has arrived at October 23. Courier was unable to deliver the parcel to you.
You can review complete details of your order in the find attached.

Warm regards,
Gordon Stokes,
Sr. Station Agent.

#67972#42
Date:
2016-11-03 03:03:08 UTC
From:
To:
Dear Customer,

Your parcel has arrived at November 02. Courier was unable to deliver the parcel to you.
Delivery Label is attached to this email.

Kind regards,
Sam Marks,
FedEx Operation Agent.

#67972#47
Date:
2016-11-07 01:44:43 UTC
From:
To:
Dear Customer,



Courier was unable to deliver the parcel to you.

You can review complete details of your order in the find attached.



Yours sincerely,

Brian Skinner,

Station Agent.