2011-11-30 20:12:32 +04:00
|
|
|
/* $NetBSD: quota.c,v 1.43 2011/11/30 16:12:32 dholland Exp $ */
|
1997-01-09 23:18:21 +03:00
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
1994-06-14 01:33:03 +04:00
|
|
|
* Copyright (c) 1980, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:58:42 +04:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-09 16:58:42 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#ifndef lint
|
2008-07-21 18:19:20 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-10-19 08:59:20 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
|
|
|
|
#else
|
2011-11-30 20:12:32 +04:00
|
|
|
__RCSID("$NetBSD: quota.c,v 1.43 2011/11/30 16:12:32 dholland Exp $");
|
1997-10-19 08:59:20 +04:00
|
|
|
#endif
|
1993-04-09 16:58:42 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disk quota reporting program.
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
1994-06-28 11:47:23 +04:00
|
|
|
#include <sys/types.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
1994-06-28 11:47:23 +04:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/socket.h>
|
1997-10-19 08:59:20 +04:00
|
|
|
|
2011-11-30 20:09:29 +04:00
|
|
|
#include <assert.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <ctype.h>
|
1997-10-19 17:16:33 +04:00
|
|
|
#include <err.h>
|
1993-04-09 16:58:42 +04:00
|
|
|
#include <errno.h>
|
1997-10-19 08:59:20 +04:00
|
|
|
#include <fstab.h>
|
|
|
|
#include <grp.h>
|
1994-06-28 11:47:23 +04:00
|
|
|
#include <netdb.h>
|
1997-10-19 08:59:20 +04:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-10-19 17:16:33 +04:00
|
|
|
#include <string.h>
|
1998-04-02 14:45:54 +04:00
|
|
|
#include <time.h>
|
1997-10-19 17:16:33 +04:00
|
|
|
#include <unistd.h>
|
1997-10-19 08:59:20 +04:00
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
#include <quota/quotaprop.h>
|
|
|
|
#include <quota/quota.h>
|
1994-06-28 11:47:23 +04:00
|
|
|
|
2011-03-07 01:36:07 +03:00
|
|
|
#include "printquota.h"
|
|
|
|
#include "getvfsquota.h"
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
struct quotause {
|
|
|
|
struct quotause *next;
|
|
|
|
long flags;
|
2011-03-24 20:05:39 +03:00
|
|
|
uid_t id;
|
2011-11-30 20:12:32 +04:00
|
|
|
struct quotaval *qvs;
|
|
|
|
unsigned numqvs;
|
1993-04-09 16:58:42 +04:00
|
|
|
char fsname[MAXPATHLEN + 1];
|
1994-06-28 11:47:23 +04:00
|
|
|
};
|
1993-04-09 16:58:42 +04:00
|
|
|
#define FOUND 0x01
|
2011-03-06 20:08:10 +03:00
|
|
|
#define QUOTA2 0x02
|
|
|
|
|
2011-11-30 20:09:29 +04:00
|
|
|
static int anyusage(struct quotaval *, unsigned);
|
|
|
|
static int anyover(struct quotaval *, unsigned, time_t);
|
|
|
|
static const char *getovermsg(struct quotaval *, const char *, time_t);
|
2011-11-27 17:23:50 +04:00
|
|
|
static struct quotause *getprivs(id_t, int);
|
|
|
|
static void heading(int, id_t, const char *, const char *);
|
2011-11-30 20:09:29 +04:00
|
|
|
static int isover(struct quotaval *qv, time_t now);
|
|
|
|
static void printqv(struct quotaval *, int, int, time_t);
|
2011-03-06 23:47:59 +03:00
|
|
|
static void showgid(gid_t);
|
|
|
|
static void showgrpname(const char *);
|
2011-11-30 20:07:28 +04:00
|
|
|
static void showonequota(int, id_t, const char *, struct quotause *);
|
2011-11-27 17:23:50 +04:00
|
|
|
static void showquotas(int, id_t, const char *);
|
2011-03-06 23:47:59 +03:00
|
|
|
static void showuid(uid_t);
|
|
|
|
static void showusrname(const char *);
|
2011-11-30 20:09:29 +04:00
|
|
|
static int unlimited(struct quotaval *qvs, unsigned numqvs);
|
2011-11-27 17:24:32 +04:00
|
|
|
static void usage(void) __dead;
|
2011-03-06 23:47:59 +03:00
|
|
|
|
|
|
|
static int qflag = 0;
|
|
|
|
static int vflag = 0;
|
|
|
|
static int hflag = 0;
|
|
|
|
static int dflag = 0;
|
|
|
|
static int Dflag = 0;
|
|
|
|
static uid_t myuid;
|
2011-11-30 20:07:28 +04:00
|
|
|
static int needheading;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
int
|
2011-03-06 23:47:59 +03:00
|
|
|
main(int argc, char *argv[])
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1994-04-01 05:19:08 +04:00
|
|
|
int ngroups;
|
1995-06-03 07:12:05 +04:00
|
|
|
gid_t mygid, gidset[NGROUPS];
|
1993-04-09 16:58:42 +04:00
|
|
|
int i, gflag = 0, uflag = 0;
|
1996-04-02 01:31:33 +04:00
|
|
|
int ch;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1998-07-12 08:56:06 +04:00
|
|
|
myuid = getuid();
|
2011-03-06 20:08:10 +03:00
|
|
|
while ((ch = getopt(argc, argv, "Ddhugvq")) != -1) {
|
1993-04-09 16:58:42 +04:00
|
|
|
switch(ch) {
|
|
|
|
case 'g':
|
|
|
|
gflag++;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
uflag++;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
vflag++;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
qflag++;
|
|
|
|
break;
|
2011-03-06 20:08:10 +03:00
|
|
|
case 'h':
|
|
|
|
hflag++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dflag++;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
Dflag++;
|
|
|
|
break;
|
1993-04-09 16:58:42 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (!uflag && !gflag)
|
|
|
|
uflag++;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (dflag) {
|
|
|
|
#if 0
|
2011-03-06 23:47:59 +03:00
|
|
|
if (myuid != 0)
|
|
|
|
errx(1, "-d: permission denied");
|
2011-03-06 20:08:10 +03:00
|
|
|
#endif
|
|
|
|
if (uflag)
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_USER, 0, "");
|
2011-03-06 20:08:10 +03:00
|
|
|
if (gflag)
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_GROUP, 0, "");
|
2011-03-06 23:47:59 +03:00
|
|
|
return 0;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
if (argc == 0) {
|
|
|
|
if (uflag)
|
1998-07-12 08:56:06 +04:00
|
|
|
showuid(myuid);
|
1993-04-09 16:58:42 +04:00
|
|
|
if (gflag) {
|
2011-03-06 20:08:10 +03:00
|
|
|
if (dflag)
|
|
|
|
showgid(0);
|
|
|
|
else {
|
|
|
|
mygid = getgid();
|
|
|
|
ngroups = getgroups(NGROUPS, gidset);
|
|
|
|
if (ngroups < 0)
|
|
|
|
err(1, "getgroups");
|
|
|
|
showgid(mygid);
|
|
|
|
for (i = 0; i < ngroups; i++)
|
|
|
|
if (gidset[i] != mygid)
|
|
|
|
showgid(gidset[i]);
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-03-06 23:47:59 +03:00
|
|
|
return 0;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
if (uflag && gflag)
|
|
|
|
usage();
|
|
|
|
if (uflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
2011-03-06 23:47:59 +03:00
|
|
|
showuid((uid_t)atoi(*argv));
|
1993-04-09 16:58:42 +04:00
|
|
|
else
|
|
|
|
showusrname(*argv);
|
|
|
|
}
|
2011-03-06 23:47:59 +03:00
|
|
|
return 0;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
if (gflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
2011-03-06 23:47:59 +03:00
|
|
|
showgid((gid_t)atoi(*argv));
|
1993-04-09 16:58:42 +04:00
|
|
|
else
|
|
|
|
showgrpname(*argv);
|
|
|
|
}
|
2011-03-06 23:47:59 +03:00
|
|
|
return 0;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
1997-10-19 17:16:33 +04:00
|
|
|
/* NOTREACHED */
|
2011-03-06 23:47:59 +03:00
|
|
|
return 0;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
|
|
|
usage(void)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2011-03-06 23:47:59 +03:00
|
|
|
const char *p = getprogname();
|
|
|
|
fprintf(stderr, "Usage: %s [-Dhguqv]\n"
|
|
|
|
"\t%s [-Dhqv] -u username ...\n"
|
|
|
|
"\t%s [-Dhqv] -g groupname ...\n"
|
|
|
|
"\t%s -d [-Dhguqv]\n", p, p, p, p);
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified user identifier.
|
|
|
|
*/
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
|
|
|
showuid(uid_t uid)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct passwd *pwd = getpwuid(uid);
|
1998-07-27 02:15:38 +04:00
|
|
|
const char *name;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
if (pwd == NULL)
|
|
|
|
name = "(no account)";
|
|
|
|
else
|
|
|
|
name = pwd->pw_name;
|
|
|
|
if (uid != myuid && myuid != 0) {
|
2011-03-06 23:47:59 +03:00
|
|
|
warnx("%s (uid %d): permission denied", name, uid);
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_USER, uid, name);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-01-06 15:38:47 +03:00
|
|
|
* Print out quotas for a specified user name.
|
1993-04-09 16:58:42 +04:00
|
|
|
*/
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
|
|
|
showusrname(const char *name)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct passwd *pwd = getpwnam(name);
|
|
|
|
|
|
|
|
if (pwd == NULL) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("%s: unknown user", name);
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pwd->pw_uid != myuid && myuid != 0) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("%s (uid %d): permission denied", name, pwd->pw_uid);
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_USER, pwd->pw_uid, name);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified group identifier.
|
|
|
|
*/
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
|
|
|
showgid(gid_t gid)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct group *grp = getgrgid(gid);
|
1994-04-01 05:19:08 +04:00
|
|
|
int ngroups;
|
1995-06-03 07:12:05 +04:00
|
|
|
gid_t mygid, gidset[NGROUPS];
|
1997-10-19 17:16:33 +04:00
|
|
|
int i;
|
1998-07-27 02:15:38 +04:00
|
|
|
const char *name;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
if (grp == NULL)
|
|
|
|
name = "(no entry)";
|
|
|
|
else
|
|
|
|
name = grp->gr_name;
|
1995-06-03 07:12:05 +04:00
|
|
|
mygid = getgid();
|
1993-04-09 16:58:42 +04:00
|
|
|
ngroups = getgroups(NGROUPS, gidset);
|
|
|
|
if (ngroups < 0) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warn("getgroups");
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-06-03 07:12:05 +04:00
|
|
|
if (gid != mygid) {
|
|
|
|
for (i = 0; i < ngroups; i++)
|
|
|
|
if (gid == gidset[i])
|
|
|
|
break;
|
1998-07-12 08:56:06 +04:00
|
|
|
if (i >= ngroups && myuid != 0) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("%s (gid %d): permission denied", name, gid);
|
1995-06-03 07:12:05 +04:00
|
|
|
return;
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_GROUP, gid, name);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-01-06 15:38:47 +03:00
|
|
|
* Print out quotas for a specified group name.
|
1993-04-09 16:58:42 +04:00
|
|
|
*/
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
|
|
|
showgrpname(const char *name)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
|
|
|
struct group *grp = getgrnam(name);
|
1994-04-01 05:19:08 +04:00
|
|
|
int ngroups;
|
1995-06-03 07:12:05 +04:00
|
|
|
gid_t mygid, gidset[NGROUPS];
|
1997-10-19 17:16:33 +04:00
|
|
|
int i;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
if (grp == NULL) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("%s: unknown group", name);
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-06-03 07:12:05 +04:00
|
|
|
mygid = getgid();
|
1993-04-09 16:58:42 +04:00
|
|
|
ngroups = getgroups(NGROUPS, gidset);
|
|
|
|
if (ngroups < 0) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warn("getgroups");
|
1993-04-09 16:58:42 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-06-03 07:12:05 +04:00
|
|
|
if (grp->gr_gid != mygid) {
|
|
|
|
for (i = 0; i < ngroups; i++)
|
|
|
|
if (grp->gr_gid == gidset[i])
|
|
|
|
break;
|
1998-07-12 08:56:06 +04:00
|
|
|
if (i >= ngroups && myuid != 0) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("%s (gid %d): permission denied",
|
1995-06-03 07:12:05 +04:00
|
|
|
name, grp->gr_gid);
|
|
|
|
return;
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
showquotas(QUOTA_CLASS_GROUP, grp->gr_gid, name);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
2011-11-30 20:09:29 +04:00
|
|
|
showquotas(int type, id_t id, const char *idname)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-19 17:16:33 +04:00
|
|
|
struct quotause *qup;
|
1994-06-28 11:47:23 +04:00
|
|
|
struct quotause *quplist;
|
2011-11-30 20:07:28 +04:00
|
|
|
|
|
|
|
needheading = 1;
|
|
|
|
|
|
|
|
quplist = getprivs(id, type);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
2011-11-30 20:09:29 +04:00
|
|
|
showonequota(type, id, idname, qup);
|
2011-11-30 20:07:28 +04:00
|
|
|
}
|
|
|
|
if (!qflag) {
|
|
|
|
/* In case nothing printed, issue a header saying "none" */
|
2011-11-30 20:09:29 +04:00
|
|
|
heading(type, id, idname, "none");
|
2011-11-30 20:07:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-30 20:09:29 +04:00
|
|
|
showonequota(int type, id_t id, const char *idname, struct quotause *qup)
|
2011-11-30 20:07:28 +04:00
|
|
|
{
|
2011-11-30 20:09:29 +04:00
|
|
|
static const int isbytes[QUOTA_NLIMITS] = {
|
|
|
|
[QUOTA_LIMIT_BLOCK] = 1,
|
|
|
|
[QUOTA_LIMIT_FILE] = 0,
|
|
|
|
};
|
1993-04-09 16:58:42 +04:00
|
|
|
static time_t now;
|
2011-11-30 20:09:29 +04:00
|
|
|
struct quotaval *qvs;
|
|
|
|
unsigned numqvs, i;
|
|
|
|
const char *msg;
|
|
|
|
int isquota2;
|
|
|
|
|
2011-11-30 20:12:32 +04:00
|
|
|
qvs = qup->qvs;
|
|
|
|
numqvs = qup->numqvs;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
2011-11-30 20:07:28 +04:00
|
|
|
if (now == 0) {
|
1993-04-09 16:58:42 +04:00
|
|
|
time(&now);
|
2011-11-30 20:07:28 +04:00
|
|
|
}
|
|
|
|
|
2011-11-30 20:09:29 +04:00
|
|
|
if (!vflag && unlimited(qvs, numqvs)) {
|
2011-11-30 20:07:28 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-11-30 20:09:29 +04:00
|
|
|
|
2011-11-30 20:07:28 +04:00
|
|
|
if (qflag) {
|
2011-11-30 20:09:29 +04:00
|
|
|
for (i=0; i<numqvs; i++) {
|
|
|
|
msg = getovermsg(&qvs[i], ufs_quota_limit_names[i],
|
|
|
|
now);
|
|
|
|
if (msg != NULL) {
|
|
|
|
heading(type, id, idname, "");
|
|
|
|
printf("\t%s %s\n", msg, qup->fsname);
|
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-11-30 20:07:28 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-11-30 20:09:29 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: anyover can in fact be true if anyusage is not true,
|
|
|
|
* if there's a quota of zero set on some volume. This is
|
|
|
|
* because the check we do checks if adding one more thing
|
|
|
|
* will go over. That is reasonable, I suppose, but Arguably
|
|
|
|
* the resulting behavior with usage 0 is a bug. (Also, what
|
|
|
|
* reason do we have to believe that the reported grace expire
|
|
|
|
* time is valid if we aren't in fact over yet?)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vflag || dflag || anyover(qvs, numqvs, now) ||
|
|
|
|
anyusage(qvs, numqvs)) {
|
|
|
|
heading(type, id, idname, "");
|
2011-11-30 20:07:28 +04:00
|
|
|
if (strlen(qup->fsname) > 4) {
|
|
|
|
printf("%s\n", qup->fsname);
|
2011-11-30 20:09:29 +04:00
|
|
|
printf("%12s", "");
|
|
|
|
} else {
|
|
|
|
printf("%12s", qup->fsname);
|
|
|
|
}
|
|
|
|
|
|
|
|
isquota2 = (qup->flags & QUOTA2) != 0;
|
|
|
|
|
|
|
|
for (i=0; i<numqvs; i++) {
|
2011-11-30 20:12:32 +04:00
|
|
|
printqv(&qvs[i], isquota2,
|
|
|
|
i >= QUOTA_NLIMITS ? 0 : isbytes[i], now);
|
2011-11-30 20:09:29 +04:00
|
|
|
}
|
|
|
|
printf("\n");
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-06 23:47:59 +03:00
|
|
|
static void
|
2011-11-30 20:09:29 +04:00
|
|
|
heading(int type, id_t id, const char *idname, const char *tag)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2011-11-30 20:07:28 +04:00
|
|
|
if (needheading == 0)
|
|
|
|
return;
|
|
|
|
needheading = 0;
|
|
|
|
|
2011-03-06 20:08:10 +03:00
|
|
|
if (dflag)
|
|
|
|
printf("Default %s disk quotas: %s\n",
|
2011-03-24 20:05:39 +03:00
|
|
|
ufs_quota_class_names[type], tag);
|
2011-03-06 20:08:10 +03:00
|
|
|
else
|
2011-03-06 23:47:59 +03:00
|
|
|
printf("Disk quotas for %s %s (%cid %u): %s\n",
|
2011-11-30 20:09:29 +04:00
|
|
|
ufs_quota_class_names[type], idname,
|
2011-03-24 20:05:39 +03:00
|
|
|
*ufs_quota_class_names[type], id, tag);
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
if (!qflag && tag[0] == '\0') {
|
1999-12-16 20:29:52 +03:00
|
|
|
printf("%12s%9s %8s%9s%8s%8s %7s%8s%8s\n"
|
|
|
|
, "Filesystem"
|
|
|
|
, "blocks"
|
|
|
|
, "quota"
|
|
|
|
, "limit"
|
|
|
|
, "grace"
|
|
|
|
, "files"
|
|
|
|
, "quota"
|
|
|
|
, "limit"
|
|
|
|
, "grace"
|
1993-04-09 16:58:42 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:09:29 +04:00
|
|
|
static void
|
|
|
|
printqv(struct quotaval *qv, int isquota2, int isbytes, time_t now)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
const char *str;
|
|
|
|
int intprtflags, over, width;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The assorted finagling of width is to match the previous
|
|
|
|
* open-coded formatting for exactly two quota object types,
|
|
|
|
* which was chosen to make the default report fit in 80
|
|
|
|
* columns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
width = isbytes ? 9 : 8;
|
|
|
|
intprtflags = isbytes ? HN_B : 0;
|
|
|
|
over = isover(qv, now);
|
|
|
|
|
|
|
|
str = intprt(buf, width, qv->qv_usage, intprtflags, hflag);
|
|
|
|
printf("%*s", width, str);
|
|
|
|
|
|
|
|
printf("%c", over ? '*' : ' ');
|
|
|
|
|
|
|
|
str = intprt(buf, width, qv->qv_softlimit, intprtflags, hflag);
|
|
|
|
printf("%*s", width-1, str);
|
|
|
|
|
|
|
|
str = intprt(buf, width, qv->qv_hardlimit, intprtflags, hflag);
|
|
|
|
printf("%*s", width, str);
|
|
|
|
|
|
|
|
if (over) {
|
|
|
|
str = timeprt(buf, 9, now, qv->qv_expiretime);
|
|
|
|
} else if (isquota2 && vflag) {
|
|
|
|
str = timeprt(buf, 9, 0, qv->qv_grace);
|
|
|
|
} else {
|
|
|
|
str = "";
|
|
|
|
}
|
|
|
|
printf("%8s", str);
|
|
|
|
}
|
|
|
|
|
1993-04-09 16:58:42 +04:00
|
|
|
/*
|
|
|
|
* Collect the requested quota information.
|
|
|
|
*/
|
2011-03-06 23:47:59 +03:00
|
|
|
static struct quotause *
|
2011-11-27 17:23:50 +04:00
|
|
|
getprivs(id_t id, int quotatype)
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-19 17:16:33 +04:00
|
|
|
struct quotause *qup, *quptail;
|
1993-04-09 16:58:42 +04:00
|
|
|
struct quotause *quphead;
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *fst;
|
1994-06-28 11:47:23 +04:00
|
|
|
int nfst, i;
|
2011-03-06 20:08:10 +03:00
|
|
|
int8_t version;
|
1994-06-28 11:47:23 +04:00
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
qup = quphead = quptail = NULL;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1994-06-28 11:47:23 +04:00
|
|
|
nfst = getmntinfo(&fst, MNT_WAIT);
|
1997-10-19 17:16:33 +04:00
|
|
|
if (nfst == 0)
|
|
|
|
errx(2, "no filesystems mounted!");
|
1998-07-12 08:56:06 +04:00
|
|
|
for (i = 0; i < nfst; i++) {
|
1994-06-28 11:47:23 +04:00
|
|
|
if (qup == NULL) {
|
2011-03-06 23:47:59 +03:00
|
|
|
if ((qup = malloc(sizeof *qup)) == NULL)
|
2011-11-30 20:12:32 +04:00
|
|
|
err(1, "Out of memory");
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2007-07-18 01:36:18 +04:00
|
|
|
if (strncmp(fst[i].f_fstypename, "nfs",
|
|
|
|
sizeof(fst[i].f_fstypename)) == 0) {
|
2011-03-06 20:08:10 +03:00
|
|
|
version = 0;
|
2011-11-30 20:12:32 +04:00
|
|
|
qup->numqvs = QUOTA_NLIMITS;
|
|
|
|
qup->qvs = malloc(qup->numqvs * sizeof(qup->qvs[0]));
|
|
|
|
if (qup->qvs == NULL) {
|
|
|
|
err(1, "Out of memory");
|
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
if (getnfsquota(fst[i].f_mntfromname,
|
2011-11-30 20:12:32 +04:00
|
|
|
qup->qvs, id, ufs_quota_class_names[quotatype]) != 1)
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
2011-03-06 20:08:10 +03:00
|
|
|
} else if ((fst[i].f_flag & ST_QUOTA) != 0) {
|
2011-11-30 20:12:32 +04:00
|
|
|
qup->numqvs = QUOTA_NLIMITS;
|
|
|
|
qup->qvs = malloc(qup->numqvs * sizeof(qup->qvs[0]));
|
|
|
|
if (qup->qvs == NULL) {
|
|
|
|
err(1, "Out of memory");
|
|
|
|
}
|
|
|
|
if (getvfsquota(fst[i].f_mntonname, qup->qvs, &version,
|
2011-03-24 20:05:39 +03:00
|
|
|
id, quotatype, dflag, Dflag) != 1)
|
1994-06-28 11:47:23 +04:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
continue;
|
1997-02-11 12:29:26 +03:00
|
|
|
(void)strncpy(qup->fsname, fst[i].f_mntonname,
|
|
|
|
sizeof(qup->fsname) - 1);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (version == 2)
|
|
|
|
qup->flags |= QUOTA2;
|
1993-04-09 16:58:42 +04:00
|
|
|
if (quphead == NULL)
|
|
|
|
quphead = qup;
|
|
|
|
else
|
|
|
|
quptail->next = qup;
|
|
|
|
quptail = qup;
|
1994-06-28 11:47:23 +04:00
|
|
|
quptail->next = 0;
|
|
|
|
qup = NULL;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-03-06 23:47:59 +03:00
|
|
|
free(qup);
|
|
|
|
return quphead;
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
2011-11-30 20:09:29 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
unlimited(struct quotaval *qvs, unsigned numqvs)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i=0; i<numqvs; i++) {
|
|
|
|
if (qvs[i].qv_softlimit != UQUAD_MAX ||
|
|
|
|
qvs[i].qv_hardlimit != UQUAD_MAX) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
anyusage(struct quotaval *qvs, unsigned numqvs)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i=0; i<numqvs; i++) {
|
|
|
|
if (qvs[i].qv_usage > 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
anyover(struct quotaval *qvs, unsigned numqvs, time_t now)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i=0; i<numqvs; i++) {
|
|
|
|
if (isover(&qvs[i], now)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
isover(struct quotaval *qv, time_t now)
|
|
|
|
{
|
|
|
|
int ql_stat;
|
|
|
|
|
|
|
|
ql_stat = quota_check_limit(qv->qv_usage, 1,
|
|
|
|
qv->qv_softlimit,
|
|
|
|
qv->qv_hardlimit,
|
|
|
|
qv->qv_expiretime, now);
|
|
|
|
switch(QL_STATUS(ql_stat)) {
|
|
|
|
case QL_S_DENY_HARD:
|
|
|
|
case QL_S_DENY_GRACE:
|
|
|
|
case QL_S_ALLOW_SOFT:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
getovermsg(struct quotaval *qv, const char *what, time_t now)
|
|
|
|
{
|
|
|
|
static char buf[64];
|
|
|
|
int ql_stat;
|
|
|
|
|
|
|
|
ql_stat = quota_check_limit(qv->qv_usage, 1,
|
|
|
|
qv->qv_softlimit,
|
|
|
|
qv->qv_hardlimit,
|
|
|
|
qv->qv_expiretime, now);
|
|
|
|
switch(QL_STATUS(ql_stat)) {
|
|
|
|
case QL_S_DENY_HARD:
|
|
|
|
snprintf(buf, sizeof(buf), "%c%s limit reached on",
|
|
|
|
toupper((unsigned char)what[0]), what+1);
|
|
|
|
break;
|
|
|
|
case QL_S_DENY_GRACE:
|
|
|
|
snprintf(buf, sizeof(buf), "Over %s quota on", what);
|
|
|
|
break;
|
|
|
|
case QL_S_ALLOW_SOFT:
|
|
|
|
snprintf(buf, sizeof(buf), "In %s grace period on", what);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|