void GnomeKeyringPasswordBackend::updateLastUsed(PasswordEntry &entry) { initialize(); entry.updated = QDateTime::currentDateTime().toTime_t(); GnomeKeyringAttributeList* attributes = createAttributes(entry); GnomeKeyringResult result = gnome_keyring_item_set_attributes_sync(GNOME_KEYRING_DEFAULT, entry.id.toUInt(), attributes); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) { qWarning() << "GnomeKeyringPasswordBackend::updateLastUsed Cannot updated entry in keyring!"; return; } int index = m_allEntries.indexOf(entry); if (index > -1) { m_allEntries[index] = entry; } }
bool GnomeKeyringPasswordBackend::updateEntry(const PasswordEntry &entry) { initialize(); // Update item attributes GnomeKeyringAttributeList* attributes = createAttributes(entry); GnomeKeyringResult result = gnome_keyring_item_set_attributes_sync(GNOME_KEYRING_DEFAULT, entry.id.toUInt(), attributes); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) { qWarning() << "GnomeKeyringPasswordBackend::updateEntry Cannot updated entry attributes in keyring!"; return false; } // Update secret GnomeKeyringItemInfo* info; result = gnome_keyring_item_get_info_full_sync(GNOME_KEYRING_DEFAULT, entry.id.toUInt(), GNOME_KEYRING_ITEM_INFO_SECRET, &info); if (result != GNOME_KEYRING_RESULT_OK) { qWarning() << "GnomeKeyringPasswordBackend::updateEntry Cannot get entry info from keyring!"; return false; } QByteArray pass = entry.password.toUtf8(); gnome_keyring_item_info_set_secret(info, pass.constData()); result = gnome_keyring_item_set_info_sync(GNOME_KEYRING_DEFAULT, entry.id.toUInt(), info); gnome_keyring_item_info_free(info); if (result != GNOME_KEYRING_RESULT_OK) { qWarning() << "GnomeKeyringPasswordBackend::updateEntry Cannot set entry info in keyring!"; return false; } int index = m_allEntries.indexOf(entry); if (index > -1) { m_allEntries[index] = entry; } return true; }
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); }
NS_IMETHODIMP GnomeKeyring::ModifyLogin(nsILoginInfo *oldLogin, nsISupports *modLogin) { nsresult interfaceok; /* If the second argument is an nsILoginInfo, * just remove the old login and add the new one */ nsCOMPtr<nsILoginInfo> newLogin( do_QueryInterface(modLogin, &interfaceok) ); if (interfaceok == NS_OK) { nsresult rvremovelogin = RemoveLogin(oldLogin); nsresult rvaddlogin = AddLogin(newLogin); if(NS_FAILED(rvremovelogin)) { return rvremovelogin; } else { return rvaddlogin; } } /* Otherwise, it has to be an nsIPropertyBag. * Let's get the attributes from the old login, then append the ones * fetched from the property bag. Gracefully, if an attribute appears * twice in an attribut list, the last value is stored. */ nsCOMPtr<nsIPropertyBag> matchData( do_QueryInterface(modLogin, &interfaceok) ); if (interfaceok != NS_OK) { return interfaceok; } GnomeKeyringResult result; AutoAttributeList attributes; newLoginInfoAttributes(&attributes); appendAttributesFromLogin(oldLogin, attributes); // We need the id of the keyring item to set its attributes. AutoFoundList foundList; result = findLoginItems(attributes, &foundList); MGK_GK_CHECK_NS(result); PRUint32 i = 0, id; for (GList* l = foundList; l != NULL; l = l->next, i++) { GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(l->data); id = found->item_id; if (i >= 1) { NS_ERROR("found more than one item to edit"); return NS_ERROR_FAILURE; } } // set new attributes appendAttributesFromBag(matchData.get(), attributes); result = gnome_keyring_item_set_attributes_sync(keyringName.get(), id, attributes); MGK_GK_CHECK_NS(result); // set new iteminfo, e.g. password AutoItemInfo itemInfo; result = gnome_keyring_item_get_info_sync(keyringName.get(), id, &itemInfo); MGK_GK_CHECK_NS(result); appendItemInfoFromBag(matchData.get(), itemInfo); result = gnome_keyring_item_set_info_sync(keyringName.get(), id, itemInfo); MGK_GK_CHECK_NS(result); return NS_OK; }