1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#if 0
|
1994-05-26 05:23:31 +00:00
|
|
|
#ifndef lint
|
1997-09-17 06:29:23 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 05:23:31 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1990, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char sccsid[] = "@(#)edquota.c 8.1 (Berkeley) 6/6/93";
|
|
|
|
#endif /* not lint */
|
2003-05-03 21:06:42 +00:00
|
|
|
#endif
|
2006-09-14 04:45:44 +00:00
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disk quota editor.
|
|
|
|
*/
|
2006-09-14 04:45:44 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
2007-02-04 06:33:15 +00:00
|
|
|
#include <sys/mount.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <ufs/ufs/quota.h>
|
2009-01-30 13:54:03 +00:00
|
|
|
|
1997-09-17 06:29:23 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fstab.h>
|
|
|
|
#include <grp.h>
|
2009-01-30 13:54:03 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <libutil.h>
|
1997-09-17 06:29:23 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <signal.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <stdio.h>
|
1997-09-17 06:29:23 +00:00
|
|
|
#include <stdlib.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-01-30 13:54:03 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
2009-02-04 00:21:36 +00:00
|
|
|
/* Let's be paranoid about block size */
|
|
|
|
#if 10 > DEV_BSHIFT
|
|
|
|
#define dbtokb(db) \
|
|
|
|
((off_t)(db) >> (10-DEV_BSHIFT))
|
|
|
|
#elif 10 < DEV_BSHIFT
|
|
|
|
#define dbtokb(db) \
|
|
|
|
((off_t)(db) << (DEV_BSHIFT-10))
|
|
|
|
#else
|
|
|
|
#define dbtokb(db) (db)
|
|
|
|
#endif
|
|
|
|
|
2001-12-10 06:05:28 +00:00
|
|
|
const char *qfextension[] = INITQFNAMES;
|
1994-05-26 05:23:31 +00:00
|
|
|
char tmpfil[] = _PATH_TMP;
|
2009-02-04 00:21:36 +00:00
|
|
|
int hflag;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
struct quotause {
|
|
|
|
struct quotause *next;
|
2009-02-14 08:08:08 +00:00
|
|
|
struct quotafile *qf;
|
1994-05-26 05:23:31 +00:00
|
|
|
struct dqblk dqblk;
|
2009-02-14 08:08:08 +00:00
|
|
|
int flags;
|
1994-05-26 05:23:31 +00:00
|
|
|
char fsname[MAXPATHLEN + 1];
|
1997-09-17 06:29:23 +00:00
|
|
|
};
|
1994-05-26 05:23:31 +00:00
|
|
|
#define FOUND 0x01
|
|
|
|
|
2002-07-11 18:31:16 +00:00
|
|
|
int alldigits(const char *s);
|
2009-09-27 17:33:26 +00:00
|
|
|
int cvtatos(uint64_t, char *, uint64_t *);
|
|
|
|
char *cvtstoa(uint64_t);
|
|
|
|
uint64_t cvtblkval(uint64_t, char, const char *);
|
|
|
|
uint64_t cvtinoval(uint64_t, char, const char *);
|
2002-07-11 18:31:16 +00:00
|
|
|
int editit(char *);
|
2009-02-10 08:09:03 +00:00
|
|
|
char *fmthumanvalblks(int64_t);
|
|
|
|
char *fmthumanvalinos(int64_t);
|
2002-07-11 18:31:16 +00:00
|
|
|
void freeprivs(struct quotause *);
|
|
|
|
int getentry(const char *, int);
|
|
|
|
struct quotause *getprivs(long, int, char *);
|
2009-02-14 08:08:08 +00:00
|
|
|
void putprivs(long, struct quotause *);
|
2002-07-11 18:31:16 +00:00
|
|
|
int readprivs(struct quotause *, char *);
|
|
|
|
int readtimes(struct quotause *, char *);
|
|
|
|
static void usage(void);
|
|
|
|
int writetimes(struct quotause *, int, int);
|
|
|
|
int writeprivs(struct quotause *, int, char *, int);
|
1997-09-17 06:29:23 +00:00
|
|
|
|
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2002-09-07 12:26:07 +00:00
|
|
|
struct quotause *qup, *protoprivs, *curprivs;
|
|
|
|
long id, protoid;
|
|
|
|
int i, quotatype, range, tmpfd;
|
|
|
|
uid_t startuid, enduid;
|
2009-09-27 17:33:26 +00:00
|
|
|
uint64_t lim;
|
2009-02-04 00:21:36 +00:00
|
|
|
char *protoname, *cp, *endpt, *oldoptarg;
|
2004-01-22 07:23:36 +00:00
|
|
|
int eflag = 0, tflag = 0, pflag = 0, ch;
|
2001-09-28 10:22:36 +00:00
|
|
|
char *fspath = NULL;
|
2004-02-24 20:58:16 +00:00
|
|
|
char buf[MAXLOGNAME];
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
1997-09-17 06:29:23 +00:00
|
|
|
if (getuid())
|
|
|
|
errx(1, "permission denied");
|
1994-05-26 05:23:31 +00:00
|
|
|
quotatype = USRQUOTA;
|
2002-09-07 12:26:07 +00:00
|
|
|
protoprivs = NULL;
|
2006-09-14 04:45:44 +00:00
|
|
|
curprivs = NULL;
|
|
|
|
protoname = NULL;
|
2009-02-04 00:21:36 +00:00
|
|
|
while ((ch = getopt(argc, argv, "ughtf:p:e:")) != -1) {
|
1994-05-26 05:23:31 +00:00
|
|
|
switch(ch) {
|
2001-09-28 10:22:36 +00:00
|
|
|
case 'f':
|
|
|
|
fspath = optarg;
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case 'p':
|
2009-02-14 08:08:08 +00:00
|
|
|
if (eflag) {
|
|
|
|
warnx("cannot specify both -e and -p");
|
|
|
|
usage();
|
|
|
|
/* not reached */
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
protoname = optarg;
|
|
|
|
pflag++;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
quotatype = GRPQUOTA;
|
|
|
|
break;
|
2009-02-04 00:21:36 +00:00
|
|
|
case 'h':
|
|
|
|
hflag++;
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case 'u':
|
|
|
|
quotatype = USRQUOTA;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tflag++;
|
|
|
|
break;
|
2002-09-07 12:26:07 +00:00
|
|
|
case 'e':
|
2009-02-14 08:08:08 +00:00
|
|
|
if (pflag) {
|
|
|
|
warnx("cannot specify both -e and -p");
|
|
|
|
usage();
|
|
|
|
/* not reached */
|
|
|
|
}
|
|
|
|
if ((qup = calloc(1, sizeof(*qup))) == NULL)
|
2002-09-07 12:26:07 +00:00
|
|
|
errx(2, "out of memory");
|
|
|
|
oldoptarg = optarg;
|
2009-02-05 14:06:43 +00:00
|
|
|
for (i = 0, cp = optarg;
|
|
|
|
(cp = strsep(&optarg, ":")) != NULL; i++) {
|
2002-09-07 12:26:07 +00:00
|
|
|
if (cp != oldoptarg)
|
|
|
|
*(cp - 1) = ':';
|
2009-02-10 08:09:03 +00:00
|
|
|
if (i > 0 && !isdigit(*cp)) {
|
|
|
|
warnx("incorrect quota specification: "
|
|
|
|
"%s", oldoptarg);
|
|
|
|
usage();
|
|
|
|
/* Not Reached */
|
|
|
|
}
|
2002-09-07 12:26:07 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
strlcpy(qup->fsname, cp,
|
|
|
|
sizeof(qup->fsname));
|
|
|
|
break;
|
|
|
|
case 1:
|
2009-02-04 00:21:36 +00:00
|
|
|
lim = strtoll(cp, &endpt, 10);
|
|
|
|
qup->dqblk.dqb_bsoftlimit =
|
2009-02-10 08:09:03 +00:00
|
|
|
cvtblkval(lim, *endpt,
|
|
|
|
"block soft limit");
|
2009-02-04 00:21:36 +00:00
|
|
|
continue;
|
2002-09-07 12:26:07 +00:00
|
|
|
case 2:
|
2009-02-04 00:21:36 +00:00
|
|
|
lim = strtoll(cp, &endpt, 10);
|
|
|
|
qup->dqblk.dqb_bhardlimit =
|
2009-02-10 08:09:03 +00:00
|
|
|
cvtblkval(lim, *endpt,
|
|
|
|
"block hard limit");
|
2009-02-04 00:21:36 +00:00
|
|
|
continue;
|
2002-09-07 12:26:07 +00:00
|
|
|
case 3:
|
2009-02-05 14:06:43 +00:00
|
|
|
lim = strtoll(cp, &endpt, 10);
|
2009-02-04 00:21:36 +00:00
|
|
|
qup->dqblk.dqb_isoftlimit =
|
2009-02-10 08:09:03 +00:00
|
|
|
cvtinoval(lim, *endpt,
|
|
|
|
"inode soft limit");
|
2009-02-04 00:21:36 +00:00
|
|
|
continue;
|
2002-09-07 12:26:07 +00:00
|
|
|
case 4:
|
2009-02-05 14:06:43 +00:00
|
|
|
lim = strtoll(cp, &endpt, 10);
|
2009-02-04 00:21:36 +00:00
|
|
|
qup->dqblk.dqb_ihardlimit =
|
2009-02-10 08:09:03 +00:00
|
|
|
cvtinoval(lim, *endpt,
|
|
|
|
"inode hard limit");
|
2009-02-04 00:21:36 +00:00
|
|
|
continue;
|
2002-09-07 12:26:07 +00:00
|
|
|
default:
|
|
|
|
warnx("incorrect quota specification: "
|
|
|
|
"%s", oldoptarg);
|
|
|
|
usage();
|
2009-02-10 08:09:03 +00:00
|
|
|
/* Not Reached */
|
2002-09-07 12:26:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (protoprivs == NULL) {
|
|
|
|
protoprivs = curprivs = qup;
|
|
|
|
} else {
|
|
|
|
curprivs->next = qup;
|
|
|
|
curprivs = qup;
|
|
|
|
}
|
|
|
|
eflag++;
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
default:
|
|
|
|
usage();
|
2009-02-10 08:09:03 +00:00
|
|
|
/* Not Reached */
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2009-02-14 08:08:08 +00:00
|
|
|
if (pflag || eflag) {
|
|
|
|
if (pflag) {
|
2002-09-07 12:26:07 +00:00
|
|
|
if ((protoid = getentry(protoname, quotatype)) == -1)
|
|
|
|
exit(1);
|
|
|
|
protoprivs = getprivs(protoid, quotatype, fspath);
|
2009-02-13 06:12:15 +00:00
|
|
|
if (protoprivs == NULL)
|
|
|
|
exit(0);
|
2002-09-07 12:26:07 +00:00
|
|
|
for (qup = protoprivs; qup; qup = qup->next) {
|
|
|
|
qup->dqblk.dqb_btime = 0;
|
|
|
|
qup->dqblk.dqb_itime = 0;
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2002-08-09 01:21:03 +00:00
|
|
|
for (; argc-- > 0; argv++) {
|
|
|
|
if (strspn(*argv, "0123456789-") == strlen(*argv) &&
|
1996-03-31 20:57:44 +00:00
|
|
|
(cp = strchr(*argv, '-')) != NULL) {
|
|
|
|
*cp++ = '\0';
|
|
|
|
startuid = atoi(*argv);
|
|
|
|
enduid = atoi(cp);
|
1997-09-17 06:29:23 +00:00
|
|
|
if (enduid < startuid)
|
|
|
|
errx(1,
|
|
|
|
"ending uid (%d) must be >= starting uid (%d) when using uid ranges",
|
1996-03-31 20:57:44 +00:00
|
|
|
enduid, startuid);
|
2002-09-07 12:26:07 +00:00
|
|
|
range = 1;
|
|
|
|
} else {
|
|
|
|
startuid = enduid = 0;
|
|
|
|
range = 0;
|
|
|
|
}
|
|
|
|
for ( ; startuid <= enduid; startuid++) {
|
|
|
|
if (range)
|
|
|
|
snprintf(buf, sizeof(buf), "%d",
|
1996-03-31 20:57:44 +00:00
|
|
|
startuid);
|
2002-09-07 12:26:07 +00:00
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%s",
|
|
|
|
*argv);
|
|
|
|
if ((id = getentry(buf, quotatype)) < 0)
|
|
|
|
continue;
|
2009-02-14 08:08:08 +00:00
|
|
|
if (pflag) {
|
|
|
|
putprivs(id, protoprivs);
|
2009-02-13 06:12:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-02-14 08:08:08 +00:00
|
|
|
for (qup = protoprivs; qup; qup = qup->next) {
|
2009-02-13 06:12:15 +00:00
|
|
|
curprivs = getprivs(id, quotatype,
|
|
|
|
qup->fsname);
|
|
|
|
if (curprivs == NULL)
|
|
|
|
continue;
|
2009-02-14 08:08:08 +00:00
|
|
|
curprivs->dqblk = qup->dqblk;
|
|
|
|
putprivs(id, curprivs);
|
|
|
|
freeprivs(curprivs);
|
1996-03-31 20:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2009-02-14 08:08:08 +00:00
|
|
|
if (pflag)
|
|
|
|
freeprivs(protoprivs);
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
tmpfd = mkstemp(tmpfil);
|
|
|
|
fchown(tmpfd, getuid(), getgid());
|
|
|
|
if (tflag) {
|
2009-02-13 06:12:15 +00:00
|
|
|
if ((protoprivs = getprivs(0, quotatype, fspath)) != NULL) {
|
|
|
|
if (writetimes(protoprivs, tmpfd, quotatype) != 0 &&
|
|
|
|
editit(tmpfil) && readtimes(protoprivs, tmpfil))
|
2009-02-14 08:08:08 +00:00
|
|
|
putprivs(0L, protoprivs);
|
2009-02-13 06:12:15 +00:00
|
|
|
freeprivs(protoprivs);
|
|
|
|
}
|
1997-08-19 20:45:45 +00:00
|
|
|
close(tmpfd);
|
|
|
|
unlink(tmpfil);
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
for ( ; argc > 0; argc--, argv++) {
|
|
|
|
if ((id = getentry(*argv, quotatype)) == -1)
|
|
|
|
continue;
|
2009-02-13 06:12:15 +00:00
|
|
|
if ((curprivs = getprivs(id, quotatype, fspath)) == NULL)
|
|
|
|
exit(1);
|
1994-05-26 05:23:31 +00:00
|
|
|
if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0)
|
|
|
|
continue;
|
1994-11-22 18:52:58 +00:00
|
|
|
if (editit(tmpfil) && readprivs(curprivs, tmpfil))
|
2009-02-14 08:08:08 +00:00
|
|
|
putprivs(id, curprivs);
|
1994-05-26 05:23:31 +00:00
|
|
|
freeprivs(curprivs);
|
|
|
|
}
|
|
|
|
close(tmpfd);
|
|
|
|
unlink(tmpfil);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1997-09-17 06:29:23 +00:00
|
|
|
static void
|
2008-07-02 15:51:59 +00:00
|
|
|
usage(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2002-09-07 12:26:07 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
2009-02-05 14:06:43 +00:00
|
|
|
"usage: edquota [-uh] [-f fspath] [-p username] username ...",
|
2002-09-07 12:26:07 +00:00
|
|
|
" edquota [-u] -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]",
|
|
|
|
" username ...",
|
2009-02-05 14:06:43 +00:00
|
|
|
" edquota -g [-h] [-f fspath] [-p groupname] groupname ...",
|
2002-09-07 12:26:07 +00:00
|
|
|
" edquota -g -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]",
|
|
|
|
" groupname ...",
|
2001-09-28 10:22:36 +00:00
|
|
|
" edquota [-u] -t [-f fspath]",
|
|
|
|
" edquota -g -t [-f fspath]");
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine converts a name for a particular quota type to
|
|
|
|
* an identifier. This routine must agree with the kernel routine
|
|
|
|
* getinoquota as to the interpretation of quota types.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
getentry(const char *name, int quotatype)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
struct group *gr;
|
|
|
|
|
|
|
|
if (alldigits(name))
|
|
|
|
return (atoi(name));
|
|
|
|
switch(quotatype) {
|
|
|
|
case USRQUOTA:
|
1997-09-17 06:29:23 +00:00
|
|
|
if ((pw = getpwnam(name)))
|
1994-05-26 05:23:31 +00:00
|
|
|
return (pw->pw_uid);
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: no such user", name);
|
2009-02-04 00:21:36 +00:00
|
|
|
sleep(3);
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
case GRPQUOTA:
|
1997-09-17 06:29:23 +00:00
|
|
|
if ((gr = getgrnam(name)))
|
1994-05-26 05:23:31 +00:00
|
|
|
return (gr->gr_gid);
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: no such group", name);
|
2009-02-04 00:21:36 +00:00
|
|
|
sleep(3);
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%d: unknown quota type", quotatype);
|
2009-02-04 00:21:36 +00:00
|
|
|
sleep(3);
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the requested quota information.
|
|
|
|
*/
|
|
|
|
struct quotause *
|
2008-07-02 15:51:59 +00:00
|
|
|
getprivs(long id, int quotatype, char *fspath)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2009-01-30 13:54:03 +00:00
|
|
|
struct quotafile *qf;
|
2008-07-02 15:51:59 +00:00
|
|
|
struct fstab *fs;
|
|
|
|
struct quotause *qup, *quptail;
|
1994-05-26 05:23:31 +00:00
|
|
|
struct quotause *quphead;
|
|
|
|
|
|
|
|
setfsent();
|
2006-09-14 04:45:44 +00:00
|
|
|
quphead = quptail = NULL;
|
1997-09-17 06:29:23 +00:00
|
|
|
while ((fs = getfsent())) {
|
2001-09-28 10:22:36 +00:00
|
|
|
if (fspath && *fspath && strcmp(fspath, fs->fs_spec) &&
|
|
|
|
strcmp(fspath, fs->fs_file))
|
|
|
|
continue;
|
1994-05-26 05:23:31 +00:00
|
|
|
if (strcmp(fs->fs_vfstype, "ufs"))
|
|
|
|
continue;
|
2009-02-14 08:08:08 +00:00
|
|
|
if ((qf = quota_open(fs, quotatype, O_CREAT|O_RDWR)) == NULL) {
|
|
|
|
if (errno != EOPNOTSUPP)
|
|
|
|
warn("cannot open quotas on %s", fs->fs_file);
|
1994-05-26 05:23:31 +00:00
|
|
|
continue;
|
2009-02-14 08:08:08 +00:00
|
|
|
}
|
|
|
|
if ((qup = (struct quotause *)calloc(1, sizeof(*qup))) == NULL)
|
1997-09-17 06:29:23 +00:00
|
|
|
errx(2, "out of memory");
|
2009-02-14 08:08:08 +00:00
|
|
|
qup->qf = qf;
|
|
|
|
strncpy(qup->fsname, fs->fs_file, sizeof(qup->fsname));
|
|
|
|
if (quota_read(qf, &qup->dqblk, id) == -1) {
|
|
|
|
warn("cannot read quotas on %s", fs->fs_file);
|
|
|
|
freeprivs(qup);
|
|
|
|
continue;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
if (quphead == NULL)
|
|
|
|
quphead = qup;
|
|
|
|
else
|
|
|
|
quptail->next = qup;
|
|
|
|
quptail = qup;
|
|
|
|
qup->next = 0;
|
|
|
|
}
|
2009-02-13 06:12:15 +00:00
|
|
|
if (quphead == NULL) {
|
|
|
|
warnx("No quotas on %s", fspath ? fspath : "any filesystems");
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
endfsent();
|
|
|
|
return (quphead);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the requested quota information.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
void
|
2009-02-14 08:08:08 +00:00
|
|
|
putprivs(long id, struct quotause *quplist)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2009-02-14 08:08:08 +00:00
|
|
|
for (qup = quplist; qup; qup = qup->next)
|
|
|
|
if (quota_write_limits(qup->qf, &qup->dqblk, id) == -1)
|
|
|
|
warn("%s", qup->fsname);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a list of priviledges and get it edited.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
editit(char *tmpf)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
long omask;
|
2001-12-10 06:05:28 +00:00
|
|
|
int pid, status;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
|
|
|
|
top:
|
|
|
|
if ((pid = fork()) < 0) {
|
|
|
|
|
|
|
|
if (errno == EPROCLIM) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("you have too many processes");
|
1994-05-26 05:23:31 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if (errno == EAGAIN) {
|
|
|
|
sleep(1);
|
|
|
|
goto top;
|
|
|
|
}
|
1997-09-17 06:29:23 +00:00
|
|
|
warn("fork");
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (pid == 0) {
|
2008-07-02 15:51:59 +00:00
|
|
|
const char *ed;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
sigsetmask(omask);
|
|
|
|
setgid(getgid());
|
|
|
|
setuid(getuid());
|
|
|
|
if ((ed = getenv("EDITOR")) == (char *)0)
|
|
|
|
ed = _PATH_VI;
|
2001-12-10 06:05:28 +00:00
|
|
|
execlp(ed, ed, tmpf, (char *)0);
|
1997-09-17 06:29:23 +00:00
|
|
|
err(1, "%s", ed);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2001-12-10 06:05:28 +00:00
|
|
|
waitpid(pid, &status, 0);
|
1994-05-26 05:23:31 +00:00
|
|
|
sigsetmask(omask);
|
2001-12-10 06:05:28 +00:00
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a quotause list to an ASCII file.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
writeprivs(struct quotause *quplist, int outfd, char *name, int quotatype)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup;
|
1994-05-26 05:23:31 +00:00
|
|
|
FILE *fd;
|
|
|
|
|
|
|
|
ftruncate(outfd, 0);
|
|
|
|
lseek(outfd, 0, L_SET);
|
1997-09-17 06:29:23 +00:00
|
|
|
if ((fd = fdopen(dup(outfd), "w")) == NULL)
|
|
|
|
err(1, "%s", tmpfil);
|
1994-05-26 05:23:31 +00:00
|
|
|
fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
2009-02-04 00:21:36 +00:00
|
|
|
fprintf(fd, "%s: in use: %s, ", qup->fsname,
|
2009-02-10 08:09:03 +00:00
|
|
|
fmthumanvalblks(qup->dqblk.dqb_curblocks));
|
2009-02-04 00:21:36 +00:00
|
|
|
fprintf(fd, "limits (soft = %s, ",
|
2009-02-10 08:09:03 +00:00
|
|
|
fmthumanvalblks(qup->dqblk.dqb_bsoftlimit));
|
2009-02-04 00:21:36 +00:00
|
|
|
fprintf(fd, "hard = %s)\n",
|
2009-02-10 08:09:03 +00:00
|
|
|
fmthumanvalblks(qup->dqblk.dqb_bhardlimit));
|
|
|
|
fprintf(fd, "\tinodes in use: %s, ",
|
|
|
|
fmthumanvalinos(qup->dqblk.dqb_curinodes));
|
|
|
|
fprintf(fd, "limits (soft = %s, ",
|
|
|
|
fmthumanvalinos(qup->dqblk.dqb_isoftlimit));
|
|
|
|
fprintf(fd, "hard = %s)\n",
|
|
|
|
fmthumanvalinos(qup->dqblk.dqb_ihardlimit));
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-02-04 00:21:36 +00:00
|
|
|
char *
|
2009-02-10 08:09:03 +00:00
|
|
|
fmthumanvalblks(int64_t blocks)
|
2009-02-04 00:21:36 +00:00
|
|
|
{
|
2009-02-05 14:06:43 +00:00
|
|
|
static char numbuf[20];
|
2009-02-04 00:21:36 +00:00
|
|
|
|
|
|
|
if (hflag) {
|
2009-02-10 08:09:03 +00:00
|
|
|
humanize_number(numbuf, blocks < 0 ? 7 : 6,
|
2009-02-04 00:21:36 +00:00
|
|
|
dbtob(blocks), "", HN_AUTOSCALE, HN_NOSPACE);
|
2009-02-05 14:06:43 +00:00
|
|
|
return (numbuf);
|
2009-02-04 00:21:36 +00:00
|
|
|
}
|
2009-09-27 17:33:26 +00:00
|
|
|
snprintf(numbuf, sizeof(numbuf), "%juk", (uintmax_t)dbtokb(blocks));
|
2009-02-04 00:21:36 +00:00
|
|
|
return(numbuf);
|
|
|
|
}
|
|
|
|
|
2009-02-10 08:09:03 +00:00
|
|
|
char *
|
|
|
|
fmthumanvalinos(int64_t inos)
|
|
|
|
{
|
|
|
|
static char numbuf[20];
|
|
|
|
|
|
|
|
if (hflag) {
|
|
|
|
humanize_number(numbuf, inos < 0 ? 7 : 6,
|
|
|
|
inos, "", HN_AUTOSCALE, HN_NOSPACE | HN_DIVISOR_1000);
|
|
|
|
return (numbuf);
|
|
|
|
}
|
2009-09-27 17:33:26 +00:00
|
|
|
snprintf(numbuf, sizeof(numbuf), "%ju", (uintmax_t)inos);
|
2009-02-10 08:09:03 +00:00
|
|
|
return(numbuf);
|
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* Merge changes to an ASCII file into a quotause list.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
readprivs(struct quotause *quplist, char *inname)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup;
|
1994-05-26 05:23:31 +00:00
|
|
|
FILE *fd;
|
2009-09-27 17:33:26 +00:00
|
|
|
uintmax_t hardlimit, softlimit, curitems;
|
2009-02-05 14:06:43 +00:00
|
|
|
char hardunits, softunits, curitemunits;
|
1994-05-26 05:23:31 +00:00
|
|
|
int cnt;
|
2008-07-02 15:51:59 +00:00
|
|
|
char *cp;
|
1994-05-26 05:23:31 +00:00
|
|
|
struct dqblk dqblk;
|
|
|
|
char *fsp, line1[BUFSIZ], line2[BUFSIZ];
|
|
|
|
|
1994-11-22 18:52:58 +00:00
|
|
|
fd = fopen(inname, "r");
|
1994-05-26 05:23:31 +00:00
|
|
|
if (fd == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("can't re-read temp file!!");
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Discard title line, then read pairs of lines to process.
|
|
|
|
*/
|
|
|
|
(void) fgets(line1, sizeof (line1), fd);
|
|
|
|
while (fgets(line1, sizeof (line1), fd) != NULL &&
|
|
|
|
fgets(line2, sizeof (line2), fd) != NULL) {
|
|
|
|
if ((fsp = strtok(line1, " \t:")) == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: bad format", line1);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if ((cp = strtok((char *)0, "\n")) == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cnt = sscanf(cp,
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c, limits (soft = %ju%c, hard = %ju%c)",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit, &softunits,
|
|
|
|
&hardlimit, &hardunits);
|
2009-02-04 00:21:36 +00:00
|
|
|
/*
|
|
|
|
* The next three check for old-style input formats.
|
|
|
|
*/
|
|
|
|
if (cnt != 6)
|
|
|
|
cnt = sscanf(cp,
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c, limits (soft = %ju%c hard = %ju%c",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
2009-02-04 00:21:36 +00:00
|
|
|
if (cnt != 6)
|
|
|
|
cnt = sscanf(cp,
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c, limits (soft = %ju%c hard = %ju%c)",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
2009-02-04 00:21:36 +00:00
|
|
|
if (cnt != 6)
|
|
|
|
cnt = sscanf(cp,
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c, limits (soft = %ju%c, hard = %ju%c",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
2009-02-04 00:21:36 +00:00
|
|
|
if (cnt != 6) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s:%s: bad format", fsp, cp);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2009-02-10 08:09:03 +00:00
|
|
|
dqblk.dqb_curblocks = cvtblkval(curitems, curitemunits,
|
|
|
|
"current block count");
|
|
|
|
dqblk.dqb_bsoftlimit = cvtblkval(softlimit, softunits,
|
|
|
|
"block soft limit");
|
|
|
|
dqblk.dqb_bhardlimit = cvtblkval(hardlimit, hardunits,
|
|
|
|
"block hard limit");
|
1994-05-26 05:23:31 +00:00
|
|
|
if ((cp = strtok(line2, "\n")) == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: %s: bad format", fsp, line2);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2009-02-10 08:09:03 +00:00
|
|
|
cnt = sscanf(&cp[7],
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c limits (soft = %ju%c, hard = %ju%c)",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
|
|
|
/*
|
|
|
|
* The next three check for old-style input formats.
|
|
|
|
*/
|
|
|
|
if (cnt != 6)
|
2009-02-10 08:09:03 +00:00
|
|
|
cnt = sscanf(&cp[7],
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c limits (soft = %ju%c hard = %ju%c",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
|
|
|
if (cnt != 6)
|
2009-02-10 08:09:03 +00:00
|
|
|
cnt = sscanf(&cp[7],
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c limits (soft = %ju%c hard = %ju%c)",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
|
|
|
if (cnt != 6)
|
2009-02-10 08:09:03 +00:00
|
|
|
cnt = sscanf(&cp[7],
|
2009-09-27 17:33:26 +00:00
|
|
|
" in use: %ju%c limits (soft = %ju%c, hard = %ju%c",
|
2009-02-05 14:06:43 +00:00
|
|
|
&curitems, &curitemunits, &softlimit,
|
|
|
|
&softunits, &hardlimit, &hardunits);
|
2009-02-10 08:09:03 +00:00
|
|
|
if (cnt != 6) {
|
|
|
|
warnx("%s: %s: bad format cnt %d", fsp, &cp[7], cnt);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2009-02-10 08:09:03 +00:00
|
|
|
dqblk.dqb_curinodes = cvtinoval(curitems, curitemunits,
|
|
|
|
"current inode count");
|
|
|
|
dqblk.dqb_isoftlimit = cvtinoval(softlimit, softunits,
|
|
|
|
"inode soft limit");
|
|
|
|
dqblk.dqb_ihardlimit = cvtinoval(hardlimit, hardunits,
|
|
|
|
"inode hard limit");
|
1994-05-26 05:23:31 +00:00
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
|
|
|
if (strcmp(fsp, qup->fsname))
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Cause time limit to be reset when the quota
|
|
|
|
* is next used if previously had no soft limit
|
|
|
|
* or were under it, but now have a soft limit
|
|
|
|
* and are over it.
|
|
|
|
*/
|
|
|
|
if (dqblk.dqb_bsoftlimit &&
|
|
|
|
qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit &&
|
|
|
|
(qup->dqblk.dqb_bsoftlimit == 0 ||
|
|
|
|
qup->dqblk.dqb_curblocks <
|
|
|
|
qup->dqblk.dqb_bsoftlimit))
|
|
|
|
qup->dqblk.dqb_btime = 0;
|
|
|
|
if (dqblk.dqb_isoftlimit &&
|
|
|
|
qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit &&
|
|
|
|
(qup->dqblk.dqb_isoftlimit == 0 ||
|
|
|
|
qup->dqblk.dqb_curinodes <
|
|
|
|
qup->dqblk.dqb_isoftlimit))
|
|
|
|
qup->dqblk.dqb_itime = 0;
|
|
|
|
qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit;
|
|
|
|
qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit;
|
|
|
|
qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit;
|
|
|
|
qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit;
|
|
|
|
qup->flags |= FOUND;
|
2009-02-10 08:09:03 +00:00
|
|
|
/* Humanized input returns only approximate counts */
|
|
|
|
if (hflag ||
|
|
|
|
(dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
|
|
|
|
dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes))
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: cannot change current allocation", fsp);
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
/*
|
|
|
|
* Disable quotas for any filesystems that have not been found.
|
|
|
|
*/
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
|
|
|
if (qup->flags & FOUND) {
|
|
|
|
qup->flags &= ~FOUND;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qup->dqblk.dqb_bsoftlimit = 0;
|
|
|
|
qup->dqblk.dqb_bhardlimit = 0;
|
|
|
|
qup->dqblk.dqb_isoftlimit = 0;
|
|
|
|
qup->dqblk.dqb_ihardlimit = 0;
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a quotause list to an ASCII file of grace times.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
writetimes(struct quotause *quplist, int outfd, int quotatype)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup;
|
1994-05-26 05:23:31 +00:00
|
|
|
FILE *fd;
|
|
|
|
|
|
|
|
ftruncate(outfd, 0);
|
|
|
|
lseek(outfd, 0, L_SET);
|
1997-09-17 06:29:23 +00:00
|
|
|
if ((fd = fdopen(dup(outfd), "w")) == NULL)
|
|
|
|
err(1, "%s", tmpfil);
|
1994-05-26 05:23:31 +00:00
|
|
|
fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n");
|
|
|
|
fprintf(fd, "Grace period before enforcing soft limits for %ss:\n",
|
|
|
|
qfextension[quotatype]);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
|
|
|
fprintf(fd, "%s: block grace period: %s, ",
|
|
|
|
qup->fsname, cvtstoa(qup->dqblk.dqb_btime));
|
|
|
|
fprintf(fd, "file grace period: %s\n",
|
|
|
|
cvtstoa(qup->dqblk.dqb_itime));
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Merge changes of grace times in an ASCII file into a quotause list.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
readtimes(struct quotause *quplist, char *inname)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup;
|
1994-05-26 05:23:31 +00:00
|
|
|
FILE *fd;
|
|
|
|
int cnt;
|
2008-07-02 15:51:59 +00:00
|
|
|
char *cp;
|
2009-09-27 17:33:26 +00:00
|
|
|
uintmax_t itime, btime, iseconds, bseconds;
|
1994-05-26 05:23:31 +00:00
|
|
|
char *fsp, bunits[10], iunits[10], line1[BUFSIZ];
|
|
|
|
|
1994-11-22 18:52:58 +00:00
|
|
|
fd = fopen(inname, "r");
|
1994-05-26 05:23:31 +00:00
|
|
|
if (fd == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("can't re-read temp file!!");
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Discard two title lines, then read lines to process.
|
|
|
|
*/
|
|
|
|
(void) fgets(line1, sizeof (line1), fd);
|
|
|
|
(void) fgets(line1, sizeof (line1), fd);
|
|
|
|
while (fgets(line1, sizeof (line1), fd) != NULL) {
|
|
|
|
if ((fsp = strtok(line1, " \t:")) == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: bad format", line1);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if ((cp = strtok((char *)0, "\n")) == NULL) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
cnt = sscanf(cp,
|
2009-09-27 17:33:26 +00:00
|
|
|
" block grace period: %ju %s file grace period: %ju %s",
|
2009-02-04 00:21:36 +00:00
|
|
|
&btime, bunits, &itime, iunits);
|
1994-05-26 05:23:31 +00:00
|
|
|
if (cnt != 4) {
|
1997-09-17 06:29:23 +00:00
|
|
|
warnx("%s:%s: bad format", fsp, cp);
|
1994-05-26 05:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (cvtatos(btime, bunits, &bseconds) == 0)
|
|
|
|
return (0);
|
|
|
|
if (cvtatos(itime, iunits, &iseconds) == 0)
|
|
|
|
return (0);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
|
|
|
if (strcmp(fsp, qup->fsname))
|
|
|
|
continue;
|
|
|
|
qup->dqblk.dqb_btime = bseconds;
|
|
|
|
qup->dqblk.dqb_itime = iseconds;
|
|
|
|
qup->flags |= FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
/*
|
|
|
|
* reset default grace periods for any filesystems
|
|
|
|
* that have not been found.
|
|
|
|
*/
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
|
|
|
if (qup->flags & FOUND) {
|
|
|
|
qup->flags &= ~FOUND;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qup->dqblk.dqb_btime = 0;
|
|
|
|
qup->dqblk.dqb_itime = 0;
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert seconds to ASCII times.
|
|
|
|
*/
|
|
|
|
char *
|
2009-09-27 17:33:26 +00:00
|
|
|
cvtstoa(uint64_t secs)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
static char buf[20];
|
|
|
|
|
2001-12-10 06:05:28 +00:00
|
|
|
if (secs % (24 * 60 * 60) == 0) {
|
|
|
|
secs /= 24 * 60 * 60;
|
2009-09-27 17:33:26 +00:00
|
|
|
sprintf(buf, "%ju day%s", (uintmax_t)secs,
|
|
|
|
secs == 1 ? "" : "s");
|
2001-12-10 06:05:28 +00:00
|
|
|
} else if (secs % (60 * 60) == 0) {
|
|
|
|
secs /= 60 * 60;
|
2009-09-27 17:33:26 +00:00
|
|
|
sprintf(buf, "%ju hour%s", (uintmax_t)secs,
|
|
|
|
secs == 1 ? "" : "s");
|
2001-12-10 06:05:28 +00:00
|
|
|
} else if (secs % 60 == 0) {
|
|
|
|
secs /= 60;
|
2009-09-27 17:33:26 +00:00
|
|
|
sprintf(buf, "%ju minute%s", (uintmax_t)secs,
|
|
|
|
secs == 1 ? "" : "s");
|
1994-05-26 05:23:31 +00:00
|
|
|
} else
|
2009-09-27 17:33:26 +00:00
|
|
|
sprintf(buf, "%ju second%s", (uintmax_t)secs,
|
|
|
|
secs == 1 ? "" : "s");
|
1994-05-26 05:23:31 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert ASCII input times to seconds.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2009-09-27 17:33:26 +00:00
|
|
|
cvtatos(uint64_t period, char *units, uint64_t *seconds)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (bcmp(units, "second", 6) == 0)
|
2001-12-10 06:05:28 +00:00
|
|
|
*seconds = period;
|
1994-05-26 05:23:31 +00:00
|
|
|
else if (bcmp(units, "minute", 6) == 0)
|
2001-12-10 06:05:28 +00:00
|
|
|
*seconds = period * 60;
|
1994-05-26 05:23:31 +00:00
|
|
|
else if (bcmp(units, "hour", 4) == 0)
|
2001-12-10 06:05:28 +00:00
|
|
|
*seconds = period * 60 * 60;
|
1994-05-26 05:23:31 +00:00
|
|
|
else if (bcmp(units, "day", 3) == 0)
|
2001-12-10 06:05:28 +00:00
|
|
|
*seconds = period * 24 * 60 * 60;
|
1994-05-26 05:23:31 +00:00
|
|
|
else {
|
2009-02-04 00:21:36 +00:00
|
|
|
warnx("%s: bad units, specify %s\n", units,
|
1994-05-26 05:23:31 +00:00
|
|
|
"days, hours, minutes, or seconds");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-02-04 00:21:36 +00:00
|
|
|
/*
|
|
|
|
* Convert a limit to number of disk blocks.
|
|
|
|
*/
|
2009-09-27 17:33:26 +00:00
|
|
|
uint64_t
|
|
|
|
cvtblkval(uint64_t limit, char units, const char *itemname)
|
2009-02-04 00:21:36 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch(units) {
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
limit = btodb(limit);
|
|
|
|
break;
|
|
|
|
case '\0': /* historic behavior */
|
|
|
|
case ',': /* historic behavior */
|
|
|
|
case ')': /* historic behavior */
|
|
|
|
case 'K':
|
|
|
|
case 'k':
|
|
|
|
limit *= btodb(1024);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
limit *= btodb(1048576);
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
case 'g':
|
|
|
|
limit *= btodb(1073741824);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
case 't':
|
|
|
|
limit *= btodb(1099511627776);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
case 'p':
|
|
|
|
limit *= btodb(1125899906842624);
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
limit *= btodb(1152921504606846976);
|
|
|
|
break;
|
2009-02-05 14:06:43 +00:00
|
|
|
case ' ':
|
2009-02-10 08:09:03 +00:00
|
|
|
errx(2, "No space permitted between value and units for %s\n",
|
|
|
|
itemname);
|
|
|
|
break;
|
|
|
|
default:
|
2009-09-27 17:33:26 +00:00
|
|
|
errx(2, "%ju%c: unknown units for %s, specify "
|
|
|
|
"none, K, M, G, T, P, or E\n",
|
|
|
|
(uintmax_t)limit, units, itemname);
|
2009-02-10 08:09:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a limit to number of inodes.
|
|
|
|
*/
|
2009-09-27 17:33:26 +00:00
|
|
|
uint64_t
|
|
|
|
cvtinoval(uint64_t limit, char units, const char *itemname)
|
2009-02-10 08:09:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch(units) {
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
case '\0': /* historic behavior */
|
|
|
|
case ',': /* historic behavior */
|
|
|
|
case ')': /* historic behavior */
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
case 'k':
|
|
|
|
limit *= 1000;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
limit *= 1000000;
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
case 'g':
|
|
|
|
limit *= 1000000000;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
case 't':
|
|
|
|
limit *= 1000000000000;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
case 'p':
|
|
|
|
limit *= 1000000000000000;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
limit *= 1000000000000000000;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
errx(2, "No space permitted between value and units for %s\n",
|
|
|
|
itemname);
|
2009-02-05 14:06:43 +00:00
|
|
|
break;
|
2009-02-04 00:21:36 +00:00
|
|
|
default:
|
2009-09-27 17:33:26 +00:00
|
|
|
errx(2, "%ju%c: unknown units for %s, specify "
|
|
|
|
"none, K, M, G, T, P, or E\n",
|
|
|
|
(uintmax_t)limit, units, itemname);
|
2009-02-04 00:21:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (limit);
|
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
/*
|
|
|
|
* Free a list of quotause structures.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
void
|
2008-07-02 15:51:59 +00:00
|
|
|
freeprivs(struct quotause *quplist)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
struct quotause *qup, *nextqup;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
for (qup = quplist; qup; qup = nextqup) {
|
2009-02-14 08:08:08 +00:00
|
|
|
quota_close(qup->qf);
|
1994-05-26 05:23:31 +00:00
|
|
|
nextqup = qup->next;
|
|
|
|
free(qup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether a string is completely composed of digits.
|
|
|
|
*/
|
1997-09-17 06:29:23 +00:00
|
|
|
int
|
2008-07-02 15:51:59 +00:00
|
|
|
alldigits(const char *s)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2008-07-02 15:51:59 +00:00
|
|
|
int c;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
c = *s++;
|
|
|
|
do {
|
|
|
|
if (!isdigit(c))
|
|
|
|
return (0);
|
1997-09-17 06:29:23 +00:00
|
|
|
} while ((c = *s++));
|
1994-05-26 05:23:31 +00:00
|
|
|
return (1);
|
|
|
|
}
|