diff options
author | mpp <mpp@FreeBSD.org> | 2007-02-04 06:33:15 +0000 |
---|---|---|
committer | mpp <mpp@FreeBSD.org> | 2007-02-04 06:33:15 +0000 |
commit | 2088a69616fcc7d02d198087f76856402c7063c4 (patch) | |
tree | 12409a8c0f64e04f52020f1914b5612c3779d48e | |
parent | 25c9a05e1c0e7a7da4d9d9c787ab9b29d7449ae9 (diff) | |
download | FreeBSD-src-2088a69616fcc7d02d198087f76856402c7063c4.zip FreeBSD-src-2088a69616fcc7d02d198087f76856402c7063c4.tar.gz |
If two files systems, /a and /b are marked as having quotas enabled
in fstab and they are normally mounted as /a/b, if /b is not mounted,
the various quota utilities will incorrectly operate with the quotas on
/a (silently) when operations are attemted on /b.
Sync up all the hasquota() routines between all the different
quota utilities and change it to detect if the file system we are
attempting to perform quota operations on is not currently mounted
and warn the user accordingly.
PR: bin/38918
-rw-r--r-- | sbin/quotacheck/quotacheck.c | 23 | ||||
-rw-r--r-- | usr.bin/quota/quota.c | 28 | ||||
-rw-r--r-- | usr.sbin/edquota/edquota.c | 31 | ||||
-rw-r--r-- | usr.sbin/quotaon/quotaon.c | 29 | ||||
-rw-r--r-- | usr.sbin/repquota/repquota.c | 30 |
5 files changed, 104 insertions, 37 deletions
diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index 90d8954..02ee25d 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); */ #include <sys/param.h> #include <sys/disklabel.h> +#include <sys/mount.h> #include <sys/stat.h> #include <ufs/ufs/dinode.h> @@ -587,14 +588,15 @@ hasquota(fs, type, qfnamep) { char *opt; char *cp; + struct statfs sfb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { - (void)snprintf(usrname, sizeof(usrname), - "%s%s", qfextension[USRQUOTA], qfname); - (void)snprintf(grpname, sizeof(grpname), - "%s%s", qfextension[GRPQUOTA], qfname); + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], qfname); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); @@ -611,10 +613,19 @@ hasquota(fs, type, qfnamep) if (cp) *qfnamep = cp; else { - (void)snprintf(buf, sizeof(buf), - "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + qfname, qfextension[type]); *qfnamep = buf; } + if (statfs(fs->fs_file, &sfb) != 0) { + warn("cannot statfs mount point %s", fs->fs_file); + return (0); + } + if (strcmp(fs->fs_file, sfb.f_mntonname)) { + warnx("%s not mounted for %s quotas", fs->fs_file, + type == USRQUOTA ? "user" : "group"); + return (0); + } return (1); } diff --git a/usr.bin/quota/quota.c b/usr.bin/quota/quota.c index c97fec5..6ddd7aa 100644 --- a/usr.bin/quota/quota.c +++ b/usr.bin/quota/quota.c @@ -483,13 +483,17 @@ getprivs(long id, int quotatype) static int ufshasquota(struct fstab *fs, int type, char **qfnamep) { + char *opt; + char *cp; + struct statfs sfb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; - char *opt, *cp; if (!initname) { - sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); - sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], qfname); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); @@ -503,12 +507,22 @@ ufshasquota(struct fstab *fs, int type, char **qfnamep) } if (!opt) return (0); - if (cp) { + if (cp) *qfnamep = cp; - return (1); + else { + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + qfname, qfextension[type]); + *qfnamep = buf; + } + if (statfs(fs->fs_file, &sfb) != 0) { + warn("cannot statfs mount point %s", fs->fs_file); + return (0); + } + if (strcmp(fs->fs_file, sfb.f_mntonname)) { + warnx("%s not mounted for %s quotas", fs->fs_file, + type == USRQUOTA ? "user" : "group"); + return (0); } - (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); - *qfnamep = buf; return (1); } diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c index a333314..83de530 100644 --- a/usr.sbin/edquota/edquota.c +++ b/usr.sbin/edquota/edquota.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/stat.h> #include <sys/file.h> +#include <sys/mount.h> #include <sys/wait.h> #include <ufs/ufs/quota.h> #include <ctype.h> @@ -869,18 +870,21 @@ alldigits(s) */ int hasquota(fs, type, qfnamep) - register struct fstab *fs; + struct fstab *fs; int type; char **qfnamep; { - register char *opt; + char *opt; char *cp; + struct statfs sfb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { - sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); - sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], qfname); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); @@ -894,11 +898,22 @@ hasquota(fs, type, qfnamep) } if (!opt) return (0); - if (cp) { + if (cp) *qfnamep = cp; - return (1); + else { + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + qfname, qfextension[type]); + *qfnamep = buf; + } + if (statfs(fs->fs_file, &sfb) != 0) { + warn("cannot statfs mount point %s", fs->fs_file); + return (0); + } + if (strcmp(fs->fs_file, sfb.f_mntonname)) { + warnx("%s not mounted for %s quotas", fs->fs_file, + type == USRQUOTA ? "user" : "group"); + sleep(3); + return (0); } - (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); - *qfnamep = buf; return (1); } diff --git a/usr.sbin/quotaon/quotaon.c b/usr.sbin/quotaon/quotaon.c index 7d0ec7f..03df4e2 100644 --- a/usr.sbin/quotaon/quotaon.c +++ b/usr.sbin/quotaon/quotaon.c @@ -203,18 +203,21 @@ oneof(target, list, cnt) */ int hasquota(fs, type, qfnamep) - register struct fstab *fs; + struct fstab *fs; int type; char **qfnamep; { - register char *opt; + char *opt; char *cp; + struct statfs sfb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { - sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); - sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], qfname); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); @@ -228,12 +231,22 @@ hasquota(fs, type, qfnamep) } if (!opt) return (0); - if (cp) { + if (cp) *qfnamep = cp; - return (1); + else { + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + qfname, qfextension[type]); + *qfnamep = buf; + } + if (statfs(fs->fs_file, &sfb) != 0) { + warn("cannot statfs mount point %s", fs->fs_file); + return (0); + } + if (strcmp(fs->fs_file, sfb.f_mntonname)) { + warnx("%s not mounted for %s quotas", fs->fs_file, + type == USRQUOTA ? "user" : "group"); + return (0); } - (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); - *qfnamep = buf; return (1); } diff --git a/usr.sbin/repquota/repquota.c b/usr.sbin/repquota/repquota.c index f497953..8399377 100644 --- a/usr.sbin/repquota/repquota.c +++ b/usr.sbin/repquota/repquota.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); * Quota report */ #include <sys/param.h> +#include <sys/mount.h> #include <ufs/ufs/quota.h> #include <err.h> #include <errno.h> @@ -288,18 +289,21 @@ oneof(target, list, cnt) */ int hasquota(fs, type, qfnamep) - register struct fstab *fs; + struct fstab *fs; int type; char **qfnamep; { - register char *opt; + char *opt; char *cp; + struct statfs sfb; static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { - sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); - sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); + (void)snprintf(usrname, sizeof(usrname), "%s%s", + qfextension[USRQUOTA], qfname); + (void)snprintf(grpname, sizeof(grpname), "%s%s", + qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); @@ -313,12 +317,22 @@ hasquota(fs, type, qfnamep) } if (!opt) return (0); - if (cp) { + if (cp) *qfnamep = cp; - return (1); + else { + (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file, + qfname, qfextension[type]); + *qfnamep = buf; + } + if (statfs(fs->fs_file, &sfb) != 0) { + warn("cannot statfs mount point %s", fs->fs_file); + return (0); + } + if (strcmp(fs->fs_file, sfb.f_mntonname)) { + warnx("%s not mounted for %s quotas", fs->fs_file, + type == USRQUOTA ? "user" : "group"); + return (0); } - (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); - *qfnamep = buf; return (1); } |