mirror of git://git.sysmocom.de/ofono
gril: Add g_ril_new_with_ucred
This commit is contained in:
parent
0689b1481a
commit
8e40ef7e1f
56
gril/gril.c
56
gril/gril.c
|
@ -48,10 +48,6 @@
|
||||||
ofono_debug(fmt, ## arg); \
|
ofono_debug(fmt, ## arg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
#define RADIO_GID 1001
|
|
||||||
#define RADIO_UID 1001
|
|
||||||
|
|
||||||
struct ril_request {
|
struct ril_request {
|
||||||
gchar *data;
|
gchar *data;
|
||||||
guint data_len;
|
guint data_len;
|
||||||
|
@ -792,23 +788,14 @@ static gboolean node_compare_by_group(struct ril_notify_node *node,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_process_id(gid_t gid, uid_t uid)
|
static struct ril_s *create_ril(const char *sock_path, unsigned int uid,
|
||||||
{
|
unsigned int gid)
|
||||||
if (setegid(gid) < 0)
|
|
||||||
ofono_error("%s: setegid(%d) failed: %s (%d)",
|
|
||||||
__func__, gid, strerror(errno), errno);
|
|
||||||
|
|
||||||
if (seteuid(uid) < 0)
|
|
||||||
ofono_error("%s: seteuid(%d) failed: %s (%d)",
|
|
||||||
__func__, uid, strerror(errno), errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct ril_s *create_ril(const char *sock_path)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
struct ril_s *ril;
|
struct ril_s *ril;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
int sk;
|
int sk;
|
||||||
|
int r;
|
||||||
GIOChannel *io;
|
GIOChannel *io;
|
||||||
|
|
||||||
ril = g_try_new0(struct ril_s, 1);
|
ril = g_try_new0(struct ril_s, 1);
|
||||||
|
@ -837,20 +824,31 @@ static struct ril_s *create_ril(const char *sock_path)
|
||||||
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);
|
||||||
|
|
||||||
/* RIL expects user radio to connect to the socket */
|
if (uid != 0 && seteuid(uid) < 0)
|
||||||
set_process_id(RADIO_GID, RADIO_UID);
|
ofono_error("%s: seteuid(%d) failed: %s (%d)",
|
||||||
|
__func__, uid, strerror(errno), errno);
|
||||||
|
|
||||||
if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
if (gid != 0 && setegid(gid) < 0)
|
||||||
|
ofono_error("%s: setegid(%d) failed: %s (%d)",
|
||||||
|
__func__, gid, strerror(errno), errno);
|
||||||
|
|
||||||
|
r = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
|
||||||
|
|
||||||
|
/* Switch back to root as needed */
|
||||||
|
if (uid && seteuid(0) < 0)
|
||||||
|
ofono_error("%s: seteuid(0) failed: %s (%d)",
|
||||||
|
__func__, strerror(errno), errno);
|
||||||
|
|
||||||
|
if (gid && setegid(0) < 0)
|
||||||
|
ofono_error("%s: setegid(0) failed: %s (%d)",
|
||||||
|
__func__, strerror(errno), errno);
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
ofono_error("create_ril: can't connect to RILD: %s (%d)\n",
|
ofono_error("create_ril: can't connect to RILD: %s (%d)\n",
|
||||||
strerror(errno), errno);
|
strerror(errno), errno);
|
||||||
/* Switch back to root */
|
|
||||||
set_process_id(0, 0);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch back to root */
|
|
||||||
set_process_id(0, 0);
|
|
||||||
|
|
||||||
io = g_io_channel_unix_new(sk);
|
io = g_io_channel_unix_new(sk);
|
||||||
if (io == NULL) {
|
if (io == NULL) {
|
||||||
ofono_error("create_ril: can't open RILD io channel: %s (%d)\n",
|
ofono_error("create_ril: can't open RILD io channel: %s (%d)\n",
|
||||||
|
@ -1046,7 +1044,8 @@ void g_ril_init_parcel(const struct ril_msg *message, struct parcel *rilp)
|
||||||
rilp->malformed = 0;
|
rilp->malformed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GRil *g_ril_new(const char *sock_path, enum ofono_ril_vendor vendor)
|
GRil *g_ril_new_with_ucred(const char *sock_path, enum ofono_ril_vendor vendor,
|
||||||
|
unsigned int uid, unsigned int gid)
|
||||||
{
|
{
|
||||||
GRil *ril;
|
GRil *ril;
|
||||||
|
|
||||||
|
@ -1054,7 +1053,7 @@ GRil *g_ril_new(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);
|
ril->parent = create_ril(sock_path, 0, 0);
|
||||||
if (ril->parent == NULL) {
|
if (ril->parent == NULL) {
|
||||||
g_free(ril);
|
g_free(ril);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1068,6 +1067,11 @@ GRil *g_ril_new(const char *sock_path, enum ofono_ril_vendor vendor)
|
||||||
return ril;
|
return ril;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GRil *g_ril_new(const char *sock_path, enum ofono_ril_vendor vendor)
|
||||||
|
{
|
||||||
|
return g_ril_new_with_ucred(sock_path, vendor, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
GRil *g_ril_clone(GRil *clone)
|
GRil *g_ril_clone(GRil *clone)
|
||||||
{
|
{
|
||||||
GRil *ril;
|
GRil *ril;
|
||||||
|
|
|
@ -109,6 +109,8 @@ extern char print_buf[];
|
||||||
void g_ril_init_parcel(const struct ril_msg *message, struct parcel *rilp);
|
void g_ril_init_parcel(const struct ril_msg *message, struct parcel *rilp);
|
||||||
|
|
||||||
GRil *g_ril_new(const char *sock_path, enum ofono_ril_vendor vendor);
|
GRil *g_ril_new(const char *sock_path, enum ofono_ril_vendor vendor);
|
||||||
|
GRil *g_ril_new_with_ucred(const char *sock_path, enum ofono_ril_vendor vendor,
|
||||||
|
unsigned int uid, unsigned int gid);
|
||||||
|
|
||||||
GIOChannel *g_ril_get_channel(GRil *ril);
|
GIOChannel *g_ril_get_channel(GRil *ril);
|
||||||
GRilIO *g_ril_get_io(GRil *ril);
|
GRilIO *g_ril_get_io(GRil *ril);
|
||||||
|
|
Loading…
Reference in New Issue