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