Skip to content

Commit af4c2dd

Browse files
committed
wmain wrapper for ssh-keygen
1 parent 1f42832 commit af4c2dd

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

contrib/win32/openssh/keygen.vcxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<GenerateDebugInformation>true</GenerateDebugInformation>
113113
<AdditionalDependencies>win32iocompat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
114114
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
115+
<EntryPointSymbol>wmain</EntryPointSymbol>
115116
</Link>
116117
</ItemDefinitionGroup>
117118
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -131,6 +132,7 @@
131132
<GenerateDebugInformation>true</GenerateDebugInformation>
132133
<AdditionalDependencies>win32iocompat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
133134
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
135+
<EntryPointSymbol>wmain</EntryPointSymbol>
134136
</Link>
135137
</ItemDefinitionGroup>
136138
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -153,6 +155,7 @@
153155
<OptimizeReferences>true</OptimizeReferences>
154156
<AdditionalDependencies>win32iocompat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
155157
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
158+
<EntryPointSymbol>wmain</EntryPointSymbol>
156159
</Link>
157160
</ItemDefinitionGroup>
158161
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -175,10 +178,12 @@
175178
<OptimizeReferences>true</OptimizeReferences>
176179
<AdditionalDependencies>win32iocompat.lib;bcrypt.lib;Userenv.lib;Ws2_32.lib;Secur32.lib;Shlwapi.lib;openbsd_compat.lib;libssh.lib;win32compat.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
177180
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
181+
<EntryPointSymbol>wmain</EntryPointSymbol>
178182
</Link>
179183
</ItemDefinitionGroup>
180184
<ItemGroup>
181185
<ClCompile Include="$(OpenSSH-Src-Path)ssh-keygen.c" />
186+
<ClCompile Include="..\win32compat\wmain.c" />
182187
</ItemGroup>
183188
<ItemGroup>
184189
<ResourceCompile Include="version.rc" />

contrib/win32/openssh/keygen.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<ClCompile Include="$(OpenSSH-Src-Path)ssh-keygen.c">
1919
<Filter>Source Files</Filter>
2020
</ClCompile>
21+
<ClCompile Include="..\win32compat\wmain.c">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
2124
</ItemGroup>
2225
<ItemGroup>
2326
<ResourceCompile Include="version.rc">

contrib/win32/win32compat/wmain.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Author: Manoj Ampalam <[email protected]>
3+
*
4+
* Converts UTF-16 arguments to UTF-8
5+
*
6+
* Copyright (c) 2015 Microsoft Corp.
7+
* All rights reserved
8+
*
9+
* Microsoft openssh win32 port
10+
*
11+
* Redistribution and use in source and binary forms, with or without
12+
* modification, are permitted provided that the following conditions
13+
* are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in the
19+
* documentation and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#include <Windows.h>
34+
35+
char*
36+
utf16_to_utf8(wchar_t utf16str) {
37+
char* ret;
38+
int needed;
39+
if ((needed = WideCharToMultiByte(CP_UTF8, 0, utf16str, -1, NULL, 0, NULL, NULL)) == 0 ||
40+
(ret = malloc(needed)) == NULL ||
41+
WideCharToMultiByte(CP_UTF8, 0, utf16str, -1, ret, needed, NULL, NULL) != needed )
42+
fatal("failed to covert input arguments");
43+
44+
return ret;
45+
}
46+
47+
int
48+
wmain(int argc, wchar_t **wargv) {
49+
char** argv = NULL;
50+
int i;
51+
52+
if (argc) {
53+
if ((argv = malloc(argc * sizeof(char*))) == NULL)
54+
fatal("out of memory");
55+
for (i = 0; i < argc; i++)
56+
argv[i] = utf16_to_utf8(wargv[i]);
57+
}
58+
59+
return main(argc, argv);
60+
}

0 commit comments

Comments
 (0)