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.32 by pcg, Sat Mar 5 15:48:54 2005 UTC vs.
Revision 1.39 by pcg, Sat Mar 26 03:16:24 2005 UTC

37#include <openssl/pem.h> 37#include <openssl/pem.h>
38#include <openssl/rsa.h> 38#include <openssl/rsa.h>
39#include <openssl/rand.h> 39#include <openssl/rand.h>
40#include <openssl/bn.h> 40#include <openssl/bn.h>
41 41
42#include "gettext.h"
43
44#include "conf.h" 42#include "conf.h"
45#include "slog.h" 43#include "slog.h"
46#include "util.h" 44#include "util.h"
47 45
48char *confbase; 46char *confbase;
90 ); 88 );
91} 89}
92 90
93conf_node::~conf_node () 91conf_node::~conf_node ()
94{ 92{
93#if 0
94 // does not work, because string pointers etc. are shared
95 // is not called, however
95 if (rsa_key) 96 if (rsa_key)
96 RSA_free (rsa_key); 97 RSA_free (rsa_key);
97 98
98 free (nodename); 99 free (nodename);
99 free (hostname); 100 free (hostname);
101 free (if_up_data);
100#if ENABLE_DNS 102#if ENABLE_DNS
101 free (domain); 103 free (domain);
102 free (dns_hostname); 104 free (dns_hostname);
105#endif
103#endif 106#endif
104} 107}
105 108
106void configuration::init () 109void configuration::init ()
107{ 110{
120 default_node.tcp_port = DEFAULT_UDPPORT; // ehrm 123 default_node.tcp_port = DEFAULT_UDPPORT; // ehrm
121 default_node.connectmode = conf_node::C_ALWAYS; 124 default_node.connectmode = conf_node::C_ALWAYS;
122 default_node.compress = true; 125 default_node.compress = true;
123 default_node.protocols = 0; 126 default_node.protocols = 0;
124 default_node.max_retry = DEFAULT_MAX_RETRY; 127 default_node.max_retry = DEFAULT_MAX_RETRY;
128 default_node.if_up_data = strdup ("");
125 129
126#if ENABLE_DNS 130#if ENABLE_DNS
127 default_node.dns_port = 0; // default is 0 == client 131 default_node.dns_port = 0; // default is 0 == client
132
133 dns_forw_host = strdup ("127.0.0.1");
128 dns_forw_port = 53; 134 dns_forw_port = 53;
135 dns_timeout_factor = DEFAULT_DNS_TIMEOUT_FACTOR;
136 dns_send_interval = DEFAULT_DNS_SEND_INTERVAL;
137 dns_overlap_factor = DEFAULT_DNS_OVERLAP_FACTOR;
138 dns_max_outstanding = DEFAULT_DNS_MAX_OUTSTANDING;
129#endif 139#endif
130 140
131 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); 141 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
132} 142}
133 143
159 169
160 cleanup (); 170 cleanup ();
161 init (); 171 init ();
162} 172}
163 173
164#define parse_bool(target,name,trueval,falseval) \ 174#define parse_bool(target,name,trueval,falseval) do { \
165 if (!strcmp (val, "yes")) target = trueval; \ 175 if (!strcmp (val, "yes")) target = trueval; \
166 else if (!strcmp (val, "no")) target = falseval; \ 176 else if (!strcmp (val, "no")) target = falseval; \
167 else if (!strcmp (val, "true")) target = trueval; \ 177 else if (!strcmp (val, "true")) target = trueval; \
168 else if (!strcmp (val, "false")) target = falseval; \ 178 else if (!strcmp (val, "false")) target = falseval; \
169 else if (!strcmp (val, "on")) target = trueval; \ 179 else if (!strcmp (val, "on")) target = trueval; \
170 else if (!strcmp (val, "off")) target = falseval; \ 180 else if (!strcmp (val, "off")) target = falseval; \
171 else \ 181 else \
172 slog (L_WARN, \ 182 slog (L_WARN, \
173 _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \ 183 _("illegal value for '%s', only 'yes|true|on' or 'no|false|off' allowed, at '%s' line %d"), \
174 name, var, fname, lineno); 184 name, var, fname, lineno); \
185} while (0)
175 186
176void configuration::read_config (bool need_keys) 187void configuration::read_config (bool need_keys)
177{ 188{
178 char *fname; 189 char *fname;
179 FILE *f; 190 FILE *f;
218 val = strtok (NULL, "\t\n\r ="); 229 val = strtok (NULL, "\t\n\r =");
219 230
220 if (!val || val[0] == '#') 231 if (!val || val[0] == '#')
221 { 232 {
222 slog (L_WARN, 233 slog (L_WARN,
223 _("no value for variable `%s', at '%s' line %d"), 234 _("no value for variable `%s', at '%s' line %d, skipping."),
224 var, fname, lineno); 235 var, fname, lineno);
225 break; 236 continue;
226 } 237 }
227 238
228 if (!strcmp (var, "on")) 239 if (!strcmp (var, "on"))
229 { 240 {
230 if (!::thisnode 241 if (!::thisnode
302 thisnode = node; 313 thisnode = node;
303 } 314 }
304 else if (!strcmp (var, "private-key")) 315 else if (!strcmp (var, "private-key"))
305 free (prikeyfile), prikeyfile = strdup (val); 316 free (prikeyfile), prikeyfile = strdup (val);
306 else if (!strcmp (var, "ifpersist")) 317 else if (!strcmp (var, "ifpersist"))
307 {
308 parse_bool (ifpersist, "ifpersist", true, false); 318 parse_bool (ifpersist, "ifpersist", true, false);
309 }
310 else if (!strcmp (var, "ifname")) 319 else if (!strcmp (var, "ifname"))
311 free (ifname), ifname = strdup (val); 320 free (ifname), ifname = strdup (val);
312 else if (!strcmp (var, "rekey")) 321 else if (!strcmp (var, "rekey"))
313 rekey = atoi (val); 322 rekey = atoi (val);
314 else if (!strcmp (var, "keepalive")) 323 else if (!strcmp (var, "keepalive"))
321 free (script_node_up), script_node_up = strdup (val); 330 free (script_node_up), script_node_up = strdup (val);
322 else if (!strcmp (var, "node-down")) 331 else if (!strcmp (var, "node-down"))
323 free (script_node_down), script_node_down = strdup (val); 332 free (script_node_down), script_node_down = strdup (val);
324 else if (!strcmp (var, "pid-file")) 333 else if (!strcmp (var, "pid-file"))
325 free (pidfilename), pidfilename = strdup (val); 334 free (pidfilename), pidfilename = strdup (val);
326#if ENABLE_DNS
327 else if (!strcmp (var, "dns-forw-host")) 335 else if (!strcmp (var, "dns-forw-host"))
336 {
337#if ENABLE_DNS
328 free (dns_forw_host), dns_forw_host = strdup (val); 338 free (dns_forw_host), dns_forw_host = strdup (val);
339#endif
340 }
329 else if (!strcmp (var, "dns-forw-port")) 341 else if (!strcmp (var, "dns-forw-port"))
342 {
343#if ENABLE_DNS
330 dns_forw_port = atoi (val); 344 dns_forw_port = atoi (val);
331#endif 345#endif
346 }
347 else if (!strcmp (var, "dns-timeout-factor"))
348 {
349#if ENABLE_DNS
350 dns_timeout_factor = atof (val);
351#endif
352 }
353 else if (!strcmp (var, "dns-send-interval"))
354 {
355#if ENABLE_DNS
356 dns_send_interval = atoi (val);
357#endif
358 }
359 else if (!strcmp (var, "dns-overlap-factor"))
360 {
361#if ENABLE_DNS
362 dns_overlap_factor = atof (val);
363#endif
364 }
365 else if (!strcmp (var, "dns-max-outstanding"))
366 {
367#if ENABLE_DNS
368 dns_max_outstanding = atoi (val);
369#endif
370 }
332 else if (!strcmp (var, "http-proxy-host")) 371 else if (!strcmp (var, "http-proxy-host"))
333 { 372 {
334#if ENABLE_HTTP_PROXY 373#if ENABLE_HTTP_PROXY
335 free (proxy_host), proxy_host = strdup (val); 374 free (proxy_host), proxy_host = strdup (val);
336#endif 375#endif
355 /* node-specific, defaultable */ 394 /* node-specific, defaultable */
356 else if (!strcmp (var, "udp-port")) 395 else if (!strcmp (var, "udp-port"))
357 node->udp_port = atoi (val); 396 node->udp_port = atoi (val);
358 else if (!strcmp (var, "tcp-port")) 397 else if (!strcmp (var, "tcp-port"))
359 node->tcp_port = atoi (val); 398 node->tcp_port = atoi (val);
360#if ENABLE_DNS
361 else if (!strcmp (var, "dns-hostname")) 399 else if (!strcmp (var, "dns-hostname"))
400 {
401#if ENABLE_DNS
362 free (node->dns_hostname), node->dns_hostname = strdup (val); 402 free (node->dns_hostname), node->dns_hostname = strdup (val);
403#endif
404 }
363 else if (!strcmp (var, "dns-port")) 405 else if (!strcmp (var, "dns-port"))
406 {
407#if ENABLE_DNS
364 node->dns_port = atoi (val); 408 node->dns_port = atoi (val);
365#endif 409#endif
410 }
366 else if (!strcmp (var, "dns-domain")) 411 else if (!strcmp (var, "dns-domain"))
367 { 412 {
368#if ENABLE_DNS 413#if ENABLE_DNS
369 free (node->domain), node->domain = strdup (val); 414 free (node->domain), node->domain = strdup (val);
370#endif 415#endif
371 } 416 }
417 else if (!strcmp (var, "if-up-data"))
418 free (node->if_up_data), node->if_up_data = strdup (val);
372 else if (!strcmp (var, "router-priority")) 419 else if (!strcmp (var, "router-priority"))
373 node->routerprio = atoi (val); 420 node->routerprio = atoi (val);
374 else if (!strcmp (var, "max-retry")) 421 else if (!strcmp (var, "max-retry"))
375 node->max_retry = atoi (val); 422 node->max_retry = atoi (val);
376 else if (!strcmp (var, "connect")) 423 else if (!strcmp (var, "connect"))
383 node->connectmode = conf_node::C_ALWAYS; 430 node->connectmode = conf_node::C_ALWAYS;
384 else if (!strcmp (val, "disabled")) 431 else if (!strcmp (val, "disabled"))
385 node->connectmode = conf_node::C_DISABLED; 432 node->connectmode = conf_node::C_DISABLED;
386 else 433 else
387 slog (L_WARN, 434 slog (L_WARN,
388 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d"), 435 _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', at '%s' line %d, ignoring."),
389 var, fname, lineno); 436 var, fname, lineno);
390 } 437 }
391 else if (!strcmp (var, "inherit-tos")) 438 else if (!strcmp (var, "inherit-tos"))
392 {
393 parse_bool (node->inherit_tos, "inherit-tos", true, false); 439 parse_bool (node->inherit_tos, "inherit-tos", true, false);
394 }
395 else if (!strcmp (var, "compress")) 440 else if (!strcmp (var, "compress"))
396 {
397 parse_bool (node->compress, "compress", true, false); 441 parse_bool (node->compress, "compress", true, false);
398 }
399 // all these bool options really really cost a lot of executable size! 442 // all these bool options really really cost a lot of executable size!
400 else if (!strcmp (var, "enable-tcp")) 443 else if (!strcmp (var, "enable-tcp"))
401 { 444 {
402#if ENABLE_TCP 445#if ENABLE_TCP
403 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v; 446 u8 v; parse_bool (v, "enable-tcp" , PROT_TCPv4, 0); node->protocols = (node->protocols & ~PROT_TCPv4) | v;
425 } 468 }
426 469
427 // unknown or misplaced 470 // unknown or misplaced
428 else 471 else
429 slog (L_WARN, 472 slog (L_WARN,
430 _("unknown or misplaced variable `%s', at '%s' line %d"), 473 _("unknown or misplaced variable `%s', at '%s' line %d, skipping."),
431 var, fname, lineno); 474 var, fname, lineno);
432 } 475 }
433 476
434 fclose (f); 477 fclose (f);
435 } 478 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines