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