X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconf.c;h=0bbee092411df4366f543dc800913dcbaed63d43;hb=30ef2a981e1d62692b3a2363e0b3a0e8711d9604;hp=faff003b260807b258701aa656119eb25d882a3b;hpb=886a6f61a1f4cc48a77b42d10f34f9126377d904;p=tinc diff --git a/src/conf.c b/src/conf.c index faff003b..0bbee092 100644 --- a/src/conf.c +++ b/src/conf.c @@ -3,7 +3,7 @@ Copyright (C) 1998 Robert van der Meulen 1998-2005 Ivo Timmermans 2000-2010 Guus Sliepen - 2010 Julien Muchembled + 2010-2011 Julien Muchembled 2000 Cris van Pelt This program is free software; you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include "splay_tree.h" #include "connection.h" #include "conf.h" +#include "list.h" #include "logger.h" #include "netutl.h" /* for str2address */ #include "protocol.h" @@ -188,7 +189,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 = {0}; + subnet_t subnet = {NULL}; if(!cfg) return false; @@ -342,22 +343,33 @@ void read_config_options(splay_tree_t *config_tree, const char *prefix) { size_t prefix_len = prefix ? strlen(prefix) : 0; for(node = cmdline_conf->tail; node; node = next) { - config_t *cfg = (config_t *)node->data; + config_t *orig_cfg, *cfg = (config_t *)node->data; next = node->prev; - if(!prefix && strchr(cfg->variable, '.')) - continue; - - if(prefix && (strncmp(prefix, cfg->variable, prefix_len) || cfg->variable[prefix_len] != '.')) - continue; - + if(!prefix) { + if(strchr(cfg->variable, '.')) + continue; + node->data = NULL; + list_unlink_node(cmdline_conf, node); + } else { + if(strncmp(prefix, cfg->variable, prefix_len) || + cfg->variable[prefix_len] != '.') + continue; + /* Because host configuration is parsed again when + reconnecting, nodes must not be freed when a prefix + is given. */ + orig_cfg = cfg; + cfg = new_config(); + cfg->variable = xstrdup(orig_cfg->variable + prefix_len + 1); + cfg->value = xstrdup(orig_cfg->value); + cfg->file = NULL; + cfg->line = orig_cfg->line; + } config_add(config_tree, cfg); - node->data = NULL; - list_unlink_node(cmdline_conf, node); } } -bool read_server_config() { +bool read_server_config(void) { char *fname; bool x; @@ -388,6 +400,24 @@ bool read_connection_config(connection_t *c) { return x; } +bool append_connection_config(const connection_t *c, const char *key, const char *value) { + char *fname; + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); + + FILE *fp = fopen(fname, "a"); + + if(!fp) { + logger(LOG_ERR, "Cannot open config file %s: %s", fname, strerror(errno)); + } else { + fprintf(fp, "\n# The following line was automatically added by tinc\n%s = %s\n", key, value); + fclose(fp); + } + + free(fname); + + return fp; +} + bool disable_old_keys(FILE *f) { char buf[100]; long pos;