1 | /* |
1 | /* |
2 | conf.c -- configuration code |
2 | conf.c -- configuration code |
3 | Copyright (C) 1998 Robert van der Meulen |
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | 1998-2002 Ivo Timmermans <ivo@o2w.nl> |
|
|
5 | 2000-2002 Guus Sliepen <guus@sliepen.eu.org> |
|
|
6 | 2000 Cris van Pelt <tribbel@arise.dhs.org> |
|
|
7 | 2003 Marc Lehmann <pcg@goof.com> |
|
|
8 | |
4 | |
9 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
11 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
12 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
37 | |
33 | |
38 | #include <openssl/err.h> |
34 | #include <openssl/err.h> |
39 | #include <openssl/pem.h> |
35 | #include <openssl/pem.h> |
40 | #include <openssl/rsa.h> |
36 | #include <openssl/rsa.h> |
41 | #include <openssl/rand.h> |
37 | #include <openssl/rand.h> |
|
|
38 | #include <openssl/bn.h> |
42 | |
39 | |
43 | #include "gettext.h" |
40 | #include "gettext.h" |
44 | |
41 | |
45 | #include "conf.h" |
42 | #include "conf.h" |
46 | #include "slog.h" |
43 | #include "slog.h" |
… | |
… | |
101 | |
98 | |
102 | void configuration::init () |
99 | void configuration::init () |
103 | { |
100 | { |
104 | memset (this, 0, sizeof (*this)); |
101 | memset (this, 0, sizeof (*this)); |
105 | |
102 | |
|
|
103 | mtu = DEFAULT_MTU; |
106 | rekey = DEFAULT_REKEY; |
104 | rekey = DEFAULT_REKEY; |
107 | keepalive = DEFAULT_KEEPALIVE; |
105 | keepalive = DEFAULT_KEEPALIVE; |
108 | llevel = L_INFO; |
106 | llevel = L_INFO; |
109 | ip_proto = IPPROTO_GRE; |
107 | ip_proto = IPPROTO_GRE; |
110 | #if ENABLE_ICMP |
108 | #if ENABLE_ICMP |
… | |
… | |
228 | else |
226 | else |
229 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
227 | slog (L_WARN, "'%s': %s, at '%s' line %d", val, UNKNOWN_LOGLEVEL, fname, line); |
230 | } |
228 | } |
231 | else if (!strcmp (var, "ip-proto")) |
229 | else if (!strcmp (var, "ip-proto")) |
232 | ip_proto = atoi (val); |
230 | ip_proto = atoi (val); |
|
|
231 | else if (!strcmp (var, "icmp-type")) |
|
|
232 | { |
233 | #if ENABLE_ICMP |
233 | #if ENABLE_ICMP |
234 | //TODO: error message |
|
|
235 | else if (!strcmp (var, "icmp-type")) |
|
|
236 | icmp_type = atoi (val); |
234 | icmp_type = atoi (val); |
237 | #endif |
235 | #endif |
|
|
236 | } |
238 | |
237 | |
239 | // per config |
238 | // per config |
240 | else if (!strcmp (var, "node")) |
239 | else if (!strcmp (var, "node")) |
241 | { |
240 | { |
242 | default_node.id++; |
241 | default_node.id++; |
… | |
… | |
260 | |
259 | |
261 | if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) |
260 | if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) |
262 | { |
261 | { |
263 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
262 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
264 | slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
263 | slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
265 | exit (1); |
264 | exit (EXIT_FAILURE); |
266 | } |
265 | } |
267 | |
266 | |
268 | RSA_blinding_on (node->rsa_key, 0); |
267 | require (RSA_blinding_on (node->rsa_key, 0)); |
269 | |
268 | |
270 | fclose (f); |
269 | fclose (f); |
271 | } |
270 | } |
272 | else |
271 | else |
273 | { |
272 | { |
274 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); |
273 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); |
275 | |
274 | |
276 | if (need_keys) |
275 | if (need_keys) |
277 | exit (1); |
276 | exit (EXIT_FAILURE); |
278 | } |
277 | } |
279 | |
278 | |
280 | free (fname); |
279 | free (fname); |
281 | } |
280 | } |
282 | |
281 | |
… | |
… | |
301 | script_if_up = strdup (val); |
300 | script_if_up = strdup (val); |
302 | else if (!strcmp (var, "node-up")) |
301 | else if (!strcmp (var, "node-up")) |
303 | script_node_up = strdup (val); |
302 | script_node_up = strdup (val); |
304 | else if (!strcmp (var, "node-down")) |
303 | else if (!strcmp (var, "node-down")) |
305 | script_node_down = strdup (val); |
304 | script_node_down = strdup (val); |
|
|
305 | else if (!strcmp (var, "http-proxy-host")) |
|
|
306 | { |
306 | #if ENABLE_HTTP_PROXY |
307 | #if ENABLE_HTTP_PROXY |
307 | else if (!strcmp (var, "http-proxy-host")) |
|
|
308 | proxy_host = strdup (val); |
308 | proxy_host = strdup (val); |
|
|
309 | #endif |
|
|
310 | } |
309 | else if (!strcmp (var, "http-proxy-port")) |
311 | else if (!strcmp (var, "http-proxy-port")) |
|
|
312 | { |
|
|
313 | #if ENABLE_HTTP_PROXY |
310 | proxy_port = atoi (val); |
314 | proxy_port = atoi (val); |
|
|
315 | #endif |
|
|
316 | } |
311 | else if (!strcmp (var, "http-proxy-auth")) |
317 | else if (!strcmp (var, "http-proxy-auth")) |
|
|
318 | { |
|
|
319 | #if ENABLE_HTTP_PROXY |
312 | proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); |
320 | proxy_auth = (char *)base64_encode ((const u8 *)val, strlen (val)); |
313 | #endif |
321 | #endif |
|
|
322 | } |
314 | |
323 | |
315 | /* node-specific, non-defaultable */ |
324 | /* node-specific, non-defaultable */ |
316 | else if (node != &default_node && !strcmp (var, "hostname")) |
325 | else if (node != &default_node && !strcmp (var, "hostname")) |
317 | { |
326 | { |
318 | free (node->hostname); |
327 | free (node->hostname); |
… | |
… | |
381 | fclose (f); |
390 | fclose (f); |
382 | } |
391 | } |
383 | else |
392 | else |
384 | { |
393 | { |
385 | slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); |
394 | slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); |
386 | exit (1); |
395 | exit (EXIT_FAILURE); |
387 | } |
396 | } |
388 | |
397 | |
389 | free (fname); |
398 | free (fname); |
390 | |
399 | |
391 | fname = config_filename (prikeyfile, "hostkey"); |
400 | fname = config_filename (prikeyfile, "hostkey"); |
… | |
… | |
397 | |
406 | |
398 | if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) |
407 | if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) |
399 | { |
408 | { |
400 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
409 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
401 | slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
410 | slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
402 | exit (1); |
411 | exit (EXIT_FAILURE); |
403 | } |
412 | } |
404 | |
413 | |
405 | RSA_blinding_on (rsa_key, 0); |
414 | require (RSA_blinding_on (rsa_key, 0)); |
406 | |
415 | |
407 | fclose (f); |
416 | fclose (f); |
408 | } |
417 | } |
409 | else |
418 | else |
410 | { |
419 | { |
411 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); |
420 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); |
412 | |
421 | |
413 | if (need_keys) |
422 | if (need_keys) |
414 | exit (1); |
423 | exit (EXIT_FAILURE); |
415 | } |
424 | } |
|
|
425 | |
|
|
426 | if (need_keys && rsa_key && thisnode && thisnode->rsa_key) |
|
|
427 | if (BN_cmp (rsa_key->n, thisnode->rsa_key->n) != 0 |
|
|
428 | || BN_cmp (rsa_key->e, thisnode->rsa_key->e) != 0) |
|
|
429 | { |
|
|
430 | slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); |
|
|
431 | exit (EXIT_FAILURE); |
|
|
432 | } |
416 | |
433 | |
417 | free (fname); |
434 | free (fname); |
418 | } |
435 | } |
419 | |
436 | |
420 | char *configuration::config_filename (const char *name, const char *dflt) |
437 | char *configuration::config_filename (const char *name, const char *dflt) |