#include <utime.h>
#include <stdio.h>
#include <limits.h>
+#include <assert.h>
#define NOCRASH 1 /* test11(), 2nd pipe */
#define PDPNOHANG 1 /* test03(), write_standards() */
int errct;
-char *file[];
-char *fnames[];
-char *dir[];
-
/* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */
-char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6",
- "f7", "f8", "f9", "f10", "f11", "f12", "f13",
- "f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--",
- "r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x",
- "drw-", "drwx"};
+char *filenames[MAXOPEN];
+
+#define MODES 8
+char *mode_fnames[MODES] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
+*mode_dir[MODES] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
+
/* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */
char *argv[];
{
char buffer[PATH_MAX + 1];
- int n, mask;
+ int n, mask, i;
+
+ /* Create filenames for MAXOPEN files, the *filenames[] array. */
+ for(i = 0; i < MAXOPEN; i++) {
+ if(asprintf(&filenames[i], "file%d", i) == -1) {
+ fprintf(stderr, "asprintf failed\n");
+ return 1;
+ }
+ }
sync();
if (geteuid() == 0 || getuid() == 0) {
exit(1);
}
- system("rm -rf DIR_17; mkdir DIR_17");
- chdir("DIR_17");
+#define DIR "DIR17"
+ system("rm -rf " DIR);
+
+ if(mkdir(DIR, 0755) != 0) {
+ perror("mkdir");
+ return 1;
+ }
+
+ if(chdir(DIR) < 0) {
+ perror("chdir");
+ return 1;
+ }
mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
mode = 0;
/* Create twenty files, check filedes */
for (n = 0; n < MAXOPEN; n++) {
- if (creat(file[n], mode) != FF + n)
- err(13, CREAT, file[n]);
+ if (creat(filenames[n], mode) != FF + n)
+ err(13, CREAT, filenames[n]);
else {
- if (get_mode(file[n]) != mode)
+ if (get_mode(filenames[n]) != mode)
err(7, CREAT, "mode set while creating many files");
/* Change mode of file to standard mode, we want to *
* use a lot (20) of files to be opened later, see *
* open_alot(), close_alot(). */
- if (chmod(file[n], 0700) != OK) err(5, CHMOD, file[n]);
-
+ if (chmod(filenames[n], 0700) != OK) err(5, CHMOD, filenames[n]);
}
mode = (mode + 0100) % 01000;
}
int n, n1;
char a[ARSIZE], b[ARSIZE], *f, *lf;
- f = "file10";
+ f = "anotherfile10";
lf = "linkfile10";
if ((n = creat(f, 0702)) != FF) /* no other open files */
{
int mode, i;
- for (i = 0; i < 8; i++) {
- mkdir(dir[i], 0700);
- chown(dir[i], USER_ID, GROUP_ID);
+ for (i = 0; i < MODES; i++) {
+ mkdir(mode_dir[i], 0700);
+ chown(mode_dir[i], USER_ID, GROUP_ID);
}
setuid(USER_ID);
setgid(GROUP_ID);
err(5, CHDIR, "to dirname (put_f_in_dir)");
else {
/* Creat the file */
- if ((nr = creat(fnames[mode], mode * 0100)) < 0)
- err(13, CREAT, fnames[mode]);
- else
- try_close(nr, fnames[mode]);
+ assert(mode >= 0 && mode < MODES);
+ if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0)
+ err(13, CREAT, mode_fnames[mode]);
+ else {
+ try_close(nr, mode_fnames[mode]);
+ }
if (chdir("..") != OK)
err(5, CHDIR, "to previous dir (put_f_in_dir)");
int i;
for (i = 0; i < MAXOPEN; i++)
- if (open(file[i], R) == FAIL) break;
+ if (open(filenames[i], R) == FAIL) break;
if (i == 0) err(5, "open_alot", "at all");
return(i);
} /* open_alot */
char dirname[6];
/* First remove 'a lot' files */
- for (i = 0; i < MAXOPEN; i++) try_unlink(file[i]);
+ for (i = 0; i < MAXOPEN; i++) {
+ try_unlink(filenames[i]);
+}
/* Unlink the files in dir 'drwx' */
if (chdir("drwx") != OK)
err(5, CHDIR, "to 'drwx'");
else {
- for (i = 0; i < 8; i++) try_unlink(fnames[i]);
+ for (i = 0; i < MODES; i++) {
+ try_unlink(mode_fnames[i]);
+ }
if (chdir("..") != OK) err(5, CHDIR, "to '..'");
}
try_unlink("drw-/rwx");
/* Unlink dirs */
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < MODES; i++) {
strcpy(dirname, "d");
- strcat(dirname, fnames[i]);
+ strcat(dirname, mode_fnames[i]);
/* 'dirname' contains the directoryname */
rmdir(dirname);
else
mode = sw;
- for (i = 0; i < 8; i++) {
- chmod(dir[i], 040000 + mode * 0100);
+ for (i = 0; i < MODES; i++) {
+ chmod(mode_dir[i], 040000 + mode * 0100);
if (sw == 8) mode++;
}
}
int errct;
-char *file[];
-char *fnames[];
-char *dir[];
-
/* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */
-char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6",
- "f7", "f8", "f9", "f10", "f11", "f12", "f13",
- "f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--",
- "r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x",
- "drw-", "drwx"};
+char *file[MAXOPEN];
+char *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
+ *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
+
/* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */
int main(int argc, char **argv)
{
char buffer[PATH_MAX + 1];
- int n;
+ int n, i;
+
+ /* Create filenames for MAXOPEN files, the *file[] array. */
+ for(i = 0; i < MAXOPEN; i++) {
+ if(asprintf(&file[i], "file%d", i) == -1) {
+ fprintf(stderr, "asprintf failed\n");
+ return 1;
+ }
+ }
if (geteuid() == 0 || getuid() == 0) {
realpath(argv[0], buffer);
exit(1);
}
- system("rm -rf DIR_18; mkdir DIR_18");
- chdir("DIR_18");
+#define DIR "DIR18"
+ system("rm -rf " DIR);
+ if(mkdir(DIR, 0755) != 0) {
+ perror("mkdir");
+ return 1;
+ }
+ if(chdir(DIR) != 0) {
+ perror("chdir");
+ return 1;
+ }
if (fork()) {
printf("Test 18 ");
check(OPEN, ENOENT);
/* Dir is not searchable */
- if (n = open("drw-/rwx", R) != FAIL)
+ if ((n = open("drw-/rwx", R)) != FAIL)
err(11, OPEN, "open in an non-searchabledir");
else
check(OPEN, EACCES);