gchar * gkr_attributes_print (GnomeKeyringAttributeList *attrs) { GnomeKeyringAttribute *attr; GString *string; guint i; if (attrs == NULL) return g_strdup ("(null)"); string = g_string_new ("{ "); for (i = 0; attrs && i < attrs->len; ++i) { if (i > 0) g_string_append (string, ", "); attr = &gnome_keyring_attribute_list_index (attrs, i); /* Add in the attribute type */ g_string_append (string, attr->name ? attr->name : "(null)"); g_string_append (string, ": "); /* String values */ if (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) { g_string_append_c (string, '"'); g_string_append (string, attr->value.string ? attr->value.string : ""); g_string_append_c (string, '"'); /* Integer values */ } else if (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) { g_string_append_printf (string, "%u", (guint)attr->value.integer); } else { g_string_append (string, "???"); } } g_string_append (string, " }"); return g_string_free (string, FALSE); }
GHashTable* dt_pwstorage_gkeyring_get(const gchar* slot) { GHashTable* table = g_hash_table_new_full (g_str_hash,g_str_equal, g_free, g_free); /* find item for slot */ GList *items=NULL; GnomeKeyringAttributeList *attributes; attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string (attributes,"magic",PACKAGE_NAME); gnome_keyring_attribute_list_append_string (attributes,"slot",slot); gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&items); gnome_keyring_attribute_list_free(attributes); /* if item found get the attributes into result table and return */ if (items) { GnomeKeyringFound *f = (GnomeKeyringFound *)items->data; /* get all attributes of found item */ gnome_keyring_item_get_attributes_sync (DARKTABLE_KEYRING,f->item_id,&attributes); /* build hash table result */ for (int i=0; i<attributes->len; i++) { GnomeKeyringAttribute *attribute = &gnome_keyring_attribute_list_index (attributes,i); if (attribute != NULL) { if( strcmp(attribute->name,"slot")!=0 && strcmp(attribute->name,"magic")!=0 ) g_hash_table_insert (table,g_strdup (attribute->name),g_strdup(attribute->value.string)); } else break; } gnome_keyring_attribute_list_free(attributes); gnome_keyring_found_free (items->data); } return table; }
static void keyring_pin_check_cb (GnomeKeyringResult result, GList *list, gpointer user_data) { BroadbandDeviceInfo *info = user_data; GList *iter; const char *pin = NULL; const char *simid; info->keyring_id = NULL; if (result != GNOME_KEYRING_RESULT_OK) { /* No saved PIN, just ask the user */ unlock_dialog_new (info->device, info); return; } /* Look for a result with a matching "simid" attribute since that's * better than just using a matching "devid". The PIN is really tied * to the SIM, not the modem itself. */ simid = mm_sim_get_identifier (info->mm_sim); if (simid) { for (iter = list; (pin == NULL) && iter; iter = g_list_next (iter)) { GnomeKeyringFound *found = iter->data; int i; /* Look for a matching "simid" attribute */ for (i = 0; (pin == NULL) && i < found->attributes->len; i++) { GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index (found->attributes, i); if (g_strcmp0 (attr.name, "simid") == 0 && attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING && g_strcmp0 (attr.value.string, simid) == 0) { pin = found->secret; break; } } } } if (pin == NULL) { /* Fall back to the first result's PIN */ pin = ((GnomeKeyringFound *) list->data)->secret; if (pin == NULL) { /* Should never get here */ g_warn_if_fail (pin != NULL); unlock_dialog_new (info->device, info); return; } } mm_sim_send_pin (info->mm_sim, pin, NULL, /* cancellable */ (GAsyncReadyCallback)autounlock_sim_send_pin_ready, info); }
static void keyring_find_secrets_cb (GnomeKeyringResult result, GList *list, gpointer user_data) { KeyringCall *call = user_data; Request *r = call->r; GError *error = NULL; const char *connection_id = NULL; GHashTable *secrets = NULL, *settings = NULL; GList *iter; gboolean hint_found = FALSE, ask = FALSE; r->keyring_calls = g_slist_remove (r->keyring_calls, call); if (r->canceled) { /* Callback already called by NM or dispose */ request_free (r); return; } connection_id = nm_connection_get_id (r->connection); if (result == GNOME_KEYRING_RESULT_CANCELLED) { error = g_error_new_literal (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_USER_CANCELED, "The secrets request was canceled by the user"); goto done; } else if ( result != GNOME_KEYRING_RESULT_OK && result != GNOME_KEYRING_RESULT_NO_MATCH) { error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, "%s.%d - failed to read secrets from keyring (result %d)", __FILE__, __LINE__, result); goto done; } /* Only ask if we're allowed to, ie if flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE */ if (r->flags && g_list_length (list) == 0) { g_message ("No keyring secrets found for %s/%s; asking user.", connection_id, r->setting_name); ask_for_secrets (r); return; } secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue); /* Extract the secrets from the list of matching keyring items */ for (iter = list; iter != NULL; iter = g_list_next (iter)) { GnomeKeyringFound *found = iter->data; GnomeKeyringAttribute *attr; const char *key_name = NULL; int i; for (i = 0; i < found->attributes->len; i++) { attr = &(gnome_keyring_attribute_list_index (found->attributes, i)); if ( (strcmp (attr->name, KEYRING_SK_TAG) == 0) && (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)) { key_name = attr->value.string; g_hash_table_insert (secrets, g_strdup (key_name), string_to_gvalue (found->secret)); /* See if this property matches a given hint */ if (r->hints && r->hints[0]) { if (!g_strcmp0 (r->hints[0], key_name) || !g_strcmp0 (r->hints[1], key_name)) hint_found = TRUE; } break; } } } /* If there were hints, and none of the hints were returned by the keyring, * get some new secrets. */ if (r->flags) { if (r->hints && r->hints[0] && !hint_found) ask = TRUE; else if (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) { g_message ("New secrets for %s/%s requested; ask the user", connection_id, r->setting_name); ask = TRUE; } else if ( (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION) && is_connection_always_ask (r->connection)) ask = TRUE; } /* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that * will contain all the individual settings hashes. */ settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); g_hash_table_insert (settings, g_strdup (r->setting_name), secrets); done: if (ask) { GHashTableIter hash_iter; const char *setting_name; GHashTable *setting_hash; /* Stuff all the found secrets into the connection for the UI to use */ g_hash_table_iter_init (&hash_iter, settings); while (g_hash_table_iter_next (&hash_iter, (gpointer *) &setting_name, (gpointer *) &setting_hash)) { nm_connection_update_secrets (r->connection, setting_name, setting_hash, NULL); } ask_for_secrets (r); } else { /* Otherwise send the secrets back to NetworkManager */ r->get_callback (NM_SECRET_AGENT (r->agent), r->connection, error ? NULL : settings, error, r->callback_data); request_free (r); } if (settings) g_hash_table_destroy (settings); g_clear_error (&error); }