From: Christian Brauner Date: Sat, 7 Jan 2017 11:40:37 +0000 (+0100) Subject: caps: add lxc_cap_is_set() X-Git-Tag: lxc-2.1.0~214^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca364dc0ddac2215a4a28a587b829cf9509b479f;p=thirdparty%2Flxc.git caps: add lxc_cap_is_set() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 9712e11d2..73b55161f 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -22,20 +22,21 @@ */ #define _GNU_SOURCE -#include +#include "config.h" + +#include +#include #include #include -#include +#include #include -#include -#include "config.h" +#include "caps.h" #include "log.h" lxc_log_define(lxc_caps, lxc); #if HAVE_SYS_CAPABILITY_H -#include #ifndef PR_CAPBSET_READ #define PR_CAPBSET_READ 23 @@ -208,4 +209,27 @@ int lxc_caps_last_cap(void) return last_cap; } +bool lxc_cap_is_set(cap_value_t cap, cap_flag_t flag) +{ + int ret; + cap_t caps; + cap_flag_value_t flagval; + + caps = cap_get_proc(); + if (!caps) { + ERROR("Failed to perform cap_get_proc(): %s.", strerror(errno)); + return false; + } + + ret = cap_get_flag(caps, cap, flag, &flagval); + if (ret < 0) { + ERROR("Failed to perform cap_get_flag(): %s.", strerror(errno)); + cap_free(caps); + return false; + } + + cap_free(caps); + return flagval == CAP_SET; +} + #endif diff --git a/src/lxc/caps.h b/src/lxc/caps.h index f39fec65a..390dbdd4c 100644 --- a/src/lxc/caps.h +++ b/src/lxc/caps.h @@ -20,17 +20,23 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #include "config.h" +#include #ifndef __LXC_CAPS_H #define __LXC_CAPS_H #if HAVE_SYS_CAPABILITY_H +#include + extern int lxc_caps_down(void); extern int lxc_caps_up(void); extern int lxc_caps_init(void); extern int lxc_caps_last_cap(void); + +extern bool lxc_cap_is_set(cap_value_t cap, cap_flag_t flag); #else static inline int lxc_caps_down(void) { return 0; @@ -45,6 +51,12 @@ static inline int lxc_caps_init(void) { static inline int lxc_caps_last_cap(void) { return 0; } + +typedef int cap_value_t; +typedef int cap_flag_t; +static inline bool lxc_cap_is_set(cap_value_t cap, cap_flag_t flag) { + return true; +} #endif #define lxc_priv(__lxc_function) \