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 57dabcc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
8 changes: 7 additions & 1 deletion contrib/win32/win32compat/socketio.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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 @@ -778,6 +778,12 @@ 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_addr4, sizeof(tmp_addr4));
tmp_addr4.sin_family = AF_UNIX;
tmp_addr4.sin_port = 0;
tmp_addr = (SOCKADDR*)&tmp_addr4;
tmp_addr_len = sizeof(tmp_addr4);
} 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 57dabcc

Please sign in to comment.