diff --git a/cfg.c b/cfg.c index a77d9c2..262d0b2 100644 --- a/cfg.c +++ b/cfg.c @@ -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; @@ -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; } @@ -148,19 +155,24 @@ 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; @@ -168,8 +180,11 @@ static int open_safely(int *outfd, size_t *outsize, const char *path) { *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)