diff options
author | Dan Winship <danw@gnome.org> | 2014-10-15 15:27:25 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-10-22 08:29:09 -0400 |
commit | 821258048b620bdc381089c0f442674b0f83be6e (patch) | |
tree | 3122b22b72662fbfa79454fc13011d5bc3f7b7b5 | |
parent | 86331d9ef49716a4bd2a7790289b5665eed84dd1 (diff) | |
download | NetworkManager-821258048b620bdc381089c0f442674b0f83be6e.tar.gz |
libnm-core, libnm, settings: move NMSecretAgentError to nm-errors
Move the definition of NMSecretAgentError to nm-errors, register it
with D-Bus, and verify in the tests that it maps correctly.
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR is renamed to
NM_SECRET_AGENT_ERROR_FAILED, and NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED
to NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, for consistency with other
error domains. While NMSecretAgentError, unlike most other error
domains, has always been correctly mapped across D-Bus, the renaming
is not an ABI break, because the daemon never checks for either of
those values, so all versions of the daemon will treat
"org.freedesktop.NetworkManager.SecretAgent.InternalError" and
"org.freedesktop.NetworkManager.SecretAgent.Failed" the same (by just
ignoring the error name and keeping only the error message).
-rw-r--r-- | clients/tui/nmt-secret-agent.c | 2 | ||||
-rw-r--r-- | libnm-core/nm-errors.c | 4 | ||||
-rw-r--r-- | libnm-core/nm-errors.h | 34 | ||||
-rw-r--r-- | libnm/nm-secret-agent.c | 34 | ||||
-rw-r--r-- | libnm/nm-secret-agent.h | 30 | ||||
-rw-r--r-- | libnm/tests/test-secret-agent.c | 4 |
6 files changed, 49 insertions, 59 deletions
diff --git a/clients/tui/nmt-secret-agent.c b/clients/tui/nmt-secret-agent.c index d2ee50efd3..40ab9c14cb 100644 --- a/clients/tui/nmt-secret-agent.c +++ b/clients/tui/nmt-secret-agent.c @@ -444,7 +444,7 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent, request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); if (g_hash_table_lookup (priv->requests, request_id) != NULL) { /* We already have a request pending for this (connection, setting) */ - error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, + error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, "Request for %s secrets already pending", request_id); nope: callback (agent, connection, NULL, error, callback_data); diff --git a/libnm-core/nm-errors.c b/libnm-core/nm-errors.c index 0e45f50ce8..12da2aa89c 100644 --- a/libnm-core/nm-errors.c +++ b/libnm-core/nm-errors.c @@ -31,6 +31,7 @@ G_DEFINE_QUARK (nm-connection-error-quark, nm_connection_error) G_DEFINE_QUARK (nm-crypto-error-quark, nm_crypto_error) G_DEFINE_QUARK (nm-device-error-quark, nm_device_error) G_DEFINE_QUARK (nm-manager-error-quark, nm_manager_error) +G_DEFINE_QUARK (nm-secret-agent-error-quark, nm_secret_agent_error) G_DEFINE_QUARK (nm-settings-error-quark, nm_settings_error) static void @@ -70,6 +71,9 @@ _nm_dbus_errors_init (void) register_error_domain (NM_MANAGER_ERROR, NM_DBUS_INTERFACE, NM_TYPE_MANAGER_ERROR); + register_error_domain (NM_SECRET_AGENT_ERROR, + NM_DBUS_INTERFACE_SECRET_AGENT, + NM_TYPE_SECRET_AGENT_ERROR); register_error_domain (NM_SETTINGS_ERROR, NM_DBUS_INTERFACE_SETTINGS, NM_TYPE_SETTINGS_ERROR); diff --git a/libnm-core/nm-errors.h b/libnm-core/nm-errors.h index 62434dfb75..c3c26e8763 100644 --- a/libnm-core/nm-errors.h +++ b/libnm-core/nm-errors.h @@ -208,6 +208,40 @@ GQuark nm_manager_error_quark (void); #define NM_MANAGER_ERROR (nm_manager_error_quark ()) /** + * NMSecretAgentError: + * @NM_SECRET_AGENT_ERROR_FAILED: unknown or unclassified error + * @NM_SECRET_AGENT_ERROR_PERMISSION_DENIED: the caller (ie, NetworkManager) is + * not authorized to make this request + * @NM_SECRET_AGENT_ERROR_INVALID_CONNECTION: the connection for which secrets + * were requested is invalid + * @NM_SECRET_AGENT_ERROR_USER_CANCELED: the request was canceled by the user + * @NM_SECRET_AGENT_ERROR_AGENT_CANCELED: the agent canceled the request + * because it was requested to do so by NetworkManager + * @NM_SECRET_AGENT_ERROR_NO_SECRETS: the agent cannot find any secrets for this + * connection + * + * #NMSecretAgentError values are passed by secret agents back to NetworkManager + * when they encounter problems retrieving secrets on behalf of NM. They + * correspond to errors in the "org.freedesktop.NetworkManager.SecretManager" + * namespace. + * + * Client APIs such as nm_client_activate_connection() will not see these error + * codes; instead, the secret agent manager will translate them to the + * corresponding #NMAgentManagerError codes. + */ +typedef enum { + NM_SECRET_AGENT_ERROR_FAILED = 0, /*< nick=Failed >*/ + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, /*< nick=PermissionDenied >*/ + NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, /*< nick=InvalidConnection >*/ + NM_SECRET_AGENT_ERROR_USER_CANCELED, /*< nick=UserCanceled >*/ + NM_SECRET_AGENT_ERROR_AGENT_CANCELED, /*< nick=AgentCanceled >*/ + NM_SECRET_AGENT_ERROR_NO_SECRETS, /*< nick=NoSecrets >*/ +} NMSecretAgentError; + +GQuark nm_secret_agent_error_quark (void); +#define NM_SECRET_AGENT_ERROR (nm_secret_agent_error_quark ()) + +/** * NMSettingsError: * @NM_SETTINGS_ERROR_FAILED: unknown or unclassified error * @NM_SETTINGS_ERROR_PERMISSION_DENIED: permission denied diff --git a/libnm/nm-secret-agent.c b/libnm/nm-secret-agent.c index 7c782d1d94..1cba0b77a4 100644 --- a/libnm/nm-secret-agent.c +++ b/libnm/nm-secret-agent.c @@ -69,18 +69,6 @@ enum { LAST_PROP }; -/********************************************************************/ - -GQuark -nm_secret_agent_error_quark (void) -{ - static GQuark ret = 0; - - if (G_UNLIKELY (ret == 0)) - ret = g_quark_from_static_string ("nm-secret-agent-error"); - return ret; -} - /*************************************************************/ static void @@ -182,7 +170,7 @@ verify_sender (NMSecretAgent *self, if (!nm_owner) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, "NetworkManager bus name owner unknown."); return FALSE; } @@ -191,7 +179,7 @@ verify_sender (NMSecretAgent *self, if (!sender) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, "Failed to get request sender."); return FALSE; } @@ -200,7 +188,7 @@ verify_sender (NMSecretAgent *self, if (strcmp (sender, nm_owner) != 0) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, "Request sender does not match NetworkManager bus name owner."); return FALSE; } @@ -227,7 +215,7 @@ verify_sender (NMSecretAgent *self, g_dbus_error_strip_remote_error (local); g_set_error (error, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, "Failed to request unix user: (%s) %s.", remote_error ? remote_error : "", local->message); @@ -242,7 +230,7 @@ verify_sender (NMSecretAgent *self, if (0 != sender_uid) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, + NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, "Request sender is not root."); return FALSE; } @@ -287,9 +275,7 @@ verify_request (NMSecretAgent *self, g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, - "Invalid connection: (%d) %s", - local ? local->code : -1, - (local && local->message) ? local->message : "(unknown)"); + "Invalid connection: %s", local->message); g_clear_error (&local); } @@ -390,7 +376,7 @@ impl_secret_agent_cancel_get_secrets (NMSecretAgent *self, if (!info) { g_dbus_method_invocation_return_error (context, NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, + NM_SECRET_AGENT_ERROR_FAILED, "No secrets request in progress for this connection."); return; } @@ -490,7 +476,7 @@ check_nm_running (NMSecretAgent *self, GError **error) if (g_dbus_proxy_get_name_owner (G_DBUS_PROXY (priv->manager_proxy))) return TRUE; - g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, + g_set_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, "NetworkManager is not running"); return FALSE; } @@ -1347,10 +1333,6 @@ nm_secret_agent_class_init (NMSecretAgentClass *class) _nm_dbus_register_proxy_type (NM_DBUS_INTERFACE_AGENT_MANAGER, NMDBUS_TYPE_AGENT_MANAGER_PROXY); - - _nm_dbus_register_error_domain (NM_SECRET_AGENT_ERROR, - NM_DBUS_INTERFACE_SECRET_AGENT, - NM_TYPE_SECRET_AGENT_ERROR); } static void diff --git a/libnm/nm-secret-agent.h b/libnm/nm-secret-agent.h index 6b88699005..41b8b742a2 100644 --- a/libnm/nm-secret-agent.h +++ b/libnm/nm-secret-agent.h @@ -29,36 +29,6 @@ G_BEGIN_DECLS -#define NM_SECRET_AGENT_ERROR (nm_secret_agent_error_quark ()) - -GQuark nm_secret_agent_error_quark (void); - -/** - * NMSecretAgentError: - * @NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED: the caller (ie, NetworkManager) is not - * authorized to make this request - * @NM_SECRET_AGENT_ERROR_INVALID_CONNECTION: the connection for which secrets - * were requested could not be found - * @NM_SECRET_AGENT_ERROR_USER_CANCELED: the request was canceled by the user - * @NM_SECRET_AGENT_ERROR_AGENT_CANCELED: the agent canceled the request - * because it was requested to do so by NetworkManager - * @NM_SECRET_AGENT_ERROR_INTERNAL_ERROR: some internal error in the agent caused - * the request to fail - * @NM_SECRET_AGENT_ERROR_NO_SECRETS: the agent cannot find any secrets for this - * connection - * - * #NMSecretAgentError values are passed by secret agents back to NetworkManager - * when they encounter problems retrieving secrets on behalf of NM. - */ -typedef enum { - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED = 0, /*< nick=NotAuthorized >*/ - NM_SECRET_AGENT_ERROR_INVALID_CONNECTION, /*< nick=InvalidConnection >*/ - NM_SECRET_AGENT_ERROR_USER_CANCELED, /*< nick=UserCanceled >*/ - NM_SECRET_AGENT_ERROR_AGENT_CANCELED, /*< nick=AgentCanceled >*/ - NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, /*< nick=InternalError >*/ - NM_SECRET_AGENT_ERROR_NO_SECRETS, /*< nick=NoSecrets >*/ -} NMSecretAgentError; - #define NM_TYPE_SECRET_AGENT (nm_secret_agent_get_type ()) #define NM_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgent)) #define NM_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT, NMSecretAgentClass)) diff --git a/libnm/tests/test-secret-agent.c b/libnm/tests/test-secret-agent.c index 899df536a4..76f8a02e20 100644 --- a/libnm/tests/test-secret-agent.c +++ b/libnm/tests/test-secret-agent.c @@ -537,7 +537,7 @@ async_init_cb (GObject *object, GAsyncResult *result, gpointer user_data) GObject *agent; agent = g_async_initable_new_finish (G_ASYNC_INITABLE (object), result, &error); - g_assert_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR); + g_assert_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED); g_assert (agent == NULL); g_clear_error (&error); @@ -554,7 +554,7 @@ test_secret_agent_nm_not_running (void) agent = g_initable_new (test_secret_agent_get_type (), NULL, &error, NM_SECRET_AGENT_IDENTIFIER, "test-secret-agent", NULL); - g_assert_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR); + g_assert_error (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED); g_assert (agent == NULL); g_clear_error (&error); |