Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/lpr/lpd Add -W parameter to lpd to disable check fo...



details:   https://anonhg.NetBSD.org/src/rev/6f75f4d1e7a2
branches:  trunk
changeset: 513745:6f75f4d1e7a2
user:      mjl <mjl%NetBSD.org@localhost>
date:      Sat Aug 11 01:04:57 2001 +0000

description:
Add -W parameter to lpd to disable check for a reserved port,
this is needed to get Win2k print to a NetBSD box. Heavily
inspired by FreeBSD.

diffstat:

 usr.sbin/lpr/lpd/lpd.8 |   9 ++++++-
 usr.sbin/lpr/lpd/lpd.c |  54 ++++++++++++++++++++++++++-----------------------
 2 files changed, 36 insertions(+), 27 deletions(-)

diffs (216 lines):

diff -r 51421a7cab37 -r 6f75f4d1e7a2 usr.sbin/lpr/lpd/lpd.8
--- a/usr.sbin/lpr/lpd/lpd.8    Fri Aug 10 20:53:50 2001 +0000
+++ b/usr.sbin/lpr/lpd/lpd.8    Sat Aug 11 01:04:57 2001 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: lpd.8,v 1.20 2001/04/05 11:49:14 wiz Exp $
+.\"    $NetBSD: lpd.8,v 1.21 2001/08/11 01:04:57 mjl Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -41,7 +41,7 @@
 .Nd line printer spooler daemon
 .Sh SYNOPSIS
 .Nm ""
-.Op Fl dlsr
+.Op Fl dlsrW
 .Op Fl b Ar bind-address
 .Op Fl n Ar maxchild
 .Op Fl w Ar maxwait
@@ -145,6 +145,11 @@
 no response is returned from a connected server within this period,
 the connection is closed and a message logged.  The default is
 120 seconds.
+.It Fl W
+The
+.Fl W
+option will instruct lpd not to verify a remote tcp connection
+comes from a reserved port (<1024).
 .El
 .Pp
 If the
diff -r 51421a7cab37 -r 6f75f4d1e7a2 usr.sbin/lpr/lpd/lpd.c
--- a/usr.sbin/lpr/lpd/lpd.c    Fri Aug 10 20:53:50 2001 +0000
+++ b/usr.sbin/lpr/lpd/lpd.c    Sat Aug 11 01:04:57 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lpd.c,v 1.29 2001/06/25 15:29:12 mrg Exp $     */
+/*     $NetBSD: lpd.c,v 1.30 2001/08/11 01:04:57 mjl Exp $     */
 
 /*
  * Copyright (c) 1983, 1993, 1994
@@ -45,7 +45,7 @@
 #if 0
 static char sccsid[] = "@(#)lpd.c      8.7 (Berkeley) 5/10/95";
 #else
-__RCSID("$NetBSD: lpd.c,v 1.29 2001/06/25 15:29:12 mrg Exp $");
+__RCSID("$NetBSD: lpd.c,v 1.30 2001/08/11 01:04:57 mjl Exp $");
 #endif
 #endif /* not lint */
 
@@ -95,6 +95,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <dirent.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -123,7 +124,7 @@
 static void       mcleanup __P((int));
 static void       doit __P((void));
 static void       startup __P((void));
-static void       chkhost __P((struct sockaddr *));
+static void       chkhost __P((struct sockaddr *, int));
 static int       ckqueue __P((char *));
 static void      usage __P((void));
 static int       *socksetup __P((int, int, const char *));
@@ -131,10 +132,10 @@
 uid_t  uid, euid;
 int child_count;
 
+#define LPD_NOPORTCHK  0001            /* skip reserved-port check */
+
 int
