/* This should be replaced by more convenient method of accessing gnome-keyring.. We have very unnecessery dependecies with gnome devs here. */ const QStringList DesktopCouchProvider::getOAuthCredentials(void) { QLog::getLogger()->log("Retrieving credentials...",QLog::INFO); //QStringList* creds = NULL; g_set_application_name("desktop-couch-qt"); GnomeKeyringAttributeList* attributes; GnomeKeyringResult result; GList* found_list; GList* i; GnomeKeyringFound * found; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string(attributes,"desktopcouch","oauth"); result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&found_list); char* item; if (result == GNOME_KEYRING_RESULT_OK ) { for ( i = found_list; i != NULL; i = i->next ) { found = (GnomeKeyringFound*)i->data; item = g_strdup(found->secret); QString i(item); QStringList lcreds = i.split(":"); return lcreds; } } QLog::getLogger()->log("Retrieving credentials failed...\n(check if Gnome-Keyring-Daemon is running)",QLog::ERROR); return QStringList(); }
/** * 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; }
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; }
GnomeKeyringResult GnomeKeyring::findItems(GnomeKeyringItemType type, GnomeKeyringAttributeList* attributes, GList** found) { GnomeKeyringResult result; result = gnome_keyring_find_items_sync(type, attributes, found); MGK_GK_CHECK(result, bail1); *found = _g_list_remove_all_custom(*found, matchKeyring, keyringName.get()); bail1: return result; }
gboolean dt_pwstorage_gkeyring_set(const gchar* slot, GHashTable* table) { GnomeKeyringResult result=0; GnomeKeyringAttributeList * attributes; gchar name[256]="Darktable account information for "; /* build up attributes for slot */ 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); /* search for existing item for slot */ GList *items=NULL; gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&items); guint item_id; /* add attributes from hash table*/ GHashTableIter iter; g_hash_table_iter_init (&iter, table); gpointer key, value; while (g_hash_table_iter_next (&iter, &key, &value)) gnome_keyring_attribute_list_append_string (attributes,key,value); if (items) { GnomeKeyringFound *f = (GnomeKeyringFound *)items->data; gnome_keyring_item_set_attributes_sync(DARKTABLE_KEYRING,f->item_id,attributes); } else { g_strlcat(name, slot, sizeof(name)); /* create/update item with attributes */ result = gnome_keyring_item_create_sync(DARKTABLE_KEYRING, GNOME_KEYRING_ITEM_GENERIC_SECRET, name, attributes, NULL, TRUE, &item_id); } gnome_keyring_attribute_list_free(attributes); return (result == GNOME_KEYRING_RESULT_OK); }
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; }
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; }
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 GList * ep_keyring_lookup_passwords (const gchar *user, const gchar *server, const gchar *protocol, GError **error) { GnomeKeyringAttributeList *attributes; GnomeKeyringResult result; GList *passwords = NULL; attributes = gnome_keyring_attribute_list_new (); gnome_keyring_attribute_list_append_string ( attributes, "application", "Evolution"); if (user != NULL) gnome_keyring_attribute_list_append_string ( attributes, "user", user); if (server != NULL) gnome_keyring_attribute_list_append_string ( attributes, "server", server); if (protocol != NULL) gnome_keyring_attribute_list_append_string ( attributes, "protocol", protocol); result = gnome_keyring_find_items_sync ( GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &passwords); if (result != GNOME_KEYRING_RESULT_OK) { g_set_error ( error, EP_KEYRING_ERROR, result, "Unable to find password(s) in " "keyring (Keyring reports: %s)", gnome_keyring_result_to_message (result)); } gnome_keyring_attribute_list_free (attributes); return passwords; }
/** * 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; }