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); }
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; }
char * get_password(const char * name) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password; 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_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); break; } gnome_keyring_found_list_free(found_list); return password; }
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); }
void newLoginInfoAttributes(GnomeKeyringAttributeList** attributes) { *attributes = gnome_keyring_attribute_list_new(); gnome_keyring_attribute_list_append_string( *attributes, kLoginInfoMagicAttrName, kLoginInfoMagicAttrValue); }
/* This should be replaced by more convenient method of accessing gnome-keyring.. We have very unnecessery dependecies with gnome devs here. */ const QStringList DesktopCouchProvider::getOAuthCredentials(void) { QLog::getLogger()->log("Retrieving credentials...",QLog::INFO); //QStringList* creds = NULL; g_set_application_name("desktop-couch-qt"); GnomeKeyringAttributeList* attributes; GnomeKeyringResult result; GList* found_list; GList* i; GnomeKeyringFound * found; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); gnome_keyring_attribute_list_append_string(attributes,"desktopcouch","oauth"); result = gnome_keyring_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&found_list); char* item; if (result == GNOME_KEYRING_RESULT_OK ) { for ( i = found_list; i != NULL; i = i->next ) { found = (GnomeKeyringFound*)i->data; item = g_strdup(found->secret); QString i(item); QStringList lcreds = i.split(":"); return lcreds; } } QLog::getLogger()->log("Retrieving credentials failed...\n(check if Gnome-Keyring-Daemon is running)",QLog::ERROR); return QStringList(); }
void newDisabledHostsAttributes(GnomeKeyringAttributeList** attributes) { *attributes = gnome_keyring_attribute_list_new(); gnome_keyring_attribute_list_append_string( *attributes, kDisabledHostMagicAttrName, kDisabledHostMagicAttrValue); }
void addAttribute(GnomeKeyringAttributeList* attributes, const char* name, const nsAString & value) { gnome_keyring_attribute_list_append_string( attributes, name, NS_ConvertUTF16toUTF8(value).get()); }
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); }
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; }
char * gnome_keyring_sf_get_password(const char * repo_id, const char * type, guint *item_id) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password = NULL; 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_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); *item_id = -1; if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); *item_id = found->item_id; break; } gnome_keyring_found_list_free(found_list); return password; }
GHashTable* dt_pwstorage_gkeyring_get(const gchar* slot) { GHashTable* table = g_hash_table_new_full (g_str_hash,g_str_equal, g_free, g_free); /* find item for slot */ GList *items=NULL; GnomeKeyringAttributeList *attributes; 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); gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,attributes,&items); gnome_keyring_attribute_list_free(attributes); /* if item found get the attributes into result table and return */ if (items) { GnomeKeyringFound *f = (GnomeKeyringFound *)items->data; /* get all attributes of found item */ gnome_keyring_item_get_attributes_sync (DARKTABLE_KEYRING,f->item_id,&attributes); /* build hash table result */ for (int i=0; i<attributes->len; i++) { GnomeKeyringAttribute *attribute = &gnome_keyring_attribute_list_index (attributes,i); if (attribute != NULL) { if( strcmp(attribute->name,"slot")!=0 && strcmp(attribute->name,"magic")!=0 ) g_hash_table_insert (table,g_strdup (attribute->name),g_strdup(attribute->value.string)); } else break; } gnome_keyring_attribute_list_free(attributes); gnome_keyring_found_free (items->data); } return table; }
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); }
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; }
char * get_password(const int argc, char * argv[]) { GnomeKeyringAttributeList * attributes; GnomeKeyringResult result; GList * found_list; GList * i; GnomeKeyringFound * found; char * password; int j; attributes = g_array_new(FALSE, FALSE, sizeof (GnomeKeyringAttribute)); for (j = 2; 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_find_items_sync(GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, &found_list); gnome_keyring_attribute_list_free(attributes); if (result != GNOME_KEYRING_RESULT_OK) return NULL; for (i = found_list; i != NULL; i = i->next) { found = i->data; password = g_strdup(found->secret); break; } gnome_keyring_found_list_free(found_list); return password; }
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; }
void GnomeKeyring::appendAttributesFromBag(nsIPropertyBag *matchData, GnomeKeyringAttributeList * &attributes) { nsAutoString s, property, propName; nsCOMPtr<nsIVariant> propValue; nsresult result; gnome_keyring_attribute_list_append_string(attributes, kLoginInfoMagicAttrName, kLoginInfoMagicAttrValue); property.AssignLiteral(kHostnameAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); gnome_keyring_attribute_list_append_string(attributes, kHostnameAttr, NS_ConvertUTF16toUTF8(s).get()); } // formSubmitURL and httpRealm are not guaranteed to be set. property.AssignLiteral(kFormSubmitURLAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); if (!s.IsVoid()){ gnome_keyring_attribute_list_append_string(attributes, kFormSubmitURLAttr, NS_ConvertUTF16toUTF8(s).get()); } } property.AssignLiteral(kHttpRealmAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); if (!s.IsVoid()){ gnome_keyring_attribute_list_append_string(attributes, kHttpRealmAttr, NS_ConvertUTF16toUTF8(s).get()); } } property.AssignLiteral(kUsernameFieldAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); gnome_keyring_attribute_list_append_string(attributes, kUsernameFieldAttr, NS_ConvertUTF16toUTF8(s).get()); } property.AssignLiteral(kPasswordFieldAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); gnome_keyring_attribute_list_append_string(attributes, kPasswordFieldAttr, NS_ConvertUTF16toUTF8(s).get()); } property.AssignLiteral(kUsernameAttr); result = matchData->GetProperty(property, getter_AddRefs(propValue)); if ( result != NS_ERROR_FAILURE ) { propValue->GetAsAString(s); gnome_keyring_attribute_list_append_string(attributes, kUsernameAttr, NS_ConvertUTF16toUTF8(s).get()); } }