X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=3e2db15a78a4230beaa8eb037b1763169c84df7c;hp=c4dbecbec9cb8c9c4d883d9b11def27ca1316390;hb=d3ba4d04f6c5d22ba97ea81cdca2e2acd04dfec1;hpb=ab324851dd66efb814b32d134dd1ae427c22b8fe diff --git a/src/daemon/common.c b/src/daemon/common.c index c4dbecbe..3e2db15a 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -60,6 +60,10 @@ # include #endif +#ifdef HAVE_SYS_CAPABILITY_H +# include +#endif + #ifdef HAVE_LIBKSTAT extern kstat_ctl_t *kc; #endif @@ -1668,3 +1672,26 @@ void strarray_free (char **array, size_t array_len) /* {{{ */ sfree (array[i]); sfree (array); } /* }}} void strarray_free */ + +#ifdef HAVE_SYS_CAPABILITY_H +int check_capability (int capability) /* {{{ */ +{ + struct __user_cap_header_struct cap_header_data; + cap_user_header_t cap_header = &cap_header_data; + struct __user_cap_data_struct cap_data_data; + cap_user_data_t cap_data = &cap_data_data; + + cap_header->pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION; + if (capget(cap_header, cap_data) < 0) + { + ERROR("check_capability: capget failed"); + return (-1); + } + + if ((cap_data->effective & (1 << capability)) == 0) + return (-1); + else + return (0); +} /* }}} int check_capability */ +#endif