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; }
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; }