summaryrefslogtreecommitdiffstats
path: root/uncrypt/uncrypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'uncrypt/uncrypt.cpp')
-rw-r--r--uncrypt/uncrypt.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp
index 21db29026..904ddad1b 100644
--- a/uncrypt/uncrypt.cpp
+++ b/uncrypt/uncrypt.cpp
@@ -107,12 +107,12 @@
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h>
#include <cutils/android_reboot.h>
-#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <fs_mgr.h>
@@ -163,13 +163,15 @@ static struct fstab* read_fstab() {
fstab = NULL;
// The fstab path is always "/fstab.${ro.hardware}".
- char fstab_path[PATH_MAX+1] = "/fstab.";
- if (!property_get("ro.hardware", fstab_path+strlen(fstab_path), "")) {
+ std::string ro_hardware = android::base::GetProperty("ro.hardware", "");
+ if (ro_hardware.empty()) {
LOG(ERROR) << "failed to get ro.hardware";
return NULL;
}
- fstab = fs_mgr_read_fstab(fstab_path);
+ std::string fstab_path = "/fstab." + ro_hardware;
+
+ fstab = fs_mgr_read_fstab(fstab_path.c_str());
if (!fstab) {
LOG(ERROR) << "failed to read " << fstab_path;
return NULL;
@@ -194,9 +196,7 @@ static const char* find_block_device(const char* path, bool* encryptable, bool*
*encryptable = false;
if (fs_mgr_is_encryptable(v) || fs_mgr_is_file_encrypted(v)) {
*encryptable = true;
- char buffer[PROPERTY_VALUE_MAX+1];
- if (property_get("ro.crypto.state", buffer, "") &&
- strcmp(buffer, "encrypted") == 0) {
+ if (android::base::GetProperty("ro.crypto.state", "") == "encrypted") {
*encrypted = true;
}
}
@@ -208,6 +208,11 @@ static const char* find_block_device(const char* path, bool* encryptable, bool*
}
static bool write_status_to_socket(int status, int socket) {
+ // If socket equals -1, uncrypt is in debug mode without socket communication.
+ // Skip writing and return success.
+ if (socket == -1) {
+ return true;
+ }
int status_out = htonl(status);
return android::base::WriteFully(socket, &status_out, sizeof(int));
}
@@ -557,7 +562,7 @@ static void usage(const char* exename) {
}
int main(int argc, char** argv) {
- enum { UNCRYPT, SETUP_BCB, CLEAR_BCB } action;
+ enum { UNCRYPT, SETUP_BCB, CLEAR_BCB, UNCRYPT_DEBUG } action;
const char* input_path = nullptr;
const char* map_file = CACHE_BLOCK_MAP.c_str();
@@ -570,7 +575,7 @@ int main(int argc, char** argv) {
} else if (argc == 3) {
input_path = argv[1];
map_file = argv[2];
- action = UNCRYPT;
+ action = UNCRYPT_DEBUG;
} else {
usage(argv[0]);
return 2;
@@ -580,6 +585,17 @@ int main(int argc, char** argv) {
return 1;
}
+ if (action == UNCRYPT_DEBUG) {
+ LOG(INFO) << "uncrypt called in debug mode, skip socket communication";
+ bool success = uncrypt_wrapper(input_path, map_file, -1);
+ if (success) {
+ LOG(INFO) << "uncrypt succeeded";
+ } else{
+ LOG(INFO) << "uncrypt failed";
+ }
+ return success ? 0 : 1;
+ }
+
// c3. The socket is created by init when starting the service. uncrypt
// will use the socket to communicate with its caller.
android::base::unique_fd service_socket(android_get_control_socket(UNCRYPT_SOCKET.c_str()));