summaryrefslogtreecommitdiffstats
path: root/adb/set_verity_enable_state_service.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-09-23 15:40:03 -0700
committerElliott Hughes <enh@google.com>2016-09-26 13:14:14 -0700
commitffdec180176094dac0fb902263370dea1deb138f (patch)
treefb211879d041f4383aec1e51fec8fd16b55d1e3a /adb/set_verity_enable_state_service.cpp
parent3f049c3f1916070f07bc4cfab3f0b3609f9b83e6 (diff)
downloadsystem_core-ffdec180176094dac0fb902263370dea1deb138f.tar.gz
system_core-ffdec180176094dac0fb902263370dea1deb138f.tar.bz2
system_core-ffdec180176094dac0fb902263370dea1deb138f.zip
Switch adb to <android-base/properties.h>.
Bug: http://b/23102347 Test: manual Change-Id: Iffa66258c01f84f41b9af99ab5e768a0a2669106
Diffstat (limited to 'adb/set_verity_enable_state_service.cpp')
-rw-r--r--adb/set_verity_enable_state_service.cpp81
1 files changed, 36 insertions, 45 deletions
diff --git a/adb/set_verity_enable_state_service.cpp b/adb/set_verity_enable_state_service.cpp
index f5188e94f..ae628e4bd 100644
--- a/adb/set_verity_enable_state_service.cpp
+++ b/adb/set_verity_enable_state_service.cpp
@@ -24,16 +24,17 @@
#include <stdio.h>
#include <sys/stat.h>
-#include "cutils/properties.h"
+#include "android-base/properties.h"
+#include "android-base/stringprintf.h"
#include "adb.h"
#include "adb_io.h"
+#include "adb_unique_fd.h"
#include "fs_mgr.h"
#include "remount_service.h"
#include "fec/io.h"
-#define FSTAB_PREFIX "/fstab."
struct fstab *fstab;
#ifdef ALLOW_ADBD_DISABLE_VERITY
@@ -88,56 +89,46 @@ static int set_verity_enabled_state(int fd, const char *block_device,
return 0;
}
-void set_verity_enabled_state_service(int fd, void* cookie)
-{
+void set_verity_enabled_state_service(int fd, void* cookie) {
+ unique_fd closer(fd);
+
bool enable = (cookie != NULL);
- if (kAllowDisableVerity) {
- char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
- char propbuf[PROPERTY_VALUE_MAX];
- int i;
- bool any_changed = false;
-
- property_get("ro.secure", propbuf, "0");
- if (strcmp(propbuf, "1")) {
- WriteFdFmt(fd, "verity not enabled - ENG build\n");
- goto errout;
- }
+ if (!kAllowDisableVerity) {
+ WriteFdFmt(fd, "%s-verity only works for userdebug builds\n",
+ enable ? "enable" : "disable");
+ }
- property_get("ro.debuggable", propbuf, "0");
- if (strcmp(propbuf, "1")) {
- WriteFdFmt(fd, "verity cannot be disabled/enabled - USER build\n");
- goto errout;
- }
+ if (!android::base::GetBoolProperty("ro.secure", false)) {
+ WriteFdFmt(fd, "verity not enabled - ENG build\n");
+ return;
+ }
- property_get("ro.hardware", propbuf, "");
- snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s",
- propbuf);
+ if (!android::base::GetBoolProperty("ro.debuggable", false)) {
+ WriteFdFmt(fd, "verity cannot be disabled/enabled - USER build\n");
+ return;
+ }
- fstab = fs_mgr_read_fstab(fstab_filename);
- if (!fstab) {
- WriteFdFmt(fd, "Failed to open %s\nMaybe run adb root?\n", fstab_filename);
- goto errout;
- }
+ std::string fstab_filename = "/fstab." + android::base::GetProperty("ro.hardware", "");
- /* Loop through entries looking for ones that vold manages */
- for (i = 0; i < fstab->num_entries; i++) {
- if(fs_mgr_is_verified(&fstab->recs[i])) {
- if (!set_verity_enabled_state(fd, fstab->recs[i].blk_device,
- fstab->recs[i].mount_point,
- enable)) {
- any_changed = true;
- }
- }
- }
+ fstab = fs_mgr_read_fstab(fstab_filename.c_str());
+ if (!fstab) {
+ WriteFdFmt(fd, "Failed to open %s\nMaybe run adb root?\n", fstab_filename.c_str());
+ return;
+ }
- if (any_changed) {
- WriteFdFmt(fd, "Now reboot your device for settings to take effect\n");
+ // Loop through entries looking for ones that vold manages.
+ bool any_changed = false;
+ for (int i = 0; i < fstab->num_entries; i++) {
+ if (fs_mgr_is_verified(&fstab->recs[i])) {
+ if (!set_verity_enabled_state(fd, fstab->recs[i].blk_device,
+ fstab->recs[i].mount_point,
+ enable)) {
+ any_changed = true;
+ }
}
- } else {
- WriteFdFmt(fd, "%s-verity only works for userdebug builds\n",
- enable ? "enable" : "disable");
}
-errout:
- adb_close(fd);
+ if (any_changed) {
+ WriteFdFmt(fd, "Now reboot your device for settings to take effect\n");
+ }
}