Move permission checking code to it's own function.

Change-Id: Ibe46ca3043791f3b3815080f9e23ac307b1f5900
This commit is contained in:
Nick Kralevich 2012-01-19 10:18:59 -08:00
parent abc12070d0
commit bd9206bc73
1 changed files with 31 additions and 23 deletions

View File

@ -842,10 +842,39 @@ void build_local_name(char* target_str, size_t target_size, int server_port)
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 @@ int adb_main(int is_daemon, int server_port)
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;