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.59 by root, Tue Dec 4 10:29:43 2012 UTC vs.
Revision 1.62 by root, Wed Jul 17 16:40:57 2013 UTC

161 dns_send_interval = DEFAULT_DNS_SEND_INTERVAL; 161 dns_send_interval = DEFAULT_DNS_SEND_INTERVAL;
162 dns_overlap_factor = DEFAULT_DNS_OVERLAP_FACTOR; 162 dns_overlap_factor = DEFAULT_DNS_OVERLAP_FACTOR;
163 dns_max_outstanding = DEFAULT_DNS_MAX_OUTSTANDING; 163 dns_max_outstanding = DEFAULT_DNS_MAX_OUTSTANDING;
164#endif 164#endif
165 165
166 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); 166 pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
167 seed_dev = strdup ("/dev/urandom");
168 reseed = DEFAULT_RESEED;
167} 169}
168 170
169void 171void
170configuration::cleanup () 172configuration::cleanup ()
171{ 173{
172 if (rsa_key) 174 if (rsa_key)
173 RSA_free (rsa_key); 175 RSA_free (rsa_key);
174 176
175 rsa_key = 0; 177 rsa_key = 0;
176 178
179 free (seed_dev); seed_dev = 0;
177 free (pidfilename); pidfilename = 0; 180 free (pidfilename); pidfilename = 0;
178 free (ifname); ifname = 0; 181 free (ifname); ifname = 0;
179#if ENABLE_HTTP_PROXY 182#if ENABLE_HTTP_PROXY
180 free (proxy_host); proxy_host = 0; 183 free (proxy_host); proxy_host = 0;
181 free (proxy_auth); proxy_auth = 0; 184 free (proxy_auth); proxy_auth = 0;
198 201
199 nodes.clear (); 202 nodes.clear ();
200 203
201 cleanup (); 204 cleanup ();
202 init (); 205 init ();
206}
207
208conf_node *
209configuration::find_node (const char *name)
210{
211 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i)
212 if (!strcmp ((*i)->nodename, name))
213 return *i;
214
215 return 0;
203} 216}
204 217
205//static bool 218//static bool
206//is_true (const char *name) 219//is_true (const char *name)
207//{ 220//{
292 conf.change_gid = atoi (val); 305 conf.change_gid = atoi (val);
293 else if (!strcmp (var, "chroot")) 306 else if (!strcmp (var, "chroot"))
294 free (conf.change_root), conf.change_root = strdup (val); 307 free (conf.change_root), conf.change_root = strdup (val);
295 308
296 // per node 309 // per node
310 else if (!strcmp (var, "global"))
311 node = &conf.default_node;
297 else if (!strcmp (var, "node")) 312 else if (!strcmp (var, "node"))
298 { 313 {
299 parse_argv (); 314 node = conf.find_node (val);
300 315
316 if (!node)
317 {
301 conf.default_node.id++; 318 conf.default_node.id++;
302 node = new conf_node (conf.default_node); 319 node = new conf_node (conf.default_node);
303 conf.nodes.push_back (node); 320 conf.nodes.push_back (node);
304 node->nodename = strdup (val); 321 node->nodename = strdup (val);
305
306 {
307 char *fname;
308 FILE *f;
309
310 asprintf (&fname, "%s/pubkey/%s", confbase, node->nodename);
311
312 f = fopen (fname, "r");
313 if (f)
314 {
315 node->rsa_key = RSA_new ();
316
317 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL))
318 {
319 ERR_load_RSA_strings (); ERR_load_PEM_strings ();
320 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
321 exit (EXIT_FAILURE);
322 }
323
324 require (RSA_blinding_on (node->rsa_key, 0));
325
326 fclose (f);
327 } 322 }
328 else
329 {
330 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno));
331
332 if (need_keys)
333 exit (EXIT_FAILURE);
334 }
335
336 free (fname);
337 }
338
339 if (::thisnode && !strcmp (node->nodename, ::thisnode))
340 conf.thisnode = node;
341 } 323 }
342 else if (!strcmp (var, "private-key")) 324 else if (!strcmp (var, "private-key"))
343 free (conf.prikeyfile), conf.prikeyfile = strdup (val); 325 free (conf.prikeyfile), conf.prikeyfile = strdup (val);
344 else if (!strcmp (var, "ifpersist")) 326 else if (!strcmp (var, "ifpersist"))
345 parse_bool (conf.ifpersist, "ifpersist", true, false); 327 parse_bool (conf.ifpersist, "ifpersist", true, false);
351 conf.keepalive = atoi (val); 333 conf.keepalive = atoi (val);
352 else if (!strcmp (var, "mtu")) 334 else if (!strcmp (var, "mtu"))
353 conf.mtu = atoi (val); 335 conf.mtu = atoi (val);
354 else if (!strcmp (var, "nfmark")) 336 else if (!strcmp (var, "nfmark"))
355 conf.nfmark = atoi (val); 337 conf.nfmark = atoi (val);
338 else if (!strcmp (var, "seed-device"))
339 free (conf.seed_dev), conf.seed_dev = strdup (val);
340 else if (!strcmp (var, "seed-interval"))
341 conf.reseed = atoi (val);
356 else if (!strcmp (var, "if-up")) 342 else if (!strcmp (var, "if-up"))
357 free (conf.script_if_up), conf.script_if_up = strdup (val); 343 free (conf.script_if_up), conf.script_if_up = strdup (val);
358 else if (!strcmp (var, "node-up")) 344 else if (!strcmp (var, "node-up"))
359 free (conf.script_node_up), conf.script_node_up = strdup (val); 345 free (conf.script_node_up), conf.script_node_up = strdup (val);
360 else if (!strcmp (var, "node-change")) 346 else if (!strcmp (var, "node-change"))
532 connectmode = C_ALWAYS; 518 connectmode = C_ALWAYS;
533 } 519 }
534} 520}
535 521
536void 522void
537configuration_parser::parse_argv ()
538{
539 for (int i = 0; i < argc; ++i)
540 {
541 char *v = argv [i];
542
543 if (!*v)
544 continue;
545
546 char *enode = v;
547
548 while (*enode != '.' && *enode > ' ' && *enode != '=' && *enode)
549 enode++;
550
551 if (*enode != '.')
552 enode = 0;
553
554 char *wnode = node == &conf.default_node
555 ? 0
556 : node->nodename;
557
558 if ((!wnode && !enode)
559 || (wnode && enode && !strncmp (wnode, v, enode - v)))
560 {
561 const char *warn = parse_line (enode ? enode + 1 : v);
562
563 if (warn)
564 slog (L_WARN, _("%s, while parsing command line option '%s'."), warn, v);
565
566 *v = 0;
567 }
568 }
569}
570
571void
572configuration_parser::parse_file (const char *fname) 523configuration_parser::parse_file (const char *fname)
573{ 524{
574 if (FILE *f = fopen (fname, "r")) 525 if (FILE *f = fopen (fname, "r"))
575 { 526 {
576 char line [2048]; 527 char line [2048];
585 if (warn) 536 if (warn)
586 slog (L_WARN, _("%s, at '%s', line %d."), warn, fname, lineno); 537 slog (L_WARN, _("%s, at '%s', line %d."), warn, fname, lineno);
587 } 538 }
588 539
589 fclose (f); 540 fclose (f);
590
591 parse_argv ();
592 } 541 }
593 else 542 else
594 { 543 {
595 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); 544 slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno));
596 exit (EXIT_FAILURE); 545 exit (EXIT_FAILURE);
599 548
600configuration_parser::configuration_parser (configuration &conf, 549configuration_parser::configuration_parser (configuration &conf,
601 bool need_keys, 550 bool need_keys,
602 int argc, 551 int argc,
603 char **argv) 552 char **argv)
604: conf (conf),need_keys (need_keys), argc (argc), argv (argv) 553: conf (conf), need_keys (need_keys), argc (argc), argv (argv)
605{ 554{
606 char *fname; 555 char *fname;
607 556
608 conf.clear (); 557 conf.clear ();
609 node = &conf.default_node; 558 node = &conf.default_node;
629 578
630 fclose (f); 579 fclose (f);
631 } 580 }
632 else 581 else
633 { 582 {
634 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno));
635
636 if (need_keys) 583 if (need_keys)
584 {
585 slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno));
637 exit (EXIT_FAILURE); 586 exit (EXIT_FAILURE);
587 }
638 } 588 }
639 589
640 free (fname); 590 free (fname);
641 591
642 if (need_keys && ::thisnode 592 fname = conf.config_filename (conf.pidfilename);
643 && conf.rsa_key && conf.thisnode && conf.thisnode->rsa_key) 593 free (conf.pidfilename); conf.pidfilename = fname;
644 if (BN_cmp (conf.rsa_key->n, conf.thisnode->rsa_key->n) != 0
645 || BN_cmp (conf.rsa_key->e, conf.thisnode->rsa_key->e) != 0)
646 {
647 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
648 exit (EXIT_FAILURE);
649 }
650 594
651 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i) 595 for (configuration::node_vector::iterator i = conf.nodes.begin(); i != conf.nodes.end(); ++i)
596 {
597 conf_node *node = *i;
598 char *fname;
599 FILE *f;
600
601 asprintf (&fname, "%s/pubkey/%s", confbase, node->nodename);
602
603 f = fopen (fname, "r");
604 if (f)
605 {
606 node->rsa_key = RSA_new ();
607
608 if (!PEM_read_RSAPublicKey (f, &node->rsa_key, NULL, NULL))
609 {
610 ERR_load_RSA_strings (); ERR_load_PEM_strings ();
611 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
612 exit (EXIT_FAILURE);
613 }
614
615 require (RSA_blinding_on (node->rsa_key, 0));
616
617 fclose (f);
618 }
619 else
620 {
621 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno));
622
623 if (need_keys)
624 exit (EXIT_FAILURE);
625 }
626
627 free (fname);
628
652 (*i)->finalise (); 629 (*i)->finalise ();
630 }
631
632 if (::thisnode)
633 {
634 conf.thisnode = conf.find_node (::thisnode);
635
636 if (need_keys)
637 {
638 if (!conf.thisnode)
639 {
640 slog (L_NOTICE, _("local node ('%s') not found in config file, aborting."), ::thisnode);
641 exit (EXIT_FAILURE);
642 }
643
644 if (conf.rsa_key && conf.thisnode->rsa_key)
645 if (BN_cmp (conf.rsa_key->n, conf.thisnode->rsa_key->n) != 0
646 || BN_cmp (conf.rsa_key->e, conf.thisnode->rsa_key->e) != 0)
647 {
648 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
649 exit (EXIT_FAILURE);
650 }
651 }
652 }
653
654 parse_argv ();
655}
656
657void
658configuration_parser::parse_argv ()
659{
660 for (int i = 0; i < argc; ++i)
661 {
662 char *v = argv [i];
663
664 if (!*v)
665 continue;
666
667 char *enode = v;
668
669 while (*enode != '.' && *enode > ' ' && *enode != '=' && *enode)
670 enode++;
671
672 if (*enode != '.')
673 enode = 0;
674
675 if (enode)
676 {
677 char *val = strdup (v);
678 val [enode - v] = 0;
679 node = conf.find_node (val);
680 free (val);
681
682 if (!node)
683 {
684 slog (L_WARN, _("command line option '%s' refers to unknown node, ignoring."), v);
685 continue;
686 }
687 }
688 else
689 node = &conf.default_node;
690
691 const char *warn = parse_line (enode ? enode + 1 : v);
692
693 if (warn)
694 slog (L_WARN, _("%s, while parsing command line option '%s'."), warn, v);
695 }
653} 696}
654 697
655char * 698char *
656configuration::config_filename (const char *name, const char *dflt) 699configuration::config_filename (const char *name, const char *dflt)
657{ 700{
658 char *fname; 701 char *fname;
659 702
660 asprintf (&fname, name ? name : dflt, ::thisnode); 703 asprintf (&fname, name ? name : dflt, ::thisnode ? ::thisnode : "<unset>");
661 704
662 if (!ABSOLUTE_PATH (fname)) 705 if (!ABSOLUTE_PATH (fname))
663 { 706 {
664 char *rname = fname; 707 char *rname = fname;
665 asprintf (&fname, "%s/%s", confbase, rname); 708 asprintf (&fname, "%s/%s", confbase, rname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines