XQuartz: Now properly disable xauth checking on launchd socket and mostly fix the xinitrc / launchd race condition

This commit is contained in:
Jeremy Huddleston 2008-08-06 10:23:31 -07:00
parent d1b96cdea9
commit e72b1d21e4
5 changed files with 52 additions and 37 deletions

View File

@ -1545,7 +1545,7 @@ if test "x$XQUARTZ" = xyes; then
AC_CHECK_LIB([Xplugin],[xp_init],[:]) AC_CHECK_LIB([Xplugin],[xp_init],[:])
CFLAGS="${CFLAGS} -DROOTLESS_WORKAROUND -DNO_ALLOCA -DXQUARTZ_EXPORTS_LAUNCHD_FD" CFLAGS="${CFLAGS} -DROOTLESS_WORKAROUND -DNO_ALLOCA"
fi fi
# Support for objc in autotools is minimal and not documented. # Support for objc in autotools is minimal and not documented.

View File

@ -343,12 +343,16 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
} }
} }
#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
int xquartz_launchd_fd = -1; int xquartz_launchd_fd = -1;
#endif
void DarwinListenOnOpenFD(int fd) { void DarwinListenOnOpenFD(int fd) {
ErrorF("DarwinListenOnOpenFD: %d\n", fd); ErrorF("DarwinListenOnOpenFD: %d\n", fd);
#if 0 #ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
xquartz_launchd_fd = fd;
#else
pthread_mutex_lock(&fd_add_lock); pthread_mutex_lock(&fd_add_lock);
if(fd_add_count < FD_ADD_MAX) if(fd_add_count < FD_ADD_MAX)
fd_add[fd_add_count++] = fd; fd_add[fd_add_count++] = fd;
@ -357,8 +361,6 @@ void DarwinListenOnOpenFD(int fd) {
pthread_cond_broadcast(&fd_add_ready_cond); pthread_cond_broadcast(&fd_add_ready_cond);
pthread_mutex_unlock(&fd_add_lock); pthread_mutex_unlock(&fd_add_lock);
#else
xquartz_launchd_fd = fd;
#endif #endif
} }
@ -378,7 +380,7 @@ static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceInt
for (i=0; i<nevents; i++) { for (i=0; i<nevents; i++) {
ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)xe[i].u.clientMessage.u.l.longs0); ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)xe[i].u.clientMessage.u.l.longs0);
ListenOnOpenFD((int)xe[i].u.clientMessage.u.l.longs0); ListenOnOpenFD((int)xe[i].u.clientMessage.u.l.longs0, 1);
} }
} }

View File

