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