Home | History | Annotate | only in /src/usr.sbin/lpr
History log of /src/usr.sbin/lpr
RevisionDateAuthorComments
 1.12 10-Jun-2018  christos use SUBDIR.roff suggested by uwe@
 1.11 05-Jul-2014  dholland branches: 1.11.22;
Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.10 09-Jan-2001  lukem branches: 1.10.62; 1.10.74;
convert to using .WAIT
 1.9 16-Oct-1997  lukem fix race condition when building libcommon with make -j
 1.8 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 15-Nov-1995  pk Id -> NetBSD
 1.5 30-Jun-1994  cgd deal with new share/doc strategy
 1.4 25-Jun-1994  cgd update for new doc-make/install strategy
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.74.1 10-Aug-2014  tls Rebase.
 1.10.62.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.22.1 25-Jun-2018  pgoyette Sync with HEAD
 1.8 22-Apr-2009  lukem Enable WARNS=4 by default, except for:
cpuctl dumplfs hprop ipf iprop-log kadmin kcm kdc kdigest
kimpersonate kstash ktutil makefs ndbootd ntp pppd quot
racoon racoonctl rtadvd sntp sup tcpdchk tcpdmatch tcpdump
traceroute traceroute6 user veriexecgen wsmoused zic
(Mostly third-party applications)
 1.7 28-May-2007  tls branches: 1.7.20;
Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.6 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.5 07-Jan-2001  enami Use PRINTOBJDIR.
 1.4 25-Oct-1997  lukem use CPPFLAGS instead of CFLAGS
 1.3 18-Oct-1997  lukem branches: 1.3.2;
enable WARNS=1 by default, but disable in unclean 3rd party code
 1.2 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.1 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.3.2.1 08-Nov-1997  lukem sync with trunk (approved by thorpej)
 1.7.20.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  mycroft Clean up deleted files.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.3 09-Jul-1997  jtc Changed pathnames to correspond to current reality.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.3 09-Jul-1997  jtc Changed pathnames to correspond to current reality.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.6 12-Jan-2006  wiz New sentence, new line.
 1.5 04-Jan-2006  garbled Address PR bin/12112
Lpd has the ability to start on a port other than "printer" but has no
way to connect to a remote lpd on that port. This change adds the
ability to specify port@host in the rm element of printcap(5). Tested to
work with both a standard lpd setup and one running on special ports.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.3 09-Jul-1997  jtc Changed pathnames to correspond to current reality.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.4 07-May-2008  christos patch from Dennis den Brok for foomatic
 1.3 07-Aug-2003  agc branches: 1.3.30;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.3.30.1 18-May-2008  yamt sync with head.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.3 09-Jul-1997  jtc Changed pathnames to correspond to current reality.
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.7 05-Jul-2014  dholland Reorg docs, part 1:
Move all the reference manuals to subdirs of /usr/share/doc/reference.
We have subdirs ref1-ref9, corresponding to man page sections 1-9.

Everything that's the reference manual for a program (sections 1, 6,
8), C interface (sections 2, 3), driver or file system (section 4),
format or configuration (section 5), or kernel internal interface
(section 9) belongs in here.

Section 7 is a little less clear: some things that might go in section
7 if they were a man page aren't really reference manuals. So I'm only
putting things in reference section 7 that are (to me) clearly
reference material, rather than e.g. tutorials, guides, FAQs, etc.
This obviously leaves some room for debate, especially without first
editing the docs with this distinction in mind, but if people hate
what I've done things can always be moved again.

Note also that while roff macro man pages traditionally go in section
7, I have put all the roff documentation (macros, tools, etc.) in one
place in reference/ref1/roff. This will make it easier to find and
also easier to edit it into some kind of coherent form.
 1.6 05-Jul-2014  dholland Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.5 10-Jul-2003  lukem branches: 1.5.60; 1.5.72;
Rename a large chunk of the make(1) variables which refer to a
program/tool from "FOO" to "TOOL_FOO". The new variables are:
TOOL_ASN1_COMPILE TOOL_CAP_MKDB TOOL_CAT TOOL_CKSUM TOOL_COMPILE_ET
TOOL_CONFIG TOOL_CRUNCHGEN TOOL_CTAGS TOOL_DB TOOL_EQN TOOL_FGEN
TOOL_GENCAT TOOL_GROFF TOOL_HEXDUMP TOOL_INDXBIB TOOL_INSTALLBOOT
TOOL_INSTALL_INFO TOOL_M4 TOOL_MAKEFS TOOL_MAKEINFO TOOL_MAKEWHATIS
TOOL_MDSETIMAGE TOOL_MENUC TOOL_MKCSMAPPER TOOL_MKESDB
TOOL_MKLOCALE TOOL_MKMAGIC TOOL_MKTEMP TOOL_MSGC TOOL_MTREE
TOOL_PAX TOOL_PIC TOOL_PREPMKBOOTIMAGE TOOL_PWD_MKDB TOOL_REFER
TOOL_ROFF_ASCII TOOL_ROFF_DVI TOOL_ROFF_HTML TOOL_ROFF_PS
TOOL_ROFF_RAW TOOL_RPCGEN TOOL_SOELIM TOOL_SUNLABEL TOOL_TBL
TOOL_UUDECODE TOOL_VGRIND TOOL_ZIC

For each, provide default in <bsd.sys.mk> of the form:
TOOL_FOO?= foo
and for the ${USETOOLS}=="yes" case in <bsd.own.mk>, provide override:
TOOL_FOO= ${TOOLDIR}/bin/${_TOOL_PREFIX}foo

Document all of these in bsd.README.

This cleans up a chunk of potential (and actual) namespace collision
within our build infrastructure, as well as improves consistency in
the share/mk documentation and provision of appropriate defaults for
each of these variables.
 1.4 05-Jan-2003  pooka Add ${MACROS} to ${ROFF} usage to make output readable

from jbernard@mines.edu in misc/19685
 1.3 21-Dec-1997  christos Use obj dirs
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.5.72.1 10-Aug-2014  tls Rebase.
 1.5.60.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.12 20-Dec-2014  prlw1 MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.11 03-May-2008  lukem branches: 1.11.40;
Rename MKPRIVATELIB to LIBISPRIVATE, to make it clearer that this is
a variable that is used by in-tree Makefiles to control behaviour.
(MKsomevar variables are generally intended to be controlled by the end-user)
 1.10 23-May-2004  tron branches: 1.10.24;
Really set "MKPRIVATELIB" and not "INTERNALLIB".
 1.9 23-May-2004  lukem Use MKPRIVATELIB=yes instead of providing an empty libinstall:: target and
setting NOLINT, NOPIC, NOPROFILE (etc)
 1.8 18-Sep-2002  lukem minor makefile delint
 1.7 12-Dec-2001  tv MKfoo=no -> NOfoo
 1.6 05-Dec-1999  jdolecek put fatal() and a some of variables used independantly of other functions
in common.c into separate files - this slighly cuts down size of pac(1)
not that it's really significant, but every bit counts ....
 1.5 13-Mar-1999  lukem branches: 1.5.6;
