BSD 4_4 release
[unix-history] / usr / src / usr.bin / quota / quota.c
index 8d8d76b..1d18a13 100644 (file)
@@ -1,31 +1,47 @@
 /*
 /*
- * Copyright (c) 1980, 1990 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Robert Elz at The University of Melbourne.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * Robert Elz at The University of Melbourne.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980, 1990 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1990, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)quota.c    5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)quota.c    8.1 (Berkeley) 6/6/93";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -34,7 +50,7 @@ static char sccsid[] = "@(#)quota.c   5.9 (Berkeley) %G%";
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/stat.h>
-#include <ufs/quota.h>
+#include <ufs/ufs/quota.h>
 #include <stdio.h>
 #include <fstab.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <fstab.h>
 #include <ctype.h>
@@ -42,6 +58,9 @@ static char sccsid[] = "@(#)quota.c   5.9 (Berkeley) %G%";
 #include <grp.h>
 #include <errno.h>
 
 #include <grp.h>
 #include <errno.h>
 
+char *qfname = QUOTAFILENAME;
+char *qfextension[] = INITQFNAMES;
+
 struct quotause {
        struct  quotause *next;
        long    flags;
 struct quotause {
        struct  quotause *next;
        long    flags;
@@ -381,28 +400,29 @@ getprivs(id, quotatype)
        int quotatype;
 {
        register struct fstab *fs;
        int quotatype;
 {
        register struct fstab *fs;
-       char qfilename[MAXPATHLEN + 1];
        register struct quotause *qup, *quptail;
        struct quotause *quphead;
        register struct quotause *qup, *quptail;
        struct quotause *quphead;
+       char *qfpathname;
        int qcmd, fd;
 
        setfsent();
        quphead = (struct quotause *)0;
        qcmd = QCMD(Q_GETQUOTA, quotatype);
        while (fs = getfsent()) {
        int qcmd, fd;
 
        setfsent();
        quphead = (struct quotause *)0;
        qcmd = QCMD(Q_GETQUOTA, quotatype);
        while (fs = getfsent()) {
-               if (!hasquota(fs->fs_mntops, quotatype))
+               if (strcmp(fs->fs_vfstype, "ufs"))
                        continue;
                        continue;
-               sprintf(qfilename, "%s/%s.%s", fs->fs_file, qfname,
-                   qfextension[quotatype]);
-               if ((fd = open(qfilename, O_RDONLY)) < 0) {
-                       perror(qfilename);
+               if (!hasquota(fs, quotatype, &qfpathname))
                        continue;
                        continue;
-               }
                if ((qup = (struct quotause *)malloc(sizeof *qup)) == NULL) {
                        fprintf(stderr, "quota: out of memory\n");
                        exit(2);
                }
                if ((qup = (struct quotause *)malloc(sizeof *qup)) == NULL) {
                        fprintf(stderr, "quota: out of memory\n");
                        exit(2);
                }
-               if (quotactl(qfilename, qcmd, id, &qup->dqblk) != 0) {
+               if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) {
+                       if ((fd = open(qfpathname, O_RDONLY)) < 0) {
+                               perror(qfpathname);
+                               free(qup);
+                               continue;
+                       }
                        lseek(fd, (long)(id * sizeof(struct dqblk)), L_SET);
                        switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
                        case 0:                 /* EOF */
                        lseek(fd, (long)(id * sizeof(struct dqblk)), L_SET);
                        switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
                        case 0:                 /* EOF */
@@ -419,13 +439,13 @@ getprivs(id, quotatype)
 
                        default:                /* ERROR */
                                fprintf(stderr, "quota: read error");
 
                        default:                /* ERROR */
                                fprintf(stderr, "quota: read error");
-                               perror(qfilename);
+                               perror(qfpathname);
                                close(fd);
                                free(qup);
                                continue;
                        }
                                close(fd);
                                free(qup);
                                continue;
                        }
+                       close(fd);
                }
                }
-               close(fd);
                strcpy(qup->fsname, fs->fs_file);
                if (quphead == NULL)
                        quphead = qup;
                strcpy(qup->fsname, fs->fs_file);
                if (quphead == NULL)
                        quphead = qup;
@@ -441,28 +461,39 @@ getprivs(id, quotatype)
 /*
  * Check to see if a particular quota is to be enabled.
  */
 /*
  * Check to see if a particular quota is to be enabled.
  */
-hasquota(options, type)
-       char *options;
+hasquota(fs, type, qfnamep)
+       register struct fstab *fs;
        int type;
        int type;
+       char **qfnamep;
 {
        register char *opt;
 {
        register char *opt;
-       char buf[BUFSIZ];
-       char *strtok();
+       char *cp, *index(), *strtok();
        static char initname, usrname[100], grpname[100];
        static char initname, usrname[100], grpname[100];
+       static char buf[BUFSIZ];
 
        if (!initname) {
                sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname);
                sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname);
                initname = 1;
        }
 
        if (!initname) {
                sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname);
                sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname);
                initname = 1;
        }
-       strcpy(buf, options);
+       strcpy(buf, fs->fs_mntops);
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
+               if (cp = index(opt, '='))
+                       *cp++ = '\0';
                if (type == USRQUOTA && strcmp(opt, usrname) == 0)
                if (type == USRQUOTA && strcmp(opt, usrname) == 0)
-                       return(1);
+                       break;
                if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
                if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
-                       return(1);
+                       break;
        }
        }
-       return (0);
+       if (!opt)
+               return (0);
+       if (cp) {
+               *qfnamep = cp;
+               return (1);
+       }
+       (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]);
+       *qfnamep = buf;
+       return (1);
 }
 
 alldigits(s)
 }
 
 alldigits(s)