integrity-checker: Use chunk_map() instead of non-portable mmap()
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@@ -61,40 +60,17 @@ METHOD(integrity_checker_t, build_file, u_int32_t,
|
|||||||
private_integrity_checker_t *this, char *file, size_t *len)
|
private_integrity_checker_t *this, char *file, size_t *len)
|
||||||
{
|
{
|
||||||
u_int32_t checksum;
|
u_int32_t checksum;
|
||||||
chunk_t contents;
|
chunk_t *contents;
|
||||||
struct stat sb;
|
|
||||||
void *addr;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = open(file, O_RDONLY);
|
contents = chunk_map(file, FALSE);
|
||||||
if (fd == -1)
|
if (!contents)
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, " opening '%s' failed: %s", file, strerror(errno));
|
DBG1(DBG_LIB, " opening '%s' failed: %s", file, strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*len = contents->len;
|
||||||
if (fstat(fd, &sb) == -1)
|
checksum = chunk_hash_static(*contents);
|
||||||
{
|
chunk_unmap(contents);
|
||||||
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);
|
|
||||||
|
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
@@ -318,4 +294,3 @@ integrity_checker_t *integrity_checker_create(char *checksum_library)
|
|||||||
}
|
}
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user