diff options
Diffstat (limited to 'recovery.c')
-rw-r--r-- | recovery.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/recovery.c b/recovery.c index 087258fe8..2454a07d8 100644 --- a/recovery.c +++ b/recovery.c @@ -36,12 +36,14 @@ #include "minzip/DirUtil.h" #include "roots.h" #include "recovery_ui.h" +#include "encryptedfs_provisioning.h" static const struct option OPTIONS[] = { { "send_intent", required_argument, NULL, 's' }, { "update_package", required_argument, NULL, 'u' }, { "wipe_data", no_argument, NULL, 'w' }, { "wipe_cache", no_argument, NULL, 'c' }, + { "set_encrypted_filesystems", required_argument, NULL, 'e' }, { NULL, 0, NULL, 0 }, }; @@ -108,9 +110,9 @@ static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; * -- after this, rebooting will (try to) restart the main system -- * 9. main() calls reboot() to boot main system * - * ENCRYPTED FILE SYSTEMS ENABLE/DISABLE + * SECURE FILE SYSTEMS ENABLE/DISABLE * 1. user selects "enable encrypted file systems" - * 2. main system writes "--set_encrypted_filesystem=on|off" to + * 2. main system writes "--set_encrypted_filesystems=on|off" to * /cache/recovery/command * 3. main system reboots into recovery * 4. get_args() writes BCB with "boot-recovery" and @@ -468,7 +470,10 @@ main(int argc, char **argv) { int previous_runs = 0; const char *send_intent = NULL; const char *update_package = NULL; + const char *encrypted_fs_mode = NULL; int wipe_data = 0, wipe_cache = 0; + int toggle_secure_fs = 0; + encrypted_fs_info encrypted_fs_data; int arg; while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) { @@ -478,6 +483,7 @@ main(int argc, char **argv) { case 'u': update_package = optarg; break; case 'w': wipe_data = wipe_cache = 1; break; case 'c': wipe_cache = 1; break; + case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break; case '?': LOGE("Invalid command argument\n"); continue; @@ -497,7 +503,43 @@ main(int argc, char **argv) { int status = INSTALL_SUCCESS; - if (update_package != NULL) { + if (toggle_secure_fs) { + if (strcmp(encrypted_fs_mode,"on") == 0) { + encrypted_fs_data.mode = MODE_ENCRYPTED_FS_ENABLED; + ui_print("Enabling Encrypted FS.\n"); + } else if (strcmp(encrypted_fs_mode,"off") == 0) { + encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED; + ui_print("Disabling Encrypted FS.\n"); + } else { + ui_print("Error: invalid Encrypted FS setting.\n"); + status = INSTALL_ERROR; + } + + // Recovery strategy: if the data partition is damaged, disable encrypted file systems. + // This preventsthe device recycling endlessly in recovery mode. + if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) && + (read_encrypted_fs_info(&encrypted_fs_data))) { + ui_print("Encrypted FS change aborted, resetting to disabled state.\n"); + encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED; + } + + if (status != INSTALL_ERROR) { + if (erase_root("DATA:")) { + ui_print("Data wipe failed.\n"); + status = INSTALL_ERROR; + } else if (erase_root("CACHE:")) { + ui_print("Cache wipe failed.\n"); + status = INSTALL_ERROR; + } else if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) && + (restore_encrypted_fs_info(&encrypted_fs_data))) { + ui_print("Encrypted FS change aborted.\n"); + status = INSTALL_ERROR; + } else { + ui_print("Successfully updated Encrypted FS.\n"); + status = INSTALL_SUCCESS; + } + } + } else if (update_package != NULL) { status = install_package(update_package); if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n"); } else if (wipe_data) { |