Bug fixes (#58)
PowerShell/Win32-OpenSSH#458 PowerShell/Win32-OpenSSH#497 a) Deleted the unwanted file (conio.c) b) Added more debug logs to get_passwd() c) Removed ReadThread() in termio.c
This commit is contained in:
parent
9bc3da7fa7
commit
073eadfc98
|
@ -156,7 +156,6 @@
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\no-ops.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\no-ops.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_zlib.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_zlib.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\conio.c" />
|
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\console.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\console.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\no-ops.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\no-ops.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_zlib.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_zlib.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\conio.c" />
|
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\console.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\console.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
|
||||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
|
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
|
||||||
|
|
|
@ -1,183 +0,0 @@
|
||||||
/*
|
|
||||||
* Author: Microsoft Corp.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015 Microsoft Corp.
|
|
||||||
* All rights reserved
|
|
||||||
*
|
|
||||||
* Microsoft openssh win32 port
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
/* conio.c
|
|
||||||
*
|
|
||||||
* Inserts data into Windows Console Input. Needed WriteToConsole() API implemented.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include "console.h"
|
|
||||||
#include <conio.h>
|
|
||||||
|
|
||||||
COORD lastCursorLoc = { 0, 0 };
|
|
||||||
BYTE KeyboardState[256];
|
|
||||||
INPUT_RECORD srec;
|
|
||||||
DWORD dwGlobalConsoleMode ;
|
|
||||||
|
|
||||||
int WriteToConsole(HANDLE fd, unsigned char *buf, size_t len, size_t *dwWritten, void *flag)
|
|
||||||
{
|
|
||||||
static KEY_EVENT_RECORD *pkey;
|
|
||||||
static KEY_EVENT_RECORD *pkey2;
|
|
||||||
static INPUT_RECORD irec[2];
|
|
||||||
static BOOL bInitKeyboard = TRUE;
|
|
||||||
size_t ctr;
|
|
||||||
int rc;
|
|
||||||
DWORD dwRecords;
|
|
||||||
DWORD vkey;
|
|
||||||
BOOL bNeedToWait = TRUE;
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
||||||
|
|
||||||
int scr_width = 80; /* screen horizontal width, e.g. 80 */
|
|
||||||
int scr_height = 25; /* screen vertical length, e.g. 25 */
|
|
||||||
char tmpbuf[2];
|
|
||||||
int local_echo = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Need to set pkey and pkey2 which we use below. Initialize the keyboard state table.
|
|
||||||
*/
|
|
||||||
if (bInitKeyboard)
|
|
||||||
{
|
|
||||||
GetKeyboardState(KeyboardState);
|
|
||||||
bInitKeyboard = FALSE;
|
|
||||||
srec.EventType = KEY_EVENT;
|
|
||||||
srec.Event.KeyEvent.bKeyDown = TRUE;
|
|
||||||
srec.Event.KeyEvent.wRepeatCount = 1;
|
|
||||||
srec.Event.KeyEvent.wVirtualKeyCode = 0x10;
|
|
||||||
srec.Event.KeyEvent.wVirtualScanCode = 0x2a;
|
|
||||||
srec.Event.KeyEvent.uChar.AsciiChar = 0;
|
|
||||||
srec.Event.KeyEvent.uChar.UnicodeChar = 0;
|
|
||||||
srec.Event.KeyEvent.dwControlKeyState = 0x10;
|
|
||||||
|
|
||||||
irec[0].EventType = KEY_EVENT; /* init key down message */
|
|
||||||
pkey = &(irec[0].Event.KeyEvent);
|
|
||||||
pkey->wRepeatCount = 1;
|
|
||||||
pkey->bKeyDown = TRUE;
|
|
||||||
|
|
||||||
irec[1].EventType = KEY_EVENT; /* init key up message */
|
|
||||||
pkey2 = &(irec[1].Event.KeyEvent);
|
|
||||||
pkey2->wRepeatCount = 1;
|
|
||||||
pkey2->bKeyDown = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stream mode processing
|
|
||||||
if (local_echo)
|
|
||||||
{
|
|
||||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
|
||||||
}
|
|
||||||
|
|
||||||
GetConsoleMode(fd, &dwGlobalConsoleMode);
|
|
||||||
|
|
||||||
ctr = 0;
|
|
||||||
while (ctr < len)
|
|
||||||
{
|
|
||||||
if (local_echo)
|
|
||||||
{
|
|
||||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
|
||||||
lastCursorLoc.Y = csbi.dwCursorPosition.Y;
|
|
||||||
lastCursorLoc.X = csbi.dwCursorPosition.X;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
pkey->dwControlKeyState = 0x00000000;
|
|
||||||
pkey->uChar.AsciiChar = buf[ctr]; /* next char in ascii */
|
|
||||||
|
|
||||||
mbtowc(&(pkey->uChar.UnicodeChar), (const char *)&(buf[ctr]), 1);
|
|
||||||
vkey = VkKeyScan(pkey->uChar.AsciiChar);
|
|
||||||
|
|
||||||
if ((BYTE)(vkey >> 8) != 0xFF) // high order word
|
|
||||||
{
|
|
||||||
if (vkey & 0x0100 || (KeyboardState[VK_LSHIFT] & 0x80)) /* high word gives shift, ctrl, alt status */
|
|
||||||
pkey->dwControlKeyState |= SHIFT_PRESSED; /* shift key presssed*/
|
|
||||||
if (vkey & 0x0200 || (KeyboardState[VK_LCONTROL] & 0x80))
|
|
||||||
pkey->dwControlKeyState |= LEFT_CTRL_PRESSED; /* any ctrl really*/
|
|
||||||
if ((vkey & 0x0400) || (KeyboardState[VK_LMENU] & 0x80))
|
|
||||||
pkey->dwControlKeyState |= LEFT_ALT_PRESSED; /* any ALT really*/
|
|
||||||
}
|
|
||||||
if ((BYTE)vkey != 0xFF) // low order word
|
|
||||||
{
|
|
||||||
pkey->wVirtualKeyCode = (BYTE)vkey;
|
|
||||||
pkey->wVirtualScanCode = MapVirtualKey(pkey->wVirtualKeyCode, 0);
|
|
||||||
if (pkey->uChar.UnicodeChar == 0x1b) // stream mode fix for Admark ESC sequences
|
|
||||||
pkey->wVirtualKeyCode = 0x00db;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we need to mimic key up and key down */
|
|
||||||
if (pkey->dwControlKeyState & 0x0100)
|
|
||||||
{
|
|
||||||
srec.Event.KeyEvent.bKeyDown = TRUE;
|
|
||||||
srec.Event.KeyEvent.dwControlKeyState = 0x10;
|
|
||||||
WriteConsoleInput(fd, &srec, 1, &dwRecords); /* write shift down */
|
|
||||||
tmpbuf[0] = irec[0].Event.KeyEvent.uChar.AsciiChar;
|
|
||||||
tmpbuf[1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
pkey->bKeyDown = TRUE; /*since pkey is mucked by others we do it again*/
|
|
||||||
|
|
||||||
/* dup these into key up message structure from key down message */
|
|
||||||
pkey2->wVirtualKeyCode = pkey->wVirtualKeyCode;
|
|
||||||
pkey2->wVirtualScanCode = pkey->wVirtualScanCode;
|
|
||||||
pkey2->uChar.AsciiChar = pkey->uChar.AsciiChar;
|
|
||||||
pkey2->uChar.UnicodeChar = pkey->uChar.UnicodeChar;
|
|
||||||
pkey2->dwControlKeyState = pkey->dwControlKeyState;
|
|
||||||
|
|
||||||
WriteConsoleInput(fd, irec, 2, &dwRecords); /* key down,up msgs */
|
|
||||||
tmpbuf[0] = irec[0].Event.KeyEvent.uChar.AsciiChar;
|
|
||||||
tmpbuf[1] = '\0';
|
|
||||||
if (pkey->dwControlKeyState & 0x0100)
|
|
||||||
{
|
|
||||||
srec.Event.KeyEvent.bKeyDown = FALSE;
|
|
||||||
srec.Event.KeyEvent.dwControlKeyState = 0x0;
|
|
||||||
WriteConsoleInput(fd, &srec, 1, &dwRecords); /* write shift up */
|
|
||||||
|
|
||||||
}
|
|
||||||
//if ((local_echo))
|
|
||||||
//{
|
|
||||||
// bNeedToWait = EchoInputCharacter(buf[ctr], &csbi.dwCursorPosition, dwGlobalConsoleMode);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
ctr++;
|
|
||||||
Sleep(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
*dwWritten = len;
|
|
||||||
|
|
||||||
//netflush();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -118,25 +118,35 @@ get_passwd(const char *user_utf8, LPWSTR user_sid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user_sid == NULL) {
|
if (user_sid == NULL) {
|
||||||
if (NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info) != NERR_Success) {
|
NET_API_STATUS status;
|
||||||
if (DsGetDcNameW(NULL, udom_utf16, NULL, NULL, DS_DIRECTORY_SERVICE_PREFERRED, &pdc) == ERROR_SUCCESS) {
|
if ((status = NetUserGetInfo(udom_utf16, uname_utf16, 23, &user_info)) != NERR_Success) {
|
||||||
if (NetUserGetInfo(pdc->DomainControllerName, uname_utf16, 23, &user_info) != NERR_Success ||
|
debug("NetUserGetInfo() failed with error: %d \n", status);
|
||||||
ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
|
||||||
errno = ENOMEM; //??
|
DWORD dsStatus;
|
||||||
goto done;
|
if ((dsStatus = DsGetDcNameW(NULL, udom_utf16, NULL, NULL, DS_DIRECTORY_SERVICE_PREFERRED, &pdc)) == ERROR_SUCCESS) {
|
||||||
}
|
if ((status = NetUserGetInfo(pdc->DomainControllerName, uname_utf16, 23, &user_info)) != NERR_Success) {
|
||||||
}
|
debug("NetUserGetInfo() with domainController failed with error: %d \n", status);
|
||||||
else {
|
|
||||||
|
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
||||||
|
error("ConvertSidToStringSidW() failed with error: %d\n", GetLastError());
|
||||||
|
|
||||||
|
errno = ENOMEM; //??
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error("DsGetDcNameW() failed with error: %d \n", dsStatus);
|
||||||
errno = ENOMEM; //??
|
errno = ENOMEM; //??
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
if (ConvertSidToStringSidW(((LPUSER_INFO_23)user_info)->usri23_user_sid, &user_sid_local) == FALSE) {
|
||||||
|
error("NetUserGetInfo() Succeded but ConvertSidToStringSidW() failed with error: %d\n", GetLastError());
|
||||||
errno = ENOMEM; //??
|
errno = ENOMEM; //??
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user_sid = user_sid_local;
|
user_sid = user_sid_local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ struct key_translation keys[] = {
|
||||||
{ "\x1b", VK_ESCAPE, "\x1b" },
|
{ "\x1b", VK_ESCAPE, "\x1b" },
|
||||||
{ "\r", VK_RETURN, "\r" },
|
{ "\r", VK_RETURN, "\r" },
|
||||||
{ "\b", VK_BACK, "\b" },
|
{ "\b", VK_BACK, "\b" },
|
||||||
{ "\x7f", VK_BACK, "\x7f" },
|
{ "\x7f", VK_BACK, "\b" },
|
||||||
{ "\t", VK_TAB, "\t" },
|
{ "\t", VK_TAB, "\t" },
|
||||||
{ "\x1b[A", VK_UP, 0 },
|
{ "\x1b[A", VK_UP, 0 },
|
||||||
{ "\x1b[B", VK_DOWN, 0 },
|
{ "\x1b[B", VK_DOWN, 0 },
|
||||||
|
|
|
@ -30,27 +30,6 @@ static VOID CALLBACK ReadAPCProc(
|
||||||
pio->read_overlapped.hEvent = 0;
|
pio->read_overlapped.hEvent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD WINAPI ReadThread(
|
|
||||||
_In_ LPVOID lpParameter
|
|
||||||
) {
|
|
||||||
struct w32_io* pio = (struct w32_io*)lpParameter;
|
|
||||||
debug3("TermRead thread, io:%p", pio);
|
|
||||||
memset(&read_status, 0, sizeof(read_status));
|
|
||||||
if (!ReadFile(WINHANDLE(pio), pio->read_details.buf,
|
|
||||||
pio->read_details.buf_size, &read_status.transferred, NULL)) {
|
|
||||||
read_status.error = GetLastError();
|
|
||||||
debug("TermRead thread - ReadFile failed %d, io:%p", GetLastError(), pio);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
|
|
||||||
debug("TermRead thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio);
|
|
||||||
pio->read_details.pending = FALSE;
|
|
||||||
pio->read_details.error = GetLastError();
|
|
||||||
DebugBreak();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DWORD WINAPI ReadConsoleThread(
|
static DWORD WINAPI ReadConsoleThread(
|
||||||
_In_ LPVOID lpParameter
|
_In_ LPVOID lpParameter
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in New Issue