check permission for verify
| 418 | |
| 419 | // check permission for verify |
| 420 | static int |
| 421 | permission_handler(const char *path, const struct stat *s, int flag) |
| 422 | { |
| 423 | std::string cur_directory = permission_entry.name; |
| 424 | // filter traffic server related files |
| 425 | if (!filter_ts_files(cur_directory, path)) { |
| 426 | return 0; |
| 427 | } |
| 428 | if (flag == FTW_NS || !s) { |
| 429 | ink_warning("unable to stat() destination path %s - %s", path, strerror(errno)); |
| 430 | return -1; |
| 431 | } |
| 432 | |
| 433 | int ret = 0; |
| 434 | // --------- for directories --------- |
| 435 | if (flag == FTW_D || flag == FTW_DNR) { |
| 436 | // always need read permission for directories |
| 437 | if (!(s->st_mode & permission_entry.r_mode)) { |
| 438 | if (fix_flag) { |
| 439 | if (chmod(path, s->st_mode | permission_entry.r_mode) < 0) { |
| 440 | ink_warning("Unable to change file mode on %s - %s", path, strerror(errno)); |
| 441 | } else { |
| 442 | std::cout << "Fixed read permission: " << path << std::endl; |
| 443 | } |
| 444 | } else { |
| 445 | std::cout << "Read permission failed for directory: " << path << std::endl; |
| 446 | ret = -1; |
| 447 | } |
| 448 | } |
| 449 | // need write permission for logdir, runtimedir and cachedir |
| 450 | if (cur_directory == LAYOUT_LOGDIR || cur_directory == LAYOUT_RUNTIMEDIR || cur_directory == LAYOUT_CACHEDIR) { |
| 451 | if (!(s->st_mode & permission_entry.w_mode)) { |
| 452 | if (fix_flag) { |
| 453 | if (chmod(path, s->st_mode | permission_entry.w_mode) < 0) { |
| 454 | ink_warning("Unable to change file mode on %s - %s", path, strerror(errno)); |
| 455 | } else { |
| 456 | std::cout << "Fixed write permission: " << path << std::endl; |
| 457 | } |
| 458 | } else { |
| 459 | std::cout << "Write permission failed for directory: " << path << std::endl; |
| 460 | ret = -1; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | // always need execute permission for directories |
| 465 | if (!(s->st_mode & permission_entry.e_mode)) { |
| 466 | if (fix_flag) { |
| 467 | if (chmod(path, s->st_mode | permission_entry.e_mode) < 0) { |
| 468 | ink_warning("Unable to change file mode on %s - %s", path, strerror(errno)); |
| 469 | } else { |
| 470 | std::cout << "Fixed execute permission: " << path << std::endl; |
| 471 | } |
| 472 | } else { |
| 473 | std::cout << "Execute permission failed for directory: " << path << std::endl; |
| 474 | ret = -1; |
| 475 | } |
| 476 | } |
| 477 | } else { |
nothing calls this directly
no test coverage detected