Index: gdm-2.20.7/daemon/slave.c
===================================================================
--- gdm-2.20.7.orig/daemon/slave.c	2009-10-20 16:00:07.000000000 -0300
+++ gdm-2.20.7/daemon/slave.c	2009-10-20 16:04:59.000000000 -0300
@@ -4333,7 +4333,14 @@
 #endif
 
 #if defined(HAVE_UT_UT_ID)
-	strncpy (record.ut_id, d->name, sizeof (record.ut_id));
+	/* ut_id is defined as a char ut_id[4]. When it's not zero, it's
+	 * used as the unique identifier for getutxid (used below), when
+	 * ut_id is zero, ut_line is used as the identifier instead.
+	 *
+	 * d->name can be hosname:display :display or ip:display.
+	 * Since storing the first bytes may create collissions, we choose to
+	 * leave ut_id as zero and use ut_line as the main identifier.
+	 */
 	gdm_debug ("utmp-wtmp: Using id %*s",
 	       (int) sizeof (record.ut_id),
 	       record.ut_id);
@@ -4363,7 +4370,6 @@
 
 	if (host) {
 		strncpy (record.ut_host, host, sizeof (record.ut_host));
-		g_free (host);
 
 		gdm_debug ("utmp-wtmp: Using hostname %*s",
 		   (int) sizeof (record.ut_host),
@@ -4372,6 +4378,28 @@
 #ifdef HAVE_UT_SYSLEN
 		record.ut_syslen = MIN (strlen (host), sizeof (record.ut_host));
 #endif
+		/* If it hasn't been set yet, set ut_line to the host:display */
+		if (device_name == NULL) {
+			size_t len_host = strlen(host);
+			strncpy (record.ut_line, host, sizeof (record.ut_line));
+
+			/* If the hostname was too long put the display at the end */
+			if ( (len_host+1) > sizeof(record.ut_line) ) {
+				size_t len_display = 0;
+				char *sep = strrchr(host,':');
+				len_display = strlen(sep);
+
+				if ( sep && ( len_display+1 < sizeof (record.ut_line) ) ) {
+					strncpy(record.ut_line + sizeof (record.ut_line) - (len_display+1),
+							sep, len_display+1 );
+				} else {
+					/* if no display was found (or display was too long),
+					 * make sure it's a string */
+					record.ut_line[sizeof (record.ut_line) - 1] = '\0';
+				}
+			}
+		}
+		g_free (host);
 	} 
 #endif
 