set MKLINT=no. noted by NAKAJIMA Yoshihiro <nakayosh@kcn.ne.jp>
 1.4 13-Feb-1999  lukem convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.
 1.3 11-Oct-1997  mycroft GC some garbage variables.
 1.2 11-Oct-1997  veego Don't install this libraries, we only this during the build.
 1.1 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.5.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.10.24.1 18-May-2008  yamt sync with head.
 1.11.40.1 29-Dec-2014  martin Pull up following revision(s) (requested by prlw1 in ticket #358):
sbin/route/route.c: revision 1.149
external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c: revision 1.7
external/bsd/ipf/dist/lib/printhost.c: revision 1.3
usr.sbin/lpr/common_source/common.c: revision 1.43
usr.sbin/lpr/common_source/Makefile: revision 1.12
external/bsd/ipf/dist/lib/printhostmask.c: revision 1.3
external/bsd/ipf/dist/lib/save_v1trap.c: revision 1.2
external/bsd/dhcpcd/dist/dhcpcd.c: revision 1.21
external/bsd/tcpdump/bin/Makefile: revision 1.12
external/bsd/ipf/dist/lib/save_v2trap.c: revision 1.2
external/bsd/ipf/dist/tools/lexer.c: revision 1.2
external/bsd/ppp/usr.sbin/pppd/sys-bsd.c: revision 1.3
external/bsd/ipf/dist/lib/printipfexpr.c: revision 1.2
MKINET6=no build fixes
http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.2 05-Oct-1997  mrg oops; did not mean to import these.
 1.1 05-Oct-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1997  mrg lite-2
 1.2 05-Oct-1997  mrg oops; did not mean to import these.
 1.1 05-Oct-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1997  mrg lite-2
 1.44 13-May-2023  andvar change a typo in sizeof(struct queueue *) to sizeof(nqueue[0])
riastradh recommends using array[0] instead of pointer.
 1.43 20-Dec-2014  prlw1 MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.42 13-Nov-2013  christos branches: 1.42.4;
CID 1125882: Don't use unitialized variable; move code inside conditional
where it was intended.
 1.41 19-Oct-2013  christos use new scopeid functions
 1.40 13-Jul-2009  roy branches: 1.40.6; 1.40.12;
Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.39 18-Jan-2009  lukem fix -Wsign-compare issues
 1.38 01-Dec-2007  mlelstv Sort queue by time and jobid so that jobs submitted within the
same second are printed in order.
Fixes PR bin/37346
 1.37 25-May-2006  christos branches: 1.37.4; 1.37.6; 1.37.10;
Add missing semicolon.
 1.36 25-May-2006  christos Coverity CID 3322: Fix memory leak.
 1.35 21-Mar-2006  christos Coverity CID 1750: Add a function to free a queue and use it.
 1.34 17-Mar-2006  christos free memory on allocation failure.
 1.33 20-Jan-2006  christos Instead of dealing with port@host in many places, do it where it is needed.
It reduces code and complexity and at the same time allows as to use symbolic
ports instead of just numeric everywhere.
 1.32 18-Jan-2006  garbled change return(0) to return(rv). We went to all the trouble to calculate the
return value, we might as well return it. (fixes lpq -a, and probably lpd)
 1.31 17-Jan-2006  garbled Fix PR bin/14247
This PR claims that MacOSX 10.1 cannot print postscript files to a NetBSD
lpd because the mac will tag the file with an "o" for postscript, which
we do not handle. Rather than simply mapping o -> f as was done in the
PR, or mapping o -> l as was done in FreeBSD, I have implemented full
support for the "o" option. If a postscript filter does not exist in the
printcap file however, it will default to "l" handling.

With this change, you can now specify a "pf" or postscript filter in your
printcap, and have it handle postscript files sent to it with "lpr -o".

The "o" format in lpd is specified in RFC1179 as being a valid format flag.
 1.30 17-Jan-2006  garbled in ckqueue() if "sd" is not an existing capability, than sd will be
uninitialized, causing the free() in out: to explode. Initialize sd to NULL.
 1.29 04-Jan-2006  garbled Address PR bin/12112
Lpd has the ability to start on a port other than "printer" but has no
way to connect to a remote lpd on that port. This change adds the
ability to specify port@host in the rm element of printcap(5). Tested to
work with both a standard lpd setup and one running on special ports.
 1.28 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.27 16-Nov-2004  itojun branches: 1.27.2;
NI_WITHSCOPEID was not picked up by IETF standardization
 1.26 16-Oct-2003  itojun safer use of realloc
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.24 18-Sep-2002  mycroft select() -> nanosleep()
 1.23 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.22 05-Apr-2001  wiz Fix possible security problem (euid swapout in error handling).
Based on a similar patch in OpenBSD, reported there by
j@ida.interface-business.de.
Fix the second occurrance of a similar problem in that file, too, though.
 1.21 09-Aug-2000  itojun rewrite local address detection code, to use getifaddrs(3), not gethostname(3).
gethostname(3) do not necessarily represent local host addrses.
pointed out by: Chuck Cranor
 1.20 25-Apr-2000  itojun branches: 1.20.4;
allow lp=port@host again. PR9975 from Andreas Gustafsson.
 1.19 24-Apr-2000  itojun avoid NULL pointer access when rp=<ipv4 numberic address> (no ai_canonname).
From: hiro@takechi.org

XXX checkremote() should be improved. gethostname -> getaddrinfo is
not the right thing to do, we cannot assume DNS FQDNs is configured
as hostname. if the goal here is to check if it is really remote or not,
getifaddrs() is the way to go.
 1.18 18-Feb-2000  itojun do not sleep on ECONNREFUSED, rather, try the next address first.
the behavior itself has a room for debate. (why we retry on ECONNREFUSED?)

From: SHIMIZU Ryo <ryo@misakimix.org>
 1.17 27-Jan-2000  itojun IPv6 support, using rcmd-family funciton added.
NetBSD PR: 9050
From: Feico Dillema
 1.16 05-Dec-1999  jdolecek put fatal() and a some of variables used independantly of other functions
in common.c into separate files - this slighly cuts down size of pac(1)
not that it's really significant, but every bit counts ....
 1.15 26-Sep-1999  mrg delint and other cleanups.
 1.14 09-Jul-1998  msaitoh branches: 1.14.4;
Declare ints, too, don't default them.
 1.13 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.12 18-Oct-1997  lukem use memcmp/memset/memmove instead of bcmp/bzero/bcopy
 1.11 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.10 05-Oct-1997  mrg merge 4.4 lite2
 1.9 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.8 28-Nov-1995  jtc branches: 1.8.4;
merge in changes from 1.1 release branch
 1.7 15-Nov-1995  pk Add RCSIDs.
 1.6 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.5 18-May-1994  cgd clean up that import. no rcsids yet.
 1.4 17-May-1994  cgd copyright foo
 1.3 08-Dec-1993  jtc Upgraded to use <dirent.h>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.14.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20.4.2 24-Dec-2001  he Pull up revision 1.21 (requested by wiz):
Use getifaddrs(3) instead of gethostname(3) for local address
detection.
 1.20.4.1 26-Apr-2001  he Pull up revision 1.22 (requested by wiz):
Fix possible security problem (euid swapout in error handling).
 1.27.2.1 11-May-2008  jdc Pull up revision 1.38 via patch (requested by mlelstv in ticket #1929).

Sort queue by time and jobid so that jobs submitted within the
same second are printed in order.
 1.37.10.1 09-Jan-2008  matt sync with HEAD
 1.37.6.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.37.4.1 11-May-2008  jdc Pull up revision 1.38 (requested by mlelstv in ticket #1136).

Sort queue by time and jobid so that jobs submitted within the
same second are printed in order.
 1.40.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.42.4.1 29-Dec-2014  martin Pull up following revision(s) (requested by prlw1 in ticket #358):
sbin/route/route.c: revision 1.149
external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c: revision 1.7
external/bsd/ipf/dist/lib/printhost.c: revision 1.3
usr.sbin/lpr/common_source/common.c: revision 1.43
usr.sbin/lpr/common_source/Makefile: revision 1.12
external/bsd/ipf/dist/lib/printhostmask.c: revision 1.3
external/bsd/ipf/dist/lib/save_v1trap.c: revision 1.2
external/bsd/dhcpcd/dist/dhcpcd.c: revision 1.21
external/bsd/tcpdump/bin/Makefile: revision 1.12
external/bsd/ipf/dist/lib/save_v2trap.c: revision 1.2
external/bsd/ipf/dist/tools/lexer.c: revision 1.2
external/bsd/ppp/usr.sbin/pppd/sys-bsd.c: revision 1.3
external/bsd/ipf/dist/lib/printipfexpr.c: revision 1.2
MKINET6=no build fixes
http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.4 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.3 24-Apr-2004  christos constify printcapdb
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.1 05-Dec-1999  jdolecek branches: 1.1.2;
put fatal() and a some of variables used independantly of other functions
in common.c into separate files - this slighly cuts down size of pac(1)
not that it's really significant, but every bit counts ....
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.34 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.33 18-Jan-2009  lukem fix -Wsign-compare issues
 1.32 21-Mar-2006  christos Coverity CID 1750: Add a function to free a queue and use it.
 1.31 21-Mar-2006  christos Coverity CID 1752: getq() always allocates a queue if nitems >= 0, so always
free it.
 1.30 20-Jan-2006  christos Instead of dealing with port@host in many places, do it where it is needed.
It reduces code and complexity and at the same time allows as to use symbolic
ports instead of just numeric everywhere.
 1.29 04-Jan-2006  garbled Address PR bin/12112
Lpd has the ability to start on a port other than "printer" but has no
way to connect to a remote lpd on that port. This change adds the
ability to specify port@host in the rm element of printcap(5). Tested to
work with both a standard lpd setup and one running on special ports.
 1.28 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.27 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.26 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.25 17-May-2003  itojun use strlcpy/strlcat.
[fix off-by-one in displayq.c]
 1.24 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.23 08-Jun-2002  itojun avoid hardcoded octals
 1.22 30-Aug-2001  itojun use strlcpy. from openbsd
 1.21 30-Aug-2001  itojun security fix from openbsd:

Fix buffer oflow reading from queue file. While we are at it, crank
the size of buffers that can hold filenames to MAXPATHLEN.
 1.20 25-Jun-2001  mrg use DEFLP instead of "lp".
 1.19 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.18 11-Oct-2000  is More format string cleanups by sommerfeld.
 1.17 07-Dec-1999  mrg branches: 1.17.4;
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.16 26-Sep-1999  mrg delint and other cleanups.
 1.15 14-Sep-1998  frueauf branches: 1.15.2; 1.15.4;
Fix pr 5071 better after feedback from the Originator Havard Eidnes.
 1.14 14-Sep-1998  frueauf Add (ugly?) code to prevent core dump as described in pr 5071 by Havard Eidnes.

XXX Maybe someone with more taste and understanding should have a look
XXX at this? At least I prefer this over the solution provided in the pr.
 1.13 05-Oct-1997  mrg fix alpha compile warnings.
 1.12 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.11 05-Oct-1997  mrg merge 4.4 lite2
 1.10 10-Jul-1997  mikel make explicit comparisons to NULL (gcc -Wall)
 1.9 19-Apr-1997  thorpej getc() returns an int, not a char.
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 28-Nov-1995  jtc branches: 1.7.4;
merge in changes from 1.1 release branch
 1.6 15-Nov-1995  pk Fix garbled lines (from Thomas Eberhardt; PR#1756).
Add RCSId.
 1.5 03-Oct-1995  hpeyerl branches: 1.5.2;
-- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 27-Mar-1994  cgd off_t exp.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 19-Nov-1995  pk Update from trunk: fix garbled lines.
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.15.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.2.1 19-Oct-2000  he Pull up revision 1.18 (requested by he):
Format string cleanup.
 1.17.4.2 30-Sep-2001  he Pull up revision 1.21 (requested by itojun):
Fix buffer overflow reading from queue file. Also increase the
size of buffers for file names.
 1.17.4.1 17-Oct-2000  tv Pullup usr.sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.5 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.3 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.2 04-Jul-2000  matt More #include <stdlib.h> string, etc. cleanup
 1.1 05-Dec-1999  jdolecek branches: 1.1.2;
put fatal() and a some of variables used independantly of other functions
in common.c into separate files - this slighly cuts down size of pac(1)
not that it's really significant, but every bit counts ....
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25 30-Aug-2011  joerg static, __printflike, __dead
 1.24 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.23 18-Jan-2009  lukem fix -Wsign-compare issues
 1.22 21-Mar-2006  christos Coverity CID 1750: Add a function to free a queue and use it.
 1.21 20-Jan-2006  christos Instead of dealing with port@host in many places, do it where it is needed.
It reduces code and complexity and at the same time allows as to use symbolic
ports instead of just numeric everywhere.
 1.20 17-Jan-2006  garbled Fix PR bin/14247
This PR claims that MacOSX 10.1 cannot print postscript files to a NetBSD
lpd because the mac will tag the file with an "o" for postscript, which
we do not handle. Rather than simply mapping o -> f as was done in the
PR, or mapping o -> l as was done in FreeBSD, I have implemented full
support for the "o" option. If a postscript filter does not exist in the
printcap file however, it will default to "l" handling.

With this change, you can now specify a "pf" or postscript filter in your
printcap, and have it handle postscript files sent to it with "lpr -o".

The "o" format in lpd is specified in RFC1179 as being a valid format flag.
 1.19 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.18 24-Apr-2004  christos constify printcapdb
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.16 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.15 11-Oct-2000  is More format string cleanups by sommerfeld.
 1.14 16-Apr-2000  mrg branches: 1.14.4;
make scandir(3)'s 3rd argument take a function that takes a *const*
struct dirent *, rather than non-const. this makes scandir(3) the
same as the scandir implementations in libiberty and glibc, and the
select function has no need to modify the dirent.
 1.13 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.12 07-Jul-1998  mrg branches: 1.12.2; 1.12.6;
oops, missed this in gethostname sweep.
 1.11 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.10 05-Oct-1997  mrg merge 4.4 lite2
 1.9 10-Jul-1997  mikel fix typos
 1.8 28-Nov-1995  jtc merge in changes from 1.1 release branch
 1.7 15-Nov-1995  pk Add RCSIDs.
 1.6 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.5 18-May-1994  cgd clean up that import. no rcsids yet.
 1.4 18-May-1994  cgd need unistd.h
 1.3 08-Dec-1993  jtc Upgraded to use <dirent.h>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.2.1 19-Oct-2000  he Pull up revision 1.15 (requested by he):
Format string cleanup.
 1.14.4.1 17-Oct-2000  tv Pullup usr.sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.9 03-Dec-2021  andvar fix various typos in comments, log messages and documentation.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.7 28-Nov-1995  jtc merge in changes from 1.1 release branch
 1.6 15-Nov-1995  pk Add RCSIDs.
 1.5 18-May-1994  cgd clean up that import. no rcsids yet.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 25-May-1993  deraadt make lpd know about modern ar files rather than the old ones.
Like, if it's going to want to make an effort, at least do it right.
 1.2 25-May-1993  deraadt lpr should not access a_magic directly. That's what the N_BADMAG() macro
in a.out.h is there for!
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3 18-May-1994  mycroft Clean up deleted files.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8 19-Oct-2003  lukem #define _PATH_BIN_RCMD in common_source/pathnames.h rather than using
wacky Makefile rules to compile rcmd.c
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.6 14-Mar-1997  mycroft Change _PATH_MASTERLOCK to /var/run/lpd.pid.
 1.5 28-Nov-1995  jtc merge in changes from 1.1 release branch
 1.4 15-Nov-1995  pk Add RCSIDs.
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.10 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.9 05-Oct-1997  mrg merge 4.4 lite2
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 28-Nov-1995  jtc branches: 1.7.4;
merge in changes from 1.1 release branch
 1.6 15-Nov-1995  pk Add RCSIDs.
 1.5 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 18-Apr-1993  mycroft Cleanup for GCC 2.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.25 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.24 18-Jan-2009  lukem fix -Wsign-compare issues
 1.23 20-Jan-2006  christos Instead of dealing with port@host in many places, do it where it is needed.
It reduces code and complexity and at the same time allows as to use symbolic
ports instead of just numeric everywhere.
 1.22 04-Jan-2006  garbled Address PR bin/12112
Lpd has the ability to start on a port other than "printer" but has no
way to connect to a remote lpd on that port. This change adds the
ability to specify port@host in the rm element of printcap(5). Tested to
work with both a standard lpd setup and one running on special ports.
 1.21 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.20 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.18 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.17 25-Jun-2001  mrg use DEFLP instead of "lp".
 1.16 16-Apr-2000  mrg make scandir(3)'s 3rd argument take a function that takes a *const*
struct dirent *, rather than non-const. this makes scandir(3) the
same as the scandir implementations in libiberty and glibc, and the
select function has no need to modify the dirent.
 1.15 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.14 26-Sep-1999  mrg delint and other cleanups.
 1.13 05-Oct-1997  mrg branches: 1.13.6;
- WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.12 05-Oct-1997  mrg merge 4.4 lite2
 1.11 10-Jul-1997  mikel make explicit comparisons to NULL (gcc -Wall)
 1.10 10-Mar-1997  cgd fix one more goofup in the buffer safety changes: snprintf() should be
called with enough space for the trailing NUL, because it (unlike strn*())
always NUL-terminates.
 1.9 08-Mar-1997  cgd fix two bugs pointed out by Paul Sijben <Paul.Sijben@huygens.org>:
(1) incorrect check on length of data being written (fix provided by
Paul Sijben <Paul.Sijben@huygens.org>), and
(2) inadequate buffer (too small) for data being sent to remote meant
that properly-formed messages couldn't be created, so job removal
didn't work properly.
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 28-Nov-1995  jtc branches: 1.7.4;
merge in changes from 1.1 release branch
 1.6 15-Nov-1995  pk Fix garbled lines (from Thomas Eberhardt; PR#1756).
Add RCSId.
 1.5 03-Oct-1995  hpeyerl branches: 1.5.2;
-- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 08-Dec-1993  jtc Upgraded to use <dirent.h>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 19-Nov-1995  pk Update from trunk: fix garbled lines.
 1.7.4.2 12-Mar-1997  mycroft Fix errors in previous change.
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.13.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15 16-May-2007  christos coverity CID 1220: Don't use size_t for return of read.
 1.14 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.12 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.11 26-Sep-1999  mrg delint and other cleanups.
 1.10 18-Jul-1998  lukem branches: 1.10.4;
use AF_LOCAL instead of AF_UNIX
 1.9 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 28-Nov-1995  jtc branches: 1.7.4;
merge in changes from 1.1 release branch
 1.6 15-Nov-1995  pk Add RCSIDs.
 1.5 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 10-Nov-1993  cgd bzero structs before using; fix from theo
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.10.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8 20-Jan-2006  garbled Add a simple filter that encapsulates ascii text into HP PJL format.
Script written by Ross Harvey.
 1.7 18-Sep-2002  lukem minor makefile delint
 1.6 12-Dec-2001  tv MKfoo=no -> NOfoo
 1.5 13-Feb-1999  lukem convert from NOxxx= to MKxxx=no.
include <bsd.own.mk> if testing a MKxxx variable.
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.14 30-Aug-2011  joerg branches: 1.14.42;
static, __printflike, __dead
 1.13 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.12 07-May-2008  christos branches: 1.12.2;
patch from Dennis den Brok for foomatic
 1.11 07-Aug-2003  agc branches: 1.11.30;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.10 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.9 30-Apr-2000  thorpej Need <string.h> for memset() prototype.
 1.8 29-Apr-2000  abs lpf used its own broken argv parsing (-h without an argument would dump core)
Convert to getopt() and add a basic usage()
 1.7 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.6 05-Oct-1997  mrg branches: 1.6.8;
- WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.5 10-Jul-1997  mikel add parens (gcc -Wall)
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11.30.1 18-May-2008  yamt sync with head.
 1.12.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.14.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 20-Jan-2006  garbled Add a simple filter that encapsulates ascii text into HP PJL format.
Script written by Ross Harvey.
 1.3 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.2 05-Oct-1997  mrg add rcsid, use FILES, etc., in Makefile.
 1.1 05-Oct-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1997  mrg freebsd's lp frontend for lpr
 1.5 28-Mar-2003  perry Add a -R flag to lpr, which prints the print job number
Make lp use the -R flag to lpr unless the lp -s flag is used.
This fixes standards/17917, patches and PR from
Brian Ginsbach <ginsbach@cray.com>
 1.4 07-Jul-1998  mrg fix "-s" option
 1.3 07-Jul-1998  mrg add "lp -s" switch, from darcy@druid.net in pr#5713. document "lp -s" and "lp -o"
 1.2 05-Oct-1997  mrg add rcsid, use FILES, etc., in Makefile.
 1.1 05-Oct-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1997  mrg freebsd's lp frontend for lpr
 1.11 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.10 12-Apr-2009  wiz branches: 1.10.6;
New sentence, new line. Use .An.
 1.9 12-Apr-2009  joerg Remove conditional, groff now knows how to deal with ASCII output.
 1.8 25-Feb-2003  wiz branches: 1.8.40;
.Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.7 19-Jan-2002  wiz Whitespace and punctuation nits, use standard headers.
 1.6 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.5 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.4 07-Jul-1998  mrg fix "-s" option
 1.3 07-Jul-1998  mrg add "lp -s" switch, from darcy@druid.net in pr#5713. document "lp -s" and "lp -o"
 1.2 05-Oct-1997  mrg add rcsid, use FILES, etc., in Makefile.
 1.1 05-Oct-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1997  mrg freebsd's lp frontend for lpr
 1.8.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.10.6.1 17-Apr-2012  yamt sync with head
 1.10 03-Feb-2010  roy Userland now builds and uses terminfo instead of termcap.

OK: core@, jdc@
 1.9 12-Jan-2006  garbled Add libedit command line history capability to lpc(8).
 1.8 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.7 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.6 06-May-1997  gwr Use .PATH.c: ...
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 22-Dec-1994  cgd specify man pages the new way.
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25 16-Dec-2016  mrg scandir/alphasort take "const struct dirent **" not "const void *" in
modern unix. since we claim to be 'IEEE Std 1003.1-2008', make it so.
 1.24 31-Aug-2011  plunky branches: 1.24.24;
NULL does not need a cast
 1.23 04-Jan-2011  wiz Fix fd leak in error cases. Found by cppcheck.
 1.22 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.21 18-Jan-2009  lukem fix -Wsign-compare issues
 1.20 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.19 21-Mar-2006  christos branches: 1.19.20;
Coverity CID 1225: Don't close negative fd. While here fix fd leak.
 1.18 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.17 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.15 17-May-2003  itojun use strlcpy/strlcat.
[fix off-by-one in displayq.c]
 1.14 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.13 16-Apr-2000  mrg make scandir(3)'s 3rd argument take a function that takes a *const*
struct dirent *, rather than non-const. this makes scandir(3) the
same as the scandir implementations in libiberty and glibc, and the
select function has no need to modify the dirent.
 1.12 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.11 05-Oct-1997  mrg merge 4.4 lite2
 1.10 10-Jul-1997  mikel oops
 1.9 10-Jul-1997  mikel clarify assignments used as conditionals (gcc -Wall)
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 14-Jan-1996  hpeyerl branches: 1.7.4;
More descriptive message for printer status. Addresses PR #509.
 1.6 15-Nov-1995  pk Add RCSIDs
 1.5 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 08-Dec-1993  jtc Upgraded to use <dirent.h>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.19.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.24.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.8 22-Oct-2006  christos use c99 initializers
 1.7 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.5 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 30-Aug-2011  joerg static, __printflike, __dead
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.4 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.3 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.18 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.17 06-Dec-2008  jnemeth branches: 1.17.8;
PR/40117 - Bug Hunting -- new line, new sentence; punctuation
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.15 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.14 19-Jan-2002  wiz Sort SEE ALSO and sections.
 1.13 09-Apr-2001  wiz lowercase Lpq in xref, and some whitespace fixes.
 1.12 24-Mar-1999  mycroft Remove spurious .ne's.
 1.11 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.10 10-Mar-1999  erh Add missing .El line.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.7 05-Oct-1997  mrg merge 4.4 lite2
 1.6 09-Jul-1997  jtc Changed /var/spool/* to /var/spool/output/*, to be consistant with reality.
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 14-Jan-1994  jtc Fix spelling errors
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17.8.1 17-Apr-2012  yamt sync with head
 1.27 04-May-2017  sevan Drop main() prototype.
 1.26 30-Aug-2011  joerg branches: 1.26.32;
static, __printflike, __dead
 1.25 18-Jan-2009  lukem fix -Wsign-compare issues
 1.24 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.23 03-Oct-2007  christos branches: 1.23.8;
remove null test; it is not necessary as we always look at the next element.
from Anon Ymous
 1.22 03-Oct-2007  christos - int -> size_t
- off by one in \n printing [Anon Ymous]
- return when the end of the array is reached.
 1.21 25-May-2006  christos branches: 1.21.10;
Coverity CID 830: Avoid NULL deref.
 1.20 15-Jan-2006  is Fix obvious error, hopefully correctly.
 1.19 12-Jan-2006  garbled sizeof(char) is unneccesary.
 1.18 12-Jan-2006  garbled Add libedit command line history capability to lpc(8).
 1.17 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.16 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.14 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.13 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.12 19-May-2002  wiz Make ngroups, which is the size of a static array, static too. From
Todd Miller in bin/16871.
 1.11 14-Nov-2001  enami Test absense of command differently to avoid null pointer deference
when only whitespaces are given.
 1.10 24-Aug-2000  sommerfeld Fix ingroup() to not check gid against trailing groups not set by
getgroups().

Reported to security-officer, but not a security hole, since
"operator" is not gid 0.
 1.9 05-Oct-1997  mrg fix alpha compile warnings.
 1.8 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.7 05-Oct-1997  mrg merge 4.4 lite2
 1.6 10-Jul-1997  mikel clarify conditional in for-loop (gcc -Wall)
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.10.1 06-Nov-2007  matt sync with HEAD
 1.23.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.26.32.1 11-May-2017  pgoyette Sync with HEAD
 1.6 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.4 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.3 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.2 15-Nov-1995  pk Add RCSIDs
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.19 07-Mar-2021  christos Add blocklist support to libwrap which enables all programs using libwrap
to block access from hosts we deny. (libwrap support from Greg A. Woods)
 1.18 10-Jan-2005  lukem Only compile in IPv6 support if ${USE_INET6} != "no"

MKINET6 is for providing IPv6 infrastructure.
USE_INET6 is for compiling IPv6 support into the programs (needs MKINET6).
 1.17 19-Oct-2003  lukem #define _PATH_BIN_RCMD in common_source/pathnames.h rather than using
wacky Makefile rules to compile rcmd.c
 1.16 18-Sep-2002  lukem use NETBSDSRCDIR as appropriate
 1.15 12-Aug-2002  itojun add libwrap support for lpd (you need to pass all tests to print,
so you will want "+" in hosts.lpd then restrict by hosts.allow/deny).
setsockopt(SO_REUSEPORT) while i'm here.
 1.14 05-Jun-2000  mycroft branches: 1.14.4;
Get rid of the stupid hack that makes this lose when ${CC} is more than one word.
 1.13 31-May-2000  enami Just remove the first word so that rcmd.c compiles even if the command line
contains same substrings with the name of compiler.
 1.12 30-May-2000  itojun usr.sbin/lpr/lpd now compiles lib/libc/net/rcmd.c on its own, to avoid
use of non-exported function __ivaliduser{,_sa}().

we cannot make __ivaliduser{,_sa}() static yet, since doing that would choke
compiled lpd binaries. we should do it on next libc major version bump.
added a memo on lib/libc/shlib_version.
 1.11 10-Oct-1997  lukem branches: 1.11.10;
only compile common_source/* once (25% faster), remove unused printcap.c
 1.10 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.9 06-May-1997  gwr Use .PATH.c: ...
 1.8 15-Nov-1995  pk Add RCSIDs
 1.7 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 18-May-1994  cgd clean up that import. no rcsids yet.
 1.4 28-Jan-1994  cgd don't need -lutil
 1.3 30-Jul-1993  mycroft Add RCS identifiers.
 1.2 15-Jun-1993  mycroft And just one more.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.4.1 21-Oct-2003  jmc Using hand patch from Havard (requested by thorpej in ticket #946)

* Use STDOUT_FILENO instead of 1.
* Pass the file descriptor to request_init() (libwrap) so that
it can actually do something useful later in fromhost().
 1.12 30-Aug-2011  joerg static, __printflike, __dead
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.10 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.9 24-Feb-2000  itojun (rcmd.c) to make Zoularis happier, pass sa_len separately from sockaddrs.
this changes function prototype for __ivalid*.
This commit breaks binary compatibility for __ivalid*. I believe this can be
forgiven due to the following:
- this is not really exported function. no function prototype is in headers.
function name starts with underbars. No third-party applications are
expected to use it.
- the function was introduced very recently, when rcmd.c was made IPv6-ready.
- the only customer in NetBSD tree is lpd.

(lpd.c) sync with rcmd.c change.
 1.8 27-Jan-2000  itojun IPv6 support, using rcmd-family funciton added.
NetBSD PR: 9050
From: Feico Dillema
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 10-Jul-1997  veego Add #include <stdio.h> for struct FILE.
 1.5 10-Jul-1997  mikel add prototypes for ksearch(), msearch(), and __ivaliduser()
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 05-Oct-1995  mycroft Fix type errors.
 1.2 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.1 18-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-May-1994  cgd lpr from 4.4-Lite
 1.7 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.5 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.4 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.3 20-Oct-1997  scottr Add support for DTR/CTS flow control, from Bill Studenmund.
 1.2 17-Jul-1997  mikel use <sys/cdefs.h> __RCSID macro, add prototype for local c_key function
 1.1 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.36 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.35 09-Nov-2011  wiz Use Sq, and remove trailing whitespace.
 1.34 09-Nov-2011  is If hosts.lpd contains '+', don't insist on reverse DNS == forward DNS.
 1.33 22-Jan-2006  wiz branches: 1.33.42;
New sentence, new line. Bump date for previous. Properly case PostScript.
 1.32 20-Jan-2006  garbled Add control file documentation for 'o' handling, and fix the
documentation on the DVI handling, the correct letter is 'd' not 'r'.
 1.31 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.30 15-Mar-2003  wiz IPv4/IPv6, not IPV4/IPV6.
 1.29 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.28 06-Jan-2003  wiz Stanford, not Standford. From Chad Loder.
 1.27 03-Sep-2002  abs When -r is given actually pass the file through of, and also enable if.
 1.26 12-Aug-2002  wiz Minor mdoc nit.
 1.25 12-Aug-2002  itojun add libwrap support for lpd (you need to pass all tests to print,
so you will want "+" in hosts.lpd then restrict by hosts.allow/deny).
setsockopt(SO_REUSEPORT) while i'm here.
 1.24 31-Jul-2002  jschauma Fix typo pointed out by haes at shrubbery dot net in PR bin/17396
"filter to be use" -> "filter to be used"
 1.23 08-Feb-2002  ross branches: 1.23.2;
Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.22 19-Jan-2002  wiz Convert .Xr to non-existing program to Ic.
 1.21 11-Aug-2001  mjl Add -W parameter to lpd to disable check for a reserved port,
this is needed to get Win2k print to a NetBSD box. Heavily
inspired by FreeBSD.
 1.20 05-Apr-2001  wiz Improve markup, and add sections to xrefs, as well as the obligatory
whitespace fixes.
 1.19 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.18 03-Oct-2000  scw Add a "-b" option to specify one or more local addresses to bind
to instead of the default INADDR_ANY.
 1.17 10-Apr-2000  mrg branches: 1.17.4;
- fix usage message to current reality.
- pull over "lpd [port]" code from freebsd's lpr code.
- use posix signal handling.
 1.16 11-Dec-1999  mrg xref setsockopt (from freebsd) and hosts.equiv.
 1.15 10-Dec-1999  mrg tsk. tsk. document new features i added.
 1.14 22-Mar-1999  garbled branches: 1.14.6;
More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.13 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.12 28-Apr-1998  fair Change occurrences of "UNIX" to .Ux or .At as appropriate.
 1.11 09-Oct-1997  mrg document -d, -s. remove bogus #port. fix getopt().
 1.10 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.9 16-Jul-1997  mikel xref pac(8) not nonexistent pac(1), sort xrefs
 1.8 09-Jul-1997  jtc Changed /var/spool/* to /var/spool/output/*, to be consistant with reality.
 1.7 21-Sep-1996  perry close out pr 2771, which added a -s ("secure") flag to lpd -- makes
lpd run in a mode where the it listens only to the local unix domain
socket and not to the network. Changes are similar but not identical
to the supplied patches.
 1.6 16-Jun-1996  pk `/dev/printer' => `/var/run/printer' (PR#2552).
Also, change `.Os 4.2' => `.Os 4.4' (this man page is from 4.4 lite), and
for now, refer to the "BSD 4.3 Line printer manual", because that is what
we now have in lpr/SMM.doc (SMM.doc needs updating too).
 1.5 15-Nov-1995  pk branches: 1.5.4;
Add RCSIDs
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 14-Jan-1994  jtc Fix spelling errors
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.4.2 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.5.4.1 14-Nov-1996  thorpej Pull up from trunk:

> revision 1.6
> date: 1996/06/16 22:36:59; author: pk; state: Exp; lines: +4 -4
> `/dev/printer' => `/var/run/printer' (PR#2552).
> Also, change `.Os 4.2' => `.Os 4.4' (this man page is from 4.4 lite), and
> for now, refer to the "BSD 4.3 Line printer manual", because that is what
> we now have in lpr/SMM.doc (SMM.doc needs updating too).
 1.14.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.4.3 15-Dec-2002  he Pull up revision 1.27 (via patch, requested by abs):
When ``-r'' is given, actually pass the file through ``of'' and
also enable ``if''.
 1.17.4.2 08-Oct-2001  he Apply patch (requested by msaitoh):
Add missing command name.
 1.17.4.1 26-Apr-2001  he Pull up revisions 1.19-1.20 (via patch, requested by wiz):
Cleanup Nm uses, add sections to cross references, and whitespace
fixes, and other fixes.
 1.23.2.2 21-Oct-2003  jmc Using hand patch from Havard (requested by thorpej in ticket #946)

* Use STDOUT_FILENO instead of 1.
* Pass the file descriptor to request_init() (libwrap) so that
it can actually do something useful later in fromhost().
 1.23.2.1 07-Dec-2002  he Pull up revision 1.27 (via patch, requested by abs in ticket #906):
When ``-r'' is given, actually pass the file through ``of'',
and also enable ``if''.
 1.33.42.1 10-Nov-2011  yamt sync with head
 1.60 26-Apr-2023  kre Us daemons don't need no unions - just wait, the easy way.
 1.59 08-Apr-2022  andvar fix various typos, mainly in comments, but also log messages, docs, game text.
 1.58 04-May-2017  sevan Drop main() prototype.
 1.57 09-Nov-2011  is branches: 1.57.30;
If hosts.lpd contains '+', don't insist on reverse DNS == forward DNS.
 1.56 30-Aug-2011  joerg branches: 1.56.2;
static, __printflike, __dead
 1.55 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.54 18-Jan-2006  garbled branches: 1.54.20;
If we set SIGCHLD to SIG_IGN then any wait()'s on the child processes will
return -1. This causes filters to fail because we get a value for
child_pid we weren't expecting. Set SIGCHLD to SIG_DFL instead to clear
the reapchild setting when forking the child lpd.
 1.53 02-Dec-2005  yamt constify.
 1.52 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.51 02-Jun-2005  lukem Ensure s is initialized before testing (none of the sockets may be ready
so it might not be setup).
Detected with gcc -Wuninitialized.
 1.50 30-Oct-2004  dsl branches: 1.50.2;
Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.49 16-Oct-2003  itojun safer use of realloc
 1.48 16-Oct-2003  itojun safer realloc.
sizeof() for malloc was mistaken in socksetup().
 1.47 01-Sep-2003  itojun plug memory leak. oenbsd-pr-3425
 1.46 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.45 17-May-2003  itojun use strlcpy/strlcat.
[fix off-by-one in displayq.c]
 1.44 26-Oct-2002  thorpej * Use STDOUT_FILENO instead of 1.
* Pass the file descriptor to request_init() (libwrap) so that
it can actually do something useful later in fromhost().
 1.43 24-Sep-2002  itojun set IPV6_V6ONLY socket option for AF_INET6 socket, to avoid
complicated access control issue due to IPv4 mapped address.
 1.42 20-Sep-2002  lukem cast "%ld", xxx.tv_sec to a long
 1.41 19-Sep-2002  mycroft Simplify the accept() code a little -- sockaddr_storage is fine for both
AF_LOCAL and AF_INET{,6}.
 1.40 19-Sep-2002  mycroft If we exit because the pid file is locked, syslog that.
 1.39 19-Sep-2002  mycroft select() -> poll(), nanosleep()
 1.38 12-Aug-2002  itojun add libwrap support for lpd (you need to pass all tests to print,
so you will want "+" in hosts.lpd then restrict by hosts.allow/deny).
setsockopt(SO_REUSEPORT) while i'm here.
 1.37 11-Aug-2002  grant specify the reason when aborting with "Malformed from address",
suggested by Matt Green.
 1.36 09-Aug-2002  itojun die if fd_set overruns
 1.35 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.34 09-Jul-2002  hubertf This fixes various little problems in the lpd source.

lpd.c bogus 'c' option in getopt option string

printjob.c spelling "prstatic inter" -> "printer"
finish ANSIfication

recvjob.c finish ANSIfication

Patch contributed by Brian Ginsbach <ginsbach@cray.com> in PR 17520
 1.33 21-Jan-2002  wiz branches: 1.33.2;
deamon -> daemon
 1.32 21-Nov-2001  wiz "than" instead of "then".
 1.31 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.30 11-Aug-2001  mjl Add -W parameter to lpd to disable check for a reserved port,
this is needed to get Win2k print to a NetBSD box. Heavily
inspired by FreeBSD.
 1.29 25-Jun-2001  mrg printer of "" becomes the DEFLP (the default printer, "lp")
 1.28 28-Mar-2001  simonb 80 column police.
 1.27 19-Feb-2001  cgd convert to use getprogname()
 1.26 02-Feb-2001  itojun listen to the port number specified on argument, as advertised
in document. part of PR 12112 from feico@pasta.cs.uit.no.
 1.25 03-Oct-2000  itojun don't give result of function directly into syslog, use "%s".
 1.24 03-Oct-2000  scw Free the bind-address list entries, as well as the list itself.
 1.23 03-Oct-2000  scw Add a "-b" option to specify one or more local addresses to bind
to instead of the default INADDR_ANY.
 1.22 10-Apr-2000  mrg branches: 1.22.4;
- fix usage message to current reality.
- pull over "lpd [port]" code from freebsd's lpr code.
- use posix signal handling.
 1.21 24-Feb-2000  itojun (rcmd.c) to make Zoularis happier, pass sa_len separately from sockaddrs.
this changes function prototype for __ivalid*.
This commit breaks binary compatibility for __ivalid*. I believe this can be
forgiven due to the following:
- this is not really exported function. no function prototype is in headers.
function name starts with underbars. No third-party applications are
expected to use it.
- the function was introduced very recently, when rcmd.c was made IPv6-ready.
- the only customer in NetBSD tree is lpd.

(lpd.c) sync with rcmd.c change.
 1.20 27-Jan-2000  itojun IPv6 support, using rcmd-family funciton added.
NetBSD PR: 9050
From: Feico Dillema
 1.19 23-Dec-1999  mjl Fix null terminating the wrong buffer curtesy of similar variables
mixed up. Seemed to never have any ill effect, but then...
Noted by Tetsuya Furukawa in FreeBSD PR/15604.
 1.18 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.17 18-Jul-1998  lukem branches: 1.17.6;
use AF_LOCAL instead of AF_UNIX
 1.16 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.15 18-Oct-1997  lukem use memcmp/memset/memmove instead of bcmp/bzero/bcopy
 1.14 09-Oct-1997  mrg document -d, -s. remove bogus #port. fix getopt().
 1.13 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.12 05-Oct-1997  mrg merge 4.4 lite2
 1.11 17-Jul-1997  mikel use <sys/cdefs.h> __COPYRIGHT and __RCSID macros
include <arpa/inet.h> for inet_ntoa() prototype, nuke local declaration
 1.10 10-Jul-1997  mikel index array with int, not char
 1.9 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.8 21-Sep-1996  perry close out pr 2771, which added a -s ("secure") flag to lpd -- makes
lpd run in a mode where the it listens only to the local unix domain
socket and not to the network. Changes are similar but not identical
to the supplied patches.
 1.7 24-Apr-1996  mrg branches: 1.7.4;
Stylistic changes.
 1.6 15-Nov-1995  pk Add RCSIDs
 1.5 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 10-Nov-1993  cgd bzero structs before using; fix from theo
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.17.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.4.3 24-Sep-2002  itojun usr.sbin/lpr/lpd/lpd.c 1.43 via patch

Set IPV6_BINDV6ONLY socket option for AF_INET6 socket, to avoid
complicated access control issue due to IPv4 mapped address.

(itojun)
 1.22.4.2 26-Oct-2001  jhawk Pull up revision 1.29 (requested by mrg):
Use DEFLP ("lp") for printer when printer is zero-length.
 1.22.4.1 03-Oct-2000  itojun pullup: part of 1.24 -> 1.25 (approved by releng-1-5)
(this may not raise a real issue)

> don't give result of function directly into syslog, use "%s".
 1.33.2.2 21-Oct-2003  jmc Using hand patch from Havard (requested by thorpej in ticket #946)

* Use STDOUT_FILENO instead of 1.
* Pass the file descriptor to request_init() (libwrap) so that
it can actually do something useful later in fromhost().
 1.33.2.1 02-Oct-2002  lukem Pull up revision 1.43 (via patch) (requested by itojun in ticket #857):
set IPV6_V6ONLY socket option for AF_INET6 socket, to avoid
complicated access control issue due to IPv4 mapped address.
 1.50.2.1 15-Jun-2005  snj Pull up revision 1.51 (requested by lukem in ticket #416):
Ensure s is initialized before testing (none of the sockets may be ready
so it might not be setup).
Detected with gcc -Wuninitialized.
 1.54.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.56.2.1 10-Nov-2011  yamt sync with head
 1.57.30.1 11-May-2017  pgoyette Sync with HEAD
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.6 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.5 17-Jul-1997  mikel use <sys/cdefs.h> __RCSID macro
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7 22-Oct-2006  christos use c99 initializers
 1.6 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.4 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.3 20-Oct-1997  scottr Add support for DTR/CTS flow control, from Bill Studenmund.
 1.2 17-Jul-1997  mikel use <sys/cdefs.h> __RCSID macro
 1.1 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.57 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.56 30-Aug-2011  joerg branches: 1.56.42;
static, __printflike, __dead
 1.55 13-Jul-2009  roy Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
 1.54 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.53 07-May-2008  christos branches: 1.53.2;
patch from Dennis den Brok for foomatic
 1.52 03-Mar-2008  lukem branches: 1.52.2;
Use mkstemp(3) (in a hokey manner) instead of mktemp(3).

XXX: still not 100% "safe", except that we're in a protected directory.
XXX: arguably we should keep the fds open and fdopen(3) dup()s,
XXX: but we're in a protected directory so it shouldn't matter.
 1.51 16-Feb-2008  matt branches: 1.51.2;
scnkey is const char [][HEIGHT], not char [][HEIGHT]
 1.50 11-May-2006  mrg branches: 1.50.10;
end the argument list to exec*(3) with a NULL instead of a bare '0', as
the latter isn't a pointer context in these varargs functions.
 1.49 17-Mar-2006  christos Appease Coverity CID 2580 [not a bug]
 1.48 20-Jan-2006  christos Instead of dealing with port@host in many places, do it where it is needed.
It reduces code and complexity and at the same time allows as to use symbolic
ports instead of just numeric everywhere.
 1.47 19-Jan-2006  garbled Fix PR bin/30272 Lpd would create the tempfile "remotexxxxx" and send
that, but then fill out the control file with the "df" filename. Fix by
sending the remote file with the "df" filename, as suggested by Robert
Vargason on tech-userlevel. lpd -r now works properly with an if (input
filter)
 1.46 17-Jan-2006  garbled Update a comment regarding control file WRT "o"
 1.45 17-Jan-2006  garbled Fix PR bin/14247
This PR claims that MacOSX 10.1 cannot print postscript files to a NetBSD
lpd because the mac will tag the file with an "o" for postscript, which
we do not handle. Rather than simply mapping o -> f as was done in the
PR, or mapping o -> l as was done in FreeBSD, I have implemented full
support for the "o" option. If a postscript filter does not exist in the
printcap file however, it will default to "l" handling.

With this change, you can now specify a "pf" or postscript filter in your
printcap, and have it handle postscript files sent to it with "lpr -o".

The "o" format in lpd is specified in RFC1179 as being a valid format flag.
 1.44 04-Jan-2006  garbled Address PR bin/12112
Lpd has the ability to start on a port other than "printer" but has no
way to connect to a remote lpd on that port. This change adds the
ability to specify port@host in the rm element of printcap(5). Tested to
work with both a standard lpd setup and one running on special ports.
 1.43 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.42 27-Nov-2005  jdolecek the mktemp() use here is not OK, adjust comment
 1.41 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.40 26-Aug-2004  wiz Avoid printing a useless \0. From SHIMIZU Ryo in PR 26766.
 1.39 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.38 17-May-2003  itojun use strlcpy/strlcat.
[fix off-by-one in displayq.c]
 1.37 26-Oct-2002  thorpej Rather than relying on pure luck to get the log file on STDERR_FILENO,
explictly dup2 the log file dscriptor to STDERR_FILENO and close the
original.
 1.36 04-Sep-2002  abs Add back __attribute__() data for pstatus() removed by error in last commit.
Noted by wiz.
 1.35 03-Sep-2002  abs When -r is given actually pass the file through of, and also enable if.
 1.34 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.33 09-Jul-2002  hubertf This fixes various little problems in the lpd source.

lpd.c bogus 'c' option in getopt option string

printjob.c spelling "prstatic inter" -> "printer"
finish ANSIfication

recvjob.c finish ANSIfication

Patch contributed by Brian Ginsbach <ginsbach@cray.com> in PR 17520
 1.32 08-Jun-2002  itojun avoid hardcoded octals. openbsd
 1.31 21-Jan-2002  wiz branches: 1.31.2;
deamon -> daemon
 1.30 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.29 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.28 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.27 25-Jun-2001  mrg use DEFLP instead of "lp".
 1.26 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.25 11-Oct-2000  is More format string cleanups by sommerfeld.
 1.24 26-Sep-2000  itojun syslog() string format hole.
http://www.securityfocus.com/templates/archive.pike?start=2000-09-24&fromthread=0&mid=85023&list=1&end=2000-09-30&threads=0&
 1.23 24-Aug-2000  itohy Don't pass null pointer to syslog.

lpd[6813]: mail sent to user itohy about job foo.ps on printer lp ((null))
^^^^^^
 1.22 11-Dec-1999  mrg branches: 1.22.4;
- use symbolic names for mode bits
- use _exit() where we should
- fix spelling mistake
- use vasprintf() in pstatus()
all from freebsd.
 1.21 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.20 26-Sep-1999  mrg delint and other cleanups.
 1.19 06-Jul-1998  mrg branches: 1.19.2; 1.19.4;
- use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.18 19-Oct-1997  mycroft Use S_IS*(), not S_IF*.
 1.17 05-Oct-1997  mrg fix alpha compile warnings.
 1.16 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.15 05-Oct-1997  mrg merge 4.4 lite2
 1.14 17-Jul-1997  mikel use <sys/cdefs.h> __COPYRIGHT and __RCSID macros
garbage-collect old set_ttyflags() and ctime() declarations
 1.13 10-Jul-1997  mikel fix printf formats and implicit comparisons (gcc -Wall)
 1.12 22-Mar-1997  lukem use O_EXCL with O_CREAT when making the tempfile
 1.11 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.10 30-Jun-1996  jtc Changed to not use a compiled in table of baud rates. Evidently
there are some PC/Mac oriented devices that use non-standard speeds,
furthermore that's just not the way we do things anymore.

"Bad" baud rates are no longer caught with their own error message,
but the condition will still be diagnosed when the tcsetattr() fails.
 1.9 30-Apr-1996  jtc branches: 1.9.4;
Use XS, not XC, flags when setting tty flags.
From Brook Milligan <brook@trillium.nmsu.edu>.
 1.8 15-Nov-1995  pk Add RCSIDs
 1.7 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.6 14-Apr-1995  mycroft Reset group list before execing child, as pointed out by Mike Pritchard.
 1.5 18-May-1994  cgd clean up that import. no rcsids yet.
 1.4 27-Mar-1994  cgd off_t exp.
 1.3 07-Mar-1994  cgd fix from John F. Woods <jfw@ksr.com>: don't clobber page width specified
in printcap file.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.4.4 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.9.4.3 12-Jul-1996  jtc pull up baud rate change anyway; turns out this is very useful to mac folks
 1.9.4.2 30-Jun-1996  jtc Revert last checkin, it wasn't supposed to go to the release branch
 1.9.4.1 30-Jun-1996  jtc Changed to not use a compiled in table of baud rates. Evidently
there are some PC/Mac oriented devices that use non-standard speeds,
furthermore that's just not the way we do things anymore.

"Bad" baud rates are no longer caught with their own error message,
but the condition will still be diagnosed when the tcsetattr() fails.
 1.19.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.2.2 19-Oct-2000  he Pull up revision 1.25 (via patch, requested by he):
Format string cleanup.
 1.19.2.1 04-Oct-2000  he Pull up revisions 1.23-1.24 (requested by sommerfeld):
Fix potential syslog() format string hole.
 1.22.4.3 15-Dec-2002  he Pull up revision 1.35-1.36 (via patch, requested by abs):
When ``-r'' is given, actually pass the file through ``of'' and
also enable ``if''.
 1.22.4.2 17-Oct-2000  tv Pullup usr.sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.22.4.1 28-Sep-2000  itojun pullup 1.23 -> 1.24 (approved by releng-1-5)

> syslog() string format hole.
> http://www.securityfocus.com/templates/archive.pike?start=2000-09-24&fromthread=0&mid=85023&list=1&end=2000-09-30&threads=0&
 1.31.2.2 07-Dec-2002  he Pull up revision 1.37 (requested by thorpej in ticket #947):
Rather than relying on pure luck to get the log file on
STDERR_FILENO, explicitly dup2 the log file descriptor to
STDERR_FILENO and close the original.
 1.31.2.1 07-Dec-2002  he Pull up revisions 1.35-1.36 (via patch, requested by abs in ticket #906):
When ``-r'' is given, actually pass the file through ``of'',
and also enable ``if''.
 1.50.10.1 23-Mar-2008  matt sync with HEAD
 1.51.2.1 24-Mar-2008  keiichi sync with head.
 1.52.2.1 18-May-2008  yamt sync with head.
 1.53.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.56.42.1 10-Jun-2019  christos Sync with HEAD
 1.26 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.25 27-Dec-2019  msaitoh s/transfered/transferred/
 1.24 14-Oct-2015  christos branches: 1.24.16;
this is syslog-like
 1.23 30-Aug-2011  joerg static, __printflike, __dead
 1.22 18-Jan-2009  lukem fix -Wsign-compare issues
 1.21 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.20 28-Nov-2005  christos branches: 1.20.20;
- WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.19 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.17 26-Oct-2002  thorpej Rather than relying on pure luck to get the log file on STDERR_FILENO,
explictly dup2 the log file dscriptor to STDERR_FILENO and close the
original.
 1.16 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.15 09-Jul-2002  hubertf This fixes various little problems in the lpd source.

lpd.c bogus 'c' option in getopt option string

printjob.c spelling "prstatic inter" -> "printer"
finish ANSIfication

recvjob.c finish ANSIfication

Patch contributed by Brian Ginsbach <ginsbach@cray.com> in PR 17520
 1.14 04-Dec-2001  christos branches: 1.14.2;
Make sure that the we have a valid pathname. [We did the check too late,
and we had a buffer overflow]. Bug found by Sebastian Krahmer of SuSE,
fix inspired by patch 008 for OpenBSD-3.0.
 1.13 09-Oct-2001  mjl Replace 1 and 2 with STDOUT_FILENO and STDERR_FILENO.
ANSIfy and constify.
 1.12 11-Oct-2000  is More format string cleanups by sommerfeld.
 1.11 05-Oct-1997  mrg branches: 1.11.4; 1.11.12;
in rcleanup() don't unlink() the dfname if it contains a /. noted
by matt power <mhpower@mit.edu>.
 1.10 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.9 05-Oct-1997  mrg merge 4.4 lite2
 1.8 17-Jul-1997  mikel use <sys/cdefs.h> __RCSID macro
 1.7 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.6 15-Nov-1995  pk branches: 1.6.4;
Add RCSIDs
 1.5 11-Dec-1994  pk Correct character array declaration (bug-report bin608).
 1.4 18-May-1994  cgd clean up that import. no rcsids yet.
 1.3 21-Apr-1994  cgd header file foo
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.11.12.1 17-Oct-2000  tv Pullup usr.sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.11.4.1 19-Oct-2000  he Pull up revision 1.12 (requested by he):
Format string cleanup.
 1.14.2.1 07-Dec-2002  he Pull up revision 1.17 (requested by thorpej in ticket #947):
Rather than relying on pure luck to get the log file on
STDERR_FILENO, explicitly dup2 the log file descriptor to
STDERR_FILENO and close the original.
 1.20.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.11 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.10 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.9 15-Nov-1995  pk Add RCSIDs
 1.8 05-Oct-1995  mycroft Update from kernel source.
 1.7 05-Oct-1995  mycroft Fix typos.
 1.6 05-Oct-1995  mycroft Fix various parity and character size bugs from the termios transition.
 1.5 05-Oct-1995  mycroft Fix a couple of things broken in the termios transition.
 1.4 05-Oct-1995  mycroft Fix type errors.
 1.3 05-Oct-1995  mycroft Fix typo in previous.
 1.2 05-Oct-1995  mycroft Change to use SET(), CLR(), and ISSET() macros.
 1.1 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.7 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16 21-Dec-2016  abhinav s/results/result
Also remove .Pp before .Bl
 1.15 22-Mar-2012  wiz branches: 1.15.14;
Fix whitespace nits. Suggested by Bug Hunting.
 1.14 07-Aug-2003  agc branches: 1.14.54;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.13 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.12 08-Jul-2002  wiz Document -w. Patch from Brian Ginsbach in bin/17518.
 1.11 19-Jan-2002  wiz Sort sections.
 1.10 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.7 05-Oct-1997  mrg merge 4.4 lite2
 1.6 09-Jul-1997  jtc Changed /var/spool/* to /var/spool/output/*, to be consistant with reality.
 1.5 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.54.1 17-Apr-2012  yamt sync with head
 1.15.14.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.20 08-Apr-2022  andvar fix various typos, mainly in comments, but also log messages, docs, game text.
 1.19 22-Oct-2008  mishka Perform line feed after printing usage line.
 1.18 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.17 15-Dec-2007  perry branches: 1.17.6;
convert __attribute__s to applicable cdefs.h macros
 1.16 28-Nov-2005  christos branches: 1.16.10;
- WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.15 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.14 01-Sep-2003  itojun plug memory leak. oenbsd-pr-3425
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.12 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.11 08-Jul-2002  wiz Document -w. Patch from Brian Ginsbach in bin/17518.
 1.10 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.9 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.8 06-Jul-1998  mrg branches: 1.8.6;
- use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 05-Oct-1997  mrg merge 4.4 lite2
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.10.1 09-Jan-2008  matt sync with HEAD
 1.17.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.19 10-Mar-2009  joerg branches: 1.19.6;
Remove redundant .Xo / .Xc scope.
 1.18 21-Jan-2006  wiz branches: 1.18.28;
Bump date for previous.
 1.17 17-Jan-2006  garbled Fix PR bin/14247
This PR claims that MacOSX 10.1 cannot print postscript files to a NetBSD
lpd because the mac will tag the file with an "o" for postscript, which
we do not handle. Rather than simply mapping o -> f as was done in the
PR, or mapping o -> l as was done in FreeBSD, I have implemented full
support for the "o" option. If a postscript filter does not exist in the
printcap file however, it will default to "l" handling.

With this change, you can now specify a "pf" or postscript filter in your
printcap, and have it handle postscript files sent to it with "lpr -o".

The "o" format in lpd is specified in RFC1179 as being a valid format flag.
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.15 16-Apr-2003  wiz Sort options; fix typo; new sentence, new line.
 1.14 28-Mar-2003  perry Add a -R flag to lpr, which prints the print job number
Make lp use the -R flag to lpr unless the lp -s flag is used.
This fixes standards/17917, patches and PR from
Brian Ginsbach <ginsbach@cray.com>
 1.13 27-Mar-2003  perry Fix the broken -q option to lpr, apparently broken long ago after lpr
was converted to getopt.
Also, document the -q option.

Fix supplied by Brian Ginsbach in PR #20890
 1.12 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.11 03-Jul-2002  wiz Sort options in getopt string.
 1.10 19-Jan-2002  wiz Sort sections.
 1.9 08-May-2001  wiz Replace some .Xr with .Ic (programs non-existing or not in base system).
 1.8 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.7 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.6 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.5 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.19.6.1 17-Apr-2012  yamt sync with head
 1.47 24-Jun-2023  msaitoh Fix typo in comment.
 1.46 02-Jun-2012  jnemeth PR/46500 - Henning Petersen -- wrong permissions on create .seq files
 1.45 30-Aug-2011  joerg branches: 1.45.2;
static, __printflike, __dead
 1.44 20-Jan-2011  ginsbach - Replace fatal2() with the appropriate err(3)/errx(3) calls.
 1.43 20-Aug-2009  he branches: 1.43.2;
Remove what appears to be a spurious include of a.out.h.
 1.42 18-Jan-2009  lukem fix -Wsign-compare issues
 1.41 28-Dec-2008  christos fix for 64 bit dev_t
 1.40 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.39 07-May-2008  christos branches: 1.39.2;
patch from Dennis den Brok for foomatic
 1.38 24-Feb-2008  dholland branches: 1.38.2;
This file requires errno.h
 1.37 15-Dec-2007  perry branches: 1.37.2;
convert __attribute__s to applicable cdefs.h macros
 1.36 11-Sep-2007  ginsbach - remove extraneous \n in err(3) message
- minor KNF whitespace nit
 1.35 29-Jan-2006  christos branches: 1.35.10;
- use sizeof() instead of the buffer size.
- check write return.
- use MAXPATHLEN instead of BUFSIZ for a path buffer.
 1.34 17-Jan-2006  garbled per PR bin/12958 change buf[MAXPATHLEN] to buf[BUFSIZ] to avoid potential
future problems if either should change.
 1.33 17-Jan-2006  garbled Fix PR bin/14247
This PR claims that MacOSX 10.1 cannot print postscript files to a NetBSD
lpd because the mac will tag the file with an "o" for postscript, which
we do not handle. Rather than simply mapping o -> f as was done in the
PR, or mapping o -> l as was done in FreeBSD, I have implemented full
support for the "o" option. If a postscript filter does not exist in the
printcap file however, it will default to "l" handling.

With this change, you can now specify a "pf" or postscript filter in your
printcap, and have it handle postscript files sent to it with "lpr -o".

The "o" format in lpd is specified in RFC1179 as being a valid format flag.
 1.32 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.31 19-Aug-2005  christos 64 bit inode changes
 1.30 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.28 13-Jul-2003  itojun use bounded string op
 1.27 16-Apr-2003  wiz p before q in options/usage.
 1.26 28-Mar-2003  perry fix the fix, from Brian Ginsbach
 1.25 28-Mar-2003  perry Add a -R flag to lpr, which prints the print job number
Make lp use the -R flag to lpr unless the lp -s flag is used.
This fixes standards/17917, patches and PR from
Brian Ginsbach <ginsbach@cray.com>
 1.24 27-Mar-2003  perry Fix the broken -q option to lpr, apparently broken long ago after lpr
was converted to getopt.
Also, document the -q option.

Fix supplied by Brian Ginsbach in PR #20890
 1.23 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.22 03-Jul-2002  hubertf * Add missing 'break'
* cosmetic update in getoipt string

Patch supplied by Brian Ginsbach <ginsbach@cray.com> in PR 17473.
 1.21 08-Jun-2002  itojun avoid more hardcoded octals. openbsd
 1.20 25-Jun-2001  mrg extend file size lossage message.
 1.19 11-Oct-2000  is More format string cleanups by sommerfeld.
 1.18 27-Jul-1998  mycroft branches: 1.18.2; 1.18.10;
const poisoning.
 1.17 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.16 19-Oct-1997  mycroft Use S_IS*(), not S_IF*.
 1.15 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.14 05-Oct-1997  mrg merge 4.4 lite2
 1.13 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.12 25-Oct-1996  explorer Fix the get-a-shell hole, even if we are not currently open to that attack.
(1.2 release is, however, and this should be pulled up and released ASAP)

The previous version (1.11) checked into current limits the duration of
setuid-root periods much more than the 1.2 released version does, so the
attacker DID get a shell, but it was not a root shell.
 1.11 10-Aug-1996  explorer Fix printing over non-root-exported NFS at least.

The problem here is setuid(euid) is used far too much. Since I removed
many of these calls, and added no new ones, I do not think this weakens
security. In fact, it quite likely improves it quite a bit, since
access() is called as the real userid, and the file is opened for printing
as the real userid rather than the (setuid-root) effective one.
 1.10 21-Mar-1996  jtc branches: 1.10.4;
Be pedantic, main() returns int in C.
 1.9 15-Nov-1995  pk Add RCSIDs
 1.8 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.7 18-May-1994  cgd clean up that import. no rcsids yet.
 1.6 17-May-1994  cgd copyright foo
 1.5 07-Mar-1994  cgd Fix for symlink-related security hole. from comp.security.unix.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 25-May-1993  deraadt make lpd know about modern ar files rather than the old ones.
Like, if it's going to want to make an effort, at least do it right.
 1.2 25-May-1993  deraadt lpr should not access a_magic directly. That's what the N_BADMAG() macro
in a.out.h is there for!
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 05-Oct-1997  mrg lite-2
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.18.10.1 17-Oct-2000  tv Pullup usr.sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.18.2.1 19-Oct-2000  he Pull up revision 1.19 (requested by he):
Format string cleanup.
 1.35.10.3 23-Mar-2008  matt sync with HEAD
 1.35.10.2 09-Jan-2008  matt sync with HEAD
 1.35.10.1 06-Nov-2007  matt sync with HEAD
 1.37.2.1 24-Mar-2008  keiichi sync with head.
 1.38.2.1 18-May-2008  yamt sync with head.
 1.39.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.43.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.45.2.1 30-Oct-2012  yamt sync with head
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  mycroft Clean up deleted files.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.16 22-Mar-2012  wiz Fix whitespace nits. Suggested by Bug Hunting.
 1.15 07-Aug-2003  agc branches: 1.15.54;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.14 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.13 04-Feb-2003  perry "Utilize" has exactly the same meaning as "use," but it is more
difficult to read and understand. Most manuals of English style
therefore say that you should use "use".
 1.12 03-Jul-2002  wiz Improve last.
 1.11 03-Jul-2002  hubertf Document missing -w option.
Patch submitted by Brian Ginsbach <ginsbach@cray.com> in PR 17472.
 1.10 19-Jan-2002  wiz Sort sections, whitespace nit.
 1.9 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.8 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 09-Jul-1997  jtc Changed /var/spool/* to /var/spool/output/*, to be consistant with reality.
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 07-Jul-1995  jtc Use consistant style of quotes; PR #1194
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15.54.1 17-Apr-2012  yamt sync with head
 1.20 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.19 21-Jul-2008  lukem branches: 1.19.60;
Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.18 15-Dec-2007  perry branches: 1.18.6;
convert __attribute__s to applicable cdefs.h macros
 1.17 28-Nov-2005  christos branches: 1.17.10;
- WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.16 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
Some of this code could usefully be converted to use strtoul() and/or
some small helper functions.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.14 17-May-2003  itojun use strlcpy/strlcat.
[fix off-by-one in displayq.c]
 1.13 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.12 03-Jul-2002  kleink postive -> positive
 1.11 03-Jul-2002  wiz Fix error output for negative argument to '-w'.
Also update usage to include -w.
Patches from Brian Ginsbach in bin/17471.
 1.10 07-Dec-1999  mrg - add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.

these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.

- add a -r flag to lpd to allow `of' filters for remote jobs.

i know there are ways around this, but i just don't care.

- add a -f flag to lpf to add missing carriage returns.

useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.

- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..

- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.

this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.


i have been running these changes in production for about a year.
 1.9 16-Aug-1999  simonb branches: 1.9.4;
Spell "privilege" correctly (correct spelling from Jonathan Stone).
 1.8 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.5 15-Nov-1995  pk branches: 1.5.4;
Add RCSIDs
 1.4 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.10.1 09-Jan-2008  matt sync with HEAD
 1.18.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.60.1 10-Jun-2019  christos Sync with HEAD
 1.5 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.9 12-Aug-2002  wiz Correct usage. bin/17916 by Brian Ginsbach.
 1.8 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.7 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.6 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.5 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11 23-Jan-2018  sevan drop main() prototype
 1.10 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.9 07-Aug-2003  agc branches: 1.9.32;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.8 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.7 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.6 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.5 21-Mar-1996  jtc branches: 1.5.4;
Be pedantic, main() returns int in C.
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.9.32.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.9 18-Sep-2025  mrg introduce a couple of new turn-off-gcc-warning variables and use them.

GCC 14 has a new annoying calloc() checker that we turn off in a bunch
of places, and there are a few more dangling-pointer issuse that come up,
but seem bogus.
 1.8 10-Oct-1997  lukem only compile common_source/* once (25% faster), remove unused printcap.c
 1.7 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.6 06-May-1997  gwr Use .PATH.c: ...
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 22-Dec-1994  cgd specify man pages the new way.
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 30-Jul-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.11 07-Aug-2003  agc branches: 1.11.54;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 19-Jan-2002  wiz empty line -> .Pp; sort sections.
 1.8 04-Oct-2000  jdolecek document output format, so that users would know exact meaning
of printed statistics
 1.7 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.6 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.5 05-Oct-1997  mrg - WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.4 15-Nov-1995  pk Add RCSIDs
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.54.1 17-Apr-2012  yamt sync with head
 1.24 17-Jan-2016  christos PR/50666: David Binderman:
He's out of jail and out of bail and that's the way it goes:
free(base);
 1.23 30-Aug-2011  joerg static, __printflike, __dead
 1.22 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.21 24-Nov-2006  christos branches: 1.21.18;
fix spelling of accommodate; from Zapher.
 1.20 28-Nov-2005  christos - WARNS = 4
- factor out commonly used code.
- constify
- use warn/warnx instead of printf
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.18 13-Jul-2003  itojun use bounded string op
 1.17 17-May-2003  itojun sscanf possible overrun
 1.16 14-Jul-2002  wiz Unifdef __STDC__. Remove __P(). ANSIfy.
 1.15 16-Jul-2000  jdolecek account(): fix so that number of copies is optional and whitespace
between it and hostname:username is optional as well (some software relies
in this); while here, covert to use sscanf() instead of explicit parse code,
sprinkle some comments

dumpit(): change so that the price is total price for this entry, instead of
beeing price per copy

Addresses bin/9996 by Brian Stark, though the implementation differs from
patch code attached to it.
 1.14 27-Apr-2000  msaitoh branches: 1.14.4;
remove unused variable
 1.13 27-Apr-2000  jdolecek Finish transition to using getopt(3). Fixes bin/9963 by Brian Stark.
 1.12 05-Dec-1999  jdolecek main(): g/c variable errs accidentaly introduced in last commit, rename
'i' to 'opt'
 1.11 05-Dec-1999  jdolecek Change the formatting of output so that entries with host:user longer than
24 characters would be displayed correctly.
Fixes bin/8880 by Brian Stark <bstark@uswest.net>.

While here, convert code to use getopt(3) and do some const poisoning.
Also g/c variables uid and euid, they are no longer needed after
the split of ../common_source/common.c
 1.10 05-Oct-1997  mrg branches: 1.10.8;
- WARNS?=1
- be safe with unlinking files (from freebsd)
- remove register
- clean up $NetBSD$'s.
- use inet_ntoa() in one place (from openbsd)
- nul terminate after a bunch of strncpy()'s
- #ifdef __STDC__ rather than #if (from freebsd)
- be safe with a bunch of string operations (from freebsd)
- use warn()/err() over home grown versions (some from freebsd)
- rename warn() to nodaemon() to remove conflict with above
- check errno from failed kill(2) against ESRCH (from freebsd)
- use getopt() rather than home grown versions (from freebsd)
- clean up a bunch of man pages (some from freebsd)
- check for hostname spoof (from freebsd)
- use POSIX wait() interfaces
- use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd)
- deal with fork() failure
- index/rindex -> strchr/strrchr (some from freebsd)
- add B57600 and B115200 speeds (from freebsd)
- some KNF
- be safe with files passed in over the network (some from freebsd)
- check return value of malloc(), calloc() and strdup()
 1.9 11-Jul-1997  mikel include <unistd.h> for get{,e}uid() prototypes
 1.8 09-Dec-1996  mrg remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.
 1.7 21-Mar-1996  jtc branches: 1.7.4;
Be pedantic, main() returns int in C.
 1.6 13-Jan-1996  pk Fix typo (Noriyuki Soda; PR#1926).
 1.5 15-Nov-1995  pk Add RCSIDs
 1.4 03-Oct-1995  hpeyerl -- convert sgtty to termios. From: Scott Bartram <scottb@iis.net>
-- Use seteuid() to only give lpr, lprm, lpq and lpc root when they
need it from matthew green <mrg@mame.mu.oz.au>
 1.3 18-May-1994  cgd clean up that import. no rcsids yet.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-May-1994  cgd lpr from 4.4-Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update from trunk. Fixes security bugs.
 1.10.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.4.1 19-Oct-2000  tv Pullup 1.15 by patch [jdolecek]:
account(): fix so that number of copies is optional and whitespace
between it and hostname:username is optional as well (some software relies
in this); while here, covert to use sscanf() instead of explicit parse code,
sprinkle some comments

Portion of 1.15 dealing with changing the printing of totals is not pulled up.
 1.21.18.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.

RSS XML Feed