Skip to content

Commit d4527fe

Browse files
committed
fall back to /etc/doas.conf if /etc/doas.d is not present
1 parent 185e210 commit d4527fe

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

doas.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ parseconfig(const char *filename, int checkperms)
183183
}
184184

185185
#ifdef DOAS_CONFDIR
186+
static int
187+
isconfdir(const char *dirpath)
188+
{
189+
struct stat sb;
190+
191+
if (lstat(dirpath, &sb) != 0)
192+
err(1, "lstat(\"%s\")", dirpath);
193+
194+
if ((sb.st_mode & (S_IFMT)) == S_IFDIR)
195+
return 1;
196+
197+
errno = ENOTDIR;
198+
return 0;
199+
}
200+
186201
static int
187202
filterconfdir(const struct dirent *dirent)
188203
{
@@ -194,10 +209,9 @@ parseconfdir(const char *dirpath, int checkperms)
194209
{
195210
struct dirent **dirent_table;
196211
size_t i, dirent_count;
197-
198212
char pathbuf[PATH_MAX];
199213

200-
if (access(dirpath, F_OK))
214+
if (!isconfdir(dirpath))
201215
err(1, checkperms ? "doas is not enabled, %s" :
202216
"could not open config directory %s", dirpath);
203217

@@ -225,7 +239,9 @@ checkconfig(const char *confpath, int argc, char **argv,
225239
err(1, "setresuid");
226240

227241
#ifdef DOAS_CONFDIR
228-
parseconfdir(confpath, 0);
242+
if (isconfdir(confpath))
243+
parseconfdir(confpath, 0);
244+
else
229245
#else
230246
parseconfig(confpath, 0);
231247
#endif
@@ -371,7 +387,9 @@ main(int argc, char **argv)
371387
errx(1, "not installed setuid");
372388

373389
#ifdef DOAS_CONFDIR
374-
parseconfdir(DOAS_CONFDIR, 1);
390+
if (isconfdir(DOAS_CONFDIR))
391+
parseconfdir(DOAS_CONFDIR, 1);
392+
else
375393
#else
376394
parseconfig(DOAS_CONF, 1);
377395
#endif

0 commit comments

Comments
 (0)