Commit 440da29d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use group lists

so that devices can be opened according to usual group ownership (audio, video...)
parent f15b9cb7
...@@ -63,71 +63,37 @@ static int clearenv (void) ...@@ -63,71 +63,37 @@ static int clearenv (void)
#endif*/ #endif*/
/** /**
* Converts username to UID. * Tries to find a real non-root user to use
*/ */
static uid_t parse_user (const char *name) static struct passwd *guess_user (void)
{
struct passwd *pw;
pw = getpwnam (name);
if (pw == NULL)
return (uid_t)(-1);
return pw->pw_uid;
}
/**
* Tries to find a real non-root user ID
*/
static uid_t guess_user (void)
{ {
const char *name; const char *name;
struct passwd *pw;
uid_t uid; uid_t uid;
/* Try real UID */ /* Try real UID */
uid = getuid (); uid = getuid ();
if (uid) if (uid)
return uid; if ((pw = getpwuid (uid)) != NULL)
return pw;
/* Try sudo */ /* Try sudo */
name = getenv ("SUDO_USER"); name = getenv ("SUDO_USER");
if (name != NULL) if (name != NULL)
{ if ((pw = getpwnam (name)) != NULL)
uid = parse_user (name); return pw;
if (uid != (uid_t)(-1))
return uid;
}
/* Try VLC_USER */ /* Try VLC_USER */
name = getenv ("VLC_USER"); name = getenv ("VLC_USER");
if (name != NULL) if (name != NULL)
{ if ((pw = getpwnam (name)) != NULL)
uid = parse_user (name); return pw;
if (uid != (uid_t)(-1))
return uid;
}
/* Try vlc */ /* Try vlc */
uid = parse_user ("vlc"); if ((pw = getpwnam ("vlc")) != NULL)
if (uid != (uid_t)(-1)) return pw;
return uid;
return 0; return getpwuid (0);
}
/**
* Returns the main GID associated with a given UID.
*/
static gid_t guess_gid (uid_t uid)
{
struct passwd *pw;
pw = getpwuid (uid);
if (pw != NULL)
return pw->pw_gid;
return 65534;
} }
...@@ -255,8 +221,8 @@ void rootwrap (void) ...@@ -255,8 +221,8 @@ void rootwrap (void)
{ {
struct rlimit lim; struct rlimit lim;
int fd, pair[2]; int fd, pair[2];
struct passwd *pw;
uid_t u; uid_t u;
gid_t g;
u = geteuid (); u = geteuid ();
/* Are we running with root privileges? */ /* Are we running with root privileges? */
...@@ -280,12 +246,12 @@ void rootwrap (void) ...@@ -280,12 +246,12 @@ void rootwrap (void)
fputs ("Starting VLC root wrapper...", stderr); fputs ("Starting VLC root wrapper...", stderr);
u = guess_user (); pw = guess_user ();
fprintf (stderr, " using UID %u", (unsigned)u); if (pw == NULL)
return; /* Should we rather print an error and exit ? */
g = guess_gid (u);
fprintf (stderr, ", using GID %u\n", (unsigned)g);
u = pw->pw_uid,
fprintf (stderr, " using UID %u (%s)\n", (unsigned)u, pw->pw_name);
if (u == 0) if (u == 0)
{ {
fputs ("***************************************\n" fputs ("***************************************\n"
...@@ -298,8 +264,8 @@ void rootwrap (void) ...@@ -298,8 +264,8 @@ void rootwrap (void)
} }
/* GID */ /* GID */
setgid (g); initgroups (pw->pw_name, pw->pw_gid);
setgroups (0, NULL); setgid (pw->pw_gid);
if (socketpair (AF_LOCAL, SOCK_STREAM, 0, pair)) if (socketpair (AF_LOCAL, SOCK_STREAM, 0, pair))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment