Commit 8517a4c6 authored by Tomi Leppänen's avatar Tomi Leppänen

[common] Check for restricted modes. JB#48441

Check for restricted modes in common_get_mode_list and don't return them
unless allowed. Add uid parameter to common_get_mode_list to do that.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent 12eee448
......@@ -61,7 +61,7 @@ bool common_msleep_ (const char *file, int line, co
static bool common_mode_in_list (const char *mode, char *const *modes);
bool common_modename_is_internal (const char *modename);
int common_valid_mode (const char *mode);
gchar *common_get_mode_list (mode_list_type_t type);
gchar *common_get_mode_list (mode_list_type_t type, uid_t uid);
/* ========================================================================= *
* Functions
......@@ -205,7 +205,7 @@ void common_send_supported_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST);
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST, 0);
umdbus_send_supported_modes_signal(mode_list);
g_free(mode_list);
}
......@@ -216,7 +216,7 @@ void common_send_available_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST);
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST, 0);
umdbus_send_available_modes_signal(mode_list);
g_free(mode_list);
}
......@@ -503,10 +503,12 @@ int common_valid_mode(const char *mode)
/** make a list of all available usb modes
*
* @param type The type of list to return. Supported or available.
* @param uid Uid of the process requesting the information;
* this is used to limit allowed modes, 0 returns all
*
* @return a comma-separated list of modes (MODE_ASK not included as it is not a real mode)
*/
gchar *common_get_mode_list(mode_list_type_t type)
gchar *common_get_mode_list(mode_list_type_t type, uid_t uid)
{
LOG_REGISTER_CONTEXT;
......@@ -544,6 +546,10 @@ gchar *common_get_mode_list(mode_list_type_t type)
{
modedata_t *data = iter->data;
/* skip dynamic modes that are not allowed */
if (!usbmoded_is_mode_permitted(data->mode_name, uid))
continue;
/* skip items in the hidden list */
if (common_mode_in_list(data->mode_name, hidden_modes_array))
continue;
......
......@@ -61,7 +61,7 @@ waitres_t common_wait (unsigned tot_ms, bool (*ready_c
bool common_msleep_ (const char *file, int line, const char *func, unsigned msec);
bool common_modename_is_internal (const char *modename);
int common_valid_mode (const char *mode);
gchar *common_get_mode_list (mode_list_type_t type);
gchar *common_get_mode_list (mode_list_type_t type, uid_t uid);
/* ========================================================================= *
* Macros
......
......@@ -338,7 +338,7 @@ void control_select_usb_mode(void)
* going through ask-mode */
if( !strcmp(MODE_ASK, mode_to_set) ) {
// FIXME free() vs g_free() conflict
gchar *available = common_get_mode_list(AVAILABLE_MODES_LIST);
gchar *available = common_get_mode_list(AVAILABLE_MODES_LIST, 0);
if( *available && !strchr(available, ',') ) {
free(mode_to_set), mode_to_set = available, available = 0;
}
......
......@@ -500,7 +500,7 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
}
else if(!strcmp(member, USB_MODE_LIST))
{
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST);
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST, 0);
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, (const char *) &mode_list, DBUS_TYPE_INVALID);
......@@ -508,7 +508,7 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
}
else if(!strcmp(member, USB_MODE_AVAILABLE_MODES_GET))
{
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST);
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST, 0);
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, (const char *) &mode_list, DBUS_TYPE_INVALID);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment