@cryptotaxi247 / netdata-1 / commits / f77b4d270

attempt to setuid to root, to detect if we are capable of running as root

Costa Tsaousis (ktsaou) committed Jan 29, 2017 at 22:30 UTC f77b4d270f29813072ffd960d24141fb63c1d9be
1 file changed +8 -2
src/apps_plugin.c
+8 -2
@@ -3020,6 +3020,12 @@ static int am_i_running_as_root() {
3020 return 1;
3021 }
3022
3023 + if(seteuid(0) == 0) {
3024 + euid = geteuid();
3025 + if(debug) info("I am running with escalated privileges, uid = %u, euid = %u.", uid, euid);
3026 + return 1;
3027 + }
3028 +
3029 if(debug) info("I am not running with escalated privileges, uid = %u, euid = %u.", uid, euid);
3030 return 0;
3031 }
@@ -3135,8 +3141,8 @@ int main(int argc, char **argv) {
3141
3142 parse_args(argc, argv);
3143
3138 - if(!am_i_running_as_root()) {
3139 - if(!check_capabilities()) {
3144 + if(!check_capabilities()) {
3145 + if(!am_i_running_as_root()) {
3146 uid_t uid = getuid(), euid = geteuid();
3147 #ifdef HAVE_CAPABILITY
3148 error("apps.plugin should either run as root (now running with uid %u, euid %u) or have special capabilities. "