Add -p option to prevent lpd(8) from opening a listening socket.

PR:		17384
Submitted by:	Niels Endres <niels@b5.nu>
This commit is contained in:
Sheldon Hearn 2000-03-29 11:15:54 +00:00
parent b565321aa1
commit ba901a111b
2 changed files with 32 additions and 17 deletions

View File

@ -40,7 +40,7 @@
.Nd line printer spooler daemon
.Sh SYNOPSIS
.Nm lpd
.Op Fl dl
.Op Fl dlp
.Op Ar port#
.Sh DESCRIPTION
.Nm Lpd
@ -75,6 +75,12 @@ flag causes
to log valid requests received from the network.
This can be useful
for debugging purposes.
.It Fl p
The
.Fl p
flag causes
.Nm
not to open an Internet listening socket.
.It Ar "port#"
The Internet port number used to rendezvous
with other processes is normally obtained with

View File

@ -104,6 +104,7 @@ static const char rcsid[] =
#include "extern.h"
int lflag; /* log requests flag */
int pflag; /* no incoming port flag */
int from_remote; /* from remote socket */
int main __P((int, char **));
@ -144,7 +145,7 @@ main(argc, argv)
errx(EX_NOPERM,"must run as root");
errs = 0;
while ((i = getopt(argc, argv, "dl")) != -1)
while ((i = getopt(argc, argv, "dlp")) != -1)
switch (i) {
case 'd':
options |= SO_DEBUG;
@ -152,6 +153,9 @@ main(argc, argv)
case 'l':
lflag++;
break;
case 'p':
pflag++;
break;
default:
errs++;
}
@ -278,22 +282,25 @@ main(argc, argv)
FD_ZERO(&defreadfds);
FD_SET(funix, &defreadfds);
listen(funix, 5);
finet = socket(AF_INET, SOCK_STREAM, 0);
if (finet >= 0) {
if (options & SO_DEBUG)
if (setsockopt(finet, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) {
if (pflag == 0) {
finet = socket(AF_INET, SOCK_STREAM, 0);
if (finet >= 0) {
if (options & SO_DEBUG &&
setsockopt(finet, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) {
syslog(LOG_ERR, "setsockopt (SO_DEBUG): %m");
mcleanup(0);
}
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = sp->s_port;
if (bind(finet, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
syslog(LOG_ERR, "bind: %m");
mcleanup(0);
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = sp->s_port;
if (bind(finet, (struct sockaddr *)&sin,
sizeof(sin)) < 0) {
syslog(LOG_ERR, "bind: %m");
mcleanup(0);
}
FD_SET(finet, &defreadfds);
listen(finet, 5);
}
FD_SET(finet, &defreadfds);
listen(finet, 5);
}
/*
* Main loop: accept, do a request, continue.
@ -318,7 +325,7 @@ main(argc, argv)
domain = AF_UNIX, fromlen = sizeof(fromunix);
s = accept(funix,
(struct sockaddr *)&fromunix, &fromlen);
} else /* if (FD_ISSET(finet, &readfds)) */ {
} else if (pflag == 0) /* if (FD_ISSET(finet, &readfds)) */ {
domain = AF_INET, fromlen = sizeof(frominet);
s = accept(finet,
(struct sockaddr *)&frominet, &fromlen);
@ -339,7 +346,9 @@ main(argc, argv)
signal(SIGQUIT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
(void) close(funix);
(void) close(finet);
if (pflag == 0) {
(void) close(finet);
}
dup2(s, 1);
(void) close(s);
if (domain == AF_INET) {
@ -629,6 +638,6 @@ chkhost(f)
static void
usage()
{
fprintf(stderr, "usage: lpd [-dl] [port#]\n");
fprintf(stderr, "usage: lpd [-dlp] [port#]\n");
exit(EX_USAGE);
}