From 5a47bedd446999215dee51dd8a38a8e39a9d6c42 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Sun, 13 Mar 2016 11:40:04 -0700 Subject: [PATCH] enabled sftp-server over new POSIX wrapper. not functional yet --- contrib/win32/openssh/Win32-OpenSSH.sln | 1 + contrib/win32/openssh/sftp-server.vcxproj | 12 ++- contrib/win32/openssh/sftp.vcxproj | 3 + sftp-server.c | 125 ++++++++-------------- 4 files changed, 59 insertions(+), 82 deletions(-) diff --git a/contrib/win32/openssh/Win32-OpenSSH.sln b/contrib/win32/openssh/Win32-OpenSSH.sln index cf518a6..ba6081b 100644 --- a/contrib/win32/openssh/Win32-OpenSSH.sln +++ b/contrib/win32/openssh/Win32-OpenSSH.sln @@ -73,6 +73,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sftp-server", "sftp-server. {05E1115F-8529-46D0-AAAF-52A404CE79A7} = {05E1115F-8529-46D0-AAAF-52A404CE79A7} {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} = {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} {DD483F7D-C553-4740-BC1A-903805AD0174} = {DD483F7D-C553-4740-BC1A-903805AD0174} + {0D02F0F0-013B-4EE3-906D-86517F3822C0} = {0D02F0F0-013B-4EE3-906D-86517F3822C0} {8660C2FE-9874-432D-B047-E042BB41DBE0} = {8660C2FE-9874-432D-B047-E042BB41DBE0} EndProjectSection EndProject diff --git a/contrib/win32/openssh/sftp-server.vcxproj b/contrib/win32/openssh/sftp-server.vcxproj index 4829170..b597f93 100644 --- a/contrib/win32/openssh/sftp-server.vcxproj +++ b/contrib/win32/openssh/sftp-server.vcxproj @@ -80,21 +80,25 @@ true $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); true $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); false $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); false $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); @@ -111,7 +115,7 @@ Console true - 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) + 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) $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories) @@ -130,7 +134,7 @@ Console true - 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) + 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) $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories) @@ -152,7 +156,7 @@ true true true - 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) + 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) $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories) @@ -174,7 +178,7 @@ true true true - 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) + 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) $(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories) diff --git a/contrib/win32/openssh/sftp.vcxproj b/contrib/win32/openssh/sftp.vcxproj index d4bea70..096b943 100644 --- a/contrib/win32/openssh/sftp.vcxproj +++ b/contrib/win32/openssh/sftp.vcxproj @@ -82,6 +82,7 @@ true $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); true @@ -93,11 +94,13 @@ false $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); false $(OpenSSH-Bin-Path)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\$(TargetName)\ + $(OpenSSH-Src-Path)contrib\win32\win32compat\inc;$(VC_IncludePath);$(WindowsSDK_IncludePath); diff --git a/sftp-server.c b/sftp-server.c index 29b0f55..8538aec 100644 --- a/sftp-server.c +++ b/sftp-server.c @@ -79,28 +79,6 @@ #ifdef WIN32_FIXME - #undef select - #undef send - #undef recv - - #include - - // #define isatty(a) WSHELPisatty(a) - - #define mkdir(a, b) _mkdir(a) - - #define open(NAME, FLAGS, MODE) _open(NAME, FLAGS | O_BINARY, MODE) - - #define close(FD) _close(FD) - - #define write(FD, BUF, LEN) _write(FD, BUF, LEN) - - #define read(FD, BUF, LEN) _read(FD, BUF, LEN) - - #define lstat(PATH, BUF) _stat(PATH, BUF) - - #define stat(PATH, BUF) _stat(PATH, BUF) - char * get_inside_path(char *, BOOL, BOOL); int readlink(const char *path, char *link, int linklen); @@ -112,15 +90,6 @@ #define realpath realpathWin32 - /* - * Don't use fstat() function redefined - * in socket.h ported header. It is wrong - * in this context. - */ - - #ifdef fstat - #undef fstat - #endif /* * Handle to log file. @@ -2202,7 +2171,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) fatal("%s: sshbuf_new failed", __func__); if ((oqueue = sshbuf_new()) == NULL) fatal("%s: sshbuf_new failed", __func__); -#ifdef WIN32_FIXME +#if(0)//def WIN32_FIXME //rset = (fd_set *)xmalloc(sizeof(fd_set)); //wset = (fd_set *)xmalloc(sizeof(fd_set)); #else @@ -2250,52 +2219,52 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) fatal("%s: sshbuf_check_reserve failed: %s", __func__, ssh_err(r)); - +#endif /* send oqueue to stdout */ - olen = sshbuf_len(oqueue); - - if (olen > 0) { - len = _write(out, sshbuf_ptr(oqueue), olen); - if (len < 0) { - error("write: %s", strerror(errno)); - sftp_server_cleanup_exit(1); - } else if ((r = sshbuf_consume(oqueue, len)) != 0) { - fatal("%s: buffer error: %s", - __func__, ssh_err(r)); - } - } - - /* copy stdin to iqueue */ - if ( select_read ) { - if ( readsomemore || ( sshbuf_len(iqueue) <= 0)) { - len = _read(in, buf, sizeof buf); - if (len == 0) { - debug("read eof"); - sftp_server_cleanup_exit(0); - } else if (len < 0) { - error("read: %s", strerror(errno)); - sftp_server_cleanup_exit(1); - } else if ((r = sshbuf_put(iqueue, buf, len)) != 0) { - fatal("%s: buffer error: %s", - __func__, ssh_err(r)); - } - } - } - - - /* - * Process requests from client if we can fit the results - * into the output buffer, otherwise stop processing input - * and let the output queue drain. - */ - r = sshbuf_check_reserve(oqueue, SFTP_MAX_MSG_LENGTH); - if (r == 0) - process(); - else if (r != SSH_ERR_NO_BUFFER_SPACE) - fatal("%s: sshbuf_check_reserve: %s", - __func__, ssh_err(r)); - } -#else /* WIN32_FIXME */ +// olen = sshbuf_len(oqueue); +// +// if (olen > 0) { +// len = _write(out, sshbuf_ptr(oqueue), olen); +// if (len < 0) { +// error("write: %s", strerror(errno)); +// sftp_server_cleanup_exit(1); +// } else if ((r = sshbuf_consume(oqueue, len)) != 0) { +// fatal("%s: buffer error: %s", +// __func__, ssh_err(r)); +// } +// } +// +// /* copy stdin to iqueue */ +// if ( select_read ) { +// if ( readsomemore || ( sshbuf_len(iqueue) <= 0)) { +// len = _read(in, buf, sizeof buf); +// if (len == 0) { +// debug("read eof"); +// sftp_server_cleanup_exit(0); +// } else if (len < 0) { +// error("read: %s", strerror(errno)); +// sftp_server_cleanup_exit(1); +// } else if ((r = sshbuf_put(iqueue, buf, len)) != 0) { +// fatal("%s: buffer error: %s", +// __func__, ssh_err(r)); +// } +// } +// } +// +// +// /* +// * Process requests from client if we can fit the results +// * into the output buffer, otherwise stop processing input +// * and let the output queue drain. +// */ +// r = sshbuf_check_reserve(oqueue, SFTP_MAX_MSG_LENGTH); +// if (r == 0) +// process(); +// else if (r != SSH_ERR_NO_BUFFER_SPACE) +// fatal("%s: sshbuf_check_reserve: %s", +// __func__, ssh_err(r)); +// } +//#else /* WIN32_FIXME */ olen = sshbuf_len(oqueue); if (olen > 0) @@ -2346,5 +2315,5 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) fatal("%s: sshbuf_check_reserve: %s", __func__, ssh_err(r)); } -#endif /* else WIN32 */ +//#endif /* else WIN32 */ }