Skip to content

Commit fe136bc

Browse files
committed
Code fixed for ssh-agent.exe and ssh-add.exe to work in Windows
ssh-agent.exe and ssh-add.exe code updated and fixed to work in Windows. For convenience of users, ssh-agent.exe starts a cmd shell with the "SSH_AUTH_SOCK" and "SSH_AGENT_PID" environment variables set. ssh-add.exe can be run immediately from the cmd shell. 'ssh-add -L" and "ssh-add id_rsa" and "ssh-add -d id_rsa" are 3 useful commands to list, add and delete keys from ssh-agent cache.
1 parent 8f42a2f commit fe136bc

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

authfd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ ssh_get_authentication_socket(int *fdp)
114114
errno = oerrno;
115115
return SSH_ERR_SYSTEM_ERROR;
116116
}
117+
#else
118+
if (
119+
connect(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) {
120+
oerrno = errno;
121+
close(sock);
122+
errno = oerrno;
123+
return SSH_ERR_SYSTEM_ERROR;
124+
}
117125
#endif /* #ifndef WIN32_FIXME */
118126

119127
if (fdp != NULL)

contrib/win32/win32compat/socket.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,9 +2013,10 @@ int cleanSelectThread(int thread_no)
20132013

20142014
if(thread_data_set[thread_no] != NULL)
20152015
{
2016-
HeapFree(GetProcessHeap(), 0, thread_data_set[thread_no]);
2017-
2018-
thread_data_set[thread_no] = NULL;
2016+
thread_data_p ap = thread_data_set[thread_no];
2017+
thread_data_set[thread_no] = NULL;
2018+
HeapFree(GetProcessHeap(), 0, ap);
2019+
20192020
}
20202021

20212022
DBG_MSG("<- cleanSelectThread()...\n");

ssh-add.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ main(int argc, char **argv)
520520
fprintf(stderr, "Could not open a connection to your "
521521
"authentication agent.\n");
522522
exit(2);
523+
#ifdef WIN32_FIXME
524+
case SSH_ERR_SYSTEM_ERROR:
525+
fprintf(stderr, "Error connecting to agent: ssh-agent.exe may not be running\n");
526+
exit(2);
527+
#endif
523528
default:
524529
fprintf(stderr, "Error connecting to agent: %s\n", ssh_err(r));
525530
exit(2);

ssh-agent.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,9 @@ main(int ac, char **av)
17341734
cleanup_exit(1);
17351735
}
17361736
if (pid != 0) { /* Parent - execute the given command. */
1737+
#ifndef WIN32_FIXME
17371738
close(sock);
1739+
#endif
17381740
snprintf(pidstrbuf, sizeof pidstrbuf, "%ld", (long)pid);
17391741
if (ac == 0) {
17401742
#ifdef WIN32_FIXME
@@ -1748,6 +1750,11 @@ main(int ac, char **av)
17481750
printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf,
17491751
SSH_AGENTPID_ENV_NAME);
17501752
printf("echo Agent pid %ld;\n", (long)pid);
1753+
#ifdef WIN32_FIXME
1754+
SetEnvironmentVariable(SSH_AUTHSOCKET_ENV_NAME, socket_name);
1755+
SetEnvironmentVariable(SSH_AGENTPID_ENV_NAME, pidstrbuf);
1756+
system("start cmd");
1757+
#endif
17511758
exit(0);
17521759
}
17531760
if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 ||

0 commit comments

Comments
 (0)