1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Since r8305, Unix PuTTY has always "upgraded" an X11 display like "localhost:0"

to a Unix-domain socket. This typically works fine when PuTTY is run on the
same machine as the X server, but it's broken multi-hop X forwarding through
OpenSSH; when OpenSSH creates a proxy X server "localhost:10", it only listens
on TCP, not on a Unix-domain socket.

Instead, when deciding on the details of the display, we actively probe to see
if there's a Unix-domain socket we can use instead, and only use it if it's
there, falling back to the specified IP "localhost" if not.

Independently, when looking for local auth details in Xauthority for a
"localhost" TCP display, we prefer a matching Unix-domain entry, but will fall
back to an IP "localhost" entry (which would be unusual, but we don't trust a
Windows X server not to do it) -- this is a generalisation of the special case
added in r2538 (but removed in r8305, as the automatic upgrade masked the need
for it).
(This is now done in platform-independent code, so a side-effect is that
get_hostname() is now part of the networking abstraction on all platforms.)

[originally from svn r8462]
[r2538 == fda9983243]
[r8305 == ca6fc3a4da]
This commit is contained in:
Jacob Nevins
2009-02-24 01:01:23 +00:00
parent 40be9eeedd
commit d699530e4c
5 changed files with 153 additions and 60 deletions

View File

@ -17,40 +17,6 @@ void platform_get_x11_auth(struct X11Display *disp, const Config *cfg)
char *xauthfile;
int needs_free;
/*
* Upgrade an IP-style localhost display to a Unix-socket
* display.
*/
if (!disp->unixdomain && sk_address_is_local(disp->addr)) {
sk_addr_free(disp->addr);
disp->unixdomain = TRUE;
disp->addr = platform_get_x11_unix_address(NULL, disp->displaynum);
disp->realhost = dupprintf("unix:%d", disp->displaynum);
disp->port = 0;
}
/*
* Set the hostname for Unix-socket displays, so that we'll
* look it up correctly in the X authority file.
*/
if (disp->unixdomain) {
int len;
sfree(disp->hostname);
disp->hostname = NULL;
len = 128;
do {
len *= 2;
disp->hostname = sresize(disp->hostname, len, char);
if ((gethostname(disp->hostname, len) < 0) &&
(errno != ENAMETOOLONG)) {
sfree(disp->hostname);
disp->hostname = NULL;
return;
}
} while (strlen(disp->hostname) >= len-1);
}
/*
* Find the .Xauthority file.
*/

View File

@ -1395,6 +1395,23 @@ int net_service_lookup(char *service)
return 0;
}
char *get_hostname(void)
{
int len = 128;
char *hostname = NULL;
do {
len *= 2;
hostname = sresize(hostname, len, char);
if ((gethostname(hostname, len) < 0) &&
(errno != ENAMETOOLONG)) {
sfree(hostname);
hostname = NULL;
break;
}
} while (strlen(hostname) >= len-1);
return hostname;
}
SockAddr platform_get_x11_unix_address(const char *sockpath, int displaynum)
{
SockAddr ret = snew(struct SockAddr_tag);