bug fixes and changes for lpc command.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 14 May 1983 02:54:11 +0000 (18:54 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 14 May 1983 02:54:11 +0000 (18:54 -0800)
SCCS-vsn: usr.sbin/lpr/common_source/printcap.c 1.5
SCCS-vsn: usr.sbin/lpr/lpd/lpd.c 4.2
SCCS-vsn: usr.sbin/lpr/lpq/lpq.c 4.2
SCCS-vsn: usr.sbin/lpr/lpr/lpr.c 4.16
SCCS-vsn: usr.sbin/lpr/lprm/lprm.c 4.2
SCCS-vsn: usr.sbin/lpr/Makefile 4.9
SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 4.2
SCCS-vsn: usr.sbin/lpr/lpd/recvjob.c 4.2
SCCS-vsn: usr.sbin/lpr/common_source/rmjob.c 4.2
SCCS-vsn: usr.sbin/lpr/common_source/startdaemon.c 4.2
SCCS-vsn: usr.sbin/lpr/common_source/common.c 4.2
SCCS-vsn: usr.sbin/lpr/common_source/lp.h 4.2

12 files changed:
usr/src/usr.sbin/lpr/Makefile
usr/src/usr.sbin/lpr/common_source/common.c
usr/src/usr.sbin/lpr/common_source/lp.h
usr/src/usr.sbin/lpr/common_source/printcap.c
usr/src/usr.sbin/lpr/common_source/rmjob.c
usr/src/usr.sbin/lpr/common_source/startdaemon.c
usr/src/usr.sbin/lpr/lpd/lpd.c
usr/src/usr.sbin/lpr/lpd/printjob.c
usr/src/usr.sbin/lpr/lpd/recvjob.c
usr/src/usr.sbin/lpr/lpq/lpq.c
usr/src/usr.sbin/lpr/lpr/lpr.c
usr/src/usr.sbin/lpr/lprm/lprm.c

index 55bb01e..554c45b 100644 (file)
@@ -1,4 +1,4 @@
-#      @(#)Makefile    4.8     (Berkeley)      %G%
+#      @(#)Makefile    4.9     (Berkeley)      %G%
 #
 # makefile for line printer spooling system
 #
 #
 # makefile for line printer spooling system
 #
@@ -18,27 +18,17 @@ DAEMON=daemon
 SPGRP=daemon
 DESTDIR=
 
 SPGRP=daemon
 DESTDIR=
 
-SRCS=  lpd.c lpr.c lpq.c lprm.c restart.c pac.c \
-       startup.c printjob.c recvjob.c displayq.c rmjob.c \
-       startdaemon.c common.c printcap.c lpdchar.c lpf.c necf.c \
-       rvsort.c rvcat.c vsort.c vcat.c vpf.c vpsf.c vdmp.c vpltdmp.c \
-       vfontinfo.c vwidth.c vfw.c fcvt.c rotate.c rotprt.c
-OBJS=  lpd lpr lpq lprm restart pac
-PRINTER=       lpf necf
-VARIAN=        rvsort rvcat vsort vcat vpf vpsf vdmp vpltdmp vfontinfo vwidth \
-       vfw fcvt rotate rotprt
+SRCS=  lpd.c lpr.c lpq.c lprm.c pac.c lpd.c cmds.c cmdtab.c \
+       printjob.c recvjob.c displayq.c rmjob.c \
+       startdaemon.c common.c printcap.c lpdchar.c
+OBJS=  lpd lpr lpq lprm pac lpc
 
 all:   ${OBJS}
 
 
 all:   ${OBJS}
 
-printer: ${PRINTER}
-
-varian:        ${VARIAN}
-
-lpd:   lpd.o startup.o printjob.o recvjob.o displayq.o rmjob.o \
+lpd:   lpd.o printjob.o recvjob.o displayq.o rmjob.o \
        startdaemon.o lpdchar.o common.o printcap.o
        startdaemon.o lpdchar.o common.o printcap.o
-       ${CC} -o lpd lpd.o startup.o printjob.o recvjob.o \
-               displayq.o rmjob.o startdaemon.o lpdchar.o common.o printcap.o \
-               -ljobs
+       ${CC} -o lpd lpd.o printjob.o recvjob.o displayq.o rmjob.o \
+               startdaemon.o lpdchar.o common.o printcap.o -ljobs
 
 lpr:   lpr.o startdaemon.o common.o printcap.o
        ${CC} -o lpr lpr.o startdaemon.o common.o printcap.o -ljobs
 
 lpr:   lpr.o startdaemon.o common.o printcap.o
        ${CC} -o lpr lpr.o startdaemon.o common.o printcap.o -ljobs
@@ -49,96 +39,30 @@ lpq:        lpq.o displayq.o common.o printcap.o
 lprm:  lprm.o rmjob.o startdaemon.o common.o printcap.o
        ${CC} -o lprm lprm.o rmjob.o startdaemon.o common.o printcap.o
 
 lprm:  lprm.o rmjob.o startdaemon.o common.o printcap.o
        ${CC} -o lprm lprm.o rmjob.o startdaemon.o common.o printcap.o
 
-restart: restart.o startdaemon.o common.o printcap.o
-       ${CC} -o restart restart.o startdaemon.o common.o printcap.o
-
-lpf:   lpf.c
-       ${CC} -o lpf ${CFLAGS} lpf.c
-
-necf:  necf.c
-       ${CC} -o necf ${CFLAGS} necf.c
-
-rvsort:        rvsort.c
-       ${CC} -o rvsort ${CFLAGS} rvsort.c
-
-rvcat: rvcat.c
-       ${CC} -o rvcat ${CFLAGS} rvcat.c
-
-vsort: vsort.c
-       ${CC} -o vsort ${CFLAGS} vsort.c
-
-vcat:  vcat.c
-       ${CC} -o vcat ${CFLAGS} vcat.c
-
-vpf:   vpf.c
-       ${CC} -o vpf ${CFLAGS} vpf.c
-
-vpsf:  vpsf.c
-       ${CC} -o vpsf ${CFLAGS} vpsf.c
-
-vdmp: vdmp.c
-       ${CC} -o vdmp ${CFLAGS} vdmp.c
-
-vpltdmp: vpltdmp.c
-       ${CC} -o vpltdmp ${CFLAGS} vpltdmp.c
-
-vfontinfo: vfontinfo.c
-       ${CC} -o vfontinfo ${CFLAGS} vfontinfo.c
-
-vwidth: vwidth.c
-       ${CC} -o vwidth ${CFLAGS} vwidth.c
-
-vfw: vfw.c
-       ${CC} -o vfw ${CFLAGS} vfw.c
-
-fcvt: fcvt.c
-       ${CC} -o fcvt ${CFLAGS} fcvt.c
-
-rotate: rotate.c
-       ${CC} -o rotate ${CFLAGS} rotate.c
-
-rotprt: rotprt.c
-       ${CC} -o rotprt ${CFLAGS} rotprt.c
+lpc:   lpc.o cmds.o cmdtab.o startdaemon.o common.o printcap.o
+       ${CC} -o lpc lpc.o cmds.o cmdtab.o startdaemon.o common.o printcap.o -ljobs
 
 pac:   pac.o printcap.o
        ${CC} -o pac pac.o printcap.o
 
 
 pac:   pac.o printcap.o
        ${CC} -o pac pac.o printcap.o
 
-lpd.o lpr.o lpq.o lprm.o restart.o pac.o: lp.h lp.local.h
+lpd.o lpr.o lpq.o lprm.o pac.o: lp.h lp.local.h
 recvjob.o printjob.o displayq.o rmjob.o common.o: lp.h lp.local.h
 recvjob.o printjob.o displayq.o rmjob.o common.o: lp.h lp.local.h
+lpc.o cmdtab.o: lpc.h
+cmds.o: lp.h lp.local.h
 
 install: all
        install -s -g ${SPGRP} -m 6711 lpd ${DESTDIR}${LIBDIR}/lpd
        install -s -g ${SPGRP} -m 6711 lpr ${DESTDIR}${BINDIR}/lpr
        install -s -g ${SPGRP} -m 6711 lpq ${DESTDIR}${BINDIR}/lpq
        install -s -g ${SPGRP} -m 6711 lprm ${DESTDIR}${BINDIR}/lprm
 
 install: all
        install -s -g ${SPGRP} -m 6711 lpd ${DESTDIR}${LIBDIR}/lpd
        install -s -g ${SPGRP} -m 6711 lpr ${DESTDIR}${BINDIR}/lpr
        install -s -g ${SPGRP} -m 6711 lpq ${DESTDIR}${BINDIR}/lpq
        install -s -g ${SPGRP} -m 6711 lprm ${DESTDIR}${BINDIR}/lprm
-       install -s -g ${SPGRP} -m 6711 restart ${DESTDIR}${BINDIR}/restart
+       install -s -g ${SPGRP} -m 6711 lpc ${DESTDIR}/etc/lpc
+       install -s pac ${DESTDIR}/etc/pac
        chown ${DAEMON} ${DESTDIR}${SPOOLDIR}
        chgrp ${SPGRP} ${DESTDIR}${SPOOLDIR}
        chmod 775 ${DESTDIR}${SPOOLDIR}
        chown ${DAEMON} ${DESTDIR}${SPOOLDIR}
        chgrp ${SPGRP} ${DESTDIR}${SPOOLDIR}
        chmod 775 ${DESTDIR}${SPOOLDIR}
-       install -s pac ${DESTDIR}/etc/pac
-
-installp: filters
-       install -s lpf ${DESTDIR}${LIBDIR}/lpf
-       install -s necf ${DESTDIR}${LIBDIR}/necf
-
-installv: varian
-       install -s vfontinfo ${DESTDIR}${LIBDIR}/vfontinfo
-       install -s vwidth ${DESTDIR}${LIBDIR}/vwidth
-       install -s vfw ${DESTDIR}${LIBDIR}/vfw
-       install -s fcvt ${DESTDIR}${LIBDIR}/fcvt
-       install -s rotate ${DESTDIR}${LIBDIR}/rotate
-       install -s rotprt ${DESTDIR}${LIBDIR}/rotprt
-       install -s rvsort ${DESTDIR}${LIBDIR}/rvsort
-       install -s rvcat ${DESTDIR}${LIBDIR}/rvcat
-       install -s vsort ${DESTDIR}${LIBDIR}/vsort
-       install -s vcat ${DESTDIR}${LIBDIR}/vcat
-       install -s vpf ${DESTDIR}${LIBDIR}/vpf
-       install -s vpsf ${DESTDIR}${LIBDIR}/vpsf
-       install -s vdmp ${DESTDIR}${LIBDIR}/vdmp
-       install -s vpltdmp ${DESTDIR}${LIBDIR}/vpltdmp
 
 clean:
 
 clean:
-       rm -f ${OBJS} ${PRINTER} ${VARIAN} *.o
+       rm -f ${OBJS} *.o
 
 print:
        @pr makefile
 
 print:
        @pr makefile
index ee000d1..9703265 100644 (file)
@@ -1,4 +1,4 @@
-/*     common.c        4.1     83/04/29        */
+/*     common.c        4.2     83/05/13        */
 /*
  * Routines and data common to all the line printer functions.
  */
 /*
  * Routines and data common to all the line printer functions.
  */
@@ -17,6 +17,7 @@ char  *AF;            /* accounting file */
 char   *LF;            /* log file for error messages */
 char   *OF;            /* name of output filter (created once) */
 char   *IF;            /* name of input filter (created per job) */
 char   *LF;            /* log file for error messages */
 char   *OF;            /* name of output filter (created once) */
 char   *IF;            /* name of input filter (created per job) */
+char   *RF;            /* name of fortran text filter (per job) */
 char   *TF;            /* name of troff filter (per job) */
 char   *DF;            /* name of tex filter (per job) */
 char   *GF;            /* name of graph(1G) filter (per job) */
 char   *TF;            /* name of troff filter (per job) */
 char   *DF;            /* name of tex filter (per job) */
 char   *GF;            /* name of graph(1G) filter (per job) */
@@ -31,11 +32,14 @@ short       SB;             /* short banner instead of normal header */
 short  RW;             /* open LP for reading and writing */
 short  PW;             /* page width */
 short  PL;             /* page length */
 short  RW;             /* open LP for reading and writing */
 short  PW;             /* page width */
 short  PL;             /* page length */
+short  PX;             /* page width in pixels */
+short  PY;             /* page length in pixels */
 short  BR;             /* baud rate if lp is a tty */
 short  FC;             /* flags to clear if lp is a tty */
 short  FS;             /* flags to set if lp is a tty */
 short  XC;             /* flags to clear for local mode */
 short  XS;             /* flags to set for local mode */
 short  BR;             /* baud rate if lp is a tty */
 short  FC;             /* flags to clear if lp is a tty */
 short  FS;             /* flags to set if lp is a tty */
 short  XC;             /* flags to clear for local mode */
 short  XS;             /* flags to set for local mode */
+short  RS;             /* restricted to those with local accounts */
 
 char   line[BUFSIZ];
 char   pbuf[BUFSIZ/2]; /* buffer for printcap strings */
 
 char   line[BUFSIZ];
 char   pbuf[BUFSIZ/2]; /* buffer for printcap strings */
@@ -223,22 +227,6 @@ compar(p1, p2)
        return(0);
 }
 
        return(0);
 }
 
