[RFC v2 5/6] android: Change user to bluetooth when starting daemon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 android/main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/android/main.c b/android/main.c
index 6324f31..8983a84 100644
--- a/android/main.c
+++ b/android/main.c
@@ -38,6 +38,7 @@
 #include <sys/signalfd.h>
 #if defined(ANDROID)
 #include <sys/capability.h>
+#include <linux/prctl.h>
 #endif
 
 #include <glib.h>
@@ -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));
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux