diff options
author | Dan Williams <dcbw@redhat.com> | 2011-07-01 14:25:15 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-07-01 15:38:38 -0500 |
commit | 3b226980c7413972f9f78a5cff34230b16117b9e (patch) | |
tree | 0d47e95729b57129f24ea9d3a9e1767ad9c9569f /src/settings | |
parent | c08279dff449a7f593a729fa798d2d4207b421fc (diff) | |
download | NetworkManager-3b226980c7413972f9f78a5cff34230b16117b9e.tar.gz |
agents: track agent username
Look up the username of the user whose session the agent is
part of andkeep that around for later.
Diffstat (limited to 'src/settings')
-rw-r--r-- | src/settings/nm-secret-agent.c | 24 | ||||
-rw-r--r-- | src/settings/nm-secret-agent.h | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 346c7310a0..5036b98d79 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -20,6 +20,9 @@ #include <config.h> +#include <sys/types.h> +#include <pwd.h> + #include <glib.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> @@ -41,6 +44,7 @@ typedef struct { char *owner; char *identifier; uid_t owner_uid; + char *owner_username; guint32 hash; NMDBusManager *dbus_mgr; @@ -134,6 +138,15 @@ nm_secret_agent_get_owner_uid (NMSecretAgent *agent) return NM_SECRET_AGENT_GET_PRIVATE (agent)->owner_uid; } +const char * +nm_secret_agent_get_owner_username(NMSecretAgent *agent) +{ + g_return_val_if_fail (agent != NULL, NULL); + g_return_val_if_fail (NM_IS_SECRET_AGENT (agent), NULL); + + return NM_SECRET_AGENT_GET_PRIVATE (agent)->owner_username; +} + guint32 nm_secret_agent_get_hash (NMSecretAgent *agent) { @@ -330,11 +343,17 @@ nm_secret_agent_new (NMDBusManager *dbus_mgr, NMSecretAgent *self; NMSecretAgentPrivate *priv; DBusGConnection *bus; - char *hash_str; + char *hash_str, *username; + struct passwd *pw; g_return_val_if_fail (owner != NULL, NULL); g_return_val_if_fail (identifier != NULL, NULL); + pw = getpwuid (owner_uid); + g_return_val_if_fail (pw != NULL, NULL); + g_return_val_if_fail (pw->pw_name[0] != '\0', NULL); + username = g_strdup (pw->pw_name); + self = (NMSecretAgent *) g_object_new (NM_TYPE_SECRET_AGENT, NULL); if (self) { priv = NM_SECRET_AGENT_GET_PRIVATE (self); @@ -342,6 +361,7 @@ nm_secret_agent_new (NMDBusManager *dbus_mgr, priv->owner = g_strdup (owner); priv->identifier = g_strdup (identifier); priv->owner_uid = owner_uid; + priv->owner_username = g_strdup (username); hash_str = g_strdup_printf ("%08u%s", owner_uid, identifier); priv->hash = g_str_hash (hash_str); @@ -356,6 +376,7 @@ nm_secret_agent_new (NMDBusManager *dbus_mgr, g_assert (priv->proxy); } + g_free (username); return self; } @@ -379,6 +400,7 @@ dispose (GObject *object) g_free (priv->description); g_free (priv->owner); g_free (priv->identifier); + g_free (priv->owner_username); g_hash_table_destroy (priv->requests); g_object_unref (priv->proxy); diff --git a/src/settings/nm-secret-agent.h b/src/settings/nm-secret-agent.h index 597940b440..556907290a 100644 --- a/src/settings/nm-secret-agent.h +++ b/src/settings/nm-secret-agent.h @@ -60,6 +60,8 @@ const char *nm_secret_agent_get_identifier (NMSecretAgent *agent); uid_t nm_secret_agent_get_owner_uid (NMSecretAgent *agent); +const char *nm_secret_agent_get_owner_username (NMSecretAgent *agent); + guint32 nm_secret_agent_get_hash (NMSecretAgent *agent); typedef void (*NMSecretAgentCallback) (NMSecretAgent *agent, |