-/*VARARGS1*/
-status(msg, a1, a2, a3)
-       char *msg;
-{
-       register int fd;
-       char buf[BUFSIZ];
-
-       umask(0);
-       if ((fd = open(ST, FWRONLY|FCREATE|FTRUNCATE|FEXLOCK, 0664)) < 0)
-               fatal("cannot create status file");
-       sprintf(buf, msg, a1, a2, a3);
-       strcat(buf, "\n");
-       (void) write(fd, buf, strlen(buf));
-       (void) close(fd);
-}
-
 /*VARARGS1*/
 fatal(msg, a1, a2, a3)
        char *msg;
 /*VARARGS1*/
 fatal(msg, a1, a2, a3)
        char *msg;
index f7cbd4c..40ecf49 100644 (file)
@@ -1,4 +1,4 @@
-/*     lp.h    4.1     83/04/29        */
+/*     lp.h    4.2     83/05/13        */
 /*
  * Global definitions for the line printer system.
  */
 /*
  * Global definitions for the line printer system.
  */
@@ -31,6 +31,7 @@ extern char   *AF;            /* accounting file */
 extern char    *LF;            /* log file for error messages */
 extern char    *OF;            /* name of output filter (created once) */
 extern char    *IF;            /* name of input filter (created per job) */
 extern char    *LF;            /* log file for error messages */
 extern char    *OF;            /* name of output filter (created once) */
 extern char    *IF;            /* name of input filter (created per job) */
