From 244fde00a9da55b4a55cc3c0944b28d28b90e597 Mon Sep 17 00:00:00 2001 From: Nathan Neulinger Date: Tue, 3 Jun 2003 05:31:08 +0000 Subject: [PATCH] afsd-check-for-bad-partition-type-20030602 FIXES 1455 disallow cache directory of types we know cause problems ==================== This delta was composed from multiple commits as part of the CVS->Git migration. The checkin message with each commit was inconsistent. The following are the additional commit messages. ==================== FIXES 1542 typo --- acinclude.m4 | 2 +- src/afsd/afsd.c | 125 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 97 insertions(+), 30 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index be836393e..de72cac9c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -752,7 +752,7 @@ AC_HEADER_SYS_WAIT AC_HEADER_DIRENT AC_CHECK_HEADERS(stdlib.h string.h unistd.h fcntl.h sys/time.h sys/file.h) AC_CHECK_HEADERS(netinet/in.h netdb.h sys/fcntl.h sys/mnttab.h sys/mntent.h) -AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h) +AC_CHECK_HEADERS(mntent.h sys/vfs.h sys/param.h sys/fs_types.h sys/fstyp.h) AC_CHECK_HEADERS(sys/mount.h strings.h termios.h signal.h) AC_CHECK_HEADERS(windows.h malloc.h winsock2.h direct.h io.h) AC_CHECK_HEADERS(security/pam_modules.h siad.h usersec.h ucontext.h) diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 85ae976d7..af5773b49 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -113,6 +113,10 @@ RCSID("$Header$"); #include #endif +#ifdef HAVE_SYS_FSTYP_H +#include +#endif + #ifdef HAVE_UNISTD_H #include #endif @@ -993,6 +997,95 @@ static int doSweepAFSCache(vFilesFound,directory,dirNum,maxDir) return(0); } +char *CheckCacheBaseDir(char *dir) +{ + struct stat statbuf; + + if ( !dir ) { return "cache base dir not specified"; } + if ( stat(dir, &statbuf) != 0 ) { + return "unable to stat cache base directory"; + } + + /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */ + +#ifdef AFS_LINUX24_ENV + { + int res; + struct statfs statfsbuf; + + res = statfs(dir, &statfsbuf); + if ( res != 0 ) { + return "unable to statfs cache base directory"; + } + if ( statfsbuf.f_type == 0x52654973 ) /* REISERFS_SUPER_MAGIC */ + { + return "cannot use reiserfs as cache partition"; + } + } +#endif + +#ifdef AFS_HPUX_ENV + { + int res; + struct statfs statfsbuf; + char name[FSTYPSZ]; + + res = statfs(dir, &statfsbuf); + if ( res != 0 ) + { + return "unable to statfs cache base directory"; + } + + if (sysfs(GETFSTYP, statfsbuf.f_fsid, name) != 0 ) + { + return "unable to determine filesystem type for cache base dir"; + } + + if ( strcmp(name, "hfs") ) + { + return "can only use hfs filesystem for cache partition on hpux"; + } + } +#endif + +#ifdef AFS_SUN5_ENV + { + FILE *vfstab; + struct mnttab mnt; + struct stat statmnt, statci; + + if ((stat(dir, &statci) == 0) && + ((vfstab = fopen(MNTTAB, "r")) != NULL)) + { + while (getmntent(vfstab, &mnt) == 0) { + if (strcmp(dir, mnt.mnt_mountp) != 0) + { + char *cp; + int rdev = 0; + + if (cp = hasmntopt(&mnt, "dev=")) + rdev=(int)strtol(cp+strlen("dev="), (char **)NULL, 16); + + if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0)) + rdev=statmnt.st_dev; + + if ((rdev == statci.st_dev) && + (hasmntopt (&mnt, "logging") != NULL)) { + + fclose(vfstab); + return "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n"; + } + } + } + + fclose(vfstab); + } + } +#endif + + return NULL; +} + int SweepAFSCache(vFilesFound) int *vFilesFound; { @@ -1176,6 +1269,7 @@ mainproc(as, arock) int vFilesFound; /*How many data cache files were found in sweep*/ struct afsconf_dir *cdir; /* config dir */ FILE *logfd; + char *fsTypeMsg = NULL; #ifdef AFS_SUN5_ENV struct stat st; #endif @@ -1497,36 +1591,9 @@ mainproc(as, arock) sprintf(fullpn_VFile, "%s/", cacheBaseDir); vFilePtr = fullpn_VFile + strlen(fullpn_VFile); -#ifdef AFS_SUN5_ENV - { - FILE *vfstab; - struct mnttab mnt; - struct stat statmnt, statci; - - if ((stat(cacheBaseDir, &statci) == 0) && - ((vfstab = fopen(MNTTAB, "r")) != NULL)) { - while (getmntent(vfstab, &mnt) == 0) { - if (strcmp(cacheBaseDir, mnt.mnt_mountp) != 0) { - char *cp; - int rdev = 0; - - if (cp = hasmntopt(&mnt, "dev=")) - rdev=(int)strtol(cp+strlen("dev="), (char **)NULL, 16); - - if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0)) - rdev=statmnt.st_dev; - - if ((rdev == statci.st_dev) && - (hasmntopt (&mnt, "logging") != NULL)) { - printf("WARNING: Mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n"); - fflush(stdout); - } - } - } - fclose(vfstab); - } + if ((fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) { + printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg); } -#endif #if 0 fputs(AFS_GOVERNMENT_MESSAGE, stdout); -- 2.39.5