e0e7dff8 |
1 | /* |
2 | * ux_x11.c: fetch local auth data for X forwarding. |
3 | */ |
4 | |
5 | #include <ctype.h> |
6 | #include <unistd.h> |
fc0f17db |
7 | #include <assert.h> |
8def70c3 |
8 | #include <stdlib.h> |
9 | |
e0e7dff8 |
10 | #include "putty.h" |
fc0f17db |
11 | #include "ssh.h" |
8def70c3 |
12 | #include "network.h" |
e0e7dff8 |
13 | |
8def70c3 |
14 | void platform_get_x11_auth(struct X11Display *disp, const Config *cfg) |
e0e7dff8 |
15 | { |
8def70c3 |
16 | char *xauthfile; |
17 | int needs_free; |
e0e7dff8 |
18 | |
9939292a |
19 | /* |
8def70c3 |
20 | * Upgrade an IP-style localhost display to a Unix-socket |
21 | * display. |
9939292a |
22 | */ |
8def70c3 |
23 | if (!disp->unixdomain && sk_address_is_local(disp->addr)) { |
24 | sk_addr_free(disp->addr); |
25 | disp->unixdomain = TRUE; |
26 | disp->addr = platform_get_x11_unix_address(NULL, disp->displaynum); |
27 | disp->realhost = dupprintf("unix:%d", disp->displaynum); |
28 | disp->port = 0; |
29 | } |
e0e7dff8 |
30 | |
8def70c3 |
31 | /* |
32 | * Set the hostname for Unix-socket displays, so that we'll |
33 | * look it up correctly in the X authority file. |
34 | */ |
35 | if (disp->unixdomain) { |
36 | int len; |
e0e7dff8 |
37 | |
8def70c3 |
38 | sfree(disp->hostname); |
39 | len = 128; |
40 | do { |
41 | len *= 2; |
42 | disp->hostname = snewn(len, char); |
43 | if (gethostname(disp->hostname, len) < 0) { |
44 | disp->hostname = NULL; |
45 | return; |
46 | } |
47 | } while (strlen(disp->hostname) >= len-1); |
48 | } |
e0e7dff8 |
49 | |
8def70c3 |
50 | /* |
51 | * Find the .Xauthority file. |
52 | */ |
53 | needs_free = FALSE; |
54 | xauthfile = getenv("XAUTHORITY"); |
55 | if (!xauthfile) { |
56 | xauthfile = getenv("HOME"); |
57 | if (xauthfile) { |
58 | xauthfile = dupcat(xauthfile, "/.Xauthority", NULL); |
59 | needs_free = TRUE; |
60 | } |
61 | } |
e0e7dff8 |
62 | |
8def70c3 |
63 | if (xauthfile) { |
64 | x11_get_auth_from_authfile(disp, xauthfile); |
65 | if (needs_free) |
66 | sfree(xauthfile); |
e0e7dff8 |
67 | } |
e0e7dff8 |
68 | } |
8def70c3 |
69 | |
70 | const int platform_uses_x11_unix_by_default = TRUE; |