Blame SOURCES/0004-Apply-selinux_current_policy_path-patch.patch

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