- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
/* $NetBSD: displayq.c,v 1.17 1999/12/07 14:54:44 mrg Exp $ */
|
1995-11-28 22:43:04 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-05-18 05:25:21 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-05 19:11:58 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-07-10 10:19:53 +04:00
|
|
|
#if 0
|
1997-10-05 15:52:17 +04:00
|
|
|
static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95";
|
1997-07-10 10:19:53 +04:00
|
|
|
#else
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
__RCSID("$NetBSD: displayq.c,v 1.17 1999/12/07 14:54:44 mrg Exp $");
|
1997-07-10 10:19:53 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1997-10-05 15:52:17 +04:00
|
|
|
#include <sys/file.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "lp.h"
|
1994-05-18 05:25:21 +04:00
|
|
|
#include "lp.local.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
/*
|
|
|
|
* Routines to display the state of the queue.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
#define JOBCOL 40 /* column for job # in -l format */
|
|
|
|
#define OWNCOL 7 /* start of Owner column in normal */
|
|
|
|
#define SIZCOL 62 /* start of Size column in normal */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stuff for handling job specifications
|
|
|
|
*/
|
|
|
|
extern int requ[]; /* job number of spool entries */
|
|
|
|
extern int requests; /* # of spool requests */
|
1994-05-18 05:25:21 +04:00
|
|
|
extern char *user[]; /* users to process */
|
|
|
|
extern int users; /* # of users in user array */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
extern uid_t uid, euid;
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
static int col; /* column on screen */
|
|
|
|
static char current[40]; /* current file being printed */
|
|
|
|
static char file[132]; /* print file name */
|
|
|
|
static int first; /* first file in ``files'' column? */
|
|
|
|
static int garbage; /* # of garbage cf files */
|
|
|
|
static int lflag; /* long output option */
|
|
|
|
static int rank; /* order to be printed (-1=none, 0=active) */
|
|
|
|
static long totsize; /* total print job size in bytes */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
static char *head0 = "Rank Owner Job Files";
|
|
|
|
static char *head1 = "Total Size\n";
|
1993-03-21 12:45:37 +03:00
|
|
|
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
static void alarmer __P((int));
|
|
|
|
|
|
|
|
int wait_time = 300; /* time out after 5 minutes by default */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Display the current state of the queue. Format = 1 if long format.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
displayq(format)
|
|
|
|
int format;
|
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
struct queue *q;
|
|
|
|
int i, nitems, fd, ret;
|
|
|
|
char *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct queue **queue;
|
|
|
|
struct stat statb;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
lflag = format;
|
|
|
|
totsize = 0;
|
|
|
|
rank = -1;
|
1994-05-18 05:25:21 +04:00
|
|
|
if ((i = cgetent(&bp, printcapdb, printer)) == -2)
|
|
|
|
fatal("can't open printer description file");
|
|
|
|
else if (i == -1)
|
1993-03-21 12:45:37 +03:00
|
|
|
fatal("unknown printer");
|
1994-05-18 05:25:21 +04:00
|
|
|
else if (i == -3)
|
|
|
|
fatal("potential reference loop detected in printcap file");
|
|
|
|
if (cgetstr(bp, "lp", &LP) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
LP = _PATH_DEFDEVLP;
|
1994-05-18 05:25:21 +04:00
|
|
|
if (cgetstr(bp, "rp", &RP) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
RP = DEFLP;
|
1994-05-18 05:25:21 +04:00
|
|
|
if (cgetstr(bp, "sd", &SD) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
SD = _PATH_DEFSPOOL;
|
1994-05-18 05:25:21 +04:00
|
|
|
if (cgetstr(bp,"lo", &LO) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
LO = DEFLOCK;
|
1994-05-18 05:25:21 +04:00
|
|
|
if (cgetstr(bp, "st", &ST) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
ST = DEFSTAT;
|
1994-05-18 05:25:21 +04:00
|
|
|
cgetstr(bp, "rm", &RM);
|
1997-07-10 10:19:53 +04:00
|
|
|
if ((cp = checkremote()) != NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("Warning: %s\n", cp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out local queue
|
|
|
|
* Find all the control files in the spooling directory
|
|
|
|
*/
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (chdir(SD) < 0)
|
|
|
|
fatal("cannot chdir to spooling directory");
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((nitems = getq(&queue)) < 0)
|
|
|
|
fatal("cannot examine spooling area\n");
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
|
|
|
ret = stat(LO, &statb);
|
|
|
|
seteuid(uid);
|
|
|
|
if (ret >= 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (statb.st_mode & 0100) {
|
1997-10-05 15:52:17 +04:00
|
|
|
if (remote)
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("%s: ", host);
|
|
|
|
printf("Warning: %s is down: ", printer);
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
fd = open(ST, O_RDONLY);
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (fd >= 0) {
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)flock(fd, LOCK_SH);
|
1993-03-21 12:45:37 +03:00
|
|
|
while ((i = read(fd, line, sizeof(line))) > 0)
|
1999-09-26 14:32:27 +04:00
|
|
|
(void)fwrite(line, 1, (size_t)i, stdout);
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)close(fd); /* unlocks as well */
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (statb.st_mode & 010) {
|
1997-10-05 15:52:17 +04:00
|
|
|
if (remote)
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("%s: ", host);
|
|
|
|
printf("Warning: %s queue is turned off\n", printer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nitems) {
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
fp = fopen(LO, "r");
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (fp == NULL)
|
1997-10-05 19:11:58 +04:00
|
|
|
nodaemon();
|
1993-03-21 12:45:37 +03:00
|
|
|
else {
|
|
|
|
/* get daemon pid */
|
|
|
|
cp = current;
|
1997-10-05 19:11:58 +04:00
|
|
|
while ((i = getc(fp)) != EOF && i != '\n')
|
|
|
|
*cp++ = i;
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = '\0';
|
|
|
|
i = atoi(current);
|
1995-10-03 18:02:17 +03:00
|
|
|
if (i <= 0) {
|
1995-11-16 01:20:33 +03:00
|
|
|
ret = -1;
|
|
|
|
} else {
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
|
|
|
ret = kill(i, 0);
|
|
|
|
seteuid(uid);
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
1997-10-05 19:11:58 +04:00
|
|
|
nodaemon();
|
1995-11-16 01:20:33 +03:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
/* read current file name */
|
|
|
|
cp = current;
|
1997-10-05 19:11:58 +04:00
|
|
|
while ((i = getc(fp)) != EOF && i != '\n')
|
|
|
|
*cp++ = i;
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = '\0';
|
|
|
|
/*
|
|
|
|
* Print the status file.
|
|
|
|
*/
|
1997-10-05 15:52:17 +04:00
|
|
|
if (remote)
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("%s: ", host);
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
fd = open(ST, O_RDONLY);
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (fd >= 0) {
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)flock(fd, LOCK_SH);
|
1993-03-21 12:45:37 +03:00
|
|
|
while ((i = read(fd, line, sizeof(line))) > 0)
|
1999-09-26 14:32:27 +04:00
|
|
|
(void)fwrite(line, 1, (size_t)i, stdout);
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)close(fd); /* unlocks as well */
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
putchar('\n');
|
|
|
|
}
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)fclose(fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now, examine the control files and print out the jobs to
|
|
|
|
* be done for each user.
|
|
|
|
*/
|
|
|
|
if (!lflag)
|
|
|
|
header();
|
|
|
|
for (i = 0; i < nitems; i++) {
|
|
|
|
q = queue[i];
|
|
|
|
inform(q->q_name);
|
|
|
|
free(q);
|
|
|
|
}
|
|
|
|
free(queue);
|
|
|
|
}
|
1997-10-05 15:52:17 +04:00
|
|
|
if (!remote) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (nitems == 0)
|
|
|
|
puts("no entries");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print foreign queue
|
|
|
|
* Note that a file in transit may show up in either queue.
|
|
|
|
*/
|
|
|
|
if (nitems)
|
|
|
|
putchar('\n');
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)snprintf(line, sizeof(line), "%c%s", format + '\3', RP);
|
1993-03-21 12:45:37 +03:00
|
|
|
cp = line;
|
1997-10-05 19:11:58 +04:00
|
|
|
for (i = 0; i < requests && cp-line+10 < sizeof(line) - 1; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp += strlen(cp);
|
1999-09-26 14:32:27 +04:00
|
|
|
(void)snprintf(cp, (size_t)(line - cp), " %d", requ[i]);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-05 19:11:58 +04:00
|
|
|
for (i = 0; i < users && cp - line + 1 + strlen(user[i]) <
|
|
|
|
sizeof(line) - 1; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp += strlen(cp);
|
1996-12-09 12:57:40 +03:00
|
|
|
if (cp - line > sizeof(line) - 1)
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = ' ';
|
1998-09-15 01:23:07 +04:00
|
|
|
if (strlen(user[i]) < (sizeof(line) - (cp - line) - 1))
|
1998-09-14 15:52:21 +04:00
|
|
|
(void)strcpy(cp, user[i]);
|
1998-09-15 01:23:07 +04:00
|
|
|
else
|
|
|
|
(void)strncpy(cp, user[i],
|
|
|
|
(sizeof(line) - (cp - line) - 1));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)strncat(line, "\n", sizeof(line) - strlen(line) - 1);
|
1997-10-05 15:52:17 +04:00
|
|
|
fd = getport(RM, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (fd < 0) {
|
|
|
|
if (from != host)
|
|
|
|
printf("%s: ", host);
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)printf("connection to %s is down\n", RM);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
else {
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
struct sigaction osa, nsa;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
i = strlen(line);
|
1999-09-26 14:32:27 +04:00
|
|
|
if (write(fd, line, (size_t)i) != i)
|
1993-03-21 12:45:37 +03:00
|
|
|
fatal("Lost connection");
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
nsa.sa_handler = alarmer;
|
|
|
|
sigemptyset(&nsa.sa_mask);
|
|
|
|
sigaddset(&nsa.sa_mask, SIGALRM);
|
|
|
|
nsa.sa_flags = 0;
|
|
|
|
(void)sigaction(SIGALRM, &nsa, &osa);
|
|
|
|
alarm(wait_time);
|
|
|
|
while ((i = read(fd, line, sizeof(line))) > 0) {
|
1999-09-26 14:32:27 +04:00
|
|
|
(void)fwrite(line, 1, (size_t)i, stdout);
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
alarm(wait_time);
|
|
|
|
}
|
|
|
|
alarm(0);
|
|
|
|
(void)sigaction(SIGALRM, &osa, NULL);
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)close(fd);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
- add timeouts to displayq(), rmremote(), sendfile() and response(),
and use these timeout in the lpq, lpd and lprm programs.
these stop hung remote printers that accept tcp connections but do
not process jobs from hanging the whole system and letting the sysadmin
have a clue about what is going on with this rogue printer.
- add a -r flag to lpd to allow `of' filters for remote jobs.
i know there are ways around this, but i just don't care.
- add a -f flag to lpf to add missing carriage returns.
useful when printing UNIX files to an, eg, LaserWriter that wants CR's
as well as LF's in raw text. stair-stepped text is no fun.
- implement child process accounting: we just have a limit on the number
of children we can have (settable by the sysadmin), and we sleep when
this number is reached. this can reduce malicious not-so-malicious
attacks on the print server by a rogue remote client..
- use setproctitle() where appropriate so the sysadmin has a clue about
what each of the lpd's here are doing.
this was useful to help diagnose a problem (that the above child process
accounting change reduces the lossages of) where a rogue client was
attempting "lpq" operations on one stuck queue in rapid succession,
causing the lpd server to be extremely slow, due to the large number
of lpd processes running.
i have been running these changes in production for about a year.
1999-12-07 17:54:44 +03:00
|
|
|
static void
|
|
|
|
alarmer(s)
|
|
|
|
int s;
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Print a warning message if there is no daemon present.
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1997-10-05 19:11:58 +04:00
|
|
|
nodaemon()
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-05 15:52:17 +04:00
|
|
|
if (remote)
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("\n%s: ", host);
|
|
|
|
puts("Warning: no daemon present");
|
|
|
|
current[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the header for the short listing format
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
header()
|
|
|
|
{
|
|
|
|
printf(head0);
|
|
|
|
col = strlen(head0)+1;
|
|
|
|
blankfill(SIZCOL);
|
|
|
|
printf(head1);
|
|
|
|
}
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
inform(cf)
|
|
|
|
char *cf;
|
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
int j;
|
1993-03-21 12:45:37 +03:00
|
|
|
FILE *cfp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's a chance the control file has gone away
|
|
|
|
* in the meantime; if this is the case just keep going
|
|
|
|
*/
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((cfp = fopen(cf, "r")) == NULL)
|
|
|
|
return;
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (rank < 0)
|
|
|
|
rank = 0;
|
1997-10-05 15:52:17 +04:00
|
|
|
if (remote || garbage || strcmp(cf, current))
|
1993-03-21 12:45:37 +03:00
|
|
|
rank++;
|
|
|
|
j = 0;
|
|
|
|
while (getline(cfp)) {
|
|
|
|
switch (line[0]) {
|
|
|
|
case 'P': /* Was this file specified in the user's list? */
|
|
|
|
if (!inlist(line+1, cf)) {
|
|
|
|
fclose(cfp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (lflag) {
|
|
|
|
printf("\n%s: ", line+1);
|
|
|
|
col = strlen(line+1) + 2;
|
|
|
|
prank(rank);
|
|
|
|
blankfill(JOBCOL);
|
|
|
|
printf(" [job %s]\n", cf+3);
|
|
|
|
} else {
|
|
|
|
col = 0;
|
|
|
|
prank(rank);
|
|
|
|
blankfill(OWNCOL);
|
|
|
|
printf("%-10s %-3d ", line+1, atoi(cf+3));
|
|
|
|
col += 16;
|
|
|
|
first = 1;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
default: /* some format specifer and file name? */
|
|
|
|
if (line[0] < 'a' || line[0] > 'z')
|
|
|
|
continue;
|
1997-10-05 19:11:58 +04:00
|
|
|
if (j == 0 || strcmp(file, line+1) != 0) {
|
1996-12-09 12:57:40 +03:00
|
|
|
(void)strncpy(file, line+1, sizeof(file) - 1);
|
1997-10-05 19:11:58 +04:00
|
|
|
file[sizeof(file) - 1] = '\0';
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
case 'N':
|
|
|
|
show(line+1, file, j);
|
|
|
|
file[0] = '\0';
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(cfp);
|
|
|
|
if (!lflag) {
|
|
|
|
blankfill(SIZCOL);
|
|
|
|
printf("%ld bytes\n", totsize);
|
|
|
|
totsize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
inlist(name, file)
|
|
|
|
char *name, *file;
|
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
int *r, n;
|
|
|
|
char **u, *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (users == 0 && requests == 0)
|
|
|
|
return(1);
|
|
|
|
/*
|
|
|
|
* Check to see if it's in the user list
|
|
|
|
*/
|
|
|
|
for (u = user; u < &user[users]; u++)
|
|
|
|
if (!strcmp(*u, name))
|
|
|
|
return(1);
|
|
|
|
/*
|
|
|
|
* Check the request list
|
|
|
|
*/
|
|
|
|
for (n = 0, cp = file+3; isdigit(*cp); )
|
|
|
|
n = n * 10 + (*cp++ - '0');
|
|
|
|
for (r = requ; r < &requ[requests]; r++)
|
|
|
|
if (*r == n && !strcmp(cp, from))
|
|
|
|
return(1);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
show(nfile, file, copies)
|
1997-10-05 19:11:58 +04:00
|
|
|
char *nfile, *file;
|
1994-05-18 05:25:21 +04:00
|
|
|
int copies;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (strcmp(nfile, " ") == 0)
|
|
|
|
nfile = "(standard input)";
|
|
|
|
if (lflag)
|
|
|
|
ldump(nfile, file, copies);
|
|
|
|
else
|
|
|
|
dump(nfile, file, copies);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill the line with blanks to the specified column
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
blankfill(n)
|
1997-10-05 19:11:58 +04:00
|
|
|
int n;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
while (col++ < n)
|
|
|
|
putchar(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the abbreviated dump of the file names
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
dump(nfile, file, copies)
|
|
|
|
char *nfile, *file;
|
1994-05-18 05:25:21 +04:00
|
|
|
int copies;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-05 19:11:58 +04:00
|
|
|
short n, fill;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct stat lbuf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print as many files as will fit
|
|
|
|
* (leaving room for the total size)
|
|
|
|
*/
|
|
|
|
fill = first ? 0 : 2; /* fill space for ``, '' */
|
|
|
|
if (((n = strlen(nfile)) + col + fill) >= SIZCOL-4) {
|
|
|
|
if (col < SIZCOL) {
|
|
|
|
printf(" ..."), col += 4;
|
|
|
|
blankfill(SIZCOL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (first)
|
|
|
|
first = 0;
|
|
|
|
else
|
|
|
|
printf(", ");
|
|
|
|
printf("%s", nfile);
|
|
|
|
col += n+fill;
|
|
|
|
}
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(euid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*file && !stat(file, &lbuf))
|
1999-09-26 14:32:27 +04:00
|
|
|
totsize += copies * (long)lbuf.st_size;
|
1995-10-03 18:02:17 +03:00
|
|
|
seteuid(uid);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the long info about the file
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
ldump(nfile, file, copies)
|
|
|
|
char *nfile, *file;
|
1994-05-18 05:25:21 +04:00
|
|
|
int copies;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct stat lbuf;
|
|
|
|
|
|
|
|
putchar('\t');
|
|
|
|
if (copies > 1)
|
|
|
|
printf("%-2d copies of %-19s", copies, nfile);
|
|
|
|
else
|
|
|
|
printf("%-32s", nfile);
|
|
|
|
if (*file && !stat(file, &lbuf))
|
1997-10-05 20:45:43 +04:00
|
|
|
printf(" %qd bytes", (long long)lbuf.st_size);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
printf(" ??? bytes");
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the job's rank in the queue,
|
|
|
|
* update col for screen management
|
|
|
|
*/
|
1994-05-18 05:25:21 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
prank(n)
|
1994-05-18 05:25:21 +04:00
|
|
|
int n;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-18 05:25:21 +04:00
|
|
|
char rline[100];
|
1993-03-21 12:45:37 +03:00
|
|
|
static char *r[] = {
|
|
|
|
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
printf("active");
|
|
|
|
col += 6;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((n/10)%10 == 1)
|
1994-05-18 05:25:21 +04:00
|
|
|
(void)snprintf(rline, sizeof(rline), "%dth", n);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-05-18 05:25:21 +04:00
|
|
|
(void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]);
|
|
|
|
col += strlen(rline);
|
|
|
|
printf("%s", rline);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|