X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/e0e7dff87dc3f482da6ab00317664474b0f82995..HEAD:/unix/ux_x11.c diff --git a/unix/ux_x11.c b/unix/ux_x11.c index 7753c854..63a92b58 100644 --- a/unix/ux_x11.c +++ b/unix/ux_x11.c @@ -4,103 +4,37 @@ #include #include +#include +#include +#include + #include "putty.h" +#include "ssh.h" +#include "network.h" -void platform_get_x11_auth(char *display, int *protocol, - unsigned char *data, int *datalen) +void platform_get_x11_auth(struct X11Display *disp, Conf *conf) { - FILE *fp; - char *command; - int maxsize = *datalen; - char *localbuf; - - command = dupprintf("xauth list %s 2>/dev/null", display); - fp = popen(command, "r"); - sfree(command); - - if (!fp) - return; /* assume no auth */ - - localbuf = smalloc(maxsize); - - while (1) { - /* - * Read a line from stdin, and attempt to parse it into a - * display name (ignored), auth protocol, and auth string. - */ - int c, i, hexdigit, proto; - char protoname[64]; - - /* Skip the display name. */ - while (c = getc(fp), c != EOF && c != '\n' && !isspace(c)); - if (c == EOF) break; - if (c == '\n') continue; - - /* Skip white space. */ - while (c != EOF && c != '\n' && isspace(c)) - c = getc(fp); - if (c == EOF) break; - if (c == '\n') continue; - - /* Read the auth protocol name, and see if it matches any we - * know about. */ - i = 0; - while (c != EOF && c != '\n' && !isspace(c)) { - if (i < lenof(protoname)-1) protoname[i++] = c; - c = getc(fp); - } - protoname[i] = '\0'; - - for (i = X11_NO_AUTH; ++i < X11_NAUTHS ;) { - if (!strcmp(protoname, x11_authnames[i])) - break; - } - if (i >= X11_NAUTHS || i <= proto) { - /* Unrecognised protocol name, or a worse one than we already have. - * Skip this line. */ - while (c != EOF && c != '\n') - c = getc(fp); - if (c == EOF) break; - } - proto = i; - - /* Skip white space. */ - while (c != EOF && c != '\n' && isspace(c)) - c = getc(fp); - if (c == EOF) break; - if (c == '\n') continue; - - /* - * Now grab pairs of hex digits and shove them into `data'. - */ - i = 0; - hexdigit = -1; - while (c != EOF && c != '\n') { - int hexval = -1; - if (c >= 'A' && c <= 'F') - hexval = c + 10 - 'A'; - if (c >= 'a' && c <= 'f') - hexval = c + 10 - 'a'; - if (c >= '0' && c <= '9') - hexval = c - '0'; - if (hexval >= 0) { - if (hexdigit >= 0) { - hexdigit = (hexdigit << 4) + hexval; - if (i < maxsize) - localbuf[i++] = hexdigit; - hexdigit = -1; - } else - hexdigit = hexval; - } - c = getc(fp); - } - - *datalen = i; - *protocol = proto; - memcpy(data, localbuf, i); + char *xauthfile; + int needs_free; + + /* + * 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; + } + } - /* Nonetheless, continue looping round; we might find a better one. */ + if (xauthfile) { + x11_get_auth_from_authfile(disp, xauthfile); + if (needs_free) + sfree(xauthfile); } - pclose(fp); - sfree(localbuf); } + +const int platform_uses_x11_unix_by_default = TRUE;