2 * winproxy.c: Windows implementation of platform_new_connection(),
3 * supporting an OpenSSH-like proxy command via the winhandl.c
10 #define DEFINE_PLUG_METHOD_MACROS
16 Socket make_handle_socket(HANDLE send_H, HANDLE recv_H, Plug plug,
19 Socket platform_new_connection(SockAddr addr, char *hostname,
20 int port, int privport,
21 int oobinline, int nodelay, int keepalive,
22 Plug plug, Conf *conf)
25 HANDLE us_to_cmd, us_from_cmd, cmd_to_us, cmd_from_us;
26 SECURITY_ATTRIBUTES sa;
28 PROCESS_INFORMATION pi;
30 if (conf_get_int(conf, CONF_proxy_type) != PROXY_CMD)
33 cmd = format_telnet_command(addr, port, conf);
35 /* We are responsible for this and don't need it any more */
39 char *msg = dupprintf("Starting local proxy command: %s", cmd);
40 /* We're allowed to pass NULL here, because we're part of the Windows
41 * front end so we know logevent doesn't expect any data. */
47 * Create the pipes to the proxy command, and spawn the proxy
50 sa.nLength = sizeof(sa);
51 sa.lpSecurityDescriptor = NULL; /* default */
52 sa.bInheritHandle = TRUE;
53 if (!CreatePipe(&us_from_cmd, &cmd_to_us, &sa, 0)) {
55 new_error_socket("Unable to create pipes for proxy command", plug);
60 if (!CreatePipe(&cmd_from_us, &us_to_cmd, &sa, 0)) {
62 new_error_socket("Unable to create pipes for proxy command", plug);
64 CloseHandle(us_from_cmd);
65 CloseHandle(cmd_to_us);
69 SetHandleInformation(us_to_cmd, HANDLE_FLAG_INHERIT, 0);
70 SetHandleInformation(us_from_cmd, HANDLE_FLAG_INHERIT, 0);
76 si.dwFlags = STARTF_USESTDHANDLES;
78 si.lpReserved2 = NULL;
79 si.hStdInput = cmd_from_us;
80 si.hStdOutput = cmd_to_us;
82 CreateProcess(NULL, cmd, NULL, NULL, TRUE,
83 CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
84 NULL, NULL, &si, &pi);
85 CloseHandle(pi.hProcess);
86 CloseHandle(pi.hThread);
90 CloseHandle(cmd_from_us);
91 CloseHandle(cmd_to_us);
93 return make_handle_socket(us_to_cmd, us_from_cmd, plug, FALSE);