@ -161,11 +161,18 @@ static void accept_fd_handoff(int connected_fd) {
launchd_fd = *((int*)CMSG_DATA(cmsg)); launchd_fd = *((int*)CMSG_DATA(cmsg));
if(launchd_fd == -1) if(launchd_fd == -1) {
fprintf(stderr, "X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd); fprintf(stderr, "X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd);
return;
}
#ifndef XQUARTZ_EXPORTS_LAUNCHD_FD
fprintf(stderr, "X11.app: Received new DISPLAY fd: %d ... sleeping to allow xinitrc to catchup.\n", launchd_fd);
/* TODO: Clean up this race better... givint xinitrc time to run. */
sleep(2);
#endif
// fprintf(stderr, "X11.app: Received new DISPLAY fd: %d ... sleeping before handoff to server thread\n", launchd_fd);
// sleep(5);
fprintf(stderr, "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd); fprintf(stderr, "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd);
DarwinListenOnOpenFD(launchd_fd); DarwinListenOnOpenFD(launchd_fd);
} }
@ -329,8 +336,12 @@ int main(int argc, char **argv, char **envp) {
/* Could open the display, start the launcher */ /* Could open the display, start the launcher */
XCloseDisplay(display); XCloseDisplay(display);
#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
fprintf(stderr, "X11.app: Received new DISPLAY fd: %d ... sleeping to allow xinitrc to catchup.\n", launchd_fd);
/* TODO: Clean up this race better... givint xinitrc time to run. */ /* TODO: Clean up this race better... givint xinitrc time to run. */
sleep(2); sleep(2);
#endif
return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT)); return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
} }
@ -359,7 +370,7 @@ int main(int argc, char **argv, char **envp) {
noPanoramiXExtension = TRUE; noPanoramiXExtension = TRUE;
fprintf(stderr, "X11.app: main(): argc=%d\n", argc); fprintf(stderr, "X11.app: main(): argc=%d\n", argc);
for(i=1; i < argc; i++) { for(i=0; i < argc; i++) {
fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]); fprintf(stderr, "\targv[%u] = %s\n", (unsigned)i, argv[i]);
if(!strcmp(argv[i], "--listenonly")) { if(!strcmp(argv[i], "--listenonly")) {
listenOnly = TRUE; listenOnly = TRUE;

View File

@ -166,7 +166,7 @@ extern void MakeClientGrabImpervious(ClientPtr /*client*/);
extern void MakeClientGrabPervious(ClientPtr /*client*/); extern void MakeClientGrabPervious(ClientPtr /*client*/);
#ifdef XQUARTZ #ifdef XQUARTZ
extern void ListenOnOpenFD(int /* fd */); extern void ListenOnOpenFD(int /* fd */, int /* noxauth */);
#endif #endif
extern void AvailableClientInput(ClientPtr /* client */); extern void AvailableClientInput(ClientPtr /* client */);

View File

@ -74,9 +74,7 @@ SOFTWARE.
#define TRANS_SERVER #define TRANS_SERVER
#define TRANS_REOPEN #define TRANS_REOPEN
#include <X11/Xtrans/Xtrans.h> #include <X11/Xtrans/Xtrans.h>
#ifdef HAVE_LAUNCHD
#include <X11/Xtrans/Xtransint.h> #include <X11/Xtrans/Xtransint.h>
#endif
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -661,23 +659,22 @@ ClientAuthorized(ClientPtr client,
XID auth_id; XID auth_id;
char *reason = NULL; char *reason = NULL;
XtransConnInfo trans_conn; XtransConnInfo trans_conn;
#ifdef HAVE_LAUNCHD
struct sockaddr *saddr;
#endif
priv = (OsCommPtr)client->osPrivate; priv = (OsCommPtr)client->osPrivate;
trans_conn = priv->trans_conn; trans_conn = priv->trans_conn;
#ifdef HAVE_LAUNCHD /* Make it compile for now, remove this once we have a new xtrans release and are depending on it in configure.ac */
saddr = (struct sockaddr *) (trans_conn->addr); #ifndef TRANS_NOXAUTH
/* Allow any client to connect without authorization on a launchd socket, #define TRANS_NOXAUTH 0
because it is securely created -- this prevents a race condition on launch */
if (saddr->sa_len > 11 && saddr->sa_family == AF_UNIX &&
!strncmp(saddr->sa_data, "/tmp/launch", 11)) goto done;
#endif #endif
auth_id = CheckAuthorization (proto_n, auth_proto, /* Allow any client to connect without authorization on a launchd socket,
string_n, auth_string, client, &reason); because it is securely created -- this prevents a race condition on launch */
if(trans_conn->flags | TRANS_NOXAUTH) {
auth_id = (XID) 0L;
} else {
auth_id = CheckAuthorization (proto_n, auth_proto, string_n, auth_string, client, &reason);
}
if (auth_id == (XID) ~0L) if (auth_id == (XID) ~0L)
{ {
@ -725,9 +722,6 @@ ClientAuthorized(ClientPtr client,
} }
} }
priv->auth_id = auth_id; priv->auth_id = auth_id;
#ifdef HAVE_LAUNCHD
done:
#endif
priv->conn_time = 0; priv->conn_time = 0;
#ifdef XDMCP #ifdef XDMCP
@ -1269,12 +1263,17 @@ MakeClientGrabPervious(ClientPtr client)
#ifdef XQUARTZ #ifdef XQUARTZ
/* Add a fd (from launchd) to our listeners */ /* Add a fd (from launchd) to our listeners */
_X_EXPORT void ListenOnOpenFD(int fd) { _X_EXPORT void ListenOnOpenFD(int fd, int noxauth) {
char port[20]; char port[256];
XtransConnInfo ciptr; XtransConnInfo ciptr;
/* Sigh for inconsistencies. */ if(!strncmp(getenv("DISPLAY"), "/tmp/launch", 11)) {
sprintf (port, ":%d", atoi(display)); /* Make the path the launchd socket if our DISPLAY is set right */
strcpy(port, getenv("DISPLAY"));
} else {
/* Just some default so things don't break and die. */
sprintf(port, ":%d", atoi(display));
}
/* Make our XtransConnInfo /* Make our XtransConnInfo
* TRANS_SOCKET_LOCAL_INDEX = 5 from Xtrans.c * TRANS_SOCKET_LOCAL_INDEX = 5 from Xtrans.c
@ -1285,6 +1284,9 @@ _X_EXPORT void ListenOnOpenFD(int fd) {
return; return;
} }
if(noxauth)
ciptr->flags = ciptr->flags | TRANS_NOXAUTH;
/* Allocate space to store it */ /* Allocate space to store it */
ListenTransFds = (int *) xrealloc(ListenTransFds, (ListenTransCount + 1) * sizeof (int)); ListenTransFds = (int *) xrealloc(ListenTransFds, (ListenTransCount + 1) * sizeof (int));
ListenTransConns = (XtransConnInfo *) xrealloc(ListenTransConns, (ListenTransCount + 1) * sizeof (XtransConnInfo)); ListenTransConns = (XtransConnInfo *) xrealloc(ListenTransConns, (ListenTransCount + 1) * sizeof (XtransConnInfo));
@ -1299,11 +1301,11 @@ _X_EXPORT void ListenOnOpenFD(int fd) {
/* Increment the count */ /* Increment the count */
ListenTransCount++; ListenTransCount++;
/* This *might* be needed, but it seems to be working fine without it... */ /* This *might* not be needed... /shrug */
//ResetAuthorization(); ResetAuthorization();
//ResetHosts(display); ResetHosts(display);
#ifdef XDMCP #ifdef XDMCP
//XdmcpReset(); XdmcpReset();
#endif #endif
} }