X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconf.c;h=a33bdfea3b0b0624ef5681e79924582e20568b2b;hb=017a7fb57655d9b1d706ee78f7e3d0000411b883;hp=e789f72c1ab447874ae4d74aea4ac9ad36373c9c;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/conf.c b/src/conf.c index e789f72c..a33bdfea 100644 --- a/src/conf.c +++ b/src/conf.c @@ -80,18 +80,9 @@ config_t *new_config(void) { } void free_config(config_t *cfg) { - if(cfg->variable) { - free(cfg->variable); - } - - if(cfg->value) { - free(cfg->value); - } - - if(cfg->file) { - free(cfg->file); - } - + free(cfg->variable); + free(cfg->value); + free(cfg->file); free(cfg); } @@ -203,7 +194,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) { } bool get_config_subnet(const config_t *cfg, subnet_t **result) { - subnet_t subnet = {NULL}; + subnet_t subnet = {0}; if(!cfg) { return false; @@ -313,7 +304,7 @@ config_t *parse_config_line(char *line, const char *fname, int lineno) { Parse a configuration file and put the results in the configuration tree starting at *base. */ -bool read_config_file(splay_tree_t *config_tree, const char *fname) { +bool read_config_file(splay_tree_t *config_tree, const char *fname, bool verbose) { FILE *fp; char buffer[MAX_STRING_SIZE]; char *line; @@ -325,7 +316,7 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname) { fp = fopen(fname, "r"); if(!fp) { - logger(DEBUG_ALWAYS, LOG_DEBUG, "Cannot open config file %s: %s", fname, strerror(errno)); + logger(verbose ? DEBUG_ALWAYS : DEBUG_CONNECTIONS, LOG_ERR, "Cannot open config file %s: %s", fname, strerror(errno)); return false; } @@ -415,7 +406,7 @@ bool read_server_config(void) { snprintf(fname, sizeof(fname), "%s" SLASH "tinc.conf", confbase); errno = 0; - x = read_config_file(config_tree, fname); + x = read_config_file(config_tree, fname, true); // We will try to read the conf files in the "conf.d" dir if(x) { @@ -433,8 +424,12 @@ bool read_server_config(void) { // And we try to read the ones that end with ".conf" if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { - snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name); - x = read_config_file(config_tree, fname); + if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) { + logger(DEBUG_ALWAYS, LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name); + return false; + } + + x = read_config_file(config_tree, fname, true); } } @@ -449,16 +444,12 @@ bool read_server_config(void) { return x; } -bool read_host_config(splay_tree_t *config_tree, const char *name) { - char fname[PATH_MAX]; - bool x; - +bool read_host_config(splay_tree_t *config_tree, const char *name, bool verbose) { read_config_options(config_tree, name); + char fname[PATH_MAX]; snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); - x = read_config_file(config_tree, fname); - - return x; + return read_config_file(config_tree, fname, verbose); } bool append_config_file(const char *name, const char *key, const char *value) {