Fix for GDM and ConsoleKit modules
CRs 7121864 7120515 7116014 7110596 7094175 7093681 7096672 7146593
RTIs 362787, 362788 and 362785
--- gdm-2.30.7/gui/simple-greeter/gdm-greeter-panel.c 2012-02-01 14:18:54.932680691 +0100
+++ gdm-2.30.7/gui/simple-greeter/gdm-greeter-panel.c 2012-02-01 14:29:27.255918276 +0100
@@ -1096,6 +1096,11 @@
const char *layout_name)
{
#ifdef HAVE_LIBXKLAVIER
+ /* Unless we have both xclient/xserver running in the local */
+ /* machine we won't display the keyboard layout tab */
+
+ if (!is_xclient_local() || !is_xserver_local())
+ return;
g_return_if_fail (GDM_IS_GREETER_PANEL (panel));
if (layout_name != NULL &&
--- gdm-2.30.7/gui/simple-greeter/gdm-layouts.c 2012-02-01 14:18:54.967140816 +0100
+++ gdm-2.30.7/gui/simple-greeter/gdm-layouts.c 2012-02-01 15:13:14.159363229 +0100
@@ -29,6 +29,7 @@
#ifdef HAVE_LIBXKLAVIER
#include <libxklavier/xklavier.h>
+#include <ucred.h>
#endif
#include <gconf/gconf-client.h>
@@ -46,9 +47,67 @@
static XklConfigRegistry *config_registry = NULL;
static XklConfigRec *initial_config = NULL;
+/*
+ * Function to determine if a connection is local or not.
+ * Returns: FALSE for remote, TRUE for local
+ */
+gboolean
+is_xclient_local (void)
+{
+ Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ int c = ConnectionNumber(dpy);
+ struct stat statbuf;
+ gboolean rv = FALSE;
+ ucred_t *ucred = NULL;
+ const char *disp_name;
+
+ if (c >= 0) {
+ /*
+ * stat the connection fd. If we succeed and the type of file
+ * is a FIFO, then we must be local.
+ */
+ if ((fstat(c, &statbuf) >= 0) && S_ISFIFO(statbuf.st_mode)) {
+ return TRUE;
+ }
+ /*
+ * Then call getpeerucred - if it succeeds, the other end of the
+ * connection must be on the same machine (though possibly in a
+ * different zone).
+ */
+ if (getpeerucred(c, &ucred) == 0) {
+ if (ucred_getzoneid(ucred) != -1)
+ rv = TRUE;
+ ucred_free(ucred);
+ }
+ }
+ return rv;
+}
+
+gboolean
+is_xserver_local (void)
+{
+ const char *dt_xserver_loc;
+ const char *gdm_xserver_loc;
+
+ dt_xserver_loc = g_getenv ("DTXSERVERLOCATION");
+ gdm_xserver_loc = g_getenv ("GDM_XSERVER_LOCATION");
+
+ if ((dt_xserver_loc && strcmp (dt_xserver_loc, "remote") == 0) ||
+ (gdm_xserver_loc && strcmp (gdm_xserver_loc, "xdmcp") == 0))
+ return FALSE;
+
+ return TRUE;
+}
+
static void
init_xkl (void)
{
+ /* Unless we have both xclient/xserver running in the local */
+ /* machine we won't display the keyboard layout tab */
+
+ if (!is_xclient_local() || !is_xserver_local())
+ return;
+
if (config_registry == NULL) {
engine = xkl_engine_get_instance (GDK_DISPLAY ());
config_registry = xkl_config_registry_get_instance (engine);
@@ -66,6 +125,8 @@
xci_desc_to_utf8 (XklConfigItem * ci)
{
char *sd = g_strstrip (ci->description);
+ if (!is_xclient_local() || !is_xserver_local())
+ return NULL;
return sd[0] == 0 ? g_strdup (ci->name) :
g_locale_to_utf8 (sd, -1, NULL, NULL, NULL);
}
@@ -77,6 +138,9 @@
{
LayoutData *ldata = data;
+ if (!is_xclient_local() || !is_xserver_local())
+ return;
+
ldata->list = g_slist_prepend (ldata->list, g_strdup_printf ("%s\t%s", ldata->layout, item->name));
}
@@ -87,6 +151,9 @@
{
LayoutData *ldata = data;
+ if (!is_xclient_local() || !is_xserver_local())
+ return;
+
ldata->layout = item->name;
ldata->list = g_slist_prepend (ldata->list, g_strdup (item->name));
xkl_config_registry_foreach_layout_variant (config, item->name, add_variant, data);
@@ -106,6 +173,9 @@
char *id2;
char *p;
+ if (!is_xclient_local() || !is_xserver_local())
+ return NULL;
+
init_xkl ();
id1 = g_strdup (name);
@@ -168,6 +238,9 @@
data.list = NULL;
data.layout = NULL;
+ if (!is_xclient_local() || !is_xserver_local())
+ return NULL;
+
init_xkl ();
xkl_config_registry_foreach_layout (config_registry, add_layout, &data);
@@ -198,6 +271,9 @@
char *variant;
gboolean retval;
+ if (!is_xclient_local() || !is_xserver_local())
+ return TRUE;
+
if (layout_variant != NULL && strcmp (layout_variant, GDM_LAST_LAYOUT) == 0) {
return TRUE;
}
@@ -232,6 +308,10 @@
gdm_layout_get_default_layout (void)
{
#ifdef HAVE_LIBXKLAVIER
+
+ if (!is_xclient_local() || !is_xserver_local())
+ return NULL;
+
init_xkl ();
if (initial_config->layouts)
@@ -250,6 +330,9 @@
XklConfigRec *config;
char *p;
+ if (!is_xclient_local() || !is_xserver_local())
+ return;
+
if (layout != NULL && strcmp (layout, GDM_LAST_LAYOUT) == 0) {
return;
}
--- gdm-2.30.7/gui/simple-greeter/gdm-layouts.h 2012-02-01 14:18:54.926446809 +0100
+++ gdm-2.30.7/gui/simple-greeter/gdm-layouts.h 2012-02-01 15:14:04.894492766 +0100
@@ -29,6 +29,8 @@
gboolean gdm_layout_is_valid (const char *layout);
const char * gdm_layout_get_default_layout (void);
void gdm_layout_activate (const char *layout);
+gboolean is_xclient_local (void);
+gboolean is_xserver_local (void);
G_END_DECLS