try hostname uncanonified if getaddrinfo() fails

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8194 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-04-19 14:19:38 +00:00
parent cb35b03467
commit 499c5a0751

View File

@@ -555,12 +555,13 @@ fail:
/* /*
* Return 0 iff `cookie' is compatible with the cookie for the * Return 0 iff `cookie' is compatible with the cookie for the
* localhost with name given in `disp_he' and display number in * localhost with name given in `ai' (or `hostname') and display
* `disp_nr'. * number in `disp_nr'.
*/ */
static int static int
match_local_auth (Xauth* auth, struct addrinfo *ai, int disp_nr) match_local_auth (Xauth* auth,
struct addrinfo *ai, const char *hostname, int disp_nr)
{ {
int auth_disp; int auth_disp;
char *tmp_disp; char *tmp_disp;
@@ -582,6 +583,11 @@ match_local_auth (Xauth* auth, struct addrinfo *ai, int disp_nr)
auth->address_length) == 0) auth->address_length) == 0)
return 0; return 0;
} }
if (hostname != NULL
&& (auth->family == FamilyLocal
|| auth->family == FamilyWild)
&& strncmp (auth->address, hostname, auth->address_length) == 0)
return 0;
return 1; return 1;
} }
@@ -622,18 +628,18 @@ find_auth_cookie (FILE *f)
hints.ai_protocol = IPPROTO_TCP; hints.ai_protocol = IPPROTO_TCP;
error = getaddrinfo (display, NULL, &hints, &ai); error = getaddrinfo (display, NULL, &hints, &ai);
if (error) { if (error)
warnx ("getaddrinfo %s: %s", display, gai_strerror(error)); ai = NULL;
return NULL;
}
for (; (ret = XauReadAuth (f)) != NULL; XauDisposeAuth(ret)) { for (; (ret = XauReadAuth (f)) != NULL; XauDisposeAuth(ret)) {
if (match_local_auth (ret, ai, disp) == 0) { if (match_local_auth (ret, ai, display, disp) == 0) {
freeaddrinfo (ai); if (ai != NULL)
freeaddrinfo (ai);
return ret; return ret;
} }
} }
freeaddrinfo (ai); if (ai != NULL)
freeaddrinfo (ai);
return NULL; return NULL;
} }