diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2013-10-17 21:23:38 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2013-10-17 21:23:38 +0200 |
commit | 9d37ad77ef660b92ea51b69d74e14f931d2a04e2 (patch) | |
tree | d6bbb4a5fed1959f8675df9ee7c03713b543fcc9 /src/libtnccs/tnc/tnc.c | |
parent | 104f57d4b0fb6d7547d6898352eaa5fb4b222010 (diff) | |
parent | e5ee4e7fcdd58b7d86bf1b458da2c63e8e19627b (diff) | |
download | vyos-strongswan-9d37ad77ef660b92ea51b69d74e14f931d2a04e2.tar.gz vyos-strongswan-9d37ad77ef660b92ea51b69d74e14f931d2a04e2.zip |
Merge tag 'v5.1.0-1' into sid
tag strongSwan 5.1.0-1
Diffstat (limited to 'src/libtnccs/tnc/tnc.c')
-rw-r--r-- | src/libtnccs/tnc/tnc.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/libtnccs/tnc/tnc.c b/src/libtnccs/tnc/tnc.c index 652afc291..3a5b84596 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,10 +59,18 @@ 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,18 +82,29 @@ 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; } static bool load_imcvs_from_config(char *filename, bool is_imc) { + bool success = FALSE; int fd, line_nr = 0; chunk_t src, line; struct stat sb; void *addr; char *label; + if (!filename || !*filename) + { + return TRUE; + } + label = is_imc ? "IMC" : "IMV"; DBG1(DBG_TNC, "loading %ss from '%s'", label, filename); @@ -110,7 +134,6 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) while (fetchline(&src, &line)) { char *name, *path; - bool success; chunk_t token; line_nr++; @@ -126,7 +149,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) { DBG1(DBG_TNC, "line %d: keyword must be followed by a space", line_nr); - return FALSE; + break; } /* only interested in IMCs or IMVs depending on label */ @@ -141,20 +164,18 @@ static bool load_imcvs_from_config(char *filename, bool is_imc) { DBG1(DBG_TNC, "line %d: %s name must be set in double quotes", line_nr, label); - return FALSE; + break; } /* 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)) { DBG1(DBG_TNC, "line %d: %s path is missing", line_nr, label); free(name); - return FALSE; + break; } if (!extract_token(&token, ' ', &line)) { @@ -162,9 +183,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,14 +194,16 @@ 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) { - return FALSE; + break; } } munmap(addr, sb.st_size); close(fd); - return TRUE; + return success; } /** @@ -243,24 +264,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; |