stroke: Use chunk_map() instead of non-portable mmap()
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -1101,46 +1100,24 @@ static bool load_shared(mem_cred_t *secrets, chunk_t line, int line_nr,
|
|||||||
static void load_secrets(private_stroke_cred_t *this, mem_cred_t *secrets,
|
static void load_secrets(private_stroke_cred_t *this, mem_cred_t *secrets,
|
||||||
char *file, int level, FILE *prompt)
|
char *file, int level, FILE *prompt)
|
||||||
{
|
{
|
||||||
int line_nr = 0, fd;
|
int line_nr = 0;
|
||||||
chunk_t src, line;
|
chunk_t *src, line;
|
||||||
struct stat sb;
|
|
||||||
void *addr;
|
|
||||||
|
|
||||||
DBG1(DBG_CFG, "loading secrets from '%s'", file);
|
DBG1(DBG_CFG, "loading secrets from '%s'", file);
|
||||||
fd = open(file, O_RDONLY);
|
src = chunk_map(file, FALSE);
|
||||||
if (fd == -1)
|
if (!src)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "opening secrets file '%s' failed: %s", file,
|
DBG1(DBG_CFG, "opening secrets file '%s' failed: %s", file,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fstat(fd, &sb) == -1)
|
|
||||||
{
|
|
||||||
DBG1(DBG_LIB, "getting file size of '%s' failed: %s", file,
|
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (sb.st_size == 0)
|
|
||||||
{ /* skip empty files, as mmap() complains */
|
|
||||||
close(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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", file, strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
src = chunk_create(addr, sb.st_size);
|
|
||||||
|
|
||||||
if (!secrets)
|
if (!secrets)
|
||||||
{
|
{
|
||||||
secrets = mem_cred_create();
|
secrets = mem_cred_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fetchline(&src, &line))
|
while (fetchline(src, &line))
|
||||||
{
|
{
|
||||||
chunk_t ids, token;
|
chunk_t ids, token;
|
||||||
shared_key_type_t type;
|
shared_key_type_t type;
|
||||||
@@ -1281,8 +1258,7 @@ static void load_secrets(private_stroke_cred_t *this, mem_cred_t *secrets,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
munmap(addr, sb.st_size);
|
chunk_unmap(src);
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
{ /* replace secrets in active credential set */
|
{ /* replace secrets in active credential set */
|
||||||
|
|||||||
Reference in New Issue
Block a user