From bf2bb516a584937cd45728fdb6e21bc84dce365a Mon Sep 17 00:00:00 2001
From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Date: Sat, 10 Sep 2016 22:32:56 -0700
Subject: [PATCH 1/3] os/connection: Improve abstraction for launchd secure
This changes away from hard-coding the /tmp/launch-* path to now
supporting a generic <absolute path to unix socket>[.<screen>]
cf-libxcb: d978a4f69b30b630f28d07f1003cf290284d24d8
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
CC: Adam Jackson <ajax@kemper.freedesktop.org>
os/connection.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/os/connection.c b/os/connection.c
index a901ebf..0d42184 100644
@@ -79,6 +79,8 @@ SOFTWARE.
@@ -1112,15 +1114,34 @@ MakeClientGrabPervious(ClientPtr client)
ListenOnOpenFD(int fd, int noxauth)
const char *display_env = getenv("DISPLAY");
- if (display_env && (strncmp(display_env, "/tmp/launch", 11) == 0)) {
- /* Make the path the launchd socket if our DISPLAY is set right */
- strcpy(port, display_env);
+ /* First check if display_env matches a <absolute path to unix socket>[.<screen number>] scheme (eg: launchd) */
+ if (display_env && display_env[0] == '/') {
+ strlcpy(port, display_env, sizeof(port));
+ /* If the path exists, we don't have do do anything else.
+ * If it doesn't, we need to check for a .<screen number> to strip off and recheck.
+ if (0 != stat(port, &sbuf)) {
+ char *dot = strrchr(port, '.');
+ if (0 != stat(port, &sbuf)) {