History log of /freebsd-current/usr.sbin/lpr/lpr/lpr.c
Revision Date Author Comments
# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 8a7b6120 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 05d85d77 01-Jun-2023 Elyes Haouas <ehaouas@noos.fr>

lpr: Fix typos

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/653


# a812a5ca 15-Apr-2022 Brooks Davis <brooks@FreeBSD.org>

lpr: remove a.out binary detection

Since the first unattributed commit in 1981, lpr has attempted to
prevent users from printing executables (and in earlier versions
archives). Archive detection was lost in 1992 when lpr gained a
dependency on a.out.h. No corresponding support was added for ELF files
with the full transiation to ELF in 1998, but a.out support has been
dragged forward to and contaminated platforms that never supported
a.out.

While this feature isn't unuseful, preventing the printing of
a single file format we stopped producing ~20 years ago isn't worth
the costs (however minimal).

Reviewed by: gad, imp, emaste
Differential Revision: https://reviews.freebsd.org/D34901


# df57947f 18-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

spdx: initial adoption of licensing ID tags.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes: yes
Differential Revision: https://reviews.freebsd.org/D13133


# 9b337054 17-Dec-2014 Gleb Kurtsou <gleb@FreeBSD.org>

Adjust printf format specifiers for dev_t and ino_t in user space.

ino_t and dev_t are about to become uint64_t.

Reviewed by: kib, mckusick


# 1d1d4a47 21-Oct-2012 Eitan Adler <eadler@FreeBSD.org>

Check the return error of set[ug]id. While this can never fail in the
current version of FreeBSD, this isn't guarenteed by the API. Custom
security modules, or future implementations of the setuid and setgid
may fail.

PR: bin/172289
PR: bin/172290
PR: bin/172291
Submittud by: Erik Cederstrand <erik@cederstrand.dk>
Discussed by: freebsd-security
Approved by: cperciva
MFC after: 1 week


# b424efd5 27-Sep-2012 Matthew D Fleming <mdf@FreeBSD.org>

Fix usr.bin/ and usr.sbin/ build with a 64-bit ino_t.

Original code by: Gleb Kurtsou


# 31fd5c11 29-May-2012 Eitan Adler <eadler@FreeBSD.org>

Relax security permissions on '.seq' file creation - the strict,
but odd permissions resulted in a security alert from 110.neggrpperm

PR: kern/165533
Submitted by: Anton Shterenlikht <mexas@bristol.ac.uk>
Submitted by: J B <jb.1234abcd@gmail.com>
Approved by: cperciva
MFC after: 1 week


# e7820994 21-Oct-2010 Edwin Groothuis <edwin@FreeBSD.org>

Fix printing of files located on ZFS filesystem with an st_dev or
st_ino larger than 2**31.

From the PR:

Printing from a ZFS filesystem using 'lp' fails and returns an
email reporting "Your printer job was not printed because it was
not linked to the original file".

In order to protect against files being switched when files
are printed using 'lp' or 'lpr -s', the st_dev and st_ino
values for the original file are saved by lpr and verified
by lpd before the file is printed. Unfortunately, lpr prints
both values using '%d' (although both fields are unsigned)
and lpd(8) assumes a string of decimal digits.

ZFS (at least) generates st_dev values greater than 2^31-1,
resulting in negative values being printed - which lpd cannot
parse, leading it to report that the file has been switched.

A similar problem would occur with large inode numbers.

How-To-Repeat:

Find a file with either st_dev or st_ino greater than 2^31-1
(stat(1) will report both numbers) and print it with 'lpq -s'.
This should generate an email reporting that the file could
not be printed because it was not linked to the original file

PR: bin/151567
Submitted by: Peter Jeremy <Peter.Jeremy@alcatel-lucent.com>
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 6d261443 15-Jul-2003 Garance A Drosehn <gad@FreeBSD.org>

