]> git.sesse.net Git - vlc/commitdiff
Support for sudo
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 9 Jun 2008 18:49:29 +0000 (21:49 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 9 Jun 2008 18:50:41 +0000 (21:50 +0300)
src/network/rootwrap.c

index fdf736535e48eeea0dabf0e32969708aa8ce5962..f2c851a3544347ea5cdc522cf29a62f3f68c49e8 100644 (file)
@@ -205,12 +205,24 @@ int main (int argc, char *argv[])
     setrlimit (RLIMIT_RTPRIO, &rlim);
 #endif
 
-    setuid (getuid ());
+    uid_t uid = getuid ();
+    if (uid == 0)
+    {
+        const char *sudo = getenv ("SUDO_UID");
+        if (sudo)
+            uid = atoi (sudo);
+    }
+    if (uid == 0)
+    {
+        fprintf (stderr, "Cannot determine unprivileged user for VLC!\n");
+        exit (1);
+    }
+    setuid (uid);
 
     if (!setuid (0)) /* sanity check: we cannot get root back */
         exit (1);
 
-    /* Yeah, the user can force to execute just about anything from here.
+    /* Yeah, the user can execute just about anything from here.
      * But we've dropped privileges, so it does not matter. */
     if (strlen (argv[0]) < sizeof ("-wrapper"))
         goto error;