Bug#551802: gdm: still fails to manage remote utmp records correctly

Maximiliano Curia maxy at debian.org
Fri Oct 15 17:34:07 UTC 2010


Hola Josselin Mouette!

El 15/10/2010 a las 15:23 escribiste:
> The gdm package is only here to handle upgrades from lenny. Could you
> test again with gdm3?

gdm3 shows the same behaviour, a patch for this is reported here:
http://mail.gnome.org/archives/gdm-list/2009-October/msg00021.html

Looking the patch I see that I forgot to add a g_free in one of the
get_hostname calls. So, I'm attaching a patch that includes the missing
g_free. Anyway, as I don't have a test machine available right now, I
haven't test this patch with the debian gdm3 version. I'll try to test it this
weekend.

Sadly I didn't notice https://bugzilla.gnome.org/show_bug.cgi?id=599103 being
closed, I'll try to reopen that as well.

-- 
"La duración de un minuto depende de que lado del baño estés."
		-- Ley de la Relatividad (Burke)
Saludos /\/\ /\ >< `/
-------------- next part --------------
commit e7207d3a29b79c6de20e0eac80d0ec5cec19b1af
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date:   Fri Oct 15 14:13:25 2010 -0300

    Missing g_free

diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 49237fa..0ff2c25 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -209,6 +209,7 @@ record_set_line (UTMP       *u,
 							u->ut_line[sizeof (u->ut_line) - 1] = '\0';
 						}
 				}
+				g_free(hostname);
 			}
 		}
         g_debug ("using ut_line %.*s", (int) sizeof (u->ut_line), u->ut_line);

commit db8dfa01f888bbf4b63d52f5d9e3d3766b9ade51
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date:   Wed Oct 21 13:26:23 2009 -0300

    Replacing a one time while with a simple if

diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 8ca0e4f..49237fa 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -328,14 +328,9 @@ gdm_session_record_logout (GPid                  session_pid,
 #if defined(HAVE_GETUTXENT)
         setutxent ();
 
-        while ((u = getutxline (&session_record)) != NULL) {
+        if ((u = getutxline (&session_record)) != NULL) {
 
                 g_debug ("Removing utmp record");
-                if (u->ut_pid == session_pid &&
-                    u->ut_type == DEAD_PROCESS) {
-                        /* Already done */
-                        break;
-                }
 
                 u->ut_type = DEAD_PROCESS;
 #if defined(HAVE_UT_UT_TV)

commit 1121c86629798f294c56d131fd8e33f937df5db8
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date:   Wed Oct 21 13:14:32 2009 -0300

    Removing unneeded call to getutxent

diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index e65c79e..8ca0e4f 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -328,8 +328,7 @@ gdm_session_record_logout (GPid                  session_pid,
 #if defined(HAVE_GETUTXENT)
         setutxent ();
 
-        while ((u = getutxent ()) != NULL &&
-               (u = getutxline (&session_record)) != NULL) {
+        while ((u = getutxline (&session_record)) != NULL) {
 
                 g_debug ("Removing utmp record");
                 if (u->ut_pid == session_pid &&

commit 1725094cadcf2896a8fed59313494f92d3f0d8f9
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date:   Wed Oct 21 12:35:51 2009 -0300

    Remote display utmp fix

diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 4ed60a1..e65c79e 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -136,36 +136,38 @@ record_set_id (UTMP       *u,
 #endif
 }
 
-static void
-record_set_host (UTMP       *u,
-                 const char *x11_display_name,
-                 const char *host_name)
+static char *get_hostname(const char* x11_display_name, const char* host_name)
 {
-        char *hostname;
-
-#if defined(HAVE_UT_UT_HOST)
-        hostname = NULL;
-
         /*
-         * Set ut_host to hostname:$DISPLAY if remote, otherwise set
+         * Returns hostname:$DISPLAY if remote, otherwise set
          * to $DISPLAY
          */
         if (host_name != NULL
             && x11_display_name != NULL
             && g_str_has_prefix (x11_display_name, ":")) {
-                hostname = g_strdup_printf ("%s%s", host_name, x11_display_name);
-        } else {
-                hostname = g_strdup (x11_display_name);
+                return g_strdup_printf ("%s%s", host_name, x11_display_name);
         }
+		return g_strdup (x11_display_name);
+}
+
+static void
+record_set_host (UTMP       *u,
+                 const char *x11_display_name,
+                 const char *host_name)
+{
+        char *hostname;
+
+#if defined(HAVE_UT_UT_HOST)
+        hostname = get_hostname(x11_display_name, host_name);
 
         if (hostname != NULL) {
                 strncpy (u->ut_host, hostname, sizeof (u->ut_host));
                 g_debug ("using ut_host %.*s", (int) sizeof (u->ut_host), u->ut_host);
-                g_free (hostname);
 
 #ifdef HAVE_UT_UT_SYSLEN
                 u->ut_syslen = MIN (strlen (hostname), sizeof (u->ut_host));
 #endif
+                g_free (hostname);
         }
 #endif
 }
@@ -173,7 +175,8 @@ record_set_host (UTMP       *u,
 static void
 record_set_line (UTMP       *u,
                  const char *display_device,
-                 const char *x11_display_name)
+                 const char *x11_display_name,
+				 const char *host_name)
 {
         /*
          * Set ut_line to the device name associated with this display
@@ -185,13 +188,29 @@ record_set_line (UTMP       *u,
                 strncpy (u->ut_line,
                          display_device + strlen ("/dev/"),
                          sizeof (u->ut_line));
-        } else if (x11_display_name != NULL
-                   && g_str_has_prefix (x11_display_name, ":")) {
-                strncpy (u->ut_line,
-                         x11_display_name,
-                         sizeof (u->ut_line));
-        }
-
+        } else {
+			char *hostname = get_hostname(x11_display_name, host_name);
+			if ( hostname != NULL ) {
+	            strncpy (u->ut_line, hostname, sizeof (u->ut_line));
+
+				/* If the hostname was too long put the display at the end */
+				if ( strlen(hostname)+1 > sizeof(u->ut_line) ) {
+					size_t len_display = 0;
+					char *sep = strrchr(hostname,':');
+					len_display = strlen(sep);
+
+					if ( sep && ( len_display+1 < sizeof (u->ut_line) ) )
+						{
+							strncpy(u->ut_line + sizeof (u->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 */
+							u->ut_line[sizeof (u->ut_line) - 1] = '\0';
+						}
+				}
+			}
+		}
         g_debug ("using ut_line %.*s", (int) sizeof (u->ut_line), u->ut_line);
 }
 
@@ -218,9 +237,11 @@ gdm_session_record_login (GPid                  session_pid,
         record_set_pid (&session_record, session_pid);
 
         /* Set ut_id to the $DISPLAY value */
-        record_set_id (&session_record, x11_display_name);
+		/* Don't, leave it as all \0s */
+        /* record_set_id (&session_record, x11_display_name); */
         record_set_host (&session_record, x11_display_name, host_name);
-        record_set_line (&session_record, display_device, x11_display_name);
+        record_set_line (&session_record, display_device, x11_display_name,
+				host_name);
 
         /* Handle wtmp */
         g_debug ("Writing wtmp session record to " GDM_NEW_SESSION_RECORDS_FILE);
@@ -286,9 +307,11 @@ gdm_session_record_logout (GPid                  session_pid,
         record_set_timestamp (&session_record);
         record_set_pid (&session_record, session_pid);
         /* Set ut_id to the $DISPLAY value */
-        record_set_id (&session_record, x11_display_name);
+		/* Don't, leave it as all \0s */
+        /* record_set_id (&session_record, x11_display_name); */
         record_set_host (&session_record, x11_display_name, host_name);
-        record_set_line (&session_record, display_device, x11_display_name);
+        record_set_line (&session_record, display_device, x11_display_name,
+				host_name);
 
 
         /* Handle wtmp */
@@ -306,7 +329,7 @@ gdm_session_record_logout (GPid                  session_pid,
         setutxent ();
 
         while ((u = getutxent ()) != NULL &&
-               (u = getutxid (&session_record)) != NULL) {
+               (u = getutxline (&session_record)) != NULL) {
 
                 g_debug ("Removing utmp record");
                 if (u->ut_pid == session_pid &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-gnome-maintainers/attachments/20101015/287ba282/attachment.pgp>


More information about the pkg-gnome-maintainers mailing list