More changes to use __FBSDID() for setting rcsids, and fix the
format of 'sccsid' lines so they consistently match style(9)
Also the 'sccsid' line is formatted to match style(9), and
a 'From:' is removed so the sccsid returns to what it was back
in the days of '-r CSRG' (1996).

Reviewed by: discussed with bde and obrien
MFC after: 15 days


# f16d68d0 25-Apr-2002 Garance A Drosehn <gad@FreeBSD.org>

Include <netinet/in.h> to squash one more compile-time warning.

MFC after: 3 days


# ce0b09c3 08-Oct-2001 Garance A Drosehn <gad@FreeBSD.org>

Fix one more compile-time warning by renaming a local variable.

MFC after: 4 days


# 9e75a09e 08-Oct-2001 Garance A Drosehn <gad@FreeBSD.org>

Fix a compile-time warning by declaring 'len' as size_t instead of int.

MFC after: 4 days


# ce89013a 08-Oct-2001 Garance A Drosehn <gad@FreeBSD.org>

Rename the local variable 'person' to 'lpr_username', to avoid compile-time
warnings about conflict with a global variable used by 'lprm'.

MFC after: 4 days


# fd41faa7 14-Jul-2001 Garance A Drosehn <gad@FreeBSD.org>

Replace a call to 'alloca', thus avoiding an error when compiling on
freebsd/alpha with -ansi (and on some non-fbsd platforms). This change
can only affect the access checking of 'lpr -r'.

MFC after: 1 week


# cc3fd56f 15-Jun-2001 Garance A Drosehn <gad@FreeBSD.org>

Rename a few global variables which hold hostname-related values to be
more sensible/understandable. 'from'->'from_host' 'host'->'local_host'
'fromb'->'frombuf' 'fromhost'->'origin_host' and a local-variable
named 'host'->'hostbuf'. This fixes some compile-time warnings about
local variables shadowing global variables.

Other than renaming variables, the only actual code changes are to call
strlcpy() instead of strncpy() when setting those (renamed) variables,
and that 'from_ip' is now a strdup()-created buffer instead of being a
static buffer compiled in as 1025 bytes.

Reviewed by: freebsd-print@bostonradio.org (an earlier version)
MFC after: 1 week


# 31058a75 15-Jun-2001 Garance A Drosehn <gad@FreeBSD.org>

Rename global variable 'name' to 'progname', thus fixing a number of
warnings which come up for various routines that have a parameter which
is also called 'name'.

Reviewed by: freebsd-print@bostonradio.org
MFC after: 1 week


# ba7a1ad7 12-Jun-2001 Garance A Drosehn <gad@FreeBSD.org>

Fix about 90-100 warnings one gets when trying to compile lpr&friends
with BDECFLAGS on, mainly by adding 'const' to parameters in a number
of routine declarations. While I'm at it, ANSI-fy all of the routine
declarations. The resulting object code is exactly the same after
this update as before it, with the exception of one unavoidable
change to lpd.o on freebsd/alpha.

Also added $FreeBSD$ line to lpc/extern.h lpc/lpc.h lptest/lptest.c

Reviewed by: /sbin/md5, and no feedback from freebsd-audit


# 4c4f66db 02-Nov-2000 Garance A Drosehn <gad@FreeBSD.org>

This update gets it so 'lpr -r' ("remove the file after printing") will
try to move the file from the source to the destination (spool) directory.
If that succeeds, much time and disk-space will be saved by doing that
instead of copying the entire file only to remove the original. This
could be a big win on machines doing samba-service or CAP-based printing.

Note that this is about the fourth or fifth iteration of the patch, after
trying to address all possible security implications of the change.

PR: 16124
Reviewed by: freebsd-current or freebsd-hackers (some time ago)


# 160325d6 31-Oct-2000 Garance A Drosehn <gad@FreeBSD.org>

Change 'lpr' so -C (class) information is included in the control file
even for jobs or queues which will not print header (separator) pages.

