summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--partition.cpp46
-rw-r--r--twrpTar.cpp23
-rw-r--r--twrpTar.hpp3
3 files changed, 27 insertions, 45 deletions
diff --git a/partition.cpp b/partition.cpp
index b597695e2..74271922f 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -1593,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;
}
@@ -1681,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;
}
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 824356aae..ee9d9dcb7 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -21,7 +21,6 @@ extern "C" {
#include "libtar/libtar.h"
#include "twrpTar.h"
#include "tarWrite.h"
- #include "libcrecovery/common.h"
}
#include <sys/types.h>
#include <sys/stat.h>
@@ -39,7 +38,6 @@ extern "C" {
#include <sys/mman.h>
#include "twrpTar.hpp"
#include "twcommon.h"
-#include "data.hpp"
#include "variables.h"
#include "twrp-functions.hpp"
@@ -77,6 +75,10 @@ void twrpTar::setsize(unsigned long long backup_size) {
Total_Backup_Size = backup_size;
}
+void twrpTar::setpassword(string pass) {
+ password = pass;
+}
+
int twrpTar::createTarFork() {
int status = 0;
pid_t pid, rc_pid;
@@ -529,9 +531,7 @@ int twrpTar::extract() {
int ret = extractTar();
return ret;
} else if (Archive_Current_Type == 2) {
- string Password;
- DataManager::GetValue("tw_restore_password", Password);
- int ret = TWFunc::Try_Decrypting_File(tarfn, Password);
+ int ret = TWFunc::Try_Decrypting_File(tarfn, password);
if (ret < 1) {
LOGERR("Failed to decrypt tar file '%s'\n", tarfn.c_str());
return -1;
@@ -675,13 +675,11 @@ int twrpTar::createTar() {
char* charTarFile = (char*) tarfn.c_str();
char* charRootDir = (char*) tardir.c_str();
static tartype_t type = { open, close, read, write_tar };
- string Password;
if (use_encryption && use_compression) {
// Compressed and encrypted
Archive_Current_Type = 3;
LOGINFO("Using encryption and compression...\n");
- DataManager::GetValue("tw_backup_password", Password);
int i, pipes[4];
if (pipe(pipes) < 0) {
@@ -738,7 +736,7 @@ int twrpTar::createTar() {
dup2(pipes[2], 0);
close(1);
dup2(output_fd, 1);
- if (execlp("openaes", "openaes", "enc", "--key", Password.c_str(), NULL) < 0) {
+ if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) {
LOGERR("execlp openaes ERROR!\n");
close(pipes[2]);
close(output_fd);
@@ -806,7 +804,6 @@ int twrpTar::createTar() {
// Encrypted
Archive_Current_Type = 2;
LOGINFO("Using encryption...\n");
- DataManager::GetValue("tw_backup_password", Password);
int oaesfd[2];
pipe(oaesfd);
oaes_pid = fork();
@@ -826,7 +823,7 @@ int twrpTar::createTar() {
}
dup2(oaesfd[0], 0); // remap stdin
dup2(output_fd, 1); // remap stdout to output file
- if (execlp("openaes", "openaes", "enc", "--key", Password.c_str(), NULL) < 0) {
+ if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) {
LOGERR("execlp openaes ERROR!\n");
close(output_fd);
close(oaesfd[0]);
@@ -861,7 +858,6 @@ int twrpTar::openTar() {
if (Archive_Current_Type == 3) {
LOGINFO("Opening encrypted and compressed backup...\n");
- DataManager::GetValue("tw_restore_password", Password);
int i, pipes[4];
if (pipe(pipes) < 0) {
@@ -894,7 +890,7 @@ int twrpTar::openTar() {
dup2(input_fd, 0);
close(1);
dup2(pipes[1], 1);
- if (execlp("openaes", "openaes", "dec", "--key", Password.c_str(), NULL) < 0) {
+ if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) {
LOGERR("execlp openaes ERROR!\n");
close(input_fd);
close(pipes[1]);
@@ -938,7 +934,6 @@ int twrpTar::openTar() {
}
} else if (Archive_Current_Type == 2) {
LOGINFO("Opening encrypted backup...\n");
- DataManager::GetValue("tw_restore_password", Password);
int oaesfd[2];
pipe(oaesfd);
@@ -960,7 +955,7 @@ int twrpTar::openTar() {
close(0); // close stdin
dup2(oaesfd[1], 1); // remap stdout
dup2(input_fd, 0); // remap input fd to stdin
- if (execlp("openaes", "openaes", "dec", "--key", Password.c_str(), NULL) < 0) {
+ if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) {
LOGERR("execlp openaes ERROR!\n");
close(input_fd);
close(oaesfd[1]);
diff --git a/twrpTar.hpp b/twrpTar.hpp
index 17f69594d..02d4b8004 100644
--- a/twrpTar.hpp
+++ b/twrpTar.hpp
@@ -51,6 +51,8 @@ public:
void setfn(string fn);
void setdir(string dir);
void setsize(unsigned long long backup_size);
+ void setpassword(string pass);
+
unsigned long long uncompressedSize();
public:
@@ -89,6 +91,7 @@ private:
string tardir;
string tarfn;
string basefn;
+ string password;
vector <string> tarexclude;