_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 */
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
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,
#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <sys/statvfs.h>
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));
}
}
+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;
{
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));
cleanup();
exit(1);
}
- errno = 0; /* don't leave it around to confuse next e() */
+ errno = err_number;
}
void cleanup()
#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. */
_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[])
{
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);
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/*");
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);
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);
- }
-}
_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;
/* Test whether wrong things go wrong right. */
DIR *dirp;
+ int does_truncate;
subtest = 3;
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 */
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);
- }
-}
#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 */
}
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);
void test25e()
{
- int fd;
+ int fd, does_truncate;
char *noread = "noread"; /* Name for unreadable file. */
char *nowrite = "nowrite"; /* Same for unwritable. */
int stat_loc;
/* 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] = '/';
}
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);
- }
-}
#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 */
_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[])
{
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++) {
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;
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. */
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);
- }
-}
#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 */
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();
void test30c()
{
- int fd;
+ int fd, does_truncate;
subtest = 3;
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);
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);
- }
-}
#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 */
_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[])
{
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();
void test31c()
{
+ int does_truncate;
subtest = 3;
System("rm -rf ../DIR_31/*");
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);
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);
- }
-}
#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 */
_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[])
{
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);
void test33c()
{ /* Test errors returned. */
- int i;
+ int i, fd, does_truncate;
subtest = 3;
System("rm -rf ../DIR_33/*");
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);
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);
- }
-}
#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)
/* 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;
_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[])
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);
I_can_chown = 1;
#endif
- umask(0000);
for (i = 1; i < ITERATIONS; i++) {
if (m & 0001) test34a();
struct stat st;
uid_t uid, uid2;
gid_t gid, gid2;
- int stat_loc;
+ int fd, does_truncate, stat_loc;
subtest = 3;
}
/* 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] = '/';
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:
* <user_name>:<passwd>:<uid>:<gid>:<other_stuff>
#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)
#define PASSWD_FILE "/etc/passwd"
-int errct = 0;
int subtest = 1;
int I_can_chown;
int superuser;
_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[])
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);
gid_t gid, gid2;
uid_t uid, uid2;
struct utimbuf ub;
- int stat_loc;
+ int fd, does_truncate, stat_loc;
subtest = 3;
}
/* 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] = '/';
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:
** <user_name>:<passwd>:<uid>:<gid>:<other_stuff>