quota.c revision 227176
1181834Sroberto/* 2290000Sglebius * Copyright (c) 1980, 1990, 1993 3290000Sglebius * The Regents of the University of California. All rights reserved. 4181834Sroberto * 5181834Sroberto * This code is derived from software contributed to Berkeley by 6181834Sroberto * Robert Elz at The University of Melbourne. 7290000Sglebius * 8290000Sglebius * Redistribution and use in source and binary forms, with or without 9290000Sglebius * modification, are permitted provided that the following conditions 10181834Sroberto * are met: 11181834Sroberto * 1. Redistributions of source code must retain the above copyright 12290000Sglebius * notice, this list of conditions and the following disclaimer. 13290000Sglebius * 2. Redistributions in binary form must reproduce the above copyright 14290000Sglebius * notice, this list of conditions and the following disclaimer in the 15181834Sroberto * documentation and/or other materials provided with the distribution. 16290000Sglebius * 4. Neither the name of the University nor the names of its contributors 17290000Sglebius * may be used to endorse or promote products derived from this software 18290000Sglebius * without specific prior written permission. 19181834Sroberto * 20290000Sglebius * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21290000Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22181834Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23290000Sglebius * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24290000Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25181834Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26290000Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27181834Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28290000Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29290000Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30290000Sglebius * SUCH DAMAGE. 31181834Sroberto */ 32181834Sroberto 33181834Sroberto#ifndef lint 34181834Srobertostatic const char copyright[] = 35181834Sroberto"@(#) Copyright (c) 1980, 1990, 1993\n\ 36181834Sroberto The Regents of the University of California. All rights reserved.\n"; 37181834Sroberto#endif 38181834Sroberto 39181834Sroberto#ifndef lint 40181834Srobertostatic const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93"; 41290000Sglebius#endif /* not lint */ 42290000Sglebius 43181834Sroberto/* 44181834Sroberto * Disk quota reporting program. 45181834Sroberto */ 46181834Sroberto#include <sys/cdefs.h> 47181834Sroberto__FBSDID("$FreeBSD: head/usr.bin/quota/quota.c 227176 2011-11-06 08:16:29Z ed $"); 48290000Sglebius 49181834Sroberto#include <sys/param.h> 50290000Sglebius#include <sys/types.h> 51181834Sroberto#include <sys/file.h> 52290000Sglebius#include <sys/stat.h> 53290000Sglebius#include <sys/mount.h> 54290000Sglebius#include <sys/socket.h> 55290000Sglebius 56290000Sglebius#include <rpc/rpc.h> 57181834Sroberto#include <rpc/pmap_prot.h> 58181834Sroberto#include <rpcsvc/rquota.h> 59181834Sroberto 60181834Sroberto#include <ufs/ufs/quota.h> 61290000Sglebius 62290000Sglebius#include <ctype.h> 63290000Sglebius#include <err.h> 64290000Sglebius#include <fstab.h> 65181834Sroberto#include <grp.h> 66181834Sroberto#include <libutil.h> 67181834Sroberto#include <netdb.h> 68181834Sroberto#include <pwd.h> 69181834Sroberto#include <stdio.h> 70181834Sroberto#include <stdint.h> 71181834Sroberto#include <stdlib.h> 72181834Sroberto#include <string.h> 73290000Sglebius#include <time.h> 74181834Sroberto#include <unistd.h> 75181834Sroberto 76181834Srobertostatic const char *qfextension[] = INITQFNAMES; 77181834Sroberto 78181834Srobertostruct quotause { 79181834Sroberto struct quotause *next; 80181834Sroberto long flags; 81181834Sroberto struct dqblk dqblk; 82290000Sglebius char fsname[MAXPATHLEN + 1]; 83290000Sglebius}; 84290000Sglebius 85290000Sglebiusstatic char *timeprt(int64_t seconds); 86181834Srobertostatic struct quotause *getprivs(long id, int quotatype); 87290000Sglebiusstatic void usage(void); 88181834Srobertostatic int showuid(u_long uid); 89181834Srobertostatic int showgid(u_long gid); 90181834Srobertostatic int showusrname(char *name); 91290000Sglebiusstatic int showgrpname(char *name); 92181834Srobertostatic int showquotas(int type, u_long id, const char *name); 93181834Srobertostatic void showrawquotas(int type, u_long id, struct quotause *qup); 94181834Srobertostatic void heading(int type, u_long id, const char *name, const char *tag); 95181834Srobertostatic int getufsquota(struct fstab *fs, struct quotause *qup, long id, 96181834Sroberto int quotatype); 97181834Srobertostatic int getnfsquota(struct statfs *fst, struct quotause *qup, long id, 98181834Sroberto int quotatype); 99181834Srobertostatic int callaurpc(char *host, int prognum, int versnum, int procnum, 100290000Sglebius xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); 101181834Srobertostatic int alldigits(char *s); 102181834Sroberto 103181834Srobertostatic int hflag; 104181834Srobertostatic int lflag; 105181834Srobertostatic int rflag; 106181834Srobertostatic int qflag; 107181834Srobertostatic int vflag; 108181834Srobertostatic char *filename = NULL; 109181834Sroberto 110181834Srobertoint 111181834Srobertomain(int argc, char *argv[]) 112181834Sroberto{ 113290000Sglebius int ngroups; 114181834Sroberto gid_t mygid, gidset[NGROUPS]; 115181834Sroberto int i, ch, gflag = 0, uflag = 0, errflag = 0; 116181834Sroberto 117181834Sroberto while ((ch = getopt(argc, argv, "f:ghlrquv")) != -1) { 118290000Sglebius switch(ch) { 119181834Sroberto case 'f': 120181834Sroberto filename = optarg; 121181834Sroberto break; 122181834Sroberto case 'g': 123181834Sroberto gflag++; 124181834Sroberto break; 125181834Sroberto case 'h': 126181834Sroberto hflag++; 127181834Sroberto break; 128181834Sroberto case 'l': 129181834Sroberto lflag++; 130290000Sglebius break; 131290000Sglebius case 'q': 132290000Sglebius qflag++; 133181834Sroberto break; 134181834Sroberto case 'r': 135181834Sroberto rflag++; 136181834Sroberto break; 137290000Sglebius case 'u': 138181834Sroberto uflag++; 139181834Sroberto break; 140181834Sroberto case 'v': 141181834Sroberto vflag++; 142181834Sroberto break; 143181834Sroberto default: 144290000Sglebius usage(); 145181834Sroberto } 146181834Sroberto } 147181834Sroberto argc -= optind; 148181834Sroberto argv += optind; 149181834Sroberto if (!uflag && !gflag) 150181834Sroberto uflag++; 151181834Sroberto if (argc == 0) { 152181834Sroberto if (uflag) 153181834Sroberto errflag += showuid(getuid()); 154290000Sglebius if (gflag) { 155181834Sroberto mygid = getgid(); 156181834Sroberto ngroups = getgroups(NGROUPS, gidset); 157181834Sroberto if (ngroups < 0) 158181834Sroberto err(1, "getgroups"); 159181834Sroberto errflag += showgid(mygid); 160181834Sroberto for (i = 0; i < ngroups; i++) 161181834Sroberto if (gidset[i] != mygid) 162181834Sroberto errflag += showgid(gidset[i]); 163181834Sroberto } 164290000Sglebius return(errflag); 165290000Sglebius } 166290000Sglebius if (uflag && gflag) 167290000Sglebius usage(); 168290000Sglebius if (uflag) { 169290000Sglebius for (; argc > 0; argc--, argv++) { 170181834Sroberto if (alldigits(*argv)) 171181834Sroberto errflag += showuid(atoi(*argv)); 172181834Sroberto else 173181834Sroberto errflag += showusrname(*argv); 174181834Sroberto } 175181834Sroberto return(errflag); 176181834Sroberto } 177181834Sroberto if (gflag) { 178181834Sroberto for (; argc > 0; argc--, argv++) { 179181834Sroberto if (alldigits(*argv)) 180290000Sglebius errflag += showgid(atoi(*argv)); 181181834Sroberto else 182290000Sglebius errflag += showgrpname(*argv); 183181834Sroberto } 184181834Sroberto } 185181834Sroberto return(errflag); 186181834Sroberto} 187181834Sroberto 188181834Srobertostatic void 189290000Sglebiususage(void) 190181834Sroberto{ 191181834Sroberto 192181834Sroberto fprintf(stderr, "%s\n%s\n%s\n", 193181834Sroberto "usage: quota [-ghlu] [-f path] [-v | -q | -r]", 194290000Sglebius " quota [-hlu] [-f path] [-v | -q | -r] user ...", 195181834Sroberto " quota -g [-hl] [-f path] [-v | -q | -r] group ..."); 196181834Sroberto exit(1); 197181834Sroberto} 198181834Sroberto 199181834Sroberto/* 200181834Sroberto * Print out quotas for a specified user identifier. 201181834Sroberto */ 202290000Sglebiusstatic int 203181834Srobertoshowuid(u_long uid) 204181834Sroberto{ 205181834Sroberto struct passwd *pwd = getpwuid(uid); 206181834Sroberto const char *name; 207181834Sroberto 208181834Sroberto if (pwd == NULL) 209290000Sglebius name = "(no account)"; 210290000Sglebius else 211181834Sroberto name = pwd->pw_name; 212181834Sroberto return(showquotas(USRQUOTA, uid, name)); 213290000Sglebius} 214181834Sroberto 215181834Sroberto/* 216181834Sroberto * Print out quotas for a specifed user name. 217181834Sroberto */ 218181834Srobertostatic int 219181834Srobertoshowusrname(char *name) 220181834Sroberto{ 221181834Sroberto struct passwd *pwd = getpwnam(name); 222181834Sroberto 223181834Sroberto if (pwd == NULL) { 224181834Sroberto warnx("%s: unknown user", name); 225181834Sroberto return(1); 226181834Sroberto } 227290000Sglebius return(showquotas(USRQUOTA, pwd->pw_uid, name)); 228290000Sglebius} 229181834Sroberto 230181834Sroberto/* 231181834Sroberto * Print out quotas for a specified group identifier. 232181834Sroberto */ 233181834Srobertostatic int 234290000Sglebiusshowgid(u_long gid) 235181834Sroberto{ 236181834Sroberto struct group *grp = getgrgid(gid); 237181834Sroberto const char *name; 238290000Sglebius 239181834Sroberto if (grp == NULL) 240181834Sroberto name = "(no entry)"; 241290000Sglebius else 242290000Sglebius name = grp->gr_name; 243290000Sglebius return(showquotas(GRPQUOTA, gid, name)); 244290000Sglebius} 245290000Sglebius 246290000Sglebius/* 247290000Sglebius * Print out quotas for a specifed group name. 248290000Sglebius */ 249290000Sglebiusstatic int 250290000Sglebiusshowgrpname(char *name) 251290000Sglebius{ 252290000Sglebius struct group *grp = getgrnam(name); 253290000Sglebius 254290000Sglebius if (grp == NULL) { 255290000Sglebius warnx("%s: unknown group", name); 256290000Sglebius return(1); 257290000Sglebius } 258290000Sglebius return(showquotas(GRPQUOTA, grp->gr_gid, name)); 259181834Sroberto} 260290000Sglebius 261290000Sglebiusstatic void 262181834Srobertoprthumanval(int len, u_int64_t bytes) 263181834Sroberto{ 264181834Sroberto char buf[len + 1]; 265181834Sroberto 266181834Sroberto /* 267181834Sroberto * Limit the width to 5 bytes as that is what users expect. 268 */ 269 humanize_number(buf, sizeof(buf) < 5 ? sizeof(buf) : 5, bytes, "", 270 HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); 271 272 (void)printf(" %*s", len, buf); 273} 274 275static int 276showquotas(int type, u_long id, const char *name) 277{ 278 struct quotause *qup; 279 struct quotause *quplist; 280 const char *msgi, *msgb; 281 const char *nam; 282 char *bgrace = NULL, *igrace = NULL; 283 int lines = 0, overquota = 0; 284 static time_t now; 285 286 if (now == 0) 287 time(&now); 288 quplist = getprivs(id, type); 289 for (qup = quplist; qup; qup = qup->next) { 290 msgi = NULL; 291 if (qup->dqblk.dqb_ihardlimit && 292 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) { 293 overquota++; 294 msgi = "File limit reached on"; 295 } 296 else if (qup->dqblk.dqb_isoftlimit && 297 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) { 298 overquota++; 299 if (qup->dqblk.dqb_itime > now) 300 msgi = "In file grace period on"; 301 else 302 msgi = "Over file quota on"; 303 } 304 msgb = NULL; 305 if (qup->dqblk.dqb_bhardlimit && 306 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) { 307 overquota++; 308 msgb = "Block limit reached on"; 309 } 310 else if (qup->dqblk.dqb_bsoftlimit && 311 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) { 312 overquota++; 313 if (qup->dqblk.dqb_btime > now) 314 msgb = "In block grace period on"; 315 else 316 msgb = "Over block quota on"; 317 } 318 if (rflag) { 319 showrawquotas(type, id, qup); 320 continue; 321 } 322 if (!vflag && 323 qup->dqblk.dqb_isoftlimit == 0 && 324 qup->dqblk.dqb_ihardlimit == 0 && 325 qup->dqblk.dqb_bsoftlimit == 0 && 326 qup->dqblk.dqb_bhardlimit == 0) 327 continue; 328 if (qflag) { 329 if ((msgi != NULL || msgb != NULL) && 330 lines++ == 0) 331 heading(type, id, name, ""); 332 if (msgi != NULL) 333 printf("\t%s %s\n", msgi, qup->fsname); 334 if (msgb != NULL) 335 printf("\t%s %s\n", msgb, qup->fsname); 336 continue; 337 } 338 if (!vflag && 339 qup->dqblk.dqb_curblocks == 0 && 340 qup->dqblk.dqb_curinodes == 0) 341 continue; 342 if (lines++ == 0) 343 heading(type, id, name, ""); 344 nam = qup->fsname; 345 if (strlen(qup->fsname) > 15) { 346 printf("%s\n", qup->fsname); 347 nam = ""; 348 } 349 printf("%-15s", nam); 350 if (hflag) { 351 prthumanval(7, dbtob(qup->dqblk.dqb_curblocks)); 352 printf("%c", (msgb == NULL) ? ' ' : '*'); 353 prthumanval(7, dbtob(qup->dqblk.dqb_bsoftlimit)); 354 prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit)); 355 } else { 356 printf(" %7ju%c %7ju %7ju", 357 (uintmax_t)dbtob(qup->dqblk.dqb_curblocks) 358 / 1024, 359 (msgb == NULL) ? ' ' : '*', 360 (uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit) 361 / 1024, 362 (uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit) 363 / 1024); 364 } 365 if (msgb != NULL) 366 bgrace = timeprt(qup->dqblk.dqb_btime); 367 if (msgi != NULL) 368 igrace = timeprt(qup->dqblk.dqb_itime); 369 printf("%8s %6ju%c %6ju %6ju%8s\n" 370 , (msgb == NULL) ? "" : bgrace 371 , (uintmax_t)qup->dqblk.dqb_curinodes 372 , (msgi == NULL) ? ' ' : '*' 373 , (uintmax_t)qup->dqblk.dqb_isoftlimit 374 , (uintmax_t)qup->dqblk.dqb_ihardlimit 375 , (msgi == NULL) ? "" : igrace 376 ); 377 if (msgb != NULL) 378 free(bgrace); 379 if (msgi != NULL) 380 free(igrace); 381 } 382 if (!qflag && !rflag && lines == 0) 383 heading(type, id, name, "none"); 384 return (overquota); 385} 386 387static void 388showrawquotas(int type, u_long id, struct quotause *qup) 389{ 390 time_t t; 391 392 printf("Raw %s quota information for id %lu on %s\n", 393 type == USRQUOTA ? "user" : "group", id, qup->fsname); 394 printf("block hard limit: %ju\n", 395 (uintmax_t)qup->dqblk.dqb_bhardlimit); 396 printf("block soft limit: %ju\n", 397 (uintmax_t)qup->dqblk.dqb_bsoftlimit); 398 printf("current block count: %ju\n", 399 (uintmax_t)qup->dqblk.dqb_curblocks); 400 printf("i-node hard limit: %ju\n", 401 (uintmax_t)qup->dqblk.dqb_ihardlimit); 402 printf("i-node soft limit: %ju\n", 403 (uintmax_t)qup->dqblk.dqb_isoftlimit); 404 printf("current i-node count: %ju\n", 405 (uintmax_t)qup->dqblk.dqb_curinodes); 406 printf("block grace time: %jd", 407 (intmax_t)qup->dqblk.dqb_btime); 408 if (qup->dqblk.dqb_btime != 0) { 409 t = qup->dqblk.dqb_btime; 410 printf(" %s", ctime(&t)); 411 } else { 412 printf("\n"); 413 } 414 printf("i-node grace time: %jd", (intmax_t)qup->dqblk.dqb_itime); 415 if (qup->dqblk.dqb_itime != 0) { 416 t = qup->dqblk.dqb_itime; 417 printf(" %s", ctime(&t)); 418 } else { 419 printf("\n"); 420 } 421} 422 423 424static void 425heading(int type, u_long id, const char *name, const char *tag) 426{ 427 428 printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type], 429 name, *qfextension[type], id, tag); 430 if (!qflag && tag[0] == '\0') { 431 printf("%-15s %7s %8s %7s %7s %6s %7s %6s%8s\n" 432 , "Filesystem" 433 , "usage" 434 , "quota" 435 , "limit" 436 , "grace" 437 , "files" 438 , "quota" 439 , "limit" 440 , "grace" 441 ); 442 } 443} 444 445/* 446 * Calculate the grace period and return a printable string for it. 447 */ 448static char * 449timeprt(int64_t seconds) 450{ 451 time_t hours, minutes; 452 char *buf; 453 static time_t now; 454 455 if (now == 0) 456 time(&now); 457 if (now > seconds) { 458 if ((buf = strdup("none")) == NULL) 459 errx(1, "strdup() failed in timeprt()"); 460 return (buf); 461 } 462 seconds -= now; 463 minutes = (seconds + 30) / 60; 464 hours = (minutes + 30) / 60; 465 if (hours >= 36) { 466 if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0) 467 errx(1, "asprintf() failed in timeprt(1)"); 468 return (buf); 469 } 470 if (minutes >= 60) { 471 if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60, 472 (long)minutes % 60) < 0) 473 errx(1, "asprintf() failed in timeprt(2)"); 474 return (buf); 475 } 476 if (asprintf(&buf, "%2ld", (long)minutes) < 0) 477 errx(1, "asprintf() failed in timeprt(3)"); 478 return (buf); 479} 480 481/* 482 * Collect the requested quota information. 483 */ 484static struct quotause * 485getprivs(long id, int quotatype) 486{ 487 struct quotause *qup, *quptail = NULL; 488 struct fstab *fs; 489 struct quotause *quphead; 490 struct statfs *fst; 491 int nfst, i; 492 struct statfs sfb; 493 494 qup = quphead = (struct quotause *)0; 495 496 if (filename != NULL && statfs(filename, &sfb) != 0) 497 err(1, "cannot statfs %s", filename); 498 nfst = getmntinfo(&fst, MNT_NOWAIT); 499 if (nfst == 0) 500 errx(2, "no filesystems mounted!"); 501 setfsent(); 502 for (i = 0; i < nfst; i++) { 503 if (qup == NULL) { 504 if ((qup = (struct quotause *)malloc(sizeof *qup)) 505 == NULL) 506 errx(2, "out of memory"); 507 } 508 /* 509 * See if the user requested a specific file system 510 * or specified a file inside a mounted file system. 511 */ 512 if (filename != NULL && 513 strcmp(sfb.f_mntonname, fst[i].f_mntonname) != 0) 514 continue; 515 if (strcmp(fst[i].f_fstypename, "nfs") == 0) { 516 if (lflag) 517 continue; 518 if (getnfsquota(&fst[i], qup, id, quotatype) == 0) 519 continue; 520 } else if (strcmp(fst[i].f_fstypename, "ufs") == 0) { 521 /* 522 * XXX 523 * UFS filesystems must be in /etc/fstab, and must 524 * indicate that they have quotas on (?!) This is quite 525 * unlike SunOS where quotas can be enabled/disabled 526 * on a filesystem independent of /etc/fstab, and it 527 * will still print quotas for them. 528 */ 529 if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL) 530 continue; 531 if (getufsquota(fs, qup, id, quotatype) == 0) 532 continue; 533 } else 534 continue; 535 strcpy(qup->fsname, fst[i].f_mntonname); 536 if (quphead == NULL) 537 quphead = qup; 538 else 539 quptail->next = qup; 540 quptail = qup; 541 quptail->next = 0; 542 qup = NULL; 543 } 544 if (qup) 545 free(qup); 546 endfsent(); 547 return (quphead); 548} 549 550/* 551 * Check to see if a particular quota is available. 552 */ 553static int 554getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype) 555{ 556 struct quotafile *qf; 557 558 if ((qf = quota_open(fs, quotatype, O_RDONLY)) == NULL) 559 return (0); 560 if (quota_read(qf, &qup->dqblk, id) != 0) 561 return (0); 562 quota_close(qf); 563 return (1); 564} 565 566static int 567getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype) 568{ 569 struct getquota_args gq_args; 570 struct getquota_rslt gq_rslt; 571 struct dqblk *dqp = &qup->dqblk; 572 struct timeval tv; 573 char *cp; 574 575 if (fst->f_flags & MNT_LOCAL) 576 return (0); 577 578 /* 579 * rpc.rquotad does not support group quotas 580 */ 581 if (quotatype != USRQUOTA) 582 return (0); 583 584 /* 585 * must be some form of "hostname:/path" 586 */ 587 cp = strchr(fst->f_mntfromname, ':'); 588 if (cp == NULL) { 589 warnx("cannot find hostname for %s", fst->f_mntfromname); 590 return (0); 591 } 592 593 *cp = '\0'; 594 if (*(cp+1) != '/') { 595 *cp = ':'; 596 return (0); 597 } 598 599 /* Avoid attempting the RPC for special amd(8) filesystems. */ 600 if (strncmp(fst->f_mntfromname, "pid", 3) == 0 && 601 strchr(fst->f_mntfromname, '@') != NULL) { 602 *cp = ':'; 603 return (0); 604 } 605 606 gq_args.gqa_pathp = cp + 1; 607 gq_args.gqa_uid = id; 608 if (callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS, 609 RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args, 610 (xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) { 611 *cp = ':'; 612 return (0); 613 } 614 615 switch (gq_rslt.status) { 616 case Q_NOQUOTA: 617 break; 618 case Q_EPERM: 619 warnx("quota permission error, host: %s", 620 fst->f_mntfromname); 621 break; 622 case Q_OK: 623 gettimeofday(&tv, NULL); 624 /* blocks*/ 625 dqp->dqb_bhardlimit = 626 gq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit * 627 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 628 dqp->dqb_bsoftlimit = 629 gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit * 630 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 631 dqp->dqb_curblocks = 632 gq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks * 633 (gq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize / DEV_BSIZE); 634 /* inodes */ 635 dqp->dqb_ihardlimit = 636 gq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit; 637 dqp->dqb_isoftlimit = 638 gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit; 639 dqp->dqb_curinodes = 640 gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles; 641 /* grace times */ 642 dqp->dqb_btime = 643 tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft; 644 dqp->dqb_itime = 645 tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft; 646 *cp = ':'; 647 return (1); 648 default: 649 warnx("bad rpc result, host: %s", fst->f_mntfromname); 650 break; 651 } 652 *cp = ':'; 653 return (0); 654} 655 656static int 657callaurpc(char *host, int prognum, int versnum, int procnum, 658 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) 659{ 660 struct sockaddr_in server_addr; 661 enum clnt_stat clnt_stat; 662 struct hostent *hp; 663 struct timeval timeout, tottimeout; 664 665 CLIENT *client = NULL; 666 int sock = RPC_ANYSOCK; 667 668 if ((hp = gethostbyname(host)) == NULL) 669 return ((int) RPC_UNKNOWNHOST); 670 timeout.tv_usec = 0; 671 timeout.tv_sec = 6; 672 bcopy(hp->h_addr, &server_addr.sin_addr, 673 MIN(hp->h_length,(int)sizeof(server_addr.sin_addr))); 674 server_addr.sin_family = AF_INET; 675 server_addr.sin_port = 0; 676 677 if ((client = clntudp_create(&server_addr, prognum, 678 versnum, timeout, &sock)) == NULL) 679 return ((int) rpc_createerr.cf_stat); 680 681 client->cl_auth = authunix_create_default(); 682 tottimeout.tv_sec = 25; 683 tottimeout.tv_usec = 0; 684 clnt_stat = clnt_call(client, procnum, inproc, in, 685 outproc, out, tottimeout); 686 687 return ((int) clnt_stat); 688} 689 690static int 691alldigits(char *s) 692{ 693 int c; 694 695 c = *s++; 696 do { 697 if (!isdigit(c)) 698 return (0); 699 } while ((c = *s++)); 700 return (1); 701} 702