quota.c (227176) | quota.c (285253) |
---|---|
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 --- 30 unchanged lines hidden (view full) --- 39#ifndef lint 40static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93"; 41#endif /* not lint */ 42 43/* 44 * Disk quota reporting program. 45 */ 46#include <sys/cdefs.h> | 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 --- 30 unchanged lines hidden (view full) --- 39#ifndef lint 40static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93"; 41#endif /* not lint */ 42 43/* 44 * Disk quota reporting program. 45 */ 46#include <sys/cdefs.h> |
47__FBSDID("$FreeBSD: head/usr.bin/quota/quota.c 227176 2011-11-06 08:16:29Z ed $"); | 47__FBSDID("$FreeBSD: head/usr.bin/quota/quota.c 285253 2015-07-07 20:15:09Z hrs $"); |
48 49#include <sys/param.h> 50#include <sys/types.h> 51#include <sys/file.h> 52#include <sys/stat.h> 53#include <sys/mount.h> 54#include <sys/socket.h> 55 --- 509 unchanged lines hidden (view full) --- 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; | 48 49#include <sys/param.h> 50#include <sys/types.h> 51#include <sys/file.h> 52#include <sys/stat.h> 53#include <sys/mount.h> 54#include <sys/socket.h> 55 --- 509 unchanged lines hidden (view full) --- 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; | 573 char *cp, host[NI_MAXHOST]; |
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 */ | 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, ':'); | 587 cp = fst->f_mntfromname; 588 do { 589 cp = strrchr(cp, ':'); 590 } while (cp != NULL && *(cp + 1) != '/'); |
588 if (cp == NULL) { 589 warnx("cannot find hostname for %s", fst->f_mntfromname); 590 return (0); 591 } | 591 if (cp == NULL) { 592 warnx("cannot find hostname for %s", fst->f_mntfromname); 593 return (0); 594 } |
595 memset(host, 0, sizeof(host)); 596 memcpy(host, fst->f_mntfromname, cp - fst->f_mntfromname); 597 host[sizeof(host) - 1] = '\0'; |
|
592 | 598 |
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 && | 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 = ':'; | 601 strchr(fst->f_mntfromname, '@') != NULL) |
603 return (0); | 602 return (0); |
604 } | |
605 606 gq_args.gqa_pathp = cp + 1; 607 gq_args.gqa_uid = id; | 603 604 gq_args.gqa_pathp = cp + 1; 605 gq_args.gqa_uid = id; |
608 if (callaurpc(fst->f_mntfromname, RQUOTAPROG, RQUOTAVERS, | 606 if (callaurpc(host, RQUOTAPROG, RQUOTAVERS, |
609 RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args, | 607 RQUOTAPROC_GETQUOTA, (xdrproc_t)xdr_getquota_args, (char *)&gq_args, |
610 (xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) { 611 *cp = ':'; | 608 (xdrproc_t)xdr_getquota_rslt, (char *)&gq_rslt) != 0) |
612 return (0); | 609 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; --- 16 unchanged lines hidden (view full) --- 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; | 610 611 switch (gq_rslt.status) { 612 case Q_NOQUOTA: 613 break; 614 case Q_EPERM: 615 warnx("quota permission error, host: %s", 616 fst->f_mntfromname); 617 break; --- 16 unchanged lines hidden (view full) --- 634 gq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit; 635 dqp->dqb_curinodes = 636 gq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles; 637 /* grace times */ 638 dqp->dqb_btime = 639 tv.tv_sec + gq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft; 640 dqp->dqb_itime = 641 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 } | 642 return (1); 643 default: 644 warnx("bad rpc result, host: %s", fst->f_mntfromname); 645 break; 646 } |
652 *cp = ':'; | 647 |
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{ | 648 return (0); 649} 650 651static int 652callaurpc(char *host, int prognum, int versnum, int procnum, 653 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) 654{ |
660 struct sockaddr_in server_addr; | |
661 enum clnt_stat clnt_stat; | 655 enum clnt_stat clnt_stat; |
662 struct hostent *hp; | |
663 struct timeval timeout, tottimeout; 664 665 CLIENT *client = NULL; | 656 struct timeval timeout, tottimeout; 657 658 CLIENT *client = NULL; |
666 int sock = RPC_ANYSOCK; 667 668 if ((hp = gethostbyname(host)) == NULL) 669 return ((int) RPC_UNKNOWNHOST); | 659 660 client = clnt_create(host, prognum, versnum, "udp"); 661 if (client == NULL) 662 return ((int)rpc_createerr.cf_stat); |
670 timeout.tv_usec = 0; 671 timeout.tv_sec = 6; | 663 timeout.tv_usec = 0; 664 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; | 665 CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)(void *)&timeout); |
676 | 666 |
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} --- 13 unchanged lines hidden --- | 667 client->cl_auth = authunix_create_default(); 668 tottimeout.tv_sec = 25; 669 tottimeout.tv_usec = 0; 670 clnt_stat = clnt_call(client, procnum, inproc, in, 671 outproc, out, tottimeout); 672 673 return ((int) clnt_stat); 674} --- 13 unchanged lines hidden --- |