From owner-freebsd-hackers Thu Mar 6 05:49:12 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id FAA19275 for hackers-outgoing; Thu, 6 Mar 1997 05:49:12 -0800 (PST) Received: from nic.follonett.no (nic.follonett.no [194.198.43.10]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id FAA19270 for ; Thu, 6 Mar 1997 05:49:09 -0800 (PST) Received: (from uucp@localhost) by nic.follonett.no (8.8.5/8.8.3) with UUCP id OAA22291 for hackers@freebsd.org; Thu, 6 Mar 1997 14:47:11 +0100 (MET) Received: from oo7 (oo7.dimaga.com [192.0.0.65]) by dimaga.com (8.7.5/8.7.2) with SMTP id OAA00998 for ; Thu, 6 Mar 1997 14:51:35 +0100 (MET) Message-Id: <3.0.32.19970306145125.00c77cf0@dimaga.com> X-Sender: eivind@dimaga.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Date: Thu, 06 Mar 1997 14:51:26 +0100 To: hackers@freebsd.org From: Eivind Eklund Subject: Re: Strange lpr or lpd bug Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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