1 /* parts of this are lifted from the bsd quota program and are
2 * therefore under the following copyright:
4 * Copyright (c) 1980, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Robert Elz at The University of Melbourne.
10 * Ported for AIX (jfs) by Joerg Schumacher (J.Schumacher@tu-bs.de) at the
11 * Technische Universitaet Braunschweig, FRG
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <sys/param.h> /* for DEV_BSIZE */
19 #include <sys/time.h> /* <rpc/rpc.h> on ultrix doesn't include this */
23 #include <netinet/in.h>
25 #include <rpc/pmap_prot.h>
26 #include <rpcsvc/rquota.h>
28 #include <atalk/afp.h>
32 #ifndef NO_QUOTA_SUPPORT
33 /* lifted (with modifications) from the bsd quota program */
35 callaurpc(vol, prognum, versnum, procnum, inproc, in, outproc, out)
37 u_long prognum, versnum, procnum;
38 xdrproc_t inproc, outproc;
41 enum clnt_stat clnt_stat;
42 struct timeval tottimeout;
44 if (!vol->v_nfsclient) {
46 struct sockaddr_in server_addr;
47 struct timeval timeout;
48 int socket = RPC_ANYSOCK;
50 if ((hp = gethostbyname(vol->v_gvs)) == NULL)
51 return ((int) RPC_UNKNOWNHOST);
54 memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
55 server_addr.sin_family = AF_INET;
56 server_addr.sin_port = 0;
58 if ((vol->v_nfsclient = (void *)
59 clntudp_create(&server_addr, prognum, versnum,
60 timeout, &socket)) == NULL)
61 return ((int) rpc_createerr.cf_stat);
63 ((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default();
66 tottimeout.tv_sec = 10;
67 tottimeout.tv_usec = 0;
68 clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum,
69 inproc, in, outproc, out, tottimeout);
70 return ((int) clnt_stat);
74 /* sunos 4 machines structure things a little differently. */
76 #define GQR_STATUS gqr_status
77 #define GQR_RQUOTA gqr_rquota
79 #define GQR_STATUS status
80 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
83 int getnfsquota(const struct vol *vol, const int uid, const u_int32_t bsize,
87 struct getquota_args gq_args;
88 struct getquota_rslt gq_rslt;
92 /* figure out the host and path */
93 if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) {
94 syslog(LOG_ERR, "can't find hostname for %s", vol->v_gvs);
98 if (*(hostpath + 1) != '/')
101 /* separate host from hostpath */
104 gq_args.gqa_pathp = hostpath + 1;
105 gq_args.gqa_uid = uid;
107 if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA,
108 (xdrproc_t) xdr_getquota_args, (char *) &gq_args,
109 (xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) {
110 syslog(LOG_INFO, "nfsquota: can't retrieve nfs quota information. \
111 make sure that rpc.rquotad is running on %s.", vol->v_gvs);
116 switch (gq_rslt.GQR_STATUS) {
121 syslog(LOG_ERR, "nfsquota: quota permission error, host: %s\n",
125 case Q_OK: /* we only copy the bits that we need. */
126 gettimeofday(&tv, NULL);
129 /* why doesn't using bsize work? */
130 #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / DEV_BSIZE)
132 /* NOTE: linux' rquotad program doesn't currently report the
133 * correct rq_bsize. */
134 #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / bsize)
137 dqp->dqb_bhardlimit =
138 gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE;
139 dqp->dqb_bsoftlimit =
140 gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE;
142 gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE;
145 dqp->dqb_bwarn = gq_rslt.GQR_RQUOTA.rq_btimeleft;
147 dqp->dqb_btimelimit =
148 tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft;
156 syslog(LOG_INFO, "bad rpc result, host: %s\n", vol->v_gvs);