a53c777a82e25865f4b862e776092bf2ce8a5d8a
[strongswan.git] / src / pluto / plutomain.c
1 /* Pluto main program
2 * Copyright (C) 1997 Angelos D. Keromytis.
3 * Copyright (C) 1998-2001 D. Hugh Redelmeier.
4 * Copyright (C) 2009 Andreas Steffen - Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <ctype.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/un.h>
26 #include <fcntl.h>
27 #include <getopt.h>
28 #include <resolv.h>
29 #include <arpa/nameser.h> /* missing from <resolv.h> on old systems */
30 #include <sys/queue.h>
31 #include <sys/prctl.h>
32 #include <pwd.h>
33 #include <grp.h>
34
35 #ifdef CAPABILITIES
36 #include <sys/capability.h>
37 #endif /* CAPABILITIES */
38
39 #include <freeswan.h>
40
41 #include <library.h>
42 #include <debug.h>
43 #include <utils/enumerator.h>
44 #include <utils/optionsfrom.h>
45
46 #ifdef INTEGRITY_TEST
47 #include <fips/fips.h>
48 #include <fips/fips_signature.h>
49 #endif /* INTEGRITY_TEST */
50
51 #include <pfkeyv2.h>
52 #include <pfkey.h>
53
54 #include "constants.h"
55 #include "defs.h"
56 #include "id.h"
57 #include "ca.h"
58 #include "certs.h"
59 #include "ac.h"
60 #include "connections.h"
61 #include "foodgroups.h"
62 #include "packet.h"
63 #include "demux.h" /* needs packet.h */
64 #include "server.h"
65 #include "kernel.h"
66 #include "log.h"
67 #include "keys.h"
68 #include "adns.h" /* needs <resolv.h> */
69 #include "dnskey.h" /* needs keys.h and adns.h */
70 #include "state.h"
71 #include "ipsec_doi.h" /* needs demux.h and state.h */
72 #include "ocsp.h"
73 #include "crl.h"
74 #include "fetch.h"
75 #include "xauth.h"
76 #include "crypto.h"
77 #include "nat_traversal.h"
78 #include "virtual.h"
79 #include "timer.h"
80 #include "vendor.h"
81
82 static void usage(const char *mess)
83 {
84 if (mess != NULL && *mess != '\0')
85 fprintf(stderr, "%s\n", mess);
86 fprintf(stderr
87 , "Usage: pluto"
88 " [--help]"
89 " [--version]"
90 " [--optionsfrom <filename>]"
91 " \\\n\t"
92 "[--nofork]"
93 " [--stderrlog]"
94 " [--noklips]"
95 " [--nocrsend]"
96 " \\\n\t"
97 "[--strictcrlpolicy]"
98 " [--crlcheckinterval <interval>]"
99 " [--cachecrls]"
100 " [--uniqueids]"
101 " \\\n\t"
102 "[--interface <ifname>]"
103 " [--ikeport <port-number>]"
104 " \\\n\t"
105 "[--ctlbase <path>]"
106 " \\\n\t"
107 "[--perpeerlogbase <path>] [--perpeerlog]"
108 " \\\n\t"
109 "[--secretsfile <secrets-file>]"
110 " [--policygroupsdir <policygroups-dir>]"
111 " \\\n\t"
112 "[--adns <pathname>]"
113 "[--pkcs11module <path>]"
114 "[--pkcs11keepstate]"
115 "[--pkcs11initargs <string>]"
116 #ifdef DEBUG
117 " \\\n\t"
118 "[--debug-none]"
119 " [--debug-all]"
120 " \\\n\t"
121 "[--debug-raw]"
122 " [--debug-crypt]"
123 " [--debug-parsing]"
124 " [--debug-emitting]"
125 " \\\n\t"
126 "[--debug-control]"
127 " [--debug-lifecycle]"
128 " [--debug-klips]"
129 " [--debug-dns]"
130 " \\\n\t"
131 "[--debug-oppo]"
132 " [--debug-controlmore]"
133 " [--debug-private]"
134 " [--debug-natt]"
135 #endif
136 " \\\n\t"
137 "[--nat_traversal] [--keep_alive <delay_sec>]"
138 " \\\n\t"
139 "[--force_keepalive] [--disable_port_floating]"
140 " \\\n\t"
141 "[--virtual_private <network_list>]"
142 "\n"
143 "strongSwan %s\n"
144 , ipsec_version_code());
145 exit_pluto(mess == NULL? 0 : 1);
146 }
147
148
149 /* lock file support
150 * - provides convenient way for scripts to find Pluto's pid
151 * - prevents multiple Plutos competing for the same port
152 * - same basename as unix domain control socket
153 * NOTE: will not take account of sharing LOCK_DIR with other systems.
154 */
155
156 static char pluto_lock[sizeof(ctl_addr.sun_path)] = DEFAULT_CTLBASE LOCK_SUFFIX;
157 static bool pluto_lock_created = FALSE;
158
159 /* create lockfile, or die in the attempt */
160 static int create_lock(void)
161 {
162 int fd = open(pluto_lock, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC
163 , S_IRUSR | S_IRGRP | S_IROTH);
164
165 if (fd < 0)
166 {
167 if (errno == EEXIST)
168 {
169 fprintf(stderr, "pluto: lock file \"%s\" already exists\n"
170 , pluto_lock);
171 exit_pluto(10);
172 }
173 else
174 {
175 fprintf(stderr
176 , "pluto: unable to create lock file \"%s\" (%d %s)\n"
177 , pluto_lock, errno, strerror(errno));
178 exit_pluto(1);
179 }
180 }
181 pluto_lock_created = TRUE;
182 return fd;
183 }
184
185 static bool fill_lock(int lockfd, pid_t pid)
186 {
187 char buf[30]; /* holds "<pid>\n" */
188 int len = snprintf(buf, sizeof(buf), "%u\n", (unsigned int) pid);
189 bool ok = len > 0 && write(lockfd, buf, len) == len;
190
191 close(lockfd);
192 return ok;
193 }
194
195 static void delete_lock(void)
196 {
197 if (pluto_lock_created)
198 {
199 delete_ctl_socket();
200 unlink(pluto_lock); /* is noting failure useful? */
201 }
202 }
203
204
205 /* by default pluto sends certificate requests to its peers */
206 bool no_cr_send = FALSE;
207
208 /* by default the CRL policy is lenient */
209 bool strict_crl_policy = FALSE;
210
211 /* by default CRLs are cached locally as files */
212 bool cache_crls = FALSE;
213
214 /* by default pluto does not check crls dynamically */
215 long crl_check_interval = 0;
216
217 /* path to the PKCS#11 module */
218 char *pkcs11_module_path = NULL;
219
220 /* by default pluto logs out after every smartcard use */
221 bool pkcs11_keep_state = FALSE;
222
223 /* by default pluto does not allow pkcs11 proxy access via whack */
224 bool pkcs11_proxy = FALSE;
225
226 /* argument string to pass to PKCS#11 module.
227 * Not used for compliant modules, just for NSS softoken
228 */
229 static const char *pkcs11_init_args = NULL;
230
231 /* options read by optionsfrom */
232 options_t *options;
233
234 /**
235 * Log loaded plugins
236 */
237 static void print_plugins()
238 {
239 char buf[BUF_LEN], *plugin;
240 int len = 0;
241 enumerator_t *enumerator;
242
243 buf[0] = '\0';
244 enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
245 while (len < BUF_LEN && enumerator->enumerate(enumerator, &plugin))
246 {
247 len += snprintf(&buf[len], BUF_LEN-len, "%s ", plugin);
248 }
249 enumerator->destroy(enumerator);
250 DBG1("loaded plugins: %s", buf);
251 }
252
253 int main(int argc, char **argv)
254 {
255 bool fork_desired = TRUE;
256 bool log_to_stderr_desired = FALSE;
257 bool nat_traversal = FALSE;
258 bool nat_t_spf = TRUE; /* support port floating */
259 unsigned int keep_alive = 0;
260 bool force_keepalive = FALSE;
261 char *virtual_private = NULL;
262 int lockfd;
263 #ifdef CAPABILITIES
264 cap_t caps;
265 int keep[] = { CAP_NET_ADMIN, CAP_NET_BIND_SERVICE };
266 #endif /* CAPABILITIES */
267
268 /* initialize library and optionsfrom */
269 library_init(STRONGSWAN_CONF);
270 options = options_create();
271
272 /* handle arguments */
273 for (;;)
274 {
275 # define DBG_OFFSET 256
276 static const struct option long_opts[] = {
277 /* name, has_arg, flag, val */
278 { "help", no_argument, NULL, 'h' },
279 { "version", no_argument, NULL, 'v' },
280 { "optionsfrom", required_argument, NULL, '+' },
281 { "nofork", no_argument, NULL, 'd' },
282 { "stderrlog", no_argument, NULL, 'e' },
283 { "noklips", no_argument, NULL, 'n' },
284 { "nocrsend", no_argument, NULL, 'c' },
285 { "strictcrlpolicy", no_argument, NULL, 'r' },
286 { "crlcheckinterval", required_argument, NULL, 'x'},
287 { "cachecrls", no_argument, NULL, 'C' },
288 { "uniqueids", no_argument, NULL, 'u' },
289 { "interface", required_argument, NULL, 'i' },
290 { "ikeport", required_argument, NULL, 'p' },
291 { "ctlbase", required_argument, NULL, 'b' },
292 { "secretsfile", required_argument, NULL, 's' },
293 { "foodgroupsdir", required_argument, NULL, 'f' },
294 { "perpeerlogbase", required_argument, NULL, 'P' },
295 { "perpeerlog", no_argument, NULL, 'l' },
296 { "policygroupsdir", required_argument, NULL, 'f' },
297 #ifdef USE_LWRES
298 { "lwdnsq", required_argument, NULL, 'a' },
299 #else /* !USE_LWRES */
300 { "adns", required_argument, NULL, 'a' },
301 #endif /* !USE_LWRES */
302 { "pkcs11module", required_argument, NULL, 'm' },
303 { "pkcs11keepstate", no_argument, NULL, 'k' },
304 { "pkcs11initargs", required_argument, NULL, 'z' },
305 { "pkcs11proxy", no_argument, NULL, 'y' },
306 { "nat_traversal", no_argument, NULL, '1' },
307 { "keep_alive", required_argument, NULL, '2' },
308 { "force_keepalive", no_argument, NULL, '3' },
309 { "disable_port_floating", no_argument, NULL, '4' },
310 { "debug-natt", no_argument, NULL, '5' },
311 { "virtual_private", required_argument, NULL, '6' },
312 #ifdef DEBUG
313 { "debug-none", no_argument, NULL, 'N' },
314 { "debug-all", no_argument, NULL, 'A' },
315 { "debug-raw", no_argument, NULL, DBG_RAW + DBG_OFFSET },
316 { "debug-crypt", no_argument, NULL, DBG_CRYPT + DBG_OFFSET },
317 { "debug-parsing", no_argument, NULL, DBG_PARSING + DBG_OFFSET },
318 { "debug-emitting", no_argument, NULL, DBG_EMITTING + DBG_OFFSET },
319 { "debug-control", no_argument, NULL, DBG_CONTROL + DBG_OFFSET },
320 { "debug-lifecycle", no_argument, NULL, DBG_LIFECYCLE + DBG_OFFSET },
321 { "debug-klips", no_argument, NULL, DBG_KLIPS + DBG_OFFSET },
322 { "debug-dns", no_argument, NULL, DBG_DNS + DBG_OFFSET },
323 { "debug-oppo", no_argument, NULL, DBG_OPPO + DBG_OFFSET },
324 { "debug-controlmore", no_argument, NULL, DBG_CONTROLMORE + DBG_OFFSET },
325 { "debug-private", no_argument, NULL, DBG_PRIVATE + DBG_OFFSET },
326
327 { "impair-delay-adns-key-answer", no_argument, NULL, IMPAIR_DELAY_ADNS_KEY_ANSWER + DBG_OFFSET },
328 { "impair-delay-adns-txt-answer", no_argument, NULL, IMPAIR_DELAY_ADNS_TXT_ANSWER + DBG_OFFSET },
329 { "impair-bust-mi2", no_argument, NULL, IMPAIR_BUST_MI2 + DBG_OFFSET },
330 { "impair-bust-mr2", no_argument, NULL, IMPAIR_BUST_MR2 + DBG_OFFSET },
331 #endif
332 { 0,0,0,0 }
333 };
334 /* Note: we don't like the way short options get parsed
335 * by getopt_long, so we simply pass an empty string as
336 * the list. It could be "hvdenp:l:s:" "NARXPECK".
337 */
338 int c = getopt_long(argc, argv, "", long_opts, NULL);
339
340 /* Note: "breaking" from case terminates loop */
341 switch (c)
342 {
343 case EOF: /* end of flags */
344 break;
345
346 case 0: /* long option already handled */
347 continue;
348
349 case ':': /* diagnostic already printed by getopt_long */
350 case '?': /* diagnostic already printed by getopt_long */
351 usage("");
352 break; /* not actually reached */
353
354 case 'h': /* --help */
355 usage(NULL);
356 break; /* not actually reached */
357
358 case 'v': /* --version */
359 {
360 const char **sp = ipsec_copyright_notice();
361
362 printf("%s%s\n", ipsec_version_string(),
363 compile_time_interop_options);
364 for (; *sp != NULL; sp++)
365 puts(*sp);
366 }
367 exit_pluto(0);
368 break; /* not actually reached */
369
370 case '+': /* --optionsfrom <filename> */
371 if (!options->from(options, optarg, &argc, &argv, optind))
372 {
373 exit_pluto(1);
374 }
375 continue;
376
377 case 'd': /* --nofork*/
378 fork_desired = FALSE;
379 continue;
380
381 case 'e': /* --stderrlog */
382 log_to_stderr_desired = TRUE;
383 continue;
384
385 case 'n': /* --noklips */
386 no_klips = TRUE;
387 continue;
388
389 case 'c': /* --nocrsend */
390 no_cr_send = TRUE;
391 continue;
392
393 case 'r': /* --strictcrlpolicy */
394 strict_crl_policy = TRUE;
395 continue;
396
397 case 'x': /* --crlcheckinterval <time>*/
398 if (optarg == NULL || !isdigit(optarg[0]))
399 usage("missing interval time");
400
401 {
402 char *endptr;
403 long interval = strtol(optarg, &endptr, 0);
404
405 if (*endptr != '\0' || endptr == optarg
406 || interval <= 0)
407 usage("<interval-time> must be a positive number");
408 crl_check_interval = interval;
409 }
410 continue;
411
412 case 'C': /* --cachecrls */
413 cache_crls = TRUE;
414 continue;
415
416 case 'u': /* --uniqueids */
417 uniqueIDs = TRUE;
418 continue;
419
420 case 'i': /* --interface <ifname> */
421 if (!use_interface(optarg))
422 usage("too many --interface specifications");
423 continue;
424
425 case 'p': /* --port <portnumber> */
426 if (optarg == NULL || !isdigit(optarg[0]))
427 usage("missing port number");
428
429 {
430 char *endptr;
431 long port = strtol(optarg, &endptr, 0);
432
433 if (*endptr != '\0' || endptr == optarg
434 || port <= 0 || port > 0x10000)
435 usage("<port-number> must be a number between 1 and 65535");
436 pluto_port = port;
437 }
438 continue;
439
440 case 'b': /* --ctlbase <path> */
441 if (snprintf(ctl_addr.sun_path, sizeof(ctl_addr.sun_path)
442 , "%s%s", optarg, CTL_SUFFIX) == -1)
443 usage("<path>" CTL_SUFFIX " too long for sun_path");
444 if (snprintf(info_addr.sun_path, sizeof(info_addr.sun_path)
445 , "%s%s", optarg, INFO_SUFFIX) == -1)
446 usage("<path>" INFO_SUFFIX " too long for sun_path");
447 if (snprintf(pluto_lock, sizeof(pluto_lock)
448 , "%s%s", optarg, LOCK_SUFFIX) == -1)
449 usage("<path>" LOCK_SUFFIX " must fit");
450 continue;
451
452 case 's': /* --secretsfile <secrets-file> */
453 shared_secrets_file = optarg;
454 continue;
455
456 case 'f': /* --policygroupsdir <policygroups-dir> */
457 policygroups_dir = optarg;
458 continue;
459
460 case 'a': /* --adns <pathname> */
461 pluto_adns_option = optarg;
462 continue;
463
464 case 'm': /* --pkcs11module <pathname> */
465 pkcs11_module_path = optarg;
466 continue;
467
468 case 'k': /* --pkcs11keepstate */
469 pkcs11_keep_state = TRUE;
470 continue;
471
472 case 'y': /* --pkcs11proxy */
473 pkcs11_proxy = TRUE;
474 continue;
475
476 case 'z': /* --pkcs11initargs */
477 pkcs11_init_args = optarg;
478 continue;
479
480 #ifdef DEBUG
481 case 'N': /* --debug-none */
482 base_debugging = DBG_NONE;
483 continue;
484
485 case 'A': /* --debug-all */
486 base_debugging = DBG_ALL;
487 continue;
488 #endif
489
490 case 'P': /* --perpeerlogbase */
491 base_perpeer_logdir = optarg;
492 continue;
493
494 case 'l':
495 log_to_perpeer = TRUE;
496 continue;
497
498 case '1': /* --nat_traversal */
499 nat_traversal = TRUE;
500 continue;
501 case '2': /* --keep_alive */
502 keep_alive = atoi(optarg);
503 continue;
504 case '3': /* --force_keepalive */
505 force_keepalive = TRUE;
506 continue;
507 case '4': /* --disable_port_floating */
508 nat_t_spf = FALSE;
509 continue;
510 case '5': /* --debug-nat_t */
511 base_debugging |= DBG_NATT;
512 continue;
513 case '6': /* --virtual_private */
514 virtual_private = optarg;
515 continue;
516
517 default:
518 #ifdef DEBUG
519 if (c >= DBG_OFFSET)
520 {
521 base_debugging |= c - DBG_OFFSET;
522 continue;
523 }
524 # undef DBG_OFFSET
525 #endif
526 bad_case(c);
527 }
528 break;
529 }
530 if (optind != argc)
531 usage("unexpected argument");
532 reset_debugging();
533 lockfd = create_lock();
534
535 /* select between logging methods */
536
537 if (log_to_stderr_desired)
538 {
539 log_to_syslog = FALSE;
540 }
541 else
542 {
543 log_to_stderr = FALSE;
544 }
545
546 /* set the logging function of pfkey debugging */
547 #ifdef DEBUG
548 pfkey_debug_func = DBG_log;
549 #else
550 pfkey_debug_func = NULL;
551 #endif
552
553 /* create control socket.
554 * We must create it before the parent process returns so that
555 * there will be no race condition in using it. The easiest
556 * place to do this is before the daemon fork.
557 */
558 {
559 err_t ugh = init_ctl_socket();
560
561 if (ugh != NULL)
562 {
563 fprintf(stderr, "pluto: %s", ugh);
564 exit_pluto(1);
565 }
566 }
567
568 /* If not suppressed, do daemon fork */
569
570 if (fork_desired)
571 {
572 {
573 pid_t pid = fork();
574
575 if (pid < 0)
576 {
577 int e = errno;
578
579 fprintf(stderr, "pluto: fork failed (%d %s)\n",
580 errno, strerror(e));
581 exit_pluto(1);
582 }
583
584 if (pid != 0)
585 {
586 /* parent: die, after filling PID into lock file.
587 * must not use exit_pluto: lock would be removed!
588 */
589 exit(fill_lock(lockfd, pid)? 0 : 1);
590 }
591 }
592
593 if (setsid() < 0)
594 {
595 int e = errno;
596
597 fprintf(stderr, "setsid() failed in main(). Errno %d: %s\n",
598 errno, strerror(e));
599 exit_pluto(1);
600 }
601 }
602 else
603 {
604 /* no daemon fork: we have to fill in lock file */
605 (void) fill_lock(lockfd, getpid());
606 fprintf(stdout, "Pluto initialized\n");
607 fflush(stdout);
608 }
609
610 /* Close everything but ctl_fd and (if needed) stderr.
611 * There is some danger that a library that we don't know
612 * about is using some fd that we don't know about.
613 * I guess we'll soon find out.
614 */
615 {
616 int i;
617
618 for (i = getdtablesize() - 1; i >= 0; i--) /* Bad hack */
619 {
620 if ((!log_to_stderr || i != 2) && i != ctl_fd)
621 close(i);
622 }
623
624 /* make sure that stdin, stdout, stderr are reserved */
625 if (open("/dev/null", O_RDONLY) != 0)
626 abort();
627 if (dup2(0, 1) != 1)
628 abort();
629 if (!log_to_stderr && dup2(0, 2) != 2)
630 abort();
631 }
632
633 init_constants();
634 init_log("pluto");
635
636 /* Note: some scripts may look for this exact message -- don't change
637 * ipsec barf was one, but it no longer does.
638 */
639 plog("Starting Pluto (strongSwan Version %s%s)"
640 , ipsec_version_code()
641 , compile_time_interop_options);
642
643 /* load plugins, further infrastructure may need it */
644 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
645 lib->settings->get_str(lib->settings, "pluto.load", PLUGINS));
646 print_plugins();
647
648 #ifdef INTEGRITY_TEST
649 DBG1("integrity test of libstrongswan code");
650 if (fips_verify_hmac_signature(hmac_key, hmac_signature))
651 {
652 DBG1(" integrity test passed");
653 }
654 else
655 {
656 DBG1(" integrity test failed");
657 abort();
658 }
659 #endif /* INTEGRITY_TEST */
660
661 init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
662 init_virtual_ip(virtual_private);
663 scx_init(pkcs11_module_path, pkcs11_init_args);
664 xauth_init();
665 init_secret();
666 init_states();
667 init_crypto();
668 init_demux();
669 init_kernel();
670 init_adns();
671 init_id();
672 init_fetch();
673
674 /* drop unneeded capabilities and change UID/GID */
675 prctl(PR_SET_KEEPCAPS, 1);
676
677 #ifdef IPSEC_GROUP
678 {
679 struct group group, *grp;
680 char buf[1024];
681
682 if (getgrnam_r(IPSEC_GROUP, &group, buf, sizeof(buf), &grp) != 0 ||
683 grp == NULL || setgid(grp->gr_gid) != 0)
684 {
685 plog("unable to change daemon group");
686 abort();
687 }
688 }
689 #endif
690 #ifdef IPSEC_USER
691 {
692 struct passwd passwd, *pwp;
693 char buf[1024];
694
695 if (getpwnam_r(IPSEC_USER, &passwd, buf, sizeof(buf), &pwp) != 0 ||
696 pwp == NULL || setuid(pwp->pw_uid) != 0)
697 {
698 plog("unable to change daemon user");
699 abort();
700 }
701 }
702 #endif
703
704 #ifdef CAPABILITIES
705 caps = cap_init();
706 cap_set_flag(caps, CAP_EFFECTIVE, 2, keep, CAP_SET);
707 cap_set_flag(caps, CAP_INHERITABLE, 2, keep, CAP_SET);
708 cap_set_flag(caps, CAP_PERMITTED, 2, keep, CAP_SET);
709 if (cap_set_proc(caps) != 0)
710 {
711 plog("unable to drop daemon capabilities");
712 abort();
713 }
714 cap_free(caps);
715 #endif /* CAPABILITIES */
716
717 /* loading X.509 CA certificates */
718 load_authcerts("CA cert", CA_CERT_PATH, AUTH_CA);
719 /* loading X.509 AA certificates */
720 load_authcerts("AA cert", AA_CERT_PATH, AUTH_AA);
721 /* loading X.509 OCSP certificates */
722 load_authcerts("OCSP cert", OCSP_CERT_PATH, AUTH_OCSP);
723 /* loading X.509 CRLs */
724 load_crls();
725 /* loading attribute certificates (experimental) */
726 load_acerts();
727
728 daily_log_event();
729 call_server();
730 return -1; /* Shouldn't ever reach this */
731 }
732
733 /* leave pluto, with status.
734 * Once child is launched, parent must not exit this way because
735 * the lock would be released.
736 *
737 * 0 OK
738 * 1 general discomfort
739 * 10 lock file exists
740 */
741 void exit_pluto(int status)
742 {
743 reset_globals(); /* needed because we may be called in odd state */
744 free_preshared_secrets();
745 free_remembered_public_keys();
746 delete_every_connection();
747 free_crl_fetch(); /* free chain of crl fetch requests */
748 free_ocsp_fetch(); /* free chain of ocsp fetch requests */
749 free_authcerts(); /* free chain of X.509 authority certificates */
750 free_crls(); /* free chain of X.509 CRLs */
751 free_acerts(); /* free chain of X.509 attribute certificates */
752 free_ca_infos(); /* free chain of X.509 CA information records */
753 free_ocsp(); /* free ocsp cache */
754 free_ifaces();
755 scx_finalize(); /* finalize and unload PKCS #11 module */
756 xauth_finalize(); /* finalize and unload XAUTH module */
757 stop_adns();
758 free_md_pool();
759 free_crypto();
760 free_id(); /* free myids */
761 free_events(); /* free remaining events */
762 free_vendorid(); /* free all vendor id records */
763 delete_lock();
764 options->destroy(options);
765 library_deinit();
766 close_log();
767 exit(status);
768 }
769
770 /*
771 * Local Variables:
772 * c-basic-offset:4
773 * c-style: pluto
774 * End:
775 */