Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Jan 16, 2020
1 parent 12eee44 commit 8517a4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/usb_moded-common.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-common.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-control.c
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-dbus.c
Expand Up @@ -500,15 +500,15 @@ 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);
g_free(mode_list);
}
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);
Expand Down

0 comments on commit 8517a4c

Please sign in to comment.