static gboolean password_get_hook(gpointer source, gpointer hook_data) { PasswordRequest *req = source; GError* error = NULL; gchar *pass; // "full search" debug_print("LIBSECRET:: user: %s, server: %s, proto: %s \n", req->user, req->server, req->protocol); pass = secret_password_lookup_sync(GENERIC_SCHEMA, NULL, &error, "user", req->user, "server", req->server, "protocol", req->protocol, NULL); if (pass != NULL) { req->password = g_strdup(pass); secret_password_free(pass); return TRUE; } else if (error != NULL) { debug_print("libsecret access failed: %s.", error->message); g_error_free(error); return FALSE; } // fallback debug_print("LIBSECRET:: user: %s, server: %s \n", req->user, req->server); pass = secret_password_lookup_sync(GENERIC_SCHEMA, NULL, &error, "user", req->user, "server", req->server, NULL); if (pass != NULL) { req->password = g_strdup(pass); secret_password_free(pass); return TRUE; } else if (error != NULL) { debug_print("libsecret access failed: %s.", error->message); g_error_free(error); return FALSE; } return FALSE; }
int main () { GError *error = NULL; gchar *password = secret_password_lookup_sync (FOO_SCHEMA, NULL, &error, NULL); if (error != NULL) { g_critical ("%s\n", error->message); g_error_free (error); return 1; } g_message ("Password %s\n", password); secret_password_free (password); return 0; }
/***************************************************************************** ** pfUnixPasswordStore ** *****************************************************************************/ ST::string pfUnixPasswordStore::GetPassword(const ST::string& username) { GError *error = nullptr; gchar *password = secret_password_lookup_sync(&pfPasswordStore_Schema, nullptr, &error, "username", username.c_str(), "server", GetServerDisplayName().c_str(), nullptr); ST::string result; if (error) { // Throw away the error and treat it as if no password was found... g_error_free(error); } else if (password) { result = ST::string::from_utf8(password); secret_password_free(password); } return result; }
gchar* remmina_plugin_glibsecret_get_password(RemminaFile *remminafile, const gchar *key) { TRACE_CALL(__func__); GError *r = NULL; const gchar *path; gchar *password; gchar *p; path = remmina_plugin_service->file_get_path(remminafile); password = secret_password_lookup_sync(&remmina_file_secret_schema, NULL, &r, "filename", path, "key", key, NULL); if (r == NULL) { // remmina_plugin_service->log_printf("[glibsecret] found password for file %s\n", path); p = g_strdup(password); secret_password_free(password); return p; }else { remmina_plugin_service->log_printf("[glibsecret] password cannot be found for file %s\n", path); return NULL; } }
static char * _get_integer_value_0( const SecretSchema * s,int key ) { return secret_password_lookup_sync( s,NULL,NULL,"integer",key,NULL ) ; }
static char * _get_string_value_0( const SecretSchema * s,const char * key ) { return secret_password_lookup_sync( s,NULL,NULL,"string",key,NULL ) ; }
GVariant * goa_utils_lookup_credentials_sync (GoaProvider *provider, GoaObject *object, GCancellable *cancellable, GError **error) { gchar *password_key; GVariant *ret; gchar *password; const gchar *id; GError *sec_error = NULL; g_return_val_if_fail (GOA_IS_PROVIDER (provider), NULL); g_return_val_if_fail (GOA_IS_OBJECT (object) && goa_object_peek_account (object) != NULL, FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); ret = NULL; password_key = NULL; password = NULL; id = goa_account_get_id (goa_object_peek_account (object)); password_key = g_strdup_printf ("%s:gen%d:%s", goa_provider_get_provider_type (GOA_PROVIDER (provider)), goa_provider_get_credentials_generation (GOA_PROVIDER (provider)), id); password = secret_password_lookup_sync (&secret_password_schema, cancellable, &sec_error, "goa-identity", password_key, NULL); if (sec_error != NULL) { g_warning ("secret_password_lookup_sync() failed: %s", sec_error->message); g_set_error_literal (error, GOA_ERROR, GOA_ERROR_FAILED, /* TODO: more specific */ _("Failed to retrieve credentials from the keyring")); g_error_free (sec_error); goto out; } else if (password == NULL) { g_warning ("secret_password_lookup_sync() returned NULL"); g_set_error_literal (error, GOA_ERROR, GOA_ERROR_FAILED, /* TODO: more specific */ _("No credentials found in the keyring")); goto out; } g_debug ("Retrieved keyring credentials for id: %s", id); ret = g_variant_parse (NULL, /* GVariantType */ password, NULL, /* limit */ NULL, /* endptr */ error); if (ret == NULL) { g_prefix_error (error, _("Error parsing result obtained from the keyring: ")); goto out; } if (g_variant_is_floating (ret)) g_variant_ref_sink (ret); out: g_free (password); g_free (password_key); return ret; }
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; }