diff options
author | sobomax <sobomax@FreeBSD.org> | 2002-09-07 12:26:07 +0000 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2002-09-07 12:26:07 +0000 |
commit | 04cbb04f2ee9a17616a80b202ef464b89abcd2f0 (patch) | |
tree | eaecee4b1b34b61fd6b0d092547f9d5790d894a9 /usr.sbin/edquota/edquota.c | |
parent | 43881a9c90f63314dc5ea38dcd072e77bccf9c34 (diff) | |
download | FreeBSD-src-04cbb04f2ee9a17616a80b202ef464b89abcd2f0.zip FreeBSD-src-04cbb04f2ee9a17616a80b202ef464b89abcd2f0.tar.gz |
Allow edquota(8) to be used for setting up quotas non-interactively (add a
new -e option for that).
Feature requested by: Alex V. Belinsky <fozzy@kievweb.net.ua>
MFC after: 1 month
Diffstat (limited to 'usr.sbin/edquota/edquota.c')
-rw-r--r-- | usr.sbin/edquota/edquota.c | 127 |
1 files changed, 104 insertions, 23 deletions
diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c index 326c741..48e462a 100644 --- a/usr.sbin/edquota/edquota.c +++ b/usr.sbin/edquota/edquota.c @@ -101,12 +101,14 @@ int writeprivs(struct quotause *, int, char *, int); int main(int argc, char **argv) { - register struct quotause *qup, *protoprivs, *curprivs; - register long id, protoid; - register int quotatype, tmpfd; - register uid_t startuid, enduid; - char *protoname, *cp, ch; - int tflag = 0, pflag = 0; + struct quotause *qup, *protoprivs, *curprivs; + long id, protoid; + long long lim; + int i, quotatype, range, tmpfd; + uid_t startuid, enduid; + u_int32_t *limp; + char *protoname, *cp, *oldoptarg, ch; + int eflag = 0, tflag = 0, pflag = 0; char *fspath = NULL; char buf[30]; @@ -115,7 +117,8 @@ main(int argc, char **argv) if (getuid()) errx(1, "permission denied"); quotatype = USRQUOTA; - while ((ch = getopt(argc, argv, "ugtf:p:")) != -1) { + protoprivs = NULL; + while ((ch = getopt(argc, argv, "ugtf:p:e:")) != -1) { switch(ch) { case 'f': fspath = optarg; @@ -133,6 +136,61 @@ main(int argc, char **argv) case 't': tflag++; break; + case 'e': + if ((qup = malloc(sizeof(*qup))) == NULL) + errx(2, "out of memory"); + bzero(qup, sizeof(*qup)); + i = 0; + oldoptarg = optarg; + for (cp = optarg; (cp = strsep(&optarg, ":")) != NULL; + i++) { + if (cp != oldoptarg) + *(cp - 1) = ':'; + limp = NULL; + switch (i) { + case 0: + strlcpy(qup->fsname, cp, + sizeof(qup->fsname)); + break; + case 1: + limp = &qup->dqblk.dqb_bsoftlimit; + break; + case 2: + limp = &qup->dqblk.dqb_bhardlimit; + break; + case 3: + limp = &qup->dqblk.dqb_isoftlimit; + break; + case 4: + limp = &qup->dqblk.dqb_ihardlimit; + break; + default: + warnx("incorrect quota specification: " + "%s", oldoptarg); + usage(); + break; /* XXX: report an error */ + } + if (limp != NULL) { + lim = strtoll(cp, NULL, 10); + if (lim < 0 || lim > UINT_MAX) + errx(1, "invalid limit value: " + "%lld", lim); + *limp = (u_int32_t)lim; + } + } + qup->dqblk.dqb_bsoftlimit = + btodb((off_t)qup->dqblk.dqb_bsoftlimit * 1024); + qup->dqblk.dqb_bhardlimit = + btodb((off_t)qup->dqblk.dqb_bhardlimit * 1024); + if (protoprivs == NULL) { + protoprivs = curprivs = qup; + } else { + curprivs->next = qup; + curprivs = qup; + } + eflag++; + pflag++; + break; default: usage(); } @@ -140,12 +198,14 @@ main(int argc, char **argv) argc -= optind; argv += optind; if (pflag) { - if ((protoid = getentry(protoname, quotatype)) == -1) - exit(1); - protoprivs = getprivs(protoid, quotatype, fspath); - for (qup = protoprivs; qup; qup = qup->next) { - qup->dqblk.dqb_btime = 0; - qup->dqblk.dqb_itime = 0; + if (protoprivs == NULL) { + if ((protoid = getentry(protoname, quotatype)) == -1) + exit(1); + protoprivs = getprivs(protoid, quotatype, fspath); + for (qup = protoprivs; qup; qup = qup->next) { + qup->dqblk.dqb_btime = 0; + qup->dqblk.dqb_itime = 0; + } } for (; argc-- > 0; argv++) { if (strspn(*argv, "0123456789-") == strlen(*argv) && @@ -157,18 +217,35 @@ main(int argc, char **argv) errx(1, "ending uid (%d) must be >= starting uid (%d) when using uid ranges", enduid, startuid); - for ( ; startuid <= enduid; startuid++) { - snprintf(buf, sizeof(buf), "%d", + range = 1; + } else { + startuid = enduid = 0; + range = 0; + } + for ( ; startuid <= enduid; startuid++) { + if (range) + snprintf(buf, sizeof(buf), "%d", startuid); - if ((id = getentry(buf, quotatype)) < 0) - continue; - putprivs(id, quotatype, protoprivs); + else + snprintf(buf, sizeof(buf), "%s", + *argv); + if ((id = getentry(buf, quotatype)) < 0) + continue; + if (eflag) { + for (qup = protoprivs; qup; + qup = qup->next) { + curprivs = getprivs(id, + quotatype, qup->fsname); + if (curprivs == NULL) + continue; + strcpy(qup->qfname, + curprivs->qfname); + strcpy(qup->fsname, + curprivs->fsname); + } } - continue; + putprivs(id, quotatype, protoprivs); } - if ((id = getentry(*argv, quotatype)) < 0) - continue; - putprivs(id, quotatype, protoprivs); } exit(0); } @@ -203,9 +280,13 @@ main(int argc, char **argv) static void usage() { - fprintf(stderr, "%s\n%s\n%s\n%s\n", + fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "usage: edquota [-u] [-f fspath] [-p username] username ...", + " edquota [-u] -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]", + " username ...", " edquota -g [-f fspath] [-p groupname] groupname ...", + " edquota -g -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]", + " groupname ...", " edquota [-u] -t [-f fspath]", " edquota -g -t [-f fspath]"); exit(1); |