remove unsafe calls to strcpy(), strcat(), and sprintf(). some KNF.

This commit is contained in:
mrg 1996-12-09 09:57:40 +00:00
parent 5dc95f5908
commit 077acf5088
13 changed files with 279 additions and 253 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: common.c,v 1.8 1995/11/28 19:43:19 jtc Exp $ */
/* $NetBSD: common.c,v 1.9 1996/12/09 09:57:40 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@ -159,7 +159,7 @@ retry:
return(-1);
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
err = errno;
(void) close(s);
(void)close(s);
errno = err;
if (errno == EADDRINUSE) {
lport--;
@ -249,7 +249,7 @@ getq(namelist)
if (q == NULL)
goto errdone;
q->q_time = stbuf.st_mtime;
strcpy(q->q_name, d->d_name);
strcpy(q->q_name, d->d_name); /* XXX: strcpy is safe */
/*
* Check to make sure the array has space left and
* realloc the maximum size.
@ -305,16 +305,16 @@ checkremote()
name[sizeof(name)-1] = '\0';
hp = gethostbyname(name);
if (hp == (struct hostent *) NULL) {
(void) snprintf(errbuf, sizeof(errbuf),
(void)snprintf(errbuf, sizeof(errbuf),
"unable to get official name for local machine %s",
name);
return errbuf;
} else (void) strcpy(name, hp->h_name);
} else (void)strncpy(name, hp->h_name, MAXHOSTNAMELEN - 1);
/* get the official name of RM */
hp = gethostbyname(RM);
if (hp == (struct hostent *) NULL) {
(void) snprintf(errbuf, sizeof(errbuf),
(void)snprintf(errbuf, sizeof(errbuf),
"unable to get official name for remote machine %s",
RM);
return errbuf;

View File

@ -1,4 +1,4 @@
/* $NetBSD: displayq.c,v 1.7 1995/11/28 19:43:21 jtc Exp $ */
/* $NetBSD: displayq.c,v 1.8 1996/12/09 09:57:41 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@ -140,10 +140,10 @@ displayq(format)
fd = open(ST, O_RDONLY);
seteuid(uid);
if (fd >= 0) {
(void) flock(fd, LOCK_SH);
(void)flock(fd, LOCK_SH);
while ((i = read(fd, line, sizeof(line))) > 0)
(void) fwrite(line, 1, i, stdout);
(void) close(fd); /* unlocks as well */
(void)fwrite(line, 1, i, stdout);
(void)close(fd); /* unlocks as well */
} else
putchar('\n');
}
@ -191,14 +191,14 @@ displayq(format)
fd = open(ST, O_RDONLY);
seteuid(uid);
if (fd >= 0) {
(void) flock(fd, LOCK_SH);
(void)flock(fd, LOCK_SH);
while ((i = read(fd, line, sizeof(line))) > 0)
(void) fwrite(line, 1, i, stdout);
(void) close(fd); /* unlocks as well */
(void)fwrite(line, 1, i, stdout);
(void)close(fd); /* unlocks as well */
} else
putchar('\n');
}
(void) fclose(fp);
(void)fclose(fp);
}
/*
* Now, examine the control files and print out the jobs to
@ -225,31 +225,33 @@ displayq(format)
*/
if (nitems)
putchar('\n');
(void) sprintf(line, "%c%s", format + '\3', RP);
(void)snprintf(line, sizeof(line), "%c%s", format + '\3', RP);
cp = line;
for (i = 0; i < requests; i++) {
cp += strlen(cp);
(void) sprintf(cp, " %d", requ[i]);
(void)snprintf(cp, line - cp, " %d", requ[i]);
}
for (i = 0; i < users; i++) {
cp += strlen(cp);
if (cp - line > sizeof(line) - 1)
break;
*cp++ = ' ';
(void) strcpy(cp, user[i]);
(void)strncpy(cp, user[i], line - cp - 1);
}
strcat(line, "\n");
(void)strncat(line, "\n", sizeof(line) - strlen(line) - 1);
fd = getport(RM);
if (fd < 0) {
if (from != host)
printf("%s: ", host);
printf("connection to %s is down\n", RM);
(void)printf("connection to %s is down\n", RM);
}
else {
i = strlen(line);
if (write(fd, line, i) != i)
fatal("Lost connection");
while ((i = read(fd, line, sizeof(line))) > 0)
(void) fwrite(line, 1, i, stdout);
(void) close(fd);
(void)fwrite(line, 1, i, stdout);
(void)close(fd);
}
}
@ -324,7 +326,7 @@ inform(cf)
if (line[0] < 'a' || line[0] > 'z')
continue;
if (j == 0 || strcmp(file, line+1) != 0)
(void) strcpy(file, line+1);
(void)strncpy(file, line+1, sizeof(file) - 1);
j++;
continue;
case 'N':

View File

