xref: /freebsd/tests/sys/audit/process-control.c (revision 2da0fcde21e0b90384f61fd50b87ea7dbd820233)
1 /*-
2  * Copyright (c) 2018 Aniket Pandey
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
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  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #include <sys/param.h>
29 #include <sys/uio.h>
30 #include <sys/ktrace.h>
31 #include <sys/mman.h>
32 #include <sys/procctl.h>
33 #include <sys/ptrace.h>
34 #include <sys/resource.h>
35 #include <sys/rtprio.h>
36 #include <sys/stat.h>
37 #include <sys/time.h>
38 #include <sys/wait.h>
39 
40 #include <atf-c.h>
41 #include <fcntl.h>
42 #include <signal.h>
43 #include <stdint.h>
44 #include <stdlib.h>
45 #include <unistd.h>
46 
47 #include "utils.h"
48 
49 static pid_t pid;
50 static int filedesc, status;
51 static struct pollfd fds[1];
52 static char pcregex[80];
53 static const char *auclass = "pc";
54 
55 
56 ATF_TC_WITH_CLEANUP(fork_success);
57 ATF_TC_HEAD(fork_success, tc)
58 {
59 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
60 					"fork(2) call");
61 }
62 
63 ATF_TC_BODY(fork_success, tc)
64 {
65 	pid = getpid();
66 	snprintf(pcregex, sizeof(pcregex), "fork.*%d.*return,success", pid);
67 
68 	FILE *pipefd = setup(fds, auclass);
69 	/* Check if fork(2) succeded. If so, exit from the child process */
70 	ATF_REQUIRE((pid = fork()) != -1);
71 	if (pid)
72 		check_audit(fds, pcregex, pipefd);
73 	else
74 		_exit(0);
75 }
76 
77 ATF_TC_CLEANUP(fork_success, tc)
78 {
79 	cleanup();
80 }
81 
82 /*
83  * No fork(2) in failure mode since possibilities for failure are only when
84  * user is not privileged or when the number of processes exceed KERN_MAXPROC.
85  */
86 
87 
88 ATF_TC_WITH_CLEANUP(rfork_success);
89 ATF_TC_HEAD(rfork_success, tc)
90 {
91 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
92 					"rfork(2) call");
93 }
94 
95 ATF_TC_BODY(rfork_success, tc)
96 {
97 	pid = getpid();
98 	snprintf(pcregex, sizeof(pcregex), "rfork.*%d.*return,success", pid);
99 
100 	FILE *pipefd = setup(fds, auclass);
101 	ATF_REQUIRE((pid = rfork(RFPROC)) != -1);
102 	if (pid)
103 		check_audit(fds, pcregex, pipefd);
104 	else
105 		_exit(0);
106 }
107 
108 ATF_TC_CLEANUP(rfork_success, tc)
109 {
110 	cleanup();
111 }
112 
113 
114 ATF_TC_WITH_CLEANUP(rfork_failure);
115 ATF_TC_HEAD(rfork_failure, tc)
116 {
117 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
118 					"rfork(2) call");
119 }
120 
121 ATF_TC_BODY(rfork_failure, tc)
122 {
123 	pid = getpid();
124 	snprintf(pcregex, sizeof(pcregex), "rfork.*%d.*return,failure", pid);
125 
126 	FILE *pipefd = setup(fds, auclass);
127 	/* Failure reason: Invalid argument */
128 	ATF_REQUIRE_EQ(-1, rfork(-1));
129 	check_audit(fds, pcregex, pipefd);
130 }
131 
132 ATF_TC_CLEANUP(rfork_failure, tc)
133 {
134 	cleanup();
135 }
136 
137 
138 ATF_TC_WITH_CLEANUP(wait4_success);
139 ATF_TC_HEAD(wait4_success, tc)
140 {
141 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
142 					"wait4(2) call");
143 }
144 
145 ATF_TC_BODY(wait4_success, tc)
146 {
147 	pid = getpid();
148 	snprintf(pcregex, sizeof(pcregex), "wait4.*%d.*return,success", pid);
149 
150 	ATF_REQUIRE((pid = fork()) != -1);
151 	if (pid) {
152 		FILE *pipefd = setup(fds, auclass);
153 		/* wpid = -1 : Wait for any child process */
154 		ATF_REQUIRE(wait4(-1, &status, 0, NULL) != -1);
155 		check_audit(fds, pcregex, pipefd);
156 	}
157 	else
158 		_exit(0);
159 }
160 
161 ATF_TC_CLEANUP(wait4_success, tc)
162 {
163 	cleanup();
164 }
165 
166 
167 ATF_TC_WITH_CLEANUP(wait4_failure);
168 ATF_TC_HEAD(wait4_failure, tc)
169 {
170 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
171 					"wait4(2) call");
172 }
173 
174 ATF_TC_BODY(wait4_failure, tc)
175 {
176 	pid = getpid();
177 	snprintf(pcregex, sizeof(pcregex), "wait4.*%d.*return,failure", pid);
178 
179 	FILE *pipefd = setup(fds, auclass);
180 	/* Failure reason: No child process to wait for */
181 	ATF_REQUIRE_EQ(-1, wait4(-1, NULL, 0, NULL));
182 	check_audit(fds, pcregex, pipefd);
183 }
184 
185 ATF_TC_CLEANUP(wait4_failure, tc)
186 {
187 	cleanup();
188 }
189 
190 
191 ATF_TC_WITH_CLEANUP(wait6_success);
192 ATF_TC_HEAD(wait6_success, tc)
193 {
194 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
195 					"wait6(2) call");
196 }
197 
198 ATF_TC_BODY(wait6_success, tc)
199 {
200 	pid = getpid();
201 	snprintf(pcregex, sizeof(pcregex), "wait6.*%d.*return,success", pid);
202 
203 	ATF_REQUIRE((pid = fork()) != -1);
204 	if (pid) {
205 		FILE *pipefd = setup(fds, auclass);
206 		ATF_REQUIRE(wait6(P_ALL, 0, &status, WEXITED, NULL,NULL) != -1);
207 		check_audit(fds, pcregex, pipefd);
208 	}
209 	else
210 		_exit(0);
211 }
212 
213 ATF_TC_CLEANUP(wait6_success, tc)
214 {
215 	cleanup();
216 }
217 
218 
219 ATF_TC_WITH_CLEANUP(wait6_failure);
220 ATF_TC_HEAD(wait6_failure, tc)
221 {
222 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
223 					"wait6(2) call");
224 }
225 
226 ATF_TC_BODY(wait6_failure, tc)
227 {
228 	pid = getpid();
229 	snprintf(pcregex, sizeof(pcregex), "wait6.*%d.*return,failure", pid);
230 
231 	FILE *pipefd = setup(fds, auclass);
232 	/* Failure reason: Invalid argument */
233 	ATF_REQUIRE_EQ(-1, wait6(0, 0, NULL, 0, NULL, NULL));
234 	check_audit(fds, pcregex, pipefd);
235 }
236 
237 ATF_TC_CLEANUP(wait6_failure, tc)
238 {
239 	cleanup();
240 }
241 
242 
243 ATF_TC_WITH_CLEANUP(kill_success);
244 ATF_TC_HEAD(kill_success, tc)
245 {
246 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
247 					"kill(2) call");
248 }
249 
250 ATF_TC_BODY(kill_success, tc)
251 {
252 	pid = getpid();
253 	snprintf(pcregex, sizeof(pcregex), "kill.*%d.*return,success", pid);
254 
255 	FILE *pipefd = setup(fds, auclass);
256 	/* Don't send any signal to anyone, live in peace! */
257 	ATF_REQUIRE_EQ(0, kill(0, 0));
258 	check_audit(fds, pcregex, pipefd);
259 }
260 
261 ATF_TC_CLEANUP(kill_success, tc)
262 {
263 	cleanup();
264 }
265 
266 
267 ATF_TC_WITH_CLEANUP(kill_failure);
268 ATF_TC_HEAD(kill_failure, tc)
269 {
270 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
271 					"kill(2) call");
272 }
273 
274 ATF_TC_BODY(kill_failure, tc)
275 {
276 	pid = getpid();
277 	snprintf(pcregex, sizeof(pcregex), "kill.*%d.*return,failure", pid);
278 
279 	FILE *pipefd = setup(fds, auclass);
280 	/*
281 	 * Failure reason: Non existent process with PID '-2'
282 	 * Note: '-1' is not used as it means sending no signal to
283 	 * all non-system processes: A successful invocation
284 	 */
285 	ATF_REQUIRE_EQ(-1, kill(0, -2));
286 	check_audit(fds, pcregex, pipefd);
287 }
288 
289 ATF_TC_CLEANUP(kill_failure, tc)
290 {
291 	cleanup();
292 }
293 
294 
295 ATF_TC_WITH_CLEANUP(chdir_success);
296 ATF_TC_HEAD(chdir_success, tc)
297 {
298 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
299 					"chdir(2) call");
300 }
301 
302 ATF_TC_BODY(chdir_success, tc)
303 {
304 	pid = getpid();
305 	snprintf(pcregex, sizeof(pcregex), "chdir.*/.*%d.*return,success", pid);
306 
307 	FILE *pipefd = setup(fds, auclass);
308 	ATF_REQUIRE_EQ(0, chdir("/"));
309 	check_audit(fds, pcregex, pipefd);
310 }
311 
312 ATF_TC_CLEANUP(chdir_success, tc)
313 {
314 	cleanup();
315 }
316 
317 
318 ATF_TC_WITH_CLEANUP(chdir_failure);
319 ATF_TC_HEAD(chdir_failure, tc)
320 {
321 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
322 					"chdir(2) call");
323 }
324 
325 ATF_TC_BODY(chdir_failure, tc)
326 {
327 	pid = getpid();
328 	snprintf(pcregex, sizeof(pcregex), "chdir.*%d.*return,failure", pid);
329 
330 	FILE *pipefd = setup(fds, auclass);
331 	/* Failure reason: Bad address */
332 	ATF_REQUIRE_EQ(-1, chdir(NULL));
333 	check_audit(fds, pcregex, pipefd);
334 }
335 
336 ATF_TC_CLEANUP(chdir_failure, tc)
337 {
338 	cleanup();
339 }
340 
341 
342 ATF_TC_WITH_CLEANUP(fchdir_success);
343 ATF_TC_HEAD(fchdir_success, tc)
344 {
345 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
346 					"fchdir(2) call");
347 }
348 
349 ATF_TC_BODY(fchdir_success, tc)
350 {
351 	/* Build an absolute path to the test-case directory */
352 	char dirpath[50];
353 	ATF_REQUIRE(getcwd(dirpath, sizeof(dirpath)) != NULL);
354 	ATF_REQUIRE((filedesc = open(dirpath, O_RDONLY)) != -1);
355 
356 	/* Audit record generated by fchdir(2) does not contain filedesc */
357 	pid = getpid();
358 	snprintf(pcregex, sizeof(pcregex), "fchdir.*%d.*return,success", pid);
359 
360 	FILE *pipefd = setup(fds, auclass);
361 	ATF_REQUIRE_EQ(0, fchdir(filedesc));
362 	check_audit(fds, pcregex, pipefd);
363 	close(filedesc);
364 }
365 
366 ATF_TC_CLEANUP(fchdir_success, tc)
367 {
368 	cleanup();
369 }
370 
371 
372 ATF_TC_WITH_CLEANUP(fchdir_failure);
373 ATF_TC_HEAD(fchdir_failure, tc)
374 {
375 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
376 					"fchdir(2) call");
377 }
378 
379 ATF_TC_BODY(fchdir_failure, tc)
380 {
381 	pid = getpid();
382 	snprintf(pcregex, sizeof(pcregex), "fchdir.*%d.*return,failure", pid);
383 
384 	FILE *pipefd = setup(fds, auclass);
385 	/* Failure reason: Bad directory address */
386 	ATF_REQUIRE_EQ(-1, fchdir(-1));
387 	check_audit(fds, pcregex, pipefd);
388 }
389 
390 ATF_TC_CLEANUP(fchdir_failure, tc)
391 {
392 	cleanup();
393 }
394 
395 
396 ATF_TC_WITH_CLEANUP(chroot_success);
397 ATF_TC_HEAD(chroot_success, tc)
398 {
399 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
400 					"chroot(2) call");
401 }
402 
403 ATF_TC_BODY(chroot_success, tc)
404 {
405 	pid = getpid();
406 	snprintf(pcregex, sizeof(pcregex), "chroot.*%d.*return,success", pid);
407 
408 	FILE *pipefd = setup(fds, auclass);
409 	/* We don't want to change the root directory, hence '/' */
410 	ATF_REQUIRE_EQ(0, chroot("/"));
411 	check_audit(fds, pcregex, pipefd);
412 }
413 
414 ATF_TC_CLEANUP(chroot_success, tc)
415 {
416 	cleanup();
417 }
418 
419 
420 ATF_TC_WITH_CLEANUP(chroot_failure);
421 ATF_TC_HEAD(chroot_failure, tc)
422 {
423 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
424 					"chroot(2) call");
425 }
426 
427 ATF_TC_BODY(chroot_failure, tc)
428 {
429 	pid = getpid();
430 	snprintf(pcregex, sizeof(pcregex), "chroot.*%d.*return,failure", pid);
431 
432 	FILE *pipefd = setup(fds, auclass);
433 	ATF_REQUIRE_EQ(-1, chroot(NULL));
434 	check_audit(fds, pcregex, pipefd);
435 }
436 
437 ATF_TC_CLEANUP(chroot_failure, tc)
438 {
439 	cleanup();
440 }
441 
442 
443 ATF_TC_WITH_CLEANUP(umask_success);
444 ATF_TC_HEAD(umask_success, tc)
445 {
446 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
447 					"umask(2) call");
448 }
449 
450 ATF_TC_BODY(umask_success, tc)
451 {
452 	pid = getpid();
453 	snprintf(pcregex, sizeof(pcregex), "umask.*%d.*return,success", pid);
454 
455 	FILE *pipefd = setup(fds, auclass);
456 	umask(0);
457 	check_audit(fds, pcregex, pipefd);
458 }
459 
460 ATF_TC_CLEANUP(umask_success, tc)
461 {
462 	cleanup();
463 }
464 
465 /*
466  * umask(2) system call never fails. Hence, no test case for failure mode
467  */
468 
469 
470 ATF_TC_WITH_CLEANUP(setuid_success);
471 ATF_TC_HEAD(setuid_success, tc)
472 {
473 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
474 					"setuid(2) call");
475 }
476 
477 ATF_TC_BODY(setuid_success, tc)
478 {
479 	pid = getpid();
480 	snprintf(pcregex, sizeof(pcregex), "setuid.*%d.*return,success", pid);
481 
482 	FILE *pipefd = setup(fds, auclass);
483 	/* Since we're privileged, we'll let ourselves be privileged! */
484 	ATF_REQUIRE_EQ(0, setuid(0));
485 	check_audit(fds, pcregex, pipefd);
486 }
487 
488 ATF_TC_CLEANUP(setuid_success, tc)
489 {
490 	cleanup();
491 }
492 
493 /*
494  * setuid(2) fails only when the current user is not root. So no test case for
495  * failure mode since the required_user="root"
496  */
497 
498 
499 ATF_TC_WITH_CLEANUP(seteuid_success);
500 ATF_TC_HEAD(seteuid_success, tc)
501 {
502 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
503 					"seteuid(2) call");
504 }
505 
506 ATF_TC_BODY(seteuid_success, tc)
507 {
508 	pid = getpid();
509 	snprintf(pcregex, sizeof(pcregex), "seteuid.*%d.*return,success", pid);
510 
511 	FILE *pipefd = setup(fds, auclass);
512 	/* This time, we'll let ourselves be 'effectively' privileged! */
513 	ATF_REQUIRE_EQ(0, seteuid(0));
514 	check_audit(fds, pcregex, pipefd);
515 }
516 
517 ATF_TC_CLEANUP(seteuid_success, tc)
518 {
519 	cleanup();
520 }
521 
522 /*
523  * seteuid(2) fails only when the current user is not root. So no test case for
524  * failure mode since the required_user="root"
525  */
526 
527 
528 ATF_TC_WITH_CLEANUP(setgid_success);
529 ATF_TC_HEAD(setgid_success, tc)
530 {
531 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
532 					"setgid(2) call");
533 }
534 
535 ATF_TC_BODY(setgid_success, tc)
536 {
537 	pid = getpid();
538 	snprintf(pcregex, sizeof(pcregex), "setgid.*%d.*return,success", pid);
539 
540 	FILE *pipefd = setup(fds, auclass);
541 	ATF_REQUIRE_EQ(0, setgid(0));
542 	check_audit(fds, pcregex, pipefd);
543 }
544 
545 ATF_TC_CLEANUP(setgid_success, tc)
546 {
547 	cleanup();
548 }
549 
550 /*
551  * setgid(2) fails only when the current user is not root. So no test case for
552  * failure mode since the required_user="root"
553  */
554 
555 
556 ATF_TC_WITH_CLEANUP(setegid_success);
557 ATF_TC_HEAD(setegid_success, tc)
558 {
559 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
560 					"setegid(2) call");
561 }
562 
563 ATF_TC_BODY(setegid_success, tc)
564 {
565 	pid = getpid();
566 	snprintf(pcregex, sizeof(pcregex), "setegid.*%d.*return,success", pid);
567 
568 	FILE *pipefd = setup(fds, auclass);
569 	ATF_REQUIRE_EQ(0, setegid(0));
570 	check_audit(fds, pcregex, pipefd);
571 }
572 
573 ATF_TC_CLEANUP(setegid_success, tc)
574 {
575 	cleanup();
576 }
577 
578 /*
579  * setegid(2) fails only when the current user is not root. So no test case for
580  * failure mode since the required_user="root"
581  */
582 
583 
584 ATF_TC_WITH_CLEANUP(setregid_success);
585 ATF_TC_HEAD(setregid_success, tc)
586 {
587 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
588 					"setregid(2) call");
589 }
590 
591 ATF_TC_BODY(setregid_success, tc)
592 {
593 	pid = getpid();
594 	snprintf(pcregex, sizeof(pcregex), "setregid.*%d.*return,success", pid);
595 
596 	FILE *pipefd = setup(fds, auclass);
597 	/* setregid(-1, -1) does not change any real or effective GIDs */
598 	ATF_REQUIRE_EQ(0, setregid(-1, -1));
599 	check_audit(fds, pcregex, pipefd);
600 }
601 
602 ATF_TC_CLEANUP(setregid_success, tc)
603 {
604 	cleanup();
605 }
606 
607 /*
608  * setregid(2) fails only when the current user is not root. So no test case for
609  * failure mode since the required_user="root"
610  */
611 
612 
613 ATF_TC_WITH_CLEANUP(setreuid_success);
614 ATF_TC_HEAD(setreuid_success, tc)
615 {
616 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
617 					"setreuid(2) call");
618 }
619 
620 ATF_TC_BODY(setreuid_success, tc)
621 {
622 	pid = getpid();
623 	snprintf(pcregex, sizeof(pcregex), "setreuid.*%d.*return,success", pid);
624 
625 	FILE *pipefd = setup(fds, auclass);
626 	/* setreuid(-1, -1) does not change any real or effective UIDs */
627 	ATF_REQUIRE_EQ(0, setreuid(-1, -1));
628 	check_audit(fds, pcregex, pipefd);
629 }
630 
631 ATF_TC_CLEANUP(setreuid_success, tc)
632 {
633 	cleanup();
634 }
635 
636 /*
637  * setregid(2) fails only when the current user is not root. So no test case for
638  * failure mode since the required_user="root"
639  */
640 
641 
642 ATF_TC_WITH_CLEANUP(setresuid_success);
643 ATF_TC_HEAD(setresuid_success, tc)
644 {
645 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
646 					"setresuid(2) call");
647 }
648 
649 ATF_TC_BODY(setresuid_success, tc)
650 {
651 	pid = getpid();
652 	snprintf(pcregex, sizeof(pcregex), "setresuid.*%d.*return,success", pid);
653 
654 	FILE *pipefd = setup(fds, auclass);
655 	/* setresuid(-1, -1, -1) does not change real, effective & saved UIDs */
656 	ATF_REQUIRE_EQ(0, setresuid(-1, -1, -1));
657 	check_audit(fds, pcregex, pipefd);
658 }
659 
660 ATF_TC_CLEANUP(setresuid_success, tc)
661 {
662 	cleanup();
663 }
664 
665 /*
666  * setresuid(2) fails only when the current user is not root. So no test case
667  * for failure mode since the required_user="root"
668  */
669 
670 
671 ATF_TC_WITH_CLEANUP(setresgid_success);
672 ATF_TC_HEAD(setresgid_success, tc)
673 {
674 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
675 					"setresgid(2) call");
676 }
677 
678 ATF_TC_BODY(setresgid_success, tc)
679 {
680 	pid = getpid();
681 	snprintf(pcregex, sizeof(pcregex), "setresgid.*%d.*ret.*success", pid);
682 
683 	FILE *pipefd = setup(fds, auclass);
684 	/* setresgid(-1, -1, -1) does not change real, effective & saved GIDs */
685 	ATF_REQUIRE_EQ(0, setresgid(-1, -1, -1));
686 	check_audit(fds, pcregex, pipefd);
687 }
688 
689 ATF_TC_CLEANUP(setresgid_success, tc)
690 {
691 	cleanup();
692 }
693 
694 /*
695  * setresgid(2) fails only when the current user is not root. So no test case
696  * for failure mode since the required_user="root"
697  */
698 
699 
700 ATF_TC_WITH_CLEANUP(getresuid_success);
701 ATF_TC_HEAD(getresuid_success, tc)
702 {
703 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
704 					"getresuid(2) call");
705 }
706 
707 ATF_TC_BODY(getresuid_success, tc)
708 {
709 	pid = getpid();
710 	snprintf(pcregex, sizeof(pcregex), "getresuid.*%d.*ret.*success", pid);
711 
712 	FILE *pipefd = setup(fds, auclass);
713 	ATF_REQUIRE_EQ(0, getresuid(NULL, NULL, NULL));
714 	check_audit(fds, pcregex, pipefd);
715 }
716 
717 ATF_TC_CLEANUP(getresuid_success, tc)
718 {
719 	cleanup();
720 }
721 
722 
723 ATF_TC_WITH_CLEANUP(getresuid_failure);
724 ATF_TC_HEAD(getresuid_failure, tc)
725 {
726 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
727 					"getresuid(2) call");
728 }
729 
730 ATF_TC_BODY(getresuid_failure, tc)
731 {
732 	pid = getpid();
733 	snprintf(pcregex, sizeof(pcregex), "getresuid.*%d.*ret.*failure", pid);
734 
735 	FILE *pipefd = setup(fds, auclass);
736 	/* Failure reason: Invalid address "-1" */
737 	ATF_REQUIRE_EQ(-1, getresuid((uid_t *)-1, NULL, NULL));
738 	check_audit(fds, pcregex, pipefd);
739 }
740 
741 ATF_TC_CLEANUP(getresuid_failure, tc)
742 {
743 	cleanup();
744 }
745 
746 
747 ATF_TC_WITH_CLEANUP(getresgid_success);
748 ATF_TC_HEAD(getresgid_success, tc)
749 {
750 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
751 					"getresgid(2) call");
752 }
753 
754 ATF_TC_BODY(getresgid_success, tc)
755 {
756 	pid = getpid();
757 	snprintf(pcregex, sizeof(pcregex), "getresgid.*%d.*ret.*success", pid);
758 
759 	FILE *pipefd = setup(fds, auclass);
760 	ATF_REQUIRE_EQ(0, getresgid(NULL, NULL, NULL));
761 	check_audit(fds, pcregex, pipefd);
762 }
763 
764 ATF_TC_CLEANUP(getresgid_success, tc)
765 {
766 	cleanup();
767 }
768 
769 
770 ATF_TC_WITH_CLEANUP(getresgid_failure);
771 ATF_TC_HEAD(getresgid_failure, tc)
772 {
773 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
774 					"getresgid(2) call");
775 }
776 
777 ATF_TC_BODY(getresgid_failure, tc)
778 {
779 	pid = getpid();
780 	snprintf(pcregex, sizeof(pcregex), "getresgid.*%d.*ret.*failure", pid);
781 
782 	FILE *pipefd = setup(fds, auclass);
783 	/* Failure reason: Invalid address "-1" */
784 	ATF_REQUIRE_EQ(-1, getresgid((gid_t *)-1, NULL, NULL));
785 	check_audit(fds, pcregex, pipefd);
786 }
787 
788 ATF_TC_CLEANUP(getresgid_failure, tc)
789 {
790 	cleanup();
791 }
792 
793 
794 ATF_TC_WITH_CLEANUP(setpriority_success);
795 ATF_TC_HEAD(setpriority_success, tc)
796 {
797 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
798 					"setpriority(2) call");
799 }
800 
801 ATF_TC_BODY(setpriority_success, tc)
802 {
803 	pid = getpid();
804 	snprintf(pcregex, sizeof(pcregex), "setpriority.*%d.*success", pid);
805 
806 	FILE *pipefd = setup(fds, auclass);
807 	ATF_REQUIRE_EQ(0, setpriority(PRIO_PROCESS, 0, 0));
808 	check_audit(fds, pcregex, pipefd);
809 }
810 
811 ATF_TC_CLEANUP(setpriority_success, tc)
812 {
813 	cleanup();
814 }
815 
816 
817 ATF_TC_WITH_CLEANUP(setpriority_failure);
818 ATF_TC_HEAD(setpriority_failure, tc)
819 {
820 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
821 					"setpriority(2) call");
822 }
823 
824 ATF_TC_BODY(setpriority_failure, tc)
825 {
826 	pid = getpid();
827 	snprintf(pcregex, sizeof(pcregex), "setpriority.*%d.*failure", pid);
828 
829 	FILE *pipefd = setup(fds, auclass);
830 	ATF_REQUIRE_EQ(-1, setpriority(-1, -1, -1));
831 	check_audit(fds, pcregex, pipefd);
832 }
833 
834 ATF_TC_CLEANUP(setpriority_failure, tc)
835 {
836 	cleanup();
837 }
838 
839 
840 ATF_TC_WITH_CLEANUP(setgroups_success);
841 ATF_TC_HEAD(setgroups_success, tc)
842 {
843 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
844 					"setgroups(2) call");
845 }
846 
847 ATF_TC_BODY(setgroups_success, tc)
848 {
849 	gid_t gids[5];
850 	pid = getpid();
851 	snprintf(pcregex, sizeof(pcregex), "setgroups.*%d.*ret.*success", pid);
852 	/* Retrieve the current group access list to be used with setgroups */
853 	ATF_REQUIRE(getgroups(sizeof(gids)/sizeof(gids[0]), gids) != -1);
854 
855 	FILE *pipefd = setup(fds, auclass);
856 	ATF_REQUIRE_EQ(0, setgroups(sizeof(gids)/sizeof(gids[0]), gids));
857 	check_audit(fds, pcregex, pipefd);
858 }
859 
860 ATF_TC_CLEANUP(setgroups_success, tc)
861 {
862 	cleanup();
863 }
864 
865 
866 ATF_TC_WITH_CLEANUP(setgroups_failure);
867 ATF_TC_HEAD(setgroups_failure, tc)
868 {
869 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
870 					"setgroups(2) call");
871 }
872 
873 ATF_TC_BODY(setgroups_failure, tc)
874 {
875 	pid = getpid();
876 	snprintf(pcregex, sizeof(pcregex), "setgroups.*%d.*ret.*failure", pid);
877 
878 	FILE *pipefd = setup(fds, auclass);
879 	ATF_REQUIRE_EQ(-1, setgroups(-1, NULL));
880 	check_audit(fds, pcregex, pipefd);
881 }
882 
883 ATF_TC_CLEANUP(setgroups_failure, tc)
884 {
885 	cleanup();
886 }
887 
888 
889 ATF_TC_WITH_CLEANUP(setpgrp_success);
890 ATF_TC_HEAD(setpgrp_success, tc)
891 {
892 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
893 					"setpgrp(2) call");
894 }
895 
896 ATF_TC_BODY(setpgrp_success, tc)
897 {
898 	/* Main procedure is carried out from within the child process */
899 	ATF_REQUIRE((pid = fork()) != -1);
900 	if (pid) {
901 		ATF_REQUIRE(wait(&status) != -1);
902 	} else {
903 		pid = getpid();
904 		snprintf(pcregex, sizeof(pcregex), "setpgrp.*%d.*success", pid);
905 
906 		FILE *pipefd = setup(fds, auclass);
907 		ATF_REQUIRE_EQ(0, setpgrp(0, 0));
908 		check_audit(fds, pcregex, pipefd);
909 	}
910 }
911 
912 ATF_TC_CLEANUP(setpgrp_success, tc)
913 {
914 	cleanup();
915 }
916 
917 
918 ATF_TC_WITH_CLEANUP(setpgrp_failure);
919 ATF_TC_HEAD(setpgrp_failure, tc)
920 {
921 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
922 					"setpgrp(2) call");
923 }
924 
925 ATF_TC_BODY(setpgrp_failure, tc)
926 {
927 	pid = getpid();
928 	snprintf(pcregex, sizeof(pcregex), "setpgrp.*%d.*return,failure", pid);
929 
930 	FILE *pipefd = setup(fds, auclass);
931 	ATF_REQUIRE_EQ(-1, setpgrp(-1, -1));
932 	check_audit(fds, pcregex, pipefd);
933 }
934 
935 ATF_TC_CLEANUP(setpgrp_failure, tc)
936 {
937 	cleanup();
938 }
939 
940 
941 ATF_TC_WITH_CLEANUP(setsid_success);
942 ATF_TC_HEAD(setsid_success, tc)
943 {
944 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
945 					"setsid(2) call");
946 }
947 
948 ATF_TC_BODY(setsid_success, tc)
949 {
950 	/* Main procedure is carried out from within the child process */
951 	ATF_REQUIRE((pid = fork()) != -1);
952 	if (pid) {
953 		ATF_REQUIRE(wait(&status) != -1);
954 	} else {
955 		pid = getpid();
956 		snprintf(pcregex, sizeof(pcregex), "setsid.*%d.*success", pid);
957 
958 		FILE *pipefd = setup(fds, auclass);
959 		ATF_REQUIRE(setsid() != -1);
960 		check_audit(fds, pcregex, pipefd);
961 	}
962 }
963 
964 ATF_TC_CLEANUP(setsid_success, tc)
965 {
966 	cleanup();
967 }
968 
969 
970 ATF_TC_WITH_CLEANUP(setsid_failure);
971 ATF_TC_HEAD(setsid_failure, tc)
972 {
973 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
974 					"setsid(2) call");
975 }
976 
977 ATF_TC_BODY(setsid_failure, tc)
978 {
979 	pid = getpid();
980 	snprintf(pcregex, sizeof(pcregex), "setsid.*%d.*return,failure", pid);
981 
982 	/*
983 	 * Here, we are intentionally ignoring the output of the setsid()
984 	 * call because it may or may not be a process leader already. But it
985 	 * ensures that the next invocation of setsid() will definitely fail.
986 	 */
987 	setsid();
988 	FILE *pipefd = setup(fds, auclass);
989 	/*
990 	 * Failure reason: [EPERM] Creating a new session is not permitted
991 	 * as the PID of calling process matches the PGID of a process group
992 	 * created by premature setsid() call.
993 	 */
994 	ATF_REQUIRE_EQ(-1, setsid());
995 	check_audit(fds, pcregex, pipefd);
996 }
997 
998 ATF_TC_CLEANUP(setsid_failure, tc)
999 {
1000 	cleanup();
1001 }
1002 
1003 
1004 ATF_TC_WITH_CLEANUP(setrlimit_success);
1005 ATF_TC_HEAD(setrlimit_success, tc)
1006 {
1007 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1008 					"setrlimit(2) call");
1009 }
1010 
1011 ATF_TC_BODY(setrlimit_success, tc)
1012 {
1013 	struct rlimit rlp;
1014 	pid = getpid();
1015 	snprintf(pcregex, sizeof(pcregex), "setrlimit.*%d.*ret.*success", pid);
1016 	/* Retrieve the system resource consumption limit to be used later on */
1017 	ATF_REQUIRE_EQ(0, getrlimit(RLIMIT_FSIZE, &rlp));
1018 
1019 	FILE *pipefd = setup(fds, auclass);
1020 	ATF_REQUIRE_EQ(0, setrlimit(RLIMIT_FSIZE, &rlp));
1021 	check_audit(fds, pcregex, pipefd);
1022 }
1023 
1024 ATF_TC_CLEANUP(setrlimit_success, tc)
1025 {
1026 	cleanup();
1027 }
1028 
1029 
1030 ATF_TC_WITH_CLEANUP(setrlimit_failure);
1031 ATF_TC_HEAD(setrlimit_failure, tc)
1032 {
1033 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1034 					"setrlimit(2) call");
1035 }
1036 
1037 ATF_TC_BODY(setrlimit_failure, tc)
1038 {
1039 	pid = getpid();
1040 	snprintf(pcregex, sizeof(pcregex), "setrlimit.*%d.*ret.*failure", pid);
1041 
1042 	FILE *pipefd = setup(fds, auclass);
1043 	ATF_REQUIRE_EQ(-1, setrlimit(RLIMIT_FSIZE, NULL));
1044 	check_audit(fds, pcregex, pipefd);
1045 }
1046 
1047 ATF_TC_CLEANUP(setrlimit_failure, tc)
1048 {
1049 	cleanup();
1050 }
1051 
1052 
1053 ATF_TC_WITH_CLEANUP(mlock_success);
1054 ATF_TC_HEAD(mlock_success, tc)
1055 {
1056 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1057 					"mlock(2) call");
1058 }
1059 
1060 ATF_TC_BODY(mlock_success, tc)
1061 {
1062 	pid = getpid();
1063 	snprintf(pcregex, sizeof(pcregex), "mlock.*%d.*return,success", pid);
1064 
1065 	FILE *pipefd = setup(fds, auclass);
1066 	ATF_REQUIRE_EQ(0, mlock(NULL, 0));
1067 	check_audit(fds, pcregex, pipefd);
1068 }
1069 
1070 ATF_TC_CLEANUP(mlock_success, tc)
1071 {
1072 	cleanup();
1073 }
1074 
1075 
1076 ATF_TC_WITH_CLEANUP(mlock_failure);
1077 ATF_TC_HEAD(mlock_failure, tc)
1078 {
1079 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1080 					"mlock(2) call");
1081 }
1082 
1083 ATF_TC_BODY(mlock_failure, tc)
1084 {
1085 	pid = getpid();
1086 	snprintf(pcregex, sizeof(pcregex), "mlock.*%d.*return,failure", pid);
1087 
1088 	FILE *pipefd = setup(fds, auclass);
1089 	ATF_REQUIRE_EQ(-1, mlock((void *)(-1), -1));
1090 	check_audit(fds, pcregex, pipefd);
1091 }
1092 
1093 ATF_TC_CLEANUP(mlock_failure, tc)
1094 {
1095 	cleanup();
1096 }
1097 
1098 
1099 ATF_TC_WITH_CLEANUP(munlock_success);
1100 ATF_TC_HEAD(munlock_success, tc)
1101 {
1102 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1103 					"munlock(2) call");
1104 }
1105 
1106 ATF_TC_BODY(munlock_success, tc)
1107 {
1108 	pid = getpid();
1109 	snprintf(pcregex, sizeof(pcregex), "munlock.*%d.*return,success", pid);
1110 
1111 	FILE *pipefd = setup(fds, auclass);
1112 	ATF_REQUIRE_EQ(0, munlock(NULL, 0));
1113 	check_audit(fds, pcregex, pipefd);
1114 }
1115 
1116 ATF_TC_CLEANUP(munlock_success, tc)
1117 {
1118 	cleanup();
1119 }
1120 
1121 
1122 ATF_TC_WITH_CLEANUP(munlock_failure);
1123 ATF_TC_HEAD(munlock_failure, tc)
1124 {
1125 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1126 					"munlock(2) call");
1127 }
1128 
1129 ATF_TC_BODY(munlock_failure, tc)
1130 {
1131 	pid = getpid();
1132 	snprintf(pcregex, sizeof(pcregex), "munlock.*%d.*return,failure", pid);
1133 
1134 	FILE *pipefd = setup(fds, auclass);
1135 	ATF_REQUIRE_EQ(-1, munlock((void *)(-1), -1));
1136 	check_audit(fds, pcregex, pipefd);
1137 }
1138 
1139 ATF_TC_CLEANUP(munlock_failure, tc)
1140 {
1141 	cleanup();
1142 }
1143 
1144 
1145 ATF_TC_WITH_CLEANUP(minherit_success);
1146 ATF_TC_HEAD(minherit_success, tc)
1147 {
1148 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1149 					"minherit(2) call");
1150 }
1151 
1152 ATF_TC_BODY(minherit_success, tc)
1153 {
1154 	pid = getpid();
1155 	snprintf(pcregex, sizeof(pcregex), "minherit.*%d.*return,success", pid);
1156 
1157 	FILE *pipefd = setup(fds, auclass);
1158 	ATF_REQUIRE_EQ(0, minherit(NULL, 0, INHERIT_ZERO));
1159 	check_audit(fds, pcregex, pipefd);
1160 }
1161 
1162 ATF_TC_CLEANUP(minherit_success, tc)
1163 {
1164 	cleanup();
1165 }
1166 
1167 
1168 ATF_TC_WITH_CLEANUP(minherit_failure);
1169 ATF_TC_HEAD(minherit_failure, tc)
1170 {
1171 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1172 					"minherit(2) call");
1173 }
1174 
1175 ATF_TC_BODY(minherit_failure, tc)
1176 {
1177 	pid = getpid();
1178 	snprintf(pcregex, sizeof(pcregex), "minherit.*%d.*return,failure", pid);
1179 
1180 	FILE *pipefd = setup(fds, auclass);
1181 	ATF_REQUIRE_EQ(-1, minherit((void *)(-1), -1, 0));
1182 	check_audit(fds, pcregex, pipefd);
1183 }
1184 
1185 ATF_TC_CLEANUP(minherit_failure, tc)
1186 {
1187 	cleanup();
1188 }
1189 
1190 
1191 ATF_TC_WITH_CLEANUP(setlogin_success);
1192 ATF_TC_HEAD(setlogin_success, tc)
1193 {
1194 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1195 					"setlogin(2) call");
1196 }
1197 
1198 ATF_TC_BODY(setlogin_success, tc)
1199 {
1200 	char *name;
1201 	pid = getpid();
1202 	snprintf(pcregex, sizeof(pcregex), "setlogin.*%d.*return,success", pid);
1203 
1204 	/* Retrieve the current user's login name to be used with setlogin(2) */
1205 	ATF_REQUIRE((name = getlogin()) != NULL);
1206 	FILE *pipefd = setup(fds, auclass);
1207 	ATF_REQUIRE_EQ(0, setlogin(name));
1208 	check_audit(fds, pcregex, pipefd);
1209 }
1210 
1211 ATF_TC_CLEANUP(setlogin_success, tc)
1212 {
1213 	cleanup();
1214 }
1215 
1216 
1217 ATF_TC_WITH_CLEANUP(setlogin_failure);
1218 ATF_TC_HEAD(setlogin_failure, tc)
1219 {
1220 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1221 					"setlogin(2) call");
1222 }
1223 
1224 ATF_TC_BODY(setlogin_failure, tc)
1225 {
1226 	pid = getpid();
1227 	snprintf(pcregex, sizeof(pcregex), "setlogin.*%d.*return,failure", pid);
1228 
1229 	FILE *pipefd = setup(fds, auclass);
1230 	ATF_REQUIRE_EQ(-1, setlogin(NULL));
1231 	check_audit(fds, pcregex, pipefd);
1232 }
1233 
1234 ATF_TC_CLEANUP(setlogin_failure, tc)
1235 {
1236 	cleanup();
1237 }
1238 
1239 
1240 ATF_TC_WITH_CLEANUP(rtprio_success);
1241 ATF_TC_HEAD(rtprio_success, tc)
1242 {
1243 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1244 					"rtprio(2) call");
1245 }
1246 
1247 ATF_TC_BODY(rtprio_success, tc)
1248 {
1249 	struct rtprio rtp;
1250 	pid = getpid();
1251 	snprintf(pcregex, sizeof(pcregex), "rtprio.*%d.*return,success", pid);
1252 
1253 	FILE *pipefd = setup(fds, auclass);
1254 	ATF_REQUIRE_EQ(0, rtprio(RTP_LOOKUP, 0, &rtp));
1255 	check_audit(fds, pcregex, pipefd);
1256 }
1257 
1258 ATF_TC_CLEANUP(rtprio_success, tc)
1259 {
1260 	cleanup();
1261 }
1262 
1263 
1264 ATF_TC_WITH_CLEANUP(rtprio_failure);
1265 ATF_TC_HEAD(rtprio_failure, tc)
1266 {
1267 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1268 					"rtprio(2) call");
1269 }
1270 
1271 ATF_TC_BODY(rtprio_failure, tc)
1272 {
1273 	pid = getpid();
1274 	snprintf(pcregex, sizeof(pcregex), "rtprio.*%d.*return,failure", pid);
1275 
1276 	FILE *pipefd = setup(fds, auclass);
1277 	ATF_REQUIRE_EQ(-1, rtprio(-1, -1, NULL));
1278 	check_audit(fds, pcregex, pipefd);
1279 }
1280 
1281 ATF_TC_CLEANUP(rtprio_failure, tc)
1282 {
1283 	cleanup();
1284 }
1285 
1286 
1287 ATF_TC_WITH_CLEANUP(profil_success);
1288 ATF_TC_HEAD(profil_success, tc)
1289 {
1290 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1291 					"profil(2) call");
1292 }
1293 
1294 ATF_TC_BODY(profil_success, tc)
1295 {
1296 	pid = getpid();
1297 	snprintf(pcregex, sizeof(pcregex), "profil.*%d.*return,success", pid);
1298 
1299 	char samples[20];
1300 	FILE *pipefd = setup(fds, auclass);
1301 	/* Set scale argument as 0 to disable profiling of current process */
1302 	ATF_REQUIRE_EQ(0, profil(samples, sizeof(samples), 0, 0));
1303 	check_audit(fds, pcregex, pipefd);
1304 }
1305 
1306 ATF_TC_CLEANUP(profil_success, tc)
1307 {
1308 	cleanup();
1309 }
1310 
1311 
1312 ATF_TC_WITH_CLEANUP(profil_failure);
1313 ATF_TC_HEAD(profil_failure, tc)
1314 {
1315 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1316 					"profil(2) call");
1317 }
1318 
1319 ATF_TC_BODY(profil_failure, tc)
1320 {
1321 	pid = getpid();
1322 	snprintf(pcregex, sizeof(pcregex), "profil.*%d.*return,failure", pid);
1323 
1324 	FILE *pipefd = setup(fds, auclass);
1325 	ATF_REQUIRE_EQ(-1, profil((char *)(SIZE_MAX), -1, -1, -1));
1326 	check_audit(fds, pcregex, pipefd);
1327 }
1328 
1329 ATF_TC_CLEANUP(profil_failure, tc)
1330 {
1331 	cleanup();
1332 }
1333 
1334 
1335 ATF_TC_WITH_CLEANUP(ptrace_success);
1336 ATF_TC_HEAD(ptrace_success, tc)
1337 {
1338 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1339 					"ptrace(2) call");
1340 }
1341 
1342 ATF_TC_BODY(ptrace_success, tc)
1343 {
1344 	pid = getpid();
1345 	snprintf(pcregex, sizeof(pcregex), "ptrace.*%d.*return,success", pid);
1346 
1347 	FILE *pipefd = setup(fds, auclass);
1348 	ATF_REQUIRE_EQ(0, ptrace(PT_TRACE_ME, 0, NULL, 0));
1349 	check_audit(fds, pcregex, pipefd);
1350 }
1351 
1352 ATF_TC_CLEANUP(ptrace_success, tc)
1353 {
1354 	cleanup();
1355 }
1356 
1357 
1358 ATF_TC_WITH_CLEANUP(ptrace_failure);
1359 ATF_TC_HEAD(ptrace_failure, tc)
1360 {
1361 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1362 					"ptrace(2) call");
1363 }
1364 
1365 ATF_TC_BODY(ptrace_failure, tc)
1366 {
1367 	pid = getpid();
1368 	snprintf(pcregex, sizeof(pcregex), "ptrace.*%d.*return,failure", pid);
1369 
1370 	FILE *pipefd = setup(fds, auclass);
1371 	ATF_REQUIRE_EQ(-1, ptrace(-1, 0, NULL, 0));
1372 	check_audit(fds, pcregex, pipefd);
1373 }
1374 
1375 ATF_TC_CLEANUP(ptrace_failure, tc)
1376 {
1377 	cleanup();
1378 }
1379 
1380 
1381 ATF_TC_WITH_CLEANUP(ktrace_success);
1382 ATF_TC_HEAD(ktrace_success, tc)
1383 {
1384 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1385 					"ktrace(2) call");
1386 }
1387 
1388 ATF_TC_BODY(ktrace_success, tc)
1389 {
1390 	pid = getpid();
1391 	snprintf(pcregex, sizeof(pcregex), "ktrace.*%d.*return,success", pid);
1392 
1393 	FILE *pipefd = setup(fds, auclass);
1394 	ATF_REQUIRE_EQ(0, ktrace(NULL, KTROP_CLEAR, KTRFAC_SYSCALL, pid));
1395 	check_audit(fds, pcregex, pipefd);
1396 }
1397 
1398 ATF_TC_CLEANUP(ktrace_success, tc)
1399 {
1400 	cleanup();
1401 }
1402 
1403 
1404 ATF_TC_WITH_CLEANUP(ktrace_failure);
1405 ATF_TC_HEAD(ktrace_failure, tc)
1406 {
1407 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1408 					"ktrace(2) call");
1409 }
1410 
1411 ATF_TC_BODY(ktrace_failure, tc)
1412 {
1413 	pid = getpid();
1414 	snprintf(pcregex, sizeof(pcregex), "ktrace.*%d.*return,failure", pid);
1415 
1416 	FILE *pipefd = setup(fds, auclass);
1417 	ATF_REQUIRE_EQ(-1, ktrace(NULL, -1, -1, 0));
1418 	check_audit(fds, pcregex, pipefd);
1419 }
1420 
1421 ATF_TC_CLEANUP(ktrace_failure, tc)
1422 {
1423 	cleanup();
1424 }
1425 
1426 
1427 ATF_TC_WITH_CLEANUP(procctl_success);
1428 ATF_TC_HEAD(procctl_success, tc)
1429 {
1430 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1431 					"procctl(2) call");
1432 }
1433 
1434 ATF_TC_BODY(procctl_success, tc)
1435 {
1436 	pid = getpid();
1437 	snprintf(pcregex, sizeof(pcregex), "procctl.*%d.*return,success", pid);
1438 
1439 	struct procctl_reaper_status reapstat;
1440 	FILE *pipefd = setup(fds, auclass);
1441 	/* Retrieve information about the reaper of current process (pid) */
1442 	ATF_REQUIRE_EQ(0, procctl(P_PID, pid, PROC_REAP_STATUS, &reapstat));
1443 	check_audit(fds, pcregex, pipefd);
1444 }
1445 
1446 ATF_TC_CLEANUP(procctl_success, tc)
1447 {
1448 	cleanup();
1449 }
1450 
1451 
1452 ATF_TC_WITH_CLEANUP(procctl_failure);
1453 ATF_TC_HEAD(procctl_failure, tc)
1454 {
1455 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1456 					"procctl(2) call");
1457 }
1458 
1459 ATF_TC_BODY(procctl_failure, tc)
1460 {
1461 	pid = getpid();
1462 	snprintf(pcregex, sizeof(pcregex), "procctl.*%d.*return,failure", pid);
1463 
1464 	FILE *pipefd = setup(fds, auclass);
1465 	ATF_REQUIRE_EQ(-1, procctl(-1, -1, -1, NULL));
1466 	check_audit(fds, pcregex, pipefd);
1467 }
1468 
1469 ATF_TC_CLEANUP(procctl_failure, tc)
1470 {
1471 	cleanup();
1472 }
1473 
1474 
1475 ATF_TP_ADD_TCS(tp)
1476 {
1477 	ATF_TP_ADD_TC(tp, fork_success);
1478 	ATF_TP_ADD_TC(tp, rfork_success);
1479 	ATF_TP_ADD_TC(tp, rfork_failure);
1480 
1481 	ATF_TP_ADD_TC(tp, wait4_success);
1482 	ATF_TP_ADD_TC(tp, wait4_failure);
1483 	ATF_TP_ADD_TC(tp, wait6_success);
1484 	ATF_TP_ADD_TC(tp, wait6_failure);
1485 	ATF_TP_ADD_TC(tp, kill_success);
1486 	ATF_TP_ADD_TC(tp, kill_failure);
1487 
1488 	ATF_TP_ADD_TC(tp, chdir_success);
1489 	ATF_TP_ADD_TC(tp, chdir_failure);
1490 	ATF_TP_ADD_TC(tp, fchdir_success);
1491 	ATF_TP_ADD_TC(tp, fchdir_failure);
1492 	ATF_TP_ADD_TC(tp, chroot_success);
1493 	ATF_TP_ADD_TC(tp, chroot_failure);
1494 
1495 	ATF_TP_ADD_TC(tp, umask_success);
1496 	ATF_TP_ADD_TC(tp, setuid_success);
1497 	ATF_TP_ADD_TC(tp, seteuid_success);
1498 	ATF_TP_ADD_TC(tp, setgid_success);
1499 	ATF_TP_ADD_TC(tp, setegid_success);
1500 
1501 	ATF_TP_ADD_TC(tp, setreuid_success);
1502 	ATF_TP_ADD_TC(tp, setregid_success);
1503 	ATF_TP_ADD_TC(tp, setresuid_success);
1504 	ATF_TP_ADD_TC(tp, setresgid_success);
1505 
1506 	ATF_TP_ADD_TC(tp, getresuid_success);
1507 	ATF_TP_ADD_TC(tp, getresuid_failure);
1508 	ATF_TP_ADD_TC(tp, getresgid_success);
1509 	ATF_TP_ADD_TC(tp, getresgid_failure);
1510 
1511 	ATF_TP_ADD_TC(tp, setpriority_success);
1512 	ATF_TP_ADD_TC(tp, setpriority_failure);
1513 	ATF_TP_ADD_TC(tp, setgroups_success);
1514 	ATF_TP_ADD_TC(tp, setgroups_failure);
1515 	ATF_TP_ADD_TC(tp, setpgrp_success);
1516 	ATF_TP_ADD_TC(tp, setpgrp_failure);
1517 	ATF_TP_ADD_TC(tp, setsid_success);
1518 	ATF_TP_ADD_TC(tp, setsid_failure);
1519 	ATF_TP_ADD_TC(tp, setrlimit_success);
1520 	ATF_TP_ADD_TC(tp, setrlimit_failure);
1521 
1522 	ATF_TP_ADD_TC(tp, mlock_success);
1523 	ATF_TP_ADD_TC(tp, mlock_failure);
1524 	ATF_TP_ADD_TC(tp, munlock_success);
1525 	ATF_TP_ADD_TC(tp, munlock_failure);
1526 	ATF_TP_ADD_TC(tp, minherit_success);
1527 	ATF_TP_ADD_TC(tp, minherit_failure);
1528 
1529 	ATF_TP_ADD_TC(tp, setlogin_success);
1530 	ATF_TP_ADD_TC(tp, setlogin_failure);
1531 	ATF_TP_ADD_TC(tp, rtprio_success);
1532 	ATF_TP_ADD_TC(tp, rtprio_failure);
1533 
1534 	ATF_TP_ADD_TC(tp, profil_success);
1535 	ATF_TP_ADD_TC(tp, profil_failure);
1536 	ATF_TP_ADD_TC(tp, ptrace_success);
1537 	ATF_TP_ADD_TC(tp, ptrace_failure);
1538 	ATF_TP_ADD_TC(tp, ktrace_success);
1539 	ATF_TP_ADD_TC(tp, ktrace_failure);
1540 	ATF_TP_ADD_TC(tp, procctl_success);
1541 	ATF_TP_ADD_TC(tp, procctl_failure);
1542 
1543 	return (atf_no_error());
1544 }
1545