+extern char    *RF;            /* name of fortran text filter (per job) */
 extern char    *TF;            /* name of troff(1) filter (per job) */
 extern char    *DF;            /* name of tex filter (per job) */
 extern char    *GF;            /* name of graph(1G) filter (per job) */
 extern char    *TF;            /* name of troff(1) filter (per job) */
 extern char    *DF;            /* name of tex filter (per job) */
 extern char    *GF;            /* name of graph(1G) filter (per job) */
@@ -43,12 +44,15 @@ extern short        SH;             /* suppress header page */
 extern short   SB;             /* short banner instead of normal header */
 extern short   RW;             /* open LP for reading and writing */
 extern short   PW;             /* page width */
 extern short   SB;             /* short banner instead of normal header */
 extern short   RW;             /* open LP for reading and writing */
 extern short   PW;             /* page width */
+extern short   PX;             /* page width in pixels */
+extern short   PY;             /* page length in pixels */
 extern short   PL;             /* page length */
 extern short   BR;             /* baud rate if lp is a tty */
 extern short   FC;             /* flags to clear if lp is a tty */
 extern short   FS;             /* flags to set if lp is a tty */
 extern short   XC;             /* flags to clear for local mode */
 extern short   XS;             /* flags to set for local mode */
 extern short   PL;             /* page length */
 extern short   BR;             /* baud rate if lp is a tty */
 extern short   FC;             /* flags to clear if lp is a tty */
 extern short   FS;             /* flags to set if lp is a tty */
 extern short   XC;             /* flags to clear for local mode */
 extern short   XS;             /* flags to set for local mode */
