diff --git a/auth.c b/auth.c index 405371c..5b21636 100644 --- a/auth.c +++ b/auth.c @@ -379,72 +379,6 @@ auth_root_allowed(const char *method) * This returns a buffer allocated by xmalloc. */ -/* - * Win32 implementation uses UTF16 names. - */ - -#ifdef WIN32_FIXME - -char *expand_authorized_keys(const char *filename, struct passwd *pw) -{ - wchar_t *file_w, ret[MAXPATHLEN], pw_name_w[MAXPATHLEN], filename_w[MAXPATHLEN], pw_dir_w[MAXPATHLEN]; - char* expanded_utf8[MAXPATHLEN]; - int i; - - wchar_t *slash; - - if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_w, MAXPATHLEN) == 0 || - MultiByteToWideChar(CP_UTF8, 0, pw->pw_name, -1, pw_name_w, MAXPATHLEN) == 0 || - MultiByteToWideChar(CP_UTF8, 0, pw->pw_dir, -1, pw_dir_w, MAXPATHLEN) == 0) - fatal("expand_authorized_keys -MultiByteToWideChar failed" ); - - file_w = percent_expand_w(filename_w, L"h", pw_dir_w, - L"u", pw_name_w, (char *) NULL); - - /* - * Replace '/' with '\' - */ - - slash = file_w; - - while ((slash = wcschr(slash, L'/'))) - { - *slash = L'\\'; - } - - /* - * Absolute path given. - */ - - if (wcschr(file_w, ':')) - { - i = _snwprintf(ret, sizeof(ret), L"%ls", file_w); - } - - /* - * Relative path given. Expand to user homedir. - */ - - else - { - i = _snwprintf(ret, sizeof(ret), L"%ls\\%ls", pw->pw_dir, file_w); - } - - if (i < 0 || (size_t) i >= sizeof(ret)) - { - fatal("expand_authorized_keys: path too long"); - } - - if (WideCharToMultiByte(CP_UTF8, 0, ret, -1, expanded_utf8, MAXPATHLEN, NULL, NULL) == 0) - fatal("expand_authorized_keys: WideCharToMultiByte failed"); - - free(file_w); - - return (xstrdup(expanded_utf8)); -} - -#else /* WIN32_FIXME */ - char * expand_authorized_keys(const char *filename, struct passwd *pw) { @@ -467,7 +401,6 @@ expand_authorized_keys(const char *filename, struct passwd *pw) free(file); return (xstrdup(ret)); } -#endif /* WIN32_FIXME */ char * authorized_principals_file(struct passwd *pw) diff --git a/contrib/win32/openssh/win32iocompat.vcxproj b/contrib/win32/openssh/win32iocompat.vcxproj index bbed3a8..1573471 100644 --- a/contrib/win32/openssh/win32iocompat.vcxproj +++ b/contrib/win32/openssh/win32iocompat.vcxproj @@ -172,6 +172,7 @@ + diff --git a/contrib/win32/openssh/win32iocompat.vcxproj.filters b/contrib/win32/openssh/win32iocompat.vcxproj.filters index 7a11eaa..433a8c8 100644 --- a/contrib/win32/openssh/win32iocompat.vcxproj.filters +++ b/contrib/win32/openssh/win32iocompat.vcxproj.filters @@ -60,6 +60,9 @@ inc\sys + + inc + diff --git a/contrib/win32/win32compat/inc/utf.h b/contrib/win32/win32compat/inc/utf.h new file mode 100644 index 0000000..1e959b5 --- /dev/null +++ b/contrib/win32/win32compat/inc/utf.h @@ -0,0 +1,12 @@ +/* +* Author: Manoj Ampalam +* +* UTF-16 <--> UTF-8 definitions +*/ +#ifndef UTF_H +#define UTF_H 1 + +wchar_t* utf8_to_utf16(const char *); +char* utf16_to_utf8(const wchar_t*); + +#endif \ No newline at end of file diff --git a/contrib/win32/win32compat/inc/w32posix.h b/contrib/win32/win32compat/inc/w32posix.h index 67ca87a..0f8e55d 100644 --- a/contrib/win32/win32compat/inc/w32posix.h +++ b/contrib/win32/win32compat/inc/w32posix.h @@ -8,6 +8,7 @@ #include #include #include "defs.h" +#include "utf.h" typedef struct w32_fd_set_ { diff --git a/contrib/win32/win32compat/pwd.c b/contrib/win32/win32compat/pwd.c index afe6f6a..4bcac14 100644 --- a/contrib/win32/win32compat/pwd.c +++ b/contrib/win32/win32compat/pwd.c @@ -36,17 +36,17 @@ #define SECURITY_WIN32 #include #include "inc\pwd.h" +#include "inc\utf.h" static struct passwd pw; static char* pw_shellpath = "ssh-shellhost.exe"; -char* utf16_to_utf8(const wchar_t*); -wchar_t* utf8_to_utf16(const char *); int initialize_pw() { if (pw.pw_shell != pw_shellpath) { memset(&pw, 0, sizeof(pw)); pw.pw_shell = pw_shellpath; + pw.pw_passwd = "\0"; } return 0; } diff --git a/contrib/win32/win32compat/ssh-agent/agentconfig.c b/contrib/win32/win32compat/ssh-agent/agentconfig.c index fa06b67..c0ed77d 100644 --- a/contrib/win32/win32compat/ssh-agent/agentconfig.c +++ b/contrib/win32/win32compat/ssh-agent/agentconfig.c @@ -46,6 +46,8 @@ #include "digest.h" #include "agent.h" +#include + static int use_privsep = -1; Buffer cfg; ServerOptions options; @@ -85,8 +87,6 @@ int GetCurrentModulePath(wchar_t *path, int pathSize) return -1; } -char* utf16_to_utf8(const wchar_t*); - int load_config() { wchar_t basePath[MAX_PATH] = { 0 }; wchar_t path[MAX_PATH] = { 0 }; diff --git a/contrib/win32/win32compat/w32fd.c b/contrib/win32/win32compat/w32fd.c index 9579999..becc894 100644 --- a/contrib/win32/win32compat/w32fd.c +++ b/contrib/win32/win32compat/w32fd.c @@ -399,7 +399,6 @@ w32_lseek(int fd, long offset, int origin) { return fileio_lseek(fd_table.w32_ios[fd], offset, origin); } -wchar_t* utf8_to_utf16(const char *); int w32_mkdir(const char *path_utf8, unsigned short mode) { wchar_t *path_utf16 = utf8_to_utf16(path_utf8); diff --git a/contrib/win32/win32compat/wmain.c b/contrib/win32/win32compat/wmain.c index 79795db..b8418b8 100644 --- a/contrib/win32/win32compat/wmain.c +++ b/contrib/win32/win32compat/wmain.c @@ -31,9 +31,9 @@ */ #include +#include "inc\utf.h" int main(int, char **); -char* utf16_to_utf8(const wchar_t*); void w32posix_initialize(); int diff --git a/misc.c b/misc.c index 2c7b100..797e4cd 100644 --- a/misc.c +++ b/misc.c @@ -646,64 +646,6 @@ percent_expand(const char *string, ...) #undef EXPAND_MAX_KEYS } -#ifdef WIN32_FIXME -wchar_t *percent_expand_w(const wchar_t *string, ...) -{ -#define EXPAND_MAX_KEYS 16 - u_int num_keys, i, j; - struct { - const wchar_t *key; - const wchar_t *repl; - } keys[EXPAND_MAX_KEYS]; - wchar_t buf[4096]; - wchar_t *aptr = NULL; - va_list ap; - - /* Gather keys */ - va_start(ap, string); - for (num_keys = 0; num_keys < EXPAND_MAX_KEYS; num_keys++) { - keys[num_keys].key = va_arg(ap, wchar_t *); - if (keys[num_keys].key == NULL) - break; - keys[num_keys].repl = va_arg(ap, wchar_t *); - if (keys[num_keys].repl == NULL) - fatal("%s: NULL replacement", __func__); - } - if (num_keys == EXPAND_MAX_KEYS && va_arg(ap, wchar_t *) != NULL) - fatal("%s: too many keys", __func__); - va_end(ap); - - /* Expand string */ - *buf = L'\0'; - for (i = 0; *string != L'\0'; string++) { - if (*string != L'%') { - append: - buf[i++] = *string; - if (i >= sizeof(buf)) - fatal("%s: string too long", __func__); - buf[i] = L'\0'; - continue; - } - string++; - /* %% case */ - if (*string == L'%') - goto append; - for (j = 0; j < num_keys; j++) { - if (wcschr(keys[j].key, *string) != NULL) { - aptr = wcsncat(buf, keys[j].repl, sizeof(buf)); - buf[sizeof(buf)-1] = 0; - if (aptr == NULL) - fatal("%s: string too long", __func__); - break; - } - } - if (j >= num_keys) - fatal("%s: unknown key %%%c", __func__, *string); - } - return (_wcsdup(buf)); -#undef EXPAND_MAX_KEYS -} -#endif /* * Read an entire line from a public key file into a static buffer, discarding * lines that exceed the buffer size. Returns 0 on success, -1 on failure. diff --git a/misc.h b/misc.h index 764cc5a..374c33c 100644 --- a/misc.h +++ b/misc.h @@ -50,9 +50,6 @@ char *colon(char *); long convtime(const char *); char *tilde_expand_filename(const char *, uid_t); char *percent_expand(const char *, ...) __attribute__((__sentinel__)); -#ifdef WIN32_FIXME -wchar_t *percent_expand_w(const wchar_t *, ...) __attribute__((__sentinel__)); -#endif char *tohex(const void *, size_t); void sanitise_stdfd(void); void ms_subtract_diff(struct timeval *, int *); diff --git a/session.c b/session.c index 82e3c62..49b3c78 100644 --- a/session.c +++ b/session.c @@ -509,6 +509,7 @@ int do_exec_no_pty(Session *s, const char *command) { #ifdef WIN32_FIXME + wchar_t* pw_dir_utf16 = utf8_to_utf16(s->pw->pw_dir); /* * Win32 code. @@ -707,20 +708,22 @@ do_exec_no_pty(Session *s, const char *command) * also change subsequent calls to SetEnvironmentVariable */ - _chdir(s->pw->pw_dir); + _wchdir(pw_dir_utf16); + + SetEnvironmentVariableW(L"HOME", pw_dir_utf16); + SetEnvironmentVariableW(L"USERPROFILE", pw_dir_utf16); - SetEnvironmentVariableW(L"HOME", s -> pw -> pw_dir); wchar_t *wstr, wchr; - wstr = wcschr(s->pw->pw_dir, ':'); + wstr = wcschr(pw_dir_utf16, L':'); if (wstr) { wchr = *(wstr + 1); *(wstr + 1) = '\0'; - SetEnvironmentVariableW(L"HOMEDRIVE", s->pw->pw_dir); + SetEnvironmentVariableW(L"HOMEDRIVE", pw_dir_utf16); *(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 GetDomainFromToken ( &hToken, buf, sizeof(buf)); @@ -734,7 +737,7 @@ do_exec_no_pty(Session *s, const char *command) snprintf(buf, sizeof buf, "%.50s %d %d", get_remote_ipaddr(), get_remote_port(), get_local_port()); - SetEnvironmentVariable("SSH_CLIENT", buf); + SetEnvironmentVariableA("SSH_CLIENT", buf); /* * Set SSH_CONNECTION variable. @@ -747,16 +750,16 @@ do_exec_no_pty(Session *s, const char *command) free(laddr); - SetEnvironmentVariable("SSH_CONNECTION", buf); + SetEnvironmentVariableA("SSH_CONNECTION", buf); if (original_command) - SetEnvironmentVariable("SSH_ORIGINAL_COMMAND", original_command); + SetEnvironmentVariableA("SSH_ORIGINAL_COMMAND", original_command); // set better prompt for Windows cmd shell if (!s -> is_subsystem) { snprintf(buf,sizeof buf, "%s@%s $P$G", s->pw->pw_name, getenv("COMPUTERNAME")); - SetEnvironmentVariable("PROMPT", buf); + SetEnvironmentVariableA("PROMPT", buf); } /* @@ -789,14 +792,17 @@ do_exec_no_pty(Session *s, const char *command) DWORD dwStartupFlags = DETACHED_PROCESS;// CREATE_SUSPENDED; // 0 SetConsoleCtrlHandler(NULL, FALSE); - if (debug_flag) - b = CreateProcessW(NULL, exec_command_w, NULL, NULL, TRUE, - /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags, NULL, s->pw->pw_dir, - &si, &pi); - else - b = CreateProcessAsUserW(hToken, NULL, exec_command_w, NULL, NULL, TRUE, - /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags, NULL, s -> pw -> pw_dir, - &si, &pi); + + wchar_t* p_dir = utf8_to_utf16(s->pw->pw_dir); + if (debug_flag) + b = CreateProcessW(NULL, exec_command_w, NULL, NULL, TRUE, + /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags, NULL, pw_dir_utf16, + &si, &pi); + else + b = CreateProcessAsUserW(hToken, NULL, exec_command_w, NULL, NULL, TRUE, + /*CREATE_NEW_PROCESS_GROUP*/ dwStartupFlags, NULL, pw_dir_utf16, + &si, &pi); + if (!b) { debug("ERROR. Cannot create process (%u).\n", GetLastError());