radattr: Use chunk_map() instead of non-portable mmap()
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
@@ -110,10 +109,7 @@ static void add_radius_attribute(private_radattr_listener_t *this,
|
|||||||
identification_t *id;
|
identification_t *id;
|
||||||
auth_cfg_t *auth;
|
auth_cfg_t *auth;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
chunk_t data;
|
chunk_t *data;
|
||||||
struct stat sb;
|
|
||||||
void *addr;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
auth = ike_sa->get_auth_cfg(ike_sa, TRUE);
|
auth = ike_sa->get_auth_cfg(ike_sa, TRUE);
|
||||||
id = auth->get(auth, AUTH_RULE_EAP_IDENTITY);
|
id = auth->get(auth, AUTH_RULE_EAP_IDENTITY);
|
||||||
@@ -123,44 +119,16 @@ static void add_radius_attribute(private_radattr_listener_t *this,
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s/%Y", this->dir, id);
|
snprintf(path, sizeof(path), "%s/%Y", this->dir, id);
|
||||||
fd = open(path, O_RDONLY);
|
data = chunk_map(path, FALSE);
|
||||||
if (fd != -1)
|
if (data)
|
||||||
{
|
{
|
||||||
if (fstat(fd, &sb) != -1)
|
if (data->len >= 2)
|
||||||
{
|
{
|
||||||
if (sb.st_size <= MAX_ATTR_SIZE)
|
DBG1(DBG_CFG, "adding RADIUS %N attribute",
|
||||||
{
|
radius_attribute_type_names, data->ptr[0]);
|
||||||
addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
message->add_notify(message, FALSE, RADIUS_ATTRIBUTE, *data);
|
||||||
if (addr != MAP_FAILED)
|
|
||||||
{
|
|
||||||
data = chunk_create(addr, sb.st_size);
|
|
||||||
if (data.len >= 2)
|
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "adding RADIUS %N attribute",
|
|
||||||
radius_attribute_type_names, data.ptr[0]);
|
|
||||||
message->add_notify(message, FALSE,
|
|
||||||
RADIUS_ATTRIBUTE, data);
|
|
||||||
}
|
|
||||||
munmap(addr, sb.st_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "mapping RADIUS attribute '%s' failed: %s",
|
|
||||||
path, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "RADIUS attribute '%s' exceeds size limit",
|
|
||||||
path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
chunk_unmap(data);
|
||||||
{
|
|
||||||
DBG1(DBG_CFG, "fstat RADIUS attribute '%s' failed: %s",
|
|
||||||
path, strerror(errno));
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user