Index: xdm/auth.c
===================================================================
--- xdm.orig/auth.c
+++ xdm/auth.c
@@ -744,7 +744,7 @@ writeAddr (
 }
 
 static void
-DefineLocal (FILE *file, Xauth *auth)
+DefineLocal (FILE *file, Xauth *auth, char **pLocalAddress)
 {
 	char	displayname[100];
 	int	len = _XGetHostname (displayname, sizeof(displayname));
@@ -759,6 +759,9 @@ DefineLocal (FILE *file, Xauth *auth)
 
 
 	writeAddr (FamilyLocal, len, displayname, file, auth);
+
+        if (pLocalAddress)
+           *pLocalAddress = strdup(displayname);
 }
 
 #ifdef HAVE_GETIFADDRS
@@ -1019,7 +1022,7 @@ setAuthNumber (Xauth *auth, char *name)
 }
 
 static void
-writeLocalAuth (FILE *file, Xauth *auth, char *name)
+writeLocalAuth (FILE *file, Xauth *auth, char *name, char **pLocalAddress)
 {
     int	fd;
 
@@ -1034,13 +1037,13 @@ writeLocalAuth (FILE *file, Xauth *auth,
     DefineSelf (fd, file, auth);
     close (fd);
 #endif
-    DefineLocal (file, auth);
+    DefineLocal (file, auth, pLocalAddress);
 }
 
 #ifdef XDMCP
 
 static void
-writeRemoteAuth (FILE *file, Xauth *auth, XdmcpNetaddr peer, int peerlen, char *name)
+writeRemoteAuth (FILE *file, Xauth *auth, XdmcpNetaddr peer, int peerlen, char *name, char **pLocalAddress)
 {
     int	    family = FamilyLocal;
     char    *addr;
@@ -1059,7 +1062,7 @@ writeRemoteAuth (FILE *file, Xauth *auth
     }
     else
     {
-	writeLocalAuth (file, auth, name);
+	writeLocalAuth (file, auth, name, pLocalAddress);
     }
 }
 
@@ -1083,6 +1086,7 @@ SetUserAuthorization (struct display *d,
 #ifdef HAVE_MKSTEMP
     int		fd;
 #endif
+    char	*localAddress = NULL;
 
     Debug ("SetUserAuthorization\n");
     auths = d->authorizations;
@@ -1175,10 +1179,10 @@ SetUserAuthorization (struct display *d,
 	    {
 		magicCookie = i;
 		if (d->displayType.location == Local)
-		    writeLocalAuth (new, auths[i], d->name);
+		    writeLocalAuth (new, auths[i], d->name, &localAddress);
 #ifdef XDMCP
 		else
-		    writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
+		    writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name, &localAddress);
 #endif
 		break;
 	    }
@@ -1196,10 +1200,10 @@ SetUserAuthorization (struct display *d,
 		    !strncmp (auths[i]->name, "MIT-KERBEROS-5", 14))
 		    auths[i]->data_length = 0;
 		if (d->displayType.location == Local)
-		    writeLocalAuth (new, auths[i], d->name);
+		    writeLocalAuth (new, auths[i], d->name, &localAddress);
 #ifdef XDMCP
 		else
-		    writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
+		    writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name, &localAddress);
 #endif
 		auths[i]->data_length = data_len;
 	    }
@@ -1244,6 +1248,12 @@ SetUserAuthorization (struct display *d,
 	    verify->systemEnviron = setEnv (verify->systemEnviron,
 				    "XAUTHORITY", envname);
 	}
+	if (localAddress) {
+	    verify->userEnviron = setEnv (verify->userEnviron,
+				    "XAUTHLOCALHOSTNAME",localAddress);
+	    free(localAddress);
+	}
+	
 	XauUnlockAuth (name);
 	if (envname)
 	    chown (envname, verify->uid, verify->gid);
@@ -1282,10 +1292,10 @@ RemoveUserAuthorization (struct display
 	for (i = 0; i < d->authNum; i++)
 	{
 	    if (d->displayType.location == Local)
-		writeLocalAuth (new, auths[i], d->name);
+		writeLocalAuth (new, auths[i], d->name, NULL);
 #ifdef XDMCP
 	    else
-		writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
+		writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name, NULL);
 #endif
 	}
 	doWrite = 1;