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.33 by pcg, Sun Mar 6 18:34:46 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
128 dns_forw_host = strdup ("127.0.0.1"); 133 dns_forw_host = strdup ("127.0.0.1");
129 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;
130#endif 139#endif
131 140
132 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid"); 141 conf.pidfilename = strdup (LOCALSTATEDIR "/run/gvpe.pid");
133} 142}
134 143
160 169
161 cleanup (); 170 cleanup ();
162 init (); 171 init ();
163} 172}
164 173
165#define parse_bool(target,name,trueval,falseval) \ 174#define parse_bool(target,name,trueval,falseval) do { \
166 if (!strcmp (val, "yes")) target = trueval; \ 175 if (!strcmp (val, "yes")) target = trueval; \
167 else if (!strcmp (val, "no")) target = falseval; \ 176 else if (!strcmp (val, "no")) target = falseval; \
168 else if (!strcmp (val, "true")) target = trueval; \ 177 else if (!strcmp (val, "true")) target = trueval; \
169 else if (!strcmp (val, "false")) target = falseval; \ 178 else if (!strcmp (val, "false")) target = falseval; \
170 else if (!strcmp (val, "on")) target = trueval; \ 179 else if (!strcmp (val, "on")) target = trueval; \
171 else if (!strcmp (val, "off")) target = falseval; \ 180 else if (!strcmp (val, "off")) target = falseval; \
172 else \ 181 else \
173 slog (L_WARN, \ 182 slog (L_WARN, \
174 _("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"), \
175 name, var, fname, lineno); 184 name, var, fname, lineno); \
185} while (0)
176 186
177void configuration::read_config (bool need_keys) 187void configuration::read_config (bool need_keys)
178{ 188{
179 char *fname; 189 char *fname;
180 FILE *f; 190 FILE *f;
219 val = strtok (NULL, "\t\n\r ="); 229 val = strtok (NULL, "\t\n\r =");
220 230
221 if (!val || val[0] == '#') 231 if (!val || val[0] == '#')
222 { 232 {
223 slog (L_WARN, 233 slog (L_WARN,
224 _("no value for variable `%s', at '%s' line %d"), 234 _("no value for variable `%s', at '%s' line %d, skipping."),
225 var, fname, lineno); 235 var, fname, lineno);
226 break; 236 continue;
227 } 237 }
228 238
229 if (!strcmp (var, "on")) 239 if (!strcmp (var, "on"))
230 { 240 {
231 if (!::thisnode 241 if (!::thisnode
303 thisnode = node; 313 thisnode = node;
304 } 314 }
305 else if (!strcmp (var, "private-key")) 315 else if (!strcmp (var, "private-key"))
306 free (prikeyfile), prikeyfile = strdup (val); 316 free (prikeyfile), prikeyfile = strdup (val);
307 else if (!strcmp (var, "ifpersist")) 317 else if (!strcmp (var, "ifpersist"))
308 {
309 parse_bool (ifpersist, "ifpersist", true, false); 318 parse_bool (ifpersist, "ifpersist", true, false);
310 }
311 else if (!strcmp (var, "ifname")) 319 else if (!strcmp (var, "ifname"))
312 free (ifname), ifname = strdup (val); 320 free (ifname), ifname = strdup (val);
313 else if (!strcmp (var, "rekey")) 321 else if (!strcmp (var, "rekey"))
314 rekey = atoi (val); 322 rekey = atoi (val);
315 else if (!strcmp (var, "keepalive")) 323 else if (!strcmp (var, "keepalive"))
322 free (script_node_up), script_node_up = strdup (val); 330 free (script_node_up), script_node_up = strdup (val);
323 else if (!strcmp (var, "node-down")) 331 else if (!strcmp (var, "node-down"))
324 free (script_node_down), script_node_down = strdup (val); 332 free (script_node_down), script_node_down = strdup (val);
325 else if (!strcmp (var, "pid-file")) 333 else if (!strcmp (var, "pid-file"))
326 free (pidfilename), pidfilename = strdup (val); 334 free (pidfilename), pidfilename = strdup (val);
327#if ENABLE_DNS
328 else if (!strcmp (var, "dns-forw-host")) 335 else if (!strcmp (var, "dns-forw-host"))
336 {
337#if ENABLE_DNS
329 free (dns_forw_host), dns_forw_host = strdup (val); 338 free (dns_forw_host), dns_forw_host = strdup (val);
339#endif
340 }
330 else if (!strcmp (var, "dns-forw-port")) 341 else if (!strcmp (var, "dns-forw-port"))
342 {
343#if ENABLE_DNS
331 dns_forw_port = atoi (val); 344 dns_forw_port = atoi (val);
332#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 }
333 else if (!strcmp (var, "http-proxy-host")) 371 else if (!strcmp (var, "http-proxy-host"))
334 { 372 {
335#if ENABLE_HTTP_PROXY 373#if ENABLE_HTTP_PROXY
336 free (proxy_host), proxy_host = strdup (val); 374 free (proxy_host), proxy_host = strdup (val);
337#endif 375#endif
356 /* node-specific, defaultable */ 394 /* node-specific, defaultable */
357 else if (!strcmp (var, "udp-port")) 395 else if (!strcmp (var, "udp-port"))
358 node->udp_port = atoi (val); 396 node->udp_port = atoi (val);
359 else if (!strcmp (var, "tcp-port")) 397 else if (!strcmp (var, "tcp-port"))
360 node->tcp_port = atoi (val); 398 node->tcp_port = atoi (val);
361#if ENABLE_DNS
362 else if (!strcmp (var, "dns-hostname")) 399 else if (!strcmp (var, "dns-hostname"))
400 {
401#if ENABLE_DNS
363 free (node->dns_hostname), node->dns_hostname = strdup (val); 402 free (node->dns_hostname), node->dns_hostname = strdup (val);
403#endif
404 }
364 else if (!strcmp (var, "dns-port")) 405 else if (!strcmp (var, "dns-port"))
406 {
407#if ENABLE_DNS
365 node->dns_port = atoi (val); 408 node->dns_port = atoi (val);
409#endif
410 }
366 else if (!strcmp (var, "dns-domain")) 411 else if (!strcmp (var, "dns-domain"))
412 {
413#if ENABLE_DNS
367 free (node->domain), node->domain = strdup (val); 414 free (node->domain), node->domain = strdup (val);
368#endif 415#endif
416 }
417 else if (!strcmp (var, "if-up-data"))
418 free (node->if_up_data), node->if_up_data = strdup (val);
369 else if (!strcmp (var, "router-priority")) 419 else if (!strcmp (var, "router-priority"))
370 node->routerprio = atoi (val); 420 node->routerprio = atoi (val);
371 else if (!strcmp (var, "max-retry")) 421 else if (!strcmp (var, "max-retry"))
372 node->max_retry = atoi (val); 422 node->max_retry = atoi (val);
373 else if (!strcmp (var, "connect")) 423 else if (!strcmp (var, "connect"))
380 node->connectmode = conf_node::C_ALWAYS; 430 node->connectmode = conf_node::C_ALWAYS;
381 else if (!strcmp (val, "disabled")) 431 else if (!strcmp (val, "disabled"))
382 node->connectmode = conf_node::C_DISABLED; 432 node->connectmode = conf_node::C_DISABLED;
383 else 433 else
384 slog (L_WARN, 434 slog (L_WARN,
385 _("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."),
386 var, fname, lineno); 436 var, fname, lineno);
387 } 437 }
388 else if (!strcmp (var, "inherit-tos")) 438 else if (!strcmp (var, "inherit-tos"))
389 {
390 parse_bool (node->inherit_tos, "inherit-tos", true, false); 439 parse_bool (node->inherit_tos, "inherit-tos", true, false);
391 }
392 else if (!strcmp (var, "compress")) 440 else if (!strcmp (var, "compress"))
393 {
394 parse_bool (node->compress, "compress", true, false); 441 parse_bool (node->compress, "compress", true, false);
395 }
396 // 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!
397 else if (!strcmp (var, "enable-tcp")) 443 else if (!strcmp (var, "enable-tcp"))
398 { 444 {
399#if ENABLE_TCP 445#if ENABLE_TCP
400 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;
422 } 468 }
423 469
424 // unknown or misplaced 470 // unknown or misplaced
425 else 471 else
426 slog (L_WARN, 472 slog (L_WARN,
427 _("unknown or misplaced variable `%s', at '%s' line %d"), 473 _("unknown or misplaced variable `%s', at '%s' line %d, skipping."),
428 var, fname, lineno); 474 var, fname, lineno);
429 } 475 }
430 476
431 fclose (f); 477 fclose (f);
432 } 478 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines