gril: Really use given uid/gid to open ril socket

This commit is contained in:
Alfonso Sanchez-Beato 2016-03-23 10:58:13 +01:00 committed by Denis Kenzior
parent 267ac0418e
commit e5e6add6ad
1 changed files with 6 additions and 5 deletions

View File

@ -824,14 +824,15 @@ static struct ril_s *create_ril(const char *sock_path, unsigned int uid,
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
if (uid != 0 && seteuid(uid) < 0)
ofono_error("%s: seteuid(%d) failed: %s (%d)",
__func__, uid, strerror(errno), errno);
/* Drop root user last, otherwise we won't be able to change egid */
if (gid != 0 && setegid(gid) < 0)
ofono_error("%s: setegid(%d) failed: %s (%d)",
__func__, gid, strerror(errno), errno);
if (uid != 0 && seteuid(uid) < 0)
ofono_error("%s: seteuid(%d) failed: %s (%d)",
__func__, uid, strerror(errno), errno);
r = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
/* Switch back to root as needed */
@ -1053,7 +1054,7 @@ GRil *g_ril_new_with_ucred(const char *sock_path, enum ofono_ril_vendor vendor,
if (ril == NULL)
return NULL;
ril->parent = create_ril(sock_path, 0, 0);
ril->parent = create_ril(sock_path, uid, gid);
if (ril->parent == NULL) {
g_free(ril);
return NULL;