summaryrefslogtreecommitdiff
path: root/gril
diff options
context:
space:
mode:
authorAlfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>2016-03-23 10:58:13 +0100
committerDenis Kenzior <denkenz@gmail.com>2016-03-24 09:29:19 -0500
commite5e6add6adef82cdeeefa3f6c4ee22b3ab34d962 (patch)
treece584ac740fe647009763be0d3d712450e0f1ea1 /gril
parent267ac0418e95114d330ec6f176eb6a11851be278 (diff)
downloadofono-e5e6add6adef82cdeeefa3f6c4ee22b3ab34d962.tar.gz
gril: Really use given uid/gid to open ril socket
Diffstat (limited to 'gril')
-rw-r--r--gril/gril.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gril/gril.c b/gril/gril.c
index fa1a7801..297a7720 100644
--- a/gril/gril.c
+++ b/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;
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;