xref: /freebsd/tests/sys/audit/file-attribute-modify.c (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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/types.h>
29 #include <sys/extattr.h>
30 #include <sys/file.h>
31 #include <sys/mman.h>
32 #include <sys/stat.h>
33 #include <sys/time.h>
34 
35 #include <atf-c.h>
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <stdint.h>
39 #include <unistd.h>
40 
41 #include "utils.h"
42 
43 static pid_t pid;
44 static uid_t uid = -1;
45 static gid_t gid = -1;
46 static int filedesc, retval;
47 static struct pollfd fds[1];
48 static mode_t mode = 0777;
49 static char extregex[80];
50 static char buff[] = "ezio";
51 static const char *auclass = "fm";
52 static const char *name = "authorname";
53 static const char *path = "fileforaudit";
54 static const char *errpath = "adirhasnoname/fileforaudit";
55 static const char *successreg = "fileforaudit.*return,success";
56 static const char *failurereg = "fileforaudit.*return,failure";
57 
58 
59 ATF_TC_WITH_CLEANUP(flock_success);
60 ATF_TC_HEAD(flock_success, tc)
61 {
62 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
63 					"flock(2) call");
64 }
65 
66 ATF_TC_BODY(flock_success, tc)
67 {
68 	pid = getpid();
69 	snprintf(extregex, sizeof(extregex), "flock.*%d.*return,success", pid);
70 
71 	/* File needs to exist to call flock(2) */
72 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
73 	FILE *pipefd = setup(fds, auclass);
74 	ATF_REQUIRE_EQ(0, flock(filedesc, LOCK_SH));
75 	check_audit(fds, extregex, pipefd);
76 	close(filedesc);
77 }
78 
79 ATF_TC_CLEANUP(flock_success, tc)
80 {
81 	cleanup();
82 }
83 
84 
85 ATF_TC_WITH_CLEANUP(flock_failure);
86 ATF_TC_HEAD(flock_failure, tc)
87 {
88 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
89 					"flock(2) call");
90 }
91 
92 ATF_TC_BODY(flock_failure, tc)
93 {
94 	const char *regex = "flock.*return,failure : Bad file descriptor";
95 	FILE *pipefd = setup(fds, auclass);
96 	ATF_REQUIRE_ERRNO(EBADF, flock(-1, LOCK_SH) == -1);
97 	check_audit(fds, regex, pipefd);
98 }
99 
100 ATF_TC_CLEANUP(flock_failure, tc)
101 {
102 	cleanup();
103 }
104 
105 
106 ATF_TC_WITH_CLEANUP(fcntl_success);
107 ATF_TC_HEAD(fcntl_success, tc)
108 {
109 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
110 					"fcntl(2) call");
111 }
112 
113 ATF_TC_BODY(fcntl_success, tc)
114 {
115 	int flagstatus;
116 	/* File needs to exist to call fcntl(2) */
117 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
118 	FILE *pipefd = setup(fds, auclass);
119 
120 	/* Retrieve the status flags of 'filedesc' and store it in flagstatus */
121 	ATF_REQUIRE((flagstatus = fcntl(filedesc, F_GETFL, 0)) != -1);
122 	snprintf(extregex, sizeof(extregex),
123 			"fcntl.*return,success,%d", flagstatus);
124 	check_audit(fds, extregex, pipefd);
125 	close(filedesc);
126 }
127 
128 ATF_TC_CLEANUP(fcntl_success, tc)
129 {
130 	cleanup();
131 }
132 
133 
134 ATF_TC_WITH_CLEANUP(fcntl_failure);
135 ATF_TC_HEAD(fcntl_failure, tc)
136 {
137 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
138 					"fcntl(2) call");
139 }
140 
141 ATF_TC_BODY(fcntl_failure, tc)
142 {
143 	const char *regex = "fcntl.*return,failure : Bad file descriptor";
144 	FILE *pipefd = setup(fds, auclass);
145 	ATF_REQUIRE_ERRNO(EBADF, fcntl(-1, F_GETFL, 0) == -1);
146 	check_audit(fds, regex, pipefd);
147 }
148 
149 ATF_TC_CLEANUP(fcntl_failure, tc)
150 {
151 	cleanup();
152 }
153 
154 
155 ATF_TC_WITH_CLEANUP(fsync_success);
156 ATF_TC_HEAD(fsync_success, tc)
157 {
158 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
159 					"fsync(2) call");
160 }
161 
162 ATF_TC_BODY(fsync_success, tc)
163 {
164 	pid = getpid();
165 	snprintf(extregex, sizeof(extregex), "fsync.*%d.*return,success", pid);
166 
167 	/* File needs to exist to call fsync(2) */
168 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
169 	FILE *pipefd = setup(fds, auclass);
170 	ATF_REQUIRE_EQ(0, fsync(filedesc));
171 	check_audit(fds, extregex, pipefd);
172 	close(filedesc);
173 }
174 
175 ATF_TC_CLEANUP(fsync_success, tc)
176 {
177 	cleanup();
178 }
179 
180 
181 ATF_TC_WITH_CLEANUP(fsync_failure);
182 ATF_TC_HEAD(fsync_failure, tc)
183 {
184 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
185 					"fsync(2) call");
186 }
187 
188 ATF_TC_BODY(fsync_failure, tc)
189 {
190 	const char *regex = "fsync.*return,failure : Bad file descriptor";
191 	FILE *pipefd = setup(fds, auclass);
192 	/* Failure reason: Invalid file descriptor */
193 	ATF_REQUIRE_ERRNO(EBADF, fsync(-1) == -1);
194 	check_audit(fds, regex, pipefd);
195 }
196 
197 ATF_TC_CLEANUP(fsync_failure, tc)
198 {
199 	cleanup();
200 }
201 
202 
203 ATF_TC_WITH_CLEANUP(chmod_success);
204 ATF_TC_HEAD(chmod_success, tc)
205 {
206 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
207 					"chmod(2) call");
208 }
209 
210 ATF_TC_BODY(chmod_success, tc)
211 {
212 	/* File needs to exist to call chmod(2) */
213 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
214 	FILE *pipefd = setup(fds, auclass);
215 	ATF_REQUIRE_EQ(0, chmod(path, mode));
216 	check_audit(fds, successreg, pipefd);
217 	close(filedesc);
218 }
219 
220 ATF_TC_CLEANUP(chmod_success, tc)
221 {
222 	cleanup();
223 }
224 
225 
226 ATF_TC_WITH_CLEANUP(chmod_failure);
227 ATF_TC_HEAD(chmod_failure, tc)
228 {
229 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
230 					"chmod(2) call");
231 }
232 
233 ATF_TC_BODY(chmod_failure, tc)
234 {
235 	FILE *pipefd = setup(fds, auclass);
236 	/* Failure reason: file does not exist */
237 	ATF_REQUIRE_ERRNO(ENOENT, chmod(errpath, mode) == -1);
238 	check_audit(fds, failurereg, pipefd);
239 }
240 
241 ATF_TC_CLEANUP(chmod_failure, tc)
242 {
243 	cleanup();
244 }
245 
246 
247 ATF_TC_WITH_CLEANUP(fchmod_success);
248 ATF_TC_HEAD(fchmod_success, tc)
249 {
250 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
251 					"fchmod(2) call");
252 }
253 
254 ATF_TC_BODY(fchmod_success, tc)
255 {
256 	pid = getpid();
257 	snprintf(extregex, sizeof(extregex), "fchmod.*%d.*return,success", pid);
258 
259 	/* File needs to exist to call fchmod(2) */
260 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
261 	FILE *pipefd = setup(fds, auclass);
262 	ATF_REQUIRE_EQ(0, fchmod(filedesc, mode));
263 	check_audit(fds, extregex, pipefd);
264 	close(filedesc);
265 }
266 
267 ATF_TC_CLEANUP(fchmod_success, tc)
268 {
269 	cleanup();
270 }
271 
272 
273 ATF_TC_WITH_CLEANUP(fchmod_failure);
274 ATF_TC_HEAD(fchmod_failure, tc)
275 {
276 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
277 					"fchmod(2) call");
278 }
279 
280 ATF_TC_BODY(fchmod_failure, tc)
281 {
282 	const char *regex = "fchmod.*return,failure : Bad file descriptor";
283 	FILE *pipefd = setup(fds, auclass);
284 	/* Failure reason: Invalid file descriptor */
285 	ATF_REQUIRE_ERRNO(EBADF, fchmod(-1, mode) == -1);
286 	check_audit(fds, regex, pipefd);
287 }
288 
289 ATF_TC_CLEANUP(fchmod_failure, tc)
290 {
291 	cleanup();
292 }
293 
294 
295 ATF_TC_WITH_CLEANUP(lchmod_success);
296 ATF_TC_HEAD(lchmod_success, tc)
297 {
298 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
299 					"lchmod(2) call");
300 }
301 
302 ATF_TC_BODY(lchmod_success, tc)
303 {
304 	/* Symbolic link needs to exist to call lchmod(2) */
305 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
306 	FILE *pipefd = setup(fds, auclass);
307 	ATF_REQUIRE_EQ(0, lchmod(path, mode));
308 	check_audit(fds, successreg, pipefd);
309 }
310 
311 ATF_TC_CLEANUP(lchmod_success, tc)
312 {
313 	cleanup();
314 }
315 
316 
317 ATF_TC_WITH_CLEANUP(lchmod_failure);
318 ATF_TC_HEAD(lchmod_failure, tc)
319 {
320 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
321 					"lchmod(2) call");
322 }
323 
324 ATF_TC_BODY(lchmod_failure, tc)
325 {
326 	FILE *pipefd = setup(fds, auclass);
327 	/* Failure reason: file does not exist */
328 	ATF_REQUIRE_ERRNO(ENOENT, lchmod(errpath, mode) == -1);
329 	check_audit(fds, failurereg, pipefd);
330 }
331 
332 ATF_TC_CLEANUP(lchmod_failure, tc)
333 {
334 	cleanup();
335 }
336 
337 
338 ATF_TC_WITH_CLEANUP(fchmodat_success);
339 ATF_TC_HEAD(fchmodat_success, tc)
340 {
341 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
342 					"fchmodat(2) call");
343 }
344 
345 ATF_TC_BODY(fchmodat_success, tc)
346 {
347 	/* File needs to exist to call fchmodat(2) */
348 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
349 	FILE *pipefd = setup(fds, auclass);
350 	ATF_REQUIRE_EQ(0, fchmodat(AT_FDCWD, path, mode, 0));
351 	check_audit(fds, successreg, pipefd);
352 	close(filedesc);
353 }
354 
355 ATF_TC_CLEANUP(fchmodat_success, tc)
356 {
357 	cleanup();
358 }
359 
360 
361 ATF_TC_WITH_CLEANUP(fchmodat_failure);
362 ATF_TC_HEAD(fchmodat_failure, tc)
363 {
364 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
365 					"fchmodat(2) call");
366 }
367 
368 ATF_TC_BODY(fchmodat_failure, tc)
369 {
370 	FILE *pipefd = setup(fds, auclass);
371 	/* Failure reason: file does not exist */
372 	ATF_REQUIRE_ERRNO(ENOENT, fchmodat(AT_FDCWD, errpath, mode, 0) == -1);
373 	check_audit(fds, failurereg, pipefd);
374 }
375 
376 ATF_TC_CLEANUP(fchmodat_failure, tc)
377 {
378 	cleanup();
379 }
380 
381 
382 ATF_TC_WITH_CLEANUP(chown_success);
383 ATF_TC_HEAD(chown_success, tc)
384 {
385 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
386 					"chown(2) call");
387 }
388 
389 ATF_TC_BODY(chown_success, tc)
390 {
391 	/* File needs to exist to call chown(2) */
392 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
393 	FILE *pipefd = setup(fds, auclass);
394 	ATF_REQUIRE_EQ(0, chown(path, uid, gid));
395 	check_audit(fds, successreg, pipefd);
396 	close(filedesc);
397 }
398 
399 ATF_TC_CLEANUP(chown_success, tc)
400 {
401 	cleanup();
402 }
403 
404 
405 ATF_TC_WITH_CLEANUP(chown_failure);
406 ATF_TC_HEAD(chown_failure, tc)
407 {
408 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
409 					"chown(2) call");
410 }
411 
412 ATF_TC_BODY(chown_failure, tc)
413 {
414 	FILE *pipefd = setup(fds, auclass);
415 	/* Failure reason: file does not exist */
416 	ATF_REQUIRE_ERRNO(ENOENT, chown(errpath, uid, gid) == -1);
417 	check_audit(fds, failurereg, pipefd);
418 }
419 
420 ATF_TC_CLEANUP(chown_failure, tc)
421 {
422 	cleanup();
423 }
424 
425 
426 ATF_TC_WITH_CLEANUP(fchown_success);
427 ATF_TC_HEAD(fchown_success, tc)
428 {
429 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
430 					"fchown(2) call");
431 }
432 
433 ATF_TC_BODY(fchown_success, tc)
434 {
435 	pid = getpid();
436 	snprintf(extregex, sizeof(extregex), "fchown.*%d.*return,success", pid);
437 
438 	/* File needs to exist to call fchown(2) */
439 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
440 	FILE *pipefd = setup(fds, auclass);
441 	ATF_REQUIRE_EQ(0, fchown(filedesc, uid, gid));
442 	check_audit(fds, extregex, pipefd);
443 	close(filedesc);
444 }
445 
446 ATF_TC_CLEANUP(fchown_success, tc)
447 {
448 	cleanup();
449 }
450 
451 
452 ATF_TC_WITH_CLEANUP(fchown_failure);
453 ATF_TC_HEAD(fchown_failure, tc)
454 {
455 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
456 					"fchown(2) call");
457 }
458 
459 ATF_TC_BODY(fchown_failure, tc)
460 {
461 	const char *regex = "fchown.*return,failure : Bad file descriptor";
462 	FILE *pipefd = setup(fds, auclass);
463 	/* Failure reason: Invalid file descriptor */
464 	ATF_REQUIRE_ERRNO(EBADF, fchown(-1, uid, gid) == -1);
465 	check_audit(fds, regex, pipefd);
466 }
467 
468 ATF_TC_CLEANUP(fchown_failure, tc)
469 {
470 	cleanup();
471 }
472 
473 
474 ATF_TC_WITH_CLEANUP(lchown_success);
475 ATF_TC_HEAD(lchown_success, tc)
476 {
477 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
478 					"lchown(2) call");
479 }
480 
481 ATF_TC_BODY(lchown_success, tc)
482 {
483 	/* Symbolic link needs to exist to call lchown(2) */
484 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
485 	FILE *pipefd = setup(fds, auclass);
486 	ATF_REQUIRE_EQ(0, lchown(path, uid, gid));
487 	check_audit(fds, successreg, pipefd);
488 }
489 
490 ATF_TC_CLEANUP(lchown_success, tc)
491 {
492 	cleanup();
493 }
494 
495 
496 ATF_TC_WITH_CLEANUP(lchown_failure);
497 ATF_TC_HEAD(lchown_failure, tc)
498 {
499 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
500 					"lchown(2) call");
501 }
502 
503 ATF_TC_BODY(lchown_failure, tc)
504 {
505 	FILE *pipefd = setup(fds, auclass);
506 	/* Failure reason: Symbolic link does not exist */
507 	ATF_REQUIRE_ERRNO(ENOENT, lchown(errpath, uid, gid) == -1);
508 	check_audit(fds, failurereg, pipefd);
509 }
510 
511 ATF_TC_CLEANUP(lchown_failure, tc)
512 {
513 	cleanup();
514 }
515 
516 
517 ATF_TC_WITH_CLEANUP(fchownat_success);
518 ATF_TC_HEAD(fchownat_success, tc)
519 {
520 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
521 					"fchownat(2) call");
522 }
523 
524 ATF_TC_BODY(fchownat_success, tc)
525 {
526 	/* File needs to exist to call fchownat(2) */
527 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
528 	FILE *pipefd = setup(fds, auclass);
529 	ATF_REQUIRE_EQ(0, fchownat(AT_FDCWD, path, uid, gid, 0));
530 	check_audit(fds, successreg, pipefd);
531 	close(filedesc);
532 }
533 
534 ATF_TC_CLEANUP(fchownat_success, tc)
535 {
536 	cleanup();
537 }
538 
539 
540 ATF_TC_WITH_CLEANUP(fchownat_failure);
541 ATF_TC_HEAD(fchownat_failure, tc)
542 {
543 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
544 					"fchownat(2) call");
545 }
546 
547 ATF_TC_BODY(fchownat_failure, tc)
548 {
549 	FILE *pipefd = setup(fds, auclass);
550 	/* Failure reason: file does not exist */
551 	ATF_REQUIRE_ERRNO(ENOENT,
552 	    fchownat(AT_FDCWD, errpath, uid, gid, 0) == -1);
553 	check_audit(fds, failurereg, pipefd);
554 }
555 
556 ATF_TC_CLEANUP(fchownat_failure, tc)
557 {
558 	cleanup();
559 }
560 
561 
562 ATF_TC_WITH_CLEANUP(chflags_success);
563 ATF_TC_HEAD(chflags_success, tc)
564 {
565 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
566 					"chflags(2) call");
567 }
568 
569 ATF_TC_BODY(chflags_success, tc)
570 {
571 	/* File needs to exist to call chflags(2) */
572 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
573 	FILE *pipefd = setup(fds, auclass);
574 	ATF_REQUIRE_EQ(0, chflags(path, UF_OFFLINE));
575 	check_audit(fds, successreg, pipefd);
576 	close(filedesc);
577 }
578 
579 ATF_TC_CLEANUP(chflags_success, tc)
580 {
581 	cleanup();
582 }
583 
584 
585 ATF_TC_WITH_CLEANUP(chflags_failure);
586 ATF_TC_HEAD(chflags_failure, tc)
587 {
588 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
589 					"chflags(2) call");
590 }
591 
592 ATF_TC_BODY(chflags_failure, tc)
593 {
594 	FILE *pipefd = setup(fds, auclass);
595 	/* Failure reason: file does not exist */
596 	ATF_REQUIRE_ERRNO(ENOENT, chflags(errpath, UF_OFFLINE) == -1);
597 	check_audit(fds, failurereg, pipefd);
598 }
599 
600 ATF_TC_CLEANUP(chflags_failure, tc)
601 {
602 	cleanup();
603 }
604 
605 
606 ATF_TC_WITH_CLEANUP(fchflags_success);
607 ATF_TC_HEAD(fchflags_success, tc)
608 {
609 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
610 					"fchflags(2) call");
611 }
612 
613 ATF_TC_BODY(fchflags_success, tc)
614 {
615 	pid = getpid();
616 	snprintf(extregex, sizeof(extregex), "fchflags.*%d.*ret.*success", pid);
617 	/* File needs to exist to call fchflags(2) */
618 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
619 
620 	FILE *pipefd = setup(fds, auclass);
621 	ATF_REQUIRE_EQ(0, fchflags(filedesc, UF_OFFLINE));
622 	check_audit(fds, extregex, pipefd);
623 	close(filedesc);
624 }
625 
626 ATF_TC_CLEANUP(fchflags_success, tc)
627 {
628 	cleanup();
629 }
630 
631 
632 ATF_TC_WITH_CLEANUP(fchflags_failure);
633 ATF_TC_HEAD(fchflags_failure, tc)
634 {
635 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
636 					"fchflags(2) call");
637 }
638 
639 ATF_TC_BODY(fchflags_failure, tc)
640 {
641 	const char *regex = "fchflags.*return,failure : Bad file descriptor";
642 	FILE *pipefd = setup(fds, auclass);
643 	/* Failure reason: Invalid file descriptor */
644 	ATF_REQUIRE_ERRNO(EBADF, fchflags(-1, UF_OFFLINE) == -1);
645 	check_audit(fds, regex, pipefd);
646 }
647 
648 ATF_TC_CLEANUP(fchflags_failure, tc)
649 {
650 	cleanup();
651 }
652 
653 
654 ATF_TC_WITH_CLEANUP(lchflags_success);
655 ATF_TC_HEAD(lchflags_success, tc)
656 {
657 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
658 					"lchflags(2) call");
659 }
660 
661 ATF_TC_BODY(lchflags_success, tc)
662 {
663 	/* Symbolic link needs to exist to call lchflags(2) */
664 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
665 	FILE *pipefd = setup(fds, auclass);
666 	ATF_REQUIRE_EQ(0, lchflags(path, UF_OFFLINE));
667 	check_audit(fds, successreg, pipefd);
668 }
669 
670 ATF_TC_CLEANUP(lchflags_success, tc)
671 {
672 	cleanup();
673 }
674 
675 
676 ATF_TC_WITH_CLEANUP(lchflags_failure);
677 ATF_TC_HEAD(lchflags_failure, tc)
678 {
679 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
680 					"lchflags(2) call");
681 }
682 
683 ATF_TC_BODY(lchflags_failure, tc)
684 {
685 	FILE *pipefd = setup(fds, auclass);
686 	/* Failure reason: Symbolic link does not exist */
687 	ATF_REQUIRE_ERRNO(ENOENT, lchflags(errpath, UF_OFFLINE) == -1);
688 	check_audit(fds, failurereg, pipefd);
689 }
690 
691 ATF_TC_CLEANUP(lchflags_failure, tc)
692 {
693 	cleanup();
694 }
695 
696 
697 ATF_TC_WITH_CLEANUP(chflagsat_success);
698 ATF_TC_HEAD(chflagsat_success, tc)
699 {
700 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
701 					"chflagsat(2) call");
702 }
703 
704 ATF_TC_BODY(chflagsat_success, tc)
705 {
706 	/* File needs to exist to call chflagsat(2) */
707 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
708 	FILE *pipefd = setup(fds, auclass);
709 	ATF_REQUIRE_EQ(0, chflagsat(AT_FDCWD, path, UF_OFFLINE, 0));
710 	check_audit(fds, successreg, pipefd);
711 	close(filedesc);
712 }
713 
714 ATF_TC_CLEANUP(chflagsat_success, tc)
715 {
716 	cleanup();
717 }
718 
719 
720 ATF_TC_WITH_CLEANUP(chflagsat_failure);
721 ATF_TC_HEAD(chflagsat_failure, tc)
722 {
723 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
724 					"chflagsat(2) call");
725 }
726 
727 ATF_TC_BODY(chflagsat_failure, tc)
728 {
729 	FILE *pipefd = setup(fds, auclass);
730 	/* Failure reason: file does not exist */
731 	ATF_REQUIRE_ERRNO(ENOENT,
732 	    chflagsat(AT_FDCWD, errpath, UF_OFFLINE, 0) == -1);
733 	check_audit(fds, failurereg, pipefd);
734 }
735 
736 ATF_TC_CLEANUP(chflagsat_failure, tc)
737 {
738 	cleanup();
739 }
740 
741 
742 ATF_TC_WITH_CLEANUP(utimes_success);
743 ATF_TC_HEAD(utimes_success, tc)
744 {
745 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
746 					"utimes(2) call");
747 }
748 
749 ATF_TC_BODY(utimes_success, tc)
750 {
751 	/* File needs to exist to call utimes(2) */
752 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
753 	FILE *pipefd = setup(fds, auclass);
754 	ATF_REQUIRE_EQ(0, utimes(path, NULL));
755 	check_audit(fds, successreg, pipefd);
756 	close(filedesc);
757 }
758 
759 ATF_TC_CLEANUP(utimes_success, tc)
760 {
761 	cleanup();
762 }
763 
764 
765 ATF_TC_WITH_CLEANUP(utimes_failure);
766 ATF_TC_HEAD(utimes_failure, tc)
767 {
768 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
769 					"utimes(2) call");
770 }
771 
772 ATF_TC_BODY(utimes_failure, tc)
773 {
774 	FILE *pipefd = setup(fds, auclass);
775 	/* Failure reason: file does not exist */
776 	ATF_REQUIRE_ERRNO(ENOENT, utimes(errpath, NULL) == -1);
777 	check_audit(fds, failurereg, pipefd);
778 }
779 
780 ATF_TC_CLEANUP(utimes_failure, tc)
781 {
782 	cleanup();
783 }
784 
785 
786 ATF_TC_WITH_CLEANUP(futimes_success);
787 ATF_TC_HEAD(futimes_success, tc)
788 {
789 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
790 					"futimes(2) call");
791 }
792 
793 ATF_TC_BODY(futimes_success, tc)
794 {
795 	pid = getpid();
796 	snprintf(extregex, sizeof(extregex), "futimes.*%d.*ret.*success", pid);
797 
798 	/* File needs to exist to call futimes(2) */
799 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
800 	FILE *pipefd = setup(fds, auclass);
801 	ATF_REQUIRE_EQ(0, futimes(filedesc, NULL));
802 	check_audit(fds, extregex, pipefd);
803 	close(filedesc);
804 }
805 
806 ATF_TC_CLEANUP(futimes_success, tc)
807 {
808 	cleanup();
809 }
810 
811 
812 ATF_TC_WITH_CLEANUP(futimes_failure);
813 ATF_TC_HEAD(futimes_failure, tc)
814 {
815 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
816 					"futimes(2) call");
817 }
818 
819 ATF_TC_BODY(futimes_failure, tc)
820 {
821 	const char *regex = "futimes.*return,failure : Bad file descriptor";
822 	FILE *pipefd = setup(fds, auclass);
823 	/* Failure reason: Invalid file descriptor */
824 	ATF_REQUIRE_ERRNO(EBADF, futimes(-1, NULL) == -1);
825 	check_audit(fds, regex, pipefd);
826 }
827 
828 ATF_TC_CLEANUP(futimes_failure, tc)
829 {
830 	cleanup();
831 }
832 
833 
834 ATF_TC_WITH_CLEANUP(lutimes_success);
835 ATF_TC_HEAD(lutimes_success, tc)
836 {
837 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
838 					"lutimes(2) call");
839 }
840 
841 ATF_TC_BODY(lutimes_success, tc)
842 {
843 	/* Symbolic link needs to exist to call lutimes(2) */
844 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
845 	FILE *pipefd = setup(fds, auclass);
846 	ATF_REQUIRE_EQ(0, lutimes(path, NULL));
847 	check_audit(fds, successreg, pipefd);
848 }
849 
850 ATF_TC_CLEANUP(lutimes_success, tc)
851 {
852 	cleanup();
853 }
854 
855 
856 ATF_TC_WITH_CLEANUP(lutimes_failure);
857 ATF_TC_HEAD(lutimes_failure, tc)
858 {
859 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
860 					"lutimes(2) call");
861 }
862 
863 ATF_TC_BODY(lutimes_failure, tc)
864 {
865 	FILE *pipefd = setup(fds, auclass);
866 	/* Failure reason: symbolic link does not exist */
867 	ATF_REQUIRE_ERRNO(ENOENT, lutimes(errpath, NULL) == -1);
868 	check_audit(fds, failurereg, pipefd);
869 }
870 
871 ATF_TC_CLEANUP(lutimes_failure, tc)
872 {
873 	cleanup();
874 }
875 
876 
877 ATF_TC_WITH_CLEANUP(futimesat_success);
878 ATF_TC_HEAD(futimesat_success, tc)
879 {
880 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
881 					"futimesat(2) call");
882 }
883 
884 ATF_TC_BODY(futimesat_success, tc)
885 {
886 	/* File needs to exist to call futimesat(2) */
887 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
888 	FILE *pipefd = setup(fds, auclass);
889 	ATF_REQUIRE_EQ(0, futimesat(AT_FDCWD, path, NULL));
890 	check_audit(fds, successreg, pipefd);
891 	close(filedesc);
892 }
893 
894 ATF_TC_CLEANUP(futimesat_success, tc)
895 {
896 	cleanup();
897 }
898 
899 
900 ATF_TC_WITH_CLEANUP(futimesat_failure);
901 ATF_TC_HEAD(futimesat_failure, tc)
902 {
903 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
904 					"futimesat(2) call");
905 }
906 
907 ATF_TC_BODY(futimesat_failure, tc)
908 {
909 	FILE *pipefd = setup(fds, auclass);
910 	/* Failure reason: file does not exist */
911 	ATF_REQUIRE_ERRNO(ENOENT, futimesat(AT_FDCWD, errpath, NULL) == -1);
912 	check_audit(fds, failurereg, pipefd);
913 }
914 
915 ATF_TC_CLEANUP(futimesat_failure, tc)
916 {
917 	cleanup();
918 }
919 
920 
921 ATF_TC_WITH_CLEANUP(mprotect_success);
922 ATF_TC_HEAD(mprotect_success, tc)
923 {
924 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
925 					"mprotect(2) call");
926 }
927 
928 ATF_TC_BODY(mprotect_success, tc)
929 {
930 	pid = getpid();
931 	snprintf(extregex, sizeof(extregex), "mprotect.*%d.*ret.*success", pid);
932 
933 	FILE *pipefd = setup(fds, auclass);
934 	ATF_REQUIRE_EQ(0, mprotect(NULL, 0, PROT_NONE));
935 	check_audit(fds, extregex, pipefd);
936 }
937 
938 ATF_TC_CLEANUP(mprotect_success, tc)
939 {
940 	cleanup();
941 }
942 
943 
944 ATF_TC_WITH_CLEANUP(mprotect_failure);
945 ATF_TC_HEAD(mprotect_failure, tc)
946 {
947 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
948 					"mprotect(2) call");
949 }
950 
951 ATF_TC_BODY(mprotect_failure, tc)
952 {
953 	const char *regex = "mprotect.*return,failure : Invalid argument";
954 	FILE *pipefd = setup(fds, auclass);
955 	ATF_REQUIRE_ERRNO(EINVAL,
956 	    mprotect((void *)SIZE_MAX, -1, PROT_NONE) == -1);
957 	check_audit(fds, regex, pipefd);
958 }
959 
960 ATF_TC_CLEANUP(mprotect_failure, tc)
961 {
962 	cleanup();
963 }
964 
965 /*
966  * undelete(2) only works on whiteout files in union file system. Hence, no
967  * test case for successful invocation.
968  */
969 
970 ATF_TC_WITH_CLEANUP(undelete_failure);
971 ATF_TC_HEAD(undelete_failure, tc)
972 {
973 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
974 					"undelete(2) call");
975 }
976 
977 ATF_TC_BODY(undelete_failure, tc)
978 {
979 	pid = getpid();
980 	snprintf(extregex, sizeof(extregex), "undelete.*%d.*ret.*failure", pid);
981 
982 	FILE *pipefd = setup(fds, auclass);
983 	/* Failure reason: File does not exist */
984 	ATF_REQUIRE_ERRNO(ENOENT, undelete(errpath) == -1);
985 	check_audit(fds, extregex, pipefd);
986 }
987 
988 ATF_TC_CLEANUP(undelete_failure, tc)
989 {
990 	cleanup();
991 }
992 
993 
994 ATF_TC_WITH_CLEANUP(extattr_set_file_success);
995 ATF_TC_HEAD(extattr_set_file_success, tc)
996 {
997 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
998 					"extattr_set_file(2) call");
999 }
1000 
1001 ATF_TC_BODY(extattr_set_file_success, tc)
1002 {
1003 	/* File needs to exist to call extattr_set_file(2) */
1004 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
1005 	skip_if_extattr_not_supported(path);
1006 
1007 	/* Prepare the regex to be checked in the audit record */
1008 	snprintf(extregex, sizeof(extregex),
1009 		"extattr_set_file.*%s.*%s.*return,success", path, name);
1010 
1011 	FILE *pipefd = setup(fds, auclass);
1012 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_file(path,
1013 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1014 	check_audit(fds, extregex, pipefd);
1015 	close(filedesc);
1016 }
1017 
1018 ATF_TC_CLEANUP(extattr_set_file_success, tc)
1019 {
1020 	cleanup();
1021 }
1022 
1023 
1024 ATF_TC_WITH_CLEANUP(extattr_set_file_failure);
1025 ATF_TC_HEAD(extattr_set_file_failure, tc)
1026 {
1027 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1028 					"extattr_set_file(2) call");
1029 }
1030 
1031 ATF_TC_BODY(extattr_set_file_failure, tc)
1032 {
1033 	/* Prepare the regex to be checked in the audit record */
1034 	snprintf(extregex, sizeof(extregex),
1035 		"extattr_set_file.*%s.*%s.*failure", path, name);
1036 
1037 	FILE *pipefd = setup(fds, auclass);
1038 	/* Failure reason: file does not exist */
1039 	ATF_REQUIRE_ERRNO(ENOENT,
1040 	    extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, NULL, 0) ==
1041 		-1);
1042 	check_audit(fds, extregex, pipefd);
1043 }
1044 
1045 ATF_TC_CLEANUP(extattr_set_file_failure, tc)
1046 {
1047 	cleanup();
1048 }
1049 
1050 
1051 ATF_TC_WITH_CLEANUP(extattr_set_fd_success);
1052 ATF_TC_HEAD(extattr_set_fd_success, tc)
1053 {
1054 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1055 					"extattr_set_fd(2) call");
1056 }
1057 
1058 ATF_TC_BODY(extattr_set_fd_success, tc)
1059 {
1060 	/* File needs to exist to call extattr_set_fd(2) */
1061 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
1062 	skip_if_extattr_not_supported(path);
1063 
1064 	/* Prepare the regex to be checked in the audit record */
1065 	snprintf(extregex, sizeof(extregex),
1066 		"extattr_set_fd.*%s.*return,success", name);
1067 
1068 	FILE *pipefd = setup(fds, auclass);
1069 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_fd(filedesc,
1070 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1071 	check_audit(fds, extregex, pipefd);
1072 	close(filedesc);
1073 }
1074 
1075 ATF_TC_CLEANUP(extattr_set_fd_success, tc)
1076 {
1077 	cleanup();
1078 }
1079 
1080 
1081 ATF_TC_WITH_CLEANUP(extattr_set_fd_failure);
1082 ATF_TC_HEAD(extattr_set_fd_failure, tc)
1083 {
1084 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1085 					"extattr_set_fd(2) call");
1086 }
1087 
1088 ATF_TC_BODY(extattr_set_fd_failure, tc)
1089 {
1090 	/* Prepare the regex to be checked in the audit record */
1091 	snprintf(extregex, sizeof(extregex),
1092 	"extattr_set_fd.*%s.*return,failure : Bad file descriptor", name);
1093 
1094 	FILE *pipefd = setup(fds, auclass);
1095 	/* Failure reason: Invalid file descriptor */
1096 	ATF_REQUIRE_ERRNO(EBADF,
1097 	    extattr_set_fd(-1, EXTATTR_NAMESPACE_USER, name, NULL, 0) == -1);
1098 	check_audit(fds, extregex, pipefd);
1099 }
1100 
1101 ATF_TC_CLEANUP(extattr_set_fd_failure, tc)
1102 {
1103 	cleanup();
1104 }
1105 
1106 
1107 ATF_TC_WITH_CLEANUP(extattr_set_link_success);
1108 ATF_TC_HEAD(extattr_set_link_success, tc)
1109 {
1110 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1111 					"extattr_set_link(2) call");
1112 }
1113 
1114 ATF_TC_BODY(extattr_set_link_success, tc)
1115 {
1116 	/* Symbolic link needs to exist to call extattr_set_link(2) */
1117 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
1118 	skip_if_extattr_not_supported(".");
1119 
1120 	/* Prepare the regex to be checked in the audit record */
1121 	snprintf(extregex, sizeof(extregex),
1122 		"extattr_set_link.*%s.*%s.*return,success", path, name);
1123 
1124 	FILE *pipefd = setup(fds, auclass);
1125 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_link(path,
1126 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1127 
1128 	check_audit(fds, extregex, pipefd);
1129 }
1130 
1131 ATF_TC_CLEANUP(extattr_set_link_success, tc)
1132 {
1133 	cleanup();
1134 }
1135 
1136 
1137 ATF_TC_WITH_CLEANUP(extattr_set_link_failure);
1138 ATF_TC_HEAD(extattr_set_link_failure, tc)
1139 {
1140 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1141 					"extattr_set_link(2) call");
1142 }
1143 
1144 ATF_TC_BODY(extattr_set_link_failure, tc)
1145 {
1146 	/* Prepare the regex to be checked in the audit record */
1147 	snprintf(extregex, sizeof(extregex),
1148 		"extattr_set_link.*%s.*%s.*failure", path, name);
1149 	FILE *pipefd = setup(fds, auclass);
1150 	/* Failure reason: symbolic link does not exist */
1151 	ATF_REQUIRE_ERRNO(ENOENT,
1152 	    extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, NULL, 0) ==
1153 		-1);
1154 	check_audit(fds, extregex, pipefd);
1155 }
1156 
1157 ATF_TC_CLEANUP(extattr_set_link_failure, tc)
1158 {
1159 	cleanup();
1160 }
1161 
1162 
1163 ATF_TC_WITH_CLEANUP(extattr_delete_file_success);
1164 ATF_TC_HEAD(extattr_delete_file_success, tc)
1165 {
1166 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1167 					"extattr_delete_file(2) call");
1168 }
1169 
1170 ATF_TC_BODY(extattr_delete_file_success, tc)
1171 {
1172 	/* File needs to exist to call extattr_delete_file(2) */
1173 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
1174 	skip_if_extattr_not_supported(path);
1175 
1176 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_file(path,
1177 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1178 
1179 	FILE *pipefd = setup(fds, auclass);
1180 	retval = REQUIRE_EXTATTR_SUCCESS(
1181 	    extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name));
1182 	/* Prepare the regex to be checked in the audit record */
1183 	snprintf(extregex, sizeof(extregex),
1184 	"extattr_delete_file.*%s.*return,success,%d", path, retval);
1185 	check_audit(fds, extregex, pipefd);
1186 	close(filedesc);
1187 }
1188 
1189 ATF_TC_CLEANUP(extattr_delete_file_success, tc)
1190 {
1191 	cleanup();
1192 }
1193 
1194 
1195 ATF_TC_WITH_CLEANUP(extattr_delete_file_failure);
1196 ATF_TC_HEAD(extattr_delete_file_failure, tc)
1197 {
1198 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1199 					"extattr_delete_file(2) call");
1200 }
1201 
1202 ATF_TC_BODY(extattr_delete_file_failure, tc)
1203 {
1204 	/* Prepare the regex to be checked in the audit record */
1205 	snprintf(extregex, sizeof(extregex),
1206 		"extattr_delete_file.*%s.*return,failure", path);
1207 
1208 	FILE *pipefd = setup(fds, auclass);
1209 	/* Failure reason: file does not exist */
1210 	ATF_REQUIRE_ERRNO(ENOENT,
1211 	    extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name) == -1);
1212 	check_audit(fds, extregex, pipefd);
1213 }
1214 
1215 ATF_TC_CLEANUP(extattr_delete_file_failure, tc)
1216 {
1217 	cleanup();
1218 }
1219 
1220 
1221 ATF_TC_WITH_CLEANUP(extattr_delete_fd_success);
1222 ATF_TC_HEAD(extattr_delete_fd_success, tc)
1223 {
1224 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1225 					"extattr_delete_fd(2) call");
1226 }
1227 
1228 ATF_TC_BODY(extattr_delete_fd_success, tc)
1229 {
1230 	/* File needs to exist to call extattr_delete_fd(2) */
1231 	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
1232 	skip_if_extattr_not_supported(path);
1233 
1234 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_file(path,
1235 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1236 
1237 	FILE *pipefd = setup(fds, auclass);
1238 	retval = REQUIRE_EXTATTR_SUCCESS(extattr_delete_fd(filedesc,
1239 		EXTATTR_NAMESPACE_USER, name));
1240 	/* Prepare the regex to be checked in the audit record */
1241 	snprintf(extregex, sizeof(extregex),
1242 		"extattr_delete_fd.*return,success,%d", retval);
1243 	check_audit(fds, extregex, pipefd);
1244 	close(filedesc);
1245 }
1246 
1247 ATF_TC_CLEANUP(extattr_delete_fd_success, tc)
1248 {
1249 	cleanup();
1250 }
1251 
1252 
1253 ATF_TC_WITH_CLEANUP(extattr_delete_fd_failure);
1254 ATF_TC_HEAD(extattr_delete_fd_failure, tc)
1255 {
1256 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1257 					"extattr_delete_fd(2) call");
1258 }
1259 
1260 ATF_TC_BODY(extattr_delete_fd_failure, tc)
1261 {
1262 	/* Prepare the regex to be checked in the audit record */
1263 	snprintf(extregex, sizeof(extregex),
1264 		"extattr_delete_fd.*return,failure : Bad file descriptor");
1265 
1266 	FILE *pipefd = setup(fds, auclass);
1267 	/* Failure reason: Invalid file descriptor */
1268 	ATF_REQUIRE_ERRNO(EBADF,
1269 	    extattr_delete_fd(-1, EXTATTR_NAMESPACE_USER, name) == -1);
1270 	check_audit(fds, extregex, pipefd);
1271 }
1272 
1273 ATF_TC_CLEANUP(extattr_delete_fd_failure, tc)
1274 {
1275 	cleanup();
1276 }
1277 
1278 
1279 ATF_TC_WITH_CLEANUP(extattr_delete_link_success);
1280 ATF_TC_HEAD(extattr_delete_link_success, tc)
1281 {
1282 	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
1283 					"extattr_delete_link(2) call");
1284 }
1285 
1286 ATF_TC_BODY(extattr_delete_link_success, tc)
1287 {
1288 	/* Symbolic link needs to exist to call extattr_delete_link(2) */
1289 	ATF_REQUIRE_EQ(0, symlink("symlink", path));
1290 	skip_if_extattr_not_supported(".");
1291 
1292 	REQUIRE_EXTATTR_RESULT(sizeof(buff), extattr_set_link(path,
1293 		EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff)));
1294 
1295 	FILE *pipefd = setup(fds, auclass);
1296 	retval = REQUIRE_EXTATTR_SUCCESS(extattr_delete_link(path,
1297 		EXTATTR_NAMESPACE_USER, name));
1298 	/* Prepare the regex to be checked in the audit record */
1299 	snprintf(extregex, sizeof(extregex),
1300 	"extattr_delete_link.*%s.*return,success,%d", path, retval);
1301 	check_audit(fds, extregex, pipefd);
1302 }
1303 
1304 ATF_TC_CLEANUP(extattr_delete_link_success, tc)
1305 {
1306 	cleanup();
1307 }
1308 
1309 
1310 ATF_TC_WITH_CLEANUP(extattr_delete_link_failure);
1311 ATF_TC_HEAD(extattr_delete_link_failure, tc)
1312 {
1313 	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
1314 					"extattr_delete_link(2) call");
1315 }
1316 
1317 ATF_TC_BODY(extattr_delete_link_failure, tc)
1318 {
1319 	/* Prepare the regex to be checked in the audit record */
1320 	snprintf(extregex, sizeof(extregex),
1321 		"extattr_delete_link.*%s.*failure", path);
1322 	FILE *pipefd = setup(fds, auclass);
1323 	/* Failure reason: symbolic link does not exist */
1324 	ATF_REQUIRE_ERRNO(ENOENT,
1325 	    extattr_delete_link(path, EXTATTR_NAMESPACE_USER, name) == -1);
1326 	check_audit(fds, extregex, pipefd);
1327 }
1328 
1329 ATF_TC_CLEANUP(extattr_delete_link_failure, tc)
1330 {
1331 	cleanup();
1332 }
1333 
1334 
1335 ATF_TP_ADD_TCS(tp)
1336 {
1337 	ATF_TP_ADD_TC(tp, flock_success);
1338 	ATF_TP_ADD_TC(tp, flock_failure);
1339 	ATF_TP_ADD_TC(tp, fcntl_success);
1340 	ATF_TP_ADD_TC(tp, fcntl_failure);
1341 	ATF_TP_ADD_TC(tp, fsync_success);
1342 	ATF_TP_ADD_TC(tp, fsync_failure);
1343 
1344 	ATF_TP_ADD_TC(tp, chmod_success);
1345 	ATF_TP_ADD_TC(tp, chmod_failure);
1346 	ATF_TP_ADD_TC(tp, fchmod_success);
1347 	ATF_TP_ADD_TC(tp, fchmod_failure);
1348 	ATF_TP_ADD_TC(tp, lchmod_success);
1349 	ATF_TP_ADD_TC(tp, lchmod_failure);
1350 	ATF_TP_ADD_TC(tp, fchmodat_success);
1351 	ATF_TP_ADD_TC(tp, fchmodat_failure);
1352 
1353 	ATF_TP_ADD_TC(tp, chown_success);
1354 	ATF_TP_ADD_TC(tp, chown_failure);
1355 	ATF_TP_ADD_TC(tp, fchown_success);
1356 	ATF_TP_ADD_TC(tp, fchown_failure);
1357 	ATF_TP_ADD_TC(tp, lchown_success);
1358 	ATF_TP_ADD_TC(tp, lchown_failure);
1359 	ATF_TP_ADD_TC(tp, fchownat_success);
1360 	ATF_TP_ADD_TC(tp, fchownat_failure);
1361 
1362 	ATF_TP_ADD_TC(tp, chflags_success);
1363 	ATF_TP_ADD_TC(tp, chflags_failure);
1364 	ATF_TP_ADD_TC(tp, fchflags_success);
1365 	ATF_TP_ADD_TC(tp, fchflags_failure);
1366 	ATF_TP_ADD_TC(tp, lchflags_success);
1367 	ATF_TP_ADD_TC(tp, lchflags_failure);
1368 	ATF_TP_ADD_TC(tp, chflagsat_success);
1369 	ATF_TP_ADD_TC(tp, chflagsat_failure);
1370 
1371 	ATF_TP_ADD_TC(tp, utimes_success);
1372 	ATF_TP_ADD_TC(tp, utimes_failure);
1373 	ATF_TP_ADD_TC(tp, futimes_success);
1374 	ATF_TP_ADD_TC(tp, futimes_failure);
1375 	ATF_TP_ADD_TC(tp, lutimes_success);
1376 	ATF_TP_ADD_TC(tp, lutimes_failure);
1377 	ATF_TP_ADD_TC(tp, futimesat_success);
1378 	ATF_TP_ADD_TC(tp, futimesat_failure);
1379 
1380 	ATF_TP_ADD_TC(tp, mprotect_success);
1381 	ATF_TP_ADD_TC(tp, mprotect_failure);
1382 	ATF_TP_ADD_TC(tp, undelete_failure);
1383 
1384 	ATF_TP_ADD_TC(tp, extattr_set_file_success);
1385 	ATF_TP_ADD_TC(tp, extattr_set_file_failure);
1386 	ATF_TP_ADD_TC(tp, extattr_set_fd_success);
1387 	ATF_TP_ADD_TC(tp, extattr_set_fd_failure);
1388 	ATF_TP_ADD_TC(tp, extattr_set_link_success);
1389 	ATF_TP_ADD_TC(tp, extattr_set_link_failure);
1390 
1391 	ATF_TP_ADD_TC(tp, extattr_delete_file_success);
1392 	ATF_TP_ADD_TC(tp, extattr_delete_file_failure);
1393 	ATF_TP_ADD_TC(tp, extattr_delete_fd_success);
1394 	ATF_TP_ADD_TC(tp, extattr_delete_fd_failure);
1395 	ATF_TP_ADD_TC(tp, extattr_delete_link_success);
1396 	ATF_TP_ADD_TC(tp, extattr_delete_link_failure);
1397 
1398 	return (atf_no_error());
1399 }
1400