Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-quota2]: src/libexec/rpc.rquotad Convert to new quotactl interface



details:   https://anonhg.NetBSD.org/src/rev/437e083fa152
branches:  bouyer-quota2
changeset: 761130:437e083fa152
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Feb 08 22:14:22 2011 +0000

description:
Convert to new quotactl interface

diffstat:

 libexec/rpc.rquotad/Makefile  |   14 ++-
 libexec/rpc.rquotad/rquotad.c |  226 +++++------------------------------------
 2 files changed, 40 insertions(+), 200 deletions(-)

diffs (truncated from 326 to 300 lines):

diff -r 27d7eb3c08d1 -r 437e083fa152 libexec/rpc.rquotad/Makefile
--- a/libexec/rpc.rquotad/Makefile      Tue Feb 08 21:47:25 2011 +0000
+++ b/libexec/rpc.rquotad/Makefile      Tue Feb 08 22:14:22 2011 +0000
@@ -1,11 +1,19 @@
-#      $NetBSD: Makefile,v 1.6 1997/10/08 09:07:30 mrg Exp $
+#      $NetBSD: Makefile,v 1.6.64.1 2011/02/08 22:14:22 bouyer Exp $
 
+.include <bsd.own.mk>
 PROG = rpc.rquotad
 SRCS = rquotad.c
 MAN  = rpc.rquotad.8
 MLINKS = rpc.rquotad.8 rquotad.8
 
-DPADD= ${LIBRPCSVC}
-LDADD= -lrpcsvc
+CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
+DPADD= ${LIBRPCSVC} ${LIBPROP}
+LDADD= -lrpcsvc -lprop
+
+.PATH:  ${NETBSDSRCDIR}/usr.bin/quota
+SRCS+= getvfsquota.c
+.PATH:  ${NETBSDSRCDIR}/sys/ufs/ufs
+SRCS+= quota2_prop.c
+
 
 .include <bsd.prog.mk>
diff -r 27d7eb3c08d1 -r 437e083fa152 libexec/rpc.rquotad/rquotad.c
--- a/libexec/rpc.rquotad/rquotad.c     Tue Feb 08 21:47:25 2011 +0000
+++ b/libexec/rpc.rquotad/rquotad.c     Tue Feb 08 22:14:22 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rquotad.c,v 1.24 2009/03/16 00:43:33 lukem Exp $       */
+/*     $NetBSD: rquotad.c,v 1.24.2.1 2011/02/08 22:14:22 bouyer 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.24 2009/03/16 00:43:33 lukem Exp $");
+__RCSID("$NetBSD: rquotad.c,v 1.24.2.1 2011/02/08 22:14:22 bouyer Exp $");
 #endif
 
 #include <sys/param.h>
@@ -29,34 +29,19 @@
 
 #include <syslog.h>
 
-#include <ufs/ufs/quota.h>
+#include <ufs/ufs/quota2_prop.h>
 #include <rpc/rpc.h>
 #include <rpcsvc/rquota.h>
 #include <arpa/inet.h>
 
+#include <getvfsquota.h>
+
 void rquota_service(struct svc_req *request, SVCXPRT *transp);
 void ext_rquota_service(struct svc_req *request, SVCXPRT *transp);
 void sendquota(struct svc_req *request, int vers, SVCXPRT *transp);
-void initfs(void);
-int getfsquota(int type, long id, char *path, struct dqblk *dqblk);
-int hasquota(struct fstab *fs, char **uqfnamep, char **gqfnamep);
 void cleanup(int);
 int main(int, char *[]);
 
-/*
- * structure containing informations about ufs filesystems
- * initialised by initfs()
- */
-struct fs_stat {
-       struct fs_stat *fs_next;        /* next element */
-       char   *fs_file;                /* mount point of the filesystem */
-       char   *uqfpathname;            /* pathname of the user quota file */
-       char   *gqfpathname;            /* pathname of the group quota file */
-       dev_t   st_dev;                 /* device of the filesystem */
-} fs_stat;
-struct fs_stat *fs_begin = NULL;
-
-const char *qfextension[] = INITQFNAMES;
 int from_inetd = 1;
 
 void 
