60
63
G_DEFINE_TYPE (ShellNetworkAgent, shell_network_agent, NM_TYPE_SECRET_AGENT)
65
static const SecretSchema network_agent_schema = {
66
"org.freedesktop.NetworkManager.Connection",
67
SECRET_SCHEMA_DONT_MATCH_NAME,
69
{ SHELL_KEYRING_UUID_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
70
{ SHELL_KEYRING_SN_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
71
{ SHELL_KEYRING_SK_TAG, SECRET_SCHEMA_ATTRIBUTE_STRING },
63
77
shell_agent_request_free (gpointer data)
65
79
ShellAgentRequest *request = data;
67
if (request->keyring_op)
68
gnome_keyring_cancel_request (request->keyring_op);
81
g_cancellable_cancel (request->cancellable);
82
g_object_unref (request->cancellable);
70
83
g_object_unref (request->self);
71
84
g_object_unref (request->connection);
72
85
g_free (request->setting_name);
248
get_secrets_keyring_cb (GnomeKeyringResult result,
261
get_secrets_keyring_cb (GObject *source,
262
GAsyncResult *result,
252
265
ShellAgentRequest *closure;
253
266
ShellNetworkAgent *self;
254
267
ShellNetworkAgentPrivate *priv;
268
GError *secret_error = NULL;
255
269
GError *error = NULL;
256
270
gint n_found = 0;
258
273
GHashTable *outer;
260
if (result == GNOME_KEYRING_RESULT_CANCELLED)
275
items = secret_service_search_finish (NULL, result, &secret_error);
277
if (g_error_matches (secret_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
279
g_error_free (secret_error);
263
283
closure = user_data;
264
284
self = closure->self;
265
285
priv = self->priv;
267
closure->keyring_op = NULL;
269
if (result == GNOME_KEYRING_RESULT_DENIED)
272
NM_SECRET_AGENT_ERROR,
273
NM_SECRET_AGENT_ERROR_USER_CANCELED,
274
"Access to the secret storage was denied by the user");
276
closure->callback (NM_SECRET_AGENT (closure->self), closure->connection, NULL, error, closure->callback_data);
281
if (result != GNOME_KEYRING_RESULT_OK &&
282
result != GNOME_KEYRING_RESULT_NO_MATCH)
285
NM_SECRET_AGENT_ERROR,
286
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
287
"Internal error while retrieving secrets from the keyring (result %d)", result);
289
closure->callback (NM_SECRET_AGENT (closure->self), closure->connection, NULL, error, closure->callback_data);
294
for (iter = list; iter; iter = g_list_next (iter))
296
GnomeKeyringFound *item = iter->data;
299
for (i = 0; i < item->attributes->len; i++)
287
if (secret_error != NULL)
290
NM_SECRET_AGENT_ERROR,
291
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
292
"Internal error while retrieving secrets from the keyring (%s)", secret_error->message);
293
g_error_free (secret_error);
294
closure->callback (NM_SECRET_AGENT (closure->self), closure->connection, NULL, error, closure->callback_data);
299
for (l = items; l; l = g_list_next (l))
301
SecretItem *item = l->data;
302
GHashTable *attributes;
304
const gchar *name, *attribute;
305
SecretValue *secret = secret_item_get_secret (item);
307
/* This can happen if the user denied a request to unlock */
311
attributes = secret_item_get_attributes (item);
312
g_hash_table_iter_init (&iter, attributes);
313
while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&attribute))
301
GnomeKeyringAttribute *attr = &gnome_keyring_attribute_list_index (item->attributes, i);
303
if (g_strcmp0 (attr->name, SHELL_KEYRING_SK_TAG) == 0
304
&& (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING))
315
if (g_strcmp0 (name, SHELL_KEYRING_SK_TAG) == 0)
306
gchar *secret_name = g_strdup (attr->value.string);
317
gchar *secret_name = g_strdup (attribute);
308
319
if (!closure->is_vpn)
310
321
GValue *secret_value = g_slice_new0 (GValue);
311
322
g_value_init (secret_value, G_TYPE_STRING);
312
g_value_set_string (secret_value, item->secret);
323
g_value_set_string (secret_value, secret_value_get (secret, NULL));
314
325
g_hash_table_insert (closure->entries, secret_name, secret_value);
317
g_hash_table_insert (closure->vpn_entries, secret_name, g_strdup (item->secret));
328
g_hash_table_insert (closure->vpn_entries, secret_name, g_strdup (secret_value_get (secret, NULL)));
319
330
if (closure->hints)
320
331
n_found += strv_has (closure->hints, secret_name);
335
g_hash_table_unref (attributes);
336
secret_value_unref (secret);
341
g_hash_table_unref (attributes);
342
secret_value_unref (secret);
345
g_list_free_full (items, g_object_unref);
329
347
if (n_found == 0 &&
330
348
(closure->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION))
416
request->keyring_op = gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
417
get_secrets_keyring_cb,
419
NULL, /* GDestroyNotify */
420
SHELL_KEYRING_UUID_TAG,
421
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
422
nm_connection_get_uuid (connection),
423
SHELL_KEYRING_SN_TAG,
424
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
435
attributes = secret_attributes_build (&network_agent_schema,
436
SHELL_KEYRING_UUID_TAG, nm_connection_get_uuid (connection),
437
SHELL_KEYRING_SN_TAG, setting_name,
440
secret_service_search (NULL, &network_agent_schema, attributes,
441
SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
442
request->cancellable, get_secrets_keyring_cb, request);
444
g_hash_table_unref (attributes);
576
attrs = gnome_keyring_attribute_list_new ();
577
gnome_keyring_attribute_list_append_string (attrs,
578
SHELL_KEYRING_UUID_TAG,
580
gnome_keyring_attribute_list_append_string (attrs,
581
SHELL_KEYRING_SN_TAG,
583
gnome_keyring_attribute_list_append_string (attrs,
584
SHELL_KEYRING_SK_TAG,
593
return secret_attributes_build (&network_agent_schema,
594
SHELL_KEYRING_UUID_TAG, connection_uuid,
595
SHELL_KEYRING_SN_TAG, setting_name,
596
SHELL_KEYRING_SK_TAG, setting_key,
650
661
display_name ? NULL : &alt_display_name);
651
662
g_assert (attrs);
653
gnome_keyring_item_create (NULL,
654
GNOME_KEYRING_ITEM_GENERIC_SECRET,
655
display_name ? display_name : alt_display_name,
664
secret_password_storev (&network_agent_schema, attrs, SECRET_COLLECTION_DEFAULT,
665
display_name ? display_name : alt_display_name,
666
secret, NULL, save_secret_cb, r);
663
gnome_keyring_attribute_list_free (attrs);
668
g_hash_table_unref (attrs);
664
669
g_free (alt_display_name);
769
keyring_delete_cb (GnomeKeyringResult result, gpointer user_data)
775
delete_find_items_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
774
delete_items_cb (GObject *source,
775
GAsyncResult *result,
777
778
KeyringRequest *r = user_data;
779
GError *secret_error = NULL;
779
780
GError *error = NULL;
780
781
NMSecretAgentDeleteSecretsFunc callback = r->callback;
782
if ((result == GNOME_KEYRING_RESULT_OK) || (result == GNOME_KEYRING_RESULT_NO_MATCH))
784
for (iter = list; iter != NULL; iter = g_list_next (iter))
786
GnomeKeyringFound *found = (GnomeKeyringFound *) iter->data;
788
gnome_keyring_item_delete (found->keyring, found->item_id, keyring_delete_cb, NULL, NULL);
783
secret_password_clear_finish (result, &secret_error);
784
if (secret_error != NULL)
793
786
error = g_error_new (NM_SECRET_AGENT_ERROR,
794
787
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
795
"The request could not be completed. Keyring result: %d",
788
"The request could not be completed. Keyring result: %s",
789
secret_error->message);
790
g_error_free (secret_error);
799
793
callback (r->self, r->connection, error, r->callback_data);
800
794
g_clear_error (&error);
795
keyring_request_free (r);