Skip to content

Commit

Permalink
adb: handle adbd auth in recovery mode
Browse files Browse the repository at this point in the history
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 27, 2013
1 parent 74341a3 commit 1ec4e7b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
6 changes: 1 addition & 5 deletions etc/init.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1ec4e7b

Please sign in to comment.