@ -1,4 +1,4 @@
/* $NetBSD: printcap.c,v 1.7 1995/11/28 19:43:29 jtc Exp $ */
/* $NetBSD: printcap.c,v 1.8 1996/12/09 09:57:41 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@ -176,10 +176,16 @@ tgetent(bp, name)
* has to already have the newlines crunched out.
*/
if (cp && *cp) {
if (*cp!='/') {
if (*cp != '/') {
cp2 = getenv("TERM");
if (cp2==(char *) 0 || strcmp(name,cp2)==0) {
strcpy(bp,cp);
if (cp2 == (char *) 0 || strcmp(name, cp2) == 0) {
/*
* XXX: strcpy, should perhaps use BUFSIZ
* here, as that's the general length of a
* termcap buffer. Note that this code
* isn't used now anyway.
*/
strcpy(bp, cp);
return(tnchktc());
} else {
seteuid(euid);
@ -268,25 +274,25 @@ tnchktc()
/* p now points to beginning of last field */
if (p[0] != 't' || p[1] != 'c')
return(1);
strcpy(tcname,p+3);
strncpy(tcname, p+3, sizeof(tcname) - 4);
q = tcname;
while (q && *q != ':')
q++;
*q = 0;
*q = '\0';
if (++hopcount > MAXHOP) {
write(2, "Infinite tc= loop\n", 18);
return (0);
}
if (tgetent(tcbuf, tcname) != 1)
return(0);
for (q=tcbuf; *q != ':'; q++)
for (q = tcbuf; *q != ':'; q++)
;
l = p - holdtbuf + strlen(q);
if (l > BUFSIZ) {
write(2, "Termcap entry too long\n", 23);
q[BUFSIZ - (p-tbuf)] = 0;
}
strcpy(p, q+1);
strcpy(p, q+1); /* XXX: strcpy is safe from above test */
tbuf = holdtbuf;
return(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rmjob.c,v 1.7 1995/11/28 19:43:31 jtc Exp $ */
/* $NetBSD: rmjob.c,v 1.8 1996/12/09 09:57:42 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
@ -174,12 +174,12 @@ lockchk(s)
}
seteuid(uid);
if (!getline(fp)) {
(void) fclose(fp);
(void)fclose(fp);
return(0); /* no daemon present */
}
cur_daemon = atoi(line);
if (kill(cur_daemon, 0) < 0 && errno != EPERM) {
(void) fclose(fp);
(void)fclose(fp);
return(0); /* no daemon present */
}
for (i = 1; (n = fread(current, sizeof(char), sizeof(current), fp)) <= 0; i++) {
@ -190,7 +190,7 @@ lockchk(s)
sleep(i);
}
current[n-1] = '\0';
(void) fclose(fp);
(void)fclose(fp);
return(1);
}
@ -215,7 +215,7 @@ process(file)
do_unlink(line+1);
}
}
(void) fclose(cfp);
(void)fclose(cfp);
do_unlink(file);
}
@ -264,7 +264,7 @@ chk(file)
if (line[0] == 'P')
break;
}
(void) fclose(cfp);
(void)fclose(cfp);
if (line[0] != 'P')
return(0);
@ -314,9 +314,8 @@ isowner(owner, file)
void
rmremote()
{
register char *cp;
register int i, rem;
char buf[BUFSIZ];
register char *cp, *s;
register int i, rem, len;
if (!sendtorem)
return; /* not sending to a remote machine */
@ -327,30 +326,47 @@ rmremote()
*/
fflush(stdout);
(void)snprintf(buf, sizeof(buf), "\5%s %s", RP, all ? "-all" : person);
cp = buf;
/* \5 RP space all */
len = 1 + strlen(RP) + 1 + strlen(all ? "-all" : person);
for (i = 0; i < users; i++) {
cp += strlen(cp);
*cp++ = ' ';
strcpy(cp, user[i]);
len += strlen(user[i]) + 1;
}
for (i = 0; i < requests; i++) {
cp += strlen(cp);
(void) sprintf(cp, " %d", requ[i]);
len += snprintf(line, sizeof(line), " %d", requ[i]);
}
strcat(cp, "\n");
len += 1;
if (len > sizeof(line))
s = malloc(len);
else
s = line;
cp = s;
cp += snprintf(s, len, "\5%s %s", RP, all ? "-all" : person);
for (i = 0; i < users; i++) {
*cp++ = ' ';
strncpy(cp, user[i], len - (cp - s) - 2);
cp += strlen(cp);
}
for (i = 0; i < requests; i++) {
(void)snprintf(cp, len - (cp - s) - 2, " %d", requ[i]);
cp += strlen(cp);
}
cp[0] = '\n';
cp[1] = '\0';
rem = getport(RM);
if (rem < 0) {
if (from != host)
printf("%s: ", host);
printf("connection to %s is down\n", RM);
} else {
i = strlen(buf);
if (write(rem, buf, i) != i)
if (write(rem, s, len) != i)
fatal("Lost connection");
while ((i = read(rem, buf, sizeof(buf))) > 0)
(void) fwrite(buf, 1, i, stdout);
(void) close(rem);
if (len > sizeof(line))
(void)free(s);
while ((i = read(rem, line, sizeof(line))) > 0)
(void)fwrite(line, 1, i, stdout);
(void)close(rem);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: startdaemon.c,v 1.7 1995/11/28 19:43:32 jtc Exp $ */
/* $NetBSD: startdaemon.c,v 1.8 1996/12/09 09:57:43 mrg Exp $ */
/*
* Copyright (c) 1983, 1993, 1994
@ -73,7 +73,7 @@ startdaemon(printer)
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
strcpy(un.sun_path, _PATH_SOCKETNAME);
strncpy(un.sun_path, _PATH_SOCKETNAME, sizeof(un.sun_path) - 1);
#ifndef SUN_LEN
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
#endif
@ -81,27 +81,26 @@ startdaemon(printer)
if (connect(s, (struct sockaddr *)&un, SUN_LEN(&un)) < 0) {
seteuid(uid);
perr("connect");
(void) close(s);
(void)close(s);
return(0);
}
seteuid(uid);
(void) sprintf(buf, "\1%s\n", printer);
n = strlen(buf);
n = snprintf(buf, sizeof(buf), "\1%s\n", printer);
if (write(s, buf, n) != n) {
perr("write");
(void) close(s);
(void)close(s);
return(0);
}
if (read(s, buf, 1) == 1) {
if (buf[0] == '\0') { /* everything is OK */
(void) close(s);
(void)close(s);
return(1);
}
putchar(buf[0]);
}
while ((n = read(s, buf, sizeof(buf))) > 0)
fwrite(buf, 1, n, stdout);
(void) close(s);
(void)close(s);
return(0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.7 1996/01/14 17:25:21 hpeyerl Exp $ */
/* $NetBSD: cmds.c,v 1.8 1996/12/09 09:57:44 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -137,7 +137,7 @@ abortpr(dis)
SD = _PATH_DEFSPOOL;
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
printf("%s:\n", printer);
/*
@ -156,7 +156,7 @@ abortpr(dis)
if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0)
printf("\tcannot create lock file\n");
else {
(void) close(fd);
(void)close(fd);
upstat("printing disabled\n");
printf("\tprinting disabled\n");
printf("\tno daemon to abort\n");
@ -175,11 +175,11 @@ abortpr(dis)
goto out;
}
if (!getline(fp) || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) {
(void) fclose(fp); /* unlocks as well */
(void)fclose(fp); /* unlocks as well */
printf("\tno daemon to abort\n");
goto out;
}
(void) fclose(fp);
(void)fclose(fp);
if (kill(pid = atoi(line), SIGTERM) < 0)
printf("\tWarning: daemon (pid %d) not killed\n", pid);
else
@ -200,19 +200,19 @@ upstat(msg)
if (cgetstr(bp, "st", &ST) == -1)
ST = DEFSTAT;
(void) sprintf(statfile, "%s/%s", SD, ST);
(void)snprintf(statfile, sizeof(statfile), "%s/%s", SD, ST);
umask(0);
fd = open(statfile, O_WRONLY|O_CREAT, 0664);
if (fd < 0 || flock(fd, LOCK_EX) < 0) {
printf("\tcannot create status file\n");
return;
}
(void) ftruncate(fd, 0);
(void)ftruncate(fd, 0);
if (msg == (char *)NULL)
(void) write(fd, "\n", 1);
(void)write(fd, "\n", 1);
else
(void) write(fd, msg, strlen(msg));
(void) close(fd);
(void)write(fd, msg, strlen(msg));
(void)close(fd);
}
/*
@ -310,6 +310,7 @@ cleanpr()
SD = _PATH_DEFSPOOL;
printf("%s:\n", printer);
/* XXX depends on SD being non nul */
for (lp = line, cp = SD; *lp++ = *cp++; )
;
lp[-1] = '/';
@ -336,7 +337,8 @@ cleanpr()
n++;
}
if (n == 0) {
strcpy(lp, cp);
strncpy(lp, cp, sizeof(line) - strlen(line) - 1);
line[sizeof(line) - 1] = '\0';
unlinkf(line);
}
} else {
@ -345,7 +347,8 @@ cleanpr()
* been skipped above) or a tf file (which can always
* be removed).
*/
strcpy(lp, cp);
strncpy(lp, cp, sizeof(line) - strlen(line) - 1);
line[sizeof(line) - 1] = '\0';
unlinkf(line);
}
} while (++i < nitems);
@ -415,7 +418,7 @@ enablepr()
SD = _PATH_DEFSPOOL;
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
printf("%s:\n", printer);
/*
@ -484,7 +487,7 @@ disablepr()
SD = _PATH_DEFSPOOL;
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
printf("%s:\n", printer);
/*
* Turn on the group execute bit of the lock file to disable queuing.
@ -499,7 +502,7 @@ disablepr()
if ((fd = open(line, O_WRONLY|O_CREAT, 0670)) < 0)
printf("\tcannot create lock file\n");
else {
(void) close(fd);
(void)close(fd);
printf("\tqueuing disabled\n");
}
} else
@ -570,7 +573,7 @@ putmsg(argc, argv)
* Turn on the group execute bit of the lock file to disable queuing and
* turn on the owner execute bit of the lock file to disable printing.
*/
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
seteuid(euid);
if (stat(line, &stbuf) >= 0) {
if (chmod(line, (stbuf.st_mode & 0777) | 0110) < 0)
@ -581,7 +584,7 @@ putmsg(argc, argv)
if ((fd = open(line, O_WRONLY|O_CREAT, 0770)) < 0)
printf("\tcannot create lock file\n");
else {
(void) close(fd);
(void)close(fd);
printf("\tprinter and queuing disabled\n");
}
seteuid(uid);
@ -591,7 +594,7 @@ putmsg(argc, argv)
/*
* Write the message into the status file.
*/
(void) sprintf(line, "%s/%s", SD, ST);
(void)snprintf(line, sizeof(line), "%s/%s", SD, ST);
fd = open(line, O_WRONLY|O_CREAT, 0664);
if (fd < 0 || flock(fd, LOCK_EX) < 0) {
printf("\tcannot create status file\n");
@ -599,10 +602,10 @@ putmsg(argc, argv)
return;
}
seteuid(uid);
(void) ftruncate(fd, 0);
(void)ftruncate(fd, 0);
if (argc <= 0) {
(void) write(fd, "\n", 1);
(void) close(fd);
(void)write(fd, "\n", 1);
(void)close(fd);
return;
}
cp1 = buf;
@ -614,8 +617,8 @@ putmsg(argc, argv)
}
cp1[-1] = '\n';
*cp1 = '\0';
(void) write(fd, buf, strlen(buf));
(void) close(fd);
(void)write(fd, buf, strlen(buf));
(void)close(fd);
}
/*
@ -727,7 +730,7 @@ startpr(enable)
SD = _PATH_DEFSPOOL;
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
printf("%s:\n", printer);
/*
@ -804,7 +807,7 @@ prstat()
if (cgetstr(bp, "st", &ST) == -1)
ST = DEFSTAT;
printf("%s:\n", printer);
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
if (stat(line, &stbuf) >= 0) {
printf("\tqueuing is %s\n",
(stbuf.st_mode & 010) ? "disabled" : "enabled");
@ -832,19 +835,19 @@ prstat()
printf("\t%d entries in spool area\n", i);
fd = open(line, O_RDONLY);
if (fd < 0 || flock(fd, LOCK_SH|LOCK_NB) == 0) {
(void) close(fd); /* unlocks as well */
(void)close(fd); /* unlocks as well */
printf("\tprinter idle\n");
return;
}
(void) close(fd);
(void)close(fd);
putchar('\t');
(void) sprintf(line, "%s/%s", SD, ST);
(void)snprintf(line, sizeof(line), "%s/%s", SD, ST);
fd = open(line, O_RDONLY);
if (fd >= 0) {
(void) flock(fd, LOCK_SH);
(void)flock(fd, LOCK_SH);
while ((i = read(fd, line, sizeof(line))) > 0)
(void) fwrite(line, 1, i, stdout);
(void) close(fd); /* unlocks as well */
(void)fwrite(line, 1, i, stdout);
(void)close(fd); /* unlocks as well */
}
}
@ -902,7 +905,7 @@ stoppr()
SD = _PATH_DEFSPOOL;
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) sprintf(line, "%s/%s", SD, LO);
(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
printf("%s:\n", printer);
/*
@ -920,7 +923,7 @@ stoppr()
if ((fd = open(line, O_WRONLY|O_CREAT, 0760)) < 0)
printf("\tcannot create lock file\n");
else {
(void) close(fd);
(void)close(fd);
upstat("printing disabled\n");
printf("\tprinting disabled\n");
}
@ -999,7 +1002,7 @@ topq(argc, argv)
*/
seteuid(euid);
if (changed && stat(LO, &stbuf) >= 0)
(void) chmod(LO, (stbuf.st_mode & 0777) | 01);
(void)chmod(LO, (stbuf.st_mode & 0777) | 01);
out:
seteuid(uid);
@ -1086,7 +1089,7 @@ doarg(job)
while (getline(fp) > 0)
if (line[0] == 'P')
break;
(void) fclose(fp);
(void)fclose(fp);
if (line[0] != 'P' || strcmp(job, line+1) != 0)
continue;
if (touch(*qq) == 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: lpd.c,v 1.8 1996/09/21 15:57:22 perry Exp $ */
/* $NetBSD: lpd.c,v 1.9 1996/12/09 09:57:45 mrg Exp $ */
/*
* Copyright (c) 1983, 1993, 1994
@ -151,7 +151,7 @@ main(argc, argv)
openlog("lpd", LOG_PID, LOG_LPR);
syslog(LOG_INFO, "restarted");
(void) umask(0);
(void)umask(0);
lfd = open(_PATH_MASTERLOCK, O_WRONLY|O_CREAT, 0644);
if (lfd < 0) {
syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);
@ -167,7 +167,7 @@ main(argc, argv)
/*
* write process id for others to know
*/
sprintf(line, "%u\n", getpid());
(void)snprintf(line, sizeof(line), "%u\n", getpid());
f = strlen(line);
if (write(lfd, line, f) != f) {
syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);
@ -178,7 +178,7 @@ main(argc, argv)
* Restart all the printers.
*/
startup();
(void) unlink(_PATH_SOCKETNAME);
(void)unlink(_PATH_SOCKETNAME);
funix = socket(AF_UNIX, SOCK_STREAM, 0);
if (funix < 0) {
syslog(LOG_ERR, "socket: %m");
@ -192,7 +192,7 @@ main(argc, argv)
signal(SIGTERM, mcleanup);
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
strcpy(un.sun_path, _PATH_SOCKETNAME);
strncpy(un.sun_path, _PATH_SOCKETNAME, sizeof(un.sun_path) - 1);
#ifndef SUN_LEN
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
#endif
@ -267,11 +267,11 @@ main(argc, argv)
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
(void) close(funix);
(void)close(funix);
if (!sflag)
(void) close(finet);
(void)close(finet);
dup2(s, 1);
(void) close(s);
(void)close(s);
if (domain == AF_INET) {
from_remote = 1;
chkhost(&frominet);
@ -280,7 +280,7 @@ main(argc, argv)
doit();
exit(0);
}
(void) close(s);
(void)close(s);
}
}
@ -485,7 +485,7 @@ chkhost(f)
fatal("Host name for your address (%s) unknown",
inet_ntoa(f->sin_addr));
(void) strncpy(fromb, hp->h_name, sizeof(fromb));
(void)strncpy(fromb, hp->h_name, sizeof(fromb) - 1);
from[sizeof(fromb) - 1] = '\0';
from = fromb;
@ -494,10 +494,10 @@ again:
if (hostf) {
if (__ivaliduser(hostf, f->sin_addr.s_addr,
DUMMY, DUMMY) == 0) {
(void) fclose(hostf);
(void)fclose(hostf);
return;
}
(void) fclose(hostf);
(void)fclose(hostf);
}
if (first == 1) {
first = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: printjob.c,v 1.10 1996/06/30 23:55:49 jtc Exp $ */
/* $NetBSD: printjob.c,v 1.11 1996/12/09 09:57:46 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -141,11 +141,11 @@ printjob()
int count = 0;
init(); /* set up capabilities */
(void) write(1, "", 1); /* ack that daemon is started */
(void) close(2); /* set up log file */
(void)write(1, "", 1); /* ack that daemon is started */
(void)close(2); /* set up log file */
if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
syslog(LOG_ERR, "%s: %m", LF);
(void) open(_PATH_DEVNULL, O_WRONLY);
(void)open(_PATH_DEVNULL, O_WRONLY);
}
setgid(getegid());
pid = getpid(); /* for use with lprm */
@ -155,7 +155,7 @@ printjob()
signal(SIGQUIT, abortpr);
signal(SIGTERM, abortpr);
(void) mktemp(tempfile);
(void)mktemp(tempfile);
/*
* uses short form file names
@ -181,8 +181,7 @@ printjob()
/*
* write process id for others to know
*/
sprintf(line, "%u\n", pid);
pidoff = i = strlen(line);
pidoff = i = snprintf(line, sizeof(line), "%u\n", pid);
if (write(lfd, line, i) != i) {
syslog(LOG_ERR, "%s: %s: %m", printer, LO);
exit(1);
@ -212,9 +211,8 @@ again:
if (stat(q->q_name, &stb) < 0)
continue;
restart:
(void) lseek(lfd, (off_t)pidoff, 0);
(void) sprintf(line, "%s\n", q->q_name);
i = strlen(line);
(void)lseek(lfd, (off_t)pidoff, 0);
i = snprintf(line, sizeof(line), "%s\n", q->q_name);
if (write(lfd, line, i) != i)
syslog(LOG_ERR, "%s: %s: %m", printer, LO);
if (!remote)
@ -245,12 +243,12 @@ again:
syslog(LOG_INFO, "restarting %s", printer);
if (ofilter > 0) {
kill(ofilter, SIGCONT); /* to be sure */
(void) close(ofd);
(void)close(ofd);
while ((i = wait(0)) > 0 && i != ofilter)
;
ofilter = 0;
}
(void) close(pfd); /* close printer */
(void)close(pfd); /* close printer */
if (ftruncate(lfd, pidoff) < 0)
syslog(LOG_WARNING, "%s: %s: %m", printer, LO);
openpr(); /* try to reopen printer */
@ -269,17 +267,18 @@ again:
done:
if (count > 0) { /* Files actually printed */
if (!SF && !tof)
(void) write(ofd, FF, strlen(FF));
(void)write(ofd, FF, strlen(FF));
if (TR != NULL) /* output trailer */
(void) write(ofd, TR, strlen(TR));
(void)write(ofd, TR, strlen(TR));
}
(void) unlink(tempfile);
(void)unlink(tempfile);
exit(0);
}
goto again;
}
char fonts[4][50]; /* fonts for troff */
#define FONTLEN 50
char fonts[4][FONTLEN]; /* fonts for troff */
char ifonts[4][40] = {
_PATH_VFONTR,
@ -311,9 +310,10 @@ printit(file)
* Reset troff fonts.
*/
for (i = 0; i < 4; i++)
strcpy(fonts[i], ifonts[i]);
sprintf(&width[2], "%d", PW);
strcpy(indent+2, "0");
strncpy(fonts[i], ifonts[i], FONTLEN);
(void)snprintf(&width[2], sizeof(width) - 2, "%d", PW);
indent[2] = '0';
indent[3] = '\0';
/*
* read the control file for work to do
@ -356,13 +356,13 @@ printit(file)
while (getline(cfp))
switch (line[0]) {
case 'H':
strcpy(fromhost, line+1);
strncpy(fromhost, line+1, sizeof(fromhost) - 1);
if (class[0] == '\0')
strncpy(class, line+1, sizeof(class)-1);
strncpy(class, line+1, sizeof(class) - 1);
continue;
case 'P':
strncpy(logname, line+1, sizeof(logname)-1);
strncpy(logname, line+1, sizeof(logname) - 1);
if (RS) { /* restricted */
if (getpwnam(logname) == NULL) {
bombed = NOACCT;
@ -387,20 +387,22 @@ printit(file)
case 'J':
if (line[1] != '\0')
strncpy(jobname, line+1, sizeof(jobname)-1);
else
strcpy(jobname, " ");
strncpy(jobname, line+1, sizeof(jobname) - 1);
else {
jobname[0] = ' ';
jobname[1] = '\0';
}
continue;
case 'C':
if (line[1] != '\0')
strncpy(class, line+1, sizeof(class)-1);
strncpy(class, line+1, sizeof(class) - 1);
else if (class[0] == '\0')
gethostname(class, sizeof(class));
continue;
case 'T': /* header title for pr */
strncpy(title, line+1, sizeof(title)-1);
strncpy(title, line+1, sizeof(title) - 1);
continue;
case 'L': /* identification line */
@ -413,15 +415,15 @@ printit(file)
case '3':
case '4':
if (line[1] != '\0')
strcpy(fonts[line[0]-'1'], line+1);
strncpy(fonts[line[0]-'1'], line+1, FONTLEN - 1);
continue;
case 'W': /* page width */
strncpy(width+2, line+1, sizeof(width)-3);
strncpy(width+2, line+1, sizeof(width) - 3);
continue;
case 'I': /* indent amount */
strncpy(indent+2, line+1, sizeof(indent)-3);
strncpy(indent+2, line+1, sizeof(indent) - 3);
continue;
default: /* some file to print */
@ -431,7 +433,7 @@ printit(file)
bombed = FATALERR;
break;
case REPRINT:
(void) fclose(cfp);
(void)fclose(cfp);
return(REPRINT);
case FILTERERR:
case ACCESS:
@ -464,13 +466,13 @@ pass2:
continue;
case 'U':
(void) unlink(line+1);
(void)unlink(line+1);
}
/*
* clean-up in case another control file exists
*/
(void) fclose(cfp);
(void) unlink(file);
(void)fclose(cfp);
(void)unlink(file);
return(bombed == OK ? OK : ERROR);
}
@ -509,17 +511,17 @@ print(format, file)
(stb.st_dev != fdev || stb.st_ino != fino))
return(ACCESS);
if (!SF && !tof) { /* start on a fresh page */
(void) write(ofd, FF, strlen(FF));
(void)write(ofd, FF, strlen(FF));
tof = 1;
}
if (IF == NULL && (format == 'f' || format == 'l')) {
tof = 0;
while ((n = read(fi, buf, BUFSIZ)) > 0)
if (write(ofd, buf, n) != n) {
(void) close(fi);
(void)close(fi);
return(REPRINT);
}
(void) close(fi);
(void)close(fi);
return(OK);
}
switch (format) {
@ -540,17 +542,17 @@ print(format, file)
dup2(fi, 0); /* file is stdin */
dup2(p[1], 1); /* pipe is stdout */
for (n = 3; n < NOFILE; n++)
(void) close(n);
(void)close(n);
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 */
(void) close(fi);
(void)close(p[1]); /* close output side */
(void)close(fi);
if (prchild < 0) {
prchild = 0;
(void) close(p[0]);
(void)close(p[0]);
return(ERROR);
}
fi = p[0]; /* use pipe for input */
@ -578,19 +580,19 @@ print(format, file)
case 't': /* print troff output */
case 'n': /* print ditroff output */
case 'd': /* print tex output */
(void) unlink(".railmag");
(void)unlink(".railmag");
if ((fo = creat(".railmag", FILMOD)) < 0) {
syslog(LOG_ERR, "%s: cannot create .railmag", printer);
(void) unlink(".railmag");
(void)unlink(".railmag");
} else {
for (n = 0; n < 4; n++) {
if (fonts[n][0] != '/')
(void) write(fo, _PATH_VFONT,
(void)write(fo, _PATH_VFONT,
sizeof(_PATH_VFONT) - 1);
(void) write(fo, fonts[n], strlen(fonts[n]));
(void) write(fo, "\n", 1);
(void)write(fo, fonts[n], strlen(fonts[n]));
(void)write(fo, "\n", 1);
}
(void) close(fo);
(void)close(fo);
}
prog = (format == 't') ? TF : (format == 'n') ? NF : DF;
av[1] = pxwidth;
@ -616,7 +618,7 @@ print(format, file)
n = 3;
break;
default:
(void) close(fi);
(void)close(fi);
syslog(LOG_ERR, "%s: illegal format character '%c'",
printer, format);
return(ERROR);
@ -638,7 +640,7 @@ print(format, file)
wait3((int *)&status, WUNTRACED, 0)) > 0 && pid != ofilter)
;
if (status.w_stopval != WSTOPPED) {
(void) close(fi);
(void)close(fi);
syslog(LOG_WARNING, "%s: output filter died (%d)",
printer, status.w_retcode);
return(REPRINT);
@ -653,12 +655,12 @@ start:
if (n >= 0)
dup2(n, 2);
for (n = 3; n < NOFILE; n++)
(void) close(n);
(void)close(n);
execv(prog, av);
syslog(LOG_ERR, "cannot execv %s", prog);
exit(2);
}
(void) close(fi);
(void)close(fi);
if (child < 0)
status.w_retcode = 100;
else
@ -748,7 +750,7 @@ sendit(file)
continue;
}
if (line[0] >= 'a' && line[0] <= 'z') {
strcpy(last, line);
strncpy(last, line, sizeof(last) - 1);
while (i = getline(cfp))
if (strcmp(last, line))
break;
@ -758,7 +760,7 @@ sendit(file)
goto again;
break;
case REPRINT:
(void) fclose(cfp);
(void)fclose(cfp);
return(REPRINT);
case ACCESS:
sendmail(logname, ACCESS);
@ -769,7 +771,7 @@ sendit(file)
}
}
if (err == OK && sendfile('\2', file) > 0) {
(void) fclose(cfp);
(void)fclose(cfp);
return(REPRINT);
}
/*
@ -778,12 +780,12 @@ sendit(file)
fseek(cfp, 0L, 0);
while (getline(cfp))
if (line[0] == 'U')
(void) unlink(line+1);
(void)unlink(line+1);
/*
* clean-up in case another control file exists
*/
(void) fclose(cfp);
(void) unlink(file);
(void)fclose(cfp);
(void)unlink(file);
return(err);
}
@ -811,12 +813,11 @@ sendfile(type, file)
if ((stb.st_mode & S_IFMT) == S_IFLNK && fstat(f, &stb) == 0 &&
(stb.st_dev != fdev || stb.st_ino != fino))
return(ACCESS);
(void) sprintf(buf, "%c%qd %s\n", type, stb.st_size, file);
amt = strlen(buf);
amt = snprintf(buf, sizeof(buf), "%c%qd %s\n", type, stb.st_size, file);
for (i = 0; ; i++) {
if (write(pfd, buf, amt) != amt ||
(resp = response()) < 0 || resp == '\1') {
(void) close(f);
(void)close(f);
return(REPRINT);
} else if (resp == '\0')
break;
@ -837,7 +838,7 @@ sendfile(type, file)
if (sizerr == 0 && read(f, buf, amt) != amt)
sizerr = 1;
if (write(pfd, buf, amt) != amt) {
(void) close(f);
(void)close(f);
return(REPRINT);
}
}
@ -845,11 +846,11 @@ sendfile(type, file)
(void) close(f);
(void)close(f);
if (sizerr) {
syslog(LOG_INFO, "%s: %s: changed size", printer, file);
/* tell recvjob to ignore this file */
(void) write(pfd, "\1", 1);
(void)write(pfd, "\1", 1);
return(ERROR);
}
if (write(pfd, "", 1) != 1 || response())
@ -886,35 +887,35 @@ banner(name1, name2)
time(&tvec);
if (!SF && !tof)
(void) write(ofd, FF, strlen(FF));
(void)write(ofd, FF, strlen(FF));
if (SB) { /* short banner only */
if (class[0]) {
(void) write(ofd, class, strlen(class));
(void) write(ofd, ":", 1);
(void)write(ofd, class, strlen(class));
(void)write(ofd, ":", 1);
}
(void) write(ofd, name1, strlen(name1));
(void) write(ofd, " Job: ", 7);
(void) write(ofd, name2, strlen(name2));
(void) write(ofd, " Date: ", 8);
(void) write(ofd, ctime(&tvec), 24);
(void) write(ofd, "\n", 1);
(void)write(ofd, name1, strlen(name1));
(void)write(ofd, " Job: ", 7);
(void)write(ofd, name2, strlen(name2));
(void)write(ofd, " Date: ", 8);
(void)write(ofd, ctime(&tvec), 24);
(void)write(ofd, "\n", 1);
} else { /* normal banner */
(void) write(ofd, "\n\n\n", 3);
(void)write(ofd, "\n\n\n", 3);
scan_out(ofd, name1, '\0');
(void) write(ofd, "\n\n", 2);
(void)write(ofd, "\n\n", 2);
scan_out(ofd, name2, '\0');
if (class[0]) {
(void) write(ofd,"\n\n\n",3);
(void)write(ofd,"\n\n\n",3);
scan_out(ofd, class, '\0');
}
(void) write(ofd, "\n\n\n\n\t\t\t\t\tJob: ", 15);
(void) write(ofd, name2, strlen(name2));
(void) write(ofd, "\n\t\t\t\t\tDate: ", 12);
(void) write(ofd, ctime(&tvec), 24);
(void) write(ofd, "\n", 1);
(void)write(ofd, "\n\n\n\n\t\t\t\t\tJob: ", 15);
(void)write(ofd, name2, strlen(name2));
(void)write(ofd, "\n\t\t\t\t\tDate: ", 12);
(void)write(ofd, ctime(&tvec), 24);
(void)write(ofd, "\n", 1);
}
if (!SF)
(void) write(ofd, FF, strlen(FF));
(void)write(ofd, FF, strlen(FF));
tof = 1;
}
@ -965,7 +966,7 @@ scan_out(scfd, scsp, dlm)
;
strp++;
*strp++ = '\n';
(void) write(scfd, outbuf, strp-outbuf);
(void)write(scfd, outbuf, strp-outbuf);
}
}
@ -1010,12 +1011,12 @@ sendmail(user, bombed)
if ((s = dofork(DORETURN)) == 0) { /* child */
dup2(p[0], 0);
for (i = 3; i < NOFILE; i++)
(void) close(i);
(void)close(i);
if ((cp = rindex(_PATH_SENDMAIL, '/')) != NULL)
cp++;
else
cp = _PATH_SENDMAIL;
sprintf(buf, "%s@%s", user, fromhost);
(void)snprintf(buf, sizeof(buf), "%s@%s", user, fromhost);
execl(_PATH_SENDMAIL, cp, buf, 0);
exit(0);
} else if (s > 0) { /* parent */
@ -1045,16 +1046,16 @@ sendmail(user, bombed)
printf("\nwas printed but had the following errors:\n");
while ((i = getc(fp)) != EOF)
putchar(i);
(void) fclose(fp);
(void)fclose(fp);
break;
case ACCESS:
printf("\nwas not printed because it was not linked to the original file\n");
}
fflush(stdout);
(void) close(1);
(void)close(1);
}
(void) close(p[0]);
(void) close(p[1]);
(void)close(p[0]);
(void)close(p[1]);
wait(&s);
}
@ -1110,7 +1111,7 @@ static void
abortpr(signo)
int signo;
{
(void) unlink(tempfile);
(void)unlink(tempfile);
kill(0, SIGINT);
if (ofilter > 0)
kill(ofilter, SIGCONT);
@ -1152,16 +1153,16 @@ init()
FF = DEFFF;
if (cgetnum(bp, "pw", &PW) < 0)
PW = DEFWIDTH;
sprintf(&width[2], "%d", PW);
(void)snprintf(&width[2], sizeof(width) - 2, "%d", PW);
if (cgetnum(bp, "pl", &PL) < 0)
PL = DEFLENGTH;
sprintf(&length[2], "%d", PL);
(void)snprintf(&length[2], sizeof(length) - 2, "%d", PL);
if (cgetnum(bp,"px", &PX) < 0)
PX = 0;
sprintf(&pxwidth[2], "%d", PX);
(void)snprintf(&pxwidth[2], sizeof(pxwidth) - 2, "%d", PX);
if (cgetnum(bp, "py", &PY) < 0)
PY = 0;
sprintf(&pxlength[2], "%d", PY);
(void)snprintf(&pxlength[2], sizeof(pxlength) - 2, "%d", PY);
cgetstr(bp, "rm", &RM);
if (s = checkremote())
syslog(LOG_WARNING, s);
@ -1229,12 +1230,11 @@ openpr()
resp = -1;
pfd = getport(RM);
if (pfd >= 0) {
(void) sprintf(line, "\2%s\n", RP);
n = strlen(line);
n = snprintf(line, sizeof(line), "\2%s\n", RP);
if (write(pfd, line, n) == n &&
(resp = response()) == '\0')
break;
(void) close(pfd);
(void)close(pfd);
}
if (i == 1) {
if (resp < 0)
@ -1265,7 +1265,7 @@ openpr()
dup2(p[0], 0); /* pipe is std in */
dup2(pfd, 1); /* printer is std out */
for (i = 3; i < NOFILE; i++)
(void) close(i);
(void)close(i);
if ((cp = rindex(OF, '/')) == NULL)
cp = OF;
else
@ -1274,7 +1274,7 @@ openpr()
syslog(LOG_ERR, "%s: %s: %m", printer, OF);
exit(1);
}
(void) close(p[0]); /* close input side */
(void)close(p[0]); /* close input side */
ofd = p[1]; /* use pipe for output */
} else {
ofd = pfd;
@ -1428,9 +1428,9 @@ pstatus(msg, va_alist)
exit(1);
}
ftruncate(fd, 0);
(void)vsnprintf(buf, sizeof(buf), msg, ap);
(void)vsnprintf(buf, sizeof(buf) - 2, msg, ap);
va_end(ap);
strcat(buf, "\n");
(void) write(fd, buf, strlen(buf));
(void) close(fd);
strncat(buf, "\n", 2);
(void)write(fd, buf, strlen(buf));
(void)close(fd);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: recvjob.c,v 1.6 1995/11/15 22:49:58 pk Exp $ */
/* $NetBSD: recvjob.c,v 1.7 1996/12/09 09:57:47 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -64,7 +64,7 @@ static char sccsid[] = "@(#)recvjob.c 8.1 (Berkeley) 6/6/93";
#include "extern.h"
#include "pathnames.h"
#define ack() (void) write(1, sp, 1);
#define ack() (void)write(1, sp, 1);
static char dfname[40]; /* data files */
static int minfree; /* keep at least minfree blocks available */
@ -103,10 +103,10 @@ recvjob()
if (cgetstr(bp, "lo", &LO) == -1)
LO = DEFLOCK;
(void) close(2); /* set up log file */
(void)close(2); /* set up log file */
if (open(LF, O_WRONLY|O_APPEND, 0664) < 0) {
syslog(LOG_ERR, "%s: %m", LF);
(void) open(_PATH_DEVNULL, O_WRONLY);
(void)open(_PATH_DEVNULL, O_WRONLY);
}
if (chdir(SD) < 0)
@ -170,11 +170,11 @@ readjob()
* something different than what gethostbyaddr()
* returns
*/
strcpy(cp + 6, from);
strcpy(tfname, cp);
(void)strncpy(cp + 6, from, sizeof(line) - strlen(line) - 1);
(void)strncpy(tfname, cp, sizeof(tfname) - 1);
tfname[0] = 't';
if (!chksize(size)) {
(void) write(1, "\2", 1);
(void)write(1, "\2", 1);
continue;
}
if (!readfile(tfname, size)) {
@ -183,7 +183,7 @@ readjob()
}
if (link(tfname, cp) < 0)
frecverr("%s: %m", tfname);
(void) unlink(tfname);
(void)unlink(tfname);
tfname[0] = '\0';
nfiles++;
continue;
@ -195,14 +195,14 @@ readjob()
if (*cp++ != ' ')
break;
if (!chksize(size)) {
(void) write(1, "\2", 1);
(void)write(1, "\2", 1);
continue;
}
(void) strcpy(dfname, cp);
(void)strncpy(dfname, cp, sizeof(dfname) - 1);
if (index(dfname, '/'))
frecverr("readjob: %s: illegal path name",
dfname);
(void) readfile(dfname, size);
(void)readfile(dfname, size);
continue;
}
frecverr("protocol screwup: %s", line);
@ -247,11 +247,11 @@ readfile(file, size)
break;
}
}
(void) close(fd);
(void)close(fd);
if (err)
frecverr("%s: write error", file);
if (noresponse()) { /* file sent had bad data in it */
(void) unlink(file);
(void)unlink(file);
return(0);
}
ack();
@ -317,11 +317,11 @@ rcleanup(signo)
int signo;
{
if (tfname[0])
(void) unlink(tfname);
(void)unlink(tfname);
if (dfname[0])
do {
do
(void) unlink(dfname);
(void)unlink(dfname);
while (dfname[2]-- != 'A');
dfname[2] = 'z';
} while (dfname[0]-- != 'd');

View File

@ -1,4 +1,4 @@
/* $NetBSD: lpr.c,v 1.12 1996/10/25 22:07:53 explorer Exp $ */
/* $NetBSD: lpr.c,v 1.13 1996/12/09 09:57:48 mrg Exp $ */
/*
* Copyright (c) 1983, 1989, 1993
* The Regents of the University of California. All rights reserved.
@ -294,7 +294,7 @@ main(argc, argv)
/*
* Check to make sure queuing is enabled if userid is not root.
*/
(void) snprintf(buf, BUFSIZ, "%s/%s", SD, LO);
(void)snprintf(buf, BUFSIZ, "%s/%s", SD, LO);
if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010))
fatal2("Printer queue is disabled");
/*
@ -303,7 +303,7 @@ main(argc, argv)
mktemps();
tfd = nfile(tfname);
seteuid(euid);
(void) fchown(tfd, DU, -1); /* owned by daemon for protection */
(void)fchown(tfd, DU, -1); /* owned by daemon for protection */
seteuid(uid);
card('H', host);
card('P', person);
@ -339,7 +339,7 @@ main(argc, argv)
continue; /* file unreasonable */
if (sflag && (cp = linked(arg)) != NULL) {
(void) snprintf(buf, BUFSIZ,
(void)snprintf(buf, BUFSIZ,
"%d %d", statb.st_dev, statb.st_ino);
card('S', buf);
if (format == 'p')
@ -363,14 +363,14 @@ main(argc, argv)
continue;
}
copy(i, arg);
(void) close(i);
(void)close(i);
if (f && unlink(arg) < 0)
printf("%s: %s: not removed\n", name, arg);
seteuid(uid);
}
if (nact) {
(void) close(tfd);
(void)close(tfd);
tfname[inchar]--;
/*
* Touch the control file to fix position in the queue.
@ -386,7 +386,7 @@ main(argc, argv)
tfname[inchar]++;
cleanup(0);
}
(void) close(tfd);
(void)close(tfd);
}
if (link(tfname, cfname) < 0) {
printf("%s: cannot rename %s\n", name, cfname);
@ -439,7 +439,7 @@ copy(f, n)
}
}
}
(void) close(fd);
(void)close(fd);
if (nc==0 && nr==0)
printf("%s: %s: empty input file\n", name, f ? n : "stdin");
else
@ -459,7 +459,8 @@ linked(file)
register int ret;
if (*file != '/') {
if (getcwd(buf, BUFSIZ) == NULL) {
/* XXX: 2 and file for "/file" */
if (getcwd(buf, BUFSIZ - 2 - strlen(file)) == NULL) {
return(NULL);
}
while (file[0] == '.') {
@ -477,8 +478,8 @@ linked(file)
}
break;
}
strcat(buf, "/");
strcat(buf, file);
strcat(buf, "/"); /* XXX: strcat is safe */
strcat(buf, file); /* XXX: strcat is safe */
file = buf;
}
seteuid(euid);
@ -523,7 +524,7 @@ nfile(n)
seteuid(euid);
f = open(n, O_WRONLY | O_EXCL | O_CREAT, FILMOD);
(void) umask(oldumask);
(void)umask(oldumask);
if (f < 0) {
printf("%s: cannot create %s\n", name, n);
cleanup(0);
@ -615,10 +616,10 @@ test(file)
!N_BADMAG(execb)) {
printf("%s: %s is an executable program and is unprintable",
name, file);
(void) close(fd);
(void)close(fd);
goto bad;
}
(void) close(fd);
(void)close(fd);
if (rflag) {
if ((cp = rindex(file, '/')) == NULL) {
if (access(".", 2) == 0)
@ -697,7 +698,7 @@ mktemps()
char buf[BUFSIZ];
char *lmktemp();
(void) snprintf(buf, BUFSIZ, "%s/.seq", SD);
(void)snprintf(buf, BUFSIZ, "%s/.seq", SD);
seteuid(euid);
if ((fd = open(buf, O_RDWR|O_CREAT, 0661)) < 0) {
printf("%s: cannot create %s\n", name, buf);
@ -722,10 +723,10 @@ mktemps()
dfname = lmktemp("df", n, len);
inchar = strlen(SD) + 3;
n = (n + 1) % 1000;
(void) lseek(fd, (off_t)0, 0);
(void)lseek(fd, (off_t)0, 0);
snprintf(buf, BUFSIZ, "%03d\n", n);
(void) write(fd, buf, strlen(buf));
(void) close(fd); /* unlocks as well */
(void)write(fd, buf, strlen(buf));
(void)close(fd); /* unlocks as well */
}
/*
@ -740,7 +741,7 @@ lmktemp(id, num, len)
if ((s = malloc(len)) == NULL)
fatal2("out of memory");
(void) snprintf(s, len, "%s/%sA%03d%s", SD, id, num, host);
(void)snprintf(s, len, "%s/%sA%03d%s", SD, id, num, host);
return(s);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lprm.c,v 1.5 1995/11/15 22:52:21 pk Exp $ */
/* $NetBSD: lprm.c,v 1.6 1996/12/09 09:57:49 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -99,7 +99,7 @@ main(argc, argv)
fatal("Who are you?");
if (strlen(p->pw_name) >= sizeof(luser))
fatal("Your name is too long");
strcpy(luser, p->pw_name);
strncpy(luser, p->pw_name, sizeof(luser) - 1);
person = luser;
while (--argc) {
if ((arg = *++argv)[0] == '-')

View File

@ -1,4 +1,4 @@
/* $NetBSD: lptest.c,v 1.5 1996/03/21 18:13:20 jtc Exp $ */
/* $NetBSD: lptest.c,v 1.6 1996/12/09 09:57:50 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -79,6 +79,6 @@ main(argc, argv)
}
putchar('\n');
}
(void) fflush(stdout);
(void)fflush(stdout);
exit(0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pac.c,v 1.7 1996/03/21 18:21:20 jtc Exp $ */
/* $NetBSD: pac.c,v 1.8 1996/12/09 09:57:51 mrg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@ -164,7 +164,7 @@ fprintf(stderr,
exit(1);
}
}
(void) enter(--cp);
(void)enter(--cp);
allflag = 0;
}
if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
@ -332,8 +332,7 @@ enter(name)
h = hash(name);
hcount++;
hp = (struct hent *) calloc(sizeof *hp, 1);
hp->h_name = (char *) calloc(sizeof(char), strlen(name)+1);
strcpy(hp->h_name, name);
hp->h_name = strdup(name);
hp->h_feetpages = 0.0;
hp->h_count = 0;
hp->h_link = hashtab[h];
@ -443,7 +442,7 @@ chkprinter(s)
perror("pac");
exit(1);
}
strcpy(sumfile, acctfile);
strcat(sumfile, "_sum");
strcpy(sumfile, acctfile); /* XXX: strcpy is safe */
strcat(sumfile, "_sum"); /* XXX: strcat is safe */
return(1);
}