-main(argc, argv)
-       int argc;
-       char **argv;
+main(int argc, char **argv)
 {
        fd_set defreadfds;
        struct sockaddr_un un, fromunix;
@@ -142,7 +143,7 @@
        sigset_t nmask, omask;
        int lfd, errs, i, f, funix, *finet;
        int child_max = 32;     /* more then enough to hose the system */
-       int options = 0;
+       int options = 0, check_options = 0;
        struct servent *sp;
        const char *port = "printer";
 
@@ -153,7 +154,7 @@
        name = argv[0];
 
        errs = 0;
-       while ((i = getopt(argc, argv, "b:dln:srw:")) != -1)
+       while ((i = getopt(argc, argv, "b:cdln:srw:W")) != -1)
                switch (i) {
                case 'b':
                        if (blist_addrs >= blist_size) {
@@ -193,6 +194,10 @@
                        if (wait_time < 30)
                            warnx("warning: wait time less than 30 seconds");
                        break;
+               case 'W':/* allow connections coming from a non-reserved port */
+                        /* (done by some lpr-implementations for MS-Windows) */
+                       check_options |= LPD_NOPORTCHK;
+                       break;
                default:
                        errs++;
                }
@@ -370,7 +375,7 @@
                        if (domain == AF_INET) {
                                /* for both AF_INET and AF_INET6 */
                                from_remote = 1;
-                               chkhost((struct sockaddr *)&frominet);
+                               chkhost((struct sockaddr *)&frominet, check_options);
                        } else
                                from_remote = 0;
                        doit();
@@ -387,8 +392,7 @@
 }
 
 static void
-reapchild(signo)
-       int signo;
+reapchild(int signo)
 {
        union wait status;
 
@@ -397,8 +401,7 @@
 }
 
 static void
-mcleanup(signo)
-       int signo;
+mcleanup(int signo)
 {
        if (lflag)
                syslog(LOG_INFO, "exiting");
@@ -427,7 +430,7 @@
 };
 
 static void
-doit()
+doit(void)
 {
        char *cp;
        int n;
@@ -546,7 +549,7 @@
  * files left from the last time the machine went down.
  */
 static void
-startup()
+startup(void)
 {
        char *buf;
        char *cp;
@@ -587,8 +590,7 @@
  * Make sure there's some work to do before forking off a child
  */
 static int
-ckqueue(cap)
-       char *cap;
+ckqueue(char *cap)
 {
        struct dirent *d;
        DIR *dirp;
@@ -614,8 +616,7 @@
  * Check to see if the from host has access to the line printer.
  */
 static void
-chkhost(f)
-       struct sockaddr *f;
+chkhost(struct sockaddr *f, int check_opts)
 {
        struct addrinfo hints, *res, *r;
        FILE *hostf;
@@ -626,9 +627,13 @@
 
        error = getnameinfo(f, f->sa_len, NULL, 0, serv, sizeof(serv),
                            NI_NUMERICSERV);
-       if (error || atoi(serv) >= IPPORT_RESERVED)
+       if (error)
                fatal("Malformed from address");
 
+         if (!(check_opts & LPD_NOPORTCHK) &&
+              atoi(serv) >= IPPORT_RESERVED)
+               fatal("Connect from invalid port (%s)", serv);
+
        /* Need real hostname for temporary filenames */
        error = getnameinfo(f, f->sa_len, host, sizeof(host), NULL, 0,
                            NI_NAMEREQD);
@@ -690,11 +695,12 @@
        /*NOTREACHED*/
 }
 
+
 static void
-usage()
+usage(void)
 {
 
-       fprintf(stderr, "usage: %s [-dlrs] [-b bind-address] [-n maxchild] "
+       fprintf(stderr, "usage: %s [-dlrsW] [-b bind-address] [-n maxchild] "
            "[-w maxwait] [port]\n", getprogname());
        exit(1);
 }
@@ -703,9 +709,7 @@
 /* if af is PF_UNSPEC more than one socket may be returned */
 /* the returned list is dynamically allocated, so caller needs to free it */
 int *
-socksetup(af, options, port)
-        int af, options;
-       const char *port;
+socksetup(int af, int options, const char *port)
 {
        struct addrinfo hints, *res, *r;
        int error, maxs = 0, *s, *socks = NULL, blidx = 0;



Home | Main Index | Thread Index | Old Index