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>
48 #define RQ_PATHLEN 1024
51 #ifdef HAVE_GETQUOTA_RSLT_GETQUOTA_RSLT_U
52 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
53 #define GQR_STATUS status
55 #define GQR_RQUOTA gqr_rquota
56 #define GQR_STATUS gqr_status
59 static int my_xdr_getquota_args(XDR
*xdrsp
, struct getquota_args
*args
)
61 if (!xdr_string(xdrsp
, &args
->gqa_pathp
, RQ_PATHLEN
))
63 if (!xdr_int(xdrsp
, &args
->gqa_uid
))
68 static int my_xdr_getquota_rslt(XDR
*xdrsp
, struct getquota_rslt
*gqr
)
72 if (!xdr_int(xdrsp
, "astat
)) {
73 DEBUG(6,("nfs_quotas: Status bad or zero\n"));
76 gqr
->GQR_STATUS
= quotastat
;
78 if (!xdr_int(xdrsp
, &gqr
->GQR_RQUOTA
.rq_bsize
)) {
79 DEBUG(6,("nfs_quotas: Block size bad or zero\n"));
82 if (!xdr_bool(xdrsp
, &gqr
->GQR_RQUOTA
.rq_active
)) {
83 DEBUG(6,("nfs_quotas: Active bad or zero\n"));
86 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_bhardlimit
)) {
87 DEBUG(6,("nfs_quotas: Hardlimit bad or zero\n"));
90 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_bsoftlimit
)) {
91 DEBUG(6,("nfs_quotas: Softlimit bad or zero\n"));
94 if (!xdr_int(xdrsp
, (int *)&gqr
->GQR_RQUOTA
.rq_curblocks
)) {
95 DEBUG(6,("nfs_quotas: Currentblocks bad or zero\n"));
102 int sys_get_nfs_quota(const char *path
, const char *bdev
,
103 enum SMB_QUOTA_TYPE qtype
,
104 unid_t id
, SMB_DISK_QUOTA
*dp
)
107 struct getquota_rslt gq_rslt
;
108 struct getquota_args gq_args
;
110 char *cutstr
, *pathname
, *host
, *testpath
;
112 static struct timeval timeout
= {2,0};
113 enum clnt_stat clnt_stat
;
118 if (!path
|| !bdev
|| !dp
) {
119 smb_panic("sys_get_nfs_quota: called with NULL pointer");
122 DEBUG(10, ("sys_get_nfs_quota: path[%s] bdev[%s] qtype[%d]\n",
129 if (qtype
!= SMB_USER_QUOTA_TYPE
) {
130 DEBUG(3, ("sys_get_nfs_quota: got unsupported quota type '%d', "
131 "only supported type is '%d' (SMB_USER_QUOTA_TYPE)\n",
132 qtype
, SMB_USER_QUOTA_TYPE
));
138 len
= strcspn(mnttype
, ":");
139 pathname
= strstr(mnttype
, ":");
140 cutstr
= (char *) SMB_MALLOC(len
+1);
141 if (cutstr
== NULL
) {
146 memset(cutstr
, '\0', len
+1);
147 host
= strncat(cutstr
, mnttype
, sizeof(char) * len
);
148 testpath
= strchr_m(mnttype
, ':');
149 if (testpath
== NULL
) {
154 gq_args
.gqa_pathp
= testpath
;
155 gq_args
.gqa_uid
= id
.uid
;
157 DEBUG(10, ("sys_get_nfs_quotas: Asking for quota of path '%s' on "
158 "host '%s', rpcprog '%i', rpcvers '%i', network '%s'\n",
159 host
, testpath
+1, RQUOTAPROG
, RQUOTAVERS
, "udp"));
161 clnt
= clnt_create(host
, RQUOTAPROG
, RQUOTAVERS
, "udp");
167 clnt
->cl_auth
= authunix_create_default();
168 if (clnt
->cl_auth
== NULL
) {
169 DEBUG(3, ("sys_get_nfs_quotas: authunix_create_default "
175 clnt_stat
= clnt_call(clnt
,
177 (const xdrproc_t
) my_xdr_getquota_args
,
179 (const xdrproc_t
) my_xdr_getquota_rslt
,
183 if (clnt_stat
!= RPC_SUCCESS
) {
184 DEBUG(3, ("sys_get_nfs_quotas: clnt_call failed\n"));
189 DEBUG(10, ("sys_get_nfs_quotas: getquota_rslt:\n"
193 "bhardlimit : '%u'\n"
194 "bsoftlimit : '%u'\n"
196 "fhardlimit : '%u'\n"
197 "fsoftlimit : '%u'\n"
200 "ftimeleft : '%u'\n",
202 gq_rslt
.GQR_RQUOTA
.rq_bsize
,
203 gq_rslt
.GQR_RQUOTA
.rq_active
?"yes":"no",
204 gq_rslt
.GQR_RQUOTA
.rq_bhardlimit
,
205 gq_rslt
.GQR_RQUOTA
.rq_bsoftlimit
,
206 gq_rslt
.GQR_RQUOTA
.rq_curblocks
,
207 gq_rslt
.GQR_RQUOTA
.rq_fhardlimit
,
208 gq_rslt
.GQR_RQUOTA
.rq_fsoftlimit
,
209 gq_rslt
.GQR_RQUOTA
.rq_curfiles
,
210 gq_rslt
.GQR_RQUOTA
.rq_btimeleft
,
211 gq_rslt
.GQR_RQUOTA
.rq_ftimeleft
));
215 * 0 if the rpc call fails,
217 * 2 if there is no quota set, and
218 * 3 if no permission to get the quota.
221 switch (gq_rslt
.GQR_STATUS
) {
223 DEBUG(3, ("sys_get_nfs_quotas: Remote Quotas Failed! "
224 "Error '%i'\n", gq_rslt
.GQR_STATUS
));
229 DEBUG(10, ("sys_get_nfs_quotas: Good quota data\n"));
230 dp
->bsize
= (uint64_t)gq_rslt
.GQR_RQUOTA
.rq_bsize
;
231 dp
->softlimit
= gq_rslt
.GQR_RQUOTA
.rq_bsoftlimit
;
232 dp
->hardlimit
= gq_rslt
.GQR_RQUOTA
.rq_bhardlimit
;
233 dp
->curblocks
= gq_rslt
.GQR_RQUOTA
.rq_curblocks
;
237 DEBUG(5, ("sys_get_nfs_quotas: No quota set\n"));
238 SMB_QUOTAS_SET_NO_LIMIT(dp
);
242 DEBUG(3, ("sys_get_nfs_quotas: no permission to get quota\n"));
248 DEBUG(5, ("sys_get_nfs_quotas: Unknown remote quota status "
249 "code '%i'\n", gq_rslt
.GQR_STATUS
));
262 auth_destroy(clnt
->cl_auth
);
269 DEBUG(10, ("sys_get_nfs_quotas: finished\n" ));
273 int sys_set_nfs_quota(const char *path
, const char *bdev
,
274 enum SMB_QUOTA_TYPE qtype
,
275 unid_t id
, SMB_DISK_QUOTA
*dp
)
277 DEBUG(1, ("sys_set_nfs_quota : not supported\n"));
282 #else /* HAVE_NFS_QUOTAS */
284 void dummy_sysquotas_nfs(void);
285 void dummy_sysquotas_nfs(void) {}
287 #endif /* HAVE_NFS_QUOTAS */