Skip to content

Commit 49da240

Browse files
committed
Cleaning up stringhelp.c
1 parent dcb6346 commit 49da240

File tree

6 files changed

+22
-265
lines changed

6 files changed

+22
-265
lines changed

contrib/win32/openssh/win32compat.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@
153153
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\kerberos.c" />
154154
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\startupneeds.c" />
155155
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\strcasecmp.c" />
156-
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\stringhelp.c" />
157156
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
158157
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
159158
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32auth.c" />

contrib/win32/openssh/win32compat.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\strcasecmp.c">
6464
<Filter>Source Files</Filter>
6565
</ClCompile>
66-
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\stringhelp.c">
67-
<Filter>Source Files</Filter>
68-
</ClCompile>
6966
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c">
7067
<Filter>Source Files</Filter>
7168
</ClCompile>

contrib/win32/win32compat/fileio.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "inc/defs.h"
3737
#include <errno.h>
3838
#include <stddef.h>
39+
#include "inc\utf.h"
3940

4041
/* internal read buffer size */
4142
#define READ_BUFFER_SIZE 100*1024
@@ -238,39 +239,40 @@ createFile_flags_setup(int flags, int mode, struct createFile_flags* cf_flags) {
238239

239240
/* open() implementation. Uses CreateFile to open file, console, device, etc */
240241
struct w32_io*
241-
fileio_open(const char *pathname, int flags, int mode) {
242+
fileio_open(const char *path_utf8, int flags, int mode) {
242243
struct w32_io* pio = NULL;
243244
struct createFile_flags cf_flags;
244245
HANDLE handle;
245-
wchar_t wpathname[MAX_PATH];
246+
wchar_t *path_utf16 = NULL;
246247

247-
debug2("open - pathname:%s, flags:%d, mode:%d", pathname, flags, mode);
248+
debug2("open - pathname:%s, flags:%d, mode:%d", path_utf8, flags, mode);
248249
/* check input params*/
249-
if (pathname == NULL) {
250+
if (path_utf8 == NULL) {
250251
errno = EINVAL;
251252
debug("open - ERROR:%d", errno);
252253
return NULL;
253254
}
254255

255-
if (MultiByteToWideChar(CP_UTF8, 0, pathname, -1, wpathname, MAX_PATH) == 0) {
256-
errno = EFAULT;
257-
debug("WideCharToMultiByte failed - ERROR:%d", GetLastError());
256+
if ((path_utf16 = utf8_to_utf16(path_utf8)) == NULL) {
257+
errno = ENOMEM;
258+
debug("utf8_to_utf16 failed - ERROR:%d", GetLastError());
258259
return NULL;
259260
}
260261

261262
if (createFile_flags_setup(flags, mode, &cf_flags) == -1)
262263
return NULL;
263264

264-
handle = CreateFileW(wpathname, cf_flags.dwDesiredAccess, cf_flags.dwShareMode,
265+
handle = CreateFileW(path_utf16, cf_flags.dwDesiredAccess, cf_flags.dwShareMode,
265266
&cf_flags.securityAttributes, cf_flags.dwCreationDisposition,
266267
cf_flags.dwFlagsAndAttributes, NULL);
267268

268269
if (handle == INVALID_HANDLE_VALUE) {
269270
errno = errno_from_Win32LastError();
270271
debug("open - CreateFile ERROR:%d", GetLastError());
272+
free(path_utf16);
271273
return NULL;
272274
}
273-
275+
free(path_utf16);
274276
pio = (struct w32_io*)malloc(sizeof(struct w32_io));
275277
if (pio == NULL) {
276278
CloseHandle(handle);

contrib/win32/win32compat/ssh-agent/agentconfig.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,18 @@ int config_log_level() {
116116

117117
int pubkey_allowed(struct sshkey* pubkey, wchar_t* wuser, wchar_t* wuser_home) {
118118
struct passwd pw;
119-
char user[256], user_home[MAX_PATH];
119+
int ret;
120+
char *user = NULL, *user_home = NULL;
120121
memset(&pw, 0, sizeof(pw));
121122

122-
if (WideCharToMultiByte(CP_UTF8, 0, wuser, -1, user, 256, NULL, NULL) == 0)
123-
return 0;
124-
WideCharToMultiByte(CP_UTF8, 0, wuser_home, -1, user_home, MAX_PATH, NULL, NULL);
125-
pw.pw_dir = user_home;
123+
if ((user_home = utf16_to_utf8(wuser_home)) == NULL ||
124+
(user = utf16_to_utf8(wuser)) == NULL)
125+
return 0;
126+
127+
pw.pw_dir = user_home;
126128
pw.pw_name = user;
127-
return user_key_allowed(&pw, pubkey, 1);
129+
ret = user_key_allowed(&pw, pubkey, 1);
130+
free(user);
131+
free(user_home);
132+
return ret;
128133
}

contrib/win32/win32compat/stringhelp.c

Lines changed: 0 additions & 198 deletions
This file was deleted.

contrib/win32/win32compat/stringhelp.h

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)