Remove duplicate command-line option parsing.
Also fix parsing of command-line host configuration options for the local node.
This commit is contained in:
parent
ff71f28902
commit
667b1bac77
5 changed files with 40 additions and 36 deletions
46
src/conf.c
46
src/conf.c
|
@ -23,6 +23,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
#include "avl_tree.h"
|
#include "avl_tree.h"
|
||||||
|
#include "connection.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "netutl.h" /* for str2address */
|
#include "netutl.h" /* for str2address */
|
||||||
|
@ -335,20 +336,32 @@ bool read_config_file(avl_tree_t *config_tree, const char *fname) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read_config_options(avl_tree_t *config_tree, const char *prefix) {
|
||||||
|
list_node_t *node, *next;
|
||||||
|
size_t prefix_len = strlen(prefix);
|
||||||
|
|
||||||
|
for(node = cmdline_conf->tail; node; node = next) {
|
||||||
|
config_t *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;
|
||||||
|
|
||||||
|
config_add(config_tree, cfg);
|
||||||
|
node->data = NULL;
|
||||||
|
list_unlink_node(cmdline_conf, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool read_server_config() {
|
bool read_server_config() {
|
||||||
list_node_t *node, *next;
|
list_node_t *node, *next;
|
||||||
char *fname;
|
char *fname;
|
||||||
bool x;
|
bool x;
|
||||||
|
|
||||||
for(node = cmdline_conf->tail; node; node = next) {
|
read_config_options(config_tree, NULL);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xasprintf(&fname, "%s/tinc.conf", confbase);
|
xasprintf(&fname, "%s/tinc.conf", confbase);
|
||||||
x = read_config_file(config_tree, fname);
|
x = read_config_file(config_tree, fname);
|
||||||
|
@ -362,6 +375,21 @@ bool read_server_config() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool read_connection_config(connection_t *c) {
|
||||||
|
list_node_t *node, *next;
|
||||||
|
size_t name_len = strlen(c->name);
|
||||||
|
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 *ask_and_open(const char *filename, const char *what) {
|
||||||
FILE *r;
|
FILE *r;
|
||||||
char *directory;
|
char *directory;
|
||||||
|
|
|
@ -58,7 +58,9 @@ extern bool get_config_subnet(const config_t *, struct subnet_t **);
|
||||||
|
|
||||||
extern config_t *parse_config_line(char *, const char *, int);
|
extern config_t *parse_config_line(char *, const char *, int);
|
||||||
extern bool read_config_file(avl_tree_t *, const char *);
|
extern bool read_config_file(avl_tree_t *, const char *);
|
||||||
|
extern void read_config_options(avl_tree_t *, const char *);
|
||||||
extern bool read_server_config(void);
|
extern bool read_server_config(void);
|
||||||
|
extern bool read_connection_config(struct connection_t *);
|
||||||
extern FILE *ask_and_open(const char *, const char *);
|
extern FILE *ask_and_open(const char *, const char *);
|
||||||
extern bool is_safe_path(const char *);
|
extern bool is_safe_path(const char *);
|
||||||
extern bool disable_old_keys(FILE *);
|
extern bool disable_old_keys(FILE *);
|
||||||
|
|
|
@ -127,29 +127,3 @@ void dump_connections(void) {
|
||||||
|
|
||||||
logger(LOG_DEBUG, "End of connections.");
|
logger(LOG_DEBUG, "End of connections.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_connection_config(connection_t *c) {
|
|
||||||
list_node_t *node, *next;
|
|
||||||
size_t name_len = strlen(c->name);
|
|
||||||
char *fname;
|
|
||||||
bool x;
|
|
||||||
|
|
||||||
for(node = cmdline_conf->tail; node; node = next) {
|
|
||||||
config_t *cfg = (config_t *)node->data;
|
|
||||||
next = node->prev;
|
|
||||||
if (!strncmp(c->name, cfg->variable, name_len) && cfg->variable[name_len] == '.') {
|
|
||||||
config_t *new_cfg = new_config();
|
|
||||||
new_cfg->variable = xstrdup(cfg->variable + name_len + 1);
|
|
||||||
new_cfg->value = xstrdup(cfg->value);
|
|
||||||
new_cfg->file = NULL;
|
|
||||||
new_cfg->line = cfg->line;
|
|
||||||
config_add(c->config_tree, new_cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
|
||||||
x = read_config_file(c->config_tree, fname);
|
|
||||||
free(fname);
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
|
@ -111,6 +111,5 @@ extern void free_connection(connection_t *);
|
||||||
extern void connection_add(connection_t *);
|
extern void connection_add(connection_t *);
|
||||||
extern void connection_del(connection_t *);
|
extern void connection_del(connection_t *);
|
||||||
extern void dump_connections(void);
|
extern void dump_connections(void);
|
||||||
extern bool read_connection_config(connection_t *);
|
|
||||||
|
|
||||||
#endif /* __TINC_CONNECTION_H__ */
|
#endif /* __TINC_CONNECTION_H__ */
|
||||||
|
|
|
@ -300,6 +300,7 @@ bool setup_myself(void) {
|
||||||
myself->name = name;
|
myself->name = name;
|
||||||
myself->connection->name = xstrdup(name);
|
myself->connection->name = xstrdup(name);
|
||||||
xasprintf(&fname, "%s/hosts/%s", confbase, name);
|
xasprintf(&fname, "%s/hosts/%s", confbase, name);
|
||||||
|
read_config_options(config_tree, name);
|
||||||
read_config_file(config_tree, fname);
|
read_config_file(config_tree, fname);
|
||||||
free(fname);
|
free(fname);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue