From 16bb798861b0f8b727dcb9d843693edee6959003 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 18 Jul 2013 22:39:39 -0500 Subject: [PATCH] agents: add agent capabilities A new agent registration method enables agents to pass capabilities during the registration process. --- introspection/nm-agent-manager.xml | 18 ++++++++++++++++++ introspection/nm-secret-agent.xml | 12 ++++++++++++ src/settings/nm-agent-manager.c | 22 ++++++++++++++++++---- src/settings/nm-secret-agent.c | 13 ++++++++++++- src/settings/nm-secret-agent.h | 13 ++++++++++++- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/introspection/nm-agent-manager.xml b/introspection/nm-agent-manager.xml index e26caacf42..d107442860 100644 --- a/introspection/nm-agent-manager.xml +++ b/introspection/nm-agent-manager.xml @@ -23,6 +23,24 @@ + + + Like Register() but indicates agent capabilities to NetworkManager. + + + + + + See the Register() method's identifier argument. + + + + + Indicates various agent capabilities to NetworkManager. + + + + Called by secret Agents to notify NetworkManager that they will no diff --git a/introspection/nm-secret-agent.xml b/introspection/nm-secret-agent.xml index fa85cb6c65..291f1bdd92 100644 --- a/introspection/nm-secret-agent.xml +++ b/introspection/nm-secret-agent.xml @@ -223,6 +223,18 @@ + + + No special capabilities. + + + + The agent supports passing hints to VPN plugin authentication + dialogs. + + + + diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 3f6d355d49..c6ab771e56 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -80,6 +80,11 @@ static void impl_agent_manager_register (NMAgentManager *self, const char *identifier, DBusGMethodInvocation *context); +static void impl_agent_manager_register_with_capabilities (NMAgentManager *self, + const char *identifier, + NMSecretAgentCapabilities capabilities, + DBusGMethodInvocation *context); + static void impl_agent_manager_unregister (NMAgentManager *self, DBusGMethodInvocation *context); @@ -259,9 +264,10 @@ find_agent_by_identifier_and_uid (NMAgentManager *self, } static void -impl_agent_manager_register (NMAgentManager *self, - const char *identifier, - DBusGMethodInvocation *context) +impl_agent_manager_register_with_capabilities (NMAgentManager *self, + const char *identifier, + NMSecretAgentCapabilities capabilities, + DBusGMethodInvocation *context) { NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self); char *sender = NULL; @@ -305,7 +311,7 @@ impl_agent_manager_register (NMAgentManager *self, } /* Success, add the new agent */ - agent = nm_secret_agent_new (context, sender, identifier, sender_uid); + agent = nm_secret_agent_new (context, sender, identifier, sender_uid, capabilities); if (!agent) { error = g_error_new_literal (NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_INTERNAL_ERROR, @@ -338,6 +344,14 @@ done: g_free (sender); } +static void +impl_agent_manager_register (NMAgentManager *self, + const char *identifier, + DBusGMethodInvocation *context) +{ + impl_agent_manager_register_with_capabilities (self, identifier, 0, context); +} + static void impl_agent_manager_unregister (NMAgentManager *self, DBusGMethodInvocation *context) diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index a44625a921..aa6f2822d4 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -47,6 +47,7 @@ typedef struct { char *identifier; uid_t owner_uid; char *owner_username; + NMSecretAgentCapabilities capabilities; guint32 hash; GSList *permissions; @@ -145,6 +146,14 @@ nm_secret_agent_get_owner_username(NMSecretAgent *agent) return NM_SECRET_AGENT_GET_PRIVATE (agent)->owner_username; } +NMSecretAgentCapabilities +nm_secret_agent_get_capabilities (NMSecretAgent *agent) +{ + g_return_val_if_fail (NM_IS_SECRET_AGENT (agent), NM_SECRET_AGENT_CAPABILITY_NONE); + + return NM_SECRET_AGENT_GET_PRIVATE (agent)->capabilities; +} + guint32 nm_secret_agent_get_hash (NMSecretAgent *agent) { @@ -421,7 +430,8 @@ NMSecretAgent * nm_secret_agent_new (DBusGMethodInvocation *context, const char *owner, const char *identifier, - uid_t owner_uid) + uid_t owner_uid, + NMSecretAgentCapabilities capabilities) { NMSecretAgent *self; NMSecretAgentPrivate *priv; @@ -443,6 +453,7 @@ nm_secret_agent_new (DBusGMethodInvocation *context, priv->identifier = g_strdup (identifier); priv->owner_uid = owner_uid; priv->owner_username = g_strdup (username); + priv->capabilities = capabilities; hash_str = g_strdup_printf ("%08u%s", owner_uid, identifier); priv->hash = g_str_hash (hash_str); diff --git a/src/settings/nm-secret-agent.h b/src/settings/nm-secret-agent.h index ace060919a..a59182e533 100644 --- a/src/settings/nm-secret-agent.h +++ b/src/settings/nm-secret-agent.h @@ -30,6 +30,14 @@ #include "nm-dbus-manager.h" #include "nm-settings-flags.h" +/* NOTE: ensure these capabilities match those in introspection/nm-secret-agent.xml and + * libnm-glib/nm-secret-agent.h. + */ +typedef enum { + NM_SECRET_AGENT_CAPABILITY_NONE = 0x0, + NM_SECRET_AGENT_CAPABILITY_VPN_HINTS = 0x1, +} NMSecretAgentCapabilities; + #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)) @@ -50,7 +58,8 @@ GType nm_secret_agent_get_type (void); NMSecretAgent *nm_secret_agent_new (DBusGMethodInvocation *context, const char *owner, const char *identifier, - uid_t owner_uid); + uid_t owner_uid, + NMSecretAgentCapabilities capabilities); const char *nm_secret_agent_get_description (NMSecretAgent *agent); @@ -62,6 +71,8 @@ uid_t nm_secret_agent_get_owner_uid (NMSecretAgent *agent); const char *nm_secret_agent_get_owner_username (NMSecretAgent *agent); +NMSecretAgentCapabilities nm_secret_agent_get_capabilities (NMSecretAgent *agent); + guint32 nm_secret_agent_get_hash (NMSecretAgent *agent); void nm_secret_agent_add_permission (NMSecretAgent *agent,