summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/lpr/common_source/displayq.c3
-rw-r--r--usr.sbin/lpr/common_source/lp.h1
-rw-r--r--usr.sbin/lpr/lpd/lpd.88
-rw-r--r--usr.sbin/lpr/lpd/lpd.c69
4 files changed, 55 insertions, 26 deletions
diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c
index d326e79..4e5f060 100644
--- a/usr.sbin/lpr/common_source/displayq.c
+++ b/usr.sbin/lpr/common_source/displayq.c
@@ -76,6 +76,7 @@ static char *head0 = "Rank Owner Job Files";
static char *head1 = "Total Size\n";
static void alarmhandler __P((int));
+static void warn __P((void));
/*
* Display the current state of the queue. Format = 1 if long format.
@@ -257,7 +258,7 @@ displayq(format)
/*
* Print a warning message if there is no daemon present.
*/
-void
+static void
warn()
{
if (remote)
diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h
index 0c94372..5fdd7c5 100644
--- a/usr.sbin/lpr/common_source/lp.h
+++ b/usr.sbin/lpr/common_source/lp.h
@@ -128,6 +128,5 @@ void rmjob __P((void));
void rmremote __P((void));
void show __P((char *, char *, int));
int startdaemon __P((char *));
-void warn __P((void));
void delay __P((int));
__END_DECLS
diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8
index b8fe9bf..3b6d768 100644
--- a/usr.sbin/lpr/lpd/lpd.8
+++ b/usr.sbin/lpr/lpd/lpd.8
@@ -39,7 +39,7 @@
.Nd line printer spooler daemon
.Sh SYNOPSIS
.Nm lpd
-.Op Fl l
+.Op Fl dl
.Op Ar port#
.Sh DESCRIPTION
.Nm Lpd
@@ -60,6 +60,11 @@ the request so the parent can continue to listen for more requests.
.Pp
Available options:
.Bl -tag -width Ds
+.It Fl d
+Turn on
+.Dv SO_DEBUG
+on the Internet listening socket (see
+.Xr setsockopt 2 ) .
.It Fl l
The
.Fl l
@@ -236,6 +241,7 @@ but not under same administrative control.
.Xr lpq 1 ,
.Xr lpr 1 ,
.Xr lprm 1 ,
+.Xr setsockopt 2 ,
.Xr syslog 3 ,
.Xr hosts.lpd 5 ,
.Xr printcap 5 ,
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index 1a7448a..7fc8a8f 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -85,12 +85,14 @@ static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
#include <unistd.h>
#include <syslog.h>
#include <signal.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <ctype.h>
#include "lp.h"
#include "lp.local.h"
@@ -106,6 +108,7 @@ static void doit __P((void));
static void startup __P((void));
static void chkhost __P((struct sockaddr_in *));
static int ckqueue __P((char *));
+static void usage __P((void));
uid_t uid, euid;
@@ -114,11 +117,12 @@ main(argc, argv)
int argc;
char **argv;
{
- int f, funix, finet, options, fromlen;
+ int f, funix, finet, options, fromlen, i, errs;
fd_set defreadfds;
struct sockaddr_un un, fromunix;
struct sockaddr_in sin, frominet;
int omask, lfd;
+ struct servent *sp, serv;
euid = geteuid(); /* these shouldn't be different */
uid = getuid();
@@ -127,24 +131,44 @@ main(argc, argv)
name = "lpd";
- if (euid != 0) {
- fprintf(stderr,"lpd: must run as root\n");
- exit(1);
- }
+ if (euid != 0)
+ errx(EX_NOPERM,"must run as root");
- while (--argc > 0) {
- argv++;
- if (argv[0][0] == '-')
- switch (argv[0][1]) {
- case 'd':
- options |= SO_DEBUG;
- break;
- case 'l':
- lflag++;
- break;
- }
+ errs = 0;
+ while ((i = getopt(argc, argv, "dl")) != -1)
+ switch (i) {
+ case 'd':
+ options |= SO_DEBUG;
+ break;
+ case 'l':
+ lflag++;
+ break;
+ default:
+ errs++;
+ }
+ argc -= optind;
+ argv += optind;
+ 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;
+ argc--;
+ } else {
+ sp = getservbyname("printer", "tcp");
+ if (sp == NULL)
+ errx(EX_OSFILE, "printer/tcp: unknown service");
}
+ if (argc != 0)
+ usage();
+
#ifndef DEBUG
/*
* Set up standard environment by detaching from the parent.
@@ -211,18 +235,11 @@ main(argc, argv)
listen(funix, 5);
finet = socket(AF_INET, SOCK_STREAM, 0);
if (finet >= 0) {
- struct servent *sp;
-
if (options & SO_DEBUG)
if (setsockopt(finet, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) {
syslog(LOG_ERR, "setsockopt (SO_DEBUG): %m");
mcleanup(0);
}
- sp = getservbyname("printer", "tcp");
- if (sp == NULL) {
- syslog(LOG_ERR, "printer/tcp: unknown service");
- mcleanup(0);
- }
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = sp->s_port;
@@ -585,3 +602,9 @@ again:
fatal("Your host does not have line printer access");
/*NOTREACHED*/
}
+
+void
+usage()
+{
+ errx(EX_USAGE, "usage: lpd [-dl] [port#]");
+}
OpenPOWER on IntegriCloud