main: drop privileges right after reading the config
authorMichael Adam <obnox@samba.org>
Tue, 2 Mar 2010 21:02:46 +0000 (22:02 +0100)
committerMichael Adam <obnox@samba.org>
Tue, 2 Mar 2010 21:02:46 +0000 (22:02 +0100)
This is the second part of fixing bug #74.
I lets tinyproxy create its log and pid files as the
user as which it is running, so that later on at SIGHUP,
the log file can successfully be reopened.

Michael

src/main.c

index e7801773e6dbca50f65c0aa93dd6d92710e2da16..c9229f3eea66be18e706e34d94523666d5b405b3 100644 (file)
@@ -393,6 +393,14 @@ main (int argc, char **argv)
                 exit (EX_SOFTWARE);
         }
 
+        /* Switch to a different user if we're running as root */
+        if (geteuid () == 0) {
+                change_user (argv[0]);
+        } else {
+                log_message (LOG_WARNING,
+                             "Not running as root, so not changing UID/GID.");
+        }
+
         ret = setup_logging ();
         if (ret != 0) {
                 exit (EX_SOFTWARE);
@@ -438,13 +446,6 @@ main (int argc, char **argv)
                 exit (EX_OSERR);
         }
 
-        /* Switch to a different user if we're running as root */
-        if (geteuid () == 0)
-                change_user (argv[0]);
-        else
-                log_message (LOG_WARNING,
-                             "Not running as root, so not changing UID/GID.");
-
         if (child_pool_create () < 0) {
                 fprintf (stderr,
                          "%s: Could not create the pool of children.\n",