summaryrefslogtreecommitdiff
path: root/daemon/gdm-display.c
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2015-02-03 16:14:20 -0500
committerRay Strode <rstrode@redhat.com>2015-02-18 17:34:12 -0500
commit08eee2ae1175cc43015329a00230f38066130c57 (patch)
treee5509c915a5825ec3be6b3741dc640b49ec7d90d /daemon/gdm-display.c
parent7b9dfd7a0156faf081b0a02db99dd0ffc526076b (diff)
downloadgdm-08eee2ae1175cc43015329a00230f38066130c57.tar.gz
display: move x11 connection from slave to display
It's more logical here, and we're trying to get rid of the slave object eventually, anyway. https://bugzilla.gnome.org/show_bug.cgi?id=744764
Diffstat (limited to 'daemon/gdm-display.c')
-rw-r--r--daemon/gdm-display.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
index a205839a..7b06a9d1 100644
--- a/daemon/gdm-display.c
+++ b/daemon/gdm-display.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
@@ -33,6 +34,9 @@
#include <glib/gi18n.h>
#include <glib-object.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
#include "gdm-common.h"
#include "gdm-display.h"
#include "gdm-display-glue.h"
@@ -46,6 +50,7 @@
#include "gdm-simple-slave.h"
#include "gdm-xdmcp-chooser-slave.h"
#include "gdm-dbus-util.h"
+#include "gdm-xerrors.h"
#define INITIAL_SETUP_USERNAME "gnome-initial-setup"
#define GNOME_SESSION_SESSIONS_PATH DATADIR "/gnome-session/sessions"
@@ -72,6 +77,8 @@ struct GdmDisplayPrivate
guint finish_idle_id;
+ Display *x11_display;
+
GdmSlave *slave;
GDBusConnection *connection;
GdmDisplayAccessFile *user_access_file;
@@ -283,6 +290,35 @@ gdm_display_create_authority (GdmDisplay *self)
return TRUE;
}
+static void
+setup_xhost_auth (XHostAddress *host_entries,
+ XServerInterpretedAddress *si_entries)
+{
+ si_entries[0].type = "localuser";
+ si_entries[0].typelength = strlen ("localuser");
+ si_entries[1].type = "localuser";
+ si_entries[1].typelength = strlen ("localuser");
+ si_entries[2].type = "localuser";
+ si_entries[2].typelength = strlen ("localuser");
+
+ si_entries[0].value = "root";
+ si_entries[0].valuelength = strlen ("root");
+ si_entries[1].value = GDM_USERNAME;
+ si_entries[1].valuelength = strlen (GDM_USERNAME);
+ si_entries[2].value = "gnome-initial-setup";
+ si_entries[2].valuelength = strlen ("gnome-initial-setup");
+
+ host_entries[0].family = FamilyServerInterpreted;
+ host_entries[0].address = (char *) &si_entries[0];
+ host_entries[0].length = sizeof (XServerInterpretedAddress);
+ host_entries[1].family = FamilyServerInterpreted;
+ host_entries[1].address = (char *) &si_entries[1];
+ host_entries[1].length = sizeof (XServerInterpretedAddress);
+ host_entries[2].family = FamilyServerInterpreted;
+ host_entries[2].address = (char *) &si_entries[2];
+ host_entries[2].length = sizeof (XServerInterpretedAddress);
+}
+
gboolean
gdm_display_add_user_authorization (GdmDisplay *self,
const char *username,
@@ -293,6 +329,10 @@ gdm_display_add_user_authorization (GdmDisplay *self,
GError *access_file_error;
gboolean res;
+ int i;
+ XServerInterpretedAddress si_entries[3];
+ XHostAddress host_entries[3];
+
g_return_val_if_fail (GDM_IS_DISPLAY (self), FALSE);
g_debug ("GdmDisplay: Adding authorization for user:%s on display %s", username, self->priv->x11_display_name);
@@ -338,6 +378,18 @@ gdm_display_add_user_authorization (GdmDisplay *self,
self->priv->user_access_file = access_file;
g_debug ("GdmDisplay: Added user authorization for %s: %s", username, *filename);
+ /* Remove access for the programs run by slave and greeter now that the
+ * user session is starting.
+ */
+ setup_xhost_auth (host_entries, si_entries);
+ gdm_error_trap_push ();
+ for (i = 0; i < G_N_ELEMENTS (host_entries); i++) {
+ XRemoveHost (self->priv->x11_display, &host_entries[i]);
+ }
+ XSync (self->priv->x11_display, False);
+ if (gdm_error_trap_pop ()) {
+ g_warning ("Failed to remove slave program access to the display. Trying to proceed.");
+ }
return TRUE;
}
@@ -1738,3 +1790,134 @@ gdm_display_get_slave (GdmDisplay *self)
{
return self->priv->slave;
}
+
+static void
+gdm_display_set_windowpath (GdmDisplay *self)
+{
+ /* setting WINDOWPATH for clients */
+ Atom prop;
+ Atom actualtype;
+ int actualformat;
+ unsigned long nitems;
+ unsigned long bytes_after;
+ unsigned char *buf;
+ const char *windowpath;
+ char *newwindowpath;
+ unsigned long num;
+ char nums[10];
+ int numn;
+
+ prop = XInternAtom (self->priv->x11_display, "XFree86_VT", False);
+ if (prop == None) {
+ g_debug ("no XFree86_VT atom\n");
+ return;
+ }
+ if (XGetWindowProperty (self->priv->x11_display,
+ DefaultRootWindow (self->priv->x11_display), prop, 0, 1,
+ False, AnyPropertyType, &actualtype, &actualformat,
+ &nitems, &bytes_after, &buf)) {
+ g_debug ("no XFree86_VT property\n");
+ return;
+ }
+
+ if (nitems != 1) {
+ g_debug ("%lu items in XFree86_VT property!\n", nitems);
+ XFree (buf);
+ return;
+ }
+
+ switch (actualtype) {
+ case XA_CARDINAL:
+ case XA_INTEGER:
+ case XA_WINDOW:
+ switch (actualformat) {
+ case 8:
+ num = (*(uint8_t *)(void *)buf);
+ break;
+ case 16:
+ num = (*(uint16_t *)(void *)buf);
+ break;
+ case 32:
+ num = (*(long *)(void *)buf);
+ break;
+ default:
+ g_debug ("format %d in XFree86_VT property!\n", actualformat);
+ XFree (buf);
+ return;
+ }
+ break;
+ default:
+ g_debug ("type %lx in XFree86_VT property!\n", actualtype);
+ XFree (buf);
+ return;
+ }
+ XFree (buf);
+
+ windowpath = getenv ("WINDOWPATH");
+ numn = snprintf (nums, sizeof (nums), "%lu", num);
+ if (!windowpath) {
+ newwindowpath = malloc (numn + 1);
+ sprintf (newwindowpath, "%s", nums);
+ } else {
+ newwindowpath = malloc (strlen (windowpath) + 1 + numn + 1);
+ sprintf (newwindowpath, "%s:%s", windowpath, nums);
+ }
+
+ g_setenv ("WINDOWPATH", newwindowpath, TRUE);
+}
+
+gboolean
+gdm_display_connect (GdmDisplay *self)
+{
+ gboolean ret;
+
+ ret = FALSE;
+
+ g_debug ("GdmDisplay: Server is ready - opening display %s", self->priv->x11_display_name);
+
+ /* Get access to the display independent of current hostname */
+ if (self->priv->x11_cookie != NULL) {
+ XSetAuthorization ("MIT-MAGIC-COOKIE-1",
+ strlen ("MIT-MAGIC-COOKIE-1"),
+ (gpointer)
+ self->priv->x11_cookie,
+ self->priv->x11_cookie_size);
+ }
+
+ self->priv->x11_display = XOpenDisplay (self->priv->x11_display_name);
+
+ if (self->priv->x11_display == NULL) {
+ g_warning ("Unable to connect to display %s", self->priv->x11_display_name);
+ ret = FALSE;
+ } else if (self->priv->is_local) {
+ XServerInterpretedAddress si_entries[3];
+ XHostAddress host_entries[3];
+ int i;
+
+ g_debug ("GdmDisplay: Connected to display %s", self->priv->x11_display_name);
+ ret = TRUE;
+
+ /* Give programs access to the display independent of current hostname
+ */
+ setup_xhost_auth (host_entries, si_entries);
+
+ gdm_error_trap_push ();
+
+ for (i = 0; i < G_N_ELEMENTS (host_entries); i++) {
+ XAddHost (self->priv->x11_display, &host_entries[i]);
+ }
+
+ XSync (self->priv->x11_display, False);
+ if (gdm_error_trap_pop ()) {
+ g_debug ("Failed to give some system users access to the display. Trying to proceed.");
+ }
+
+ gdm_display_set_windowpath (self);
+ } else {
+ g_debug ("GdmDisplay: Connected to display %s", self->priv->x11_display_name);
+ ret = TRUE;
+ }
+
+ return ret;
+}
+