Skip to content

Commit c25f6a0

Browse files
committed
Converged Win Unix code in auth.c, move utf routine declarations to separate header
1 parent 8566745 commit c25f6a0

File tree

12 files changed

+45
-151
lines changed

12 files changed

+45
-151
lines changed

auth.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -379,72 +379,6 @@ auth_root_allowed(const char *method)
379379
* This returns a buffer allocated by xmalloc.
380380
*/
381381

382-
/*
383-
* Win32 implementation uses UTF16 names.
384-
*/
385-
386-
#ifdef WIN32_FIXME
387-
388-
char *expand_authorized_keys(const char *filename, struct passwd *pw)
389-
{
390-
wchar_t *file_w, ret[MAXPATHLEN], pw_name_w[MAXPATHLEN], filename_w[MAXPATHLEN], pw_dir_w[MAXPATHLEN];
391-
char* expanded_utf8[MAXPATHLEN];
392-
int i;
393-
394-
wchar_t *slash;
395-
396-
if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_w, MAXPATHLEN) == 0 ||
397-
MultiByteToWideChar(CP_UTF8, 0, pw->pw_name, -1, pw_name_w, MAXPATHLEN) == 0 ||
398-
MultiByteToWideChar(CP_UTF8, 0, pw->pw_dir, -1, pw_dir_w, MAXPATHLEN) == 0)
399-
fatal("expand_authorized_keys -MultiByteToWideChar failed" );
400-
401-
file_w = percent_expand_w(filename_w, L"h", pw_dir_w,
402-
L"u", pw_name_w, (char *) NULL);
403-
404-
/*
405-
* Replace '/' with '\'
406-
*/
407-
408-
slash = file_w;
409-
410-
while ((slash = wcschr(slash, L'/')))
411-
{
412-
*slash = L'\\';
413-
}
414-
415-
/*
416-
* Absolute path given.
417-
*/
418-
419-
if (wcschr(file_w, ':'))
420-
{
421-
i = _snwprintf(ret, sizeof(ret), L"%ls", file_w);
422-
}
423-
424-
/*
425-
* Relative path given. Expand to user homedir.
426-
*/
427-
428-
else
429-
{
430-
i = _snwprintf(ret, sizeof(ret), L"%ls\\%ls", pw->pw_dir, file_w);
431-
}
432-
433-
if (i < 0 || (size_t) i >= sizeof(ret))
434-
{
435-
fatal("expand_authorized_keys: path too long");
436-
}
437-
438-
if (WideCharToMultiByte(CP_UTF8, 0, ret, -1, expanded_utf8, MAXPATHLEN, NULL, NULL) == 0)
439-
fatal("expand_authorized_keys: WideCharToMultiByte failed");
440-
441-
free(file_w);
442-
443-
return (xstrdup(expanded_utf8));
444-
}
445-
446-
#else /* WIN32_FIXME */
447-
448382
char *
449383
expand_authorized_keys(const char *filename, struct passwd *pw)
450384
{
@@ -467,7 +401,6 @@ expand_authorized_keys(const char *filename, struct passwd *pw)
467401
free(file);
468402
return (xstrdup(ret));
469403
}
470-
#endif /* WIN32_FIXME */
471404

472405
char *
473406
authorized_principals_file(struct passwd *pw)

contrib/win32/openssh/win32iocompat.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_internal.h" />
173173
<ClInclude Include="..\win32compat\inc\pwd.h" />
174174
<ClInclude Include="..\win32compat\inc\sys\param.h" />
175+
<ClInclude Include="..\win32compat\inc\utf.h" />
175176
</ItemGroup>
176177
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
177178
<ImportGroup Label="ExtensionTargets">

contrib/win32/openssh/win32iocompat.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<ClInclude Include="..\win32compat\inc\sys\param.h">
6161
<Filter>inc\sys</Filter>
6262
</ClInclude>
63+
<ClInclude Include="..\win32compat\inc\utf.h">
64+
<Filter>inc</Filter>
65+
</ClInclude>
6366
</ItemGroup>
6467
<ItemGroup>
6568
<Filter Include="inc">

contrib/win32/win32compat/inc/utf.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Author: Manoj Ampalam <[email protected]>
3+
*
4+
* UTF-16 <--> UTF-8 definitions
5+
*/
6+
#ifndef UTF_H
7+
#define UTF_H 1
8+
9+
wchar_t* utf8_to_utf16(const char *);
10+
char* utf16_to_utf8(const wchar_t*);
11+
12+
#endif

contrib/win32/win32compat/inc/w32posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <WS2tcpip.h>
99
#include <stdio.h>
1010
#include "defs.h"
11+
#include "utf.h"
1112

1213

