WARNSify, deprecate bcmp/perror et al in favour of memcmp/err* et al

This commit is contained in:
lukem 1997-10-17 02:25:02 +00:00
parent e12c721705
commit 699d25a64e
2 changed files with 93 additions and 99 deletions

View File

@ -33,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)edquota.8 8.2 (Berkeley) 4/27/95
.\" $NetBSD: edquota.8,v 1.6 1997/05/29 01:48:45 cgd Exp $
.\" $NetBSD: edquota.8,v 1.7 1997/10/17 02:25:02 lukem Exp $
.\"
.Dd April 27, 1995
.Dt EDQUOTA 8
@ -42,22 +42,22 @@
.Nm edquota
.Nd edit user quotas
.Sh SYNOPSIS
.Nm edquota
.Nm
.Op Fl u
.Op Fl p Ar proto-username
.Ar username ...
.Nm edquota
.Nm ""
.Fl g
.Op Fl p Ar proto-groupname
.Ar groupname ...
.Nm edquota
.Nm ""
.Fl t
.Op Fl u
.Nm edquota
.Nm ""
.Fl t
.Fl g
.Sh DESCRIPTION
.Nm Edquota
.Nm
is a quota editor.
By default, or if the
.Fl u

View File

@ -34,15 +34,18 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1980, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
__COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
/* static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95"; */
static char *rcsid = "$NetBSD: edquota.c,v 1.14 1997/08/25 19:32:04 kleink Exp $";
#if 0
static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95";
#else
__RCSID("$NetBSD: edquota.c,v 1.15 1997/10/17 02:25:08 lukem Exp $");
#endif
#endif /* not lint */
/*
@ -54,11 +57,13 @@ static char *rcsid = "$NetBSD: edquota.c,v 1.14 1997/08/25 19:32:04 kleink Exp $
#include <sys/wait.h>
#include <sys/queue.h>
#include <ufs/ufs/quota.h>
#include <err.h>
#include <errno.h>
#include <fstab.h>
#include <pwd.h>
#include <grp.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -76,9 +81,10 @@ struct quotause {
struct dqblk dqblk;
char fsname[MAXPATHLEN + 1];
char qfname[1]; /* actually longer */
} *getprivs();
};
#define FOUND 0x01
int main __P((int, char **));
void usage __P((void));
int getentry __P((char *, int));
struct quotause *
@ -97,24 +103,23 @@ int hasquota __P((struct fstab *, int, char **));
int
main(argc, argv)
register char **argv;
int argc;
char **argv;
{
register struct quotause *qup, *protoprivs, *curprivs;
struct quotause *qup, *protoprivs, *curprivs;
extern char *optarg;
extern int optind;
register long id, protoid;
register int quotatype, tmpfd;
long id, protoid;
int quotatype, tmpfd;
char *protoname;
int ch;
int tflag = 0, pflag = 0;
if (argc < 2)
usage();
if (getuid()) {
fprintf(stderr, "edquota: permission denied\n");
exit(1);
}
if (getuid())
errx(1, "permission denied");
protoname = NULL;
quotatype = USRQUOTA;
while ((ch = getopt(argc, argv, "ugtp:")) != -1) {
switch(ch) {
@ -205,17 +210,17 @@ getentry(name, quotatype)
return (atoi(name));
switch(quotatype) {
case USRQUOTA:
if (pw = getpwnam(name))
if ((pw = getpwnam(name)) != NULL)
return (pw->pw_uid);
fprintf(stderr, "%s: no such user\n", name);
warnx("%s: no such user", name);
break;
case GRPQUOTA:
if (gr = getgrnam(name))
if ((gr = getgrnam(name)) != NULL)
return (gr->gr_gid);
fprintf(stderr, "%s: no such group\n", name);
warnx("%s: no such group", name);
break;
default:
fprintf(stderr, "%d: unknown quota type\n", quotatype);
warnx("%d: unknown quota type", quotatype);
break;
}
sleep(1);
@ -227,11 +232,11 @@ getentry(name, quotatype)
*/
struct quotause *
getprivs(id, quotatype)
register long id;
long id;
int quotatype;
{
register struct fstab *fs;
register struct quotause *qup, *quptail;
struct fstab *fs;
struct quotause *qup, *quptail;
struct quotause *quphead;
int qcmd, qupsize, fd;
char *qfpathname;
@ -239,34 +244,32 @@ getprivs(id, quotatype)
extern int errno;
setfsent();
quptail = NULL;
quphead = (struct quotause *)0;
qcmd = QCMD(Q_GETQUOTA, quotatype);
while (fs = getfsent()) {
while ((fs = getfsent()) != NULL) {
if (strcmp(fs->fs_vfstype, "ffs"))
continue;
if (!hasquota(fs, quotatype, &qfpathname))
continue;
qupsize = sizeof(*qup) + strlen(qfpathname);
if ((qup = (struct quotause *)malloc(qupsize)) == NULL) {
fprintf(stderr, "edquota: out of memory\n");
exit(2);
}
if ((qup = (struct quotause *)malloc(qupsize)) == NULL)
errx(2, "out of memory");
if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) {
if (errno == EOPNOTSUPP && !warned) {
warned++;
fprintf(stderr, "Warning: %s\n",
warnx(
"Quotas are not compiled into this kernel");
sleep(3);
}
if ((fd = open(qfpathname, O_RDONLY)) < 0) {
fd = open(qfpathname, O_RDWR|O_CREAT, 0640);
if (fd < 0 && errno != ENOENT) {
perror(qfpathname);
warnx("open `%s'", qfpathname);
free(qup);
continue;
}
fprintf(stderr, "Creating quota file %s\n",
qfpathname);
warnx("Creating quota file %s", qfpathname);
sleep(3);
(void) fchown(fd, getuid(),
getentry(quotagroup, GRPQUOTA));
@ -280,7 +283,7 @@ getprivs(id, quotatype)
* Convert implicit 0 quota (EOF)
* into an explicit one (zero'ed dqblk)
*/
bzero((caddr_t)&qup->dqblk,
memset((caddr_t)&qup->dqblk, 0,
sizeof(struct dqblk));
break;
@ -288,8 +291,7 @@ getprivs(id, quotatype)
break;
default: /* ERROR */
fprintf(stderr, "edquota: read error in ");
perror(qfpathname);
warn("read error in `%s'", qfpathname);
close(fd);
free(qup);
continue;
@ -318,7 +320,7 @@ putprivs(id, quotatype, quplist)
int quotatype;
struct quotause *quplist;
{
register struct quotause *qup;
struct quotause *qup;
int qcmd, fd;
qcmd = QCMD(Q_SETQUOTA, quotatype);
@ -326,16 +328,14 @@ putprivs(id, quotatype, quplist)
if (quotactl(qup->fsname, qcmd, id, &qup->dqblk) == 0)
continue;
if ((fd = open(qup->qfname, O_WRONLY)) < 0) {
perror(qup->qfname);
warnx("open `%s'", qup->qfname);
} else {
(void)lseek(fd,
(off_t)(id * (long)sizeof (struct dqblk)),
SEEK_SET);
if (write(fd, &qup->dqblk, sizeof (struct dqblk)) !=
sizeof (struct dqblk)) {
fprintf(stderr, "edquota: ");
perror(qup->qfname);
}
sizeof (struct dqblk))
warnx("writing `%s'", qup->qfname);
close(fd);
}
}
@ -350,7 +350,6 @@ editit(tmpfile)
{
long omask;
int pid, stat;
extern char *getenv();
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
top:
@ -358,18 +357,18 @@ editit(tmpfile)
extern errno;
if (errno == EPROCLIM) {
fprintf(stderr, "You have too many processes\n");
warnx("You have too many processes");
return(0);
}
if (errno == EAGAIN) {
sleep(1);
goto top;
}
perror("fork");
warn("fork");
return (0);
}
if (pid == 0) {
register char *ed;
char *ed;
sigsetmask(omask);
setgid(getgid());
@ -377,8 +376,7 @@ editit(tmpfile)
if ((ed = getenv("EDITOR")) == (char *)0)
ed = _PATH_VI;
execlp(ed, ed, tmpfile, 0);
perror(ed);
exit(1);
err(1, "%s", ed);
}
waitpid(pid, &stat, 0);
sigsetmask(omask);
@ -397,16 +395,13 @@ writeprivs(quplist, outfd, name, quotatype)
char *name;
int quotatype;
{
register struct quotause *qup;
struct quotause *qup;
FILE *fd;
ftruncate(outfd, 0);
(void)lseek(outfd, (off_t)0, SEEK_SET);
if ((fd = fdopen(dup(outfd), "w")) == NULL) {
fprintf(stderr, "edquota: ");
perror(tmpfil);
exit(1);
}
if ((fd = fdopen(dup(outfd), "w")) == NULL)
errx(1, "fdopen `%s'", tmpfil);
fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name);
for (qup = quplist; qup; qup = qup->next) {
fprintf(fd, "%s: %s %d, limits (soft = %d, hard = %d)\n",
@ -430,17 +425,17 @@ readprivs(quplist, infd)
struct quotause *quplist;
int infd;
{
register struct quotause *qup;
struct quotause *qup;
FILE *fd;
int cnt;
register char *cp;
char *cp;
struct dqblk dqblk;
char *fsp, line1[BUFSIZ], line2[BUFSIZ];
(void)lseek(infd, (off_t)0, SEEK_SET);
fd = fdopen(dup(infd), "r");
if (fd == NULL) {
fprintf(stderr, "Can't re-read temp file!!\n");
warn("Can't re-read temp file");
return (0);
}
/*
@ -450,11 +445,11 @@ readprivs(quplist, infd)
while (fgets(line1, sizeof (line1), fd) != NULL &&
fgets(line2, sizeof (line2), fd) != NULL) {
if ((fsp = strtok(line1, " \t:")) == NULL) {
fprintf(stderr, "%s: bad format\n", line1);
warnx("%s: bad format", line1);
return (0);
}
if ((cp = strtok((char *)0, "\n")) == NULL) {
fprintf(stderr, "%s: %s: bad format\n", fsp,
warnx("%s: %s: bad format", fsp,
&fsp[strlen(fsp) + 1]);
return (0);
}
@ -463,14 +458,14 @@ readprivs(quplist, infd)
&dqblk.dqb_curblocks, &dqblk.dqb_bsoftlimit,
&dqblk.dqb_bhardlimit);
if (cnt != 3) {
fprintf(stderr, "%s:%s: bad format\n", fsp, cp);
warnx("%s:%s: bad format", fsp, cp);
return (0);
}
dqblk.dqb_curblocks = btodb(dqblk.dqb_curblocks * 1024);
dqblk.dqb_bsoftlimit = btodb(dqblk.dqb_bsoftlimit * 1024);
dqblk.dqb_bhardlimit = btodb(dqblk.dqb_bhardlimit * 1024);
if ((cp = strtok(line2, "\n")) == NULL) {
fprintf(stderr, "%s: %s: bad format\n", fsp, line2);
warnx("%s: %s: bad format", fsp, line2);
return (0);
}
cnt = sscanf(cp,
@ -478,7 +473,7 @@ readprivs(quplist, infd)
&dqblk.dqb_curinodes, &dqblk.dqb_isoftlimit,
&dqblk.dqb_ihardlimit);
if (cnt != 3) {
fprintf(stderr, "%s: %s: bad format\n", fsp, line2);
warnx("%s: %s: bad format", fsp, line2);
return (0);
}
for (qup = quplist; qup; qup = qup->next) {
@ -510,8 +505,7 @@ readprivs(quplist, infd)
if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)
break;
fprintf(stderr,
"%s: cannot change current allocation\n", fsp);
warnx("%s: cannot change current allocation", fsp);
break;
}
}
@ -541,17 +535,13 @@ writetimes(quplist, outfd, quotatype)
int outfd;
int quotatype;
{
register struct quotause *qup;
char *cvtstoa();
struct quotause *qup;
FILE *fd;
ftruncate(outfd, 0);
(void)lseek(outfd, (off_t)0, SEEK_SET);
if ((fd = fdopen(dup(outfd), "w")) == NULL) {
fprintf(stderr, "edquota: ");
perror(tmpfil);
exit(1);
}
if ((fd = fdopen(dup(outfd), "w")) == NULL)
err(1, "fdopen `%s'", tmpfil);
fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n");
fprintf(fd, "Grace period before enforcing soft limits for %ss:\n",
qfextension[quotatype]);
@ -573,17 +563,18 @@ readtimes(quplist, infd)
struct quotause *quplist;
int infd;
{
register struct quotause *qup;
struct quotause *qup;
FILE *fd;
int cnt;
register char *cp;
char *cp;
long litime, lbtime;
time_t itime, btime, iseconds, bseconds;
char *fsp, bunits[10], iunits[10], line1[BUFSIZ];
(void)lseek(infd, (off_t)0, SEEK_SET);
fd = fdopen(dup(infd), "r");
if (fd == NULL) {
fprintf(stderr, "Can't re-read temp file!!\n");
warnx("Can't re-read temp file!!");
return (0);
}
/*
@ -593,21 +584,23 @@ readtimes(quplist, infd)
(void) fgets(line1, sizeof (line1), fd);
while (fgets(line1, sizeof (line1), fd) != NULL) {
if ((fsp = strtok(line1, " \t:")) == NULL) {
fprintf(stderr, "%s: bad format\n", line1);
warnx("%s: bad format", line1);
return (0);
}
if ((cp = strtok((char *)0, "\n")) == NULL) {
fprintf(stderr, "%s: %s: bad format\n", fsp,
warnx("%s: %s: bad format", fsp,
&fsp[strlen(fsp) + 1]);
return (0);
}
cnt = sscanf(cp,
" block grace period: %d %s file grace period: %d %s",
&btime, bunits, &itime, iunits);
" block grace period: %ld %s file grace period: %ld %s",
&lbtime, bunits, &litime, iunits);
if (cnt != 4) {
fprintf(stderr, "%s:%s: bad format\n", fsp, cp);
warnx("%s:%s: bad format", fsp, cp);
return (0);
}
itime = (time_t)litime;
btime = (time_t)lbtime;
if (cvtatos(btime, bunits, &bseconds) == 0)
return (0);
if (cvtatos(itime, iunits, &iseconds) == 0)
@ -648,15 +641,16 @@ cvtstoa(time)
if (time % (24 * 60 * 60) == 0) {
time /= 24 * 60 * 60;
sprintf(buf, "%d day%s", time, time == 1 ? "" : "s");
snprintf(buf, sizeof buf, "%ld day%s", (long)time,
time == 1 ? "" : "s");
} else if (time % (60 * 60) == 0) {
time /= 60 * 60;
sprintf(buf, "%d hour%s", time, time == 1 ? "" : "s");
sprintf(buf, "%ld hour%s", (long)time, time == 1 ? "" : "s");
} else if (time % 60 == 0) {
time /= 60;
sprintf(buf, "%d minute%s", time, time == 1 ? "" : "s");
sprintf(buf, "%ld minute%s", (long)time, time == 1 ? "" : "s");
} else
sprintf(buf, "%d second%s", time, time == 1 ? "" : "s");
sprintf(buf, "%ld second%s", (long)time, time == 1 ? "" : "s");
return (buf);
}
@ -670,13 +664,13 @@ cvtatos(time, units, seconds)
time_t *seconds;
{
if (bcmp(units, "second", 6) == 0)
if (memcmp(units, "second", 6) == 0)
*seconds = time;
else if (bcmp(units, "minute", 6) == 0)
else if (memcmp(units, "minute", 6) == 0)
*seconds = time * 60;
else if (bcmp(units, "hour", 4) == 0)
else if (memcmp(units, "hour", 4) == 0)
*seconds = time * 60 * 60;
else if (bcmp(units, "day", 3) == 0)
else if (memcmp(units, "day", 3) == 0)
*seconds = time * 24 * 60 * 60;
else {
printf("%s: bad units, specify %s\n", units,
@ -693,7 +687,7 @@ void
freeprivs(quplist)
struct quotause *quplist;
{
register struct quotause *qup, *nextqup;
struct quotause *qup, *nextqup;
for (qup = quplist; qup; qup = nextqup) {
nextqup = qup->next;
@ -706,15 +700,15 @@ freeprivs(quplist)
*/
int
alldigits(s)
register char *s;
char *s;
{
register c;
int c;
c = *s++;
do {
if (!isdigit(c))
return (0);
} while (c = *s++);
} while ((c = *s++) != 0);
return (1);
}
@ -723,12 +717,12 @@ alldigits(s)
*/
int
hasquota(fs, type, qfnamep)
register struct fstab *fs;
struct fstab *fs;
int type;
char **qfnamep;
{
register char *opt;
char *cp, *index(), *strtok();
char *opt;
char *cp;
static char initname, usrname[100], grpname[100];
static char buf[BUFSIZ];
@ -739,7 +733,7 @@ hasquota(fs, type, qfnamep)
}
strcpy(buf, fs->fs_mntops);
for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
if (cp = index(opt, '='))
if ((cp = strchr(opt, '=')) != NULL)
*cp++ = '\0';
if (type == USRQUOTA && strcmp(opt, usrname) == 0)
break;