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.21 by pcg, Sat Jan 17 01:18:36 2004 UTC vs.
Revision 1.26 by pcg, Wed May 12 13:32:13 2004 UTC

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;
118
119 conf.pidfilename = strdup (LOCALSTATEDIR "/run/vped.pid");
116} 120}
117 121
118void configuration::cleanup() 122void configuration::cleanup()
119{ 123{
120 if (rsa_key) 124 if (rsa_key)
121 RSA_free (rsa_key); 125 RSA_free (rsa_key);
122 126
123 rsa_key = 0; 127 rsa_key = 0;
124 128
129 free (pidfilename); pidfilename = 0;
125 free (ifname); ifname = 0; 130 free (ifname); ifname = 0;
126#if ENABLE_HTTP_PROXY 131#if ENABLE_HTTP_PROXY
127 free (proxy_host); proxy_host = 0; 132 free (proxy_host); proxy_host = 0;
128 free (proxy_auth); proxy_auth = 0; 133 free (proxy_auth); proxy_auth = 0;
129#endif 134#endif
130} 135}
131 136
132void 137void
133configuration::clear_config () 138configuration::clear_config ()
258 263
259 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) 264 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL))
260 { 265 {
261 ERR_load_RSA_strings (); ERR_load_PEM_strings (); 266 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)); 267 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
263 exit (1); 268 exit (EXIT_FAILURE);
264 } 269 }
265 270
266 RSA_blinding_on (node->rsa_key, 0); 271 require (RSA_blinding_on (node->rsa_key, 0));
267 272
268 fclose (f); 273 fclose (f);
269 } 274 }
270 else 275 else
271 { 276 {
272 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); 277 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno));
273 278
274 if (need_keys) 279 if (need_keys)
275 exit (1); 280 exit (EXIT_FAILURE);
276 } 281 }
277 282
278 free (fname); 283 free (fname);
279 } 284 }
280 285
281 if (!::thisnode || !strcmp (node->nodename, ::thisnode)) 286 if (::thisnode && !strcmp (node->nodename, ::thisnode))
282 thisnode = node; 287 thisnode = node;
283 } 288 }
284 else if (!strcmp (var, "private-key")) 289 else if (!strcmp (var, "private-key"))
285 prikeyfile = strdup (val); 290 free (prikeyfile), prikeyfile = strdup (val);
286 else if (!strcmp (var, "ifpersist")) 291 else if (!strcmp (var, "ifpersist"))
287 { 292 {
288 parse_bool (ifpersist, "ifpersist", true, false); 293 parse_bool (ifpersist, "ifpersist", true, false);
289 } 294 }
290 else if (!strcmp (var, "ifname")) 295 else if (!strcmp (var, "ifname"))
291 ifname = strdup (val); 296 free (ifname), ifname = strdup (val);
292 else if (!strcmp (var, "rekey")) 297 else if (!strcmp (var, "rekey"))
293 rekey = atoi (val); 298 rekey = atoi (val);
294 else if (!strcmp (var, "keepalive")) 299 else if (!strcmp (var, "keepalive"))
295 keepalive = atoi (val); 300 keepalive = atoi (val);
296 else if (!strcmp (var, "mtu")) 301 else if (!strcmp (var, "mtu"))
297 mtu = atoi (val); 302 mtu = atoi (val);
298 else if (!strcmp (var, "if-up")) 303 else if (!strcmp (var, "if-up"))
299 script_if_up = strdup (val); 304 free (script_if_up), script_if_up = strdup (val);
300 else if (!strcmp (var, "node-up")) 305 else if (!strcmp (var, "node-up"))
301 script_node_up = strdup (val); 306 free (script_node_up), script_node_up = strdup (val);
302 else if (!strcmp (var, "node-down")) 307 else if (!strcmp (var, "node-down"))
303 script_node_down = strdup (val); 308 free (script_node_down), script_node_down = strdup (val);
309 else if (!strcmp (var, "pid-file"))
310 free (pidfilename), pidfilename = strdup (val);
304 else if (!strcmp (var, "http-proxy-host")) 311 else if (!strcmp (var, "http-proxy-host"))
305 { 312 {
306#if ENABLE_HTTP_PROXY 313#if ENABLE_HTTP_PROXY
307 proxy_host = strdup (val); 314 free (proxy_host), proxy_host = strdup (val);
308#endif 315#endif
309 } 316 }
310 else if (!strcmp (var, "http-proxy-port")) 317 else if (!strcmp (var, "http-proxy-port"))
311 { 318 {
312#if ENABLE_HTTP_PROXY 319#if ENABLE_HTTP_PROXY
320#endif 327#endif
321 } 328 }
322 329
323 /* node-specific, non-defaultable */ 330 /* node-specific, non-defaultable */
324 else if (node != &default_node && !strcmp (var, "hostname")) 331 else if (node != &default_node && !strcmp (var, "hostname"))
325 {
326 free (node->hostname);
327 node->hostname = strdup (val); 332 free (node->hostname), node->hostname = strdup (val);
328 }
329 333
330 /* node-specific, defaultable */ 334 /* node-specific, defaultable */
331 else if (!strcmp (var, "udp-port")) 335 else if (!strcmp (var, "udp-port"))
332 node->udp_port = atoi (val); 336 node->udp_port = atoi (val);
333 else if (!strcmp (var, "tcp-port")) 337 else if (!strcmp (var, "tcp-port"))
334 node->tcp_port = atoi (val); 338 node->tcp_port = atoi (val);
339 else if (!strcmp (var, "dns-port"))
340 node->dns_port = atoi (val);
335 else if (!strcmp (var, "router-priority")) 341 else if (!strcmp (var, "router-priority"))
336 node->routerprio = atoi (val); 342 node->routerprio = atoi (val);
337 else if (!strcmp (var, "connect")) 343 else if (!strcmp (var, "connect"))
338 { 344 {
339 if (!strcmp (val, "ondemand")) 345 if (!strcmp (val, "ondemand"))
368 { 374 {
369#if ENABLE_ICMP 375#if ENABLE_ICMP
370 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v; 376 u8 v; parse_bool (v, "enable-icmp" , PROT_ICMPv4, 0); node->protocols = (node->protocols & ~PROT_ICMPv4) | v;
371#endif 377#endif
372 } 378 }
379 else if (!strcmp (var, "enable-dns"))
380 {
381#if ENABLE_DNS
382 u8 v; parse_bool (v, "enable-dns" , PROT_DNSv4, 0); node->protocols = (node->protocols & ~PROT_DNSv4) | v;
383#endif
384 }
373 else if (!strcmp (var, "enable-udp")) 385 else if (!strcmp (var, "enable-udp"))
374 { 386 {
375 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v; 387 u8 v; parse_bool (v, "enable-udp" , PROT_UDPv4, 0); node->protocols = (node->protocols & ~PROT_UDPv4) | v;
376 } 388 }
377 else if (!strcmp (var, "enable-rawip")) 389 else if (!strcmp (var, "enable-rawip"))
378 { 390 {;
379 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v; 391 u8 v; parse_bool (v, "enable-rawip", PROT_IPv4, 0); node->protocols = (node->protocols & ~PROT_IPv4 ) | v;
380 } 392 }
381 393
382 // unknown or misplaced 394 // unknown or misplaced
383 else 395 else
389 fclose (f); 401 fclose (f);
390 } 402 }
391 else 403 else
392 { 404 {
393 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); 405 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno));
394 exit (1); 406 exit (EXIT_FAILURE);
395 } 407 }
396 408
397 free (fname); 409 free (fname);
398 410
399 fname = config_filename (prikeyfile, "hostkey"); 411 fname = config_filename (prikeyfile, "hostkey");
405 417
406 if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) 418 if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL))
407 { 419 {
408 ERR_load_RSA_strings (); ERR_load_PEM_strings (); 420 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)); 421 slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
410 exit (1); 422 exit (EXIT_FAILURE);
411 } 423 }
412 424
413 RSA_blinding_on (rsa_key, 0); 425 require (RSA_blinding_on (rsa_key, 0));
414 426
415 fclose (f); 427 fclose (f);
416 } 428 }
417 else 429 else
418 { 430 {
419 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); 431 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno));
420 432
421 if (need_keys) 433 if (need_keys)
422 exit (1); 434 exit (EXIT_FAILURE);
423 } 435 }
436
437 if (need_keys && ::thisnode
438 && rsa_key && thisnode && thisnode->rsa_key)
439 if (BN_cmp (rsa_key->n, thisnode->rsa_key->n) != 0
440 || BN_cmp (rsa_key->e, thisnode->rsa_key->e) != 0)
441 {
442 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
443 exit (EXIT_FAILURE);
444 }
424 445
425 free (fname); 446 free (fname);
426} 447}
427 448
428char *configuration::config_filename (const char *name, const char *dflt) 449char *configuration::config_filename (const char *name, const char *dflt)
464 printf ("\n"); 485 printf ("\n");
465} 486}
466 487
467configuration::configuration () 488configuration::configuration ()
468{ 489{
490 asprintf (&confbase, "%s/vpe", CONFDIR);
491
469 init (); 492 init ();
470} 493}
471 494
472configuration::~configuration () 495configuration::~configuration ()
473{ 496{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines