File: policyvers.c

package info (click to toggle)
libselinux 1.32-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,192 kB
  • ctags: 2,205
  • sloc: ansic: 13,005; sh: 195; makefile: 133; python: 103
file content (47 lines) | stat: -rw-r--r-- 816 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "selinux_internal.h"
#include <stdio.h>
#include "policy.h"
#include "dso.h"
#include <limits.h>

#define DEFAULT_POLICY_VERSION 15

int security_policyvers(void)
{
	int fd, ret;
	char path[PATH_MAX];
	char buf[20];
	unsigned vers = DEFAULT_POLICY_VERSION;

	if (!selinux_mnt) {
		errno = ENOENT;
		return -1;
	}

	snprintf(path, sizeof path, "%s/policyvers", selinux_mnt);
	fd = open(path, O_RDONLY);
	if (fd < 0) {
		if (errno == ENOENT)
			return vers;
		else
			return -1;
	}
	memset(buf, 0, sizeof buf);
	ret = read(fd, buf, sizeof buf - 1);
	close(fd);
	if (ret < 0)
		return -1;

	if (sscanf(buf, "%u", &vers) != 1)
		return -1;

	return vers;
}

hidden_def(security_policyvers)