--- gvpe/src/conf.C 2004/01/29 18:55:10 1.22 +++ gvpe/src/conf.C 2005/03/17 23:59:37 1.34 @@ -1,8 +1,10 @@ /* conf.c -- configuration code - Copyright (C) 2003-2004 Marc Lehmann + Copyright (C) 2003-2005 Marc Lehmann - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -13,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with gvpe; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -46,7 +48,6 @@ char *confbase; char *thisnode; char *identname; -char *pidfilename; struct configuration conf; @@ -56,6 +57,7 @@ if (protset & PROT_ICMPv4) return PROT_ICMPv4; if (protset & PROT_UDPv4 ) return PROT_UDPv4; if (protset & PROT_TCPv4 ) return PROT_TCPv4; + if (protset & PROT_DNSv4 ) return PROT_DNSv4; return 0; } @@ -66,6 +68,7 @@ if (protocol & PROT_ICMPv4) return "icmp"; if (protocol & PROT_UDPv4 ) return "udp"; if (protocol & PROT_TCPv4 ) return "tcp"; + if (protocol & PROT_DNSv4 ) return "dns"; return ""; } @@ -94,6 +97,10 @@ free (nodename); free (hostname); +#if ENABLE_DNS + free (domain); + free (dns_hostname); +#endif } void configuration::init () @@ -110,10 +117,19 @@ #endif default_node.udp_port = DEFAULT_UDPPORT; - default_node.tcp_port = DEFAULT_UDPPORT; + default_node.tcp_port = DEFAULT_UDPPORT; // ehrm default_node.connectmode = conf_node::C_ALWAYS; default_node.compress = true; - default_node.protocols = PROT_UDPv4; + default_node.protocols = 0; + default_node.max_retry = DEFAULT_MAX_RETRY; + +#if ENABLE_DNS + default_node.dns_port = 0; // default is 0 == client + dns_forw_host = strdup ("127.0.0.1"); + dns_forw_port = 53; +#endif + + conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); } void configuration::cleanup() @@ -123,10 +139,14 @@ rsa_key = 0; - free (ifname); ifname = 0; + free (pidfilename); pidfilename = 0; + free (ifname); ifname = 0; #if ENABLE_HTTP_PROXY - free (proxy_host); proxy_host = 0; - free (proxy_auth); proxy_auth = 0; + free (proxy_host); proxy_host = 0; + free (proxy_auth); proxy_auth = 0; +#endif +#if ENABLE_DNS + free (dns_forw_host); dns_forw_host = 0; #endif } @@ -161,7 +181,7 @@ clear_config (); - asprintf (&fname, "%s/vped.conf", confbase); + asprintf (&fname, "%s/gvpe.conf", confbase); f = fopen (fname, "r"); if (f) @@ -279,17 +299,17 @@ free (fname); } - if (!::thisnode || !strcmp (node->nodename, ::thisnode)) + if (::thisnode && !strcmp (node->nodename, ::thisnode)) thisnode = node; } else if (!strcmp (var, "private-key")) - prikeyfile = strdup (val); + free (prikeyfile), prikeyfile = strdup (val); else if (!strcmp (var, "ifpersist")) { parse_bool (ifpersist, "ifpersist", true, false); } else if (!strcmp (var, "ifname")) - ifname = strdup (val); + free (ifname), ifname = strdup (val); else if (!strcmp (var, "rekey")) rekey = atoi (val); else if (!strcmp (var, "keepalive")) @@ -297,15 +317,29 @@ else if (!strcmp (var, "mtu")) mtu = atoi (val); else if (!strcmp (var, "if-up")) - script_if_up = strdup (val); + free (script_if_up), script_if_up = strdup (val); else if (!strcmp (var, "node-up")) - script_node_up = strdup (val); + free (script_node_up), script_node_up = strdup (val); else if (!strcmp (var, "node-down")) - script_node_down = strdup (val); + free (script_node_down), script_node_down = strdup (val); + else if (!strcmp (var, "pid-file")) + free (pidfilename), pidfilename = strdup (val); + else if (!strcmp (var, "dns-forw-host")) + { +#if ENABLE_DNS + free (dns_forw_host), dns_forw_host = strdup (val); +#endif + } + else if (!strcmp (var, "dns-forw-port")) + { +#if ENABLE_DNS + dns_forw_port = atoi (val); +#endif + } else if (!strcmp (var, "http-proxy-host")) { #if ENABLE_HTTP_PROXY - proxy_host = strdup (val); + free (proxy_host), proxy_host = strdup (val); #endif } else if (!strcmp (var, "http-proxy-port")) @@ -323,18 +357,35 @@ /* node-specific, non-defaultable */ else if (node != &default_node && !strcmp (var, "hostname")) - { - free (node->hostname); - node->hostname = strdup (val); - } + free (node->hostname), node->hostname = strdup (val); /* node-specific, defaultable */ else if (!strcmp (var, "udp-port")) node->udp_port = atoi (val); else if (!strcmp (var, "tcp-port")) node->tcp_port = atoi (val); + else if (!strcmp (var, "dns-hostname")) + { +#if ENABLE_DNS + free (node->dns_hostname), node->dns_hostname = strdup (val); +#endif + } + else if (!strcmp (var, "dns-port")) + { +#if ENABLE_DNS + node->dns_port = atoi (val); +#endif + } + else if (!strcmp (var, "dns-domain")) + { +#if ENABLE_DNS + free (node->domain), node->domain = strdup (val); +#endif + } else if (!strcmp (var, "router-priority")) node->routerprio = atoi (val); + else if (!strcmp (var, "max-retry")) + node->max_retry = atoi (val); else if (!strcmp (var, "connect")) { if (!strcmp (val, "ondemand")) @@ -347,8 +398,8 @@ node->connectmode = conf_node::C_DISABLED; else slog (L_WARN, - _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), - var, fname, lineno); + _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), + var, fname, lineno); } else if (!strcmp (var, "inherit-tos")) { @@ -371,6 +422,12 @@ u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; #endif } + else if (!strcmp (var, "enable-dns")) + { +#if ENABLE_DNS + u8 v; parse_bool (v, "enable-dns" , PROT_DNSv4, 0); node->protocols = (node->protocols & ~PROT_DNSv4) | v; +#endif + } else if (!strcmp (var, "enable-udp")) { u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; @@ -423,7 +480,8 @@ exit (EXIT_FAILURE); } - if (need_keys && rsa_key && thisnode && thisnode->rsa_key) + if (need_keys && ::thisnode + && rsa_key && thisnode && thisnode->rsa_key) if (BN_cmp (rsa_key->n, thisnode->rsa_key->n) != 0 || BN_cmp (rsa_key->e, thisnode->rsa_key->e) != 0) { @@ -475,6 +533,8 @@ configuration::configuration () { + asprintf (&confbase, "%s/gvpe", CONFDIR); + init (); }