2011-03-06 20:08:10 +03:00
|
|
|
/* $NetBSD: quota.c,v 1.34 2011/03/06 17:08:42 bouyer 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-03-06 20:08:10 +03:00
|
|
|
__RCSID("$NetBSD: quota.c,v 1.34 2011/03/06 17:08:42 bouyer 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
|
|
|
|
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-06 20:08:10 +03:00
|
|
|
#include <ufs/ufs/quota2.h>
|
|
|
|
#include <ufs/ufs/quota1.h>
|
|
|
|
|
1994-06-28 11:47:23 +04:00
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/pmap_prot.h>
|
|
|
|
#include <rpcsvc/rquota.h>
|
|
|
|
|
2011-03-06 20:08:10 +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-06 20:08:10 +03:00
|
|
|
struct quota2_entry q2e;
|
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
|
|
|
|
|
|
|
|
int alldigits(char *);
|
|
|
|
int callaurpc(char *, int, int, int, xdrproc_t, void *, xdrproc_t, void *);
|
|
|
|
int main(int, char **);
|
|
|
|
int getnfsquota(struct statvfs *, struct fstab *, struct quotause *,
|
|
|
|
long, int);
|
|
|
|
struct quotause *getprivs(long id, int quotatype);
|
|
|
|
void heading(int, u_long, const char *, const char *);
|
|
|
|
void showgid(gid_t);
|
|
|
|
void showgrpname(const char *);
|
|
|
|
void showquotas(int, u_long, const char *);
|
|
|
|
void showuid(uid_t);
|
|
|
|
void showusrname(const char *);
|
|
|
|
void usage(void);
|
|
|
|
|
|
|
|
int qflag = 0;
|
|
|
|
int vflag = 0;
|
|
|
|
int hflag = 0;
|
|
|
|
int dflag = 0;
|
|
|
|
int Dflag = 0;
|
1998-07-12 08:56:06 +04:00
|
|
|
uid_t myuid;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
int
|
1993-04-09 16:58:42 +04:00
|
|
|
main(argc, argv)
|
1997-10-19 17:16:33 +04:00
|
|
|
int argc;
|
1993-04-09 16:58:42 +04:00
|
|
|
char *argv[];
|
|
|
|
{
|
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
|
|
|
|
if (myuid != 0) {
|
|
|
|
printf("quota: -d: permission denied\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (uflag)
|
|
|
|
showquotas(USRQUOTA, 0, "");
|
|
|
|
if (gflag)
|
|
|
|
showquotas(GRPQUOTA, 0, "");
|
|
|
|
exit(0);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (uflag && gflag)
|
|
|
|
usage();
|
|
|
|
if (uflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
|
|
|
showuid(atoi(*argv));
|
|
|
|
else
|
|
|
|
showusrname(*argv);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (gflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
|
|
|
showgid(atoi(*argv));
|
|
|
|
else
|
|
|
|
showgrpname(*argv);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
1997-10-19 17:16:33 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
return (0);
|
1993-04-09 16:58:42 +04:00
|
|
|
}
|
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
|
2011-03-06 20:08:10 +03:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
|
|
|
"usage: quota [-Dhguqv]",
|
|
|
|
"\tquota [-Dhqv] -u username ...",
|
|
|
|
"\tquota [-Dhqv] -g groupname ...",
|
|
|
|
"\tquota -d [-Dhguqv]");
|
1993-04-09 16:58:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified user identifier.
|
|
|
|
*/
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
showuid(uid)
|
1997-10-19 17:16:33 +04:00
|
|
|
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) {
|
|
|
|
printf("quota: %s (uid %d): permission denied\n", name, uid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
showquotas(USRQUOTA, uid, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-01-06 15:38:47 +03:00
|
|
|
* Print out quotas for a specified user name.
|
1993-04-09 16:58:42 +04:00
|
|
|
*/
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
showusrname(name)
|
1998-07-27 02:15:38 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
showquotas(USRQUOTA, pwd->pw_uid, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified group identifier.
|
|
|
|
*/
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
showgid(gid)
|
1997-10-19 17:16:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
showquotas(GRPQUOTA, gid, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-01-06 15:38:47 +03:00
|
|
|
* Print out quotas for a specified group name.
|
1993-04-09 16:58:42 +04:00
|
|
|
*/
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
showgrpname(name)
|
1998-07-27 02:15:38 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
showquotas(GRPQUOTA, grp->gr_gid, name);
|
|
|
|
}
|
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
showquotas(type, id, name)
|
|
|
|
int type;
|
|
|
|
u_long id;
|
1998-07-27 02:15:38 +04:00
|
|
|
const char *name;
|
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-03-06 20:08:10 +03:00
|
|
|
const char *msgi, *msgb, *nam, *timemsg;
|
1997-10-19 17:16:33 +04:00
|
|
|
int lines = 0;
|
1993-04-09 16:58:42 +04:00
|
|
|
static time_t now;
|
|
|
|
|
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
|
|
|
quplist = getprivs(id, type);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
2011-03-06 20:08:10 +03:00
|
|
|
int ql_stat;
|
1993-04-09 16:58:42 +04:00
|
|
|
if (!vflag &&
|
2011-03-06 20:08:10 +03:00
|
|
|
qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit == UQUAD_MAX &&
|
|
|
|
qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit == UQUAD_MAX &&
|
|
|
|
qup->q2e.q2e_val[QL_FILE].q2v_softlimit == UQUAD_MAX &&
|
|
|
|
qup->q2e.q2e_val[QL_FILE].q2v_hardlimit == UQUAD_MAX)
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
2011-03-06 20:08:10 +03:00
|
|
|
ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_FILE],
|
|
|
|
1, now);
|
|
|
|
switch(QL_STATUS(ql_stat)) {
|
|
|
|
case QL_S_DENY_HARD:
|
1993-04-09 16:58:42 +04:00
|
|
|
msgi = "File limit reached on";
|
2011-03-06 20:08:10 +03:00
|
|
|
break;
|
|
|
|
case QL_S_DENY_GRACE:
|
|
|
|
msgi = "Over file quota on";
|
|
|
|
break;
|
|
|
|
case QL_S_ALLOW_SOFT:
|
|
|
|
msgi = "In file grace period on";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msgi = NULL;
|
1998-08-26 00:59:36 +04:00
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_BLOCK],
|
|
|
|
1, now);
|
|
|
|
switch(QL_STATUS(ql_stat)) {
|
|
|
|
case QL_S_DENY_HARD:
|
1993-04-09 16:58:42 +04:00
|
|
|
msgb = "Block limit reached on";
|
2011-03-06 20:08:10 +03:00
|
|
|
break;
|
|
|
|
case QL_S_DENY_GRACE:
|
|
|
|
msgb = "Over block quota on";
|
|
|
|
break;
|
|
|
|
case QL_S_ALLOW_SOFT:
|
|
|
|
msgb = "In block grace period on";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
msgb = NULL;
|
1998-08-26 00:59:36 +04:00
|
|
|
}
|
1993-04-09 16:58:42 +04:00
|
|
|
if (qflag) {
|
2009-04-13 08:16:38 +04:00
|
|
|
if ((msgi != NULL || msgb != NULL) &&
|
1993-04-09 16:58:42 +04:00
|
|
|
lines++ == 0)
|
|
|
|
heading(type, id, name, "");
|
2009-04-13 08:16:38 +04:00
|
|
|
if (msgi != NULL)
|
1993-04-09 16:58:42 +04:00
|
|
|
printf("\t%s %s\n", msgi, qup->fsname);
|
2009-04-13 08:16:38 +04:00
|
|
|
if (msgb != NULL)
|
1993-04-09 16:58:42 +04:00
|
|
|
printf("\t%s %s\n", msgb, qup->fsname);
|
|
|
|
continue;
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
if (vflag || dflag || msgi || msgb ||
|
|
|
|
qup->q2e.q2e_val[QL_BLOCK].q2v_cur ||
|
|
|
|
qup->q2e.q2e_val[QL_FILE].q2v_cur) {
|
1993-04-09 16:58:42 +04:00
|
|
|
if (lines++ == 0)
|
|
|
|
heading(type, id, name, "");
|
1994-06-28 11:47:23 +04:00
|
|
|
nam = qup->fsname;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (strlen(qup->fsname) > 4) {
|
1994-06-28 11:47:23 +04:00
|
|
|
printf("%s\n", qup->fsname);
|
|
|
|
nam = "";
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
if (msgb)
|
|
|
|
timemsg = timeprt(now,
|
|
|
|
qup->q2e.q2e_val[QL_BLOCK].q2v_time, 8);
|
|
|
|
else if ((qup->flags & QUOTA2) != 0 && vflag)
|
|
|
|
timemsg = timeprt(0,
|
|
|
|
qup->q2e.q2e_val[QL_BLOCK].q2v_grace, 8);
|
|
|
|
else
|
|
|
|
timemsg = "";
|
|
|
|
|
|
|
|
printf("%12s%9s%c%8s%9s%8s"
|
1999-12-16 20:29:52 +03:00
|
|
|
, nam
|
2011-03-06 20:08:10 +03:00
|
|
|
, intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_cur
|
|
|
|
,HN_B, hflag, 8)
|
2009-04-13 08:16:38 +04:00
|
|
|
, (msgb == NULL) ? ' ' : '*'
|
2011-03-06 20:08:10 +03:00
|
|
|
, intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit
|
|
|
|
, HN_B, hflag, 8)
|
|
|
|
, intprt(qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit
|
|
|
|
, HN_B, hflag, 8)
|
|
|
|
, timemsg);
|
|
|
|
|
|
|
|
if (msgi)
|
|
|
|
timemsg = timeprt(now,
|
|
|
|
qup->q2e.q2e_val[QL_FILE].q2v_time, 8);
|
|
|
|
else if ((qup->flags & QUOTA2) != 0 && vflag)
|
|
|
|
timemsg = timeprt(0,
|
|
|
|
qup->q2e.q2e_val[QL_FILE].q2v_grace, 8);
|
|
|
|
else
|
|
|
|
timemsg = "";
|
|
|
|
|
|
|
|
printf("%8s%c%7s%8s%8s\n"
|
|
|
|
, intprt(qup->q2e.q2e_val[QL_FILE].q2v_cur
|
|
|
|
, 0, hflag, 7)
|
2009-04-13 08:16:38 +04:00
|
|
|
, (msgi == NULL) ? ' ' : '*'
|
2011-03-06 20:08:10 +03:00
|
|
|
, intprt(qup->q2e.q2e_val[QL_FILE].q2v_softlimit
|
|
|
|
, 0, hflag, 7)
|
|
|
|
, intprt(qup->q2e.q2e_val[QL_FILE].q2v_hardlimit
|
|
|
|
, 0, hflag, 7)
|
|
|
|
, timemsg);
|
1993-04-09 16:58:42 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!qflag && lines == 0)
|
|
|
|
heading(type, id, name, "none");
|
|
|
|
}
|
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
void
|
1993-04-09 16:58:42 +04:00
|
|
|
heading(type, id, name, tag)
|
|
|
|
int type;
|
|
|
|
u_long id;
|
1998-07-27 02:15:38 +04:00
|
|
|
const char *name, *tag;
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
2011-03-06 20:08:10 +03:00
|
|
|
if (dflag)
|
|
|
|
printf("Default %s disk quotas: %s\n",
|
|
|
|
qfextension[type], tag);
|
|
|
|
else
|
|
|
|
printf("Disk quotas for %s %s (%cid %ld): %s\n",
|
|
|
|
qfextension[type], name, *qfextension[type],
|
|
|
|
(u_long)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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the requested quota information.
|
|
|
|
*/
|
|
|
|
struct quotause *
|
|
|
|
getprivs(id, quotatype)
|
1997-10-19 17:16:33 +04:00
|
|
|
long id;
|
1993-04-09 16:58:42 +04:00
|
|
|
int quotatype;
|
|
|
|
{
|
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) {
|
1997-10-19 17:16:33 +04:00
|
|
|
if ((qup =
|
|
|
|
(struct quotause *)malloc(sizeof *qup)) == NULL)
|
|
|
|
errx(2, "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;
|
1994-06-28 11:47:23 +04:00
|
|
|
if (getnfsquota(&fst[i], NULL, qup, id, quotatype) == 0)
|
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) {
|
|
|
|
if (getvfsquota(fst[i].f_mntonname, &qup->q2e, &version,
|
|
|
|
id, quotatype, dflag, Dflag) == 0)
|
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
|
|
|
}
|
1994-06-28 11:47:23 +04:00
|
|
|
if (qup)
|
|
|
|
free(qup);
|
1993-04-09 16:58:42 +04:00
|
|
|
return (quphead);
|
|
|
|
}
|
|
|
|
|
1994-06-28 11:47:23 +04:00
|
|
|
int
|
|
|
|
getnfsquota(fst, fs, qup, id, quotatype)
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *fst;
|
1994-06-28 11:47:23 +04:00
|
|
|
struct fstab *fs;
|
|
|
|
struct quotause *qup;
|
|
|
|
long id;
|
|
|
|
int quotatype;
|
|
|
|
{
|
|
|
|
struct getquota_args gq_args;
|
2003-02-14 17:55:58 +03:00
|
|
|
struct ext_getquota_args ext_gq_args;
|
1994-06-28 11:47:23 +04:00
|
|
|
struct getquota_rslt gq_rslt;
|
2011-03-06 20:08:10 +03:00
|
|
|
struct quota2_entry *q2e = &qup->q2e;
|
|
|
|
struct dqblk dqblk;
|
1994-06-28 11:47:23 +04:00
|
|
|
struct timeval tv;
|
|
|
|
char *cp;
|
2003-02-14 17:55:58 +03:00
|
|
|
int ret;
|
1994-06-28 11:47:23 +04:00
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
if (fst->f_flag & MNT_LOCAL)
|
1994-06-28 11:47:23 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* must be some form of "hostname:/path"
|
|
|
|
*/
|
|
|
|
cp = strchr(fst->f_mntfromname, ':');
|
|
|
|
if (cp == NULL) {
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("cannot find hostname for %s", fst->f_mntfromname);
|
1994-06-28 11:47:23 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp = '\0';
|
|
|
|
if (*(cp+1) != '/') {
|
|
|
|
*cp = ':';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-02-14 17:55:58 +03:00
|
|
|
ext_gq_args.gqa_pathp = cp + 1;
|
|
|
|
ext_gq_args.gqa_id = id;
|
|
|
|
ext_gq_args.gqa_type =
|
|
|
|
(quotatype == USRQUOTA) ? RQUOTA_USRQUOTA : RQUOTA_GRPQUOTA;
|
|
|
|
ret = callaurpc(fst->f_mntfromname, RQUOTAPROG, EXT_RQUOTAVERS,
|
|
|
|
RQUOTAPROC_GETQUOTA, xdr_ext_getquota_args, &ext_gq_args,
|
|
|
|
xdr_getquota_rslt, &gq_rslt);
|
2003-09-21 21:01:43 +04:00
|
|
|
if (ret == RPC_PROGVERSMISMATCH) {
|
2003-02-14 17:55:58 +03:00
|
|
|
if (quotatype != USRQUOTA) {
|
|
|
|
*cp = ':';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/* try RQUOTAVERS */
|
|
|
|
gq_args.gqa_pathp = cp + 1;
|
|
|
|
gq_args.gqa_uid = id;
|
|
|
|
ret = callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS,
|
|
|
|
RQUOTAPROC_GETQUOTA, xdr_getquota_args, &gq_args,
|
|
|
|
xdr_getquota_rslt, &gq_rslt);
|
|
|
|
}
|
|
|
|
if (ret != RPC_SUCCESS) {
|
1994-06-28 11:47:23 +04:00
|
|
|
*cp = ':';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (gq_rslt.status) {
|
|
|
|
case Q_NOQUOTA:
|
|
|
|
break;
|
|
|
|
case Q_EPERM:
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("quota permission error, host: %s", fst->f_mntfromname);
|
1994-06-28 11:47:23 +04:00
|
|
|
break;
|
|
|
|
case Q_OK:
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
/* blocks*/
|
2011-03-06 20:08:10 +03:00
|
|
|
q2e->q2e_val[QL_BLOCK].q2v_hardlimit =
|
|
|
|
dqblk.dqb_bhardlimit =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
|
2001-03-30 01:54:01 +04:00
|
|
|
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_bsoftlimit =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit *
|
2001-03-30 01:54:01 +04:00
|
|
|
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_curblocks =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
|
2001-03-30 01:54:01 +04:00
|
|
|
(gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
|
1994-06-28 11:47:23 +04:00
|
|
|
/* inodes */
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_ihardlimit =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_isoftlimit =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit;
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_curinodes =
|
1994-06-28 11:47:23 +04:00
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles;
|
|
|
|
/* grace times */
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_btime =
|
1994-06-28 11:47:23 +04:00
|
|
|
tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft;
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk.dqb_itime =
|
1994-06-28 11:47:23 +04:00
|
|
|
tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft;
|
2011-03-06 20:08:10 +03:00
|
|
|
dqblk2q2e(&dqblk, q2e);
|
1994-06-28 11:47:23 +04:00
|
|
|
*cp = ':';
|
|
|
|
return (1);
|
|
|
|
default:
|
1997-10-19 17:16:33 +04:00
|
|
|
warnx("bad rpc result, host: %s", fst->f_mntfromname);
|
1994-06-28 11:47:23 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
*cp = ':';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
callaurpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
|
|
|
|
char *host;
|
1997-10-19 17:16:33 +04:00
|
|
|
int prognum, versnum, procnum;
|
|
|
|
xdrproc_t inproc;
|
|
|
|
void *in;
|
|
|
|
xdrproc_t outproc;
|
|
|
|
void *out;
|
1994-06-28 11:47:23 +04:00
|
|
|
{
|
|
|
|
struct sockaddr_in server_addr;
|
|
|
|
enum clnt_stat clnt_stat;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct timeval timeout, tottimeout;
|
|
|
|
|
|
|
|
CLIENT *client = NULL;
|
2009-04-13 08:16:38 +04:00
|
|
|
int sock = RPC_ANYSOCK;
|
1994-06-28 11:47:23 +04:00
|
|
|
|
|
|
|
if ((hp = gethostbyname(host)) == NULL)
|
|
|
|
return ((int) RPC_UNKNOWNHOST);
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
timeout.tv_sec = 6;
|
1997-10-19 17:16:33 +04:00
|
|
|
memmove(&server_addr.sin_addr, hp->h_addr, hp->h_length);
|
1994-06-28 11:47:23 +04:00
|
|
|
server_addr.sin_family = AF_INET;
|
|
|
|
server_addr.sin_port = 0;
|
|
|
|
|
|
|
|
if ((client = clntudp_create(&server_addr, prognum,
|
2009-04-13 08:16:38 +04:00
|
|
|
versnum, timeout, &sock)) == NULL)
|
1994-06-28 11:47:23 +04:00
|
|
|
return ((int) rpc_createerr.cf_stat);
|
|
|
|
|
|
|
|
client->cl_auth = authunix_create_default();
|
|
|
|
tottimeout.tv_sec = 25;
|
|
|
|
tottimeout.tv_usec = 0;
|
|
|
|
clnt_stat = clnt_call(client, procnum, inproc, in,
|
|
|
|
outproc, out, tottimeout);
|
|
|
|
|
|
|
|
return ((int) clnt_stat);
|
|
|
|
}
|
|
|
|
|
1997-10-19 17:16:33 +04:00
|
|
|
int
|
1993-04-09 16:58:42 +04:00
|
|
|
alldigits(s)
|
1997-10-19 17:16:33 +04:00
|
|
|
char *s;
|
1993-04-09 16:58:42 +04:00
|
|
|
{
|
1997-10-19 17:16:33 +04:00
|
|
|
int c;
|
1993-04-09 16:58:42 +04:00
|
|
|
|
|
|
|
c = *s++;
|
|
|
|
do {
|
|
|
|
if (!isdigit(c))
|
|
|
|
return (0);
|
1997-10-19 17:16:33 +04:00
|
|
|
} while ((c = *s++) != 0);
|
1993-04-09 16:58:42 +04:00
|
|
|
return (1);
|
|
|
|
}
|