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