Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [RFC 12/16] android: Add cap to bind to port < 1024
Date: Mon, 30 Sep 2013 09:36:54 +0200	[thread overview]
Message-ID: <7348700.bQ9Re4jemt@uw000953> (raw)
In-Reply-To: <1380291161-10232-13-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> For SDP server we need to bind to lower port, acquire this capability.
> ---
>  android/main.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  configure.ac   |    4 ++++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/android/main.c b/android/main.c
> index 5fef095..649867d 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -31,6 +31,19 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <sys/prctl.h>
> +#include <linux/capability.h>
> +
> +/**
> + * Include <sys/capability.h> for host build and
> + * also for Android 4.3 when it is added to bionic
> + */
> +#if (defined(__ANDROID_API__) && (__ANDROID_API__ > 17)) || \
> +					!defined(__ANDROID_API__)
> +#include <sys/capability.h>
> +#endif
>  
>  #include <glib.h>
>  
> @@ -319,6 +332,43 @@ static void cleanup_mgmt_interface(void)
>  	mgmt_if = NULL;
>  }
>  
> +static bool android_set_aid_and_cap()
> +{
> +	struct __user_cap_header_struct header;
> +	struct __user_cap_data_struct cap;
> +
> +	DBG("%s: pid %d uid %d gid %d", __func__, getpid(), getuid(), getgid());

DBG macro already adds function name to string so there is no need to double
that. This applies to other places as well.

> +
> +	header.version = _LINUX_CAPABILITY_VERSION;
> +	header.pid = getpid();
> +	if (capget(&header, &cap) < 0)
> +		error("%s: capget(): %s", __func__, strerror(errno));
> +
> +	DBG("%s: Cap data 0x%x, 0x%x, 0x%x\n", __func__, cap.effective,
> +					cap.permitted, cap.inheritable);
> +
> +	prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
> +
> +	header.version = _LINUX_CAPABILITY_VERSION;
> +	header.pid = 0;
> +
> +	cap.effective = cap.permitted = cap.inheritable =
> +		1 << CAP_NET_RAW |
> +		1 << CAP_NET_ADMIN |
> +		1 << CAP_NET_BIND_SERVICE |
> +		1 << CAP_SYS_RAWIO |
> +		1 << CAP_SYS_NICE |
> +		1 << CAP_SETGID;
> +
> +	if (capset(&header, &cap)) {
> +		error("%s: capset(): %s", __func__, strerror(errno));
> +		return false;
> +	}
> +
> +	DBG("%s: capset(): Success", __func__);
> +	return true;
> +}
> +
>  int main(int argc, char *argv[])
>  {
>  	GOptionContext *context;
> @@ -357,6 +407,9 @@ int main(int argc, char *argv[])
>  	/* no need to keep parsed option in memory */
>  	free_options();
>  
> +	if (android_set_aid_and_cap() == false)
> +		exit(1);
> +
>  	init_mgmt_interface();
>  
>  	DBG("Entering main loop");
> diff --git a/configure.ac b/configure.ac
> index 3b7a5d9..af418d3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -247,4 +247,8 @@ AC_ARG_ENABLE(android-daemon, AC_HELP_STRING([--enable-android-daemon],
>  					[android_daemon=${enableval}])
>  AM_CONDITIONAL(ANDROID_DAEMON, test "${android_daemon}" = "yes")
>  
> +if (test "${android_daemon}" = "yes"); then
> +	AC_CHECK_LIB(cap, capget, dummy=yes, AC_MSG_ERROR(libcap is required))
> +fi
> +
>  AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
> 

-- 
BR
Szymon Janc



  parent reply	other threads:[~2013-09-30  7:36 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 14:12 [RFC 00/16] Basic code for Android BlueZ Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 01/16] android: Add Adapter Bluetooth HAL template Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 02/16] android: Add Socket " Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 03/16] android: Enable Socket interface Andrei Emeltchenko
2013-09-27 16:04   ` Anderson Lizardo
2013-09-27 14:12 ` [RFC 04/16] android: Start Android Bluetooth daemon Andrei Emeltchenko
2013-09-29 13:28   ` Marcel Holtmann
2013-09-30  7:07     ` Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 05/16] android: Add Android Makefile for mgmt library Andrei Emeltchenko
2013-09-29 13:34   ` Marcel Holtmann
2013-09-27 14:12 ` [RFC 06/16] android: Add basic mgmt initialization sequence Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 07/16] android: Create HAL API header skeleton Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 08/16] android: Add Android HAL callback task Andrei Emeltchenko
2013-09-29 13:22   ` Marcel Holtmann
2013-09-27 14:12 ` [RFC 09/16] android: Add adapter and device struct for BlueZ daemon Andrei Emeltchenko
2013-09-27 17:07   ` Anderson Lizardo
2013-09-29 13:38   ` Marcel Holtmann
2013-09-30  7:28     ` Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 10/16] android: Add Android Makefile for libbluetooth Andrei Emeltchenko
2013-09-27 18:01   ` Anderson Lizardo
2013-09-30  7:32     ` Andrei Emeltchenko
2013-09-30 12:14       ` Szymon Janc
2013-09-27 14:12 ` [RFC 11/16] android: sdp: Reuse BlueZ SDP server in Android Andrei Emeltchenko
2013-09-29 13:31   ` Marcel Holtmann
2013-09-30  7:45     ` Szymon Janc
2013-09-30  7:47     ` Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 12/16] android: Add cap to bind to port < 1024 Andrei Emeltchenko
2013-09-27 17:17   ` Anderson Lizardo
2013-09-27 17:21     ` Anderson Lizardo
2013-09-29 13:40   ` Marcel Holtmann
2013-09-30  7:36   ` Szymon Janc [this message]
2013-09-30  7:51     ` Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 13/16] android: Implement read_info_complete callback Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 14/16] android: Handle mgmt changed events Andrei Emeltchenko
2013-09-27 17:59   ` Anderson Lizardo
2013-09-27 14:12 ` [RFC 15/16] android: Implement basic HAL server Andrei Emeltchenko
2013-09-27 17:50   ` Anderson Lizardo
2013-09-30  8:25     ` Andrei Emeltchenko
2013-09-30  8:33       ` Marcel Holtmann
2013-09-30 10:26         ` Andrei Emeltchenko
2013-09-29 14:59   ` Johan Hedberg
2013-09-30  8:42     ` Andrei Emeltchenko
2013-09-27 14:12 ` [RFC 16/16] android: Add HAL message helpers Andrei Emeltchenko
2013-09-29 15:00   ` Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7348700.bQ9Re4jemt@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=Andrei.Emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox