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