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
This commit is contained in:
parent
7c2ffa8911
commit
b8b743d723
@ -48,11 +48,21 @@
|
|||||||
.Op Fl p Ar proto-username
|
.Op Fl p Ar proto-username
|
||||||
.Ar username ...
|
.Ar username ...
|
||||||
.Nm
|
.Nm
|
||||||
|
.Op Fl u
|
||||||
|
.Fl e Ar fspath Ns Op : Ns Ar bslim Ns Op : Ns Ar bhlim Ns Op : Ns Ar islim Ns Op : Ns Ar ihlim
|
||||||
|
.Op Fl e Ar ...
|
||||||
|
.Ar username ...
|
||||||
|
.Nm
|
||||||
.Fl g
|
.Fl g
|
||||||
.Op Fl f Ar fspath
|
.Op Fl f Ar fspath
|
||||||
.Op Fl p Ar proto-groupname
|
.Op Fl p Ar proto-groupname
|
||||||
.Ar groupname ...
|
.Ar groupname ...
|
||||||
.Nm
|
.Nm
|
||||||
|
.Fl g
|
||||||
|
.Fl e Ar fspath Ns Op : Ns Ar bslim Ns Op : Ns Ar bhlim Ns Op : Ns Ar islim Ns Op : Ns Ar ihlim
|
||||||
|
.Op Fl e Ar ...
|
||||||
|
.Ar groupname ...
|
||||||
|
.Nm
|
||||||
.Fl t
|
.Fl t
|
||||||
.Op Fl u
|
.Op Fl u
|
||||||
.Op Fl f Ar fspath
|
.Op Fl f Ar fspath
|
||||||
@ -118,6 +128,34 @@ for easy setup of default quotas for a group of users.
|
|||||||
The uids in question do not have to be currently assigned in
|
The uids in question do not have to be currently assigned in
|
||||||
.Pa /etc/passwd .
|
.Pa /etc/passwd .
|
||||||
.Pp
|
.Pp
|
||||||
|
If one or more
|
||||||
|
.Fl e Ar fspath Ns Op : Ns Ar bslim Ns Op : Ns Ar bhlim Ns Op : Ns Ar islim Ns Op : Ns Ar ihlim
|
||||||
|
options are specified,
|
||||||
|
.Nm
|
||||||
|
will non-interactively set quotas defined by
|
||||||
|
.Ar bslim ,
|
||||||
|
.Ar bhlim ,
|
||||||
|
.Ar islim and
|
||||||
|
.Ar ihlim
|
||||||
|
on each particular filesystem referenced by
|
||||||
|
.Ar fspath .
|
||||||
|
Here
|
||||||
|
.Ar bslim
|
||||||
|
is soft limit on number of blocks,
|
||||||
|
.Ar bslim
|
||||||
|
is hard limit on number of blocks,
|
||||||
|
.Ar islim
|
||||||
|
is soft limit on number of files and
|
||||||
|
.Ar ihlim
|
||||||
|
is hard limit on number of files.
|
||||||
|
If any of the
|
||||||
|
.Ar bslim ,
|
||||||
|
.Ar bhlim ,
|
||||||
|
.Ar islim and
|
||||||
|
.Ar ihlim
|
||||||
|
values are omitted, it is assumed to be zero, therefore
|
||||||
|
indicating that no quota should be imposed.
|
||||||
|
.Pp
|
||||||
If invoked with the
|
If invoked with the
|
||||||
.Fl f
|
.Fl f
|
||||||
option,
|
option,
|
||||||
@ -147,6 +185,13 @@ the
|
|||||||
.Fl g
|
.Fl g
|
||||||
flag to specify a prototypical group
|
flag to specify a prototypical group
|
||||||
to be duplicated among the listed set of groups.
|
to be duplicated among the listed set of groups.
|
||||||
|
Similarly,
|
||||||
|
.Fl e
|
||||||
|
flag can be specified in conjunction with
|
||||||
|
the
|
||||||
|
.Fl g
|
||||||
|
flag to non-interactively set-up quotas on the listed set
|
||||||
|
of groups.
|
||||||
.Pp
|
.Pp
|
||||||
Users are permitted to exceed their soft limits
|
Users are permitted to exceed their soft limits
|
||||||
for a grace period that may be specified per filesystem.
|
for a grace period that may be specified per filesystem.
|
||||||
|
@ -101,12 +101,14 @@ int writeprivs(struct quotause *, int, char *, int);
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
register struct quotause *qup, *protoprivs, *curprivs;
|
struct quotause *qup, *protoprivs, *curprivs;
|
||||||
register long id, protoid;
|
long id, protoid;
|
||||||
register int quotatype, tmpfd;
|
long long lim;
|
||||||
register uid_t startuid, enduid;
|
int i, quotatype, range, tmpfd;
|
||||||
char *protoname, *cp, ch;
|
uid_t startuid, enduid;
|
||||||
int tflag = 0, pflag = 0;
|
u_int32_t *limp;
|
||||||
|
char *protoname, *cp, *oldoptarg, ch;
|
||||||
|
int eflag = 0, tflag = 0, pflag = 0;
|
||||||
char *fspath = NULL;
|
char *fspath = NULL;
|
||||||
char buf[30];
|
char buf[30];
|
||||||
|
|
||||||
@ -115,7 +117,8 @@ main(int argc, char **argv)
|
|||||||
if (getuid())
|
if (getuid())
|
||||||
errx(1, "permission denied");
|
errx(1, "permission denied");
|
||||||
quotatype = USRQUOTA;
|
quotatype = USRQUOTA;
|
||||||
while ((ch = getopt(argc, argv, "ugtf:p:")) != -1) {
|
protoprivs = NULL;
|
||||||
|
while ((ch = getopt(argc, argv, "ugtf:p:e:")) != -1) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'f':
|
case 'f':
|
||||||
fspath = optarg;
|
fspath = optarg;
|
||||||
@ -133,6 +136,61 @@ main(int argc, char **argv)
|
|||||||
case 't':
|
case 't':
|
||||||
tflag++;
|
tflag++;
|
||||||
break;
|
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:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
@ -140,12 +198,14 @@ main(int argc, char **argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
if (pflag) {
|
if (pflag) {
|
||||||
if ((protoid = getentry(protoname, quotatype)) == -1)
|
if (protoprivs == NULL) {
|
||||||
exit(1);
|
if ((protoid = getentry(protoname, quotatype)) == -1)
|
||||||
protoprivs = getprivs(protoid, quotatype, fspath);
|
exit(1);
|
||||||
for (qup = protoprivs; qup; qup = qup->next) {
|
protoprivs = getprivs(protoid, quotatype, fspath);
|
||||||
qup->dqblk.dqb_btime = 0;
|
for (qup = protoprivs; qup; qup = qup->next) {
|
||||||
qup->dqblk.dqb_itime = 0;
|
qup->dqblk.dqb_btime = 0;
|
||||||
|
qup->dqblk.dqb_itime = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (; argc-- > 0; argv++) {
|
for (; argc-- > 0; argv++) {
|
||||||
if (strspn(*argv, "0123456789-") == strlen(*argv) &&
|
if (strspn(*argv, "0123456789-") == strlen(*argv) &&
|
||||||
@ -157,18 +217,35 @@ main(int argc, char **argv)
|
|||||||
errx(1,
|
errx(1,
|
||||||
"ending uid (%d) must be >= starting uid (%d) when using uid ranges",
|
"ending uid (%d) must be >= starting uid (%d) when using uid ranges",
|
||||||
enduid, startuid);
|
enduid, startuid);
|
||||||
for ( ; startuid <= enduid; startuid++) {
|
range = 1;
|
||||||
snprintf(buf, sizeof(buf), "%d",
|
} else {
|
||||||
startuid);
|
startuid = enduid = 0;
|
||||||
if ((id = getentry(buf, quotatype)) < 0)
|
range = 0;
|
||||||
continue;
|
}
|
||||||
putprivs(id, quotatype, protoprivs);
|
for ( ; startuid <= enduid; startuid++) {
|
||||||
}
|
if (range)
|
||||||
continue;
|
snprintf(buf, sizeof(buf), "%d",
|
||||||
|
startuid);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
putprivs(id, quotatype, protoprivs);
|
||||||
}
|
}
|
||||||
if ((id = getentry(*argv, quotatype)) < 0)
|
|
||||||
continue;
|
|
||||||
putprivs(id, quotatype, protoprivs);
|
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -203,9 +280,13 @@ main(int argc, char **argv)
|
|||||||
static void
|
static void
|
||||||
usage()
|
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 ...",
|
"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 [-f fspath] [-p groupname] groupname ...",
|
||||||
|
" edquota -g -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]",
|
||||||
|
" groupname ...",
|
||||||
" edquota [-u] -t [-f fspath]",
|
" edquota [-u] -t [-f fspath]",
|
||||||
" edquota -g -t [-f fspath]");
|
" edquota -g -t [-f fspath]");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user