From a95f55c3ef657411f92c0c00a2e23ceb1d52b851 Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Sat, 17 Aug 2013 13:14:43 +0000 Subject: Add SELinux support Change-Id: I11e1a3d018d921d96ba08915925b14bf633be6ed --- Android.mk | 13 +++++++++---- partition.cpp | 20 +++++++++++++++++++- prebuilt/Android.mk | 4 +++- twrp.cpp | 16 ++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Android.mk b/Android.mk index da06b9a60..a6a82ef26 100644 --- a/Android.mk +++ b/Android.mk @@ -56,7 +56,7 @@ LOCAL_STATIC_LIBRARIES := LOCAL_SHARED_LIBRARIES := LOCAL_STATIC_LIBRARIES += libcrecovery libguitwrp -LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libext4_utils libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libaosprecovery +LOCAL_SHARED_LIBRARIES += libz libc libstlport libcutils libstdc++ libtar libblkid libminuitwrp libminadbd libmtdutils libminzip libaosprecovery ifneq ($(wildcard system/core/libsparse/Android.mk),) LOCAL_SHARED_LIBRARIES += libsparse @@ -65,9 +65,9 @@ endif ifeq ($(TARGET_USERIMAGES_USE_EXT4), true) LOCAL_CFLAGS += -DUSE_EXT4 LOCAL_C_INCLUDES += system/extras/ext4_utils - #LOCAL_STATIC_LIBRARIES += libext4_utils + LOCAL_SHARED_LIBRARIES += libext4_utils endif - +LOCAL_C_INCLUDES += external/libselinux/include ifeq ($(HAVE_SELINUX), true) #LOCAL_C_INCLUDES += external/libselinux/include #LOCAL_STATIC_LIBRARIES += libselinux @@ -75,8 +75,13 @@ ifeq ($(HAVE_SELINUX), true) endif # HAVE_SELINUX ifneq ($(wildcard external/libselinux/Android.mk),) LOCAL_C_INCLUDES += external/libselinux/include - LOCAL_STATIC_LIBRARIES += libselinux + LOCAL_SHARED_LIBRARIES += libselinux LOCAL_CFLAGS += -DHAVE_SELINUX -g + ifneq ($(TARGET_USERIMAGES_USE_EXT4), true) + LOCAL_CFLAGS += -DUSE_EXT4 + LOCAL_C_INCLUDES += system/extras/ext4_utils + LOCAL_SHARED_LIBRARIES += libext4_utils + endif endif # This binary is in the recovery ramdisk, which is otherwise a copy of root. diff --git a/partition.cpp b/partition.cpp index f81748d72..dc71bb9a4 100644 --- a/partition.cpp +++ b/partition.cpp @@ -49,10 +49,15 @@ extern "C" { #ifdef TW_INCLUDE_CRYPTO_SAMSUNG #include "crypto/libcrypt_samsung/include/libcrypt_samsung.h" #endif +#ifdef USE_EXT4 + #include "make_ext4fs.h" +#endif } using namespace std; +extern struct selabel_handle *selinux_handle; + TWPartition::TWPartition(void) { Can_Be_Mounted = false; Can_Be_Wiped = false; @@ -1257,6 +1262,19 @@ bool TWPartition::Wipe_EXT4() { if (!UnMount(true)) return false; +#ifdef USE_EXT4 + gui_print("Formatting %s using make_ext4fs function.\n", Display_Name.c_str()); +#ifdef HAVE_SELINUX + if (make_ext4fs(Actual_Block_Device.c_str(), Length, Mount_Point.c_str(), selinux_handle) != 0) { +#else + if (make_ext4fs(Actual_Block_Device.c_str(), Length) != 0) { +#endif + LOGERR("Unable to wipe '%s' using function call.\n", Mount_Point.c_str()); + return false; + } else { + return true; + } +#else if (TWFunc::Path_Exists("/sbin/make_ext4fs")) { string Command, result; @@ -1283,7 +1301,7 @@ bool TWPartition::Wipe_EXT4() { } } else return Wipe_EXT23("ext4"); - +#endif return false; } diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk index e31ec8e31..74923a050 100644 --- a/prebuilt/Android.mk +++ b/prebuilt/Android.mk @@ -46,7 +46,9 @@ RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libbmlutils.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libflashutils.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libstlport.so #RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libmincrypt.so -RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext4_utils.so +ifeq ($(TARGET_USERIMAGES_USE_EXT4), true) + RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext4_utils.so +endif RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libaosprecovery.so RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libjpeg.so ifneq ($(wildcard external/libselinux/Android.mk),) diff --git a/twrp.cpp b/twrp.cpp index bc3ce7b6d..04851aaf1 100644 --- a/twrp.cpp +++ b/twrp.cpp @@ -46,6 +46,11 @@ extern "C" { #include "openrecoveryscript.hpp" #include "variables.h" +#ifdef HAVE_SELINUX +#include "selinux/label.h" +struct selabel_handle *selinux_handle; +#endif + TWPartitionManager PartitionManager; int Log_Offset; @@ -90,6 +95,17 @@ int main(int argc, char **argv) { // Load up all the resources gui_loadResources(); +#ifdef HAVE_SELINUX + struct selinux_opt selinux_options[] = { + { SELABEL_OPT_PATH, "/file_contexts" } + }; + selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1); + if (!selinux_handle) + printf("No file contexts for SELinux\n"); + else + printf("SELinux contexts loaded from /file_contexts\n"); +#endif + PartitionManager.Mount_By_Path("/cache", true); string Zip_File, Reboot_Value; -- cgit v1.2.3