X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconf.c;h=fc8237201cba67075f3aed67836fecd29818d079;hp=1ac01c31b4e5727609f7bc71f501115c4384da79;hb=f0aa9641e82fb6e09c1e485366d14dddaa7f7c36;hpb=ea607d2d9292d3969f9d164b432dc64a33c2dade diff --git a/src/conf.c b/src/conf.c index 1ac01c31..fc823720 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,8 +1,8 @@ /* conf.c -- configuration code Copyright (C) 1998 Robert van der Meulen - 1998-2001 Ivo Timmermans - 2000,2001 Guus Sliepen + 1998-2002 Ivo Timmermans + 2000-2002 Guus Sliepen 2000 Cris van Pelt This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.c,v 1.9.4.44 2001/10/10 20:34:27 guus Exp $ + $Id: conf.c,v 1.9.4.52 2002/02/10 21:57:53 guus Exp $ */ #include "config.h" @@ -42,20 +42,17 @@ #include #include "conf.h" -#include "netutl.h" /* for strtoip */ +#include "netutl.h" /* for str2address */ #include "system.h" avl_tree_t *config_tree; int debug_lvl = 0; -int timeout = 0; /* seconds before timeout */ +int pingtimeout = 0; /* seconds before timeout */ char *confbase = NULL; /* directory in which all config files are */ char *netname = NULL; /* name of the vpn network */ -/* Will be set if HUP signal is received. It will be processed when it is safe. */ -int sighup = 0; - int config_compare(config_t *a, config_t *b) { int result; @@ -126,11 +123,14 @@ cp cfg.line = 0; found = avl_search_closest_greater(config_tree, &cfg); + + if(!found) + return NULL; - if(!strcmp(found->variable, variable)) - return found; - else + if(strcmp(found->variable, variable)) return NULL; + + return found; } config_t *lookup_config_next(avl_tree_t *config_tree, config_t *cfg) @@ -164,14 +164,14 @@ cp *result = 1; return 1; } - else if(!strcasecmp(cfg->value, "np")) + else if(!strcasecmp(cfg->value, "no")) { *result = 0; return 1; } syslog(LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"), - cfg->value, cfg->file, cfg->line); + cfg->variable, cfg->file, cfg->line); return 0; } @@ -186,7 +186,7 @@ cp return 1; syslog(LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"), - cfg->value, cfg->file, cfg->line); + cfg->variable, cfg->file, cfg->line); return 0; } @@ -200,14 +200,15 @@ cp return 1; } -int get_config_ip(config_t *cfg, ip_mask_t **result) +int get_config_address(config_t *cfg, ipv4_t **result) { - ip_mask_t *ip; + ipv4_t *ip; cp if(!cfg) return 0; - ip = strtoip(cfg->value); + ip = xmalloc(sizeof(*ip)); + *ip = str2address(cfg->value); if(ip) { @@ -216,10 +217,56 @@ cp } syslog(LOG_ERR, _("IP address expected for configuration variable %s in %s line %d"), - cfg->value, cfg->file, cfg->line); + cfg->variable, cfg->file, cfg->line); + return 0; +} + +int get_config_port(config_t *cfg, port_t *result) +{ +cp + if(!cfg) + return 0; + + if(sscanf(cfg->value, "%hu", result) == 1) + return 1; + + syslog(LOG_ERR, _("Port number expected for configuration variable %s in %s line %d"), + cfg->variable, cfg->file, cfg->line); return 0; } +int get_config_subnet(config_t *cfg, subnet_t **result) +{ + subnet_t *subnet; +cp + if(!cfg) + return 0; + + subnet = str2net(cfg->value); + + if(!subnet) + { + syslog(LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"), + cfg->variable, cfg->file, cfg->line); + return 0; + } + + /* Teach newbies what subnets are... */ + + if(subnet->type == SUBNET_IPV4) + if((subnet->net.ipv4.address & subnet->net.ipv4.mask) != subnet->net.ipv4.address) + { + syslog(LOG_ERR, _("Network address and mask length do not match for configuration variable %s in %s line %d"), + cfg->variable, cfg->file, cfg->line); + free(subnet); + return 0; + } + + *result = subnet; + + return 1; +} + /* Read exactly one line and strip the trailing newline if any. If the file was on EOF, return NULL. Otherwise, return all the data in a