@@ -2477,7 +2477,7 @@ static int StartSSHD(int argc, char** argv)
24772477#ifdef _WIN32
24782478/* Used to setup a console and run command as a user.
24792479 * returns the process exit value */
2480- static int SetupConsole (char * sysCmd )
2480+ static int SetupConsole (char * inCmd )
24812481{
24822482 HANDLE sOut ;
24832483 HANDLE sIn ;
@@ -2490,8 +2490,9 @@ static int SetupConsole(char* sysCmd)
24902490 PROCESS_INFORMATION processInfo ;
24912491 size_t sz = 0 ;
24922492 DWORD processState = 0 ;
2493+ PCSTR shellCmd = "c:\\windows\\system32\\cmd.exe" ;
24932494
2494- if (sysCmd == NULL ) {
2495+ if (inCmd == NULL ) {
24952496 return -1 ;
24962497 }
24972498
@@ -2500,15 +2501,31 @@ static int SetupConsole(char* sysCmd)
25002501 cord .Y = 24 ;
25012502
25022503 sIn = GetStdHandle (STD_INPUT_HANDLE );
2503- sOut = GetStdHandle (STD_OUTPUT_HANDLE );
2504- if (CreatePseudoConsole (cord , sIn , sOut , 0 , & pCon ) != S_OK ) {
2505- wolfSSH_Log (WS_LOG_ERROR ,
2506- "[SSHD] Issue creating pseudo console" );
2507- ret = WS_FATAL_ERROR ;
2504+
2505+ if (WSTRCMP (shellCmd , inCmd ) != 0 ) {
2506+ /* if not opening a shell, pipe virtual terminal sequences to 'nul' */
2507+ if (CreatePseudoConsole (cord , sIn , INVALID_HANDLE_VALUE , 0 , & pCon ) != S_OK ) {
2508+ wolfSSH_Log (WS_LOG_ERROR ,
2509+ "[SSHD] Issue creating pseudo console" );
2510+ ret = WS_FATAL_ERROR ;
2511+ }
2512+ else {
2513+ CloseHandle (sIn );
2514+ }
25082515 }
2509- else {
2510- CloseHandle (sIn );
2511- CloseHandle (sOut );
2516+ else
2517+ {
2518+ /* if opening a shell, pipe virtual terminal sequences back to calling process */
2519+ sOut = GetStdHandle (STD_OUTPUT_HANDLE );
2520+ if (CreatePseudoConsole (cord , sIn , sOut , 0 , & pCon ) != S_OK ) {
2521+ wolfSSH_Log (WS_LOG_ERROR ,
2522+ "[SSHD] Issue creating pseudo console" );
2523+ ret = WS_FATAL_ERROR ;
2524+ }
2525+ else {
2526+ CloseHandle (sIn );
2527+ CloseHandle (sOut );
2528+ }
25122529 }
25132530
25142531 /* setup startup extended info for pseudo terminal */
@@ -2553,7 +2570,7 @@ static int SetupConsole(char* sysCmd)
25532570 }
25542571
25552572 if (ret == WS_SUCCESS ) {
2556- cmdSz = WSTRLEN (sysCmd ) + 1 ; /* +1 for terminator */
2573+ cmdSz = WSTRLEN (inCmd ) + 1 ; /* +1 for terminator */
25572574 cmd = (PWSTR )HeapAlloc (GetProcessHeap (), 0 , sizeof (wchar_t ) * cmdSz );
25582575 if (cmd == NULL ) {
25592576 ret = WS_MEMORY_E ;
@@ -2562,11 +2579,10 @@ static int SetupConsole(char* sysCmd)
25622579 size_t numConv = 0 ;
25632580
25642581 WMEMSET (cmd , 0 , sizeof (wchar_t ) * cmdSz );
2565- mbstowcs_s (& numConv , cmd , cmdSz , sysCmd , strlen (sysCmd ));
2582+ mbstowcs_s (& numConv , cmd , cmdSz , inCmd , strlen (inCmd ));
25662583 }
25672584 }
25682585
2569-
25702586 ZeroMemory (& processInfo , sizeof (processInfo ));
25712587 if (ret == WS_SUCCESS ) {
25722588 if (CreateProcessW (NULL , cmd ,
0 commit comments