mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 12:48:51 +00:00
Register secret service errors as DBus errors
* and strip remote error codes from error->message so that they don't clutter things.
This commit is contained in:
parent
8339f296e8
commit
30d1337a7c
@ -1137,8 +1137,10 @@ on_item_load_secret (GObject *source,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
g_object_unref (res);
|
g_object_unref (res);
|
||||||
@ -1337,8 +1339,10 @@ on_get_secrets_complete (GObject *source,
|
|||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (async, error);
|
g_simple_async_result_take_error (async, error);
|
||||||
|
}
|
||||||
|
|
||||||
g_simple_async_result_complete (async);
|
g_simple_async_result_complete (async);
|
||||||
g_object_unref (async);
|
g_object_unref (async);
|
||||||
@ -1545,10 +1549,12 @@ on_item_set_secret (GObject *source,
|
|||||||
|
|
||||||
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
||||||
|
|
||||||
if (error == NULL)
|
if (error == NULL) {
|
||||||
_secret_item_set_cached_secret (self, set->value);
|
_secret_item_set_cached_secret (self, set->value);
|
||||||
else
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
|
}
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
|
@ -539,8 +539,10 @@ on_get_secrets_complete (GObject *source,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
closure->out = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
closure->out = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
|
}
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
|
|
||||||
g_object_unref (res);
|
g_object_unref (res);
|
||||||
@ -896,6 +898,7 @@ on_xlock_called (GObject *source,
|
|||||||
|
|
||||||
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
|
|
||||||
@ -1291,6 +1294,7 @@ on_delete_complete (GObject *source,
|
|||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
}
|
}
|
||||||
@ -1519,6 +1523,7 @@ on_create_collection_called (GObject *source,
|
|||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
}
|
}
|
||||||
@ -1784,6 +1789,7 @@ on_create_item_called (GObject *source,
|
|||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
}
|
}
|
||||||
@ -2056,6 +2062,8 @@ secret_service_read_alias_dbus_path_finish (SecretService *self,
|
|||||||
GVariant *retval;
|
GVariant *retval;
|
||||||
|
|
||||||
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
|
||||||
|
|
||||||
|
_secret_util_strip_remote_error (error);
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -2174,6 +2182,8 @@ secret_service_set_alias_to_dbus_path_finish (SecretService *self,
|
|||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (self), result, error);
|
||||||
|
|
||||||
|
_secret_util_strip_remote_error (error);
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ void _secret_sync_on_result (GObject *source,
|
|||||||
SecretPrompt * _secret_prompt_instance (SecretService *service,
|
SecretPrompt * _secret_prompt_instance (SecretService *service,
|
||||||
const gchar *prompt_path);
|
const gchar *prompt_path);
|
||||||
|
|
||||||
|
void _secret_util_strip_remote_error (GError **error);
|
||||||
|
|
||||||
gchar * _secret_util_parent_path (const gchar *path);
|
gchar * _secret_util_parent_path (const gchar *path);
|
||||||
|
|
||||||
gboolean _secret_util_empty_path (const gchar *path);
|
gboolean _secret_util_empty_path (const gchar *path);
|
||||||
|
@ -331,6 +331,7 @@ on_prompt_prompted (GObject *source,
|
|||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
perform_prompt_complete (res, TRUE);
|
perform_prompt_complete (res, TRUE);
|
||||||
|
|
||||||
@ -377,6 +378,7 @@ on_prompt_dismissed (GObject *source,
|
|||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
perform_prompt_complete (res, TRUE);
|
perform_prompt_complete (res, TRUE);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@
|
|||||||
|
|
||||||
EGG_SECURE_GLIB_DEFINITIONS ();
|
EGG_SECURE_GLIB_DEFINITIONS ();
|
||||||
|
|
||||||
|
GQuark _secret_error_quark = 0;
|
||||||
static const gchar *default_bus_name = SECRET_SERVICE_BUS_NAME;
|
static const gchar *default_bus_name = SECRET_SERVICE_BUS_NAME;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -542,6 +543,9 @@ secret_service_class_init (SecretServiceClass *klass)
|
|||||||
_secret_list_get_type (), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
_secret_list_get_type (), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (SecretServicePrivate));
|
g_type_class_add_private (klass, sizeof (SecretServicePrivate));
|
||||||
|
|
||||||
|
/* Initialize this error domain, registers dbus errors */
|
||||||
|
_secret_error_quark = secret_error_get_quark ();
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -248,6 +248,7 @@ on_service_open_session_plain (GObject *source,
|
|||||||
g_variant_unref (response);
|
g_variant_unref (response);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
}
|
}
|
||||||
@ -296,6 +297,7 @@ on_service_open_session_aes (GObject *source,
|
|||||||
|
|
||||||
/* Other errors result in a failure */
|
/* Other errors result in a failure */
|
||||||
} else {
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
g_simple_async_result_complete (res);
|
g_simple_async_result_complete (res);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ GQuark secret_error_get_quark (void) G_GNUC_CONST;
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SECRET_ERROR_PROTOCOL = 1,
|
SECRET_ERROR_PROTOCOL = 1,
|
||||||
|
SECRET_ERROR_IS_LOCKED = 2,
|
||||||
|
SECRET_ERROR_NO_SUCH_OBJECT = 3,
|
||||||
|
SECRET_ERROR_ALREADY_EXISTS = 4,
|
||||||
} SecretError;
|
} SecretError;
|
||||||
|
|
||||||
typedef struct _SecretCollection SecretCollection;
|
typedef struct _SecretCollection SecretCollection;
|
||||||
|
@ -35,6 +35,11 @@
|
|||||||
* SecretError:
|
* SecretError:
|
||||||
* @SECRET_ERROR_PROTOCOL: received an invalid data or message from the Secret
|
* @SECRET_ERROR_PROTOCOL: received an invalid data or message from the Secret
|
||||||
* Service
|
* Service
|
||||||
|
* @SECRET_ERROR_IS_LOCKED: the item or collection is locked and the operation
|
||||||
|
* cannot be performed
|
||||||
|
* @SECRET_ERROR_NO_SUCH_OBJECT: no such item or collection found in the
|
||||||
|
* Secret Service
|
||||||
|
* @SECRET_ERROR_ALREADY_EXISTS: a relevant item or collection already exists
|
||||||
*
|
*
|
||||||
* Errors returned by the Secret Service. None of the errors are appropriate
|
* Errors returned by the Secret Service. None of the errors are appropriate
|
||||||
* for display to the user.
|
* for display to the user.
|
||||||
@ -77,17 +82,38 @@ _secret_list_get_type (void)
|
|||||||
GQuark
|
GQuark
|
||||||
secret_error_get_quark (void)
|
secret_error_get_quark (void)
|
||||||
{
|
{
|
||||||
static volatile gsize initialized = 0;
|
static volatile gsize quark = 0;
|
||||||
static GQuark quark = 0;
|
|
||||||
|
|
||||||
if (g_once_init_enter (&initialized)) {
|
static const GDBusErrorEntry entries[] = {
|
||||||
quark = g_quark_from_static_string ("secret-error");
|
{ SECRET_ERROR_IS_LOCKED, "org.freedesktop.Secret.Error.IsLocked", },
|
||||||
g_once_init_leave (&initialized, 1);
|
{ SECRET_ERROR_NO_SUCH_OBJECT, "org.freedesktop.Secret.Error.NoSuchObject", },
|
||||||
}
|
{ SECRET_ERROR_ALREADY_EXISTS, "org.freedesktop.Secret.Error.AlreadyExists" },
|
||||||
|
};
|
||||||
|
|
||||||
|
g_dbus_error_register_error_domain ("secret-error", &quark,
|
||||||
|
entries, G_N_ELEMENTS (entries));
|
||||||
|
|
||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_secret_util_strip_remote_error (GError **error)
|
||||||
|
{
|
||||||
|
gchar *remote;
|
||||||
|
|
||||||
|
if (error == NULL || *error == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
remote = g_dbus_error_get_remote_error (*error);
|
||||||
|
if (remote) {
|
||||||
|
if (g_dbus_error_strip_remote_error (*error)) {
|
||||||
|
g_message ("Remote error from secret service: %s: %s",
|
||||||
|
remote, (*error)->message);
|
||||||
|
}
|
||||||
|
g_free (remote);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
_secret_util_parent_path (const gchar *path)
|
_secret_util_parent_path (const gchar *path)
|
||||||
{
|
{
|
||||||
@ -177,10 +203,12 @@ on_get_properties (GObject *source,
|
|||||||
|
|
||||||
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
|
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
|
||||||
|
|
||||||
if (error == NULL)
|
if (error == NULL) {
|
||||||
process_get_all_reply (proxy, retval);
|
process_get_all_reply (proxy, retval);
|
||||||
else
|
} else {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
|
}
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
@ -262,8 +290,10 @@ on_set_property (GObject *source,
|
|||||||
|
|
||||||
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
|
retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
|
||||||
result, &error);
|
result, &error);
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
|
_secret_util_strip_remote_error (&error);
|
||||||
g_simple_async_result_take_error (res, error);
|
g_simple_async_result_take_error (res, error);
|
||||||
|
}
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
g_variant_unref (retval);
|
g_variant_unref (retval);
|
||||||
|
|
||||||
|
@ -378,6 +378,13 @@ test_service_path (Test *test,
|
|||||||
egg_test_wait_idle ();
|
egg_test_wait_idle ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
null_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
|
||||||
|
const gchar *message, gpointer user_data)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -385,6 +392,10 @@ main (int argc, char **argv)
|
|||||||
g_set_prgname ("test-prompt");
|
g_set_prgname ("test-prompt");
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
|
/* Suppress these messages in tests */
|
||||||
|
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG,
|
||||||
|
null_log_handler, NULL);
|
||||||
|
|
||||||
g_test_add ("/prompt/run", Test, "mock-service-prompt.py", setup, test_perform_run, teardown);
|
g_test_add ("/prompt/run", Test, "mock-service-prompt.py", setup, test_perform_run, teardown);
|
||||||
g_test_add ("/prompt/perform-sync", Test, "mock-service-prompt.py", setup, test_perform_sync, teardown);
|
g_test_add ("/prompt/perform-sync", Test, "mock-service-prompt.py", setup, test_perform_sync, teardown);
|
||||||
g_test_add ("/prompt/perform-async", Test, "mock-service-prompt.py", setup, test_perform_async, teardown);
|
g_test_add ("/prompt/perform-async", Test, "mock-service-prompt.py", setup, test_perform_async, teardown);
|
||||||
|
Loading…
Reference in New Issue
Block a user