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