- WARNS?=1
- be safe with unlinking files (from freebsd) - remove register - clean up $NetBSD$'s. - use inet_ntoa() in one place (from openbsd) - nul terminate after a bunch of strncpy()'s - #ifdef __STDC__ rather than #if (from freebsd) - be safe with a bunch of string operations (from freebsd) - use warn()/err() over home grown versions (some from freebsd) - rename warn() to nodaemon() to remove conflict with above - check errno from failed kill(2) against ESRCH (from freebsd) - use getopt() rather than home grown versions (from freebsd) - clean up a bunch of man pages (some from freebsd) - check for hostname spoof (from freebsd) - use POSIX wait() interfaces - use sysconf(_SC_OPEN_MAX) in preference to NOFILE (from freebsd) - deal with fork() failure - index/rindex -> strchr/strrchr (some from freebsd) - add B57600 and B115200 speeds (from freebsd) - some KNF - be safe with files passed in over the network (some from freebsd) - check return value of malloc(), calloc() and strdup()
This commit is contained in:
parent
a1b6da927d
commit
fe7ed7ce37
@ -1,7 +1,7 @@
|
||||
# $NetBSD: Makefile,v 1.6 1995/11/15 22:55:41 pk Exp $
|
||||
# $NetBSD: Makefile,v 1.7 1997/10/05 15:11:58 mrg Exp $
|
||||
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
SUBDIR= lpc lpd lpq lpr lprm lptest pac filters
|
||||
SUBDIR= lp lpc lpd lpq lpr lprm lptest pac filters
|
||||
|
||||
.if make(install)
|
||||
SUBDIR+= SMM.doc
|
||||
|
3
usr.sbin/lpr/Makefile.inc
Normal file
3
usr.sbin/lpr/Makefile.inc
Normal file
@ -0,0 +1,3 @@
|
||||
# $NetBSD: Makefile.inc,v 1.1 1997/10/05 15:11:59 mrg Exp $
|
||||
|
||||
WARNS?=1
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: common.c,v 1.10 1997/10/05 11:52:17 mrg Exp $ */
|
||||
/* $NetBSD: common.c,v 1.11 1997/10/05 15:12:00 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -38,8 +38,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: common.c,v 1.11 1997/10/05 15:12:00 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -48,6 +53,7 @@ static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95";
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <dirent.h>
|
||||
@ -141,8 +147,7 @@ getport(rhost, rport)
|
||||
if (rhost == NULL)
|
||||
fatal("no remote host to connect to");
|
||||
bzero((char *)&sin, sizeof(sin));
|
||||
sin.sin_addr.s_addr = inet_addr(rhost);
|
||||
if (sin.sin_addr.s_addr != INADDR_NONE)
|
||||
if (inet_aton(rhost, &sin.sin_addr) == 1)
|
||||
sin.sin_family = AF_INET;
|
||||
else {
|
||||
hp = gethostbyname(rhost);
|
||||
@ -195,18 +200,17 @@ int
|
||||
getline(cfp)
|
||||
FILE *cfp;
|
||||
{
|
||||
register int linel = 0;
|
||||
register char *lp = line;
|
||||
register c;
|
||||
int linel = 0, c;
|
||||
char *lp = line;
|
||||
|
||||
while ((c = getc(cfp)) != '\n') {
|
||||
while ((c = getc(cfp)) != '\n' && linel+1<sizeof(line)) {
|
||||
if (c == EOF)
|
||||
return(0);
|
||||
if (c == '\t') {
|
||||
do {
|
||||
*lp++ = ' ';
|
||||
linel++;
|
||||
} while ((linel & 07) != 0);
|
||||
} while ((linel & 07) != 0 && linel+1 < sizeof(line));
|
||||
continue;
|
||||
}
|
||||
*lp++ = c;
|
||||
@ -225,12 +229,11 @@ int
|
||||
getq(namelist)
|
||||
struct queue *(*namelist[]);
|
||||
{
|
||||
register struct dirent *d;
|
||||
register struct queue *q, **queue;
|
||||
register int nitems;
|
||||
struct dirent *d;
|
||||
struct queue *q, **queue;
|
||||
struct stat stbuf;
|
||||
DIR *dirp;
|
||||
int arraysz;
|
||||
int nitems, arraysz;
|
||||
|
||||
seteuid(euid);
|
||||
if ((dirp = opendir(SD)) == NULL)
|
||||
@ -307,7 +310,7 @@ char *
|
||||
checkremote()
|
||||
{
|
||||
char name[MAXHOSTNAMELEN];
|
||||
register struct hostent *hp;
|
||||
struct hostent *hp;
|
||||
static char errbuf[128];
|
||||
|
||||
remote = 0; /* assume printer is local */
|
||||
@ -321,7 +324,10 @@ checkremote()
|
||||
"unable to get official name for local machine %s",
|
||||
name);
|
||||
return errbuf;
|
||||
} else (void)strncpy(name, hp->h_name, MAXHOSTNAMELEN - 1);
|
||||
} else {
|
||||
(void)strncpy(name, hp->h_name, sizeof(name) - 1);
|
||||
name[sizeof(name) - 1] = '\0';
|
||||
}
|
||||
|
||||
/* get the official name of RM */
|
||||
hp = gethostbyname(RM);
|
||||
@ -355,14 +361,14 @@ delay(n)
|
||||
(void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
fatal(const char *msg, ...)
|
||||
#else
|
||||
fatal(msg, va_alist)
|
||||
@ -371,7 +377,7 @@ fatal(msg, va_alist)
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: displayq.c,v 1.11 1997/10/05 11:52:19 mrg Exp $ */
|
||||
/* $NetBSD: displayq.c,v 1.12 1997/10/05 15:12:01 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -33,11 +33,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: displayq.c,v 1.11 1997/10/05 11:52:19 mrg Exp $";
|
||||
__RCSID("$NetBSD: displayq.c,v 1.12 1997/10/05 15:12:01 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -93,9 +94,9 @@ void
|
||||
displayq(format)
|
||||
int format;
|
||||
{
|
||||
register struct queue *q;
|
||||
register int i, nitems, fd, ret, c;
|
||||
register char *cp;
|
||||
struct queue *q;
|
||||
int i, nitems, fd, ret;
|
||||
char *cp;
|
||||
struct queue **queue;
|
||||
struct stat statb;
|
||||
FILE *fp;
|
||||
@ -164,12 +165,12 @@ displayq(format)
|
||||
fp = fopen(LO, "r");
|
||||
seteuid(uid);
|
||||
if (fp == NULL)
|
||||
warn();
|
||||
nodaemon();
|
||||
else {
|
||||
/* get daemon pid */
|
||||
cp = current;
|
||||
while ((c = getc(fp)) != EOF && (*cp = c) != '\n')
|
||||
cp++;
|
||||
while ((i = getc(fp)) != EOF && i != '\n')
|
||||
*cp++ = i;
|
||||
*cp = '\0';
|
||||
i = atoi(current);
|
||||
if (i <= 0) {
|
||||
@ -180,13 +181,12 @@ displayq(format)
|
||||
seteuid(uid);
|
||||
}
|
||||
if (ret < 0) {
|
||||
warn();
|
||||
nodaemon();
|
||||
} else {
|
||||
/* read current file name */
|
||||
cp = current;
|
||||
while ((c = getc(fp)) != EOF &&
|
||||
(*cp = c) != '\n')
|
||||
cp++;
|
||||
while ((i = getc(fp)) != EOF && i != '\n')
|
||||
*cp++ = i;
|
||||
*cp = '\0';
|
||||
/*
|
||||
* Print the status file.
|
||||
@ -233,11 +233,12 @@ displayq(format)
|
||||
putchar('\n');
|
||||
(void)snprintf(line, sizeof(line), "%c%s", format + '\3', RP);
|
||||
cp = line;
|
||||
for (i = 0; i < requests; i++) {
|
||||
for (i = 0; i < requests && cp-line+10 < sizeof(line) - 1; i++) {
|
||||
cp += strlen(cp);
|
||||
(void)snprintf(cp, line - cp, " %d", requ[i]);
|
||||
}
|
||||
for (i = 0; i < users; i++) {
|
||||
for (i = 0; i < users && cp - line + 1 + strlen(user[i]) <
|
||||
sizeof(line) - 1; i++) {
|
||||
cp += strlen(cp);
|
||||
if (cp - line > sizeof(line) - 1)
|
||||
break;
|
||||
@ -265,7 +266,7 @@ displayq(format)
|
||||
* Print a warning message if there is no daemon present.
|
||||
*/
|
||||
void
|
||||
warn()
|
||||
nodaemon()
|
||||
{
|
||||
if (remote)
|
||||
printf("\n%s: ", host);
|
||||
@ -289,7 +290,7 @@ void
|
||||
inform(cf)
|
||||
char *cf;
|
||||
{
|
||||
register int j;
|
||||
int j;
|
||||
FILE *cfp;
|
||||
|
||||
/*
|
||||
@ -331,8 +332,10 @@ inform(cf)
|
||||
default: /* some format specifer and file name? */
|
||||
if (line[0] < 'a' || line[0] > 'z')
|
||||
continue;
|
||||
if (j == 0 || strcmp(file, line+1) != 0)
|
||||
if (j == 0 || strcmp(file, line+1) != 0) {
|
||||
(void)strncpy(file, line+1, sizeof(file) - 1);
|
||||
file[sizeof(file) - 1] = '\0';
|
||||
}
|
||||
j++;
|
||||
continue;
|
||||
case 'N':
|
||||
@ -353,8 +356,8 @@ int
|
||||
inlist(name, file)
|
||||
char *name, *file;
|
||||
{
|
||||
register int *r, n;
|
||||
register char **u, *cp;
|
||||
int *r, n;
|
||||
char **u, *cp;
|
||||
|
||||
if (users == 0 && requests == 0)
|
||||
return(1);
|
||||
@ -377,7 +380,7 @@ inlist(name, file)
|
||||
|
||||
void
|
||||
show(nfile, file, copies)
|
||||
register char *nfile, *file;
|
||||
char *nfile, *file;
|
||||
int copies;
|
||||
{
|
||||
if (strcmp(nfile, " ") == 0)
|
||||
@ -393,7 +396,7 @@ show(nfile, file, copies)
|
||||
*/
|
||||
void
|
||||
blankfill(n)
|
||||
register int n;
|
||||
int n;
|
||||
{
|
||||
while (col++ < n)
|
||||
putchar(' ');
|
||||
@ -407,7 +410,7 @@ dump(nfile, file, copies)
|
||||
char *nfile, *file;
|
||||
int copies;
|
||||
{
|
||||
register short n, fill;
|
||||
short n, fill;
|
||||
struct stat lbuf;
|
||||
|
||||
/*
|
||||
@ -450,7 +453,7 @@ ldump(nfile, file, copies)
|
||||
else
|
||||
printf("%-32s", nfile);
|
||||
if (*file && !stat(file, &lbuf))
|
||||
printf(" %ld bytes", (long)lbuf.st_size);
|
||||
printf(" %qd bytes", lbuf.st_size);
|
||||
else
|
||||
printf(" ??? bytes");
|
||||
putchar('\n');
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lp.h,v 1.10 1997/10/05 11:52:21 mrg Exp $ */
|
||||
/* $NetBSD: lp.h,v 1.11 1997/10/05 15:12:02 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -125,6 +125,6 @@ void rmjob __P((void));
|
||||
void rmremote __P((void));
|
||||
void show __P((char *, char *, int));
|
||||
int startdaemon __P((char *));
|
||||
void warn __P((void));
|
||||
void nodaemon __P((void));
|
||||
void delay __P((int));
|
||||
__END_DECLS
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: printcap.c,v 1.9 1997/10/05 11:52:22 mrg Exp $ */
|
||||
/* $NetBSD: printcap.c,v 1.10 1997/10/05 15:12:03 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -33,8 +33,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)printcap.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: printcap.c,v 1.10 1997/10/05 15:12:03 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -65,7 +70,7 @@ extern char line[]; /* buffer for printcap entries */
|
||||
|
||||
int
|
||||
cgetnext(bp, db_array)
|
||||
register char **bp;
|
||||
char **bp;
|
||||
char **db_array;
|
||||
{
|
||||
int ret;
|
||||
@ -178,9 +183,9 @@ static char *tdecode __P((char *, char **));
|
||||
*/
|
||||
int
|
||||
getprent(bp)
|
||||
register char *bp;
|
||||
char *bp;
|
||||
{
|
||||
register int c, skip = 0;
|
||||
int c, skip = 0;
|
||||
|
||||
if (pfp == NULL) {
|
||||
seteuid(euid);
|
||||
@ -250,9 +255,9 @@ int
|
||||
tgetent(bp, name)
|
||||
char *bp, *name;
|
||||
{
|
||||
register char *cp;
|
||||
register int c;
|
||||
register int i = 0, cnt = 0;
|
||||
char *cp;
|
||||
int c;
|
||||
int i = 0, cnt = 0;
|
||||
char ibuf[BUFSIZ];
|
||||
|
||||
tbuf = bp;
|
||||
@ -341,7 +346,7 @@ tgetent(bp, name)
|
||||
int
|
||||
tnchktc()
|
||||
{
|
||||
register char *p, *q;
|
||||
char *p, *q;
|
||||
char tcname[16]; /* name of similar terminal */
|
||||
char tcbuf[BUFSIZ];
|
||||
char *holdtbuf = tbuf;
|
||||
@ -390,7 +395,7 @@ int
|
||||
tnamatch(np)
|
||||
char *np;
|
||||
{
|
||||
register char *Np, *Bp;
|
||||
char *Np, *Bp;
|
||||
|
||||
Bp = tbuf;
|
||||
if (*Bp == '#')
|
||||
@ -415,7 +420,7 @@ tnamatch(np)
|
||||
*/
|
||||
static char *
|
||||
tskip(bp)
|
||||
register char *bp;
|
||||
char *bp;
|
||||
{
|
||||
|
||||
while (*bp && *bp != ':')
|
||||
@ -437,8 +442,8 @@ int
|
||||
tgetnum(id)
|
||||
char *id;
|
||||
{
|
||||
register int i, base;
|
||||
register char *bp = tbuf;
|
||||
int i, base;
|
||||
char *bp = tbuf;
|
||||
|
||||
for (;;) {
|
||||
bp = tskip(bp);
|
||||
@ -471,7 +476,7 @@ int
|
||||
tgetflag(id)
|
||||
char *id;
|
||||
{
|
||||
register char *bp = tbuf;
|
||||
char *bp = tbuf;
|
||||
|
||||
for (;;) {
|
||||
bp = tskip(bp);
|
||||
@ -498,7 +503,7 @@ char *
|
||||
tgetstr(id, area)
|
||||
char *id, **area;
|
||||
{
|
||||
register char *bp = tbuf;
|
||||
char *bp = tbuf;
|
||||
|
||||
for (;;) {
|
||||
bp = tskip(bp);
|
||||
@ -521,12 +526,12 @@ tgetstr(id, area)
|
||||
*/
|
||||
static char *
|
||||
tdecode(str, area)
|
||||
register char *str;
|
||||
char *str;
|
||||
char **area;
|
||||
{
|
||||
register char *cp;
|
||||
register int c;
|
||||
register char *dp;
|
||||
char *cp;
|
||||
int c;
|
||||
char *dp;
|
||||
int i;
|
||||
|
||||
cp = *area;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rmjob.c,v 1.12 1997/10/05 11:52:24 mrg Exp $ */
|
||||
/* $NetBSD: rmjob.c,v 1.13 1997/10/05 15:12:04 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -33,11 +33,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)rmjob.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD";
|
||||
__RCSID("$NetBSD: rmjob.c,v 1.13 1997/10/05 15:12:04 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -80,7 +81,7 @@ static void do_unlink __P((char *));
|
||||
void
|
||||
rmjob()
|
||||
{
|
||||
register int i, nitems;
|
||||
int i, nitems;
|
||||
int assasinated = 0;
|
||||
struct dirent **files;
|
||||
char *cp;
|
||||
@ -166,8 +167,8 @@ int
|
||||
lockchk(s)
|
||||
char *s;
|
||||
{
|
||||
register FILE *fp;
|
||||
register int i, n;
|
||||
FILE *fp;
|
||||
int i, n;
|
||||
|
||||
seteuid(euid);
|
||||
if ((fp = fopen(s, "r")) == NULL) {
|
||||
@ -216,6 +217,8 @@ process(file)
|
||||
while (getline(cfp)) {
|
||||
switch (line[0]) {
|
||||
case 'U': /* unlink associated files */
|
||||
if (strchr(line+1, '/') || strncmp(line+1, "df", 2))
|
||||
break;
|
||||
do_unlink(line+1);
|
||||
}
|
||||
}
|
||||
@ -244,8 +247,8 @@ int
|
||||
chk(file)
|
||||
char *file;
|
||||
{
|
||||
register int *r, n;
|
||||
register char **u, *cp;
|
||||
int *r, n;
|
||||
char **u, *cp;
|
||||
FILE *cfp;
|
||||
|
||||
/*
|
||||
@ -318,8 +321,8 @@ isowner(owner, file)
|
||||
void
|
||||
rmremote()
|
||||
{
|
||||
register char *cp, *s;
|
||||
register int i, rem, len;
|
||||
char *cp, *s;
|
||||
int i, rem, len;
|
||||
|
||||
if (!remote)
|
||||
return; /* not sending to a remote machine */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: startdaemon.c,v 1.8 1996/12/09 09:57:43 mrg Exp $ */
|
||||
/* $NetBSD: startdaemon.c,v 1.9 1997/10/05 15:12:04 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993, 1994
|
||||
@ -33,8 +33,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)startdaemon.c 8.2 (Berkeley) 4/17/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: startdaemon.c,v 1.9 1997/10/05 15:12:04 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
||||
@ -47,13 +52,12 @@ static char sccsid[] = "@(#)startdaemon.c 8.2 (Berkeley) 4/17/94";
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include "lp.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
extern uid_t uid, euid;
|
||||
|
||||
static void perr __P((char *));
|
||||
|
||||
/*
|
||||
* Tell the printer daemon that there are new files in the spool directory.
|
||||
*/
|
||||
@ -63,12 +67,12 @@ startdaemon(printer)
|
||||
char *printer;
|
||||
{
|
||||
struct sockaddr_un un;
|
||||
register int s, n;
|
||||
int s, n;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
perr("socket");
|
||||
warn("socket");
|
||||
return(0);
|
||||
}
|
||||
memset(&un, 0, sizeof(un));
|
||||
@ -80,14 +84,14 @@ startdaemon(printer)
|
||||
seteuid(euid);
|
||||
if (connect(s, (struct sockaddr *)&un, SUN_LEN(&un)) < 0) {
|
||||
seteuid(uid);
|
||||
perr("connect");
|
||||
warn("connect");
|
||||
(void)close(s);
|
||||
return(0);
|
||||
}
|
||||
seteuid(uid);
|
||||
n = snprintf(buf, sizeof(buf), "\1%s\n", printer);
|
||||
if (write(s, buf, n) != n) {
|
||||
perr("write");
|
||||
warn("write");
|
||||
(void)close(s);
|
||||
return(0);
|
||||
}
|
||||
@ -103,12 +107,3 @@ startdaemon(printer)
|
||||
(void)close(s);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void
|
||||
perr(msg)
|
||||
char *msg;
|
||||
{
|
||||
extern char *name;
|
||||
|
||||
(void)printf("%s: %s: %s\n", name, msg, strerror(errno));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lpf.c,v 1.5 1997/07/10 06:21:51 mikel Exp $ */
|
||||
/* $NetBSD: lpf.c,v 1.6 1997/10/05 15:12:05 mrg Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -32,17 +32,14 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lpf.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD";
|
||||
__RCSID("$NetBSD: lpf.c,v 1.6 1997/10/05 15:12:05 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -75,16 +72,18 @@ char *name; /* user's login name */
|
||||
char *host; /* user's machine name */
|
||||
char *acctfile; /* accounting information file */
|
||||
|
||||
int main __P((int, char *[]));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register FILE *p = stdin, *o = stdout;
|
||||
register int i, col;
|
||||
register char *cp;
|
||||
int done, linedone, maxrep;
|
||||
char ch, *limit;
|
||||
FILE *p = stdin, *o = stdout;
|
||||
int i, col;
|
||||
char *cp;
|
||||
int done, linedone, maxrep, ch;
|
||||
char *limit;
|
||||
|
||||
while (--argc) {
|
||||
if (*(cp = *++argv) == '-') {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cmds.c,v 1.11 1997/10/05 11:52:26 mrg Exp $ */
|
||||
/* $NetBSD: cmds.c,v 1.12 1997/10/05 15:12:06 mrg Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,17 +33,14 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD";
|
||||
__RCSID("$NetBSD: cmds.c,v 1.12 1997/10/05 15:12:06 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -96,8 +93,8 @@ doabort(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -109,7 +106,8 @@ doabort(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
abortpr(1);
|
||||
@ -134,9 +132,9 @@ static void
|
||||
abortpr(dis)
|
||||
int dis;
|
||||
{
|
||||
register FILE *fp;
|
||||
FILE *fp;
|
||||
struct stat stbuf;
|
||||
int pid, fd, ret;
|
||||
int pid, fd;
|
||||
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
@ -185,9 +183,12 @@ abortpr(dis)
|
||||
goto out;
|
||||
}
|
||||
(void)fclose(fp);
|
||||
if (kill(pid = atoi(line), SIGTERM) < 0)
|
||||
printf("\tWarning: daemon (pid %d) not killed\n", pid);
|
||||
else
|
||||
if (kill(pid = atoi(line), SIGTERM) < 0) {
|
||||
if (errno == ESRCH)
|
||||
printf("\tno daemon to abort\n");
|
||||
else
|
||||
printf("\tWarning: daemon (pid %d) not killed\n", pid);
|
||||
} else
|
||||
printf("\tdaemon (pid %d) killed\n", pid);
|
||||
out:
|
||||
seteuid(uid);
|
||||
@ -200,8 +201,8 @@ static void
|
||||
upstat(msg)
|
||||
char *msg;
|
||||
{
|
||||
register int fd;
|
||||
char statfile[BUFSIZ];
|
||||
int fd;
|
||||
char statfile[MAXPATHLEN];
|
||||
|
||||
if (cgetstr(bp, "st", &ST) == -1)
|
||||
ST = DEFSTAT;
|
||||
@ -228,8 +229,8 @@ clean(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -241,7 +242,8 @@ clean(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
cleanpr();
|
||||
@ -306,8 +308,8 @@ sortq(a, b)
|
||||
static void
|
||||
cleanpr()
|
||||
{
|
||||
register int i, n;
|
||||
register char *cp, *cp1, *lp;
|
||||
int i, n;
|
||||
char *cp, *cp1, *lp;
|
||||
struct dirent **queue;
|
||||
int nitems;
|
||||
|
||||
@ -316,7 +318,8 @@ cleanpr()
|
||||
printf("%s:\n", printer);
|
||||
|
||||
/* XXX depends on SD being non nul */
|
||||
for (lp = line, cp = SD; (*lp++ = *cp++) != '\0'; )
|
||||
for (lp = line, cp = SD; (lp - line) < sizeof(line) &&
|
||||
(*lp++ = *cp++) != '\0'; )
|
||||
;
|
||||
lp[-1] = '/';
|
||||
|
||||
@ -379,8 +382,8 @@ enable(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -392,7 +395,8 @@ enable(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
enablepr();
|
||||
@ -447,8 +451,8 @@ disable(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -460,7 +464,8 @@ disable(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
disablepr();
|
||||
@ -485,7 +490,7 @@ disable(argc, argv)
|
||||
static void
|
||||
disablepr()
|
||||
{
|
||||
register int fd;
|
||||
int fd;
|
||||
struct stat stbuf;
|
||||
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
@ -524,8 +529,8 @@ down(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -537,7 +542,8 @@ down(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
putmsg(argc - 2, argv + 2);
|
||||
@ -562,8 +568,8 @@ putmsg(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int fd;
|
||||
register char *cp1, *cp2;
|
||||
int fd;
|
||||
char *cp1, *cp2;
|
||||
char buf[1024];
|
||||
struct stat stbuf;
|
||||
|
||||
@ -616,7 +622,7 @@ putmsg(argc, argv)
|
||||
cp1 = buf;
|
||||
while (--argc >= 0) {
|
||||
cp2 = *argv++;
|
||||
while ((*cp1++ = *cp2++) != '\0')
|
||||
while ((cp1 - buf) < sizeof(buf) && (*cp1++ = *cp2++))
|
||||
;
|
||||
cp1[-1] = ' ';
|
||||
}
|
||||
@ -645,8 +651,8 @@ restart(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -658,7 +664,8 @@ restart(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
abortpr(0);
|
||||
@ -690,8 +697,8 @@ startcmd(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -703,7 +710,8 @@ startcmd(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
startpr(1);
|
||||
@ -763,16 +771,17 @@ status(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
if (argc == 1 || (argc == 2 && strcmp(argv[1], "all") == 0)) {
|
||||
printer = prbuf;
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
prstat();
|
||||
@ -801,8 +810,8 @@ static void
|
||||
prstat()
|
||||
{
|
||||
struct stat stbuf;
|
||||
register int fd, i;
|
||||
register struct dirent *dp;
|
||||
int fd, i;
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
@ -845,13 +854,16 @@ prstat()
|
||||
return;
|
||||
}
|
||||
(void)close(fd);
|
||||
putchar('\t');
|
||||
(void)snprintf(line, sizeof(line), "%s/%s", SD, ST);
|
||||
fd = open(line, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
(void)flock(fd, LOCK_SH);
|
||||
while ((i = read(fd, line, sizeof(line))) > 0)
|
||||
(void)fwrite(line, 1, i, stdout);
|
||||
(void)fstat(fd, &stbuf);
|
||||
if (stbuf.st_size > 0) {
|
||||
putchar('\t');
|
||||
while ((i = read(fd, line, sizeof(line))) > 0)
|
||||
(void)fwrite(line, 1, i, stdout);
|
||||
}
|
||||
(void)close(fd); /* unlocks as well */
|
||||
}
|
||||
}
|
||||
@ -865,8 +877,8 @@ stop(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -878,7 +890,8 @@ stop(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
stoppr();
|
||||
@ -903,7 +916,7 @@ stop(argc, argv)
|
||||
static void
|
||||
stoppr()
|
||||
{
|
||||
register int fd;
|
||||
int fd;
|
||||
struct stat stbuf;
|
||||
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
@ -949,7 +962,7 @@ topq(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
struct stat stbuf;
|
||||
int status, changed;
|
||||
|
||||
@ -1040,9 +1053,9 @@ static int
|
||||
doarg(job)
|
||||
char *job;
|
||||
{
|
||||
register struct queue **qq;
|
||||
register int jobnum, n;
|
||||
register char *cp, *machine;
|
||||
struct queue **qq;
|
||||
int jobnum, n;
|
||||
char *cp, *machine;
|
||||
int cnt = 0;
|
||||
FILE *fp;
|
||||
|
||||
@ -1050,7 +1063,7 @@ doarg(job)
|
||||
* Look for a job item consisting of system name, colon, number
|
||||
* (example: ucbarpa:114)
|
||||
*/
|
||||
if ((cp = index(job, ':')) != NULL) {
|
||||
if ((cp = strchr(job, ':')) != NULL) {
|
||||
machine = job;
|
||||
*cp++ = '\0';
|
||||
job = cp;
|
||||
@ -1113,8 +1126,8 @@ up(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
register char *cp1, *cp2;
|
||||
int c, status;
|
||||
char *cp1, *cp2;
|
||||
char prbuf[100];
|
||||
|
||||
if (argc == 1) {
|
||||
@ -1126,7 +1139,8 @@ up(argc, argv)
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
while ((c = *cp2++) && c != '|' && c != ':' &&
|
||||
(cp1 - prbuf) < sizeof(prbuf))
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
startpr(2);
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: cmdtab.c,v 1.4 1995/11/15 22:27:34 pk Exp $ */
|
||||
/* $NetBSD: cmdtab.c,v 1.5 1997/10/05 15:12:07 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -32,8 +33,13 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: cmdtab.c,v 1.5 1997/10/05 15:12:07 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: extern.h,v 1.2 1995/11/15 22:27:36 pk Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1997/10/05 15:12:08 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -1,4 +1,5 @@
|
||||
.\" $NetBSD: lpc.8,v 1.7 1997/10/05 11:52:29 mrg Exp $
|
||||
.\" $NetBSD: lpc.8,v 1.8 1997/10/05 15:12:09 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
@ -39,18 +40,18 @@
|
||||
.Nm lpc
|
||||
.Nd line printer control program
|
||||
.Sh SYNOPSIS
|
||||
.Nm lpc
|
||||
.Nm
|
||||
.Oo
|
||||
.Ar command
|
||||
.Op Ar argument ...
|
||||
.Oc
|
||||
.Sh DESCRIPTION
|
||||
.Nm Lpc
|
||||
.Nm
|
||||
is used by the system administrator to control the
|
||||
operation of the line printer system.
|
||||
For each line printer configured in
|
||||
.Pa /etc/printcap ,
|
||||
.Nm lpc
|
||||
.Nm
|
||||
may be used to:
|
||||
.Bl -bullet -offset indent
|
||||
.It
|
||||
@ -65,14 +66,14 @@ spooling queues and printer daemons.
|
||||
.El
|
||||
.Pp
|
||||
Without any arguments,
|
||||
.Nm lpc
|
||||
.Nm
|
||||
will prompt for commands from the standard input.
|
||||
If arguments are supplied,
|
||||
.Nm lpc
|
||||
.Nm
|
||||
interprets the first argument as a command and the remaining
|
||||
arguments as parameters to the command. The standard input
|
||||
may be redirected causing
|
||||
.Nm lpc
|
||||
.Nm
|
||||
to read commands from file.
|
||||
Commands may be abbreviated;
|
||||
the following is the list of recognized commands.
|
||||
@ -86,7 +87,7 @@ or, if no argument is given, a list of the recognized commands.
|
||||
.It Ic abort No {\ all\ |\ printer\ }
|
||||
Terminate an active spooling daemon on the local host immediately and
|
||||
then disable printing (preventing new daemons from being started by
|
||||
.Xr lpr )
|
||||
.Xr lpr 1 )
|
||||
for the specified printers.
|
||||
.Pp
|
||||
.It Ic clean No {\ all\ |\ printer\ }
|
||||
@ -97,7 +98,7 @@ from the specified printer queue(s) on the local machine.
|
||||
.It Ic disable No {\ all\ |\ printer\ }
|
||||
Turn the specified printer queues off. This prevents new
|
||||
printer jobs from being entered into the queue by
|
||||
.Xr lpr .
|
||||
.Xr lpr 1 .
|
||||
.Pp
|
||||
.It Ic down No {\ all\ |\ printer\ } message ...
|
||||
Turn the specified printer queue off, disable printing and put
|
||||
@ -124,7 +125,7 @@ Exit from lpc.
|
||||
Attempt to start a new printer daemon.
|
||||
This is useful when some abnormal condition causes the daemon to
|
||||
die unexpectedly, leaving jobs in the queue.
|
||||
.Xr Lpq
|
||||
.Xr Lpq 1
|
||||
will report that there is no daemon present when this condition occurs.
|
||||
If the user is the super-user,
|
||||
try to abort the current daemon first (i.e., kill and restart a stuck daemon).
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lpc.c,v 1.7 1997/10/05 11:52:30 mrg Exp $ */
|
||||
/* $NetBSD: lpc.c,v 1.8 1997/10/05 15:12:10 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,14 +34,15 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: lpc.c,v 1.8 1997/10/05 15:12:10 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -55,7 +57,7 @@ static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95";
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
#include <sys/param.h>
|
||||
#include <err.h>
|
||||
#include "lp.h"
|
||||
#include "lpc.h"
|
||||
#include "extern.h"
|
||||
@ -85,13 +87,14 @@ static struct cmd *getcmd __P((char *));
|
||||
static void intr __P((int));
|
||||
static void makeargv __P((void));
|
||||
static int ingroup __P((char *));
|
||||
int main __P((int, char *p[]));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register struct cmd *c;
|
||||
struct cmd *c;
|
||||
|
||||
euid = geteuid();
|
||||
uid = getuid();
|
||||
@ -142,7 +145,7 @@ static void
|
||||
cmdscanner(top)
|
||||
int top;
|
||||
{
|
||||
register struct cmd *c;
|
||||
struct cmd *c;
|
||||
|
||||
if (!top)
|
||||
putchar('\n');
|
||||
@ -176,11 +179,11 @@ cmdscanner(top)
|
||||
|
||||
static struct cmd *
|
||||
getcmd(name)
|
||||
register char *name;
|
||||
char *name;
|
||||
{
|
||||
register char *p, *q;
|
||||
register struct cmd *c, *found;
|
||||
register int nmatches, longest;
|
||||
char *p, *q;
|
||||
struct cmd *c, *found;
|
||||
int nmatches, longest;
|
||||
|
||||
longest = 0;
|
||||
nmatches = 0;
|
||||
@ -209,12 +212,13 @@ getcmd(name)
|
||||
static void
|
||||
makeargv()
|
||||
{
|
||||
register char *cp;
|
||||
register char **argp = margv;
|
||||
register int n = 0;
|
||||
char *cp;
|
||||
char **argp = margv;
|
||||
int n = 0;
|
||||
|
||||
margc = 0;
|
||||
for (cp = cmdline; *cp && n < MAX_MARGV; n++) {
|
||||
for (cp = cmdline; *cp && (cp - cmdline) < sizeof(cmdline) &&
|
||||
n < MAX_MARGV; n++) {
|
||||
while (isspace(*cp))
|
||||
cp++;
|
||||
if (*cp == '\0')
|
||||
@ -240,12 +244,11 @@ help(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register struct cmd *c;
|
||||
struct cmd *c;
|
||||
|
||||
if (argc == 1) {
|
||||
register int i, j, w;
|
||||
int i, j, w;
|
||||
int columns, width = 0, lines;
|
||||
extern int NCMDS;
|
||||
|
||||
printf("Commands may be abbreviated. Commands are:\n\n");
|
||||
for (c = cmdtab; c->c_name; c++) {
|
||||
@ -278,7 +281,7 @@ help(argc, argv)
|
||||
return;
|
||||
}
|
||||
while (--argc > 0) {
|
||||
register char *arg;
|
||||
char *arg;
|
||||
arg = *++argv;
|
||||
c = getcmd(arg);
|
||||
if (c == (struct cmd *)-1)
|
||||
@ -300,19 +303,17 @@ ingroup(grname)
|
||||
{
|
||||
static struct group *gptr=NULL;
|
||||
static gid_t groups[NGROUPS];
|
||||
register gid_t gid;
|
||||
register int i;
|
||||
gid_t gid;
|
||||
int i;
|
||||
|
||||
if (gptr == NULL) {
|
||||
if ((gptr = getgrnam(grname)) == NULL) {
|
||||
fprintf(stderr, "Warning: unknown group '%s'\n",
|
||||
warnx("Warning: unknown group `%s'\n",
|
||||
grname);
|
||||
return(0);
|
||||
}
|
||||
if (getgroups(NGROUPS, groups) < 0) {
|
||||
perror("getgroups");
|
||||
exit(1);
|
||||
}
|
||||
if (getgroups(NGROUPS, groups) < 0)
|
||||
err(1, "getgroups");
|
||||
}
|
||||
gid = gptr->gr_gid;
|
||||
for (i = 0; i < NGROUPS; i++)
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lpc.h,v 1.2 1995/11/15 22:27:44 pk Exp $ */
|
||||
/* $NetBSD: lpc.h,v 1.3 1997/10/05 15:12:11 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: extern.h,v 1.6 1997/07/10 10:44:48 veego Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.7 1997/10/05 15:12:12 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: lpd.8,v 1.9 1997/07/16 05:54:25 mikel Exp $
|
||||
.\" $NetBSD: lpd.8,v 1.10 1997/10/05 15:12:12 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lpd.c,v 1.12 1997/10/05 11:52:32 mrg Exp $ */
|
||||
/* $NetBSD: lpd.c,v 1.13 1997/10/05 15:12:13 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993, 1994
|
||||
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993, 1994\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: lpd.c,v 1.12 1997/10/05 11:52:32 mrg Exp $");
|
||||
__RCSID("$NetBSD: lpd.c,v 1.13 1997/10/05 15:12:13 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -116,6 +116,7 @@ static void doit __P((void));
|
||||
static void startup __P((void));
|
||||
static void chkhost __P((struct sockaddr_in *));
|
||||
static int ckqueue __P((char *));
|
||||
static void usage __P((void));
|
||||
|
||||
uid_t uid, euid;
|
||||
|
||||
@ -128,7 +129,7 @@ main(argc, argv)
|
||||
fd_set defreadfds;
|
||||
struct sockaddr_un un, fromunix;
|
||||
struct sockaddr_in sin, frominet;
|
||||
int omask, lfd;
|
||||
int omask, lfd, errs, i;
|
||||
|
||||
euid = geteuid(); /* these shouldn't be different */
|
||||
uid = getuid();
|
||||
@ -136,21 +137,22 @@ main(argc, argv)
|
||||
gethostname(host, sizeof(host));
|
||||
name = argv[0];
|
||||
|
||||
while (--argc > 0) {
|
||||
argv++;
|
||||
if (argv[0][0] == '-')
|
||||
switch (argv[0][1]) {
|
||||
case 'd':
|
||||
options |= SO_DEBUG;
|
||||
break;
|
||||
case 'l':
|
||||
lflag++;
|
||||
break;
|
||||
case 's':
|
||||
sflag++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
errs = 0;
|
||||
while ((i = getopt(argc, argv, "dl")) != -1)
|
||||
switch (i) {
|
||||
case 'd':
|
||||
options |= SO_DEBUG;
|
||||
break;
|
||||
case 'l':
|
||||
lflag++;
|
||||
break;
|
||||
default:
|
||||
errs++;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (errs || argc != 0)
|
||||
usage();
|
||||
|
||||
#ifndef DEBUG
|
||||
/*
|
||||
@ -337,8 +339,8 @@ char *cmdnames[] = {
|
||||
static void
|
||||
doit()
|
||||
{
|
||||
register char *cp;
|
||||
register int n;
|
||||
char *cp;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
cp = cbuf;
|
||||
@ -446,7 +448,7 @@ static void
|
||||
startup()
|
||||
{
|
||||
char *buf;
|
||||
register char *cp;
|
||||
char *cp;
|
||||
int pid;
|
||||
|
||||
/*
|
||||
@ -485,7 +487,7 @@ static int
|
||||
ckqueue(cap)
|
||||
char *cap;
|
||||
{
|
||||
register struct dirent *d;
|
||||
struct dirent *d;
|
||||
DIR *dirp;
|
||||
char *spooldir;
|
||||
|
||||
@ -512,9 +514,9 @@ static void
|
||||
chkhost(f)
|
||||
struct sockaddr_in *f;
|
||||
{
|
||||
register struct hostent *hp;
|
||||
register FILE *hostf;
|
||||
int first = 1;
|
||||
struct hostent *hp;
|
||||
FILE *hostf;
|
||||
int first = 1, good = 0;
|
||||
|
||||
f->sin_port = ntohs(f->sin_port);
|
||||
if (f->sin_family != AF_INET || f->sin_port >= IPPORT_RESERVED)
|
||||
@ -531,6 +533,19 @@ chkhost(f)
|
||||
from[sizeof(fromb) - 1] = '\0';
|
||||
from = fromb;
|
||||
|
||||
/* Check for spoof, ala rlogind */
|
||||
hp = gethostbyname(fromb);
|
||||
if (!hp)
|
||||
fatal("hostname for your address (%s) unknown",
|
||||
inet_ntoa(f->sin_addr));
|
||||
for (; good == 0 && hp->h_addr_list[0] != NULL; hp->h_addr_list++) {
|
||||
if (!bcmp(hp->h_addr_list[0], (caddr_t)&f->sin_addr,
|
||||
sizeof(f->sin_addr)))
|
||||
good = 1;
|
||||
}
|
||||
if (good == 0)
|
||||
fatal("address for your hostname (%s) not matched",
|
||||
inet_ntoa(f->sin_addr));
|
||||
hostf = fopen(_PATH_HOSTSEQUIV, "r");
|
||||
again:
|
||||
if (hostf) {
|
||||
@ -549,3 +564,12 @@ again:
|
||||
fatal("Your host does not have line printer access");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
extern char *__progname; /* XXX */
|
||||
|
||||
fprintf(stderr, "usage: %s [-d] [-l]\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: printjob.c,v 1.15 1997/10/05 11:52:33 mrg Exp $ */
|
||||
/* $NetBSD: printjob.c,v 1.16 1997/10/05 15:12:14 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)printjob.c 8.7 (Berkeley) 5/10/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: printjob.c,v 1.15 1997/10/05 11:52:33 mrg Exp $");
|
||||
__RCSID("$NetBSD: printjob.c,v 1.16 1997/10/05 15:12:14 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -74,6 +74,7 @@ __RCSID("$NetBSD: printjob.c,v 1.15 1997/10/05 11:52:33 mrg Exp $");
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
@ -142,9 +143,9 @@ void
|
||||
printjob()
|
||||
{
|
||||
struct stat stb;
|
||||
register struct queue *q, **qp;
|
||||
struct queue *q, **qp;
|
||||
struct queue **queue;
|
||||
register int i, nitems;
|
||||
int i, nitems;
|
||||
off_t pidoff;
|
||||
int errcnt, count = 0;
|
||||
|
||||
@ -316,7 +317,7 @@ static int
|
||||
printit(file)
|
||||
char *file;
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
char *cp;
|
||||
int bombed = OK;
|
||||
|
||||
@ -381,10 +382,12 @@ printit(file)
|
||||
strncpy(fromhost, line+1, sizeof(fromhost) - 1);
|
||||
if (class[0] == '\0')
|
||||
strncpy(class, line+1, sizeof(class) - 1);
|
||||
class[sizeof(class)-1] = '\0';
|
||||
continue;
|
||||
|
||||
case 'P':
|
||||
strncpy(logname, line+1, sizeof(logname) - 1);
|
||||
logname[sizeof(logname)-1] = '\0';
|
||||
if (RS) { /* restricted */
|
||||
if (getpwnam(logname) == NULL) {
|
||||
bombed = NOACCT;
|
||||
@ -408,23 +411,26 @@ printit(file)
|
||||
continue;
|
||||
|
||||
case 'J':
|
||||
if (line[1] != '\0')
|
||||
if (line[1] != '\0') {
|
||||
strncpy(jobname, line+1, sizeof(jobname) - 1);
|
||||
else {
|
||||
jobname[sizeof(jobname)-1] = '\0';
|
||||
} else {
|
||||
jobname[0] = ' ';
|
||||
jobname[1] = '\0';
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'C':
|
||||
if (line[1] != '\0')
|
||||
if (line[1] != '\0') {
|
||||
strncpy(class, line+1, sizeof(class) - 1);
|
||||
else if (class[0] == '\0')
|
||||
class[sizeof(class)-1] = '\0';
|
||||
} else if (class[0] == '\0')
|
||||
gethostname(class, sizeof(class));
|
||||
continue;
|
||||
|
||||
case 'T': /* header title for pr */
|
||||
strncpy(title, line+1, sizeof(title) - 1);
|
||||
title[sizeof(title)-1] = '\0';
|
||||
continue;
|
||||
|
||||
case 'L': /* identification line */
|
||||
@ -436,16 +442,20 @@ printit(file)
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
if (line[1] != '\0')
|
||||
if (line[1] != '\0') {
|
||||
strncpy(fonts[line[0]-'1'], line+1, FONTLEN - 1);
|
||||
fonts[line[0]-'1'][50-1] = '\0';
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'W': /* page width */
|
||||
strncpy(width+2, line+1, sizeof(width) - 3);
|
||||
width[sizeof(width)-1] = '\0';
|
||||
continue;
|
||||
|
||||
case 'I': /* indent amount */
|
||||
strncpy(indent+2, line+1, sizeof(indent) - 3);
|
||||
indent[sizeof(indent)-1] = '\0';
|
||||
continue;
|
||||
|
||||
default: /* some file to print */
|
||||
@ -489,6 +499,8 @@ pass2:
|
||||
continue;
|
||||
|
||||
case 'U':
|
||||
if (strchr(line+1, '/'))
|
||||
continue;
|
||||
(void)unlink(line+1);
|
||||
}
|
||||
/*
|
||||
@ -514,14 +526,11 @@ print(format, file)
|
||||
int format;
|
||||
char *file;
|
||||
{
|
||||
register int n;
|
||||
register char *prog;
|
||||
int fi, fo;
|
||||
FILE *fp;
|
||||
char *av[15], buf[BUFSIZ];
|
||||
int pid, p[2], stopped = 0;
|
||||
union wait status;
|
||||
int status;
|
||||
struct stat stb;
|
||||
char *prog, *av[15], buf[BUFSIZ];
|
||||
int n, fi, fo, pid, p[2], stopped = 0, nofile;
|
||||
|
||||
if (lstat(file, &stb) < 0 || (fi = open(file, O_RDONLY)) < 0)
|
||||
return(ERROR);
|
||||
@ -565,7 +574,8 @@ print(format, file)
|
||||
dup2(fi, 0); /* file is stdin */
|
||||
dup2(p[1], 1); /* pipe is stdout */
|
||||
closelog();
|
||||
for (n = 3; n < NOFILE; n++)
|
||||
nofile = sysconf(_SC_OPEN_MAX);
|
||||
for (n = 3; n < nofile; n++)
|
||||
(void)close(n);
|
||||
execl(_PATH_PR, "pr", width, length,
|
||||
"-h", *title ? title : " ", 0);
|
||||
@ -648,13 +658,13 @@ print(format, file)
|
||||
return(ERROR);
|
||||
}
|
||||
if (prog == NULL) {
|
||||
(void) close(fi);
|
||||
(void)close(fi);
|
||||
syslog(LOG_ERR,
|
||||
"%s: no filter found in printcap for format character '%c'",
|
||||
printer, format);
|
||||
return(ERROR);
|
||||
"%s: no filter found in printcap for format character '%c'",
|
||||
printer, format);
|
||||
return (ERROR);
|
||||
}
|
||||
if ((av[0] = rindex(prog, '/')) != NULL)
|
||||
if ((av[0] = strrchr(prog, '/')) != NULL)
|
||||
av[0]++;
|
||||
else
|
||||
av[0] = prog;
|
||||
@ -668,13 +678,13 @@ print(format, file)
|
||||
if (ofilter > 0) { /* stop output filter */
|
||||
write(ofd, "\031\1", 2);
|
||||
while ((pid =
|
||||
wait3((int *)&status, WUNTRACED, 0)) > 0 && pid != ofilter)
|
||||
wait3(&status, WUNTRACED, 0)) > 0 && pid != ofilter)
|
||||
;
|
||||
if (status.w_stopval != WSTOPPED) {
|
||||
if (WIFSTOPPED(status) == 0) {
|
||||
(void)close(fi);
|
||||
syslog(LOG_WARNING,
|
||||
"%s: output filter died (retcode=%d termsig=%d)",
|
||||
printer, status.w_retcode, status.w_termsig);
|
||||
"%s: output filter died (retcode=%d termsig=%d)",
|
||||
printer, WEXITSTATUS(status), WTERMSIG(status));
|
||||
return(REPRINT);
|
||||
}
|
||||
stopped++;
|
||||
@ -688,18 +698,23 @@ start:
|
||||
if (n >= 0)
|
||||
dup2(n, 2);
|
||||
closelog();
|
||||
for (n = 3; n < NOFILE; n++)
|
||||
nofile = sysconf(_SC_OPEN_MAX);
|
||||
for (n = 3; n < nofile; n++)
|
||||
(void)close(n);
|
||||
execv(prog, av);
|
||||
syslog(LOG_ERR, "cannot execv %s", prog);
|
||||
exit(2);
|
||||
}
|
||||
if (child < 0) {
|
||||
child = 0;
|
||||
prchild = 0;
|
||||
tof = 0;
|
||||
syslog(LOG_ERR, "cannot start child process: %m");
|
||||
return (ERROR);
|
||||
}
|
||||
(void)close(fi);
|
||||
if (child < 0)
|
||||
status.w_retcode = 100;
|
||||
else
|
||||
while ((pid = wait((int *)&status)) > 0 && pid != child)
|
||||
;
|
||||
while ((pid = wait(&status)) > 0 && pid != child)
|
||||
;
|
||||
child = 0;
|
||||
prchild = 0;
|
||||
if (stopped) { /* restart output filter */
|
||||
@ -718,11 +733,12 @@ start:
|
||||
}
|
||||
|
||||
if (!WIFEXITED(status)) {
|
||||
syslog(LOG_WARNING, "%s: filter '%c' terminated (termsig=%d)",
|
||||
printer, format, status.w_termsig);
|
||||
syslog(LOG_WARNING,
|
||||
"%s: Daemon filter '%c' terminated (termsig=%d)",
|
||||
printer, format, WTERMSIG(status));
|
||||
return(ERROR);
|
||||
}
|
||||
switch (status.w_retcode) {
|
||||
switch (WEXITSTATUS(status)) {
|
||||
case 0:
|
||||
tof = 1;
|
||||
return(OK);
|
||||
@ -732,7 +748,7 @@ start:
|
||||
return(ERROR);
|
||||
default:
|
||||
syslog(LOG_WARNING, "%s: filter '%c' exited (retcode=%d)",
|
||||
printer, format, status.w_retcode);
|
||||
printer, format, WEXITSTATUS(status));
|
||||
return(FILTERERR);
|
||||
}
|
||||
}
|
||||
@ -746,7 +762,7 @@ static int
|
||||
sendit(file)
|
||||
char *file;
|
||||
{
|
||||
register int i, err = OK;
|
||||
int i, err = OK;
|
||||
char *cp, last[BUFSIZ];
|
||||
|
||||
/*
|
||||
@ -786,6 +802,7 @@ sendit(file)
|
||||
}
|
||||
if (line[0] >= 'a' && line[0] <= 'z') {
|
||||
strncpy(last, line, sizeof(last) - 1);
|
||||
last[sizeof(last) - 1] = '\0';
|
||||
while ((i = getline(cfp)) != 0)
|
||||
if (strcmp(last, line))
|
||||
break;
|
||||
@ -814,7 +831,7 @@ sendit(file)
|
||||
*/
|
||||
fseek(cfp, 0L, 0);
|
||||
while (getline(cfp))
|
||||
if (line[0] == 'U')
|
||||
if (line[0] == 'U' && strchr(line+1, '/') == 0)
|
||||
(void)unlink(line+1);
|
||||
/*
|
||||
* clean-up in case another control file exists
|
||||
@ -833,7 +850,7 @@ sendfile(type, file)
|
||||
int type;
|
||||
char *file;
|
||||
{
|
||||
register int f, i, amt;
|
||||
int f, i, amt;
|
||||
struct stat stb;
|
||||
char buf[BUFSIZ];
|
||||
int sizerr, resp;
|
||||
@ -878,9 +895,6 @@ sendfile(type, file)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
(void)close(f);
|
||||
if (sizerr) {
|
||||
syslog(LOG_INFO, "%s: %s: changed size", printer, file);
|
||||
@ -955,11 +969,11 @@ banner(name1, name2)
|
||||
|
||||
static char *
|
||||
scnline(key, p, c)
|
||||
register int key;
|
||||
register char *p;
|
||||
int key;
|
||||
char *p;
|
||||
int c;
|
||||
{
|
||||
register scnwidth;
|
||||
int scnwidth;
|
||||
|
||||
for (scnwidth = WIDTH; --scnwidth;) {
|
||||
key <<= 1;
|
||||
@ -975,8 +989,8 @@ scan_out(scfd, scsp, dlm)
|
||||
int scfd, dlm;
|
||||
char *scsp;
|
||||
{
|
||||
register char *strp;
|
||||
register nchrs, j;
|
||||
char *strp;
|
||||
int nchrs, j;
|
||||
char outbuf[LINELEN+1], *sp, c, cc;
|
||||
int d, scnhgt;
|
||||
extern char scnkey[][HEIGHT]; /* in lpdchar.c */
|
||||
@ -1036,25 +1050,25 @@ sendmail(user, bombed)
|
||||
char *user;
|
||||
int bombed;
|
||||
{
|
||||
register int i;
|
||||
int p[2], s;
|
||||
register char *cp;
|
||||
char buf[100];
|
||||
int i, p[2], s, nofile;
|
||||
char *cp = NULL; /* XXX gcc */
|
||||
struct stat stb;
|
||||
FILE *fp;
|
||||
|
||||
if (user[0] == '-' || user[0] == '/' || !isprint(user[0]))
|
||||
return;
|
||||
pipe(p);
|
||||
if ((s = dofork(DORETURN)) == 0) { /* child */
|
||||
dup2(p[0], 0);
|
||||
closelog();
|
||||
for (i = 3; i < NOFILE; i++)
|
||||
nofile = sysconf(_SC_OPEN_MAX);
|
||||
for (i = 3; i < nofile; i++)
|
||||
(void)close(i);
|
||||
if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL)
|
||||
if ((cp = strrchr(_PATH_SENDMAIL, '/')) != NULL)
|
||||
cp++;
|
||||
else
|
||||
else
|
||||
cp = _PATH_SENDMAIL;
|
||||
(void)snprintf(buf, sizeof(buf), "%s@%s", user, fromhost);
|
||||
execl(_PATH_SENDMAIL, cp, buf, 0);
|
||||
execl(_PATH_SENDMAIL, cp, "-t", 0);
|
||||
exit(0);
|
||||
} else if (s > 0) { /* parent */
|
||||
dup2(p[1], 1);
|
||||
@ -1097,12 +1111,17 @@ sendmail(user, bombed)
|
||||
}
|
||||
fflush(stdout);
|
||||
(void)close(1);
|
||||
} else {
|
||||
syslog(LOG_ERR, "fork for sendmail failed: %m");
|
||||
}
|
||||
(void)close(p[0]);
|
||||
(void)close(p[1]);
|
||||
wait(NULL);
|
||||
syslog(LOG_INFO, "mail sent to user %s about job %s on printer %s (%s)",
|
||||
user, *jobname ? jobname : "<unknown>", printer, cp);
|
||||
if (s > 0) {
|
||||
wait(NULL);
|
||||
syslog(LOG_INFO, "mail sent to user %s about job %s on "
|
||||
"printer %s (%s)", user, *jobname ? jobname : "<unknown>",
|
||||
printer, cp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1112,7 +1131,7 @@ static int
|
||||
dofork(action)
|
||||
int action;
|
||||
{
|
||||
register int i, pid;
|
||||
int i, pid;
|
||||
struct passwd *pw;
|
||||
|
||||
for (i = 0; i < 20; i++) {
|
||||
@ -1252,11 +1271,11 @@ init()
|
||||
static void
|
||||
openpr()
|
||||
{
|
||||
register int i;
|
||||
int i, nofile;
|
||||
char *cp;
|
||||
|
||||
if (!remote && *LP) {
|
||||
if (cp = strchr(LP, '@'))
|
||||
if ((cp = strchr(LP, '@')))
|
||||
opennet(cp);
|
||||
else
|
||||
opentty();
|
||||
@ -1279,9 +1298,10 @@ openpr()
|
||||
dup2(p[0], 0); /* pipe is std in */
|
||||
dup2(pfd, 1); /* printer is std out */
|
||||
closelog();
|
||||
for (i = 3; i < NOFILE; i++)
|
||||
nofile = sysconf(_SC_OPEN_MAX);
|
||||
for (i = 3; i < nofile; i++)
|
||||
(void)close(i);
|
||||
if ((cp = rindex(OF, '/')) == NULL)
|
||||
if ((cp = strrchr(OF, '/')) == NULL)
|
||||
cp = OF;
|
||||
else
|
||||
cp++;
|
||||
@ -1305,7 +1325,7 @@ static void
|
||||
opennet(cp)
|
||||
char *cp;
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
int resp, port;
|
||||
char save_ch;
|
||||
|
||||
@ -1349,8 +1369,7 @@ opennet(cp)
|
||||
static void
|
||||
opentty()
|
||||
{
|
||||
register int i;
|
||||
int resp, port;
|
||||
int i;
|
||||
|
||||
for (i = 1; ; i = i < 32 ? i << 1 : i) {
|
||||
pfd = open(LP, RW ? O_RDWR : O_WRONLY);
|
||||
@ -1378,8 +1397,8 @@ opentty()
|
||||
static void
|
||||
openrem()
|
||||
{
|
||||
register int i, n;
|
||||
int resp, port;
|
||||
int i, n;
|
||||
int resp;
|
||||
|
||||
for (i = 1; ; i = i < 256 ? i << 1 : i) {
|
||||
resp = -1;
|
||||
@ -1425,6 +1444,8 @@ struct bauds {
|
||||
9600, B9600,
|
||||
19200, B19200,
|
||||
38400, B38400,
|
||||
57600, B57600,
|
||||
115200, B115200,
|
||||
0, 0
|
||||
};
|
||||
#endif
|
||||
@ -1450,7 +1471,7 @@ setty()
|
||||
}
|
||||
if (BR > 0) {
|
||||
#if !defined(__NetBSD__)
|
||||
register struct bauds *bp;
|
||||
struct bauds *bp;
|
||||
for (bp = bauds; bp->baud; bp++)
|
||||
if (BR == bp->baud)
|
||||
break;
|
||||
@ -1520,14 +1541,14 @@ setty()
|
||||
return;
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
pstatus(const char *msg, ...)
|
||||
#else
|
||||
pstatus(msg, va_alist)
|
||||
@ -1535,10 +1556,10 @@ pstatus(msg, va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
register int fd;
|
||||
int fd;
|
||||
char buf[BUFSIZ];
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: recvjob.c,v 1.9 1997/10/05 11:52:35 mrg Exp $ */
|
||||
/* $NetBSD: recvjob.c,v 1.10 1997/10/05 15:12:15 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -45,7 +45,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)recvjob.c 8.2 (Berkeley) 4/27/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: recvjob.c,v 1.9 1997/10/05 11:52:35 mrg Exp $");
|
||||
__RCSID("$NetBSD: recvjob.c,v 1.10 1997/10/05 15:12:15 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -72,10 +72,10 @@ __RCSID("$NetBSD: recvjob.c,v 1.9 1997/10/05 11:52:35 mrg Exp $");
|
||||
|
||||
#define ack() (void)write(1, sp, 1);
|
||||
|
||||
static char dfname[40]; /* data files */
|
||||
static char dfname[NAME_MAX]; /* data files */
|
||||
static int minfree; /* keep at least minfree blocks available */
|
||||
static char *sp = "";
|
||||
static char tfname[40]; /* tmp copy of cf before linking */
|
||||
static char tfname[NAME_MAX]; /* tmp copy of cf before linking */
|
||||
|
||||
static int chksize __P((int));
|
||||
static void frecverr __P((const char *, ...));
|
||||
@ -140,8 +140,8 @@ recvjob()
|
||||
static int
|
||||
readjob()
|
||||
{
|
||||
register int size, nfiles;
|
||||
register char *cp;
|
||||
int size, nfiles;
|
||||
char *cp;
|
||||
|
||||
ack();
|
||||
nfiles = 0;
|
||||
@ -153,10 +153,13 @@ readjob()
|
||||
do {
|
||||
if ((size = read(1, cp, 1)) != 1) {
|
||||
if (size < 0)
|
||||
frecverr("%s: Lost connection",printer);
|
||||
frecverr("%s: Lost connection",
|
||||
printer);
|
||||
return(nfiles);
|
||||
}
|
||||
} while (*cp++ != '\n');
|
||||
} while (*cp++ != '\n' && (cp - line + 1) < sizeof(line));
|
||||
if (cp - line + 1 >= sizeof(line))
|
||||
frecverr("readjob overflow");
|
||||
*--cp = '\0';
|
||||
cp = line;
|
||||
switch (*cp++) {
|
||||
@ -177,8 +180,13 @@ readjob()
|
||||
* returns
|
||||
*/
|
||||
(void)strncpy(cp + 6, from, sizeof(line) - strlen(line) - 1);
|
||||
line[sizeof(line) - 1 ] = '\0';
|
||||
(void)strncpy(tfname, cp, sizeof(tfname) - 1);
|
||||
tfname[sizeof(tfname) - 1 ] = '\0';
|
||||
tfname[0] = 't';
|
||||
if (strchr(tfname, '/'))
|
||||
frecverr("readjob: %s: illegal path name",
|
||||
tfname);
|
||||
if (!chksize(size)) {
|
||||
(void)write(1, "\2", 1);
|
||||
continue;
|
||||
@ -205,7 +213,8 @@ readjob()
|
||||
continue;
|
||||
}
|
||||
(void)strncpy(dfname, cp, sizeof(dfname) - 1);
|
||||
if (index(dfname, '/'))
|
||||
dfname[sizeof(dfname) - 1] = '\0';
|
||||
if (strchr(dfname, '/'))
|
||||
frecverr("readjob: %s: illegal path name",
|
||||
dfname);
|
||||
(void)readfile(dfname, size);
|
||||
@ -223,9 +232,9 @@ readfile(file, size)
|
||||
char *file;
|
||||
int size;
|
||||
{
|
||||
register char *cp;
|
||||
char *cp;
|
||||
char buf[BUFSIZ];
|
||||
register int i, j, amt;
|
||||
int i, j, amt;
|
||||
int fd, err;
|
||||
|
||||
fd = open(file, O_CREAT|O_EXCL|O_WRONLY, FILMOD);
|
||||
@ -303,7 +312,7 @@ read_number(fn)
|
||||
char *fn;
|
||||
{
|
||||
char lin[80];
|
||||
register FILE *fp;
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(fn, "r")) == NULL)
|
||||
return (0);
|
||||
@ -334,14 +343,14 @@ rcleanup(signo)
|
||||
dfname[0] = '\0';
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
frecverr(const char *msg, ...)
|
||||
#else
|
||||
frecverr(msg, va_alist)
|
||||
@ -351,7 +360,7 @@ frecverr(msg, va_alist)
|
||||
{
|
||||
extern char fromb[];
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ttcompat.c,v 1.9 1995/11/15 22:50:00 pk Exp $ */
|
||||
/* $NetBSD: ttcompat.c,v 1.10 1997/10/05 15:12:16 mrg Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1995
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -58,15 +58,18 @@
|
||||
#define CLR(t, f) (t) &= ~(f)
|
||||
#define ISSET(t, f) ((t) & (f))
|
||||
|
||||
static int sttygetoflags __P((struct termios *));
|
||||
static void sttysetoflags __P((struct termios *, int));
|
||||
|
||||
static int
|
||||
sttygetoflags(tp)
|
||||
struct termios *tp;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
register int flags = 0;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
int flags = 0;
|
||||
|
||||
if (ISSET(cflag, PARENB)) {
|
||||
if (ISSET(iflag, INPCK)) {
|
||||
@ -101,10 +104,10 @@ sttysetoflags(tp, flags)
|
||||
struct termios *tp;
|
||||
int flags;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
|
||||
if (ISSET(flags, RAW)) {
|
||||
iflag &= IXOFF;
|
||||
@ -167,11 +170,11 @@ sttyclearflags(tp, flags)
|
||||
struct termios *tp;
|
||||
int flags;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
register int oflags = sttygetoflags(tp) & ~flags;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
int oflags = sttygetoflags(tp) & ~flags;
|
||||
|
||||
if (ISSET(flags, TANDEM))
|
||||
CLR(iflag, IXOFF);
|
||||
@ -198,11 +201,11 @@ sttysetflags(tp, flags)
|
||||
struct termios *tp;
|
||||
int flags;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
register int oflags = sttygetoflags(tp) | flags;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
int oflags = sttygetoflags(tp) | flags;
|
||||
|
||||
if (ISSET(flags, TANDEM))
|
||||
SET(iflag, IXOFF);
|
||||
@ -228,11 +231,11 @@ sttyclearlflags(tp, flags)
|
||||
struct termios *tp;
|
||||
int flags;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
register int oflags = sttygetoflags(tp) & ~flags;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
int oflags = sttygetoflags(tp) & ~flags;
|
||||
|
||||
/* Nothing we can do with CRTBS. */
|
||||
if (ISSET(flags, PRTERA))
|
||||
@ -265,11 +268,11 @@ sttysetlflags(tp, flags)
|
||||
struct termios *tp;
|
||||
int flags;
|
||||
{
|
||||
register tcflag_t iflag = tp->c_iflag;
|
||||
register tcflag_t oflag = tp->c_oflag;
|
||||
register tcflag_t lflag = tp->c_lflag;
|
||||
register tcflag_t cflag = tp->c_cflag;
|
||||
register int oflags = sttygetoflags(tp) | flags;
|
||||
tcflag_t iflag = tp->c_iflag;
|
||||
tcflag_t oflag = tp->c_oflag;
|
||||
tcflag_t lflag = tp->c_lflag;
|
||||
tcflag_t cflag = tp->c_cflag;
|
||||
int oflags = sttygetoflags(tp) | flags;
|
||||
|
||||
/* Nothing we can do with CRTBS. */
|
||||
if (ISSET(flags, PRTERA))
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: lpq.1,v 1.7 1997/10/05 11:52:37 mrg Exp $
|
||||
.\" $NetBSD: lpq.1,v 1.8 1997/10/05 15:12:17 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -40,19 +40,19 @@
|
||||
.Nm lpq
|
||||
.Nd spool queue examination program
|
||||
.Sh SYNOPSIS
|
||||
.Nm lpq
|
||||
.OP Fl a
|
||||
.Nm
|
||||
.Op Fl a
|
||||
.Op Fl l
|
||||
.Op Fl P Ns Ar printer
|
||||
.Op job # ...
|
||||
.Op user ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Lpq
|
||||
.Nm
|
||||
examines the spooling area used by
|
||||
.Xr lpd 8
|
||||
.Xr lpd 8
|
||||
for printing files on the line printer, and reports the status of the
|
||||
specified jobs or all jobs associated with a user.
|
||||
.Nm Lpq
|
||||
.Nm
|
||||
invoked
|
||||
without any arguments reports on any jobs currently in the queue.
|
||||
.Pp
|
||||
@ -76,8 +76,8 @@ rather than just the specified printer.
|
||||
.El
|
||||
.Pp
|
||||
For each job submitted (i.e. invocation of
|
||||
.Xr lpr 1 )
|
||||
.Nm lpq
|
||||
.Xr lpr 1 )
|
||||
.Nm
|
||||
reports the user's name, current rank in the queue, the
|
||||
names of files comprising the job, the job identifier (a number which
|
||||
may be supplied to
|
||||
@ -95,14 +95,14 @@ is used as a sink in a pipeline) in which case the file
|
||||
is indicated as ``(standard input)''.
|
||||
.Pp
|
||||
If
|
||||
.Nm lpq
|
||||
.Nm
|
||||
warns that there is no daemon present (i.e. due to some malfunction),
|
||||
the
|
||||
.Xr lpc 8
|
||||
command can be used to restart the printer daemon.
|
||||
.Sh ENVIRONMENT
|
||||
If the following environment variable exists, it is used by
|
||||
.Nm lpq :
|
||||
.Nm "" :
|
||||
.Bl -tag -width PRINTER
|
||||
.It Ev PRINTER
|
||||
Specifies an alternative default printer.
|
||||
@ -124,12 +124,12 @@ The lock file to obtain the currently active job.
|
||||
.Xr lpc 8 ,
|
||||
.Xr lpd 8
|
||||
.Sh HISTORY
|
||||
.Nm Lpq
|
||||
.Nm
|
||||
appeared in
|
||||
.Bx 3 .
|
||||
.Sh BUGS
|
||||
Due to the dynamic nature of the information in the spooling directory
|
||||
.Nm lpq
|
||||
.Nm
|
||||
may report unreliably.
|
||||
Output formatting is sensitive to the line length of the terminal;
|
||||
this can results in widely spaced columns.
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lpq.c,v 1.6 1997/10/05 11:52:38 mrg Exp $ */
|
||||
/* $NetBSD: lpq.c,v 1.7 1997/10/05 15:12:18 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,14 +34,15 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: lpq.c,v 1.7 1997/10/05 15:12:18 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -61,6 +63,8 @@ static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
@ -72,12 +76,13 @@ int users; /* # of users in user array */
|
||||
uid_t uid, euid;
|
||||
|
||||
static int ckqueue __P((char *));
|
||||
void usage __P((void));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char *[]));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
register int argc;
|
||||
register char **argv;
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
@ -88,14 +93,12 @@ main(argc, argv)
|
||||
uid = getuid();
|
||||
seteuid(uid);
|
||||
name = *argv;
|
||||
if (gethostname(host, sizeof(host))) {
|
||||
perror("lpq: gethostname");
|
||||
exit(1);
|
||||
}
|
||||
if (gethostname(host, sizeof(host)))
|
||||
err(1, "lpq: gethostname");
|
||||
openlog("lpd", 0, LOG_LPR);
|
||||
|
||||
aflag = lflag = 0;
|
||||
while ((ch = getopt(argc, argv, "alP:")) != EOF)
|
||||
while ((ch = getopt(argc, argv, "alP:")) != -1)
|
||||
switch((char)ch) {
|
||||
case 'a':
|
||||
++aflag;
|
||||
@ -152,7 +155,7 @@ static int
|
||||
ckqueue(cap)
|
||||
char *cap;
|
||||
{
|
||||
register struct dirent *d;
|
||||
struct dirent *d;
|
||||
DIR *dirp;
|
||||
char *spooldir;
|
||||
|
||||
@ -170,7 +173,7 @@ ckqueue(cap)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
puts("usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]");
|
||||
|
@ -1,4 +1,5 @@
|
||||
.\" $NetBSD: lpr.1,v 1.5 1997/03/08 14:31:07 mouse Exp $
|
||||
.\" $NetBSD: lpr.1,v 1.6 1997/10/05 15:12:19 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
@ -39,20 +40,20 @@
|
||||
.Nm lpr
|
||||
.Nd off line print
|
||||
.Sh SYNOPSIS
|
||||
.Nm lpr
|
||||
.Nm
|
||||
.Op Fl P Ns Ar printer
|
||||
.Op Fl \&# Ns Ar num
|
||||
.Op Fl C Ar class
|
||||
.Op Fl J Ar job
|
||||
.Op Fl T Ar title
|
||||
.Op Fl U Ar user
|
||||
.Op Fl i Op Ar numcols
|
||||
.Op Fl i Ar numcols
|
||||
.Op Fl 1234 Ar font
|
||||
.Op Fl w Ns Ar num
|
||||
.Op Fl cdfghlnmprstv
|
||||
.Op Ar name ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Lpr
|
||||
.Nm
|
||||
uses a spooling daemon to print the named files when facilities
|
||||
become available. If no names appear, the standard input is assumed.
|
||||
.Pp
|
||||
@ -75,9 +76,9 @@ standard
|
||||
carriage control character.
|
||||
.It Fl g
|
||||
The files are assumed to contain standard plot data as produced by the
|
||||
.Xr plot
|
||||
.Xr plot 1
|
||||
routines (see also
|
||||
.Xr plot
|
||||
.Xr plot 1
|
||||
for the filters used by the printer spooler).
|
||||
.It Fl l
|
||||
Use a filter which allows control characters to be printed and suppresses
|
||||
@ -88,12 +89,12 @@ The files are assumed to contain data from
|
||||
(device independent troff).
|
||||
.It Fl p
|
||||
Use
|
||||
.Xr pr 1
|
||||
.Xr pr 1
|
||||
to format the files (equivalent to
|
||||
.Xr print ) .
|
||||
.Xr print 1 ) .
|
||||
.It Fl t
|
||||
The files are assumed to contain data from
|
||||
.Xr troff 1
|
||||
.Xr troff 1
|
||||
(cat phototypesetter commands).
|
||||
.It Fl v
|
||||
The files are assumed to contain a raster image for devices like the
|
||||
@ -123,7 +124,7 @@ Use symbolic links. Usually files are copied to the spool directory.
|
||||
The
|
||||
.Fl s
|
||||
option will use
|
||||
.Xr symlink 2
|
||||
.Xr symlink 2
|
||||
to link data files rather than trying to copy them so large files can be
|
||||
printed. This means the files should
|
||||
not be modified or removed until they have been printed.
|
||||
@ -167,7 +168,7 @@ lpr \-C EECS foo.c
|
||||
.Ed
|
||||
.Pp
|
||||
causes the system name (the name returned by
|
||||
.Xr hostname 1 )
|
||||
.Xr hostname 1 )
|
||||
to be replaced on the burst page by
|
||||
.Tn EECS ,
|
||||
and the file foo.c to be printed.
|
||||
@ -176,7 +177,7 @@ Job name to print on the burst page.
|
||||
Normally, the first file's name is used.
|
||||
.It Fl T Ar title
|
||||
Title name for
|
||||
.Xr pr 1 ,
|
||||
.Xr pr 1 ,
|
||||
instead of the file name.
|
||||
.It Fl U Ar user
|
||||
User name to print on the burst page,
|
||||
@ -184,12 +185,9 @@ also for accounting purposes.
|
||||
This option is only honored if the real user-id is daemon
|
||||
(or that specified in the printcap file instead of daemon),
|
||||
and is intended for those instances where print filters wish to requeue jobs.
|
||||
.It Fl i Op numcols
|
||||
The output is indented. If the next argument
|
||||
is numeric
|
||||
.Pq Ar numcols ,
|
||||
it is used as the number of blanks to be printed before each
|
||||
line; otherwise, 8 characters are printed.
|
||||
.It Fl i numcols
|
||||
The output is indented by
|
||||
.Pq Ar numcols .
|
||||
.It Fl w Ns Ar num
|
||||
Uses
|
||||
.Ar num
|
||||
@ -198,7 +196,7 @@ as the page width for
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
If the following environment variable exists, it is used by
|
||||
.Nm lpr :
|
||||
.Nm "" :
|
||||
.Bl -tag -width PRINTER
|
||||
.It Ev PRINTER
|
||||
Specifies an alternative default printer.
|
||||
@ -209,7 +207,7 @@ Specifies an alternative default printer.
|
||||
Personal identification.
|
||||
.It Pa /etc/printcap
|
||||
Printer capabilities data base.
|
||||
.It Pa /usr/sbin/lpd*
|
||||
.It Pa /usr/sbin/lpd
|
||||
Line printer daemons.
|
||||
.It Pa /var/spool/output/*
|
||||
Directories used for spooling.
|
||||
@ -230,28 +228,28 @@ Temporary copies of "cf" files.
|
||||
.Xr lpd 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm lpr
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3 .
|
||||
.Sh DIAGNOSTICS
|
||||
If you try to spool too large a file, it will be truncated.
|
||||
.Nm Lpr
|
||||
.Nm
|
||||
will object to printing binary files.
|
||||
If a user other than root prints a file and spooling is disabled,
|
||||
.Nm lpr
|
||||
.Nm
|
||||
will print a message saying so and will not put jobs in the queue.
|
||||
If a connection to
|
||||
.Xr lpd 1
|
||||
.Xr lpd 8
|
||||
on the local machine cannot be made,
|
||||
.Nm lpr
|
||||
.Nm
|
||||
will say that the daemon cannot be started.
|
||||
Diagnostics may be printed in the daemon's log file
|
||||
regarding missing spool files by
|
||||
.Xr lpd 1 .
|
||||
.Xr lpd 8 .
|
||||
.Sh BUGS
|
||||
Fonts for
|
||||
.Xr troff 1
|
||||
and
|
||||
.Xr tex
|
||||
.Xr tex 1
|
||||
reside on the host with the printer. It is currently not possible to
|
||||
use local font libraries.
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lpr.c,v 1.14 1997/10/05 11:52:40 mrg Exp $ */
|
||||
/* $NetBSD: lpr.c,v 1.15 1997/10/05 15:12:20 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -38,14 +39,15 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lpr.c 8.4 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: lpr.c,v 1.15 1997/10/05 15:12:20 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -71,6 +73,8 @@ static char sccsid[] = "@(#)lpr.c 8.4 (Berkeley) 4/28/95";
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
@ -111,6 +115,8 @@ static char *lmktemp __P((char *, int, int));
|
||||
static void mktemps __P((void));
|
||||
static int nfile __P((char *));
|
||||
static int test __P((char *));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char *[]));
|
||||
|
||||
uid_t uid, euid;
|
||||
|
||||
@ -121,10 +127,9 @@ main(argc, argv)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct group *gptr;
|
||||
extern char *itoa();
|
||||
register char *arg, *cp;
|
||||
char buf[BUFSIZ];
|
||||
int i, f;
|
||||
char *arg, *cp;
|
||||
char buf[MAXPATHLEN];
|
||||
int i, f, errs, c;
|
||||
struct stat stb;
|
||||
|
||||
euid = geteuid();
|
||||
@ -144,121 +149,110 @@ main(argc, argv)
|
||||
gethostname(host, sizeof (host));
|
||||
openlog("lpd", 0, LOG_LPR);
|
||||
|
||||
while (argc > 1 && argv[1][0] == '-') {
|
||||
argc--;
|
||||
arg = *++argv;
|
||||
switch (arg[1]) {
|
||||
errs = 0;
|
||||
while ((c = getopt(argc, argv,
|
||||
":#:1:2:3:4:C:J:P:T:U:cdfghi:lnmprstvw:")) != -1) {
|
||||
switch (c) {
|
||||
|
||||
case 'P': /* specifiy printer name */
|
||||
if (arg[2])
|
||||
printer = &arg[2];
|
||||
else if (argc > 1) {
|
||||
argc--;
|
||||
printer = *++argv;
|
||||
case '#': /* n copies */
|
||||
if (isdigit(*optarg)) {
|
||||
i = atoi(optarg);
|
||||
if (i > 0)
|
||||
ncopies = i;
|
||||
}
|
||||
|
||||
case '4': /* troff fonts */
|
||||
case '3':
|
||||
case '2':
|
||||
case '1':
|
||||
fonts[optopt - '1'] = optarg;
|
||||
break;
|
||||
|
||||
case 'C': /* classification spec */
|
||||
hdr++;
|
||||
if (arg[2])
|
||||
class = &arg[2];
|
||||
else if (argc > 1) {
|
||||
argc--;
|
||||
class = *++argv;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'U': /* user name */
|
||||
hdr++;
|
||||
if (arg[2])
|
||||
person = &arg[2];
|
||||
else if (argc > 1) {
|
||||
argc--;
|
||||
person = *++argv;
|
||||
}
|
||||
class = optarg;
|
||||
break;
|
||||
|
||||
case 'J': /* job name */
|
||||
hdr++;
|
||||
if (arg[2])
|
||||
jobname = &arg[2];
|
||||
else if (argc > 1) {
|
||||
argc--;
|
||||
jobname = *++argv;
|
||||
}
|
||||
jobname = optarg;
|
||||
break;
|
||||
|
||||
case 'P': /* specifiy printer name */
|
||||
printer = optarg;
|
||||
break;
|
||||
|
||||
case 'T': /* pr's title line */
|
||||
if (arg[2])
|
||||
title = &arg[2];
|
||||
else if (argc > 1) {
|
||||
argc--;
|
||||
title = *++argv;
|
||||
}
|
||||
title = optarg;
|
||||
break;
|
||||
|
||||
case 'l': /* literal output */
|
||||
case 'p': /* print using ``pr'' */
|
||||
case 't': /* print troff output (cat files) */
|
||||
case 'n': /* print ditroff output */
|
||||
case 'U': /* user name */
|
||||
hdr++;
|
||||
person = optarg;
|
||||
break;
|
||||
|
||||
case 'c': /* print cifplot output */
|
||||
case 'd': /* print tex output (dvi files) */
|
||||
case 'g': /* print graph(1G) output */
|
||||
case 'c': /* print cifplot output */
|
||||
case 'l': /* literal output */
|
||||
case 'n': /* print ditroff output */
|
||||
case 'p': /* print using ``pr'' */
|
||||
case 't': /* print troff output (cat files) */
|
||||
case 'v': /* print vplot output */
|
||||
format = arg[1];
|
||||
format = optopt;
|
||||
break;
|
||||
|
||||
case 'f': /* print fortran output */
|
||||
format = 'r';
|
||||
break;
|
||||
|
||||
case '4': /* troff fonts */
|
||||
case '3':
|
||||
case '2':
|
||||
case '1':
|
||||
if (argc > 1) {
|
||||
argc--;
|
||||
fonts[arg[1] - '1'] = *++argv;
|
||||
}
|
||||
case 'h': /* toggle want of header page */
|
||||
hdr = !hdr;
|
||||
break;
|
||||
|
||||
case 'w': /* versatec page width */
|
||||
width = arg+2;
|
||||
break;
|
||||
|
||||
case 'r': /* remove file when done */
|
||||
rflag++;
|
||||
case 'i': /* indent output */
|
||||
iflag++;
|
||||
indent = atoi(optarg);
|
||||
if (indent < 0)
|
||||
indent = 8;
|
||||
break;
|
||||
|
||||
case 'm': /* send mail when done */
|
||||
mailflg++;
|
||||
break;
|
||||
|
||||
case 'h': /* toggle want of header page */
|
||||
hdr = !hdr;
|
||||
case 'q': /* just q job */
|
||||
qflag++;
|
||||
break;
|
||||
|
||||
case 'r': /* remove file when done */
|
||||
rflag++;
|
||||
break;
|
||||
|
||||
case 's': /* try to link files */
|
||||
sflag++;
|
||||
break;
|
||||
|
||||
case 'q': /* just q job */
|
||||
qflag++;
|
||||
case 'w': /* versatec page width */
|
||||
width = optarg;
|
||||
break;
|
||||
|
||||
case 'i': /* indent output */
|
||||
iflag++;
|
||||
indent = arg[2] ? atoi(&arg[2]) : 8;
|
||||
case ':': /* catch "missing argument" error */
|
||||
if (optopt == 'i') {
|
||||
iflag++; /* -i without args is valid */
|
||||
indent = 8;
|
||||
} else
|
||||
errs++;
|
||||
break;
|
||||
|
||||
case '#': /* n copies */
|
||||
if (isdigit(arg[2])) {
|
||||
i = atoi(&arg[2]);
|
||||
if (i > 0)
|
||||
ncopies = i;
|
||||
}
|
||||
default:
|
||||
errs++;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (errs)
|
||||
usage();
|
||||
if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
|
||||
printer = DEFLP;
|
||||
chkprinter(printer);
|
||||
@ -295,7 +289,7 @@ main(argc, argv)
|
||||
/*
|
||||
* Check to make sure queuing is enabled if userid is not root.
|
||||
*/
|
||||
(void)snprintf(buf, BUFSIZ, "%s/%s", SD, LO);
|
||||
(void)snprintf(buf, sizeof buf, "%s/%s", SD, LO);
|
||||
if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010))
|
||||
fatal2("Printer queue is disabled");
|
||||
/*
|
||||
@ -310,10 +304,11 @@ main(argc, argv)
|
||||
card('P', person);
|
||||
if (hdr) {
|
||||
if (jobname == NULL) {
|
||||
if (argc == 1)
|
||||
if (argc == 0)
|
||||
jobname = "stdin";
|
||||
else
|
||||
jobname = (arg = rindex(argv[1], '/')) ? arg+1 : argv[1];
|
||||
jobname = (arg = strrchr(argv[0], '/')) ?
|
||||
arg+1 : argv[0];
|
||||
}
|
||||
card('J', jobname);
|
||||
card('C', class);
|
||||
@ -333,14 +328,20 @@ main(argc, argv)
|
||||
/*
|
||||
* Read the files and spool them.
|
||||
*/
|
||||
if (argc == 1)
|
||||
if (argc == 0)
|
||||
copy(0, " ");
|
||||
else while (--argc) {
|
||||
if ((f = test(arg = *++argv)) < 0)
|
||||
else while (argc--) {
|
||||
if (argv[0][0] == '-' && argv[0][1] == '\0') {
|
||||
/* use stdin */
|
||||
copy(0, " ");
|
||||
argv++;
|
||||
continue;
|
||||
}
|
||||
if ((f = test(arg = *argv++)) < 0)
|
||||
continue; /* file unreasonable */
|
||||
|
||||
if (sflag && (cp = linked(arg)) != NULL) {
|
||||
(void)snprintf(buf, BUFSIZ,
|
||||
(void)snprintf(buf, sizeof buf,
|
||||
"%d %d", statb.st_dev, statb.st_ino);
|
||||
card('S', buf);
|
||||
if (format == 'p')
|
||||
@ -362,11 +363,12 @@ main(argc, argv)
|
||||
seteuid(uid);
|
||||
printf("%s: cannot open %s\n", name, arg);
|
||||
continue;
|
||||
} else {
|
||||
copy(i, arg);
|
||||
(void)close(i);
|
||||
if (f && unlink(arg) < 0)
|
||||
printf("%s: %s: not removed\n", name, arg);
|
||||
}
|
||||
copy(i, arg);
|
||||
(void)close(i);
|
||||
if (f && unlink(arg) < 0)
|
||||
printf("%s: %s: not removed\n", name, arg);
|
||||
seteuid(uid);
|
||||
}
|
||||
|
||||
@ -403,6 +405,9 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
cleanup(0);
|
||||
#ifdef __GNUC__
|
||||
return (0);
|
||||
#endif
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
@ -414,8 +419,8 @@ copy(f, n)
|
||||
int f;
|
||||
char n[];
|
||||
{
|
||||
register int fd, i, nr, nc;
|
||||
char buf[BUFSIZ];
|
||||
int fd, i, nr, nc;
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (format == 'p')
|
||||
card('T', title ? title : n);
|
||||
@ -425,17 +430,18 @@ copy(f, n)
|
||||
card('N', n);
|
||||
fd = nfile(dfname);
|
||||
nr = nc = 0;
|
||||
while ((i = read(f, buf, BUFSIZ)) > 0) {
|
||||
while ((i = read(f, buf, sizeof buf)) > 0) {
|
||||
if (write(fd, buf, i) != i) {
|
||||
printf("%s: %s: temp file write error\n", name, n);
|
||||
break;
|
||||
}
|
||||
nc += i;
|
||||
if (nc >= BUFSIZ) {
|
||||
nc -= BUFSIZ;
|
||||
if (nc >= sizeof buf) {
|
||||
nc -= sizeof buf;
|
||||
nr++;
|
||||
if (MX > 0 && nr > MX) {
|
||||
printf("%s: %s: copy file is too large\n", name, n);
|
||||
printf("%s: %s: copy file is too large\n",
|
||||
name, n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -453,17 +459,16 @@ copy(f, n)
|
||||
*/
|
||||
static char *
|
||||
linked(file)
|
||||
register char *file;
|
||||
char *file;
|
||||
{
|
||||
register char *cp;
|
||||
char *cp;
|
||||
static char buf[BUFSIZ];
|
||||
register int ret;
|
||||
int ret;
|
||||
|
||||
if (*file != '/') {
|
||||
/* XXX: 2 and file for "/file" */
|
||||
if (getcwd(buf, BUFSIZ - 2 - strlen(file)) == NULL) {
|
||||
if (getcwd(buf, BUFSIZ - 2 - strlen(file)) == NULL)
|
||||
return(NULL);
|
||||
}
|
||||
while (file[0] == '.') {
|
||||
switch (file[1]) {
|
||||
case '/':
|
||||
@ -471,7 +476,7 @@ linked(file)
|
||||
continue;
|
||||
case '.':
|
||||
if (file[2] == '/') {
|
||||
if ((cp = rindex(buf, '/')) != NULL)
|
||||
if ((cp = strrchr(buf, '/')) != NULL)
|
||||
*cp = '\0';
|
||||
file += 3;
|
||||
continue;
|
||||
@ -494,15 +499,15 @@ linked(file)
|
||||
*/
|
||||
static void
|
||||
card(c, p2)
|
||||
register int c;
|
||||
register char *p2;
|
||||
int c;
|
||||
char *p2;
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
register char *p1 = buf;
|
||||
register int len = 2;
|
||||
char *p1 = buf;
|
||||
int len = 2;
|
||||
|
||||
if (strlen(p2) > BUFSIZ - 2)
|
||||
errx(1, "Internal error: String longer than %d", BUFSIZ);
|
||||
errx(1, "Internal error: String longer than %d", BUFSIZ);
|
||||
|
||||
*p1++ = c;
|
||||
while ((c = *p2++) != '\0') {
|
||||
@ -520,7 +525,7 @@ static int
|
||||
nfile(n)
|
||||
char *n;
|
||||
{
|
||||
register int f;
|
||||
int f;
|
||||
int oldumask = umask(0); /* should block signals */
|
||||
|
||||
seteuid(euid);
|
||||
@ -553,7 +558,7 @@ static void
|
||||
cleanup(signo)
|
||||
int signo;
|
||||
{
|
||||
register i;
|
||||
int i;
|
||||
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
signal(SIGINT, SIG_IGN);
|
||||
@ -589,8 +594,8 @@ test(file)
|
||||
char *file;
|
||||
{
|
||||
struct exec execb;
|
||||
register int fd;
|
||||
register char *cp;
|
||||
int fd;
|
||||
char *cp;
|
||||
|
||||
seteuid(uid);
|
||||
if (access(file, 4) < 0) {
|
||||
@ -622,7 +627,7 @@ test(file)
|
||||
}
|
||||
(void)close(fd);
|
||||
if (rflag) {
|
||||
if ((cp = rindex(file, '/')) == NULL) {
|
||||
if ((cp = strrchr(file, '/')) == NULL) {
|
||||
if (access(".", 2) == 0)
|
||||
return(1);
|
||||
} else {
|
||||
@ -649,10 +654,10 @@ bad:
|
||||
*/
|
||||
static char *
|
||||
itoa(i)
|
||||
register int i;
|
||||
int i;
|
||||
{
|
||||
static char b[10] = "########";
|
||||
register char *p;
|
||||
char *p;
|
||||
|
||||
p = &b[8];
|
||||
do
|
||||
@ -694,10 +699,9 @@ chkprinter(s)
|
||||
static void
|
||||
mktemps()
|
||||
{
|
||||
register int len, fd, n;
|
||||
register char *cp;
|
||||
int len, fd, n;
|
||||
char *cp;
|
||||
char buf[BUFSIZ];
|
||||
char *lmktemp();
|
||||
|
||||
(void)snprintf(buf, BUFSIZ, "%s/.seq", SD);
|
||||
seteuid(euid);
|
||||
@ -738,7 +742,7 @@ lmktemp(id, num, len)
|
||||
char *id;
|
||||
int num, len;
|
||||
{
|
||||
register char *s;
|
||||
char *s;
|
||||
|
||||
if ((s = malloc(len)) == NULL)
|
||||
fatal2("out of memory");
|
||||
@ -746,14 +750,14 @@ lmktemp(id, num, len)
|
||||
return(s);
|
||||
}
|
||||
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
fatal2(const char *msg, ...)
|
||||
#else
|
||||
fatal2(msg, va_alist)
|
||||
@ -762,7 +766,7 @@ fatal2(msg, va_alist)
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
#ifdef __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
@ -773,3 +777,14 @@ fatal2(msg, va_alist)
|
||||
va_end(ap);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
fprintf(stderr, "%s\n%s\n",
|
||||
"usage: lpr [-Pprinter] [-#num] [-C class] [-J job] [-T title] "
|
||||
"[-U user]",
|
||||
"[-i[numcols]] [-1234 font] [-wnum] [-cdfghlnmprstv] [name ...]");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
.\" $NetBSD: lprm.1,v 1.6 1997/07/09 02:04:30 jtc Exp $
|
||||
.\" $NetBSD: lprm.1,v 1.7 1997/10/05 15:12:21 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
@ -39,16 +40,16 @@
|
||||
.Nm lprm
|
||||
.Nd remove jobs from the line printer spooling queue
|
||||
.Sh SYNOPSIS
|
||||
.Nm lprm
|
||||
.Nm
|
||||
.Op Fl P Ns Ar printer
|
||||
.Op Fl
|
||||
.Op job # ...
|
||||
.Op Ar user ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Lprm
|
||||
.Nm
|
||||
will remove a job, or jobs, from a printer's spool queue.
|
||||
Since the spooling directory is protected from users, using
|
||||
.Nm lprm
|
||||
.Nm
|
||||
is normally the only method by which a user may remove a job.
|
||||
The owner of a job is determined by the user's login name
|
||||
and host name on the machine where the
|
||||
@ -65,16 +66,16 @@ Specify the queue associated with a specific
|
||||
If a single
|
||||
.Sq Fl
|
||||
is given,
|
||||
.Nm lprm
|
||||
.Nm
|
||||
will remove all jobs which a user
|
||||
owns. If the super-user employs this flag, the spool queue will
|
||||
be emptied entirely.
|
||||
.It Ar user
|
||||
Causes
|
||||
.Nm lprm
|
||||
.Nm
|
||||
to attempt to remove any jobs queued belonging to that user
|
||||
(or users). This form of invoking
|
||||
.Nm lprm
|
||||
.Nm
|
||||
is useful only to the super-user.
|
||||
.It Ar job\ \&#
|
||||
A user may dequeue an individual job by specifying its job number.
|
||||
@ -92,22 +93,22 @@ program, e.g.
|
||||
.El
|
||||
.Pp
|
||||
If neither arguments or options are given,
|
||||
.Nm Lprm
|
||||
.Nm
|
||||
will delete the currently active job if it is
|
||||
owned by the user who invoked
|
||||
.Nm lprm .
|
||||
.Nm "" .
|
||||
.Pp
|
||||
.Nm Lprm
|
||||
.Nm
|
||||
announces the names of any files it removes and is silent if
|
||||
there are no jobs in the queue which match the request list.
|
||||
.Pp
|
||||
.Nm Lprm
|
||||
.Nm
|
||||
will kill off an active daemon, if necessary, before removing
|
||||
any spooling files. If a daemon is killed, a new one is
|
||||
automatically restarted upon completion of file removals.
|
||||
.Sh ENVIRONMENT
|
||||
If the following environment variable exists, it is utilized by
|
||||
.Nm lprm .
|
||||
.Nm "" .
|
||||
.Bl -tag -width PRINTER
|
||||
.It Ev PRINTER
|
||||
If the environment variable
|
||||
@ -141,6 +142,6 @@ Since there are race conditions possible in the update of the lock file,
|
||||
the currently active job may be incorrectly identified.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm lprm
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lprm.c,v 1.6 1996/12/09 09:57:49 mrg Exp $ */
|
||||
/* $NetBSD: lprm.c,v 1.7 1997/10/05 15:12:22 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,14 +34,15 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: lprm.c,v 1.7 1997/10/05 15:12:22 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -64,6 +66,7 @@ static char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
|
||||
@ -79,14 +82,15 @@ uid_t uid, euid; /* real and effective user id's */
|
||||
|
||||
static char luser[16]; /* buffer for person */
|
||||
|
||||
void usage __P((void));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char *[]));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register char *arg;
|
||||
char *arg;
|
||||
struct passwd *p;
|
||||
|
||||
uid = getuid();
|
||||
@ -100,6 +104,7 @@ main(argc, argv)
|
||||
if (strlen(p->pw_name) >= sizeof(luser))
|
||||
fatal("Your name is too long");
|
||||
strncpy(luser, p->pw_name, sizeof(luser) - 1);
|
||||
luser[sizeof(luser) - 1] = '\0';
|
||||
person = luser;
|
||||
while (--argc) {
|
||||
if ((arg = *++argv)[0] == '-')
|
||||
@ -141,7 +146,7 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
|
||||
|
@ -1,4 +1,5 @@
|
||||
.\" $NetBSD: lptest.1,v 1.4 1995/11/15 22:50:43 pk Exp $
|
||||
.\" $NetBSD: lptest.1,v 1.5 1997/10/05 15:12:23 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1985, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: lptest.c,v 1.6 1996/12/09 09:57:50 mrg Exp $ */
|
||||
/* $NetBSD: lptest.c,v 1.7 1997/10/05 15:12:24 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,19 +34,22 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lptest.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: lptest.c,v 1.7 1997/10/05 15:12:24 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main __P((int, char *[]));
|
||||
|
||||
/*
|
||||
* lptest -- line printer test program (and other devices).
|
||||
*/
|
||||
@ -55,7 +59,7 @@ main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
int len, count;
|
||||
register i, j, fc, nc;
|
||||
int i, j, fc, nc;
|
||||
char outbuf[BUFSIZ];
|
||||
|
||||
setbuf(stdout, outbuf);
|
||||
|
@ -1,4 +1,5 @@
|
||||
.\" $NetBSD: pac.8,v 1.4 1995/11/15 22:52:07 pk Exp $
|
||||
.\" $NetBSD: pac.8,v 1.5 1997/10/05 15:12:25 mrg Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
@ -39,7 +40,7 @@
|
||||
.Nm pac
|
||||
.Nd printer/plotter accounting information
|
||||
.Sh SYNOPSIS
|
||||
.Nm pac
|
||||
.Nm
|
||||
.Op Fl P Ns Ar printer
|
||||
.Op Fl c
|
||||
.Op Fl m
|
||||
@ -48,7 +49,7 @@
|
||||
.Op Fl r
|
||||
.Op Ar name ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Pac
|
||||
.Nm
|
||||
reads the printer/plotter accounting files, accumulating the number
|
||||
of pages (the usual case) or feet (for raster devices)
|
||||
of paper consumed by each user, and printing out
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* $NetBSD: pac.c,v 1.9 1997/07/11 06:43:51 mikel Exp $ */
|
||||
/* $NetBSD: pac.c,v 1.10 1997/10/05 15:12:25 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -33,17 +34,14 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: pac.c,v 1.9 1997/07/11 06:43:51 mikel Exp $";
|
||||
__RCSID("$NetBSD: pac.c,v 1.10 1997/10/05 15:12:25 mrg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -61,6 +59,8 @@ static char rcsid[] = "$NetBSD: pac.c,v 1.9 1997/07/11 06:43:51 mikel Exp $";
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
|
||||
@ -105,14 +105,16 @@ static struct hent *enter __P((char []));
|
||||
static struct hent *lookup __P((char []));
|
||||
static int qucmp __P((const void *, const void *));
|
||||
static void rewrite __P((void));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char *[]));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register FILE *acct;
|
||||
register char *cp;
|
||||
FILE *acct;
|
||||
char *cp;
|
||||
|
||||
euid = geteuid(); /* these aren't used in pac(1) */
|
||||
uid = getuid();
|
||||
@ -164,8 +166,7 @@ main(argc, argv)
|
||||
continue;
|
||||
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"usage: pac [-Pprinter] [-pprice] [-s] [-c] [-r] [-m] [user ...]\n");
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -179,10 +180,8 @@ fprintf(stderr,
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if ((acct = fopen(acctfile, "r")) == NULL) {
|
||||
perror(acctfile);
|
||||
exit(1);
|
||||
}
|
||||
if ((acct = fopen(acctfile, "r")) == NULL)
|
||||
err(1, "%s", acctfile);
|
||||
account(acct);
|
||||
fclose(acct);
|
||||
if ((acct = fopen(sumfile, "r")) != NULL) {
|
||||
@ -206,13 +205,13 @@ fprintf(stderr,
|
||||
*/
|
||||
static void
|
||||
account(acct)
|
||||
register FILE *acct;
|
||||
FILE *acct;
|
||||
{
|
||||
char linebuf[BUFSIZ];
|
||||
double t;
|
||||
register char *cp, *cp2;
|
||||
register struct hent *hp;
|
||||
register int ic;
|
||||
char *cp, *cp2;
|
||||
struct hent *hp;
|
||||
int ic;
|
||||
|
||||
while (fgets(linebuf, BUFSIZ, acct) != NULL) {
|
||||
cp = linebuf;
|
||||
@ -227,8 +226,8 @@ account(acct)
|
||||
;
|
||||
ic = atoi(cp2);
|
||||
*cp2 = '\0';
|
||||
if (mflag && index(cp, ':'))
|
||||
cp = index(cp, ':') + 1;
|
||||
if (mflag && strchr(cp, ':'))
|
||||
cp = strchr(cp, ':') + 1;
|
||||
hp = lookup(cp);
|
||||
if (hp == NULL) {
|
||||
if (!allflag)
|
||||
@ -251,13 +250,15 @@ static void
|
||||
dumpit()
|
||||
{
|
||||
struct hent **base;
|
||||
register struct hent *hp, **ap;
|
||||
register int hno, c, runs;
|
||||
struct hent *hp, **ap;
|
||||
int hno, c, runs;
|
||||
float feet;
|
||||
|
||||
hp = hashtab[0];
|
||||
hno = 1;
|
||||
base = (struct hent **) calloc(sizeof hp, hcount);
|
||||
if (base == NULL)
|
||||
err(1, "calloc");
|
||||
for (ap = base, c = hcount; c--; ap++) {
|
||||
while (hp == NULL)
|
||||
hp = hashtab[hno++];
|
||||
@ -288,12 +289,12 @@ dumpit()
|
||||
static void
|
||||
rewrite()
|
||||
{
|
||||
register struct hent *hp;
|
||||
register int i;
|
||||
register FILE *acctf;
|
||||
struct hent *hp;
|
||||
int i;
|
||||
FILE *acctf;
|
||||
|
||||
if ((acctf = fopen(sumfile, "w")) == NULL) {
|
||||
perror(sumfile);
|
||||
warn("%s", sumfile);
|
||||
errs++;
|
||||
return;
|
||||
}
|
||||
@ -307,12 +308,12 @@ rewrite()
|
||||
}
|
||||
fflush(acctf);
|
||||
if (ferror(acctf)) {
|
||||
perror(sumfile);
|
||||
warn("%s", sumfile);
|
||||
errs++;
|
||||
}
|
||||
fclose(acctf);
|
||||
if ((acctf = fopen(acctfile, "w")) == NULL)
|
||||
perror(acctfile);
|
||||
warn("%s", acctfile);
|
||||
else
|
||||
fclose(acctf);
|
||||
}
|
||||
@ -329,15 +330,19 @@ static struct hent *
|
||||
enter(name)
|
||||
char name[];
|
||||
{
|
||||
register struct hent *hp;
|
||||
register int h;
|
||||
struct hent *hp;
|
||||
int h;
|
||||
|
||||
if ((hp = lookup(name)) != NULL)
|
||||
return(hp);
|
||||
h = hash(name);
|
||||
hcount++;
|
||||
hp = (struct hent *) calloc(sizeof *hp, 1);
|
||||
if (hp == NULL)
|
||||
err(1, "calloc");
|
||||
hp->h_name = strdup(name);
|
||||
if (hp->h_name == NULL)
|
||||
err(1, "malloc");
|
||||
hp->h_feetpages = 0.0;
|
||||
hp->h_count = 0;
|
||||
hp->h_link = hashtab[h];
|
||||
@ -354,8 +359,8 @@ static struct hent *
|
||||
lookup(name)
|
||||
char name[];
|
||||
{
|
||||
register int h;
|
||||
register struct hent *hp;
|
||||
int h;
|
||||
struct hent *hp;
|
||||
|
||||
h = hash(name);
|
||||
for (hp = hashtab[h]; hp != NULL; hp = hp->h_link)
|
||||
@ -372,8 +377,8 @@ static int
|
||||
hash(name)
|
||||
char name[];
|
||||
{
|
||||
register int h;
|
||||
register char *cp;
|
||||
int h;
|
||||
char *cp;
|
||||
|
||||
for (cp = name, h = 0; *cp; h = (h << 2) + *cp++)
|
||||
;
|
||||
@ -388,8 +393,8 @@ any(ch, str)
|
||||
int ch;
|
||||
char str[];
|
||||
{
|
||||
register int c = ch;
|
||||
register char *cp = str;
|
||||
int c = ch;
|
||||
char *cp = str;
|
||||
|
||||
while (*cp)
|
||||
if (*cp++ == c)
|
||||
@ -406,8 +411,8 @@ static int
|
||||
qucmp(a, b)
|
||||
const void *a, *b;
|
||||
{
|
||||
register struct hent *h1, *h2;
|
||||
register int r;
|
||||
struct hent *h1, *h2;
|
||||
int r;
|
||||
|
||||
h1 = *(struct hent **)a;
|
||||
h2 = *(struct hent **)b;
|
||||
@ -424,7 +429,7 @@ qucmp(a, b)
|
||||
*/
|
||||
static int
|
||||
chkprinter(s)
|
||||
register char *s;
|
||||
char *s;
|
||||
{
|
||||
int stat;
|
||||
|
||||
@ -443,11 +448,17 @@ chkprinter(s)
|
||||
if (!pflag && (cgetnum(bp, "pc", &price100) == 0))
|
||||
price = price100/10000.0;
|
||||
sumfile = (char *) calloc(sizeof(char), strlen(acctfile)+5);
|
||||
if (sumfile == NULL) {
|
||||
perror("pac");
|
||||
exit(1);
|
||||
}
|
||||
if (sumfile == NULL)
|
||||
err(1, "pac");
|
||||
strcpy(sumfile, acctfile); /* XXX: strcpy is safe */
|
||||
strcat(sumfile, "_sum"); /* XXX: strcat is safe */
|
||||
return(1);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
fprintf(stderr,
|
||||
"usage: pac [-Pprinter] [-pprice] [-s] [-c] [-r] [-m] [user ...]\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user