From b2fb259e7ba7cb029469c47a93988387349e7b2c Mon Sep 17 00:00:00 2001
From: Laurent Bigonville <bigon@bigon.be>
Date: Mon, 11 Nov 2013 11:31:48 +0100
Subject: [PATCH] Add an option to use GDM as a standalone XDMCP server

This patch add an option (xdmcp/ShowLocalGreeter) to disable the local X
console and turn GDM into a simple XDMCP server

Thanks to Patrick Monnerat and Josselin Mouette for the patch

https://bugzilla.gnome.org/show_bug.cgi?id=567522
---
 common/gdm-settings-keys.h |  1 +
 daemon/gdm-manager.c       | 26 ++++++++++++++++++++++----
 daemon/gdm-manager.h       |  2 ++
 daemon/main.c              |  5 +++++
 data/gdm.schemas.in.in     |  5 +++++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/common/gdm-settings-keys.h b/common/gdm-settings-keys.h
index 6e50621..f4dcca2 100644
--- a/common/gdm-settings-keys.h
+++ b/common/gdm-settings-keys.h
@@ -43,6 +43,7 @@ G_BEGIN_DECLS
 #define GDM_KEY_DISALLOW_TCP "security/DisallowTCP"
 
 #define GDM_KEY_XDMCP_ENABLE "xdmcp/Enable"
+#define GDM_KEY_SHOW_LOCAL_GREETER "xdmcp/ShowLocalGreeter"
 #define GDM_KEY_MAX_PENDING "xdmcp/MaxPending"
 #define GDM_KEY_MAX_SESSIONS "xdmcp/MaxSessions"
 #define GDM_KEY_MAX_WAIT "xdmcp/MaxWait"
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
index ad0ac63..5108c37 100644
--- a/daemon/gdm-manager.c
+++ b/daemon/gdm-manager.c
@@ -65,7 +65,7 @@ struct GdmManagerPrivate
 
         gboolean                started;
         gboolean                wait_for_go;
-        gboolean                no_console;
+        gboolean                show_local_greeter;
 
         GDBusProxy               *bus_proxy;
         GDBusConnection          *connection;
@@ -74,7 +74,8 @@ struct GdmManagerPrivate
 
 enum {
         PROP_0,
-        PROP_XDMCP_ENABLED
+        PROP_XDMCP_ENABLED,
+        PROP_SHOW_LOCAL_GREETER
 };
 
 enum {
@@ -544,7 +545,7 @@ gdm_manager_start (GdmManager *manager)
 {
         g_debug ("GdmManager: GDM starting to manage displays");
 
-        if (! manager->priv->wait_for_go) {
+        if (! manager->priv->wait_for_go && (!manager->priv->xdmcp_enabled || manager->priv->show_local_greeter)) {
                 gdm_display_factory_start (GDM_DISPLAY_FACTORY (manager->priv->local_factory));
         }
 
@@ -570,7 +571,9 @@ gdm_manager_set_wait_for_go (GdmManager *manager,
 
                 if (! wait_for_go) {
                         /* we got a go */
-                        gdm_display_factory_start (GDM_DISPLAY_FACTORY (manager->priv->local_factory));
+                        if (!manager->priv->xdmcp_enabled || manager->priv->show_local_greeter) {
+                                gdm_display_factory_start (GDM_DISPLAY_FACTORY (manager->priv->local_factory));
+                        }
 
 #ifdef HAVE_LIBXDMCP
                         if (manager->priv->xdmcp_enabled && manager->priv->xdmcp_factory != NULL) {
@@ -643,6 +646,15 @@ gdm_manager_set_xdmcp_enabled (GdmManager *manager,
 
 }
 
+void
+gdm_manager_set_show_local_greeter (GdmManager *manager,
+                                    gboolean    show_local_greeter)
+{
+        g_return_if_fail (GDM_IS_MANAGER (manager));
+
+        manager->priv->show_local_greeter = show_local_greeter;
+}
+
 static void
 gdm_manager_set_property (GObject      *object,
                           guint         prop_id,
@@ -657,6 +669,9 @@ gdm_manager_set_property (GObject      *object,
         case PROP_XDMCP_ENABLED:
                 gdm_manager_set_xdmcp_enabled (self, g_value_get_boolean (value));
                 break;
+        case PROP_SHOW_LOCAL_GREETER:
+                gdm_manager_set_show_local_greeter (self, g_value_get_boolean (value));
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -677,6 +692,9 @@ gdm_manager_get_property (GObject    *object,
         case PROP_XDMCP_ENABLED:
                 g_value_set_boolean (value, self->priv->xdmcp_enabled);
                 break;
+        case PROP_SHOW_LOCAL_GREETER:
+                g_value_set_boolean (value, self->priv->show_local_greeter);
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
diff --git a/daemon/gdm-manager.h b/daemon/gdm-manager.h
index 3ee550f..4482bdd 100644
--- a/daemon/gdm-manager.h
+++ b/daemon/gdm-manager.h
@@ -71,6 +71,8 @@ void                gdm_manager_set_wait_for_go                (GdmManager *mana
 
 void                gdm_manager_set_xdmcp_enabled              (GdmManager *manager,
                                                                 gboolean    enabled);
+void                gdm_manager_set_show_local_greeter         (GdmManager *manager,
+                                                                gboolean    show_local_greeter);
 gboolean            gdm_manager_get_displays                   (GdmManager *manager,
                                                                 GPtrArray **displays,
                                                                 GError    **error);
diff --git a/daemon/main.c b/daemon/main.c
index 43625d6..7bd342d 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -440,6 +440,7 @@ on_name_acquired (GDBusConnection *bus,
                   gpointer         user_data)
 {
         gboolean xdmcp_enabled;
+        gboolean show_local_greeter;
 
         manager = gdm_manager_new ();
         if (manager == NULL) {
@@ -451,6 +452,10 @@ on_name_acquired (GDBusConnection *bus,
 
         gdm_manager_start (manager);
 
+        show_local_greeter = TRUE;
+        gdm_settings_direct_get_boolean (GDM_KEY_SHOW_LOCAL_GREETER, &show_local_greeter);
+        gdm_manager_set_show_local_greeter (manager, show_local_greeter);
+
         xdmcp_enabled = FALSE;
         gdm_settings_direct_get_boolean (GDM_KEY_XDMCP_ENABLE, &xdmcp_enabled);
         gdm_manager_set_xdmcp_enabled (manager, xdmcp_enabled);
diff --git a/data/gdm.schemas.in.in b/data/gdm.schemas.in.in
index 3c83125..4278b06 100644
--- a/data/gdm.schemas.in.in
+++ b/data/gdm.schemas.in.in
@@ -70,6 +70,11 @@
       <default>false</default>
     </schema>
     <schema>
+      <key>xdmcp/ShowLocalGreeter</key>
+      <signature>b</signature>
+      <default>true</default>
+    </schema>
+    <schema>
       <key>xdmcp/MaxPending</key>
       <signature>i</signature>
       <default>4</default>
-- 
1.8.5.6

