From 4ae70ba552e775f3a75f623e09674fd6b040f761 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 17 Jan 2014 16:30:45 +0100 Subject: [PATCH] android: Change user to bluetooth when starting daemon --- android/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/android/main.c b/android/main.c index 6324f315f..8983a8434 100644 --- a/android/main.c +++ b/android/main.c @@ -38,6 +38,7 @@ #include #if defined(ANDROID) #include +#include #endif #include @@ -350,6 +351,18 @@ static bool set_capabilities(void) CAP_TO_MASK(CAP_NET_BIND_SERVICE); cap.inheritable = 0; + /* don't clear capabilities when dropping root */ + if (prctl(PR_SET_KEEPCAPS, 1) < 0) { + error("%s: prctl(): %s", __func__,strerror(errno)); + return false; + } + + /* Android bluetooth user UID=1002 */ + if (setuid(1002) < 0) { + error("%s: setuid(): %s", __func__, strerror(errno)); + return false; + } + /* TODO: Move to cap_set_proc once bionic support it */ if (capset(&header, &cap) < 0) { error("%s: capset(): %s", __func__, strerror(errno)); -- 2.47.3