X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fiptables.c;h=35c93f4e1c1939d796a4df518b06554b31388d6c;hb=99db6e480437d6dd6cf80580d19a65855768a727;hp=e035a88818f7069c9575beb6beae42d4e64e561a;hpb=c7d859191d8fbfc129dea8cfaf9e13e78fd6642c;p=collectd.git diff --git a/src/iptables.c b/src/iptables.c index e035a888..35c93f4e 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -33,6 +33,10 @@ #include #include +#ifdef HAVE_SYS_CAPABILITY_H +# include +#endif + /* * iptc_handle_t was available before libiptc was officially available as a * shared library. Note, that when the shared lib was introduced, the API and @@ -499,10 +503,30 @@ static int iptables_shutdown (void) return (0); } /* int iptables_shutdown */ +static int iptables_init (void) +{ +#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_ADMIN) + if (check_capability (CAP_NET_ADMIN) != 0) + { + if (getuid () == 0) + WARNING ("iptables plugin: Running collectd as root, but the " + "CAP_NET_ADMIN capability is missing. The plugin's read " + "function will probably fail. Is your init system dropping " + "capabilities?"); + else + WARNING ("iptables plugin: collectd doesn't have the CAP_NET_ADMIN " + "capability. If you don't want to run collectd as root, try " + "running \"setcap cap_net_admin=ep\" on the collectd binary."); + } +#endif + return (0); +} /* int iptables_init */ + void module_register (void) { plugin_register_config ("iptables", iptables_config, config_keys, config_keys_num); + plugin_register_init ("iptables", iptables_init); plugin_register_read ("iptables", iptables_read); plugin_register_shutdown ("iptables", iptables_shutdown); } /* void module_register */