Esempio n. 1
0
void Ring::create_password(const std::string & keyring, const std::string & displayName,
                          const std::map<std::string, std::string> & attributes,
                          const std::string & secret)
{
  GHashTable *atts = keyring_attributes(attributes);
  GError *error = NULL;
  secret_password_storev_sync(&s_schema, atts, keyring.c_str(), displayName.c_str(),
                              secret.c_str(), NULL, &error);
  g_hash_table_unref(atts);
  if(error) {
    KeyringException e(error->message);
    g_error_free(error);
    throw e;
  }
}
Esempio n. 2
0
static int keyring_store(struct credential *c)
{
	char *label = NULL;
	GHashTable *attributes = NULL;
	GError *error = NULL;

	/*
	 * Sanity check that what we are storing is actually sensible.
	 * In particular, we can't make a URL without a protocol field.
	 * Without either a host or pathname (depending on the scheme),
	 * we have no primary key. And without a username and password,
	 * we are not actually storing a credential.
	 */
	if (!c->protocol || !(c->host || c->path) ||
	    !c->username || !c->password)
		return EXIT_FAILURE;

	label = make_label(c);
	attributes = make_attr_list(c);
	secret_password_storev_sync(SECRET_SCHEMA_COMPAT_NETWORK,
				    attributes,
				    NULL,
				    label,
				    c->password,
				    NULL,
				    &error);
	g_free(label);
	g_hash_table_unref(attributes);

	if (error != NULL) {
		g_critical("store failed: %s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Esempio n. 3
0
gboolean
g_vfs_keyring_save_password (const gchar  *username,
                             const gchar  *host,
                             const gchar  *domain,
                             const gchar  *protocol,
                             const gchar  *object,
                             const gchar  *authtype,
                             guint32       port,
                             const gchar  *password,
                             GPasswordSave flags)
{
#ifdef HAVE_KEYRING
    const gchar       *keyring;
    GHashTable        *attributes;
    gchar             *label;
    gboolean           ret;

    if (flags == G_PASSWORD_SAVE_NEVER)
        return FALSE;

    keyring = (flags == G_PASSWORD_SAVE_FOR_SESSION) ? SECRET_COLLECTION_SESSION : SECRET_COLLECTION_DEFAULT;

    label = build_network_label (username, host, object, port);
    attributes = build_network_attributes (username, host, domain, protocol, object, authtype, port);

    ret = secret_password_storev_sync (SECRET_SCHEMA_COMPAT_NETWORK, attributes,
                                       keyring, label, password, NULL, NULL);

    g_free (label);
    g_hash_table_unref (attributes);

    return ret;
#else
    return FALSE;
#endif /* HAVE_KEYRING */
}