Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Mar 1997 14:51:26 +0100
From:      Eivind Eklund <eivind@dimaga.com>
To:        hackers@freebsd.org
Subject:   Re: Strange lpr or lpd bug
Message-ID:  <3.0.32.19970306145125.00c77cf0@dimaga.com>

next in thread | raw e-mail | index | archive | help
At 11:53 PM 3/5/97 +0100, J Wunsch wrote:
>As Eivind Eklund wrote:
>
>> I'd make the test check for printers with same spool directory but
>> different targets - somebody might want to use the same printer with
>> different filters and the same spooldir.
>
>Even this is bogus, and will cause all jobs to be spooled through the
>same filter.
>
>Don't worry, i once stumpled across exactly the same problem :)

Unless somebody veto me patching this, you won't be able to do the same
mistake again :)  Below is a my patch for it (against 2.1.7 source; tested
and working); it only check against the spooldirs for the first 16
printers, but will provide todays functionality for any number of printers.
 Getting the number of printers seems to need a full parse of the printcap
file :-(

--- lpd/lpd.c   Thu Mar  6 14:37:52 1997
+++ /usr/src/usr.sbin/lpr/lpd/lpd.c     Thu Mar  6 14:45:38 1997
@@ -430,11 +430,40 @@
        char *buf;
        register char *cp;
        int pid;
+       char *spooldirs[16];        /* Which spooldirs are active? */
+       int i;                      /* Printer index presently processed */
+       int j;                      /* Printer index of potential conflict */
+       char *spooldir;             /* Spooldir of present printer */
+       int  canfreespool;          /* Is the spooldir malloc()ed? */
 
        /*
-        * Restart the daemons.
+        * Restart the daemons and test for spooldir conflict.
         */
+       i = 0;
        while (cgetnext(&buf, printcapdb) > 0) {
+
+               /* Check for duplicate spooldirs */
+               canfreespool = 1;
+               if (cgetstr(buf, "sd", &spooldir) <= 0) {
+                       spooldir = _PATH_DEFSPOOL;
+                       canfreespool = 0;
+               }
+               if (i < sizeof(spooldirs)/sizeof(spooldirs[0]))
+                       spooldirs[i] = spooldir;
+               for (j = 0;
+                        j < MIN(i,sizeof(spooldirs)/sizeof(spooldirs[0]));
+                        j++) {
+                       if (strcmp(spooldir, spooldirs[j]) == 0) {
+                               syslog(LOG_ERR,
+                                       "startup: duplicate spool
directories");
+                               mcleanup(0);
+                       }
+               }
+               if (canfreespool && i >=
sizeof(spooldirs)/sizeof(spooldirs[0]))
+                       free(spooldir);
+               i++;
+               /* Spooldir test done */
+
                for (cp = buf; *cp; cp++)
                        if (*cp == '|' || *cp == ':') {
                                *cp = '\0';


Eivind Eklund perhaps@yes.no http://maybe.yes.no/perhaps/ eivind@freebsd.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.32.19970306145125.00c77cf0>