---
 gril/gril.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gril/gril.c b/gril/gril.c
index fa1a780..297a772 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;
-- 
2.5.0

_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to