Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/quota/quota.c
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
static int showgrpname(char *name); | static int showgrpname(char *name); | ||||
static int showquotas(int type, u_long id, const char *name); | static int showquotas(int type, u_long id, const char *name); | ||||
static void showrawquotas(int type, u_long id, struct quotause *qup); | static void showrawquotas(int type, u_long id, struct quotause *qup); | ||||
static void heading(int type, u_long id, const char *name, const char *tag); | 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, | static int getufsquota(struct fstab *fs, struct quotause *qup, long id, | ||||
int quotatype); | int quotatype); | ||||
static int getnfsquota(struct statfs *fst, struct quotause *qup, long id, | static int getnfsquota(struct statfs *fst, struct quotause *qup, long id, | ||||
int quotatype); | int quotatype); | ||||
static int callaurpc(char *host, int prognum, int versnum, int procnum, | static enum clnt_stat callaurpc(char *host, int prognum, int versnum, int procnum, | ||||
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); | xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); | ||||
static int alldigits(char *s); | static int alldigits(char *s); | ||||
static int hflag; | static int hflag; | ||||
static int lflag; | static int lflag; | ||||
static int rflag; | static int rflag; | ||||
static int qflag; | static int qflag; | ||||
static int vflag; | static int vflag; | ||||
▲ Show 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | if (quota_read(qf, &qup->dqblk, id) != 0) | ||||
return (0); | return (0); | ||||
quota_close(qf); | quota_close(qf); | ||||
return (1); | return (1); | ||||
} | } | ||||
static int | static int | ||||
getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype) | getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype) | ||||
{ | { | ||||
struct getquota_args gq_args; | struct ext_getquota_args gq_args; | ||||
struct getquota_args old_gq_args; | |||||
struct getquota_rslt gq_rslt; | struct getquota_rslt gq_rslt; | ||||
struct dqblk *dqp = &qup->dqblk; | struct dqblk *dqp = &qup->dqblk; | ||||
struct timeval tv; | struct timeval tv; | ||||
char *cp, host[NI_MAXHOST]; | char *cp, host[NI_MAXHOST]; | ||||
enum clnt_stat call_stat; | |||||
if (fst->f_flags & MNT_LOCAL) | if (fst->f_flags & MNT_LOCAL) | ||||
return (0); | return (0); | ||||
/* | /* | ||||
* rpc.rquotad does not support group quotas | |||||
*/ | |||||
if (quotatype != USRQUOTA) | |||||
return (0); | |||||
/* | |||||
* must be some form of "hostname:/path" | * must be some form of "hostname:/path" | ||||
*/ | */ | ||||
cp = fst->f_mntfromname; | cp = fst->f_mntfromname; | ||||
do { | do { | ||||
cp = strrchr(cp, ':'); | cp = strrchr(cp, ':'); | ||||
} while (cp != NULL && *(cp + 1) != '/'); | } while (cp != NULL && *(cp + 1) != '/'); | ||||
if (cp == NULL) { | if (cp == NULL) { | ||||
warnx("cannot find hostname for %s", fst->f_mntfromname); | warnx("cannot find hostname for %s", fst->f_mntfromname); | ||||
return (0); | return (0); | ||||
} | } | ||||
memset(host, 0, sizeof(host)); | memset(host, 0, sizeof(host)); | ||||
memcpy(host, fst->f_mntfromname, cp - fst->f_mntfromname); | memcpy(host, fst->f_mntfromname, cp - fst->f_mntfromname); | ||||
host[sizeof(host) - 1] = '\0'; | host[sizeof(host) - 1] = '\0'; | ||||
/* Avoid attempting the RPC for special amd(8) filesystems. */ | /* Avoid attempting the RPC for special amd(8) filesystems. */ | ||||
if (strncmp(fst->f_mntfromname, "pid", 3) == 0 && | if (strncmp(fst->f_mntfromname, "pid", 3) == 0 && | ||||
strchr(fst->f_mntfromname, '@') != NULL) | strchr(fst->f_mntfromname, '@') != NULL) | ||||
return (0); | return (0); | ||||
gq_args.gqa_pathp = cp + 1; | gq_args.gqa_pathp = cp + 1; | ||||
gq_args.gqa_uid = id; | gq_args.gqa_id = id; | ||||
if (callaurpc(host, RQUOTAPROG, RQUOTAVERS, | gq_args.gqa_type = quotatype; | ||||
RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args, | |||||
(xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) | call_stat = callaurpc(host, RQUOTAPROG, EXT_RQUOTAVERS, | ||||
RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_ext_getquota_args, (char *)&gq_args, | |||||
(xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt); | |||||
if (call_stat == RPC_PROGVERSMISMATCH) { | |||||
if (quotatype == USRQUOTA) { | |||||
old_gq_args.gqa_pathp = cp + 1; | |||||
old_gq_args.gqa_uid = id; | |||||
call_stat = callaurpc(host, RQUOTAPROG, RQUOTAVERS, | |||||
RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&old_gq_args, | |||||
(xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt); | |||||
} else { | |||||
/* Old rpc quota does not support group type */ | |||||
return (0); | return (0); | ||||
} | |||||
} | |||||
if (call_stat != 0) | |||||
return (call_stat); | |||||
switch (gq_rslt.status) { | switch (gq_rslt.status) { | ||||
case Q_NOQUOTA: | case Q_NOQUOTA: | ||||
break; | break; | ||||
case Q_EPERM: | case Q_EPERM: | ||||
warnx("quota permission error, host: %s", | warnx("quota permission error, host: %s", | ||||
fst->f_mntfromname); | fst->f_mntfromname); | ||||
break; | break; | ||||
Show All 25 Lines | getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype) | ||||
default: | default: | ||||
warnx("bad rpc result, host: %s", fst->f_mntfromname); | warnx("bad rpc result, host: %s", fst->f_mntfromname); | ||||
break; | break; | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static enum clnt_stat | ||||
callaurpc(char *host, int prognum, int versnum, int procnum, | callaurpc(char *host, int prognum, int versnum, int procnum, | ||||
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) | xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) | ||||
{ | { | ||||
enum clnt_stat clnt_stat; | enum clnt_stat clnt_stat; | ||||
struct timeval timeout, tottimeout; | struct timeval timeout, tottimeout; | ||||
CLIENT *client = NULL; | CLIENT *client = NULL; | ||||
client = clnt_create(host, prognum, versnum, "udp"); | client = clnt_create(host, prognum, versnum, "udp"); | ||||
if (client == NULL) | if (client == NULL) | ||||
return ((int)rpc_createerr.cf_stat); | return ((int)rpc_createerr.cf_stat); | ||||
timeout.tv_usec = 0; | timeout.tv_usec = 0; | ||||
timeout.tv_sec = 6; | timeout.tv_sec = 6; | ||||
CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)(void *)&timeout); | CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)(void *)&timeout); | ||||
client->cl_auth = authunix_create_default(); | client->cl_auth = authunix_create_default(); | ||||
tottimeout.tv_sec = 25; | tottimeout.tv_sec = 25; | ||||
tottimeout.tv_usec = 0; | tottimeout.tv_usec = 0; | ||||
clnt_stat = clnt_call(client, procnum, inproc, in, | clnt_stat = clnt_call(client, procnum, inproc, in, | ||||
outproc, out, tottimeout); | outproc, out, tottimeout); | ||||
return (clnt_stat); | |||||
return ((int) clnt_stat); | |||||
} | } | ||||
static int | static int | ||||
alldigits(char *s) | alldigits(char *s) | ||||
{ | { | ||||
int c; | int c; | ||||
c = *s++; | c = *s++; | ||||
do { | do { | ||||
if (!isdigit(c)) | if (!isdigit(c)) | ||||
return (0); | return (0); | ||||
} while ((c = *s++)); | } while ((c = *s++)); | ||||
return (1); | return (1); | ||||
} | } |