--- gvpe/src/conf.C 2011/02/15 13:31:23 1.54 +++ gvpe/src/conf.C 2013/07/16 16:44:36 1.61 @@ -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. @@ -40,6 +40,7 @@ #include #include #include +#include #include "netcompat.h" @@ -153,6 +154,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; @@ -161,7 +163,9 @@ dns_max_outstanding = DEFAULT_DNS_MAX_OUTSTANDING; #endif - conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); + pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); + seed_dev = strdup ("/dev/urandom"); + reseed = DEFAULT_RESEED; } void @@ -172,6 +176,7 @@ rsa_key = 0; + free (seed_dev); seed_dev = 0; free (pidfilename); pidfilename = 0; free (ifname); ifname = 0; #if ENABLE_HTTP_PROXY @@ -181,6 +186,7 @@ #if ENABLE_DNS free (dns_forw_host); dns_forw_host = 0; #endif + free (change_root); change_root = 0; free (script_if_up); script_if_up = 0; free (script_node_up); script_node_up = 0; free (script_node_change); script_node_change = 0; @@ -199,6 +205,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; \ @@ -207,7 +219,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 * @@ -235,25 +247,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); @@ -263,8 +280,23 @@ conf.icmp_type = atoi (val); #endif } + else if (!strcmp (var, "chuser")) + { + struct passwd *pw = getpwnam (val); + if (!pw) + return _("user specified for chuser not found"); + + conf.change_uid = pw->pw_uid; + conf.change_gid = pw->pw_gid; + } + else if (!strcmp (var, "chuid")) + conf.change_uid = atoi (val); + else if (!strcmp (var, "chgid")) + conf.change_gid = atoi (val); + else if (!strcmp (var, "chroot")) + free (conf.change_root), conf.change_root = strdup (val); - // per config + // per node else if (!strcmp (var, "node")) { parse_argv (); @@ -324,6 +356,10 @@ conf.mtu = atoi (val); else if (!strcmp (var, "nfmark")) conf.nfmark = atoi (val); + else if (!strcmp (var, "seed-device")) + free (conf.seed_dev), conf.seed_dev = strdup (val); + else if (!strcmp (var, "seed-interval")) + conf.reseed = atoi (val); else if (!strcmp (var, "if-up")) free (conf.script_if_up), conf.script_if_up = strdup (val); else if (!strcmp (var, "node-up")) @@ -370,6 +406,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 @@ -433,7 +475,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); @@ -477,7 +519,7 @@ // unknown or misplaced else - return _("unknown configuration directive. (ignored)"); + return _("unknown configuration directive - ignored"); return 0; } @@ -533,25 +575,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)) { @@ -572,13 +602,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 (); @@ -595,12 +638,15 @@ } else { - slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); - if (need_keys) - exit (EXIT_FAILURE); + { + slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); + 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 @@ -610,7 +656,8 @@ exit (EXIT_FAILURE); } - free (fname); + fname = conf.config_filename (conf.pidfilename); + free (conf.pidfilename); conf.pidfilename = fname; for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) (*i)->finalise (); @@ -621,7 +668,7 @@ { char *fname; - asprintf (&fname, name ? name : dflt, ::thisnode); + asprintf (&fname, name ? name : dflt, ::thisnode ? ::thisnode : ""); if (!ABSOLUTE_PATH (fname)) {