Skip to content

Commit 6dd4311

Browse files
committed
Use Windows GetTempPath instead of /tmp
1 parent f7a8825 commit 6dd4311

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

contrib/win32/win32compat/socketio.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
*/
3030

3131
#include <winsock2.h>
32-
#ifdef HAVE_AFUNIX_H
33-
#include <afunix.h>
34-
#endif
3532
#include <ws2tcpip.h>
3633
#include <mswsock.h>
3734
#include <errno.h>
@@ -41,6 +38,10 @@
4138
#include "inc\utf.h"
4239
#include "misc_internal.h"
4340
#include "debug.h"
41+
#include "../../../config.h"
42+
#ifdef HAVE_AFUNIX_H
43+
#include <afunix.h>
44+
#endif
4445

4546
#define INTERNAL_SEND_BUFFER_SIZE 70*1024 //70KB
4647
#define INTERNAL_RECV_BUFFER_SIZE 70*1024 //70KB

contrib/win32/win32compat/w32fd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <sys\utime.h>
5353
#include "misc_internal.h"
5454
#include "debug.h"
55+
#include "../../../config.h"
5556

5657
/* internal table that stores the fd to w32_io mapping*/
5758
struct w32fd_table {

session.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,26 @@ auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
199199
temporarily_use_uid(pw);
200200

201201
#ifdef WINDOWS
202-
/* Allocate a buffer for the socket name, and format the name. */
203-
auth_sock_dir = xstrdup("C:\\tmp\\ssh-XXXXXXXXXX");
202+
/* Use Windows temporal directory instead of unix `/tmp` folder */
203+
static char tmp_file_path[MAX_PATH];
204+
DWORD tmp_path_len = GetTempPath(MAX_PATH, tmp_file_path);
205+
if (tmp_path_len > MAX_PATH || tmp_file_path == 0) {
206+
error("Agent forwarding disabled: GetTempPath() failed.");
207+
return 0;
208+
}
204209

210+
char* ssh_prefix = xstrdup("ssh-XXXXXXXXXX");
211+
size_t sock_dir_len = tmp_path_len + strlen(ssh_prefix) + 1;
212+
213+
auth_sock_dir = xmalloc(sock_dir_len);
214+
memset(auth_sock_dir, 0, sock_dir_len);
215+
strcat(auth_sock_dir, tmp_file_path);
216+
strcat(auth_sock_dir, ssh_prefix);
205217
#else
206218
/* Allocate a buffer for the socket name, and format the name. */
207219
auth_sock_dir = xstrdup("/tmp/ssh-XXXXXXXXXX");
208220
#endif
209221

210-
211222
/* Create private directory for socket */
212223
if (mkdtemp(auth_sock_dir) == NULL) {
213224
ssh_packet_send_debug(ssh, "Agent forwarding disabled: "

0 commit comments

Comments
 (0)