mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-22 05:24:43 +02:00
Initial WIN32_FIXME changes.
This commit is contained in:
parent
1f4283265d
commit
2447272622
@ -1581,6 +1581,7 @@
|
|||||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||||
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
||||||
#define WIN32_FIXME 1
|
#define WIN32_FIXME 1
|
||||||
|
#define WINDOWS 1
|
||||||
|
|
||||||
/* Define if you must implement a startup_needs function for your platform */
|
/* Define if you must implement a startup_needs function for your platform */
|
||||||
#define HAVE_STARTUP_NEEDS 1
|
#define HAVE_STARTUP_NEEDS 1
|
||||||
@ -1631,6 +1632,9 @@
|
|||||||
#define HAVE_STRNCASECMP 1
|
#define HAVE_STRNCASECMP 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the locale.h header. */
|
||||||
|
#define HAVE_LOCALE_H 1
|
||||||
|
|
||||||
#define HAVE_STRUCT_IN6_ADDR 1
|
#define HAVE_STRUCT_IN6_ADDR 1
|
||||||
#define HAVE_STRUCT_SOCKADDR_IN6 1
|
#define HAVE_STRUCT_SOCKADDR_IN6 1
|
||||||
#define HAVE_STRUCT_TIMEVAL 1
|
#define HAVE_STRUCT_TIMEVAL 1
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
<OpenSSH-Src-Path>$(SolutionDir)..\..\..\</OpenSSH-Src-Path>
|
<OpenSSH-Src-Path>$(SolutionDir)..\..\..\</OpenSSH-Src-Path>
|
||||||
<OpenSSH-Bin-Path>$(SolutionDir)..\..\..\bin\</OpenSSH-Bin-Path>
|
<OpenSSH-Bin-Path>$(SolutionDir)..\..\..\bin\</OpenSSH-Bin-Path>
|
||||||
<OpenSSH-Lib-Path>$(SolutionDir)lib\</OpenSSH-Lib-Path>
|
<OpenSSH-Lib-Path>$(SolutionDir)lib\</OpenSSH-Lib-Path>
|
||||||
<OpenSSL-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\</OpenSSL-Path>
|
<OpenSSL-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015-debug\</OpenSSL-Path>
|
||||||
<OpenSSL-Win32-Release-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\Win32\Release\</OpenSSL-Win32-Release-Path>
|
<OpenSSL-Win32-Release-Path>g:\openssl-1.0.2h-x86\OpenSSLInstallx86_vs2015\</OpenSSL-Win32-Release-Path>
|
||||||
<OpenSSL-Win32-Debug-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\Win32\Debug\</OpenSSL-Win32-Debug-Path>
|
<OpenSSL-Win32-Debug-Path>g:\openssl-1.0.2h-x86\OpenSSLInstallx86_vs2015-debug\</OpenSSL-Win32-Debug-Path>
|
||||||
<OpenSSL-x64-Release-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\x64\Release\</OpenSSL-x64-Release-Path>
|
<OpenSSL-x64-Release-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015\</OpenSSL-x64-Release-Path>
|
||||||
<OpenSSL-x64-Debug-Path>$(SolutionDir)..\..\..\..\OpenSSL\1.0.2d\VS2015\x64\Debug\</OpenSSL-x64-Debug-Path>
|
<OpenSSL-x64-Debug-Path>g:\openssl-1.0.2h-x64\OpenSSLInstallx64_vs2015-debug\</OpenSSL-x64-Debug-Path>
|
||||||
|
<OpenSSL-x86-ARM-Release-Path>g:\openssl-1.0.2h-arm-x86\OpenSSLInstallx86_vs2015\</OpenSSL-x86-ARM-Release-Path>
|
||||||
|
<OpenSSL-x86-ARM-Debug-Path>g:\openssl-1.0.2h-arm-x86\OpenSSLInstallx86_vs2015\</OpenSSL-x86-ARM-Debug-Path>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#define open w32_open
|
#define open w32_open
|
||||||
#define read w32_read
|
#define read w32_read
|
||||||
#define write w32_write
|
#define write w32_write
|
||||||
|
#define writev w32_writev
|
||||||
//#define isatty w32_isatty
|
//#define isatty w32_isatty
|
||||||
#define close w32_close
|
#define close w32_close
|
||||||
#define dup w32_dup
|
#define dup w32_dup
|
||||||
|
@ -44,6 +44,7 @@ int w32_pipe(int *pfds);
|
|||||||
int w32_open(const char *pathname, int flags, ...);
|
int w32_open(const char *pathname, int flags, ...);
|
||||||
int w32_read(int fd, void *dst, size_t max);
|
int w32_read(int fd, void *dst, size_t max);
|
||||||
int w32_write(int fd, const void *buf, unsigned int max);
|
int w32_write(int fd, const void *buf, unsigned int max);
|
||||||
|
int w32_writev(int fd, const struct iovec *iov, int iovcnt);
|
||||||
int w32_fstat(int fd, struct w32_stat *buf);
|
int w32_fstat(int fd, struct w32_stat *buf);
|
||||||
int w32_stat(const char *path, struct w32_stat *buf);
|
int w32_stat(const char *path, struct w32_stat *buf);
|
||||||
long w32_lseek( int fd, long offset, int origin);
|
long w32_lseek( int fd, long offset, int origin);
|
||||||
@ -117,7 +118,6 @@ int sw_add_child(HANDLE child, DWORD pid);
|
|||||||
#define allocate_sfd(a, b) w32_allocate_fd_for_handle((a, b))
|
#define allocate_sfd(a, b) w32_allocate_fd_for_handle((a, b))
|
||||||
//#define WSHELPwopen(a, b) w32_open((a, b))
|
//#define WSHELPwopen(a, b) w32_open((a, b))
|
||||||
|
|
||||||
|
|
||||||
/* TODO - These defs need to revisited and positioned appropriately */
|
/* TODO - These defs need to revisited and positioned appropriately */
|
||||||
#define environ _environ
|
#define environ _environ
|
||||||
|
|
||||||
|
@ -50,6 +50,33 @@
|
|||||||
#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
|
#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
HINSTANCE hUserLibrary;
|
||||||
|
HINSTANCE hKernelLibrary;
|
||||||
|
|
||||||
|
// kernel32.dll
|
||||||
|
typedef BOOL(WINAPI * fSetCurrentConsoleFontEx)(
|
||||||
|
_In_ HANDLE hConsoleOutput,
|
||||||
|
_In_ BOOL bMaximumWindow,
|
||||||
|
_In_ PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
|
||||||
|
fSetCurrentConsoleFontEx fnSetCurrentConsoleFontEx = NULL;
|
||||||
|
|
||||||
|
// user32.dll
|
||||||
|
typedef HWINEVENTHOOK (WINAPI * fSetWinEventHook)(
|
||||||
|
_In_ UINT eventMin,
|
||||||
|
_In_ UINT eventMax,
|
||||||
|
_In_ HMODULE hmodWinEventProc,
|
||||||
|
_In_ WINEVENTPROC lpfnWinEventProc,
|
||||||
|
_In_ DWORD idProcess,
|
||||||
|
_In_ DWORD idThread,
|
||||||
|
_In_ UINT dwflags
|
||||||
|
);
|
||||||
|
fSetWinEventHook fnSetWinEventHook = NULL;
|
||||||
|
|
||||||
|
typedef BOOL (WINAPI * fUnhookWinEvent)(
|
||||||
|
_In_ HWINEVENTHOOK hWinEventHook
|
||||||
|
);
|
||||||
|
fUnhookWinEvent fnUnhookWinEvent = NULL;
|
||||||
|
|
||||||
typedef struct consoleEvent {
|
typedef struct consoleEvent {
|
||||||
DWORD event;
|
DWORD event;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
@ -66,6 +93,7 @@ BOOL bRet = FALSE;
|
|||||||
BOOL bNoScrollRegion = FALSE;
|
BOOL bNoScrollRegion = FALSE;
|
||||||
BOOL bStartup = TRUE;
|
BOOL bStartup = TRUE;
|
||||||
BOOL bAnsi = FALSE;
|
BOOL bAnsi = FALSE;
|
||||||
|
BOOL bHookEvents = FALSE;
|
||||||
|
|
||||||
HANDLE child_out = INVALID_HANDLE_VALUE;
|
HANDLE child_out = INVALID_HANDLE_VALUE;
|
||||||
HANDLE child_in = INVALID_HANDLE_VALUE;
|
HANDLE child_in = INVALID_HANDLE_VALUE;
|
||||||
@ -389,7 +417,8 @@ void SizeWindow(HANDLE hInput) {
|
|||||||
matchingFont.FontWeight = FW_NORMAL;
|
matchingFont.FontWeight = FW_NORMAL;
|
||||||
wcscpy(matchingFont.FaceName, L"Consolas");
|
wcscpy(matchingFont.FaceName, L"Consolas");
|
||||||
|
|
||||||
bSuccess = SetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
|
if(fnSetCurrentConsoleFontEx != NULL)
|
||||||
|
bSuccess = fnSetCurrentConsoleFontEx(child_out, FALSE, &matchingFont);
|
||||||
|
|
||||||
// This information is the live screen
|
// This information is the live screen
|
||||||
ZeroMemory(&consoleInfo, sizeof(consoleInfo));
|
ZeroMemory(&consoleInfo, sizeof(consoleInfo));
|
||||||
@ -1058,6 +1087,22 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
DWORD dwStatus;
|
DWORD dwStatus;
|
||||||
HANDLE hEventHook = NULL;
|
HANDLE hEventHook = NULL;
|
||||||
|
|
||||||
|
HINSTANCE hUserLibrary;
|
||||||
|
HINSTANCE hKernelLibrary;
|
||||||
|
|
||||||
|
hKernelLibrary = LoadLibrary(L"kernel32.dll");
|
||||||
|
if (hKernelLibrary != NULL)
|
||||||
|
{
|
||||||
|
fnSetCurrentConsoleFontEx = (fSetCurrentConsoleFontEx)GetProcAddress(hKernelLibrary, "SetCurrentConsoleFontEx");
|
||||||
|
}
|
||||||
|
|
||||||
|
hUserLibrary = LoadLibrary(L"user32.dll");
|
||||||
|
if (hUserLibrary != NULL)
|
||||||
|
{
|
||||||
|
fnSetWinEventHook = (fSetWinEventHook)GetProcAddress(hUserLibrary, "SetWinEventHook");
|
||||||
|
fnUnhookWinEvent = (fUnhookWinEvent)GetProcAddress(hUserLibrary, "UnhookWinEvent");
|
||||||
|
}
|
||||||
|
|
||||||
pipe_in = GetStdHandle(STD_INPUT_HANDLE);
|
pipe_in = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
pipe_out = GetStdHandle(STD_OUTPUT_HANDLE);
|
pipe_out = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
pipe_err = GetStdHandle(STD_ERROR_HANDLE);
|
pipe_err = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
@ -1094,6 +1139,7 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
|
|
||||||
InitializeCriticalSection(&criticalSection);
|
InitializeCriticalSection(&criticalSection);
|
||||||
|
|
||||||
|
if(fnSetWinEventHook != NULL)
|
||||||
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
|
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
|
||||||
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
|
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
|
||||||
|
|
||||||
@ -1103,6 +1149,12 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
// Copy our parent buffer sizes
|
// Copy our parent buffer sizes
|
||||||
si.cb = sizeof(STARTUPINFO);
|
si.cb = sizeof(STARTUPINFO);
|
||||||
si.dwFlags = 0;
|
si.dwFlags = 0;
|
||||||
|
if (fnSetWinEventHook == NULL) {
|
||||||
|
si.hStdInput = INVALID_HANDLE_VALUE;
|
||||||
|
si.hStdOutput = pipe_out;
|
||||||
|
si.hStdError = pipe_err;
|
||||||
|
si.dwFlags = STARTF_USESTDHANDLES;
|
||||||
|
}
|
||||||
|
|
||||||
/* disable inheritance on pipe_in*/
|
/* disable inheritance on pipe_in*/
|
||||||
GOTO_CLEANUP_ON_FALSE(SetHandleInformation(pipe_in, HANDLE_FLAG_INHERIT, 0));
|
GOTO_CLEANUP_ON_FALSE(SetHandleInformation(pipe_in, HANDLE_FLAG_INHERIT, 0));
|
||||||
@ -1163,8 +1215,13 @@ cleanup:
|
|||||||
WaitForSingleObject(monitor_thread, INFINITE);
|
WaitForSingleObject(monitor_thread, INFINITE);
|
||||||
if (ux_thread != INVALID_HANDLE_VALUE)
|
if (ux_thread != INVALID_HANDLE_VALUE)
|
||||||
TerminateThread(ux_thread, S_OK);
|
TerminateThread(ux_thread, S_OK);
|
||||||
if (hEventHook)
|
if (hEventHook && fnUnhookWinEvent != NULL)
|
||||||
UnhookWinEvent(hEventHook);
|
fnUnhookWinEvent(hEventHook);
|
||||||
|
|
||||||
|
if (hKernelLibrary != NULL)
|
||||||
|
FreeLibrary(hKernelLibrary);
|
||||||
|
if (hUserLibrary != NULL)
|
||||||
|
FreeLibrary(hUserLibrary);
|
||||||
|
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
|
|
||||||
|
@ -382,6 +382,23 @@ w32_write(int fd, const void *buf, unsigned int max) {
|
|||||||
return fileio_write(fd_table.w32_ios[fd], buf, max);
|
return fileio_write(fd_table.w32_ios[fd], buf, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w32_writev(int fd, const struct iovec *iov, int iovcnt) {
|
||||||
|
int written = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
CHECK_FD(fd);
|
||||||
|
|
||||||
|
for (i = 0; i < iovcnt; i++) {
|
||||||
|
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
|
||||||
|
|
||||||
|
if (ret > 0) {
|
||||||
|
written += ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
w32_fstat(int fd, struct w32_stat *buf) {
|
w32_fstat(int fd, struct w32_stat *buf) {
|
||||||
CHECK_FD(fd);
|
CHECK_FD(fd);
|
||||||
|
26
misc.c
26
misc.c
@ -436,9 +436,34 @@ char *
|
|||||||
colon(char *cp)
|
colon(char *cp)
|
||||||
{
|
{
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
if (*cp == ':') /* Leading colon is part of file name. */
|
if (*cp == ':') /* Leading colon is part of file name. */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
for (; *cp; ++cp) {
|
||||||
|
len++;
|
||||||
|
|
||||||
|
if (*cp == '[')
|
||||||
|
flag = 1;
|
||||||
|
|
||||||
|
if (flag && *cp != ']')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (*cp == ']')
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
if (*cp == ':') {
|
||||||
|
if (len != 2) { // avoid x: format for drive letter in Windows
|
||||||
|
return (cp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if ( (*cp == '/') || (*cp == '\\') )
|
||||||
|
// return (0);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
if (*cp == '[')
|
if (*cp == '[')
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
|
||||||
@ -453,6 +478,7 @@ colon(char *cp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function to assist building execv() arguments */
|
/* function to assist building execv() arguments */
|
||||||
|
@ -81,10 +81,16 @@ static const char unit[] = " KMGT";
|
|||||||
static int
|
static int
|
||||||
can_output(void)
|
can_output(void)
|
||||||
{
|
{
|
||||||
#ifndef WIN32_FIXME//R
|
#ifndef WINDOWS
|
||||||
return (getpgrp() == tcgetpgrp(STDOUT_FILENO));
|
return (getpgrp() == tcgetpgrp(STDOUT_FILENO));
|
||||||
#else
|
#else
|
||||||
return 1;
|
DWORD dwProcessId = -1;
|
||||||
|
if (GetWindowThreadProcessId(GetStdHandle(STD_OUTPUT_HANDLE), &dwProcessId)) {
|
||||||
|
return(GetCurrentProcess() == dwProcessId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +304,7 @@ sig_winch(int sig)
|
|||||||
static void
|
static void
|
||||||
setscreensize(void)
|
setscreensize(void)
|
||||||
{
|
{
|
||||||
#ifndef WIN32_FIXME//N
|
#ifndef WINDOWS
|
||||||
struct winsize winsize;
|
struct winsize winsize;
|
||||||
|
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
|
||||||
@ -310,6 +316,7 @@ setscreensize(void)
|
|||||||
} else
|
} else
|
||||||
win_size = DEFAULT_WINSIZE;
|
win_size = DEFAULT_WINSIZE;
|
||||||
win_size += 1; /* trailing \0 */
|
win_size += 1; /* trailing \0 */
|
||||||
|
#else
|
||||||
|
win_size = ConScreenSizeX() + 1;
|
||||||
#endif
|
#endif
|
||||||
win_size = DEFAULT_WINSIZE + 1;
|
|
||||||
}
|
}
|
||||||
|
147
scp.c
147
scp.c
@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#ifndef WIN32_FIXME
|
#ifndef WINDOWS
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -159,14 +159,11 @@ char *ssh_program = _PATH_SSH_PROGRAM;
|
|||||||
pid_t do_cmd_pid = -1;
|
pid_t do_cmd_pid = -1;
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
typedef BOOL bool;
|
typedef BOOL bool;
|
||||||
#define false FALSE
|
#define false FALSE
|
||||||
#define true TRUE
|
#define true TRUE
|
||||||
|
|
||||||
char *win32colon(char *);
|
|
||||||
#define colon win32colon
|
|
||||||
|
|
||||||
#ifndef _SH_DENYNO
|
#ifndef _SH_DENYNO
|
||||||
#define _SH_DENYNO 0x40
|
#define _SH_DENYNO 0x40
|
||||||
#endif
|
#endif
|
||||||
@ -293,6 +290,8 @@ int start_process_io(char *exename, char **argv, char **envv,
|
|||||||
unsigned long CreateFlags, PROCESS_INFORMATION *pi,
|
unsigned long CreateFlags, PROCESS_INFORMATION *pi,
|
||||||
char *homedir, char *lpDesktop);
|
char *homedir, char *lpDesktop);
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
|
||||||
// InitForMicrosoftWindows() will initialize Unix like settings in Windows operating system.
|
// InitForMicrosoftWindows() will initialize Unix like settings in Windows operating system.
|
||||||
struct passwd pw;
|
struct passwd pw;
|
||||||
char username[128];
|
char username[128];
|
||||||
@ -304,8 +303,12 @@ int InitForMicrosoftWindows()
|
|||||||
/* Get user\'s passwd structure. We need this for the home directory. */
|
/* Get user\'s passwd structure. We need this for the home directory. */
|
||||||
pwd = &pw ;
|
pwd = &pw ;
|
||||||
rc = sizeof(username);
|
rc = sizeof(username);
|
||||||
GetUserName(username,(LPDWORD)&rc);
|
if (GetUserName(username, (LPDWORD)&rc)) {
|
||||||
pwd->pw_name = username;
|
pwd->pw_name = username;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -343,21 +346,7 @@ char * fixslashes(char * str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * unfixslashes(char * str)
|
// force path separator to sep
|
||||||
{
|
|
||||||
int i;
|
|
||||||
if (str == NULL)
|
|
||||||
return str;
|
|
||||||
|
|
||||||
int len = (int)strlen(str);
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
if (str[i] == '//')
|
|
||||||
str[i] = '/';
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// force path separator to
|
|
||||||
char * forcepathsep(char * str, char sep)
|
char * forcepathsep(char * str, char sep)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -374,7 +363,6 @@ char * forcepathsep(char * str, char sep)
|
|||||||
if (sep == '/')
|
if (sep == '/')
|
||||||
antisep = '\\';
|
antisep = '\\';
|
||||||
|
|
||||||
|
|
||||||
int len = (int)strlen(str);
|
int len = (int)strlen(str);
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@ -406,13 +394,10 @@ bool getRootFrompath(char * path, char * root)
|
|||||||
return (lastslash != NULL);
|
return (lastslash != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get option letter from argument vector
|
* get option letter from argument vector
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
char * getfilenamefrompath(char * path)
|
char * getfilenamefrompath(char * path)
|
||||||
{
|
{
|
||||||
char * lastslash;
|
char * lastslash;
|
||||||
@ -447,7 +432,7 @@ char * getfilenamefrompath(char * path)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define EMSG ""
|
#define EMSG ""
|
||||||
#define BADCH (int)'~'
|
#define BADCH (int)'~'
|
||||||
@ -669,7 +654,7 @@ do_local_cmd(arglist *a)
|
|||||||
fprintf(stderr, " %s", a->list[i]);
|
fprintf(stderr, " %s", a->list[i]);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
// flatten the cmd into a long space separated string and execute using system(cmd) api
|
// flatten the cmd into a long space separated string and execute using system(cmd) api
|
||||||
char cmdstr[2048] ;
|
char cmdstr[2048] ;
|
||||||
cmdstr[0] = '\0' ;
|
cmdstr[0] = '\0' ;
|
||||||
@ -680,7 +665,7 @@ do_local_cmd(arglist *a)
|
|||||||
if (system(cmdstr))
|
if (system(cmdstr))
|
||||||
return (-1); // failure executing
|
return (-1); // failure executing
|
||||||
return (0); // success
|
return (0); // success
|
||||||
#else
|
#else
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
fatal("do_local_cmd: fork: %s", strerror(errno));
|
fatal("do_local_cmd: fork: %s", strerror(errno));
|
||||||
|
|
||||||
@ -705,7 +690,7 @@ do_local_cmd(arglist *a)
|
|||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pipe_counter = 1;
|
static int pipe_counter = 1;
|
||||||
@ -770,7 +755,7 @@ error:
|
|||||||
int
|
int
|
||||||
do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
||||||
{
|
{
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
HANDLE hSaveStdout, hSaveStdin ;
|
HANDLE hSaveStdout, hSaveStdin ;
|
||||||
@ -788,8 +773,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
// Child code in Windows OS will be a new created process of ssh.exe.
|
// Child code in Windows OS will be a new created process of ssh.exe.
|
||||||
// Child to execute the command on the remote host using ssh.
|
// Child to execute the command on the remote host using ssh.
|
||||||
|
|
||||||
if (1) { // No fork in Windows OS, so we code it such that we use CreateProcess()
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
args[i++] = ssh_program;
|
args[i++] = ssh_program;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -821,28 +804,23 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
args[i++] = "-P";
|
args[i++] = "-P";
|
||||||
if (batchmode)
|
if (batchmode)
|
||||||
args[i++] = "\"-oBatchMode yes\"";
|
args[i++] = "\"-oBatchMode yes\"";
|
||||||
if (password != NULL)
|
if (password != NULL) {
|
||||||
{
|
|
||||||
args[i++] = "-A";
|
args[i++] = "-A";
|
||||||
args[i++] = password;
|
args[i++] = password;
|
||||||
}
|
}
|
||||||
if (cipher != NULL)
|
if (cipher != NULL) {
|
||||||
{
|
|
||||||
args[i++] = "-c";
|
args[i++] = "-c";
|
||||||
args[i++] = cipher;
|
args[i++] = cipher;
|
||||||
}
|
}
|
||||||
if (identity != NULL)
|
if (identity != NULL) {
|
||||||
{
|
|
||||||
args[i++] = "-i";
|
args[i++] = "-i";
|
||||||
args[i++] = identity;
|
args[i++] = identity;
|
||||||
}
|
}
|
||||||
if (port != NULL)
|
if (port != NULL) {
|
||||||
{
|
|
||||||
args[i++] = "-p";
|
args[i++] = "-p";
|
||||||
args[i++] = port;
|
args[i++] = port;
|
||||||
}
|
}
|
||||||
if (remuser != NULL)
|
if (remuser != NULL) {
|
||||||
{
|
|
||||||
args[i++] = "-l";
|
args[i++] = "-l";
|
||||||
args[i++] = remuser;
|
args[i++] = remuser;
|
||||||
}
|
}
|
||||||
@ -879,7 +857,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
CloseHandle(hstdout[0]); // this CloseHandle() is a crucial must do
|
CloseHandle(hstdout[0]); // this CloseHandle() is a crucial must do
|
||||||
hstdout[0] = rfdfromssh ;
|
hstdout[0] = rfdfromssh ;
|
||||||
|
|
||||||
|
|
||||||
*fdin = _open_osfhandle((intptr_t)hstdout[0],0);
|
*fdin = _open_osfhandle((intptr_t)hstdout[0],0);
|
||||||
_setmode (*fdin, O_BINARY); // set this file handle for binary I/O
|
_setmode (*fdin, O_BINARY); // set this file handle for binary I/O
|
||||||
|
|
||||||
@ -895,7 +872,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
CloseHandle(hstdin[1]); // this CloseHandle() is a crucial must do
|
CloseHandle(hstdin[1]); // this CloseHandle() is a crucial must do
|
||||||
hstdin[1] = (HANDLE) wfdtossh ;
|
hstdin[1] = (HANDLE) wfdtossh ;
|
||||||
|
|
||||||
|
|
||||||
*fdout = _open_osfhandle((intptr_t)hstdin[1],0);
|
*fdout = _open_osfhandle((intptr_t)hstdin[1],0);
|
||||||
_setmode (*fdout, O_BINARY); // set this file handle for binary I/O
|
_setmode (*fdout, O_BINARY); // set this file handle for binary I/O
|
||||||
|
|
||||||
@ -910,7 +886,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
// Set a input handle to the pipe to be STDIN.
|
// Set a input handle to the pipe to be STDIN.
|
||||||
SetStdHandle(STD_INPUT_HANDLE, hstdin[0]);
|
SetStdHandle(STD_INPUT_HANDLE, hstdin[0]);
|
||||||
|
|
||||||
|
|
||||||
// start the child process(ssh)
|
// start the child process(ssh)
|
||||||
rc = start_process_io(
|
rc = start_process_io(
|
||||||
NULL, /* executable name with .ext found in argv[0] */
|
NULL, /* executable name with .ext found in argv[0] */
|
||||||
@ -942,7 +917,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
CloseHandle(hstdout[1]) ;
|
CloseHandle(hstdout[1]) ;
|
||||||
/* now close the pipe's side that the ssh.exe will use as read handle */
|
/* now close the pipe's side that the ssh.exe will use as read handle */
|
||||||
CloseHandle(hstdin[0]) ;
|
CloseHandle(hstdin[0]) ;
|
||||||
}
|
|
||||||
|
|
||||||
// update passed variables with where other funstions should read and write
|
// update passed variables with where other funstions should read and write
|
||||||
// from to get I/O from above child process over pipe.
|
// from to get I/O from above child process over pipe.
|
||||||
@ -951,7 +925,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
//*fdin = remin;
|
//*fdin = remin;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
int pin[2], pout[2], reserved[2];
|
int pin[2], pout[2], reserved[2];
|
||||||
|
|
||||||
if (verbose_mode)
|
if (verbose_mode)
|
||||||
@ -1016,7 +990,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
signal(SIGINT, killchild);
|
signal(SIGINT, killchild);
|
||||||
signal(SIGHUP, killchild);
|
signal(SIGHUP, killchild);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1027,8 +1001,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
|
|||||||
int
|
int
|
||||||
do_cmd2(char *host, char *remuser, char *cmd, int fdin, int fdout)
|
do_cmd2(char *host, char *remuser, char *cmd, int fdin, int fdout)
|
||||||
{
|
{
|
||||||
#ifndef WIN32_FIXME
|
#ifndef WIN32_FIXME
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -1062,7 +1035,7 @@ do_cmd2(char *host, char *remuser, char *cmd, int fdin, int fdout)
|
|||||||
while (waitpid(pid, &status, 0) == -1)
|
while (waitpid(pid, &status, 0) == -1)
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
fatal("do_cmd2: waitpid: %s", strerror(errno));
|
fatal("do_cmd2: waitpid: %s", strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,9 +1077,7 @@ main(int argc, char **argv)
|
|||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
sanitise_stdfd();
|
sanitise_stdfd();
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Copy argv, because we modify it */
|
/* Copy argv, because we modify it */
|
||||||
newargv = xcalloc(MAX(argc + 1, 1), sizeof(*newargv));
|
newargv = xcalloc(MAX(argc + 1, 1), sizeof(*newargv));
|
||||||
@ -1208,22 +1179,18 @@ main(int argc, char **argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
#ifndef WIN32_FIXME
|
#ifndef WINDOWS
|
||||||
if ((pwd = getpwuid(userid = getuid())) == NULL)
|
if ((pwd = getpwuid(userid = getuid())) == NULL)
|
||||||
fatal("unknown user %u", (u_int) userid);
|
fatal("unknown user %u", (u_int) userid);
|
||||||
#else
|
#else
|
||||||
InitForMicrosoftWindows(); // picks the username, user home dir
|
InitForMicrosoftWindows(); // picks the username, user home dir
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!isatty(STDOUT_FILENO))
|
if (!isatty(STDOUT_FILENO))
|
||||||
showprogress = 0;
|
showprogress = 0;
|
||||||
|
|
||||||
remin = STDIN_FILENO;
|
remin = STDIN_FILENO;
|
||||||
remout = STDOUT_FILENO;
|
remout = STDOUT_FILENO;
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
_setmode(remin,O_BINARY); // needed for Windows OS to avoid CrLf translations of text mode
|
|
||||||
_setmode(remout,O_BINARY);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fflag) {
|
if (fflag) {
|
||||||
/* Follow "protocol", send data. */
|
/* Follow "protocol", send data. */
|
||||||
@ -1249,7 +1216,7 @@ main(int argc, char **argv)
|
|||||||
iamrecursive ? " -r" : "", pflag ? " -p" : "",
|
iamrecursive ? " -r" : "", pflag ? " -p" : "",
|
||||||
targetshouldbedirectory ? " -d" : "");
|
targetshouldbedirectory ? " -d" : "");
|
||||||
|
|
||||||
#ifndef WIN32_FIXME
|
#ifndef WINDOWS
|
||||||
(void) signal(SIGPIPE, lostconn);
|
(void) signal(SIGPIPE, lostconn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1264,7 +1231,7 @@ main(int argc, char **argv)
|
|||||||
* Finally check the exit status of the ssh process, if one was forked
|
* Finally check the exit status of the ssh process, if one was forked
|
||||||
* and no error has occurred yet
|
* and no error has occurred yet
|
||||||
*/
|
*/
|
||||||
#ifndef WIN32_FIXME
|
#ifndef WINDOWS
|
||||||
if (do_cmd_pid != -1 && errs == 0) {
|
if (do_cmd_pid != -1 && errs == 0) {
|
||||||
if (remin != -1)
|
if (remin != -1)
|
||||||
(void) close(remin);
|
(void) close(remin);
|
||||||
@ -1277,7 +1244,7 @@ main(int argc, char **argv)
|
|||||||
errs = 1;
|
errs = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
exit(errs != 0);
|
exit(errs != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1443,7 +1410,6 @@ tolocal(int argc, char **argv)
|
|||||||
|
|
||||||
for (i = 0; i < argc - 1; i++) {
|
for (i = 0; i < argc - 1; i++) {
|
||||||
if (!(src = colon(argv[i]))) { /* Local to local. */
|
if (!(src = colon(argv[i]))) { /* Local to local. */
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
freeargs(&alist);
|
freeargs(&alist);
|
||||||
addargs(&alist, "%s", _PATH_CP);
|
addargs(&alist, "%s", _PATH_CP);
|
||||||
if (iamrecursive)
|
if (iamrecursive)
|
||||||
@ -1455,7 +1421,6 @@ tolocal(int argc, char **argv)
|
|||||||
addargs(&alist, "%s", argv[argc-1]);
|
addargs(&alist, "%s", argv[argc-1]);
|
||||||
if (do_local_cmd(&alist))
|
if (do_local_cmd(&alist))
|
||||||
++errs;
|
++errs;
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*src++ = 0;
|
*src++ = 0;
|
||||||
@ -2823,36 +2788,6 @@ lostconn(int signo)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
char *win32colon(char *cp)
|
|
||||||
{
|
|
||||||
int len=0;
|
|
||||||
bool bSkip = false;
|
|
||||||
|
|
||||||
if (*cp == ':') /* Leading colon is part of file name. */
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
for (; *cp; ++cp) {
|
|
||||||
len++;
|
|
||||||
|
|
||||||
if (*cp == '[')
|
|
||||||
bSkip = true;
|
|
||||||
|
|
||||||
if (bSkip && *cp!= ']')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (*cp == ']')
|
|
||||||
bSkip = false;
|
|
||||||
|
|
||||||
if (*cp == ':') {
|
|
||||||
if ( len != 2 ) { // avoid x: format for drive letter in Windows
|
|
||||||
return (cp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if ( (*cp == '/') || (*cp == '\\') )
|
|
||||||
// return (0);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void verifydir(char *cp)
|
void verifydir(char *cp)
|
||||||
{
|
{
|
||||||
@ -2910,8 +2845,6 @@ void lostconn(int signo)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
|
|
||||||
#ifdef WITH_SCP_STATS
|
#ifdef WITH_SCP_STATS
|
||||||
void stats_fixlen(int bwritten)
|
void stats_fixlen(int bwritten)
|
||||||
{
|
{
|
||||||
@ -2927,17 +2860,11 @@ void stats_fixlen(int bwritten)
|
|||||||
fflush(SOME_STATS_FILE);
|
fflush(SOME_STATS_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *stat_eta_new(int msecs)
|
char *stat_eta_new(int msecs)
|
||||||
{
|
{
|
||||||
static char stat_result[32];
|
static char stat_result[32];
|
||||||
int hours = 0, mins = 0, secs = 0;
|
int hours = 0, mins = 0, secs = 0;
|
||||||
|
|
||||||
// hours = msecs / 3600000;
|
|
||||||
// msecs %= 3600000;
|
|
||||||
// mins = msecs / 60000;
|
|
||||||
// msecs %= 60000;
|
|
||||||
|
|
||||||
hours = msecs / 3600000;
|
hours = msecs / 3600000;
|
||||||
msecs %= 3600000;
|
msecs %= 3600000;
|
||||||
mins = msecs / 60000;
|
mins = msecs / 60000;
|
||||||
@ -2954,7 +2881,7 @@ char *stat_eta_new(int msecs)
|
|||||||
return(stat_result);
|
return(stat_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *stat_eta_old(int secs)
|
char *stat_eta(int secs)
|
||||||
{
|
{
|
||||||
static char stat_result[20];
|
static char stat_result[20];
|
||||||
int hours, mins;
|
int hours, mins;
|
||||||
@ -2964,19 +2891,19 @@ char *stat_eta_old(int secs)
|
|||||||
mins = secs / 60;
|
mins = secs / 60;
|
||||||
secs %= 60;
|
secs %= 60;
|
||||||
|
|
||||||
sprintf_s(stat_result, sizeof(stat_result), "%02d:%02d:%02d", hours, mins, secs);
|
sprintf(stat_result, "%02d:%02d:%02d", hours, mins, secs);
|
||||||
return(stat_result);
|
return(stat_result);
|
||||||
}
|
}
|
||||||
#endif /* WITH_SCP_STATS */
|
#endif /* WITH_SCP_STATS */
|
||||||
|
|
||||||
|
#ifdef WIN32_FIXME
|
||||||
char *TranslatePath(char *path, bool *bDirSpec)
|
char *TranslatePath(char *path, bool *bDirSpec)
|
||||||
{
|
{
|
||||||
char temp[MAX_PATH*2];
|
char temp[MAX_PATH * 2];
|
||||||
char resolved[MAX_PATH];
|
char resolved[MAX_PATH];
|
||||||
char * rootpath;
|
char* rootpath;
|
||||||
|
|
||||||
if ( iamremote == 0)
|
if (iamremote == 0)
|
||||||
return path; // if we are scp client, nothing special to do, return path we got.
|
return path; // if we are scp client, nothing special to do, return path we got.
|
||||||
|
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
@ -3007,7 +2934,6 @@ char *TranslatePath(char *path, bool *bDirSpec)
|
|||||||
fixslashes(temp);
|
fixslashes(temp);
|
||||||
PathCanonicalizeA(resolved,temp);
|
PathCanonicalizeA(resolved,temp);
|
||||||
|
|
||||||
|
|
||||||
*bDirSpec = (resolved[strlen(temp)-1] == '\\');
|
*bDirSpec = (resolved[strlen(temp)-1] == '\\');
|
||||||
// Remove trailing slash unless it's a root spec (c:\ etc)
|
// Remove trailing slash unless it's a root spec (c:\ etc)
|
||||||
if (strcmp(&(resolved[1]),":\\") && resolved[strlen(temp)-1] == '\\')
|
if (strcmp(&(resolved[1]),":\\") && resolved[strlen(temp)-1] == '\\')
|
||||||
@ -3033,7 +2959,6 @@ char *TranslatePath(char *path, bool *bDirSpec)
|
|||||||
if (path[0] != '/' && path[0] != '\\')
|
if (path[0] != '/' && path[0] != '\\')
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
|
|
||||||
s = (char *)LocalAlloc(LPTR,strlen(resolved)+1);
|
s = (char *)LocalAlloc(LPTR,strlen(resolved)+1);
|
||||||
strcpy_s(s,strlen(resolved)+1,resolved);
|
strcpy_s(s,strlen(resolved)+1,resolved);
|
||||||
isRootedPath = 1;
|
isRootedPath = 1;
|
||||||
|
@ -109,30 +109,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TODO - Move this to POSIX wrapper**/
|
|
||||||
/* ??? What if fd is nonblocking ???*/
|
|
||||||
int writev(int fd, struct iovec *iov, int iovcnt)
|
|
||||||
{
|
|
||||||
int written = 0;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < iovcnt; i++)
|
|
||||||
{
|
|
||||||
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
|
|
||||||
|
|
||||||
if (ret > 0)
|
|
||||||
{
|
|
||||||
written += ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern volatile sig_atomic_t interrupted;
|
extern volatile sig_atomic_t interrupted;
|
||||||
extern int showprogress;
|
extern int showprogress;
|
||||||
|
|
||||||
@ -1502,15 +1480,19 @@ do_download(struct sftp_conn *conn, const char *remote_path,
|
|||||||
error("Can't set times on \"%s\": %s",
|
error("Can't set times on \"%s\": %s",
|
||||||
local_path, strerror(errno));
|
local_path, strerror(errno));
|
||||||
}
|
}
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
// PRAGMA:TODO
|
|
||||||
if (fsync_flag) {
|
if (fsync_flag) {
|
||||||
debug("syncing \"%s\"", local_path);
|
debug("syncing \"%s\"", local_path);
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if(FlushFileBuffers(local_fd))
|
||||||
|
error("Couldn't sync file \"%s\": %s",
|
||||||
|
local_path, strerror(GetLastError()));
|
||||||
|
#else
|
||||||
if (fsync(local_fd) == -1)
|
if (fsync(local_fd) == -1)
|
||||||
error("Couldn't sync file \"%s\": %s",
|
error("Couldn't sync file \"%s\": %s",
|
||||||
local_path, strerror(errno));
|
local_path, strerror(errno));
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close(local_fd);
|
close(local_fd);
|
||||||
sshbuf_free(msg);
|
sshbuf_free(msg);
|
||||||
@ -1657,15 +1639,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
|
|||||||
|
|
||||||
TAILQ_INIT(&acks);
|
TAILQ_INIT(&acks);
|
||||||
|
|
||||||
#if(0)//def WIN32_FIXME
|
|
||||||
|
|
||||||
if ((local_fd = _open(local_path, O_RDONLY | O_BINARY, 0)) == -1) {
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) {
|
if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) {
|
||||||
|
|
||||||
#endif
|
|
||||||
error("Couldn't open local file \"%s\" for reading: %s",
|
error("Couldn't open local file \"%s\" for reading: %s",
|
||||||
local_path, strerror(errno));
|
local_path, strerror(errno));
|
||||||
return(-1);
|
return(-1);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
void strmode(mode_t mode, char *p);
|
void strmode(mode_t mode, char *p);
|
||||||
void strmode_from_attrib(unsigned attrib, char *p);
|
void strmode_from_attrib(unsigned attrib, char *p);
|
||||||
#endif
|
#endif
|
||||||
@ -225,27 +225,20 @@ ls_file(const char *name, const struct stat *st, int remote, int si_units)
|
|||||||
char sbuf[FMT_SCALED_STRSIZE];
|
char sbuf[FMT_SCALED_STRSIZE];
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
strmode(st->st_mode, mode);
|
|
||||||
#else
|
|
||||||
strmode(st->st_mode, mode);
|
strmode(st->st_mode, mode);
|
||||||
|
#ifdef WINDOWS
|
||||||
strmode_from_attrib(remote, mode);
|
strmode_from_attrib(remote, mode);
|
||||||
#endif
|
#endif
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
user = user_from_uid(st->st_uid, 0);
|
user = user_from_uid(st->st_uid, 0);
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
|
snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
|
||||||
group = gbuf;
|
group = gbuf;
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
|
snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
|
||||||
user = ubuf;
|
user = ubuf;
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
|
|
||||||
snprintf(gbuf, sizeof gbuf, "%u", (u_int) st -> st_gid);
|
snprintf(gbuf, sizeof gbuf, "%u", (u_int) st -> st_gid);
|
||||||
|
|
||||||
group = gbuf;
|
group = gbuf;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (!remote) {
|
if (!remote) {
|
||||||
group = group_from_gid(st->st_gid, 0);
|
group = group_from_gid(st->st_gid, 0);
|
||||||
@ -254,7 +247,6 @@ ls_file(const char *name, const struct stat *st, int remote, int si_units)
|
|||||||
group = gbuf;
|
group = gbuf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ltime != NULL) {
|
if (ltime != NULL) {
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
@ -281,7 +273,7 @@ ls_file(const char *name, const struct stat *st, int remote, int si_units)
|
|||||||
return xstrdup(buf);
|
return xstrdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -297,7 +289,6 @@ strmode_from_attrib(unsigned attrib, char *p)
|
|||||||
*p = '-';
|
*p = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
strmode(mode_t mode, char *p)
|
strmode(mode_t mode, char *p)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32_VS
|
#ifdef WINDOWS
|
||||||
#include "win32_dirent.h"
|
#include "win32_dirent.h"
|
||||||
#else
|
#else
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
#include "sftp-common.h"
|
#include "sftp-common.h"
|
||||||
#include "sftp-client.h"
|
#include "sftp-client.h"
|
||||||
|
|
||||||
#ifdef WIN32_VS
|
#ifdef WINDOWS
|
||||||
#include "win32_dirent.c"
|
#include "win32_dirent.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
77
sftp.c
77
sftp.c
@ -73,10 +73,6 @@ typedef void EditLine;
|
|||||||
#define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
|
#define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
|
||||||
#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
|
#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
#define FAIL(X) if (X) goto fail
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIN32_VS
|
#ifdef WIN32_VS
|
||||||
#include "win32_dirent.h"
|
#include "win32_dirent.h"
|
||||||
#endif
|
#endif
|
||||||
@ -290,17 +286,12 @@ help(void)
|
|||||||
static void
|
static void
|
||||||
local_do_shell(const char *args)
|
local_do_shell(const char *args)
|
||||||
{
|
{
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
|
|
||||||
if (!*args) {
|
if (!*args) {
|
||||||
args = (char *) getenv("ComSpec"); // get name of Windows cmd shell
|
args = (char *) getenv("ComSpec"); // get name of Windows cmd shell
|
||||||
}
|
}
|
||||||
system(args); // execute the shell or cmd given
|
system(args); // execute the shell or cmd given
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
|
||||||
* Original OpenSSH code.
|
|
||||||
*/
|
|
||||||
int status;
|
int status;
|
||||||
char *shell;
|
char *shell;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -823,13 +814,12 @@ do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
|
|||||||
tmp = path_strip(path, strip_path);
|
tmp = path_strip(path, strip_path);
|
||||||
m += strlen(tmp);
|
m += strlen(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
#ifndef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
|
width = ConSetScreenX();
|
||||||
|
#else
|
||||||
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
|
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
|
||||||
width = ws.ws_col;
|
width = ws.ws_col;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
columns = width / (m + 2);
|
columns = width / (m + 2);
|
||||||
columns = MAX(columns, 1);
|
columns = MAX(columns, 1);
|
||||||
colspace = width / columns;
|
colspace = width / columns;
|
||||||
@ -926,14 +916,13 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
#ifndef WIN32_FIXME
|
width = ConSetScreenX();
|
||||||
|
#else
|
||||||
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
|
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
|
||||||
width = ws.ws_col;
|
width = ws.ws_col;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!(lflag & LS_SHORT_VIEW)) {
|
if (!(lflag & LS_SHORT_VIEW)) {
|
||||||
/* Count entries for sort and find longest filename */
|
/* Count entries for sort and find longest filename */
|
||||||
for (i = 0; g.gl_pathv[i]; i++)
|
for (i = 0; g.gl_pathv[i]; i++)
|
||||||
@ -2187,9 +2176,6 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
|
|||||||
static void
|
static void
|
||||||
connect_to_server(char *path, char **args, int *in, int *out)
|
connect_to_server(char *path, char **args, int *in, int *out)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* Original OpenSSH code.
|
|
||||||
*/
|
|
||||||
int c_in, c_out;
|
int c_in, c_out;
|
||||||
|
|
||||||
#ifdef USE_PIPES
|
#ifdef USE_PIPES
|
||||||
@ -2210,9 +2196,9 @@ connect_to_server(char *path, char **args, int *in, int *out)
|
|||||||
c_in = c_out = inout[1];
|
c_in = c_out = inout[1];
|
||||||
#endif /* USE_PIPES */
|
#endif /* USE_PIPES */
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0;
|
||||||
char fullCmd[MAX_PATH] = { 0 };
|
char fullCmd[MAX_PATH] = { 0 };
|
||||||
char ioArg[1024] = { 0 };
|
char ioArg[1024] = { 0 };
|
||||||
PROCESS_INFORMATION pi = { 0 };
|
PROCESS_INFORMATION pi = { 0 };
|
||||||
@ -2220,8 +2206,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
|
|||||||
|
|
||||||
debug3("Generating ssh-client command...");
|
debug3("Generating ssh-client command...");
|
||||||
strncat(fullCmd, path, MAX_PATH);
|
strncat(fullCmd, path, MAX_PATH);
|
||||||
for (i = 1; args[i]; i++)
|
for (i = 1; args[i]; i++) {
|
||||||
{
|
|
||||||
strncat(fullCmd, " ", MAX_PATH);
|
strncat(fullCmd, " ", MAX_PATH);
|
||||||
strncat(fullCmd, args[i], MAX_PATH);
|
strncat(fullCmd, args[i], MAX_PATH);
|
||||||
}
|
}
|
||||||
@ -2332,40 +2317,29 @@ main(int argc, char **argv)
|
|||||||
size_t num_requests = DEFAULT_NUM_REQUESTS;
|
size_t num_requests = DEFAULT_NUM_REQUESTS;
|
||||||
long long limit_kbps = 0;
|
long long limit_kbps = 0;
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WINDOWS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize I/O wrappers.
|
* Initialize I/O wrappers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
w32posix_initialize();
|
w32posix_initialize();
|
||||||
|
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
||||||
sanitise_stdfd();
|
sanitise_stdfd();
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
#endif
|
|
||||||
|
|
||||||
__progname = ssh_get_progname(argv[0]);
|
__progname = ssh_get_progname(argv[0]);
|
||||||
memset(&args, '\0', sizeof(args));
|
memset(&args, '\0', sizeof(args));
|
||||||
args.list = NULL;
|
args.list = NULL;
|
||||||
addargs(&args, "%s", ssh_program);
|
addargs(&args, "%s", ssh_program);
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
|
|
||||||
addargs(&args, "-oForwardX11=no");
|
|
||||||
addargs(&args, "-oForwardAgent=no");
|
|
||||||
addargs(&args, "-oPermitLocalCommand=no");
|
|
||||||
addargs(&args, "-oClearAllForwardings=yes");
|
|
||||||
|
|
||||||
#else
|
|
||||||
addargs(&args, "-oForwardX11 no");
|
addargs(&args, "-oForwardX11 no");
|
||||||
addargs(&args, "-oForwardAgent no");
|
addargs(&args, "-oForwardAgent no");
|
||||||
addargs(&args, "-oPermitLocalCommand no");
|
addargs(&args, "-oPermitLocalCommand no");
|
||||||
addargs(&args, "-oClearAllForwardings yes");
|
addargs(&args, "-oClearAllForwardings yes");
|
||||||
#endif
|
|
||||||
ll = SYSLOG_LEVEL_INFO;
|
ll = SYSLOG_LEVEL_INFO;
|
||||||
infile = stdin;
|
infile = stdin;
|
||||||
|
|
||||||
@ -2393,16 +2367,7 @@ main(int argc, char **argv)
|
|||||||
addargs(&args, "-%c", ch);
|
addargs(&args, "-%c", ch);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
|
|
||||||
addargs(&args, "-oPort=%s", optarg);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
addargs(&args, "-oPort %s", optarg);
|
addargs(&args, "-oPort %s", optarg);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
if (debug_level < 3) {
|
if (debug_level < 3) {
|
||||||
@ -2437,16 +2402,7 @@ main(int argc, char **argv)
|
|||||||
fatal("%s (%s).", strerror(errno), optarg);
|
fatal("%s (%s).", strerror(errno), optarg);
|
||||||
showprogress = 0;
|
showprogress = 0;
|
||||||
quiet = batchmode = 1;
|
quiet = batchmode = 1;
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
|
|
||||||
addargs(&args, "-obatchmode=yes");
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
addargs(&args, "-obatchmode yes");
|
addargs(&args, "-obatchmode yes");
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
global_fflag = 1;
|
global_fflag = 1;
|
||||||
@ -2520,17 +2476,8 @@ main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Missing hostname\n");
|
fprintf(stderr, "Missing hostname\n");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
|
|
||||||
addargs(&args, "-oProtocol=%d", sshver);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
addargs(&args, "-oProtocol %d", sshver);
|
addargs(&args, "-oProtocol %d", sshver);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* no subsystem if the server-spec contains a '/' */
|
/* no subsystem if the server-spec contains a '/' */
|
||||||
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
|
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
|
||||||
addargs(&args, "-s");
|
addargs(&args, "-s");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user