Skip to content

Commit f524d91

Browse files
committed
drop filterconfdir, use lstat instead to filter out non-files
1 parent d4527fe commit f524d91

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

doas.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ isconfdir(const char *dirpath)
198198
return 0;
199199
}
200200

201-
static int
202-
filterconfdir(const struct dirent *dirent)
203-
{
204-
return dirent->d_type == DT_REG;
205-
}
206-
207201
static void
208202
parseconfdir(const char *dirpath, int checkperms)
209203
{
@@ -215,13 +209,21 @@ parseconfdir(const char *dirpath, int checkperms)
215209
err(1, checkperms ? "doas is not enabled, %s" :
216210
"could not open config directory %s", dirpath);
217211

218-
dirent_count = scandir(dirpath, &dirent_table, filterconfdir, alphasort);
212+
dirent_count = scandir(dirpath, &dirent_table, NULL, alphasort);
219213

220214
for (i = 0; i < dirent_count; i++)
221215
{
216+
struct stat sb;
217+
222218
snprintf(pathbuf, sizeof pathbuf, "%s/%s", dirpath, dirent_table[i]->d_name);
223219
free(dirent_table[i]);
224220

221+
if (lstat(pathbuf, &sb) != 0)
222+
err(1, "lstat(\"%s\")", pathbuf);
223+
224+
if ((sb.st_mode & (S_IFMT)) != S_IFREG)
225+
continue;
226+
225227
parseconfig(pathbuf, checkperms);
226228
}
227229

0 commit comments

Comments
 (0)