From: Martin Willi Date: Thu, 21 Nov 2013 13:50:30 +0000 (+0100) Subject: integrity-checker: Use chunk_map() instead of non-portable mmap() X-Git-Tag: 5.1.2rc1~42^2~6 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=69be6a9e052d100b993519487ca174fad1401afb;p=thirdparty%2Fstrongswan.git integrity-checker: Use chunk_map() instead of non-portable mmap() --- diff --git a/src/libstrongswan/utils/integrity_checker.c b/src/libstrongswan/utils/integrity_checker.c index d59a762324..b66df02e78 100644 --- a/src/libstrongswan/utils/integrity_checker.c +++ b/src/libstrongswan/utils/integrity_checker.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -61,40 +60,17 @@ METHOD(integrity_checker_t, build_file, u_int32_t, private_integrity_checker_t *this, char *file, size_t *len) { u_int32_t checksum; - chunk_t contents; - struct stat sb; - void *addr; - int fd; + chunk_t *contents; - fd = open(file, O_RDONLY); - if (fd == -1) + contents = chunk_map(file, FALSE); + if (!contents) { DBG1(DBG_LIB, " opening '%s' failed: %s", file, strerror(errno)); return 0; } - - if (fstat(fd, &sb) == -1) - { - DBG1(DBG_LIB, " getting file size of '%s' failed: %s", file, - strerror(errno)); - close(fd); - return 0; - } - - 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 0; - } - - *len = sb.st_size; - contents = chunk_create(addr, sb.st_size); - checksum = chunk_hash_static(contents); - - munmap(addr, sb.st_size); - close(fd); + *len = contents->len; + checksum = chunk_hash_static(*contents); + chunk_unmap(contents); return checksum; } @@ -318,4 +294,3 @@ integrity_checker_t *integrity_checker_create(char *checksum_library) } return &this->public; } -