… | |
… | |
38 | #include <errno.h> |
38 | #include <errno.h> |
39 | #include <netdb.h> |
39 | #include <netdb.h> |
40 | #include <sys/stat.h> |
40 | #include <sys/stat.h> |
41 | #include <sys/types.h> |
41 | #include <sys/types.h> |
42 | #include <unistd.h> |
42 | #include <unistd.h> |
|
|
43 | #include <pwd.h> |
43 | |
44 | |
44 | #include "netcompat.h" |
45 | #include "netcompat.h" |
45 | |
46 | |
46 | #include <openssl/err.h> |
47 | #include <openssl/err.h> |
47 | #include <openssl/pem.h> |
48 | #include <openssl/pem.h> |
… | |
… | |
180 | free (proxy_auth); proxy_auth = 0; |
181 | free (proxy_auth); proxy_auth = 0; |
181 | #endif |
182 | #endif |
182 | #if ENABLE_DNS |
183 | #if ENABLE_DNS |
183 | free (dns_forw_host); dns_forw_host = 0; |
184 | free (dns_forw_host); dns_forw_host = 0; |
184 | #endif |
185 | #endif |
|
|
186 | free (change_root); change_root = 0; |
185 | free (script_if_up); script_if_up = 0; |
187 | free (script_if_up); script_if_up = 0; |
186 | free (script_node_up); script_node_up = 0; |
188 | free (script_node_up); script_node_up = 0; |
187 | free (script_node_change); script_node_change = 0; |
189 | free (script_node_change); script_node_change = 0; |
188 | free (script_node_down); script_node_down = 0; |
190 | free (script_node_down); script_node_down = 0; |
189 | } |
191 | } |
… | |
… | |
212 | else if (!strcmp (val, "true")) target = trueval; \ |
214 | else if (!strcmp (val, "true")) target = trueval; \ |
213 | else if (!strcmp (val, "false")) target = falseval; \ |
215 | else if (!strcmp (val, "false")) target = falseval; \ |
214 | else if (!strcmp (val, "on")) target = trueval; \ |
216 | else if (!strcmp (val, "on")) target = trueval; \ |
215 | else if (!strcmp (val, "off")) target = falseval; \ |
217 | else if (!strcmp (val, "off")) target = falseval; \ |
216 | else \ |
218 | else \ |
217 | return _("illegal boolean value, only 'yes|true|on' or 'no|false|off' allowed. (ignored)"); \ |
219 | return _("illegal boolean value, only 'yes|true|on' or 'no|false|off' allowed, ignored"); \ |
218 | } while (0) |
220 | } while (0) |
219 | |
221 | |
220 | const char * |
222 | const char * |
221 | configuration_parser::parse_line (char *line) |
223 | configuration_parser::parse_line (char *line) |
222 | { |
224 | { |
… | |
… | |
240 | return 0; /* comment: ignore */ |
242 | return 0; /* comment: ignore */ |
241 | |
243 | |
242 | char *val = strtok (NULL, "\t\n\r ="); |
244 | char *val = strtok (NULL, "\t\n\r ="); |
243 | |
245 | |
244 | if (!val || val[0] == '#') |
246 | if (!val || val[0] == '#') |
245 | return _("no value given for variable. (ignored)"); |
247 | return _("no value given for variable, ignored"); |
246 | |
248 | |
247 | else if (!strcmp (var, "on")) |
249 | else if (!strcmp (var, "on")) |
248 | { |
250 | { |
249 | if (!::thisnode |
251 | if (::thisnode |
250 | || (val[0] == '!' && strcmp (val + 1, ::thisnode)) |
252 | && ((val[0] == '!' && strcmp (val + 1, ::thisnode)) |
251 | || !strcmp (val, ::thisnode)) |
253 | || !strcmp (val, ::thisnode))) |
252 | return parse_line (strtok (NULL, "\n\r")); |
254 | return parse_line (strtok (NULL, "\n\r")); |
253 | } |
255 | } |
254 | |
256 | |
255 | else if (!strcmp (var, "include")) |
257 | else if (!strcmp (var, "include")) |
256 | { |
258 | { |
… | |
… | |
263 | else if (!strcmp (var, "loglevel")) |
265 | else if (!strcmp (var, "loglevel")) |
264 | { |
266 | { |
265 | loglevel l = string_to_loglevel (val); |
267 | loglevel l = string_to_loglevel (val); |
266 | |
268 | |
267 | if (l == L_NONE) |
269 | if (l == L_NONE) |
268 | return _("unknown loglevel. (skipping)"); |
270 | return _("unknown loglevel, ignored"); |
269 | } |
271 | } |
270 | else if (!strcmp (var, "ip-proto")) |
272 | else if (!strcmp (var, "ip-proto")) |
271 | conf.ip_proto = atoi (val); |
273 | conf.ip_proto = atoi (val); |
272 | else if (!strcmp (var, "icmp-type")) |
274 | else if (!strcmp (var, "icmp-type")) |
273 | { |
275 | { |
274 | #if ENABLE_ICMP |
276 | #if ENABLE_ICMP |
275 | conf.icmp_type = atoi (val); |
277 | conf.icmp_type = atoi (val); |
276 | #endif |
278 | #endif |
277 | } |
279 | } |
|
|
280 | else if (!strcmp (var, "chuser")) |
|
|
281 | { |
|
|
282 | struct passwd *pw = getpwnam (val); |
|
|
283 | if (!pw) |
|
|
284 | return _("user specified for chuser not found"); |
278 | |
285 | |
279 | // per config |
286 | conf.change_uid = pw->pw_uid; |
|
|
287 | conf.change_gid = pw->pw_gid; |
|
|
288 | } |
|
|
289 | else if (!strcmp (var, "chuid")) |
|
|
290 | conf.change_uid = atoi (val); |
|
|
291 | else if (!strcmp (var, "chgid")) |
|
|
292 | conf.change_gid = atoi (val); |
|
|
293 | else if (!strcmp (var, "chroot")) |
|
|
294 | free (conf.change_root), conf.change_root = strdup (val); |
|
|
295 | |
|
|
296 | // per node |
280 | else if (!strcmp (var, "node")) |
297 | else if (!strcmp (var, "node")) |
281 | { |
298 | { |
282 | parse_argv (); |
299 | parse_argv (); |
283 | |
300 | |
284 | conf.default_node.id++; |
301 | conf.default_node.id++; |
… | |
… | |
449 | else if (!strcmp (val, "always")) |
466 | else if (!strcmp (val, "always")) |
450 | node->connectmode = conf_node::C_ALWAYS; |
467 | node->connectmode = conf_node::C_ALWAYS; |
451 | else if (!strcmp (val, "disabled")) |
468 | else if (!strcmp (val, "disabled")) |
452 | node->connectmode = conf_node::C_DISABLED; |
469 | node->connectmode = conf_node::C_DISABLED; |
453 | else |
470 | else |
454 | return _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled'. (ignored)"); |
471 | return _("illegal value for 'connectmode', use one of 'ondemand', 'never', 'always' or 'disabled', ignored"); |
455 | } |
472 | } |
456 | else if (!strcmp (var, "inherit-tos")) |
473 | else if (!strcmp (var, "inherit-tos")) |
457 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
474 | parse_bool (node->inherit_tos, "inherit-tos", true, false); |
458 | else if (!strcmp (var, "compress")) |
475 | else if (!strcmp (var, "compress")) |
459 | parse_bool (node->compress, "compress", true, false); |
476 | parse_bool (node->compress, "compress", true, false); |
… | |
… | |
556 | { |
573 | { |
557 | if (FILE *f = fopen (fname, "r")) |
574 | if (FILE *f = fopen (fname, "r")) |
558 | { |
575 | { |
559 | char line [2048]; |
576 | char line [2048]; |
560 | int lineno = 0; |
577 | int lineno = 0; |
561 | node = &conf.default_node; |
|
|
562 | |
578 | |
563 | while (fgets (line, sizeof (line), f)) |
579 | while (fgets (line, sizeof (line), f)) |
564 | { |
580 | { |
565 | lineno++; |
581 | lineno++; |
566 | |
582 | |
… | |
… | |
588 | : conf (conf),need_keys (need_keys), argc (argc), argv (argv) |
604 | : conf (conf),need_keys (need_keys), argc (argc), argv (argv) |
589 | { |
605 | { |
590 | char *fname; |
606 | char *fname; |
591 | |
607 | |
592 | conf.clear (); |
608 | conf.clear (); |
|
|
609 | node = &conf.default_node; |
593 | |
610 | |
594 | asprintf (&fname, "%s/gvpe.conf", confbase); |
611 | asprintf (&fname, "%s/gvpe.conf", confbase); |
595 | parse_file (fname); |
612 | parse_file (fname); |
596 | free (fname); |
613 | free (fname); |
597 | |
614 | |