2 * $Id: nfsquota.c,v 1.3 2001-06-20 18:33:04 rufustfirefly 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 */
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <sys/param.h> /* for DEV_BSIZE */
26 #include <sys/time.h> /* <rpc/rpc.h> on ultrix doesn't include this */
31 #endif /* HAVE_NETDB_H */
32 #include <netinet/in.h>
34 #include <rpc/pmap_prot.h>
35 #include <rpcsvc/rquota.h>
37 #include <atalk/afp.h>
41 #ifndef NO_QUOTA_SUPPORT
42 /* lifted (with modifications) from the bsd quota program */
44 callaurpc(vol, prognum, versnum, procnum, inproc, in, outproc, out)
46 u_long prognum, versnum, procnum;
47 xdrproc_t inproc, outproc;
50 enum clnt_stat clnt_stat;
51 struct timeval tottimeout;
53 if (!vol->v_nfsclient) {
55 struct sockaddr_in server_addr;
56 struct timeval timeout;
57 int socket = RPC_ANYSOCK;
59 if ((hp = gethostbyname(vol->v_gvs)) == NULL)
60 return ((int) RPC_UNKNOWNHOST);
63 memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
64 server_addr.sin_family = AF_INET;
65 server_addr.sin_port = 0;
67 if ((vol->v_nfsclient = (void *)
68 clntudp_create(&server_addr, prognum, versnum,
69 timeout, &socket)) == NULL)
70 return ((int) rpc_createerr.cf_stat);
72 ((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default();
75 tottimeout.tv_sec = 10;
76 tottimeout.tv_usec = 0;
77 clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum,
78 inproc, in, outproc, out, tottimeout);
79 return ((int) clnt_stat);
83 /* sunos 4 machines structure things a little differently. */
85 #define GQR_STATUS gqr_status
86 #define GQR_RQUOTA gqr_rquota
87 #else /* USE_OLD_RQUOTA */
88 #define GQR_STATUS status
89 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
90 #endif /* USE_OLD_RQUOTA */
92 int getnfsquota(const struct vol *vol, const int uid, const u_int32_t bsize,
96 struct getquota_args gq_args;
97 struct getquota_rslt gq_rslt;
101 /* figure out the host and path */
102 if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) {
103 syslog(LOG_ERR, "can't find hostname for %s", vol->v_gvs);
107 if (*(hostpath + 1) != '/')
110 /* separate host from hostpath */
113 gq_args.gqa_pathp = hostpath + 1;
114 gq_args.gqa_uid = uid;
116 if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA,
117 (xdrproc_t) xdr_getquota_args, (char *) &gq_args,
118 (xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) {
119 syslog(LOG_INFO, "nfsquota: can't retrieve nfs quota information. \
120 make sure that rpc.rquotad is running on %s.", vol->v_gvs);
125 switch (gq_rslt.GQR_STATUS) {
130 syslog(LOG_ERR, "nfsquota: quota permission error, host: %s\n",
134 case Q_OK: /* we only copy the bits that we need. */
135 gettimeofday(&tv, NULL);
138 /* why doesn't using bsize work? */
139 #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / DEV_BSIZE)
141 /* NOTE: linux' rquotad program doesn't currently report the
142 * correct rq_bsize. */
143 #define NFS_BSIZE (gq_rslt.GQR_RQUOTA.rq_bsize / bsize)
144 #endif /* __svr4__ */
146 dqp->dqb_bhardlimit =
147 gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE;
148 dqp->dqb_bsoftlimit =
149 gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE;
151 gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE;
154 dqp->dqb_bwarn = gq_rslt.GQR_RQUOTA.rq_btimeleft;
156 dqp->dqb_btimelimit =
157 tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft;
165 syslog(LOG_INFO, "bad rpc result, host: %s\n", vol->v_gvs);
172 #endif /* ! NO_QUOTA_SUPPORT */