git: eb5bab240e00 - stable/15 - lpd: Restore ability to specify a port number
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 28 May 2026 08:25:17 UTC
The branch stable/15 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=eb5bab240e00c539c6e43edcc2625b40e010863b
commit eb5bab240e00c539c6e43edcc2625b40e010863b
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-05-25 16:51:31 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-05-28 08:24:16 +0000
lpd: Restore ability to specify a port number
This has been broken since IPv6 support was added in 2000. We would
validate the port number (which had to be a port number, but can now
also be a service name) and then ignore it.
MFC after: 1 week
Fixes: 08829865f659 ("IPv6 support for lpr.")
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D57181
(cherry picked from commit c0cae7d8da50daa87af4cd6d7c9a2043343b506f)
---
usr.sbin/lpr/lpd/lpd.8 | 19 ++++++++++---------
usr.sbin/lpr/lpd/lpd.c | 28 +++++++++-------------------
2 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8
index 9d24a450ba0e..269ef3580ce7 100644
--- a/usr.sbin/lpr/lpd/lpd.8
+++ b/usr.sbin/lpr/lpd/lpd.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd February 19, 2026
+.Dd May 25, 2026
.Dt LPD 8
.Os
.Sh NAME
@@ -35,7 +35,7 @@
.Nm
.Op Fl cdlpsFW46
.Op Fl t Ar timeout
-.Op Ar port#
+.Op Ar port
.Sh DEPRECATION NOTICE
This facility is scheduled for removal prior to the release of
.Fx 16.0 .
@@ -143,13 +143,13 @@ Inet only.
Inet6 only.
.It Fl 46
Inet and inet6 (default).
-.It Ar "port#"
-The Internet port number used to rendezvous
-with other processes is normally obtained with
-.Xr getservbyname 3
-but can be changed with the
-.Ar port#
-argument.
+.It Ar "port"
+The Internet port number or service name used to rendezvous with other
+processes.
+Can be any number from 1 to 65,535 or any service name defined in
+.Pa /etc/services .
+Defaults to
+.Li printer .
.El
.Pp
Access control is provided by two means.
@@ -346,6 +346,7 @@ but not under same administrative control.
.Xr syslog 3 ,
.Xr hosts.lpd 5 ,
.Xr printcap 5 ,
+.Xr services 5 ,
.Xr chkprintcap 8 ,
.Xr lpc 8 ,
.Xr pac 8
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index d1dcd0766a77..5550846dca18 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -101,7 +101,7 @@ static void startup(void);
static void chkhost(struct sockaddr *_f, int _ch_opts);
static int ckqueue(struct printer *_pp);
static void fhosterr(int _ch_opts, char *_sysmsg, char *_usermsg);
-static int *socksetup(int _af, int _debuglvl);
+static int *socksetup(int _af, const char *portstr, int _debuglvl);
static void usage(void);
/* XXX from libc/net/rcmd.c */
@@ -124,7 +124,7 @@ main(int argc, char **argv)
struct sockaddr_storage frominet;
socklen_t fromlen;
sigset_t omask, nmask;
- struct servent *sp, serv;
+ const char *portstr = "printer";
int inet_flag = 0, inet6_flag = 0;
euid = geteuid(); /* these shouldn't be different */
@@ -215,19 +215,9 @@ main(int argc, char **argv)
if (errs)
usage();
- if (argc == 1) {
- if ((i = atoi(argv[0])) == 0)
- usage();
- if (i < 0 || i > USHRT_MAX)
- errx(EX_USAGE, "port # %d is invalid", i);
-
- serv.s_port = htons(i);
- sp = &serv;
+ if (argc > 0) {
+ portstr = *argv++;
argc--;
- } else {
- sp = getservbyname("printer", "tcp");
- if (sp == NULL)
- errx(EX_OSFILE, "printer/tcp: unknown service");
}
if (argc != 0)
@@ -339,7 +329,7 @@ main(int argc, char **argv)
FD_SET(funix, &defreadfds);
listen(funix, 5);
if (sflag == 0) {
- finet = socksetup(family, socket_debug);
+ finet = socksetup(family, portstr, socket_debug);
} else
finet = NULL; /* pretend we couldn't open TCP socket. */
if (finet) {
@@ -855,7 +845,7 @@ fhosterr(int ch_opts, char *sysmsg, char *usermsg)
/* if af is PF_UNSPEC more than one socket may be returned */
/* the returned list is dynamically allocated, so caller needs to free it */
static int *
-socksetup(int af, int debuglvl)
+socksetup(int af, const char *portstr, int debuglvl)
{
struct addrinfo hints, *res, *r;
int error, maxs, *s, *socks;
@@ -865,7 +855,7 @@ socksetup(int af, int debuglvl)
hints.ai_flags = AI_PASSIVE;
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
- error = getaddrinfo(NULL, "printer", &hints, &res);
+ error = getaddrinfo(NULL, portstr, &hints, &res);
if (error) {
syslog(LOG_ERR, "%s", gai_strerror(error));
mcleanup(0);
@@ -934,9 +924,9 @@ static void
usage(void)
{
#ifdef INET6
- fprintf(stderr, "usage: lpd [-cdlsFW46] [port#]\n");
+ fprintf(stderr, "usage: lpd [-cdlsFW46] [port]\n");
#else
- fprintf(stderr, "usage: lpd [-cdlsFW] [port#]\n");
+ fprintf(stderr, "usage: lpd [-cdlsFW] [port]\n");
#endif
exit(EX_USAGE);
}