mirror of git://git.sysmocom.de/ofono
gril: Really use given uid/gid to open ril socket
This commit is contained in:
parent
267ac0418e
commit
e5e6add6ad
11
gril/gril.c
11
gril/gril.c
|
@ -824,14 +824,15 @@ static struct ril_s *create_ril(const char *sock_path, unsigned int uid,
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
if (uid != 0 && seteuid(uid) < 0)
|
/* Drop root user last, otherwise we won't be able to change egid */
|
||||||
ofono_error("%s: seteuid(%d) failed: %s (%d)",
|
|
||||||
__func__, uid, strerror(errno), errno);
|
|
||||||
|
|
||||||
if (gid != 0 && setegid(gid) < 0)
|
if (gid != 0 && setegid(gid) < 0)
|
||||||
ofono_error("%s: setegid(%d) failed: %s (%d)",
|
ofono_error("%s: setegid(%d) failed: %s (%d)",
|
||||||
__func__, gid, strerror(errno), errno);
|
__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));
|
r = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
|
||||||
|
|
||||||
/* Switch back to root as needed */
|
/* 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)
|
if (ril == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ril->parent = create_ril(sock_path, 0, 0);
|
ril->parent = create_ril(sock_path, uid, gid);
|
||||||
if (ril->parent == NULL) {
|
if (ril->parent == NULL) {
|
||||||
g_free(ril);
|
g_free(ril);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue