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