diff --git a/data/bash-completion/fwupdtool b/data/bash-completion/fwupdtool index 3109f2a1f..d1389d89a 100644 --- a/data/bash-completion/fwupdtool +++ b/data/bash-completion/fwupdtool @@ -15,6 +15,7 @@ _fwupdmgr_opts=( '--allow-older' '--force' '--show-all-devices' + '--plugin-whitelist' ) _show_modifiers() diff --git a/src/fu-engine.c b/src/fu-engine.c index bd3948e8c..8d0da7130 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,7 @@ struct _FuEngine guint coldplug_id; guint coldplug_delay; FuPluginList *plugin_list; + GPtrArray *plugin_filter; GPtrArray *supported_guids; FuSmbios *smbios; FuHwids *hwids; @@ -2896,6 +2898,27 @@ fu_engine_is_plugin_name_blacklisted (FuEngine *self, const gchar *name) return FALSE; } +static gboolean +fu_engine_is_plugin_name_whitelisted (FuEngine *self, const gchar *name) +{ + if (self->plugin_filter->len == 0) + return TRUE; + for (guint i = 0; i < self->plugin_filter->len; i++) { + const gchar *name_tmp = g_ptr_array_index (self->plugin_filter, i); + if (fnmatch (name_tmp, name, 0) == 0) + return TRUE; + } + return FALSE; +} + +void +fu_engine_add_plugin_filter (FuEngine *self, const gchar *plugin_glob) +{ + g_return_if_fail (FU_IS_ENGINE (self)); + g_return_if_fail (plugin_glob != NULL); + g_ptr_array_add (self->plugin_filter, g_strdup (plugin_glob)); +} + gboolean fu_engine_load_plugins (FuEngine *self, GError **error) { @@ -2926,7 +2949,11 @@ fu_engine_load_plugins (FuEngine *self, GError **error) if (name == NULL) continue; if (fu_engine_is_plugin_name_blacklisted (self, name)) { - g_debug ("%s is blacklisted", name); + g_debug ("plugin %s is blacklisted", name); + continue; + } + if (!fu_engine_is_plugin_name_whitelisted (self, name)) { + g_debug ("plugin %s is not whitelisted", name); continue; } @@ -3373,6 +3400,7 @@ fu_engine_init (FuEngine *self) self->plugin_list = fu_plugin_list_new (); self->profile = as_profile_new (); self->store = as_store_new (); + self->plugin_filter = g_ptr_array_new_with_free_func (g_free); self->supported_guids = g_ptr_array_new_with_free_func (g_free); self->runtime_versions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); self->compile_versions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); @@ -3424,6 +3452,7 @@ fu_engine_finalize (GObject *obj) g_object_unref (self->store); g_object_unref (self->device_list); g_ptr_array_unref (self->supported_guids); + g_ptr_array_unref (self->plugin_filter); g_hash_table_unref (self->runtime_versions); g_hash_table_unref (self->compile_versions); diff --git a/src/fu-engine.h b/src/fu-engine.h index 1586d28b8..8a7982201 100644 --- a/src/fu-engine.h +++ b/src/fu-engine.h @@ -38,6 +38,8 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (FuEngine, fu_engine, FU, ENGINE, GObject) FuEngine *fu_engine_new (FuAppFlags app_flags); +void fu_engine_add_plugin_filter (FuEngine *self, + const gchar *plugin_glob); gboolean fu_engine_load (FuEngine *self, GError **error); gboolean fu_engine_load_plugins (FuEngine *self, diff --git a/src/fu-tool.c b/src/fu-tool.c index 16c7a92e0..cceefb9e1 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -653,6 +653,7 @@ main (int argc, char *argv[]) gboolean force = FALSE; gboolean ret; gboolean verbose = FALSE; + g_auto(GStrv) plugin_glob = NULL; g_autoptr(FuUtilPrivate) priv = g_new0 (FuUtilPrivate, 1); g_autoptr(GError) error = NULL; g_autofree gchar *cmd_descriptions = NULL; @@ -672,6 +673,9 @@ main (int argc, char *argv[]) { "show-all-devices", '\0', 0, G_OPTION_ARG_NONE, &priv->show_all_devices, /* TRANSLATORS: command line option */ _("Show devices that are not updatable"), NULL }, + { "plugin-whitelist", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &plugin_glob, + /* TRANSLATORS: command line option */ + _("Manually whitelist specific plugins"), NULL }, { NULL} }; @@ -815,6 +819,10 @@ main (int argc, char *argv[]) G_CALLBACK (fu_main_engine_percentage_changed_cb), priv); + /* any plugin whitelist specified */ + for (guint i = 0; plugin_glob != NULL && plugin_glob[i] != NULL; i++) + fu_engine_add_plugin_filter (priv->engine, plugin_glob[i]); + /* run the specified command */ ret = fu_util_run (priv, argv[1], (gchar**) &argv[2], &error); if (!ret) {