Skip to content

Commit 6ba1ba5

Browse files
committed
Merge branch 'L2-Win32Posix-Prototype' into L1-Prod
2 parents 8dd7423 + 318a2fb commit 6ba1ba5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+6598
-772
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,5 @@ Makefile.in
276276
#temp key files
277277
d2utmpa*
278278
configure
279-
contrib/win32/openssh/Win32-OpenSSH.VC.opendb
279+
contrib/win32/openssh/Win32-OpenSSH.VC.opendb
280+
*.opendb

auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ auth_openfile(const char *file, struct passwd *pw, int strict_modes,
647647
int fd;
648648
FILE *f;
649649

650-
#ifdef WIN32_FIXME
650+
#if(0)def WIN32_FIXME
651651
if ((fd = WSHELPwopen(file, O_RDONLY|O_NONBLOCK)) == -1) {
652652
#else
653653
if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {

channels.c

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,6 @@
4141

4242
#include "includes.h"
4343

44-
#ifdef WIN32_FIXME
45-
//#define WIN32_PRAGMA_REMCON
46-
#ifdef ECONNABORTED
47-
#undef ECONNABORTED
48-
#endif
49-
#define ECONNABORTED WSAECONNABORTED
50-
#ifdef ECONNREFUSED
51-
#undef ECONNREFUSED
52-
#endif
53-
#define ECONNREFUSED WSAECONNREFUSED
54-
#ifdef EINPROGRESS
55-
#undef EINPROGRESS
56-
#endif
57-
#define EINPROGRESS WSAEINPROGRESS
58-
#define _CRT_NO_POSIX_ERROR_CODES
59-
#endif
60-
6144

6245
#include <sys/types.h>
6346
#include <sys/param.h> /* MIN MAX */
@@ -101,10 +84,10 @@
10184
#include "authfd.h"
10285
#include "pathnames.h"
10386

104-
#ifdef WIN32_FIXME
105-
#define isatty(a) WSHELPisatty(a)
106-
#define SFD_TYPE_CONSOLE 4
107-
#endif
87+
//#ifdef WIN32_FIXME
88+
//#define isatty(a) WSHELPisatty(a)
89+
//#define SFD_TYPE_CONSOLE 4
90+
//#endif
10891

10992

11093
/* -- channel core */
@@ -1700,7 +1683,9 @@ channel_handle_rfd(Channel *c, fd_set *readset, fd_set *writeset)
17001683
len = read(c->rfd, buf, sizeof(buf));
17011684
#ifdef WIN32_FIXME
17021685
if (len == 0) {
1703-
if ( get_sfd_type(c->rfd) == SFD_TYPE_CONSOLE)
1686+
1687+
//if ( get_sfd_type(c->rfd) == SFD_TYPE_CONSOLE)
1688+
if(isatty(c->rfd))
17041689
return 1; // in Win32 console read, there may be no data, but is ok
17051690
}
17061691
#endif
@@ -2239,7 +2224,7 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
22392224
* Winsock can't support this sort of fdset reallocation
22402225
*/
22412226

2242-
#ifndef WIN32_FIXME
2227+
#if(1)//ndef WIN32_FIXME
22432228

22442229
nfdset = howmany(n+1, NFDBITS);
22452230
/* Explicitly test here, because xrealloc isn't always called */
@@ -2257,7 +2242,7 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
22572242

22582243
*maxfdp = n;
22592244

2260-
#ifdef WIN32_FIXME
2245+
#if(0)//def WIN32_FIXME
22612246

22622247
if (*readsetp == NULL)
22632248
{
@@ -2477,52 +2462,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
24772462
if (c->datagram)
24782463
buffer_put_string(&c->output, data, data_len);
24792464
else {
2480-
#ifndef WIN32_FIXME
24812465
buffer_append(&c->output, data, data_len);
2482-
#else
2483-
if ( c->client_tty )
2484-
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
2485-
else {
2486-
#ifdef WIN32_PRAGMA_REMCON
2487-
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
2488-
#else
2489-
if ( ( c->isatty) && (data_len ==1) && (data[0] == '\003') ) {
2490-
/* send control-c to the shell process */
2491-
if ( GenerateConsoleCtrlEvent ( CTRL_C_EVENT, 0 ) ) {
2492-
}
2493-
else {
2494-
debug3("GenerateConsoleCtrlEvent failed with %d\n",GetLastError());
2495-
}
2496-
}
2497-
else {
2498-
// avoid sending the 4 arrow keys out to remote for now "ESC[A" ..
2499-
if ( (c->isatty) && (data_len ==3) && (data[0] == '\033') && (data[1] == '[')) {
2500-
if ( ( data[2] == 'A') || (data[2] == 'B') || (data[2] == 'C') || (data[2] == 'D'))
2501-
packet_check_eom();
2502-
return 0;
2503-
}
2504-
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
2505-
if ( c->isatty ) { // we echo the data if it is sshd server and pty interactive mode
2506-
2507-
if ( (data_len ==1) && (data[0] == '\b') ) {
2508-
if (charinline >0) {
2509-
buffer_append(&c->input, "\b \b", 3); // for backspace, we need to send space and another backspace for visual erase
2510-
charinline--;
2511-
}
2512-
}
2513-
else {
2514-
buffer_append(&c->input, data, data_len);
2515-
charinline += data_len; // one more char on the line
2516-
}
2517-
2518-
if ( (data[data_len-1] == '\r') || (data[data_len-1] == '\n') )
2519-
charinline = 0; // a line has ended, begin char in line count again
2520-
}
2521-
}
2522-
#endif // WIN32_PRAGMA_REMCON
2523-
}
2524-
2525-
#endif
25262466
}
25272467
packet_check_eom();
25282468
return 0;

clientloop.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
#ifdef WIN32_FIXME
119119
#include <sys/stat.h>
120120

121-
#define isatty(a) WSHELPisatty(a)
121+
//#define isatty(a) WSHELPisatty(a)
122122

123123
// Windows Console screen size change related
124124
extern int ScreenX;
@@ -1520,6 +1520,25 @@ client_simple_escape_filter(Channel *c, char *buf, int len)
15201520
buf, len);
15211521
}
15221522

1523+
#ifdef WIN32_FIXME
1524+
u_char * client_ansi_parser_filter(Channel *c, u_char **buf, u_int *len) {
1525+
/* TODO - account fo error/extended stream*/
1526+
if (c->client_tty) {
1527+
telProcessNetwork(buffer_ptr(&c->output), buffer_len(&c->output));
1528+
buffer_clear(&c->output);
1529+
buffer_append(&c->output, " \b", 2);
1530+
*buf = buffer_ptr(&c->output);
1531+
*len = buffer_len(&c->output);
1532+
return *buf;
1533+
}
1534+
else {
1535+
*buf = buffer_ptr(&c->output);
1536+
*len = buffer_len(&c->output);
1537+
return *buf;
1538+
}
1539+
}
1540+
#endif
1541+
15231542
static void
15241543
client_channel_closed(int id, void *arg)
15251544
{
@@ -1606,7 +1625,11 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
16061625
if (session_ident != -1) {
16071626
if (escape_char_arg != SSH_ESCAPECHAR_NONE) {
16081627
channel_register_filter(session_ident,
1628+
#ifdef WIN32_FIXME
1629+
client_simple_escape_filter, client_ansi_parser_filter,
1630+
#else
16091631
client_simple_escape_filter, NULL,
1632+
#endif
16101633
client_filter_cleanup,
16111634
client_new_escape_filter_ctx(
16121635
escape_char_arg));
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.24720.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RedirectedIO", "RedirectedIO\RedirectedIO.vcxproj", "{47CB1D05-8813-415A-BB85-042E09B8A794}"
7+
EndProject
8+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shell-host", "shell-host\shell-host.vcxproj", "{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|x64 = Debug|x64
13+
Debug|x86 = Debug|x86
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Debug|x64.ActiveCfg = Debug|x64
19+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Debug|x64.Build.0 = Debug|x64
20+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Debug|x86.ActiveCfg = Debug|Win32
21+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Debug|x86.Build.0 = Debug|Win32
22+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Release|x64.ActiveCfg = Release|x64
23+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Release|x64.Build.0 = Release|x64
24+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Release|x86.ActiveCfg = Release|Win32
25+
{47CB1D05-8813-415A-BB85-042E09B8A794}.Release|x86.Build.0 = Release|Win32
26+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Debug|x64.ActiveCfg = Debug|x64
27+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Debug|x64.Build.0 = Debug|x64
28+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Debug|x86.ActiveCfg = Debug|Win32
29+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Debug|x86.Build.0 = Debug|Win32
30+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Release|x64.ActiveCfg = Release|x64
31+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Release|x64.Build.0 = Release|x64
32+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Release|x86.ActiveCfg = Release|Win32
33+
{BEFEFB98-000C-4DBB-A9E8-79EFAB305300}.Release|x86.Build.0 = Release|Win32
34+
EndGlobalSection
35+
GlobalSection(SolutionProperties) = preSolution
36+
HideSolutionNode = FALSE
37+
EndGlobalSection
38+
EndGlobal
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// RedirectedIO.cpp : Defines the entry point for the console application.
2+
//
3+
4+
#include <Windows.h>
5+
#include <stdio.h>
6+
7+
int pipe_counter = 0;
8+
HANDLE in[2];
9+
HANDLE out[2];
10+
HANDLE err[2];
11+
12+
DWORD WINAPI OutThreadProc(
13+
_In_ LPVOID lpParameter
14+
)
15+
{
16+
char buf[1024];
17+
DWORD tmp;
18+
BOOL ret = TRUE;
19+
while (ret) {
20+
ret = ReadFile(out[0], buf, 1024, &tmp, NULL);
21+
if (ret) {
22+
ret = WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, tmp, &tmp, NULL);
23+
}
24+
}
25+
26+
printf("----- OUT STREAM CLOSED -------\n");
27+
return ret;
28+
}
29+
30+
DWORD WINAPI ErrThreadProc(
31+
_In_ LPVOID lpParameter
32+
)
33+
{
34+
char buf[1024];
35+
DWORD tmp;
36+
BOOL ret = TRUE;
37+
while (ret) {
38+
ret = ReadFile(err[0], buf, 1024, &tmp, NULL);
39+
if (ret) {
40+
ret = WriteFile(GetStdHandle(STD_ERROR_HANDLE), buf, tmp, &tmp, NULL);
41+
}
42+
}
43+
44+
printf("-------------ERROR STREAM CLOSED -------------\n");
45+
return ret;
46+
}
47+
48+
int
49+
fileio_pipe(HANDLE pio[2]) {
50+
HANDLE read_handle = INVALID_HANDLE_VALUE, write_handle = INVALID_HANDLE_VALUE;
51+
char pipe_name[MAX_PATH];
52+
SECURITY_ATTRIBUTES sec_attributes;
53+
54+
pio[0] = INVALID_HANDLE_VALUE;
55+
pio[1] = INVALID_HANDLE_VALUE;
56+
57+
/* create name for named pipe */
58+
if (-1 == sprintf_s(pipe_name, MAX_PATH, "\\\\.\\Pipe\\W32PosixPipe.%08x.%08x",
59+
GetCurrentProcessId(), pipe_counter++)) {
60+
goto error;
61+
}
62+
63+
sec_attributes.bInheritHandle = TRUE;
64+
sec_attributes.lpSecurityDescriptor = NULL;
65+
sec_attributes.nLength = 0;
66+
67+
/* create named pipe */
68+
read_handle = CreateNamedPipeA(pipe_name,
69+
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
70+
PIPE_TYPE_BYTE | PIPE_WAIT,
71+
1,
72+
4096,
73+
4096,
74+
0,
75+
&sec_attributes);
76+
if (read_handle == INVALID_HANDLE_VALUE) {
77+
goto error;
78+
}
79+
80+
/* connect to named pipe */
81+
write_handle = CreateFileA(pipe_name,
82+
GENERIC_WRITE,
83+
0,
84+
&sec_attributes,
85+
OPEN_EXISTING,
86+
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
87+
NULL);
88+
if (write_handle == INVALID_HANDLE_VALUE) {
89+
goto error;
90+
}
91+
92+
pio[0] = read_handle;
93+
pio[1] = write_handle;
94+
return 0;
95+
96+
error:
97+
if (read_handle != INVALID_HANDLE_VALUE)
98+
CloseHandle(read_handle);
99+
if (write_handle != INVALID_HANDLE_VALUE)
100+
CloseHandle(write_handle);
101+
return -1;
102+
}
103+
104+
105+
int main()
106+
{
107+
108+
STARTUPINFO si;
109+
PROCESS_INFORMATION pi;
110+
DWORD tmp;
111+
BOOL ret;
112+
char buf[1024];
113+
wchar_t cmd[MAX_PATH];
114+
115+
fileio_pipe(in);
116+
fileio_pipe(out);
117+
fileio_pipe(err);
118+
119+
memset(&si, 0, sizeof(STARTUPINFO));
120+
si.cb = sizeof(STARTUPINFO);
121+
si.lpReserved = 0;
122+
si.lpTitle = NULL; /* NULL means use exe name as title */
123+
si.dwFillAttribute = 0;
124+
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW ;
125+
si.wShowWindow = 1; // FALSE ;
126+
si.cbReserved2 = 0;
127+
si.lpReserved2 = 0;
128+
si.hStdInput = in[0];
129+
si.hStdOutput = out[1];
130+
si.hStdError = err[1];
131+
132+
//swprintf(cmd, L"%ls", L"shell-host.exe ping -t 127.0.0.1");
133+
swprintf(cmd, L"%ls", L"shell-host.exe");
134+
SetHandleInformation(in[1], HANDLE_FLAG_INHERIT, 0);
135+
SetHandleInformation(out[0], HANDLE_FLAG_INHERIT, 0);
136+
SetHandleInformation(out[0], HANDLE_FLAG_INHERIT, 0);
137+
138+
139+
ret = CreateProcessW(NULL, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
140+
//ret = CreateProcessW(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
141+
if (!ret)
142+
exit(-1);
143+
144+
/* close unwanted handles*/
145+
CloseHandle(in[0]);
146+
CloseHandle(out[1]);
147+
CloseHandle(err[1]);
148+
149+
DWORD mode;
150+
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
151+
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode & ~( ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT));
152+
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
153+
154+
HANDLE t[2];
155+
t[0] = CreateThread(NULL, 0, OutThreadProc, NULL, 0, NULL);
156+
t[1] = CreateThread(NULL, 0, ErrThreadProc, NULL, 0, NULL);
157+
158+
ret = true;
159+
while (ret) {
160+
ret = ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 1024, &tmp, NULL);
161+
if (ret) {
162+
ret = WriteFile(in[1], buf, tmp, &tmp, NULL);
163+
}
164+
}
165+
}
166+
167+

0 commit comments

Comments
 (0)