@@ -124,7 +109,6 @@
                }
        }
 
-       initfs();               /* init the fs_stat list */
        svc_run();
        syslog(LOG_ERR, "svc_run returned");
        exit(1);
@@ -179,7 +163,9 @@
        struct getquota_args getq_args;
        struct ext_getquota_args ext_getq_args;
        struct getquota_rslt getq_rslt;
-       struct dqblk dqblk;
+       struct quota2_entry q2e;
+       int type;
+       int8_t version;
        struct timeval timev;
 
        memset((char *)&getq_args, 0, sizeof(getq_args));
@@ -203,11 +189,21 @@
                }
                break;
        }
+       switch (ext_getq_args.gqa_type) {
+       case RQUOTA_USRQUOTA:
+               type = USRQUOTA;
+               break;
+       case RQUOTA_GRPQUOTA:
+               type = GRPQUOTA;
+               break;
+       default:
+               getq_rslt.status = Q_NOQUOTA;
+               goto out;
+       }
        if (request->rq_cred.oa_flavor != AUTH_UNIX) {
                /* bad auth */
                getq_rslt.status = Q_EPERM;
-       } else if (!getfsquota(ext_getq_args.gqa_type, ext_getq_args.gqa_id,
-           ext_getq_args.gqa_pathp, &dqblk)) {
+       } else if (!getvfsquota(ext_getq_args.gqa_pathp, &q2e, &version, ext_getq_args.gqa_id, ext_getq_args.gqa_type, 0, 0)) {
                /* failed, return noquota */
                getq_rslt.status = Q_NOQUOTA;
        } else {
@@ -216,22 +212,23 @@
                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 =
-                   dqblk.dqb_bhardlimit;
+                   q2e.q2e_val[QL_BLOCK].q2v_hardlimit;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit =
-                   dqblk.dqb_bsoftlimit;
+                   q2e.q2e_val[QL_BLOCK].q2v_softlimit;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks =
-                   dqblk.dqb_curblocks;
+                   q2e.q2e_val[QL_BLOCK].q2v_cur;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit =
-                   dqblk.dqb_ihardlimit;
+                   q2e.q2e_val[QL_FILE].q2v_hardlimit;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit =
-                   dqblk.dqb_isoftlimit;
+                   q2e.q2e_val[QL_FILE].q2v_softlimit;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles =
-                   dqblk.dqb_curinodes;
+                   q2e.q2e_val[QL_FILE].q2v_softlimit;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft =
-                   dqblk.dqb_btime - timev.tv_sec;
+                   q2e.q2e_val[QL_BLOCK].q2v_time - timev.tv_sec;
                getq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft =
-                   dqblk.dqb_itime - timev.tv_sec;
+                   q2e.q2e_val[QL_FILE].q2v_time - timev.tv_sec;
        }
+out:
        if (!svc_sendreply(transp, xdr_getquota_rslt, (char *)&getq_rslt))
                svcerr_systemerr(transp);
        if (!svc_freeargs(transp, xdr_getquota_args, (caddr_t)&getq_args)) {
@@ -239,168 +236,3 @@
                exit(1);
        }
 }
