Fall back on lstat(2) if d_type in struct dirent is DT_UNKNOWN.
Not all file systems support d_type. Bug #572
This commit is contained in:
@@ -968,6 +968,11 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
|
|||||||
size_t sdlen, sessions_len = 0, sessions_size = 36*36;
|
size_t sdlen, sessions_len = 0, sessions_size = 36*36;
|
||||||
int i, len;
|
int i, len;
|
||||||
char pathbuf[PATH_MAX], **sessions = NULL;
|
char pathbuf[PATH_MAX], **sessions = NULL;
|
||||||
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
|
bool checked_type = true;
|
||||||
|
#else
|
||||||
|
const bool checked_type = false;
|
||||||
|
#endif
|
||||||
debug_decl(find_sessions, SUDO_DEBUG_UTIL)
|
debug_decl(find_sessions, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
d = opendir(dir);
|
d = opendir(dir);
|
||||||
@@ -991,8 +996,14 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
|
|||||||
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
|
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
|
||||||
continue;
|
continue;
|
||||||
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||||
if (dp->d_type != DT_DIR)
|
if (checked_type) {
|
||||||
continue;
|
if (dp->d_type != DT_DIR) {
|
||||||
|
/* Not all file systems support d_type. */
|
||||||
|
if (dp->d_type != DT_UNKNOWN)
|
||||||
|
continue;
|
||||||
|
checked_type = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Add name to session list. */
|
/* Add name to session list. */
|
||||||
@@ -1021,9 +1032,7 @@ find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
|
|||||||
} else {
|
} else {
|
||||||
/* Strip off "/log" and recurse if a dir. */
|
/* Strip off "/log" and recurse if a dir. */
|
||||||
pathbuf[sdlen + len - 4] = '\0';
|
pathbuf[sdlen + len - 4] = '\0';
|
||||||
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
if (checked_type || (lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode)))
|
||||||
if (lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode))
|
|
||||||
#endif
|
|
||||||
find_sessions(pathbuf, re, user, tty);
|
find_sessions(pathbuf, re, user, tty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user