* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
-static char sccsid[] = "@(#)printjob.c 5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)printjob.c 5.11 (Berkeley) %G%";
#endif /* not lint */
/*
*/
#include "lp.h"
+#include "pathnames.h"
#define DORETURN 0 /* absorb fork error */
#define DOABORT 1 /* abort if dofork fails */
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 tmpfile[] = "errsXXXXXX"; /* file name for filter output */
+char tempfile[] = "errsXXXXXX"; /* file name for filter output */
printjob()
{
(void) close(2); /* set up log file */
if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
syslog(LOG_ERR, "%s: %m", LF);
- (void) open("/dev/null", O_WRONLY);
+ (void) open(_PATH_DEVNULL, O_WRONLY);
}
setgid(getegid());
pid = getpid(); /* for use with lprm */
signal(SIGQUIT, abortpr);
signal(SIGTERM, abortpr);
- (void) mktemp(tmpfile);
+ (void) mktemp(tempfile);
/*
* uses short form file names
if (TR != NULL) /* output trailer */
(void) write(ofd, TR, strlen(TR));
}
- (void) unlink(tmpfile);
+ (void) unlink(tempfile);
exit(0);
}
goto again;
char fonts[4][50]; /* fonts for troff */
-char ifonts[4][18] = {
- "/usr/lib/vfont/R",
- "/usr/lib/vfont/I",
- "/usr/lib/vfont/B",
- "/usr/lib/vfont/S"
+char ifonts[4][40] = {
+ _PATH_VFONTR,
+ _PATH_VFONTI,
+ _PATH_VFONTB,
+ _PATH_VFONTS,
};
/*
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;
switch (format) {
case 'p': /* print file using 'pr' */
if (IF == NULL) { /* use output filter */
- prog = PR;
+ prog = _PATH_PR;
av[0] = "pr";
av[1] = width;
av[2] = length;
dup2(p[1], 1); /* pipe is stdout */
for (n = 3; n < NOFILE; n++)
(void) close(n);
- execl(PR, "pr", width, length, "-h", *title ? title : " ", 0);
- syslog(LOG_ERR, "cannot execl %s", PR);
+ execl(_PATH_PR, "pr", width, length,
+ "-h", *title ? title : " ", 0);
+ syslog(LOG_ERR, "cannot execl %s", _PATH_PR);
exit(2);
}
(void) close(p[1]); /* close output side */
} else {
for (n = 0; n < 4; n++) {
if (fonts[n][0] != '/')
- (void) write(fo, "/usr/lib/vfont/", 15);
+ (void) write(fo, _PATH_VFONT, 15);
(void) write(fo, fonts[n], strlen(fonts[n]));
(void) write(fo, "\n", 1);
}
if ((child = dofork(DORETURN)) == 0) { /* child */
dup2(fi, 0);
dup2(fo, 1);
- n = open(tmpfile, O_WRONLY|O_CREAT|O_TRUNC, 0664);
+ n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0664);
if (n >= 0)
dup2(n, 2);
for (n = 3; n < NOFILE; n++)
}
}
tof = 0;
+
+ /* 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);
+ }
+
if (!WIFEXITED(status)) {
syslog(LOG_WARNING, "%s: Daemon filter '%c' terminated (%d)",
printer, format, status.w_termsig);
dup2(p[0], 0);
for (i = 3; i < NOFILE; i++)
(void) close(i);
- if ((cp = rindex(MAIL, '/')) != NULL)
+ if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL)
cp++;
else
- cp = MAIL;
+ cp = _PATH_SENDMAIL;
sprintf(buf, "%s@%s", user, fromhost);
- execl(MAIL, cp, buf, 0);
+ execl(_PATH_SENDMAIL, cp, buf, 0);
exit(0);
} else if (s > 0) { /* parent */
dup2(p[1], 1);
printf("\ncould not be printed without an account on %s\n", host);
break;
case FILTERERR:
- if (stat(tmpfile, &stb) < 0 || stb.st_size == 0 ||
- (fp = fopen(tmpfile, "r")) == NULL) {
+ if (stat(tempfile, &stb) < 0 || stb.st_size == 0 ||
+ (fp = fopen(tempfile, "r")) == NULL) {
printf("\nwas printed but had some errors\n");
break;
}
*/
abortpr()
{
- (void) unlink(tmpfile);
+ (void) unlink(tempfile);
kill(0, SIGINT);
if (ofilter > 0)
kill(ofilter, SIGCONT);
init()
{
int status;
+ char *s;
if ((status = pgetent(line, printer)) < 0) {
syslog(LOG_ERR, "can't open printer description file");
exit(1);
}
if ((LP = pgetstr("lp", &bp)) == NULL)
- LP = DEFDEVLP;
+ LP = _PATH_DEFDEVLP;
if ((RP = pgetstr("rp", &bp)) == NULL)
RP = DEFLP;
if ((LO = pgetstr("lo", &bp)) == NULL)
if ((ST = pgetstr("st", &bp)) == NULL)
ST = DEFSTAT;
if ((LF = pgetstr("lf", &bp)) == NULL)
- LF = DEFLOGF;
+ LF = _PATH_CONSOLE;
if ((SD = pgetstr("sd", &bp)) == NULL)
- SD = DEFSPOOL;
+ SD = _PATH_DEFSPOOL;
if ((DU = pgetnum("du")) < 0)
DU = DEFUID;
if ((FF = pgetstr("ff", &bp)) == NULL)
PY = 0;
sprintf(&pxlength[2], "%d", PY);
RM = pgetstr("rm", &bp);
- /*
- * Figure out whether the local machine is the same as the remote
- * machine entry (if it exists). If not, then ignore the local
- * queue information.
- */
- if (RM != (char *) NULL) {
- char name[256];
- struct hostent *hp;
-
- /* get the standard network name of the local host */
- gethostname(name, sizeof(name));
- name[sizeof(name)-1] = '\0';
- hp = gethostbyname(name);
- if (hp == (struct hostent *) NULL) {
- syslog(LOG_ERR,
- "unable to get network name for local machine %s",
- name);
- goto localcheck_done;
- } else strcpy(name, hp->h_name);
-
- /* get the standard network name of RM */
- hp = gethostbyname(RM);
- if (hp == (struct hostent *) NULL) {
- syslog(LOG_ERR,
- "unable to get hostname for remote machine %s", RM);
- goto localcheck_done;
- }
-
- /* if printer is not on local machine, ignore LP */
- if (strcmp(name, hp->h_name) != 0) *LP = '\0';
- }
-localcheck_done:
+ if (s = checkremote())
+ syslog(LOG_WARNING, s);
AF = pgetstr("af", &bp);
OF = pgetstr("of", &bp);
register int i, n;
int resp;
- if (*LP) {
+ if (!sendtorem && *LP) {
for (i = 1; ; i = i < 32 ? i << 1 : i) {
pfd = open(LP, RW ? O_RDWR : O_WRONLY);
if (pfd >= 0)
/*
* Start up an output filter, if needed.
*/
- if (OF) {
+ if (!remote && OF) {
int p[2];
char *cp;
syslog(LOG_ERR, "%s: ioctl(TIOCSETP): %m", printer);
exit(1);
}
- if (XC || XS) {
- int ldisc = NTTYDISC;
-
- if (ioctl(pfd, TIOCSETD, &ldisc) < 0) {
- syslog(LOG_ERR, "%s: ioctl(TIOCSETD): %m", printer);
- exit(1);
- }
- }
if (XC) {
if (ioctl(pfd, TIOCLBIC, &XC) < 0) {
syslog(LOG_ERR, "%s: ioctl(TIOCLBIC): %m", printer);