Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/rpc.rquotad Update rquotad to use the new libquota API.
details: https://anonhg.NetBSD.org/src/rev/03e500eb6b25
branches: trunk
changeset: 772605:03e500eb6b25
user: dholland <dholland%NetBSD.org@localhost>
date: Mon Jan 09 15:37:34 2012 +0000
description:
Update rquotad to use the new libquota API.
diffstat:
libexec/rpc.rquotad/rquotad.c | 149 +++++++++++++++++++++++++++++------------
1 files changed, 106 insertions(+), 43 deletions(-)
diffs (215 lines):
diff -r d7699eea0695 -r 03e500eb6b25 libexec/rpc.rquotad/rquotad.c
--- a/libexec/rpc.rquotad/rquotad.c Mon Jan 09 15:35:44 2012 +0000
+++ b/libexec/rpc.rquotad/rquotad.c Mon Jan 09 15:37:34 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rquotad.c,v 1.31 2011/11/25 16:55:05 dholland Exp $ */
+/* $NetBSD: rquotad.c,v 1.32 2012/01/09 15:37:34 dholland Exp $ */
/*
* by Manuel Bouyer (bouyer%ensta.fr@localhost). Public domain.
@@ -6,7 +6,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rquotad.c,v 1.31 2011/11/25 16:55:05 dholland Exp $");
+__RCSID("$NetBSD: rquotad.c,v 1.32 2012/01/09 15:37:34 dholland Exp $");
#endif
#include <sys/param.h>
@@ -26,15 +26,14 @@
#include <grp.h>
#include <errno.h>
#include <unistd.h>
-
#include <syslog.h>
-#include <quota/quotaprop.h>
-#include <quota/quota.h>
#include <rpc/rpc.h>
#include <rpcsvc/rquota.h>
#include <arpa/inet.h>
+#include <quota.h>
+
static void rquota_service(struct svc_req *request, SVCXPRT *transp);
static void ext_rquota_service(struct svc_req *request, SVCXPRT *transp);
static void sendquota(struct svc_req *request, int vers, SVCXPRT *transp);
@@ -42,15 +41,6 @@
static int from_inetd = 1;
-static uint32_t
-qlim2rqlim(uint64_t lim)
-{
- if (lim == UQUAD_MAX)
- return 0;
- else
- return (lim + 1);
-}
-
static void
cleanup(int dummy)
{
@@ -163,6 +153,58 @@
exit(0);
}
+/*
+ * Convert a limit to rquota representation (where 0 == unlimited).
+ * Clamp the result into a uint32_t.
+ */
+static uint32_t
+limit_to_rquota(uint64_t lim)
+{
+ if (lim == QUOTA_NOLIMIT || lim > 0xfffffffeUL)
+ return 0;
+ else
+ return (lim + 1);
+}
+
+/*
+ * Convert a time to rquota representation.
+ */
+static uint32_t
+time_to_rquota(time_t when, time_t now)
+{
+ if (when == QUOTA_NOTIME) {
+ return 0;
+ } else {
+ return when - now;
+ }
+}
+
+/*
+ * Convert to rquota representation.
+ */
+static void
+quotavals_to_rquota(const struct quotaval *blocks,
+ const struct quotaval *files,
+ struct rquota *rq)
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+
+ rq->rq_active = TRUE;
+ rq->rq_bsize = DEV_BSIZE;
+
+ rq->rq_bhardlimit = limit_to_rquota(blocks->qv_hardlimit);
+ rq->rq_bsoftlimit = limit_to_rquota(blocks->qv_softlimit);
+ rq->rq_curblocks = blocks->qv_usage;
+ rq->rq_btimeleft = time_to_rquota(blocks->qv_expiretime, now.tv_sec);
+
+ rq->rq_fhardlimit = limit_to_rquota(files->qv_hardlimit);
+ rq->rq_fsoftlimit = limit_to_rquota(files->qv_softlimit);
+ rq->rq_curfiles = files->qv_usage;
+ rq->rq_ftimeleft = time_to_rquota(files->qv_expiretime, now.tv_sec);
+}
+
/* read quota for the specified id, and send it */
static void
sendquota(struct svc_req *request, int vers, SVCXPRT *transp)
@@ -170,9 +212,10 @@
struct getquota_args getq_args;
struct ext_getquota_args ext_getq_args;
struct getquota_rslt getq_rslt;
- struct quotaval qv[QUOTA_NLIMITS];
- const char *class;
- struct timeval timev;
+ struct quotahandle *qh;
+ struct quotakey qk;
+ struct quotaval blocks, files;
+ int idtype;
memset((char *)&getq_args, 0, sizeof(getq_args));
memset((char *)&ext_getq_args, 0, sizeof(ext_getq_args));
@@ -197,10 +240,10 @@
}
switch (ext_getq_args.gqa_type) {
case RQUOTA_USRQUOTA:
- class = QUOTADICT_CLASS_USER;
+ idtype = QUOTA_IDTYPE_USER;
break;
case RQUOTA_GRPQUOTA:
- class = QUOTADICT_CLASS_GROUP;
+ idtype = QUOTA_IDTYPE_GROUP;
break;
default:
getq_rslt.status = Q_NOQUOTA;
@@ -209,32 +252,52 @@
if (request->rq_cred.oa_flavor != AUTH_UNIX) {
/* bad auth */
getq_rslt.status = Q_EPERM;
- } else if (!getufsquota(ext_getq_args.gqa_pathp, qv,
- ext_getq_args.gqa_id, class)) {
- /* failed, return noquota */
+ goto out;
+ }
+
+ /*
+ * XXX validate the path...
+ */
+
+ qh = quota_open(ext_getq_args.gqa_pathp);
+ if (qh == NULL) {
+ /*
+ * There are only three possible responses: success,
+ * permission denied, and "no quota", so we return
+ * the last for essentially all errors.
+ */
+ if (errno == EPERM || errno == EACCES) {
+ getq_rslt.status = Q_EPERM;
+ goto out;
+ }
getq_rslt.status = Q_NOQUOTA;
- } else {
- gettimeofday(&timev, NULL);
- getq_rslt.status = Q_OK;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_active = TRUE;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize = DEV_BSIZE;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit =
- qlim2rqlim(qv[QUOTA_LIMIT_BLOCK].qv_hardlimit);
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit =
- qlim2rqlim(qv[QUOTA_LIMIT_BLOCK].qv_softlimit);
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks =
- qv[QUOTA_LIMIT_BLOCK].qv_usage;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit =
- qlim2rqlim(qv[QUOTA_LIMIT_FILE].qv_hardlimit);
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit =
- qlim2rqlim(qv[QUOTA_LIMIT_FILE].qv_softlimit);
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles =
- qv[QUOTA_LIMIT_FILE].qv_usage;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft =
- qv[QUOTA_LIMIT_BLOCK].qv_expiretime - timev.tv_sec;
- getq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft =
- qv[QUOTA_LIMIT_FILE].qv_expiretime - timev.tv_sec;
+ goto out;
+ }
+
+ qk.qk_id = ext_getq_args.gqa_id;
+ qk.qk_idtype = idtype;
+ qk.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
+ if (quota_get(qh, &qk, &blocks) < 0) {
+ /* failed, return noquota */
+ quota_close(qh);
+ getq_rslt.status = Q_NOQUOTA;
+ goto out;
}
+
+ qk.qk_objtype = QUOTA_OBJTYPE_FILES;
+ if (quota_get(qh, &qk, &files) < 0) {
+ /* failed, return noquota */
+ quota_close(qh);
+ getq_rslt.status = Q_NOQUOTA;
+ goto out;
+ }
+
+ quota_close(qh);
+
+ quotavals_to_rquota(&blocks, &files,
+ &getq_rslt.getquota_rslt_u.gqr_rquota);
+ getq_rslt.status = Q_OK;
+
out:
if (!svc_sendreply(transp, (xdrproc_t)xdr_getquota_rslt, (char *)&getq_rslt))
svcerr_systemerr(transp);
Home |
Main Index |
Thread Index |
Old Index