2 Unix SMB/CIFS implementation.
3 System QUOTA function wrappers for NFS
4 Copyright (C) Michael Adam 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #define DBGC_CLASS DBGC_QUOTA
26 #ifndef HAVE_SYS_QUOTAS
27 #ifdef HAVE_NFS_QUOTAS
28 #undef HAVE_NFS_QUOTAS
32 #ifdef HAVE_NFS_QUOTAS
36 * This is based on the FreeBSD / SUNOS5 section of quotas.c
40 #include <rpc/types.h>
41 #include <rpcsvc/rquota.h>
42 #ifdef HAVE_RPC_NETTYPE_H
43 #include <rpc/nettype.h>
47 #ifdef HAVE_GETQUOTA_RSLT_GETQUOTA_RSLT_U
48 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
49 #define GQR_STATUS status
51 #define GQR_RQUOTA gqr_rquota
52 #define GQR_STATUS gqr_status
55 static int my_xdr_getquota_args(XDR
*xdrsp
, struct getquota_args
*args
)
57 if (!xdr_string(xdrsp
, &args
->gqa_pathp
, RQ_PATHLEN
))
59 if (!xdr_int(xdrsp
, &args
->gqa_uid
))
64 static int my_xdr_getquota_rslt(XDR
*xdrsp
, struct getquota_rslt
*gqr
)
68 if (!xdr_int(xdrsp
, "astat
)) {
69 DEBUG(6,("nfs_quotas: Status bad or zero\n"));
72 gqr
->status
= quotastat
;
74 if (!xdr_int(xdrsp
, &gqr
->GQR_RQUOTA
.rq_bsize
)) {
75 DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
78 if (!xdr_bool(xdrsp
, &gqr
->GQR_RQUOTA
.rq_active
)) {
79 DEBUG(6,("nfs_quotas: Active bad or zero\n"));
82 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_bhardlimit
)) {
83 DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
86 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_bsoftlimit
)) {
87 DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
90 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_curblocks
)) {
91 DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
98 int sys_get_nfs_quota(const char *path
, const char *bdev
,
99 enum SMB_QUOTA_TYPE qtype
,
100 unid_t id
, SMB_DISK_QUOTA
*dp
)
103 struct getquota_rslt gq_rslt
;
104 struct getquota_args gq_args
;
106 char *cutstr
, *pathname
, *host
, *testpath
;
108 static struct timeval timeout
= {2,0};
109 enum clnt_stat clnt_stat
;
114 if (!path
|| !bdev
|| !dp
) {
115 smb_panic("sys_get_nfs_quota: called with NULL pointer");
118 DEBUG(10, ("sys_get_nfs_quota: path[%s] bdev[%s] qtype[%d]\n",
125 if (qtype
!= SMB_USER_QUOTA_TYPE
) {
126 DEBUG(3, ("sys_get_nfs_quota: got unsupported quota type '%d', "
127 "only supported type is '%d' (SMB_USER_QUOTA_TYPE)\n",
128 qtype
, SMB_USER_QUOTA_TYPE
));
134 len
= strcspn(mnttype
, ":");
135 pathname
= strstr(mnttype
, ":");
136 cutstr
= (char *) SMB_MALLOC(len
+1);
137 if (cutstr
== NULL
) {
142 memset(cutstr
, '\0', len
+1);
143 host
= strncat(cutstr
, mnttype
, sizeof(char) * len
);
144 testpath
= strchr_m(mnttype
, ':');
145 if (testpath
== NULL
) {
150 gq_args
.gqa_pathp
= testpath
;
151 gq_args
.gqa_uid
= id
.uid
;
153 DEBUG(10, ("sys_get_nfs_quotas: Asking for quota of path '%s' on "
154 "host '%s', rpcprog '%i', rpcvers '%i', network '%s'\n",
155 host
, testpath
+1, RQUOTAPROG
, RQUOTAVERS
, "udp"));
157 clnt
= clnt_create(host
, RQUOTAPROG
, RQUOTAVERS
, "udp");
163 clnt
->cl_auth
= authunix_create_default();
164 if (clnt
->cl_auth
== NULL
) {
165 DEBUG(3, ("sys_get_nfs_quotas: authunix_create_default "
171 clnt_stat
= clnt_call(clnt
,
173 (const xdrproc_t
) my_xdr_getquota_args
,
175 (const xdrproc_t
) my_xdr_getquota_rslt
,
179 if (clnt_stat
!= RPC_SUCCESS
) {
180 DEBUG(3, ("sys_get_nfs_quotas: clnt_call failed\n"));
185 DEBUG(10, ("sys_get_nfs_quotas: getquota_rslt:\n"
189 "bhardlimit : '%u'\n"
190 "bsoftlimit : '%u'\n"
192 "fhardlimit : '%u'\n"
193 "fsoftlimit : '%u'\n"
196 "ftimeleft : '%u'\n",
198 gq_rslt
.GQR_RQUOTA
.rq_bsize
,
199 gq_rslt
.GQR_RQUOTA
.rq_active
?"yes":"no",
200 gq_rslt
.GQR_RQUOTA
.rq_bhardlimit
,
201 gq_rslt
.GQR_RQUOTA
.rq_bsoftlimit
,
202 gq_rslt
.GQR_RQUOTA
.rq_curblocks
,
203 gq_rslt
.GQR_RQUOTA
.rq_fhardlimit
,
204 gq_rslt
.GQR_RQUOTA
.rq_fsoftlimit
,
205 gq_rslt
.GQR_RQUOTA
.rq_curfiles
,
206 gq_rslt
.GQR_RQUOTA
.rq_btimeleft
,
207 gq_rslt
.GQR_RQUOTA
.rq_ftimeleft
));
211 * 0 if the rpc call fails,
213 * 2 if there is no quota set, and
214 * 3 if no permission to get the quota.
217 switch (gq_rslt
.GQR_STATUS
) {
219 DEBUG(3, ("sys_get_nfs_quotas: Remote Quotas Failed! "
220 "Error '%i'\n", gq_rslt
.GQR_STATUS
));
225 DEBUG(10, ("sys_get_nfs_quotas: Good quota data\n"));
226 dp
->bsize
= (uint64_t)gq_rslt
.GQR_RQUOTA
.rq_bsize
;
227 dp
->softlimit
= gq_rslt
.GQR_RQUOTA
.rq_bsoftlimit
;
228 dp
->hardlimit
= gq_rslt
.GQR_RQUOTA
.rq_bhardlimit
;
229 dp
->curblocks
= gq_rslt
.GQR_RQUOTA
.rq_curblocks
;
233 DEBUG(5, ("sys_get_nfs_quotas: No quota set\n"));
234 SMB_QUOTAS_SET_NO_LIMIT(dp
);
238 DEBUG(3, ("sys_get_nfs_quotas: no permission to get quota\n"));
244 DEBUG(5, ("sys_get_nfs_quotas: Unknown remote quota status "
245 "code '%i'\n", gq_rslt
.GQR_STATUS
));
258 auth_destroy(clnt
->cl_auth
);
265 DEBUG(10, ("sys_get_nfs_quotas: finished\n" ));
269 int sys_set_nfs_quota(const char *path
, const char *bdev
,
270 enum SMB_QUOTA_TYPE qtype
,
271 unid_t id
, SMB_DISK_QUOTA
*dp
)
273 DEBUG(1, ("sys_set_nfs_quota : not supported\n"));
278 #else /* HAVE_NFS_QUOTAS */
280 void dummy_sysquotas_nfs(void);
281 void dummy_sysquotas_nfs(void) {}
283 #endif /* HAVE_NFS_QUOTAS */