5a1cfbf
--- gdm-2.17.6/docs/C/gdm.xml.username	2007-01-22 00:31:17.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/docs/C/gdm.xml	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
@@ -2,8 +2,8 @@
5a1cfbf
 
5a1cfbf
     "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
5a1cfbf
     
5a1cfbf
-     
5a1cfbf
-     
5a1cfbf
+     
5a1cfbf
+     
5a1cfbf
 ]>
5a1cfbf
 
5a1cfbf
 <article id="index" lang="en">
5a1cfbf
@@ -13,7 +13,7 @@
5a1cfbf
     <revhistory>
5a1cfbf
       <revision>
5a1cfbf
         <revnumber>0.0</revnumber>
5a1cfbf
-        <date>2006-12</date>
5a1cfbf
+        <date>2007-01</date>
5a1cfbf
       </revision>
5a1cfbf
     </revhistory>
5a1cfbf
 
5a1cfbf
@@ -4515,7 +4515,9 @@
5a1cfbf
 AUTH_LOCAL
5a1cfbf
 CLOSE
5a1cfbf
 FLEXI_XNEST
5a1cfbf
+FLEXI_XNEST_USER
5a1cfbf
 FLEXI_XSERVER
5a1cfbf
+FLEXI_XSERVER_USER
5a1cfbf
 GET_CONFIG
5a1cfbf
 GET_CONFIG_FILE
5a1cfbf
 GET_CUSTOM_CONFIG_FILE
5a1cfbf
@@ -4699,6 +4701,36 @@
5a1cfbf
 </screen>
5a1cfbf
       </sect3>
5a1cfbf
       
5a1cfbf
+      <sect3 id="flexixnestuser">
5a1cfbf
+      <title>FLEXI_XNEST_USER</title>
5a1cfbf
+<screen>
5a1cfbf
+FLEXI_XNEST_USER: Start a new flexible Xnest display and
5a1cfbf
+                  initialize the greeter with the given username.
5a1cfbf
+Note:             This is a variant of the FLEXI_XNEST command.
5a1cfbf
+Note:             The cookie should be the MIT-MAGIC-COOKIE-1,
5a1cfbf
+                  the first one GDM can find in the XAUTHORITY
5a1cfbf
+                  file for this display.  If that's not what you
5a1cfbf
+                  use you should generate one first.  The cookie
5a1cfbf
+                  should be in hex form.
5a1cfbf
+Supported since:  2.17.7
5a1cfbf
+Arguments: <username> <display to run on> <uid of requesting user>
5a1cfbf
+           <xauth cookie for the display> <xauth file>
5a1cfbf
+Answers:
5a1cfbf
+  OK <display>
5a1cfbf
+  ERROR <err number> <english error description>
5a1cfbf
+     0 = Not implemented
5a1cfbf
+     1 = No more flexi servers
5a1cfbf
+     2 = Startup errors
5a1cfbf
+     3 = X failed
5a1cfbf
+     4 = X too busy
5a1cfbf
+     5 = Xnest can't connect
5a1cfbf
+     6 = No server binary
5a1cfbf
+     100 = Not authenticated
5a1cfbf
+     200 = Too many messages
5a1cfbf
+     999 = Unknown error
5a1cfbf
+</screen>
5a1cfbf
+      </sect3>
5a1cfbf
+
5a1cfbf
       <sect3 id="flexixserver">
5a1cfbf
       <title>FLEXI_XSERVER</title>
5a1cfbf
 <screen>
5a1cfbf
@@ -4722,6 +4754,30 @@
5a1cfbf
 </screen>
5a1cfbf
       </sect3>
5a1cfbf
       
5a1cfbf
+      <sect3 id="flexixserveruser">
5a1cfbf
+      <title>FLEXI_XSERVER_USER</title>
5a1cfbf
+<screen>
5a1cfbf
+FLEXI_XSERVER_USER: Start a new X flexible display and initialize the
5a1cfbf
+                    greeter with the given username.  Only supported on
5a1cfbf
+                    connection that passed AUTH_LOCAL
5a1cfbf
+Supported since:    2.17.7 
5a1cfbf
+Arguments: <username> <xserver type>
5a1cfbf
+  If no server type specified, starts the standard X server
5a1cfbf
+Answers:
5a1cfbf
+  OK <display>
5a1cfbf
+  ERROR <err number> <english error description>
5a1cfbf
+     0 = Not implemented
5a1cfbf
+     1 = No more flexi servers
5a1cfbf
+     2 = Startup errors
5a1cfbf
+     3 = X failed
5a1cfbf
+     4 = X too busy
5a1cfbf
+     6 = No server binary
5a1cfbf
+     100 = Not authenticated
5a1cfbf
+     200 = Too many messages
5a1cfbf
+     999 = Unknown error
5a1cfbf
+</screen>
5a1cfbf
+      </sect3>
5a1cfbf
+
5a1cfbf
       <sect3 id="getconfig">
