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 1e9bb39 commit 48b9b17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion build-aux/ci/build-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export PKG_CONFIG_PATH="${LIBFIDO2_PKGCONF}:${OPENSSL_PKGCONF}"
./autogen.sh
./configure --disable-silent-rules --disable-man
make -j $(sysctl -n hw.logicalcpu)
make check
make check || {
more tests/*.log
exit 1
}
29 changes: 27 additions & 2 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,59 +120,81 @@ 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;

system("ls -ld /usr/local/etc");

Step = 1000;
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;
fprintf(stderr, " _ fd=-1 errno=[%d %s] ENOENT=[%d %s]\n", errno,
strerror(errno), ENOENT, strerror(ENOENT));
goto exit;
}

if (fstat(fd, &st))
if (fstat(fd, &st)) {
fprintf(stderr, " _ fstat errno=[%d %s]\n", errno, strerror(errno));
goto exit;
}

#ifndef PAM_U2F_TESTING
if (st.st_uid != 0)
goto exit;
#endif
if (!S_ISDIR(st.st_mode) || st.st_mode & (S_IWGRP | S_IWOTH))
if (!S_ISDIR(st.st_mode) || st.st_mode & (S_IWGRP | S_IWOTH)) {
fprintf(stderr, " _ mode %d %d\n", !S_ISDIR(st.st_mode),
st.st_mode & (S_IWGRP | S_IWOTH));
goto exit;
}

close(parent_fd);
parent_fd = fd;

Step += 100;
p = c;
}

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 = 10000;
goto exit;
}

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

#ifndef PAM_U2F_TESTING
Step = 10002;
if (st.st_uid != 0)
goto exit;
#endif
Step = 10003;
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 = 99999;

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

0 comments on commit 48b9b17

Please sign in to comment.