1314
typedef struct w32_fd_set_ {

contrib/win32/win32compat/pwd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
#define SECURITY_WIN32
3737
#include <security.h>
3838
#include "inc\pwd.h"
39+
#include "inc\utf.h"
3940

4041
static struct passwd pw;
4142
static char* pw_shellpath = "ssh-shellhost.exe";
42-
char* utf16_to_utf8(const wchar_t*);
43-
wchar_t* utf8_to_utf16(const char *);
4443

4544
int
4645
initialize_pw() {
4746
if (pw.pw_shell != pw_shellpath) {
4847
memset(&pw, 0, sizeof(pw));
4948
pw.pw_shell = pw_shellpath;
49+
pw.pw_passwd = "\0";
5050
}
5151
return 0;
5252
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include "digest.h"
4747
#include "agent.h"
4848

49+
#include <utf.h>
50+
4951
static int use_privsep = -1;
5052
Buffer cfg;
5153
ServerOptions options;
@@ -85,8 +87,6 @@ int GetCurrentModulePath(wchar_t *path, int pathSize)
8587
return -1;
8688
}
8789

88-
char* utf16_to_utf8(const wchar_t*);
89-
9090
int load_config() {
9191
wchar_t basePath[MAX_PATH] = { 0 };
9292
wchar_t path[MAX_PATH] = { 0 };

contrib/win32/win32compat/w32fd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ w32_lseek(int fd, long offset, int origin) {
399399
return fileio_lseek(fd_table.w32_ios[fd], offset, origin);
400400
}
401401

402-
wchar_t* utf8_to_utf16(const char *);
403402
int
404403
w32_mkdir(const char *path_utf8, unsigned short mode) {
405404
wchar_t *path_utf16 = utf8_to_utf16(path_utf8);

contrib/win32/win32compat/wmain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
*/
3232

3333
#include <Windows.h>
34+
#include "inc\utf.h"
3435

3536
int main(int, char **);
36-
char* utf16_to_utf8(const wchar_t*);
3737
void w32posix_initialize();
3838

3939
int

misc.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -646,64 +646,6 @@ percent_expand(const char *string, ...)
646646
#undef EXPAND_MAX_KEYS
647647
}
648648

649-
#ifdef WIN32_FIXME
650-
wchar_t *percent_expand_w(const wchar_t *string, ...)
651-
{
652-
#define EXPAND_MAX_KEYS 16
653-
u_int num_keys, i, j;
654-
struct {
655-
const wchar_t *key;
656-
const wchar_t *repl;
657-
} keys[EXPAND_MAX_KEYS];
658-
wchar_t buf[4096];
659-
wchar_t *aptr = NULL;
660-
va_list ap;
661-
662-
/* Gather keys */
663-
va_start(ap, string);
664-
for (num_keys = 0; num_keys < EXPAND_MAX_KEYS; num_keys++) {
665-
keys[num_keys].key = va_arg(ap, wchar_t *);
666-
if (keys[num_keys].key == NULL)
667-
break;
668-
keys[num_keys].repl = va_arg(ap, wchar_t *);
669-
if (keys[num_keys].repl == NULL)
670-
fatal("%s: NULL replacement", __func__);
671-
}
672-
if (num_keys == EXPAND_MAX_KEYS && va_arg(ap, wchar_t *) != NULL)
673-
fatal("%s: too many keys", __func__);
674-
va_end(ap);
675-
676-
/* Expand string */
677-
*buf = L'\0';
678-
for (i = 0; *string != L'\0'; string++) {
679-
if (*string != L'%') {
680-
append:
681-
buf[i++] = *string;
682-
if (i >= sizeof(buf))
683-
fatal("%s: string too long", __func__);
684-
buf[i] = L'\0';
685-
continue;
686-
}
687-
string++;
688-
/* %% case */
689-
if (*string == L'%')
690-
goto append;
691-
for (j = 0; j < num_keys; j++) {
692-
if (wcschr(keys[j].key, *string) != NULL) {
693-
aptr = wcsncat(buf, keys[j].repl, sizeof(buf));
694-
buf[sizeof(buf)-1] = 0;
695-
if (aptr == NULL)
696-
fatal("%s: string too long", __func__);
697-
break;
698-
}
699-
}
700-
if (j >= num_keys)
701-
fatal("%s: unknown key %%%c", __func__, *string);
702-
}
703-
return (_wcsdup(buf));
704-
#undef EXPAND_MAX_KEYS
705-
}
706-
#endif
707649
/*
708650
* Read an entire line from a public key file into a static buffer, discarding
709651
* lines that exceed the buffer size. Returns 0 on success, -1 on failure.

0 commit comments

Comments
 (0)