X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fconf.c;h=16247570c25cc617ffe2e78f8808ca0f76e771a0;hb=1564f52f7643c554ec49a3e014bc9b9a8745c856;hp=c4f8abb8303f649eff8f9f96eeb751f3f015d357;hpb=cc3c69c892b0dad9a6ece0a0f4ccd429a22fcbff;p=meshlink diff --git a/src/conf.c b/src/conf.c index c4f8abb8..16247570 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,10 +1,11 @@ /* conf.c -- configuration code - Copyright (C) 1998 Robert van der Meulen + Copyright (C) 1998 Robert van der Meulen 1998-2005 Ivo Timmermans - 2000-2013 Guus Sliepen + 2000 Cris van Pelt 2010-2011 Julien Muchembled - 2000 Cris van Pelt + 2000-2013 Guus Sliepen + 2013 Florent Clairambault This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +29,6 @@ #include "conf.h" #include "list.h" #include "logger.h" -#include "names.h" #include "netutl.h" /* for str2address */ #include "protocol.h" #include "utils.h" /* for cp */ @@ -71,7 +71,7 @@ void exit_configuration(splay_tree_t ** config_tree) { } config_t *new_config(void) { - return xmalloc_and_zero(sizeof(config_t)); + return xzalloc(sizeof(config_t)); } void free_config(config_t *cfg) { @@ -186,34 +186,6 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) { return false; } -bool get_config_subnet(const config_t *cfg, subnet_t ** result) { - subnet_t subnet = {NULL}; - - if(!cfg) - return false; - - if(!str2net(&subnet, cfg->value)) { - logger(DEBUG_ALWAYS, LOG_ERR, "Subnet expected for configuration variable %s in %s line %d", - cfg->variable, cfg->file, cfg->line); - return false; - } - - /* Teach newbies what subnets are... */ - - if(((subnet.type == SUBNET_IPV4) - && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof subnet.net.ipv4.address)) - || ((subnet.type == SUBNET_IPV6) - && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address))) { - logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d", - cfg->variable, cfg->file, cfg->line); - return false; - } - - *(*result = new_subnet()) = subnet; - - return true; -} - /* Read exactly one line and strip the trailing newline if any. */ @@ -370,12 +342,36 @@ bool read_server_config(void) { char *fname; bool x; - read_config_options(config_tree, NULL); + //read_config_options(config_tree, NULL); xasprintf(&fname, "%s" SLASH "tinc.conf", confbase); + errno = 0; x = read_config_file(config_tree, fname); - if(!x) + // We will try to read the conf files in the "conf.d" dir + if (x) { + char * dname; + xasprintf(&dname, "%s" SLASH "conf.d", confbase); + DIR *dir = opendir (dname); + // If we can find this dir + if (dir) { + struct dirent *ep; + // We list all the files in it + while (x && (ep = readdir (dir))) { + size_t l = strlen(ep->d_name); + // And we try to read the ones that end with ".conf" + if (l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { + free(fname); + xasprintf(&fname, "%s" SLASH "%s", dname, ep->d_name); + x = read_config_file(config_tree, fname); + } + } + closedir (dir); + } + free(dname); + } + + if(!x && errno) logger(DEBUG_ALWAYS, LOG_ERR, "Failed to read `%s': %s", fname, strerror(errno)); free(fname); @@ -387,7 +383,7 @@ bool read_host_config(splay_tree_t *config_tree, const char *name) { char *fname; bool x; - read_config_options(config_tree, name); + //read_config_options(config_tree, name); xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name); x = read_config_file(config_tree, fname);