+extern short   RS;             /* restricted to those with local accounts */
 
 extern char    line[BUFSIZ];
 extern char    pbuf[];         /* buffer for printcap entry */
 
 extern char    line[BUFSIZ];
 extern char    pbuf[];         /* buffer for printcap entry */
index cd368f6..0621297 100644 (file)
@@ -1,10 +1,10 @@
-/*     printcap.c      1.4     83/01/05        */
+/*     printcap.c      1.5     83/05/13        */
 /* Copyright (c) 1979 Regents of the University of California */
 #define        BUFSIZ  1024
 #define MAXHOP 32      /* max number of tc= indirections */
 
 #include <ctype.h>
 /* Copyright (c) 1979 Regents of the University of California */
 #define        BUFSIZ  1024
 #define MAXHOP 32      /* max number of tc= indirections */
 
 #include <ctype.h>
-#include "local/uparm.h"
+#include <stdio.h>
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
 #define V6
 #endif
 
 #define V6
 #endif
 
+static FILE *pfp = NULL;       /* printcap data base file pointer */
 static char *tbuf;
 static char *tbuf;
-static int hopcount;   /* detect infinite loops in termcap, init 0 */
+static int hopcount;           /* detect infinite loops in termcap, init 0 */
 char   *tskip();
 char   *tgetstr();
 char   *tdecode();
 char   *getenv();
 
 char   *tskip();
 char   *tgetstr();
 char   *tdecode();
 char   *getenv();
 
+/*
+ * Similar to tgetent except it returns the next enrty instead of
+ * doing a lookup.
+ */
+getprent(bp)
+       register char *bp;
+{
+       register int c, skip = 0;
+
+       if (pfp == NULL && (pfp = fopen(E_TERMCAP, "r")) == NULL)
+               return(-1);
+       tbuf = bp;
+       for (;;) {
+               switch (c = getc(pfp)) {
+               case EOF:
+                       fclose(pfp);
+                       pfp = NULL;
+                       return(0);
+               case '\n':
+                       if (bp == tbuf) {
+                               skip = 0;
+                               continue;
+                       }
+                       if (bp[-1] == '\\') {
+                               bp--;
+                               continue;
+                       }
+                       *bp = '\0';
+                       return(1);
+               case '#':
+                       if (bp == tbuf)
+                               skip++;
+               default:
+                       if (skip)
+                               continue;
+                       if (bp >= tbuf+BUFSIZ) {
+                               write(2, "Termcap entry too long\n", 23);
+                               *bp = '\0';
+                               return(1);
+                       }
+                       *bp++ = c;
+               }
+       }
+}
+
+endprent()
+{
+       if (pfp != NULL)
+               fclose(pfp);
+}
+
 /*
  * Get an entry for terminal name in buffer bp,
  * from the termcap file.  Parse is very rudimentary;
 /*
  * Get an entry for terminal name in buffer bp,
  * from the termcap file.  Parse is very rudimentary;
index 8afc77b..f9c2aa5 100644 (file)
@@ -1,4 +1,4 @@
-/*     rmjob.c 4.1     83/04/29        */
+/*     rmjob.c 4.2     83/05/13        */
 /*
  * rmjob - remove the specified jobs from the queue.
  */
 /*
  * rmjob - remove the specified jobs from the queue.
  */
@@ -27,8 +27,6 @@ rmjob()
        int assasinated = 0;
        struct direct **files;
 
        int assasinated = 0;
        struct direct **files;
 
-       name = "rmjob";
-
        if ((i = pgetent(line, printer)) < 0)
                fatal("cannot open printer description file");
        else if (i == 0)
        if ((i = pgetent(line, printer)) < 0)
                fatal("cannot open printer description file");
        else if (i == 0)
@@ -40,7 +38,7 @@ rmjob()
        if ((LP = pgetstr("lp", &bp)) == NULL)
                LP = DEFDEVLP;
        if ((RP = pgetstr("rp", &bp)) == NULL)
        if ((LP = pgetstr("lp", &bp)) == NULL)
                LP = DEFDEVLP;
        if ((RP = pgetstr("rp", &bp)) == NULL)
-               RP = printer;
+               RP = DEFLP;
        if ((RM = pgetstr("rm", &bp)) == NULL)
                RM = host;
 
        if ((RM = pgetstr("rm", &bp)) == NULL)
                RM = host;
 
