Bug 44859 - ConvertAddress (in backend/netaddr.c) does not handle localhost correctly
Summary: ConvertAddress (in backend/netaddr.c) does not handle localhost correctly
Status: CLOSED FIXED
Alias: None
Product: kdm
Classification: Unmaintained
Component: general (other bugs)
Version First Reported In: unspecified
Platform: FreeBSD Ports FreeBSD
: NOR normal
Target Milestone: ---
Assignee: kdm bugs tracker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-08 02:33 UTC by ab
Modified: 2008-05-19 17:30 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ab 2002-07-08 02:22:32 UTC
(*** This bug was imported into bugs.kde.org ***)

Package:           kdm
Version:           KDE 3.0.2 
Severity:          normal
Installed from:    FreeBSD Ports
Compiler:          gcc version 2.95.4 20020320 [FreeBSD]
OS:                FreeBSD
OS/Compiler notes: Not Specified

* Symptom:

When an X server connects to a local KDM over XDMCP the greeter works but X user applications launched from Xsession fail to connect to the X server.

* Background:

Out of bazillion useful but ugly hacks that X11 has there is this one: When given a local display name is specified using the IPv4 loopback address 127.0.0.1 libX11 implicitly converts the display name to one that uses the local transport e.g. `127.0.0.1:0.0' will be converted to `:0.0'.  X11R6's _XTransConvertAddress() in xc/lib/xtrans/Xtransutil.c is where this hack lives.

It is also this converted display name that libX11 looks for in the xauth database ($XAUTHORITY ~/.Xauthority).  For example when $DISPLAY is set to 127.0.0.1:0.0 libX11 looks for an entry of :0.0 not of 127.0.0.1:0.0.  And if there are entries for 127.0.0.1:* they are just ignored.

Unfortunately XDM fails to meet this hack and adds an xauth entry for 127.0.0.1:* to the user's xauth database when it accepts a login session over XDMCP from the localhost.  And KDM being an XDM descendant inherits the same problem.

The following patch fixes this problem by adding a functionally equivalent hack as libX11's one to ConvertAddress() in backend/netaddr.c.

* Fix:

--- snip ---
--- kdebase-3.0.2/kdm/backend/netaddr.c.oldMon Jun 24 04:56:29 2002
+++ kdebase-3.0.2/kdm/backend/netaddr.cSun Jul  7 11:21:17 2002
@@ -556 +557 @@
 #ifdef DNETCONN
 #include <netdnet/dn.h>/* struct sockaddr_dn */
 #endif
+#include <sys/param.h>/* struct sockaddr_in */
 
 /* given an XdmcpNetaddr returns the socket protocol family used
    e.g. AF_INET */
@@ -1616 +16211 @@
 #endif
 #ifdef TCPCONN
       case AF_INET:
+/* BSD localhost hack; meets the _XTransConvertAddress behavior */
+if (ntohl(*(in_addr_t *)*addr) == 0x7F000001L) {
+  retval = FamilyLocal;
+  break;
+}
         retval = FamilyInternet;
 break;
 #endif
--- snip ---


(Submitted via bugs.kde.org)
Comment 1 Eugene M. Kim 2002-07-08 17:05:14 UTC
--0OAP2g/MAC+5xKAE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

The original patch breaks indirect queries; here's a new version that
affects only the xauth portion.  Please use this instead and revert
netaddr.c to the original version.

Thanks
Eugene

--0OAP2g/MAC+5xKAE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kdm-localhost-fix.diff"

--- kdebase-3.0.2/kdm/backend/auth.c.oldSun Mar 24 09:31:09 2002
+++ kdebase-3.0.2/kdm/backend/auth.cMon Jul  8 09:52:50 2002
@@ -6646 +66422 @@
 /* Argh! this is evil. But ConvertAddr works only with Xdmcp.h */
 #ifdef XDMCP
 
+/*
+ * Call ConvertAddr() and if it returns an IPv4 localhost convert it
+ * to a local display name.  Meets the _XTransConvertAddress's localhost
+ * hack.
+ */
+ 
+static int ConvertAuthAddr
+(XdmcpNetaddr saddr int *len char **addr)
+{
+    int ret;
+    ret = ConvertAddr(saddr len addr);
+    if (ret == FamilyInternet && *(in_addr_t *)*addr == htonl(0x7F000001L))
+ret = FamilyLocal;
+    return ret;
+}
+
 #ifdef SYSV_SIOCGIFCONF
 
 /* Deal with different SIOCGIFCONF ioctl semantics on SYSV SVR4 */
@@ -10157 +10317 @@
     if (!peer || peerlen < 2)
 return;
     setAuthNumber (auth name);
-    family = ConvertAddr (peer &peerlen &addr);
+    family = ConvertAuthAddr (peer &peerlen &addr);
     Debug ("writeRemoteAuth: family %d\n" family);
     if (family != FamilyLocal)
     {

--0OAP2g/MAC+5xKAE--
Comment 2 Oswald Buddenhagen 2002-07-14 00:07:37 UTC
second patch applied