summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2017-10-19 15:20:59 +0200
committerGravatar Christian Hesse <mail@eworm.de>2017-10-19 15:20:59 +0200
commit053ae1080405c77e4f63c0cf78cb41f61aec4a33 (patch)
treecf438dc0a5871bc3bd8479feb9b4ec3894d0c7af
parenta152505d8a22f9e2a56509b933118be0f0ebe818 (diff)
downloadpacredir-053ae1080405c77e4f63c0cf78cb41f61aec4a33.tar.gz
pacredir-053ae1080405c77e4f63c0cf78cb41f61aec4a33.tar.zst
try to drop root privileges
-rw-r--r--pacredir.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/pacredir.c b/pacredir.c
index a079e31..e2a4b1c 100644
--- a/pacredir.c
+++ b/pacredir.c
@@ -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;