--- gvpe/src/conf.C 2011/02/08 23:11:35 1.52 +++ gvpe/src/conf.C 2011/03/06 21:01:36 1.56 @@ -1,6 +1,6 @@ /* - conf.c -- configuration code - Copyright (C) 2003-2008 Marc Lehmann + conf.C -- configuration code + Copyright (C) 2003-2008,2011 Marc Lehmann This file is part of GVPE. @@ -107,25 +107,6 @@ return true; } -void -conf_node::print () -{ - printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %s%s%d\n", - id, - id >> 8, id & 0xff, - compress ? 'Y' : 'N', - connectmode == C_ONDEMAND ? "ondemand" - : connectmode == C_NEVER ? "never" - : connectmode == C_ALWAYS ? "always" - : connectmode == C_DISABLED ? "disabled" - : "", - nodename, - hostname ? hostname : "", - hostname ? ":" : "", - hostname ? udp_port : 0 - ); -} - conf_node::~conf_node () { #if 0 @@ -172,6 +153,7 @@ #if ENABLE_DNS default_node.dns_port = 0; // default is 0 == client + dns_case_preserving = true; dns_forw_host = strdup ("127.0.0.1"); dns_forw_port = 53; dns_timeout_factor = DEFAULT_DNS_TIMEOUT_FACTOR; @@ -193,11 +175,11 @@ free (pidfilename); pidfilename = 0; free (ifname); ifname = 0; -#if ENABLE_HTTP_PROXY +#if ENABLE_HTTP_PROXY free (proxy_host); proxy_host = 0; free (proxy_auth); proxy_auth = 0; -#endif -#if ENABLE_DNS +#endif +#if ENABLE_DNS free (dns_forw_host); dns_forw_host = 0; #endif free (script_if_up); script_if_up = 0; @@ -218,6 +200,12 @@ init (); } +//static bool +//is_true (const char *name) +//{ + //re +//} + #define parse_bool(target,name,trueval,falseval) do { \ if (!strcmp (val, "yes")) target = trueval; \ else if (!strcmp (val, "no")) target = falseval; \ @@ -226,7 +214,7 @@ else if (!strcmp (val, "on")) target = trueval; \ else if (!strcmp (val, "off")) target = falseval; \ else \ - return _("illegal boolean value, only 'yes|true|on' or 'no|false|off' allowed. (ignored)"); \ + return _("illegal boolean value, only 'yes|true|on' or 'no|false|off' allowed, ignored"); \ } while (0) const char * @@ -254,25 +242,30 @@ char *val = strtok (NULL, "\t\n\r ="); if (!val || val[0] == '#') - return _("no value given for variable. (ignored)"); + return _("no value given for variable, ignored"); - if (!strcmp (var, "on")) + else if (!strcmp (var, "on")) { - if (!::thisnode - || (val[0] == '!' && strcmp (val + 1, ::thisnode)) - || !strcmp (val, ::thisnode)) + if (::thisnode + && ((val[0] == '!' && strcmp (val + 1, ::thisnode)) + || !strcmp (val, ::thisnode))) return parse_line (strtok (NULL, "\n\r")); - else - return 0; + } + + else if (!strcmp (var, "include")) + { + char *fname = conf.config_filename (val); + parse_file (fname); + free (fname); } // truly global - if (!strcmp (var, "loglevel")) + else if (!strcmp (var, "loglevel")) { loglevel l = string_to_loglevel (val); if (l == L_NONE) - return _("unknown loglevel. (skipping)"); + return _("unknown loglevel, ignored"); } else if (!strcmp (var, "ip-proto")) conf.ip_proto = atoi (val); @@ -389,6 +382,12 @@ conf.dns_max_outstanding = atoi (val); #endif } + else if (!strcmp (var, "dns-case-preserving")) + { +#if ENABLE_DNS + parse_bool (conf.dns_case_preserving, "dns-case-preserving", true, false); +#endif + } else if (!strcmp (var, "http-proxy-host")) { #if ENABLE_HTTP_PROXY @@ -452,7 +451,7 @@ else if (!strcmp (val, "disabled")) node->connectmode = conf_node::C_DISABLED; else - return _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled'. (ignored)"); + return _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', ignored"); } else if (!strcmp (var, "inherit-tos")) parse_bool (node->inherit_tos, "inherit-tos", true, false); @@ -496,7 +495,7 @@ // unknown or misplaced else - return _("unknown configuration directive. (ignored)"); + return _("unknown configuration directive - ignored"); return 0; } @@ -552,25 +551,13 @@ } } -configuration_parser::configuration_parser (configuration &conf, - bool need_keys, - int argc, - char **argv) -: conf (conf),need_keys (need_keys), argc (argc), argv (argv) +void +configuration_parser::parse_file (const char *fname) { - char *fname; - FILE *f; - - conf.clear (); - - asprintf (&fname, "%s/gvpe.conf", confbase); - f = fopen (fname, "r"); - - if (f) + if (FILE *f = fopen (fname, "r")) { - char line[16384]; + char line [2048]; int lineno = 0; - node = &conf.default_node; while (fgets (line, sizeof (line), f)) { @@ -591,13 +578,26 @@ slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); exit (EXIT_FAILURE); } +} +configuration_parser::configuration_parser (configuration &conf, + bool need_keys, + int argc, + char **argv) +: conf (conf),need_keys (need_keys), argc (argc), argv (argv) +{ + char *fname; + + conf.clear (); + node = &conf.default_node; + + asprintf (&fname, "%s/gvpe.conf", confbase); + parse_file (fname); free (fname); fname = conf.config_filename (conf.prikeyfile, "hostkey"); - f = fopen (fname, "r"); - if (f) + if (FILE *f = fopen (fname, "r")) { conf.rsa_key = RSA_new (); @@ -620,6 +620,8 @@ exit (EXIT_FAILURE); } + free (fname); + if (need_keys && ::thisnode && conf.rsa_key && conf.thisnode && conf.thisnode->rsa_key) if (BN_cmp (conf.rsa_key->n, conf.thisnode->rsa_key->n) != 0 @@ -629,8 +631,6 @@ exit (EXIT_FAILURE); } - free (fname); - for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) (*i)->finalise (); } @@ -653,6 +653,26 @@ } void +conf_node::print () +{ + printf ("%4d fe:fd:80:00:0%1x:%02x %c %-8.8s %-10.10s %02x %s%s%d\n", + id, + id >> 8, id & 0xff, + compress ? 'Y' : 'N', + connectmode == C_ONDEMAND ? "ondemand" + : connectmode == C_NEVER ? "never" + : connectmode == C_ALWAYS ? "always" + : connectmode == C_DISABLED ? "disabled" + : "", + nodename, + protocols, + hostname ? hostname : "", + hostname ? ":" : "", + hostname ? udp_port : 0 + ); +} + +void configuration::print () { printf (_("\nConfiguration\n\n")); @@ -666,8 +686,8 @@ printf (_("rsa key size: %d\n"), rsa_key ? RSA_size (rsa_key) * 8 : -1); printf ("\n"); - printf ("%4s %-17s %s %-8.8s %-10.10s %s\n", - _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Host:Port")); + printf ("%4s %-17s %s %-8.8s %-10.10s %04s %s\n", + _("ID#"), _("MAC"), _("Com"), _("Conmode"), _("Node"), _("Prot"), _("Host:Port")); for (node_vector::iterator i = nodes.begin (); i != nodes.end (); ++i) (*i)->print ();