void
newDisabledHostsAttributes(GnomeKeyringAttributeList** attributes)
{
  *attributes = gnome_keyring_attribute_list_new();
  gnome_keyring_attribute_list_append_string(
          *attributes, kDisabledHostMagicAttrName, kDisabledHostMagicAttrValue);
}
/**
 * ggn_keyring_attribs:
 * @user: The username string.
 * @domain: The domain name string.
 *
 * This function will build a G#nomeKeyringAttributeList from the
 * passed username and domain name strings, simplifying access to
 * gnome-keyring.
 *
 * Returns: An allocated #GnomeKeyringAttributeList. Free with
 *          gnome_keyring_attribute_list_free().
 **/
GnomeKeyringAttributeList *ggn_keyring_attribs (const gchar *user,
                                                const gchar *domain) {
  /* initialize an attribute list. */
  GnomeKeyringAttribute attrib;
  GnomeKeyringAttributeList *keyattribs;
  keyattribs = gnome_keyring_attribute_list_new ();

  /* set the "user" attribute. */
  attrib.name = g_strdup (GGN_KEYRING_USER_NAME);
  attrib.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
  attrib.value.string = g_strdup_printf ("%s@%s", user, domain);
  g_array_append_val (keyattribs, attrib);

  /* set the "server" attribute. */
  attrib.name = g_strdup (GGN_KEYRING_SERVER_NAME);
  attrib.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
  attrib.value.string = g_strdup (GGN_KEYRING_SERVER_VAL);
  g_array_append_val (keyattribs, attrib);

  /* set the "object" attribute. */
  attrib.name = g_strdup (GGN_KEYRING_OBJECT_NAME);
  attrib.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
  attrib.value.string = g_strdup (GGN_KEYRING_OBJECT_VAL);
  g_array_append_val (keyattribs, attrib);

  /* set the "protocol" attribute. */
  attrib.name = g_strdup (GGN_KEYRING_PROTOCOL_NAME);
  attrib.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
  attrib.value.string = g_strdup (GGN_KEYRING_PROTOCOL_VAL);
  g_array_append_val (keyattribs, attrib);

  /* return the attribute list. */
  return keyattribs;
}
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;
}
void
newLoginInfoAttributes(GnomeKeyringAttributeList** attributes)
{
  *attributes = gnome_keyring_attribute_list_new();
  gnome_keyring_attribute_list_append_string(
          *attributes, kLoginInfoMagicAttrName, kLoginInfoMagicAttrValue);
}
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);
}
示例#6
0
GnomeKeyringAttributeList *
utils_create_keyring_add_attr_list (NMConnection *connection,
                                    const char *connection_uuid,
                                    const char *connection_id,
                                    const char *setting_name,
                                    const char *setting_key,
                                    char **out_display_name)
{
	GnomeKeyringAttributeList *attrs = NULL;
	NMSettingConnection *s_con;

	if (connection) {
		s_con = nm_connection_get_setting_connection (connection);
		g_return_val_if_fail (s_con != NULL, NULL);
		connection_uuid = nm_setting_connection_get_uuid (s_con);
		connection_id = nm_setting_connection_get_id (s_con);
	}

	g_return_val_if_fail (connection_uuid != NULL, NULL);
	g_return_val_if_fail (connection_id != NULL, NULL);
	g_return_val_if_fail (setting_name != NULL, NULL);
	g_return_val_if_fail (setting_key != NULL, NULL);

	if (out_display_name) {
		*out_display_name = g_strdup_printf ("Network secret for %s/%s/%s",
		                                     connection_id,
		                                     setting_name,
		                                     setting_key);
	}

	attrs = gnome_keyring_attribute_list_new ();
	gnome_keyring_attribute_list_append_string (attrs,
	                                            KEYRING_UUID_TAG,
	                                            connection_uuid);
	gnome_keyring_attribute_list_append_string (attrs,
	                                            KEYRING_SN_TAG,
	                                            setting_name);
	gnome_keyring_attribute_list_append_string (attrs,
	                                            KEYRING_SK_TAG,
	                                            setting_key);
	return attrs;
}
static GnomeKeyringAttributeList* createAttributes(const PasswordEntry &entry)
{
    GnomeKeyringAttributeList* attributes = gnome_keyring_attribute_list_new();

    gnome_keyring_attribute_list_append_string(attributes, "application", "QupZilla");

    QByteArray value = entry.username.toUtf8();
    gnome_keyring_attribute_list_append_string(attributes, "username", value.constData());

    value = entry.data;
    value.replace(PasswordManager::urlEncodePassword(entry.password), "___PASSWORD-VALUE___");
    gnome_keyring_attribute_list_append_string(attributes, "data", value.constData());

    value = entry.host.toUtf8();
    gnome_keyring_attribute_list_append_string(attributes, "host", value.constData());

    gnome_keyring_attribute_list_append_uint32(attributes, "updated", entry.updated);

    return attributes;
}
GnomeKeyringAttributeList *
GnomeKeyring::buildAttributeList(nsILoginInfo *aLogin)
{
  nsAutoString s;
  GnomeKeyringAttributeList *attributes = gnome_keyring_attribute_list_new();

  aLogin->GetHostname(s);
  gnome_keyring_attribute_list_append_string(attributes, kHostnameAttr,
                                             NS_ConvertUTF16toUTF8(s).get());

  // formSubmitURL and httpRealm are not guaranteed to be set.

  aLogin->GetFormSubmitURL(s);
  if (!s.IsVoid()) {
    gnome_keyring_attribute_list_append_string(attributes, kFormSubmitURLAttr,
                                               NS_ConvertUTF16toUTF8(s).get());
  }

  aLogin->GetHttpRealm(s);
  if (!s.IsVoid()) {
    gnome_keyring_attribute_list_append_string(attributes, kHttpRealmAttr,
                                               NS_ConvertUTF16toUTF8(s).get());
  }

  aLogin->GetUsername(s);
  gnome_keyring_attribute_list_append_string(attributes, kUsernameAttr,
                                             NS_ConvertUTF16toUTF8(s).get());
  aLogin->GetUsernameField(s);
  gnome_keyring_attribute_list_append_string(attributes, kUsernameFieldAttr,
                                             NS_ConvertUTF16toUTF8(s).get());
  aLogin->GetPasswordField(s);
  gnome_keyring_attribute_list_append_string(attributes, kPasswordFieldAttr,
                                             NS_ConvertUTF16toUTF8(s).get());

  gnome_keyring_attribute_list_append_string(attributes,
                                             kLoginInfoMagicAttrName,
                                             kLoginInfoMagicAttrValue);

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