2003-01-10 18:33:35 +00:00
|
|
|
/*
|
|
|
|
* ux_x11.c: fetch local auth data for X forwarding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
2004-05-31 14:01:52 +00:00
|
|
|
#include <assert.h>
|
2008-11-17 18:38:09 +00:00
|
|
|
#include <stdlib.h>
|
2009-01-05 01:01:58 +00:00
|
|
|
#include <errno.h>
|
2008-11-17 18:38:09 +00:00
|
|
|
|
2003-01-10 18:33:35 +00:00
|
|
|
#include "putty.h"
|
2004-05-31 14:01:52 +00:00
|
|
|
#include "ssh.h"
|
2008-11-17 18:38:09 +00:00
|
|
|
#include "network.h"
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2008-11-17 18:38:09 +00:00
|
|
|
void platform_get_x11_auth(struct X11Display *disp, const Config *cfg)
|
2003-01-10 18:33:35 +00:00
|
|
|
{
|
2008-11-17 18:38:09 +00:00
|
|
|
char *xauthfile;
|
|
|
|
int needs_free;
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2003-01-11 09:46:50 +00:00
|
|
|
/*
|
2008-11-17 18:38:09 +00:00
|
|
|
* Upgrade an IP-style localhost display to a Unix-socket
|
|
|
|
* display.
|
2003-01-11 09:46:50 +00:00
|
|
|
*/
|
2008-11-17 18:38:09 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2008-11-17 18:38:09 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2008-11-17 18:38:09 +00:00
|
|
|
sfree(disp->hostname);
|
|
|
|
len = 128;
|
|
|
|
do {
|
|
|
|
len *= 2;
|
|
|
|
disp->hostname = snewn(len, char);
|
2009-01-05 01:01:58 +00:00
|
|
|
if ((gethostname(disp->hostname, len) < 0) &&
|
|
|
|
(errno != ENAMETOOLONG)) {
|
2008-11-17 18:38:09 +00:00
|
|
|
disp->hostname = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (strlen(disp->hostname) >= len-1);
|
|
|
|
}
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2008-11-17 18:38:09 +00:00
|
|
|
/*
|
|
|
|
* Find the .Xauthority file.
|
|
|
|
*/
|
|
|
|
needs_free = FALSE;
|
|
|
|
xauthfile = getenv("XAUTHORITY");
|
|
|
|
if (!xauthfile) {
|
|
|
|
xauthfile = getenv("HOME");
|
|
|
|
if (xauthfile) {
|
|
|
|
xauthfile = dupcat(xauthfile, "/.Xauthority", NULL);
|
|
|
|
needs_free = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2003-01-10 18:33:35 +00:00
|
|
|
|
2008-11-17 18:38:09 +00:00
|
|
|
if (xauthfile) {
|
|
|
|
x11_get_auth_from_authfile(disp, xauthfile);
|
|
|
|
if (needs_free)
|
|
|
|
sfree(xauthfile);
|
2003-01-10 18:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:38:09 +00:00
|
|
|
|
|
|
|
const int platform_uses_x11_unix_by_default = TRUE;
|