Blame libselinux/src/policyvers.c
|
Chris PeBenito |
473ea7 |
#include <unistd.h>
|
|
Chris PeBenito |
473ea7 |
#include <sys/types.h>
|
|
Chris PeBenito |
473ea7 |
#include <fcntl.h>
|
|
Chris PeBenito |
473ea7 |
#include <stdlib.h>
|
|
Chris PeBenito |
473ea7 |
#include <errno.h>
|
|
Chris PeBenito |
473ea7 |
#include <string.h>
|
|
Chris PeBenito |
473ea7 |
#include "selinux_internal.h"
|
|
Chris PeBenito |
473ea7 |
#include <stdio.h>
|
|
Chris PeBenito |
473ea7 |
#include "policy.h"
|
|
Chris PeBenito |
473ea7 |
#include "dso.h"
|
|
Chris PeBenito |
473ea7 |
#include <limits.h>
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#define DEFAULT_POLICY_VERSION 15
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
int security_policyvers(void)
|
|
Chris PeBenito |
473ea7 |
{
|
|
Chris PeBenito |
473ea7 |
int fd, ret;
|
|
Chris PeBenito |
473ea7 |
char path[PATH_MAX];
|
|
Chris PeBenito |
473ea7 |
char buf[20];
|
|
Chris PeBenito |
473ea7 |
unsigned vers = DEFAULT_POLICY_VERSION;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
snprintf(path, sizeof path, "%s/policyvers", selinux_mnt);
|
|
Chris PeBenito |
473ea7 |
fd = open(path, O_RDONLY);
|
|
Chris PeBenito |
473ea7 |
if (fd < 0) {
|
|
Chris PeBenito |
473ea7 |
if (errno == ENOENT)
|
|
Chris PeBenito |
473ea7 |
return vers;
|
|
Chris PeBenito |
473ea7 |
else
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
memset(buf, 0, sizeof buf);
|
|
Chris PeBenito |
473ea7 |
ret = read(fd, buf, sizeof buf-1);
|
|
Chris PeBenito |
473ea7 |
close(fd);
|
|
Chris PeBenito |
473ea7 |
if (ret < 0)
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
if (sscanf(buf, "%u", &vers) != 1)
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
return vers;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
hidden_def(security_policyvers)
|
|
Chris PeBenito |
473ea7 |
|