Merge branch 'L1' into L2-Win32Posix-Prototype
This commit is contained in:
commit
10acae4a83
|
@ -91,7 +91,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
|
|||
sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o blocks.o \
|
||||
kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \
|
||||
kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
|
||||
kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o
|
||||
kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o openssl-dh.o openssl-bn.o
|
||||
|
||||
SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
|
||||
sshconnect.o sshconnect1.o sshconnect2.o mux.o \
|
||||
|
|
|
@ -8,3 +8,6 @@ See the [wiki](https://github.com/PowerShell/Win32-OpenSSH/wiki) for installatio
|
|||
[First release announcement](http://blogs.msdn.com/b/powershell/archive/2015/10/19/openssh-for-windows-update.aspx
|
||||
)
|
||||
|
||||
### Chocolatey
|
||||
|
||||
[](https://chocolatey.org/packages/win32-openssh) [](https://chocolatey.org/packages/win32-openssh)
|
||||
|
|
|
@ -223,8 +223,65 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
|
|||
/*
|
||||
* Identify domain or local login.
|
||||
*/
|
||||
|
||||
domain_UTF16 = strchr(authctxt -> user, '@') ? NULL : L".";
|
||||
|
||||
char *username = authctxt->user;
|
||||
|
||||
char *domainslash = strchr(authctxt->user, '\\');
|
||||
if (domainslash) {
|
||||
// domain\username format
|
||||
char *domainname = authctxt->user;
|
||||
*domainslash = '\0';
|
||||
username = ++domainslash; // username is past the domain \ is the username
|
||||
|
||||
// Convert domainname from UTF-8 to UTF-16
|
||||
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
|
||||
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
domain_UTF16 = xmalloc(4 * buffer_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
|
||||
-1, domain_UTF16, buffer_size))
|
||||
{
|
||||
free(domain_UTF16);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (domainslash = strchr(authctxt->user, '@')) {
|
||||
// username@domain format
|
||||
username = authctxt->user;
|
||||
*domainslash = '\0';
|
||||
char *domainname = ++domainslash; // domainname is past the user@
|
||||
|
||||
// Convert domainname from UTF-8 to UTF-16
|
||||
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
|
||||
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
domain_UTF16 = xmalloc(4 * buffer_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
|
||||
-1, domain_UTF16, buffer_size))
|
||||
{
|
||||
free(domain_UTF16);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
domain_UTF16 = strchr(authctxt->user, '@') ? NULL : L".";
|
||||
}
|
||||
|
||||
authctxt -> methoddata = hToken;
|
||||
|
||||
|
@ -237,7 +294,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
|
|||
* Convert username from UTF-8 to UTF-16
|
||||
*/
|
||||
|
||||
buffer_size = MultiByteToWideChar(CP_UTF8, 0, authctxt -> user, -1, NULL, 0);
|
||||
buffer_size = MultiByteToWideChar(CP_UTF8, 0, username, -1, NULL, 0);
|
||||
|
||||
if (buffer_size > 0)
|
||||
{
|
||||
|
@ -248,7 +305,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (0 == MultiByteToWideChar(CP_UTF8, 0, authctxt -> user,
|
||||
if (0 == MultiByteToWideChar(CP_UTF8, 0, username,
|
||||
-1, user_UTF16, buffer_size))
|
||||
{
|
||||
free(user_UTF16);
|
||||
|
@ -296,7 +353,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
|
|||
HANDLE weakToken = INVALID_HANDLE_VALUE;
|
||||
|
||||
debug3("Netork login attemp [%s][%ls]...",
|
||||
authctxt -> user, domain_UTF16);
|
||||
username, domain_UTF16);
|
||||
|
||||
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
|
||||
LOGON32_LOGON_NETWORK,
|
||||
|
@ -314,6 +371,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
|
|||
|
||||
free(user_UTF16);
|
||||
free(password_UTF16);
|
||||
if (domainslash) free(domain_UTF16);
|
||||
|
||||
/*
|
||||
* If login still fails, go out.
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "includes.h"
|
||||
|
||||
#ifdef WIN32_FIXME
|
||||
//#define WIN32_PRAGMA_REMCON
|
||||
#ifdef ECONNABORTED
|
||||
#undef ECONNABORTED
|
||||
#endif
|
||||
|
@ -2482,6 +2483,9 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
|
|||
if ( c->client_tty )
|
||||
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
|
||||
else {
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
|
||||
#else
|
||||
if ( ( c->isatty) && (data_len ==1) && (data[0] == '\003') ) {
|
||||
/* send control-c to the shell process */
|
||||
if ( GenerateConsoleCtrlEvent ( CTRL_C_EVENT, 0 ) ) {
|
||||
|
@ -2492,7 +2496,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
|
|||
}
|
||||
else {
|
||||
// avoid sending the 4 arrow keys out to remote for now "ESC[A" ..
|
||||
if ( (c->isatty) && (data_len ==3) && (data[0] == '\033') && (data[1] == '[')) {
|
||||
if ( (c->isatty) && (data_len ==3) && (data[0] == '\033') && (data[1] == '[')) {
|
||||
if ( ( data[2] == 'A') || (data[2] == 'B') || (data[2] == 'C') || (data[2] == 'D'))
|
||||
packet_check_eom();
|
||||
return 0;
|
||||
|
@ -2515,6 +2519,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
|
|||
charinline = 0; // a line has ended, begin char in line count again
|
||||
}
|
||||
}
|
||||
#endif // WIN32_PRAGMA_REMCON
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
Set-StrictMode -Version Latest
|
||||
$Win32Macro = 'WIN32_FIXME'
|
||||
$sourceRoot = 'C:\openssh\Win32-OpenSSH'
|
||||
|
||||
[int]$g_code = 0
|
||||
[int]$g_win32 = 0
|
||||
[int]$g_unix = 0
|
||||
|
||||
function AnalyzeFile($file, [bool]$log)
|
||||
{
|
||||
$file = Join-Path $sourceRoot $file
|
||||
if ($log) { Write-Host -ForegroundColor Gray $file }
|
||||
$content = Get-Content $file
|
||||
[int]$commentlines = 0 #comments
|
||||
[int]$emptylines = 0 #emptylines
|
||||
[int]$code = 0 #all code lines
|
||||
[int]$win32 = 0 #win32 only lines
|
||||
[int]$win32substituted = 0#lines in win32 block that have a corresponding Unix block (#ifdef with #else)
|
||||
[int]$unix = 0; #unix only lines
|
||||
[int]$unixsubstituted = 0 #lines in unix block that have a corresponding Win32 block (#ifdef with #else)
|
||||
[int]$total = 0
|
||||
[int]$nestedmacros = 0 #tracks nested macro blocks inside a win32 or a unix block
|
||||
[bool]$incommentblock = $false
|
||||
[bool]$inWin32block = $false
|
||||
[bool]$inUnixblock = $false
|
||||
[int]$currentblockcode = 0
|
||||
[bool]$insubstitutedblock = $false
|
||||
|
||||
|
||||
foreach ($linestr in $content)
|
||||
{
|
||||
$total++
|
||||
$line = [String]$linestr
|
||||
$line = $line.Trim()
|
||||
#skip if line is empty
|
||||
if ($line.Length -gt 0)
|
||||
{
|
||||
if ($incommentblock)
|
||||
{
|
||||
$commentlines++
|
||||
if ($line.EndsWith('*/')) {$incommentblock = $false}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($line.StartsWith('//')) {$commentlines++}
|
||||
elseif ($line.StartsWith('/*'))
|
||||
{
|
||||
if (!($line.EndsWith('*/'))) { $incommentblock = $true }
|
||||
$commentlines++
|
||||
}
|
||||
else
|
||||
{
|
||||
$code++
|
||||
if ($inWin32block)
|
||||
{
|
||||
$win32++
|
||||
$currentblockcode++
|
||||
#keep skipping inner #ifdefs
|
||||
if ($line.StartsWith('#ifdef')) {$nestedmacros++}
|
||||
|
||||
if ($line.EndsWith('#endif') -or $line.EndsWith('#else'))
|
||||
{
|
||||
if ($nestedmacros -eq 0)
|
||||
{
|
||||
$inWin32block = $false
|
||||
if ($line.EndsWith('#else'))
|
||||
{
|
||||
$inUnixblock = $true
|
||||
$insubstitutedblock = $true
|
||||
$win32substituted += $currentblockcode
|
||||
}
|
||||
elseif ($insubstitutedblock)
|
||||
{
|
||||
$win32substituted += $currentblockcode
|
||||
$insubstitutedblock = $false
|
||||
}
|
||||
$currentblockcode = 0
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($line.EndsWith('#endif')) {$nestedmacros--}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($inUnixblock)
|
||||
{
|
||||
$unix++
|
||||
$currentblockcode++
|
||||
#keep skipping inner #ifdefs
|
||||
if ($line.StartsWith('#ifdef')) {$nestedmacros++}
|
||||
|
||||
if ($line.EndsWith('#endif') -or $line.EndsWith('#else'))
|
||||
{
|
||||
if ($nestedmacros -eq 0)
|
||||
{
|
||||
$inUnixblock = $false
|
||||
if ($line.EndsWith('#else'))
|
||||
{
|
||||
$inWin32block = $true
|
||||
$insubstitutedblock = $true
|
||||
$unixsubstituted += $currentblockcode
|
||||
}
|
||||
elseif ($insubstitutedblock)
|
||||
{
|
||||
$unixsubstituted += $currentblockcode
|
||||
$insubstitutedblock = $false
|
||||
}
|
||||
|
||||
$currentblockcode = 0
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($line.EndsWith('#endif')) {$nestedmacros--}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($line.StartsWith('#ifdef') -and $line.Contains($Win32Macro))
|
||||
{
|
||||
$inWin32block = $true
|
||||
$currentblockcode = 0
|
||||
}
|
||||
if ($line.StartsWith('#ifndef') -and $line.Contains($Win32Macro))
|
||||
{
|
||||
$inUnixblock = $true
|
||||
$currentblockcode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {$emptylines++}
|
||||
}
|
||||
|
||||
if ($log)
|
||||
{
|
||||
Write-Host -ForegroundColor Yellow " Comments " $commentlines
|
||||
Write-Host -ForegroundColor Green " Blank " $emptylines
|
||||
Write-Host -ForegroundColor Cyan " Code " $code
|
||||
Write-Host -ForegroundColor DarkMagenta " Total " $total " check("($commentlines+$emptylines+$code)")"
|
||||
Write-Host -ForegroundColor Cyan " Win32 " $win32
|
||||
Write-Host -ForegroundColor Cyan " Unix " $unix
|
||||
Write-Host -ForegroundColor Cyan " Win32sub " $win32substituted
|
||||
Write-Host -ForegroundColor Cyan " Unixsub " $unixsubstituted
|
||||
}
|
||||
|
||||
$global:g_code += $code
|
||||
$global:g_win32 += $win32
|
||||
$global:g_unix += $unix
|
||||
|
||||
}
|
||||
|
||||
|
||||
function AnalyzeProject($project, [bool]$log)
|
||||
{
|
||||
if ($log) { Write-Host "Project: " $project}
|
||||
$projectName = $project
|
||||
$projectroot = Join-Path $sourceRoot 'contrib\win32\openssh'
|
||||
$project = Join-Path $projectroot $project
|
||||
$project = $project + '.vcxproj'
|
||||
|
||||
$global:g_code = 0
|
||||
$global:g_win32 = 0
|
||||
$global:g_unix = 0
|
||||
|
||||
$c = Get-Content $project
|
||||
foreach ($ln in $c){
|
||||
$l = [String]$ln
|
||||
$l = $l.Trim()
|
||||
|
||||
if ($l.StartsWith('<ClCompile Include="$(OpenSSH-Src-Path)'))
|
||||
{
|
||||
$l = $l.Replace('<ClCompile Include="$(OpenSSH-Src-Path)','')
|
||||
$l = $l.Substring(0, $l.IndexOf('"'))
|
||||
AnalyzeFile $l $log
|
||||
}
|
||||
}
|
||||
|
||||
if ($log)
|
||||
{
|
||||
Write-Host " Total Code " $global:g_code
|
||||
Write-Host " Win32 Code " $global:g_win32
|
||||
Write-Host " Unix Code " $global:g_unix
|
||||
}
|
||||
|
||||
Write-Host $projectName " " (100 - ($global:g_unix*100/($global:g_code - $global:g_win32))) "%"
|
||||
|
||||
}
|
||||
|
||||
|
||||
AnalyzeProject libssh
|
||||
AnalyzeProject scp
|
||||
AnalyzeProject sftp
|
||||
AnalyzeProject sftp-server
|
||||
AnalyzeProject ssh
|
||||
AnalyzeProject ssh-add
|
||||
AnalyzeProject ssh-agent
|
||||
AnalyzeProject sshd
|
|
@ -0,0 +1,45 @@
|
|||
set OPENSSL_VERSION=1.0.2d
|
||||
set PerlPath=c:\perl\bin
|
||||
set NASMPath=c:\nasm
|
||||
|
||||
set VS2013="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
|
||||
set VS2013_AMD64="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat"
|
||||
set VS2015="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"
|
||||
set VS2015_AMD64="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
|
||||
|
||||
set path=%NASMPath%;%PerlPath%;%path%
|
||||
|
||||
|
||||
CALL %VS2015%
|
||||
|
||||
cd \Dev\OpenSSL\openssl-%OPENSSL_VERSION%-src-x86
|
||||
perl Configure VC-WIN32 --prefix=C:\dev\OpenSSL\%OPENSSL_VERSION%\VS2015\Win32\Release
|
||||
call ms\do_ms.bat
|
||||
call ms\do_nasm.bat
|
||||
nmake -f ms\nt.mak clean
|
||||
nmake -f ms\nt.mak
|
||||
nmake -f ms\nt.mak install
|
||||
|
||||
cd \Dev\OpenSSL\openssl-%OPENSSL_VERSION%-src-x86
|
||||
perl Configure debug-VC-WIN32 --prefix=C:\dev\OpenSSL\%OPENSSL_VERSION%\VS2015\Win32\Debug
|
||||
call ms\do_ms.bat
|
||||
call ms\do_nasm.bat
|
||||
nmake -f ms\nt.mak clean
|
||||
nmake -f ms\nt.mak
|
||||
nmake -f ms\nt.mak install
|
||||
|
||||
CALL %VS2015_AMD64%
|
||||
|
||||
cd \Dev\OpenSSL\openssl-%OPENSSL_VERSION%-src-x64
|
||||
perl Configure VC-WIN64A --prefix=C:\dev\OpenSSL\%OPENSSL_VERSION%\VS2015\x64\Release
|
||||
call ms\do_win64a.bat
|
||||
nmake -f ms\nt.mak clean
|
||||
nmake -f ms\nt.mak
|
||||
nmake -f ms\nt.mak install
|
||||
|
||||
cd \Dev\OpenSSL\openssl-%OPENSSL_VERSION%-src-x64
|
||||
perl Configure debug-VC-WIN64A --prefix=C:\dev\OpenSSL\%OPENSSL_VERSION%\VS2015\x64\Debug
|
||||
call ms\do_win64a.bat
|
||||
nmake -f ms\nt.mak clean
|
||||
nmake -f ms\nt.mak
|
||||
nmake -f ms\nt.mak install
|
|
@ -1707,5 +1707,7 @@ struct iovec
|
|||
|
||||
// define building with MS Visual Studio Compiler and runtime and not with MingW/gcc compiler
|
||||
#define WIN32_VS 1
|
||||
|
||||
// Use Pragma Systems Remote Console modules for shell sessions so that cmd/powershell fully
|
||||
// works remotely over SSH like they operate in a local machine
|
||||
//#define WIN32_PRAGMA_REMCON
|
||||
|
||||
|
|
|
@ -262,6 +262,7 @@
|
|||
<ClCompile Include="$(OpenSSH-Src-Path)openssl-dh.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\openssl-epoint.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)crypto-wrap.h" />
|
||||
|
|
|
@ -288,15 +288,18 @@
|
|||
<ClCompile Include="$(OpenSSH-Src-Path)xmalloc.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\openssl-dh.c">
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openssl-bn.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\openssl-bn.c">
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openssl-dh.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\openssl-epoint.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\crypto-wrap.h">
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)crypto-wrap.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -129,6 +129,7 @@ int GetDomainFromToken ( HANDLE *hAccessToken, UCHAR *domain, DWORD dwSize)
|
|||
char *GetHomeDirFromToken(char *userName, HANDLE token)
|
||||
{
|
||||
UCHAR domain[200];
|
||||
wchar_t pw_buf[MAX_PATH] = { L'\0' };
|
||||
|
||||
debug("-> GetHomeDirFromToken()...");
|
||||
|
||||
|
@ -172,7 +173,19 @@ char *GetHomeDirFromToken(char *userName, HANDLE token)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// update APPDATA user's env variable
|
||||
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, token, 0, pw_buf)))
|
||||
{
|
||||
SetEnvironmentVariableW(L"APPDATA", pw_buf);
|
||||
}
|
||||
|
||||
// update LOCALAPPDATA user's env variable
|
||||
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, token, 0, pw_buf)))
|
||||
{
|
||||
SetEnvironmentVariableW(L"LOCALAPPDATA", pw_buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unload user profile.
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,10 @@ struct sshdh;
|
|||
struct sshbn;
|
||||
struct sshbuf;
|
||||
struct ssh;
|
||||
struct sshedh;
|
||||
struct sshepoint;
|
||||
struct sshecurve;
|
||||
|
||||
|
||||
struct sshdh *sshdh_new(void);
|
||||
void sshdh_free(struct sshdh *dh);
|
||||
|
@ -21,6 +25,27 @@ int sshdh_new_group_hex(const char *gen, const char *modulus,
|
|||
struct sshdh **dhp);
|
||||
struct sshdh *sshdh_new_group(struct sshbn *gen, struct sshbn *modulus);
|
||||
|
||||
struct sshedh *sshedh_new(void);
|
||||
void sshedh_free(struct sshdh *dh);
|
||||
struct sshepoint *sshedh_pubkey(struct sshedh *dh);
|
||||
void sshedh_dump(struct sshedh *dh);
|
||||
size_t sshedh_shared_key_size(struct sshedh *dh);
|
||||
int sshedh_compute_key(struct sshedh *dh, struct sshepoint *pubkey,
|
||||
struct sshbn **shared_secretp);
|
||||
int sshedh_generate(struct sshedh *dh, size_t len);
|
||||
struct sshedh *sshedh_new_curve(int nid);
|
||||
|
||||
struct sshepoint * sshepoint_new(void);
|
||||
int sshepoint_from(struct sshbn * x, struct sshbn * y, struct sshecurve * sshecurve, struct sshepoint **retp);
|
||||
int sshepoint_to(struct sshepoint * pt, struct sshbn **retx, struct sshbn **rety, struct sshecurve ** retcurve);
|
||||
void sshepoint_free(struct sshepoint * pt);
|
||||
|
||||
struct sshecurve * sshecurve_new(void);
|
||||
void sshecurve_free(struct sshecurve * curve);
|
||||
struct sshecurve * sshecurve_new_curve(int nid);
|
||||
|
||||
|
||||
|
||||
struct sshbn *sshbn_new(void);
|
||||
void sshbn_free(struct sshbn *bn);
|
||||
int sshbn_from(const void *d, size_t l, struct sshbn **retp);
|
||||
|
|
1
kex.h
1
kex.h
|
@ -29,6 +29,7 @@
|
|||
#include "mac.h"
|
||||
#include "buffer.h" /* XXX for typedef */
|
||||
#include "key.h" /* XXX for typedef */
|
||||
#include "crypto-wrap.h"
|
||||
|
||||
#ifdef WITH_LEAKMALLOC
|
||||
#include "leakmalloc.h"
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Damien Miller <djm@mindrot.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <includes.h>
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ec.h>
|
||||
|
||||
|
||||
#include "sshbuf.h"
|
||||
#include "packet.h"
|
||||
#include "ssherr.h"
|
||||
#include "crypto-wrap.h"
|
||||
|
||||
struct sshepoint {
|
||||
EC_POINT *pt;
|
||||
EC_GROUP *gp;
|
||||
};
|
||||
|
||||
struct sshecurve {
|
||||
EC_GROUP *gp;
|
||||
};
|
||||
|
||||
|
||||
struct sshepoint *
|
||||
sshepoint_new(void)
|
||||
{
|
||||
return malloc(sizeof(struct sshepoint));
|
||||
}
|
||||
|
||||
void
|
||||
sshepoint_free(struct sshepoint *pt)
|
||||
{
|
||||
if (pt != NULL) {
|
||||
if (pt->pt != NULL)
|
||||
EC_POINT_free(pt->pt);
|
||||
if (pt->gp != NULL)
|
||||
EC_GROUP_free(pt->gp);
|
||||
explicit_bzero(pt, sizeof(*pt));
|
||||
free(pt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int sshepoint_from(struct sshbn * x, struct sshbn * y, struct sshecurve * curve, struct sshepoint **retp)
|
||||
{
|
||||
struct sshepoint *ret = NULL;
|
||||
|
||||
|
||||
*retp = NULL;
|
||||
if ((ret = sshepoint_new()) == NULL)
|
||||
{
|
||||
return SSH_ERR_ALLOC_FAIL;
|
||||
}
|
||||
if ((ret->pt = EC_POINT_new(curve->gp)) == NULL)
|
||||
{
|
||||
sshepoint_free(ret);
|
||||
return SSH_ERR_LIBCRYPTO_ERROR;
|
||||
}
|
||||
ret->gp = curve->gp;
|
||||
if (EC_POINT_set_affine_corrdinates_GFp(curve->gp, ret->pt, x, y)) {
|
||||
sshepoint_free(ret);
|
||||
return SSH_ERR_LIBCRYPTO_ERROR;
|
||||
}
|
||||
*retp = ret;
|
||||
return 0;
|
||||
}
|
||||
int sshepoint_to(struct sshepoint * pt, struct sshbn **retx, struct sshbn **rety, struct sshecurve ** retcurve)
|
||||
{
|
||||
struct sshbn * x = NULL;
|
||||
struct sshbn * y = NULL;
|
||||
struct sshecurve * curve = NULL;
|
||||
|
||||
if (((x = sshbn_new()) == NULL) ||
|
||||
((y = sshbn_new()) == NULL) ||
|
||||
((curve = sshecurve_new()) == NULL))
|
||||
{
|
||||
sshbn_free(x);
|
||||
sshbn_free(y);
|
||||
sshecurve_free(curve);
|
||||
return SSH_ERR_ALLOC_FAIL;
|
||||
}
|
||||
|
||||
curve->gp = pt->gp;
|
||||
if (EC_POINT_get_affine_coordinates_GFp(pt->gp, pt->pt, sshbn_bignum(x), sshbn_bignum(y), NULL))
|
||||
{
|
||||
sshecurve_free(curve);
|
||||
sshbn_free(x);
|
||||
sshbn_free(y);
|
||||
return SSH_ERR_LIBCRYPTO_ERROR;
|
||||
}
|
||||
*retcurve = curve;
|
||||
*retx = x;
|
||||
*rety = y;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sshecurve * sshecurve_new(void)
|
||||
{
|
||||
struct sshecurve * curve = NULL;
|
||||
|
||||
curve = (struct sshecurve *)malloc(sizeof(struct sshecurve));
|
||||
memset(curve, 0, sizeof(struct sshecurve));
|
||||
|
||||
return curve;
|
||||
}
|
||||
|
||||
void sshecurve_free(struct sshecurve * curve)
|
||||
{
|
||||
if (curve != NULL) {
|
||||
if (curve->gp != NULL)
|
||||
EC_GROUP_free(curve->gp);
|
||||
explicit_bzero(curve, sizeof(*curve));
|
||||
free(curve);
|
||||
}
|
||||
}
|
||||
|
||||
struct sshecurve * sshecurve_new_curve(int nid)
|
||||
{
|
||||
struct sshecurve * ret;
|
||||
|
||||
if ((ret = sshecurve_new()) == NULL)
|
||||
return NULL;
|
||||
ret->gp = EC_GROUP_new_by_curve_name(nid);
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
|
@ -43,8 +43,8 @@
|
|||
# define _PATH_HOST_ECDSA_KEY_FILE "ssh_host_ecdsa_key"
|
||||
# define _PATH_HOST_ED25519_KEY_FILE "ssh_host_ed25519_key"
|
||||
# define _PATH_HOST_RSA_KEY_FILE "ssh_host_rsa_key"
|
||||
# define _PATH_DH_MODULI "/moduli"
|
||||
# define _PATH_DH_PRIMES "/primes"
|
||||
# define _PATH_DH_MODULI "moduli"
|
||||
# define _PATH_DH_PRIMES "primes"
|
||||
# define _PATH_SSH_PROGRAM "ssh.exe"
|
||||
|
||||
#else
|
||||
|
|
102
session.c
102
session.c
|
@ -42,6 +42,7 @@
|
|||
#undef GSSAPI
|
||||
#undef KRB5
|
||||
#define WIN32_USER_AUTH 1
|
||||
//#define WIN32_PRAGMA_REMCON
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -116,6 +117,9 @@ FIXME: GFPZR: Function stat() may be undeclared.
|
|||
#include <Userenv.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
#include <shlwapi.h>
|
||||
#endif
|
||||
extern char HomeDirLsaW[MAX_PATH];
|
||||
|
||||
#endif
|
||||
|
@ -589,11 +593,28 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
char buf[256];
|
||||
int prot_scr_width = 80;
|
||||
int prot_scr_height = 25;
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
char exec_command_str[512];
|
||||
#endif
|
||||
|
||||
if (!command)
|
||||
{
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
exec_command = s->pw->pw_shell;
|
||||
//exec_command = "c:\\tools\\echoit.exe"; // temp
|
||||
#else
|
||||
if ( PathFileExists("\\program files\\pragma\\shared files\\cmdserver.exe") )
|
||||
snprintf(exec_command_str, sizeof(exec_command_str),
|
||||
"\\program files\\pragma\\shared files\\cmdserver.exe SSHD %d %d", s->row, s->col );
|
||||
else {
|
||||
// find base path of our executable
|
||||
char basepath[MAX_PATH];
|
||||
strcpy_s(basepath, MAX_PATH, __progname);
|
||||
PathRemoveFileSpec(basepath); // get the full dir part of the name
|
||||
snprintf(exec_command_str, sizeof(exec_command_str),
|
||||
"%s\\cmdserver.exe SSHD %d %d", basepath,s->row, s->col);
|
||||
}
|
||||
exec_command = exec_command_str;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -606,28 +627,42 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
* Create three socket pairs for stdin, stdout and stderr
|
||||
*/
|
||||
|
||||
HANDLE wfdtocmd = -1;
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
|
||||
int retcode = -1;
|
||||
if ( (!s -> is_subsystem) && (s ->ttyfd != -1))
|
||||
{
|
||||
//FreeConsole();
|
||||
//AllocConsole();
|
||||
MakeNewConsole();
|
||||
prot_scr_width = s->col;
|
||||
prot_scr_height = s->row;
|
||||
extern HANDLE hConsole ;
|
||||
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
ConSetScreenSize( s->col, s->row );
|
||||
s->ptyfd = hConsole ; // the pty is the Windows console output handle in our Win32 port
|
||||
|
||||
wfdtocmd = GetStdHandle (STD_INPUT_HANDLE) ; // we use this console handle to feed input to Windows shell cmd.exe
|
||||
sockin[1] = allocate_sfd((int)wfdtocmd); // put the std input handle in our global general handle table
|
||||
//if (sockin[1] >= 0)
|
||||
// sfd_set_to_console(sockin[1]); // mark it as Console type
|
||||
|
||||
socketpair(sockin);
|
||||
s->ptyfd = sockin[1]; // hConsole; // the pty is the Windows console output handle in our Win32 port
|
||||
}
|
||||
else
|
||||
socketpair(sockin);
|
||||
#else
|
||||
HANDLE wfdtocmd = -1;
|
||||
int retcode = -1;
|
||||
if ((!s->is_subsystem) && (s->ttyfd != -1))
|
||||
{
|
||||
//FreeConsole();
|
||||
//AllocConsole();
|
||||
MakeNewConsole();
|
||||
prot_scr_width = s->col;
|
||||
prot_scr_height = s->row;
|
||||
extern HANDLE hConsole;
|
||||
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
ConSetScreenSize(s->col, s->row);
|
||||
s->ptyfd = hConsole; // the pty is the Windows console output handle in our Win32 port
|
||||
|
||||
wfdtocmd = GetStdHandle(STD_INPUT_HANDLE); // we use this console handle to feed input to Windows shell cmd.exe
|
||||
sockin[1] = allocate_sfd((int)wfdtocmd); // put the std input handle in our global general handle table
|
||||
}
|
||||
else
|
||||
socketpair(sockin);
|
||||
#endif
|
||||
|
||||
socketpair(sockout);
|
||||
socketpair(sockerr);
|
||||
|
@ -636,12 +671,14 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
debug3("sockout[0]: %d sockout[1]: %d", sockout[0], sockout[1]);
|
||||
debug3("sockerr[0]: %d sockerr[1]: %d", sockerr[0], sockerr[1]);
|
||||
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||
crlf_sfd(sockin[1]);
|
||||
|
||||
crlf_sfd(sockout[1]);
|
||||
|
||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||
#endif
|
||||
SetHandleInformation(sfd_to_handle(sockin[1]), HANDLE_FLAG_INHERIT, 0);
|
||||
|
||||
SetHandleInformation(sfd_to_handle(sockout[1]), HANDLE_FLAG_INHERIT, 0);
|
||||
|
@ -668,11 +705,16 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
si.cbReserved2 = 0;
|
||||
si.lpReserved2 = 0;
|
||||
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
if (0) {
|
||||
#else
|
||||
if ( (!s -> is_subsystem) && (s ->ttyfd != -1) ) {
|
||||
|
||||
si.hStdInput = GetStdHandle (STD_INPUT_HANDLE) ; // shell tty interactive session gets a console input for Win32
|
||||
si.hStdOutput = (HANDLE) sfd_to_handle(sockout[0]);
|
||||
si.hStdError = (HANDLE) sfd_to_handle(sockerr[0]);
|
||||
si.lpDesktop = NULL ; //winstadtname_w ;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
si.hStdInput = (HANDLE) sfd_to_handle(sockin[0]);
|
||||
|
@ -804,25 +846,25 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
* Get user homedir if needed.
|
||||
*/
|
||||
|
||||
if (s -> pw -> pw_dir == NULL || s -> pw -> pw_dir[0] == '\0')
|
||||
if (1) // (s -> pw -> pw_dir == NULL || s -> pw -> pw_dir[0] == '\0')
|
||||
{
|
||||
/*
|
||||
* If there is homedir from LSA use it.
|
||||
*/
|
||||
|
||||
if (HomeDirLsaW[0] != '\0')
|
||||
{
|
||||
s -> pw -> pw_dir = HomeDirLsaW;
|
||||
}
|
||||
//if (HomeDirLsaW[0] != '\0')
|
||||
//{
|
||||
//s -> pw -> pw_dir = HomeDirLsaW;
|
||||
//}
|
||||
|
||||
/*
|
||||
* If not get homedir from token.
|
||||
*/
|
||||
|
||||
else
|
||||
{
|
||||
//else
|
||||
//{
|
||||
s -> pw -> pw_dir = GetHomeDirFromToken(s -> pw -> pw_name, hToken);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -832,6 +874,16 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
_wchdir(s -> pw -> pw_dir);
|
||||
|
||||
SetEnvironmentVariableW(L"HOME", s -> pw -> pw_dir);
|
||||
wchar_t *wstr, wchr;
|
||||
wstr = wcschr(s->pw->pw_dir, ':');
|
||||
if (wstr) {
|
||||
wchr = *(wstr + 1);
|
||||
*(wstr + 1) = '\0';
|
||||
SetEnvironmentVariableW(L"HOMEDRIVE", s->pw->pw_dir);
|
||||
*(wstr + 1) = wchr;
|
||||
SetEnvironmentVariableW(L"HOMEPATH", (wstr+1));
|
||||
}
|
||||
|
||||
SetEnvironmentVariableW(L"USERPROFILE", s -> pw -> pw_dir);
|
||||
|
||||
// find the server name of the domain controller which created this token
|
||||
|
@ -879,6 +931,7 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
|
||||
GetUserName(name, &size);
|
||||
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) {
|
||||
// Send to the remote client ANSI/VT Sequence so that they send us CRLF in place of LF
|
||||
char *inittermseq = "\033[20h\033[?7h\0" ; // LFtoCRLF AUTOWRAPON
|
||||
|
@ -886,6 +939,7 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
buffer_append(&c->input, inittermseq, strlen(inittermseq));
|
||||
channel_output_poll();
|
||||
}
|
||||
#endif
|
||||
|
||||
//if (s ->ttyfd != -1) {
|
||||
// set the channel to tty interactive type
|
||||
|
@ -965,8 +1019,12 @@ do_exec_no_pty(Session *s, const char *command)
|
|||
/*
|
||||
* We are the parent. Close the child sides of the socket pairs.
|
||||
*/
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
if ( (s -> is_subsystem) || (s ->ttyfd == -1))
|
||||
close(sockin[0]);
|
||||
#else
|
||||
close(sockin[0]);
|
||||
#endif
|
||||
|
||||
close(sockout[0]);
|
||||
close(sockerr[0]);
|
||||
|
@ -2724,7 +2782,9 @@ session_pty_req(Session *s)
|
|||
/* for SSH1 the tty modes length is not given */
|
||||
if (!compat20)
|
||||
n_bytes = packet_remaining();
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
tty_parse_modes(s->ttyfd, &n_bytes);
|
||||
#endif
|
||||
|
||||
if (!use_privsep)
|
||||
pty_setowner(s->pw, s->tty);
|
||||
|
@ -2734,7 +2794,9 @@ session_pty_req(Session *s)
|
|||
pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
packet_check_eom();
|
||||
#endif
|
||||
session_proctitle(s);
|
||||
return 1;
|
||||
}
|
||||
|
|
4
sftp.c
4
sftp.c
|
@ -346,6 +346,10 @@ local_do_shell(const char *args)
|
|||
static void
|
||||
local_do_ls(const char *args)
|
||||
{
|
||||
#ifdef WIN32_FIXME
|
||||
#undef _PATH_LS
|
||||
#define _PATH_LS "dir"
|
||||
#endif
|
||||
if (!args || !*args)
|
||||
local_do_shell(_PATH_LS);
|
||||
else {
|
||||
|
|
2
sshd.c
2
sshd.c
|
@ -2750,8 +2750,10 @@ main(int ac, char **av)
|
|||
|
||||
/* Chdir to the root directory so that the current disk can be
|
||||
unmounted if desired. */
|
||||
#ifndef WIN32_FIXME
|
||||
if (chdir("/") == -1)
|
||||
error("chdir(\"/\"): %s", strerror(errno));
|
||||
#endif
|
||||
|
||||
/* ignore SIGPIPE */
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
|
32
sshpty.c
32
sshpty.c
|
@ -21,6 +21,7 @@
|
|||
#ifdef WIN32_FIXME
|
||||
#undef GSSAPI
|
||||
#undef KRB5
|
||||
//#define WIN32_PRAGMA_REMCON
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -196,6 +197,32 @@ pty_make_controlling_tty(int *ttyfd, const char *tty)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32_PRAGMA_REMCON
|
||||
/* Changes the window size associated with the pty. */
|
||||
|
||||
void pty_change_window_size_oob(int ptyfd, u_int row, u_int col, u_int xpixel, u_int ypixel)
|
||||
{
|
||||
int rc;
|
||||
char unsigned data[16];
|
||||
size_t data_len;
|
||||
|
||||
// IAC SB NAWS <16-bit value width> <16-bit value height> IAC
|
||||
//sprintf (data,"%c%c%c%c%c%c%c%c", 255, 250, 31, 0, col, 0, row, 255 );
|
||||
data[0] = 255; // IAC;
|
||||
data[1] = 250; // SB
|
||||
data[2] = 31; // NAWS
|
||||
data[3] = 0;
|
||||
data[4] = (unsigned char)col;
|
||||
data[5] = 0;
|
||||
data[6] = (unsigned char)row;
|
||||
data[7] = 255; // IAC
|
||||
data[8] = 240; // iac end
|
||||
data_len = 9; //strlen (data);
|
||||
rc = write(ptyfd, data, (DWORD)data_len);
|
||||
//rc = AsyncWrite(c->hInputHandle, (char *)data, (DWORD)data_len);
|
||||
}
|
||||
|
||||
#endif
|
||||
/* Changes the window size associated with the pty. */
|
||||
|
||||
void
|
||||
|
@ -214,7 +241,12 @@ pty_change_window_size(int ptyfd, u_int row, u_int col,
|
|||
#else
|
||||
extern HANDLE hConsole ;
|
||||
hConsole = ptyfd;
|
||||
#ifndef WIN32_PRAGMA_REMCON
|
||||
ConSetScreenSize( col, row );
|
||||
#else
|
||||
if (ptyfd > 0 )
|
||||
pty_change_window_size_oob(ptyfd, row, col, xpixel, ypixel);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue