Commit 925d69c6 authored by Dan Williams's avatar Dan Williams

core: use new session monitor in system connection class

parent 39ed9c29
......@@ -150,6 +150,7 @@ session_new (GKeyFile *keyfile, const char *group, GError **error)
s = g_new0 (Session, 1);
g_assert (s);
s->uid = G_MAXUINT; /* paranoia */
if (!check_key (keyfile, group, "uid", error))
return FALSE;
s->uid = (uid_t) g_key_file_get_integer (keyfile, group, "uid", error);
......@@ -397,6 +398,7 @@ nm_session_monitor_get (void)
gboolean
nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
const char *username,
uid_t *out_uid,
GError **error)
{
Session *s;
......@@ -414,6 +416,8 @@ nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
return FALSE;
}
if (out_uid)
*out_uid = s->uid;
return TRUE;
}
......@@ -431,6 +435,7 @@ nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
gboolean
nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
uid_t uid,
const char **out_user,
GError **error)
{
Session *s;
......@@ -448,6 +453,8 @@ nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
return FALSE;
}
if (out_user)
*out_user = s->user;
return TRUE;
}
......
......@@ -40,10 +40,12 @@ NMSessionMonitor *nm_session_monitor_get (void);
gboolean nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
const char *username,
uid_t *out_uid,
GError **error);
gboolean nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
uid_t uid,
const char **out_user,
GError **error);
gboolean nm_session_monitor_user_active (NMSessionMonitor *monitor,
......
......@@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Novell, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#ifndef NM_SYSCONFIG_CONNECTION_H
......@@ -23,7 +24,6 @@
#include <nm-connection.h>
#include <dbus/dbus-glib.h>
#include "nm-session-info.h"
G_BEGIN_DECLS
......@@ -34,10 +34,10 @@ G_BEGIN_DECLS
#define NM_IS_SYSCONFIG_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SYSCONFIG_CONNECTION))
#define NM_SYSCONFIG_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SYSCONFIG_CONNECTION, NMSysconfigConnectionClass))
#define NM_SYSCONFIG_CONNECTION_UPDATED "updated"
#define NM_SYSCONFIG_CONNECTION_REMOVED "removed"
#define NM_SYSCONFIG_CONNECTION_PURGED "purged"
#define NM_SYSCONFIG_CONNECTION_UNHIDDEN "unhidden"
#define NM_SYSCONFIG_CONNECTION_UPDATED "updated"
#define NM_SYSCONFIG_CONNECTION_REMOVED "removed"
#define NM_SYSCONFIG_CONNECTION_PURGED "purged"
#define NM_SYSCONFIG_CONNECTION_VISIBLE "visible"
typedef struct _NMSysconfigConnection NMSysconfigConnection;
......@@ -105,13 +105,9 @@ void nm_sysconfig_connection_get_secrets (NMSysconfigConnection *connection,
NMSysconfigConnectionGetSecretsFunc callback,
gpointer user_data);
gboolean nm_sysconfig_connection_is_visible (NMSysconfigConnection *connection);
gboolean nm_sysconfig_connection_is_accessible_by_session (NMSysconfigConnection *connection,
NMSessionInfo *session);
GSList * nm_sysconfig_connection_get_session_access_list (NMSysconfigConnection *connection);
gboolean nm_sysconfig_connection_is_visible (NMSysconfigConnection *self);
void nm_sysconfig_connection_recheck_visibility (NMSysconfigConnection *self);
G_END_DECLS
......
......@@ -60,6 +60,7 @@
#include "nm-logging.h"
#include "nm-dbus-manager.h"
#include "nm-manager-auth.h"
#include "nm-session-monitor.h"
#define CONFIG_KEY_NO_AUTO_DEFAULT "no-auto-default"
......@@ -101,6 +102,9 @@ typedef struct {
DBusGConnection *bus;
gboolean exported;
NMSessionMonitor *session_monitor;
guint session_monitor_id;
PolkitAuthority *authority;
guint auth_changed_id;
char *config_file;
......@@ -532,24 +536,26 @@ load_plugins (NMSysconfigSettings *self, const char *plugins, GError **error)
}
static void
connection_removed (NMSysconfigConnection *connection,
gpointer user_data)
session_monitor_changed_cb (NMSessionMonitor *monitor, gpointer user_data)
{
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data);
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (user_data);
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
GHashTableIter iter;
gpointer data;
g_hash_table_remove (priv->visible_connections, connection);
/* Update visibility on all connections */
g_hash_table_iter_init (&iter, priv->all_connections);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
}
}
static void
connection_unhidden (NMSysconfigConnection *connection,
gpointer user_data)
connection_removed (NMSysconfigConnection *connection,
gpointer user_data)
{
NMSysconfigSettings *settings = user_data;
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (settings);
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data);
g_hash_table_insert (priv->visible_connections,
connection, GINT_TO_POINTER (1));
g_signal_emit (settings, signals[NEW_CONNECTION], 0, connection);
g_hash_table_remove (priv->visible_connections, connection);
}
static void
......@@ -584,10 +590,6 @@ claim_connection (NMSysconfigSettings *self,
NM_SYSCONFIG_CONNECTION_PURGED,
G_CALLBACK (connection_purged),
self);
g_signal_connect (connection,
NM_SYSCONFIG_CONNECTION_UNHIDDEN,
G_CALLBACK (connection_unhidden),
self);
if (nm_sysconfig_connection_is_visible (connection)) {
g_hash_table_insert (priv->visible_connections, connection, GINT_TO_POINTER (1));
......@@ -1287,6 +1289,12 @@ dispose (GObject *object)
g_slist_free (priv->pk_calls);
priv->pk_calls = NULL;
if (priv->session_monitor) {
g_signal_handler_disconnect (priv->session_monitor, priv->session_monitor_id);
g_object_unref (priv->session_monitor);
priv->session_monitor = NULL;
}
G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->dispose (object);
}
......@@ -1441,5 +1449,12 @@ nm_sysconfig_settings_init (NMSysconfigSettings *self)
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
}
priv->session_monitor = nm_session_monitor_get ();
g_assert (priv->session_monitor);
priv->session_monitor_id = g_signal_connect (priv->session_monitor,
"changed",
G_CALLBACK (session_monitor_changed_cb),
self);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment