f6f3ac17c903c23b5826a5472c7c6da683c927ed
[strongswan.git] / src / charon / daemon.c
1 /*
2 * Copyright (C) 2006-2009 Tobias Brunner
3 * Copyright (C) 2005-2009 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 #include <stdio.h>
20 #ifdef HAVE_PRCTL
21 #include <sys/prctl.h>
22 #endif
23 #include <signal.h>
24 #include <pthread.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <time.h>
29 #include <string.h>
30 #include <getopt.h>
31 #include <errno.h>
32 #include <pwd.h>
33 #include <grp.h>
34 #ifdef CAPABILITIES
35 #include <sys/capability.h>
36 #endif /* CAPABILITIES */
37
38 #include "daemon.h"
39
40 #include <library.h>
41 #include <utils/backtrace.h>
42 #include <config/traffic_selector.h>
43 #include <config/proposal.h>
44
45 #ifdef INTEGRITY_TEST
46 #include <fips/fips.h>
47 #include <fips/fips_signature.h>
48 #endif /* INTEGRITY_TEST */
49
50 typedef struct private_daemon_t private_daemon_t;
51
52 /**
53 * Private additions to daemon_t, contains threads and internal functions.
54 */
55 struct private_daemon_t {
56 /**
57 * Public members of daemon_t.
58 */
59 daemon_t public;
60
61 /**
62 * Signal set used for signal handling.
63 */
64 sigset_t signal_set;
65
66 #ifdef CAPABILITIES
67 /**
68 * capabilities to keep
69 */
70 cap_t caps;
71 #endif /* CAPABILITIES */
72 };
73
74 /**
75 * One and only instance of the daemon.
76 */
77 daemon_t *charon;
78
79 /**
80 * hook in library for debugging messages
81 */
82 extern void (*dbg) (int level, char *fmt, ...);
83
84 /**
85 * Logging hook for library logs, spreads debug message over bus
86 */
87 static void dbg_bus(int level, char *fmt, ...)
88 {
89 va_list args;
90
91 va_start(args, fmt);
92 charon->bus->vlog(charon->bus, DBG_LIB, level, fmt, args);
93 va_end(args);
94 }
95
96 /**
97 * Logging hook for library logs, using stderr output
98 */
99 static void dbg_stderr(int level, char *fmt, ...)
100 {
101 va_list args;
102
103 if (level <= 1)
104 {
105 va_start(args, fmt);
106 fprintf(stderr, "00[LIB] ");
107 vfprintf(stderr, fmt, args);
108 fprintf(stderr, "\n");
109 va_end(args);
110 }
111 }
112
113 /**
114 * Run the daemon and handle unix signals
115 */
116 static void run(private_daemon_t *this)
117 {
118 sigset_t set;
119
120 /* handle SIGINT, SIGHUP ans SIGTERM in this handler */
121 sigemptyset(&set);
122 sigaddset(&set, SIGINT);
123 sigaddset(&set, SIGHUP);
124 sigaddset(&set, SIGTERM);
125
126 while (TRUE)
127 {
128 int sig;
129 int error;
130
131 error = sigwait(&set, &sig);
132 if (error)
133 {
134 DBG1(DBG_DMN, "error %d while waiting for a signal", error);
135 return;
136 }
137 switch (sig)
138 {
139 case SIGHUP:
140 {
141 DBG1(DBG_DMN, "signal of type SIGHUP received. Ignored");
142 break;
143 }
144 case SIGINT:
145 {
146 DBG1(DBG_DMN, "signal of type SIGINT received. Shutting down");
147 return;
148 }
149 case SIGTERM:
150 {
151 DBG1(DBG_DMN, "signal of type SIGTERM received. Shutting down");
152 return;
153 }
154 default:
155 {
156 DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
157 break;
158 }
159 }
160 }
161 }
162
163 /**
164 * Clean up all daemon resources
165 */
166 static void destroy(private_daemon_t *this)
167 {
168 /* terminate all idle threads */
169 if (this->public.processor)
170 {
171 this->public.processor->set_threads(this->public.processor, 0);
172 }
173 /* close all IKE_SAs */
174 if (this->public.ike_sa_manager)
175 {
176 this->public.ike_sa_manager->flush(this->public.ike_sa_manager);
177 }
178 /* unload plugins to release threads */
179 lib->plugins->unload(lib->plugins);
180 #ifdef CAPABILITIES
181 cap_free(this->caps);
182 #endif /* CAPABILITIES */
183 DESTROY_IF(this->public.traps);
184 DESTROY_IF(this->public.ike_sa_manager);
185 DESTROY_IF(this->public.kernel_interface);
186 DESTROY_IF(this->public.scheduler);
187 DESTROY_IF(this->public.controller);
188 DESTROY_IF(this->public.eap);
189 DESTROY_IF(this->public.sim);
190 #ifdef ME
191 DESTROY_IF(this->public.connect_manager);
192 DESTROY_IF(this->public.mediation_manager);
193 #endif /* ME */
194 DESTROY_IF(this->public.backends);
195 DESTROY_IF(this->public.attributes);
196 DESTROY_IF(this->public.credentials);
197 DESTROY_IF(this->public.sender);
198 DESTROY_IF(this->public.receiver);
199 DESTROY_IF(this->public.socket);
200 /* wait until all threads are gone */
201 DESTROY_IF(this->public.processor);
202
203 /* rehook library logging, shutdown logging */
204 dbg = dbg_stderr;
205 DESTROY_IF(this->public.bus);
206 this->public.file_loggers->destroy_offset(this->public.file_loggers,
207 offsetof(file_logger_t, destroy));
208 this->public.sys_loggers->destroy_offset(this->public.sys_loggers,
209 offsetof(sys_logger_t, destroy));
210 free(this);
211 }
212
213 /**
214 * Enforce daemon shutdown, with a given reason to do so.
215 */
216 static void kill_daemon(private_daemon_t *this, char *reason)
217 {
218 /* we send SIGTERM, so the daemon can cleanly shut down */
219 if (this->public.bus)
220 {
221 DBG1(DBG_DMN, "killing daemon: %s", reason);
222 }
223 else
224 {
225 fprintf(stderr, "killing daemon: %s\n", reason);
226 }
227 if (this->public.main_thread_id == pthread_self())
228 {
229 /* initialization failed, terminate daemon */
230 unlink(PID_FILE);
231 exit(-1);
232 }
233 else
234 {
235 DBG1(DBG_DMN, "sending SIGTERM to ourself");
236 pthread_kill(this->public.main_thread_id, SIGTERM);
237 /* thread must die, since he produced a ciritcal failure and can't continue */
238 pthread_exit(NULL);
239 }
240 }
241
242 /**
243 * drop daemon capabilities
244 */
245 static void drop_capabilities(private_daemon_t *this)
246 {
247 #ifdef HAVE_PRCTL
248 prctl(PR_SET_KEEPCAPS, 1);
249 #endif
250
251 if (setgid(charon->gid) != 0)
252 {
253 kill_daemon(this, "change to unprivileged group failed");
254 }
255 if (setuid(charon->uid) != 0)
256 {
257 kill_daemon(this, "change to unprivileged user failed");
258 }
259
260 #ifdef CAPABILITIES
261 if (cap_set_proc(this->caps) != 0)
262 {
263 kill_daemon(this, "unable to drop daemon capabilities");
264 }
265 #endif /* CAPABILITIES */
266 }
267
268 /**
269 * Implementation of daemon_t.keep_cap
270 */
271 static void keep_cap(private_daemon_t *this, u_int cap)
272 {
273 #ifdef CAPABILITIES
274 cap_set_flag(this->caps, CAP_EFFECTIVE, 1, &cap, CAP_SET);
275 cap_set_flag(this->caps, CAP_INHERITABLE, 1, &cap, CAP_SET);
276 cap_set_flag(this->caps, CAP_PERMITTED, 1, &cap, CAP_SET);
277 #endif /* CAPABILITIES */
278 }
279
280 /**
281 * lookup UID and GID
282 */
283 static void lookup_uid_gid(private_daemon_t *this)
284 {
285 #ifdef IPSEC_USER
286 {
287 char buf[1024];
288 struct passwd passwd, *pwp;
289
290 if (getpwnam_r(IPSEC_USER, &passwd, buf, sizeof(buf), &pwp) != 0 ||
291 pwp == NULL)
292 {
293 kill_daemon(this, "resolving user '"IPSEC_USER"' failed");
294 }
295 charon->uid = pwp->pw_uid;
296 }
297 #endif
298 #ifdef IPSEC_GROUP
299 {
300 char buf[1024];
301 struct group group, *grp;
302
303 if (getgrnam_r(IPSEC_GROUP, &group, buf, sizeof(buf), &grp) != 0 ||
304 grp == NULL)
305 {
306 kill_daemon(this, "resolving group '"IPSEC_GROUP"' failed");
307 }
308 charon->gid = grp->gr_gid;
309 }
310 #endif
311 }
312
313 /**
314 * Log loaded plugins
315 */
316 static void print_plugins()
317 {
318 char buf[512], *plugin;
319 int len = 0;
320 enumerator_t *enumerator;
321
322 buf[0] = '\0';
323 enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
324 while (len < sizeof(buf) && enumerator->enumerate(enumerator, &plugin))
325 {
326 len += snprintf(&buf[len], sizeof(buf)-len, "%s ", plugin);
327 }
328 enumerator->destroy(enumerator);
329 DBG1(DBG_DMN, "loaded plugins: %s", buf);
330 }
331
332 /**
333 * Initialize logging
334 */
335 static void initialize_loggers(private_daemon_t *this, bool use_stderr,
336 level_t levels[])
337 {
338 sys_logger_t *sys_logger;
339 file_logger_t *file_logger;
340 enumerator_t *enumerator;
341 char *facility, *filename;
342 int loggers_defined = 0;
343 debug_t group;
344 level_t def;
345 bool append;
346 FILE *file;
347
348 /* setup sysloggers */
349 enumerator = lib->settings->create_section_enumerator(lib->settings,
350 "charon.syslog");
351 while (enumerator->enumerate(enumerator, &facility))
352 {
353 loggers_defined++;
354 if (streq(facility, "daemon"))
355 {
356 sys_logger = sys_logger_create(LOG_DAEMON);
357 }
358 else if (streq(facility, "auth"))
359 {
360 sys_logger = sys_logger_create(LOG_AUTHPRIV);
361 }
362 else
363 {
364 continue;
365 }
366 def = lib->settings->get_int(lib->settings,
367 "charon.syslog.%s.default", 1, facility);
368 for (group = 0; group < DBG_MAX; group++)
369 {
370 sys_logger->set_level(sys_logger, group,
371 lib->settings->get_int(lib->settings,
372 "charon.syslog.%s.%N", def,
373 facility, debug_lower_names, group));
374 }
375 this->public.sys_loggers->insert_last(this->public.sys_loggers,
376 sys_logger);
377 this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
378 }
379 enumerator->destroy(enumerator);
380
381 /* and file loggers */
382 enumerator = lib->settings->create_section_enumerator(lib->settings,
383 "charon.filelog");
384 while (enumerator->enumerate(enumerator, &filename))
385 {
386 loggers_defined++;
387 if (streq(filename, "stderr"))
388 {
389 file = stderr;
390 }
391 else if (streq(filename, "stdout"))
392 {
393 file = stdout;
394 }
395 else
396 {
397 append = lib->settings->get_bool(lib->settings,
398 "charon.filelog.%s.append", TRUE, filename);
399 file = fopen(filename, append ? "a" : "w");
400 if (file == NULL)
401 {
402 DBG1(DBG_DMN, "opening file %s for logging failed: %s",
403 filename, strerror(errno));
404 continue;
405 }
406 }
407 file_logger = file_logger_create(file);
408 def = lib->settings->get_int(lib->settings,
409 "charon.filelog.%s.default", 1, filename);
410 for (group = 0; group < DBG_MAX; group++)
411 {
412 file_logger->set_level(file_logger, group,
413 lib->settings->get_int(lib->settings,
414 "charon.filelog.%s.%N", def,
415 filename, debug_lower_names, group));
416 }
417 this->public.file_loggers->insert_last(this->public.file_loggers,
418 file_logger);
419 this->public.bus->add_listener(this->public.bus, &file_logger->listener);
420
421 }
422 enumerator->destroy(enumerator);
423
424 /* set up legacy style default loggers provided via command-line */
425 if (!loggers_defined)
426 {
427 /* set up default stdout file_logger */
428 file_logger = file_logger_create(stdout);
429 this->public.bus->add_listener(this->public.bus, &file_logger->listener);
430 this->public.file_loggers->insert_last(this->public.file_loggers,
431 file_logger);
432 /* set up default daemon sys_logger */
433 sys_logger = sys_logger_create(LOG_DAEMON);
434 this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
435 this->public.sys_loggers->insert_last(this->public.sys_loggers,
436 sys_logger);
437 for (group = 0; group < DBG_MAX; group++)
438 {
439 sys_logger->set_level(sys_logger, group, levels[group]);
440 if (use_stderr)
441 {
442 file_logger->set_level(file_logger, group, levels[group]);
443 }
444 }
445
446 /* set up default auth sys_logger */
447 sys_logger = sys_logger_create(LOG_AUTHPRIV);
448 this->public.bus->add_listener(this->public.bus, &sys_logger->listener);
449 this->public.sys_loggers->insert_last(this->public.sys_loggers,
450 sys_logger);
451 sys_logger->set_level(sys_logger, DBG_ANY, LEVEL_AUDIT);
452 }
453 }
454
455 /**
456 * Initialize the daemon
457 */
458 static bool initialize(private_daemon_t *this, bool syslog, level_t levels[])
459 {
460 /* for uncritical pseudo random numbers */
461 srandom(time(NULL) + getpid());
462
463 /* setup bus and it's listeners first to enable log output */
464 this->public.bus = bus_create();
465 /* set up hook to log dbg message in library via charons message bus */
466 dbg = dbg_bus;
467
468 initialize_loggers(this, !syslog, levels);
469
470 DBG1(DBG_DMN, "Starting IKEv2 charon daemon (strongSwan "VERSION")");
471
472 /* load secrets, ca certificates and crls */
473 this->public.processor = processor_create();
474 this->public.scheduler = scheduler_create();
475 this->public.credentials = credential_manager_create();
476 this->public.controller = controller_create();
477 this->public.eap = eap_manager_create();
478 this->public.sim = sim_manager_create();
479 this->public.backends = backend_manager_create();
480 this->public.attributes = attribute_manager_create();
481 this->public.kernel_interface = kernel_interface_create();
482 this->public.socket = socket_create();
483 this->public.traps = trap_manager_create();
484
485 /* load plugins, further infrastructure may need it */
486 lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
487 lib->settings->get_str(lib->settings, "charon.load", PLUGINS));
488
489 print_plugins();
490
491 #ifdef INTEGRITY_TEST
492 DBG1(DBG_DMN, "integrity test of libstrongswan code");
493 if (fips_verify_hmac_signature(hmac_key, hmac_signature))
494 {
495 DBG1(DBG_DMN, " integrity test passed");
496 }
497 else
498 {
499 DBG1(DBG_DMN, " integrity test failed");
500 return FALSE;
501 }
502 #endif /* INTEGRITY_TEST */
503
504 this->public.ike_sa_manager = ike_sa_manager_create();
505 if (this->public.ike_sa_manager == NULL)
506 {
507 return FALSE;
508 }
509 this->public.sender = sender_create();
510 this->public.receiver = receiver_create();
511 if (this->public.receiver == NULL)
512 {
513 return FALSE;
514 }
515
516 #ifdef ME
517 this->public.connect_manager = connect_manager_create();
518 if (this->public.connect_manager == NULL)
519 {
520 return FALSE;
521 }
522 this->public.mediation_manager = mediation_manager_create();
523 #endif /* ME */
524
525 return TRUE;
526 }
527
528 /**
529 * Handle SIGSEGV/SIGILL signals raised by threads
530 */
531 static void segv_handler(int signal)
532 {
533 backtrace_t *backtrace;
534
535 DBG1(DBG_DMN, "thread %u received %d", pthread_self(), signal);
536 backtrace = backtrace_create(2);
537 backtrace->log(backtrace, stderr);
538 backtrace->destroy(backtrace);
539
540 DBG1(DBG_DMN, "killing ourself, received critical signal");
541 raise(SIGKILL);
542 }
543
544 /**
545 * Create the daemon.
546 */
547 private_daemon_t *daemon_create(void)
548 {
549 struct sigaction action;
550 private_daemon_t *this = malloc_thing(private_daemon_t);
551
552 /* assign methods */
553 this->public.kill = (void (*) (daemon_t*,char*))kill_daemon;
554 this->public.keep_cap = (void(*)(daemon_t*, u_int cap))keep_cap;
555
556 /* NULL members for clean destruction */
557 this->public.socket = NULL;
558 this->public.ike_sa_manager = NULL;
559 this->public.traps = NULL;
560 this->public.credentials = NULL;
561 this->public.backends = NULL;
562 this->public.attributes = NULL;
563 this->public.sender= NULL;
564 this->public.receiver = NULL;
565 this->public.scheduler = NULL;
566 this->public.kernel_interface = NULL;
567 this->public.processor = NULL;
568 this->public.controller = NULL;
569 this->public.eap = NULL;
570 this->public.sim = NULL;
571 this->public.bus = NULL;
572 this->public.file_loggers = linked_list_create();
573 this->public.sys_loggers = linked_list_create();
574 #ifdef ME
575 this->public.connect_manager = NULL;
576 this->public.mediation_manager = NULL;
577 #endif /* ME */
578 this->public.uid = 0;
579 this->public.gid = 0;
580
581 this->public.main_thread_id = pthread_self();
582 #ifdef CAPABILITIES
583 this->caps = cap_init();
584 keep_cap(this, CAP_NET_ADMIN);
585 if (lib->leak_detective)
586 {
587 keep_cap(this, CAP_SYS_NICE);
588 }
589 #endif /* CAPABILITIES */
590
591 /* add handler for SEGV and ILL,
592 * add handler for USR1 (cancellation).
593 * INT, TERM and HUP are handled by sigwait() in run() */
594 action.sa_handler = segv_handler;
595 action.sa_flags = 0;
596 sigemptyset(&action.sa_mask);
597 sigaddset(&action.sa_mask, SIGINT);
598 sigaddset(&action.sa_mask, SIGTERM);
599 sigaddset(&action.sa_mask, SIGHUP);
600 sigaction(SIGSEGV, &action, NULL);
601 sigaction(SIGILL, &action, NULL);
602 sigaction(SIGBUS, &action, NULL);
603 action.sa_handler = SIG_IGN;
604 sigaction(SIGPIPE, &action, NULL);
605
606 pthread_sigmask(SIG_SETMASK, &action.sa_mask, 0);
607
608 return this;
609 }
610
611 /**
612 * Check/create PID file, return TRUE if already running
613 */
614 static bool check_pidfile()
615 {
616 struct stat stb;
617 FILE *file;
618
619 if (stat(PID_FILE, &stb) == 0)
620 {
621 file = fopen(PID_FILE, "r");
622 if (file)
623 {
624 char buf[64];
625 pid_t pid = 0;
626
627 memset(buf, 0, sizeof(buf));
628 if (fread(buf, 1, sizeof(buf), file))
629 {
630 pid = atoi(buf);
631 }
632 fclose(file);
633 if (pid && kill(pid, 0) == 0)
634 { /* such a process is running */
635 return TRUE;
636 }
637 }
638 DBG1(DBG_DMN, "removing pidfile '"PID_FILE"', process not running");
639 unlink(PID_FILE);
640 }
641
642 /* create new pidfile */
643 file = fopen(PID_FILE, "w");
644 if (file)
645 {
646 fprintf(file, "%d\n", getpid());
647 ignore_result(fchown(fileno(file), charon->uid, charon->gid));
648 fclose(file);
649 }
650 return FALSE;
651 }
652
653 /**
654 * print command line usage and exit
655 */
656 static void usage(const char *msg)
657 {
658 if (msg != NULL && *msg != '\0')
659 {
660 fprintf(stderr, "%s\n", msg);
661 }
662 fprintf(stderr, "Usage: charon\n"
663 " [--help]\n"
664 " [--version]\n"
665 " [--use-syslog]\n"
666 " [--debug-<type> <level>]\n"
667 " <type>: log context type (dmn|mgr|ike|chd|job|cfg|knl|net|enc|lib)\n"
668 " <level>: log verbosity (-1 = silent, 0 = audit, 1 = control,\n"
669 " 2 = controlmore, 3 = raw, 4 = private)\n"
670 "\n"
671 );
672 exit(msg == NULL? 0 : 1);
673 }
674
675 /**
676 * Main function, manages the daemon.
677 */
678 int main(int argc, char *argv[])
679 {
680 bool use_syslog = FALSE;
681 private_daemon_t *private_charon;
682 level_t levels[DBG_MAX];
683 int group;
684
685 /* logging for library during initialization, as we have no bus yet */
686 dbg = dbg_stderr;
687
688 /* initialize library */
689 if (!library_init(STRONGSWAN_CONF))
690 {
691 exit(-1);
692 }
693 lib->printf_hook->add_handler(lib->printf_hook, 'R',
694 traffic_selector_printf_hook,
695 PRINTF_HOOK_ARGTYPE_POINTER,
696 PRINTF_HOOK_ARGTYPE_END);
697 lib->printf_hook->add_handler(lib->printf_hook, 'P',
698 proposal_printf_hook,
699 PRINTF_HOOK_ARGTYPE_POINTER,
700 PRINTF_HOOK_ARGTYPE_END);
701 private_charon = daemon_create();
702 charon = (daemon_t*)private_charon;
703
704 lookup_uid_gid(private_charon);
705
706 /* use CTRL loglevel for default */
707 for (group = 0; group < DBG_MAX; group++)
708 {
709 levels[group] = LEVEL_CTRL;
710 }
711
712 /* handle arguments */
713 for (;;)
714 {
715 struct option long_opts[] = {
716 { "help", no_argument, NULL, 'h' },
717 { "version", no_argument, NULL, 'v' },
718 { "use-syslog", no_argument, NULL, 'l' },
719 /* TODO: handle "debug-all" */
720 { "debug-dmn", required_argument, &group, DBG_DMN },
721 { "debug-mgr", required_argument, &group, DBG_MGR },
722 { "debug-ike", required_argument, &group, DBG_IKE },
723 { "debug-chd", required_argument, &group, DBG_CHD },
724 { "debug-job", required_argument, &group, DBG_JOB },
725 { "debug-cfg", required_argument, &group, DBG_CFG },
726 { "debug-knl", required_argument, &group, DBG_KNL },
727 { "debug-net", required_argument, &group, DBG_NET },
728 { "debug-enc", required_argument, &group, DBG_ENC },
729 { "debug-lib", required_argument, &group, DBG_LIB },
730 { 0,0,0,0 }
731 };
732
733 int c = getopt_long(argc, argv, "", long_opts, NULL);
734 switch (c)
735 {
736 case EOF:
737 break;
738 case 'h':
739 usage(NULL);
740 break;
741 case 'v':
742 printf("Linux strongSwan %s\n", VERSION);
743 exit(0);
744 case 'l':
745 use_syslog = TRUE;
746 continue;
747 case 0:
748 /* option is in group */
749 levels[group] = atoi(optarg);
750 continue;
751 default:
752 usage("");
753 break;
754 }
755 break;
756 }
757
758 /* initialize daemon */
759 if (!initialize(private_charon, use_syslog, levels))
760 {
761 DBG1(DBG_DMN, "initialization failed - aborting charon");
762 destroy(private_charon);
763 exit(-1);
764 }
765
766 if (check_pidfile())
767 {
768 DBG1(DBG_DMN, "charon already running (\""PID_FILE"\" exists)");
769 destroy(private_charon);
770 exit(-1);
771 }
772
773 /* drop the capabilities we won't need */
774 drop_capabilities(private_charon);
775
776 /* start the engine, go multithreaded */
777 charon->processor->set_threads(charon->processor,
778 lib->settings->get_int(lib->settings, "charon.threads",
779 DEFAULT_THREADS));
780
781 /* run daemon */
782 run(private_charon);
783
784 /* normal termination, cleanup and exit */
785 destroy(private_charon);
786 unlink(PID_FILE);
787
788 library_deinit();
789
790 return 0;
791 }
792