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>
38 #define TYPE_EXTENDED 0x01
41 #ifndef MNTTYPE_AUTOFS
42 #define MNTTYPE_AUTOFS "autofs"
46 * Global unix authentication credentials.
48 extern struct authunix_parms *unix_cred;
50 int in_group (gid_t *gids, u_int len, gid_t gid)
62 getquota_rslt *getquotainfo(int flags, caddr_t *argp, struct svc_req *rqstp)
64 static getquota_rslt result;
67 ext_getquota_args *ext_args;
72 char *pathname, *qfpathname;
73 int fd, err, id, type;
78 * First check authentication.
80 if (flags & TYPE_EXTENDED) {
81 arguments.ext_args = (ext_getquota_args *)argp;
82 id = arguments.ext_args->gqa_id;
83 type = arguments.ext_args->gqa_type;
84 pathname = arguments.ext_args->gqa_pathp;
86 if (type == USRQUOTA && unix_cred->aup_uid && unix_cred->aup_uid != id) {
87 result.status = Q_EPERM;
91 if (type == GRPQUOTA && unix_cred->aup_uid && unix_cred->aup_gid != id &&
92 !in_group((gid_t *)unix_cred->aup_gids, unix_cred->aup_len, id)) {
93 result.status = Q_EPERM;
97 arguments.args = (getquota_args *)argp;
98 id = arguments.args->gqa_uid;
100 pathname = arguments.args->gqa_pathp;
102 if (unix_cred->aup_uid && unix_cred->aup_uid != id) {
103 result.status = Q_EPERM;
108 fp = setmntent(MNTTAB, "r");
109 while ((mnt = getmntent(fp)) != (struct mntent *)0) {
110 if (stat(mnt->mnt_dir, &stm) == -1)
113 if (stat(pathname, &stn) == -1)
115 else if (stm.st_dev != stn.st_dev)
118 if (mnt->mnt_fsname [0] != '/'
119 || strcasecmp (mnt->mnt_type, MNTTYPE_NFS) == 0
120 || strcasecmp (mnt->mnt_type, MNTTYPE_AUTOFS) == 0
121 || strcasecmp (mnt->mnt_type, MNTTYPE_SWAP) == 0
122 || strcasecmp (mnt->mnt_type, MNTTYPE_IGNORE) == 0)
125 if (statfs(pathname, &stf) == -1) {
126 result.status = Q_EPERM;
129 result.getquota_rslt_u.gqr_rquota.rq_bsize = stf.f_bsize;
131 if (hasquota(mnt, type, &qfpathname)) {
132 if ((err = quotactl(QCMD(Q_GETQUOTA, type), mnt->mnt_fsname,
133 id, (caddr_t)&dq_dqb)) == -1
134 && !(flags & ACTIVE)) {
135 if ((fd = open(qfpathname, O_RDONLY)) < 0)
141 lseek(fd, (long) dqoff(id), L_SET);
142 switch (read(fd, &dq_dqb, sizeof(struct dqblk))) {
145 * Convert implicit 0 quota (EOF) into an
146 * explicit one (zero'ed dqblk)
148 memset((caddr_t)&dq_dqb, 0, sizeof(struct dqblk));
150 case sizeof(struct dqblk): /* OK */
160 if (err && (flags & ACTIVE)) {
161 result.status = Q_NOQUOTA;
165 result.status = Q_OK;
166 result.getquota_rslt_u.gqr_rquota.rq_active = (err == 0) ? TRUE : FALSE;
168 * Make a copy of the info into the last part of the remote quota
169 * struct which is exactly the same.
171 memcpy((caddr_t *)&result.getquota_rslt_u.gqr_rquota.rq_bhardlimit,
172 (caddr_t *)&dq_dqb, sizeof(struct dqblk));
179 result.status = Q_NOQUOTA;
183 getquota_rslt *rquotaproc_getquota_1(getquota_args *argp, struct svc_req *rqstp)
185 return(getquotainfo(0, (caddr_t *)argp, rqstp));
188 getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp, struct svc_req *rqstp)
190 return(getquotainfo(ACTIVE, (caddr_t *)argp, rqstp));
193 getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp, struct svc_req *rqstp)
195 return(getquotainfo(TYPE_EXTENDED, (caddr_t *)argp, rqstp));
198 getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp, struct svc_req *rqstp)
200 return(getquotainfo(TYPE_EXTENDED | ACTIVE, (caddr_t *)argp, rqstp));