From 253b4b3fe51635572e2a3ed20d71a5adadef9212 Mon Sep 17 00:00:00 2001 From: Thomas Veerman Date: Mon, 2 Aug 2010 11:16:32 +0000 Subject: [PATCH] - Add support for ST_NOTRUNC to struct statvfs. - Let tests that test for long file names check for that flag, so that they can verify the results properly. --- include/sys/statvfs.h | 8 +++-- man/man5/statvfs.5 | 2 ++ servers/hgfs/misc.c | 1 + test/common.c | 24 ++++++++++++++- test/test23.c | 64 +++++++-------------------------------- test/test24.c | 57 +++++++---------------------------- test/test25.c | 58 +++++++++++------------------------ test/test28.c | 67 +++++++++++++---------------------------- test/test30.c | 65 ++++++++++------------------------------ test/test31.c | 61 ++++++++----------------------------- test/test33.c | 70 +++++++++++++------------------------------ test/test34.c | 67 +++++++++++------------------------------ test/test35.c | 64 ++++++++------------------------------- 13 files changed, 170 insertions(+), 438 deletions(-) diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h index 79eee2932..dfeedaf64 100644 --- a/include/sys/statvfs.h +++ b/include/sys/statvfs.h @@ -30,6 +30,10 @@ _PROTOTYPE( int fstatvfs, (int fd, struct statvfs *st) ); _PROTOTYPE( int statvfs, (const char *path, struct statvfs *st)); /* Possible values for statvfs->f_flag */ -#define ST_RDONLY 0x1 -#define ST_NOSUID 0x2 +#define ST_RDONLY 0x001 /* Read-only file system */ +#define ST_NOSUID 0x002 /* Does not support the semantics of the + * ST_ISUID and ST_ISGID file mode bits. */ +#define ST_NOTRUNC 0x004 /* File system does not truncate file names + * longer than NAME_MAX */ + #endif /* _STAVTFS_H */ diff --git a/man/man5/statvfs.5 b/man/man5/statvfs.5 index ff112a4be..0f1ee9d29 100644 --- a/man/man5/statvfs.5 +++ b/man/man5/statvfs.5 @@ -77,6 +77,8 @@ The filesystem is mounted read-only; Even the super-user may not write on it. .It Dv ST_NOSUID Setuid and setgid bits on files are not honored when they are executed. +.It Dv ST_NOTRUNC +File names longer than NAME_MAX are not truncated. .El .Sh SEE ALSO .Xr statvfs 2 diff --git a/servers/hgfs/misc.c b/servers/hgfs/misc.c index 9de3c440e..0cb80566c 100644 --- a/servers/hgfs/misc.c +++ b/servers/hgfs/misc.c @@ -72,6 +72,7 @@ PUBLIC int do_statvfs() statvfs.f_favail = 0; statvfs.f_fsid = state.dev; statvfs.f_flag = state.read_only ? ST_RDONLY : 0; + statvfs.f_flag |= ST_NOTRUNC; statvfs.f_namemax = NAME_MAX; return sys_safecopyto(m_in.m_source, m_in.REQ_GRANT, 0, diff --git a/test/common.c b/test/common.c index 12fb34a0b..5aa66fa93 100644 --- a/test/common.c +++ b/test/common.c @@ -8,10 +8,12 @@ #include #include #include +#include int common_test_nr = -1, errct = 0, subtest; _PROTOTYPE(void cleanup, (void)); +_PROTOTYPE(int does_fs_truncate, (void)); _PROTOTYPE(void e, (int n)); _PROTOTYPE(void quit, (void)); _PROTOTYPE(void rm_rf_dir, (int test_nr)); @@ -40,6 +42,24 @@ int test_nr; } } +int does_fs_truncate(void) +{ + struct statvfs stvfs; + int does_truncate = 0; + char cwd[PATH_MAX]; /* Storage for path to current working dir */ + + if (realpath(".", cwd) == NULL) e(7777); /* Get current working dir */ + if (statvfs(cwd, &stvfs) != 0) e(7778); /* Get FS information */ + /* Depending on how an FS handles too long file names, we have to adjust our + * error checking. If an FS does not truncate file names, it should generate + * an ENAMETOOLONG error when we provide too long a file name. + */ + if (!(stvfs.f_flag & ST_NOTRUNC)) does_truncate = 1; + + return(does_truncate); +} + + void rm_rf_dir(test_nr) int test_nr; { @@ -74,6 +94,8 @@ int test_nr; void e(n) int n; { + int err_number; + err_number = errno; /* Store before printf can clobber it */ if (errct == 0) printf("\n"); /* finish header */ printf("Subtest %d, error %d, errno %d: %s\n", subtest, n, errno, strerror(errno)); @@ -82,7 +104,7 @@ int n; cleanup(); exit(1); } - errno = 0; /* don't leave it around to confuse next e() */ + errno = err_number; } void cleanup() diff --git a/test/test23.c b/test/test23.c index 05c5bfdb3..1b2bbbcd4 100644 --- a/test/test23.c +++ b/test/test23.c @@ -14,10 +14,11 @@ #define MAX_ERROR 4 #define ITERATIONS 3 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) -int errct; int subtest; int superuser; /* True if we are root. */ @@ -35,8 +36,6 @@ _PROTOTYPE(void test23c, (void)); _PROTOTYPE(void makelongnames, (void)); /* Fill MaxName etc. */ _PROTOTYPE(char *last_index, (char *string, int ch)); _PROTOTYPE(char *my_getcwd, (char *buf, int size)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); int main(int argc, char *argv[]) { @@ -44,10 +43,7 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 23 "); - fflush(stdout); - System("rm -rf DIR_23; mkdir DIR_23"); - Chdir("DIR_23"); + start(23); makelongnames(); superuser = (geteuid() == 0); @@ -129,19 +125,12 @@ void test23a() if (chdir(".//.//") != 0) e(39); /* .//.// == current dir */ if (getcwd(buf, PATH_MAX) != buf) e(40); if (strcmp(buf, cwd) != 0) e(41); /* we might be at '/' */ -#ifdef _MINIX - /* XXX - my_getcwd() is old rubbish. It reads the directory directly instead - * of through the directory library. It uses a fixed size buffer instead of - * a size related to PATH_MAX, NAME_MAX or the size required. - */ - if (my_getcwd(buf, PATH_MAX) != buf) e(42); /* get cwd my way */ - if (strcmp(cwd, buf) != 0) e(43); -#endif System("rm -rf foo"); } void test23b() { /* Test critical values. */ + int does_truncate; subtest = 2; System("rm -rf ../DIR_23/*"); @@ -168,16 +157,13 @@ void test23b() if (getcwd(buf, PATH_MAX) != buf) e(16); if (strcmp(buf, cwd) != 0) e(17); + does_truncate = does_fs_truncate(); if (chdir(ToLongName) != -1) e(18); -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - if (errno != ENAMETOOLONG) e(20); -# else - if (errno != ENOENT) e(20); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + if (does_truncate) { + if (errno != ENOENT) e(19); + } else { + if (errno != ENAMETOOLONG) e(20); + } if (getcwd(buf, PATH_MAX) != buf) e(21); if (strcmp(buf, cwd) != 0) e(22); @@ -381,33 +367,3 @@ int size; return buf; } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_23"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test24.c b/test/test24.c index 411b80990..44546a906 100644 --- a/test/test24.c +++ b/test/test24.c @@ -18,18 +18,17 @@ _PROTOTYPE(void test24a, (void)); _PROTOTYPE(void test24b, (void)); _PROTOTYPE(void test24c, (void)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); #define OVERFLOW_DIR_NR (OPEN_MAX + 1) #define MAX_ERROR 4 #define ITERATIONS 5 +#include "common.c" + #define DIRENT0 ((struct dirent *) NULL) #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) -int errct = 0; int subtest = 1; int superuser; @@ -245,6 +244,7 @@ void test24c() /* Test whether wrong things go wrong right. */ DIR *dirp; + int does_truncate; subtest = 3; @@ -273,20 +273,15 @@ void test24c() if (rmdir(MaxName) != 0) e(12); /* then remove it */ if ((dirp = opendir(MaxPath)) == ((DIR *) NULL)) e(13); /* open '.' */ if (closedir(dirp) != 0) e(14); /* close it */ -#if 0 /* XXX - anything could happen with the bad pointer */ - if (closedir(dirp) != -1) e(15); /* close it again */ - if (closedir(dirp) != -1) e(16); /* and again */ -#endif /* 0 */ + + does_truncate = does_fs_truncate(); if (opendir(ToLongName) != ((DIR *) NULL)) e(17); /* is too long */ -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - if (errno != ENAMETOOLONG) e(18); -# else - if (errno != ENOENT) e(19); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + if (does_truncate) { + if (errno != ENOENT) e(18); + } else { + if (errno != ENAMETOOLONG) e(19); + } + if (opendir(ToLongPath) != ((DIR *) NULL)) e(20); /* path is too long */ if (errno != ENAMETOOLONG) e(21); System("touch foo/abc"); /* make a file */ @@ -364,33 +359,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_24"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test25.c b/test/test25.c index 2bd7c39c9..ddcfd6198 100644 --- a/test/test25.c +++ b/test/test25.c @@ -19,13 +19,14 @@ #define MAX_ERROR 4 #define ITERATIONS 2 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) #define Creat(f) if (close(creat(f,0777))!=0) printf("Can't creat %s\n",f) #define Report(s,n) printf("Subtest %d" s,subtest,(n)) -int errct = 0; int subtest = 1; int superuser; char MaxName[NAME_MAX + 1]; /* Name of maximum length */ @@ -56,10 +57,7 @@ int main(int argc, char *argv[]) } if (argc == 2) m = atoi(argv[1]); - printf("Test 25 "); - fflush(stdout); - System("rm -rf DIR_25; mkdir DIR_25"); - Chdir("DIR_25"); + start(25); makelongnames(); superuser = (geteuid() == 0); @@ -570,7 +568,7 @@ void test25d() void test25e() { - int fd; + int fd, does_truncate; char *noread = "noread"; /* Name for unreadable file. */ char *nowrite = "nowrite"; /* Same for unwritable. */ int stat_loc; @@ -675,13 +673,21 @@ void test25e() /* Test ToLongName and ToLongPath */ - if ((fd = open(ToLongName, O_RDWR | O_CREAT, 0777)) != 3) e(47); - if (close(fd) != 0) e(48); + does_truncate = does_fs_truncate(); + fd = open(ToLongName, O_RDWR | O_CREAT, 0777); + if (does_truncate) { + if (fd == -1) e(47); + if (close(fd) != 0) e(48); + } else { + if (fd != -1) e(49); + (void) close(fd); /* Just in case */ + } + ToLongPath[PATH_MAX - 2] = '/'; ToLongPath[PATH_MAX - 1] = 'a'; - if ((fd = open(ToLongPath, O_RDWR | O_CREAT, 0777)) != -1) e(49); - if (errno != ENAMETOOLONG) e(50); - if (close(fd) != -1) e(51); + if ((fd = open(ToLongPath, O_RDWR | O_CREAT, 0777)) != -1) e(50); + if (errno != ENAMETOOLONG) e(51); + if (close(fd) != -1) e(52); ToLongPath[PATH_MAX - 1] = '/'; } @@ -706,33 +712,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_25"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test28.c b/test/test28.c index 46b2ddecd..b232b3a1c 100644 --- a/test/test28.c +++ b/test/test28.c @@ -23,12 +23,13 @@ #define MAX_ERROR 4 #define ITERATIONS 2 +#include "common.c" + #define DIRENT0 ((struct dirent *) NULL) #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) -int errct = 0; int subtest = 1; int superuser; char MaxName[NAME_MAX + 1]; /* Name of maximum length */ @@ -40,8 +41,6 @@ _PROTOTYPE(void test28a, (void)); _PROTOTYPE(void test28c, (void)); _PROTOTYPE(void test28b, (void)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int n)); -_PROTOTYPE(void quit, (void)); int main(int argc, char *argv[]) { @@ -49,13 +48,9 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 28 "); - fflush(stdout); + start(28); superuser = (getuid() == 0); makelongnames(); - system("chmod 777 DIR_28/* DIR_28/*/* > /dev/null 2>&1"); - System("rm -rf DIR_28; mkdir DIR_28"); - Chdir("DIR_28"); umask(0000); /* no umask */ for (i = 0; i < ITERATIONS; i++) { @@ -168,10 +163,11 @@ void test28b() struct dirent *dep; int fd; /* file descriptor */ int other = 0, dot = 0, dotdot = 0; /* dirent counters */ + int r; /* Intermediate result */ int rmdir_result; /* tmp var */ nlink_t nlink; static char bar[20]; - int stat_loc; + int stat_loc, does_truncate; subtest = 2; @@ -195,16 +191,25 @@ void test28b() if (rmdir(MaxPath) != 0) e(12); /* ok */ /* Test too long path ed. */ - if (mkdir(ToLongName, 0777) != 0) e(17); /* Try ToLongName */ - if (rmdir(ToLongName) != 0) e(18); /* and remove it */ + does_truncate = does_fs_truncate(); + r = mkdir(ToLongName, 0777); + if (does_truncate ) { + /* FS truncates names, mkdir should've worked */ + if (r != 0) e(13); /* Try ToLongName */ + if (rmdir(ToLongName) != 0) e(14); /* and remove it */ + } else { + /* Too long, should've failed with ENAMETOOLONG */ + if (r == 0) e(15); + if (errno != ENAMETOOLONG) e(16); + } ToLongPath[strlen(ToLongPath) - 2] = '/'; /* make ToLongPath */ ToLongPath[strlen(ToLongPath) - 1] = 'a'; /* contain ././.../a */ - if (mkdir(ToLongPath, 0777) != -1) e(19); /* it should */ - if (errno != ENAMETOOLONG) e(20); /* not be ok */ - if (rmdir(ToLongPath) != -1) e(21); - if (errno != ENAMETOOLONG) e(22); + if (mkdir(ToLongPath, 0777) != -1) e(17); /* it should */ + if (errno != ENAMETOOLONG) e(18); /* not be ok */ + if (rmdir(ToLongPath) != -1) e(19); + if (errno != ENAMETOOLONG) e(20); - if (mkdir("foo", 0777) != 0) e(23); + if (mkdir("foo", 0777) != 0) e(21); System("touch foo/xyzzy"); #if 0 /* Test what happens if the parent link count > LINK_MAX. */ @@ -406,33 +411,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_28"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test30.c b/test/test30.c index 586197c8e..49a84d4ef 100644 --- a/test/test30.c +++ b/test/test30.c @@ -22,11 +22,12 @@ #define MAX_ERROR 4 #define ITERATIONS 10 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -int errct = 0; int subtest = 1; int superuser; char MaxName[NAME_MAX + 1]; /* Name of maximum length */ @@ -47,14 +48,11 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 30 "); - fflush(stdout); - System("rm -rf DIR_30; mkdir DIR_30"); - Chdir("DIR_30"); + umask(0000); + start(30); makelongnames(); superuser = (geteuid() == 0); - umask(0000); for (i = 0; i < ITERATIONS; i++) { if (m & 0001) test30a(); @@ -231,7 +229,7 @@ void test30b() void test30c() { - int fd; + int fd, does_truncate; subtest = 3; @@ -266,18 +264,17 @@ void test30c() System("rm -rf bar"); /* Test ToLongName and ToLongPath */ -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - if ((fd = creat(ToLongName, 0777)) != -1) e(11); - if (errno != ENAMETOOLONG) e(12); - close(fd); /* Just in case. */ -# else - if ((fd = creat(ToLongName, 0777)) != 3) e(13); - if (close(fd) != 0) e(14); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + does_truncate = does_fs_truncate(); + fd = creat(ToLongName, 0777); + if (does_truncate) { + if (fd == -1) e(11); + if (close(fd) != 0) e(12); + } else { + if (fd != -1) e(13); + if (errno != ENAMETOOLONG) e(14); + (void) close(fd); /* Just in case. */ + } + ToLongPath[PATH_MAX - 2] = '/'; ToLongPath[PATH_MAX - 1] = 'a'; if ((fd = creat(ToLongPath, 0777)) != -1) e(15); @@ -307,33 +304,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_30"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test31.c b/test/test31.c index 412bfe7ea..4880eee1c 100644 --- a/test/test31.c +++ b/test/test31.c @@ -15,11 +15,12 @@ #define MAX_ERROR 4 #define ITERATIONS 10 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) -int errct = 0; int subtest = 1; int superuser; char MaxName[NAME_MAX + 1]; /* Name of maximum length */ @@ -31,8 +32,6 @@ _PROTOTYPE(void test31a, (void)); _PROTOTYPE(void test31b, (void)); _PROTOTYPE(void test31c, (void)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); int main(int argc, char *argv[]) { @@ -40,14 +39,11 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 31 "); - fflush(stdout); - System("rm -rf DIR_31; mkdir DIR_31"); - Chdir("DIR_31"); + umask(0000); + start(31); makelongnames(); superuser = (geteuid() == 0); - umask(0000); for (i = 0; i < ITERATIONS; i++) { if (m & 0001) test31a(); @@ -152,6 +148,7 @@ void test31b() void test31c() { + int does_truncate; subtest = 3; System("rm -rf ../DIR_31/*"); @@ -199,16 +196,14 @@ void test31c() System("rm -rf bar"); /* Test ToLongName and ToLongPath */ -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - if (mkfifo(ToLongName, 0777) != -1) e(19); - if (errno != ENAMETOOLONG) e(20); -# else - if (mkfifo(ToLongName, 0777) != 0) e(21); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + does_truncate = does_fs_truncate(); + if (does_truncate) { + if (mkfifo(ToLongName, 0777) != 0) e(19); + } else { + if (mkfifo(ToLongName, 0777) != -1) e(20); + if (errno != ENAMETOOLONG) e(21); + } + ToLongPath[PATH_MAX - 2] = '/'; ToLongPath[PATH_MAX - 1] = 'a'; if (mkfifo(ToLongPath, 0777) != -1) e(22); @@ -237,33 +232,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_31"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test33.c b/test/test33.c index 3ed79bf60..d37206f21 100644 --- a/test/test33.c +++ b/test/test33.c @@ -15,13 +15,14 @@ #define MAX_ERROR 1 #define ITERATIONS 2 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) #define Chmod(a,b) if (chmod(a,b) != 0) printf("Can't chmod %s\n", a) #define Mkfifo(f) if (mkfifo(f,0777)!=0) printf("Can't make fifo %s\n", f) -int errct = 0; int subtest = 1; int superuser; /* nonzero if uid == euid (euid == 0 always) */ char MaxName[NAME_MAX + 1]; /* Name of maximum length */ @@ -35,8 +36,6 @@ _PROTOTYPE(void test33c, (void)); _PROTOTYPE(void test33d, (void)); _PROTOTYPE(void test_access, (void)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); int main(int argc, char *argv[]) { @@ -44,21 +43,20 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 33 "); - fflush(stdout); + umask(0000); + start(33); if (geteuid() != 0) { printf("must be setuid root; test aborted\n"); + cleanup(); exit(1); } if (getuid() == 0) { printf("must be setuid root logged in as someone else; test aborted\n"); + cleanup(); exit(1); } - umask(0000); - System("rm -rf DIR_33; mkdir DIR_33"); - Chdir("DIR_33"); makelongnames(); superuser = (getuid() == 0); @@ -324,7 +322,7 @@ void test33b() void test33c() { /* Test errors returned. */ - int i; + int i, fd, does_truncate; subtest = 3; System("rm -rf ../DIR_33/*"); @@ -360,17 +358,19 @@ void test33c() if (access("nosearch/file", F_OK) != 0) e(17); /* Test ToLongName and ToLongPath */ -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - if (access(ToLongName, F_OK) != -1) e(23); - if (errno != ENAMETOOLONG) e(24); -# else - if (close(creat(ToLongName, 0777)) != 0) e(25); - if (access(ToLongName, F_OK) != 0) e(26); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + does_truncate = does_fs_truncate(); + if (does_truncate) { + if ((fd = creat(ToLongName, 0777)) != 0) e(18); + if (close(fd) != 0) e(19); + if (access(ToLongName, F_OK) != 0) e(20); + } else { + if ((fd = creat(ToLongName, 0777)) != -1) e(21); + if (errno != ENAMETOOLONG) e(22); + (void) close(fd); /* Just in case */ + if (access(ToLongName, F_OK) != -1) e(23); + if (errno != ENAMETOOLONG) e(24); + } + ToLongPath[PATH_MAX - 2] = '/'; ToLongPath[PATH_MAX - 1] = 'a'; if (access(ToLongPath, F_OK) != -1) e(27); @@ -618,33 +618,3 @@ void makelongnames() ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_33"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} diff --git a/test/test34.c b/test/test34.c index 1948573e3..81970f28c 100644 --- a/test/test34.c +++ b/test/test34.c @@ -23,6 +23,8 @@ #define ITERATIONS 4 #define N 100 +#include "common.c" + #define ALL_RWXB (S_IRWXU | S_IRWXG | S_IRWXO) #define ALL_SETB (S_ISUID | S_ISGID) #define ALL_BITS (ALL_RWXB | ALL_SETB) @@ -37,7 +39,6 @@ /* This program uses /etc/passwd and assumes things about it's contents. */ #define PASSWD_FILE "/etc/passwd" -int errct = 0; int subtest = 1; int superuser; int I_can_chown; @@ -51,8 +52,6 @@ _PROTOTYPE(void test34b, (void)); _PROTOTYPE(void test34c, (void)); _PROTOTYPE(mode_t mode, (char *file_name)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); _PROTOTYPE(void getids, (uid_t * uid, gid_t * gid)); int main(int argc, char *argv[]) @@ -61,15 +60,8 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 34 "); - fflush(stdout); - (void) system("chmod 777 DIR_34/* > /dev/null 2> /dev/null"); - System("rm -rf DIR_34; mkdir DIR_34"); - if (chdir("DIR_34") != 0) { - fprintf(stderr, "Can't go to DIR_34\n"); - system("rm -rf DIR_34"); - exit(1); - } + umask(0000); + start(34); makelongnames(); superuser = (geteuid() == (uid_t) 0); @@ -79,7 +71,6 @@ int main(int argc, char *argv[]) I_can_chown = 1; #endif - umask(0000); for (i = 1; i < ITERATIONS; i++) { if (m & 0001) test34a(); @@ -395,7 +386,7 @@ void test34c() struct stat st; uid_t uid, uid2; gid_t gid, gid2; - int stat_loc; + int fd, does_truncate, stat_loc; subtest = 3; @@ -521,9 +512,18 @@ void test34c() } /* Check too long path ed. */ - Creat(NameTooLong); - if (chmod(NameTooLong, 0777) != 0) e(57); - if (chown(NameTooLong, geteuid(), getegid()) != 0) e(58); + does_truncate = does_fs_truncate(); + fd = creat(NameTooLong, 0777); + if (does_truncate) { + if (fd == -1) e(53); + if (close(fd) != 0) e(54); + if (chmod(NameTooLong, 0777) != 0) e(55); + if (chown(NameTooLong, geteuid(), getegid()) != 0) e(56); + } else { + if (fd != -1) e(57); + if (errno != ENAMETOOLONG) e(58); + (void) close(fd); /* Just in case */ + } /* Make PathTooLong contain ././.../a */ PathTooLong[strlen(PathTooLong) - 2] = '/'; @@ -559,39 +559,6 @@ void makelongnames() PathTooLong[PATH_MAX] = '\0'; /* inc PathTooLong by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR*"); - system("rm -rf DIR_34"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - (void) system("chmod 777 DIR_34/* > /dev/null 2> /dev/null"); - System("rm -rf DIR_34"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} - /* Getids returns a valid uid and gid. Is used PASSWD FILE. * It assumes the following format for a passwd file line: * :::: diff --git a/test/test35.c b/test/test35.c index 5bb151ae0..d49fe3395 100644 --- a/test/test35.c +++ b/test/test35.c @@ -18,6 +18,8 @@ #define ITERATIONS 10 #define N 100 +#include "common.c" + #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd) #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir) #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a) @@ -30,7 +32,6 @@ #define PASSWD_FILE "/etc/passwd" -int errct = 0; int subtest = 1; int I_can_chown; int superuser; @@ -43,8 +44,6 @@ _PROTOTYPE(void test35a, (void)); _PROTOTYPE(void test35b, (void)); _PROTOTYPE(void test35c, (void)); _PROTOTYPE(void makelongnames, (void)); -_PROTOTYPE(void e, (int number)); -_PROTOTYPE(void quit, (void)); _PROTOTYPE(void getids, (uid_t * uid, gid_t * gid)); int main(int argc, char *argv[]) @@ -53,10 +52,7 @@ int main(int argc, char *argv[]) sync(); if (argc == 2) m = atoi(argv[1]); - printf("Test 35 "); - fflush(stdout); - System("rm -rf DIR_35; mkdir DIR_35"); - Chdir("DIR_35"); + start(35); makelongnames(); superuser = (geteuid() == 0); @@ -176,7 +172,7 @@ void test35c() gid_t gid, gid2; uid_t uid, uid2; struct utimbuf ub; - int stat_loc; + int fd, does_truncate, stat_loc; subtest = 3; @@ -256,18 +252,15 @@ void test35c() } /* Test names that are too long. */ -#ifdef _POSIX_NO_TRUNC -# if _POSIX_NO_TRUNC - 0 != -1 - /* Not exist might also be a propper response? */ - if (utime(NameTooLong, NULL) != -1) e(18); - if (errno != ENAMETOOLONG) e(19); -# else - Creat(NameTooLong); - if (utime(NameTooLong, NULL) != 0) e(20); -# endif -#else -# include "error, this case requires dynamic checks and is not handled" -#endif + does_truncate = does_fs_truncate(); + fd = creat(NameTooLong, 0777); + if (does_truncate) { + if (utime(NameTooLong, NULL) != 0) e(18); + } else { + if (utime(NameTooLong, NULL) != -1) e(19); + if (errno != ENAMETOOLONG) e(20); + } + (void) close(fd); /* Make PathTooLong contain ././.../a */ PathTooLong[strlen(PathTooLong) - 2] = '/'; @@ -308,37 +301,6 @@ void makelongnames() PathTooLong[PATH_MAX] = '\0'; /* inc PathTooLong by one */ } -void e(n) -int n; -{ - int err_num = errno; /* Save in case printf clobbers it. */ - - printf("Subtest %d, error %d errno=%d: ", subtest, n, errno); - errno = err_num; - perror(""); - if (errct++ > MAX_ERROR) { - printf("Too many errors; test aborted\n"); - chdir(".."); - system("rm -rf DIR* > /dev/null 2>/dev/null"); - exit(1); - } - errno = 0; -} - -void quit() -{ - Chdir(".."); - System("rm -rf DIR_35"); - - if (errct == 0) { - printf("ok\n"); - exit(0); - } else { - printf("%d errors\n", errct); - exit(1); - } -} - /* Getids returns a valid uid and gid. Is used PASSWD FILE. ** It assumes the following format for a passwd file line: ** :::: -- 2.44.0