diff --git a/src/usb_moded-common.c b/src/usb_moded-common.c index f7e487f..a433a7a 100644 --- a/src/usb_moded-common.c +++ b/src/usb_moded-common.c @@ -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; diff --git a/src/usb_moded-common.h b/src/usb_moded-common.h index 74ea5f4..8f4e7f7 100644 --- a/src/usb_moded-common.h +++ b/src/usb_moded-common.h @@ -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 diff --git a/src/usb_moded-control.c b/src/usb_moded-control.c index 1f5d900..a9cbbc3 100644 --- a/src/usb_moded-control.c +++ b/src/usb_moded-control.c @@ -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; } diff --git a/src/usb_moded-dbus.c b/src/usb_moded-dbus.c index 9111608..fcb96ec 100644 --- a/src/usb_moded-dbus.c +++ b/src/usb_moded-dbus.c @@ -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);