| 443 | } |
| 444 | |
| 445 | static FILE *bootstrap_start_failure_open(const char *log_directory, int *status_out) { |
| 446 | char path[BOOTSTRAP_PATH_CAP]; |
| 447 | int written = |
| 448 | snprintf(path, sizeof(path), "%s/%s", log_directory, BOOTSTRAP_START_FAILURE_LOG_NAME); |
| 449 | if (written <= 0 || written >= (int)sizeof(path)) { |
| 450 | *status_out = -1; |
| 451 | return NULL; |
| 452 | } |
| 453 | #ifndef _WIN32 |
| 454 | struct stat status; |
| 455 | if (lstat(path, &status) != 0) { |
| 456 | *status_out = errno == ENOENT ? 0 : -1; |
| 457 | return NULL; |
| 458 | } |
| 459 | if (!S_ISREG(status.st_mode) || status.st_uid != geteuid() || status.st_nlink != 1) { |
| 460 | *status_out = -1; |
| 461 | return NULL; |
| 462 | } |
| 463 | #endif |
| 464 | /* The directory is the trust boundary (owner-only, no symlinked |
| 465 | * ancestry); the same validation guards cbm-daemon.log itself. */ |
| 466 | if (!cbm_daemon_ipc_private_directory_secure(log_directory)) { |
| 467 | *status_out = -1; |
| 468 | return NULL; |
| 469 | } |
| 470 | FILE *file = cbm_fopen(path, "rb"); |
| 471 | if (!file) { |
| 472 | *status_out = errno == ENOENT ? 0 : -1; |
| 473 | return NULL; |
| 474 | } |
| 475 | *status_out = 1; |
| 476 | return file; |
| 477 | } |
| 478 | |
| 479 | int cbm_daemon_bootstrap_start_failure_read(const char *log_directory, |
| 480 | const cbm_daemon_ipc_endpoint_t *endpoint, |
no test coverage detected