diff options
author | joerg <joerg@FreeBSD.org> | 1996-05-05 14:04:33 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1996-05-05 14:04:33 +0000 |
commit | 0291e848bc787305335af649ac14bc8fe5a19a49 (patch) | |
tree | f679484620675241701b875cbab6124b83dc1136 /usr.sbin/lpr/common_source | |
parent | 825cd02612729df0559ca26d13d946c625215900 (diff) | |
download | FreeBSD-src-0291e848bc787305335af649ac14bc8fe5a19a49.zip FreeBSD-src-0291e848bc787305335af649ac14bc8fe5a19a49.tar.gz |
Vendor-branch import of the 4.4BSD-Lite2 code for lpr. There are
several bugfixes in it that are worth considering.
Don't be alarmed about the import conflicts...
Obtained from: 4.4BSD-Lite2
Diffstat (limited to 'usr.sbin/lpr/common_source')
-rw-r--r-- | usr.sbin/lpr/common_source/aux.c | 400 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/aux.h | 67 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/common.c | 63 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/displayq.c | 27 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/lp.h | 7 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/printcap.c | 117 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/rmjob.c | 6 |
7 files changed, 637 insertions, 50 deletions
diff --git a/usr.sbin/lpr/common_source/aux.c b/usr.sbin/lpr/common_source/aux.c new file mode 100644 index 0000000..8d7a936 --- /dev/null +++ b/usr.sbin/lpr/common_source/aux.c @@ -0,0 +1,400 @@ +/* + * Copyright (c) 1995 + * 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 + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Auxillary functions to aid portability to other systems. + * These are 4.4BSD routines that are often not found on other systems. + * + * !!!USE THIS FILE ONLY IF YOU ARE NOT RUNNING 4.4BSD!!! + */ + +#if __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif + +#ifdef NO_SNPRINTF +#if __STDC__ +snprintf(char *str, size_t n, const char *fmt, ...) +#else +snprintf(str, n, fmt, va_alist) + char *str; + size_t n; + char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + ret = vsprintf(str, fmt, ap); + va_end(ap); + if (strlen(str) > n) + fatal("memory corrupted"); + return (ret); +} + +vsnprintf(str, n, fmt, ap) + char *str; + size_t n; + char *fmt; + va_list ap; +{ + int ret; + + ret = vsprintf(str, fmt, ap); + if (strlen(str) > n) + fatal("memory corrupted"); + return (ret); +} +#endif + +#ifdef NO_STRERROR +char * +strerror(num) + int num; +{ + extern int sys_nerr; + extern char *sys_errlist[]; +#define UPREFIX "Unknown error: " + static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ + register unsigned int errnum; + register char *p, *t; + char tmp[40]; + + errnum = num; /* convert to unsigned */ + if (errnum < sys_nerr) + return(sys_errlist[errnum]); + + /* Do this by hand, so we don't include stdio(3). */ + t = tmp; + do { + *t++ = "0123456789"[errnum % 10]; + } while (errnum /= 10); + for (p = ebuf + sizeof(UPREFIX) - 1;;) { + *p++ = *--t; + if (t <= tmp) + break; + } + return(ebuf); +} +#endif + +#ifdef NO_STRDUP +char * +strdup(str) + char *str; +{ + int n; + char *sp; + + n = strlen(str) + 1; + if (sp = (char *) malloc(n)) + memcpy(sp, str, n); + return (sp); +} +#endif + +#ifdef NO_DAEMON +#include <fcntl.h> +#include <paths.h> +#include <unistd.h> +#include <sgtty.h> +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +int +daemon(nochdir, noclose) + int nochdir, noclose; +{ + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + (void)dup2(fd, STDIN_FILENO); + (void)dup2(fd, STDOUT_FILENO); + (void)dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)close (fd); + } + return (0); +} +#endif + + +#ifdef NO_SETSID +int +setsid() +{ + int f; + + f = open("/dev/tty", O_RDWR); + if (f > 0) { + ioctl(f, TIOCNOTTY, 0); + (void) close(f); + } + return f; +} +#endif + + +#ifdef NO_VSYSLOG +#include <stdio.h> +#include <errno.h> +#if __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif + +vsyslog(pri, fmt, ap) + int pri; + const char *fmt; + va_list ap; +{ + char buf[2048], fmt_cpy[1024]; + + /* substitute error message for %m */ + { + register char ch, *t1, *t2; + char *strerror(); + + for (t1 = fmt_cpy; ch = *fmt; ++fmt) + if (ch == '%' && fmt[1] == 'm') { + ++fmt; + for (t2 = strerror(errno); + *t1 = *t2++; ++t1); + } + else + *t1++ = ch; + *t1 = '\0'; + } + vsprintf(buf, fmt_cpy, ap); + syslog(pri, "%s", buf); +} +#endif + + +#ifdef NO_IVALIDUSER +#include <stdio.h> +#include <ctype.h> +#include <netdb.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <sys/param.h> +#include "pathnames.h" + +/* + * Returns 0 if ok, -1 if not ok. + */ +int +__ivaliduser(hostf, raddr, luser, ruser) + FILE *hostf; + struct in_addr raddr; + const char *luser, *ruser; +{ + register char *user, *p; + int ch; + char buf[MAXHOSTNAMELEN + 128]; /* host + login */ + + while (fgets(buf, sizeof(buf), hostf)) { + p = buf; + /* Skip lines that are too long. */ + if (strchr(p, '\n') == NULL) { + while ((ch = getc(hostf)) != '\n' && ch != EOF); + continue; + } + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { + *p = isupper(*p) ? tolower(*p) : *p; + p++; + } + if (*p == ' ' || *p == '\t') { + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + user = p; + while (*p != '\n' && *p != ' ' && + *p != '\t' && *p != '\0') + p++; + } else + user = p; + *p = '\0'; + if (__icheckhost(raddr, buf) && + strcmp(ruser, *user ? user : luser) == 0) { + return (0); + } + } + return (-1); +} + +/* + * Returns "true" if match, 0 if no match. + */ +__icheckhost(raddr, lhost) + struct in_addr raddr; + register char *lhost; +{ + register struct hostent *hp; + struct in_addr laddr; + register char **pp; + + /* Try for raw ip address first. */ + if (isdigit(*lhost) && (laddr.s_addr = inet_addr(lhost)) != INADDR_NONE) + return (raddr.s_addr == laddr.s_addr); + + /* Better be a hostname. */ + if ((hp = gethostbyname(lhost)) == NULL) + return (0); + + /* Spin through ip addresses. */ + for (pp = hp->h_addr_list; *pp; ++pp) + if (!bcmp(&raddr, *pp, sizeof(struct in_addr))) + return (1); + + /* No match. */ + return (0); +} +#endif /* NO_IVALIDUSER */ + + +#ifdef NO_STATFS +#include <sys/types.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <sys/dir.h> +#include <sys/param.h> +#include <ufs/fs.h> + +/* + * 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; +{ + struct stat stb; + int spacefree; + struct fs fs; + static int dfd; + static char *find_dev(); + +#ifndef SBOFF +#define SBOFF ((off_t)(BBSIZE)) +#endif + if (dfd <= 0) { + char *ddev; + + if (stat(".", &stb) < 0) { + syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); + return (1); + } + ddev = find_dev(stb.st_dev, S_IFBLK); + if ((dfd = open(ddev, O_RDONLY)) < 0) { + syslog(LOG_WARNING, "%s: %s: %m", printer, ddev); + return (1); + } + } + if (lseek(dfd, (off_t)(SBOFF), 0) < 0) + return(1); + if (read(dfd, (char *)&fs, sizeof fs) != sizeof fs + || fs.fs_magic != FS_MAGIC) { + syslog(LOG_ERR, "Can't calculate free space on spool device"); + return(1); + } + spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 512; + size = (size + 511) / 512; + if (minfree + size > spacefree) + return(0); + return(1); +} + +static char * +find_dev(dev, type) + register dev_t dev; + register int type; +{ + register DIR *dfd; + struct direct *dir; + struct stat stb; + char devname[MAXNAMLEN+6]; + char *dp; + int n; + + strcpy(devname, "/dev/dsk"); + if ((dfd = opendir(devname)) == NULL) { + strcpy(devname, "/dev"); + dfd = opendir(devname); + } + strcat(devname, "/"); + n = strlen(devname); + + while ((dir = readdir(dfd))) { + strcpy(devname + n, dir->d_name); + if (stat(devname, &stb)) + continue; + if ((stb.st_mode & S_IFMT) != type) + continue; + if (dev == stb.st_rdev) { + closedir(dfd); + dp = (char *)malloc(strlen(devname)+1); + strcpy(dp, devname); + return(dp); + } + } + closedir(dfd); + frecverr("cannot find device %d, %d", major(dev), minor(dev)); + /*NOTREACHED*/ +} +#endif /* NOSTATFS */ diff --git a/usr.sbin/lpr/common_source/aux.h b/usr.sbin/lpr/common_source/aux.h new file mode 100644 index 0000000..d9bb0bf --- /dev/null +++ b/usr.sbin/lpr/common_source/aux.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1995 + * 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 + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Auxillary functions to aid portability to other systems. + * These are 4.4BSD routines that are often not found on other systems. + * + * !!!USE THIS FILE ONLY IF YOU ARE NOT RUNNING 4.4BSD!!! + */ + +#ifdef PREPOSIX +#define dirent direct +extern int errno; +#endif + +#ifdef NO_RINDEX +#define index strchr +#define rindex strrchr +#endif + +#ifdef BSDWAIT +#define WAITARG_T(a) ((int *)(a)) +#else +#define WAITARG_T(a) (a) +#endif + +#ifdef SETPGID +#define setpgrp(a, b) setpgid((pid_t)(a), (pid_t)(b)) +#endif + +#ifndef FD_COPY +#define FD_COPY(f, t) memcpy((char *)t, (char *)f, sizeof(*(f))) +#endif + +#ifdef NO_SNPRINTF +int snprintf __P((char *str, size_t n, const char *fmt, ...)); +#endif diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 49f7939..8be8c8d 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -37,11 +37,12 @@ */ #ifndef lint -static char sccsid[] = "@(#)common.c 8.2 (Berkeley) 1/21/94"; +static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> @@ -108,18 +109,20 @@ char *printer; /* printer name */ /* host machine name */ char host[MAXHOSTNAMELEN]; char *from = host; /* client's machine name */ -int sendtorem; /* are we sending to a remote? */ +int remote; /* true if sending files to a remote host */ char *printcapdb[2] = { _PATH_PRINTCAP, 0 }; static int compar __P((const void *, const void *)); /* - * Create a connection to the remote printer server. + * Create a TCP connection to host "rhost" at port "rport". + * If rport == 0, then use the printer service port. * Most of this code comes from rcmd.c. */ int -getport(rhost) +getport(rhost, rport) char *rhost; + int rport; { struct hostent *hp; struct servent *sp; @@ -132,16 +135,24 @@ getport(rhost) */ if (rhost == NULL) fatal("no remote host to connect to"); - hp = gethostbyname(rhost); - if (hp == NULL) - fatal("unknown host %s", rhost); - sp = getservbyname("printer", "tcp"); - if (sp == NULL) - fatal("printer/tcp: unknown service"); bzero((char *)&sin, sizeof(sin)); - bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); - sin.sin_family = hp->h_addrtype; - sin.sin_port = sp->s_port; + sin.sin_addr.s_addr = inet_addr(rhost); + if (sin.sin_addr.s_addr != INADDR_NONE) + sin.sin_family = AF_INET; + else { + hp = gethostbyname(rhost); + if (hp == NULL) + fatal("unknown host %s", rhost); + bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); + sin.sin_family = hp->h_addrtype; + } + if (rport == 0) { + sp = getservbyname("printer", "tcp"); + if (sp == NULL) + fatal("printer/tcp: unknown service"); + sin.sin_port = sp->s_port; + } else + sin.sin_port = htons(rport); /* * Try connecting to the server. @@ -244,8 +255,9 @@ getq(namelist) * realloc the maximum size. */ if (++nitems > arraysz) { + arraysz *= 2; queue = (struct queue **)realloc((char *)queue, - (stbuf.st_size/12) * sizeof(struct queue *)); + arraysz * sizeof(struct queue *)); if (queue == NULL) goto errdone; } @@ -287,8 +299,8 @@ checkremote() register struct hostent *hp; static char errbuf[128]; - sendtorem = 0; /* assume printer is local */ - if (RM != (char *)NULL) { + remote = 0; /* assume printer is local */ + if (RM != NULL) { /* get the official name of the local host */ gethostname(name, sizeof(name)); name[sizeof(name)-1] = '\0'; @@ -313,10 +325,23 @@ checkremote() * if the two hosts are not the same, * then the printer must be remote. */ - if (strcmp(name, hp->h_name) != 0) - sendtorem = 1; + if (strcasecmp(name, hp->h_name) != 0) + remote = 1; } - return (char *)0; + return NULL; +} + +/* sleep n milliseconds */ +void +delay(n) +{ + struct timeval tdelay; + + if (n <= 0 || n > 10000) + fatal("unreasonable delay period (%d)", n); + tdelay.tv_sec = n / 1000; + tdelay.tv_usec = n * 1000 % 1000000; + (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tdelay); } #if __STDC__ diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c index 59d3cc9..34ca840 100644 --- a/usr.sbin/lpr/common_source/displayq.c +++ b/usr.sbin/lpr/common_source/displayq.c @@ -32,11 +32,12 @@ */ #ifndef lint -static char sccsid[] = "@(#)displayq.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <sys/file.h> #include <signal.h> #include <fcntl.h> @@ -124,7 +125,7 @@ displayq(format) fatal("cannot examine spooling area\n"); if (stat(LO, &statb) >= 0) { if (statb.st_mode & 0100) { - if (sendtorem) + if (remote) printf("%s: ", host); printf("Warning: %s is down: ", printer); fd = open(ST, O_RDONLY); @@ -137,7 +138,7 @@ displayq(format) putchar('\n'); } if (statb.st_mode & 010) { - if (sendtorem) + if (remote) printf("%s: ", host); printf("Warning: %s queue is turned off\n", printer); } @@ -150,8 +151,8 @@ displayq(format) else { /* get daemon pid */ cp = current; - while ((*cp = getc(fp)) != EOF && *cp != '\n') - cp++; + while ((i = getc(fp)) != EOF && i != '\n') + *cp++ = i; *cp = '\0'; i = atoi(current); if (i <= 0 || kill(i, 0) < 0) @@ -159,13 +160,13 @@ displayq(format) else { /* read current file name */ cp = current; - while ((*cp = getc(fp)) != EOF && *cp != '\n') - cp++; + while ((i = getc(fp)) != EOF && i != '\n') + *cp++ = i; *cp = '\0'; /* * Print the status file. */ - if (sendtorem) + if (remote) printf("%s: ", host); fd = open(ST, O_RDONLY); if (fd >= 0) { @@ -191,7 +192,7 @@ displayq(format) } free(queue); } - if (!sendtorem) { + if (!remote) { if (nitems == 0) puts("no entries"); return; @@ -215,7 +216,7 @@ displayq(format) (void) strcpy(cp, user[i]); } strcat(line, "\n"); - fd = getport(RM); + fd = getport(RM, 0); if (fd < 0) { if (from != host) printf("%s: ", host); @@ -237,7 +238,7 @@ displayq(format) void warn() { - if (sendtorem) + if (remote) printf("\n%s: ", host); puts("Warning: no daemon present"); current[0] = '\0'; @@ -271,7 +272,7 @@ inform(cf) if (rank < 0) rank = 0; - if (sendtorem || garbage || strcmp(cf, current)) + if (remote || garbage || strcmp(cf, current)) rank++; j = 0; while (getline(cfp)) { @@ -416,7 +417,7 @@ ldump(nfile, file, copies) else printf("%-32s", nfile); if (*file && !stat(file, &lbuf)) - printf(" %qd bytes", lbuf.st_size); + printf(" %ld bytes", (long)lbuf.st_size); else printf(" ??? bytes"); putchar('\n'); diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index 6dd1bf0..ffe42d2 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)lp.h 8.1 (Berkeley) 6/6/93 + * @(#)lp.h 8.2 (Berkeley) 4/28/95 */ @@ -85,7 +85,7 @@ extern char *printer; /* printer name */ /* host machine name */ extern char host[MAXHOSTNAMELEN]; extern char *from; /* client's machine name */ -extern int sendtorem; /* are we sending to a remote? */ +extern int remote; /* true if sending files to a remote host */ extern char *printcapdb[]; /* printcap database array */ /* * Structure used for building a sorted list of control files. @@ -107,7 +107,7 @@ void displayq __P((int)); void dump __P((char *, char *, int)); void fatal __P((const char *, ...)); int getline __P((FILE *)); -int getport __P((char *)); +int getport __P((char *, int)); int getq __P((struct queue *(*[]))); void header __P((void)); void inform __P((char *)); @@ -123,4 +123,5 @@ void rmremote __P((void)); void show __P((char *, char *, int)); int startdaemon __P((char *)); void warn __P((void)); +void delay __P((int)); __END_DECLS diff --git a/usr.sbin/lpr/common_source/printcap.c b/usr.sbin/lpr/common_source/printcap.c index 627d2ce..cbbaef1 100644 --- a/usr.sbin/lpr/common_source/printcap.c +++ b/usr.sbin/lpr/common_source/printcap.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)printcap.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)printcap.c 8.2 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> @@ -52,6 +52,87 @@ static char sccsid[] = "@(#)printcap.c 8.1 (Berkeley) 6/6/93"; #define MAXHOP 32 /* max number of tc= indirections */ /* + * getcap-style interface for the old printcap routines. + * + * !!!USE THIS INTERFACE ONLY IF YOU DON'T HAVE THE REAL GETCAP!!! + */ + +static char *pbp; /* pointer into pbuf for pgetstr() */ +static char pbuf[BUFSIZ]; /* buffer for capability strings */ +extern char line[]; /* buffer for printcap entries */ + +int +cgetnext(bp, db_array) + register char **bp; + char **db_array; +{ + int ret; + char *strdup(); + + pbp = pbuf; + ret = getprent(line); + *bp = strdup(line); + return (ret); +} + +int +cgetent(bp, db_array, name) + char **bp, **db_array, *name; +{ + int i; + + *bp = line; + pbp = pbuf; + i = pgetent(*bp, name); + if (i < 0) + return (-2); + else if (i == 0) + return (-1); + else + return (0); +} + +char * +cgetcap(buf, cap, type) + char *buf, *cap; + int type; +{ + return ((char *) pgetflag(cap)); +} + +int +cgetstr(buf, cap, str) + char *buf, *cap; + char **str; +{ + char *pgetstr __P((char *, char **)); + + if (pbp >= pbuf+BUFSIZ) { + write(2, "Capability string buffer overflow\n", 34); + return (-1); + } + return ((*str = pgetstr(cap, &pbp)) == NULL ? -1 : 0); +} + +int +cgetnum(buf, cap, num) + char *buf, *cap; + long *num; +{ + return ((*num = pgetnum(cap)) < 0 ? -1 : 0); +} + +int +cgetclose() +{ + void endprent __P((void)); + + endprent(); + return (0); +} + + +/* * termcap - routines for dealing with the terminal capability data base * * BUG: Should use a "last" pointer in tbuf, so that searching @@ -83,9 +164,10 @@ static char sccsid[] = "@(#)printcap.c 8.1 (Berkeley) 6/6/93"; static FILE *pfp = NULL; /* printcap data base file pointer */ static char *tbuf; static int hopcount; /* detect infinite loops in termcap, init 0 */ +static int tf; +char *tgetstr __P((char *, char **)); static char *tskip __P((char *)); -static char *tskip __P((char *bp)); static char *tdecode __P((char *, char **)); /* @@ -137,8 +219,18 @@ getprent(bp) void endprent() { - if (pfp != NULL) - fclose(pfp); + if (pfp != NULL) { + /* + * Can't use fclose here because on POSIX-compliant + * systems, fclose() causes the file pointer of the + * underlying file descriptor (which is possibly shared + * with a parent process) to be adjusted, and this + * reeks havoc in the parent because it doesn't know + * the file pointer has changed. + */ + (void) close(fileno(pfp)); + pfp = NULL; + } } /* @@ -154,10 +246,8 @@ tgetent(bp, name) register int c; register int i = 0, cnt = 0; char ibuf[BUFSIZ]; - int tf; tbuf = bp; - tf = 0; #ifndef V6 cp = getenv("TERMCAP"); /* @@ -179,11 +269,9 @@ tgetent(bp, name) } else tf = open(cp, 0); } +#endif if (tf==0) tf = open(_PATH_PRINTCAP, 0); -#else - tf = open(_PATH_PRINTCAP, 0); -#endif if (tf < 0) return (-1); for (;;) { @@ -193,6 +281,7 @@ tgetent(bp, name) cnt = read(tf, ibuf, BUFSIZ); if (cnt <= 0) { close(tf); + tf = 0; return (0); } i = 0; @@ -217,8 +306,13 @@ tgetent(bp, name) * The real work for the match. */ if (tnamatch(name)) { - close(tf); - return(tnchktc()); + lseek(tf, 0L, 0); + i = tnchktc(); + if (tf) { + close(tf); + tf = 0; + } + return(i); } } } @@ -455,4 +549,3 @@ nextc: *area = cp; return (str); } - diff --git a/usr.sbin/lpr/common_source/rmjob.c b/usr.sbin/lpr/common_source/rmjob.c index 74a94d8..bdfe853 100644 --- a/usr.sbin/lpr/common_source/rmjob.c +++ b/usr.sbin/lpr/common_source/rmjob.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)rmjob.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)rmjob.c 8.2 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> @@ -292,7 +292,7 @@ rmremote() register int i, rem; char buf[BUFSIZ]; - if (!sendtorem) + if (!remote) return; /* not sending to a remote machine */ /* @@ -313,7 +313,7 @@ rmremote() (void) sprintf(cp, " %d", requ[i]); } strcat(cp, "\n"); - rem = getport(RM); + rem = getport(RM, 0); if (rem < 0) { if (from != host) printf("%s: ", host); |