Merge "fix getting and setting contexts in selinux" into android-4.3
This commit is contained in:
@@ -92,29 +92,22 @@ tar_append_file(TAR *t, char *realname, char *savename)
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
/* get selinux context */
|
||||
if(t->options & TAR_STORE_SELINUX)
|
||||
{
|
||||
if(t->th_buf.selinux_context != NULL)
|
||||
{
|
||||
if(t->options & TAR_STORE_SELINUX) {
|
||||
if(t->th_buf.selinux_context != NULL) {
|
||||
free(t->th_buf.selinux_context);
|
||||
t->th_buf.selinux_context = NULL;
|
||||
}
|
||||
|
||||
security_context_t selinux_context = NULL;
|
||||
if(getfilecon(realname, &selinux_context) >= 0)
|
||||
{
|
||||
if (lgetfilecon(realname, &selinux_context) >= 0) {
|
||||
t->th_buf.selinux_context = strdup(selinux_context);
|
||||
printf("setting selinux context: %s\n", selinux_context);
|
||||
freecon(selinux_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
perror("Failed to get selinux context");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check if it's a hardlink */
|
||||
#ifdef DEBUG
|
||||
puts(" tar_append_file(): checking inode cache for hardlink...");
|
||||
|
||||
@@ -161,8 +161,9 @@ tar_extract_file(TAR *t, char *realname, char *prefix)
|
||||
#ifdef DEBUG
|
||||
printf(" Restoring SELinux context %s to file %s\n", t->th_buf.selinux_context, realname);
|
||||
#endif
|
||||
if(setfilecon(realname, t->th_buf.selinux_context) < 0)
|
||||
if (lsetfilecon(realname, t->th_buf.selinux_context) < 0) {
|
||||
fprintf(stderr, "Failed to restore SELinux context %s!\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ extern "C" {
|
||||
#include "make_ext4fs.h"
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_SELINUX
|
||||
#include "selinux/selinux.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -1272,6 +1275,12 @@ bool TWPartition::Wipe_EXT4() {
|
||||
LOGERR("Unable to wipe '%s' using function call.\n", Mount_Point.c_str());
|
||||
return false;
|
||||
} else {
|
||||
#ifdef HAVE_SELINUX
|
||||
string sedir = Mount_Point + "/lost+found";
|
||||
PartitionManager.Mount_By_Path(sedir.c_str(), true);
|
||||
rmdir(sedir.c_str());
|
||||
mkdir(sedir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -901,7 +901,6 @@ int TWPartitionManager::Run_Restore(string Restore_Name) {
|
||||
end_pos = Restore_List.find(";", start_pos);
|
||||
}
|
||||
}
|
||||
|
||||
TWFunc::GUI_Operation_Text(TW_UPDATE_SYSTEM_DETAILS_TEXT, "Updating System Details");
|
||||
Update_System_Details();
|
||||
UnMount_Main_Partitions();
|
||||
|
||||
10
twrp.cpp
10
twrp.cpp
@@ -104,10 +104,18 @@ int main(int argc, char **argv) {
|
||||
gui_loadResources();
|
||||
|
||||
#ifdef HAVE_SELINUX
|
||||
if (TWFunc::Path_Exists("/prebuilt_file_contexts")) {
|
||||
if (TWFunc::Path_Exists("/file_contexts")) {
|
||||
printf("Renaming regular /file_contexts -> /file_contexts.bak\n");
|
||||
rename("/file_contexts", "/file_contexts.bak");
|
||||
}
|
||||
printf("Moving /prebuilt_file_contexts -> /file_contexts\n");
|
||||
rename("/prebuilt_file_contexts", "/file_contexts");
|
||||
}
|
||||
struct selinux_opt selinux_options[] = {
|
||||
{ SELABEL_OPT_PATH, "/file_contexts" }
|
||||
};
|
||||
selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
|
||||
selinux_handle = selabel_open(SELABEL_CTX_FILE, selinux_options, 1);
|
||||
if (!selinux_handle)
|
||||
printf("No file contexts for SELinux\n");
|
||||
else
|
||||
|
||||
@@ -34,6 +34,7 @@ extern "C" {
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/mman.h>
|
||||
#include "twrpTar.hpp"
|
||||
#include "twcommon.h"
|
||||
@@ -532,7 +533,7 @@ int twrpTar::Generate_Multiple_Archives(string Path) {
|
||||
continue; // Skip /data/media
|
||||
if (de->d_type == DT_BLK || de->d_type == DT_CHR)
|
||||
continue;
|
||||
if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+foud") != 0)
|
||||
if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
|
||||
{
|
||||
unsigned long long folder_size = TWFunc::Get_Folder_Size(FileName, false);
|
||||
if (Archive_Current_Size + folder_size > MAX_ARCHIVE_SIZE) {
|
||||
@@ -717,7 +718,11 @@ int twrpTar::tarDirs(bool include_root) {
|
||||
if (strcmp(de->d_name, ".") != 0) {
|
||||
subfolder += de->d_name;
|
||||
} else {
|
||||
LOGINFO("addFile '%s' including root: %i\n", buf, include_root);
|
||||
std::string parentDir = basename(subfolder.c_str());
|
||||
LOGINFO("parentDir: %s\n", parentDir.c_str());
|
||||
if (!parentDir.compare("lost+found"))
|
||||
continue;
|
||||
LOGINFO("tarDirs addFile '%s' including root: %i\n", subfolder.c_str(), include_root);
|
||||
if (addFile(subfolder, include_root) != 0)
|
||||
return -1;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user