user-controls: Only save the app filter if it’s changed

This prevents a polkit authentication prompt popping up unexpectedly if,
for example, a non-privileged user has opened and immediately closed
malcontent-control.

Spotted by Andre Moreira Magalhaes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2020-11-02 15:23:29 +00:00
parent ecd541b2e9
commit cac7ba414c
1 changed files with 24 additions and 2 deletions

View File

@ -104,7 +104,8 @@ struct _MctUserControls
GDBusConnection *dbus_connection; /* (owned) */
GCancellable *cancellable; /* (owned) */
MctManager *manager; /* (owned) */
MctAppFilter *filter; /* (owned) (nullable) */
MctAppFilter *filter; /* (owned) (nullable); updated by the user of #MctUserControls */
MctAppFilter *last_saved_filter; /* (owned) (nullable); updated each time we internally time out and save the app filter */
guint selected_age; /* @oars_disabled_age to disable OARS */
guint blocklist_apps_source_id;
@ -296,6 +297,7 @@ update_app_filter_from_user (MctUserControls *self)
/* FIXME: make it asynchronous */
g_clear_pointer (&self->filter, mct_app_filter_unref);
g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
self->filter = mct_manager_get_app_filter (self->manager,
act_user_get_uid (self->user),
MCT_MANAGER_GET_VALUE_FLAGS_NONE,
@ -310,6 +312,8 @@ update_app_filter_from_user (MctUserControls *self)
return;
}
self->last_saved_filter = mct_app_filter_ref (self->filter);
g_debug ("Retrieved new app filter for user '%s'", act_user_get_user_name (self->user));
}
@ -591,6 +595,15 @@ blocklist_apps_cb (gpointer data)
mct_user_controls_build_app_filter (self, &builder);
new_filter = mct_app_filter_builder_end (&builder);
/* Dont bother saving the app filter (which could result in asking the user
* for admin permission) if it hasnt changed. */
if (self->last_saved_filter != NULL &&
mct_app_filter_equal (new_filter, self->last_saved_filter))
{
g_debug ("Not saving app filter as it hasnt changed");
return G_SOURCE_REMOVE;
}
/* FIXME: should become asynchronous */
mct_manager_set_app_filter (self->manager,
act_user_get_uid (self->user),
@ -605,6 +618,10 @@ blocklist_apps_cb (gpointer data)
setup_parental_control_settings (self);
}
/* Update the cached copy */
mct_app_filter_unref (self->last_saved_filter);
self->last_saved_filter = g_steal_pointer (&new_filter);
return G_SOURCE_REMOVE;
}
@ -816,6 +833,7 @@ mct_user_controls_finalize (GObject *object)
g_clear_object (&self->permission);
g_clear_pointer (&self->filter, mct_app_filter_unref);
g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
g_clear_object (&self->manager);
g_clear_object (&self->dbus_connection);
@ -1333,8 +1351,12 @@ mct_user_controls_set_app_filter (MctUserControls *self,
return;
g_clear_pointer (&self->filter, mct_app_filter_unref);
g_clear_pointer (&self->last_saved_filter, mct_app_filter_unref);
if (app_filter != NULL)
self->filter = mct_app_filter_ref (app_filter);
{
self->filter = mct_app_filter_ref (app_filter);
self->last_saved_filter = mct_app_filter_ref (app_filter);
}
g_debug ("Set new app filter from caller");
setup_parental_control_settings (self);