Skip to content
Permalink
Browse files

adb: handle adbd auth in recovery mode

If /data/misc/adb/adb_keys exists, copy it to /adb_keys, set property
for secure adb, and restart the adbd daemon.

Change-Id: I2f826d4c1f6a49cb0959c9cd1a803cb10ec4e408
  • Loading branch information...
jt1134 authored and pawitp committed Feb 26, 2013
1 parent 74341a3 commit 1ec4e7bddeadeb244d4f5e55d59b2d994e7c7d0f
Showing with 36 additions and 5 deletions.
  1. +1 −5 etc/init.rc
  2. +35 −0 recovery.c
@@ -52,11 +52,7 @@ service recovery /sbin/recovery
service adbd /sbin/adbd recovery
disabled

# Always start adbd on userdebug and eng builds
on property:ro.debuggable=1
write /sys/class/android_usb/android0/enable 1
start adbd
setprop service.adb.root 1
# Recovery will start adb once it has checked the keys

# Restart adbd so it can run as root
on property:service.adb.root=1
@@ -751,6 +751,39 @@ print_property(const char *key, const char *name, void *cookie) {
printf("%s=%s\n", key, name);
}

static void
setup_adbd() {
struct stat f;
static char *key_src = "/data/misc/adb/adb_keys";
static char *key_dest = "/adb_keys";

// Mount /data and copy adb_keys to root if it exists
ensure_path_mounted("/data");
if (stat(key_src, &f) == 0) {
FILE *file_src = fopen(key_src, "r");
if (file_src == NULL) {
LOGE("Can't open %s\n", key_src);
} else {
FILE *file_dest = fopen(key_dest, "w");
if (file_dest == NULL) {
LOGE("Can't open %s\n", key_dest);
} else {
char buf[4096];
while (fgets(buf, sizeof(buf), file_src)) fputs(buf, file_dest);
check_and_fclose(file_dest, key_dest);

// Enable secure adbd
property_set("ro.adb.secure", "1");
}
check_and_fclose(file_src, key_src);
}
}
ensure_path_unmounted("/data");

// Trigger (re)start of adb daemon
property_set("service.adb.root", "1");
}

int
main(int argc, char **argv) {

@@ -912,6 +945,8 @@ main(int argc, char **argv) {
}
}

setup_adbd();

if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) {
ui_set_show_text(1);
ui_set_background(BACKGROUND_ICON_ERROR);

0 comments on commit 1ec4e7b

Please sign in to comment.
You can’t perform that action at this time.