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 | 7585facf05d927eb6df3929ce09ed5e60d905437 (patch) | |
tree | e4d14b4dc180db20356b6b01ce0112f3a2d7897e /src/libtnccs/tnc | |
parent | c1343b3278cdf99533b7902744d15969f9d6fdc1 (diff) | |
download | vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.tar.gz vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.zip |
Imported Upstream version 5.0.2
Diffstat (limited to 'src/libtnccs/tnc')
-rw-r--r-- | src/libtnccs/tnc/imc/imc_manager.h | 26 | ||||
-rw-r--r-- | src/libtnccs/tnc/imv/imv_manager.h | 25 | ||||
-rw-r--r-- | src/libtnccs/tnc/tnc.c | 52 | ||||
-rw-r--r-- | src/libtnccs/tnc/tnccs/tnccs_manager.c | 2 |
4 files changed, 77 insertions, 28 deletions
diff --git a/src/libtnccs/tnc/imc/imc_manager.h b/src/libtnccs/tnc/imc/imc_manager.h index 25e0efe9d..db033c4c0 100644 --- a/src/libtnccs/tnc/imc/imc_manager.h +++ b/src/libtnccs/tnc/imc/imc_manager.h @@ -55,7 +55,31 @@ struct imc_manager_t { * @param path path of the IMC dynamic library file * @return TRUE if loading succeeded */ - bool (*load)(imc_manager_t *this, char *name, char *path); + bool (*load)(imc_manager_t *this, char *name, char *path); + + /** + * Load and initialize an IMC from a set of TNC IMC functions. + * + * @param name name of the IMC + * @param initialize TNC_IMC_InitializePointer + * @param notify_connection_change TNC_IMC_NotifyConnectionChangePointer + * @param begin_handshake TNC_IMC_BeginHandshakePointer + * @param receive_message TNC_IMC_ReceiveMessagePointer + * @param receive_message_long TNC_IMC_ReceiveMessageLongPointer + * @param batch_ending TNC_IMC_BatchEndingPointer + * @param terminate TNC_IMC_TerminatePointer + * @param provide_bind_function TNC_IMC_ProvideBindFunctionPointer + * @return TRUE if loading succeeded + */ + bool (*load_from_functions)(imc_manager_t *this, char *name, + TNC_IMC_InitializePointer initialize, + TNC_IMC_NotifyConnectionChangePointer notify_connection_change, + TNC_IMC_BeginHandshakePointer begin_handshake, + TNC_IMC_ReceiveMessagePointer receive_message, + TNC_IMC_ReceiveMessageLongPointer receive_message_long, + TNC_IMC_BatchEndingPointer batch_ending, + TNC_IMC_TerminatePointer terminate, + TNC_IMC_ProvideBindFunctionPointer provide_bind_function); /** * Check if an IMC with a given ID is registered with the IMC manager diff --git a/src/libtnccs/tnc/imv/imv_manager.h b/src/libtnccs/tnc/imv/imv_manager.h index 43f40973c..7772b7e08 100644 --- a/src/libtnccs/tnc/imv/imv_manager.h +++ b/src/libtnccs/tnc/imv/imv_manager.h @@ -56,8 +56,31 @@ struct imv_manager_t { * @param path path of the IMV dynamic library file * @return TRUE if loading succeeded */ - bool (*load)(imv_manager_t *this, char *name, char *path); + bool (*load)(imv_manager_t *this, char *name, char *path); + /** + * Load and initialize an IMV from a set of TNC IMC functions. + * + * @param name name of the IMV + * @param initialize TNC_IMV_InitializePointer + * @param notify_connection_change TNC_IMV_NotifyConnectionChangePointer + * @param receive_message TNC_IMV_ReceiveMessagePointer + * @param receive_message_long TNC_IMV_ReceiveMessageLongPointer + * @param solicit_recommendation TNC_IMV_SolicitRecommendationPointer + * @param batch_ending TNC_IMV_BatchEndingPointer + * @param terminate TNC_IMV_TerminatePointer + * @param provide_bind_function TNC_IMV_ProvideBindFunctionPointer + * @return TRUE if loading succeeded + */ + bool (*load_from_functions)(imv_manager_t *this, char *name, + TNC_IMV_InitializePointer initialize, + TNC_IMV_NotifyConnectionChangePointer notify_connection_change, + TNC_IMV_ReceiveMessagePointer receive_message, + TNC_IMV_ReceiveMessageLongPointer receive_message_long, + TNC_IMV_SolicitRecommendationPointer solicit_recommendation, + TNC_IMV_BatchEndingPointer batch_ending, + TNC_IMV_TerminatePointer terminate, + TNC_IMV_ProvideBindFunctionPointer provide_bind_function); /** * Check if an IMV with a given ID is registered with the IMV manager diff --git a/src/libtnccs/tnc/tnc.c b/src/libtnccs/tnc/tnc.c index 7c0ee4132..769b9fa54 100644 --- a/src/libtnccs/tnc/tnc.c +++ b/src/libtnccs/tnc/tnc.c @@ -23,7 +23,7 @@ #include <fcntl.h> #include <utils/lexparser.h> -#include <debug.h> +#include <utils/debug.h> typedef struct private_tnc_t private_tnc_t; @@ -40,6 +40,11 @@ struct private_tnc_t { * Public members of tnc_t. */ tnc_t public; + + /** + * Number of times we have been initialized + */ + refcount_t ref; }; /** @@ -54,9 +59,17 @@ void libtnccs_init(void) { private_tnc_t *this; + if (tnc) + { /* already initialized, increase refcount */ + this = (private_tnc_t*)tnc; + ref_get(&this->ref); + return; + } + INIT(this, .public = { }, + .ref = 1, ); tnc = &this->public; @@ -69,6 +82,11 @@ void libtnccs_deinit(void) { private_tnc_t *this = (private_tnc_t*)tnc; + if (!this || !ref_put(&this->ref)) + { /* have more users */ + return; + } + free(this); tnc = NULL; } @@ -145,9 +163,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) } /* copy the IMC/IMV name */ - name = malloc(token.len + 1); - memcpy(name, token.ptr, token.len); - name[token.len] = '\0'; + name = strndup(token.ptr, token.len); /* advance to the IMC/IMV path and extract it */ if (!eat_whitespace(&line)) @@ -162,9 +178,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) } /* copy the IMC/IMV path */ - path = malloc(token.len + 1); - memcpy(path, token.ptr, token.len); - path[token.len] = '\0'; + path = strndup(token.ptr, token.len); /* load and register an IMC/IMV instance */ if (is_imc) @@ -175,6 +189,8 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) { success = tnc->imvs->load(tnc->imvs, name, path); } + free(name); + free(path); if (!success) { break; @@ -243,24 +259,10 @@ bool tnc_manager_register(plugin_t *plugin, plugin_feature_t *feature, if (load_imcvs) { - char *tnc_config; - - tnc_config = lib->settings->get_str(lib->settings, - "libtnccs.tnc_config", "/etc/tnc_config"); - if (!load_imcvs_from_config(tnc_config, is_imc)) - { - if (is_imc) - { - tnc->imcs->destroy(tnc->imcs); - tnc->imcs = NULL; - } - else - { - tnc->imvs->destroy(tnc->imvs); - tnc->imvs = NULL; - } - return FALSE; - } + load_imcvs_from_config( + lib->settings->get_str(lib->settings, + "libtnccs.tnc_config", "/etc/tnc_config"), + is_imc); } } return TRUE; diff --git a/src/libtnccs/tnc/tnccs/tnccs_manager.c b/src/libtnccs/tnc/tnccs/tnccs_manager.c index fa91bfb21..fca4b2584 100644 --- a/src/libtnccs/tnc/tnccs/tnccs_manager.c +++ b/src/libtnccs/tnc/tnccs/tnccs_manager.c @@ -17,7 +17,7 @@ #include "tnc/tnc.h" -#include <debug.h> +#include <utils/debug.h> /** * See header |