- struct rlimit lim;
- int fd, pair[2];
- struct passwd *pw;
- uid_t u;
-
- u = geteuid ();
- /* Are we running with root privileges? */
- if (u != 0)
- {
- setuid (u);
- return;
- }
-
- /* Make sure 0, 1 and 2 are opened, and only these. */
- if (getrlimit (RLIMIT_NOFILE, &lim))
- exit (1);
-
- for (fd = 3; ((unsigned)fd) < lim.rlim_cur; fd++)
- close (fd);
-
- fd = dup (2);
- if (fd <= 2)
- exit (1);
- close (fd);
-
- fputs ("starting VLC root wrapper...", stderr);
-
- pw = guess_user ();
- if (pw == NULL)
- return; /* Should we rather print an error and exit ? */
-
- u = pw->pw_uid,
- fprintf (stderr, " using UID %u (%s)\n", (unsigned)u, pw->pw_name);
- if (u == 0)
- {
- fputs ("***************************************\n"
- "* Running VLC as root is discouraged. *\n"
- "***************************************\n"
- "\n"
- " It is potentially dangerous, "
- "and might not even work properly.\n", stderr);
- return;
- }
-
- /* GID */
- initgroups (pw->pw_name, pw->pw_gid);
- setgid (pw->pw_gid);