/** * ggn_keyring_item_find: * @user: The username string. * @domain: The domain name string. * * This function will access the gnome-keyring daemon to find * the passphrase for the given gmail account information in * the keyring. * * Returns: Passphrase or NULL if not found. Free with g_free(). **/ gchar *ggn_keyring_item_find (const gchar *user, const gchar *domain) { /* declare some helping variables. */ GList *found; gchar *passphrase; GnomeKeyringFound *item; GnomeKeyringResult result; GnomeKeyringAttributeList *keyattribs; /* ensure the passphrase is NULL. */ passphrase = NULL; /* define some variables for finding the passphrase. */ keyattribs = ggn_keyring_attribs (user, domain); /* search for the password. */ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, keyattribs, &found); /* did we find a passphrase? */ if (result == GNOME_KEYRING_RESULT_OK) { /* NOTE: read the passphrase from the _first_ found item. */ item = g_list_nth_data (found, 0); passphrase = g_strdup (item->secret); } /* free the variables used for the search. */ gnome_keyring_found_list_free (found); gnome_keyring_attribute_list_free (keyattribs); /* return the found passphrase or NULL. */ return passphrase; }
static void ep_clear_passwords (EPassMsg *msg) { GList *passwords; GError *error = NULL; /* Find all Evolution passwords and delete them. */ passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error); if (passwords != NULL) { ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error); gnome_keyring_found_list_free (passwords); } /* Not finding the requested key is acceptable, but we still * want to leave an informational message on the terminal. */ if (g_error_matches (error, EP_KEYRING_ERROR, GNOME_KEYRING_RESULT_NO_MATCH)) { g_message ("%s", error->message); g_error_free (error); } else if (error != NULL) g_propagate_error (&msg->error, error); if (!msg->noreply) e_flag_set (msg->done); }
GnomeKeyringResult findLogins(const nsAString & aHostname, const nsAString & aActionURL, const nsAString & aHttpRealm, void (*foundLogin)(GnomeKeyringFound* found, T data), T data) { GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new(); gnome_keyring_attribute_list_append_string(attributes, kLoginInfoMagicAttrName, kLoginInfoMagicAttrValue); /* Convert to UTF-8 (but keep a reference to the NS_ConvertUTF16ToUTF8 * instance around, so the string .get() returns won't be free'd */ gnome_keyring_attribute_list_append_string(attributes, kHostnameAttr, NS_ConvertUTF16toUTF8(aHostname).get()); GList* unfiltered; GnomeKeyringResult result = gnome_keyring_find_items_sync( GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &unfiltered ); gnome_keyring_attribute_list_free(attributes); /* Convert to UTF-8 (but keep a reference to the NS_ConvertUTF16ToUTF8 * instance around, so the string .get() returns won't be free'd */ const NS_ConvertUTF16toUTF8 utf8ActionURL(aActionURL); const char* tempActionUrl = utf8ActionURL.IsVoid() ? NULL : utf8ActionURL.get(); const NS_ConvertUTF16toUTF8 utf8HttpRealm(aHttpRealm); const char* tempHttpRealm = utf8HttpRealm.IsVoid() ? NULL : utf8HttpRealm.get(); for (GList* l = unfiltered; l != NULL; l = l->next) { bool isMatch = TRUE; GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(l->data); GnomeKeyringAttribute *attrArray = (GnomeKeyringAttribute *)found->attributes->data; for (PRUint32 i = 0; i < found->attributes->len; i++) { if (attrArray[i].type != GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) continue; const char *attrName = attrArray[i].name; const char *attrValue = attrArray[i].value.string; if (!strcmp(attrName, kFormSubmitURLAttr)) { checkAttribute(tempActionUrl, attrValue, &isMatch); } else if (!strcmp(attrName, kHttpRealmAttr)) { checkAttribute(tempHttpRealm, attrValue, &isMatch); } } if (isMatch) { foundLogin(found, data); } } gnome_keyring_found_list_free(unfiltered); return result; }
char * get_password(const char * name) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string(attributes, "name", name); gnome_keyring_attribute_list_append_string(attributes, "magic", APPLICATION_NAME); result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); break; } gnome_keyring_found_list_free(found_list); return password; }
static char * keyring_lookup_secret (const char *uuid, const char *secret_name) { #if defined(HAVE_LIBSECRET) GHashTable *attrs; GList *list; #else GList *found_list = NULL; GnomeKeyringResult ret; GnomeKeyringFound *found; #endif char *secret = NULL; #if defined(HAVE_LIBSECRET) attrs = secret_attributes_build(&network_manager_secret_schema, KEYRING_UUID_TAG, uuid, KEYRING_SN_TAG, NM_SETTING_VPN_SETTING_NAME, KEYRING_SK_TAG, secret_name, NULL); list = secret_service_search_sync(NULL, &network_manager_secret_schema, attrs, SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS, NULL, NULL); if (list && list->data) { SecretItem *item = list->data; SecretValue *value = secret_item_get_secret(item); if (value) { secret = g_strdup(secret_value_get(value, NULL)); secret_value_unref(value); } } g_list_free_full(list, g_object_unref); g_hash_table_unref(attrs); #else ret = gnome_keyring_find_itemsv_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, &found_list, KEYRING_UUID_TAG, GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, uuid, KEYRING_SN_TAG, GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, NM_SETTING_VPN_SETTING_NAME, KEYRING_SK_TAG, GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, secret_name, NULL); if (ret == GNOME_KEYRING_RESULT_OK && found_list) { found = g_list_nth_data(found_list, 0); secret = gnome_keyring_memory_strdup(found->secret); } gnome_keyring_found_list_free(found_list); #endif return secret; }
char * get_password(const int argc, char * argv[]) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password; int j; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); for (j = 2; j < argc; j++) { char * key; char * value; key = strtok(argv[j], "="); value = strtok(NULL, "="); gnome_keyring_attribute_list_append_string(attributes, key, value); } result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); break; } gnome_keyring_found_list_free(found_list); return password; }
static void ep_forget_passwords (EPassMsg *msg) { GList *passwords; GError *error = NULL; g_hash_table_remove_all (password_cache); /* Find all Evolution passwords and delete them. */ passwords = ep_keyring_lookup_passwords (NULL, NULL, NULL, &error); if (passwords != NULL) { ep_keyring_delete_passwords (NULL, NULL, NULL, passwords, &error); gnome_keyring_found_list_free (passwords); } if (error != NULL) g_propagate_error (&msg->error, error); if (!msg->noreply) e_flag_set (msg->done); }
char * gnome_keyring_sf_get_password(const char * repo_id, const char * type, guint *item_id) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password = NULL; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string(attributes, SEAFILE_GK_ATTR_APP_NAME, SEAFILE_GK_ATTR_APP_VALUE); gnome_keyring_attribute_list_append_string(attributes, SEAFILE_GK_ATTR_REPO_NAME, repo_id); gnome_keyring_attribute_list_append_string(attributes, SEAFILE_GK_ATTR_TYPE_NAME, type); result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); *item_id = -1; if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); *item_id = found->item_id; break; } gnome_keyring_found_list_free(found_list); return password; }
/** * ggn_keyring_item_delete: * @user: The username string. * @domain: The domain name string. * * This function will access the gnome-keyring daemon to delete * the given gmail account information from the keyring. * * Returns: Success #gboolean. **/ gboolean ggn_keyring_item_delete (const gchar *user, const gchar *domain) { /* declare some helping variables. */ GList *found; GnomeKeyringFound *item; GnomeKeyringResult result; GnomeKeyringAttributeList *keyattribs; /* define some variables for finding the passphrase. */ keyattribs = ggn_keyring_attribs (user, domain); /* search for the password. */ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD, keyattribs, &found); /* did we find a passphrase? */ if (result == GNOME_KEYRING_RESULT_OK) { /* NOTE: read the passphrase from the _first_ found item. */ item = g_list_nth_data (found, 0); /* delete this item. */ gnome_keyring_item_delete_sync (NULL, item->item_id); } /* free the variables used for the search. */ gnome_keyring_found_list_free (found); gnome_keyring_attribute_list_free (keyattribs); /* return our status boolean. */ if (result == GNOME_KEYRING_RESULT_OK) return TRUE; /* otherwise, we failed. */ return FALSE; }
static void ep_forget_password (EPassMsg *msg) { GList *passwords; EUri *uri; GError *error = NULL; g_hash_table_remove (password_cache, msg->key); uri = ep_keyring_uri_new (msg->key, &msg->error); if (uri == NULL) goto exit; /* Find all Evolution passwords matching the URI and delete them. * * XXX We didn't always store protocols in the keyring, so for * backward-compatibility we need to lookup passwords by user * and host only (no protocol). But we do send the protocol * to ep_keyring_delete_passwords(), which also knows about * the backward-compatibility issue and will filter the list * appropriately. */ passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error); if (passwords != NULL) { ep_keyring_delete_passwords (uri->user, uri->host, uri->protocol, passwords, &error); gnome_keyring_found_list_free (passwords); } if (error != NULL) g_propagate_error (&msg->error, error); e_uri_free (uri); exit: if (!msg->noreply) e_flag_set (msg->done); }
~AutoFoundList() { if (mFoundList) gnome_keyring_found_list_free(mFoundList); }
static void ep_get_password (EPassMsg *msg) { EUri *uri; GList *passwords; gchar *password; GError *error = NULL; /* Check the in-memory cache first. */ password = g_hash_table_lookup (password_cache, msg->key); if (password != NULL) { msg->password = g_strdup (password); goto exit; } uri = ep_keyring_uri_new (msg->key, &msg->error); if (uri == NULL) goto exit; /* Find the first Evolution password that matches the URI. */ passwords = ep_keyring_lookup_passwords (uri->user, uri->host, uri->protocol, &error); if (passwords != NULL) { GList *iter = passwords; while (iter != NULL) { GnomeKeyringFound *found = iter->data; if (default_keyring && strcmp (default_keyring, found->keyring) != 0) { g_message ("Received a password from keyring '%s'. But looking for the password from '%s' keyring\n", found->keyring, default_keyring); iter = g_list_next (iter); continue; } if (ep_keyring_validate (uri->user, uri->host, uri->protocol, found->attributes)) { msg->password = g_strdup (found->secret); break; } iter = g_list_next (iter); } gnome_keyring_found_list_free (passwords); } if (msg->password != NULL) goto done; /* Clear the previous error, if there was one. If the error was * something other than NO_MATCH then it's likely to occur again. */ if (error != NULL) g_clear_error (&error); /* XXX We didn't always store protocols in the keyring, so for * backward-compatibility we also need to lookup passwords * by user and host only (no protocol). */ passwords = ep_keyring_lookup_passwords (uri->user, uri->host, NULL, &error); if (passwords != NULL) { GList *iter = passwords; while (iter != NULL) { GnomeKeyringFound *found = iter->data; if (default_keyring && strcmp (default_keyring, found->keyring) != 0) { g_message ("Received a password from keyring '%s'. But looking for the password from '%s' keyring\n", found->keyring, default_keyring); iter = g_list_next (iter); continue; } if (ep_keyring_validate (uri->user, uri->host, NULL, found->attributes)) { msg->password = g_strdup (found->secret); break; } iter = g_list_next (iter); } gnome_keyring_found_list_free (passwords); } done: /* Not finding the requested key is acceptable, but we still * want to leave an informational message on the terminal. */ if (g_error_matches (error, EP_KEYRING_ERROR, GNOME_KEYRING_RESULT_NO_MATCH)) { g_message ("%s", error->message); g_error_free (error); } else if (error != NULL) g_propagate_error (&msg->error, error); e_uri_free (uri); exit: if (!msg->noreply) e_flag_set (msg->done); }