Merge branch 'unlock-before-attrs-pull' into 'master'

Unlock the keyring before getting secret attributes

See merge request GNOME/libsecret!105
This commit is contained in:
Niels De Graef 2023-05-24 07:05:50 +00:00
commit da60df0e77

View File

@ -98,18 +98,12 @@ on_search_secrets (GObject *source,
} }
static void static void
on_search_unlocked (GObject *source, secret_search_load_or_complete (GTask *task,
GAsyncResult *result, SearchClosure *search)
gpointer user_data)
{ {
GTask *task = G_TASK (user_data);
SearchClosure *search = g_task_get_task_data (task);
GCancellable *cancellable = g_task_get_cancellable (task); GCancellable *cancellable = g_task_get_cancellable (task);
GList *items; GList *items;
/* Note that we ignore any unlock failure */
secret_service_unlock_finish (search->service, result, NULL, NULL);
/* If loading secrets ... locked items automatically ignored */ /* If loading secrets ... locked items automatically ignored */
if (search->flags & SECRET_SEARCH_LOAD_SECRETS) { if (search->flags & SECRET_SEARCH_LOAD_SECRETS) {
items = g_hash_table_get_values (search->items); items = g_hash_table_get_values (search->items);
@ -121,35 +115,6 @@ on_search_unlocked (GObject *source,
} else { } else {
g_task_return_boolean (task, TRUE); g_task_return_boolean (task, TRUE);
} }
g_clear_object (&task);
}
static void
secret_search_unlock_load_or_complete (GTask *task,
SearchClosure *search)
{
GCancellable *cancellable = g_task_get_cancellable (task);
GList *items;
/* If unlocking then unlock all the locked items */
if (search->flags & SECRET_SEARCH_UNLOCK) {
items = search_closure_build_items (search, search->locked);
secret_service_unlock (search->service, items, cancellable,
on_search_unlocked, g_object_ref (task));
g_list_free_full (items, g_object_unref);
/* If loading secrets ... locked items automatically ignored */
} else if (search->flags & SECRET_SEARCH_LOAD_SECRETS) {
items = g_hash_table_get_values (search->items);
secret_item_load_secrets (items, cancellable,
on_search_secrets, g_object_ref (task));
g_list_free (items);
/* No additional options, just complete */
} else {
g_task_return_boolean (task, TRUE);
}
} }
static void static void
@ -176,7 +141,7 @@ on_search_loaded (GObject *source,
/* We're done loading, lets go to the next step */ /* We're done loading, lets go to the next step */
if (closure->loading == 0) if (closure->loading == 0)
secret_search_unlock_load_or_complete (task, closure); secret_search_load_or_complete (task, closure);
g_clear_object (&task); g_clear_object (&task);
} }
@ -200,6 +165,44 @@ search_load_item_async (SecretService *self,
} }
} }
static void
load_items (SearchClosure *closure,
GTask *task)
{
SecretService *self = closure->service;
gint want = 1;
gint count = 0;
gint i;
if (closure->flags & SECRET_SEARCH_ALL)
want = G_MAXINT;
for (i = 0; count < want && closure->unlocked[i] != NULL; i++, count++)
search_load_item_async (self, task, closure, closure->unlocked[i]);
for (i = 0; count < want && closure->locked[i] != NULL; i++, count++)
search_load_item_async (self, task, closure, closure->locked[i]);
/* No items loading, complete operation now */
if (closure->loading == 0)
secret_search_load_or_complete (task, closure);
}
static void
on_unlock_paths (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GTask *task = G_TASK (user_data);
SearchClosure *closure = g_task_get_task_data (task);
SecretService *self = closure->service;
/* Note that we ignore any unlock failure */
secret_service_unlock_dbus_paths_finish (self, result, NULL, NULL);
load_items (closure, task);
g_clear_object (&task);
}
static void static void
on_search_paths (GObject *source, on_search_paths (GObject *source,
GAsyncResult *result, GAsyncResult *result,
@ -209,27 +212,21 @@ on_search_paths (GObject *source,
SearchClosure *closure = g_task_get_task_data (task); SearchClosure *closure = g_task_get_task_data (task);
SecretService *self = closure->service; SecretService *self = closure->service;
GError *error = NULL; GError *error = NULL;
gint want = 1;
gint count;
gint i;
secret_service_search_for_dbus_paths_finish (self, result, &closure->unlocked, secret_service_search_for_dbus_paths_finish (self, result, &closure->unlocked,
&closure->locked, &error); &closure->locked, &error);
if (error == NULL) { if (error == NULL) {
want = 1; /* If unlocking then unlock all the locked items */
if (closure->flags & SECRET_SEARCH_ALL) if (closure->flags & SECRET_SEARCH_UNLOCK) {
want = G_MAXINT; GCancellable *cancellable = g_task_get_cancellable (task);
count = 0; const gchar **const_locked = (const gchar**) closure->locked;
for (i = 0; count < want && closure->unlocked[i] != NULL; i++, count++)
search_load_item_async (self, task, closure, closure->unlocked[i]);
for (i = 0; count < want && closure->locked[i] != NULL; i++, count++)
search_load_item_async (self, task, closure, closure->locked[i]);
/* No items loading, complete operation now */
if (closure->loading == 0)
secret_search_unlock_load_or_complete (task, closure);
secret_service_unlock_dbus_paths (self, const_locked, cancellable,
on_unlock_paths,
g_steal_pointer (&task));
} else {
load_items (closure, task);
}
} else { } else {
g_task_return_error (task, g_steal_pointer (&error)); g_task_return_error (task, g_steal_pointer (&error));
} }
@ -478,6 +475,10 @@ secret_service_search_sync (SecretService *service,
return NULL; return NULL;
} }
if (flags & SECRET_SEARCH_UNLOCK)
secret_service_unlock_dbus_paths_sync (service, (const gchar**) locked_paths,
cancellable, NULL, NULL);
ret = TRUE; ret = TRUE;
want = 1; want = 1;
@ -512,9 +513,6 @@ secret_service_search_sync (SecretService *service,
items = g_list_concat (items, g_list_copy (unlocked)); items = g_list_concat (items, g_list_copy (unlocked));
items = g_list_reverse (items); items = g_list_reverse (items);
if (flags & SECRET_SEARCH_UNLOCK)
secret_service_unlock_sync (service, locked, cancellable, NULL, NULL);
if (flags & SECRET_SEARCH_LOAD_SECRETS) if (flags & SECRET_SEARCH_LOAD_SECRETS)
secret_item_load_secrets_sync (items, NULL, NULL); secret_item_load_secrets_sync (items, NULL, NULL);