]> granicus.if.org Git - sudo/commitdiff
Fall back on lstat(2) if d_type in struct dirent is DT_UNKNOWN.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 17 Sep 2012 17:42:48 +0000 (13:42 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 17 Sep 2012 17:42:48 +0000 (13:42 -0400)
Not all file systems support d_type.  Bug #572

--HG--
branch : 1.7

sudoreplay.c

index 3eb1a54221224965318b0cd554d3218c19911ece..1e16a82221df1c4adb1c4b1a4e60df79e4d0c22e 100644 (file)
@@ -958,6 +958,11 @@ find_sessions(dir, re, user, tty)
     struct stat sb;
     size_t sdlen, sessions_len = 0, sessions_size = 36*36;
     int i, len;
+#ifdef HAVE_STRUCT_DIRENT_D_TYPE
+    int checked_type = TRUE;
+#else
+    const int checked_type = FALSE;
+#endif
     char pathbuf[PATH_MAX], **sessions = NULL;
 
     d = opendir(dir);
@@ -981,8 +986,14 @@ find_sessions(dir, re, user, tty)
            (dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
            continue;
 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
-       if (dp->d_type != DT_DIR)
-           continue;
+       if (checked_type) {
+           if (dp->d_type != DT_DIR) {
+               /* Not all file systems support d_type. */
+               if (dp->d_type != DT_UNKNOWN)
+                   continue;
+               checked_type = FALSE;
+           }
+       }
 #endif
 
        /* Add name to session list. */
@@ -1011,9 +1022,7 @@ find_sessions(dir, re, user, tty)
        } else {
            /* Strip off "/log" and recurse if a dir. */
            pathbuf[sdlen + len - 4] = '\0';
-#ifndef HAVE_STRUCT_DIRENT_D_TYPE
-           if (lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode))
-#endif
+           if (checked_type || (lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode)))
                find_sessions(pathbuf, re, user, tty);
        }
     }