Home | History | Annotate | Line # | Download | only in edquota
edquota.c revision 1.10
      1 /*
      2  * Copyright (c) 1980, 1990, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * This code is derived from software contributed to Berkeley by
      6  * Robert Elz at The University of Melbourne.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  */
     36 
     37 #ifndef lint
     38 static char copyright[] =
     39 "@(#) Copyright (c) 1980, 1990, 1993\n\
     40 	The Regents of the University of California.  All rights reserved.\n";
     41 #endif /* not lint */
     42 
     43 #ifndef lint
     44 /*static char sccsid[] = "from: @(#)edquota.c	8.1 (Berkeley) 6/6/93";*/
     45 static char *rcsid = "$Id: edquota.c,v 1.10 1995/11/28 19:43:12 jtc Exp $";
     46 #endif /* not lint */
     47 
     48 /*
     49  * Disk quota editor.
     50  */
     51 #include <sys/param.h>
     52 #include <sys/stat.h>
     53 #include <sys/file.h>
     54 #include <sys/wait.h>
     55 #include <ufs/ufs/quota.h>
     56 #include <errno.h>
     57 #include <fstab.h>
     58 #include <pwd.h>
     59 #include <grp.h>
     60 #include <ctype.h>
     61 #include <stdio.h>
     62 #include <stdlib.h>
     63 #include <string.h>
     64 #include <unistd.h>
     65 #include "pathnames.h"
     66 
     67 char *qfname = QUOTAFILENAME;
     68 char *qfextension[] = INITQFNAMES;
     69 char *quotagroup = QUOTAGROUP;
     70 char tmpfil[] = _PATH_TMP;
     71 
     72 struct quotause {
     73 	struct	quotause *next;
     74 	long	flags;
     75 	struct	dqblk dqblk;
     76 	char	fsname[MAXPATHLEN + 1];
     77 	char	qfname[1];	/* actually longer */
     78 } *getprivs();
     79 #define	FOUND	0x01
     80 
     81 main(argc, argv)
     82 	register char **argv;
     83 	int argc;
     84 {
     85 	register struct quotause *qup, *protoprivs, *curprivs;
     86 	extern char *optarg;
     87 	extern int optind;
     88 	register long id, protoid;
     89 	register int quotatype, tmpfd;
     90 	char *protoname, ch;
     91 	int tflag = 0, pflag = 0;
     92 
     93 	if (argc < 2)
     94 		usage();
     95 	if (getuid()) {
     96 		fprintf(stderr, "edquota: permission denied\n");
     97 		exit(1);
     98 	}
     99 	quotatype = USRQUOTA;
    100 	while ((ch = getopt(argc, argv, "ugtp:")) != EOF) {
    101 		switch(ch) {
    102 		case 'p':
    103 			protoname = optarg;
    104 			pflag++;
    105 			break;
    106 		case 'g':
    107 			quotatype = GRPQUOTA;
    108 			break;
    109 		case 'u':
    110 			quotatype = USRQUOTA;
    111 			break;
    112 		case 't':
    113 			tflag++;
    114 			break;
    115 		default:
    116 			usage();
    117 		}
    118 	}
    119 	argc -= optind;
    120 	argv += optind;
    121 	if (pflag) {
    122 		if ((protoid = getentry(protoname, quotatype)) == -1)
    123 			exit(1);
    124 		protoprivs = getprivs(protoid, quotatype);
    125 		for (qup = protoprivs; qup; qup = qup->next) {
    126 			qup->dqblk.dqb_btime = 0;
    127 			qup->dqblk.dqb_itime = 0;
    128 		}
    129 		while (argc-- > 0) {
    130 			if ((id = getentry(*argv++, quotatype)) < 0)
    131 				continue;
    132 			putprivs(id, quotatype, protoprivs);
    133 		}
    134 		exit(0);
    135 	}
    136 	tmpfd = mkstemp(tmpfil);
    137 	fchown(tmpfd, getuid(), getgid());
    138 	if (tflag) {
    139 		protoprivs = getprivs(0, quotatype);
    140 		if (writetimes(protoprivs, tmpfd, quotatype) == 0)
    141 			exit(1);
    142 		if (editit(tmpfil) && readtimes(protoprivs, tmpfd))
    143 			putprivs(0, quotatype, protoprivs);
    144 		freeprivs(protoprivs);
    145 		exit(0);
    146 	}
    147 	for ( ; argc > 0; argc--, argv++) {
    148 		if ((id = getentry(*argv, quotatype)) == -1)
    149 			continue;
    150 		curprivs = getprivs(id, quotatype);
    151 		if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0)
    152 			continue;
    153 		if (editit(tmpfil) && readprivs(curprivs, tmpfd))
    154 			putprivs(id, quotatype, curprivs);
    155 		freeprivs(curprivs);
    156 	}
    157 	close(tmpfd);
    158 	unlink(tmpfil);
    159 	exit(0);
    160 }
    161 
    162 usage()
    163 {
    164 	fprintf(stderr, "%s%s%s%s",
    165 		"Usage: edquota [-u] [-p username] username ...\n",
    166 		"\tedquota -g [-p groupname] groupname ...\n",
    167 		"\tedquota [-u] -t\n", "\tedquota -g -t\n");
    168 	exit(1);
    169 }
    170 
    171 /*
    172  * This routine converts a name for a particular quota type to
    173  * an identifier. This routine must agree with the kernel routine
    174  * getinoquota as to the interpretation of quota types.
    175  */
    176 getentry(name, quotatype)
    177 	char *name;
    178 	int quotatype;
    179 {
    180 	struct passwd *pw;
    181 	struct group *gr;
    182 
    183 	if (alldigits(name))
    184 		return (atoi(name));
    185 	switch(quotatype) {
    186 	case USRQUOTA:
    187 		if (pw = getpwnam(name))
    188 			return (pw->pw_uid);
    189 		fprintf(stderr, "%s: no such user\n", name);
    190 		break;
    191 	case GRPQUOTA:
    192 		if (gr = getgrnam(name))
    193 			return (gr->gr_gid);
    194 		fprintf(stderr, "%s: no such group\n", name);
    195 		break;
    196 	default:
    197 		fprintf(stderr, "%d: unknown quota type\n", quotatype);
    198 		break;
    199 	}
    200 	sleep(1);
    201 	return (-1);
    202 }
    203 
    204 /*
    205  * Collect the requested quota information.
    206  */
    207 struct quotause *
    208 getprivs(id, quotatype)
    209 	register long id;
    210 	int quotatype;
    211 {
    212 	register struct fstab *fs;
    213 	register struct quotause *qup, *quptail;
    214 	struct quotause *quphead;
    215 	int qcmd, qupsize, fd;
    216 	char *qfpathname;
    217 	static int warned = 0;
    218 	extern int errno;
    219 
    220 	setfsent();
    221 	quphead = (struct quotause *)0;
    222 	qcmd = QCMD(Q_GETQUOTA, quotatype);
    223 	while (fs = getfsent()) {
    224 		if (strcmp(fs->fs_vfstype, "ffs"))
    225 			continue;
    226 		if (!hasquota(fs, quotatype, &qfpathname))
    227 			continue;
    228 		qupsize = sizeof(*qup) + strlen(qfpathname);
    229 		if ((qup = (struct quotause *)malloc(qupsize)) == NULL) {
    230 			fprintf(stderr, "edquota: out of memory\n");
    231 			exit(2);
    232 		}
    233 		if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) {
    234 	    		if (errno == EOPNOTSUPP && !warned) {
    235 				warned++;
    236 				fprintf(stderr, "Warning: %s\n",
    237 				    "Quotas are not compiled into this kernel");
    238 				sleep(3);
    239 			}
    240 			if ((fd = open(qfpathname, O_RDONLY)) < 0) {
    241 				fd = open(qfpathname, O_RDWR|O_CREAT, 0640);
    242 				if (fd < 0 && errno != ENOENT) {
    243 					perror(qfpathname);
    244 					free(qup);
    245 					continue;
    246 				}
    247 				fprintf(stderr, "Creating quota file %s\n",
    248 				    qfpathname);
    249 				sleep(3);
    250 				(void) fchown(fd, getuid(),
    251 				    getentry(quotagroup, GRPQUOTA));
    252 				(void) fchmod(fd, 0640);
    253 			}
    254 			lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET);
    255 			switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
    256 			case 0:			/* EOF */
    257 				/*
    258 				 * Convert implicit 0 quota (EOF)
    259 				 * into an explicit one (zero'ed dqblk)
    260 				 */
    261 				bzero((caddr_t)&qup->dqblk,
    262 				    sizeof(struct dqblk));
    263 				break;
    264 
    265 			case sizeof(struct dqblk):	/* OK */
    266 				break;
    267 
    268 			default:		/* ERROR */
    269 				fprintf(stderr, "edquota: read error in ");
    270 				perror(qfpathname);
    271 				close(fd);
    272 				free(qup);
    273 				continue;
    274 			}
    275 			close(fd);
    276 		}
    277 		strcpy(qup->qfname, qfpathname);
    278 		strcpy(qup->fsname, fs->fs_file);
    279 		if (quphead == NULL)
    280 			quphead = qup;
    281 		else
    282 			quptail->next = qup;
    283 		quptail = qup;
    284 		qup->next = 0;
    285 	}
    286 	endfsent();
    287 	return (quphead);
    288 }
    289 
    290 /*
    291  * Store the requested quota information.
    292  */
    293 putprivs(id, quotatype, quplist)
    294 	long id;
    295 	int quotatype;
    296 	struct quotause *quplist;
    297 {
    298 	register struct quotause *qup;
    299 	int qcmd, fd;
    300 
    301 	qcmd = QCMD(Q_SETQUOTA, quotatype);
    302 	for (qup = quplist; qup; qup = qup->next) {
    303 		if (quotactl(qup->fsname, qcmd, id, &qup->dqblk) == 0)
    304 			continue;
    305 		if ((fd = open(qup->qfname, O_WRONLY)) < 0) {
    306 			perror(qup->qfname);
    307 		} else {
    308 			lseek(fd, (off_t)(id * sizeof (struct dqblk)), 0);
    309 			if (write(fd, &qup->dqblk, sizeof (struct dqblk)) !=
    310 			    sizeof (struct dqblk)) {
    311 				fprintf(stderr, "edquota: ");
    312 				perror(qup->qfname);
    313 			}
    314 			close(fd);
    315 		}
    316 	}
    317 }
    318 
    319 /*
    320  * Take a list of priviledges and get it edited.
    321  */
    322 editit(tmpfile)
    323 	char *tmpfile;
    324 {
    325 	long omask;
    326 	int pid, stat;
    327 	extern char *getenv();
    328 
    329 	omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
    330  top:
    331 	if ((pid = fork()) < 0) {
    332 		extern errno;
    333 
    334 		if (errno == EPROCLIM) {
    335 			fprintf(stderr, "You have too many processes\n");
    336 			return(0);
    337 		}
    338 		if (errno == EAGAIN) {
    339 			sleep(1);
    340 			goto top;
    341 		}
    342 		perror("fork");
    343 		return (0);
    344 	}
    345 	if (pid == 0) {
    346 		register char *ed;
    347 
    348 		sigsetmask(omask);
    349 		setgid(getgid());
    350 		setuid(getuid());
    351 		if ((ed = getenv("EDITOR")) == (char *)0)
    352 			ed = _PATH_VI;
    353 		execlp(ed, ed, tmpfile, 0);
    354 		perror(ed);
    355 		exit(1);
    356 	}
    357 	waitpid(pid, &stat, 0);
    358 	sigsetmask(omask);
    359 	if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0)
    360 		return (0);
    361 	return (1);
    362 }
    363 
    364 /*
    365  * Convert a quotause list to an ASCII file.
    366  */
    367 writeprivs(quplist, outfd, name, quotatype)
    368 	struct quotause *quplist;
    369 	int outfd;
    370 	char *name;
    371 	int quotatype;
    372 {
    373 	register struct quotause *qup;
    374 	FILE *fd;
    375 
    376 	ftruncate(outfd, 0);
    377 	lseek(outfd, 0, L_SET);
    378 	if ((fd = fdopen(dup(outfd), "w")) == NULL) {
    379 		fprintf(stderr, "edquota: ");
    380 		perror(tmpfil);
    381 		exit(1);
    382 	}
    383 	fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name);
    384 	for (qup = quplist; qup; qup = qup->next) {
    385 		fprintf(fd, "%s: %s %d, limits (soft = %d, hard = %d)\n",
    386 		    qup->fsname, "blocks in use:",
    387 		    dbtob(qup->dqblk.dqb_curblocks) / 1024,
    388 		    dbtob(qup->dqblk.dqb_bsoftlimit) / 1024,
    389 		    dbtob(qup->dqblk.dqb_bhardlimit) / 1024);
    390 		fprintf(fd, "%s %d, limits (soft = %d, hard = %d)\n",
    391 		    "\tinodes in use:", qup->dqblk.dqb_curinodes,
    392 		    qup->dqblk.dqb_isoftlimit, qup->dqblk.dqb_ihardlimit);
    393 	}
    394 	fclose(fd);
    395 	return (1);
    396 }
    397 
    398 /*
    399  * Merge changes to an ASCII file into a quotause list.
    400  */
    401 readprivs(quplist, infd)
    402 	struct quotause *quplist;
    403 	int infd;
    404 {
    405 	register struct quotause *qup;
    406 	FILE *fd;
    407 	int cnt;
    408 	register char *cp;
    409 	struct dqblk dqblk;
    410 	char *fsp, line1[BUFSIZ], line2[BUFSIZ];
    411 
    412 	lseek(infd, 0, L_SET);
    413 	fd = fdopen(dup(infd), "r");
    414 	if (fd == NULL) {
    415 		fprintf(stderr, "Can't re-read temp file!!\n");
    416 		return (0);
    417 	}
    418 	/*
    419 	 * Discard title line, then read pairs of lines to process.
    420 	 */
    421 	(void) fgets(line1, sizeof (line1), fd);
    422 	while (fgets(line1, sizeof (line1), fd) != NULL &&
    423 	       fgets(line2, sizeof (line2), fd) != NULL) {
    424 		if ((fsp = strtok(line1, " \t:")) == NULL) {
    425 			fprintf(stderr, "%s: bad format\n", line1);
    426 			return (0);
    427 		}
    428 		if ((cp = strtok((char *)0, "\n")) == NULL) {
    429 			fprintf(stderr, "%s: %s: bad format\n", fsp,
    430 			    &fsp[strlen(fsp) + 1]);
    431 			return (0);
    432 		}
    433 		cnt = sscanf(cp,
    434 		    " blocks in use: %d, limits (soft = %d, hard = %d)",
    435 		    &dqblk.dqb_curblocks, &dqblk.dqb_bsoftlimit,
    436 		    &dqblk.dqb_bhardlimit);
    437 		if (cnt != 3) {
    438 			fprintf(stderr, "%s:%s: bad format\n", fsp, cp);
    439 			return (0);
    440 		}
    441 		dqblk.dqb_curblocks = btodb(dqblk.dqb_curblocks * 1024);
    442 		dqblk.dqb_bsoftlimit = btodb(dqblk.dqb_bsoftlimit * 1024);
    443 		dqblk.dqb_bhardlimit = btodb(dqblk.dqb_bhardlimit * 1024);
    444 		if ((cp = strtok(line2, "\n")) == NULL) {
    445 			fprintf(stderr, "%s: %s: bad format\n", fsp, line2);
    446 			return (0);
    447 		}
    448 		cnt = sscanf(cp,
    449 		    "\tinodes in use: %d, limits (soft = %d, hard = %d)",
    450 		    &dqblk.dqb_curinodes, &dqblk.dqb_isoftlimit,
    451 		    &dqblk.dqb_ihardlimit);
    452 		if (cnt != 3) {
    453 			fprintf(stderr, "%s: %s: bad format\n", fsp, line2);
    454 			return (0);
    455 		}
    456 		for (qup = quplist; qup; qup = qup->next) {
    457 			if (strcmp(fsp, qup->fsname))
    458 				continue;
    459 			/*
    460 			 * Cause time limit to be reset when the quota
    461 			 * is next used if previously had no soft limit
    462 			 * or were under it, but now have a soft limit
    463 			 * and are over it.
    464 			 */
    465 			if (dqblk.dqb_bsoftlimit &&
    466 			    qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit &&
    467 			    (qup->dqblk.dqb_bsoftlimit == 0 ||
    468 			     qup->dqblk.dqb_curblocks <
    469 			     qup->dqblk.dqb_bsoftlimit))
    470 				qup->dqblk.dqb_btime = 0;
    471 			if (dqblk.dqb_isoftlimit &&
    472 			    qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit &&
    473 			    (qup->dqblk.dqb_isoftlimit == 0 ||
    474 			     qup->dqblk.dqb_curinodes <
    475 			     qup->dqblk.dqb_isoftlimit))
    476 				qup->dqblk.dqb_itime = 0;
    477 			qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit;
    478 			qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit;
    479 			qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit;
    480 			qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit;
    481 			qup->flags |= FOUND;
    482 			if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
    483 			    dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)
    484 				break;
    485 			fprintf(stderr,
    486 			    "%s: cannot change current allocation\n", fsp);
    487 			break;
    488 		}
    489 	}
    490 	fclose(fd);
    491 	/*
    492 	 * Disable quotas for any filesystems that have not been found.
    493 	 */
    494 	for (qup = quplist; qup; qup = qup->next) {
    495 		if (qup->flags & FOUND) {
    496 			qup->flags &= ~FOUND;
    497 			continue;
    498 		}
    499 		qup->dqblk.dqb_bsoftlimit = 0;
    500 		qup->dqblk.dqb_bhardlimit = 0;
    501 		qup->dqblk.dqb_isoftlimit = 0;
    502 		qup->dqblk.dqb_ihardlimit = 0;
    503 	}
    504 	return (1);
    505 }
    506 
    507 /*
    508  * Convert a quotause list to an ASCII file of grace times.
    509  */
    510 writetimes(quplist, outfd, quotatype)
    511 	struct quotause *quplist;
    512 	int outfd;
    513 	int quotatype;
    514 {
    515 	register struct quotause *qup;
    516 	char *cvtstoa();
    517 	FILE *fd;
    518 
    519 	ftruncate(outfd, 0);
    520 	lseek(outfd, 0, L_SET);
    521 	if ((fd = fdopen(dup(outfd), "w")) == NULL) {
    522 		fprintf(stderr, "edquota: ");
    523 		perror(tmpfil);
    524 		exit(1);
    525 	}
    526 	fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n");
    527 	fprintf(fd, "Grace period before enforcing soft limits for %ss:\n",
    528 	    qfextension[quotatype]);
    529 	for (qup = quplist; qup; qup = qup->next) {
    530 		fprintf(fd, "%s: block grace period: %s, ",
    531 		    qup->fsname, cvtstoa(qup->dqblk.dqb_btime));
    532 		fprintf(fd, "file grace period: %s\n",
    533 		    cvtstoa(qup->dqblk.dqb_itime));
    534 	}
    535 	fclose(fd);
    536 	return (1);
    537 }
    538 
    539 /*
    540  * Merge changes of grace times in an ASCII file into a quotause list.
    541  */
    542 readtimes(quplist, infd)
    543 	struct quotause *quplist;
    544 	int infd;
    545 {
    546 	register struct quotause *qup;
    547 	FILE *fd;
    548 	int cnt;
    549 	register char *cp;
    550 	time_t itime, btime, iseconds, bseconds;
    551 	char *fsp, bunits[10], iunits[10], line1[BUFSIZ];
    552 
    553 	lseek(infd, 0, L_SET);
    554 	fd = fdopen(dup(infd), "r");
    555 	if (fd == NULL) {
    556 		fprintf(stderr, "Can't re-read temp file!!\n");
    557 		return (0);
    558 	}
    559 	/*
    560 	 * Discard two title lines, then read lines to process.
    561 	 */
    562 	(void) fgets(line1, sizeof (line1), fd);
    563 	(void) fgets(line1, sizeof (line1), fd);
    564 	while (fgets(line1, sizeof (line1), fd) != NULL) {
    565 		if ((fsp = strtok(line1, " \t:")) == NULL) {
    566 			fprintf(stderr, "%s: bad format\n", line1);
    567 			return (0);
    568 		}
    569 		if ((cp = strtok((char *)0, "\n")) == NULL) {
    570 			fprintf(stderr, "%s: %s: bad format\n", fsp,
    571 			    &fsp[strlen(fsp) + 1]);
    572 			return (0);
    573 		}
    574 		cnt = sscanf(cp,
    575 		    " block grace period: %d %s file grace period: %d %s",
    576 		    &btime, bunits, &itime, iunits);
    577 		if (cnt != 4) {
    578 			fprintf(stderr, "%s:%s: bad format\n", fsp, cp);
    579 			return (0);
    580 		}
    581 		if (cvtatos(btime, bunits, &bseconds) == 0)
    582 			return (0);
    583 		if (cvtatos(itime, iunits, &iseconds) == 0)
    584 			return (0);
    585 		for (qup = quplist; qup; qup = qup->next) {
    586 			if (strcmp(fsp, qup->fsname))
    587 				continue;
    588 			qup->dqblk.dqb_btime = bseconds;
    589 			qup->dqblk.dqb_itime = iseconds;
    590 			qup->flags |= FOUND;
    591 			break;
    592 		}
    593 	}
    594 	fclose(fd);
    595 	/*
    596 	 * reset default grace periods for any filesystems
    597 	 * that have not been found.
    598 	 */
    599 	for (qup = quplist; qup; qup = qup->next) {
    600 		if (qup->flags & FOUND) {
    601 			qup->flags &= ~FOUND;
    602 			continue;
    603 		}
    604 		qup->dqblk.dqb_btime = 0;
    605 		qup->dqblk.dqb_itime = 0;
    606 	}
    607 	return (1);
    608 }
    609 
    610 /*
    611  * Convert seconds to ASCII times.
    612  */
    613 char *
    614 cvtstoa(time)
    615 	time_t time;
    616 {
    617 	static char buf[20];
    618 
    619 	if (time % (24 * 60 * 60) == 0) {
    620 		time /= 24 * 60 * 60;
    621 		sprintf(buf, "%d day%s", time, time == 1 ? "" : "s");
    622 	} else if (time % (60 * 60) == 0) {
    623 		time /= 60 * 60;
    624 		sprintf(buf, "%d hour%s", time, time == 1 ? "" : "s");
    625 	} else if (time % 60 == 0) {
    626 		time /= 60;
    627 		sprintf(buf, "%d minute%s", time, time == 1 ? "" : "s");
    628 	} else
    629 		sprintf(buf, "%d second%s", time, time == 1 ? "" : "s");
    630 	return (buf);
    631 }
    632 
    633 /*
    634  * Convert ASCII input times to seconds.
    635  */
    636 cvtatos(time, units, seconds)
    637 	time_t time;
    638 	char *units;
    639 	time_t *seconds;
    640 {
    641 
    642 	if (bcmp(units, "second", 6) == 0)
    643 		*seconds = time;
    644 	else if (bcmp(units, "minute", 6) == 0)
    645 		*seconds = time * 60;
    646 	else if (bcmp(units, "hour", 4) == 0)
    647 		*seconds = time * 60 * 60;
    648 	else if (bcmp(units, "day", 3) == 0)
    649 		*seconds = time * 24 * 60 * 60;
    650 	else {
    651 		printf("%s: bad units, specify %s\n", units,
    652 		    "days, hours, minutes, or seconds");
    653 		return (0);
    654 	}
    655 	return (1);
    656 }
    657 
    658 /*
    659  * Free a list of quotause structures.
    660  */
    661 freeprivs(quplist)
    662 	struct quotause *quplist;
    663 {
    664 	register struct quotause *qup, *nextqup;
    665 
    666 	for (qup = quplist; qup; qup = nextqup) {
    667 		nextqup = qup->next;
    668 		free(qup);
    669 	}
    670 }
    671 
    672 /*
    673  * Check whether a string is completely composed of digits.
    674  */
    675 alldigits(s)
    676 	register char *s;
    677 {
    678 	register c;
    679 
    680 	c = *s++;
    681 	do {
    682 		if (!isdigit(c))
    683 			return (0);
    684 	} while (c = *s++);
    685 	return (1);
    686 }
    687 
    688 /*
    689  * Check to see if a particular quota is to be enabled.
    690  */
    691 hasquota(fs, type, qfnamep)
    692 	register struct fstab *fs;
    693 	int type;
    694 	char **qfnamep;
    695 {
    696 	register char *opt;
    697 	char *cp, *index(), *strtok();
    698 	static char initname, usrname[100], grpname[100];
    699 	static char buf[BUFSIZ];
    700 
    701 	if (!initname) {
    702 		sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname);
    703 		sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname);
    704 		initname = 1;
    705 	}
    706 	strcpy(buf, fs->fs_mntops);
    707 	for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
    708 		if (cp = index(opt, '='))
    709 			*cp++ = '\0';
    710 		if (type == USRQUOTA && strcmp(opt, usrname) == 0)
    711 			break;
    712 		if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
    713 			break;
    714 	}
    715 	if (!opt)
    716 		return (0);
    717 	if (cp) {
    718 		*qfnamep = cp;
    719 		return (1);
    720 	}
    721 	(void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]);
    722 	*qfnamep = buf;
    723 	return (1);
    724 }
    725