diff options
author | Christian Hesse <mail@eworm.de> | 2017-10-19 15:20:59 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2017-10-19 15:20:59 +0200 |
commit | 053ae1080405c77e4f63c0cf78cb41f61aec4a33 (patch) | |
tree | cf438dc0a5871bc3bd8479feb9b4ec3894d0c7af | |
parent | a152505d8a22f9e2a56509b933118be0f0ebe818 (diff) | |
download | pacredir-053ae1080405c77e4f63c0cf78cb41f61aec4a33.tar.gz pacredir-053ae1080405c77e4f63c0cf78cb41f61aec4a33.tar.zst |
try to drop root privileges
-rw-r--r-- | pacredir.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -662,6 +662,14 @@ int main(int argc, char ** argv) { if (version > 0 || help > 0) return EXIT_SUCCESS; + if (getuid() == 0) { + /* process is running as root, drop privileges */ + if (verbose > 0) + write_log(stdout, "Running as root, meh! Dropping privileges.\n"); + if (setgid(65534) != 0 || setuid(65534) != 0) + write_log(stderr, "Unable to drop user privileges!\n"); + } + /* allocate first struct element as dummy */ hosts = malloc(sizeof(struct hosts)); hosts->host = NULL; |