From 053ae1080405c77e4f63c0cf78cb41f61aec4a33 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 19 Oct 2017 15:20:59 +0200 Subject: try to drop root privileges --- pacredir.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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; -- cgit v1.2.3-54-g00ecf