Skip to content

Commit f7a8825

Browse files
committed
Guard AF_UNIX paths with HAVE_AFUNIX_H
1 parent 3a77587 commit f7a8825

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

contrib/win32/openssh/config.h.vs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,9 @@
15261526
/* Use PIPES instead of a socketpair() */
15271527
#define USE_PIPES 1
15281528

1529+
/* define 1 if afunix.h is available */
1530+
#define HAVE_AFUNIX_H 1
1531+
15291532
/* Define if you want to sanitize fds */
15301533
/* #undef USE_SANITISE_STDFD */
15311534

contrib/win32/win32compat/socketio.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*/
3030

3131
#include <winsock2.h>
32+
#ifdef HAVE_AFUNIX_H
3233
#include <afunix.h>
34+
#endif
3335
#include <ws2tcpip.h>
3436
#include <mswsock.h>
3537
#include <errno.h>
@@ -119,7 +121,12 @@ socketio_acceptEx(struct w32_io* pio)
119121
}
120122

121123
/* create accepting socket */
124+
#ifdef HAVE_AFUNIX_H
122125
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_IP);
126+
#else
127+
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
128+
#endif
129+
123130
if (context->accept_socket == INVALID_SOCKET) {
124131
errno = errno_from_WSALastError();
125132
debug3("acceptEx - socket() ERROR:%d, io:%p", WSAGetLastError(), pio);
@@ -757,7 +764,10 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen)
757764
int
758765
socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
759766
{
767+
#ifdef HAVE_AFUNIX_H
760768
struct sockaddr_un tmp_unix;
769+
#endif
770+
761771
struct sockaddr_in tmp_addr4;
762772
struct sockaddr_in6 tmp_addr6;
763773
SOCKADDR* tmp_addr;
@@ -779,11 +789,13 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
779789
tmp_addr4.sin_port = 0;
780790
tmp_addr = (SOCKADDR*)&tmp_addr4;
781791
tmp_addr_len = sizeof(tmp_addr4);
792+
#ifdef HAVE_AFUNIX_H
782793
} else if (name->sa_family == AF_UNIX) {
783794
ZeroMemory(&tmp_unix, sizeof(tmp_unix));
784795
tmp_unix.sun_family = AF_UNIX;
785796
tmp_addr = (SOCKADDR*)&tmp_unix;
786797
tmp_addr_len = sizeof(tmp_unix);
798+
#endif
787799
} else {
788800
errno = ENOTSUP;
789801
debug3("connectex - ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio);

contrib/win32/win32compat/w32fd.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,25 @@ w32_socket(int domain, int type, int protocol)
298298
errno = 0;
299299
if (min_index == -1)
300300
return -1;
301-
301+
302+
#ifdef HAVE_AFUNIX_H
302303
pio = socketio_socket(domain, type, protocol);
303304
if (pio == NULL)
304305
return -1;
305306
pio->type = SOCK_FD;
306-
307+
#else
308+
if (domain == AF_UNIX && type == SOCK_STREAM) {
309+
pio = fileio_afunix_socket();
310+
if (pio == NULL)
311+
return -1;
312+
pio->type = NONSOCK_FD;
313+
} else {
314+
pio = socketio_socket(domain, type, protocol);
315+
if (pio == NULL)
316+
return -1;
317+
pio->type = SOCK_FD;
318+
}
319+
#endif
307320

308321
fd_table_set(pio, min_index);
309322
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index);

0 commit comments

Comments
 (0)