diff options
author | Miroslav Grepl <mgrepl@redhat.com> | 2014-04-11 10:53:54 +0200 |
---|---|---|
committer | Miroslav Grepl <mgrepl@redhat.com> | 2014-04-11 18:29:39 +0200 |
commit | 85a12d481d664120865b46cd1c4c325307179471 (patch) | |
tree | dae69b6d5b1a5c35937033e26e6bc34726eb3a88 /libqpol/src/util.c | |
parent | 295cc6c22440038c1b633602c0f1b38ded57e1a0 (diff) | |
download | setools-85a12d481d664120865b46cd1c4c325307179471.tar.gz setools-85a12d481d664120865b46cd1c4c325307179471.tar.xz setools-85a12d481d664120865b46cd1c4c325307179471.zip |
Apply selinux_current_policy_path patch
Diffstat (limited to 'libqpol/src/util.c')
-rw-r--r-- | libqpol/src/util.c | 73 |
1 files changed, 5 insertions, 68 deletions
diff --git a/libqpol/src/util.c b/libqpol/src/util.c index 7c49876..8f74b2b 100644 --- a/libqpol/src/util.c +++ b/libqpol/src/util.c @@ -84,75 +84,12 @@ static int get_binpol_version(const char *policy_fname) static int search_policy_binary_file(char **path) { - const char *binary_path; - if ((binary_path = selinux_binary_policy_path()) == NULL) { - return -1; - } - - int expected_version = -1, latest_version = -1; -#ifdef LIBSELINUX - /* if the system has SELinux enabled, prefer the policy whose - name matches the current policy version */ - if ((expected_version = security_policyvers()) < 0) { - return -1; - } -#endif - - glob_t glob_buf; - struct stat fs; - int rt, error = 0, retval = -1; - size_t i; - char *pattern = NULL; - if (asprintf(&pattern, "%s.*", binary_path) < 0) { - return -1; - } - glob_buf.gl_offs = 1; - glob_buf.gl_pathc = 0; - rt = glob(pattern, GLOB_DOOFFS, NULL, &glob_buf); - if (rt != 0 && rt != GLOB_NOMATCH) { - errno = EIO; - return -1; - } - - for (i = 0; i < glob_buf.gl_pathc; i++) { - char *p = glob_buf.gl_pathv[i + glob_buf.gl_offs]; - if (stat(p, &fs) != 0) { - error = errno; - goto cleanup; - } - if (S_ISDIR(fs.st_mode)) - continue; - - if ((rt = get_binpol_version(p)) < 0) { - error = errno; - goto cleanup; - } - - if (rt > latest_version || rt == expected_version) { - free(*path); - if ((*path = strdup(p)) == NULL) { - error = errno; - goto cleanup; - } - if (rt == expected_version) { - break; - } - latest_version = rt; - } - } - - if (*path == NULL) { - retval = 1; - } else { - retval = 0; - } - cleanup: - free(pattern); - globfree(&glob_buf); - if (retval == -1) { - errno = error; + const char *binary_path = selinux_current_policy_path(); + if (binary_path) { + *path = strdup(binary_path); + if (*path) return 0; } - return retval; + return -1; } int qpol_default_policy_find(char **path) |