ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/conf.C
(Generate patch)

Comparing gvpe/src/conf.C (file contents):
Revision 1.20 by pcg, Thu Oct 16 21:57:54 2003 UTC vs.
Revision 1.24 by pcg, Fri Apr 2 14:42:45 2004 UTC

1/* 1/*
2 conf.c -- configuration code 2 conf.c -- configuration code
3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com> 3 Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
33 33
34#include <openssl/err.h> 34#include <openssl/err.h>
35#include <openssl/pem.h> 35#include <openssl/pem.h>
36#include <openssl/rsa.h> 36#include <openssl/rsa.h>
37#include <openssl/rand.h> 37#include <openssl/rand.h>
38#include <openssl/bn.h>
38 39
39#include "gettext.h" 40#include "gettext.h"
40 41
41#include "conf.h" 42#include "conf.h"
42#include "slog.h" 43#include "slog.h"
43#include "util.h" 44#include "util.h"
44 45
45char *confbase; 46char *confbase;
46char *thisnode; 47char *thisnode;
47char *identname; 48char *identname;
48char *pidfilename;
49 49
50struct configuration conf; 50struct configuration conf;
51 51
52u8 best_protocol (u8 protset) 52u8 best_protocol (u8 protset)
53{ 53{
54 if (protset & PROT_IPv4 ) return PROT_IPv4; 54 if (protset & PROT_IPv4 ) return PROT_IPv4;
55 if (protset & PROT_ICMPv4) return PROT_ICMPv4; 55 if (protset & PROT_ICMPv4) return PROT_ICMPv4;
56 if (protset & PROT_UDPv4 ) return PROT_UDPv4; 56 if (protset & PROT_UDPv4 ) return PROT_UDPv4;
57 if (protset & PROT_TCPv4 ) return PROT_TCPv4; 57 if (protset & PROT_TCPv4 ) return PROT_TCPv4;
58 if (protset & PROT_DNSv4 ) return PROT_DNSv4;
58 59
59 return 0; 60 return 0;
60} 61}
61 62
62const char *strprotocol (u8 protocol) 63const char *strprotocol (u8 protocol)
63{ 64{
64 if (protocol & PROT_IPv4 ) return "rawip"; 65 if (protocol & PROT_IPv4 ) return "rawip";
65 if (protocol & PROT_ICMPv4) return "icmp"; 66 if (protocol & PROT_ICMPv4) return "icmp";
66 if (protocol & PROT_UDPv4 ) return "udp"; 67 if (protocol & PROT_UDPv4 ) return "udp";
67 if (protocol & PROT_TCPv4 ) return "tcp"; 68 if (protocol & PROT_TCPv4 ) return "tcp";
69 if (protocol & PROT_DNSv4 ) return "dns";
68 70
69 return "<unknown>"; 71 return "<unknown>";
70} 72}
71 73
72void 74void
107#if ENABLE_ICMP 109#if ENABLE_ICMP
108 icmp_type = ICMP_ECHOREPLY; 110 icmp_type = ICMP_ECHOREPLY;
109#endif 111#endif
110 112
111 default_node.udp_port = DEFAULT_UDPPORT; 113 default_node.udp_port = DEFAULT_UDPPORT;
112 default_node.tcp_port = DEFAULT_UDPPORT; 114 default_node.tcp_port = DEFAULT_UDPPORT; // ehrm
113 default_node.connectmode = conf_node::C_ALWAYS; 115 default_node.connectmode = conf_node::C_ALWAYS;
114 default_node.compress = true; 116 default_node.compress = true;
115 default_node.protocols = PROT_UDPv4; 117 default_node.protocols = PROT_UDPv4;
116} 118}
117 119
120 if (rsa_key) 122 if (rsa_key)
121 RSA_free (rsa_key); 123 RSA_free (rsa_key);
122 124
123 rsa_key = 0; 125 rsa_key = 0;
124 126
127 free (pidfilename); pidfilename = 0;
125 free (ifname); ifname = 0; 128 free (ifname); ifname = 0;
126#if ENABLE_HTTP_PROXY 129#if ENABLE_HTTP_PROXY
127 free (proxy_host); proxy_host = 0; 130 free (proxy_host); proxy_host = 0;
128 free (proxy_auth); proxy_auth = 0; 131 free (proxy_auth); proxy_auth = 0;
129#endif 132#endif
130} 133}
131 134
132void 135void
133configuration::clear_config () 136configuration::clear_config ()
258 261
259 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) 262 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL))
260 { 263 {
261 ERR_load_RSA_strings (); ERR_load_PEM_strings (); 264 ERR_load_RSA_strings (); ERR_load_PEM_strings ();
262 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); 265 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
263 exit (1); 266 exit (EXIT_FAILURE);
264 } 267 }
265 268
266 RSA_blinding_on (node->rsa_key, 0); 269 require (RSA_blinding_on (node->rsa_key, 0));
267 270
268 fclose (f); 271 fclose (f);
269 } 272 }
270 else 273 else
271 { 274 {
272 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); 275 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno));
273 276
274 if (need_keys) 277 if (need_keys)
275 exit (1); 278 exit (EXIT_FAILURE);
276 } 279 }
277 280
278 free (fname); 281 free (fname);
279 } 282 }
280 283
281 if (!::thisnode || !strcmp (node->nodename, ::thisnode)) 284 if (::thisnode && !strcmp (node->nodename, ::thisnode))
282 thisnode = node; 285 thisnode = node;
283 } 286 }
284 else if (!strcmp (var, "private-key")) 287 else if (!strcmp (var, "private-key"))
285 prikeyfile = strdup (val); 288 free (prikeyfile), prikeyfile = strdup (val);
286 else if (!strcmp (var, "ifpersist")) 289 else if (!strcmp (var, "ifpersist"))
287 { 290 {
288 parse_bool (ifpersist, "ifpersist", true, false); 291 parse_bool (ifpersist, "ifpersist", true, false);
289 } 292 }
290 else if (!strcmp (var, "ifname")) 293 else if (!strcmp (var, "ifname"))
291 ifname = strdup (val); 294 free (ifname), ifname = strdup (val);
292 else if (!strcmp (var, "rekey")) 295 else if (!strcmp (var, "rekey"))
293 rekey = atoi (val); 296 rekey = atoi (val);
294 else if (!strcmp (var, "keepalive")) 297 else if (!strcmp (var, "keepalive"))
295 keepalive = atoi (val); 298 keepalive = atoi (val);
296 else if (!strcmp (var, "mtu")) 299 else if (!strcmp (var, "mtu"))
297 mtu = atoi (val); 300 mtu = atoi (val);
298 else if (!strcmp (var, "if-up")) 301 else if (!strcmp (var, "if-up"))
299 script_if_up = strdup (val); 302 free (script_if_up), script_if_up = strdup (val);
300 else if (!strcmp (var, "node-up")) 303 else if (!strcmp (var, "node-up"))
301 script_node_up = strdup (val); 304 free (script_node_up), script_node_up = strdup (val);
302 else if (!strcmp (var, "node-down")) 305 else if (!strcmp (var, "node-down"))
303 script_node_down = strdup (val); 306 free (script_node_down), script_node_down = strdup (val);
307 else if (!strcmp (var, "pid-file"))
308 free (pidfilename), pidfilename = strdup (val);
304 else if (!strcmp (var, "http-proxy-host")) 309 else if (!strcmp (var, "http-proxy-host"))
305 { 310 {
306#if ENABLE_HTTP_PROXY 311#if ENABLE_HTTP_PROXY
307 proxy_host = strdup (val); 312 free (proxy_host), proxy_host = strdup (val);
308#endif 313#endif
309 } 314 }
310 else if (!strcmp (var, "http-proxy-port")) 315 else if (!strcmp (var, "http-proxy-port"))
311 { 316 {
312#if ENABLE_HTTP_PROXY 317#if ENABLE_HTTP_PROXY
320#endif 325#endif
321 } 326 }
322 327
323 /* node-specific, non-defaultable */ 328 /* node-specific, non-defaultable */
324 else if (node != &default_node && !strcmp (var, "hostname")) 329 else if (node != &default_node && !strcmp (var, "hostname"))
325 {
326 free (node->hostname);
327 node->hostname = strdup (val); 330 free (node->hostname), node->hostname = strdup (val);
328 }
329 331
330 /* node-specific, defaultable */ 332 /* node-specific, defaultable */
331 else if (!strcmp (var, "udp-port")) 333 else if (!strcmp (var, "udp-port"))
332 node->udp_port = atoi (val); 334 node->udp_port = atoi (val);
333 else if (!strcmp (var, "tcp-port")) 335 else if (!strcmp (var, "tcp-port"))
334 node->tcp_port = atoi (val); 336 node->tcp_port = atoi (val);
337 else if (!strcmp (var, "dns-port"))
338 node->dns_port = atoi (val);
335 else if (!strcmp (var, "router-priority")) 339 else if (!strcmp (var, "router-priority"))
336 node->routerprio = atoi (val); 340 node->routerprio = atoi (val);
337 else if (!strcmp (var, "connect")) 341 else if (!strcmp (var, "connect"))
338 { 342 {
339 if (!strcmp (val, "ondemand")) 343 if (!strcmp (val, "ondemand"))
368 { 372 {
369#if ENABLE_ICMP 373#if ENABLE_ICMP
370 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; 374 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
371#endif 375#endif
372 } 376 }
377 else if (!strcmp (var, "enable-dns"))
378 {
379#if ENABLE_DNS
380 u8 v; parse_bool (v, "enable-dns" , PROT_DNSv4, 0); node->protocols = (node->protocols & ~PROT_DNSv4) | v;
381#endif
382 }
373 else if (!strcmp (var, "enable-udp")) 383 else if (!strcmp (var, "enable-udp"))
374 { 384 {
375 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 385 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
376 } 386 }
377 else if (!strcmp (var, "enable-rawip")) 387 else if (!strcmp (var, "enable-rawip"))
378 { 388 {;
379 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 389 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
380 } 390 }
381 391
382 // unknown or misplaced 392 // unknown or misplaced
383 else 393 else
389 fclose (f); 399 fclose (f);
390 } 400 }
391 else 401 else
392 { 402 {
393 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); 403 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno));
394 exit (1); 404 exit (EXIT_FAILURE);
395 } 405 }
396 406
397 free (fname); 407 free (fname);
398 408
399 fname = config_filename (prikeyfile, "hostkey"); 409 fname = config_filename (prikeyfile, "hostkey");
405 415
406 if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) 416 if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL))
407 { 417 {
408 ERR_load_RSA_strings (); ERR_load_PEM_strings (); 418 ERR_load_RSA_strings (); ERR_load_PEM_strings ();
409 slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); 419 slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
410 exit (1); 420 exit (EXIT_FAILURE);
411 } 421 }
412 422
413 RSA_blinding_on (rsa_key, 0); 423 require (RSA_blinding_on (rsa_key, 0));
414 424
415 fclose (f); 425 fclose (f);
416 } 426 }
417 else 427 else
418 { 428 {
419 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); 429 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno));
420 430
421 if (need_keys) 431 if (need_keys)
422 exit (1); 432 exit (EXIT_FAILURE);
423 } 433 }
434
435 if (need_keys && ::thisnode
436 && rsa_key && thisnode && thisnode->rsa_key)
437 if (BN_cmp (rsa_key->n, thisnode->rsa_key->n) != 0
438 || BN_cmp (rsa_key->e, thisnode->rsa_key->e) != 0)
439 {
440 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
441 exit (EXIT_FAILURE);
442 }
424 443
425 free (fname); 444 free (fname);
426} 445}
427 446
428char *configuration::config_filename (const char *name, const char *dflt) 447char *configuration::config_filename (const char *name, const char *dflt)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines