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, *igrace; 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 prthumanval(7, dbtob(qup->dqblk.dqb_curblocks)); 354 printf("%c", (msgb == (char *)0) ? ' ' : '*'); 355 prthumanval(6, dbtob(qup->dqblk.dqb_bsoftlimit)); 356 prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit)); 357 } else { 358 printf(" %7ju%c %6ju %7ju", 359 (uintmax_t)(dbtob(qup->dqblk.dqb_curblocks) 360 / 1024), 361 (msgb == NULL) ? ' ' : '*', 362 (uintmax_t)(dbtob(qup->dqblk.dqb_bsoftlimit) 363 / 1024), 364 (uintmax_t)(dbtob(qup->dqblk.dqb_bhardlimit) 365 / 1024)); 366 } 367 if (msgb != NULL) 368 bgrace = timeprt(qup->dqblk.dqb_btime); 369 if (msgi != NULL) 370 igrace = timeprt(qup->dqblk.dqb_itime); 371 printf(" %7s %7ju%c %6ju %7ju %7s\n", 372 (msgb == NULL) ? "" : bgrace, 373 (uintmax_t)qup->dqblk.dqb_curinodes, 374 (msgi == NULL) ? ' ' : '*', 375 (uintmax_t)qup->dqblk.dqb_isoftlimit, 376 (uintmax_t)qup->dqblk.dqb_ihardlimit, 377 (msgi == NULL) ? "" : igrace 378 ); 379 if (msgb != NULL) 380 free(bgrace); 381 if (msgi != NULL) 382 free(igrace); 383 continue; 384 } 385 } 386 if (!qflag && !rflag && lines == 0) 387 heading(type, id, name, "none"); 388 return(overquota); 389 } 390 391 static void 392 showrawquotas(type, id, qup) 393 int type; 394 u_long id; 395 struct quotause *qup; 396 { 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 printf(" %s", ctime(&qup->dqblk.dqb_btime)); 408 else 409 printf("\n"); 410 printf("i-node grace time: %jd", (intmax_t)qup->dqblk.dqb_itime); 411 if (qup->dqblk.dqb_itime != 0) 412 printf(" %s", ctime(&qup->dqblk.dqb_itime)); 413 else 414 printf("\n"); 415 } 416 417 418 static void 419 heading(int type, u_long id, const char *name, const char *tag) 420 { 421 422 printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type], 423 name, *qfextension[type], id, tag); 424 if (!qflag && tag[0] == '\0') { 425 printf("%15s %7s %6s %7s %7s %7s %6s %7s %7s\n" 426 , "Filesystem" 427 , "usage" 428 , "quota" 429 , "limit" 430 , "grace" 431 , "files" 432 , "quota" 433 , "limit" 434 , "grace" 435 ); 436 } 437 } 438 439 /* 440 * Calculate the grace period and return a printable string for it. 441 */ 442 static char * 443 timeprt(time_t seconds) 444 { 445 time_t hours, minutes; 446 char *buf; 447 static time_t now; 448 449 if (now == 0) 450 time(&now); 451 if (now > seconds) { 452 return strdup("none"); 453 } 454 seconds -= now; 455 minutes = (seconds + 30) / 60; 456 hours = (minutes + 30) / 60; 457 if (hours >= 36) { 458 if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0) 459 errx(1, "asprintf failed in timeprt(1)"); 460 return (buf); 461 } 462 if (minutes >= 60) { 463 if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60, 464 (long)minutes % 60) < 0) 465 errx(1, "asprintf failed in timeprt(2)"); 466 return (buf); 467 } 468 if (asprintf(&buf, "%2ld", (long)minutes) < 0) 469 errx(1, "asprintf failed in timeprt(3)"); 470 return (buf); 471 } 472 473 /* 474 * Collect the requested quota information. 475 */ 476 static struct quotause * 477 getprivs(long id, int quotatype) 478 { 479 struct quotause *qup, *quptail = NULL; 480 struct fstab *fs; 481 struct quotause *quphead; 482 struct statfs *fst; 483 int nfst, i; 484 struct statfs sfb; 485 486 qup = quphead = (struct quotause *)0; 487 488 if (filename != NULL && statfs(filename, &sfb) != 0) 489 err(1, "cannot statfs %s", filename); 490 nfst = getmntinfo(&fst, MNT_NOWAIT); 491 if (nfst == 0) 492 errx(2, "no filesystems mounted!"); 493 setfsent(); 494 for (i=0; i<nfst; i++) { 495 if (qup == NULL) { 496 if ((qup = (struct quotause *)malloc(sizeof *qup)) 497 == NULL) 498 errx(2, "out of memory"); 499 } 500 /* 501 * See if the user requested a specific file system 502 * or specified a file inside a mounted file system. 503 */ 504 if (filename != NULL && 505 strcmp(sfb.f_mntonname, fst[i].f_mntonname) != 0) 506 continue; 507 if (strcmp(fst[i].f_fstypename, "nfs") == 0) { 508 if (lflag) 509 continue; 510 if (getnfsquota(&fst[i], qup, id, quotatype) == 0) 511 continue; 512 } else if (strcmp(fst[i].f_fstypename, "ufs") == 0) { 513 /* 514 * XXX 515 * UFS filesystems must be in /etc/fstab, and must 516 * indicate that they have quotas on (?!) This is quite 517 * unlike SunOS where quotas can be enabled/disabled 518 * on a filesystem independent of /etc/fstab, and it 519 * will still print quotas for them. 520 */ 521 if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL) 522 continue; 523 if (getufsquota(fs, qup, id, quotatype) == 0) 524 continue; 525 } else 526 continue; 527 strcpy(qup->fsname, fst[i].f_mntonname); 528 if (quphead == NULL) 529 quphead = qup; 530 else 531 quptail->next = qup; 532 quptail = qup; 533 quptail->next = 0; 534 qup = NULL; 535 } 536 if (qup) 537 free(qup); 538 endfsent(); 539 return (quphead); 540 } 541 542 /* 543 * Check to see if a particular quota is to be enabled. 544 */ 545 static int 546 ufshasquota(struct fstab *fs, int type, char **qfnamep) 547 { 548 char *opt; 549 char *cp; 550 struct statfs sfb; 551 static char initname, usrname[100], grpname[100]; 552 static char buf[BUFSIZ]; 553 554 if (!initname) { 555 (void)snprintf(usrname, sizeof(usrname), "%s%s", 556 qfextension[USRQUOTA], qfname); 557 (void)snprintf(grpname, sizeof(grpname), "%s%s", 558 qfextension[GRPQUOTA], qfname); 559 initname = 1; 560 } 561 strcpy(buf, fs->fs_mntops); 562 for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { 563 if ((cp = index(opt, '='))) 564 *cp++ = '\0'; 565 if (type == USRQUOTA && strcmp(opt, usrname) == 0) 566 break; 567 if (type == GRPQUOTA && strcmp(opt, grpname) == 0) 568 break; 569 } 570 if (!opt) 571 return (0); 572 if (cp) 573 *qfnamep = cp; 574 else { 575 (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, 576 qfname, qfextension[type]); 577 *qfnamep = buf; 578 } 579 if (statfs(fs->fs_file, &sfb) != 0) { 580 warn("cannot statfs mount point %s", fs->fs_file); 581 return (0); 582 } 583 if (strcmp(fs->fs_file, sfb.f_mntonname)) { 584 warnx("%s not mounted for %s quotas", fs->fs_file, 585 type == USRQUOTA ? "user" : "group"); 586 return (0); 587 } 588 return (1); 589 } 590 591 static int 592 getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype) 593 { 594 char *qfpathname; 595 int fd, qcmd; 596 597 qcmd = QCMD(Q_GETQUOTA, quotatype); 598 if (!ufshasquota(fs, quotatype, &qfpathname)) 599 return (0); 600 601 if (quotactl(fs->fs_file, qcmd, id, (char *)&qup->dqblk) != 0) { 602 if ((fd = open(qfpathname, O_RDONLY)) < 0) { 603 warn("%s", qfpathname); 604 return (0); 605 } 606 (void) lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET); 607 switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) { 608 case 0: /* EOF */ 609 /* 610 * Convert implicit 0 quota (EOF) 611 * into an explicit one (zero'ed dqblk) 612 */ 613 bzero((caddr_t)&qup->dqblk, sizeof(struct dqblk)); 614 break; 615 case sizeof(struct dqblk): /* OK */ 616 break; 617 default: /* ERROR */ 618 warn("read error: %s", qfpathname); 619 close(fd); 620 return (0); 621 } 622 close(fd); 623 } 624 return (1); 625 } 626 627 static int 628 getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype) 629 { 630 struct getquota_args gq_args; 631 struct getquota_rslt gq_rslt; 632 struct dqblk *dqp = &qup->dqblk; 633 struct timeval tv; 634 char *cp; 635 636 if (fst->f_flags & MNT_LOCAL) 637 return (0); 638 639 /* 640 * rpc.rquotad does not support group quotas 641 */ 642 if (quotatype != USRQUOTA) 643 return (0); 644 645 /* 646 * must be some form of "hostname:/path" 647 */ 648 cp = strchr(fst->f_mntfromname, ':'); 649 if (cp == NULL) { 650 warnx("cannot find hostname for %s", fst->f_mntfromname); 651 return (0); 652 } 653 654 *cp = '\0'; 655 if (*(cp+1) != '/') { 656 *cp = ':'; 657 return (0); 658 } 659 660 /* Avoid attempting the RPC for special amd(8) filesystems. */ 661 if (strncmp(fst->f_mntfromname, "pid", 3) == 0 && 662 strchr(fst->f_mntfromname, '@') != NULL) { 663 *cp = ':'; 664 return (0); 665 } 666 667 gq_args.gqa_pathp = cp + 1; 668 gq_args.gqa_uid = id; 669 if (callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS, 670 RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args, 671 (xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) { 672 *cp = ':'; 673 return (0); 674 } 675 676 switch (gq_rslt.status) { 677 case Q_NOQUOTA: 678 break; 679 case Q_EPERM: 680 warnx("quota permission error, host: %s", 681 fst->f_mntfromname); 682 break; 683 case Q_OK: 684 gettimeofday(&tv, NULL); 685 /* blocks*/ 686 dqp->dqb_bhardlimit = 687 gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit * 688 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 689 dqp->dqb_bsoftlimit = 690 gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit * 691 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 692 dqp->dqb_curblocks = 693 gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks * 694 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 695 /* inodes */ 696 dqp->dqb_ihardlimit = 697 gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit; 698 dqp->dqb_isoftlimit = 699 gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit; 700 dqp->dqb_curinodes = 701 gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles; 702 /* grace times */ 703 dqp->dqb_btime = 704 tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft; 705 dqp->dqb_itime = 706 tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft; 707 *cp = ':'; 708 return (1); 709 default: 710 warnx("bad rpc result, host: %s", fst->f_mntfromname); 711 break; 712 } 713 *cp = ':'; 714 return (0); 715 } 716 717 static int 718 callaurpc(char *host, int prognum, int versnum, int procnum, 719 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) 720 { 721 struct sockaddr_in server_addr; 722 enum clnt_stat clnt_stat; 723 struct hostent *hp; 724 struct timeval timeout, tottimeout; 725 726 CLIENT *client = NULL; 727 int sock = RPC_ANYSOCK; 728 729 if ((hp = gethostbyname(host)) == NULL) 730 return ((int) RPC_UNKNOWNHOST); 731 timeout.tv_usec = 0; 732 timeout.tv_sec = 6; 733 bcopy(hp->h_addr, &server_addr.sin_addr, 734 MIN(hp->h_length,(int)sizeof(server_addr.sin_addr))); 735 server_addr.sin_family = AF_INET; 736 server_addr.sin_port = 0; 737 738 if ((client = clntudp_create(&server_addr, prognum, 739 versnum, timeout, &sock)) == NULL) 740 return ((int) rpc_createerr.cf_stat); 741 742 client->cl_auth = authunix_create_default(); 743 tottimeout.tv_sec = 25; 744 tottimeout.tv_usec = 0; 745 clnt_stat = clnt_call(client, procnum, inproc, in, 746 outproc, out, tottimeout); 747 748 return ((int) clnt_stat); 749 } 750 751 static int 752 alldigits(char *s) 753 { 754 int c; 755 756 c = *s++; 757 do { 758 if (!isdigit(c)) 759 return (0); 760 } while ((c = *s++)); 761 return (1); 762 } 763