Hello, X11 authentication is currently broken, because pflocal's implementation of getsockname is broken. It seems to happen since the enabling of payload optimization.
I have attached a simple testcase: in glibc getsockname() calls socket_name() which returns a port, and then calls socket_whatis_address() on that port. In pflocal, that turns into calling sock_get_addr() which eventually calls addr_create which creates a port in the addr_port_class. Then socket_whatis_address is called, but addr is NULL, i.e. the lookup failed... I've added a call to mach_port_clear_protected_payload to disable the payload optimization for those addr ports, and it then works nicely. Also, I had to disable the msgh_bits and msgh_protected_payload mangling, otherwise pflocal was completely not working, I'm not sure what these bits were useful for actually. Thoughts? Samuel
#include <sys/socket.h> #include <stdio.h> int main(void) { int s = socket(PF_UNIX, SOCK_STREAM, 0); if (s < 0) perror("socket"); struct sockaddr sock; size_t size = sizeof(sock); if (getsockname(s, &sock, &size) < 0) perror("getsockname"); printf("%d\n", sock.sa_family); return 0; }
Index: hurd-debian/libports/manage-multithread.c =================================================================== --- hurd-debian.orig/libports/manage-multithread.c +++ hurd-debian/libports/manage-multithread.c @@ -173,6 +173,7 @@ ports_manage_port_operations_multithread else { pi = ports_lookup_port (bucket, inp->msgh_local_port, 0); +#if 0 if (pi) { inp->msgh_bits = MACH_MSGH_BITS ( @@ -180,6 +181,7 @@ ports_manage_port_operations_multithread MACH_MSG_TYPE_PROTECTED_PAYLOAD); inp->msgh_protected_payload = (unsigned long) pi; } +#endif } if (pi) Index: hurd-debian/libports/manage-one-thread.c =================================================================== --- hurd-debian.orig/libports/manage-one-thread.c +++ hurd-debian/libports/manage-one-thread.c @@ -64,6 +64,7 @@ ports_manage_port_operations_one_thread else { pi = ports_lookup_port (bucket, inp->msgh_local_port, 0); +#if 0 if (pi) { inp->msgh_bits = MACH_MSGH_BITS ( @@ -71,6 +72,7 @@ ports_manage_port_operations_one_thread MACH_MSG_TYPE_PROTECTED_PAYLOAD); inp->msgh_protected_payload = (unsigned long) pi; } +#endif } if (pi) Index: hurd-debian/pflocal/sock.c =================================================================== --- hurd-debian.orig/pflocal/sock.c +++ hurd-debian/pflocal/sock.c @@ -262,6 +262,7 @@ addr_create (struct addr **addr) if (! err) { + mach_port_clear_protected_payload (mach_task_self (), (*addr)->pi.port_right); ensure_sock_server (); (*addr)->sock = NULL; pthread_mutex_init (&(*addr)->lock, NULL);