Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-quota2]: src/usr.sbin/repquota Make sure users which don't have q...



details:   https://anonhg.NetBSD.org/src/rev/075ab3057dec
branches:  bouyer-quota2
changeset: 761193:075ab3057dec
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Mar 05 18:53:00 2011 +0000

description:
Make sure users which don't have quota entries are reported with the default
quotas (instead of wrong all-0 quota entry, which cause it to be reported
as overquota now)

diffstat:

 usr.sbin/repquota/repquota.c |  63 ++++++++++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 19 deletions(-)

diffs (149 lines):

diff -r 93d59a3c8197 -r 075ab3057dec usr.sbin/repquota/repquota.c
--- a/usr.sbin/repquota/repquota.c      Sat Mar 05 18:10:44 2011 +0000
+++ b/usr.sbin/repquota/repquota.c      Sat Mar 05 18:53:00 2011 +0000
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94";
 #else
-__RCSID("$NetBSD: repquota.c,v 1.25.2.9 2011/03/05 18:10:44 bouyer Exp $");
+__RCSID("$NetBSD: repquota.c,v 1.25.2.10 2011/03/05 18:53:00 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -95,6 +95,7 @@
 struct fileusage *addid(u_long, int, const char *);
 int    hasquota(struct fstab *, int, char **);
 struct fileusage *lookup(u_long, int);
+struct fileusage *qremove(u_long, int);
 int    main(int, char **);
 int    oneof(const char *, char **, int);
 int    repquota(const struct statvfs *, int);
@@ -110,8 +111,6 @@
        int argc;
        char **argv;
 {
-       struct passwd *pw;
-       struct group *gr;
        int gflag = 0, uflag = 0, errs = 0;
        long i, argnum, done = 0;
        int ch;
@@ -147,7 +146,7 @@
        }
        argc -= optind;
        argv += optind;
-       if (xflag && argc != 1)
+       if (xflag && (argc != 1 || aflag))
                usage();
        if (argc == 0 && !aflag)
                usage();
@@ -156,18 +155,6 @@
                        gflag++;
                uflag++;
        }
-       if (gflag) {
-               setgrent();
-               while ((gr = getgrent()) != 0)
-                       (void) addid((u_long)gr->gr_gid, GRPQUOTA, gr->gr_name);
-               endgrent();
-       }
-       if (uflag) {
-               setpwent();
-               while ((pw = getpwent()) != 0)
-                       (void) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name);
-               endpwent();
-       }
 
        nfst = getmntinfo(&fst, MNT_WAIT);
        if (nfst == 0)
@@ -410,6 +397,22 @@
        char overchar[N_QL];
        static time_t now;
 
+       if (type == GRPQUOTA) {
+               struct group *gr;
+               setgrent();
+               while ((gr = getgrent()) != 0)
+                       (void) addid((u_long)gr->gr_gid, GRPQUOTA, gr->gr_name);
+               endgrent();
+       } else if (type == USRQUOTA) {
+               struct passwd *pw;
+               setpwent();
+               while ((pw = getpwent()) != 0)
+                       (void) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name);
+               endpwent();
+       } else {
+               errx(1, "unknown quota type %d\n", type);
+       }
+
        if (now == 0)
                time(&now);
 
@@ -424,7 +427,7 @@
        printf(type == USRQUOTA ? "User " : "Group");
        printf("            used     soft     hard  grace      used    soft    hard  grace\n");
        for (id = 0; id <= highid[type]; id++) {
-               fup = lookup(id, type);
+               fup = qremove(id, type);
                if (fup == 0)
                        continue;
                for (i = 0; i < N_QL; i++) {
@@ -472,7 +475,7 @@
                        intprt(fup->fu_q2e.q2e_val[QL_FILE].q2v_hardlimit,
                                0, hflag, 8),
                        timemsg[QL_FILE]);
-               memset(&fup->fu_q2e, 0, sizeof(fup->fu_q2e));
+               free(fup);
        }
 }
 
@@ -506,7 +509,7 @@
                        err(1, "prop_array_add(data)");
 
                for (id = 0; id <= highid[type]; id++) {
-                       fup = lookup(id, type);
+                       fup = qremove(id, type);
                        if (fup == 0)
                                continue;
                        fup->fu_q2e.q2e_uid = id;
@@ -515,6 +518,7 @@
                                err(1, "q2etoprop(default)");
                        if (!prop_array_add_and_rel(datas, data))
                                err(1, "prop_array_add(data)");
+                       free(fup);
                }
 
                if (!quota2_prop_add_command(cmds, "set",
@@ -602,6 +606,26 @@
                        return (fup);
        return ((struct fileusage *)0);
 }
+/*
+ * Lookup and remove an id of a specific type.
+ */
+struct fileusage *
+qremove(id, type)
+       u_long id;
+       int type;
+{
+       struct fileusage *fup, **fupp;
+
+       for (fupp = &fuhead[type][id & (FUHASH-1)]; *fupp != 0;) {
+               fup = *fupp;
+               if (fup->fu_id == id) {
+                       *fupp = fup->fu_next;
+                       return (fup);
+               }
+               fupp = &fup->fu_next;
+       }
+       return ((struct fileusage *)0);
+}
 
 /*
  * Add a new file usage id if it does not already exist.
@@ -636,5 +660,6 @@
        } else {
                sprintf(fup->fu_name, "%lu", (u_long)id);
        }
+       fup->fu_q2e = defaultq2e[type];
        return (fup);
 }



Home | Main Index | Thread Index | Old Index