diff --git a/auth2-pubkeyfile.c b/auth2-pubkeyfile.c index 0cfacac35..f7d262a17 100644 --- a/auth2-pubkeyfile.c +++ b/auth2-pubkeyfile.c @@ -448,6 +448,23 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes, int fd; FILE *f; +#ifdef WINDOWS + /* Windows POSIX adapter does not support fdopen() on open(file)*/ + if ((f = fopen(file, "r")) == NULL) { + debug("Could not open %s '%s': %s", file_type, file, + strerror(errno)); + return NULL; + } + + // read permissions for non-admin/non-system accounts are allowed. + // Unix does safe_path_fd() which allows 022 file permissions i.e., allowing read for other users. + if (strict_modes && check_secure_file_permission(file, pw, 1) != 0) { + fclose(f); + logit("Authentication refused."); + auth_debug_add("Ignored %s", file_type); + return NULL; + } +#else /* !WINDOWS */ if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) { if (errno != ENOENT) { logit("Could not open user '%s' %s '%s': %s", @@ -481,6 +498,7 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes, auth_debug_add("Ignored %s: %s", file_type, line); return NULL; } +#endif /* !WINDOWS */ return f; }