diff options
author | Thomas Haller <thaller@redhat.com> | 2018-03-01 17:38:41 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-03-12 18:02:20 +0100 |
commit | 062f86d88e407871602eb610439b1bdd92547196 (patch) | |
tree | 43ca2cb56b6515f5bf96a48e2260072ab8a52c62 | |
parent | 39db757e44bb5c59969f143b228e40ea27a232a9 (diff) | |
download | NetworkManager-062f86d88e407871602eb610439b1bdd92547196.tar.gz |
secret-agent: don't use generated NMDBusSecretAgent proxy
The generated code is really just a thin wrapper around direct
GDBusProxy calls. GDBusProxy is reasonably convenient to use directly,
drop this wrapper.
We also don't use a generated wrapper for other cases where
NetworkManager acts as a D-Bus client. There is no reason to
do it in this case.
While the nmdbus_*() functions that we were using are small wrappers,
we also created a NMDBusSecretAgent instance, and hence several other
functions and symbols are used as well. It's unnecessary.
This saves 8552 bytes for NetworkManager binary (2817944 vs. 2809392
bytes for contrib/rpm on x86_64).
-rw-r--r-- | libnm-core/nm-dbus-utils.c | 10 | ||||
-rw-r--r-- | src/settings/nm-secret-agent.c | 124 |
2 files changed, 77 insertions, 57 deletions
diff --git a/libnm-core/nm-dbus-utils.c b/libnm-core/nm-dbus-utils.c index 79020b2d49..ea7bf783c4 100644 --- a/libnm-core/nm-dbus-utils.c +++ b/libnm-core/nm-dbus-utils.c @@ -176,11 +176,13 @@ _nm_dbus_signal_connect_data (GDBusProxy *proxy, static void -typecheck_response (GVariant **response, - const GVariantType *reply_type, - GError **error) +typecheck_response (GVariant **response, + const GVariantType *reply_type, + GError **error) { - if (*response && reply_type && !g_variant_is_of_type (*response, reply_type)) { + if ( *response + && reply_type + && !g_variant_is_of_type (*response, reply_type)) { /* This is the same error code that g_dbus_connection_call() returns if * @reply_type doesn't match. */ diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 69f7d09ab6..4bfe0f72f2 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -26,14 +26,13 @@ #include <pwd.h> #include "nm-dbus-interface.h" +#include "nm-core-internal.h" #include "nm-bus-manager.h" #include "nm-auth-subject.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" #include "nm-utils/c-list.h" -#include "introspection/org.freedesktop.NetworkManager.SecretAgent.h" - /*****************************************************************************/ enum { @@ -51,7 +50,7 @@ typedef struct { char *dbus_owner; NMSecretAgentCapabilities capabilities; GSList *permissions; - NMDBusSecretAgent *proxy; + GDBusProxy *proxy; NMBusManager *bus_mgr; GDBusConnection *connection; CList requests; @@ -336,11 +335,17 @@ get_callback (GObject *proxy, if (request_check_return (r)) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; gs_unref_variant GVariant *secrets = NULL; - nmdbus_secret_agent_call_get_secrets_finish (priv->proxy, &secrets, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (priv->proxy, result, G_VARIANT_TYPE ("(a{sa{sv}})"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); + else { + g_variant_get (ret, + "(@a{sa{sv}})", + &secrets); + } r->callback (r->agent, r, secrets, error, r->callback_data); } @@ -358,7 +363,6 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, gpointer callback_data) { NMSecretAgentPrivate *priv; - static const char *no_hints[] = { NULL }; GVariant *dict; NMSecretAgentCallId *r; @@ -379,16 +383,20 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, r = request_new (self, "GetSecrets", path, setting_name, callback, callback_data); r->is_get_secrets = TRUE; - /* Increase the timeout only for this call */ - g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), 120000); - nmdbus_secret_agent_call_get_secrets (priv->proxy, - dict, - path, - setting_name, - hints ? hints : no_hints, - flags, - r->cancellable, - get_callback, r); + g_dbus_proxy_call (priv->proxy, + "GetSecrets", + g_variant_new ("(@a{sa{sv}}os^asu)", + dict, + path, + setting_name, + hints ?: NM_PTRARRAY_EMPTY (const char *), + (guint32) flags), + G_DBUS_CALL_FLAGS_NONE, + 120000, + r->cancellable, + get_callback, + r); + g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), -1); return r; @@ -399,17 +407,16 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, static void cancel_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { - char *description = user_data; - GError *error = NULL; + gs_free char *description = user_data; + gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - if (!nmdbus_secret_agent_call_cancel_get_secrets_finish (NMDBUS_SECRET_AGENT (proxy), result, &error)) { + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) { nm_log_dbg (LOGD_AGENTS, "%s%s%s: agent failed to cancel secrets: %s", NM_PRINT_FMT_QUOTED (description, "(", description, ")", "???"), error->message); - g_clear_error (&error); } - - g_free (description); } static void @@ -426,11 +433,16 @@ do_cancel_secrets (NMSecretAgent *self, NMSecretAgentCallId *r, gboolean disposi if ( r->is_get_secrets && priv->proxy) { /* for GetSecrets call, we must cancel the request. */ - nmdbus_secret_agent_call_cancel_get_secrets (priv->proxy, - r->path, r->setting_name, - NULL, - cancel_done, - g_strdup (nm_secret_agent_get_description (self))); + g_dbus_proxy_call (G_DBUS_PROXY (priv->proxy), + "CancelGetSecrets", + g_variant_new ("(os)", + r->path, + r->setting_name), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + cancel_done, + g_strdup (nm_secret_agent_get_description (self))); } cancellable = r->cancellable; @@ -494,11 +506,11 @@ agent_save_cb (GObject *proxy, NMSecretAgentCallId *r = user_data; if (request_check_return (r)) { - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - nmdbus_secret_agent_call_save_secrets_finish (priv->proxy, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); r->callback (r->agent, r, NULL, error, r->callback_data); } @@ -527,11 +539,16 @@ nm_secret_agent_save_secrets (NMSecretAgent *self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); r = request_new (self, "SaveSecrets", path, NULL, callback, callback_data); - nmdbus_secret_agent_call_save_secrets (priv->proxy, - dict, - path, - NULL, /* cancelling the request does *not* cancel the D-Bus call. */ - agent_save_cb, r); + g_dbus_proxy_call (priv->proxy, + "SaveSecrets", + g_variant_new ("(@a{sa{sv}}o)", + dict, + path), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, /* cancelling the request does *not* cancel the D-Bus call. */ + agent_save_cb, + r); return r; } @@ -546,11 +563,11 @@ agent_delete_cb (GObject *proxy, NMSecretAgentCallId *r = user_data; if (request_check_return (r)) { - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); gs_free_error GError *error = NULL; + gs_unref_variant GVariant *ret = NULL; - nmdbus_secret_agent_call_delete_secrets_finish (priv->proxy, result, &error); - if (error) + ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, G_VARIANT_TYPE ("()"), &error); + if (!ret) g_dbus_error_strip_remote_error (error); r->callback (r->agent, r, NULL, error, r->callback_data); } @@ -579,12 +596,16 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); r = request_new (self, "DeleteSecrets", path, NULL, callback, callback_data); - nmdbus_secret_agent_call_delete_secrets (priv->proxy, - dict, - path, - NULL, /* cancelling the request does *not* cancel the D-Bus call. */ - agent_delete_cb, r); - + g_dbus_proxy_call (priv->proxy, + "DeleteSecrets", + g_variant_new ("(@a{sa{sv}}o)", + dict, + path), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, /* cancelling the request does *not* cancel the D-Bus call. */ + agent_delete_cb, + r); return r; } @@ -666,7 +687,6 @@ nm_secret_agent_new (GDBusMethodInvocation *context, NMSecretAgentPrivate *priv; const char *dbus_owner; struct passwd *pw; - GDBusProxy *proxy; char *owner_username = NULL; char *description = NULL; char buf_subject[64]; @@ -714,14 +734,12 @@ nm_secret_agent_new (GDBusMethodInvocation *context, priv->capabilities = capabilities; priv->subject = g_object_ref (subject); - proxy = nm_bus_manager_new_proxy (priv->bus_mgr, - priv->connection, - NMDBUS_TYPE_SECRET_AGENT_PROXY, - priv->dbus_owner, - NM_DBUS_PATH_SECRET_AGENT, - NM_DBUS_INTERFACE_SECRET_AGENT); - g_assert (proxy); - priv->proxy = NMDBUS_SECRET_AGENT (proxy); + priv->proxy = nm_bus_manager_new_proxy (priv->bus_mgr, + priv->connection, + G_TYPE_DBUS_PROXY, + priv->dbus_owner, + NM_DBUS_PATH_SECRET_AGENT, + NM_DBUS_INTERFACE_SECRET_AGENT); /* we cannot subscribe to notify::g-name-owner because that doesn't work * for unique names and it doesn't work for private connections. */ |