From: Serge Hallyn Date: Thu, 2 Feb 2012 21:54:53 +0000 (-0600) Subject: lxc-start: exit early and cleanly if we have insufficient privs X-Git-Tag: lxc-0.8.0-rc2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4a2ca8b2ba4b9820a3e3e26e2cf081c17d8737f9;p=thirdparty%2Flxc.git lxc-start: exit early and cleanly if we have insufficient privs Signed-off-by: Serge Hallyn Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 1610002ac..10a0b4aac 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -213,3 +213,42 @@ int lxc_caps_last_cap(void) return last_cap; } + +/* + * check if we have the caps needed to start a container. returns 1 on + * success, 0 on error. (I'd prefer this be a bool, but am afraid that + * might fail to build on some distros). + */ +int lxc_caps_check(void) +{ + uid_t uid = getuid(); + cap_t caps; + cap_flag_value_t value; + int i, ret; + + cap_value_t needed_caps[] = { CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SETUID, CAP_SETGID }; + +#define NUMCAPS ((int) (sizeof(needed_caps) / sizeof(cap_t))) + + if (!uid) + return 1; + + caps = cap_get_proc(); + if (!caps) { + ERROR("failed to cap_get_proc: %m"); + return 0; + } + + for (i=0; i