summaryrefslogtreecommitdiffstats
path: root/twrpTar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'twrpTar.cpp')
-rw-r--r--twrpTar.cpp55
1 files changed, 9 insertions, 46 deletions
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 824356aae..cc09b78ab 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]);
@@ -1119,38 +1114,6 @@ int twrpTar::entryExists(string entry) {
return ret;
}
-unsigned long long twrpTar::uncompressedSize() {
- int type = 0;
- unsigned long long total_size = 0;
- string Tar, Command, result;
- vector<string> split;
-
- Tar = TWFunc::Get_Filename(tarfn);
- type = TWFunc::Get_File_Type(tarfn);
- if (type == 0)
- total_size = TWFunc::Get_File_Size(tarfn);
- else {
- Command = "pigz -l " + tarfn;
- /* if we set Command = "pigz -l " + tarfn + " | sed '1d' | cut -f5 -d' '";
- we get the uncompressed size at once. */
- TWFunc::Exec_Cmd(Command, result);
- if (!result.empty()) {
- /* Expected output:
- compressed original reduced name
- 95855838 179403776 -1.3% data.yaffs2.win
- ^
- split[5]
- */
- split = TWFunc::split_string(result, ' ', true);
- if (split.size() > 4)
- total_size = atoi(split[5].c_str());
- }
- }
- LOGINFO("%s's uncompressed size: %llu bytes\n", Tar.c_str(), total_size);
-
- return total_size;
-}
-
extern "C" ssize_t write_tar(int fd, const void *buffer, size_t size) {
return (ssize_t) write_libtar_buffer(fd, buffer, size);
}