|
|
4ea9f2 |
From 85a12d481d664120865b46cd1c4c325307179471 Mon Sep 17 00:00:00 2001
|
|
|
4ea9f2 |
From: Miroslav Grepl <mgrepl@redhat.com>
|
|
|
4ea9f2 |
Date: Fri, 11 Apr 2014 10:53:54 +0200
|
|
|
4ea9f2 |
Subject: [PATCH 04/11] Apply selinux_current_policy_path patch
|
|
|
4ea9f2 |
|
|
|
4ea9f2 |
---
|
|
|
4ea9f2 |
libqpol/src/util.c | 73 ++++--------------------------------------------------
|
|
|
4ea9f2 |
1 file changed, 5 insertions(+), 68 deletions(-)
|
|
|
4ea9f2 |
|
|
|
4ea9f2 |
diff --git a/libqpol/src/util.c b/libqpol/src/util.c
|
|
|
4ea9f2 |
index 7c49876..8f74b2b 100644
|
|
|
4ea9f2 |
--- a/libqpol/src/util.c
|
|
|
4ea9f2 |
+++ b/libqpol/src/util.c
|
|
|
4ea9f2 |
@@ -84,75 +84,12 @@ static int get_binpol_version(const char *policy_fname)
|
|
|
4ea9f2 |
|
|
|
4ea9f2 |
static int search_policy_binary_file(char **path)
|
|
|
4ea9f2 |
{
|
|
|
4ea9f2 |
- const char *binary_path;
|
|
|
4ea9f2 |
- if ((binary_path = selinux_binary_policy_path()) == NULL) {
|
|
|
4ea9f2 |
- return -1;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- int expected_version = -1, latest_version = -1;
|
|
|
4ea9f2 |
-#ifdef LIBSELINUX
|
|
|
4ea9f2 |
- /* if the system has SELinux enabled, prefer the policy whose
|
|
|
4ea9f2 |
- name matches the current policy version */
|
|
|
4ea9f2 |
- if ((expected_version = security_policyvers()) < 0) {
|
|
|
4ea9f2 |
- return -1;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
-#endif
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- glob_t glob_buf;
|
|
|
4ea9f2 |
- struct stat fs;
|
|
|
4ea9f2 |
- int rt, error = 0, retval = -1;
|
|
|
4ea9f2 |
- size_t i;
|
|
|
4ea9f2 |
- char *pattern = NULL;
|
|
|
4ea9f2 |
- if (asprintf(&pattern, "%s.*", binary_path) < 0) {
|
|
|
4ea9f2 |
- return -1;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- glob_buf.gl_offs = 1;
|
|
|
4ea9f2 |
- glob_buf.gl_pathc = 0;
|
|
|
4ea9f2 |
- rt = glob(pattern, GLOB_DOOFFS, NULL, &glob_buf);
|
|
|
4ea9f2 |
- if (rt != 0 && rt != GLOB_NOMATCH) {
|
|
|
4ea9f2 |
- errno = EIO;
|
|
|
4ea9f2 |
- return -1;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- for (i = 0; i < glob_buf.gl_pathc; i++) {
|
|
|
4ea9f2 |
- char *p = glob_buf.gl_pathv[i + glob_buf.gl_offs];
|
|
|
4ea9f2 |
- if (stat(p, &fs) != 0) {
|
|
|
4ea9f2 |
- error = errno;
|
|
|
4ea9f2 |
- goto cleanup;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- if (S_ISDIR(fs.st_mode))
|
|
|
4ea9f2 |
- continue;
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- if ((rt = get_binpol_version(p)) < 0) {
|
|
|
4ea9f2 |
- error = errno;
|
|
|
4ea9f2 |
- goto cleanup;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- if (rt > latest_version || rt == expected_version) {
|
|
|
4ea9f2 |
- free(*path);
|
|
|
4ea9f2 |
- if ((*path = strdup(p)) == NULL) {
|
|
|
4ea9f2 |
- error = errno;
|
|
|
4ea9f2 |
- goto cleanup;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- if (rt == expected_version) {
|
|
|
4ea9f2 |
- break;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- latest_version = rt;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
-
|
|
|
4ea9f2 |
- if (*path == NULL) {
|
|
|
4ea9f2 |
- retval = 1;
|
|
|
4ea9f2 |
- } else {
|
|
|
4ea9f2 |
- retval = 0;
|
|
|
4ea9f2 |
- }
|
|
|
4ea9f2 |
- cleanup:
|
|
|
4ea9f2 |
- free(pattern);
|
|
|
4ea9f2 |
- globfree(&glob_buf);
|
|
|
4ea9f2 |
- if (retval == -1) {
|
|
|
4ea9f2 |
- errno = error;
|
|
|
4ea9f2 |
+ const char *binary_path = selinux_current_policy_path();
|
|
|
4ea9f2 |
+ if (binary_path) {
|
|
|
4ea9f2 |
+ *path = strdup(binary_path);
|
|
|
4ea9f2 |
+ if (*path) return 0;
|
|
|
4ea9f2 |
}
|
|
|
4ea9f2 |
- return retval;
|
|
|
4ea9f2 |
+ return -1;
|
|
|
4ea9f2 |
}
|
|
|
4ea9f2 |
|
|
|
4ea9f2 |
int qpol_default_policy_find(char **path)
|
|
|
4ea9f2 |
--
|
|
|
4ea9f2 |
1.8.5.3
|
|
|
4ea9f2 |
|