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/extattr.h> 30 #include <sys/ucred.h> 31 #include <sys/mount.h> 32 #include <sys/stat.h> 33 #include <sys/syscall.h> 34 35 #include <atf-c.h> 36 #include <fcntl.h> 37 #include <unistd.h> 38 39 #include "utils.h" 40 41 static struct pollfd fds[1]; 42 static mode_t mode = 0777; 43 static pid_t pid; 44 static fhandle_t fht; 45 static int filedesc, fhdesc; 46 static char extregex[80]; 47 static char buff[] = "ezio"; 48 static struct stat statbuff; 49 static struct statfs statfsbuff; 50 static const char *auclass = "fa"; 51 static const char *name = "authorname"; 52 static const char *path = "fileforaudit"; 53 static const char *errpath = "dirdoesnotexist/fileforaudit"; 54 static const char *successreg = "fileforaudit.*return,success"; 55 static const char *failurereg = "fileforaudit.*return,failure"; 56 57 58 ATF_TC_WITH_CLEANUP(stat_success); 59 ATF_TC_HEAD(stat_success, tc) 60 { 61 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 62 "stat(2) call"); 63 } 64 65 ATF_TC_BODY(stat_success, tc) 66 { 67 /* File needs to exist to call stat(2) */ 68 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 69 FILE *pipefd = setup(fds, auclass); 70 ATF_REQUIRE_EQ(0, stat(path, &statbuff)); 71 check_audit(fds, successreg, pipefd); 72 close(filedesc); 73 } 74 75 ATF_TC_CLEANUP(stat_success, tc) 76 { 77 cleanup(); 78 } 79 80 81 ATF_TC_WITH_CLEANUP(stat_failure); 82 ATF_TC_HEAD(stat_failure, tc) 83 { 84 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 85 "stat(2) call"); 86 } 87 88 ATF_TC_BODY(stat_failure, tc) 89 { 90 FILE *pipefd = setup(fds, auclass); 91 /* Failure reason: file does not exist */ 92 ATF_REQUIRE_EQ(-1, stat(errpath, &statbuff)); 93 check_audit(fds, failurereg, pipefd); 94 } 95 96 ATF_TC_CLEANUP(stat_failure, tc) 97 { 98 cleanup(); 99 } 100 101 102 ATF_TC_WITH_CLEANUP(lstat_success); 103 ATF_TC_HEAD(lstat_success, tc) 104 { 105 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 106 "lstat(2) call"); 107 } 108 109 ATF_TC_BODY(lstat_success, tc) 110 { 111 /* Symbolic link needs to exist to call lstat(2) */ 112 ATF_REQUIRE_EQ(0, symlink("symlink", path)); 113 FILE *pipefd = setup(fds, auclass); 114 ATF_REQUIRE_EQ(0, lstat(path, &statbuff)); 115 check_audit(fds, successreg, pipefd); 116 } 117 118 ATF_TC_CLEANUP(lstat_success, tc) 119 { 120 cleanup(); 121 } 122 123 124 ATF_TC_WITH_CLEANUP(lstat_failure); 125 ATF_TC_HEAD(lstat_failure, tc) 126 { 127 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 128 "lstat(2) call"); 129 } 130 131 ATF_TC_BODY(lstat_failure, tc) 132 { 133 FILE *pipefd = setup(fds, auclass); 134 /* Failure reason: symbolic link does not exist */ 135 ATF_REQUIRE_EQ(-1, lstat(errpath, &statbuff)); 136 check_audit(fds, failurereg, pipefd); 137 } 138 139 ATF_TC_CLEANUP(lstat_failure, tc) 140 { 141 cleanup(); 142 } 143 144 145 ATF_TC_WITH_CLEANUP(fstat_success); 146 ATF_TC_HEAD(fstat_success, tc) 147 { 148 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 149 "fstat(2) call"); 150 } 151 152 ATF_TC_BODY(fstat_success, tc) 153 { 154 /* File needs to exist to call fstat(2) */ 155 ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); 156 FILE *pipefd = setup(fds, auclass); 157 ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); 158 159 snprintf(extregex, sizeof(extregex), 160 "fstat.*%jd.*return,success", (intmax_t)statbuff.st_ino); 161 check_audit(fds, extregex, pipefd); 162 close(filedesc); 163 } 164 165 ATF_TC_CLEANUP(fstat_success, tc) 166 { 167 cleanup(); 168 } 169 170 171 ATF_TC_WITH_CLEANUP(fstat_failure); 172 ATF_TC_HEAD(fstat_failure, tc) 173 { 174 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 175 "fstat(2) call"); 176 } 177 178 ATF_TC_BODY(fstat_failure, tc) 179 { 180 FILE *pipefd = setup(fds, auclass); 181 const char *regex = "fstat.*return,failure : Bad file descriptor"; 182 /* Failure reason: bad file descriptor */ 183 ATF_REQUIRE_EQ(-1, fstat(-1, &statbuff)); 184 check_audit(fds, regex, pipefd); 185 } 186 187 ATF_TC_CLEANUP(fstat_failure, tc) 188 { 189 cleanup(); 190 } 191 192 193 ATF_TC_WITH_CLEANUP(fstatat_success); 194 ATF_TC_HEAD(fstatat_success, tc) 195 { 196 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 197 "fstatat(2) call"); 198 } 199 200 ATF_TC_BODY(fstatat_success, tc) 201 { 202 /* File or Symbolic link needs to exist to call lstat(2) */ 203 ATF_REQUIRE_EQ(0, symlink("symlink", path)); 204 FILE *pipefd = setup(fds, auclass); 205 ATF_REQUIRE_EQ(0, fstatat(AT_FDCWD, path, &statbuff, 206 AT_SYMLINK_NOFOLLOW)); 207 check_audit(fds, successreg, pipefd); 208 } 209 210 ATF_TC_CLEANUP(fstatat_success, tc) 211 { 212 cleanup(); 213 } 214 215 216 ATF_TC_WITH_CLEANUP(fstatat_failure); 217 ATF_TC_HEAD(fstatat_failure, tc) 218 { 219 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 220 "fstatat(2) call"); 221 } 222 223 ATF_TC_BODY(fstatat_failure, tc) 224 { 225 FILE *pipefd = setup(fds, auclass); 226 /* Failure reason: symbolic link does not exist */ 227 ATF_REQUIRE_EQ(-1, fstatat(AT_FDCWD, path, &statbuff, 228 AT_SYMLINK_NOFOLLOW)); 229 check_audit(fds, failurereg, pipefd); 230 } 231 232 ATF_TC_CLEANUP(fstatat_failure, tc) 233 { 234 cleanup(); 235 } 236 237 238 ATF_TC_WITH_CLEANUP(statfs_success); 239 ATF_TC_HEAD(statfs_success, tc) 240 { 241 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 242 "statfs(2) call"); 243 } 244 245 ATF_TC_BODY(statfs_success, tc) 246 { 247 /* File needs to exist to call statfs(2) */ 248 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 249 FILE *pipefd = setup(fds, auclass); 250 ATF_REQUIRE_EQ(0, statfs(path, &statfsbuff)); 251 check_audit(fds, successreg, pipefd); 252 close(filedesc); 253 } 254 255 ATF_TC_CLEANUP(statfs_success, tc) 256 { 257 cleanup(); 258 } 259 260 261 ATF_TC_WITH_CLEANUP(statfs_failure); 262 ATF_TC_HEAD(statfs_failure, tc) 263 { 264 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 265 "statfs(2) call"); 266 } 267 268 ATF_TC_BODY(statfs_failure, tc) 269 { 270 FILE *pipefd = setup(fds, auclass); 271 /* Failure reason: file does not exist */ 272 ATF_REQUIRE_EQ(-1, statfs(errpath, &statfsbuff)); 273 check_audit(fds, failurereg, pipefd); 274 } 275 276 ATF_TC_CLEANUP(statfs_failure, tc) 277 { 278 cleanup(); 279 } 280 281 282 ATF_TC_WITH_CLEANUP(fstatfs_success); 283 ATF_TC_HEAD(fstatfs_success, tc) 284 { 285 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 286 "fstatfs(2) call"); 287 } 288 289 ATF_TC_BODY(fstatfs_success, tc) 290 { 291 /* File needs to exist to call fstat(2) */ 292 ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); 293 /* Call stat(2) to store the Inode number of 'path' */ 294 ATF_REQUIRE_EQ(0, stat(path, &statbuff)); 295 FILE *pipefd = setup(fds, auclass); 296 ATF_REQUIRE_EQ(0, fstatfs(filedesc, &statfsbuff)); 297 298 snprintf(extregex, sizeof(extregex), "fstatfs.*%jd.*return,success", 299 (intmax_t)statbuff.st_ino); 300 check_audit(fds, extregex, pipefd); 301 close(filedesc); 302 } 303 304 ATF_TC_CLEANUP(fstatfs_success, tc) 305 { 306 cleanup(); 307 } 308 309 310 ATF_TC_WITH_CLEANUP(fstatfs_failure); 311 ATF_TC_HEAD(fstatfs_failure, tc) 312 { 313 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 314 "fstatfs(2) call"); 315 } 316 317 ATF_TC_BODY(fstatfs_failure, tc) 318 { 319 FILE *pipefd = setup(fds, auclass); 320 const char *regex = "fstatfs.*return,failure : Bad file descriptor"; 321 /* Failure reason: bad file descriptor */ 322 ATF_REQUIRE_EQ(-1, fstatfs(-1, &statfsbuff)); 323 check_audit(fds, regex, pipefd); 324 } 325 326 ATF_TC_CLEANUP(fstatfs_failure, tc) 327 { 328 cleanup(); 329 } 330 331 332 ATF_TC_WITH_CLEANUP(getfsstat_success); 333 ATF_TC_HEAD(getfsstat_success, tc) 334 { 335 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 336 "getfsstat(2) call"); 337 } 338 339 ATF_TC_BODY(getfsstat_success, tc) 340 { 341 pid = getpid(); 342 snprintf(extregex, sizeof(extregex), "getfsstat.*%d.*success", pid); 343 344 FILE *pipefd = setup(fds, auclass); 345 ATF_REQUIRE(getfsstat(NULL, 0, MNT_NOWAIT) != -1); 346 check_audit(fds, extregex, pipefd); 347 } 348 349 ATF_TC_CLEANUP(getfsstat_success, tc) 350 { 351 cleanup(); 352 } 353 354 355 ATF_TC_WITH_CLEANUP(getfsstat_failure); 356 ATF_TC_HEAD(getfsstat_failure, tc) 357 { 358 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 359 "getfsstat(2) call"); 360 } 361 362 ATF_TC_BODY(getfsstat_failure, tc) 363 { 364 const char *regex = "getfsstat.*return,failure : Invalid argument"; 365 FILE *pipefd = setup(fds, auclass); 366 /* Failure reason: Invalid value for mode */ 367 ATF_REQUIRE_EQ(-1, getfsstat(NULL, 0, -1)); 368 check_audit(fds, regex, pipefd); 369 } 370 371 ATF_TC_CLEANUP(getfsstat_failure, tc) 372 { 373 cleanup(); 374 } 375 376 377 ATF_TC_WITH_CLEANUP(fhopen_success); 378 ATF_TC_HEAD(fhopen_success, tc) 379 { 380 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 381 "fhopen(2) call"); 382 } 383 384 ATF_TC_BODY(fhopen_success, tc) 385 { 386 pid = getpid(); 387 snprintf(extregex, sizeof(extregex), "fhopen.*%d.*return,success", pid); 388 389 /* File needs to exist to get a file-handle */ 390 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 391 /* Get the file handle to be passed to fhopen(2) */ 392 ATF_REQUIRE_EQ(0, getfh(path, &fht)); 393 394 FILE *pipefd = setup(fds, auclass); 395 ATF_REQUIRE((fhdesc = fhopen(&fht, O_RDWR)) != -1); 396 check_audit(fds, extregex, pipefd); 397 398 close(fhdesc); 399 close(filedesc); 400 } 401 402 ATF_TC_CLEANUP(fhopen_success, tc) 403 { 404 cleanup(); 405 } 406 407 408 ATF_TC_WITH_CLEANUP(fhopen_failure); 409 ATF_TC_HEAD(fhopen_failure, tc) 410 { 411 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 412 "fhopen(2) call"); 413 } 414 415 ATF_TC_BODY(fhopen_failure, tc) 416 { 417 const char *regex = "fhopen.*return,failure : Invalid argument"; 418 FILE *pipefd = setup(fds, auclass); 419 /* 420 * Failure reason: NULL does not represent any file handle 421 * and O_CREAT is not allowed as the flag for fhopen(2) 422 */ 423 ATF_REQUIRE_EQ(-1, fhopen(NULL, O_CREAT)); 424 check_audit(fds, regex, pipefd); 425 } 426 427 ATF_TC_CLEANUP(fhopen_failure, tc) 428 { 429 cleanup(); 430 } 431 432 433 ATF_TC_WITH_CLEANUP(fhstat_success); 434 ATF_TC_HEAD(fhstat_success, tc) 435 { 436 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 437 "fstat(2) call"); 438 } 439 440 ATF_TC_BODY(fhstat_success, tc) 441 { 442 pid = getpid(); 443 snprintf(extregex, sizeof(extregex), "fhstat.*%d.*return,success", pid); 444 445 /* File needs to exist to get a file-handle */ 446 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 447 /* Get the file handle to be passed to fhstat(2) */ 448 ATF_REQUIRE_EQ(0, getfh(path, &fht)); 449 450 FILE *pipefd = setup(fds, auclass); 451 ATF_REQUIRE_EQ(0, fhstat(&fht, &statbuff)); 452 check_audit(fds, extregex, pipefd); 453 close(filedesc); 454 } 455 456 ATF_TC_CLEANUP(fhstat_success, tc) 457 { 458 cleanup(); 459 } 460 461 462 ATF_TC_WITH_CLEANUP(fhstat_failure); 463 ATF_TC_HEAD(fhstat_failure, tc) 464 { 465 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 466 "fhstat(2) call"); 467 } 468 469 ATF_TC_BODY(fhstat_failure, tc) 470 { 471 const char *regex = "fhstat.*return,failure : Bad address"; 472 FILE *pipefd = setup(fds, auclass); 473 /* Failure reason: NULL does not represent any file handle */ 474 ATF_REQUIRE_EQ(-1, fhstat(NULL, NULL)); 475 check_audit(fds, regex, pipefd); 476 } 477 478 ATF_TC_CLEANUP(fhstat_failure, tc) 479 { 480 cleanup(); 481 } 482 483 484 ATF_TC_WITH_CLEANUP(fhstatfs_success); 485 ATF_TC_HEAD(fhstatfs_success, tc) 486 { 487 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 488 "fstatfs(2) call"); 489 } 490 491 ATF_TC_BODY(fhstatfs_success, tc) 492 { 493 pid = getpid(); 494 snprintf(extregex, sizeof(extregex), "fhstatfs.*%d.*success", pid); 495 496 /* File needs to exist to get a file-handle */ 497 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 498 /* Get the file handle to be passed to fhstatfs(2) */ 499 ATF_REQUIRE_EQ(0, getfh(path, &fht)); 500 501 FILE *pipefd = setup(fds, auclass); 502 ATF_REQUIRE_EQ(0, fhstatfs(&fht, &statfsbuff)); 503 check_audit(fds, extregex, pipefd); 504 close(filedesc); 505 } 506 507 ATF_TC_CLEANUP(fhstatfs_success, tc) 508 { 509 cleanup(); 510 } 511 512 513 ATF_TC_WITH_CLEANUP(fhstatfs_failure); 514 ATF_TC_HEAD(fhstatfs_failure, tc) 515 { 516 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 517 "fhstatfs(2) call"); 518 } 519 520 ATF_TC_BODY(fhstatfs_failure, tc) 521 { 522 const char *regex = "fhstatfs.*return,failure : Bad address"; 523 FILE *pipefd = setup(fds, auclass); 524 /* Failure reason: NULL does not represent any file handle */ 525 ATF_REQUIRE_EQ(-1, fhstatfs(NULL, NULL)); 526 check_audit(fds, regex, pipefd); 527 } 528 529 ATF_TC_CLEANUP(fhstatfs_failure, tc) 530 { 531 cleanup(); 532 } 533 534 535 ATF_TC_WITH_CLEANUP(access_success); 536 ATF_TC_HEAD(access_success, tc) 537 { 538 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 539 "access(2) call"); 540 } 541 542 ATF_TC_BODY(access_success, tc) 543 { 544 /* File needs to exist to call access(2) */ 545 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 546 FILE *pipefd = setup(fds, auclass); 547 ATF_REQUIRE_EQ(0, access(path, F_OK)); 548 check_audit(fds, successreg, pipefd); 549 close(filedesc); 550 } 551 552 ATF_TC_CLEANUP(access_success, tc) 553 { 554 cleanup(); 555 } 556 557 558 ATF_TC_WITH_CLEANUP(access_failure); 559 ATF_TC_HEAD(access_failure, tc) 560 { 561 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 562 "access(2) call"); 563 } 564 565 ATF_TC_BODY(access_failure, tc) 566 { 567 FILE *pipefd = setup(fds, auclass); 568 /* Failure reason: file does not exist */ 569 ATF_REQUIRE_EQ(-1, access(errpath, F_OK)); 570 check_audit(fds, failurereg, pipefd); 571 } 572 573 ATF_TC_CLEANUP(access_failure, tc) 574 { 575 cleanup(); 576 } 577 578 579 ATF_TC_WITH_CLEANUP(eaccess_success); 580 ATF_TC_HEAD(eaccess_success, tc) 581 { 582 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 583 "eaccess(2) call"); 584 } 585 586 ATF_TC_BODY(eaccess_success, tc) 587 { 588 /* File needs to exist to call eaccess(2) */ 589 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 590 FILE *pipefd = setup(fds, auclass); 591 ATF_REQUIRE_EQ(0, eaccess(path, F_OK)); 592 check_audit(fds, successreg, pipefd); 593 close(filedesc); 594 } 595 596 ATF_TC_CLEANUP(eaccess_success, tc) 597 { 598 cleanup(); 599 } 600 601 602 ATF_TC_WITH_CLEANUP(eaccess_failure); 603 ATF_TC_HEAD(eaccess_failure, tc) 604 { 605 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 606 "eaccess(2) call"); 607 } 608 609 ATF_TC_BODY(eaccess_failure, tc) 610 { 611 FILE *pipefd = setup(fds, auclass); 612 /* Failure reason: file does not exist */ 613 ATF_REQUIRE_EQ(-1, eaccess(errpath, F_OK)); 614 check_audit(fds, failurereg, pipefd); 615 } 616 617 ATF_TC_CLEANUP(eaccess_failure, tc) 618 { 619 cleanup(); 620 } 621 622 623 ATF_TC_WITH_CLEANUP(faccessat_success); 624 ATF_TC_HEAD(faccessat_success, tc) 625 { 626 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 627 "faccessat(2) call"); 628 } 629 630 ATF_TC_BODY(faccessat_success, tc) 631 { 632 /* File needs to exist to call faccessat(2) */ 633 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 634 FILE *pipefd = setup(fds, auclass); 635 ATF_REQUIRE_EQ(0, faccessat(AT_FDCWD, path, F_OK, AT_EACCESS)); 636 check_audit(fds, successreg, pipefd); 637 close(filedesc); 638 } 639 640 ATF_TC_CLEANUP(faccessat_success, tc) 641 { 642 cleanup(); 643 } 644 645 646 ATF_TC_WITH_CLEANUP(faccessat_failure); 647 ATF_TC_HEAD(faccessat_failure, tc) 648 { 649 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 650 "faccessat(2) call"); 651 } 652 653 ATF_TC_BODY(faccessat_failure, tc) 654 { 655 FILE *pipefd = setup(fds, auclass); 656 /* Failure reason: file does not exist */ 657 ATF_REQUIRE_EQ(-1, faccessat(AT_FDCWD, errpath, F_OK, AT_EACCESS)); 658 check_audit(fds, failurereg, pipefd); 659 } 660 661 ATF_TC_CLEANUP(faccessat_failure, tc) 662 { 663 cleanup(); 664 } 665 666 667 ATF_TC_WITH_CLEANUP(pathconf_success); 668 ATF_TC_HEAD(pathconf_success, tc) 669 { 670 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 671 "pathconf(2) call"); 672 } 673 674 ATF_TC_BODY(pathconf_success, tc) 675 { 676 /* File needs to exist to call pathconf(2) */ 677 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 678 FILE *pipefd = setup(fds, auclass); 679 /* Get the maximum number of bytes of filename */ 680 ATF_REQUIRE(pathconf(path, _PC_NAME_MAX) != -1); 681 check_audit(fds, successreg, pipefd); 682 close(filedesc); 683 } 684 685 ATF_TC_CLEANUP(pathconf_success, tc) 686 { 687 cleanup(); 688 } 689 690 691 ATF_TC_WITH_CLEANUP(pathconf_failure); 692 ATF_TC_HEAD(pathconf_failure, tc) 693 { 694 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 695 "pathconf(2) call"); 696 } 697 698 ATF_TC_BODY(pathconf_failure, tc) 699 { 700 FILE *pipefd = setup(fds, auclass); 701 /* Failure reason: file does not exist */ 702 ATF_REQUIRE_EQ(-1, pathconf(errpath, _PC_NAME_MAX)); 703 check_audit(fds, failurereg, pipefd); 704 } 705 706 ATF_TC_CLEANUP(pathconf_failure, tc) 707 { 708 cleanup(); 709 } 710 711 712 ATF_TC_WITH_CLEANUP(lpathconf_success); 713 ATF_TC_HEAD(lpathconf_success, tc) 714 { 715 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 716 "lpathconf(2) call"); 717 } 718 719 ATF_TC_BODY(lpathconf_success, tc) 720 { 721 /* Symbolic link needs to exist to call lpathconf(2) */ 722 ATF_REQUIRE_EQ(0, symlink("symlink", path)); 723 FILE *pipefd = setup(fds, auclass); 724 /* Get the maximum number of bytes of symlink's name */ 725 ATF_REQUIRE(lpathconf(path, _PC_SYMLINK_MAX) != -1); 726 check_audit(fds, successreg, pipefd); 727 } 728 729 ATF_TC_CLEANUP(lpathconf_success, tc) 730 { 731 cleanup(); 732 } 733 734 735 ATF_TC_WITH_CLEANUP(lpathconf_failure); 736 ATF_TC_HEAD(lpathconf_failure, tc) 737 { 738 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 739 "lpathconf(2) call"); 740 } 741 742 ATF_TC_BODY(lpathconf_failure, tc) 743 { 744 FILE *pipefd = setup(fds, auclass); 745 /* Failure reason: symbolic link does not exist */ 746 ATF_REQUIRE_EQ(-1, lpathconf(errpath, _PC_SYMLINK_MAX)); 747 check_audit(fds, failurereg, pipefd); 748 } 749 750 ATF_TC_CLEANUP(lpathconf_failure, tc) 751 { 752 cleanup(); 753 } 754 755 756 ATF_TC_WITH_CLEANUP(fpathconf_success); 757 ATF_TC_HEAD(fpathconf_success, tc) 758 { 759 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 760 "fpathconf(2) call"); 761 } 762 763 ATF_TC_BODY(fpathconf_success, tc) 764 { 765 pid = getpid(); 766 snprintf(extregex, sizeof(extregex), "fpathconf.*%d.*success", pid); 767 768 /* File needs to exist to call fpathconf(2) */ 769 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 770 FILE *pipefd = setup(fds, auclass); 771 /* Get the maximum number of bytes of filename */ 772 ATF_REQUIRE(fpathconf(filedesc, _PC_NAME_MAX) != -1); 773 check_audit(fds, extregex, pipefd); 774 close(filedesc); 775 } 776 777 ATF_TC_CLEANUP(fpathconf_success, tc) 778 { 779 cleanup(); 780 } 781 782 783 ATF_TC_WITH_CLEANUP(fpathconf_failure); 784 ATF_TC_HEAD(fpathconf_failure, tc) 785 { 786 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 787 "fpathconf(2) call"); 788 } 789 790 ATF_TC_BODY(fpathconf_failure, tc) 791 { 792 FILE *pipefd = setup(fds, auclass); 793 const char *regex = "fpathconf.*return,failure : Bad file descriptor"; 794 /* Failure reason: Bad file descriptor */ 795 ATF_REQUIRE_EQ(-1, fpathconf(-1, _PC_NAME_MAX)); 796 check_audit(fds, regex, pipefd); 797 } 798 799 ATF_TC_CLEANUP(fpathconf_failure, tc) 800 { 801 cleanup(); 802 } 803 804 805 ATF_TC_WITH_CLEANUP(extattr_get_file_success); 806 ATF_TC_HEAD(extattr_get_file_success, tc) 807 { 808 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 809 "extattr_get_file(2) call"); 810 } 811 812 ATF_TC_BODY(extattr_get_file_success, tc) 813 { 814 /* File needs to exist to call extattr_get_file(2) */ 815 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 816 /* Set an extended attribute to be retrieved later on */ 817 ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, 818 EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 819 820 /* Prepare the regex to be checked in the audit record */ 821 snprintf(extregex, sizeof(extregex), 822 "extattr_get_file.*%s.*%s.*return,success", path, name); 823 824 FILE *pipefd = setup(fds, auclass); 825 ATF_REQUIRE_EQ(sizeof(buff), extattr_get_file(path, 826 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 827 check_audit(fds, extregex, pipefd); 828 close(filedesc); 829 } 830 831 ATF_TC_CLEANUP(extattr_get_file_success, tc) 832 { 833 cleanup(); 834 } 835 836 837 ATF_TC_WITH_CLEANUP(extattr_get_file_failure); 838 ATF_TC_HEAD(extattr_get_file_failure, tc) 839 { 840 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 841 "extattr_get_file(2) call"); 842 } 843 844 ATF_TC_BODY(extattr_get_file_failure, tc) 845 { 846 /* Prepare the regex to be checked in the audit record */ 847 snprintf(extregex, sizeof(extregex), 848 "extattr_get_file.*%s.*%s.*failure", path, name); 849 850 FILE *pipefd = setup(fds, auclass); 851 /* Failure reason: file does not exist */ 852 ATF_REQUIRE_EQ(-1, extattr_get_file(path, 853 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 854 check_audit(fds, extregex, pipefd); 855 } 856 857 ATF_TC_CLEANUP(extattr_get_file_failure, tc) 858 { 859 cleanup(); 860 } 861 862 863 ATF_TC_WITH_CLEANUP(extattr_get_fd_success); 864 ATF_TC_HEAD(extattr_get_fd_success, tc) 865 { 866 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 867 "extattr_get_fd(2) call"); 868 } 869 870 ATF_TC_BODY(extattr_get_fd_success, tc) 871 { 872 /* File needs to exist to call extattr_get_fd(2) */ 873 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 874 /* Set an extended attribute to be retrieved later on */ 875 ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, 876 EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 877 878 /* Prepare the regex to be checked in the audit record */ 879 snprintf(extregex, sizeof(extregex), 880 "extattr_get_fd.*%s.*return,success", name); 881 882 FILE *pipefd = setup(fds, auclass); 883 ATF_REQUIRE_EQ(sizeof(buff), extattr_get_fd(filedesc, 884 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 885 check_audit(fds, extregex, pipefd); 886 close(filedesc); 887 } 888 889 ATF_TC_CLEANUP(extattr_get_fd_success, tc) 890 { 891 cleanup(); 892 } 893 894 895 ATF_TC_WITH_CLEANUP(extattr_get_fd_failure); 896 ATF_TC_HEAD(extattr_get_fd_failure, tc) 897 { 898 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 899 "extattr_get_fd(2) call"); 900 } 901 902 ATF_TC_BODY(extattr_get_fd_failure, tc) 903 { 904 /* Prepare the regex to be checked in the audit record */ 905 snprintf(extregex, sizeof(extregex), 906 "extattr_get_fd.*%s.*return,failure : Bad file descriptor", name); 907 908 FILE *pipefd = setup(fds, auclass); 909 /* Failure reason: Invalid file descriptor */ 910 ATF_REQUIRE_EQ(-1, extattr_get_fd(-1, 911 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 912 check_audit(fds, extregex, pipefd); 913 } 914 915 ATF_TC_CLEANUP(extattr_get_fd_failure, tc) 916 { 917 cleanup(); 918 } 919 920 921 ATF_TC_WITH_CLEANUP(extattr_get_link_success); 922 ATF_TC_HEAD(extattr_get_link_success, tc) 923 { 924 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 925 "extattr_get_link(2) call"); 926 } 927 928 ATF_TC_BODY(extattr_get_link_success, tc) 929 { 930 /* Symbolic link needs to exist to call extattr_get_link(2) */ 931 ATF_REQUIRE_EQ(0, symlink("symlink", path)); 932 /* Set an extended attribute to be retrieved later on */ 933 ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, 934 EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 935 936 /* Prepare the regex to be checked in the audit record */ 937 snprintf(extregex, sizeof(extregex), 938 "extattr_get_link.*%s.*%s.*return,success", path, name); 939 940 FILE *pipefd = setup(fds, auclass); 941 ATF_REQUIRE_EQ(sizeof(buff), extattr_get_link(path, 942 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 943 check_audit(fds, extregex, pipefd); 944 } 945 946 ATF_TC_CLEANUP(extattr_get_link_success, tc) 947 { 948 cleanup(); 949 } 950 951 952 ATF_TC_WITH_CLEANUP(extattr_get_link_failure); 953 ATF_TC_HEAD(extattr_get_link_failure, tc) 954 { 955 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 956 "extattr_get_link(2) call"); 957 } 958 959 ATF_TC_BODY(extattr_get_link_failure, tc) 960 { 961 /* Prepare the regex to be checked in the audit record */ 962 snprintf(extregex, sizeof(extregex), 963 "extattr_get_link.*%s.*%s.*failure", path, name); 964 FILE *pipefd = setup(fds, auclass); 965 /* Failure reason: symbolic link does not exist */ 966 ATF_REQUIRE_EQ(-1, extattr_get_link(path, 967 EXTATTR_NAMESPACE_USER, name, NULL, 0)); 968 check_audit(fds, extregex, pipefd); 969 } 970 971 ATF_TC_CLEANUP(extattr_get_link_failure, tc) 972 { 973 cleanup(); 974 } 975 976 977 ATF_TC_WITH_CLEANUP(extattr_list_file_success); 978 ATF_TC_HEAD(extattr_list_file_success, tc) 979 { 980 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 981 "extattr_list_file(2) call"); 982 } 983 984 ATF_TC_BODY(extattr_list_file_success, tc) 985 { 986 int readbuff; 987 /* File needs to exist to call extattr_list_file(2) */ 988 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 989 990 FILE *pipefd = setup(fds, auclass); 991 ATF_REQUIRE((readbuff = extattr_list_file(path, 992 EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); 993 /* Prepare the regex to be checked in the audit record */ 994 snprintf(extregex, sizeof(extregex), 995 "extattr_list_file.*%s.*return,success,%d", path, readbuff); 996 check_audit(fds, extregex, pipefd); 997 } 998 999 ATF_TC_CLEANUP(extattr_list_file_success, tc) 1000 { 1001 cleanup(); 1002 } 1003 1004 1005 ATF_TC_WITH_CLEANUP(extattr_list_file_failure); 1006 ATF_TC_HEAD(extattr_list_file_failure, tc) 1007 { 1008 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 1009 "extattr_list_file(2) call"); 1010 } 1011 1012 ATF_TC_BODY(extattr_list_file_failure, tc) 1013 { 1014 /* Prepare the regex to be checked in the audit record */ 1015 snprintf(extregex, sizeof(extregex), 1016 "extattr_list_file.*%s.*return,failure", path); 1017 1018 FILE *pipefd = setup(fds, auclass); 1019 /* Failure reason: file does not exist */ 1020 ATF_REQUIRE_EQ(-1, extattr_list_file(path, 1021 EXTATTR_NAMESPACE_USER, NULL, 0)); 1022 check_audit(fds, extregex, pipefd); 1023 } 1024 1025 ATF_TC_CLEANUP(extattr_list_file_failure, tc) 1026 { 1027 cleanup(); 1028 } 1029 1030 1031 ATF_TC_WITH_CLEANUP(extattr_list_fd_success); 1032 ATF_TC_HEAD(extattr_list_fd_success, tc) 1033 { 1034 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 1035 "extattr_list_fd(2) call"); 1036 } 1037 1038 ATF_TC_BODY(extattr_list_fd_success, tc) 1039 { 1040 int readbuff; 1041 /* File needs to exist to call extattr_list_fd(2) */ 1042 ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 1043 1044 FILE *pipefd = setup(fds, auclass); 1045 ATF_REQUIRE((readbuff = extattr_list_fd(filedesc, 1046 EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); 1047 /* Prepare the regex to be checked in the audit record */ 1048 snprintf(extregex, sizeof(extregex), 1049 "extattr_list_fd.*return,success,%d", readbuff); 1050 check_audit(fds, extregex, pipefd); 1051 close(filedesc); 1052 } 1053 1054 ATF_TC_CLEANUP(extattr_list_fd_success, tc) 1055 { 1056 cleanup(); 1057 } 1058 1059 1060 ATF_TC_WITH_CLEANUP(extattr_list_fd_failure); 1061 ATF_TC_HEAD(extattr_list_fd_failure, tc) 1062 { 1063 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 1064 "extattr_list_fd(2) call"); 1065 } 1066 1067 ATF_TC_BODY(extattr_list_fd_failure, tc) 1068 { 1069 /* Prepare the regex to be checked in the audit record */ 1070 snprintf(extregex, sizeof(extregex), 1071 "extattr_list_fd.*return,failure : Bad file descriptor"); 1072 1073 FILE *pipefd = setup(fds, auclass); 1074 /* Failure reason: Invalid file descriptor */ 1075 ATF_REQUIRE_EQ(-1, 1076 extattr_list_fd(-1, EXTATTR_NAMESPACE_USER, NULL, 0)); 1077 check_audit(fds, extregex, pipefd); 1078 } 1079 1080 ATF_TC_CLEANUP(extattr_list_fd_failure, tc) 1081 { 1082 cleanup(); 1083 } 1084 1085 1086 ATF_TC_WITH_CLEANUP(extattr_list_link_success); 1087 ATF_TC_HEAD(extattr_list_link_success, tc) 1088 { 1089 atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 1090 "extattr_list_link(2) call"); 1091 } 1092 1093 ATF_TC_BODY(extattr_list_link_success, tc) 1094 { 1095 int readbuff; 1096 /* Symbolic link needs to exist to call extattr_list_link(2) */ 1097 ATF_REQUIRE_EQ(0, symlink("symlink", path)); 1098 FILE *pipefd = setup(fds, auclass); 1099 1100 ATF_REQUIRE((readbuff = extattr_list_link(path, 1101 EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); 1102 /* Prepare the regex to be checked in the audit record */ 1103 snprintf(extregex, sizeof(extregex), 1104 "extattr_list_link.*%s.*return,success,%d", path, readbuff); 1105 check_audit(fds, extregex, pipefd); 1106 } 1107 1108 ATF_TC_CLEANUP(extattr_list_link_success, tc) 1109 { 1110 cleanup(); 1111 } 1112 1113 1114 ATF_TC_WITH_CLEANUP(extattr_list_link_failure); 1115 ATF_TC_HEAD(extattr_list_link_failure, tc) 1116 { 1117 atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 1118 "extattr_list_link(2) call"); 1119 } 1120 1121 ATF_TC_BODY(extattr_list_link_failure, tc) 1122 { 1123 /* Prepare the regex to be checked in the audit record */ 1124 snprintf(extregex, sizeof(extregex), 1125 "extattr_list_link.*%s.*failure", path); 1126 FILE *pipefd = setup(fds, auclass); 1127 /* Failure reason: symbolic link does not exist */ 1128 ATF_REQUIRE_EQ(-1, extattr_list_link(path, 1129 EXTATTR_NAMESPACE_USER, NULL, 0)); 1130 check_audit(fds, extregex, pipefd); 1131 } 1132 1133 ATF_TC_CLEANUP(extattr_list_link_failure, tc) 1134 { 1135 cleanup(); 1136 } 1137 1138 1139 ATF_TP_ADD_TCS(tp) 1140 { 1141 ATF_TP_ADD_TC(tp, stat_success); 1142 ATF_TP_ADD_TC(tp, stat_failure); 1143 ATF_TP_ADD_TC(tp, lstat_success); 1144 ATF_TP_ADD_TC(tp, lstat_failure); 1145 ATF_TP_ADD_TC(tp, fstat_success); 1146 ATF_TP_ADD_TC(tp, fstat_failure); 1147 ATF_TP_ADD_TC(tp, fstatat_success); 1148 ATF_TP_ADD_TC(tp, fstatat_failure); 1149 1150 ATF_TP_ADD_TC(tp, statfs_success); 1151 ATF_TP_ADD_TC(tp, statfs_failure); 1152 ATF_TP_ADD_TC(tp, fstatfs_success); 1153 ATF_TP_ADD_TC(tp, fstatfs_failure); 1154 1155 ATF_TP_ADD_TC(tp, getfsstat_success); 1156 ATF_TP_ADD_TC(tp, getfsstat_failure); 1157 1158 ATF_TP_ADD_TC(tp, fhopen_success); 1159 ATF_TP_ADD_TC(tp, fhopen_failure); 1160 ATF_TP_ADD_TC(tp, fhstat_success); 1161 ATF_TP_ADD_TC(tp, fhstat_failure); 1162 ATF_TP_ADD_TC(tp, fhstatfs_success); 1163 ATF_TP_ADD_TC(tp, fhstatfs_failure); 1164 1165 ATF_TP_ADD_TC(tp, access_success); 1166 ATF_TP_ADD_TC(tp, access_failure); 1167 ATF_TP_ADD_TC(tp, eaccess_success); 1168 ATF_TP_ADD_TC(tp, eaccess_failure); 1169 ATF_TP_ADD_TC(tp, faccessat_success); 1170 ATF_TP_ADD_TC(tp, faccessat_failure); 1171 1172 ATF_TP_ADD_TC(tp, pathconf_success); 1173 ATF_TP_ADD_TC(tp, pathconf_failure); 1174 ATF_TP_ADD_TC(tp, lpathconf_success); 1175 ATF_TP_ADD_TC(tp, lpathconf_failure); 1176 ATF_TP_ADD_TC(tp, fpathconf_success); 1177 ATF_TP_ADD_TC(tp, fpathconf_failure); 1178 1179 ATF_TP_ADD_TC(tp, extattr_get_file_success); 1180 ATF_TP_ADD_TC(tp, extattr_get_file_failure); 1181 ATF_TP_ADD_TC(tp, extattr_get_fd_success); 1182 ATF_TP_ADD_TC(tp, extattr_get_fd_failure); 1183 ATF_TP_ADD_TC(tp, extattr_get_link_success); 1184 ATF_TP_ADD_TC(tp, extattr_get_link_failure); 1185 1186 ATF_TP_ADD_TC(tp, extattr_list_file_success); 1187 ATF_TP_ADD_TC(tp, extattr_list_file_failure); 1188 ATF_TP_ADD_TC(tp, extattr_list_fd_success); 1189 ATF_TP_ADD_TC(tp, extattr_list_fd_failure); 1190 ATF_TP_ADD_TC(tp, extattr_list_link_success); 1191 ATF_TP_ADD_TC(tp, extattr_list_link_failure); 1192 1193 return (atf_no_error()); 1194 } 1195