clean up that import. no rcsids yet.
This commit is contained in:
parent
2f2adba37a
commit
f881d1d4fe
|
@ -1,5 +1,4 @@
|
|||
# from: @(#)Makefile 5.9 (Berkeley) 5/13/90
|
||||
# $Id: Makefile,v 1.2 1993/07/30 22:12:39 mycroft Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= lpf
|
||||
NOMAN= noman
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,14 +32,13 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)lpf.c 5.4 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: lpf.c,v 1.2 1993/08/01 17:59:17 mycroft Exp $";
|
||||
static char sccsid[] = "@(#)lpf.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -51,8 +50,10 @@ static char rcsid[] = "$Id: lpf.c,v 1.2 1993/08/01 17:59:17 mycroft Exp $";
|
|||
* to try to gain a little speed.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAXWIDTH 132
|
||||
#define MAXREP 10
|
||||
|
@ -69,6 +70,7 @@ char *name; /* user's login name */
|
|||
char *host; /* user's machine name */
|
||||
char *acctfile; /* accounting information file */
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
# from: @(#)Makefile 5.2 (Berkeley) 5/13/90
|
||||
# $Id: Makefile,v 1.2 1993/07/30 22:12:30 mycroft Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= lpc
|
||||
CFLAGS+=-I${.CURDIR}/../common_source
|
||||
MAN8= lpc.0
|
||||
SRCS= lpc.c cmds.c cmdtab.c startdaemon.c common.c printcap.c
|
||||
SRCS= lpc.c cmds.c cmdtab.c startdaemon.c common.c
|
||||
BINGRP= daemon
|
||||
BINMODE=2555
|
||||
.PATH: ${.CURDIR}/../common_source
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,22 +33,59 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)cmds.c 5.7 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: cmds.c,v 1.3 1993/12/08 00:50:06 jtc Exp $";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* lpc -- line printer control program -- commands:
|
||||
*/
|
||||
|
||||
#include "lp.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "lpc.h"
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
static void abortpr __P((int));
|
||||
static void cleanpr __P((void));
|
||||
static void disablepr __P((void));
|
||||
static int doarg __P((char *));
|
||||
static int doselect __P((struct dirent *));
|
||||
static void enablepr __P((void));
|
||||
static void prstat __P((void));
|
||||
static void putmsg __P((int, char **));
|
||||
static int sortq __P((const void *, const void *));
|
||||
static void startpr __P((int));
|
||||
static void stoppr __P((void));
|
||||
static int touch __P((struct queue *));
|
||||
static void unlinkf __P((char *));
|
||||
static void upstat __P((char *));
|
||||
|
||||
/*
|
||||
* kill an existing daemon and disable printing.
|
||||
*/
|
||||
abort(argc, argv)
|
||||
void
|
||||
doabort(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -60,9 +98,9 @@ abort(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -72,27 +110,29 @@ abort(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
abortpr(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
abortpr(dis)
|
||||
int dis;
|
||||
{
|
||||
register FILE *fp;
|
||||
struct stat stbuf;
|
||||
int pid, fd;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
printf("%s:\n", printer);
|
||||
|
@ -145,14 +185,14 @@ abortpr(dis)
|
|||
/*
|
||||
* Write a message into the status file.
|
||||
*/
|
||||
static void
|
||||
upstat(msg)
|
||||
char *msg;
|
||||
{
|
||||
register int fd;
|
||||
char statfile[BUFSIZ];
|
||||
|
||||
bp = pbuf;
|
||||
if ((ST = pgetstr("st", &bp)) == NULL)
|
||||
if (cgetstr(bp, "st", &ST) == -1)
|
||||
ST = DEFSTAT;
|
||||
(void) sprintf(statfile, "%s/%s", SD, ST);
|
||||
umask(0);
|
||||
|
@ -172,7 +212,9 @@ upstat(msg)
|
|||
/*
|
||||
* Remove all spool files and temporaries from the spooling area.
|
||||
*/
|
||||
void
|
||||
clean(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -185,9 +227,9 @@ clean(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -197,18 +239,21 @@ clean(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
cleanpr();
|
||||
}
|
||||
}
|
||||
|
||||
select(d)
|
||||
static int
|
||||
doselect(d)
|
||||
struct dirent *d;
|
||||
{
|
||||
int c = d->d_name[0];
|
||||
|
@ -222,11 +267,15 @@ struct dirent *d;
|
|||
* Comparison routine for scandir. Sort by job number and machine, then
|
||||
* by `cf', `tf', or `df', then by the sequence letter A-Z, a-z.
|
||||
*/
|
||||
sortq(d1, d2)
|
||||
struct dirent **d1, **d2;
|
||||
static int
|
||||
sortq(a, b)
|
||||
const void *a, *b;
|
||||
{
|
||||
struct dirent **d1, **d2;
|
||||
int c1, c2;
|
||||
|
||||
d1 = (struct dirent **)a;
|
||||
d2 = (struct dirent **)b;
|
||||
if (c1 = strcmp((*d1)->d_name + 3, (*d2)->d_name + 3))
|
||||
return(c1);
|
||||
c1 = (*d1)->d_name[0];
|
||||
|
@ -243,6 +292,7 @@ struct dirent **d1, **d2;
|
|||
/*
|
||||
* Remove incomplete jobs from spooling area.
|
||||
*/
|
||||
static void
|
||||
cleanpr()
|
||||
{
|
||||
register int i, n;
|
||||
|
@ -250,8 +300,7 @@ cleanpr()
|
|||
struct dirent **queue;
|
||||
int nitems;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
printf("%s:\n", printer);
|
||||
|
||||
|
@ -259,7 +308,7 @@ cleanpr()
|
|||
;
|
||||
lp[-1] = '/';
|
||||
|
||||
nitems = scandir(SD, &queue, select, sortq);
|
||||
nitems = scandir(SD, &queue, doselect, sortq);
|
||||
if (nitems < 0) {
|
||||
printf("\tcannot examine spool directory\n");
|
||||
return;
|
||||
|
@ -294,6 +343,7 @@ cleanpr()
|
|||
} while (++i < nitems);
|
||||
}
|
||||
|
||||
static void
|
||||
unlinkf(name)
|
||||
char *name;
|
||||
{
|
||||
|
@ -306,7 +356,9 @@ unlinkf(name)
|
|||
/*
|
||||
* Enable queuing to the printer (allow lpr's).
|
||||
*/
|
||||
void
|
||||
enable(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -319,9 +371,9 @@ enable(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -331,25 +383,27 @@ enable(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
enablepr();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
enablepr()
|
||||
{
|
||||
struct stat stbuf;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
printf("%s:\n", printer);
|
||||
|
@ -368,7 +422,9 @@ enablepr()
|
|||
/*
|
||||
* Disable queuing.
|
||||
*/
|
||||
void
|
||||
disable(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -381,9 +437,9 @@ disable(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -393,26 +449,28 @@ disable(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
disablepr();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disablepr()
|
||||
{
|
||||
register int fd;
|
||||
struct stat stbuf;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
printf("%s:\n", printer);
|
||||
|
@ -440,7 +498,9 @@ disablepr()
|
|||
* Disable queuing and printing and put a message into the status file
|
||||
* (reason for being down).
|
||||
*/
|
||||
void
|
||||
down(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -453,9 +513,9 @@ down(argc, argv)
|
|||
}
|
||||
if (!strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -464,17 +524,21 @@ down(argc, argv)
|
|||
return;
|
||||
}
|
||||
printer = argv[1];
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
return;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
return;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
putmsg(argc - 2, argv + 2);
|
||||
}
|
||||
|
||||
static void
|
||||
putmsg(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int fd;
|
||||
|
@ -482,12 +546,11 @@ putmsg(argc, argv)
|
|||
char buf[1024];
|
||||
struct stat stbuf;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
if ((ST = pgetstr("st", &bp)) == NULL)
|
||||
if (cgetstr(bp, "st", &ST) == -1)
|
||||
ST = DEFSTAT;
|
||||
printf("%s:\n", printer);
|
||||
/*
|
||||
|
@ -541,7 +604,9 @@ putmsg(argc, argv)
|
|||
/*
|
||||
* Exit lpc
|
||||
*/
|
||||
void
|
||||
quit(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
exit(0);
|
||||
|
@ -550,7 +615,9 @@ quit(argc, argv)
|
|||
/*
|
||||
* Kill and restart the daemon.
|
||||
*/
|
||||
void
|
||||
restart(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -563,9 +630,9 @@ restart(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -576,13 +643,15 @@ restart(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
abortpr(0);
|
||||
startpr(0);
|
||||
}
|
||||
|
@ -591,7 +660,9 @@ restart(argc, argv)
|
|||
/*
|
||||
* Enable printing on the specified printer and startup the daemon.
|
||||
*/
|
||||
start(argc, argv)
|
||||
void
|
||||
startcmd(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -604,9 +675,9 @@ start(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -616,25 +687,28 @@ start(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
startpr(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
startpr(enable)
|
||||
int enable;
|
||||
{
|
||||
struct stat stbuf;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
printf("%s:\n", printer);
|
||||
|
@ -657,7 +731,9 @@ startpr(enable)
|
|||
/*
|
||||
* Print the status of each queue listed or all the queues.
|
||||
*/
|
||||
void
|
||||
status(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -666,9 +742,9 @@ status(argc, argv)
|
|||
|
||||
if (argc == 1) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -678,13 +754,15 @@ status(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
prstat();
|
||||
}
|
||||
}
|
||||
|
@ -692,6 +770,7 @@ status(argc, argv)
|
|||
/*
|
||||
* Print the status of the printer queue.
|
||||
*/
|
||||
static void
|
||||
prstat()
|
||||
{
|
||||
struct stat stbuf;
|
||||
|
@ -699,12 +778,11 @@ prstat()
|
|||
register struct dirent *dp;
|
||||
DIR *dirp;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
if ((ST = pgetstr("st", &bp)) == NULL)
|
||||
if (cgetstr(bp, "st", &ST) == -1)
|
||||
ST = DEFSTAT;
|
||||
printf("%s:\n", printer);
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
|
@ -755,7 +833,9 @@ prstat()
|
|||
* Stop the specified daemon after completing the current job and disable
|
||||
* printing.
|
||||
*/
|
||||
void
|
||||
stop(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -768,9 +848,9 @@ stop(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -780,26 +860,28 @@ stop(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
stoppr();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
stoppr()
|
||||
{
|
||||
register int fd;
|
||||
struct stat stbuf;
|
||||
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
(void) sprintf(line, "%s/%s", SD, LO);
|
||||
printf("%s:\n", printer);
|
||||
|
@ -833,12 +915,13 @@ time_t mtime;
|
|||
/*
|
||||
* Put the specified jobs at the top of printer queue.
|
||||
*/
|
||||
void
|
||||
topq(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int n, i;
|
||||
register int i;
|
||||
struct stat stbuf;
|
||||
register char *cfname;
|
||||
int status, changed;
|
||||
|
||||
if (argc < 3) {
|
||||
|
@ -848,18 +931,19 @@ topq(argc, argv)
|
|||
|
||||
--argc;
|
||||
printer = *++argv;
|
||||
status = pgetent(line, printer);
|
||||
if (status < 0) {
|
||||
status = cgetent(&bp, printcapdb, printer);
|
||||
if (status == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
return;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("%s: unknown printer\n", printer);
|
||||
return;
|
||||
}
|
||||
bp = pbuf;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
printf("%s:\n", printer);
|
||||
|
||||
|
@ -898,6 +982,7 @@ topq(argc, argv)
|
|||
* Reposition the job by changing the modification time of
|
||||
* the control file.
|
||||
*/
|
||||
static int
|
||||
touch(q)
|
||||
struct queue *q;
|
||||
{
|
||||
|
@ -912,6 +997,7 @@ touch(q)
|
|||
* Checks if specified job name is in the printer's queue.
|
||||
* Returns: negative (-1) if argument name is not in the queue.
|
||||
*/
|
||||
static int
|
||||
doarg(job)
|
||||
char *job;
|
||||
{
|
||||
|
@ -980,7 +1066,9 @@ doarg(job)
|
|||
/*
|
||||
* Enable everything and start printer (undo `down').
|
||||
*/
|
||||
void
|
||||
up(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register int c, status;
|
||||
|
@ -993,9 +1081,9 @@ up(argc, argv)
|
|||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "all")) {
|
||||
printer = prbuf;
|
||||
while (getprent(line) > 0) {
|
||||
while (cgetnext(&bp, printcapdb) > 0) {
|
||||
cp1 = prbuf;
|
||||
cp2 = line;
|
||||
cp2 = bp;
|
||||
while ((c = *cp2++) && c != '|' && c != ':')
|
||||
*cp1++ = c;
|
||||
*cp1 = '\0';
|
||||
|
@ -1005,13 +1093,15 @@ up(argc, argv)
|
|||
}
|
||||
while (--argc) {
|
||||
printer = *++argv;
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
printf("cannot open printer description file\n");
|
||||
continue;
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
printf("unknown printer %s\n", printer);
|
||||
continue;
|
||||
}
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
startpr(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,19 +32,17 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)cmdtab.c 5.4 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: cmdtab.c,v 1.2 1993/08/01 17:58:58 mycroft Exp $";
|
||||
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include "lpc.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* lpc -- command tables
|
||||
*/
|
||||
|
||||
#include "lpc.h"
|
||||
|
||||
int abort(), clean(), enable(), disable(), down(), help();
|
||||
int quit(), restart(), start(), status(), stop(), topq(), up();
|
||||
|
||||
char aborthelp[] = "terminate a spooling daemon immediately and disable printing";
|
||||
char cleanhelp[] = "remove cruft files from a queue";
|
||||
char enablehelp[] = "turn a spooling queue on";
|
||||
|
@ -60,7 +58,7 @@ char topqhelp[] = "put job at top of printer queue";
|
|||
char uphelp[] = "enable everything and restart spooling daemon";
|
||||
|
||||
struct cmd cmdtab[] = {
|
||||
{ "abort", aborthelp, abort, 1 },
|
||||
{ "abort", aborthelp, doabort, 1 },
|
||||
{ "clean", cleanhelp, clean, 1 },
|
||||
{ "enable", enablehelp, enable, 1 },
|
||||
{ "exit", quithelp, quit, 0 },
|
||||
|
@ -69,7 +67,7 @@ struct cmd cmdtab[] = {
|
|||
{ "help", helphelp, help, 0 },
|
||||
{ "quit", quithelp, quit, 0 },
|
||||
{ "restart", restarthelp, restart, 0 },
|
||||
{ "start", starthelp, start, 1 },
|
||||
{ "start", starthelp, startcmd, 1 },
|
||||
{ "status", statushelp, status, 0 },
|
||||
{ "stop", stophelp, stop, 1 },
|
||||
{ "topq", topqhelp, topq, 1 },
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
|
@ -29,10 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)lpc.8 6.4 (Berkeley) 3/16/91
|
||||
.\" $Id: lpc.8,v 1.3 1994/01/14 16:22:48 jtc Exp $
|
||||
.\" @(#)lpc.8 8.3 (Berkeley) 4/19/94
|
||||
.\"
|
||||
.Dd March 16, 1991
|
||||
.Dd April 19, 1994
|
||||
.Dt LPC 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
|
@ -81,7 +80,7 @@ the following is the list of recognized commands.
|
|||
.It Ic \&? No [ command ... ]
|
||||
.It Ic help No [ command ... ]
|
||||
Print a short description of each command specified in the argument list,
|
||||
or, if no arguments are given, a list of the recognized commands.
|
||||
or, if no argument is given, a list of the recognized commands.
|
||||
.Pp
|
||||
.It Ic abort No {\ all\ |\ printer\ }
|
||||
Terminate an active spooling daemon on the local host immediately and
|
||||
|
@ -122,7 +121,7 @@ Exit from lpc.
|
|||
.It Ic restart No {\ all\ |\ printer\ }
|
||||
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.
|
||||
die unexpectedly, leaving jobs in the queue.
|
||||
.Xr Lpq
|
||||
will report that there is no daemon present when this condition occurs.
|
||||
If the user is the super-user,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,26 +33,33 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)lpc.c 5.11 (Berkeley) 3/2/91";*/
|
||||
static char rcsid[] = "$Id: lpc.c,v 1.2 1993/08/01 17:58:57 mycroft Exp $";
|
||||
static char sccsid[] = "@(#)lpc.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "lp.h"
|
||||
#include "lpc.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* lpc -- line printer control program
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <setjmp.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "lpc.h"
|
||||
|
||||
int fromatty;
|
||||
|
||||
|
@ -59,16 +67,20 @@ char cmdline[200];
|
|||
int margc;
|
||||
char *margv[20];
|
||||
int top;
|
||||
void intr();
|
||||
struct cmd *getcmd();
|
||||
|
||||
jmp_buf toplevel;
|
||||
|
||||
static void cmdscanner __P((int));
|
||||
static struct cmd *getcmd __P((char *));
|
||||
static void intr __P((int));
|
||||
static void makeargv __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register struct cmd *c;
|
||||
extern char *name;
|
||||
|
||||
name = argv[0];
|
||||
openlog("lpd", 0, LOG_LPR);
|
||||
|
@ -100,8 +112,9 @@ main(argc, argv)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
intr()
|
||||
static void
|
||||
intr(signo)
|
||||
int signo;
|
||||
{
|
||||
if (!fromatty)
|
||||
exit(0);
|
||||
|
@ -111,6 +124,7 @@ intr()
|
|||
/*
|
||||
* Command parser.
|
||||
*/
|
||||
static void
|
||||
cmdscanner(top)
|
||||
int top;
|
||||
{
|
||||
|
@ -124,7 +138,7 @@ cmdscanner(top)
|
|||
fflush(stdout);
|
||||
}
|
||||
if (fgets(cmdline, sizeof(cmdline), stdin) == 0)
|
||||
quit();
|
||||
quit(0, NULL);
|
||||
if (cmdline[0] == 0 || cmdline[0] == '\n')
|
||||
break;
|
||||
makeargv();
|
||||
|
@ -146,8 +160,6 @@ cmdscanner(top)
|
|||
longjmp(toplevel, 0);
|
||||
}
|
||||
|
||||
extern struct cmd cmdtab[];
|
||||
|
||||
struct cmd *
|
||||
getcmd(name)
|
||||
register char *name;
|
||||
|
@ -180,6 +192,7 @@ getcmd(name)
|
|||
/*
|
||||
* Slice a string up into argc/argv.
|
||||
*/
|
||||
static void
|
||||
makeargv()
|
||||
{
|
||||
register char *cp;
|
||||
|
@ -207,6 +220,7 @@ makeargv()
|
|||
/*
|
||||
* Help command.
|
||||
*/
|
||||
void
|
||||
help(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
# from: @(#)Makefile 5.4 (Berkeley) 10/26/90
|
||||
# $Id: Makefile,v 1.4 1994/01/28 00:52:35 cgd Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= lpd
|
||||
CFLAGS+=-I${.CURDIR}/../common_source
|
||||
MAN8= lpd.0
|
||||
SRCS= lpd.c printjob.c recvjob.c displayq.c rmjob.c startdaemon.c \
|
||||
lpdchar.c common.c printcap.c
|
||||
lpdchar.c common.c
|
||||
.PATH: ${.CURDIR}/../common_source
|
||||
|
||||
.include "../../Makefile.inc"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
|
@ -29,10 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)lpd.8 6.6 (Berkeley) 3/16/91
|
||||
.\" $Id: lpd.8,v 1.3 1994/01/14 16:22:53 jtc Exp $
|
||||
.\" @(#)lpd.8 8.3 (Berkeley) 4/19/94
|
||||
.\"
|
||||
.Dd March 16, 1991
|
||||
.Dd April 19, 1994
|
||||
.Dt LPD 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
|
@ -152,7 +151,7 @@ output.
|
|||
DVI File. The file contains
|
||||
.Tn Tex l
|
||||
output
|
||||
DVI format from Standford).
|
||||
DVI format from Standford.
|
||||
.It g
|
||||
Graph File. The file contains data produced by
|
||||
.Xr plot 3 .
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,14 +33,13 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)lpd.c 5.12 (Berkeley) 3/7/91";*/
|
||||
static char rcsid[] = "$Id: lpd.c,v 1.3 1993/11/10 04:36:34 cgd Exp $";
|
||||
static char sccsid[] = "@(#)lpd.c 8.4 (Berkeley) 4/17/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -71,23 +71,51 @@ static char rcsid[] = "$Id: lpd.c,v 1.3 1993/11/10 04:36:34 cgd Exp $";
|
|||
* w/o help of lpq and lprm programs.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
#include "extern.h"
|
||||
|
||||
int lflag; /* log requests flag */
|
||||
int from_remote; /* from remote socket */
|
||||
|
||||
void mcleanup(), reapchild();
|
||||
static void reapchild __P((int));
|
||||
static void mcleanup __P((int));
|
||||
static void doit __P((void));
|
||||
static void startup __P((void));
|
||||
static void chkhost __P((struct sockaddr_in *));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int f, funix, finet, options = 0, defreadfds, fromlen;
|
||||
struct sockaddr_un sun, fromunix;
|
||||
int f, funix, finet, options, fromlen;
|
||||
fd_set defreadfds;
|
||||
struct sockaddr_un un, fromunix;
|
||||
struct sockaddr_in sin, frominet;
|
||||
int omask, lfd;
|
||||
|
||||
options = 0;
|
||||
gethostname(host, sizeof(host));
|
||||
name = argv[0];
|
||||
|
||||
|
@ -112,6 +140,7 @@ main(argc, argv)
|
|||
#endif
|
||||
|
||||
openlog("lpd", LOG_PID, LOG_LPR);
|
||||
syslog(LOG_INFO, "restarted");
|
||||
(void) umask(0);
|
||||
lfd = open(_PATH_MASTERLOCK, O_WRONLY|O_CREAT, 0644);
|
||||
if (lfd < 0) {
|
||||
|
@ -151,16 +180,19 @@ main(argc, argv)
|
|||
signal(SIGINT, mcleanup);
|
||||
signal(SIGQUIT, mcleanup);
|
||||
signal(SIGTERM, mcleanup);
|
||||
bzero(&sun, sizeof(sun));
|
||||
sun.sun_family = AF_UNIX;
|
||||
strcpy(sun.sun_path, _PATH_SOCKETNAME);
|
||||
if (bind(funix,
|
||||
(struct sockaddr *)&sun, strlen(sun.sun_path) + 2) < 0) {
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
strcpy(un.sun_path, _PATH_SOCKETNAME);
|
||||
#ifndef SUN_LEN
|
||||
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
|
||||
#endif
|
||||
if (bind(funix, (struct sockaddr *)&un, SUN_LEN(&un)) < 0) {
|
||||
syslog(LOG_ERR, "ubind: %m");
|
||||
exit(1);
|
||||
}
|
||||
sigsetmask(omask);
|
||||
defreadfds = 1 << funix;
|
||||
FD_ZERO(&defreadfds);
|
||||
FD_SET(funix, &defreadfds);
|
||||
listen(funix, 5);
|
||||
finet = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (finet >= 0) {
|
||||
|
@ -169,40 +201,44 @@ main(argc, argv)
|
|||
if (options & SO_DEBUG)
|
||||
if (setsockopt(finet, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) {
|
||||
syslog(LOG_ERR, "setsockopt (SO_DEBUG): %m");
|
||||
mcleanup();
|
||||
mcleanup(0);
|
||||
}
|
||||
sp = getservbyname("printer", "tcp");
|
||||
if (sp == NULL) {
|
||||
syslog(LOG_ERR, "printer/tcp: unknown service");
|
||||
mcleanup();
|
||||
mcleanup(0);
|
||||
}
|
||||
bzero(&sin, sizeof(sin));
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = sp->s_port;
|
||||
if (bind(finet, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
|
||||
syslog(LOG_ERR, "bind: %m");
|
||||
mcleanup();
|
||||
mcleanup(0);
|
||||
}
|
||||
defreadfds |= 1 << finet;
|
||||
FD_SET(finet, &defreadfds);
|
||||
listen(finet, 5);
|
||||
}
|
||||
/*
|
||||
* Main loop: accept, do a request, continue.
|
||||
*/
|
||||
memset(&frominet, 0, sizeof(frominet));
|
||||
memset(&fromunix, 0, sizeof(fromunix));
|
||||
for (;;) {
|
||||
int domain, nfds, s, readfds = defreadfds;
|
||||
int domain, nfds, s;
|
||||
fd_set readfds;
|
||||
|
||||
FD_COPY(&defreadfds, &readfds);
|
||||
nfds = select(20, &readfds, 0, 0, 0);
|
||||
if (nfds <= 0) {
|
||||
if (nfds < 0 && errno != EINTR)
|
||||
syslog(LOG_WARNING, "select: %m");
|
||||
continue;
|
||||
}
|
||||
if (readfds & (1 << funix)) {
|
||||
if (FD_ISSET(funix, &readfds)) {
|
||||
domain = AF_UNIX, fromlen = sizeof(fromunix);
|
||||
s = accept(funix,
|
||||
(struct sockaddr *)&fromunix, &fromlen);
|
||||
} else if (readfds & (1 << finet)) {
|
||||
} else /* if (FD_ISSET(finet, &readfds)) */ {
|
||||
domain = AF_INET, fromlen = sizeof(frominet);
|
||||
s = accept(finet,
|
||||
(struct sockaddr *)&frominet, &fromlen);
|
||||
|
@ -234,8 +270,9 @@ main(argc, argv)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
reapchild()
|
||||
static void
|
||||
reapchild(signo)
|
||||
int signo;
|
||||
{
|
||||
union wait status;
|
||||
|
||||
|
@ -243,8 +280,9 @@ reapchild()
|
|||
;
|
||||
}
|
||||
|
||||
void
|
||||
mcleanup()
|
||||
static void
|
||||
mcleanup(signo)
|
||||
int signo;
|
||||
{
|
||||
if (lflag)
|
||||
syslog(LOG_INFO, "exiting");
|
||||
|
@ -261,7 +299,7 @@ int requ[MAXREQUESTS]; /* job number of spool entries */
|
|||
int requests; /* # of spool requests */
|
||||
char *person; /* name of person doing lprm */
|
||||
|
||||
char fromb[32]; /* buffer for client's machine name */
|
||||
char fromb[MAXHOSTNAMELEN]; /* buffer for client's machine name */
|
||||
char cbuf[BUFSIZ]; /* command line buffer */
|
||||
char *cmdnames[] = {
|
||||
"null",
|
||||
|
@ -272,6 +310,7 @@ char *cmdnames[] = {
|
|||
"rmjob"
|
||||
};
|
||||
|
||||
static void
|
||||
doit()
|
||||
{
|
||||
register char *cp;
|
||||
|
@ -379,18 +418,17 @@ doit()
|
|||
* Make a pass through the printcap database and start printing any
|
||||
* files left from the last time the machine went down.
|
||||
*/
|
||||
static void
|
||||
startup()
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
char *buf;
|
||||
register char *cp;
|
||||
int pid;
|
||||
|
||||
printer = buf;
|
||||
|
||||
/*
|
||||
* Restart the daemons.
|
||||
*/
|
||||
while (getprent(buf) > 0) {
|
||||
while (cgetnext(&buf, printcapdb) > 0) {
|
||||
for (cp = buf; *cp; cp++)
|
||||
if (*cp == '|' || *cp == ':') {
|
||||
*cp = '\0';
|
||||
|
@ -398,10 +436,11 @@ startup()
|
|||
}
|
||||
if ((pid = fork()) < 0) {
|
||||
syslog(LOG_WARNING, "startup: cannot fork");
|
||||
mcleanup();
|
||||
mcleanup(0);
|
||||
}
|
||||
if (!pid) {
|
||||
endprent();
|
||||
printer = buf;
|
||||
cgetclose();
|
||||
printjob();
|
||||
}
|
||||
}
|
||||
|
@ -412,47 +451,35 @@ startup()
|
|||
/*
|
||||
* Check to see if the from host has access to the line printer.
|
||||
*/
|
||||
static void
|
||||
chkhost(f)
|
||||
struct sockaddr_in *f;
|
||||
{
|
||||
register struct hostent *hp;
|
||||
register FILE *hostf;
|
||||
register char *cp, *sp;
|
||||
char ahost[50];
|
||||
int first = 1;
|
||||
extern char *inet_ntoa();
|
||||
int baselen = -1;
|
||||
|
||||
f->sin_port = ntohs(f->sin_port);
|
||||
if (f->sin_family != AF_INET || f->sin_port >= IPPORT_RESERVED)
|
||||
fatal("Malformed from address");
|
||||
|
||||
/* Need real hostname for temporary filenames */
|
||||
hp = gethostbyaddr((char *)&f->sin_addr,
|
||||
sizeof(struct in_addr), f->sin_family);
|
||||
if (hp == 0)
|
||||
if (hp == NULL)
|
||||
fatal("Host name for your address (%s) unknown",
|
||||
inet_ntoa(f->sin_addr));
|
||||
|
||||
strcpy(fromb, hp->h_name);
|
||||
(void) strncpy(fromb, hp->h_name, sizeof(fromb));
|
||||
from[sizeof(fromb) - 1] = '\0';
|
||||
from = fromb;
|
||||
if (!strcmp(from, host))
|
||||
return;
|
||||
|
||||
sp = fromb;
|
||||
cp = ahost;
|
||||
while (*sp) {
|
||||
if (*sp == '.') {
|
||||
if (baselen == -1)
|
||||
baselen = sp - fromb;
|
||||
*cp++ = *sp++;
|
||||
} else {
|
||||
*cp++ = isupper(*sp) ? tolower(*sp++) : *sp++;
|
||||
}
|
||||
}
|
||||
*cp = '\0';
|
||||
hostf = fopen(_PATH_HOSTSEQUIV, "r");
|
||||
again:
|
||||
if (hostf) {
|
||||
if (!_validuser(hostf, ahost, DUMMY, DUMMY, baselen)) {
|
||||
if (__ivaliduser(hostf, f->sin_addr.s_addr,
|
||||
DUMMY, DUMMY) == 0) {
|
||||
(void) fclose(hostf);
|
||||
return;
|
||||
}
|
||||
|
@ -464,4 +491,17 @@ again:
|
|||
goto again;
|
||||
}
|
||||
fatal("Your host does not have line printer access");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,8 +32,7 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)lpdchar.c 5.4 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: lpdchar.c,v 1.2 1993/08/01 17:58:53 mycroft Exp $";
|
||||
static char sccsid[] = "@(#)lpdchar.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,10 +33,16 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)printjob.c 5.13 (Berkeley) 3/2/91";*/
|
||||
static char rcsid[] = "$Id: printjob.c,v 1.4 1994/03/27 09:14:53 cgd Exp $";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94";
|
||||
#endif /* not lint */
|
||||
|
||||
|
||||
/*
|
||||
* printjob -- print jobs in the queue.
|
||||
*
|
||||
|
@ -43,8 +50,26 @@ static char rcsid[] = "$Id: printjob.c,v 1.4 1994/03/27 09:14:53 cgd Exp $";
|
|||
* it does not need to be removed because file locks are dynamic.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sgtty.h>
|
||||
#include <syslog.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
#include "extern.h"
|
||||
|
||||
#define DORETURN 0 /* absorb fork error */
|
||||
#define DOABORT 1 /* abort if dofork fails */
|
||||
|
@ -60,31 +85,50 @@ static char rcsid[] = "$Id: printjob.c,v 1.4 1994/03/27 09:14:53 cgd Exp $";
|
|||
#define FILTERERR 3
|
||||
#define ACCESS 4
|
||||
|
||||
char title[80]; /* ``pr'' title */
|
||||
FILE *cfp; /* control file */
|
||||
int pfd; /* printer file descriptor */
|
||||
int ofd; /* output filter file descriptor */
|
||||
int lfd; /* lock file descriptor */
|
||||
int pid; /* pid of lpd process */
|
||||
int prchild; /* id of pr process */
|
||||
int child; /* id of any filters */
|
||||
int ofilter; /* id of output filter, if any */
|
||||
int tof; /* true if at top of form */
|
||||
int remote; /* true if sending files to remote */
|
||||
dev_t fdev; /* device of file pointed to by symlink */
|
||||
ino_t fino; /* inode of file pointed to by symlink */
|
||||
static dev_t fdev; /* device of file pointed to by symlink */
|
||||
static ino_t fino; /* inode of file pointed to by symlink */
|
||||
static FILE *cfp; /* control file */
|
||||
static int child; /* id of any filters */
|
||||
static int lfd; /* lock file descriptor */
|
||||
static int ofd; /* output filter file descriptor */
|
||||
static int ofilter; /* id of output filter, if any */
|
||||
static int pfd; /* prstatic inter file descriptor */
|
||||
static int pid; /* pid of lpd process */
|
||||
static int prchild; /* id of pr process */
|
||||
static int remote; /* true if sending files to remote */
|
||||
static char title[80]; /* ``pr'' title */
|
||||
static int tof; /* true if at top of form */
|
||||
|
||||
char fromhost[32]; /* user's host machine */
|
||||
char logname[32]; /* user's login name */
|
||||
char jobname[100]; /* job or file name */
|
||||
char class[32]; /* classification field */
|
||||
char width[10] = "-w"; /* page width in characters */
|
||||
char length[10] = "-l"; /* page length in lines */
|
||||
char pxwidth[10] = "-x"; /* page width in pixels */
|
||||
char pxlength[10] = "-y"; /* page length in pixels */
|
||||
char indent[10] = "-i0"; /* indentation size in characters */
|
||||
char tempfile[] = "errsXXXXXX"; /* file name for filter output */
|
||||
static char class[32]; /* classification field */
|
||||
static char fromhost[32]; /* user's host machine */
|
||||
/* indentation size in static characters */
|
||||
static char indent[10] = "-i0";
|
||||
static char jobname[100]; /* job or file name */
|
||||
static char length[10] = "-l"; /* page length in lines */
|
||||
static char logname[32]; /* user's login name */
|
||||
static char pxlength[10] = "-y"; /* page length in pixels */
|
||||
static char pxwidth[10] = "-x"; /* page width in pixels */
|
||||
static char tempfile[] = "errsXXXXXX"; /* file name for filter output */
|
||||
static char width[10] = "-w"; /* page width in static characters */
|
||||
|
||||
static void abortpr __P((int));
|
||||
static void banner __P((char *, char *));
|
||||
static int dofork __P((int));
|
||||
static int dropit __P((int));
|
||||
static void init __P((void));
|
||||
static void openpr __P((void));
|
||||
static int print __P((int, char *));
|
||||
static int printit __P((char *));
|
||||
static void pstatus __P((const char *, ...));
|
||||
static char response __P((void));
|
||||
static void scan_out __P((int, char *, int));
|
||||
static char *scnline __P((int, char *, int));
|
||||
static int sendfile __P((int, char *));
|
||||
static int sendit __P((char *));
|
||||
static void sendmail __P((char *, int));
|
||||
static void setty __P((void));
|
||||
|
||||
void
|
||||
printjob()
|
||||
{
|
||||
struct stat stb;
|
||||
|
@ -93,7 +137,6 @@ printjob()
|
|||
register int i, nitems;
|
||||
long pidoff;
|
||||
int count = 0;
|
||||
void abortpr();
|
||||
|
||||
init(); /* set up capabilities */
|
||||
(void) write(1, "", 1); /* ack that daemon is started */
|
||||
|
@ -167,7 +210,7 @@ again:
|
|||
if (stat(q->q_name, &stb) < 0)
|
||||
continue;
|
||||
restart:
|
||||
(void) lseek(lfd, pidoff, 0);
|
||||
(void) lseek(lfd, (off_t)pidoff, 0);
|
||||
(void) sprintf(line, "%s\n", q->q_name);
|
||||
i = strlen(line);
|
||||
if (write(lfd, line, i) != i)
|
||||
|
@ -247,6 +290,7 @@ char ifonts[4][40] = {
|
|||
* The remaining part is the reading of the control file (cf)
|
||||
* and performing the various actions.
|
||||
*/
|
||||
static int
|
||||
printit(file)
|
||||
char *file;
|
||||
{
|
||||
|
@ -318,7 +362,7 @@ printit(file)
|
|||
case 'P':
|
||||
strncpy(logname, line+1, sizeof(logname)-1);
|
||||
if (RS) { /* restricted */
|
||||
if (getpwnam(logname) == (struct passwd *)0) {
|
||||
if (getpwnam(logname) == NULL) {
|
||||
bombed = NOACCT;
|
||||
sendmail(line+1, bombed);
|
||||
goto pass2;
|
||||
|
@ -438,6 +482,7 @@ pass2:
|
|||
* Note: all filters take stdin as the file, stdout as the printer,
|
||||
* stderr as the log file, and must not ignore SIGINT.
|
||||
*/
|
||||
static int
|
||||
print(format, file)
|
||||
int format;
|
||||
char *file;
|
||||
|
@ -538,7 +583,8 @@ print(format, file)
|
|||
} else {
|
||||
for (n = 0; n < 4; n++) {
|
||||
if (fonts[n][0] != '/')
|
||||
(void) write(fo, _PATH_VFONT, 15);
|
||||
(void) write(fo, _PATH_VFONT,
|
||||
sizeof(_PATH_VFONT) - 1);
|
||||
(void) write(fo, fonts[n], strlen(fonts[n]));
|
||||
(void) write(fo, "\n", 1);
|
||||
}
|
||||
|
@ -628,11 +674,9 @@ start:
|
|||
|
||||
/* Copy filter output to "lf" logfile */
|
||||
if (fp = fopen(tempfile, "r")) {
|
||||
char tbuf[512];
|
||||
|
||||
while (fgets(buf, sizeof(buf), fp))
|
||||
fputs(buf, stderr);
|
||||
close(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
if (!WIFEXITED(status)) {
|
||||
|
@ -659,6 +703,7 @@ start:
|
|||
* Return -1 if a non-recoverable error occured, 1 if a recoverable error and
|
||||
* 0 if all is well.
|
||||
*/
|
||||
static int
|
||||
sendit(file)
|
||||
char *file;
|
||||
{
|
||||
|
@ -744,8 +789,10 @@ sendit(file)
|
|||
* Send a data file to the remote machine and spool it.
|
||||
* Return positive if we should try resending.
|
||||
*/
|
||||
static int
|
||||
sendfile(type, file)
|
||||
char type, *file;
|
||||
int type;
|
||||
char *file;
|
||||
{
|
||||
register int f, i, amt;
|
||||
struct stat stb;
|
||||
|
@ -772,14 +819,14 @@ sendfile(type, file)
|
|||
} else if (resp == '\0')
|
||||
break;
|
||||
if (i == 0)
|
||||
status("no space on remote; waiting for queue to drain");
|
||||
pstatus("no space on remote; waiting for queue to drain");
|
||||
if (i == 10)
|
||||
syslog(LOG_ALERT, "%s: can't send to %s; queue full",
|
||||
printer, RM);
|
||||
sleep(5 * 60);
|
||||
}
|
||||
if (i)
|
||||
status("sending to %s", RM);
|
||||
pstatus("sending to %s", RM);
|
||||
sizerr = 0;
|
||||
for (i = 0; i < stb.st_size; i += BUFSIZ) {
|
||||
amt = BUFSIZ;
|
||||
|
@ -792,6 +839,10 @@ sendfile(type, file)
|
|||
return(REPRINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
(void) close(f);
|
||||
if (sizerr) {
|
||||
syslog(LOG_INFO, "%s: %s: changed size", printer, file);
|
||||
|
@ -809,6 +860,7 @@ sendfile(type, file)
|
|||
* are in sync with eachother.
|
||||
* Return non-zero if the connection was lost.
|
||||
*/
|
||||
static char
|
||||
response()
|
||||
{
|
||||
char resp;
|
||||
|
@ -823,6 +875,7 @@ response()
|
|||
/*
|
||||
* Banner printing stuff
|
||||
*/
|
||||
static void
|
||||
banner(name1, name2)
|
||||
char *name1, *name2;
|
||||
{
|
||||
|
@ -863,10 +916,11 @@ banner(name1, name2)
|
|||
tof = 1;
|
||||
}
|
||||
|
||||
char *
|
||||
static char *
|
||||
scnline(key, p, c)
|
||||
register char key, *p;
|
||||
char c;
|
||||
register int key;
|
||||
register char *p;
|
||||
int c;
|
||||
{
|
||||
register scnwidth;
|
||||
|
||||
|
@ -879,9 +933,10 @@ scnline(key, p, c)
|
|||
|
||||
#define TRC(q) (((q)-' ')&0177)
|
||||
|
||||
static void
|
||||
scan_out(scfd, scsp, dlm)
|
||||
int scfd;
|
||||
char *scsp, dlm;
|
||||
int scfd, dlm;
|
||||
char *scsp;
|
||||
{
|
||||
register char *strp;
|
||||
register nchrs, j;
|
||||
|
@ -912,8 +967,9 @@ scan_out(scfd, scsp, dlm)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
dropit(c)
|
||||
char c;
|
||||
int c;
|
||||
{
|
||||
switch(c) {
|
||||
|
||||
|
@ -936,6 +992,7 @@ dropit(c)
|
|||
* sendmail ---
|
||||
* tell people about job completion
|
||||
*/
|
||||
static void
|
||||
sendmail(user, bombed)
|
||||
char *user;
|
||||
int bombed;
|
||||
|
@ -1002,6 +1059,7 @@ sendmail(user, bombed)
|
|||
/*
|
||||
* dofork - fork with retries on failure
|
||||
*/
|
||||
static int
|
||||
dofork(action)
|
||||
int action;
|
||||
{
|
||||
|
@ -1036,8 +1094,9 @@ dofork(action)
|
|||
/*
|
||||
* Kill child processes to abort current job.
|
||||
*/
|
||||
void
|
||||
abortpr()
|
||||
static void
|
||||
abortpr(signo)
|
||||
int signo;
|
||||
{
|
||||
(void) unlink(tempfile);
|
||||
kill(0, SIGINT);
|
||||
|
@ -1048,82 +1107,89 @@ abortpr()
|
|||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
init()
|
||||
{
|
||||
int status;
|
||||
char *s;
|
||||
|
||||
if ((status = pgetent(line, printer)) < 0) {
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2) {
|
||||
syslog(LOG_ERR, "can't open printer description file");
|
||||
exit(1);
|
||||
} else if (status == 0) {
|
||||
} else if (status == -1) {
|
||||
syslog(LOG_ERR, "unknown printer: %s", printer);
|
||||
exit(1);
|
||||
}
|
||||
if ((LP = pgetstr("lp", &bp)) == NULL)
|
||||
} else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
if (cgetstr(bp, "lp", &LP) == -1)
|
||||
LP = _PATH_DEFDEVLP;
|
||||
if ((RP = pgetstr("rp", &bp)) == NULL)
|
||||
if (cgetstr(bp, "rp", &RP) == -1)
|
||||
RP = DEFLP;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
if ((ST = pgetstr("st", &bp)) == NULL)
|
||||
if (cgetstr(bp, "st", &ST) == -1)
|
||||
ST = DEFSTAT;
|
||||
if ((LF = pgetstr("lf", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lf", &LF) == -1)
|
||||
LF = _PATH_CONSOLE;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((DU = pgetnum("du")) < 0)
|
||||
if (cgetnum(bp, "du", &DU) < 0)
|
||||
DU = DEFUID;
|
||||
if ((FF = pgetstr("ff", &bp)) == NULL)
|
||||
if (cgetstr(bp,"ff", &FF) == -1)
|
||||
FF = DEFFF;
|
||||
if ((PW = pgetnum("pw")) < 0)
|
||||
if (cgetnum(bp, "pw", &PW) < 0)
|
||||
PW = DEFWIDTH;
|
||||
sprintf(&width[2], "%d", PW);
|
||||
if ((PL = pgetnum("pl")) < 0)
|
||||
if (cgetnum(bp, "pl", &PL) < 0)
|
||||
PL = DEFLENGTH;
|
||||
sprintf(&length[2], "%d", PL);
|
||||
if ((PX = pgetnum("px")) < 0)
|
||||
if (cgetnum(bp,"px", &PX) < 0)
|
||||
PX = 0;
|
||||
sprintf(&pxwidth[2], "%d", PX);
|
||||
if ((PY = pgetnum("py")) < 0)
|
||||
if (cgetnum(bp, "py", &PY) < 0)
|
||||
PY = 0;
|
||||
sprintf(&pxlength[2], "%d", PY);
|
||||
RM = pgetstr("rm", &bp);
|
||||
cgetstr(bp, "rm", &RM);
|
||||
if (s = checkremote())
|
||||
syslog(LOG_WARNING, s);
|
||||
|
||||
AF = pgetstr("af", &bp);
|
||||
OF = pgetstr("of", &bp);
|
||||
IF = pgetstr("if", &bp);
|
||||
RF = pgetstr("rf", &bp);
|
||||
TF = pgetstr("tf", &bp);
|
||||
NF = pgetstr("nf", &bp);
|
||||
DF = pgetstr("df", &bp);
|
||||
GF = pgetstr("gf", &bp);
|
||||
VF = pgetstr("vf", &bp);
|
||||
CF = pgetstr("cf", &bp);
|
||||
TR = pgetstr("tr", &bp);
|
||||
RS = pgetflag("rs");
|
||||
SF = pgetflag("sf");
|
||||
SH = pgetflag("sh");
|
||||
SB = pgetflag("sb");
|
||||
HL = pgetflag("hl");
|
||||
RW = pgetflag("rw");
|
||||
BR = pgetnum("br");
|
||||
if ((FC = pgetnum("fc")) < 0)
|
||||
cgetstr(bp, "af", &AF);
|
||||
cgetstr(bp, "of", &OF);
|
||||
cgetstr(bp, "if", &IF);
|
||||
cgetstr(bp, "rf", &RF);
|
||||
cgetstr(bp, "tf", &TF);
|
||||
cgetstr(bp, "nf", &NF);
|
||||
cgetstr(bp, "df", &DF);
|
||||
cgetstr(bp, "gf", &GF);
|
||||
cgetstr(bp, "vf", &VF);
|
||||
cgetstr(bp, "cf", &CF);
|
||||
cgetstr(bp, "tr", &TR);
|
||||
|
||||
RS = (cgetcap(bp, "rs", ':') != NULL);
|
||||
SF = (cgetcap(bp, "sf", ':') != NULL);
|
||||
SH = (cgetcap(bp, "sh", ':') != NULL);
|
||||
SB = (cgetcap(bp, "sb", ':') != NULL);
|
||||
HL = (cgetcap(bp, "hl", ':') != NULL);
|
||||
RW = (cgetcap(bp, "rw", ':') != NULL);
|
||||
|
||||
cgetnum(bp, "br", &BR);
|
||||
if (cgetnum(bp, "fc", &FC) < 0)
|
||||
FC = 0;
|
||||
if ((FS = pgetnum("fs")) < 0)
|
||||
if (cgetnum(bp, "fs", &FS) < 0)
|
||||
FS = 0;
|
||||
if ((XC = pgetnum("xc")) < 0)
|
||||
if (cgetnum(bp, "xc", &XC) < 0)
|
||||
XC = 0;
|
||||
if ((XS = pgetnum("xs")) < 0)
|
||||
if (cgetnum(bp, "xs", &XS) < 0)
|
||||
XS = 0;
|
||||
tof = !pgetflag("fo");
|
||||
|
||||
tof = (cgetcap(bp, "fo", ':') == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Acquire line printer or remote connection.
|
||||
*/
|
||||
static void
|
||||
openpr()
|
||||
{
|
||||
register int i, n;
|
||||
|
@ -1139,12 +1205,12 @@ openpr()
|
|||
exit(1);
|
||||
}
|
||||
if (i == 1)
|
||||
status("waiting for %s to become ready (offline ?)", printer);
|
||||
pstatus("waiting for %s to become ready (offline ?)", printer);
|
||||
sleep(i);
|
||||
}
|
||||
if (isatty(pfd))
|
||||
setty();
|
||||
status("%s is ready and printing", printer);
|
||||
pstatus("%s is ready and printing", printer);
|
||||
} else if (RM != NULL) {
|
||||
for (i = 1; ; i = i < 256 ? i << 1 : i) {
|
||||
resp = -1;
|
||||
|
@ -1159,15 +1225,15 @@ openpr()
|
|||
}
|
||||
if (i == 1) {
|
||||
if (resp < 0)
|
||||
status("waiting for %s to come up", RM);
|
||||
pstatus("waiting for %s to come up", RM);
|
||||
else {
|
||||
status("waiting for queue to be enabled on %s", RM);
|
||||
pstatus("waiting for queue to be enabled on %s", RM);
|
||||
i = 256;
|
||||
}
|
||||
}
|
||||
sleep(i);
|
||||
}
|
||||
status("sending to %s", RM);
|
||||
pstatus("sending to %s", RM);
|
||||
remote = 1;
|
||||
} else {
|
||||
syslog(LOG_ERR, "%s: no line printer device or host name",
|
||||
|
@ -1228,6 +1294,7 @@ struct bauds {
|
|||
/*
|
||||
* setup tty lines.
|
||||
*/
|
||||
static void
|
||||
setty()
|
||||
{
|
||||
struct sgttyb ttybuf;
|
||||
|
@ -1271,12 +1338,29 @@ setty()
|
|||
}
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
status(msg, a1, a2, a3)
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
#if __STDC__
|
||||
pstatus(const char *msg, ...)
|
||||
#else
|
||||
pstatus(msg, va_alist)
|
||||
char *msg;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
register int fd;
|
||||
char buf[BUFSIZ];
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
|
||||
umask(0);
|
||||
fd = open(ST, O_WRONLY|O_CREAT, 0664);
|
||||
|
@ -1285,7 +1369,8 @@ status(msg, a1, a2, a3)
|
|||
exit(1);
|
||||
}
|
||||
ftruncate(fd, 0);
|
||||
sprintf(buf, msg, a1, a2, a3);
|
||||
(void)vsnprintf(buf, sizeof(buf), msg, ap);
|
||||
va_end(ap);
|
||||
strcat(buf, "\n");
|
||||
(void) write(fd, buf, strlen(buf));
|
||||
(void) close(fd);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,46 +33,73 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)recvjob.c 5.15 (Berkeley) 5/4/91";*/
|
||||
static char rcsid[] = "$Id: recvjob.c,v 1.3 1994/04/21 18:53:47 cgd Exp $";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)recvjob.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Receive printer jobs from the network, queue them and
|
||||
* start the printer daemon.
|
||||
*/
|
||||
|
||||
#include "lp.h"
|
||||
#include "pathnames.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
char *sp = "";
|
||||
#define ack() (void) write(1, sp, 1);
|
||||
|
||||
char tfname[40]; /* tmp copy of cf before linking */
|
||||
char dfname[40]; /* data files */
|
||||
int minfree; /* keep at least minfree blocks available */
|
||||
static char dfname[40]; /* data files */
|
||||
static int minfree; /* keep at least minfree blocks available */
|
||||
static char *sp = "";
|
||||
static char tfname[40]; /* tmp copy of cf before linking */
|
||||
|
||||
void rcleanup();
|
||||
static int chksize __P((int));
|
||||
static void frecverr __P((const char *, ...));
|
||||
static int noresponse __P((void));
|
||||
static void rcleanup __P((int));
|
||||
static int read_number __P((char *));
|
||||
static int readfile __P((char *, int));
|
||||
static int readjob __P((void));
|
||||
|
||||
|
||||
void
|
||||
recvjob()
|
||||
{
|
||||
struct stat stb;
|
||||
char *bp = pbuf;
|
||||
int status;
|
||||
|
||||
/*
|
||||
* Perform lookup for printer name or abbreviation
|
||||
*/
|
||||
if ((status = pgetent(line, printer)) < 0)
|
||||
if ((status = cgetent(&bp, printcapdb, printer)) == -2)
|
||||
frecverr("cannot open printer description file");
|
||||
else if (status == 0)
|
||||
else if (status == -1)
|
||||
frecverr("unknown printer %s", printer);
|
||||
if ((LF = pgetstr("lf", &bp)) == NULL)
|
||||
else if (status == -3)
|
||||
fatal("potential reference loop detected in printcap file");
|
||||
|
||||
if (cgetstr(bp, "lf", &LF) == -1)
|
||||
LF = _PATH_CONSOLE;
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
|
||||
(void) close(2); /* set up log file */
|
||||
|
@ -102,6 +130,7 @@ recvjob()
|
|||
* Read printer jobs sent by lpd and copy them to the spooling directory.
|
||||
* Return the number of jobs successfully transfered.
|
||||
*/
|
||||
static int
|
||||
readjob()
|
||||
{
|
||||
register int size, nfiles;
|
||||
|
@ -125,7 +154,7 @@ readjob()
|
|||
cp = line;
|
||||
switch (*cp++) {
|
||||
case '\1': /* cleanup because data sent was bad */
|
||||
rcleanup();
|
||||
rcleanup(0);
|
||||
continue;
|
||||
|
||||
case '\2': /* read cf file */
|
||||
|
@ -148,7 +177,7 @@ readjob()
|
|||
continue;
|
||||
}
|
||||
if (!readfile(tfname, size)) {
|
||||
rcleanup();
|
||||
rcleanup(0);
|
||||
continue;
|
||||
}
|
||||
if (link(tfname, cp) < 0)
|
||||
|
@ -175,13 +204,14 @@ readjob()
|
|||
(void) readfile(dfname, size);
|
||||
continue;
|
||||
}
|
||||
frecverr("protocol screwup");
|
||||
frecverr("protocol screwup: %s", line);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Read files send by lpd and copy them to the spooling directory.
|
||||
*/
|
||||
static int
|
||||
readfile(file, size)
|
||||
char *file;
|
||||
int size;
|
||||
|
@ -227,6 +257,7 @@ readfile(file, size)
|
|||
return(1);
|
||||
}
|
||||
|
||||
static int
|
||||
noresponse()
|
||||
{
|
||||
char resp;
|
||||
|
@ -242,6 +273,7 @@ noresponse()
|
|||
* Check to see if there is enough space on the disk for size bytes.
|
||||
* 1 == OK, 0 == Not OK.
|
||||
*/
|
||||
static int
|
||||
chksize(size)
|
||||
int size;
|
||||
{
|
||||
|
@ -259,6 +291,7 @@ chksize(size)
|
|||
return(1);
|
||||
}
|
||||
|
||||
static int
|
||||
read_number(fn)
|
||||
char *fn;
|
||||
{
|
||||
|
@ -278,10 +311,10 @@ read_number(fn)
|
|||
/*
|
||||
* Remove all the files associated with the current job being transfered.
|
||||
*/
|
||||
void
|
||||
rcleanup()
|
||||
static void
|
||||
rcleanup(signo)
|
||||
int signo;
|
||||
{
|
||||
|
||||
if (tfname[0])
|
||||
(void) unlink(tfname);
|
||||
if (dfname[0])
|
||||
|
@ -294,11 +327,32 @@ rcleanup()
|
|||
dfname[0] = '\0';
|
||||
}
|
||||
|
||||
frecverr(msg, a1, a2)
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
#if __STDC__
|
||||
frecverr(const char *msg, ...)
|
||||
#else
|
||||
frecverr(msg, va_alist)
|
||||
char *msg;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
rcleanup();
|
||||
syslog(LOG_ERR, msg, a1, a2);
|
||||
extern char *fromb;
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
rcleanup(0);
|
||||
syslog(LOG_ERR, "%s", fromb);
|
||||
vsyslog(LOG_ERR, msg, ap);
|
||||
va_end(ap);
|
||||
putchar('\1'); /* return error code */
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# from: @(#)Makefile 5.3 (Berkeley) 6/19/90
|
||||
# $Id: Makefile,v 1.2 1993/07/30 22:12:20 mycroft Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= lpq
|
||||
CFLAGS+=-I${.CURDIR}/../common_source
|
||||
SRCS= lpq.c displayq.c common.c printcap.c
|
||||
SRCS= lpq.c displayq.c common.c
|
||||
BINOWN= root
|
||||
BINGRP= daemon
|
||||
BINMODE=6555
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.\" Copyright (c) 1983, 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1983, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
|
@ -29,10 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)lpq.1 6.10 (Berkeley) 5/9/91
|
||||
.\" $Id: lpq.1,v 1.2 1993/08/01 07:24:34 mycroft Exp $
|
||||
.\" @(#)lpq.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd May 9, 1991
|
||||
.Dd June 6, 1993
|
||||
.Dt LPQ 1
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -32,14 +33,13 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)lpq.c 5.7 (Berkeley) 3/2/91";*/
|
||||
static char rcsid[] = "$Id: lpq.c,v 1.2 1993/08/01 17:58:45 mycroft Exp $";
|
||||
static char sccsid[] = "@(#)lpq.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -51,13 +51,25 @@ static char rcsid[] = "$Id: lpq.c,v 1.2 1993/08/01 17:58:45 mycroft Exp $";
|
|||
* -P used to identify printer as per lpr/lprm
|
||||
*/
|
||||
|
||||
#include "lp.h"
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <syslog.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
|
||||
char *user[MAXUSERS]; /* users to process */
|
||||
int users; /* # of users in user array */
|
||||
int requ[MAXREQUESTS]; /* job number of spool entries */
|
||||
int requests; /* # of spool requests */
|
||||
char *user[MAXUSERS]; /* users to process */
|
||||
int users; /* # of users in user array */
|
||||
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
register int argc;
|
||||
register char **argv;
|
||||
|
@ -106,6 +118,7 @@ main(argc, argv)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# from: @(#)Makefile 5.3 (Berkeley) 6/19/90
|
||||
# $Id: Makefile,v 1.2 1993/07/30 22:12:17 mycroft Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= lpr
|
||||
CFLAGS+=-I${.CURDIR}/../common_source
|
||||
SRCS= lpr.c startdaemon.c printcap.c
|
||||
SRCS= lpr.c startdaemon.c common.c
|
||||
BINOWN= root
|
||||
BINGRP= daemon
|
||||
BINMODE=6555
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
|
@ -29,10 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)lpr.1 6.10 (Berkeley) 7/24/91
|
||||
.\" $Id: lpr.1,v 1.2 1993/08/01 07:24:29 mycroft Exp $
|
||||
.\" @(#)lpr.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd July 24, 1991
|
||||
.Dd June 6, 1993
|
||||
.Dt LPR 1
|
||||
.Os BSD 4
|
||||
.Sh NAME
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1983, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -37,15 +38,15 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1983, 1989 Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
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
|
||||
/*static char sccsid[] = "from: @(#)lpr.c 5.9 (Berkeley) 3/2/91";*/
|
||||
static char rcsid[] = "$Id: lpr.c,v 1.6 1994/05/17 04:15:27 cgd Exp $";
|
||||
static char sccsid[] = "@(#)lpr.c 8.3 (Berkeley) 3/30/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* lpr -- off line print
|
||||
*
|
||||
|
@ -53,60 +54,63 @@ static char rcsid[] = "$Id: lpr.c,v 1.6 1994/05/17 04:15:27 cgd Exp $";
|
|||
* using information from a printer data base.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <a.out.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include "lp.h"
|
||||
#include "lp.local.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
char *tfname; /* tmp copy of cf before linking */
|
||||
char *cfname; /* daemon control files, linked from tf's */
|
||||
char *dfname; /* data files */
|
||||
static char *cfname; /* daemon control files, linked from tf's */
|
||||
static char *class = host; /* class title on header page */
|
||||
static char *dfname; /* data files */
|
||||
static char *fonts[4]; /* troff font names */
|
||||
static char format = 'f'; /* format char for printing files */
|
||||
static int hdr = 1; /* print header or not (default is yes) */
|
||||
static int iflag; /* indentation wanted */
|
||||
static int inchar; /* location to increment char in file names */
|
||||
static int indent; /* amount to indent */
|
||||
static char *jobname; /* job name on header page */
|
||||
static int mailflg; /* send mail */
|
||||
static int nact; /* number of jobs to act on */
|
||||
static int ncopies = 1; /* # of copies to make */
|
||||
static char *person; /* user name */
|
||||
static int qflag; /* q job, but don't exec daemon */
|
||||
static int rflag; /* remove files upon completion */
|
||||
static int sflag; /* symbolic link flag */
|
||||
static int tfd; /* control file descriptor */
|
||||
static char *tfname; /* tmp copy of cf before linking */
|
||||
static char *title; /* pr'ing title */
|
||||
static int userid; /* user id */
|
||||
static char *width; /* width for versatec printing */
|
||||
|
||||
int nact; /* number of jobs to act on */
|
||||
int tfd; /* control file descriptor */
|
||||
int mailflg; /* send mail */
|
||||
int qflag; /* q job, but don't exec daemon */
|
||||
char format = 'f'; /* format char for printing files */
|
||||
int rflag; /* remove files upon completion */
|
||||
int sflag; /* symbolic link flag */
|
||||
int inchar; /* location to increment char in file names */
|
||||
int ncopies = 1; /* # of copies to make */
|
||||
int iflag; /* indentation wanted */
|
||||
int indent; /* amount to indent */
|
||||
int hdr = 1; /* print header or not (default is yes) */
|
||||
int userid; /* user id */
|
||||
char *person; /* user name */
|
||||
char *title; /* pr'ing title */
|
||||
char *fonts[4]; /* troff font names */
|
||||
char *width; /* width for versatec printing */
|
||||
char host[32]; /* host name */
|
||||
char *class = host; /* class title on header page */
|
||||
char *jobname; /* job name on header page */
|
||||
char *name; /* program name */
|
||||
char *printer; /* printer name */
|
||||
struct stat statb;
|
||||
static struct stat statb;
|
||||
|
||||
int MX; /* maximum number of blocks to copy */
|
||||
int MC; /* maximum number of copies allowed */
|
||||
int DU; /* daemon user-id */
|
||||
char *SD; /* spool directory */
|
||||
char *LO; /* lock file name */
|
||||
char *RG; /* restrict group */
|
||||
short SC; /* suppress multiple copies */
|
||||
static void card __P((int, char *));
|
||||
static void chkprinter __P((char *));
|
||||
static void cleanup __P((int));
|
||||
static void copy __P((int, char []));
|
||||
static void fatal2 __P((const char *, ...));
|
||||
static char *itoa __P((int));
|
||||
static char *linked __P((char *));
|
||||
static char *lmktemp __P((char *, int, int));
|
||||
static void mktemps __P((void));
|
||||
static int nfile __P((char *));
|
||||
static int test __P((char *));
|
||||
|
||||
char *getenv();
|
||||
char *rindex();
|
||||
char *linked();
|
||||
void cleanup();
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
|
@ -251,9 +255,9 @@ main(argc, argv)
|
|||
printer = DEFLP;
|
||||
chkprinter(printer);
|
||||
if (SC && ncopies > 1)
|
||||
fatal("multiple copies are not allowed");
|
||||
fatal2("multiple copies are not allowed");
|
||||
if (MC > 0 && ncopies > MC)
|
||||
fatal("only %d copies are allowed", MC);
|
||||
fatal2("only %d copies are allowed", MC);
|
||||
/*
|
||||
* Get the identity of the person doing the lpr using the same
|
||||
* algorithm as lprm.
|
||||
|
@ -261,7 +265,7 @@ main(argc, argv)
|
|||
userid = getuid();
|
||||
if (userid != DU || person == 0) {
|
||||
if ((pw = getpwuid(userid)) == NULL)
|
||||
fatal("Who are you?");
|
||||
fatal2("Who are you?");
|
||||
person = pw->pw_name;
|
||||
}
|
||||
/*
|
||||
|
@ -269,7 +273,7 @@ main(argc, argv)
|
|||
*/
|
||||
if (RG != NULL && userid != DU) {
|
||||
if ((gptr = getgrnam(RG)) == NULL)
|
||||
fatal("Restricted group specified incorrectly");
|
||||
fatal2("Restricted group specified incorrectly");
|
||||
if (gptr->gr_gid != getgid()) {
|
||||
while (*gptr->gr_mem != NULL) {
|
||||
if ((strcmp(person, *gptr->gr_mem)) == 0)
|
||||
|
@ -277,7 +281,7 @@ main(argc, argv)
|
|||
gptr->gr_mem++;
|
||||
}
|
||||
if (*gptr->gr_mem == NULL)
|
||||
fatal("Not a member of the restricted group");
|
||||
fatal2("Not a member of the restricted group");
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -285,7 +289,7 @@ main(argc, argv)
|
|||
*/
|
||||
(void) sprintf(buf, "%s/%s", SD, LO);
|
||||
if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010))
|
||||
fatal("Printer queue is disabled");
|
||||
fatal2("Printer queue is disabled");
|
||||
/*
|
||||
* Initialize the control file.
|
||||
*/
|
||||
|
@ -361,18 +365,19 @@ main(argc, argv)
|
|||
if ((tfd = open(tfname, O_RDWR)) >= 0) {
|
||||
char c;
|
||||
|
||||
if (read(tfd, &c, 1) == 1 && lseek(tfd, 0L, 0) == 0 &&
|
||||
if (read(tfd, &c, 1) == 1 &&
|
||||
lseek(tfd, (off_t)0, 0) == 0 &&
|
||||
write(tfd, &c, 1) != 1) {
|
||||
printf("%s: cannot touch %s\n", name, tfname);
|
||||
tfname[inchar]++;
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
}
|
||||
(void) close(tfd);
|
||||
}
|
||||
if (link(tfname, cfname) < 0) {
|
||||
printf("%s: cannot rename %s\n", name, cfname);
|
||||
tfname[inchar]++;
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
}
|
||||
unlink(tfname);
|
||||
if (qflag) /* just q things up */
|
||||
|
@ -381,13 +386,14 @@ main(argc, argv)
|
|||
printf("jobs queued, but cannot start daemon.\n");
|
||||
exit(0);
|
||||
}
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the file n and copy from file descriptor f.
|
||||
*/
|
||||
static void
|
||||
copy(f, n)
|
||||
int f;
|
||||
char n[];
|
||||
|
@ -429,7 +435,7 @@ copy(f, n)
|
|||
* Try and link the file to dfname. Return a pointer to the full
|
||||
* path name if successful.
|
||||
*/
|
||||
char *
|
||||
static char *
|
||||
linked(file)
|
||||
register char *file;
|
||||
{
|
||||
|
@ -464,8 +470,10 @@ linked(file)
|
|||
/*
|
||||
* Put a line into the control file.
|
||||
*/
|
||||
static void
|
||||
card(c, p2)
|
||||
register char c, *p2;
|
||||
register int c;
|
||||
register char *p2;
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
register char *p1 = buf;
|
||||
|
@ -483,30 +491,27 @@ card(c, p2)
|
|||
/*
|
||||
* Create a new file in the spool directory.
|
||||
*/
|
||||
static int
|
||||
nfile(n)
|
||||
char *n;
|
||||
{
|
||||
register f;
|
||||
register int f;
|
||||
int oldumask = umask(0); /* should block signals */
|
||||
|
||||
/*
|
||||
* Use open() rather than creat() to avoid security hole
|
||||
* involving symlinks
|
||||
*/
|
||||
f = open(n, O_WRONLY | O_EXCL | O_CREAT, FILMOD);
|
||||
(void) umask(oldumask);
|
||||
if (f < 0) {
|
||||
printf("%s: cannot create %s\n", name, n);
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
}
|
||||
if (fchown(f, userid, -1) < 0) {
|
||||
printf("%s: cannot chown %s\n", name, n);
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
}
|
||||
if (++n[inchar] > 'z') {
|
||||
if (++n[inchar-2] == 't') {
|
||||
printf("too many files - break up the job\n");
|
||||
cleanup();
|
||||
cleanup(0);
|
||||
}
|
||||
n[inchar] = 'A';
|
||||
} else if (n[inchar] == '[')
|
||||
|
@ -517,8 +522,9 @@ nfile(n)
|
|||
/*
|
||||
* Cleanup after interrupts and errors.
|
||||
*/
|
||||
void
|
||||
cleanup()
|
||||
static void
|
||||
cleanup(signo)
|
||||
int signo;
|
||||
{
|
||||
register i;
|
||||
|
||||
|
@ -550,6 +556,7 @@ cleanup()
|
|||
* Return -1 if it is not, 0 if its printable, and 1 if
|
||||
* we should remove it after printing.
|
||||
*/
|
||||
static int
|
||||
test(file)
|
||||
char *file;
|
||||
{
|
||||
|
@ -577,43 +584,24 @@ test(file)
|
|||
printf("%s: cannot open %s\n", name, file);
|
||||
return(-1);
|
||||
}
|
||||
if (read(fd, &execb, sizeof(execb)) == sizeof(execb)) {
|
||||
if(!N_BADMAG(execb) ||
|
||||
#ifdef SARMAG
|
||||
strncmp((char *)&execb, ARMAG, SARMAG)==0
|
||||
#else
|
||||
execb.a_magic==ARMAG
|
||||
#endif
|
||||
) {
|
||||
if (read(fd, &execb, sizeof(execb)) == sizeof(execb) &&
|
||||
!N_BADMAG(execb)) {
|
||||
printf("%s: %s is an executable program", name, file);
|
||||
goto error1;
|
||||
}
|
||||
#ifdef A_MAGIC1
|
||||
switch(execb.a_magic) {
|
||||
case A_MAGIC1:
|
||||
case A_MAGIC2:
|
||||
case A_MAGIC3:
|
||||
#ifdef A_MAGIC4
|
||||
case A_MAGIC4:
|
||||
#endif
|
||||
printf("%s: %s is an executable program", name, file);
|
||||
goto error1;
|
||||
|
||||
case ARMAG:
|
||||
printf("%s: %s is an archive file", name, file);
|
||||
goto error1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
(void) close(fd);
|
||||
if (rflag) {
|
||||
if ((cp = rindex(file, '/')) == NULL) {
|
||||
if (access(".", 2) == 0)
|
||||
return(1);
|
||||
} else {
|
||||
if (cp == file) {
|
||||
fd = access("/", 2);
|
||||
} else {
|
||||
*cp = '\0';
|
||||
fd = access(file, 2);
|
||||
*cp = '/';
|
||||
}
|
||||
if (fd == 0)
|
||||
return(1);
|
||||
}
|
||||
|
@ -630,7 +618,7 @@ error1:
|
|||
/*
|
||||
* itoa - integer to string conversion
|
||||
*/
|
||||
char *
|
||||
static char *
|
||||
itoa(i)
|
||||
register int i;
|
||||
{
|
||||
|
@ -647,39 +635,37 @@ itoa(i)
|
|||
/*
|
||||
* Perform lookup for printer name or abbreviation --
|
||||
*/
|
||||
static void
|
||||
chkprinter(s)
|
||||
char *s;
|
||||
{
|
||||
int status;
|
||||
char buf[BUFSIZ];
|
||||
static char pbuf[BUFSIZ/2];
|
||||
char *bp = pbuf;
|
||||
extern char *pgetstr();
|
||||
|
||||
if ((status = pgetent(buf, s)) < 0)
|
||||
fatal("cannot open printer description file");
|
||||
else if (status == 0)
|
||||
fatal("%s: unknown printer", s);
|
||||
if ((SD = pgetstr("sd", &bp)) == NULL)
|
||||
if ((status = cgetent(&bp, printcapdb, s)) == -2)
|
||||
fatal2("cannot open printer description file");
|
||||
else if (status == -1)
|
||||
fatal2("%s: unknown printer", s);
|
||||
if (cgetstr(bp, "sd", &SD) == -1)
|
||||
SD = _PATH_DEFSPOOL;
|
||||
if ((LO = pgetstr("lo", &bp)) == NULL)
|
||||
if (cgetstr(bp, "lo", &LO) == -1)
|
||||
LO = DEFLOCK;
|
||||
RG = pgetstr("rg", &bp);
|
||||
if ((MX = pgetnum("mx")) < 0)
|
||||
cgetstr(bp, "rg", &RG);
|
||||
if (cgetnum(bp, "mx", &MX) < 0)
|
||||
MX = DEFMX;
|
||||
if ((MC = pgetnum("mc")) < 0)
|
||||
if (cgetnum(bp,"mc", &MC) < 0)
|
||||
MC = DEFMAXCOPIES;
|
||||
if ((DU = pgetnum("du")) < 0)
|
||||
if (cgetnum(bp, "du", &DU) < 0)
|
||||
DU = DEFUID;
|
||||
SC = pgetflag("sc");
|
||||
SC = (cgetcap(bp, "sc", ':') != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make the temp files.
|
||||
*/
|
||||
static void
|
||||
mktemps()
|
||||
{
|
||||
register int c, len, fd, n;
|
||||
register int len, fd, n;
|
||||
register char *cp;
|
||||
char buf[BUFSIZ];
|
||||
char *lmktemp();
|
||||
|
@ -707,7 +693,7 @@ mktemps()
|
|||
dfname = lmktemp("df", n, len);
|
||||
inchar = strlen(SD) + 3;
|
||||
n = (n + 1) % 1000;
|
||||
(void) lseek(fd, 0L, 0);
|
||||
(void) lseek(fd, (off_t)0, 0);
|
||||
sprintf(buf, "%03d\n", n);
|
||||
(void) write(fd, buf, strlen(buf));
|
||||
(void) close(fd); /* unlocks as well */
|
||||
|
@ -716,26 +702,43 @@ mktemps()
|
|||
/*
|
||||
* Make a temp file name.
|
||||
*/
|
||||
char *
|
||||
static char *
|
||||
lmktemp(id, num, len)
|
||||
char *id;
|
||||
int num, len;
|
||||
{
|
||||
register char *s;
|
||||
extern char *malloc();
|
||||
|
||||
if ((s = malloc(len)) == NULL)
|
||||
fatal("out of memory");
|
||||
fatal2("out of memory");
|
||||
(void) sprintf(s, "%s/%sA%03d%s", SD, id, num, host);
|
||||
return(s);
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
fatal(msg, a1, a2, a3)
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
#if __STDC__
|
||||
fatal2(const char *msg, ...)
|
||||
#else
|
||||
fatal2(msg, va_alist)
|
||||
char *msg;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#if __STDC__
|
||||
va_start(ap, msg);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
printf("%s: ", name);
|
||||
printf(msg, a1, a2, a3);
|
||||
vprintf(msg, ap);
|
||||
putchar('\n');
|
||||
va_end(ap);
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue