--- gvpe/src/conf.C 2003/04/13 00:35:46 1.15 +++ gvpe/src/conf.C 2004/05/12 13:32:13 1.26 @@ -1,10 +1,6 @@ /* conf.c -- configuration code - Copyright (C) 1998 Robert van der Meulen - 1998-2002 Ivo Timmermans - 2000-2002 Guus Sliepen - 2000 Cris van Pelt - 2003 Marc Lehmann + Copyright (C) 2003-2004 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,13 +29,13 @@ #include #include -#include -#include +#include "netcompat.h" #include #include #include #include +#include #include "gettext.h" @@ -50,7 +46,6 @@ char *confbase; char *thisnode; char *identname; -char *pidfilename; struct configuration conf; @@ -60,6 +55,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; } @@ -70,6 +66,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 ""; } @@ -104,17 +101,22 @@ { memset (this, 0, sizeof (*this)); + mtu = DEFAULT_MTU; rekey = DEFAULT_REKEY; keepalive = DEFAULT_KEEPALIVE; llevel = L_INFO; ip_proto = IPPROTO_GRE; +#if ENABLE_ICMP icmp_type = ICMP_ECHOREPLY; +#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; + + conf.pidfilename = strdup (LOCALSTATEDIR "/run/vped.pid"); } void configuration::cleanup() @@ -124,10 +126,11 @@ 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 } @@ -230,7 +233,11 @@ else if (!strcmp (var, "ip-proto")) ip_proto = atoi (val); else if (!strcmp (var, "icmp-type")) - icmp_type = atoi (val); + { +#if ENABLE_ICMP + icmp_type = atoi (val); +#endif + } // per config else if (!strcmp (var, "node")) @@ -258,10 +265,10 @@ { ERR_load_RSA_strings (); ERR_load_PEM_strings (); slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); - exit (1); + exit (EXIT_FAILURE); } - RSA_blinding_on (node->rsa_key, 0); + require (RSA_blinding_on (node->rsa_key, 0)); fclose (f); } @@ -270,23 +277,23 @@ slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); if (need_keys) - exit (1); + exit (EXIT_FAILURE); } 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")) @@ -294,32 +301,43 @@ 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); -#if ENABLE_HTTP_PROXY + free (script_node_down), script_node_down = strdup (val); + else if (!strcmp (var, "pid-file")) + free (pidfilename), pidfilename = strdup (val); else if (!strcmp (var, "http-proxy-host")) - proxy_host = strdup (val); + { +#if ENABLE_HTTP_PROXY + free (proxy_host), proxy_host = strdup (val); +#endif + } else if (!strcmp (var, "http-proxy-port")) - proxy_port = atoi (val); + { +#if ENABLE_HTTP_PROXY + proxy_port = atoi (val); +#endif + } else if (!strcmp (var, "http-proxy-auth")) - proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); + { +#if ENABLE_HTTP_PROXY + proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); #endif + } /* 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-port")) + node->dns_port = atoi (val); else if (!strcmp (var, "router-priority")) node->routerprio = atoi (val); else if (!strcmp (var, "connect")) @@ -358,12 +376,18 @@ 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; } else if (!strcmp (var, "enable-rawip")) - { + {; u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; } @@ -379,7 +403,7 @@ else { slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); - exit (1); + exit (EXIT_FAILURE); } free (fname); @@ -395,10 +419,10 @@ { ERR_load_RSA_strings (); ERR_load_PEM_strings (); slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); - exit (1); + exit (EXIT_FAILURE); } - RSA_blinding_on (rsa_key, 0); + require (RSA_blinding_on (rsa_key, 0)); fclose (f); } @@ -407,9 +431,18 @@ slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); if (need_keys) - exit (1); + exit (EXIT_FAILURE); } + 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) + { + slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); + exit (EXIT_FAILURE); + } + free (fname); } @@ -454,6 +487,8 @@ configuration::configuration () { + asprintf (&confbase, "%s/vpe", CONFDIR); + init (); }