Skip to content

Commit 3a77587

Browse files
committed
Add support for AF_UNIX
1 parent 33a141f commit 3a77587

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

contrib/win32/win32compat/socketio.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
#include <winsock2.h>
32+
#include <afunix.h>
3233
#include <ws2tcpip.h>
3334
#include <mswsock.h>
3435
#include <errno.h>
@@ -118,7 +119,7 @@ socketio_acceptEx(struct w32_io* pio)
118119
}
119120

120121
/* create accepting socket */
121-
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
122+
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_IP);
122123
if (context->accept_socket == INVALID_SOCKET) {
123124
errno = errno_from_WSALastError();
124125
debug3("acceptEx - socket() ERROR:%d, io:%p", WSAGetLastError(), pio);
@@ -756,7 +757,7 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen)
756757
int
757758
socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
758759
{
759-
760+
struct sockaddr_un tmp_unix;
760761
struct sockaddr_in tmp_addr4;
761762
struct sockaddr_in6 tmp_addr6;
762763
SOCKADDR* tmp_addr;
@@ -778,6 +779,11 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
778779
tmp_addr4.sin_port = 0;
779780
tmp_addr = (SOCKADDR*)&tmp_addr4;
780781
tmp_addr_len = sizeof(tmp_addr4);
782+
} else if (name->sa_family == AF_UNIX) {
783+
ZeroMemory(&tmp_unix, sizeof(tmp_unix));
784+
tmp_unix.sun_family = AF_UNIX;
785+
tmp_addr = (SOCKADDR*)&tmp_unix;
786+
tmp_addr_len = sizeof(tmp_unix);
781787
} else {
782788
errno = ENOTSUP;
783789
debug3("connectex - ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio);

contrib/win32/win32compat/w32fd.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,11 @@ w32_socket(int domain, int type, int protocol)
299299
if (min_index == -1)
300300
return -1;
301301

302-
if (domain == AF_UNIX && type == SOCK_STREAM) {
303-
pio = fileio_afunix_socket();
304-
if (pio == NULL)
305-
return -1;
306-
pio->type = NONSOCK_FD;
307-
} else {
308-
pio = socketio_socket(domain, type, protocol);
309-
if (pio == NULL)
310-
return -1;
311-
pio->type = SOCK_FD;
312-
}
302+
pio = socketio_socket(domain, type, protocol);
303+
if (pio == NULL)
304+
return -1;
305+
pio->type = SOCK_FD;
306+
313307

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

session.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,15 @@ auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
198198
/* Temporarily drop privileged uid for mkdir/bind. */
199199
temporarily_use_uid(pw);
200200

201+
#ifdef WINDOWS
202+
/* Allocate a buffer for the socket name, and format the name. */
203+
auth_sock_dir = xstrdup("C:\\tmp\\ssh-XXXXXXXXXX");
204+
205+
#else
201206
/* Allocate a buffer for the socket name, and format the name. */
202207
auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX");
208+
#endif
209+
203210

204211
/* Create private directory for socket */
205212
if (mkdtemp(auth_sock_dir) == NULL) {
@@ -211,8 +218,13 @@ auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
211218
goto authsock_err;
212219
}
213220

221+
#ifdef WINDOWS
222+
xasprintf(&auth_sock_name, "%s\\agent.%ld",
223+
auth_sock_dir, (long)getpid());
224+
#else
214225
xasprintf(&auth_sock_name, "%s/agent.%ld",
215-
auth_sock_dir, (long) getpid());
226+
auth_sock_dir, (long)getpid());
227+
#endif
216228

217229
/* Start a Unix listener on auth_sock_name. */
218230
sock = unix_listener(auth_sock_name, SSH_LISTEN_BACKLOG, 0);

0 commit comments

Comments
 (0)