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