Submitted by: "Steve O'Hara-Smith" <steveo@eircom.net>


# 10915f6e 21-Jun-2000 Garrett Wollman <wollman@FreeBSD.org>

Allow those of us who have to print through LPRng spoolers to send
spooler options using `Z' control-file lines and the `-Z' flag.


# 7fcba904 19-Jan-2000 Josef Karthauser <joe@FreeBSD.org>

It's not been possible to configure a print server running lpd,
with remote hosts feeding it, so that some hosts have their header
pages supressed and some don't. This is because lpd doesn't know
how to rewrite a print job before forwarding it to a remote lpd.
In particular this causes problems with p rinters that contain
their own lpd, eg. HP jet direct cards, because they can't suppress
headers. It's not possible to have headers supressed by putting
'sh' in any printcap in the lpd chain, it is up to the originating
lpr to have a '-h' option specified at run time.

Lpr has been modified to allow _it_ to honour the 'sh' flag in the
local print cap. This allows the administrator to switch off
headers for a particular printer (on a particular host) irrespective
of whether that printer is local to the machine or remote.

This doesn't break anything, because in the case of a remote printer
the 'sh' flag would have had no meaning, in the case of the local
printer it would have been on anyway.

Submitted by: Scott James Remnant <scott@pavilion.net>


# d3d56c3d 30-Nov-1999 Andrey A. Chernov <ache@FreeBSD.org>

Add support for pr's locale


# 97d92980 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 9112ae0f 01-Feb-1999 Garrett Wollman <wollman@FreeBSD.org>

Sigh. Fix capitalization bogon. Who had the pointy hat?


# 4f92720c 01-Feb-1999 Garrett Wollman <wollman@FreeBSD.org>

Observe -U flag again, and use it in preference to getlogin(), if
the user is privileged.

I believe this should address both concerns in PR 9729, and may also
provide the desired behavior from PR 9485.


# 66d959c3 06-Jan-1999 Warner Losh <imp@FreeBSD.org>

Change my mind on using base '0' for strtol for -i and -# operations
as this would change the meaning of -#050 in preexisting scripts.


# 65073469 06-Jan-1999 Warner Losh <imp@FreeBSD.org>

Add sanity checking to argument for -# and -i. Require these
arguments to be numbers. Also use '0' base to allow hex, octal or
decimal numbers.

This was done by me based on ideas in pr 3556, submitted by Uwe
Laubenstein and commented upon by j@uriah.heep.sax.de (J Wunsch).

PR: 3556


# 90cf373d 11-Sep-1998 Garrett Wollman <wollman@FreeBSD.org>

Fix additional warnings. Remove -Werror, since some people have complained
about it.

PR: 7886
Submitted by: Stefan Eggers <seggers@semyam.dinoco.de> (partially)


# 69d23ff0 17-Apr-1998 David E. O'Brien <obrien@FreeBSD.org>

Make ``-h'' follow the manpage, and suppress the burst page reguardless of
the number of ``-h'' given.


# 79031fd7 06-Dec-1997 John Polstra <jdp@FreeBSD.org>

Fix incorrect format string in call to errx().


# 4a1a0dbe 02-Dec-1997 Garrett Wollman <wollman@FreeBSD.org>

Mega lpd/lpd upgrade, part I:

- Get rid of a lot of the static variables which were shared by
many routines and programs in the suite.
- Create an abstract interface to the printcap database, so that
other retrieval and iteration mechanisms could be developed
(e.g., YP, Hesiod, or automatic retrieval from a trusted server).
- Give each capability a human-readable name in addition to the historic
two-character one.
- Otherwise generally clean up a lot of dark corners. Many still remain.
- When submitting jobs, use the official login name record (from getlogin())
if there is one, rather than reverse-mapping the uid.

More to come...


# 9b3fe531 24-Sep-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3). Add usage(). Various fixes in man pages.


# 6ee8b269 29-Jul-1997 Warner Losh <imp@FreeBSD.org>

