Skip to content

Commit

Permalink
Merge branch 'oemraw-access' into 'master'
Browse files Browse the repository at this point in the history
OemRaw access control

See merge request mer-core/ofono!265
  • Loading branch information
monich committed Jun 11, 2020
2 parents f2b1625 + 6dfce4b commit 98ffc61
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
29 changes: 17 additions & 12 deletions ofono/drivers/ril/ril_oem_raw.c
@@ -1,7 +1,8 @@
/*
* oFono - Open Source Telephony - RIL-based devices
*
* Copyright (C) 2015-2017 Jolla Ltd.
* Copyright (C) 2015-2020 Jolla Ltd.
* Copyright (C) 2020 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -32,6 +33,11 @@ struct ril_oem_raw {

#define DBG_(oem,fmt,args...) DBG("%s" fmt, (oem)->log_prefix, ##args)

static void ril_oem_raw_send_done(void *msg)
{
dbus_message_unref(msg);
}

static void ril_oem_raw_send_cb(GRilIoChannel *io, int ril_status,
const void *data, guint len, void *user_data)
{
Expand All @@ -40,20 +46,13 @@ static void ril_oem_raw_send_cb(GRilIoChannel *io, int ril_status,

if (ril_status == RIL_E_SUCCESS) {
DBusMessageIter it, array;
const guchar* bytes = data;
guint i;

reply = dbus_message_new_method_return(msg);
dbus_message_iter_init_append(reply, &it);
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY,
DBUS_TYPE_BYTE_AS_STRING, &array);

for (i = 0; i < len; i++) {
guchar byte = bytes[i];
dbus_message_iter_append_basic(&array, DBUS_TYPE_BYTE,
&byte);
}

dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
&data, len);
dbus_message_iter_close_container(&it, &array);
} else if (ril_status == GRILIO_STATUS_TIMEOUT) {
DBG("Timed out");
Expand All @@ -63,7 +62,7 @@ static void ril_oem_raw_send_cb(GRilIoChannel *io, int ril_status,
reply = __ofono_error_failed(msg);
}

__ofono_dbus_pending_reply(&msg, reply);
g_dbus_send_message(ofono_dbus_get_connection(), reply);
}

static DBusMessage *ril_oem_raw_send(DBusConnection *conn, DBusMessage *msg,
Expand All @@ -72,6 +71,12 @@ static DBusMessage *ril_oem_raw_send(DBusConnection *conn, DBusMessage *msg,
DBusMessageIter it;
struct ril_oem_raw *oem = user_data;

if (!__ofono_dbus_access_method_allowed(dbus_message_get_sender(msg),
OFONO_DBUS_ACCESS_INTF_OEMRAW,
OFONO_DBUS_ACCESS_OEMRAW_SEND, NULL)) {
return __ofono_error_access_denied(msg);
}

dbus_message_iter_init(msg, &it);
if (dbus_message_iter_get_arg_type(&it) == DBUS_TYPE_ARRAY &&
dbus_message_iter_get_element_type(&it) == DBUS_TYPE_BYTE) {
Expand All @@ -94,7 +99,7 @@ static DBusMessage *ril_oem_raw_send(DBusConnection *conn, DBusMessage *msg,
grilio_request_append_bytes(req, data, data_len);
grilio_queue_send_request_full(oem->q, req,
RIL_REQUEST_OEM_HOOK_RAW, ril_oem_raw_send_cb,
NULL, dbus_message_ref(msg));
ril_oem_raw_send_done, dbus_message_ref(msg));
grilio_request_unref(req);
return NULL;
} else {
Expand Down
7 changes: 7 additions & 0 deletions ofono/include/dbus-access.h
Expand Up @@ -40,6 +40,7 @@ enum ofono_dbus_access_intf {
OFONO_DBUS_ACCESS_INTF_MODEM, /* org.ofono.Modem */
OFONO_DBUS_ACCESS_INTF_RADIOSETTINGS, /* org.ofono.RadioSettings */
OFONO_DBUS_ACCESS_INTF_STK, /* org.ofono.SimToolkit */
OFONO_DBUS_ACCESS_INTF_OEMRAW, /* org.ofono.OemRaw */
OFONO_DBUS_ACCESS_INTF_COUNT
};

