Date: Thu, 28 May 2026 08:27:27 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 85852fe5e4a9 - stable/14 - lpd: Restore ability to specify a port number Message-ID: <6a17fc6f.22d5d.5a14075@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=85852fe5e4a9dc48e328c7f33c3be770412de5ef commit 85852fe5e4a9dc48e328c7f33c3be770412de5ef 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:27:11 +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 83b8c457d969..fc28afe51a6f 100644 --- a/usr.sbin/lpr/lpd/lpd.8 +++ b/usr.sbin/lpr/lpd/lpd.8 @@ -27,7 +27,7 @@ .\" .\" @(#)lpd.8 8.3 (Berkeley) 4/19/94 .\" -.Dd February 19, 2026 +.Dd May 25, 2026 .Dt LPD 8 .Os .Sh NAME @@ -37,7 +37,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 . @@ -145,13 +145,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. @@ -348,6 +348,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 df9bfcec5de1..3371a764caf7 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -113,7 +113,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 */ @@ -136,7 +136,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 */ @@ -227,19 +227,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) @@ -351,7 +341,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) { @@ -867,7 +857,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; @@ -877,7 +867,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); @@ -946,9 +936,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); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a17fc6f.22d5d.5a14075>
