2 * $Id: nfsquota.c,v 1.12 2005-04-28 20:49:44 bfernhomberg Exp $
4 * parts of this are lifted from the bsd quota program and are
5 * therefore under the following copyright:
7 * Copyright (c) 1980, 1990, 1993
8 * The Regents of the University of California. All rights reserved.
10 * This code is derived from software contributed to Berkeley by
11 * Robert Elz at The University of Melbourne.
13 * Ported for AIX (jfs) by Joerg Schumacher (J.Schumacher@tu-bs.de) at the
14 * Technische Universitaet Braunschweig, FRG
19 #endif /* HAVE_CONFIG_H */
21 #ifndef NO_QUOTA_SUPPORT
26 #else /* STDC_HEADERS */
30 #endif /* HAVE_STRCHR */
31 char *strchr (), *strrchr ();
33 #define memcpy(d,s,n) bcopy ((s), (d), (n))
34 #define memmove(d,s,n) bcopy ((s), (d), (n))
35 #endif /* ! HAVE_MEMCPY */
36 #endif /* STDC_HEADERS */
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <sys/param.h> /* for DEV_BSIZE */
40 #include <sys/time.h> /* <rpc/rpc.h> on ultrix doesn't include this */
43 #endif /* HAVE_NETDB_H */
44 #include <netinet/in.h>
49 #include <rpc/pmap_prot.h>
50 #include <rpcsvc/rquota.h>
53 #include <atalk/afp.h>
54 #include <atalk/logger.h>
58 /* lifted (with modifications) from the bsd quota program */
60 callaurpc(vol, prognum, versnum, procnum, inproc, in, outproc, out)
62 u_long prognum, versnum, procnum;
63 xdrproc_t inproc, outproc;
66 enum clnt_stat clnt_stat;
67 struct timeval tottimeout;
69 if (!vol->v_nfsclient) {
71 struct sockaddr_in server_addr;
72 struct timeval timeout;
73 int socket = RPC_ANYSOCK;
75 if ((hp = gethostbyname(vol->v_gvs)) == NULL)
76 return ((int) RPC_UNKNOWNHOST);
79 memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
80 server_addr.sin_family = AF_INET;
81 server_addr.sin_port = 0;
83 if ((vol->v_nfsclient = (void *)
84 clntudp_create(&server_addr, prognum, versnum,
85 timeout, &socket)) == NULL)
86 return ((int) rpc_createerr.cf_stat);
88 ((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default();
91 tottimeout.tv_sec = 10;
92 tottimeout.tv_usec = 0;
93 clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum,
94 inproc, in, outproc, out, tottimeout);
95 return ((int) clnt_stat);
99 /* sunos 4 machines structure things a little differently. */
100 #ifdef USE_OLD_RQUOTA
101 #define GQR_STATUS gqr_status
102 #define GQR_RQUOTA gqr_rquota
103 #else /* USE_OLD_RQUOTA */
104 #define GQR_STATUS status
105 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
106 #endif /* USE_OLD_RQUOTA */
108 int getnfsquota(struct vol *vol, const int uid, const u_int32_t bsize,
112 struct getquota_args gq_args;
113 struct getquota_rslt gq_rslt;
117 /* figure out the host and path */
118 if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) {
119 LOG(log_error, logtype_afpd, "can't find hostname for %s", vol->v_gvs);
123 if (*(hostpath + 1) != '/')
126 /* separate host from hostpath */
129 gq_args.gqa_pathp = hostpath + 1;
130 gq_args.gqa_uid = uid;
132 if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA,
133 (xdrproc_t) xdr_getquota_args, (char *) &gq_args,
134 (xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) {
135 LOG(log_info, logtype_afpd, "nfsquota: can't retrieve nfs quota information. \
136 make sure that rpc.rquotad is running on %s.", vol->v_gvs);
141 switch (gq_rslt.GQR_STATUS) {
146 LOG(log_error, logtype_afpd, "nfsquota: quota permission error, host: %s",
150 case Q_OK: /* we only copy the bits that we need. */
151 gettimeofday(&tv, NULL);
153 #if defined(__svr4__) || defined(TRU64)
154 /* why doesn't using bsize work? */
155 #define NFS_BSIZE gq_rslt.GQR_RQUOTA.rq_bsize / DEV_BSIZE
156 #else /* __svr4__ || TRU64 */
157 /* NOTE: linux' rquotad program doesn't currently report the
158 * correct rq_bsize. */
159 /* NOTE: This is integer division and can introduce rounding errors */
160 #define NFS_BSIZE gq_rslt.GQR_RQUOTA.rq_bsize / bsize
161 #endif /* __svr4__ || TRU64 */
163 dqp->dqb_bhardlimit =
164 gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE;
165 dqp->dqb_bsoftlimit =
166 gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE;
168 gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE;
171 dqp->dqb_bwarn = gq_rslt.GQR_RQUOTA.rq_btimeleft;
173 dqp->dqb_btimelimit =
174 tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft;
182 LOG(log_info, logtype_afpd, "bad rpc result, host: %s", vol->v_gvs);
189 #endif /* ! NO_QUOTA_SUPPORT */