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.61 by root, Tue Jul 16 16:44:36 2013 UTC vs.
Revision 1.62 by root, Wed Jul 17 16:40:57 2013 UTC

203 203
204 cleanup (); 204 cleanup ();
205 init (); 205 init ();
206} 206}
207 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;
216}
217
208//static bool 218//static bool
209//is_true (const char *name) 219//is_true (const char *name)
210//{ 220//{
211 //re 221 //re
212//} 222//}
295 conf.change_gid = atoi (val); 305 conf.change_gid = atoi (val);
296 else if (!strcmp (var, "chroot")) 306 else if (!strcmp (var, "chroot"))
297 free (conf.change_root), conf.change_root = strdup (val); 307 free (conf.change_root), conf.change_root = strdup (val);
298 308
299 // per node 309 // per node
310 else if (!strcmp (var, "global"))
311 node = &conf.default_node;
300 else if (!strcmp (var, "node")) 312 else if (!strcmp (var, "node"))
301 { 313 {
302 parse_argv (); 314 node = conf.find_node (val);
303 315
316 if (!node)
317 {
304 conf.default_node.id++; 318 conf.default_node.id++;
305 node = new conf_node (conf.default_node); 319 node = new conf_node (conf.default_node);
306 conf.nodes.push_back (node); 320 conf.nodes.push_back (node);
307 node->nodename = strdup (val); 321 node->nodename = strdup (val);
308
309 {
310 char *fname;
311 FILE *f;
312
313 asprintf (&fname, "%s/pubkey/%s", confbase, node->nodename);
314
315 f = fopen (fname, "r");
316 if (f)
317 {
318 node->rsa_key = RSA_new ();
319
320 if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL))
321 {
322 ERR_load_RSA_strings (); ERR_load_PEM_strings ();
323 slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0));
324 exit (EXIT_FAILURE);
325 }
326
327 require (RSA_blinding_on (node->rsa_key, 0));
328
329 fclose (f);
330 } 322 }
331 else
332 {
333 slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno));
334
335 if (need_keys)
336 exit (EXIT_FAILURE);
337 }
338
339 free (fname);
340 }
341
342 if (::thisnode && !strcmp (node->nodename, ::thisnode))
343 conf.thisnode = node;
344 } 323 }
345 else if (!strcmp (var, "private-key")) 324 else if (!strcmp (var, "private-key"))
346 free (conf.prikeyfile), conf.prikeyfile = strdup (val); 325 free (conf.prikeyfile), conf.prikeyfile = strdup (val);
347 else if (!strcmp (var, "ifpersist")) 326 else if (!strcmp (var, "ifpersist"))
348 parse_bool (conf.ifpersist, "ifpersist", true, false); 327 parse_bool (conf.ifpersist, "ifpersist", true, false);
539 connectmode = C_ALWAYS; 518 connectmode = C_ALWAYS;
540 } 519 }
541} 520}
542 521
543void 522void
544configuration_parser::parse_argv ()
545{
546 for (int i = 0; i < argc; ++i)
547 {
548 char *v = argv [i];
549
550 if (!*v)
551 continue;
552
553 char *enode = v;
554
555 while (*enode != '.' && *enode > ' ' && *enode != '=' && *enode)
556 enode++;
557
558 if (*enode != '.')
559 enode = 0;
560
561 char *wnode = node == &conf.default_node
562 ? 0
563 : node->nodename;
564
565 if ((!wnode && !enode)
566 || (wnode && enode && !strncmp (wnode, v, enode - v)))
567 {
568 const char *warn = parse_line (enode ? enode + 1 : v);
569
570 if (warn)
571 slog (L_WARN, _("%s, while parsing command line option '%s'."), warn, v);
572
573 *v = 0;
574 }
575 }
576}
577
578void
579configuration_parser::parse_file (const char *fname) 523configuration_parser::parse_file (const char *fname)
580{ 524{
581 if (FILE *f = fopen (fname, "r")) 525 if (FILE *f = fopen (fname, "r"))
582 { 526 {
583 char line [2048]; 527 char line [2048];
592 if (warn) 536 if (warn)
593 slog (L_WARN, _("%s, at '%s', line %d."), warn, fname, lineno); 537 slog (L_WARN, _("%s, at '%s', line %d."), warn, fname, lineno);
594 } 538 }
595 539
596 fclose (f); 540 fclose (f);
597
598 parse_argv ();
599 } 541 }
600 else 542 else
601 { 543 {
602 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));
603 exit (EXIT_FAILURE); 545 exit (EXIT_FAILURE);
606 548
607configuration_parser::configuration_parser (configuration &conf, 549configuration_parser::configuration_parser (configuration &conf,
608 bool need_keys, 550 bool need_keys,
609 int argc, 551 int argc,
610 char **argv) 552 char **argv)
611: conf (conf),need_keys (need_keys), argc (argc), argv (argv) 553: conf (conf), need_keys (need_keys), argc (argc), argv (argv)
612{ 554{
613 char *fname; 555 char *fname;
614 556
615 conf.clear (); 557 conf.clear ();
616 node = &conf.default_node; 558 node = &conf.default_node;
645 } 587 }
646 } 588 }
647 589
648 free (fname); 590 free (fname);
649 591
650 if (need_keys && ::thisnode
651 && conf.rsa_key && conf.thisnode && conf.thisnode->rsa_key)
652 if (BN_cmp (conf.rsa_key->n, conf.thisnode->rsa_key->n) != 0
653 || BN_cmp (conf.rsa_key->e, conf.thisnode->rsa_key->e) != 0)
654 {
655 slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode);
656 exit (EXIT_FAILURE);
657 }
658
659 fname = conf.config_filename (conf.pidfilename); 592 fname = conf.config_filename (conf.pidfilename);
660 free (conf.pidfilename); conf.pidfilename = fname; 593 free (conf.pidfilename); conf.pidfilename = fname;
661 594
662 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
663 (*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 }
664} 696}
665 697
666char * 698char *
667configuration::config_filename (const char *name, const char *dflt) 699configuration::config_filename (const char *name, const char *dflt)
668{ 700{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines