2 * QUOTA An implementation of the diskquota system for the LINUX
3 * operating system. QUOTA is implemented using the BSD systemcall
4 * interface as the means of communication with the user level.
5 * Should work for all filesystems because of integration into the
6 * VFS layer of the operating system.
7 * This is based on the Melbourne quota system wich uses both user and
10 * This part does the lookup of the info.
12 * Version: $Id: rquota_server.c,v 2.9 1996/11/17 16:59:46 mvw Exp mvw $
14 * Author: Marco van Wieringen <mvw@planets.elm.net>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
27 #include <sys/param.h>
28 #include <sys/quota.h>
29 #include <sys/mount.h>
38 #define TYPE_EXTENDED 0x01
41 #ifndef MNTTYPE_AUTOFS
42 #define MNTTYPE_AUTOFS "autofs"
46 #define BLOCK_SIZE 1024
50 * Global unix authentication credentials.
52 extern struct authunix_parms *unix_cred;
54 int in_group (gid_t *gids, u_int len, gid_t gid)
66 getquota_rslt *getquotainfo(int flags, caddr_t *argp, struct svc_req *rqstp)
68 static getquota_rslt result;
71 ext_getquota_args *ext_args;
76 char *pathname, *qfpathname;
77 int fd, err, id, type;
79 struct rquota *rquota;
82 * First check authentication.
84 if (flags & TYPE_EXTENDED) {
85 arguments.ext_args = (ext_getquota_args *)argp;
86 id = arguments.ext_args->gqa_id;
87 type = arguments.ext_args->gqa_type;
88 pathname = arguments.ext_args->gqa_pathp;
90 if (type == USRQUOTA && unix_cred->aup_uid && unix_cred->aup_uid != id) {
91 result.status = Q_EPERM;
95 if (type == GRPQUOTA && unix_cred->aup_uid && unix_cred->aup_gid != id &&
96 !in_group((gid_t *)unix_cred->aup_gids, unix_cred->aup_len, id)) {
97 result.status = Q_EPERM;
101 arguments.args = (getquota_args *)argp;
102 id = arguments.args->gqa_uid;
104 pathname = arguments.args->gqa_pathp;
106 if (unix_cred->aup_uid && unix_cred->aup_uid != id) {
107 result.status = Q_EPERM;
112 fp = setmntent(MNTTAB, "r");
113 while ((mnt = getmntent(fp)) != (struct mntent *)0) {
114 if (stat(mnt->mnt_dir, &stm) == -1)
117 if (stat(pathname, &stn) == -1)
119 else if (stm.st_dev != stn.st_dev)
122 if (mnt->mnt_fsname [0] != '/'
123 || strcasecmp (mnt->mnt_type, MNTTYPE_NFS) == 0
124 || strcasecmp (mnt->mnt_type, MNTTYPE_AUTOFS) == 0
125 || strcasecmp (mnt->mnt_type, MNTTYPE_SWAP) == 0
126 || strcasecmp (mnt->mnt_type, MNTTYPE_IGNORE) == 0)
129 /* All blocks reported are in BLOCK_SIZE. */
130 result.getquota_rslt_u.gqr_rquota.rq_bsize = BLOCK_SIZE;
132 if (hasquota(mnt, type, &qfpathname)) {
133 if ((err = quotactl(QCMD(Q_GETQUOTA, type), mnt->mnt_fsname,
134 id, (caddr_t)&dq_dqb)) == -1
135 && !(flags & ACTIVE)) {
136 if ((fd = open(qfpathname, O_RDONLY)) < 0)
142 lseek(fd, (long) dqoff(id), L_SET);
143 switch (read(fd, &dq_dqb, sizeof(struct dqblk))) {
146 * Convert implicit 0 quota (EOF) into an
147 * explicit one (zero'ed dqblk)
149 memset((caddr_t)&dq_dqb, 0, sizeof(struct dqblk));
151 case sizeof(struct dqblk): /* OK */
161 if (err && (flags & ACTIVE)) {
162 result.status = Q_NOQUOTA;
166 result.status = Q_OK;
167 result.getquota_rslt_u.gqr_rquota.rq_active = (err == 0) ? TRUE : FALSE;
169 * Make a copy of the info into the last part of the remote quota
170 * struct might not be exactly the same on all architectures...
173 rquota = &result.getquota_rslt_u.gqr_rquota;
174 rquota->rq_bhardlimit = dq_dqb.dqb_bhardlimit;
175 rquota->rq_bsoftlimit = dq_dqb.dqb_bsoftlimit;;
176 rquota->rq_curblocks = dq_dqb.dqb_curblocks;
177 rquota->rq_fhardlimit = dq_dqb.dqb_ihardlimit;
178 rquota->rq_fsoftlimit = dq_dqb.dqb_isoftlimit;
179 rquota->rq_curfiles = dq_dqb.dqb_curinodes;
180 rquota->rq_btimeleft = dq_dqb.dqb_btime;
181 rquota->rq_ftimeleft = dq_dqb.dqb_itime;
188 result.status = Q_NOQUOTA;
192 getquota_rslt *rquotaproc_getquota_1(getquota_args *argp, struct svc_req *rqstp)
194 return(getquotainfo(0, (caddr_t *)argp, rqstp));
197 getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp, struct svc_req *rqstp)
199 return(getquotainfo(ACTIVE, (caddr_t *)argp, rqstp));
202 getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp, struct svc_req *rqstp)
204 return(getquotainfo(TYPE_EXTENDED, (caddr_t *)argp, rqstp));
207 getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp, struct svc_req *rqstp)
209 return(getquotainfo(TYPE_EXTENDED | ACTIVE, (caddr_t *)argp, rqstp));