1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2017-11-20 19:49:47 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 12:33:43 +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.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-04 06:45:11 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1990, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
2002-04-28 11:44:30 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#ifndef lint
|
2002-04-28 11:44:30 +00:00
|
|
|
static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disk quota reporting program.
|
|
|
|
*/
|
2002-04-28 11:44:30 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/param.h>
|
1996-01-05 08:37:29 +00:00
|
|
|
#include <sys/types.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
1996-01-05 08:37:29 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/socket.h>
|
2002-04-28 11:44:30 +00:00
|
|
|
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/pmap_prot.h>
|
|
|
|
#include <rpcsvc/rquota.h>
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <ufs/ufs/quota.h>
|
2002-04-28 11:44:30 +00:00
|
|
|
|
1997-08-04 06:45:11 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <fstab.h>
|
|
|
|
#include <grp.h>
|
2006-10-21 23:57:38 +00:00
|
|
|
#include <libutil.h>
|
2002-04-28 11:44:30 +00:00
|
|
|
#include <netdb.h>
|
1997-08-04 06:45:11 +00:00
|
|
|
#include <pwd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
2007-05-07 12:10:06 +00:00
|
|
|
#include <stdint.h>
|
1996-01-05 08:37:29 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-02-11 16:25:25 +00:00
|
|
|
#include <time.h>
|
1996-06-15 01:01:02 +00:00
|
|
|
#include <unistd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2011-11-06 08:16:29 +00:00
|
|
|
static const char *qfextension[] = INITQFNAMES;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
struct quotause {
|
|
|
|
struct quotause *next;
|
|
|
|
long flags;
|
|
|
|
struct dqblk dqblk;
|
|
|
|
char fsname[MAXPATHLEN + 1];
|
1996-01-05 08:37:29 +00:00
|
|
|
};
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2010-03-04 10:54:29 +00:00
|
|
|
static char *timeprt(int64_t seconds);
|
2002-03-22 01:33:25 +00:00
|
|
|
static struct quotause *getprivs(long id, int quotatype);
|
2002-04-28 11:44:30 +00:00
|
|
|
static void usage(void);
|
2007-02-01 08:37:44 +00:00
|
|
|
static int showuid(u_long uid);
|
|
|
|
static int showgid(u_long gid);
|
|
|
|
static int showusrname(char *name);
|
|
|
|
static int showgrpname(char *name);
|
|
|
|
static int showquotas(int type, u_long id, const char *name);
|
2007-02-11 16:25:25 +00:00
|
|
|
static void showrawquotas(int type, u_long id, struct quotause *qup);
|
2002-04-28 11:44:30 +00:00
|
|
|
static void heading(int type, u_long id, const char *name, const char *tag);
|
|
|
|
static int getufsquota(struct fstab *fs, struct quotause *qup, long id,
|
|
|
|
int quotatype);
|
|
|
|
static int getnfsquota(struct statfs *fst, struct quotause *qup, long id,
|
|
|
|
int quotatype);
|
1996-06-15 01:01:02 +00:00
|
|
|
static int callaurpc(char *host, int prognum, int versnum, int procnum,
|
2002-04-28 11:44:30 +00:00
|
|
|
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
|
1996-06-15 01:01:02 +00:00
|
|
|
static int alldigits(char *s);
|
1996-01-05 08:37:29 +00:00
|
|
|
|
2011-11-06 08:16:29 +00:00
|
|
|
static int hflag;
|
|
|
|
static int lflag;
|
|
|
|
static int rflag;
|
|
|
|
static int qflag;
|
|
|
|
static int vflag;
|
|
|
|
static char *filename = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
int
|
2002-04-28 11:44:30 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-01-05 08:37:29 +00:00
|
|
|
int ngroups;
|
2009-10-21 04:35:09 +00:00
|
|
|
gid_t mygid, gidset[NGROUPS];
|
2007-02-01 08:37:44 +00:00
|
|
|
int i, ch, gflag = 0, uflag = 0, errflag = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2007-02-11 16:25:25 +00:00
|
|
|
while ((ch = getopt(argc, argv, "f:ghlrquv")) != -1) {
|
1994-05-27 12:33:43 +00:00
|
|
|
switch(ch) {
|
2007-02-11 16:25:25 +00:00
|
|
|
case 'f':
|
|
|
|
filename = optarg;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'g':
|
|
|
|
gflag++;
|
|
|
|
break;
|
2006-10-21 23:57:38 +00:00
|
|
|
case 'h':
|
|
|
|
hflag++;
|
|
|
|
break;
|
2002-08-09 00:53:00 +00:00
|
|
|
case 'l':
|
|
|
|
lflag++;
|
|
|
|
break;
|
2002-08-09 00:43:36 +00:00
|
|
|
case 'q':
|
|
|
|
qflag++;
|
|
|
|
break;
|
2007-02-11 16:25:25 +00:00
|
|
|
case 'r':
|
|
|
|
rflag++;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'u':
|
|
|
|
uflag++;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
vflag++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (!uflag && !gflag)
|
|
|
|
uflag++;
|
|
|
|
if (argc == 0) {
|
|
|
|
if (uflag)
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showuid(getuid());
|
1994-05-27 12:33:43 +00:00
|
|
|
if (gflag) {
|
1996-01-05 08:37:29 +00:00
|
|
|
mygid = getgid();
|
2009-10-21 04:35:09 +00:00
|
|
|
ngroups = getgroups(NGROUPS, gidset);
|
1997-08-04 06:45:11 +00:00
|
|
|
if (ngroups < 0)
|
|
|
|
err(1, "getgroups");
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showgid(mygid);
|
1996-01-05 08:37:29 +00:00
|
|
|
for (i = 0; i < ngroups; i++)
|
|
|
|
if (gidset[i] != mygid)
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showgid(gidset[i]);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-01 08:37:44 +00:00
|
|
|
return(errflag);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (uflag && gflag)
|
|
|
|
usage();
|
|
|
|
if (uflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showuid(atoi(*argv));
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showusrname(*argv);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-01 08:37:44 +00:00
|
|
|
return(errflag);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (gflag) {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (alldigits(*argv))
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showgid(atoi(*argv));
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2007-02-01 08:37:44 +00:00
|
|
|
errflag += showgrpname(*argv);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-01 08:37:44 +00:00
|
|
|
return(errflag);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
static void
|
2002-04-28 11:44:30 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "%s\n%s\n%s\n",
|
2007-02-11 16:25:25 +00:00
|
|
|
"usage: quota [-ghlu] [-f path] [-v | -q | -r]",
|
|
|
|
" quota [-hlu] [-f path] [-v | -q | -r] user ...",
|
|
|
|
" quota -g [-hl] [-f path] [-v | -q | -r] group ...");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified user identifier.
|
|
|
|
*/
|
2007-02-01 08:37:44 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
showuid(u_long uid)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct passwd *pwd = getpwuid(uid);
|
2002-04-28 11:44:30 +00:00
|
|
|
const char *name;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (pwd == NULL)
|
|
|
|
name = "(no account)";
|
|
|
|
else
|
|
|
|
name = pwd->pw_name;
|
2007-02-01 08:37:44 +00:00
|
|
|
return(showquotas(USRQUOTA, uid, name));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specifed user name.
|
|
|
|
*/
|
2007-02-01 08:37:44 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
showusrname(char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct passwd *pwd = getpwnam(name);
|
|
|
|
|
|
|
|
if (pwd == NULL) {
|
1997-08-04 06:45:11 +00:00
|
|
|
warnx("%s: unknown user", name);
|
2007-02-01 08:37:44 +00:00
|
|
|
return(1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-01 08:37:44 +00:00
|
|
|
return(showquotas(USRQUOTA, pwd->pw_uid, name));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specified group identifier.
|
|
|
|
*/
|
2007-02-01 08:37:44 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
showgid(u_long gid)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct group *grp = getgrgid(gid);
|
2002-04-28 11:44:30 +00:00
|
|
|
const char *name;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (grp == NULL)
|
|
|
|
name = "(no entry)";
|
|
|
|
else
|
|
|
|
name = grp->gr_name;
|
2007-02-01 08:37:44 +00:00
|
|
|
return(showquotas(GRPQUOTA, gid, name));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out quotas for a specifed group name.
|
|
|
|
*/
|
2007-02-01 08:37:44 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
showgrpname(char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct group *grp = getgrnam(name);
|
|
|
|
|
|
|
|
if (grp == NULL) {
|
1997-08-04 06:45:11 +00:00
|
|
|
warnx("%s: unknown group", name);
|
2007-02-01 08:37:44 +00:00
|
|
|
return(1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-01 08:37:44 +00:00
|
|
|
return(showquotas(GRPQUOTA, grp->gr_gid, name));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 23:57:38 +00:00
|
|
|
static void
|
2009-10-21 04:35:09 +00:00
|
|
|
prthumanval(int len, u_int64_t bytes)
|
2006-10-21 23:57:38 +00:00
|
|
|
{
|
|
|
|
char buf[len + 1];
|
|
|
|
|
2011-06-30 09:20:26 +00:00
|
|
|
/*
|
|
|
|
* Limit the width to 5 bytes as that is what users expect.
|
|
|
|
*/
|
2016-04-27 02:13:57 +00:00
|
|
|
humanize_number(buf, MIN(sizeof(buf), 5), bytes, "",
|
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
2006-10-21 23:57:38 +00:00
|
|
|
|
|
|
|
(void)printf(" %*s", len, buf);
|
|
|
|
}
|
|
|
|
|
2007-02-01 08:37:44 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
showquotas(int type, u_long id, const char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-28 11:44:30 +00:00
|
|
|
struct quotause *qup;
|
1996-01-05 08:37:29 +00:00
|
|
|
struct quotause *quplist;
|
2002-04-28 11:44:30 +00:00
|
|
|
const char *msgi, *msgb;
|
|
|
|
const char *nam;
|
2010-03-04 10:54:29 +00:00
|
|
|
char *bgrace = NULL, *igrace = NULL;
|
2007-02-01 08:37:44 +00:00
|
|
|
int lines = 0, overquota = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
static time_t now;
|
|
|
|
|
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
|
|
|
quplist = getprivs(id, type);
|
|
|
|
for (qup = quplist; qup; qup = qup->next) {
|
2010-03-04 10:54:29 +00:00
|
|
|
msgi = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (qup->dqblk.dqb_ihardlimit &&
|
2007-02-01 08:37:44 +00:00
|
|
|
qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) {
|
|
|
|
overquota++;
|
1994-05-27 12:33:43 +00:00
|
|
|
msgi = "File limit reached on";
|
2007-02-01 08:37:44 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (qup->dqblk.dqb_isoftlimit &&
|
2002-04-28 11:44:30 +00:00
|
|
|
qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
|
2007-02-01 08:37:44 +00:00
|
|
|
overquota++;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (qup->dqblk.dqb_itime > now)
|
|
|
|
msgi = "In file grace period on";
|
|
|
|
else
|
|
|
|
msgi = "Over file quota on";
|
2002-04-28 11:44:30 +00:00
|
|
|
}
|
2010-03-04 10:54:29 +00:00
|
|
|
msgb = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (qup->dqblk.dqb_bhardlimit &&
|
2007-02-01 08:37:44 +00:00
|
|
|
qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) {
|
|
|
|
overquota++;
|
1994-05-27 12:33:43 +00:00
|
|
|
msgb = "Block limit reached on";
|
2007-02-01 08:37:44 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (qup->dqblk.dqb_bsoftlimit &&
|
2002-04-28 11:44:30 +00:00
|
|
|
qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
|
2007-02-01 08:37:44 +00:00
|
|
|
overquota++;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (qup->dqblk.dqb_btime > now)
|
|
|
|
msgb = "In block grace period on";
|
|
|
|
else
|
|
|
|
msgb = "Over block quota on";
|
2002-04-28 11:44:30 +00:00
|
|
|
}
|
2007-02-11 16:25:25 +00:00
|
|
|
if (rflag) {
|
|
|
|
showrawquotas(type, id, qup);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!vflag &&
|
|
|
|
qup->dqblk.dqb_isoftlimit == 0 &&
|
|
|
|
qup->dqblk.dqb_ihardlimit == 0 &&
|
|
|
|
qup->dqblk.dqb_bsoftlimit == 0 &&
|
|
|
|
qup->dqblk.dqb_bhardlimit == 0)
|
|
|
|
continue;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (qflag) {
|
2010-03-04 10:54:29 +00:00
|
|
|
if ((msgi != NULL || msgb != NULL) &&
|
1994-05-27 12:33:43 +00:00
|
|
|
lines++ == 0)
|
|
|
|
heading(type, id, name, "");
|
2010-03-04 10:54:29 +00:00
|
|
|
if (msgi != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("\t%s %s\n", msgi, qup->fsname);
|
2010-03-04 10:54:29 +00:00
|
|
|
if (msgb != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("\t%s %s\n", msgb, qup->fsname);
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-21 04:35:09 +00:00
|
|
|
if (!vflag &&
|
|
|
|
qup->dqblk.dqb_curblocks == 0 &&
|
|
|
|
qup->dqblk.dqb_curinodes == 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
2009-10-21 04:35:09 +00:00
|
|
|
if (lines++ == 0)
|
|
|
|
heading(type, id, name, "");
|
|
|
|
nam = qup->fsname;
|
|
|
|
if (strlen(qup->fsname) > 15) {
|
|
|
|
printf("%s\n", qup->fsname);
|
|
|
|
nam = "";
|
|
|
|
}
|
|
|
|
printf("%-15s", nam);
|
|
|
|
if (hflag) {
|
|
|
|
prthumanval(7, dbtob(qup->dqblk.dqb_curblocks));
|
2010-03-04 10:54:29 +00:00
|
|
|
printf("%c", (msgb == NULL) ? ' ' : '*');
|
2009-10-21 04:35:09 +00:00
|
|
|
prthumanval(7, dbtob(qup->dqblk.dqb_bsoftlimit));
|
|
|
|
prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
|
|
|
|
} else {
|
|
|
|
printf(" %7ju%c %7ju %7ju",
|
2011-06-30 09:20:26 +00:00
|
|
|
(uintmax_t)dbtob(qup->dqblk.dqb_curblocks)
|
|
|
|
/ 1024,
|
2010-03-04 10:54:29 +00:00
|
|
|
(msgb == NULL) ? ' ' : '*',
|
2011-06-30 09:20:26 +00:00
|
|
|
(uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit)
|
|
|
|
/ 1024,
|
|
|
|
(uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit)
|
|
|
|
/ 1024);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2009-10-21 04:35:09 +00:00
|
|
|
if (msgb != NULL)
|
2010-03-04 10:54:29 +00:00
|
|
|
bgrace = timeprt(qup->dqblk.dqb_btime);
|
2009-10-21 04:35:09 +00:00
|
|
|
if (msgi != NULL)
|
2010-03-04 10:54:29 +00:00
|
|
|
igrace = timeprt(qup->dqblk.dqb_itime);
|
2009-10-21 04:35:09 +00:00
|
|
|
printf("%8s %6ju%c %6ju %6ju%8s\n"
|
2010-03-04 10:54:29 +00:00
|
|
|
, (msgb == NULL) ? "" : bgrace
|
2009-10-21 04:35:09 +00:00
|
|
|
, (uintmax_t)qup->dqblk.dqb_curinodes
|
2010-03-04 10:54:29 +00:00
|
|
|
, (msgi == NULL) ? ' ' : '*'
|
2009-10-21 04:35:09 +00:00
|
|
|
, (uintmax_t)qup->dqblk.dqb_isoftlimit
|
|
|
|
, (uintmax_t)qup->dqblk.dqb_ihardlimit
|
2010-03-04 10:54:29 +00:00
|
|
|
, (msgi == NULL) ? "" : igrace
|
2009-10-21 04:35:09 +00:00
|
|
|
);
|
2010-03-04 10:54:29 +00:00
|
|
|
if (msgb != NULL)
|
2009-10-21 04:35:09 +00:00
|
|
|
free(bgrace);
|
2010-03-04 10:54:29 +00:00
|
|
|
if (msgi != NULL)
|
2009-10-21 04:35:09 +00:00
|
|
|
free(igrace);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-11 16:25:25 +00:00
|
|
|
if (!qflag && !rflag && lines == 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
heading(type, id, name, "none");
|
2010-03-04 10:54:29 +00:00
|
|
|
return (overquota);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2007-02-11 16:25:25 +00:00
|
|
|
static void
|
2008-08-04 00:43:49 +00:00
|
|
|
showrawquotas(int type, u_long id, struct quotause *qup)
|
2007-02-11 16:25:25 +00:00
|
|
|
{
|
2010-03-04 10:54:29 +00:00
|
|
|
time_t t;
|
2009-10-21 04:35:09 +00:00
|
|
|
|
2007-02-11 16:25:25 +00:00
|
|
|
printf("Raw %s quota information for id %lu on %s\n",
|
|
|
|
type == USRQUOTA ? "user" : "group", id, qup->fsname);
|
2009-10-21 04:35:09 +00:00
|
|
|
printf("block hard limit: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_bhardlimit);
|
|
|
|
printf("block soft limit: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_bsoftlimit);
|
|
|
|
printf("current block count: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_curblocks);
|
|
|
|
printf("i-node hard limit: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_ihardlimit);
|
|
|
|
printf("i-node soft limit: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_isoftlimit);
|
|
|
|
printf("current i-node count: %ju\n",
|
|
|
|
(uintmax_t)qup->dqblk.dqb_curinodes);
|
|
|
|
printf("block grace time: %jd",
|
|
|
|
(intmax_t)qup->dqblk.dqb_btime);
|
2008-08-03 20:36:40 +00:00
|
|
|
if (qup->dqblk.dqb_btime != 0) {
|
2010-03-04 10:54:29 +00:00
|
|
|
t = qup->dqblk.dqb_btime;
|
|
|
|
printf(" %s", ctime(&t));
|
2009-10-21 04:35:09 +00:00
|
|
|
} else {
|
2007-02-11 16:25:25 +00:00
|
|
|
printf("\n");
|
2009-10-21 04:35:09 +00:00
|
|
|
}
|
2007-05-07 12:10:06 +00:00
|
|
|
printf("i-node grace time: %jd", (intmax_t)qup->dqblk.dqb_itime);
|
2008-08-03 20:36:40 +00:00
|
|
|
if (qup->dqblk.dqb_itime != 0) {
|
2010-03-04 10:54:29 +00:00
|
|
|
t = qup->dqblk.dqb_itime;
|
|
|
|
printf(" %s", ctime(&t));
|
2009-10-21 04:35:09 +00:00
|
|
|
} else {
|
2007-02-11 16:25:25 +00:00
|
|
|
printf("\n");
|
2009-10-21 04:35:09 +00:00
|
|
|
}
|
2007-02-11 16:25:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
static void
|
2002-04-28 11:44:30 +00:00
|
|
|
heading(int type, u_long id, const char *name, const char *tag)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
1996-01-09 21:41:01 +00:00
|
|
|
printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type],
|
1994-05-27 12:33:43 +00:00
|
|
|
name, *qfextension[type], id, tag);
|
|
|
|
if (!qflag && tag[0] == '\0') {
|
2009-10-21 04:35:09 +00:00
|
|
|
printf("%-15s %7s %8s %7s %7s %6s %7s %6s%8s\n"
|
1994-05-27 12:33:43 +00:00
|
|
|
, "Filesystem"
|
2001-05-23 17:12:09 +00:00
|
|
|
, "usage"
|
1994-05-27 12:33:43 +00:00
|
|
|
, "quota"
|
|
|
|
, "limit"
|
|
|
|
, "grace"
|
|
|
|
, "files"
|
|
|
|
, "quota"
|
|
|
|
, "limit"
|
|
|
|
, "grace"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the grace period and return a printable string for it.
|
|
|
|
*/
|
2007-02-04 14:06:58 +00:00
|
|
|
static char *
|
2010-03-04 10:54:29 +00:00
|
|
|
timeprt(int64_t seconds)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
time_t hours, minutes;
|
2010-03-04 10:54:29 +00:00
|
|
|
char *buf;
|
1994-05-27 12:33:43 +00:00
|
|
|
static time_t now;
|
|
|
|
|
|
|
|
if (now == 0)
|
|
|
|
time(&now);
|
2007-02-04 14:06:58 +00:00
|
|
|
if (now > seconds) {
|
2010-03-04 10:54:29 +00:00
|
|
|
if ((buf = strdup("none")) == NULL)
|
|
|
|
errx(1, "strdup() failed in timeprt()");
|
|
|
|
return (buf);
|
2007-02-04 14:06:58 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
seconds -= now;
|
|
|
|
minutes = (seconds + 30) / 60;
|
|
|
|
hours = (minutes + 30) / 60;
|
|
|
|
if (hours >= 36) {
|
2007-02-04 14:06:58 +00:00
|
|
|
if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0)
|
2010-03-04 10:54:29 +00:00
|
|
|
errx(1, "asprintf() failed in timeprt(1)");
|
1994-05-27 12:33:43 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
if (minutes >= 60) {
|
2007-02-04 14:06:58 +00:00
|
|
|
if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60,
|
|
|
|
(long)minutes % 60) < 0)
|
2010-03-04 10:54:29 +00:00
|
|
|
errx(1, "asprintf() failed in timeprt(2)");
|
1994-05-27 12:33:43 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
2007-02-04 14:06:58 +00:00
|
|
|
if (asprintf(&buf, "%2ld", (long)minutes) < 0)
|
2010-03-04 10:54:29 +00:00
|
|
|
errx(1, "asprintf() failed in timeprt(3)");
|
1994-05-27 12:33:43 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect the requested quota information.
|
|
|
|
*/
|
1996-06-15 01:01:02 +00:00
|
|
|
static struct quotause *
|
2002-04-28 11:44:30 +00:00
|
|
|
getprivs(long id, int quotatype)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-08-09 00:43:36 +00:00
|
|
|
struct quotause *qup, *quptail = NULL;
|
2002-04-28 11:44:30 +00:00
|
|
|
struct fstab *fs;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct quotause *quphead;
|
1996-01-05 08:37:29 +00:00
|
|
|
struct statfs *fst;
|
|
|
|
int nfst, i;
|
2007-02-11 16:25:25 +00:00
|
|
|
struct statfs sfb;
|
1996-01-05 08:37:29 +00:00
|
|
|
|
|
|
|
qup = quphead = (struct quotause *)0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2007-02-11 16:25:25 +00:00
|
|
|
if (filename != NULL && statfs(filename, &sfb) != 0)
|
|
|
|
err(1, "cannot statfs %s", filename);
|
2002-06-03 12:06:49 +00:00
|
|
|
nfst = getmntinfo(&fst, MNT_NOWAIT);
|
1997-08-04 06:45:11 +00:00
|
|
|
if (nfst == 0)
|
|
|
|
errx(2, "no filesystems mounted!");
|
1994-05-27 12:33:43 +00:00
|
|
|
setfsent();
|
2009-10-21 04:35:09 +00:00
|
|
|
for (i = 0; i < nfst; i++) {
|
1996-01-05 08:37:29 +00:00
|
|
|
if (qup == NULL) {
|
1996-01-09 21:41:01 +00:00
|
|
|
if ((qup = (struct quotause *)malloc(sizeof *qup))
|
1997-08-04 06:45:11 +00:00
|
|
|
== NULL)
|
|
|
|
errx(2, "out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-02-11 16:25:25 +00:00
|
|
|
/*
|
|
|
|
* See if the user requested a specific file system
|
|
|
|
* or specified a file inside a mounted file system.
|
|
|
|
*/
|
|
|
|
if (filename != NULL &&
|
|
|
|
strcmp(sfb.f_mntonname, fst[i].f_mntonname) != 0)
|
|
|
|
continue;
|
1998-01-20 12:53:43 +00:00
|
|
|
if (strcmp(fst[i].f_fstypename, "nfs") == 0) {
|
2002-08-09 00:53:00 +00:00
|
|
|
if (lflag)
|
|
|
|
continue;
|
2007-02-11 16:25:25 +00:00
|
|
|
if (getnfsquota(&fst[i], qup, id, quotatype) == 0)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
1998-06-11 03:47:29 +00:00
|
|
|
} else if (strcmp(fst[i].f_fstypename, "ufs") == 0) {
|
1996-01-05 08:37:29 +00:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* UFS filesystems must be in /etc/fstab, and must
|
|
|
|
* indicate that they have quotas on (?!) This is quite
|
|
|
|
* unlike SunOS where quotas can be enabled/disabled
|
|
|
|
* on a filesystem independent of /etc/fstab, and it
|
|
|
|
* will still print quotas for them.
|
|
|
|
*/
|
|
|
|
if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
2002-04-28 11:44:30 +00:00
|
|
|
if (getufsquota(fs, qup, id, quotatype) == 0)
|
1996-01-05 08:37:29 +00:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
continue;
|
|
|
|
strcpy(qup->fsname, fst[i].f_mntonname);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (quphead == NULL)
|
|
|
|
quphead = qup;
|
|
|
|
else
|
|
|
|
quptail->next = qup;
|
|
|
|
quptail = qup;
|
1996-01-05 08:37:29 +00:00
|
|
|
quptail->next = 0;
|
|
|
|
qup = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1996-01-05 08:37:29 +00:00
|
|
|
if (qup)
|
|
|
|
free(qup);
|
1994-05-27 12:33:43 +00:00
|
|
|
endfsent();
|
|
|
|
return (quphead);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-10-21 04:35:09 +00:00
|
|
|
* Check to see if a particular quota is available.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1996-06-15 01:01:02 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
|
1996-01-05 08:37:29 +00:00
|
|
|
{
|
2009-10-21 04:35:09 +00:00
|
|
|
struct quotafile *qf;
|
1996-01-05 08:37:29 +00:00
|
|
|
|
2009-10-21 04:35:09 +00:00
|
|
|
if ((qf = quota_open(fs, quotatype, O_RDONLY)) == NULL)
|
1996-01-05 08:37:29 +00:00
|
|
|
return (0);
|
2009-10-21 04:35:09 +00:00
|
|
|
if (quota_read(qf, &qup->dqblk, id) != 0)
|
|
|
|
return (0);
|
|
|
|
quota_close(qf);
|
1996-01-05 08:37:29 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
|
1996-01-05 08:37:29 +00:00
|
|
|
{
|
|
|
|
struct getquota_args gq_args;
|
|
|
|
struct getquota_rslt gq_rslt;
|
|
|
|
struct dqblk *dqp = &qup->dqblk;
|
|
|
|
struct timeval tv;
|
2015-07-07 20:15:09 +00:00
|
|
|
char *cp, host[NI_MAXHOST];
|
1996-01-05 08:37:29 +00:00
|
|
|
|
|
|
|
if (fst->f_flags & MNT_LOCAL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rpc.rquotad does not support group quotas
|
|
|
|
*/
|
|
|
|
if (quotatype != USRQUOTA)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* must be some form of "hostname:/path"
|
|
|
|
*/
|
2015-07-07 20:15:09 +00:00
|
|
|
cp = fst->f_mntfromname;
|
|
|
|
do {
|
|
|
|
cp = strrchr(cp, ':');
|
|
|
|
} while (cp != NULL && *(cp + 1) != '/');
|
1996-01-05 08:37:29 +00:00
|
|
|
if (cp == NULL) {
|
2000-03-26 14:48:46 +00:00
|
|
|
warnx("cannot find hostname for %s", fst->f_mntfromname);
|
1996-01-05 08:37:29 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2015-07-07 20:15:09 +00:00
|
|
|
memset(host, 0, sizeof(host));
|
|
|
|
memcpy(host, fst->f_mntfromname, cp - fst->f_mntfromname);
|
|
|
|
host[sizeof(host) - 1] = '\0';
|
1996-01-05 08:37:29 +00:00
|
|
|
|
2002-06-03 12:06:49 +00:00
|
|
|
/* Avoid attempting the RPC for special amd(8) filesystems. */
|
|
|
|
if (strncmp(fst->f_mntfromname, "pid", 3) == 0 &&
|
2015-07-07 20:15:09 +00:00
|
|
|
strchr(fst->f_mntfromname, '@') != NULL)
|
2002-06-03 12:06:49 +00:00
|
|
|
return (0);
|
|
|
|
|
1996-01-05 08:37:29 +00:00
|
|
|
gq_args.gqa_pathp = cp + 1;
|
|
|
|
gq_args.gqa_uid = id;
|
2015-07-07 20:15:09 +00:00
|
|
|
if (callaurpc(host, RQUOTAPROG, RQUOTAVERS,
|
2002-08-09 00:43:36 +00:00
|
|
|
RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args,
|
2015-07-07 20:15:09 +00:00
|
|
|
(xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0)
|
1996-01-05 08:37:29 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
switch (gq_rslt.status) {
|
|
|
|
case Q_NOQUOTA:
|
|
|
|
break;
|
|
|
|
case Q_EPERM:
|
1997-08-04 06:45:11 +00:00
|
|
|
warnx("quota permission error, host: %s",
|
1996-01-05 08:37:29 +00:00
|
|
|
fst->f_mntfromname);
|
|
|
|
break;
|
|
|
|
case Q_OK:
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
/* blocks*/
|
|
|
|
dqp->dqb_bhardlimit =
|
2018-04-16 19:33:04 +00:00
|
|
|
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
|
1996-01-05 08:37:29 +00:00
|
|
|
dqp->dqb_bsoftlimit =
|
2018-04-16 19:33:04 +00:00
|
|
|
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit *
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
|
1996-01-05 08:37:29 +00:00
|
|
|
dqp->dqb_curblocks =
|
2018-04-16 19:33:04 +00:00
|
|
|
((uint64_t)gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize) / DEV_BSIZE;
|
1996-01-05 08:37:29 +00:00
|
|
|
/* inodes */
|
|
|
|
dqp->dqb_ihardlimit =
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;
|
|
|
|
dqp->dqb_isoftlimit =
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit;
|
|
|
|
dqp->dqb_curinodes =
|
|
|
|
gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles;
|
|
|
|
/* grace times */
|
|
|
|
dqp->dqb_btime =
|
|
|
|
tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft;
|
|
|
|
dqp->dqb_itime =
|
|
|
|
tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft;
|
|
|
|
return (1);
|
|
|
|
default:
|
2000-03-26 14:48:46 +00:00
|
|
|
warnx("bad rpc result, host: %s", fst->f_mntfromname);
|
1996-01-05 08:37:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-07 20:15:09 +00:00
|
|
|
|
1996-01-05 08:37:29 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
callaurpc(char *host, int prognum, int versnum, int procnum,
|
|
|
|
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
|
1996-01-05 08:37:29 +00:00
|
|
|
{
|
|
|
|
enum clnt_stat clnt_stat;
|
|
|
|
struct timeval timeout, tottimeout;
|
|
|
|
|
|
|
|
CLIENT *client = NULL;
|
2015-07-07 20:15:09 +00:00
|
|
|
|
|
|
|
client = clnt_create(host, prognum, versnum, "udp");
|
|
|
|
if (client == NULL)
|
|
|
|
return ((int)rpc_createerr.cf_stat);
|
1996-01-05 08:37:29 +00:00
|
|
|
timeout.tv_usec = 0;
|
|
|
|
timeout.tv_sec = 6;
|
2015-07-07 20:15:09 +00:00
|
|
|
CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)(void *)&timeout);
|
1996-01-05 08:37:29 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1996-06-15 01:01:02 +00:00
|
|
|
static int
|
2002-04-28 11:44:30 +00:00
|
|
|
alldigits(char *s)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-28 11:44:30 +00:00
|
|
|
int c;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
c = *s++;
|
|
|
|
do {
|
|
|
|
if (!isdigit(c))
|
|
|
|
return (0);
|
1996-06-15 01:01:02 +00:00
|
|
|
} while ((c = *s++));
|
1994-05-27 12:33:43 +00:00
|
|
|
return (1);
|
|
|
|
}
|