static int store_password(jaro_credential_t *cred) { gchar desc[1024]; GnomeKeyringResult keyres; /* Only store complete credentials */ if (!cred->protocol || !cred->host || !cred->username || !cred->password) return 1; g_snprintf(desc, sizeof(desc), "%s %s", cred->protocol, cred->host); keyres = gnome_keyring_store_password_sync(&jaro_schema, GNOME_KEYRING_DEFAULT, desc, cred->password, "protocol", cred->protocol, "host", cred->host, "path", cred->path, "username", cred->username, NULL); if (keyres != GNOME_KEYRING_RESULT_OK) { error("failed to store password: %s", gnome_keyring_result_to_message(keyres)); return 1; } return 0; }
static void store_password(git_credential_t *cred) { gchar desc[1024]; GnomeKeyringResult keyres; /* Only store complete credentials */ if (!cred->protocol || !cred->host || !cred->username || !cred->password) return; g_snprintf(desc, sizeof(desc), "Git %s", cred->host); keyres = gnome_keyring_store_password_sync(&git_schema, GNOME_KEYRING_DEFAULT, desc, cred->password, "protocol", cred->protocol, "host", cred->host, "path", cred->path, "username", cred->username, NULL); if (keyres != GNOME_KEYRING_RESULT_OK) { error("failed to store password"); return; } }
static void session_authenticate (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { GnomeKeyringResult result; gchar *user = NULL; gchar *password = NULL; // Get the previous user name that was used for this uri // TODO Gconf stuff // There wasn't one, so let's use the logged in user's name if (!user) user = g_strdup(getenv("USER")); if (retrying) { // Prompt the user if there were no valid credentials in the keyring GtkWidget *user_field = NULL; GtkWidget *pass_field = NULL; GtkWidget *dialog = get_credentials_dialog(user, soup_auth_get_realm(auth), soup_auth_get_host(auth), &user_field, &pass_field); gint response = gtk_dialog_run(GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_REJECT) { gtk_widget_destroy(dialog); return; } g_free(user); user = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_field))); password = g_strdup(gtk_entry_get_text(GTK_ENTRY(pass_field))); gtk_widget_destroy(dialog); // Store password in the keyring gchar * description = g_strdup_printf("Nautilus-Sendto-Trac:%s:%s", soup_auth_get_host(auth), soup_auth_get_realm(auth)); result = gnome_keyring_store_password_sync(HTTP_AUTH_SCHEMA, NULL, description, password, "host", soup_auth_get_host(auth), "realm", soup_auth_get_realm(auth), "user", user, NULL); g_free(description); g_free(password); } // Try and get a password for the user from the keyring result = gnome_keyring_find_password_sync(HTTP_AUTH_SCHEMA, &password, "host", soup_auth_get_host(auth), "realm", soup_auth_get_realm(auth), "user", user, NULL); if (result != GNOME_KEYRING_RESULT_OK) password = ""; // Do the authentication soup_auth_authenticate(auth, user, password); g_free(user); if (result == GNOME_KEYRING_RESULT_OK) gnome_keyring_free_password(password); return; }
static GnomeKeyringResult set(char *name, char *password) { return gnome_keyring_store_password_sync( &schema, GNOME_KEYRING_DEFAULT, name, password, "name", name, "application", application, NULL); }
GnomeKeyringResult gnome_keyring_set(const char *service, const char *description, const char *username, const char *password) { return gnome_keyring_store_password_sync( &GNOME_KEYRING_DEFAULT_SCHEMA, NULL, description, password, "service", service, "username", username, NULL); }
// static bool OTKeyring::Gnome_StoreSecret(const OTString& strUser, const OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OT_ASSERT(thePassword.getMemorySize() > 0); OTData theData(thePassword.getMemory(), thePassword.getMemorySize()); OTASCIIArmor ascData(theData); theData.zeroMemory(); // security reasons. OTString strOutput; const bool bSuccess = ascData.Exists() && ascData.WriteArmoredString(strOutput, "DERIVED KEY"); // There's no // default, to // force you to // enter the right // string. ascData.zeroMemory(); GnomeKeyringResult theResult = GNOME_KEYRING_RESULT_IO_ERROR; if (bSuccess && strOutput.Exists()) { theResult = gnome_keyring_store_password_sync( GNOME_KEYRING_NETWORK_PASSWORD, GNOME_KEYRING_DEFAULT, // GNOME_KEYRING_SESSION, str_display.c_str(), strOutput.Get(), "user", strUser.Get(), "protocol", "opentxs", // todo: hardcoding. nullptr); strOutput.zeroMemory(); bool bResult = false; if (theResult == GNOME_KEYRING_RESULT_OK) bResult = true; else otErr << "OTKeyring::Gnome_StoreSecret: " << "Failure in gnome_keyring_store_password_sync: " << gnome_keyring_result_to_message(theResult) << '\n'; return bResult; } otOut << "OTKeyring::Gnome_StoreSecret: No secret to store.\n"; return false; }
bool GnomeKeychain::setPassword(const QString& account, const QString& password) { Q_ASSERT(isAvailable()); QString displayName = QString("%1 account for %2").arg( QCoreApplication::applicationName(), account); GnomeKeyringResult result = gnome_keyring_store_password_sync( &kOurSchema, NULL, displayName.toUtf8().constData(), password.toUtf8().constData(), "username", account.toUtf8().constData(), "service", kServiceName.toUtf8().constData(), NULL); return result == GNOME_KEYRING_RESULT_OK; }
LibBalsaImapServer* libbalsa_imap_server_new_from_config(void) { LibBalsaServer tmp_server; LibBalsaImapServer *imap_server; LibBalsaServer *server; gboolean d, d1; gint tls_mode, conn_limit; tmp_server.host = libbalsa_conf_get_string("Server"); if(strrchr(tmp_server.host, ':') == NULL) { gint port; port = libbalsa_conf_get_int_with_default("Port", &d); if (!d) { gchar *newhost = g_strdup_printf("%s:%d", tmp_server.host, port); g_free(tmp_server.host); tmp_server.host = newhost; } } tmp_server.user = libbalsa_conf_private_get_string("Username"); if (!tmp_server.user) tmp_server.user = g_strdup(getenv("USER")); imap_server = get_or_create(tmp_server.user, tmp_server.host); server = LIBBALSA_SERVER(imap_server); if (server->user) { g_free(tmp_server.user); g_free(tmp_server.host); } else { server->user = tmp_server.user; server->host = tmp_server.host; } d1 = libbalsa_conf_get_bool_with_default("Anonymous", &d); if(!d) server->try_anonymous = !!d1; server->use_ssl |= libbalsa_conf_get_bool("SSL=false"); tls_mode = libbalsa_conf_get_int_with_default("TLSMode", &d); if(!d) server->tls_mode = tls_mode; conn_limit = libbalsa_conf_get_int_with_default("ConnectionLimit", &d); if(!d) imap_server->max_connections = conn_limit; d1 = libbalsa_conf_get_bool_with_default("PersistentCache", &d); if(!d) imap_server->persistent_cache = !!d1; d1 = libbalsa_conf_get_bool_with_default("HasFetchBug", &d); if(!d) imap_server->has_fetch_bug = !!d1; d1 = libbalsa_conf_get_bool_with_default("UseStatus", &d); if(!d) imap_server->use_status = !!d1; d1 = libbalsa_conf_get_bool_with_default("UseIdle", &d); if(!d) imap_server->use_idle = !!d1; if (!server->passwd) { server->remember_passwd = libbalsa_conf_get_bool("RememberPasswd=false"); if(server->remember_passwd) { #if defined(HAVE_LIBSECRET) GError *err = NULL; server->passwd = secret_password_lookup_sync(LIBBALSA_SERVER_SECRET_SCHEMA, NULL, &err, "protocol", server->protocol, "server", server->host, "user", server->user, NULL); if (err) { libbalsa_free_password(server->passwd); server->passwd = NULL; printf(_("Error looking up password for %s@%s: %s\n"), server->user, server->host, err->message); printf(_("Falling back\n")); g_clear_error(&err); server->passwd = libbalsa_conf_private_get_string("Password"); if (server->passwd != NULL) { gchar *buff = libbalsa_rot(server->passwd); libbalsa_free_password(server->passwd); server->passwd = buff; secret_password_store_sync (LIBBALSA_SERVER_SECRET_SCHEMA, NULL, _("Balsa passwords"), server->passwd, NULL, &err, "protocol", server->protocol, "server", server->host, "user", server->user, NULL); /* We could in principle clear the password in the * config file here but we do not for the backward * compatibility. */ if (err) { printf(_("Error storing password for %s@%s: %s\n"), server->user, server->host, err->message); g_error_free(err); } } } #elif defined (HAVE_GNOME_KEYRING) GnomeKeyringResult r; server->passwd = NULL; r = gnome_keyring_find_password_sync(LIBBALSA_SERVER_KEYRING_SCHEMA, &server->passwd, "protocol", server->protocol, "server", server->host, "user", server->user, NULL); if(r != GNOME_KEYRING_RESULT_OK) { gnome_keyring_free_password(server->passwd); server->passwd = NULL; printf("Keyring has no password for %s@%s\n", server->user, server->host); server->passwd = libbalsa_conf_private_get_string("Password"); if (server->passwd != NULL) { gchar *buff = libbalsa_rot(server->passwd); libbalsa_free_password(server->passwd); server->passwd = buff; gnome_keyring_store_password_sync (LIBBALSA_SERVER_KEYRING_SCHEMA, NULL, _("Balsa passwords"), server->passwd, "protocol", server->protocol, "server", server->host, "user", server->user, NULL); /* We could in principle clear the password in the config file here but we do not for the backward compatibility. */ } } #else server->passwd = libbalsa_conf_private_get_string("Password"); if (server->passwd != NULL) { gchar *buff = libbalsa_rot(server->passwd); libbalsa_free_password(server->passwd); server->passwd = buff; } #endif /* defined(HAVE_LIBSECRET) */ } if(server->passwd && server->passwd[0] == '\0') { libbalsa_free_password(server->passwd); server->passwd = NULL; } } return imap_server; }