|
| 1 | +diff --git a/libselinux/src/init.c b/libselinux/src/init.c |
| 2 | +index 542c979b..acba93f6 100644 |
| 3 | +--- a/libselinux/src/init.c |
| 4 | ++++ b/libselinux/src/init.c |
| 5 | +@@ -149,7 +149,7 @@ static void init_lib(void) |
| 6 | + selinux_page_size = sysconf(_SC_PAGE_SIZE); |
| 7 | + init_selinuxmnt(); |
| 8 | + #ifndef ANDROID |
| 9 | +- has_selinux_config = (access(SELINUXCONFIG, F_OK) == 0); |
| 10 | ++ has_selinux_config = (access(selinux_config_path(), F_OK) == 0); |
| 11 | + #endif |
| 12 | + } |
| 13 | + |
| 14 | +diff --git a/libselinux/src/selinux_config.c b/libselinux/src/selinux_config.c |
| 15 | +index 1d8cfb71..79deb6fc 100644 |
| 16 | +--- a/libselinux/src/selinux_config.c |
| 17 | ++++ b/libselinux/src/selinux_config.c |
| 18 | +@@ -89,7 +89,7 @@ static const uint16_t file_path_suffixes_idx[NEL] = { |
| 19 | + int selinux_getenforcemode(int *enforce) |
| 20 | + { |
| 21 | + int ret = -1; |
| 22 | +- FILE *cfg = fopen(SELINUXCONFIG, "re"); |
| 23 | ++ FILE *cfg = fopen(selinux_config_path(), "re"); |
| 24 | + if (cfg) { |
| 25 | + char *buf; |
| 26 | + char *tag; |
| 27 | +@@ -153,7 +153,6 @@ static int setpolicytype(const char *type) |
| 28 | + } |
| 29 | + |
| 30 | + static char *selinux_policyroot = NULL; |
| 31 | +-static const char *selinux_rootpath = SELINUXDIR; |
| 32 | + |
| 33 | + static void init_selinux_config(void) |
| 34 | + { |
| 35 | +@@ -166,7 +165,7 @@ static void init_selinux_config(void) |
| 36 | + if (selinux_policyroot) |
| 37 | + return; |
| 38 | + |
| 39 | +- fp = fopen(SELINUXCONFIG, "re"); |
| 40 | ++ fp = fopen(selinux_config_path(), "re"); |
| 41 | + if (fp) { |
| 42 | + __fsetlocking(fp, FSETLOCKING_BYCALLER); |
| 43 | + while ((len = getline(&line_buf, &line_len, fp)) > 0) { |
| 44 | +@@ -228,7 +227,7 @@ static void init_selinux_config(void) |
| 45 | + if (!selinux_policytype && setpolicytype(SELINUXDEFAULT) != 0) |
| 46 | + return; |
| 47 | + |
| 48 | +- if (asprintf(&selinux_policyroot, "%s%s", SELINUXDIR, selinux_policytype) == -1) |
| 49 | ++ if (asprintf(&selinux_policyroot, "%s%s", selinux_path(), selinux_policytype) == -1) |
| 50 | + return; |
| 51 | + |
| 52 | + for (i = 0; i < NEL; i++) |
| 53 | +@@ -312,7 +311,13 @@ int selinux_set_policy_root(const char *path) |
| 54 | + |
| 55 | + const char *selinux_path(void) |
| 56 | + { |
| 57 | +- return selinux_rootpath; |
| 58 | ++ return access(SELINUXDIR_RO, F_OK) == 0 ? SELINUXDIR_RO : SELINUXDIR_RW; |
| 59 | ++} |
| 60 | ++ |
| 61 | ++ |
| 62 | ++const char *selinux_config_path(void) |
| 63 | ++{ |
| 64 | ++ return access(SELINUXDIR_RO, F_OK) == 0 ? SELINUXCONFIG_RO : SELINUXCONFIG_RW; |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | +diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h |
| 69 | +index af69ff04..0ff78e04 100644 |
| 70 | +--- a/libselinux/src/selinux_internal.h |
| 71 | ++++ b/libselinux/src/selinux_internal.h |
| 72 | +@@ -89,8 +89,11 @@ extern int selinux_page_size ; |
| 73 | + pthread_cond_wait \ |
| 74 | + ) |
| 75 | + |
| 76 | +-#define SELINUXDIR "/etc/selinux/" |
| 77 | +-#define SELINUXCONFIG SELINUXDIR "config" |
| 78 | ++#define SELINUXDIR_RW "/etc/selinux/" |
| 79 | ++#define SELINUXDIR_RO "/usr/etc/selinux/" |
| 80 | ++#define SELINUXCONFIG_RO SELINUXDIR_RO "config" |
| 81 | ++#define SELINUXCONFIG_RW SELINUXDIR_RW "config" |
| 82 | ++const char *selinux_config_path(void); |
| 83 | + |
| 84 | + extern int has_selinux_config ; |
| 85 | + |
0 commit comments