Commits
Chris Jones authored 8c1ba70e339
1 - | From 455d862774b791f4ca93f9885e1e899208a5080c Mon Sep 17 00:00:00 2001 |
1 + | From bf2bb516a584937cd45728fdb6e21bc84dce365a Mon Sep 17 00:00:00 2001 |
2 2 | From: Jeremy Huddleston Sequoia <jeremyhu@apple.com> |
3 3 | Date: Sat, 10 Sep 2016 22:32:56 -0700 |
4 - | Subject: [PATCH 3/3] os/connection: Improve abstraction for launchd secure |
4 + | Subject: [PATCH 1/3] os/connection: Improve abstraction for launchd secure |
5 5 | sockets |
6 6 | |
7 7 | This changes away from hard-coding the /tmp/launch-* path to now |
8 - | supporting a generic <path to unix socket>[.<screen>] format for |
9 - | $DISPLAY. |
8 + | supporting a generic <absolute path to unix socket>[.<screen>] |
9 + | format for $DISPLAY. |
10 10 | |
11 11 | cf-libxcb: d978a4f69b30b630f28d07f1003cf290284d24d8 |
12 12 | |
13 13 | Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> |
14 + | CC: Adam Jackson <ajax@kemper.freedesktop.org> |
14 15 | --- |
15 16 | os/connection.c | 31 ++++++++++++++++++++++++++----- |
16 17 | 1 file changed, 26 insertions(+), 5 deletions(-) |
17 18 | |
18 19 | diff --git a/os/connection.c b/os/connection.c |
19 - | index a901ebf..ac7d12b 100644 |
20 + | index a901ebf..0d42184 100644 |
20 21 | --- a/os/connection.c |
21 22 | +++ b/os/connection.c |
22 23 | |
23 24 | #include <stdio.h> |
24 25 | #include <stdlib.h> |
25 26 | |
26 27 | +#include <sys/stat.h> |
27 28 | + |
28 29 | #ifndef WIN32 |
29 30 | #include <sys/socket.h> |
33 34 | ListenOnOpenFD(int fd, int noxauth) |
34 35 | { |
35 36 | - char port[256]; |
36 37 | + char port[PATH_MAX]; |
37 38 | XtransConnInfo ciptr; |
38 39 | const char *display_env = getenv("DISPLAY"); |
39 40 | |
40 41 | - if (display_env && (strncmp(display_env, "/tmp/launch", 11) == 0)) { |
41 42 | - /* Make the path the launchd socket if our DISPLAY is set right */ |
42 43 | - strcpy(port, display_env); |
43 - | + /* First check if display_env matches a <path to unix socket>[.<screen number>] scheme (eg: launchd) */ |
44 - | + if (display_env) { |
44 + | + /* First check if display_env matches a <absolute path to unix socket>[.<screen number>] scheme (eg: launchd) */ |
45 + | + if (display_env && display_env[0] == '/') { |
45 46 | + struct stat sbuf; |
46 47 | + |
47 48 | + strlcpy(port, display_env, sizeof(port)); |
48 49 | + |
49 50 | + /* If the path exists, we don't have do do anything else. |
50 51 | + * If it doesn't, we need to check for a .<screen number> to strip off and recheck. |
51 52 | + */ |
52 53 | + if (0 != stat(port, &sbuf)) { |
53 54 | + char *dot = strrchr(port, '.'); |
54 55 | + if (dot) { |
61 62 | + display_env = NULL; |
62 63 | + } |
63 64 | + } |
64 65 | } |
65 66 | - else { |
66 67 | + |
67 68 | + if (!display_env) { |
68 69 | /* Just some default so things don't break and die. */ |
69 70 | snprintf(port, sizeof(port), ":%d", atoi(display)); |
70 71 | } |
71 - | -- |
72 - | 2.9.3 |
73 - | |