]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/quota/quota.c
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[FreeBSD/FreeBSD.git] / usr.bin / quota / quota.c
1 /*
2  * Copyright (c) 1980, 1990, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Robert Elz at The University of Melbourne.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef lint
38 static const char copyright[] =
39 "@(#) Copyright (c) 1980, 1990, 1993\n\
40         The Regents of the University of California.  All rights reserved.\n";
41 #endif
42
43 #ifndef lint
44 static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
45 #endif /* not lint */
46
47 /*
48  * Disk quota reporting program.
49  */
50 #include <sys/cdefs.h>
51 __FBSDID("$FreeBSD$");
52
53 #include <sys/param.h>
54 #include <sys/types.h>
55 #include <sys/file.h>
56 #include <sys/stat.h>
57 #include <sys/mount.h>
58 #include <sys/socket.h>
59
60 #include <rpc/rpc.h>
61 #include <rpc/pmap_prot.h>
62 #include <rpcsvc/rquota.h>
63
64 #include <ufs/ufs/quota.h>
65
66 #include <ctype.h>
67 #include <err.h>
68 #include <fstab.h>
69 #include <grp.h>
70 #include <libutil.h>
71 #include <netdb.h>
72 #include <pwd.h>
73 #include <stdio.h>
74 #include <stdint.h>
75 #include <stdlib.h>
76 #include <string.h>
77 #include <time.h>
78 #include <unistd.h>
79
80 const char *qfname = QUOTAFILENAME;
81 const char *qfextension[] = INITQFNAMES;
82
83 struct quotause {
84         struct  quotause *next;
85         long    flags;
86         struct  dqblk dqblk;
87         char    fsname[MAXPATHLEN + 1];
88 };
89
90 static char *timeprt(time_t seconds);
91 static struct quotause *getprivs(long id, int quotatype);
92 static void usage(void);
93 static int showuid(u_long uid);
94 static int showgid(u_long gid);
95 static int showusrname(char *name);
96 static int showgrpname(char *name);
97 static int showquotas(int type, u_long id, const char *name);
98 static void showrawquotas(int type, u_long id, struct quotause *qup);
99 static void heading(int type, u_long id, const char *name, const char *tag);
100 static int ufshasquota(struct fstab *fs, int type, char **qfnamep);
101 static int getufsquota(struct fstab *fs, struct quotause *qup, long id,
102         int quotatype);
103 static int getnfsquota(struct statfs *fst, struct quotause *qup, long id,
104         int quotatype);
105 static int callaurpc(char *host, int prognum, int versnum, int procnum, 
106         xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
107 static int alldigits(char *s);
108
109 int     hflag;
110 int     lflag;
111 int     rflag;
112 int     qflag;
113 int     vflag;
114 char    *filename = NULL;
115
116 int
117 main(int argc, char *argv[])
118 {
119         int ngroups; 
120         gid_t mygid, gidset[NGROUPS];
121         int i, ch, gflag = 0, uflag = 0, errflag = 0;
122
123         while ((ch = getopt(argc, argv, "f:ghlrquv")) != -1) {
124                 switch(ch) {
125                 case 'f':
126                         filename = optarg;
127                         break;
128                 case 'g':
129                         gflag++;
130                         break;
131                 case 'h':
132                         hflag++;
133                         break;
134                 case 'l':
135                         lflag++;
136                         break;
137                 case 'q':
138                         qflag++;
139                         break;
140                 case 'r':
141                         rflag++;
142                         break;
143                 case 'u':
144                         uflag++;
145                         break;
146                 case 'v':
147                         vflag++;
148                         break;
149                 default:
150                         usage();
151                 }
152         }
153         argc -= optind;
154         argv += optind;
155         if (!uflag && !gflag)
156                 uflag++;
157         if (argc == 0) {
158                 if (uflag)
159                         errflag += showuid(getuid());
160                 if (gflag) {
161                         mygid = getgid();
162                         ngroups = getgroups(NGROUPS, gidset);
163                         if (ngroups < 0)
164                                 err(1, "getgroups");
165                         errflag += showgid(mygid);
166                         for (i = 0; i < ngroups; i++)
167                                 if (gidset[i] != mygid)
168                                         errflag += showgid(gidset[i]);
169                 }
170                 return(errflag);
171         }
172         if (uflag && gflag)
173                 usage();
174         if (uflag) {
175                 for (; argc > 0; argc--, argv++) {
176                         if (alldigits(*argv))
177                                 errflag += showuid(atoi(*argv));
178                         else
179                                 errflag += showusrname(*argv);
180                 }
181                 return(errflag);
182         }
183         if (gflag) {
184                 for (; argc > 0; argc--, argv++) {
185                         if (alldigits(*argv))
186                                 errflag += showgid(atoi(*argv));
187                         else
188                                 errflag += showgrpname(*argv);
189                 }
190         }
191         return(errflag);
192 }
193
194 static void
195 usage(void)
196 {
197
198         fprintf(stderr, "%s\n%s\n%s\n",
199             "usage: quota [-ghlu] [-f path] [-v | -q | -r]",
200             "       quota [-hlu] [-f path] [-v | -q | -r] user ...",
201             "       quota -g [-hl] [-f path] [-v | -q | -r] group ...");
202         exit(1);
203 }
204
205 /*
206  * Print out quotas for a specified user identifier.
207  */
208 static int
209 showuid(u_long uid)
210 {
211         struct passwd *pwd = getpwuid(uid);
212         const char *name;
213
214         if (pwd == NULL)
215                 name = "(no account)";
216         else
217                 name = pwd->pw_name;
218         return(showquotas(USRQUOTA, uid, name));
219 }
220
221 /*
222  * Print out quotas for a specifed user name.
223  */
224 static int
225 showusrname(char *name)
226 {
227         struct passwd *pwd = getpwnam(name);
228
229         if (pwd == NULL) {
230                 warnx("%s: unknown user", name);
231                 return(1);
232         }
233         return(showquotas(USRQUOTA, pwd->pw_uid, name));
234 }
235
236 /*
237  * Print out quotas for a specified group identifier.
238  */
239 static int
240 showgid(u_long gid)
241 {
242         struct group *grp = getgrgid(gid);
243         const char *name;
244
245         if (grp == NULL)
246                 name = "(no entry)";
247         else
248                 name = grp->gr_name;
249         return(showquotas(GRPQUOTA, gid, name));
250 }
251
252 /*
253  * Print out quotas for a specifed group name.
254  */
255 static int
256 showgrpname(char *name)
257 {
258         struct group *grp = getgrnam(name);
259
260         if (grp == NULL) {
261                 warnx("%s: unknown group", name);
262                 return(1);
263         }
264         return(showquotas(GRPQUOTA, grp->gr_gid, name));
265 }
266
267 static void
268 prthumanval(int len, int64_t bytes)
269 {
270         char buf[len + 1];
271
272         humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
273             HN_B | HN_NOSPACE | HN_DECIMAL);
274
275         (void)printf(" %*s", len, buf);
276 }
277
278 static int
279 showquotas(int type, u_long id, const char *name)
280 {
281         struct quotause *qup;
282         struct quotause *quplist;
283         const char *msgi, *msgb;
284         const char *nam;
285         char *bgrace = NULL, *igrace = NULL;
286         int lines = 0, overquota = 0;
287         static time_t now;
288
289         if (now == 0)
290                 time(&now);
291         quplist = getprivs(id, type);
292         for (qup = quplist; qup; qup = qup->next) {
293                 msgi = (char *)0;
294                 if (qup->dqblk.dqb_ihardlimit &&
295                     qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) {
296                         overquota++;
297                         msgi = "File limit reached on";
298                 }
299                 else if (qup->dqblk.dqb_isoftlimit &&
300                     qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
301                         overquota++;
302                         if (qup->dqblk.dqb_itime > now)
303                                 msgi = "In file grace period on";
304                         else
305                                 msgi = "Over file quota on";
306                 }
307                 msgb = (char *)0;
308                 if (qup->dqblk.dqb_bhardlimit &&
309                     qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) {
310                         overquota++;
311                         msgb = "Block limit reached on";
312                 }
313                 else if (qup->dqblk.dqb_bsoftlimit &&
314                     qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
315                         overquota++;
316                         if (qup->dqblk.dqb_btime > now)
317                                 msgb = "In block grace period on";
318                         else
319                                 msgb = "Over block quota on";
320                 }
321                 if (rflag) {
322                         showrawquotas(type, id, qup);
323                         continue;
324                 }
325                 if (!vflag &&
326                     qup->dqblk.dqb_isoftlimit == 0 &&
327                     qup->dqblk.dqb_ihardlimit == 0 &&
328                     qup->dqblk.dqb_bsoftlimit == 0 &&
329                     qup->dqblk.dqb_bhardlimit == 0)
330                         continue;
331                 if (qflag) {
332                         if ((msgi != (char *)0 || msgb != (char *)0) &&
333                             lines++ == 0)
334                                 heading(type, id, name, "");
335                         if (msgi != (char *)0)
336                                 printf("\t%s %s\n", msgi, qup->fsname);
337                         if (msgb != (char *)0)
338                                 printf("\t%s %s\n", msgb, qup->fsname);
339                         continue;
340                 }
341                 if (vflag ||
342                     qup->dqblk.dqb_curblocks ||
343                     qup->dqblk.dqb_curinodes) {
344                         if (lines++ == 0)
345                                 heading(type, id, name, "");
346                         nam = qup->fsname;
347                         if (strlen(qup->fsname) > 15) {
348                                 printf("%s\n", qup->fsname);
349                                 nam = "";
350                         } 
351                         printf("%15s", nam);
352                         if (hflag) {
353                                 printf("   ");
354                                 prthumanval(4, dbtob(qup->dqblk.dqb_curblocks));
355                                 printf("%c  ", (msgb == (char *)0) ? ' ' : '*');
356                                 prthumanval(4, dbtob(qup->dqblk.dqb_bsoftlimit));
357                                 printf("   ");
358                                 prthumanval(4, dbtob(qup->dqblk.dqb_bhardlimit));
359                         } else {
360                                 printf(" %7ju%c %6ju %7ju",
361                                     (uintmax_t)(dbtob(qup->dqblk.dqb_curblocks)
362                                         / 1024),
363                                     (msgb == NULL) ? ' ' : '*',
364                                     (uintmax_t)(dbtob(qup->dqblk.dqb_bsoftlimit)
365                                         / 1024),
366                                     (uintmax_t)(dbtob(qup->dqblk.dqb_bhardlimit)
367                                         / 1024));
368                         }
369                         if (msgb != NULL)
370                                 bgrace = timeprt(qup->dqblk.dqb_btime);
371                         if (msgi != NULL)
372                                 igrace = timeprt(qup->dqblk.dqb_itime);
373                         printf(" %7s %7ju%c %6ju %7ju %7s\n",
374                             (msgb == NULL) ? "" : bgrace,
375                             (uintmax_t)qup->dqblk.dqb_curinodes,
376                             (msgi == NULL) ? ' ' : '*',
377                             (uintmax_t)qup->dqblk.dqb_isoftlimit,
378                             (uintmax_t)qup->dqblk.dqb_ihardlimit,
379                             (msgi == NULL) ? "" : igrace
380                         );
381                         if (msgb != NULL)
382                                 free(bgrace);
383                         if (msgi != NULL)
384                                 free(igrace);
385                         continue;
386                 }
387         }
388         if (!qflag && !rflag && lines == 0)
389                 heading(type, id, name, "none");
390         return(overquota);
391 }
392
393 static void
394 showrawquotas(int type, u_long id, struct quotause *qup)
395 {
396         time_t tt;
397         printf("Raw %s quota information for id %lu on %s\n",
398             type == USRQUOTA ? "user" : "group", id, qup->fsname);
399         printf("block hard limit:     %ju\n", (uintmax_t)qup->dqblk.dqb_bhardlimit);
400         printf("block soft limit:     %ju\n", (uintmax_t)qup->dqblk.dqb_bsoftlimit);
401         printf("current block count:  %ju\n", (uintmax_t)qup->dqblk.dqb_curblocks);
402         printf("i-node hard limit:    %ju\n", (uintmax_t)qup->dqblk.dqb_ihardlimit);
403         printf("i-node soft limit:    %ju\n", (uintmax_t)qup->dqblk.dqb_isoftlimit);
404         printf("current i-node count: %ju\n", (uintmax_t)qup->dqblk.dqb_curinodes);
405         printf("block grace time:     %jd", (intmax_t)qup->dqblk.dqb_btime);
406         if (qup->dqblk.dqb_btime != 0) {
407                 tt = qup->dqblk.dqb_btime;
408                 printf(" %s", ctime(&tt));
409         } else
410                 printf("\n");
411         printf("i-node grace time:    %jd", (intmax_t)qup->dqblk.dqb_itime);
412         if (qup->dqblk.dqb_itime != 0) {
413                 tt = qup->dqblk.dqb_itime;
414                 printf(" %s", ctime(&tt));
415         } else
416                 printf("\n");
417 }
418
419
420 static void
421 heading(int type, u_long id, const char *name, const char *tag)
422 {
423
424         printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type],
425             name, *qfextension[type], id, tag);
426         if (!qflag && tag[0] == '\0') {
427                 printf("%15s %7s  %6s %7s %7s %7s  %6s %7s %7s\n"
428                         , "Filesystem"
429                         , "usage"
430                         , "quota"
431                         , "limit"
432                         , "grace"
433                         , "files"
434                         , "quota"
435                         , "limit"
436                         , "grace"
437                 );
438         }
439 }
440
441 /*
442  * Calculate the grace period and return a printable string for it.
443  */
444 static char *
445 timeprt(time_t seconds)
446 {
447         time_t hours, minutes;
448         char    *buf;
449         static time_t now;
450
451         if (now == 0)
452                 time(&now);
453         if (now > seconds) {
454                 return strdup("none");
455         }
456         seconds -= now;
457         minutes = (seconds + 30) / 60;
458         hours = (minutes + 30) / 60;
459         if (hours >= 36) {
460                 if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0)
461                         errx(1, "asprintf failed in timeprt(1)");
462                 return (buf);
463         }
464         if (minutes >= 60) {
465                 if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60,
466                     (long)minutes % 60) < 0)
467                         errx(1, "asprintf failed in timeprt(2)");
468                 return (buf);
469         }
470         if (asprintf(&buf, "%2ld", (long)minutes) < 0)
471                 errx(1, "asprintf failed in timeprt(3)");
472         return (buf);
473 }
474
475 /*
476  * Collect the requested quota information.
477  */
478 static struct quotause *
479 getprivs(long id, int quotatype)
480 {
481         struct quotause *qup, *quptail = NULL;
482         struct fstab *fs;
483         struct quotause *quphead;
484         struct statfs *fst;
485         int nfst, i;
486         struct statfs sfb;
487
488         qup = quphead = (struct quotause *)0;
489
490         if (filename != NULL && statfs(filename, &sfb) != 0)
491                 err(1, "cannot statfs %s", filename);
492         nfst = getmntinfo(&fst, MNT_NOWAIT);
493         if (nfst == 0)
494                 errx(2, "no filesystems mounted!");
495         setfsent();
496         for (i=0; i<nfst; i++) {
497                 if (qup == NULL) {
498                         if ((qup = (struct quotause *)malloc(sizeof *qup))
499                             == NULL)
500                                 errx(2, "out of memory");
501                 }
502                 /*
503                  * See if the user requested a specific file system
504                  * or specified a file inside a mounted file system.
505                  */
506                 if (filename != NULL &&
507                     strcmp(sfb.f_mntonname, fst[i].f_mntonname) != 0)
508                         continue;
509                 if (strcmp(fst[i].f_fstypename, "nfs") == 0) {
510                         if (lflag)
511                                 continue;
512                         if (getnfsquota(&fst[i], qup, id, quotatype) == 0)
513                                 continue;
514                 } else if (strcmp(fst[i].f_fstypename, "ufs") == 0) {
515                         /*
516                          * XXX
517                          * UFS filesystems must be in /etc/fstab, and must
518                          * indicate that they have quotas on (?!) This is quite
519                          * unlike SunOS where quotas can be enabled/disabled
520                          * on a filesystem independent of /etc/fstab, and it
521                          * will still print quotas for them.
522                          */
523                         if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL)
524                                 continue;
525                         if (getufsquota(fs, qup, id, quotatype) == 0)
526                                 continue;
527                 } else
528                         continue;
529                 strcpy(qup->fsname, fst[i].f_mntonname);
530                 if (quphead == NULL)
531                         quphead = qup;
532                 else
533                         quptail->next = qup;
534                 quptail = qup;
535                 quptail->next = 0;
536                 qup = NULL;
537         }
538         if (qup)
539                 free(qup);
540         endfsent();
541         return (quphead);
542 }
543
544 /*
545  * Check to see if a particular quota is to be enabled.
546  */
547 static int
548 ufshasquota(struct fstab *fs, int type, char **qfnamep)
549 {
550         char *opt;
551         char *cp;
552         struct statfs sfb;
553         static char initname, usrname[100], grpname[100];
554         static char buf[BUFSIZ];
555
556         if (!initname) {
557                 (void)snprintf(usrname, sizeof(usrname), "%s%s",
558                     qfextension[USRQUOTA], qfname);
559                 (void)snprintf(grpname, sizeof(grpname), "%s%s",
560                     qfextension[GRPQUOTA], qfname);
561                 initname = 1;
562         }
563         strcpy(buf, fs->fs_mntops);
564         for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
565                 if ((cp = index(opt, '=')))
566                         *cp++ = '\0';
567                 if (type == USRQUOTA && strcmp(opt, usrname) == 0)
568                         break;
569                 if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
570                         break;
571         }
572         if (!opt)
573                 return (0);
574         if (cp)
575                 *qfnamep = cp;
576         else {
577                 (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file,
578                     qfname, qfextension[type]);
579                 *qfnamep = buf;
580         }
581         if (statfs(fs->fs_file, &sfb) != 0) {
582                 warn("cannot statfs mount point %s", fs->fs_file);
583                 return (0);
584         }
585         if (strcmp(fs->fs_file, sfb.f_mntonname)) {
586                 warnx("%s not mounted for %s quotas", fs->fs_file,
587                     type == USRQUOTA ? "user" : "group");
588                 return (0);
589         }
590         return (1);
591 }
592
593 static int
594 getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
595 {
596         char *qfpathname;
597         int fd, qcmd;
598
599         qcmd = QCMD(Q_GETQUOTA, quotatype);
600         if (!ufshasquota(fs, quotatype, &qfpathname))
601                 return (0);
602
603         if (quotactl(fs->fs_file, qcmd, id, (char *)&qup->dqblk) != 0) {
604                 if ((fd = open(qfpathname, O_RDONLY)) < 0) {
605                         warn("%s", qfpathname);
606                         return (0);
607                 }
608                 (void) lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET);
609                 switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
610                 case 0:                         /* EOF */
611                         /*
612                          * Convert implicit 0 quota (EOF)
613                          * into an explicit one (zero'ed dqblk)
614                          */
615                         bzero((caddr_t)&qup->dqblk, sizeof(struct dqblk));
616                         break;
617                 case sizeof(struct dqblk):      /* OK */
618                         break;
619                 default:                /* ERROR */
620                         warn("read error: %s", qfpathname);
621                         close(fd);
622                         return (0);
623                 }
624                 close(fd);
625         }
626         return (1);
627 }
628
629 static int
630 getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
631 {
632         struct getquota_args gq_args;
633         struct getquota_rslt gq_rslt;
634         struct dqblk *dqp = &qup->dqblk;
635         struct timeval tv;
636         char *cp;
637
638         if (fst->f_flags & MNT_LOCAL)
639                 return (0);
640
641         /*
642          * rpc.rquotad does not support group quotas
643          */
644         if (quotatype != USRQUOTA)
645                 return (0);
646
647         /*
648          * must be some form of "hostname:/path"
649          */
650         cp = strchr(fst->f_mntfromname, ':');
651         if (cp == NULL) {
652                 warnx("cannot find hostname for %s", fst->f_mntfromname);
653                 return (0);
654         }
655  
656         *cp = '\0';
657         if (*(cp+1) != '/') {
658                 *cp = ':';
659                 return (0);
660         }
661
662         /* Avoid attempting the RPC for special amd(8) filesystems. */
663         if (strncmp(fst->f_mntfromname, "pid", 3) == 0 &&
664             strchr(fst->f_mntfromname, '@') != NULL) {
665                 *cp = ':';
666                 return (0);
667         }
668
669         gq_args.gqa_pathp = cp + 1;
670         gq_args.gqa_uid = id;
671         if (callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS,
672             RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args,
673             (xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) {
674                 *cp = ':';
675                 return (0);
676         }
677
678         switch (gq_rslt.status) {
679         case Q_NOQUOTA:
680                 break;
681         case Q_EPERM:
682                 warnx("quota permission error, host: %s",
683                         fst->f_mntfromname);
684                 break;
685         case Q_OK:
686                 gettimeofday(&tv, NULL);
687                         /* blocks*/
688                 dqp->dqb_bhardlimit =
689                     gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit *
690                     (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
691                 dqp->dqb_bsoftlimit =
692                     gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit *
693                     (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
694                 dqp->dqb_curblocks =
695                     gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks *
696                     (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE);
697                         /* inodes */
698                 dqp->dqb_ihardlimit =
699                         gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit;
700                 dqp->dqb_isoftlimit =
701                         gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit;
702                 dqp->dqb_curinodes =
703                         gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles;
704                         /* grace times */
705                 dqp->dqb_btime =
706                     tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft;
707                 dqp->dqb_itime =
708                     tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft;
709                 *cp = ':';
710                 return (1);
711         default:
712                 warnx("bad rpc result, host: %s", fst->f_mntfromname);
713                 break;
714         }
715         *cp = ':';
716         return (0);
717 }
718  
719 static int
720 callaurpc(char *host, int prognum, int versnum, int procnum,
721     xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
722 {
723         struct sockaddr_in server_addr;
724         enum clnt_stat clnt_stat;
725         struct hostent *hp;
726         struct timeval timeout, tottimeout;
727  
728         CLIENT *client = NULL;
729         int sock = RPC_ANYSOCK;
730  
731         if ((hp = gethostbyname(host)) == NULL)
732                 return ((int) RPC_UNKNOWNHOST);
733         timeout.tv_usec = 0;
734         timeout.tv_sec = 6;
735         bcopy(hp->h_addr, &server_addr.sin_addr,
736                         MIN(hp->h_length,(int)sizeof(server_addr.sin_addr)));
737         server_addr.sin_family = AF_INET;
738         server_addr.sin_port =  0;
739
740         if ((client = clntudp_create(&server_addr, prognum,
741             versnum, timeout, &sock)) == NULL)
742                 return ((int) rpc_createerr.cf_stat);
743
744         client->cl_auth = authunix_create_default();
745         tottimeout.tv_sec = 25;
746         tottimeout.tv_usec = 0;
747         clnt_stat = clnt_call(client, procnum, inproc, in,
748             outproc, out, tottimeout);
749  
750         return ((int) clnt_stat);
751 }
752
753 static int
754 alldigits(char *s)
755 {
756         int c;
757
758         c = *s++;
759         do {
760                 if (!isdigit(c))
761                         return (0);
762         } while ((c = *s++));
763         return (1);
764 }