X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconf.c;h=0727953127e141ac633fc1e8e79bbaa911ab4b95;hp=dc5d2dc21f705b4d4e1e745523e495db9b75fb0e;hb=930bf74fbe5ce8363b6cc2ae3a3e960e910e0996;hpb=8c3105283ac53f8cc9cc4dde25957ec1cf6b53a0 diff --git a/src/conf.c b/src/conf.c index dc5d2dc2..07279531 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2,7 +2,8 @@ conf.c -- configuration code Copyright (C) 1998 Robert van der Meulen 1998-2005 Ivo Timmermans - 2000-2009 Guus Sliepen + 2000-2010 Guus Sliepen + 2010 Julien Muchembled 2000 Cris van Pelt This program is free software; you can redistribute it and/or modify @@ -23,6 +24,7 @@ #include "system.h" #include "avl_tree.h" +#include "connection.h" #include "conf.h" #include "logger.h" #include "netutl.h" /* for str2address */ @@ -335,20 +337,31 @@ bool read_config_file(avl_tree_t *config_tree, const char *fname) { return result; } -bool read_server_config() { +void read_config_options(avl_tree_t *config_tree, const char *prefix) { list_node_t *node, *next; - char *fname; - bool x; + size_t prefix_len = prefix ? strlen(prefix) : 0; for(node = cmdline_conf->tail; node; node = next) { config_t *cfg = (config_t *)node->data; next = node->prev; - if (!strchr(cfg->variable, '.')) { - config_add(config_tree, cfg); - node->data = NULL; - list_unlink_node(cmdline_conf, node); - } + + if(!prefix && strchr(cfg->variable, '.')) + continue; + + if(prefix && (strncmp(prefix, cfg->variable, prefix_len) || cfg->variable[prefix_len] != '.')) + continue; + + config_add(config_tree, cfg); + node->data = NULL; + list_unlink_node(cmdline_conf, node); } +} + +bool read_server_config() { + char *fname; + bool x; + + read_config_options(config_tree, NULL); xasprintf(&fname, "%s/tinc.conf", confbase); x = read_config_file(config_tree, fname); @@ -362,6 +375,19 @@ bool read_server_config() { return x; } +bool read_connection_config(connection_t *c) { + char *fname; + bool x; + + read_config_options(c->config_tree, c->name); + + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); + x = read_config_file(c->config_tree, fname); + free(fname); + + return x; +} + FILE *ask_and_open(const char *filename, const char *what) { FILE *r; char *directory; @@ -430,24 +456,33 @@ bool disable_old_keys(FILE *f) { rewind(f); pos = ftell(f); + if(pos < 0) + return false; + while(fgets(buf, sizeof buf, f)) { if(!strncmp(buf, "-----BEGIN RSA", 14)) { buf[11] = 'O'; buf[12] = 'L'; buf[13] = 'D'; - fseek(f, pos, SEEK_SET); - fputs(buf, f); + if(fseek(f, pos, SEEK_SET)) + break; + if(fputs(buf, f) <= 0) + break; disabled = true; } else if(!strncmp(buf, "-----END RSA", 12)) { buf[ 9] = 'O'; buf[10] = 'L'; buf[11] = 'D'; - fseek(f, pos, SEEK_SET); - fputs(buf, f); + if(fseek(f, pos, SEEK_SET)) + break; + if(fputs(buf, f) <= 0) + break; disabled = true; } pos = ftell(f); + if(pos < 0) + break; } return disabled;