Home | History | Annotate | Download | only in src
      1 #include <unistd.h>
      2 #include <sys/types.h>
      3 #include <fcntl.h>
      4 #include <stdlib.h>
      5 #include <errno.h>
      6 #include <string.h>
      7 #include "selinux_internal.h"
      8 #include <stdio.h>
      9 #include "policy.h"
     10 #include "dso.h"
     11 #include <limits.h>
     12 
     13 int security_policyvers(void)
     14 {
     15 	int fd, ret;
     16 	char path[PATH_MAX];
     17 	char buf[20];
     18 	unsigned vers = DEFAULT_POLICY_VERSION;
     19 
     20 	if (!selinux_mnt) {
     21 		errno = ENOENT;
     22 		return -1;
     23 	}
     24 
     25 	snprintf(path, sizeof path, "%s/policyvers", selinux_mnt);
     26 	fd = open(path, O_RDONLY);
     27 	if (fd < 0) {
     28 		if (errno == ENOENT)
     29 			return vers;
     30 		else
     31 			return -1;
     32 	}
     33 	memset(buf, 0, sizeof buf);
     34 	ret = read(fd, buf, sizeof buf - 1);
     35 	close(fd);
     36 	if (ret < 0)
     37 		return -1;
     38 
     39 	if (sscanf(buf, "%u", &vers) != 1)
     40 		return -1;
     41 
     42 	return vers;
     43 }
     44 
     45 hidden_def(security_policyvers)
     46