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

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