Esempio n. 1
0
static int
key_listing(int verbose)
{
  GList *keyrings, *current;
  if (gnome_keyring_list_keyring_names_sync(&keyrings) != OK) {
    fprintf(stderr, "Couldn't get list of keyring names\n");
    return 1;
  }

  for (current = keyrings; current; current = current->next) {
    GList *ids, *cid;
    gchar *keyring = (gchar *)current->data;
    printf("Keyring %s\n", keyring);

    if (gnome_keyring_list_item_ids_sync(keyring, &ids) != OK) {
      fprintf(stderr, "Couldn't list IDs on keyring %s\n", keyring);
      continue;
    }

    for (cid = ids; cid; cid = cid->next) {
      GnomeKeyringItemInfo *info;
      GnomeKeyringResult result =
        gnome_keyring_item_get_info_full_sync(keyring, GPOINTER_TO_INT(cid->data), GNOME_KEYRING_ITEM_INFO_SECRET, &info);
      if (result == GNOME_KEYRING_RESULT_OK) {
        printf(" %s\n", gnome_keyring_item_info_get_display_name(info));
        if (verbose)
          detailed_key_listing(keyring, GPOINTER_TO_INT(cid->data));

        gnome_keyring_item_info_free(info);
      } else {
#define CHECKIT(X) case GNOME_KEYRING_RESULT_ ## X: printf(#X "\n"); break
        switch (result) {
          CHECKIT(OK); // warning if not included
          CHECKIT(DENIED);
          CHECKIT(NO_KEYRING_DAEMON);
          CHECKIT(ALREADY_UNLOCKED);
          CHECKIT(NO_SUCH_KEYRING);
          CHECKIT(BAD_ARGUMENTS);
          CHECKIT(IO_ERROR);
          CHECKIT(CANCELLED);
          CHECKIT(KEYRING_ALREADY_EXISTS);
          CHECKIT(NO_MATCH);
        }
      }
    }
  }

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