-
-/* initialise the fs_tab list from entries in /etc/fstab */
-void 
-initfs()
-{
-       struct fs_stat *fs_current = NULL;
-       struct fs_stat *fs_next = NULL;
-       char *uqfpathname, *gqfpathname;
-       struct fstab *fs;
-       struct stat st;
-
-       setfsent();
-       while ((fs = getfsent())) {
-               if (strcmp(fs->fs_vfstype, MOUNT_FFS))
-                       continue;
-               if (!hasquota(fs, &uqfpathname, &gqfpathname))
-                       continue;
-
-               fs_current = (struct fs_stat *) malloc(sizeof(struct fs_stat));
-               if (fs_current == NULL) {
-                       syslog(LOG_ERR, "can't malloc: %m");
-                       exit(1);
-               }
-               fs_current->fs_next = fs_next;  /* next element */
-
-               fs_current->fs_file = strdup(fs->fs_file);
-               if (fs_current->fs_file == NULL) {
-                       syslog(LOG_ERR, "can't strdup: %m");
-                       exit(1);
-               }
-
-               if (uqfpathname) {
-                       fs_current->uqfpathname = strdup(uqfpathname);
-                       if (fs_current->uqfpathname == NULL) {
-                               syslog(LOG_ERR, "can't strdup: %m");
-                               exit(1);
-                       }
-               } else
-                       fs_current->uqfpathname = NULL;
-               if (gqfpathname) {
-                       fs_current->gqfpathname = strdup(gqfpathname);
-                       if (fs_current->gqfpathname == NULL) {
-                               syslog(LOG_ERR, "can't strdup: %m");
-                               exit(1);
-                       }
-               } else
-                       fs_current->gqfpathname = NULL;
-               stat(fs->fs_file, &st);
-               fs_current->st_dev = st.st_dev;
-
-               fs_next = fs_current;
-       }
-       endfsent();
-       fs_begin = fs_current;
-}
-
-/*
- * gets the quotas for id, filesystem path.
- * Return 0 if fail, 1 otherwise
- */
-int
-getfsquota(int type, long id, char *path, struct dqblk *dqblk)
-{
-       struct stat st_path;
-       struct fs_stat *fs;
-       int     qcmd, fd, ret = 0;
-       char *filename;
-
-       if (stat(path, &st_path) < 0)
-               return (0);
-
-       qcmd = QCMD(Q_GETQUOTA, type == RQUOTA_USRQUOTA ? USRQUOTA : GRPQUOTA);
-
-       for (fs = fs_begin; fs != NULL; fs = fs->fs_next) {
-               /* where the device is the same as path */
-               if (fs->st_dev != st_path.st_dev)
-                       continue;
-
-               /* find the specified filesystem. get and return quota */
-               if (quotactl(fs->fs_file, qcmd, id, dqblk) == 0)
-                       return (1);
-               filename = (type == RQUOTA_USRQUOTA) ?
-                   fs->uqfpathname : fs->gqfpathname;
-               if (filename == NULL)
-                       return 0;
-               if ((fd = open(filename, O_RDONLY)) < 0) {
-                       syslog(LOG_WARNING, "open error: %s: %m", filename);
-                       return (0);
-               }
-               if (lseek(fd, (off_t)(id * sizeof(struct dqblk)), SEEK_SET)
-                   == (off_t)-1) {
-                       close(fd);
-                       return (0);
-               }
-               switch (read(fd, dqblk, sizeof(struct dqblk))) {
-               case 0:
-                       /*
-                         * Convert implicit 0 quota (EOF)
-                         * into an explicit one (zero'ed dqblk)
-                         */
-                       memset((caddr_t) dqblk, 0, sizeof(struct dqblk));
-                       ret = 1;
-                       break;
-               case sizeof(struct dqblk):      /* OK */
-                       ret = 1;
-                       break;
-               default:        /* ERROR */
-                       syslog(LOG_WARNING, "read error: %s: %m", filename);
-                       close(fd);
-                       return (0);
-               }
-               close(fd);
-       }
-       return (ret);
-}
-
-/*
- * Check to see if a particular quota is to be enabled.
- * Comes from quota.c, NetBSD 0.9
- */
-int
-hasquota(struct fstab *fs, char **uqfnamep, char **gqfnamep)
-{
-       static char initname=0, usrname[100], grpname[100];
-       static char buf[MAXPATHLEN], ubuf[MAXPATHLEN], gbuf[MAXPATHLEN];
-       char    *opt, *cp = NULL;
-       int ret = 0;
-
-       if (!initname) {
-               (void)snprintf(usrname, sizeof usrname, "%s%s",
-                   qfextension[USRQUOTA], QUOTAFILENAME);
-               (void)snprintf(grpname, sizeof grpname, "%s%s",
-                   qfextension[GRPQUOTA], QUOTAFILENAME);
-       }
-
-       *uqfnamep = NULL;
-       *gqfnamep = NULL;
-       (void)strlcpy(buf, fs->fs_mntops, sizeof(buf));
-       for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {



Home | Main Index | Thread Index | Old Index