Skip to content

Commit

Permalink
Add support for AF_UNIX
Browse files Browse the repository at this point in the history
  • Loading branch information
bilby91 committed Apr 12, 2023
1 parent 33a141f commit 3a77587
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
10 changes: 8 additions & 2 deletions contrib/win32/win32compat/socketio.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

#include <winsock2.h>
#include <afunix.h>
#include <ws2tcpip.h>
#include <mswsock.h>
#include <errno.h>
Expand Down Expand Up @@ -118,7 +119,7 @@ socketio_acceptEx(struct w32_io* pio)
}

/* create accepting socket */
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
context->accept_socket = socket(addr.ss_family, SOCK_STREAM, IPPROTO_IP);
if (context->accept_socket == INVALID_SOCKET) {
errno = errno_from_WSALastError();
debug3("acceptEx - socket() ERROR:%d, io:%p", WSAGetLastError(), pio);
Expand Down Expand Up @@ -756,7 +757,7 @@ socketio_accept(struct w32_io* pio, struct sockaddr* addr, int* addrlen)
int
socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
{

struct sockaddr_un tmp_unix;
struct sockaddr_in tmp_addr4;
struct sockaddr_in6 tmp_addr6;
SOCKADDR* tmp_addr;
Expand All @@ -778,6 +779,11 @@ socketio_connectex(struct w32_io* pio, const struct sockaddr* name, int namelen)
tmp_addr4.sin_port = 0;
tmp_addr = (SOCKADDR*)&tmp_addr4;
tmp_addr_len = sizeof(tmp_addr4);
} else if (name->sa_family == AF_UNIX) {
ZeroMemory(&tmp_unix, sizeof(tmp_unix));
tmp_unix.sun_family = AF_UNIX;
tmp_addr = (SOCKADDR*)&tmp_unix;
tmp_addr_len = sizeof(tmp_unix);
} else {
errno = ENOTSUP;
debug3("connectex - ERROR: unsuppored address family:%d, io:%p", name->sa_family, pio);
Expand Down
16 changes: 5 additions & 11 deletions contrib/win32/win32compat/w32fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,11 @@ w32_socket(int domain, int type, int protocol)
if (min_index == -1)
return -1;

if (domain == AF_UNIX && type == SOCK_STREAM) {
pio = fileio_afunix_socket();
if (pio == NULL)
return -1;
pio->type = NONSOCK_FD;
} else {
pio = socketio_socket(domain, type, protocol);
if (pio == NULL)
return -1;
pio->type = SOCK_FD;
}
pio = socketio_socket(domain, type, protocol);
if (pio == NULL)
return -1;
pio->type = SOCK_FD;


fd_table_set(pio, min_index);
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index);
Expand Down
14 changes: 13 additions & 1 deletion session.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,15 @@ auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
/* Temporarily drop privileged uid for mkdir/bind. */
temporarily_use_uid(pw);

#ifdef WINDOWS
/* Allocate a buffer for the socket name, and format the name. */
auth_sock_dir = xstrdup("C:\\tmp\\ssh-XXXXXXXXXX");

#else
/* Allocate a buffer for the socket name, and format the name. */
auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX");
#endif


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

#ifdef WINDOWS
xasprintf(&auth_sock_name, "%s\\agent.%ld",
auth_sock_dir, (long)getpid());
#else
xasprintf(&auth_sock_name, "%s/agent.%ld",
auth_sock_dir, (long) getpid());
auth_sock_dir, (long)getpid());
#endif

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

0 comments on commit 3a77587

Please sign in to comment.