Expand Down Expand Up @@ -124,6 +125,12 @@ enum ofono_dbus_access_stk_method {
OFONO_DBUS_ACCESS_STK_METHOD_COUNT
};

/* OFONO_DBUS_ACCESS_INTF_OEMRAW */
enum ofono_dbus_access_oemraw_method {
OFONO_DBUS_ACCESS_OEMRAW_SEND,
OFONO_DBUS_ACCESS_OEMRAW_METHOD_COUNT
};

#define OFONO_DBUS_ACCESS_PRIORITY_LOW (-100)
#define OFONO_DBUS_ACCESS_PRIORITY_DEFAULT (0)
#define OFONO_DBUS_ACCESS_PRIORITY_HIGH (100)
Expand Down
10 changes: 10 additions & 0 deletions ofono/src/dbus-access.c
Expand Up @@ -44,6 +44,8 @@ const char *ofono_dbus_access_intf_name(enum ofono_dbus_access_intf intf)
return OFONO_RADIO_SETTINGS_INTERFACE;
case OFONO_DBUS_ACCESS_INTF_STK:
return OFONO_STK_INTERFACE;
case OFONO_DBUS_ACCESS_INTF_OEMRAW:
return "org.ofono.OemRaw";
case OFONO_DBUS_ACCESS_INTF_COUNT:
break;
}
Expand Down Expand Up @@ -176,6 +178,14 @@ const char *ofono_dbus_access_method_name(enum ofono_dbus_access_intf intf,
break;
}
break;
case OFONO_DBUS_ACCESS_INTF_OEMRAW:
switch ((enum ofono_dbus_access_oemraw_method)method) {
case OFONO_DBUS_ACCESS_OEMRAW_SEND:
return "Send";
case OFONO_DBUS_ACCESS_OEMRAW_METHOD_COUNT:
break;
}
break;
case OFONO_DBUS_ACCESS_INTF_COUNT:
break;
}
Expand Down
22 changes: 22 additions & 0 deletions ofono/unit/test-dbus-access.c
Expand Up @@ -34,6 +34,12 @@ static enum ofono_dbus_access deny_method_access(const char *sender,
return OFONO_DBUS_ACCESS_DENY;
}

static enum ofono_dbus_access broken_method_access(const char *sender,
enum ofono_dbus_access_intf intf, int method, const char *arg)
{
return (enum ofono_dbus_access)(-1);
}

struct ofono_dbus_access_plugin access_inval;
struct ofono_dbus_access_plugin access_dontcare = {
.name = "DontCare",
Expand All @@ -51,6 +57,12 @@ struct ofono_dbus_access_plugin access_deny = {
.method_access = deny_method_access
};

struct ofono_dbus_access_plugin access_broken = {
.name = "Broken",
.priority = OFONO_DBUS_ACCESS_PRIORITY_LOW,
.method_access = broken_method_access
};

/*==========================================================================*
* Tests
*==========================================================================*/
Expand Down Expand Up @@ -107,6 +119,9 @@ static const struct test_method_name_data method_name_tests[] = {
},{
OFONO_DBUS_ACCESS_INTF_STK,
OFONO_DBUS_ACCESS_STK_METHOD_COUNT
},{
OFONO_DBUS_ACCESS_INTF_OEMRAW,
OFONO_DBUS_ACCESS_OEMRAW_METHOD_COUNT
}
};

Expand Down Expand Up @@ -156,6 +171,13 @@ static void test_register()
ofono_dbus_access_plugin_unregister(&access_deny);
ofono_dbus_access_plugin_unregister(&access_dontcare);

/* And here too */
g_assert(!ofono_dbus_access_plugin_register(&access_broken));
g_assert(!ofono_dbus_access_plugin_register(&access_deny));
g_assert(!__ofono_dbus_access_method_allowed(":1.0", 0, 1, NULL));
ofono_dbus_access_plugin_unregister(&access_deny);
ofono_dbus_access_plugin_unregister(&access_dontcare);

/* DontCare will allow everything */
g_assert(!ofono_dbus_access_plugin_register(&access_dontcare));
g_assert(__ofono_dbus_access_method_allowed(":1.0", 0, 1, NULL));
Expand Down

0 comments on commit 98ffc61

Please sign in to comment.