mirror of https://github.com/wolfSSL/wolfssh.git
handling virtual terminal sequences with exec command
parent
4dabe1cb94
commit
25a0414378
|
@ -2477,7 +2477,7 @@ static int StartSSHD(int argc, char** argv)
|
|||
#ifdef _WIN32
|
||||
/* Used to setup a console and run command as a user.
|
||||
* returns the process exit value */
|
||||
static int SetupConsole(char* sysCmd)
|
||||
static int SetupConsole(char* inCmd)
|
||||
{
|
||||
HANDLE sOut;
|
||||
HANDLE sIn;
|
||||
|
@ -2490,8 +2490,9 @@ static int SetupConsole(char* sysCmd)
|
|||
PROCESS_INFORMATION processInfo;
|
||||
size_t sz = 0;
|
||||
DWORD processState = 0;
|
||||
PCSTR shellCmd = "c:\\windows\\system32\\cmd.exe";
|
||||
|
||||
if (sysCmd == NULL) {
|
||||
if (inCmd == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2500,6 +2501,21 @@ static int SetupConsole(char* sysCmd)
|
|||
cord.Y = 24;
|
||||
|
||||
sIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
if (WSTRCMP(shellCmd, inCmd) != 0) {
|
||||
/* if not opening a shell, pipe virtual terminal sequences to 'nul' */
|
||||
if (CreatePseudoConsole(cord, sIn, INVALID_HANDLE_VALUE, 0, &pCon) != S_OK) {
|
||||
wolfSSH_Log(WS_LOG_ERROR,
|
||||
"[SSHD] Issue creating pseudo console");
|
||||
ret = WS_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
CloseHandle(sIn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if opening a shell, pipe virtual terminal sequences back to calling process */
|
||||
sOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (CreatePseudoConsole(cord, sIn, sOut, 0, &pCon) != S_OK) {
|
||||
wolfSSH_Log(WS_LOG_ERROR,
|
||||
|
@ -2510,6 +2526,7 @@ static int SetupConsole(char* sysCmd)
|
|||
CloseHandle(sIn);
|
||||
CloseHandle(sOut);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup startup extended info for pseudo terminal */
|
||||
ZeroMemory(&ext, sizeof(ext));
|
||||
|
@ -2553,7 +2570,7 @@ static int SetupConsole(char* sysCmd)
|
|||
}
|
||||
|
||||
if (ret == WS_SUCCESS) {
|
||||
cmdSz = WSTRLEN(sysCmd) + 1; /* +1 for terminator */
|
||||
cmdSz = WSTRLEN(inCmd) + 1; /* +1 for terminator */
|
||||
cmd = (PWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(wchar_t) * cmdSz);
|
||||
if (cmd == NULL) {
|
||||
ret = WS_MEMORY_E;
|
||||
|
@ -2562,11 +2579,10 @@ static int SetupConsole(char* sysCmd)
|
|||
size_t numConv = 0;
|
||||
|
||||
WMEMSET(cmd, 0, sizeof(wchar_t) * cmdSz);
|
||||
mbstowcs_s(&numConv, cmd, cmdSz, sysCmd, strlen(sysCmd));
|
||||
mbstowcs_s(&numConv, cmd, cmdSz, inCmd, strlen(inCmd));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZeroMemory(&processInfo, sizeof(processInfo));
|
||||
if (ret == WS_SUCCESS) {
|
||||
if (CreateProcessW(NULL, cmd,
|
||||
|
|
Loading…
Reference in New Issue