From de04f7ce9ae92df14ae59f7b411fb508068669a2 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 8 Feb 2010 10:13:02 -0600 Subject: Lockdown --- src/session-service.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 8306d02..33d7bec 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -50,6 +50,9 @@ with this program. If not, see . #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" +#define LOCKDOWN_DIR "/desktop/gnome/lockdown" +#define LOCKDOWN_KEY LOCKDOWNDIR "/disable_user_switching" + typedef struct _ActivateData ActivateData; struct _ActivateData { @@ -62,6 +65,7 @@ static DBusGProxy *gdm_proxy = NULL; static UsersServiceDbus *dbus_interface = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; +static DbusmenuMenuitem *switch_menuitem = NULL; static gint count; static GList *users; @@ -80,6 +84,50 @@ static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; +static GConfClient * gconf_client = NULL; +static guint notify_lockdown_id = 0; + +static void +lockdown_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (!value || !key) + return; + + if (g_strcmp0 (key, LOCKDOWN_KEY) == 0) + { + if (gconf_value_get_bool (value)) + { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + else + { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + } +} + +static void +ensure_gconf_client (void) +{ + if (!gconf_client) + { + gconf_client = gconf_client_get_default (); + + notify_lockdown_id = gconf_client_notify_add (gconf_client, + LOCKDOWN_KEY, + (GConfClientNotifyFunc)lockdown_changed, + NULL, + NULL, + NULL); + } +} + /* A return from the command to sleep the system. Make sure that we unthrottle the screensaver. */ static void @@ -441,13 +489,18 @@ rebuild_items (DbusmenuMenuitem *root, if (check_new_session ()) { - mi = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User...")); - dbusmenu_menuitem_child_append (root, mi); - g_signal_connect (G_OBJECT (mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + ensure_gconf_client (); + + if (gconf_client_get_bool (gconf_client, LOCKDOWN_KEY, NULL)) + { + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User...")); + dbusmenu_menuitem_child_append (root, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + } } } - + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); -- cgit v1.2.3 From a16c8f412a4fe6f57a59386787081118730426c4 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 8 Feb 2010 10:19:49 -0600 Subject: Fix a typo --- src/session-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/session-service.c b/src/session-service.c index 33d7bec..0038931 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -51,7 +51,7 @@ with this program. If not, see . #define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch" #define LOCKDOWN_DIR "/desktop/gnome/lockdown" -#define LOCKDOWN_KEY LOCKDOWNDIR "/disable_user_switching" +#define LOCKDOWN_KEY LOCKDOWN_DIR "/disable_user_switching" typedef struct _ActivateData ActivateData; struct _ActivateData -- cgit v1.2.3 From eedadcc3cf3a3f76fbe7b308a9ae7f0fa1f888d7 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 8 Feb 2010 11:01:13 -0600 Subject: Check switch_menuitem for NULL first --- src/session-service.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 0038931..62987f2 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -101,13 +101,16 @@ lockdown_changed (GConfClient *client, if (g_strcmp0 (key, LOCKDOWN_KEY) == 0) { - if (gconf_value_get_bool (value)) + if (switch_menuitem) { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } - else - { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + if (gconf_value_get_bool (value)) + { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + else + { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } } } } -- cgit v1.2.3 From 6335f484c1ebe1ee6f0c940614bf4dbdfaeb2e8d Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 8 Feb 2010 11:08:09 -0600 Subject: Fixes --- src/session-service.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/session-service.c b/src/session-service.c index 62987f2..621ab72 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -109,7 +109,7 @@ lockdown_changed (GConfClient *client, } else { - dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } } @@ -494,12 +494,18 @@ rebuild_items (DbusmenuMenuitem *root, { ensure_gconf_client (); + switch_menuitem = dbusmenu_menuitem_new (); + dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User...")); + dbusmenu_menuitem_child_append (root, switch_menuitem); + g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + if (gconf_client_get_bool (gconf_client, LOCKDOWN_KEY, NULL)) { - switch_menuitem = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (switch_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Switch User...")); - dbusmenu_menuitem_child_append (root, switch_menuitem); - g_signal_connect (G_OBJECT (switch_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (activate_new_session), NULL); + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + else + { + dbusmenu_menuitem_property_set_bool (switch_menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); } } } -- cgit v1.2.3 From 19ebc417eafb4cea2e9e1d5656c46148d8f100ed Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 8 Feb 2010 11:24:13 -0600 Subject: Remove unnecessary cast --- src/session-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/session-service.c b/src/session-service.c index 621ab72..791611e 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -124,7 +124,7 @@ ensure_gconf_client (void) notify_lockdown_id = gconf_client_notify_add (gconf_client, LOCKDOWN_KEY, - (GConfClientNotifyFunc)lockdown_changed, + lockdown_changed, NULL, NULL, NULL); -- cgit v1.2.3