From: Martin Willi Date: Thu, 21 Nov 2013 13:49:37 +0000 (+0100) Subject: pem: Use chunk_map() instead of non-portable mmap() X-Git-Tag: 5.1.2rc1~42^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88fa7f62bed4d1cfd6ed4ec88336a417478b402e;p=thirdparty%2Fstrongswan.git pem: Use chunk_map() instead of non-portable mmap() --- diff --git a/src/libstrongswan/plugins/pem/pem_builder.c b/src/libstrongswan/plugins/pem/pem_builder.c index 254b1951b2..62780c3841 100644 --- a/src/libstrongswan/plugins/pem/pem_builder.c +++ b/src/libstrongswan/plugins/pem/pem_builder.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -418,39 +417,17 @@ static void *load_from_blob(chunk_t blob, credential_type_t type, int subtype, static void *load_from_file(char *file, credential_type_t type, int subtype, identification_t *subject, x509_flag_t flags) { - void *cred = NULL; - struct stat sb; - void *addr; - int fd; + void *cred; + chunk_t *chunk; - fd = open(file, O_RDONLY); - if (fd == -1) + chunk = chunk_map(file, FALSE); + if (!chunk) { DBG1(DBG_LIB, " opening '%s' failed: %s", file, strerror(errno)); return NULL; } - - if (fstat(fd, &sb) == -1) - { - DBG1(DBG_LIB, " getting file size of '%s' failed: %s", file, - strerror(errno)); - close(fd); - return NULL; - } - - addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (addr == MAP_FAILED) - { - DBG1(DBG_LIB, " mapping '%s' failed: %s", file, strerror(errno)); - close(fd); - return NULL; - } - - cred = load_from_blob(chunk_create(addr, sb.st_size), type, subtype, - subject, flags); - - munmap(addr, sb.st_size); - close(fd); + cred = load_from_blob(*chunk, type, subtype, subject, flags); + chunk_unmap(chunk); return cred; }