Windows 10 [received support](https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/) for AF_UNIX sockets in Insider Build 17063. This merge request adds basic support for AF_UNIX sockets to ws2_32 and wineserver.
Of particular note is the difficulty in handling `sun_path`. Most of the functions that allow for translating Windows paths to Unix paths are not accessible from ws2_32. I considered the following options: * Pass the Windows path to wineserver and do the conversion there. * This is, as far as I can tell, not possible without major rearchitecting. wineserver does not have functions to translate Windows paths to Unix paths, for obvious reasons. * Obtain the current working directory of the requesting process and temporarily change directories to there. * This only handles relative paths and fails for absolute paths, UNC paths, etc. * Conditionally change directories based on whether the path is relative or not. * This is error-prone and wineserver does not have the requisite functions to do this cleanly.
I ultimately decided to pass the translated Unix path to wineserver, which changes directories to `dirname(path)`. It then provides `bind` and `connect` with `basename(path)`. This is not threadsafe, but wineserver is not (currently) multithreaded.
Abstract sockets are supported by this patch.
-- v28: ws2_32/tests: Add test for AF_UNIX sockets.
From: Ally Sommers dropbear.sh@gmail.com
This header is needed for support of AF_UNIX sockets. --- include/Makefile.in | 1 + include/afunix.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 include/afunix.h
diff --git a/include/Makefile.in b/include/Makefile.in index e9f0aa8d5fb..fcdeabd2d72 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -11,6 +11,7 @@ SOURCES = \ adshlp.h \ advpub.h \ af_irda.h \ + afunix.h \ amaudio.h \ amsi.idl \ amstream.idl \ diff --git a/include/afunix.h b/include/afunix.h new file mode 100644 index 00000000000..8118dda271b --- /dev/null +++ b/include/afunix.h @@ -0,0 +1,38 @@ +/* + * Copyright 2023 Ally Sommers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef _WS2AFUNIX_ +#define _WS2AFUNIX_ + +#include "windef.h" +#include "ws2def.h" + +#ifdef USE_WS_PREFIX +# define WS(x) WS_##x +#else +# define WS(x) x +#endif + +#define UNIX_PATH_MAX 108 + +typedef struct WS(sockaddr_un) { + USHORT sun_family; + char sun_path[UNIX_PATH_MAX]; +} SOCKADDR_UN, *PSOCKADDR_UN; + +#endif /* _WS2AFUNIX_ */ \ No newline at end of file
From: Ally Sommers dropbear.sh@gmail.com
--- dlls/ntdll/unix/socket.c | 33 +++++++++++++++++++++++++++++++++ dlls/ws2_32/socket.c | 17 +++++++++++++++++ 2 files changed, 50 insertions(+)
diff --git a/dlls/ntdll/unix/socket.c b/dlls/ntdll/unix/socket.c index 4e706323a0a..51a6a6e8f47 100644 --- a/dlls/ntdll/unix/socket.c +++ b/dlls/ntdll/unix/socket.c @@ -66,6 +66,8 @@ # define HAS_IRDA #endif
+#include <sys/un.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -77,6 +79,7 @@ #include "ws2tcpip.h" #include "wsipx.h" #include "af_irda.h" +#include "afunix.h" #include "wine/afd.h"
#include "unix_private.h" @@ -105,6 +108,7 @@ union unix_sockaddr #ifdef HAS_IRDA struct sockaddr_irda irda; #endif + struct sockaddr_un un; };
struct async_recv_ioctl @@ -289,6 +293,17 @@ static socklen_t sockaddr_to_unix( const struct WS_sockaddr *wsaddr, int wsaddrl return sizeof(uaddr->in6); }
+ case WS_AF_UNIX: + { + struct WS_sockaddr_un win = {0}; + + if (wsaddrlen < sizeof(win)) return 0; + memcpy( &win, wsaddr, sizeof(win) ); + uaddr->un.sun_family = AF_UNIX; + memcpy( uaddr->un.sun_path, win.sun_path, sizeof(win.sun_path) ); + return sizeof(uaddr->un); + } + default: FIXME( "unknown address family %u\n", wsaddr->sa_family ); return 0; @@ -361,6 +376,17 @@ static int sockaddr_from_unix( const union unix_sockaddr *uaddr, struct WS_socka } #endif
+ case AF_UNIX: + { + struct WS_sockaddr_un win = {0}; + + if (wsaddrlen < sizeof(win)) return -1; + win.sun_family = WS_AF_UNIX; + memcpy( win.sun_path, uaddr->un.sun_path, sizeof(win.sun_path) ); + memcpy( wsaddr, &win, sizeof(win) ); + return sizeof(win); + } + case AF_UNSPEC: return 0;
@@ -1926,6 +1952,13 @@ NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc break; }
+ if (unix_addr.addr.sa_family == AF_UNIX) + { + FIXME( "getpeername called on AF_UNIX socket\n" ); + status = STATUS_NOT_SUPPORTED; + break; + } + len = sockaddr_from_unix( &unix_addr, out_buffer, out_size ); if (out_size < len) { diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 710ec8cbb26..234d68e0b7c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -167,6 +167,22 @@ static const WSAPROTOCOL_INFOW supported_protocols[] = .dwMessageSize = UINT_MAX, .szProtocol = L"SPX II", }, +<<<<<<< HEAD +======= + { + .dwServiceFlags1 = XP1_GUARANTEED_DELIVERY | XP1_GUARANTEED_ORDER | XP1_IFS_HANDLES, + .dwProviderFlags = PFL_MATCHES_PROTOCOL_ZERO, + .ProviderId = {0xa00943d9, 0x9c2e, 0x4633, {0x9b, 0x59, 0x00, 0x57, 0xa3, 0x16, 0x09, 0x94}}, + .dwCatalogEntryId = 1007, + .ProtocolChain.ChainLen = 1, + .iVersion = 2, + .iAddressFamily = AF_UNIX, + .iMaxSockAddr = sizeof(struct sockaddr_un), + .iMinSockAddr = offsetof(struct sockaddr_un, sun_path), + .iSocketType = SOCK_STREAM, + .szProtocol = L"AF_UNIX", + } +>>>>>>> d592fbd7db8 (add support fix) };
DECLARE_CRITICAL_SECTION(cs_socket_list); @@ -1238,6 +1254,7 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len ) status = NtDeviceIoControlFile( (HANDLE)s, sync_event, NULL, NULL, &io, IOCTL_AFD_WINE_CONNECT, params, sizeof(*params) + len, NULL, 0 ); free( params ); + free( unix_path ); if (status == STATUS_PENDING) { if (wait_event_alertable( sync_event ) == WAIT_FAILED) return -1;
From: Ally Sommers dropbear.sh@gmail.com
This commit additionally modifies wineserver's sock_ioctl to handle the provided pathname by changing directories and then returning after the native call. This is NOT threadsafe, but wineserver is not multithreaded. --- dlls/ws2_32/socket.c | 58 +++++++++++++++++++++---- dlls/ws2_32/ws2_32_private.h | 14 ++++++ server/sock.c | 82 +++++++++++++++++++++++++++++++++++- 3 files changed, 144 insertions(+), 10 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 234d68e0b7c..5e231aa428e 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -167,8 +167,6 @@ static const WSAPROTOCOL_INFOW supported_protocols[] = .dwMessageSize = UINT_MAX, .szProtocol = L"SPX II", }, -<<<<<<< HEAD -======= { .dwServiceFlags1 = XP1_GUARANTEED_DELIVERY | XP1_GUARANTEED_ORDER | XP1_IFS_HANDLES, .dwProviderFlags = PFL_MATCHES_PROTOCOL_ZERO, @@ -182,7 +180,6 @@ static const WSAPROTOCOL_INFOW supported_protocols[] = .iSocketType = SOCK_STREAM, .szProtocol = L"AF_UNIX", } ->>>>>>> d592fbd7db8 (add support fix) };
DECLARE_CRITICAL_SECTION(cs_socket_list); @@ -242,6 +239,11 @@ const char *debugstr_sockaddr( const struct sockaddr *a ) addr, ((const SOCKADDR_IRDA *)a)->irdaServiceName); } + case AF_UNIX: + { + return wine_dbg_sprintf("{ family AF_UNIX, path %s }", + ((const SOCKADDR_UN *)a)->sun_path); + } default: return wine_dbg_sprintf("{ family %d }", a->sa_family); } @@ -1122,6 +1124,9 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len ) HANDLE sync_event; NTSTATUS status;
+ char *unix_path = NULL; + int unix_path_len = 0; + TRACE( "socket %#Ix, addr %s\n", s, debugstr_sockaddr(addr) );
if (!addr) @@ -1164,6 +1169,14 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len ) } break;
+ case AF_UNIX: + if (len < sizeof(struct sockaddr_un)) + { + SetLastError( WSAEFAULT ); + return -1; + } + break; + default: FIXME( "unknown protocol %u\n", addr->sa_family ); SetLastError( WSAEAFNOSUPPORT ); @@ -1172,8 +1185,18 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len )
if (!(sync_event = get_sync_event())) return -1;
- params = malloc( sizeof(int) + len ); - ret_addr = malloc( len ); + if (addr->sa_family == AF_UNIX && *addr->sa_data) + { + WCHAR *sun_pathW = strdupAtoW(addr->sa_data); + unix_path = wine_get_unix_file_name(sun_pathW); + free(sun_pathW); + if (!unix_path) + return SOCKET_ERROR; + unix_path_len = strlen(unix_path) + 1; + } + + params = malloc( sizeof(int) + len + unix_path_len ); + ret_addr = malloc( len + unix_path_len ); if (!params || !ret_addr) { free( params ); @@ -1183,9 +1206,11 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len ) } params->unknown = 0; memcpy( ¶ms->addr, addr, len ); + if (unix_path) + memcpy( (char *)¶ms->addr + len, unix_path, unix_path_len );
status = NtDeviceIoControlFile( (HANDLE)s, sync_event, NULL, NULL, &io, IOCTL_AFD_BIND, - params, sizeof(int) + len, ret_addr, len ); + params, sizeof(int) + len + unix_path_len, ret_addr, len + unix_path_len ); if (status == STATUS_PENDING) { if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED) @@ -1198,6 +1223,8 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len )
free( params ); free( ret_addr ); + if (unix_path) + free( unix_path );
SetLastError( NtStatusToWSAError( status ) ); return status ? -1 : 0; @@ -1238,11 +1265,24 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len ) HANDLE sync_event; NTSTATUS status;
+ char *unix_path = NULL; + int unix_path_len = 0; + TRACE( "socket %#Ix, addr %s, len %d\n", s, debugstr_sockaddr(addr), len );
if (!(sync_event = get_sync_event())) return -1;
- if (!(params = malloc( sizeof(*params) + len ))) + if (addr->sa_family == AF_UNIX && *addr->sa_data) + { + WCHAR *sun_pathW = strdupAtoW(addr->sa_data); + unix_path = wine_get_unix_file_name(sun_pathW); + free(sun_pathW); + if (!unix_path) + return SOCKET_ERROR; + unix_path_len = strlen(unix_path) + 1; + } + + if (!(params = malloc( sizeof(*params) + len + unix_path_len ))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return -1; @@ -1250,9 +1290,11 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len ) params->addr_len = len; params->synchronous = TRUE; memcpy( params + 1, addr, len ); + if (unix_path_len) + memcpy( (char *)(params + 1) + len, unix_path, unix_path_len );
status = NtDeviceIoControlFile( (HANDLE)s, sync_event, NULL, NULL, &io, IOCTL_AFD_WINE_CONNECT, - params, sizeof(*params) + len, NULL, 0 ); + params, sizeof(*params) + len + unix_path_len, NULL, 0 ); free( params ); free( unix_path ); if (status == STATUS_PENDING) diff --git a/dlls/ws2_32/ws2_32_private.h b/dlls/ws2_32/ws2_32_private.h index 41d9e512488..8e5da235801 100644 --- a/dlls/ws2_32/ws2_32_private.h +++ b/dlls/ws2_32/ws2_32_private.h @@ -46,6 +46,7 @@ #include "mstcpip.h" #include "af_irda.h" #include "winnt.h" +#include "afunix.h" #define USE_WC_PREFIX /* For CMSG_DATA */ #include "iphlpapi.h" #include "ip2string.h" @@ -73,6 +74,19 @@ static inline char *strdupWtoA( const WCHAR *str ) return ret; }
+static inline WCHAR *strdupAtoW( const char *str ) +{ + WCHAR *ret = NULL; + if (str) + { + DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + if ((ret = malloc( len * sizeof(WCHAR) ))) + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + } + return ret; +} + + static const char magic_loopback_addr[] = {127, 12, 34, 56};
const char *debugstr_sockaddr( const struct sockaddr *addr ) DECLSPEC_HIDDEN; diff --git a/server/sock.c b/server/sock.c index 088e6d63079..8378944b482 100644 --- a/server/sock.c +++ b/server/sock.c @@ -53,6 +53,7 @@ #include <time.h> #include <unistd.h> #include <limits.h> +#include <libgen.h> #ifdef HAVE_LINUX_FILTER_H # include <linux/filter.h> #endif @@ -83,6 +84,8 @@ # define HAS_IRDA #endif
+#include <sys/un.h> + #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -93,6 +96,7 @@ #include "ws2tcpip.h" #include "wsipx.h" #include "af_irda.h" +#include "afunix.h" #include "wine/afd.h" #include "wine/rbtree.h"
@@ -116,6 +120,7 @@ union win_sockaddr struct WS_sockaddr_in6 in6; struct WS_sockaddr_ipx ipx; SOCKADDR_IRDA irda; + struct WS_sockaddr_un un; };
union unix_sockaddr @@ -129,6 +134,7 @@ union unix_sockaddr #ifdef HAS_IRDA struct sockaddr_irda irda; #endif + struct sockaddr_un un; };
static struct list poll_list = LIST_INIT( poll_list ); @@ -546,6 +552,17 @@ static int sockaddr_from_unix( const union unix_sockaddr *uaddr, struct WS_socka } #endif
+ case AF_UNIX: + { + struct WS_sockaddr_un win = {0}; + + if (wsaddrlen < sizeof(win)) return -1; + win.sun_family = WS_AF_UNIX; + memcpy( win.sun_path, uaddr->un.sun_path, sizeof(win.sun_path) ); + memcpy( wsaddr, &win, sizeof(win) ); + return sizeof(win); + } + case AF_UNSPEC: return 0;
@@ -646,6 +663,17 @@ static socklen_t sockaddr_to_unix( const struct WS_sockaddr *wsaddr, int wsaddrl return sizeof(uaddr->in6); }
+ case WS_AF_UNIX: + { + struct WS_sockaddr_un win = {0}; + + if (wsaddrlen < sizeof(win.sun_family) + strlen( wsaddr->sa_data ) + 1) return 0; + memcpy( &win, wsaddr, sizeof(win) ); + uaddr->un.sun_family = AF_UNIX; + memcpy( uaddr->un.sun_path, win.sun_path, sizeof(win.sun_path) ); + return sizeof(uaddr->un); + } + default: return 0; } @@ -672,6 +700,9 @@ static socklen_t get_unix_sockaddr_any( union unix_sockaddr *uaddr, int ws_famil uaddr->irda.sir_family = AF_IRDA; return sizeof(uaddr->irda); #endif + case WS_AF_UNIX: + uaddr->un.sun_family = AF_UNIX; + return sizeof(uaddr->un); default: return 0; } @@ -1757,6 +1788,7 @@ static int get_unix_family( int family ) #ifdef AF_IRDA case WS_AF_IRDA: return AF_IRDA; #endif + case WS_AF_UNIX: return AF_UNIX; case WS_AF_UNSPEC: return AF_UNSPEC; default: return -1; } @@ -2607,6 +2639,19 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (unix_addr.addr.sa_family == AF_INET && !memcmp( &unix_addr.in.sin_addr, magic_loopback_addr, 4 )) unix_addr.in.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
+ if (sock->family == WS_AF_UNIX && *((struct WS_sockaddr_un *)&addr)->sun_path) + { + char *unix_path = (char *)(params + 1) + params->addr_len; + char unix_path_copy[PATH_MAX]; + strcpy(unix_path_copy, unix_path); + if (chdir( dirname( unix_path_copy ) ) == -1) + { + set_error( sock_get_ntstatus( errno ) ); + return; + } + memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); + } + ret = connect( unix_fd, &unix_addr.addr, unix_len ); if (ret < 0 && errno == ECONNABORTED) { @@ -2619,6 +2664,9 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) ret = connect( unix_fd, &unix_addr.addr, unix_len ); }
+ if (sock->family == WS_AF_UNIX && *((struct WS_sockaddr_un *)&addr)->sun_path) + fchdir(server_dir_fd); + if (ret < 0 && errno != EINPROGRESS) { set_error( sock_get_ntstatus( errno ) ); @@ -2878,7 +2926,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) case IOCTL_AFD_BIND: { const struct afd_bind_params *params = get_req_data(); - union unix_sockaddr unix_addr, bind_addr; + union unix_sockaddr unix_addr, bind_addr, win_addr; data_size_t in_size; socklen_t unix_len; int v6only = 1; @@ -2943,12 +2991,29 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (check_addr_usage( sock, &bind_addr, v6only )) return;
+ if (sock->family == WS_AF_UNIX && *params->addr.sa_data) + { + char *unix_path = (char *)¶ms->addr + sizeof(unix_addr.un); + char unix_path_copy[PATH_MAX]; + strcpy(unix_path_copy, unix_path); + if (chdir( dirname( unix_path_copy ) ) == -1) + { + set_error( sock_get_ntstatus( errno ) ); + return; + } + + win_addr.un = bind_addr.un; + memcpy( bind_addr.un.sun_path, basename( unix_path ), sizeof(bind_addr.un.sun_path) ); + } + if (bind( unix_fd, &bind_addr.addr, unix_len ) < 0) { if (errno == EADDRINUSE && sock->reuseaddr) errno = EACCES;
set_error( sock_get_ntstatus( errno ) ); + if (sock->family == WS_AF_UNIX && *params->addr.sa_data) + fchdir(server_dir_fd); return; }
@@ -2961,6 +3026,8 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) * actual unix address */ if (bind_addr.addr.sa_family == AF_INET) bind_addr.in.sin_addr = unix_addr.in.sin_addr; + if (bind_addr.addr.sa_family == AF_UNIX) + bind_addr = win_addr; sock->addr_len = sockaddr_from_unix( &bind_addr, &sock->addr.addr, sizeof(sock->addr) ); }
@@ -2968,6 +3035,9 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
if (get_reply_max_size() >= sock->addr_len) set_reply_data( &sock->addr, sock->addr_len ); + + if (sock->family == WS_AF_UNIX && *(char *)(params + 1)) + fchdir(server_dir_fd); return; }
@@ -2984,7 +3054,15 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) return; }
- set_reply_data( &sock->addr, sock->addr_len ); + if (sock->family == WS_AF_UNIX) + { + if (*sock->addr.un.sun_path) + set_reply_data( &sock->addr, sizeof(sock->addr.un.sun_family) + strlen(sock->addr.un.sun_path) ); + else + set_reply_data( &sock->addr, sizeof(sock->addr.un) ); + } + else + set_reply_data( &sock->addr, sock->addr_len ); return;
case IOCTL_AFD_WINE_DEFER:
From: Ally Sommers dropbear.sh@gmail.com
Deleting the socket file is a common pattern with AF_UNIX sockets, and is analogous to unbinding. --- server/fd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/server/fd.c b/server/fd.c index eaebe044f37..55d3725b2e2 100644 --- a/server/fd.c +++ b/server/fd.c @@ -1957,6 +1957,24 @@ struct fd *open_fd( struct fd *root, const char *name, struct unicode_str nt_nam fd->unix_fd = open( name, O_RDONLY | (flags & ~(O_TRUNC | O_CREAT | O_EXCL)), *mode ); }
+ /* POSIX requires that open(2) throws EOPNOTSUPP when `path` is a UNIX + * socket. *BSD throws EOPNOTSUPP in this case and the additional case of + * O_SHLOCK or O_EXLOCK being passed when `path` resides on a filesystem + * without lock support. + * + * Contrary to POSIX, Linux returns ENXIO in this case, so we also check + * that error code here. */ + if ((errno == EOPNOTSUPP || errno == ENXIO) && !stat( name, &st ) && S_ISSOCK(st.st_mode)) + { + if ((access & DELETE) && unlink( name )) + { + file_set_error(); + goto error; + } + else + fd->unix_fd = open( name, O_CREAT | O_RDWR, S_IRWXU ); + } + if (fd->unix_fd == -1) { /* check for trailing slash on file path */
From: Ally Sommers dropbear.sh@gmail.com
This also introduces an error when attempting to create an AF_UNIX socket of type SOCK_DGRAM. --- server/sock.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/server/sock.c b/server/sock.c index 8378944b482..f801b44240a 100644 --- a/server/sock.c +++ b/server/sock.c @@ -1881,6 +1881,12 @@ static int init_socket( struct sock *sock, int family, int type, int protocol ) return -1; }
+ if (unix_family == AF_UNIX && unix_type == SOCK_DGRAM) + { + set_win32_error(WSAEAFNOSUPPORT); + return -1; + } + sockfd = socket( unix_family, unix_type, unix_protocol );
#ifdef linux @@ -2639,17 +2645,28 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (unix_addr.addr.sa_family == AF_INET && !memcmp( &unix_addr.in.sin_addr, magic_loopback_addr, 4 )) unix_addr.in.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
- if (sock->family == WS_AF_UNIX && *((struct WS_sockaddr_un *)&addr)->sun_path) + if (sock->family == WS_AF_UNIX) { - char *unix_path = (char *)(params + 1) + params->addr_len; - char unix_path_copy[PATH_MAX]; - strcpy(unix_path_copy, unix_path); - if (chdir( dirname( unix_path_copy ) ) == -1) + if (*((struct WS_sockaddr_un *)&addr)->sun_path) { - set_error( sock_get_ntstatus( errno ) ); + char *unix_path = (char *)(params + 1) + params->addr_len; + char unix_path_copy[PATH_MAX]; + strcpy(unix_path_copy, unix_path); + if (chdir( dirname( unix_path_copy ) ) == -1) + { + set_error( sock_get_ntstatus( errno ) ); + return; + } + memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); + } + else + { + /* Contrary to documentation, Windows does not currently support abstract Unix + * sockets. connect() throws WSAEINVAL if sun_family is AF_UNIX and sun_path + * begins with '\0', even though bind() will succeed. */ + set_win32_error( WSAEINVAL ); return; } - memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); }
ret = connect( unix_fd, &unix_addr.addr, unix_len );
From: Ally Sommers dropbear.sh@gmail.com
--- server/sock.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/server/sock.c b/server/sock.c index f801b44240a..254b007da88 100644 --- a/server/sock.c +++ b/server/sock.c @@ -2058,7 +2058,19 @@ static struct sock *accept_socket( struct sock *sock ) } unix_len = sizeof(unix_addr); if (!getsockname( acceptfd, &unix_addr.addr, &unix_len )) - acceptsock->addr_len = sockaddr_from_unix( &unix_addr, &acceptsock->addr.addr, sizeof(acceptsock->addr) ); + { + if (sock->family == WS_AF_UNIX) + { + acceptsock->addr_len = sock->addr_len; + acceptsock->addr.un = sock->addr.un; + } + else + { + acceptsock->addr_len = sockaddr_from_unix( &unix_addr, + &acceptsock->addr.addr, + sizeof(acceptsock->addr) ); + } + } } clear_error(); sock->pending_events &= ~AFD_POLL_ACCEPT; @@ -2114,7 +2126,19 @@ static int accept_into_socket( struct sock *sock, struct sock *acceptsock )
unix_len = sizeof(unix_addr); if (!getsockname( get_unix_fd( newfd ), &unix_addr.addr, &unix_len )) - acceptsock->addr_len = sockaddr_from_unix( &unix_addr, &acceptsock->addr.addr, sizeof(acceptsock->addr) ); + { + if (sock->family == WS_AF_UNIX) + { + acceptsock->addr_len = sock->addr_len; + acceptsock->addr.un = sock->addr.un; + } + else + { + acceptsock->addr_len = sockaddr_from_unix( &unix_addr, + &acceptsock->addr.addr, + sizeof(acceptsock->addr) ); + } + }
clear_error(); sock->pending_events &= ~AFD_POLL_ACCEPT; @@ -2583,7 +2607,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) { const struct afd_connect_params *params = get_req_data(); const struct WS_sockaddr *addr; - union unix_sockaddr unix_addr; + union unix_sockaddr unix_addr, win_addr; struct connect_req *req; socklen_t unix_len; int send_len, ret; @@ -2645,6 +2669,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (unix_addr.addr.sa_family == AF_INET && !memcmp( &unix_addr.in.sin_addr, magic_loopback_addr, 4 )) unix_addr.in.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
+ memcpy( &win_addr, &unix_addr, sizeof(unix_addr) ); if (sock->family == WS_AF_UNIX) { if (*((struct WS_sockaddr_un *)&addr)->sun_path) @@ -2657,6 +2682,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) set_error( sock_get_ntstatus( errno ) ); return; } + win_addr.un = unix_addr.un; memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); } else @@ -2695,7 +2721,10 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
unix_len = sizeof(unix_addr); if (!getsockname( unix_fd, &unix_addr.addr, &unix_len )) - sock->addr_len = sockaddr_from_unix( &unix_addr, &sock->addr.addr, sizeof(sock->addr) ); + { + if (sock->family != WS_AF_UNIX) + sock->addr_len = sockaddr_from_unix( &unix_addr, &sock->addr.addr, sizeof(sock->addr) ); + } sock->bound = 1;
if (!ret)
From: Ally Sommers dropbear.sh@gmail.com
--- dlls/ws2_32/tests/sock.c | 245 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index cff4acb0b3c..a619bdd87d3 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -29,6 +29,7 @@ #include <iphlpapi.h> #include <ws2tcpip.h> #include <wsipx.h> +#include <afunix.h> #include <wsnwlink.h> #include <mswsock.h> #include <mstcpip.h> @@ -13785,6 +13786,249 @@ static void test_connect_udp(void) closesocket(client); }
+struct afunix_thread_param +{ + int sockfd; + SOCKADDR_UN addr; +}; + +static DWORD WINAPI test_afunix_client_connect_thread(void *param) +{ + struct afunix_thread_param *in = param; + ok(!connect(in->sockfd, (SOCKADDR *)&in->addr, sizeof(in->addr)), "Could not connect to Unix socket: %lu\n", + GetLastError()); + return 0; +} + +static void test_afunix(void) +{ + SOCKET listener, client, server; + SOCKADDR_UN addr = { AF_UNIX, "test_afunix.sock" }; + HANDLE clientThread; + const char serverMsg[] = "ws2_32/AF_UNIX socket test"; + char clientBuf[sizeof(serverMsg)] = { 0 }; + + char paths[4][sizeof(addr.sun_path)] = { "./tmp.sock", "../tmp.sock" }; + char dosPath[sizeof(addr.sun_path)]; + WCHAR dosWidePath[sizeof(addr.sun_path)]; + UNICODE_STRING ntPath = { 0 }; + SOCKADDR_UN outAddr = { 0 }; + int outAddrSize = 0; + int ret; + + /* Test connection and send/recv */ + listener = socket(AF_UNIX, SOCK_STREAM, 0); + if (listener == INVALID_SOCKET && GetLastError() == WSAEAFNOSUPPORT) + { + win_skip("AF_UNIX sockets are unsupported, skipping...\n"); + return; + } + + ok(listener != INVALID_SOCKET, "Could not create Unix socket: %lu\n", + GetLastError()); + + ret = bind(listener, (SOCKADDR *)&addr, sizeof(SOCKADDR_UN)); + ok(!ret, "Could not bind Unix socket: %lu\n", GetLastError()); + + ret = listen(listener, 1); + ok(!ret, "Could not listen on Unix socket: %lu\n", GetLastError()); + + client = socket(AF_UNIX, SOCK_STREAM, 0); + ok(client != INVALID_SOCKET, "Failed to create second Unix socket: %lu\n", + GetLastError()); + + clientThread = CreateThread(NULL, 0, test_afunix_client_connect_thread, + &(struct afunix_thread_param){ client, addr }, 0, NULL); + ok(clientThread != NULL, "CreateThread failed unexpectedly: %ld\n", GetLastError()); + server = accept(listener, NULL, NULL); + ok(server != INVALID_SOCKET, "Could not accept Unix socket connection: %lu\n", + GetLastError()); + + ret = WaitForSingleObject(clientThread, 1000); + ok(!ret, "WaitForSingleObject returned 0x%x\n", ret); + ret = CloseHandle(clientThread); + ok(ret, "CloseHandle failed: %ld\n", GetLastError()); + + ret = send(server, serverMsg, sizeof(serverMsg), 0); + ok(ret == sizeof(serverMsg), "Incorrect return value from send: %d\n", ret); + ret = recv(client, clientBuf, sizeof(serverMsg), 0); + ok(ret == sizeof(serverMsg), "Incorrect return value from recv: %d\n", ret); + ok(!memcmp(serverMsg, clientBuf, sizeof(serverMsg)), "Data mismatch over Unix socket\n"); + + memset(clientBuf, 0, sizeof(clientBuf)); + + ret = sendto(server, serverMsg, sizeof(serverMsg), 0, NULL, 0); + ok(ret == sizeof(serverMsg), "Incorrect return value from sendto: %d\n", ret); + ret = recvfrom(client, clientBuf, sizeof(serverMsg), 0, NULL, 0); + ok(ret == sizeof(serverMsg), "Incorrect return value from recvfrom: %d\n", ret); + ok(!memcmp(serverMsg, clientBuf, sizeof(serverMsg)), "Data mismatch over Unix socket\n"); + + closesocket(listener); + closesocket(client); + closesocket(server); + + /* Test socket file deletion */ + ret = DeleteFileA("test_afunix.sock"); + ok(ret, "DeleteFileA on socket file failed: %lu\n", GetLastError()); + ok(GetFileAttributesA("test_afunix.sock") == INVALID_FILE_ATTRIBUTES && + GetLastError() == ERROR_FILE_NOT_FOUND, + "Failed to delete socket file at path '%s'\n", + addr.sun_path); + + /* Test failure modes */ + listener = socket(AF_UNIX, SOCK_STREAM, 0); + ok(listener != INVALID_SOCKET, "Could not create Unix socket: %lu\n", + GetLastError()); + ret = bind(listener, (SOCKADDR *)&addr, sizeof(SOCKADDR_UN)); + ok(!ret, "Could not bind Unix socket to path '%s': %lu\n", addr.sun_path, GetLastError()); + closesocket(listener); + listener = socket(AF_UNIX, SOCK_STREAM, 0); + ok(listener != INVALID_SOCKET, "Could not create Unix socket: %lu\n", + GetLastError()); + ret = bind(listener, (SOCKADDR *)&addr, sizeof(SOCKADDR_UN)); + ok(ret && GetLastError() == WSAEADDRINUSE, + "Bound Unix socket to path '%s' despite existing socket file: %lu\n", + addr.sun_path, + GetLastError()); + closesocket(listener); + ret = DeleteFileA(addr.sun_path); + ok(ret, "DeleteFileA on socket file failed: %lu\n", GetLastError()); + ok(GetFileAttributesA("test_afunix.sock") == INVALID_FILE_ATTRIBUTES && + GetLastError() == ERROR_FILE_NOT_FOUND, + "Failed to delete socket file at path '%s'\n", + addr.sun_path); + + /* Test different path types (relative, NT, etc.) */ + GetTempPathA(sizeof(paths[0]) - 1, paths[2]); + strcat(paths[2], "tmp.sock"); + MultiByteToWideChar(CP_ACP, 0, paths[2], -1, dosWidePath, sizeof(dosPath)); + RtlDosPathNameToNtPathName_U(dosWidePath, &ntPath, NULL, NULL); + RtlUnicodeToMultiByteN(paths[3], sizeof(addr.sun_path) - 1, NULL, ntPath.Buffer, ntPath.Length); + + for (int i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) + { + memcpy(addr.sun_path, paths[i], sizeof(paths[i])); + + listener = socket(AF_UNIX, SOCK_STREAM, 0); + ok(listener != INVALID_SOCKET, "Could not create Unix socket: %lu\n", + GetLastError()); + + ret = bind(listener, (SOCKADDR *)&addr, sizeof(SOCKADDR_UN)); + ok(!ret, "Could not bind Unix socket to path '%s': %lu\n", addr.sun_path, GetLastError()); + + ret = listen(listener, 1); + ok(!ret, "Could not listen on Unix socket: %lu\n", GetLastError()); + + client = socket(AF_UNIX, SOCK_STREAM, 0); + ok(client != INVALID_SOCKET, "Failed to create second Unix socket: %lu\n", + GetLastError()); + + clientThread = CreateThread(NULL, 0, test_afunix_client_connect_thread, + &(struct afunix_thread_param){ client, addr }, 0, NULL); + ok(clientThread != NULL, "CreateThread failed unexpectedly: %ld\n", GetLastError()); + server = accept(listener, NULL, NULL); + ok(server != INVALID_SOCKET, "Could not accept Unix socket connection: %lu\n", + GetLastError()); + + ret = WaitForSingleObject(clientThread, 1000); + ok(!ret, "WaitForSingleObject returned 0x%x\n", ret); + ret = CloseHandle(clientThread); + ok(ret, "CloseHandle failed: %ld\n", GetLastError()); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getsockname(listener, (SOCKADDR *)&outAddr, &outAddrSize); + ok(!ret, "Could not get info on Unix socket: %lu\n", GetLastError()); + ok(!memcmp(addr.sun_path, outAddr.sun_path, sizeof(addr.sun_path)), + "getsockname returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr.sun_family) + strlen(outAddr.sun_path), + "getsockname returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getsockname(client, (SOCKADDR *)&outAddr, &outAddrSize); + ok(!ret, "Could not get info on Unix socket: %lu\n", GetLastError()); + ok(!memcmp((char[108]){0}, outAddr.sun_path, sizeof(addr.sun_path)), + "getsockname returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr), + "getsockname returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getsockname(server, (SOCKADDR *)&outAddr, &outAddrSize); + ok(!ret, "Could not get info on Unix socket: %lu\n", GetLastError()); + ok(!memcmp(addr.sun_path, outAddr.sun_path, sizeof(addr.sun_path)), + "getsockname returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr.sun_family) + strlen(outAddr.sun_path), + "getsockname returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getpeername(listener, (SOCKADDR *)&outAddr, &outAddrSize); + ok(ret == -1, "Got info on Unix socket: %lu\n", GetLastError()); + ok(GetLastError() == WSAENOTCONN, + "Incorrect error returned from getpeername on Unix socket: %ld\n", + GetLastError()); + ok(!memcmp((char[108]){0}, outAddr.sun_path, sizeof(addr.sun_path)), + "getpeername returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr), + "getpeername returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getpeername(client, (SOCKADDR *)&outAddr, &outAddrSize); + todo_wine ok(!ret, "Could not get info on Unix socket: %lu\n", GetLastError()); + todo_wine ok(!memcmp(addr.sun_path, outAddr.sun_path, sizeof(addr.sun_path)), + "getpeername returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr), + "getpeername returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + memset(&outAddr, 0, sizeof(outAddr)); + outAddrSize = sizeof(outAddr); + ret = getpeername(server, (SOCKADDR *)&outAddr, &outAddrSize); + todo_wine ok(!ret, "Could not get info on Unix socket: %lu\n", GetLastError()); + ok(!memcmp((char[108]){0}, outAddr.sun_path, sizeof(addr.sun_path)), + "getpeername returned incorrect path '%s' for provided path '%s'\n", + outAddr.sun_path, + addr.sun_path); + ok(outAddrSize == sizeof(outAddr), + "getpeername returned incorrect size '%d' for provided path '%s'\n", + outAddrSize, + addr.sun_path); + + closesocket(listener); + closesocket(client); + closesocket(server); + + ret = DeleteFileA(addr.sun_path); + ok(ret, "DeleteFileA on socket file failed: %lu\n", GetLastError()); + ok(GetFileAttributesA(addr.sun_path) == INVALID_FILE_ATTRIBUTES && + GetLastError() == ERROR_FILE_NOT_FOUND, + "Failed to delete socket file at path '%s'\n", + addr.sun_path); + } +} + START_TEST( sock ) { int i; @@ -13866,6 +14110,7 @@ START_TEST( sock ) test_tcp_reset(); test_icmp(); test_connect_udp(); + test_afunix();
/* this is an io heavy test, do it at the end so the kernel doesn't start dropping packets */ test_send();
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=133891
Your paranoid android.
=== w1064v1809 (32 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w1064_tsign (32 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64 (32 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w11pro64 (32 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w1064v1809 (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w1064_2qxl (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w1064_adm (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w1064_tsign (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64 (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64_en_AE_u8 (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64_ar (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64_ja (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w10pro64_zh_CN (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
=== w11pro64_amd (64 bit report) ===
ws2_32: sock.c:13946: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '13' for provided path './tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '14' for provided path '../tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '48' for provided path 'C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13946: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock' sock.c:13972: Test failed: getsockname returned incorrect size '52' for provided path '??\C:\Users\winetest\AppData\Local\Temp\tmp.sock'
On Sun Jun 18 05:51:58 2023 +0000, Ally Sommers wrote:
changed this line in [version 26 of the diff](/wine/wine/-/merge_requests/2786/diffs?diff_id=52454&start_sha=e31566fea3b2c407aaed0b03de59ff4c7740edd6#5089ae9b8d4674b9fbd6f8fb966009d971ced651_179_179)
Well, it's not really a matter of using any one standards version, but rather supporting whatever compilers people use. I don't remember which compiler chokes on {}, but in practice I think MSVC is the limiting factor.
On Sun Jun 18 03:27:15 2023 +0000, Ally Sommers wrote:
This is still needed because we need to change directories to the Unix path. We can't use the provided Unix path directly because the Unix path length can be larger than the Windows path due to the wineprefix, and that length may exceed `sizeof(sun_path)` even if the Windows path length does not.
Ah right, of course.
On Sun Jun 18 04:54:34 2023 +0000, Ally Sommers wrote:
No; making the client socket nonblocking with `ioctlsocket()` causes it to instantly return with `WSAEWOULDBLOCK`. [Microsoft's documentation](https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-erro...) notes:
It is normal for WSAEWOULDBLOCK to be reported as the result from
calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.
At least for TCP sockets it connects anyway, though. Basically they return WSAEWOULDBLOCK instead of WSAEINPROGRESS for some reason but the behaviour is the same. Is it different for AF_UNIX?
On Sun Jun 18 04:03:01 2023 +0000, Ally Sommers wrote:
Converting the path cannot realistically be done due to size differences for the same path:
$ echo -n 'C:\tmp\foo.sock' | wc -c 15 $ winepath 'C:\tmp\foo.sock' | tr -d '\n' | wc -c 47
For the same reason as needing to change directories to actually bind and connect, path translation in these functions and their server equivalents is not feasible.
It does mean that sockaddr_to_unix() and sockaddr_from_unix() can't be used for AF_UNIX sockets, at least not with their current design. That may mean we should:
- change the function signature (always allocate instead of filling a fixed-size sockaddr union?)
- or handle AF_UNIX specially (like the way this patch set handles bind() and connect() specially)
- or just leave off sockaddr conversion in some functions for now—so mark sendto() and recvfrom() as FIXME cases like getpeername().
On Mon Jun 19 20:38:57 2023 +0000, Zebediah Figura wrote:
It does mean that sockaddr_to_unix() and sockaddr_from_unix() can't be used for AF_UNIX sockets, at least not with their current design. That may mean we should:
- change the function signature (always allocate instead of filling a
fixed-size sockaddr union?)
- or handle AF_UNIX specially (like the way this patch set handles
bind() and connect() specially)
- or just leave off sockaddr conversion in some functions for now—so
mark sendto() and recvfrom() as FIXME cases like getpeername().
Handling AF_UNIX specially, i.e. doing path translation somewhere near the call when necessary (as with `bind()` and `connect()`, seems the simplest, since adding a parameter would require significant refactoring. The only implementation of these functions that's actually called for AF_UNIX sockets is wineserver's, which does not have the path translation function this patch uses (`wine_get_unix_file_name()`, implemented in kernel32).
`sendto()` and `recvfrom()` are not currently special-cased for AF_UNIX sockets, and they work correctly. They flow to the same functions as `send()` and `recv()` respectively, specifically `WS2_sendto()` and `WS2_recv_base()`.
On Mon Jun 19 20:29:39 2023 +0000, Zebediah Figura wrote:
Well, it's not really a matter of using any one standards version, but rather supporting whatever compilers people use. I don't remember which compiler chokes on {}, but in practice I think MSVC is the limiting factor.
Makes sense. I use compound literals in a few test cases; I'll remove those too.
Surprisingly, MSVC does support compound literals, but I would have also guessed MSVC.
On Mon Jun 19 20:32:05 2023 +0000, Zebediah Figura wrote:
At least for TCP sockets it connects anyway, though. Basically they return WSAEWOULDBLOCK instead of WSAEINPROGRESS for some reason but the behaviour is the same. Is it different for AF_UNIX?
Interesting. It does in fact connect despite returning `WSAEWOULDBLOCK`, even for AF_UNIX sockets. I'll remove the thread.