5a1cfbf
       <title>GET_CONFIG</title> 
5a1cfbf
 <screen>
5a1cfbf
--- gdm-2.17.6/daemon/slave.c.username	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/daemon/slave.c	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
@@ -1946,6 +1946,7 @@
5a1cfbf
 gdm_slave_wait_for_login (void)
5a1cfbf
 {
5a1cfbf
 	char *successsound;
5a1cfbf
+	char *username;
5a1cfbf
 	g_free (login);
5a1cfbf
 	login = NULL;
5a1cfbf
 
5a1cfbf
@@ -1970,10 +1971,14 @@
5a1cfbf
 		NEVER_FAILS_root_set_euid_egid (0, 0);
5a1cfbf
 
5a1cfbf
 		gdm_debug ("gdm_slave_wait_for_login: In loop");
5a1cfbf
+		username = d->preset_user;
5a1cfbf
+		d->preset_user = NULL;
5a1cfbf
 		login = gdm_verify_user (d /* the display */,
5a1cfbf
-					 NULL /* username*/,
5a1cfbf
+					 username /* username*/,
5a1cfbf
 					 d->name /* display name */,
5a1cfbf
 					 d->attached /* display attached? (bool) */);
5a1cfbf
+		g_free (username);
5a1cfbf
+
5a1cfbf
 		gdm_debug ("gdm_slave_wait_for_login: end verify for '%s'",
5a1cfbf
 			   ve_sure_string (login));
5a1cfbf
 
5a1cfbf
--- gdm-2.17.6/daemon/server.c.username	2007-01-22 00:20:40.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/daemon/server.c	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
@@ -1439,6 +1439,7 @@
5a1cfbf
     d->retry_count = 0;
5a1cfbf
     d->sleep_before_run = 0;
5a1cfbf
     d->login = NULL;
5a1cfbf
+    d->preset_user = NULL;
5a1cfbf
 
5a1cfbf
     d->timed_login_ok = FALSE;
5a1cfbf
 
5a1cfbf
--- gdm-2.17.6/daemon/gdm.h.username	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/daemon/gdm.h	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
@@ -557,6 +557,8 @@
5a1cfbf
     gboolean logged_in; /* TRUE if someone is logged in */
5a1cfbf
     char *login;
5a1cfbf
 
5a1cfbf
+    char *preset_user;
5a1cfbf
+
5a1cfbf
     gboolean timed_login_ok;
5a1cfbf
 
5a1cfbf
     int screenx;
5a1cfbf
@@ -874,6 +876,26 @@
5a1cfbf
  *      200 = Too many messages
5a1cfbf
  *      999 = Unknown error
5a1cfbf
  */
5a1cfbf
+#define GDM_SUP_FLEXI_XSERVER_USER  "FLEXI_XSERVER_USER" /* <username> <xserver type> */
5a1cfbf
+/* FLEXI_XSERVER_USER: Start a new X flexible display and initialize the 
5a1cfbf
+ *                greeter with the given username. Only supported on 
5a1cfbf
+ *                connection that passed AUTH_LOCAL
5a1cfbf
+ * Supported since: 2.17.7
5a1cfbf
+ * Arguments: <username> <xserver type>
5a1cfbf
+ *   If no server type specified, starts the standard X server
5a1cfbf
+ * Answers:
5a1cfbf
+ *   OK <display>
5a1cfbf
+ *   ERROR <err number> <english error description>
5a1cfbf
+ *      0 = Not implemented
5a1cfbf
+ *      1 = No more flexi servers
5a1cfbf
+ *      2 = Startup errors
5a1cfbf
+ *      3 = X failed
5a1cfbf
+ *      4 = X too busy
5a1cfbf
+ *      6 = No server binary
5a1cfbf
+ *      100 = Not authenticated
5a1cfbf
+ *      200 = Too many messages
5a1cfbf
+ *      999 = Unknown error
5a1cfbf
+ */
5a1cfbf
 #define GDM_SUP_FLEXI_XNEST  "FLEXI_XNEST" /* <display> <uid> <xauth cookie> <xauth file> */
5a1cfbf
 /* FLEXI_XNEXT: Start a new flexible Xnest display.
5a1cfbf
  * Note:        Supported on older versions from 2.2.4.0, later
5a1cfbf
@@ -909,6 +931,31 @@
5a1cfbf
  *      200 = Too many messages
5a1cfbf
  *      999 = Unknown error
5a1cfbf
  */
5a1cfbf
+#define GDM_SUP_FLEXI_XNEST_USER  "FLEXI_XNEST_USER" /* <username> <display> <uid> <xauth cookie> <xauth file> */
5a1cfbf
+/* FLEXI_XNEXT_USER: Start a new flexible Xnest display and 
5a1cfbf
+ *              initialize the greeter with the given username
5a1cfbf
+ * Note:        The cookie should be the MIT-MAGIC-COOKIE-1,
5a1cfbf
+ *              the first one gdm can find in the XAUTHORITY
5a1cfbf
+ *              file for this display.  If that's not what you
5a1cfbf
+ *              use you should generate one first.  The cookie
5a1cfbf
+ *              should be in hex form.
5a1cfbf
+ * Supported since: 2.17.7
5a1cfbf
+ * Arguments: <username> <display to run on> <uid of requesting user>
5a1cfbf
+ *            <xauth cookie for the display> <xauth file>
5a1cfbf
+ * Answers:
5a1cfbf
+ *   OK <display>
5a1cfbf
+ *   ERROR <err number> <english error description>
5a1cfbf
+ *      0 = Not implemented
5a1cfbf
+ *      1 = No more flexi servers
5a1cfbf
+ *      2 = Startup errors
5a1cfbf
+ *      3 = X failed
5a1cfbf
+ *      4 = X too busy
5a1cfbf
+ *      5 = Xnest can't connect
5a1cfbf
+ *      6 = No server binary
5a1cfbf
+ *      100 = Not authenticated
5a1cfbf
+ *      200 = Too many messages
5a1cfbf
+ *      999 = Unknown error
5a1cfbf
+ */
5a1cfbf
 #define GDM_SUP_ADD_DYNAMIC_DISPLAY	"ADD_DYNAMIC_DISPLAY" 
5a1cfbf
 /*
5a1cfbf
  * ADD_DYNAMIC_DISPLAY: Create a new server definition that will
5a1cfbf
--- gdm-2.17.6/daemon/display.c.username	2007-01-22 00:20:40.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/daemon/display.c	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
@@ -1,4 +1,6 @@
5a1cfbf
-/* GDM - The GNOME Display Manager
5a1cfbf
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
5a1cfbf
+ *
5a1cfbf
+ * GDM - The GNOME Display Manager
5a1cfbf
  * Copyright (C) 1998, 1999, 2000 Martin K. Petersen <mkp@mkp.net>
5a1cfbf
  *
5a1cfbf
  * This program is free software; you can redistribute it and/or modify
5a1cfbf
@@ -531,6 +533,9 @@
5a1cfbf
     g_free (d->login);
5a1cfbf
     d->login = NULL;
5a1cfbf
 
5a1cfbf
+    g_free (d->preset_user);
5a1cfbf
+    d->preset_user = NULL;
5a1cfbf
+
5a1cfbf
     g_free (d->xsession_errors_filename);
5a1cfbf
     d->xsession_errors_filename = NULL;
5a1cfbf
 
5a1cfbf
--- gdm-2.17.6/daemon/gdm.c.username	2007-02-06 22:52:08.000000000 -0500
5a1cfbf
+++ gdm-2.17.6/daemon/gdm.c	2007-02-06 22:53:54.000000000 -0500
5a1cfbf
@@ -1,4 +1,6 @@
5a1cfbf
-/* GDM - The GNOME Display Manager
5a1cfbf
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
5a1cfbf
+ *
5a1cfbf
+ * GDM - The GNOME Display Manager
5a1cfbf
  * Copyright (C) 1998, 1999, 2000 Martin K. Petersen <mkp@mkp.net>
5a1cfbf
  *
5a1cfbf
  * This program is free software; you can redistribute it and/or modify
5a1cfbf
@@ -103,7 +105,8 @@
5a1cfbf
 				 const gchar *xnest_disp, 
5a1cfbf
 				 uid_t xnest_uid,
5a1cfbf
 				 const gchar *xnest_auth_file,
5a1cfbf
-				 const gchar *xnest_cookie);
5a1cfbf
+				 const gchar *xnest_cookie,
5a1cfbf
+				 const gchar *username);
5a1cfbf
 static void custom_cmd_restart (long cmd_id);
5a1cfbf
 static void custom_cmd_no_restart (long cmd_id);
5a1cfbf
 
5a1cfbf
@@ -2563,7 +2566,7 @@
5a1cfbf
 		handle_flexi_server (NULL, TYPE_FLEXI, gdm_get_value_string (GDM_KEY_STANDARD_XSERVER),
5a1cfbf
 				     TRUE /* handled */,
5a1cfbf
 				     FALSE /* chooser */,
5a1cfbf
-				     NULL, 0, NULL, NULL);
5a1cfbf
+				     NULL, 0, NULL, NULL, NULL);
5a1cfbf
        } else if (strcmp (msg, GDM_SOP_CANCEL_LOGIN_REQUESTS) == 0) {
5a1cfbf
                GSList *li;
5a1cfbf
                for (li = displays; li != NULL; li = li->next) {
5a1cfbf
@@ -2970,7 +2973,8 @@
5a1cfbf
 		     gboolean chooser,
5a1cfbf
 		     const gchar *xnest_disp, uid_t xnest_uid,
5a1cfbf
 		     const gchar *xnest_auth_file,
5a1cfbf
-		     const gchar *xnest_cookie)
5a1cfbf
+		     const gchar *xnest_cookie,
5a1cfbf
+		     const gchar *username)
5a1cfbf
 {
5a1cfbf
 	GdmDisplay *display;
5a1cfbf
 	gchar *bin;
5a1cfbf
@@ -3102,6 +3106,7 @@
5a1cfbf
 
5a1cfbf
 	flexi_servers++;
5a1cfbf
 
5a1cfbf
+	display->preset_user = g_strdup (username);
5a1cfbf
 	display->type = type;
5a1cfbf
 	display->socket_conn = conn;
5a1cfbf
 	display->parent_disp = g_strdup (xnest_disp);
5a1cfbf
@@ -3243,6 +3248,7 @@
5a1cfbf
 gdm_handle_user_message (GdmConnection *conn, const gchar *msg, gpointer data)
5a1cfbf
 {
5a1cfbf
 	gint i;
5a1cfbf
+	gboolean has_user;
5a1cfbf
 
5a1cfbf
 	gdm_debug ("Handling user message: '%s'", msg);
5a1cfbf
 
5a1cfbf
@@ -3311,12 +3317,16 @@
5a1cfbf
 		handle_flexi_server (conn, TYPE_FLEXI, gdm_get_value_string (GDM_KEY_STANDARD_XSERVER),
5a1cfbf
 				     TRUE /* handled */,
5a1cfbf
 				     FALSE /* chooser */,
5a1cfbf
-				     NULL, 0, NULL, NULL);
5a1cfbf
-	} else if (strncmp (msg, GDM_SUP_FLEXI_XSERVER " ",
5a1cfbf
-		            strlen (GDM_SUP_FLEXI_XSERVER " ")) == 0) {
5a1cfbf
+				     NULL, 0, NULL, NULL, NULL);
5a1cfbf
+	} else if (((has_user = strncmp (msg, GDM_SUP_FLEXI_XSERVER_USER " ", 
5a1cfbf
+                                         strlen (GDM_SUP_FLEXI_XSERVER_USER " "))) == 0) ||
5a1cfbf
+                   (strncmp (msg, GDM_SUP_FLEXI_XSERVER " ",
5a1cfbf
+		            strlen (GDM_SUP_FLEXI_XSERVER " ")) == 0)) {
5a1cfbf
 		gchar *name;
5a1cfbf
 		const gchar *command = NULL;
5a1cfbf
 		GdmXserver *svr;
5a1cfbf
+		const gchar *rest;
5a1cfbf
+		gchar *username, *end;
5a1cfbf
 
5a1cfbf
 		/* Only allow locally authenticated connections */
5a1cfbf
 		if ( ! GDM_CONN_AUTHENTICATED(conn)) {
5a1cfbf
@@ -3327,7 +3337,21 @@
5a1cfbf
 			return;
5a1cfbf
 		}
5a1cfbf
 
5a1cfbf
-		name = g_strdup (&msg[strlen (GDM_SUP_FLEXI_XSERVER " ")]);
5a1cfbf
+		if (has_user == 0) {
5a1cfbf
+			rest = msg + strlen (GDM_SUP_FLEXI_XSERVER_USER " ");
5a1cfbf
+			end = strchr (rest, ' ');
5a1cfbf
+			if (end) {
5a1cfbf
+				username = g_strndup (rest, end - rest);
5a1cfbf
+				rest = end + 1;
5a1cfbf
+			} else {
5a1cfbf
+				username = g_strdup (rest);
5a1cfbf
+				rest = rest + strlen (rest);
5a1cfbf
+			}
5a1cfbf
+		} else {
5a1cfbf
+			rest = msg + strlen (GDM_SUP_FLEXI_XSERVER " ");
5a1cfbf
+			username = NULL;
5a1cfbf
+		}
5a1cfbf
+		name = g_strdup (rest);
5a1cfbf
 		g_strstrip (name);
5a1cfbf
 		if (ve_string_empty (name)) {
5a1cfbf
 			g_free (name);
5a1cfbf
@@ -3357,13 +3381,27 @@
5a1cfbf
 					oh well, this makes other things simpler */
5a1cfbf
 				     svr->handled,
5a1cfbf
 				     svr->chooser,
5a1cfbf
-				     NULL, 0, NULL, NULL);
5a1cfbf
-	} else if (strncmp (msg, GDM_SUP_FLEXI_XNEST " ",
5a1cfbf
-		            strlen (GDM_SUP_FLEXI_XNEST " ")) == 0) {
5a1cfbf
+				     NULL, 0, NULL, NULL, username);
5a1cfbf
+		g_free (username);
5a1cfbf
+	} else if (((has_user = strncmp (msg, GDM_SUP_FLEXI_XNEST_USER " ",
5a1cfbf
+                                         strlen (GDM_SUP_FLEXI_XNEST_USER " "))) == 0) || 
5a1cfbf
+                   (strncmp (msg, GDM_SUP_FLEXI_XNEST " ",
5a1cfbf
+		            strlen (GDM_SUP_FLEXI_XNEST " ")) == 0)) {
5a1cfbf
 		gchar *dispname = NULL, *xauthfile = NULL, *cookie = NULL;
5a1cfbf
 		uid_t uid;
5a1cfbf
+		const gchar *rest;
5a1cfbf
+		gchar *username, *end;
5a1cfbf
+
5a1cfbf
+                if (has_user == 0) {
5a1cfbf
+			rest = msg + strlen (GDM_SUP_FLEXI_XNEST_USER " ");
5a1cfbf
+			end = strchr (rest, ' ');
5a1cfbf
+			username = g_strndup (rest, end - rest);
5a1cfbf
+		} else {
5a1cfbf
+			rest = msg;
5a1cfbf
+			username = NULL;
5a1cfbf
+		}
5a1cfbf
 
5a1cfbf
-		extract_dispname_uid_xauthfile_cookie (msg, &dispname, &uid,
5a1cfbf
+		extract_dispname_uid_xauthfile_cookie (rest, &dispname, &uid,
5a1cfbf
 						       &xauthfile, &cookie);
5a1cfbf
 
5a1cfbf
 		if (dispname == NULL) {
5a1cfbf
@@ -3387,10 +3425,11 @@
5a1cfbf
 		handle_flexi_server (conn, TYPE_FLEXI_XNEST, gdm_get_value_string (GDM_KEY_XNEST),
5a1cfbf
 				     TRUE /* handled */,
5a1cfbf
 				     FALSE /* chooser */,
5a1cfbf
-				     dispname, uid, xauthfile, cookie);
5a1cfbf
+				     dispname, uid, xauthfile, cookie, username);
5a1cfbf
 
5a1cfbf
 		g_free (dispname);
5a1cfbf
 		g_free (xauthfile);
5a1cfbf
+		g_free (username);
5a1cfbf
 	} else if ((strncmp (msg, GDM_SUP_ATTACHED_SERVERS,
5a1cfbf
 	                     strlen (GDM_SUP_ATTACHED_SERVERS)) == 0) ||
5a1cfbf
 	           (strncmp (msg, GDM_SUP_CONSOLE_SERVERS,