2 * Copyright (C) 2006-2017 Tobias Brunner
3 * Copyright (C) 2005-2009 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Copyright (C) 2005 Jan Hutter
6 * HSR Hochschule fuer Technik Rapperswil
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>.
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
20 * Copyright (C) 2016 secunet Security Networks AG
21 * Copyright (C) 2016 Thomas Egerer
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43 #include <sys/types.h>
55 #include <bus/listeners/sys_logger.h>
56 #include <bus/listeners/file_logger.h>
57 #include <collections/array.h>
58 #include <plugins/plugin_feature.h>
59 #include <kernel/kernel_handler.h>
60 #include <processing/jobs/start_action_job.h>
61 #include <threading/mutex.h>
63 #ifndef LOG_AUTHPRIV /* not defined on OpenSolaris */
64 #define LOG_AUTHPRIV LOG_AUTH
67 typedef struct private_daemon_t private_daemon_t
;
70 * Private additions to daemon_t, contains threads and internal functions.
72 struct private_daemon_t
{
74 * Public members of daemon_t.
79 * Handler for kernel events
81 kernel_handler_t
*kernel_handler
;
84 * A list of installed loggers (as logger_entry_t*)
86 linked_list_t
*loggers
;
89 * Cached log levels for default loggers
94 * Whether to log to stdout/err by default
99 * Identifier used for syslog (in the openlog call)
101 char *syslog_identifier
;
104 * Mutex for configured loggers
109 * Integrity check failed?
111 bool integrity_failed
;
114 * Number of times we have been initialized
120 * Register plugins if built statically
122 #ifdef STATIC_PLUGIN_CONSTRUCTORS
123 #include "plugin_constructors.c"
127 * One and only instance of the daemon.
132 * hook in library for debugging messages
134 extern void (*dbg
) (debug_t group
, level_t level
, char *fmt
, ...);
137 * we store the previous debug function so we can reset it
139 static void (*dbg_old
) (debug_t group
, level_t level
, char *fmt
, ...);
142 * Logging hook for library logs, spreads debug message over bus
144 static void dbg_bus(debug_t group
, level_t level
, char *fmt
, ...)
149 charon
->bus
->vlog(charon
->bus
, group
, level
, fmt
, args
);
154 * Data for registered custom loggers
158 * Name of the custom logger (also used for loglevel configuration)
163 * Constructor to be called for custom logger creation
165 custom_logger_constructor_t constructor
;
167 } custom_logger_entry_t
;
169 #define MAX_CUSTOM_LOGGERS 10
172 * Static array for logger registration using __attribute__((constructor))
174 static custom_logger_entry_t custom_loggers
[MAX_CUSTOM_LOGGERS
];
175 static int custom_logger_count
;
178 * Described in header
180 void register_custom_logger(char *name
,
181 custom_logger_constructor_t constructor
)
183 if (custom_logger_count
< MAX_CUSTOM_LOGGERS
- 1)
185 custom_loggers
[custom_logger_count
].name
= name
;
186 custom_loggers
[custom_logger_count
].constructor
= constructor
;
187 custom_logger_count
++;
191 fprintf(stderr
, "failed to register custom logger, please increase "
192 "MAX_CUSTOM_LOGGERS");
197 * Types of supported loggers
201 * Syslog logger instance
206 * File logger instance
211 * Custom logger instance
218 * Some metadata about configured loggers
222 * Target of the logger (syslog facility or filename)
237 custom_logger_t
*custom
;
243 * Destroy a logger entry
245 static void logger_entry_destroy(logger_entry_t
*this)
250 DESTROY_IF(this->logger
.file
);
253 DESTROY_IF(this->logger
.sys
);
256 DESTROY_IF(this->logger
.custom
);
264 * Unregister and destroy a logger entry
266 static void logger_entry_unregister_destroy(logger_entry_t
*this)
271 charon
->bus
->remove_logger(charon
->bus
, &this->logger
.file
->logger
);
274 charon
->bus
->remove_logger(charon
->bus
, &this->logger
.sys
->logger
);
277 charon
->bus
->remove_logger(charon
->bus
,
278 &this->logger
.custom
->logger
);
281 logger_entry_destroy(this);
284 CALLBACK(logger_entry_match
, bool,
285 logger_entry_t
*this, va_list args
)
290 VA_ARGS_VGET(args
, target
, type
);
291 return this->type
== type
&& streq(this->target
, target
);
295 * Handle configured syslog identifier
297 * mutex must be locked when calling this function
299 static void handle_syslog_identifier(private_daemon_t
*this)
304 identifier
= lib
->settings
->get_str(lib
->settings
, "%s.syslog.identifier",
307 { /* set identifier, which is prepended to each log line */
308 if (!this->syslog_identifier
||
309 !streq(identifier
, this->syslog_identifier
))
312 this->syslog_identifier
= identifier
;
313 openlog(this->syslog_identifier
, 0, 0);
316 else if (this->syslog_identifier
)
319 this->syslog_identifier
= NULL
;
321 #endif /* HAVE_SYSLOG */
325 * Convert the given string into a syslog facility, returns -1 if the facility
328 static int get_syslog_facility(char *facility
)
331 if (streq(facility
, "daemon"))
335 else if (streq(facility
, "auth"))
339 #endif /* HAVE_SYSLOG */
344 * Returns an existing or newly created logger entry (if found, it is removed
345 * from the given linked list of existing loggers)
347 static logger_entry_t
*get_logger_entry(char *target
, logger_type_t type
,
348 linked_list_t
*existing
,
349 custom_logger_constructor_t constructor
)
351 logger_entry_t
*entry
;
353 if (!existing
->find_first(existing
, logger_entry_match
, (void**)&entry
,
357 .target
= strdup(target
),
363 entry
->logger
.file
= file_logger_create(target
);
367 entry
->logger
.sys
= sys_logger_create(
368 get_syslog_facility(target
));
373 #endif /* HAVE_SYSLOG */
377 entry
->logger
.custom
= constructor(target
);
379 if (!entry
->logger
.custom
)
389 existing
->remove(existing
, entry
, NULL
);
395 * Create or reuse a syslog logger
397 static sys_logger_t
*add_sys_logger(private_daemon_t
*this, char *facility
,
398 linked_list_t
*current_loggers
)
400 logger_entry_t
*entry
;
402 entry
= get_logger_entry(facility
, SYS_LOGGER
, current_loggers
, NULL
);
405 this->loggers
->insert_last(this->loggers
, entry
);
407 return entry ? entry
->logger
.sys
: NULL
;
411 * Create or reuse a file logger
413 static file_logger_t
*add_file_logger(private_daemon_t
*this, char *filename
,
414 linked_list_t
*current_loggers
)
416 logger_entry_t
*entry
;
418 entry
= get_logger_entry(filename
, FILE_LOGGER
, current_loggers
, NULL
);
421 this->loggers
->insert_last(this->loggers
, entry
);
423 return entry ? entry
->logger
.file
: NULL
;
427 * Create or reuse a custom logger
429 static custom_logger_t
*add_custom_logger(private_daemon_t
*this,
430 custom_logger_entry_t
*custom
,
431 linked_list_t
*current_loggers
)
433 logger_entry_t
*entry
;
435 entry
= get_logger_entry(custom
->name
, CUSTOM_LOGGER
, current_loggers
,
436 custom
->constructor
);
439 this->loggers
->insert_last(this->loggers
, entry
);
441 return entry ? entry
->logger
.custom
: NULL
;
445 * Load the given syslog logger configured in strongswan.conf
447 static void load_sys_logger(private_daemon_t
*this, char *facility
,
448 linked_list_t
*current_loggers
)
450 sys_logger_t
*sys_logger
;
453 bool ike_name
, log_level
;
456 if (get_syslog_facility(facility
) == -1)
461 sys_logger
= add_sys_logger(this, facility
, current_loggers
);
467 ike_name
= lib
->settings
->get_bool(lib
->settings
, "%s.syslog.%s.ike_name",
468 FALSE
, lib
->ns
, facility
);
469 log_level
= lib
->settings
->get_bool(lib
->settings
, "%s.syslog.%s.log_level",
470 FALSE
, lib
->ns
, facility
);
471 map_level
= lib
->settings
->get_int(lib
->settings
, "%s.syslog.%s.map_level",
472 -1, lib
->ns
, facility
);
474 sys_logger
->set_options(sys_logger
, ike_name
, log_level
, map_level
);
476 def
= lib
->settings
->get_int(lib
->settings
, "%s.syslog.%s.default", 1,
478 for (group
= 0; group
< DBG_MAX
; group
++)
480 sys_logger
->set_level(sys_logger
, group
,
481 lib
->settings
->get_int(lib
->settings
, "%s.syslog.%s.%N", def
,
482 lib
->ns
, facility
, debug_lower_names
, group
));
484 charon
->bus
->add_logger(charon
->bus
, &sys_logger
->logger
);
488 * Load the given file logger configured in strongswan.conf
490 static void load_file_logger(private_daemon_t
*this, char *section
,
491 linked_list_t
*current_loggers
)
493 file_logger_t
*file_logger
;
496 bool add_ms
, ike_name
, log_level
, flush_line
, append
;
497 char *time_format
, *filename
;
499 time_format
= lib
->settings
->get_str(lib
->settings
,
500 "%s.filelog.%s.time_format", NULL
, lib
->ns
, section
);
501 add_ms
= lib
->settings
->get_bool(lib
->settings
,
502 "%s.filelog.%s.time_add_ms", FALSE
, lib
->ns
, section
);
503 ike_name
= lib
->settings
->get_bool(lib
->settings
,
504 "%s.filelog.%s.ike_name", FALSE
, lib
->ns
, section
);
505 log_level
= lib
->settings
->get_bool(lib
->settings
,
506 "%s.filelog.%s.log_level", FALSE
, lib
->ns
, section
);
507 flush_line
= lib
->settings
->get_bool(lib
->settings
,
508 "%s.filelog.%s.flush_line", FALSE
, lib
->ns
, section
);
509 append
= lib
->settings
->get_bool(lib
->settings
,
510 "%s.filelog.%s.append", TRUE
, lib
->ns
, section
);
511 filename
= lib
->settings
->get_str(lib
->settings
,
512 "%s.filelog.%s.path", section
, lib
->ns
, section
);
514 file_logger
= add_file_logger(this, filename
, current_loggers
);
520 file_logger
->set_options(file_logger
, time_format
, add_ms
, ike_name
,
522 file_logger
->open(file_logger
, flush_line
, append
);
524 def
= lib
->settings
->get_int(lib
->settings
, "%s.filelog.%s.default", 1,
526 for (group
= 0; group
< DBG_MAX
; group
++)
528 file_logger
->set_level(file_logger
, group
,
529 lib
->settings
->get_int(lib
->settings
, "%s.filelog.%s.%N", def
,
530 lib
->ns
, section
, debug_lower_names
, group
));
532 charon
->bus
->add_logger(charon
->bus
, &file_logger
->logger
);
536 * Load the given custom logger configured in strongswan.conf
538 static void load_custom_logger(private_daemon_t
*this,
539 custom_logger_entry_t
*entry
,
540 linked_list_t
*current_loggers
)
542 custom_logger_t
*custom_logger
;
546 custom_logger
= add_custom_logger(this, entry
, current_loggers
);
552 def
= lib
->settings
->get_int(lib
->settings
, "%s.customlog.%s.default", 1,
553 lib
->ns
, entry
->name
);
554 for (group
= 0; group
< DBG_MAX
; group
++)
556 custom_logger
->set_level(custom_logger
, group
,
557 lib
->settings
->get_int(lib
->settings
, "%s.customlog.%s.%N", def
,
558 lib
->ns
, entry
->name
, debug_lower_names
, group
));
560 if (custom_logger
->reload
)
562 custom_logger
->reload(custom_logger
);
564 charon
->bus
->add_logger(charon
->bus
, &custom_logger
->logger
);
567 METHOD(daemon_t
, load_loggers
, void,
568 private_daemon_t
*this)
570 enumerator_t
*enumerator
;
571 linked_list_t
*current_loggers
;
575 this->mutex
->lock(this->mutex
);
576 handle_syslog_identifier(this);
577 current_loggers
= this->loggers
;
578 this->loggers
= linked_list_create();
579 enumerator
= lib
->settings
->create_section_enumerator(lib
->settings
,
580 "%s.syslog", lib
->ns
);
581 while (enumerator
->enumerate(enumerator
, &target
))
583 load_sys_logger(this, target
, current_loggers
);
585 enumerator
->destroy(enumerator
);
587 enumerator
= lib
->settings
->create_section_enumerator(lib
->settings
,
588 "%s.filelog", lib
->ns
);
589 while (enumerator
->enumerate(enumerator
, &target
))
591 load_file_logger(this, target
, current_loggers
);
593 enumerator
->destroy(enumerator
);
595 for (i
= 0; i
< custom_logger_count
; ++i
)
597 load_custom_logger(this, &custom_loggers
[i
], current_loggers
);
600 if (!this->loggers
->get_count(this->loggers
) && this->levels
)
601 { /* setup legacy style default loggers configured via command-line */
602 file_logger_t
*file_logger
;
603 sys_logger_t
*sys_logger
;
606 sys_logger
= add_sys_logger(this, "daemon", current_loggers
);
607 file_logger
= add_file_logger(this, "stdout", current_loggers
);
608 file_logger
->open(file_logger
, FALSE
, FALSE
);
610 for (group
= 0; group
< DBG_MAX
; group
++)
614 sys_logger
->set_level(sys_logger
, group
, this->levels
[group
]);
618 file_logger
->set_level(file_logger
, group
, this->levels
[group
]);
623 charon
->bus
->add_logger(charon
->bus
, &sys_logger
->logger
);
625 charon
->bus
->add_logger(charon
->bus
, &file_logger
->logger
);
627 sys_logger
= add_sys_logger(this, "auth", current_loggers
);
630 sys_logger
->set_level(sys_logger
, DBG_ANY
, LEVEL_AUDIT
);
631 charon
->bus
->add_logger(charon
->bus
, &sys_logger
->logger
);
634 /* unregister and destroy any unused remaining loggers */
635 current_loggers
->destroy_function(current_loggers
,
636 (void*)logger_entry_unregister_destroy
);
637 this->mutex
->unlock(this->mutex
);
640 METHOD(daemon_t
, set_default_loggers
, void,
641 private_daemon_t
*this, level_t levels
[DBG_MAX
], bool to_stderr
)
645 this->mutex
->lock(this->mutex
);
655 this->levels
= calloc(sizeof(level_t
), DBG_MAX
);
657 for (group
= 0; group
< DBG_MAX
; group
++)
659 this->levels
[group
] = levels
[group
];
661 this->to_stderr
= to_stderr
;
663 this->mutex
->unlock(this->mutex
);
666 METHOD(daemon_t
, set_level
, void,
667 private_daemon_t
*this, debug_t group
, level_t level
)
669 enumerator_t
*enumerator
;
670 logger_entry_t
*entry
;
672 /* we set the loglevel on ALL loggers */
673 this->mutex
->lock(this->mutex
);
674 enumerator
= this->loggers
->create_enumerator(this->loggers
);
675 while (enumerator
->enumerate(enumerator
, &entry
))
680 entry
->logger
.file
->set_level(entry
->logger
.file
, group
, level
);
681 charon
->bus
->add_logger(charon
->bus
,
682 &entry
->logger
.file
->logger
);
685 entry
->logger
.sys
->set_level(entry
->logger
.sys
, group
, level
);
686 charon
->bus
->add_logger(charon
->bus
,
687 &entry
->logger
.sys
->logger
);
690 entry
->logger
.custom
->set_level(entry
->logger
.custom
, group
,
692 charon
->bus
->add_logger(charon
->bus
,
693 &entry
->logger
.custom
->logger
);
697 enumerator
->destroy(enumerator
);
698 this->mutex
->unlock(this->mutex
);
702 * Clean up all daemon resources
704 static void destroy(private_daemon_t
*this)
706 /* terminate all idle threads */
707 lib
->processor
->set_threads(lib
->processor
, 0);
708 /* make sure nobody waits for a DNS query */
709 lib
->hosts
->flush(lib
->hosts
);
710 /* close all IKE_SAs */
711 if (this->public.ike_sa_manager
)
713 this->public.ike_sa_manager
->flush(this->public.ike_sa_manager
);
715 if (this->public.traps
)
717 this->public.traps
->flush(this->public.traps
);
719 if (this->public.shunts
)
721 this->public.shunts
->flush(this->public.shunts
);
723 if (this->public.sender
)
725 this->public.sender
->flush(this->public.sender
);
728 /* cancel all threads and wait for their termination */
729 lib
->processor
->cancel(lib
->processor
);
732 DESTROY_IF(this->public.connect_manager
);
733 DESTROY_IF(this->public.mediation_manager
);
735 /* make sure the cache and scheduler are clear before unloading plugins */
736 lib
->credmgr
->flush_cache(lib
->credmgr
, CERT_ANY
);
737 lib
->scheduler
->flush(lib
->scheduler
);
738 lib
->plugins
->unload(lib
->plugins
);
739 DESTROY_IF(this->public.attributes
);
740 DESTROY_IF(this->kernel_handler
);
741 DESTROY_IF(this->public.traps
);
742 DESTROY_IF(this->public.shunts
);
743 DESTROY_IF(this->public.redirect
);
744 DESTROY_IF(this->public.controller
);
745 DESTROY_IF(this->public.eap
);
746 DESTROY_IF(this->public.xauth
);
747 DESTROY_IF(this->public.backends
);
748 DESTROY_IF(this->public.socket
);
749 DESTROY_IF(this->public.kernel
);
751 /* rehook library logging, shutdown logging */
753 DESTROY_IF(this->public.bus
);
754 this->loggers
->destroy_function(this->loggers
, (void*)logger_entry_destroy
);
755 this->mutex
->destroy(this->mutex
);
761 * Run a set of configured scripts
763 static void run_scripts(private_daemon_t
*this, char *verb
)
769 array_t
*scripts
= NULL
;
770 enumerator_t
*enumerator
;
771 char *key
, *value
, *pos
, buf
[1024];
774 /* copy the scripts so we don't hold any locks while executing them */
775 enumerator
= lib
->settings
->create_key_value_enumerator(lib
->settings
,
776 "%s.%s-scripts", lib
->ns
, verb
);
777 while (enumerator
->enumerate(enumerator
, &key
, &value
))
783 array_insert_create(&scripts
, ARRAY_TAIL
, script
);
785 enumerator
->destroy(enumerator
);
787 enumerator
= array_create_enumerator(scripts
);
788 while (enumerator
->enumerate(enumerator
, &script
))
790 DBG1(DBG_DMN
, "executing %s script '%s' (%s)", verb
, script
->name
,
792 cmd
= popen(script
->path
, "r");
795 DBG1(DBG_DMN
, "executing %s script '%s' (%s) failed: %s",
796 verb
, script
->name
, script
->path
, strerror(errno
));
802 if (!fgets(buf
, sizeof(buf
), cmd
))
806 DBG1(DBG_DMN
, "reading from %s script '%s' (%s) failed",
807 verb
, script
->name
, script
->path
);
813 pos
= buf
+ strlen(buf
);
814 if (pos
> buf
&& pos
[-1] == '\n')
818 DBG1(DBG_DMN
, "%s: %s", script
->name
, buf
);
825 enumerator
->destroy(enumerator
);
826 array_destroy(scripts
);
829 METHOD(daemon_t
, start
, void,
830 private_daemon_t
*this)
832 /* start the engine, go multithreaded */
833 lib
->processor
->set_threads(lib
->processor
,
834 lib
->settings
->get_int(lib
->settings
, "%s.threads",
835 DEFAULT_THREADS
, lib
->ns
));
837 run_scripts(this, "start");
841 * Initialize/deinitialize sender and receiver
843 static bool sender_receiver_cb(void *plugin
, plugin_feature_t
*feature
,
844 bool reg
, private_daemon_t
*this)
848 this->public.receiver
= receiver_create();
849 if (!this->public.receiver
)
853 this->public.sender
= sender_create();
857 DESTROY_IF(this->public.receiver
);
858 DESTROY_IF(this->public.sender
);
864 * Initialize/deinitialize IKE_SA/CHILD_SA managers
866 static bool sa_managers_cb(void *plugin
, plugin_feature_t
*feature
,
867 bool reg
, private_daemon_t
*this)
871 this->public.ike_sa_manager
= ike_sa_manager_create();
872 if (!this->public.ike_sa_manager
)
876 this->public.child_sa_manager
= child_sa_manager_create();
880 DESTROY_IF(this->public.ike_sa_manager
);
881 DESTROY_IF(this->public.child_sa_manager
);
886 METHOD(daemon_t
, initialize
, bool,
887 private_daemon_t
*this, char *plugins
)
889 plugin_feature_t features
[] = {
890 PLUGIN_PROVIDE(CUSTOM
, "libcharon"),
891 PLUGIN_DEPENDS(NONCE_GEN
),
892 PLUGIN_DEPENDS(CUSTOM
, "libcharon-sa-managers"),
893 PLUGIN_DEPENDS(CUSTOM
, "libcharon-receiver"),
894 PLUGIN_DEPENDS(CUSTOM
, "kernel-ipsec"),
895 PLUGIN_DEPENDS(CUSTOM
, "kernel-net"),
896 PLUGIN_CALLBACK((plugin_feature_callback_t
)sender_receiver_cb
, this),
897 PLUGIN_PROVIDE(CUSTOM
, "libcharon-receiver"),
898 PLUGIN_DEPENDS(HASHER
, HASH_SHA1
),
899 PLUGIN_DEPENDS(RNG
, RNG_STRONG
),
900 PLUGIN_DEPENDS(CUSTOM
, "socket"),
901 PLUGIN_CALLBACK((plugin_feature_callback_t
)sa_managers_cb
, this),
902 PLUGIN_PROVIDE(CUSTOM
, "libcharon-sa-managers"),
903 PLUGIN_DEPENDS(HASHER
, HASH_SHA1
),
904 PLUGIN_DEPENDS(RNG
, RNG_WEAK
),
906 lib
->plugins
->add_static_features(lib
->plugins
, lib
->ns
, features
,
907 countof(features
), TRUE
, NULL
, NULL
);
909 /* load plugins, further infrastructure may need it */
910 if (!lib
->plugins
->load(lib
->plugins
, plugins
))
915 /* Queue start_action job */
916 lib
->processor
->queue_job(lib
->processor
, (job_t
*)start_action_job_create());
919 this->public.connect_manager
= connect_manager_create();
920 if (this->public.connect_manager
== NULL
)
924 this->public.mediation_manager
= mediation_manager_create();
933 private_daemon_t
*daemon_create()
935 private_daemon_t
*this;
939 .initialize
= _initialize
,
941 .load_loggers
= _load_loggers
,
942 .set_default_loggers
= _set_default_loggers
,
943 .set_level
= _set_level
,
946 .loggers
= linked_list_create(),
947 .mutex
= mutex_create(MUTEX_TYPE_DEFAULT
),
950 charon
= &this->public;
951 this->public.kernel
= kernel_interface_create();
952 this->public.attributes
= attribute_manager_create();
953 this->public.controller
= controller_create();
954 this->public.eap
= eap_manager_create();
955 this->public.xauth
= xauth_manager_create();
956 this->public.backends
= backend_manager_create();
957 this->public.socket
= socket_manager_create();
958 this->public.traps
= trap_manager_create();
959 this->public.shunts
= shunt_manager_create();
960 this->public.redirect
= redirect_manager_create();
961 this->kernel_handler
= kernel_handler_create();
967 * Described in header.
969 void libcharon_deinit()
971 private_daemon_t
*this = (private_daemon_t
*)charon
;
973 if (!this || !ref_put(&this->ref
))
974 { /* have more users */
978 run_scripts(this, "stop");
985 * Described in header.
987 bool libcharon_init()
989 private_daemon_t
*this;
992 { /* already initialized, increase refcount */
993 this = (private_daemon_t
*)charon
;
995 return !this->integrity_failed
;
998 this = daemon_create();
1000 /* for uncritical pseudo random numbers */
1001 srandom(time(NULL
) + getpid());
1003 /* set up hook to log dbg message in library via charons message bus */
1007 if (lib
->integrity
&&
1008 !lib
->integrity
->check(lib
->integrity
, "libcharon", libcharon_init
))
1010 dbg(DBG_DMN
, 1, "integrity check of libcharon failed");
1011 this->integrity_failed
= TRUE
;
1013 return !this->integrity_failed
;