359
keyring_pin_check_cb (GnomeKeyringResult result,
358
keyring_pin_check_cb (GObject *source,
359
GAsyncResult *result,
361
360
gpointer user_data)
363
362
BroadbandDeviceInfo *info = user_data;
365
const char *pin = NULL;
366
SecretValue *pin = NULL;
367
GHashTable *attributes;
368
GError *error = NULL;
366
369
const char *simid;
368
info->keyring_id = NULL;
371
list = secret_service_search_finish (NULL, result, &error);
370
if (result != GNOME_KEYRING_RESULT_OK) {
371
374
/* No saved PIN, just ask the user */
372
375
unlock_dialog_new (info->device, info);
376
g_error_free (error);
382
386
for (iter = list;
383
387
(pin == NULL) && iter;
384
388
iter = g_list_next (iter)) {
385
GnomeKeyringFound *found = iter->data;
388
391
/* Look for a matching "simid" attribute */
389
for (i = 0; (pin == NULL) && i < found->attributes->len; i++) {
390
GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index (found->attributes, i);
392
attributes = secret_item_get_attributes (item);
393
if (g_strcmp0 (simid, g_hash_table_lookup (attributes, "simid")))
394
pin = secret_item_get_secret (item);
397
g_hash_table_unref (attributes);
392
if (g_strcmp0 (attr.name, "simid") == 0 &&
393
attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING &&
394
g_strcmp0 (attr.value.string, simid) == 0) {
402
404
if (pin == NULL) {
403
/* Fall back to the first result's PIN */
404
pin = ((GnomeKeyringFound *) list->data)->secret;
405
/* Fall back to the first result's PIN if we have one */
407
pin = secret_item_get_secret (list->data);
405
408
if (pin == NULL) {
406
/* Should never get here */
407
g_warn_if_fail (pin != NULL);
408
409
unlock_dialog_new (info->device, info);
414
/* Send the PIN code to ModemManager */
413
415
mm_sim_send_pin (info->mm_sim,
416
secret_value_get (pin, NULL),
415
417
NULL, /* cancellable */
416
418
(GAsyncReadyCallback)autounlock_sim_send_pin_ready,
420
secret_value_unref (pin);
422
425
GAsyncResult *res,
423
426
BroadbandDeviceInfo *info)
425
430
info->mm_sim = mm_modem_get_sim_finish (modem, res, NULL);
426
431
if (!info->mm_sim)
427
432
/* Ok, the modem may not need it actually */
434
439
/* If we have a device ID ask the keyring for any saved SIM-PIN codes */
435
440
if (mm_modem_get_device_identifier (info->mm_modem) &&
436
441
mm_modem_get_unlock_required (info->mm_modem) == MM_MODEM_LOCK_SIM_PIN) {
437
g_warn_if_fail (info->keyring_id == NULL);
438
info->keyring_id = gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
439
keyring_pin_check_cb,
443
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
444
mm_modem_get_device_identifier (info->mm_modem),
442
attrs = secret_attributes_build (&mobile_secret_schema, "devid",
443
mm_modem_get_device_identifier (info->mm_modem),
445
secret_service_search (NULL, &mobile_secret_schema, attrs,
446
SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
447
info->cancellable, keyring_pin_check_cb, info);
448
g_hash_table_unref (attrs);
450
/* Couldn't get a device ID, but unlock required; present dialog */
451
unlock_dialog_new (info->device, info);
449
454
/* Couldn't get a device ID, but unlock required; present dialog */
981
986
if (info->mm_object)
982
987
g_object_unref (info->mm_object);
984
if (info->keyring_id)
985
gnome_keyring_cancel_request (info->keyring_id);
986
989
if (info->dialog)
987
990
unlock_dialog_destroy (info);
991
g_object_unref (info->cancellable);
989
993
g_slice_free (BroadbandDeviceInfo, info);