Two minor, pedantic fixes from bde for my last pedantic fixes, plus
the following from recent OpenBSD changes. These changes (and all
I've made) should be merged back into 2.2 when they are vetted in
-current.

common.c:
OpenBSD 1.7: mickey: #if __STDC__ --> #ifdef __STDC__

displayq.c:
OpenBSD 1.8: deraadt: 1 byte oflows; millert

rmjob.c:
OpenBSD 1.8: deraadt: 1 byte oflows; millert

cmds.c:
OpenBSD 1.9: grr: restore traditional "all" keyword option - see lpc(8)
[[ This makes lpc status all work again -- imp ]]

printjob.c:
OpenBSD 1.17: deraadt: use sendmail -t
OpenBSD 1.16: mickey: #if __STDC__ --> #ifdef __STDC__
OpenBSD 1.15: deraadt: 1 byte oflow; Don.Lewis@tsc.tdk.com

recvjob.c:
OpenBSD 1.11: mickey: #if __STDC__ --> #ifdef __STDC__

lpr.c:
OpenBSD 1.19: mickey: #if __STDC__ --> #ifdef __STDC__

Obtained from: OpenBSD


# 5f87a7b6 28-Jul-1997 Warner Losh <imp@FreeBSD.org>

Fix boatloads of buffer overflows from the OpenBSD tree.
Be pedantic about always using sizeof(blah) vs sizeof (blah) or sizeof blah.
Obtained from:OpenBSD


# f8eb25da 23-Jul-1997 Warner Losh <imp@FreeBSD.org>

index -> strchr and rindex -> strrchr to reduce the number of gratuitous
diffes with NetBSD/OpenBSD. These changes seem to predate the NetBSD/OpenBSD
split, so it is hard to give proper credit for them.
Obtained from: OpenBSD.


# 360d4ad5 22-Jul-1997 Warner Losh <imp@FreeBSD.org>

Use setuid/seteuid around dangerous operations. Also a few buffer
overflow patches that were "near" to where these operations are taking
place. The buffer overflows are from OpenBSD. The setuid/seteuid patches
are from NetBSD by way of OpenBSD (they changed them a little), at least from
my read of the tree.

This is the first of a series of OpenBSD lpr/et al merges. It (and them)
should be merged back into 2.2 and/or 2.1 (if requested) branches when they
have been shaken out in -current.
Obtained from: OpenBSD


# d8ae1328 08-Jul-1997 Dima Ruban <dima@FreeBSD.org>

Fixed buffer overflow.

Reviewed by: Warner


# 9f38c2e5 13-May-1997 Brian Somers <brian@FreeBSD.org>

Don't drop into the troff args after parsing -#.

Submitted by: Garance A Drosehn <gad@eclipse.its.rpi.edu>


# 6c3f552a 30-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 156de774 25-Feb-1997 Mike Pritchard <mpp@FreeBSD.org>

Fix an off by one error when determing the default job name for
the banner page.

Closes PR# 1986.

Submitted by: Mark Valentine <mark@linus.demon.co.uk>


# 476602a9 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# bc407914 26-Oct-1996 Warner Losh <imp@FreeBSD.org>

lpc/cmds.c:
From NetBSD via OpenBSD to fix NetBSD PR #506
More descriptive message for printer status
(OpenBSD: 1.2)

Various warnings cleaned up (OpenBSD: 1.4)

lpc/lpc.c:
Various warnings cleaned up (OpenBSD: 1.3)

lpd/lpd.c:
Remove trailing blank lines (OpenBSD: 1.2)

Potential umask problem with creating /dev/printer
(OpenBSD: 1.4 and 1.5)

Ftp bounce attack (untested on FreeBSD)
(OpenBSD: 1.6, 1.8, 1.9)
Fencepost in strncpy
(OpenBSD: 1.6)

lpd/printjob.c:
Fix from freebsd for waiting for an exiting filter, that
appears not in the FreeBSD CVS tree.
(OpenBSD: 1.6)

lpd/recvjob.c:
Buffer overflow protection: use strncpy rather than strcpy.
(OpenBSD: 1.3)

lpr/lpr.c:
NetBSD change of return type for main()
(OpenBSD: 1.2)

Restrict time running as root
(OpenBSD: 1.7)

Use getcwd rather than getwd (from NetBSD)

Use snprintf rather than sprintf
(OpenBSD: 1.8)

Minor tweak to end of loop and buffer overflow sanity. card()
overflow already in FreeBSD
(OpenBSD: 1.9)

lptest/lptest.c:
void -> int return type of main, from NetBSD via OpenBSD
(OpenBSD: 1.2)

pac/pac.c:
void -> int return type of main, from NetBSD via OpenBSD
(OpenBSD: 1.3)

Obtained from: OpenBSD


# d1f8ff8c 25-Oct-1996 Warner Losh <imp@FreeBSD.org>

Fix transcription error I introduced in last patch. This created a
fencepost error that would run one off the end of the buffer.

Noticed by: Bruce Evans


# 4f6653b9 25-Oct-1996 Warner Losh <imp@FreeBSD.org>

Fix a problem where the command line could be used to overflow a stack
buffer which could be made to lead to a root shell. This patch is
OpenBSD's solution to the problem, and will silently truncate the
output rather than overflow the buffer.

Obtained from: OpenBSD


# afc417e0 11-May-1996 Joerg Wunsch <joerg@FreeBSD.org>

Convert the option parser to use getopt(3). This makes it more
orthogonal with the rest of the system (you can now use either -PPS or
-P PS), and makes the parser more intelligible. The only drawback is
that the old semantics for the -i flag in case a non-numeric argument
is following are no longer fully supported (only if -i is the very
last arg at all), since getopt(3) doesn't support the discticnction
between numeric and non-numeric arguments.

Make lpr also understand dashes as input pseudo filenames. This
finally makes lp(1) fully comply with Posix.2.


# 7f72cbba 09-May-1996 Joerg Wunsch <joerg@FreeBSD.org>

Cleanup.

The removed files are no longer needed, they are actually labelled as
``Use only if you are not 4.4BSD''. (Yeah, the ol' crufty printcap.c
is really gone!)

Properly declare all external objects in files ending in .h, as
opposed to embed them into files ending in .c.


# 5458e2f4 05-May-1996 Joerg Wunsch <joerg@FreeBSD.org>

Pull a bunch of fixes from the 4.4BSD-Lite2 branch. It's really
surprising how many trivial errors there have been... :-)

Some more cleanup is needed, but i'd like to separate the Lite2 changes
from other work, that's why this goes into a different commit.

People with serial printers should see whether i have broken the stty-
style printcap options (i hope not).

Inspired by: Sergey Shkonda <serg@bcs1.bcs.zaporizhzhe.ua>


# 0b561052 05-May-1996 Joerg Wunsch <joerg@FreeBSD.org>

Vendor-branch import of the 4.4BSD-Lite2 code for lpr. There are
several bugfixes in it that are worth considering.

Don't be alarmed about the import conflicts...

Obtained from: 4.4BSD-Lite2


# edab52dd 05-Oct-1995 Jordan K. Hubbard <jkh@FreeBSD.org>

Fix a longstanding bug in `lpr -r'. I used alloca() instead of
malloc(), but the change is fundamentally Chris's.
Submitted by: Chris Stenton <jacs@gnome.co.uk>


# e162d528 17-Jul-1995 Torsten Blum <torstenb@FreeBSD.org>

lpr uses access(2) to determine if the parent directory of the file
is writeable (by the real uid). if it is, lpr assumes that the file
can be unlinked. lpr does not check for directories with S_ISVTX set

Reviewed by: dima


# 709e8f9a 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# dea673e9 25-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite usr.sbin Sources