OSDN Git Service

Don't enable the SCO server socket when not necessary
[android-x86/external-bluetooth-bluez.git] / common / android_bluez.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <private/android_filesystem_config.h>
25 #include <sys/prctl.h>
26 #include <linux/capability.h>
27
28 /* Set UID to bluetooth w/ CAP_NET_RAW, CAP_NET_ADMIN and CAP_NET_BIND_SERVICE
29  * (Android's init.rc does not yet support applying linux capabilities) */
30 void android_set_aid_and_cap() {
31         prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
32         setuid(AID_BLUETOOTH);
33
34         struct __user_cap_header_struct header;
35         struct __user_cap_data_struct cap;
36         header.version = _LINUX_CAPABILITY_VERSION;
37         header.pid = 0;
38         cap.effective = cap.permitted = 1 << CAP_NET_RAW |
39                                         1 << CAP_NET_ADMIN |
40                                         1 << CAP_NET_BIND_SERVICE;
41         cap.inheritable = 0;
42         capset(&header, &cap);
43 }