check that apps.plugin runs before trusting setcap
Costa Tsaousis (ktsaou) committed
Dec 30, 2016 at 05:54 UTC
fb64fb5a1cd7100d61d17c8ff8beb0f9a575d7dc
2 files changed
+19
-1
netdata-installer.sh
+9
@@ -839,6 +839,15 @@ if [ ${UID} -eq 0 ]
839
then
840
run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
841
setcap_ret=$?
842
+
843
+ if [ ${setcap_ret} -eq 0 ]
844
+ then
845
+ # if we managed to setcap
846
+ # but we fail to execute apps.plugin
847
+ # trigger setuid to root
848
+ "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
849
+ setcap_ret=$?
850
+ fi
851
fi
852
853
if [ ${setcap_ret} -ne 0 ]
src/apps_plugin.c
+10
-1
@@ -2680,6 +2680,11 @@ static void parse_args(int argc, char **argv)
2680
}
2681
}
2682
2683
+ if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) {
2684
+ printf("apps.plugin %s\n", VERSION);
2685
+ exit(0);
2686
+ }
2687
+
2688
if(strcmp("debug", argv[i]) == 0) {
2689
debug = 1;
2690
// debug_flags = 0xffffffff;
@@ -2728,7 +2733,7 @@ static void parse_args(int argc, char **argv)
2733
2734
if(strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
2735
fprintf(stderr,
2731
- "apps.plugin\n"
2736
+ "apps.plugin %s\n"
2737
"(C) 2016 Costa Tsaousis"
2738
"GPL v3+\n"
2739
"This program is a data collector plugin for netdata.\n"
@@ -2755,6 +2760,10 @@ static void parse_args(int argc, char **argv)
2760
"NAME read apps_NAME.conf instead of\n"
2761
" apps_groups.conf\n"
2762
" (default NAME=groups)\n"
2763
+ "\n"
2764
+ "version print program version and exit\n"
2765
+ "\n"
2766
+ , VERSION
2767
);
2768
exit(1);
2769
}