OSDN Git Service

e2fsdroid: use libselinux function to read file context on device
authorJin Qian <jinqian@google.com>
Tue, 20 Jun 2017 20:49:53 +0000 (13:49 -0700)
committerJin Qian <jinqian@google.com>
Tue, 20 Jun 2017 20:53:04 +0000 (13:53 -0700)
When e2fsdroid runs on device, location of selinux file contexts
should be determined by libselinux instead of using arbitrary paths.

Bug: 35219933
Change-Id: I413b198422eddb212599498b532ba2c4d8bb36c6

contrib/android/perms.c
contrib/android/perms.h

index 9a7a93f..9ae8e58 100644 (file)
@@ -297,6 +297,7 @@ errcode_t android_configure_fs(ext2_filsys fs, char *src_dir, char *target_out,
        struct selabel_handle *sehnd = NULL;
 
        /* Retrieve file contexts */
+#if !defined(__ANDROID__)
        if (nopt > 0) {
                sehnd = selabel_open(SELABEL_CTX_FILE, seopts, nopt);
                if (!sehnd) {
@@ -306,6 +307,14 @@ errcode_t android_configure_fs(ext2_filsys fs, char *src_dir, char *target_out,
                        return -EINVAL;
                }
        }
+#else
+       sehnd = selinux_android_file_context_handle();
+       if (!sehnd) {
+               com_err(__func__, -EINVAL,
+                       _("while opening android file_contexts"));
+               return -EINVAL;
+       }
+#endif
 
        /* Load the FS config */
        if (fs_config_file) {
index 9955bb5..c404cb9 100644 (file)
@@ -25,7 +25,7 @@ static inline errcode_t android_configure_fs(ext2_filsys fs,
 # else
 #  include <selinux/selinux.h>
 #  include <selinux/label.h>
-#  if !defined(HOST)
+#  if defined(__ANDROID__)
 #   include <selinux/android.h>
 #  endif
 #  include <private/android_filesystem_config.h>