summaryrefslogtreecommitdiffstats
path: root/partition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'partition.cpp')
-rw-r--r--partition.cpp61
1 files changed, 27 insertions, 34 deletions
diff --git a/partition.cpp b/partition.cpp
index 3f19b7d61..74271922f 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -53,6 +53,7 @@ extern "C" {
}
#ifdef HAVE_SELINUX
#include "selinux/selinux.h"
+#include <selinux/label.h>
#endif
using namespace std;
@@ -1344,17 +1345,25 @@ bool TWPartition::Wipe_EXT4() {
return false;
#if defined(HAVE_SELINUX) && defined(USE_EXT4)
+ int ret;
+ char *secontext = NULL;
+
gui_print("Formatting %s using make_ext4fs function.\n", Display_Name.c_str());
- if (make_ext4fs(Actual_Block_Device.c_str(), Length, Mount_Point.c_str(), selinux_handle) != 0) {
+
+ if (selabel_lookup(selinux_handle, &secontext, Mount_Point.c_str(), S_IFDIR) < 0) {
+ LOGINFO("Cannot lookup security context for '%s'\n", Mount_Point.c_str());
+ ret = make_ext4fs(Actual_Block_Device.c_str(), Length, Mount_Point.c_str(), NULL);
+ } else {
+ ret = make_ext4fs(Actual_Block_Device.c_str(), Length, Mount_Point.c_str(), selinux_handle);
+ }
+ if (ret != 0) {
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
@@ -1584,6 +1593,9 @@ bool TWPartition::Backup_Tar(string backup_folder) {
tar.use_encryption = use_encryption;
if (Use_Userdata_Encryption)
tar.userdata_encryption = use_encryption;
+ string Password;
+ DataManager::GetValue("tw_backup_password", Password);
+ tar.setpassword(Password);
} else {
use_encryption = false;
}
@@ -1672,37 +1684,18 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System)
return false;
Full_FileName = restore_folder + "/" + Backup_FileName;
- /*if (!TWFunc::Path_Exists(Full_FileName)) {
- if (!TWFunc::Path_Exists(Full_FileName)) {
- // Backup is multiple archives
- LOGINFO("Backup is multiple archives.\n");
- sprintf(split_index, "%03i", index);
- Full_FileName = restore_folder + "/" + Backup_FileName + split_index;
- while (TWFunc::Path_Exists(Full_FileName)) {
- index++;
- gui_print("Restoring archive %i...\n", index);
- LOGINFO("Restoring '%s'...\n", Full_FileName.c_str());
- twrpTar tar;
- tar.setdir("/");
- tar.setfn(Full_FileName);
- if (tar.extractTarFork() != 0)
- return false;
- sprintf(split_index, "%03i", index);
- Full_FileName = restore_folder + "/" + Backup_FileName + split_index;
- }
- if (index == 0) {
- LOGERR("Error locating restore file: '%s'\n", Full_FileName.c_str());
- return false;
- }
- }
- } else {*/
- twrpTar tar;
- tar.setdir(Backup_Path);
- tar.setfn(Full_FileName);
- tar.backup_name = Backup_Name;
- if (tar.extractTarFork() != 0)
- return false;
- //}
+ twrpTar tar;
+ tar.setdir(Backup_Path);
+ tar.setfn(Full_FileName);
+ tar.backup_name = Backup_Name;
+#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
+ string Password;
+ DataManager::GetValue("tw_restore_password", Password);
+ if (!Password.empty())
+ tar.setpassword(Password);
+#endif
+ if (tar.extractTarFork() != 0)
+ return false;
return true;
}