@@ -201,26 +199,21 @@ chk(file)
 
 /*
  * If root is removing a file on the local machine, allow it.
 
 /*
  * If root is removing a file on the local machine, allow it.
- * If root is removing a file on a remote machine, only allow
- * files sent from the local machine to be removed.
+ * If root is removing a file from a remote machine, only allow
+ * files sent from the remote machine to be removed.
  * Normal users can only remove the file from where it was sent.
  */
 isowner(owner, file)
        char *owner, *file;
 {
  * Normal users can only remove the file from where it was sent.
  */
 isowner(owner, file)
        char *owner, *file;
 {
-       register int r;
-
-       if (from == host)
-               r = access(file, 2) == 0;
-       else
-               r = (!strcmp(person, root) || !strcmp(person, owner)) &&
-                       !strcmp(from, file+6);
-       if (!r) {
-               if (from != host)
-                       printf("%s: ", host);
-               printf("%s: Permission denied\n", file);
-       }
-       return(r);
+       if (!strcmp(person, root) && (from == host || !strcmp(from, file+6)))
+               return(1);
+       if (!strcmp(person, owner) && !strcmp(from, file+6))
+               return(1);
+       if (from != host)
+               printf("%s: ", host);
+       printf("%s: Permission denied\n", file);
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -236,6 +229,12 @@ chkremote()
        if (*LP || RM == NULL)
                return; /* not sending to a remote machine */
 
        if (*LP || RM == NULL)
                return; /* not sending to a remote machine */
 
+       /*
+        * Flush stdout so the user can see what has been deleted
+        * while we wait (possibly) for the connection.
+        */
+       fflush(stdout);
+
        sprintf(buf, "\5%s %s", RP, all ? "-all" : person);
        cp = buf;
        for (i = 0; i < users; i++) {
        sprintf(buf, "\5%s %s", RP, all ? "-all" : person);
        cp = buf;
        for (i = 0; i < users; i++) {
index df76220..cbac415 100644 (file)
@@ -1,4 +1,4 @@
-/*     startdaemon.c   4.1     83/04/29        */
+/*     startdaemon.c   4.2     83/05/13        */
 /*
  * Tell the printer daemon that there are new files in the spool directory.
  */
 /*
  * Tell the printer daemon that there are new files in the spool directory.
  */
index 93a636f..41694b8 100644 (file)
@@ -1,4 +1,4 @@
-/*     lpd.c   4.1     83/04/29        */
+/*     lpd.c   4.2     83/05/13        */
 /*
  * lpd -- line printer daemon.
  *
 /*
  * lpd -- line printer daemon.
  *
  *             return the current state of the queue (long form).
  *     \5printer person [users ...] [jobs ...]\n
  *             remove jobs from the queue.
  *             return the current state of the queue (long form).
  *     \5printer person [users ...] [jobs ...]\n
  *             remove jobs from the queue.
+ *     \6printer\n
+ *             enable queuing on the specified printer queue.
+ *     \7printer\n
+ *             disable queuing on the specified printer queue.
+ *     \8printer\n
+ *             return the queue status (queuing enabled or disabled).
  *
  * Strategy to maintain protected spooling area:
  *     1. Spooling area is writable only by daemon and spooling group
  *
  * Strategy to maintain protected spooling area:
  *     1. Spooling area is writable only by daemon and spooling group
@@ -21,7 +27,7 @@
  *        root to access any file it wants (verifying things before
  *        with an access call) and group id to know how it should
  *        set up ownership of files in the spooling area.
  *        root to access any file it wants (verifying things before
  *        with an access call) and group id to know how it should
  *        set up ownership of files in the spooling area.
- *     3. Files in spooling area are owned by the owner, group spooling
+ *     3. Files in spooling area are owned by root, group spooling
  *        group, with mode 660.
  *     4. lpd, lpq and lprm run setuid daemon and setgrp spooling group to
  *        access files and printer.  Users can't get to anything
  *        group, with mode 660.
  *     4. lpd, lpq and lprm run setuid daemon and setgrp spooling group to
  *        access files and printer.  Users can't get to anything
@@ -30,6 +36,7 @@
 
 #include "lp.h"
 
 
 #include "lp.h"
 
+int    lflag;                                  /* log requests flag */
 char   *logfile = DEFLOGF;
 struct sockaddr_in sin = { AF_INET };
 int    reapchild();
 char   *logfile = DEFLOGF;
 struct sockaddr_in sin = { AF_INET };
 int    reapchild();
@@ -40,7 +47,7 @@ main(argc, argv)
        char **argv;
 {
        int f, options;
        char **argv;
 {
        int f, options;
-       struct sockaddr_in from;
+       struct sockaddr_in fromaddr;
        struct servent *sp;
 
        gethostname(host, sizeof(host));
        struct servent *sp;
 
        gethostname(host, sizeof(host));
@@ -48,7 +55,7 @@ main(argc, argv)
 
        sp = getservbyname("printer", "tcp");
        if (sp == NULL) {
 
        sp = getservbyname("printer", "tcp");
        if (sp == NULL) {
-               log("printer/tcp: unknown service");
+               fprintf(stderr, "printer/tcp: unknown service");
                exit(1);
        }
        sin.sin_port = sp->s_port;
                exit(1);
        }
        sin.sin_port = sp->s_port;
@@ -61,15 +68,19 @@ main(argc, argv)
                                options |= SO_DEBUG;
                                break;
                        case 'l':
                                options |= SO_DEBUG;
                                break;
                        case 'l':
+                               lflag++;
+                               break;
+                       case 'L':
                                argc--;
                                logfile = *++argv;
                                break;
                        }
                else {
                        int port = atoi(argv[0]);
                                argc--;
                                logfile = *++argv;
                                break;
                        }
                else {
                        int port = atoi(argv[0]);
+                       int c = argv[0][0];
 
 
-                       if (port < 0) {
-                               fprintf(stderr, "%s: bad port #\n", argv[0]);
+                       if (c < '0' || c > '9' || port < 0) {
+                               fprintf(stderr, "lpd: %s: bad port number\n", argv[0]);
                                exit(1);
                        }
                        sin.sin_port = htons((u_short) port);
                                exit(1);
                        }
                        sin.sin_port = htons((u_short) port);
@@ -99,8 +110,10 @@ main(argc, argv)
                exit(1);
        }
        if (options & SO_DEBUG)
                exit(1);
        }
        if (options & SO_DEBUG)
-               if (setsockopt(f, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
+               if (setsockopt(f, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) {
                        logerror("setsockopt (SO_DEBUG)");
                        logerror("setsockopt (SO_DEBUG)");
+                       exit(1);
+               }
        if (bind(f, &sin, sizeof(sin), 0) < 0) {
                logerror("bind");
                exit(1);
        if (bind(f, &sin, sizeof(sin), 0) < 0) {
                logerror("bind");
                exit(1);
@@ -116,19 +129,19 @@ main(argc, argv)
        sigset(SIGCHLD, reapchild);
        listen(f, 10);
        for (;;) {
        sigset(SIGCHLD, reapchild);
        listen(f, 10);
        for (;;) {
-               int s, len = sizeof(from);
+               int s, len = sizeof(fromaddr);
 
 
-               s = accept(f, &from, &len, 0);
+               s = accept(f, &fromaddr, &len, 0);
                if (s < 0) {
                        if (errno == EINTR)
                                continue;
                        logerror("accept");
                if (s < 0) {
                        if (errno == EINTR)
                                continue;
                        logerror("accept");
-                       continue;
+                       exit(1);
                }
                if (fork() == 0) {
                        sigset(SIGCHLD, SIG_IGN);
                        (void) close(f);
                }
                if (fork() == 0) {
                        sigset(SIGCHLD, SIG_IGN);
                        (void) close(f);
-                       doit(s, &from);
+                       doit(s, &fromaddr);
                        exit(0);
                }
                (void) close(s);
                        exit(0);
                }
                (void) close(s);
@@ -151,12 +164,20 @@ int       users;                  /* # of users in user array */
 int    requ[MAXREQUESTS];      /* job number of spool entries */
 int    requests;               /* # of spool requests */
 
 int    requ[MAXREQUESTS];      /* job number of spool entries */
 int    requests;               /* # of spool requests */
 
-char   cbuf[BUFSIZ];           /* command line buffer */
 char   fromb[32];              /* buffer for client's machine name */
 char   fromb[32];              /* buffer for client's machine name */
+char   cbuf[BUFSIZ];           /* command line buffer */
+char   *cmdnames[] = {
+       "null",
+       "printjob",
+       "recvjob",
+       "displayq short",
+       "displayq long",
+       "rmjob"
+};
 
 
-doit(f, fromp)
+doit(f, fromaddr)
        int f;
        int f;
-       struct sockaddr_in *fromp;
+       struct sockaddr_in *fromaddr;
 {
        register char *cp;
        register struct hostent *hp;
 {
        register char *cp;
        register struct hostent *hp;
@@ -167,16 +188,18 @@ doit(f, fromp)
        dup2(f, 1);
        (void) close(f);
        f = 1;
        dup2(f, 1);
        (void) close(f);
        f = 1;
-       fromp->sin_port = ntohs(fromp->sin_port);
-       if (fromp->sin_family != AF_INET || fromp->sin_port >= IPPORT_RESERVED)
+       fromaddr->sin_port = ntohs(fromaddr->sin_port);
+       if (fromaddr->sin_family != AF_INET || fromaddr->sin_port >= IPPORT_RESERVED)
                fatal("Malformed from address");
                fatal("Malformed from address");
-       hp = gethostbyaddr(&fromp->sin_addr, sizeof(struct in_addr),
-               fromp->sin_family);
+       hp = gethostbyaddr(&fromaddr->sin_addr, sizeof(struct in_addr),
+               fromaddr->sin_family);
        if (hp == 0)
                fatal("Host name for your address (%s) unknown",
        if (hp == 0)
                fatal("Host name for your address (%s) unknown",
-                       ntoa(fromp->sin_addr));
+                       ntoa(fromaddr->sin_addr));
        strcpy(fromb, hp->h_name);
        from = fromb;
        strcpy(fromb, hp->h_name);
        from = fromb;
+       if (chkhost())
+               fatal("Your host does not have line printer access");
        for (;;) {
                cp = cbuf;
                do {
        for (;;) {
                cp = cbuf;
                do {
@@ -191,6 +214,10 @@ doit(f, fromp)
                } while (c != '\n');
                *--cp = '\0';
                cp = cbuf;
                } while (c != '\n');
                *--cp = '\0';
                cp = cbuf;
+               if (lflag && *cp >= '\1' && *cp <= '\5') {
+                       printer = NULL;
+                       log("%s requests %s %s", from, cmdnames[*cp], cp+1);
+               }
                switch (*cp++) {
                case '\1':      /* check the queue and print any jobs there */
                        printer = cp;
                switch (*cp++) {
                case '\1':      /* check the queue and print any jobs there */
                        printer = cp;
@@ -200,8 +227,8 @@ doit(f, fromp)
                        printer = cp;
                        recvjob();
                        break;
                        printer = cp;
                        recvjob();
                        break;
-               case '\3':      /* send back the short form queue status */
-               case '\4':      /* send back the long form queue status */
+               case '\3':      /* display the queue (short form) */
+               case '\4':      /* display the queue (long form) */
                        printer = cp;
                        while (*cp) {
                                if (*cp != ' ') {
                        printer = cp;
                        while (*cp) {
                                if (*cp != ' ') {
@@ -261,6 +288,61 @@ doit(f, fromp)
        }
 }
 
        }
 }
 
+/*
+ * Make a pass through the printcap database and start printing any
+ * files left from the last time the machine went down.
+ */
+startup()
+{
+       char buf[BUFSIZ];
+       register char *cp;
+       int pid;
+
+       printer = buf;
+
+       /*
+        * Restart the daemons.
+        */
+       while (getprent(buf) > 0) {
+               for (cp = buf; *cp; cp++)
+                       if (*cp == '|' || *cp == ':') {
+                               *cp = '\0';
+                               break;
+                       }
+               if ((pid = fork()) < 0) {
+                       log("startup: cannot fork");
+                       exit(1);
+               }
+               if (!pid) {
+                       endprent();
+                       printjob();
+               }
+       }
+}
+
+/*
+ * Check to see if the from host has access to the line printer.
+ */
+chkhost()
+{
+       register FILE *hostf;
+       register char *cp;
+       char ahost[50];
+
+       hostf = fopen("/etc/hosts.equiv", "r");
+       while (fgets(ahost, sizeof(ahost), hostf)) {
+               if (cp = index(ahost, '\n'))
+                       *cp = '\0';
+               cp = index(ahost, ' ');
+               if (!strcmp(from, ahost) && cp == NULL) {
+                       (void) fclose(hostf);
+                       return(0);
+               }
+       }
+       (void) fclose(hostf);
+       return(-1);
+}
+
 /*
  * Convert network-format internet address
  * to base 256 d.d.d.d representation.
 /*
  * Convert network-format internet address
  * to base 256 d.d.d.d representation.
@@ -303,7 +385,7 @@ logerror(msg)
        extern char *sys_errlist[];
 
        fprintf(stderr, console ? "\r\n%s: " : "%s: ", name);
        extern char *sys_errlist[];
 
        fprintf(stderr, console ? "\r\n%s: " : "%s: ", name);
-       if (*msg)
+       if (msg)
                fprintf(stderr, "%s: ", msg);
        fputs(err < sys_nerr ? sys_errlist[err] : "Unknown error" , stderr);
        if (console)
                fprintf(stderr, "%s: ", msg);
        fputs(err < sys_nerr ? sys_errlist[err] : "Unknown error" , stderr);
        if (console)
index 7f23a18..25c5387 100644 (file)
@@ -1,4 +1,4 @@
-/*     printjob.c      4.1     83/04/29        */
+/*     printjob.c      4.2     83/05/13        */
 /*
  * printjob -- print jobs in the queue.
  *
 /*
  * printjob -- print jobs in the queue.
  *
index 7f81a80..2e27f53 100644 (file)
@@ -1,4 +1,4 @@
-/*     recvjob.c       4.1     83/04/29        */
+/*     recvjob.c       4.2     83/05/13        */
 /*
  * Receive printer jobs from the network, queue them and
  * start the printer daemon.
 /*
  * Receive printer jobs from the network, queue them and
  * start the printer daemon.
index 691d5a6..c51be85 100644 (file)
@@ -1,4 +1,4 @@
-/*     lpq.c   4.1     83/04/29        */
+/*     lpq.c   4.2     83/05/13        */
 /*
  * Spool Queue examination program
  *
 /*
  * Spool Queue examination program
  *
@@ -46,6 +46,9 @@ main(argc, argv)
        register char *arg;
        register int n;
 
        register char *arg;
        register int n;
 
+       name = argv[0];
+       gethostname(host, sizeof(host));
+
        while (--argc) {
                if ((arg = *++argv)[0] == '+') {
                        if (arg[1] != '\0')
        while (--argc) {
                if ((arg = *++argv)[0] == '+') {
                        if (arg[1] != '\0')
@@ -78,7 +81,6 @@ main(argc, argv)
        }
        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
                printer = DEFLP;
        }
        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
                printer = DEFLP;
-       gethostname(host, sizeof(host));
 #ifdef TERMCAP
        dumb = termcap();
 #endif
 #ifdef TERMCAP
        dumb = termcap();
 #endif
index 03a9244..0928fef 100644 (file)
@@ -55,7 +55,7 @@
 
 char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
 
 
 char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
 
-/*     lpr.c   4.15    83/04/29        */
+/*     lpr.c   4.16    83/05/13        */
 /*
  *      lpr -- off line print
  *
 /*
  *      lpr -- off line print
  *
@@ -113,8 +113,8 @@ main(argc, argv)
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
                signal(SIGTERM, cleanup);
 
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
                signal(SIGTERM, cleanup);
 
-       gethostname(host, sizeof (host));
        name = argv[0];
        name = argv[0];
+       gethostname(host, sizeof (host));
 
        while (argc > 1 && argv[1][0] == '-') {
                argc--;
 
        while (argc > 1 && argv[1][0] == '-') {
                argc--;
@@ -216,6 +216,12 @@ main(argc, argv)
        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
                printer = DEFLP;
        chkprinter(printer);
        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
                printer = DEFLP;
        chkprinter(printer);
+       /*
+        * Check to make sure queuing is enabled.
+        */
+       (void) sprintf(line, "%s/%s", SD, LO);
+       if (stat(line, &stb) == 0 && (stb.st_mode & 010))
+               fatal("Printer queue is disabled");
        /*
         * Get the identity of the person doing the lpr using the same
         * algorithm as lprm. 
        /*
         * Get the identity of the person doing the lpr using the same
         * algorithm as lprm. 
@@ -262,27 +268,29 @@ main(argc, argv)
                if ((f = test(arg = *++argv)) < 0)
                        continue;       /* file unreasonable */
 
                if ((f = test(arg = *++argv)) < 0)
                        continue;       /* file unreasonable */
 
-               if ((f & 1) && (cp = linked(arg)) != NULL) {
+               if (sflag && (cp = linked(arg)) != NULL) {
                        if (format == 'p')
                                card('T', title ? title : arg);
                        for (i = 0; i < ncopies; i++)
                                card(format, &dfname[inchar-2]);
                        card('U', &dfname[inchar-2]);
                        if (format == 'p')
                                card('T', title ? title : arg);
                        for (i = 0; i < ncopies; i++)
                                card(format, &dfname[inchar-2]);
                        card('U', &dfname[inchar-2]);
-                       if (f & 2)
+                       if (f)
                                card('U', cp);
                        card('N', arg);
                        dfname[inchar]++;
                        nact++;
                                card('U', cp);
                        card('N', arg);
                        dfname[inchar]++;
                        nact++;
-               } else {
-                       if ((i = open(arg, 0)) < 0) {
-                               printf("%s: cannot open %s\n", name, arg);
-                               continue;
-                       }
-                       copy(i, arg);
-                       (void) close(i);
-                       if ((f & 2) && unlink(arg))
-                               printf("%s: cannot remove %s\n", name, arg);
+                       continue;
+               }
+               if (sflag)
+                       printf("%s: %s: not linked, copying instead\n", name, arg);
+               if ((i = open(arg, 0)) < 0) {
+                       printf("%s: cannot open %s\n", name, arg);
+                       continue;
                }
                }
+               copy(i, arg);
+               (void) close(i);
+               if (f && unlink(arg) < 0)
+                       printf("%s: %s: not removed\n", name, arg);
        }
 
        if (nact) {
        }
 
        if (nact) {
@@ -364,7 +372,7 @@ linked(file)
        register char *file;
 {
        register char *cp;
        register char *file;
 {
        register char *cp;
-       char buf[BUFSIZ];
+       static char buf[BUFSIZ];
 
        if (*file != '/') {
                if (getwd(buf) == NULL)
 
        if (*file != '/') {
                if (getwd(buf) == NULL)
@@ -425,11 +433,6 @@ nfile(n)
                printf("%s: cannot create %s\n", name, n);
                cleanup();
        }
                printf("%s: cannot create %s\n", name, n);
                cleanup();
        }
-       if (chown(n, userid, -1) < 0) {
-               unlink(n);
-               printf("%s: cannot chown %s\n", name, n);
-               cleanup();
-       }
        if (++n[inchar] > 'z') {
                if (++n[inchar-2] == 't') {
                        printf("too many files - break up the job\n");
        if (++n[inchar] > 'z') {
                if (++n[inchar-2] == 't') {
                        printf("too many files - break up the job\n");
@@ -473,7 +476,7 @@ cleanup()
 
 /*
  * Test to see if this is a printable file.
 
 /*
  * Test to see if this is a printable file.
- * Return -1 if it is not, 1 if we should try to link and or in 2 if
+ * Return -1 if it is not, 0 if its printable, and 1 if
  * we should remove it after printing.
  */
 test(file)
  * we should remove it after printing.
  */
 test(file)
@@ -516,21 +519,20 @@ test(file)
                        goto error1;
                }
        (void) close(fd);
                        goto error1;
                }
        (void) close(fd);
-       fd = 0;
-       if (sflag && (statb.st_mode & 04))
-               fd |= 1;
        if (rflag) {
                if ((cp = rindex(file, '/')) == NULL) {
                        if (access(".", 2) == 0)
        if (rflag) {
                if ((cp = rindex(file, '/')) == NULL) {
                        if (access(".", 2) == 0)
-                               fd |= 2;
+                               return(1);
                } else {
                        *cp = '\0';
                } else {
                        *cp = '\0';
-                       if (access(file, 2) == 0)
-                               fd |= 2;
+                       fd = access(file, 2);
                        *cp = '/';
                        *cp = '/';
+                       if (fd == 0)
+                               return(1);
                }
                }
+               printf("%s: %s: is not removable by you\n", name, file);
        }
        }
-       return(fd);
+       return(0);
 
 error1:
        printf(" and is unprintable\n");
 
 error1:
        printf(" and is unprintable\n");
@@ -569,8 +571,12 @@ chkprinter(s)
                fatal("unknown printer");
        if ((SD = pgetstr("sd", &bp)) == NULL)
                SD = DEFSPOOL;
                fatal("unknown printer");
        if ((SD = pgetstr("sd", &bp)) == NULL)
                SD = DEFSPOOL;
+       if ((LO = pgetstr("lo", &bp)) == NULL)
+               LO = DEFLOCK;
        if ((MX = pgetnum("mx")) < 0)
                MX = DEFMX;
        if ((MX = pgetnum("mx")) < 0)
                MX = DEFMX;
+       if ((DU = pgetnum("du")) < 0)
+               DU = DEFUID;
        RM = host;              /* machine for getport to connect to */
 }
 
        RM = host;              /* machine for getport to connect to */
 }
 
index ce5d9f9..a3d1769 100644 (file)
@@ -1,4 +1,4 @@
-/*     lprm.c  4.1     83/04/29        */
+/*     lprm.c  4.2     83/05/13        */
 /*
  * lprm - remove the current user's spool entry
  *
 /*
  * lprm - remove the current user's spool entry
  *