void GnomeKeyringPasswordBackend::addEntry(const PasswordEntry &entry) { initialize(); PasswordEntry stored = entry; stored.updated = QDateTime::currentDateTime().toTime_t(); guint32 itemId; GnomeKeyringAttributeList* attributes = createAttributes(stored); QByteArray pass = stored.password.toUtf8(); QByteArray host = stored.host.toUtf8(); GnomeKeyringResult result = gnome_keyring_item_create_sync(GNOME_KEYRING_DEFAULT, GNOME_KEYRING_ITEM_GENERIC_SECRET, host.constData(), attributes, pass.constData(), TRUE, // Update if exists &itemId); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) { qWarning() << "GnomeKeyringPasswordBackend::addEntry Cannot add entry to keyring!"; } stored.id = itemId; m_allEntries.append(stored); }
/** * ggn_keyring_item_create: * @user: The username string. * @domain: The domain name string. * @pass: The passphrase string. * * This function will access the gnome-keyring daemon to save * (or update, if one exists) the given gmail account information * into the keyring for use later. * * Returns: Success #gboolean. **/ gboolean ggn_keyring_item_create (const gchar *user, const gchar *domain, const gchar *pass) { /* declare some helping variables. */ guint32 id; gchar *description; GnomeKeyringResult result; GnomeKeyringAttributeList *keyattribs; /* build the string that describes the keyring entry. */ description = g_strdup_printf ("Gmail password for %s@%s", user, domain); /* define some variables for saving the passphrase. */ keyattribs = ggn_keyring_attribs (user, domain); /* synchronously write to the keyring. */ result = gnome_keyring_item_create_sync (NULL, GNOME_KEYRING_ITEM_NETWORK_PASSWORD, description, keyattribs, pass, TRUE, &id); /* free the attributes list and string. */ gnome_keyring_attribute_list_free (keyattribs); g_free (description); /* return our status boolean. */ if (result == GNOME_KEYRING_RESULT_OK) return TRUE; /* otherwise, we failed. */ return FALSE; }
int set_password(const char * name, const char * password) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; guint item_id; 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_item_create_sync(NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET, name, attributes, password, TRUE, &item_id); gnome_keyring_attribute_list_free(attributes); return (result == GNOME_KEYRING_RESULT_OK); }
int gnome_keyring_sf_set_password(const char * repo_id, const char * type, const char * password) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; guint item_id; 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_item_create_sync(NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET, "seafile repository", attributes, password, TRUE, &item_id); gnome_keyring_attribute_list_free(attributes); return (result == GNOME_KEYRING_RESULT_OK); }
NS_IMETHODIMP GnomeKeyring::SetLoginSavingEnabled(const nsAString & aHost, bool isEnabled) { GnomeKeyringResult result; if (isEnabled) { AutoFoundList foundList; result = findHostItems(aHost, &foundList); MGK_GK_CHECKF_NS(result); return deleteFoundItems(foundList, PR_TRUE); } // TODO should check if host is already enabled AutoAttributeList attributes; newDisabledHostsAttributes(&attributes); addAttribute(attributes, kDisabledHostAttrName, aHost); // TODO name should be more explicit const char* name = "Mozilla disabled host entry"; guint itemId; result = gnome_keyring_item_create_sync(keyringName.get(), GNOME_KEYRING_ITEM_NOTE, name, attributes, "", // no secret TRUE, &itemId); MGK_GK_CHECK_NS(result); return NS_OK; }
static gboolean ep_keyring_insert_password (const gchar *user, const gchar *server, const gchar *protocol, const gchar *display_name, const gchar *password, GError **error) { GnomeKeyringAttributeList *attributes; GnomeKeyringResult result; guint32 item_id; g_return_val_if_fail (user != NULL, FALSE); g_return_val_if_fail (server != NULL, FALSE); g_return_val_if_fail (protocol != NULL, FALSE); g_return_val_if_fail (display_name != NULL, FALSE); g_return_val_if_fail (password != NULL, FALSE); attributes = gnome_keyring_attribute_list_new (); gnome_keyring_attribute_list_append_string ( attributes, "application", "Evolution"); gnome_keyring_attribute_list_append_string ( attributes, "user", user); gnome_keyring_attribute_list_append_string ( attributes, "server", server); gnome_keyring_attribute_list_append_string ( attributes, "protocol", protocol); /* XXX We don't use item_id but gnome-keyring doesn't allow * for a NULL pointer. In fact it doesn't even check! */ result = gnome_keyring_item_create_sync ( NULL, GNOME_KEYRING_ITEM_NETWORK_PASSWORD, display_name, attributes, password, TRUE, &item_id); if (result != GNOME_KEYRING_RESULT_OK) { g_set_error ( error, EP_KEYRING_ERROR, result, "Unable to create password in " "keyring (Keyring reports: %s)", gnome_keyring_result_to_message (result)); } gnome_keyring_attribute_list_free (attributes); return (result == GNOME_KEYRING_RESULT_OK); }
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::AddLogin(nsILoginInfo *aLogin) { AutoAttributeList attributes; newLoginInfoAttributes(&attributes); appendAttributesFromLogin(aLogin, attributes); nsAutoString password, hostname; aLogin->GetPassword(password); aLogin->GetHostname(hostname); guint itemId; GnomeKeyringResult result = gnome_keyring_item_create_sync(keyringName.get(), GNOME_KEYRING_ITEM_GENERIC_SECRET, NS_ConvertUTF16toUTF8(hostname).get(), attributes, NS_ConvertUTF16toUTF8(password).get(), TRUE, &itemId); MGK_GK_CHECK_NS(result); return NS_OK; }
int set_password(const int argc, char * argv[], const char * password) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; guint item_id; int j; char * name; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); name = argv[2]; gnome_keyring_attribute_list_append_string(attributes, "name", name); for (j = 3; 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_item_create_sync(NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET, name, attributes, password, TRUE, &item_id); gnome_keyring_attribute_list_free(attributes); return (result == GNOME_KEYRING_RESULT_OK); }