diff options
Diffstat (limited to 'shared/config-parser.c')
-rw-r--r-- | shared/config-parser.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c index 9f294f4..1f44db4 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -6,9 +6,12 @@ #include <unistd.h> #include <arpa/inet.h> #include <inttypes.h> +#include <sys/types.h> +#include <dirent.h> #include "utils.h" #include "config-parser.h" +#include "config.h" static void eat_whitespace_and_comments(char **pos) @@ -162,7 +165,7 @@ out: return rv; } -static bool +bool strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async) { struct saddr *saddr; @@ -478,3 +481,36 @@ config_parse_header(const char *title, char **buf) return false; } + +bool +is_valid_server_config_filename(struct dirent *dent, const char *filename) +{ + const char *suffix; + + assert_return(!(dent && filename) && !(!dent && !filename), false); + + /* Maybe accept DT_LNK? */ + if (dent) { + switch (dent->d_type) { + case DT_UNKNOWN: + _fallthrough_; + case DT_REG: + break; + default: + return false; + } + filename = dent->d_name; + } + + if (empty_str(filename)) + return false; + if (filename[0] == '.') + return false; + if ((suffix = strrchr(filename, '.')) == NULL) + return false; + if (!streq(suffix, "." SERVER_CONFIG_FILE_SUFFIX)) + return false; + + return true; +} + |