agents: add agent capabilities

A new agent registration method enables agents to pass capabilities during
the registration process.
This commit is contained in:
Dan Williams 2013-07-18 22:39:39 -05:00
parent cfa4117ebb
commit 16bb798861
5 changed files with 72 additions and 6 deletions

View file

@ -23,6 +23,24 @@
</arg>
</method>
<method name="RegisterWithCapabilities">
<tp:docstring>
Like Register() but indicates agent capabilities to NetworkManager.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register_with_capabilities"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="identifier" type="s" direction="in">
<tp:docstring>
See the Register() method's identifier argument.
</tp:docstring>
</arg>
<arg name="capabilities" type="u" direction="in" tp:type="NM_SECRET_AGENT_CAPABILITIES">
<tp:docstring>
Indicates various agent capabilities to NetworkManager.
</tp:docstring>
</arg>
</method>
<method name="Unregister">
<tp:docstring>
Called by secret Agents to notify NetworkManager that they will no

View file

@ -223,6 +223,18 @@
</arg>
</method>
<tp:flags name="NM_SECRET_AGENT_CAPABILITIES" value-prefix="NM_SECRET_AGENT_CAPABILITY" type="u">
<tp:flag suffix="NONE" value="0x0">
<tp:docstring>No special capabilities.</tp:docstring>
</tp:flag>
<tp:flag suffix="VPN_HINTS" value="0x1">
<tp:docstring>
The agent supports passing hints to VPN plugin authentication
dialogs.
</tp:docstring>
</tp:flag>
</tp:flags>
</interface>
</node>

View file

@ -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)

View file

@ -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);

View file

@ -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,