xref: /freebsd/tools/regression/doat/doat.c (revision aa0a1e58)
1 /*-
2  * Copyright (c) 2007 Roman Divacky
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #include <sys/types.h>
30 #include <sys/syscall.h>
31 #include <sys/stat.h>
32 
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <stdbool.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
40 
41 void cleanup(void);
42 void setup(void);
43 void setup_once(void);
44 
45 union param {
46 	int		i;
47 	const char	*cp;
48 	mode_t		m;
49 	dev_t		d;
50 	void		*vp;
51 	uid_t		u;
52 	gid_t		g;
53 	const char	**cpp;
54 };
55 
56 struct testcase {
57 	int		result;
58 	union param	params[5];	/* no *at syscall with more than 5 params */
59 };
60 
61 struct test {
62 	int	syscall;
63 	int	num_of_cases;
64 	const char *name;
65 	struct testcase	tests[10];	/* no more than 10 tests */
66 
67 };
68 
69 struct test *tests;
70 #define	NUM_OF_TESTS	14		/* we dont want the fexecve test to run */
71 
72 char *absolute_path = NULL;
73 const char *relative_path = "tmp/";
74 const char *not_dir_path = "/bin/date";
75 
76 const char *file = "foo";
77 char *absolute_file = NULL;
78 char *relative_file = NULL;
79 const char *symlinkf = "link";
80 const char *newlink = "nlink1";
81 const char *newlink2 = "nlink2";
82 const char *newlink3 = "nlink3";
83 const char *newdir = "newdir";
84 const char *fifo = "fifo";
85 const char *nod = "nod";
86 const char *newfile = "newfile";
87 const char *newslink = "nslink1";
88 
89 bool dir_exist = false;
90 bool file_exist = false;
91 bool link_exist = false;
92 
93 int rel_fd, abs_fd, notd_fd, exec_fd;
94 
95 struct timeval times[2];
96 struct stat buf;
97 const char *pargv[2] = { "/bin/date", NULL };
98 #define	PATH_MAX	1024
99 char cbuf[PATH_MAX];
100 
101 void
102 setup(void)
103 {
104 	int i, error;
105 	struct stat sb;
106 
107 	tests = calloc(NUM_OF_TESTS, sizeof(struct test));
108 	if (tests == NULL) {
109 		perror("");
110 		exit(0);
111 	}
112 
113 	absolute_path = (char *)getcwd(NULL, 0);
114 	if (absolute_path == NULL) {
115 		perror("getcwd");
116 		exit(0);
117 	}
118 
119 	absolute_path = realloc(absolute_path, strlen(absolute_path) + 5);
120 	if (absolute_path == NULL) {
121 		perror("realloc");
122 		exit(0);
123 	}
124 
125 	absolute_path[strlen(absolute_path)] = '/';
126 	strcpy(absolute_path + strlen(absolute_path), relative_path);
127 
128 	absolute_file = malloc(strlen(absolute_path) + 1 + strlen(file));
129 	bzero(absolute_file, strlen(absolute_path) + 1 + strlen(file));
130 	if (absolute_file == NULL) {
131 		perror("malloc");
132 		exit(0);
133 	}
134 	strcpy(absolute_file, absolute_path);
135 	absolute_file[strlen(absolute_file)] = '/';
136 	strcpy(absolute_file + strlen(absolute_path), file);
137 
138 	relative_file = malloc(strlen(relative_path) + 1 + strlen(file));
139 	bzero(relative_file, strlen(relative_path) + 1 + strlen(file));
140 	if (relative_file == NULL) {
141 		perror("malloc");
142 		exit(0);
143 	}
144 	strcpy(relative_file, relative_path);
145 	relative_file[strlen(relative_file)] = '/';
146 	strcpy(relative_file + strlen(relative_path), file);
147 
148 	error = mkdir(relative_path, 666);
149 	dir_exist = (errno == EEXIST);
150 	if (error && errno != EEXIST) {
151 		perror("tmp");
152 		exit(0);
153 	}
154 
155 	error = stat("tmp/foo", &sb);
156 	file_exist = (errno != ENOENT);
157 	i = open("tmp/foo", O_RDONLY | O_CREAT);
158 	if (i == -1) {
159 		perror("foo");
160 		exit(0);
161 	}
162 
163 	rel_fd = open(relative_path, O_RDONLY);
164 	if (rel_fd == -1) {
165 		perror("relative path");
166 		exit(0);
167 	}
168 
169 	abs_fd = open(absolute_path, O_RDONLY);
170 	if (abs_fd == -1) {
171 		perror("absolute path");
172 		exit(0);
173 	}
174 
175 	notd_fd = open(not_dir_path, O_RDONLY);
176 	if (notd_fd == -1) {
177 		perror("not a directory");
178 		exit(0);
179 	}
180 
181 	exec_fd = open(not_dir_path, O_RDONLY);
182 	if (exec_fd == -1) {
183 		perror("not a directory");
184 		exit(0);
185 	}
186 
187 	error = symlink(absolute_file, symlinkf);
188 	link_exist = (errno == EEXIST);
189 	if (error && errno != EEXIST) {
190 		perror("symlink");
191 		exit(0);
192 	}
193 
194 	/* faccessat */
195 	tests[0].syscall = SYS_faccessat;
196 	tests[0].num_of_cases = 6;
197 	tests[0].name = "faccessat";
198 	tests[0].tests[0].result = EBADF;
199 	tests[0].tests[0].params[0].i = 106;	/* invalid fd */
200 	tests[0].tests[0].params[1].cp = relative_path;
201 	tests[0].tests[0].params[2].m = 0;
202 	tests[0].tests[0].params[3].i = 0;
203 	tests[0].tests[1].result = EBADF;
204 	tests[0].tests[1].params[0].i = 106;	/* invalid fd */
205 	tests[0].tests[1].params[1].cp = relative_path;
206 	tests[0].tests[1].params[2].m = 0;
207 	tests[0].tests[1].params[3].i = AT_EACCESS;
208 	tests[0].tests[2].result = EINVAL;
209 	tests[0].tests[2].params[0].i = rel_fd;
210 	tests[0].tests[2].params[1].cp = absolute_path;
211 	tests[0].tests[2].params[2].m = 0;
212 	tests[0].tests[2].params[3].i = 123;	/* invalid flag */
213 	tests[0].tests[3].result = ENOTDIR;
214 	tests[0].tests[3].params[0].i = notd_fd;
215 	tests[0].tests[3].params[1].cp = relative_file;
216 	tests[0].tests[3].params[2].m = 0;
217 	tests[0].tests[3].params[3].i = 0;
218 	tests[0].tests[4].result = 0;
219 	tests[0].tests[4].params[0].i = rel_fd;
220 	tests[0].tests[4].params[1].cp = file;
221 	tests[0].tests[4].params[2].m = 0;
222 	tests[0].tests[4].params[3].i = 0;
223 	tests[0].tests[5].result = 0;
224 	tests[0].tests[5].params[0].i = rel_fd;
225 	tests[0].tests[5].params[1].cp = file;
226 	tests[0].tests[5].params[2].m = 0;
227 	tests[0].tests[5].params[3].i = AT_EACCESS;
228 	tests[0].tests[6].result = 0;
229 	tests[0].tests[6].params[0].i = 106;	/* invalid fd */
230 	tests[0].tests[6].params[1].cp = absolute_path;
231 	tests[0].tests[6].params[2].m = 0;
232 	tests[0].tests[6].params[3].i = 0;
233 
234 	/* fchmodat */
235 	tests[1].syscall = SYS_fchmodat;
236 	tests[1].num_of_cases = 6;
237 	tests[1].name = "fchmodat";
238 	tests[1].tests[0].result = EBADF;
239 	tests[1].tests[0].params[0].i = 106;	/* invalid fd */
240 	tests[1].tests[0].params[1].cp = relative_path;
241 	tests[1].tests[0].params[2].m = 33190;
242 	tests[1].tests[0].params[3].i = 0;
243 	tests[1].tests[1].result = EINVAL;
244 	tests[1].tests[1].params[0].i = rel_fd;
245 	tests[1].tests[1].params[1].cp = absolute_path;
246 	tests[1].tests[1].params[2].m = 33190;	/* mode 646 translated */
247 	tests[1].tests[1].params[3].i = 123;	/* invalid flag */
248 	tests[1].tests[2].result = ENOTDIR;
249 	tests[1].tests[2].params[0].i = notd_fd;
250 	tests[1].tests[2].params[1].cp = relative_file;
251 	tests[1].tests[2].params[2].m = 33190;
252 	tests[1].tests[2].params[3].i = 0;
253 	tests[1].tests[3].result = 0;
254 	tests[1].tests[3].params[0].i = notd_fd;
255 	tests[1].tests[3].params[1].cp = absolute_file;
256 	tests[1].tests[3].params[2].m = 33190;
257 	tests[1].tests[3].params[3].i = 0;
258 	tests[1].tests[4].result = 0;
259 	tests[1].tests[4].params[0].i = AT_FDCWD;
260 	tests[1].tests[4].params[1].cp = symlinkf;
261 	tests[1].tests[4].params[2].m = 33190;
262 	tests[1].tests[4].params[3].i = AT_SYMLINK_NOFOLLOW;
263 	tests[1].tests[5].result = 0;
264 	tests[1].tests[5].params[0].i = rel_fd;
265 	tests[1].tests[5].params[1].cp = file;
266 	tests[1].tests[5].params[2].m = 33190;
267 	tests[1].tests[5].params[3].i = 0;
268 
269 	/* fchownat */
270 	tests[2].syscall = SYS_fchownat;
271 	tests[2].num_of_cases = 6;
272 	tests[2].name = "fchownat";
273 	tests[2].tests[0].result = EBADF;
274 	tests[2].tests[0].params[0].i = 106;	/* invalid fd */
275 	tests[2].tests[0].params[1].cp = relative_file;
276 	tests[2].tests[0].params[2].u = 65534;
277 	tests[2].tests[0].params[3].g = 65534;
278 	tests[2].tests[0].params[4].i = 0;
279 	tests[2].tests[1].result = EINVAL;
280 	tests[2].tests[1].params[0].i = rel_fd;
281 	tests[2].tests[1].params[1].cp = file;
282 	tests[2].tests[1].params[2].u = 65534;
283 	tests[2].tests[1].params[3].g = 65534;
284 	tests[2].tests[1].params[4].i = 123;	/* invalid flag */
285 	tests[2].tests[2].result = ENOTDIR;
286 	tests[2].tests[2].params[0].i = notd_fd;
287 	tests[2].tests[2].params[1].cp = relative_file;
288 	tests[2].tests[2].params[2].u = 65534;
289 	tests[2].tests[2].params[3].g = 65534;
290 	tests[2].tests[2].params[4].i = 0;
291 	tests[2].tests[3].result = 0;
292 	tests[2].tests[3].params[0].i = notd_fd;
293 	tests[2].tests[3].params[1].cp = absolute_file;
294 	tests[2].tests[3].params[2].u = 65534;
295 	tests[2].tests[3].params[3].g = 65534;
296 	tests[2].tests[3].params[4].i = 0;
297 	tests[2].tests[4].result = 0;
298 	tests[2].tests[4].params[0].i = AT_FDCWD;
299 	tests[2].tests[4].params[1].cp = symlinkf;
300 	tests[2].tests[4].params[2].u = 65534;
301 	tests[2].tests[4].params[3].g = 65534;
302 	tests[2].tests[4].params[4].i = AT_SYMLINK_NOFOLLOW;
303 	tests[2].tests[5].result = 0;
304 	tests[2].tests[5].params[0].i = rel_fd;
305 	tests[2].tests[5].params[1].cp = file;
306 	tests[2].tests[5].params[2].u = 0;
307 	tests[2].tests[5].params[3].g = 0;
308 	tests[2].tests[5].params[4].i = 0;
309 
310 	/* fstatat */
311 	tests[3].syscall = SYS_fstatat;
312 	tests[3].num_of_cases = 5;
313 	tests[3].name = "fstatat";
314 	tests[3].tests[0].result = EBADF;
315 	tests[3].tests[0].params[0].i = 106;	/* invalid fd */
316 	tests[3].tests[0].params[1].cp = relative_file;
317 	tests[3].tests[0].params[2].vp = &buf;
318 	tests[3].tests[0].params[3].i = 0;
319 	tests[3].tests[1].result = EINVAL;
320 	tests[3].tests[1].params[0].i = rel_fd;
321 	tests[3].tests[1].params[1].cp = relative_file;
322 	tests[3].tests[1].params[2].vp = &buf;
323 	tests[3].tests[1].params[3].i = 123;	/* invalid flags */
324 	tests[3].tests[2].result = ENOTDIR;
325 	tests[3].tests[2].params[0].i = notd_fd;
326 	tests[3].tests[2].params[1].cp = relative_file;
327 	tests[3].tests[2].params[2].vp = &buf;
328 	tests[3].tests[2].params[3].i = 0;
329 	tests[3].tests[2].result = 0;
330 	tests[3].tests[2].params[0].i = rel_fd;
331 	tests[3].tests[2].params[1].cp = file;
332 	tests[3].tests[2].params[2].vp = &buf;
333 	tests[3].tests[2].params[3].i = 0;
334 	tests[3].tests[3].result = 0;
335 	tests[3].tests[3].params[0].i = AT_FDCWD;
336 	tests[3].tests[3].params[1].cp = symlinkf;
337 	tests[3].tests[3].params[2].vp = &buf;
338 	tests[3].tests[3].params[3].i = AT_SYMLINK_NOFOLLOW;
339 	tests[3].tests[4].result = 0;
340 	tests[3].tests[4].params[0].i = notd_fd;
341 	tests[3].tests[4].params[1].cp = absolute_file;
342 	tests[3].tests[4].params[2].vp = &buf;
343 	tests[3].tests[4].params[3].i = 0;
344 
345 	/* futimesat */
346 	tests[4].syscall = SYS_futimesat;
347 	tests[4].num_of_cases = 4;
348 	tests[4].name = "futimesat";
349 	tests[4].tests[0].result = EBADF;
350 	tests[4].tests[0].params[0].i = 106;	/* invalid fd */
351 	tests[4].tests[0].params[1].cp = relative_file;
352 	tests[4].tests[0].params[2].vp = times;
353 	tests[4].tests[1].result = ENOTDIR;
354 	tests[4].tests[1].params[0].i = notd_fd;
355 	tests[4].tests[1].params[1].cp = relative_file;
356 	tests[4].tests[1].params[2].vp = times;
357 	tests[4].tests[2].result = 0;
358 	tests[4].tests[2].params[0].i = rel_fd;
359 	tests[4].tests[2].params[1].cp = file;
360 	tests[4].tests[2].params[2].vp = times;
361 	tests[4].tests[3].result = 0;
362 	tests[4].tests[3].params[0].i = notd_fd;
363 	tests[4].tests[3].params[1].cp = absolute_file;
364 	tests[4].tests[3].params[2].vp = times;
365 
366 	/* linkat */
367 	tests[5].syscall = SYS_linkat;
368 	tests[5].num_of_cases = 7;
369 	tests[5].name = "linkat";
370 	tests[5].tests[0].result = EBADF;
371 	tests[5].tests[0].params[0].i = 106;	/* invalid fd */
372 	tests[5].tests[0].params[1].cp = relative_file;
373 	tests[5].tests[0].params[2].i = AT_FDCWD;
374 	tests[5].tests[0].params[3].cp = newlink;
375 	tests[5].tests[0].params[4].i = 0;
376 	tests[5].tests[1].result = EBADF;
377 	tests[5].tests[1].params[0].i = AT_FDCWD;
378 	tests[5].tests[1].params[1].cp = relative_file;
379 	tests[5].tests[1].params[2].i = 106;	/* invalid fd */
380 	tests[5].tests[1].params[3].cp = newlink;
381 	tests[5].tests[1].params[4].i = 0;
382 	tests[5].tests[2].result = EINVAL;
383 	tests[5].tests[2].params[0].i = rel_fd;
384 	tests[5].tests[2].params[1].cp = relative_file;
385 	tests[5].tests[2].params[2].i = AT_FDCWD;
386 	tests[5].tests[2].params[3].cp = newlink;
387 	tests[5].tests[2].params[4].i = 123;	/* invalid flag */
388 	tests[5].tests[3].result = ENOTDIR;
389 	tests[5].tests[3].params[0].i = notd_fd;
390 	tests[5].tests[3].params[1].cp = relative_file;
391 	tests[5].tests[3].params[2].i = AT_FDCWD;
392 	tests[5].tests[3].params[3].cp = newlink;
393 	tests[5].tests[3].params[4].i = 0;
394 	tests[5].tests[4].result = 0;
395 	tests[5].tests[4].params[0].i = rel_fd;
396 	tests[5].tests[4].params[1].cp = file;
397 	tests[5].tests[4].params[2].i = rel_fd;
398 	tests[5].tests[4].params[3].cp = newlink;
399 	tests[5].tests[4].params[4].i = 0;
400 	tests[5].tests[5].result = 0;
401 	tests[5].tests[5].params[0].i = AT_FDCWD;
402 	tests[5].tests[5].params[1].cp = symlinkf;
403 	tests[5].tests[5].params[2].i = rel_fd;
404 	tests[5].tests[5].params[3].cp = newlink2;
405 	tests[5].tests[5].params[4].i = 0;
406 	tests[5].tests[6].result = 0;
407 	tests[5].tests[6].params[0].i = AT_FDCWD;
408 	tests[5].tests[6].params[1].cp = symlinkf;
409 	tests[5].tests[6].params[2].i = rel_fd;
410 	tests[5].tests[6].params[3].cp = newlink3;
411 	tests[5].tests[6].params[4].i = AT_SYMLINK_FOLLOW;
412 
413 	/* mkdirat */
414 	tests[6].syscall = SYS_mkdirat;
415 	tests[6].num_of_cases = 3;
416 	tests[6].name = "mkdirat";
417 	tests[6].tests[0].result = EBADF;
418 	tests[6].tests[0].params[0].i = 106;	/* invalid fd */
419 	tests[6].tests[0].params[1].cp = relative_file;
420 	tests[6].tests[0].params[2].m = 33190;
421 	tests[6].tests[1].result = ENOTDIR;
422 	tests[6].tests[1].params[0].i = notd_fd;
423 	tests[6].tests[1].params[1].cp = relative_file;
424 	tests[6].tests[1].params[2].m = 33190;
425 	tests[6].tests[2].result = 0;
426 	tests[6].tests[2].params[0].i = rel_fd;
427 	tests[6].tests[2].params[1].cp = newdir;
428 	tests[6].tests[2].params[2].m = 33190;
429 
430 	/* mkfifoat */
431 	tests[7].syscall = SYS_mkfifoat;
432 	tests[7].num_of_cases = 3;
433 	tests[7].name = "mkfifoat";
434 	tests[7].tests[0].result = EBADF;
435 	tests[7].tests[0].params[0].i = 107;	/* invalid fd */
436 	tests[7].tests[0].params[1].cp = relative_file;
437 	tests[7].tests[0].params[2].m = 33190;
438 	tests[7].tests[1].result = ENOTDIR;
439 	tests[7].tests[1].params[0].i = notd_fd;
440 	tests[7].tests[1].params[1].cp = relative_file;
441 	tests[7].tests[1].params[2].m = 33190;
442 	tests[7].tests[2].result = 0;
443 	tests[7].tests[2].params[0].i = rel_fd;
444 	tests[7].tests[2].params[1].cp = fifo;
445 	tests[7].tests[2].params[2].m = 33190;
446 
447 	/* mknodat */
448 	tests[8].syscall = SYS_mknodat;
449 	tests[8].num_of_cases = 3;
450 	tests[8].name = "mknodat";
451 	tests[8].tests[0].result = EBADF;
452 	tests[8].tests[0].params[0].i = 108;	/* invalid fd */
453 	tests[8].tests[0].params[1].cp = relative_file;
454 	tests[8].tests[0].params[2].m = 0666 | S_IFCHR;
455 	tests[8].tests[0].params[3].d = 15;
456 	tests[8].tests[1].result = ENOTDIR;
457 	tests[8].tests[1].params[0].i = notd_fd;
458 	tests[8].tests[1].params[1].cp = relative_file;
459 	tests[8].tests[1].params[2].m = 0666 | S_IFCHR;
460 	tests[8].tests[1].params[3].d = 15;
461 	tests[8].tests[2].result = 0;
462 	tests[8].tests[2].params[0].i = rel_fd;
463 	tests[8].tests[2].params[1].cp = nod;
464 	tests[8].tests[2].params[2].m = 0666 | S_IFCHR;
465 	tests[8].tests[2].params[3].d = 2570;
466 
467 	/* openat */
468 	tests[9].syscall = SYS_openat;
469 	tests[9].num_of_cases = 5;
470 	tests[9].name = "openat";
471 	tests[9].tests[0].result = EBADF;
472 	tests[9].tests[0].params[0].i = 106;	/* invalid fd */
473 	tests[9].tests[0].params[1].cp = relative_file;
474 	tests[9].tests[0].params[2].i = O_RDONLY;
475 	tests[9].tests[0].params[3].i = 0666;
476 	tests[9].tests[1].result = ENOTDIR;
477 	tests[9].tests[1].params[0].i = notd_fd;
478 	tests[9].tests[1].params[1].cp = relative_file;
479 	tests[9].tests[1].params[2].i = O_RDONLY;
480 	tests[9].tests[1].params[3].i = 0666;
481 	tests[9].tests[2].result = 8;		/* hardcoded fd */
482 	tests[9].tests[2].params[0].i = rel_fd;
483 	tests[9].tests[2].params[1].cp = file;
484 	tests[9].tests[2].params[2].i = O_RDONLY;
485 	tests[9].tests[2].params[3].i = 0400;
486 	tests[9].tests[3].result = 9;		/* hardcoded fd */
487 	tests[9].tests[3].params[0].i = notd_fd;
488 	tests[9].tests[3].params[1].cp = absolute_file;
489 	tests[9].tests[3].params[2].i = O_RDONLY;
490 	tests[9].tests[3].params[3].i = 0400;
491 	tests[9].tests[4].result = 10;		/* hardcoded fd */
492 	tests[9].tests[4].params[0].i = rel_fd;
493 	tests[9].tests[4].params[1].cp = newfile;
494 	tests[9].tests[4].params[2].i = O_RDONLY | O_CREAT;
495 	tests[9].tests[4].params[3].i = 0666;
496 
497 	/* readlinkat */
498 	tests[10].syscall = SYS_readlinkat;
499 	tests[10].num_of_cases = 3;
500 	tests[10].name = "readlinkat";
501 	tests[10].tests[0].result = EBADF;
502 	tests[10].tests[0].params[0].i = 106;	/* invalid fd */
503 	tests[10].tests[0].params[1].cp = relative_file;
504 	tests[10].tests[0].params[2].vp = cbuf;
505 	tests[10].tests[0].params[3].i = PATH_MAX;
506 	tests[10].tests[1].result = ENOTDIR;
507 	tests[10].tests[1].params[0].i = notd_fd;
508 	tests[10].tests[1].params[1].cp = relative_file;
509 	tests[10].tests[1].params[2].vp = cbuf;
510 	tests[10].tests[1].params[3].i = PATH_MAX;
511 	tests[10].tests[2].result = strlen(absolute_file);
512 	tests[10].tests[2].params[0].i = AT_FDCWD;
513 	tests[10].tests[2].params[1].cp = symlinkf;
514 	tests[10].tests[2].params[2].vp = cbuf;
515 	tests[10].tests[2].params[3].i = PATH_MAX;
516 
517 	/* renameat */
518 	tests[11].syscall = SYS_renameat;
519 	tests[11].num_of_cases = 5;
520 	tests[11].name = "renameat";
521 	tests[11].tests[0].result = EBADF;
522 	tests[11].tests[0].params[0].i = 106;	/* invalid fd */
523 	tests[11].tests[0].params[1].cp = file;
524 	tests[11].tests[0].params[2].i = rel_fd;
525 	tests[11].tests[0].params[3].cp = file;
526 	tests[11].tests[1].result = EBADF;
527 	tests[11].tests[1].params[0].i = rel_fd;
528 	tests[11].tests[1].params[1].cp = file;
529 	tests[11].tests[1].params[2].i = 106;	/* invalid fd */
530 	tests[11].tests[1].params[3].cp = file;
531 	tests[11].tests[2].result = ENOTDIR;
532 	tests[11].tests[2].params[0].i = notd_fd;
533 	tests[11].tests[2].params[1].cp = relative_file;
534 	tests[11].tests[2].params[2].i = rel_fd;
535 	tests[11].tests[2].params[3].cp = file;
536 	tests[11].tests[3].result = ENOTDIR;
537 	tests[11].tests[3].params[0].i = rel_fd;
538 	tests[11].tests[3].params[1].cp = file;
539 	tests[11].tests[3].params[2].i = notd_fd;
540 	tests[11].tests[3].params[3].cp = relative_file;
541 	tests[11].tests[4].result = 0;
542 	tests[11].tests[4].params[0].i = rel_fd;
543 	tests[11].tests[4].params[1].cp = newfile;
544 	tests[11].tests[4].params[2].i = AT_FDCWD;
545 	tests[11].tests[4].params[3].cp = newfile;
546 
547 	/* symlinkat */
548 	tests[12].syscall = SYS_symlinkat;
549 	tests[12].num_of_cases = 3;
550 	tests[12].name = "symlinkat";
551 	tests[12].tests[0].result = EBADF;
552 	tests[12].tests[0].params[0].cp = file;
553 	tests[12].tests[0].params[1].i = 106;	/* invalid fd */
554 	tests[12].tests[0].params[2].cp = file;
555 	tests[12].tests[1].result = ENOTDIR;
556 	tests[12].tests[1].params[0].cp = file;
557 	tests[12].tests[1].params[1].i = notd_fd;
558 	tests[12].tests[1].params[2].cp = relative_file;
559 	tests[12].tests[2].result = 0;
560 	tests[12].tests[2].params[0].cp = absolute_file;
561 	tests[12].tests[2].params[1].i = rel_fd;
562 	tests[12].tests[2].params[2].cp = newslink;
563 
564 
565 	/* unlinkat */
566 	tests[13].syscall = SYS_unlinkat;
567 	tests[13].num_of_cases = 7;
568 	tests[13].name = "unlinkat";
569 	tests[13].tests[0].result = EBADF;
570 	tests[13].tests[0].params[0].i = 106;	/* invalid fd */
571 	tests[13].tests[0].params[1].cp = relative_file;
572 	tests[13].tests[0].params[2].i = 0;
573 	tests[13].tests[1].result = ENOTDIR;
574 	tests[13].tests[1].params[0].i = notd_fd;
575 	tests[13].tests[1].params[1].cp = relative_file;
576 	tests[13].tests[1].params[2].i = 0;
577 	tests[13].tests[2].result = EINVAL;
578 	tests[13].tests[2].params[0].i = rel_fd;
579 	tests[13].tests[2].params[1].cp = file;
580 	tests[13].tests[2].params[2].i = 123;	/* invalid flag */
581 	tests[13].tests[3].result = ENOTDIR;
582 	tests[13].tests[3].params[0].i = rel_fd;
583 	tests[13].tests[3].params[1].cp = not_dir_path;
584 	tests[13].tests[3].params[2].i = AT_REMOVEDIR;
585 	tests[13].tests[4].result = ENOTEMPTY;
586 	tests[13].tests[4].params[0].i = AT_FDCWD;
587 	tests[13].tests[4].params[1].cp = relative_path;
588 	tests[13].tests[4].params[2].i = AT_REMOVEDIR;
589 	tests[13].tests[5].result = 0;
590 	tests[13].tests[5].params[0].i = rel_fd;
591 	tests[13].tests[5].params[1].cp = newdir;
592 	tests[13].tests[5].params[2].i = AT_REMOVEDIR;
593 	tests[13].tests[6].result = 0;
594 	tests[13].tests[6].params[0].i = AT_FDCWD;
595 	tests[13].tests[6].params[1].cp = newfile;
596 	tests[13].tests[6].params[2].i = 0;
597 
598 
599 	/* fexecve */
600 	tests[14].syscall = SYS_fexecve;
601 	tests[14].num_of_cases = 2;
602 	tests[14].name = "fexecve";
603 	tests[14].tests[0].result = EBADF;
604 	tests[14].tests[0].params[0].i = 106;	/* invalid fd */
605 	tests[14].tests[0].params[1].cpp = pargv;
606 	tests[14].tests[0].params[2].cpp = NULL;
607 	/* This is EXPECTED to execve /bin/date, so dont expect OK output */
608 	tests[14].tests[1].result = 0;
609 	tests[14].tests[1].params[0].i = exec_fd;
610 	tests[14].tests[1].params[1].cpp = pargv;
611 	tests[14].tests[1].params[2].cpp = NULL;
612 }
613 
614 void
615 cleanup(void)
616 {
617 	system("/bin/sh -c 'rm -rf tmp'");
618 }
619 
620 void
621 setup_once(void)
622 {
623 }
624 
625 int
626 main(int argc, char *argv[])
627 {
628 	int i,j;
629 	int error;
630 
631 	(void)argc;
632 	(void)argv;
633 
634 	setup();
635 
636 	for (i = 0; i < NUM_OF_TESTS; i++) {
637 		printf("\nTest: %s\n", tests[i].name);
638 		for (j = 0; j < tests[i].num_of_cases; j++) {
639 			error = syscall(tests[i].syscall,
640 				tests[i].tests[j].params[0],
641 				tests[i].tests[j].params[1],
642 				tests[i].tests[j].params[2],
643 				tests[i].tests[j].params[3],
644 				tests[i].tests[j].params[4]);
645 			if (error == 0) {
646 				if (tests[i].tests[j].result == 0)
647    					printf("#%i ... OK\n", j);
648 				else {
649 					printf("#%i ... BAD: ", j);
650 					printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
651 				}
652 			} else 	{
653 				if (tests[i].tests[j].result == errno)
654 					printf("#%i ... OK\n", j);
655 				else {
656 				   	if (error != tests[i].tests[j].result) {
657 						printf("#%i ... BAD: ", j);
658 						printf("expected %i, but got %i\n", tests[i].tests[j].result, error);
659 					} else
660 						printf("#%i ... OK\n", j);
661 				}
662 			}
663 		}
664 	}
665 
666 	cleanup();
667 
668 	return (0);
669 }
670