@@ -183,6 +183,21 @@ parseconfig(const char *filename, int checkperms)
183
183
}
184
184
185
185
#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
+
186
201
static int
187
202
filterconfdir (const struct dirent * dirent )
188
203
{
@@ -194,10 +209,9 @@ parseconfdir(const char *dirpath, int checkperms)
194
209
{
195
210
struct dirent * * dirent_table ;
196
211
size_t i , dirent_count ;
197
-
198
212
char pathbuf [PATH_MAX ];
199
213
200
- if (access (dirpath , F_OK ))
214
+ if (! isconfdir (dirpath ))
201
215
err (1 , checkperms ? "doas is not enabled, %s" :
202
216
"could not open config directory %s" , dirpath );
203
217
@@ -225,7 +239,9 @@ checkconfig(const char *confpath, int argc, char **argv,
225
239
err (1 , "setresuid" );
226
240
227
241
#ifdef DOAS_CONFDIR
228
- parseconfdir (confpath , 0 );
242
+ if (isconfdir (confpath ))
243
+ parseconfdir (confpath , 0 );
244
+ else
229
245
#else
230
246
parseconfig (confpath , 0 );
231
247
#endif
@@ -371,7 +387,9 @@ main(int argc, char **argv)
371
387
errx (1 , "not installed setuid" );
372
388
373
389
#ifdef DOAS_CONFDIR
374
- parseconfdir (DOAS_CONFDIR , 1 );
390
+ if (isconfdir (DOAS_CONFDIR ))
391
+ parseconfdir (DOAS_CONFDIR , 1 );
392
+ else
375
393
#else
376
394
parseconfig (DOAS_CONF , 1 );
377
395
#endif
0 commit comments