diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2013-02-07 13:27:27 +0100 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2013-02-07 13:27:27 +0100 |
commit | b4f62acfae5e58d8bbdb5a2f3a4d22dc7a47f8af (patch) | |
tree | 6a9ea7adf70239d85185a20f7d5878cfe95f8070 /src/libstrongswan/library.c | |
parent | 6307450b402e3c4a901fb8c0e54d8ad583ce2118 (diff) | |
parent | 7585facf05d927eb6df3929ce09ed5e60d905437 (diff) | |
download | vyos-strongswan-b4f62acfae5e58d8bbdb5a2f3a4d22dc7a47f8af.tar.gz vyos-strongswan-b4f62acfae5e58d8bbdb5a2f3a4d22dc7a47f8af.zip |
Merge tag 'upstream/5.0.2'
Upstream version 5.0.2
Diffstat (limited to 'src/libstrongswan/library.c')
-rw-r--r-- | src/libstrongswan/library.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index 1179b468c..30a7774df 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -18,11 +18,11 @@ #include <stdlib.h> -#include <debug.h> +#include <utils/debug.h> #include <threading/thread.h> #include <utils/identification.h> -#include <utils/host.h> -#include <utils/hashtable.h> +#include <networking/host.h> +#include <collections/hashtable.h> #include <utils/backtrace.h> #include <selectors/traffic_selector.h> @@ -44,12 +44,22 @@ struct private_library_t { * Hashtable with registered objects (name => object) */ hashtable_t *objects; + + /** + * Integrity check failed? + */ + bool integrity_failed; + + /** + * Number of times we have been initialized + */ + refcount_t ref; }; /** * library instance */ -library_t *lib; +library_t *lib = NULL; /** * Deinitialize library @@ -59,6 +69,11 @@ void library_deinit() private_library_t *this = (private_library_t*)lib; bool detailed; + if (!this || !ref_put(&this->ref)) + { /* have more users */ + return; + } + detailed = lib->settings->get_bool(lib->settings, "libstrongswan.leak_detective.detailed", TRUE); @@ -68,6 +83,7 @@ void library_deinit() this->public.scheduler->destroy(this->public.scheduler); this->public.processor->destroy(this->public.processor); this->public.plugins->destroy(this->public.plugins); + this->public.hosts->destroy(this->public.hosts); this->public.settings->destroy(this->public.settings); this->public.credmgr->destroy(this->public.credmgr); this->public.creds->destroy(this->public.creds); @@ -141,11 +157,19 @@ bool library_init(char *settings) private_library_t *this; printf_hook_t *pfh; + if (lib) + { /* already initialized, increase refcount */ + this = (private_library_t*)lib; + ref_get(&this->ref); + return !this->integrity_failed; + } + INIT(this, .public = { .get = _get, .set = _set, }, + .ref = 1, ); lib = &this->public; @@ -183,6 +207,7 @@ bool library_init(char *settings) this->objects = hashtable_create((hashtable_hash_t)hash, (hashtable_equals_t)equals, 4); this->public.settings = settings_create(settings); + this->public.hosts = host_resolver_create(); this->public.proposal = proposal_keywords_create(); this->public.crypto = crypto_factory_create(); this->public.creds = credential_factory_create(); @@ -202,14 +227,14 @@ bool library_init(char *settings) if (!lib->integrity->check(lib->integrity, "libstrongswan", library_init)) { DBG1(DBG_LIB, "integrity check of libstrongswan failed"); - return FALSE; + this->integrity_failed = TRUE; } #else /* !INTEGRITY_TEST */ DBG1(DBG_LIB, "integrity test enabled, but not supported"); - return FALSE; + this->integrity_failed = TRUE; #endif /* INTEGRITY_TEST */ } - return TRUE; + return !this->integrity_failed; } |