edquota.c revision 1.1.1.2 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[] = "@(#)edquota.c 8.3 (Berkeley) 4/27/95";
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 <sys/queue.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, (off_t)(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,
308 (off_t)(id * (long)sizeof (struct dqblk)), L_SET);
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