From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 04/10] alfred: Add CAP_NET_ADMIN capabilities for netlink
Date: Sun, 5 Jun 2016 20:47:02 +0200 [thread overview]
Message-ID: <1465152428-17299-4-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1465152428-17299-1-git-send-email-sven@narfation.org>
The batman_adv netlink family requires CAP_NET_ADMIN capabilities to query
the debugging tables.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
README | 8 ++++----
batadv_query.c | 3 +++
main.c | 12 ++++++++++++
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/README b/README
index 2a015b8..bc1c3bc 100644
--- a/README
+++ b/README
@@ -277,11 +277,11 @@ Operations requiring special capabilities:
* accessing the debugfs filesystem
The first operation can still be executed when the admin grants the special
-capability CAP_NET_RAW to anyone executing the alfred binary. The unix socket
-can also be moved using the parameter '-u' to a different directory which can
-be accessed by the user.
+capability CAP_NET_RAW+CAP_NET_ADMIN to anyone executing the alfred binary.
+The unix socket can also be moved using the parameter '-u' to a different
+directory which can be accessed by the user.
- $ sudo setcap cap_net_raw+ep alfred
+ $ sudo setcap cap_net_admin,cap_net_raw+ep alfred
$ ./alfred -u alfred.sock -i eth0
The user running alfred must still be in a group which is allowed to access
diff --git a/batadv_query.c b/batadv_query.c
index a5fa565..d917242 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef CONFIG_ALFRED_CAPABILITIES
+#include <sys/capability.h>
+#endif
#include <sys/types.h>
#include "debugfs.h"
diff --git a/main.c b/main.c
index 52dca97..9cab705 100644
--- a/main.c
+++ b/main.c
@@ -77,6 +77,7 @@ static int reduce_capabilities(void)
cap_t cap_new;
cap_flag_value_t cap_flag;
cap_value_t cap_net_raw = CAP_NET_RAW;
+ cap_value_t cap_net_admin = CAP_NET_ADMIN;
/* get current process capabilities */
cap_cur = cap_get_proc();
@@ -105,6 +106,17 @@ static int reduce_capabilities(void)
}
}
+ cap_flag = CAP_CLEAR;
+ cap_get_flag(cap_cur, CAP_NET_ADMIN, CAP_PERMITTED, &cap_flag);
+ if (cap_flag != CAP_CLEAR) {
+ ret = cap_set_flag(cap_new, CAP_PERMITTED, 1, &cap_net_admin,
+ CAP_SET);
+ if (ret < 0) {
+ perror("cap_set_flag");
+ goto out;
+ }
+ }
+
/* set minimal capabilities field */
ret = cap_set_proc(cap_new);
if (ret < 0) {
--
2.8.1
next prev parent reply other threads:[~2016-06-05 18:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-05 18:46 [B.A.T.M.A.N.] [PATCH 01/10] alfred: vis: Fix parsing of iface_status Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 02/10] alfred: Split list of objects in Makefile into separate lines Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 03/10] alfred: Add netlink dependencies Sven Eckelmann
2016-07-21 15:58 ` Simon Wunderlich
2016-07-21 16:01 ` Sven Eckelmann
2016-06-05 18:47 ` Sven Eckelmann [this message]
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 05/10] alfred: Split translate_mac from debugfs backend Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 06/10] alfred: Translate mac addresses via netlink Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 07/10] alfred: Split get_tq from debugfs backend Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 08/10] alfred: Query TQ of originators via netlink Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 09/10] alfred: vis: Save device index in interface list Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 10/10] alfred: vis: Add support for netlink Sven Eckelmann
2016-07-16 7:28 ` [B.A.T.M.A.N.] [PATCH 11/11] alfred: Switch netlink uapi header copyright to ISC Sven Eckelmann
2016-07-26 11:55 ` [B.A.T.M.A.N.] [PATCH 01/10] alfred: vis: Fix parsing of iface_status Simon Wunderlich
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=1465152428-17299-4-git-send-email-sven@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.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