summaryrefslogtreecommitdiff
path: root/src/libtnccs/tnc/tnc.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2014-03-11 20:48:48 +0100
committerYves-Alexis Perez <corsac@debian.org>2014-03-11 20:48:48 +0100
commit15fb7904f4431a6e7c305fd08732458f7f885e7e (patch)
treec93b60ee813af70509f00f34e29ebec311762427 /src/libtnccs/tnc/tnc.c
parent5313d2d78ca150515f7f5eb39801c100690b6b29 (diff)
downloadvyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.tar.gz
vyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.zip
Imported Upstream version 5.1.2
Diffstat (limited to 'src/libtnccs/tnc/tnc.c')
-rw-r--r--src/libtnccs/tnc/tnc.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/libtnccs/tnc/tnc.c b/src/libtnccs/tnc/tnc.c
index 3a5b84596..e002b10e0 100644
--- a/src/libtnccs/tnc/tnc.c
+++ b/src/libtnccs/tnc/tnc.c
@@ -13,14 +13,15 @@
* for more details.
*/
-#include "tnc.h"
-
+#define _GNU_SOURCE /* for stdndup() */
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
+#include <string.h>
+
+#include "tnc.h"
#include <utils/lexparser.h>
#include <utils/debug.h>
@@ -71,8 +72,10 @@ void libtnccs_init(void)
},
.ref = 1,
);
-
tnc = &this->public;
+ lib->settings->add_fallback(lib->settings, "%s.tnc", "libtnccs", lib->ns);
+ lib->settings->add_fallback(lib->settings, "%s.plugins", "libtnccs.plugins",
+ lib->ns);
}
/**
@@ -94,10 +97,8 @@ void libtnccs_deinit(void)
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;
+ int line_nr = 0;
+ chunk_t *src, line;
char *label;
if (!filename || !*filename)
@@ -108,30 +109,15 @@ static bool load_imcvs_from_config(char *filename, bool is_imc)
label = is_imc ? "IMC" : "IMV";
DBG1(DBG_TNC, "loading %ss from '%s'", label, filename);
- fd = open(filename, O_RDONLY);
- if (fd == -1)
+ src = chunk_map(filename, FALSE);
+ if (!src)
{
DBG1(DBG_TNC, "opening configuration file '%s' failed: %s", filename,
strerror(errno));
return FALSE;
}
- if (fstat(fd, &sb) == -1)
- {
- DBG1(DBG_LIB, "getting file size of '%s' failed: %s", filename,
- strerror(errno));
- close(fd);
- return FALSE;
- }
- addr = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- if (addr == MAP_FAILED)
- {
- DBG1(DBG_LIB, "mapping '%s' failed: %s", filename, strerror(errno));
- close(fd);
- return FALSE;
- }
- src = chunk_create(addr, sb.st_size);
- while (fetchline(&src, &line))
+ while (fetchline(src, &line))
{
char *name, *path;
chunk_t token;
@@ -201,8 +187,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc)
break;
}
}
- munmap(addr, sb.st_size);
- close(fd);
+ chunk_unmap(src);
return success;
}
@@ -266,10 +251,9 @@ bool tnc_manager_register(plugin_t *plugin, plugin_feature_t *feature,
{
load_imcvs_from_config(
lib->settings->get_str(lib->settings,
- "libtnccs.tnc_config", "/etc/tnc_config"),
+ "%s.tnc.tnc_config", "/etc/tnc_config", lib->ns),
is_imc);
}
}
return TRUE;
}
-