18 char curdir
[PATH_MAX
];
20 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
21 _PROTOTYPE(void test6a
, (void));
22 _PROTOTYPE(void test6b
, (void));
23 _PROTOTYPE(void test6c
, (void));
24 _PROTOTYPE(void e
, (int n
));
25 _PROTOTYPE(void quit
, (void));
31 char buffer
[PATH_MAX
+ 1];
35 if (geteuid() == 0 || getuid() == 0) {
36 realpath(argv
[0], buffer
);
37 execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer
, NULL
);
38 printf("Test 6 cannot run as root; test aborted\n");
42 if (argc
== 2) m
= atoi(argv
[1]);
47 getcwd(curdir
, PATH_MAX
);
48 system("rm -rf DIR_06; mkdir DIR_06");
51 for (i
= 0; i
< 70; i
++) {
52 if (m
& 00001) test6a();
53 if (m
& 00002) test6b();
54 if (m
& 00004) test6c();
58 return(-1); /* impossible */
63 /* Test sbrk() and brk(). */
65 char *addr
, *addr2
, *addr3
;
66 int i
, del
, click
, click2
;
70 addr
= sbrk(0); /* force break to a click boundary */
71 for (i
= 0; i
< 10; i
++) sbrk(7 * i
);
72 for (i
= 0; i
< 10; i
++) sbrk(-7 * i
);
73 if (sbrk(0) != addr
) e(1);
75 if (brk(addr
) != 0) e(2);
76 if (sbrk(0) != addr
) e(3);
83 } while (addr2
== addr
);
86 if (sbrk(0) != addr
) e(4);
88 if (sbrk(0) != addr
) e(5);
95 } while (addr3
== addr
);
96 click2
= addr
- addr3
;
98 if (sbrk(0) != addr
) e(6);
100 if (sbrk(0) != addr
) e(8);
101 if (click
!= click2
) e(9);
103 brk(addr
+ 2 * click
);
104 if (sbrk(0) != addr
+ 2 * click
) e(10);
106 if (sbrk(0) != addr
+ 5 * click
) e(11);
108 if (sbrk(0) != addr
) e(12);
116 signal(SIGQUIT
, SIG_IGN
);
118 for (i
= 0; i
< 5000; i
++)
119 if (zilch
[i
] != 0) err
++;
121 kill(getpid(), SIGQUIT
);
126 /* Test mknod, chdir, chmod, chown, access. */
132 if (getuid() != 0) return;
133 for (j
= 0; j
< 2; j
++) {
136 if (chdir("/") < 0) e(1);
137 if (mknod("dir", 040700, 0) < 0) e(2);
138 if (link("/", "/dir/..") < 0) e(3);
139 if (mknod("T3a", 0777, 0) < 0) e(4);
140 if (mknod("/dir/T3b", 0777, 0) < 0) e(5);
141 if (mknod("dir/T3c", 0777, 0) < 0) e(6);
142 if ((i
= open("/dir/T3b", 0)) < 0) e(7);
143 if (close(i
) < 0) e(8);
144 if ((i
= open("dir/T3c", O_RDONLY
)) < 0) e(9);
145 if (close(i
) < 0) e(10);
146 if (chdir("dir") < 0) e(11);
147 if ((i
= open("T3b", 0)) < 0) e(12);
148 if (close(i
) < 0) e(13);
149 if ((i
= open("../T3a", O_RDONLY
)) < 0) e(14);
150 if (close(i
) < 0) e(15);
151 if ((i
= open("../dir/../dir/../dir/../dir/../dir/T3c", O_RDONLY
)) < 0)
153 if (close(i
) < 0) e(17);
155 if (chmod("../dir/../dir/../dir/../dir/../T3a", 0123) < 0) e(18);
156 if (stat("../dir/../dir/../dir/../T3a", &s
) < 0) e(19);
157 if ((s
.st_mode
& 077777) != 0123) e(20);
158 if (chmod("../dir/../dir/../T3a", 0456) < 0) e(21);
159 if (stat("../T3a", &s
) < 0) e(22);
160 if ((s
.st_mode
& 077777) != 0456) e(23);
161 if (chown("../dir/../dir/../T3a", 20, 30) < 0) e(24);
162 if (stat("../T3a", &s
) < 0) e(25);
163 if (s
.st_uid
!= 20) e(26);
164 if (s
.st_gid
!= 30) e(27);
166 if ((i
= open("/T3c", O_RDONLY
)) >= 0) e(28);
167 if ((i
= open("/T3a", O_RDONLY
)) < 0) e(29);
168 if (close(i
) < 0) e(30);
170 if (access("/T3a", 4) < 0) e(31);
171 if (access("/dir/T3b", 4) < 0) e(32);
172 if (access("/dir/T3d", 4) >= 0) e(33);
174 if (unlink("T3b") < 0) e(34);
175 if (unlink("T3c") < 0) e(35);
176 if (unlink("..") < 0) e(36);
177 if (chdir("/") < 0) e(37);
178 if (unlink("dir") < 0) e(38);
179 if (unlink("/T3a") < 0) e(39);
188 int err_num
= errno
; /* save errno in case printf clobbers it */
190 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
191 errno
= err_num
; /* restore errno, just in case */
193 if (errct
++ > MAX_ERROR
) {
194 printf("Too many errors; test aborted\n");
196 system("rm -rf DIR*");
205 system("rm -rf DIR*");
208 system("rm -rf DIR*");
213 printf("%d errors\n", errct
);