diff options
author | Martin Willi <martin@revosec.ch> | 2013-11-21 14:49:57 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-01-23 15:55:33 +0100 |
commit | 7ae878c3573c50c34c7a1b7941ddcffdae1f68a6 (patch) | |
tree | 27b9ce8cb1f0cd2c7a29a2cd5e668b83ddd7f7d5 /src | |
parent | 88fa7f62bed4d1cfd6ed4ec88336a417478b402e (diff) | |
download | strongswan-7ae878c3573c50c34c7a1b7941ddcffdae1f68a6.tar.bz2 strongswan-7ae878c3573c50c34c7a1b7941ddcffdae1f68a6.tar.xz |
tnccs: Use chunk_map() instead of non-portable mmap()
Diffstat (limited to 'src')
-rw-r--r-- | src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c | 1 | ||||
-rw-r--r-- | src/libtnccs/tnc/tnc.c | 32 |
2 files changed, 6 insertions, 27 deletions
diff --git a/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c b/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c index b4f131b5d..12ea20319 100644 --- a/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c +++ b/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c @@ -21,7 +21,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <sys/mman.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> diff --git a/src/libtnccs/tnc/tnc.c b/src/libtnccs/tnc/tnc.c index 3a5b84596..fdf0412d1 100644 --- a/src/libtnccs/tnc/tnc.c +++ b/src/libtnccs/tnc/tnc.c @@ -17,7 +17,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <sys/mman.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> @@ -94,10 +93,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 +105,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 +183,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; } @@ -272,4 +253,3 @@ bool tnc_manager_register(plugin_t *plugin, plugin_feature_t *feature, } return TRUE; } - |