Skip to content

Commit

Permalink
TMP: debug macos
Browse files Browse the repository at this point in the history
  • Loading branch information
dacav committed Jan 3, 2025
1 parent 7277135 commit 2b6c61b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ static int open_safely(int *outfd, size_t *outsize, const char *path) {
size_t len;
struct stat st;

unsigned int Step = 0;
fprintf(stderr, "Enter %s (%s)\n", __func__, path);

len = strlen(path);
if (!len || path[0] != '/' || path[len - 1] == '/')
return PAM_SERVICE_ERR;
Expand All @@ -117,18 +120,22 @@ static int open_safely(int *outfd, size_t *outsize, const char *path) {

p = strtok_r(copy, "/", &saveptr);
parent_fd = open("/", O_RDONLY | O_CLOEXEC | O_DIRECTORY, 0);
Step = 2;
if (parent_fd == -1)
goto exit;

*outfd = -1;
*outsize = 0;

Step = 10;
while ((c = strtok_r(NULL, "/", &saveptr)) != NULL) {
fd =
openat(parent_fd, p, O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW, 0);
fprintf(stderr, "%s check %s (%d)\n", __func__, p, fd);
if (fd == -1) {
if (errno == ENOENT)
r = PAM_SUCCESS;
Step++;
goto exit;
}

Expand All @@ -148,28 +155,36 @@ static int open_safely(int *outfd, size_t *outsize, const char *path) {
}

fd = openat(parent_fd, p, O_RDONLY | O_CLOEXEC | O_NOCTTY | O_NOFOLLOW, 0);
fprintf(stderr, "%s lastcheck %s (%d)\n", __func__, p, fd);
if (fd == -1) {
if (errno == ENOENT)
r = PAM_SUCCESS;
Step = 100;
goto exit;
}

Step = 101;
if (fstat(fd, &st))
goto exit;

#ifndef PAM_U2F_TESTING
Step = 102;
if (st.st_uid != 0)
goto exit;
#endif
Step = 103;
if (!S_ISREG(st.st_mode) || st.st_mode & (S_IWGRP | S_IWOTH))
goto exit;

*outfd = fd;
*outsize = st.st_size;
fd = -1;
r = PAM_SUCCESS;
Step = 1000;

exit:
fprintf(stderr, "%s Exit %d at step %u, errno=[%s]\n", __func__, r, Step,
strerror(errno));
if (parent_fd != -1)
close(parent_fd);
if (fd != -1)
Expand Down

0 comments on commit 2b6c61b

Please sign in to comment.