SHARE
TWEET

james

a guest Nov 19th, 2019 87 in 9 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/obd.c b/obd.c
  2. index 49c363c..cdf9565 100644
  3. --- a/obd.c
  4. +++ b/obd.c
  5. @@ -8,6 +8,7 @@
  6.  #include <sys/socket.h>
  7.  #include <linux/if.h>
  8.  #include <ifaddrs.h>
  9. +#include <pwd.h>
  10.  
  11.  #include <sys/time.h>
  12.  #include <sys/resource.h>
  13. @@ -3579,6 +3580,24 @@ int main(int argc, char **argv)
  14.          return ret;
  15.      }
  16.  
  17. +    /* Drop root permissions. */
  18. +    if (getuid() == 0) {
  19. +        struct passwd passwd, *p_passwd;
  20. +        char buf[256];
  21. +
  22. +        if (getpwnam_r("nobody", &passwd, buf, sizeof buf, &p_passwd)) {
  23. +            ret = errno;
  24. +            perror("getpwnam_r");
  25. +            return ret;
  26. +        }
  27. +
  28. +        if (setuid(passwd.pw_uid) == -1) {
  29. +            ret = errno;
  30. +            perror("setuid");
  31. +            return ret;
  32. +        }
  33. +    }
  34. +
  35.      /* main loop */
  36.      upump_mgr_run(main_upump_mgr, NULL);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top