Move permission checking code to it's own function.
Change-Id: Ibe46ca3043791f3b3815080f9e23ac307b1f5900
diff --git a/adb.c b/adb.c
index 6dbd562..ff9e92d 100644
--- a/adb.c
+++ b/adb.c
@@ -842,10 +842,39 @@
snprintf(target_str, target_size, "tcp:%d", server_port);
}
+#if !ADB_HOST
+static int should_drop_privileges() {
+ int secure = 0;
+ char value[PROPERTY_VALUE_MAX];
+
+ /* run adbd in secure mode if ro.secure is set and
+ ** we are not in the emulator
+ */
+ property_get("ro.kernel.qemu", value, "");
+ if (strcmp(value, "1") != 0) {
+ property_get("ro.secure", value, "1");
+ if (strcmp(value, "1") == 0) {
+ // don't run as root if ro.secure is set...
+ secure = 1;
+
+ // ... except we allow running as root in userdebug builds if the
+ // service.adb.root property has been set by the "adb root" command
+ property_get("ro.debuggable", value, "");
+ if (strcmp(value, "1") == 0) {
+ property_get("service.adb.root", value, "");
+ if (strcmp(value, "1") == 0) {
+ secure = 0;
+ }
+ }
+ }
+ }
+ return secure;
+}
+#endif /* !ADB_HOST */
+
int adb_main(int is_daemon, int server_port)
{
#if !ADB_HOST
- int secure = 0;
int port;
char value[PROPERTY_VALUE_MAX];
#endif
@@ -873,31 +902,10 @@
exit(1);
}
#else
- /* run adbd in secure mode if ro.secure is set and
- ** we are not in the emulator
- */
- property_get("ro.kernel.qemu", value, "");
- if (strcmp(value, "1") != 0) {
- property_get("ro.secure", value, "1");
- if (strcmp(value, "1") == 0) {
- // don't run as root if ro.secure is set...
- secure = 1;
-
- // ... except we allow running as root in userdebug builds if the
- // service.adb.root property has been set by the "adb root" command
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") == 0) {
- property_get("service.adb.root", value, "");
- if (strcmp(value, "1") == 0) {
- secure = 0;
- }
- }
- }
- }
/* don't listen on a port (default 5037) if running in secure mode */
/* don't run as root if we are running in secure mode */
- if (secure) {
+ if (should_drop_privileges()) {
struct __user_cap_header_struct header;
struct __user_cap_data_struct cap;