Index: xauth-1.0.3/gethost.c
===================================================================
--- xauth-1.0.3/gethost.c.orig
+++ xauth-1.0.3/gethost.c
@@ -244,7 +244,8 @@ struct addrlist *get_address_info (
     int family,
     char *fulldpyname,
     int prefix,
-    char *host)
+    char *host,
+    char *localhostname)
 {
     struct addrlist *retval = NULL;
     int len = 0;
@@ -274,7 +275,7 @@ struct addrlist *get_address_info (
 	if (prefix == 0 && (strncmp (fulldpyname, "unix:", 5) == 0 ||
 			    fulldpyname[0] == ':')) {
 
-	    if (!get_local_hostname (buf, sizeof buf)) {
+	    if (!get_local_hostname (buf, sizeof buf, localhostname)) {
 		len = 0;
 	    } else {
 		src = buf;
Index: xauth-1.0.3/parsedpy.c
===================================================================
--- xauth-1.0.3/parsedpy.c.orig
+++ xauth-1.0.3/parsedpy.c
@@ -74,20 +74,24 @@ copystring (char *src, int len)
 
 
 char *
-get_local_hostname (char *buf, int maxlen)
+get_local_hostname (char *buf, int maxlen, char *localhostname)
 {
     buf[0] = '\0';
+    if (localhostname)
+	strncpy(buf, localhostname, maxlen);
+    else
     (void) XmuGetHostname (buf, maxlen);
+    
     return (buf[0] ? buf : NULL);
 }
 
 #ifndef UNIXCONN
 static char *
-copyhostname (void)
+copyhostname (char *localhostname)
 {
     char buf[256];
 
-    return (get_local_hostname (buf, sizeof buf) ? 
+    return (get_local_hostname (buf, sizeof buf, localhostname) ? 
 	    copystring (buf, strlen (buf)) : NULL);
 }
 #endif
@@ -97,6 +101,7 @@ copyhostname (void)
  */
 Bool 
 parse_displayname (char *displayname, 
+		   char *localhostname,
 		   int *familyp,	/* return */
 		   char **hostp,	/* return */
 		   int *dpynump,	/* return */
@@ -138,7 +143,7 @@ parse_displayname (char *displayname,
 	    host = copystring ("0", 1);
 	    family = FamilyDECnet;
 	} else {
-	    host = copyhostname ();
+	    host = copyhostname (localhostname);
 	    family = FamilyInternet;
 	}
 #endif
Index: xauth-1.0.3/process.c
===================================================================
--- xauth-1.0.3/process.c.orig
+++ xauth-1.0.3/process.c
@@ -466,7 +466,7 @@ read_auth_entries(FILE *fp, Bool numeric
 }
 
 static Bool 
-get_displayname_auth(char *displayname, AuthList **authl)
+get_displayname_auth(char *displayname, AuthList **authl, char *localhostname)
 {
     int family;
     char *host = NULL, *rest = NULL;
@@ -489,11 +489,13 @@ get_displayname_auth(char *displayname,
         displayname = strrchr(displayname, '/') + 1;
 
     if (!parse_displayname (displayname + ((prelen > 0) ? prelen + 1 : 0),
+			    localhostname,
 			    &family, &host, &dpynum, &scrnum, &rest)) {
 	return False;
     }
 
-    addrlist_head = get_address_info(family, displayname, prelen, host);
+    addrlist_head = get_address_info(family, displayname, prelen, host,
+				     localhostname);
     if (addrlist_head) {
 	char buf[40];			/* want to hold largest display num */
 	unsigned short dpylen;
@@ -1223,13 +1225,19 @@ iterdpy (char *inputfilename, int lineno
     Xauth *tmp_auth;
     AuthList *proto_head, *proto;
     AuthList *l, *next;
+    /*
+     * get saved local address from environment in case the host
+     * name has changed after the credential was added.
+     */
+    char *xlocalhostname = getenv("XAUTHLOCALHOSTNAME");
+    
 
     /*
      * iterate
      */
     for (i = start; i < argc; i++) {
 	char *displayname = argv[i];
-	if (!get_displayname_auth (displayname, &proto_head)) {
+	if (!get_displayname_auth (displayname, &proto_head, xlocalhostname)) {
 	    prefix (inputfilename, lineno);
 	    baddisplayname (displayname, argv[0]);
 	    errors++;
@@ -1568,7 +1576,7 @@ do_add(char *inputfilename, int lineno,
 	}
     }
 
-    if (!get_displayname_auth (dpyname, &list)) {
+    if (!get_displayname_auth (dpyname, &list, NULL)) {
 	prefix (inputfilename, lineno);
 	baddisplayname (dpyname, argv[0]);
 	free (key);
Index: xauth-1.0.3/xauth.h
===================================================================
--- xauth-1.0.3/xauth.h.orig
+++ xauth-1.0.3/xauth.h
@@ -51,10 +51,10 @@ struct addrlist {
 };
 
 extern char *get_hostname ( Xauth *auth );
-extern struct addrlist *get_address_info ( int family, char *fulldpyname, int prefix, char *host);
+extern struct addrlist *get_address_info ( int family, char *fulldpyname, int prefix, char *host, char *localhostname);
 extern char *copystring ( char *src, int len );
-extern char *get_local_hostname ( char *buf, int maxlen );
-extern Bool parse_displayname ( char *displayname, int *familyp, char **hostp, int *dpynump, int *scrnump, char **restp );
+extern char *get_local_hostname ( char *buf, int maxlen , char *localhostname);
+extern Bool parse_displayname ( char *displayname, char *localhostname, int *familyp, char **hostp, int *dpynump, int *scrnump, char **restp );
 extern int auth_initialize ( char *authfilename );
 extern int auth_finalize ( void );
 extern int process_command ( char *inputfilename, int lineno, int argc, char **argv );
Index: xdm-1.1.8/auth.c
===================================================================
--- xdm-1.1.8/auth.c.orig
+++ xdm-1.1.8/auth.c
@@ -680,7 +680,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));
@@ -716,6 +716,9 @@ DefineLocal (FILE *file, Xauth *auth)
 #endif
 
 	writeAddr (FamilyLocal, len, displayname, file, auth);
+
+        if (pLocalAddress && displayname)
+           *pLocalAddress = strdup(displayname);
 }
 
 #ifdef HAS_GETIFADDRS
@@ -1148,7 +1151,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;
 
@@ -1175,13 +1178,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;
@@ -1200,7 +1203,7 @@ writeRemoteAuth (FILE *file, Xauth *auth
     }
     else
     {
-	writeLocalAuth (file, auth, name);
+	writeLocalAuth (file, auth, name, pLocalAddress);
     }
 }
 
@@ -1224,6 +1227,7 @@ SetUserAuthorization (struct display *d,
 #ifdef HAS_MKSTEMP
     int		fd;
 #endif
+    char	*localAddress = NULL;
 
     Debug ("SetUserAuthorization\n");
     auths = d->authorizations;
@@ -1316,10 +1320,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;
 	    }
@@ -1337,10 +1341,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;
 	    }
@@ -1379,6 +1383,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);
@@ -1417,10 +1427,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;
Index: xinit-1.1.0/startx.cpp
===================================================================
--- xinit-1.1.0/startx.cpp.orig
+++ xinit-1.1.0/startx.cpp
@@ -409,6 +409,7 @@ fi
 XCOMM handle TCP port 6000
 test "$DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN" != "yes" && \
   serverargs="$serverargs -nolisten tcp"
+export XAUTHLOCALHOSTNAME=`hostname`
 XINIT $client $clientargs -- $server $display $serverargs
 #endif
 
