mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 14:04:59 +02:00
Made sftp.exe functional
This commit is contained in:
parent
31ed6d1458
commit
2854245328
@ -397,6 +397,7 @@ VOID CALLBACK WriteCompletionRoutine(
|
||||
abort();
|
||||
pio->write_details.remaining -= dwNumberOfBytesTransfered;
|
||||
pio->write_details.pending = FALSE;
|
||||
*((__int64*)&lpOverlapped->Offset) += dwNumberOfBytesTransfered;
|
||||
}
|
||||
|
||||
/* write() implementation */
|
||||
@ -507,6 +508,18 @@ fileio_stat(const char *path, struct _stat64 *buf) {
|
||||
return _stat64(path, buf);
|
||||
}
|
||||
|
||||
long
|
||||
fileio_lseek(struct w32_io* pio, long offset, int origin) {
|
||||
int fd = _open_osfhandle((intptr_t)pio->handle, 0);
|
||||
debug2("pio:%p", pio);
|
||||
if (fd == -1) {
|
||||
errno = EOTHER;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return _lseek(fd, offset, origin);
|
||||
}
|
||||
|
||||
/* isatty() implementation */
|
||||
int
|
||||
fileio_isatty(struct w32_io* pio) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#define sleep(sec) Sleep(1000 * sec)
|
||||
#define alarm w32_alarm
|
||||
#define lseek w32_lseek
|
||||
|
||||
/* Compatibility header to avoid lots of #ifdefs in includes.h on Win32 */
|
||||
|
||||
|
@ -48,6 +48,8 @@ int w32_read(int fd, void *dst, unsigned int max);
|
||||
int w32_write(int fd, const void *buf, unsigned int max);
|
||||
int w32_fstat(int fd, struct w32_stat *buf);
|
||||
int w32_stat(const char *path, struct w32_stat *buf);
|
||||
long w32_lseek( int fd, long offset, int origin);
|
||||
|
||||
int w32_isatty(int fd);
|
||||
FILE* w32_fdopen(int fd, const char *mode);
|
||||
int w32_mkdir(const char *pathname, unsigned short mode);
|
||||
|
@ -353,6 +353,12 @@ w32_stat(const char *path, struct w32_stat *buf) {
|
||||
return fileio_stat(path, (struct _stat64*)buf);
|
||||
}
|
||||
|
||||
long
|
||||
w32_lseek(int fd, long offset, int origin) {
|
||||
CHECK_FD(fd);
|
||||
return fileio_lseek(fd_table.w32_ios[fd], offset, origin);
|
||||
}
|
||||
|
||||
int
|
||||
w32_mkdir(const char *pathname, unsigned short mode) {
|
||||
return _mkdir(pathname);
|
||||
|
@ -116,6 +116,7 @@ int fileio_read(struct w32_io* pio, void *dst, unsigned int max);
|
||||
int fileio_write(struct w32_io* pio, const void *buf, unsigned int max);
|
||||
int fileio_fstat(struct w32_io* pio, struct _stat64 *buf);
|
||||
int fileio_stat(const char *path, struct _stat64 *buf);
|
||||
long fileio_lseek(struct w32_io* pio, long offset, int origin);
|
||||
int fileio_isatty(struct w32_io* pio);
|
||||
FILE* fileio_fdopen(struct w32_io* pio, const char *mode);
|
||||
|
||||
|
68
readpass.c
68
readpass.c
@ -334,41 +334,57 @@ read_passphrase(const char *prompt, int flags)
|
||||
/*
|
||||
* Show prompt for user.
|
||||
*/
|
||||
HANDLE c_in = CreateFileA("CONIN$", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
|
||||
HANDLE c_out = CreateFileA("CONOUT$", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
|
||||
int tmp;
|
||||
int originalMode, tmpMode;
|
||||
|
||||
write(STDOUT_FILENO, prompt, strlen(prompt));
|
||||
GetConsoleMode(c_in, &originalMode);
|
||||
SetConsoleMode(c_in, ENABLE_LINE_INPUT);
|
||||
//SetConsoleMode(c_in, (originalMode & ~(ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT)));
|
||||
|
||||
len = retr = 0;
|
||||
int bufsize = sizeof(buf);
|
||||
GetConsoleMode(c_in, &tmpMode);
|
||||
|
||||
while (_kbhit())
|
||||
_getch();
|
||||
WriteFile(c_out, prompt, strlen(prompt), &tmp, NULL);
|
||||
// write(STDOUT_FILENO, prompt, strlen(prompt));
|
||||
ReadFile(c_in, buf, 1024, &tmp, NULL);
|
||||
buf[tmp - 2] = '\0';
|
||||
SetConsoleMode(c_in, originalMode);
|
||||
CloseHandle(c_in);
|
||||
CloseHandle(c_out);
|
||||
|
||||
while ( len < bufsize ) {
|
||||
// len = retr = 0;
|
||||
// int bufsize = sizeof(buf);
|
||||
|
||||
buf[len] = (unsigned char) _getch() ;
|
||||
//while (_kbhit())
|
||||
// _getch();
|
||||
|
||||
//while ( len < bufsize ) {
|
||||
|
||||
// buf[len] = (unsigned char) _getch() ;
|
||||
|
||||
|
||||
if ( buf[len] == '\r' ) {
|
||||
if (_kbhit() )
|
||||
_getch(); // read linefeed if its there
|
||||
break;
|
||||
}
|
||||
else if ( buf[len] == '\n' ) {
|
||||
break;
|
||||
}
|
||||
else if ( buf[len] == '\b' ) { // backspace
|
||||
if (len > 0 )
|
||||
len--; // overwrite last character
|
||||
}
|
||||
else {
|
||||
// if ( buf[len] == '\r' ) {
|
||||
// if (_kbhit() )
|
||||
// _getch(); // read linefeed if its there
|
||||
// break;
|
||||
// }
|
||||
// else if ( buf[len] == '\n' ) {
|
||||
// break;
|
||||
// }
|
||||
// else if ( buf[len] == '\b' ) { // backspace
|
||||
// if (len > 0 )
|
||||
// len--; // overwrite last character
|
||||
// }
|
||||
// else {
|
||||
|
||||
//_putch( (int) '*' ); // show a star in place of what is typed
|
||||
len++; // keep reading in the loop
|
||||
}
|
||||
}
|
||||
// //_putch( (int) '*' ); // show a star in place of what is typed
|
||||
// len++; // keep reading in the loop
|
||||
// }
|
||||
//}
|
||||
|
||||
buf[len] = '\0' ; // get rid of the cr/lf
|
||||
write(STDOUT_FILENO,"\n", strlen("\n")); // show a newline as we do not echo password or the line
|
||||
//buf[len] = '\0' ; // get rid of the cr/lf
|
||||
//write(STDOUT_FILENO,"\n", strlen("\n")); // show a newline as we do not echo password or the line
|
||||
|
||||
ret = xstrdup(buf);
|
||||
|
||||
|
@ -1556,7 +1556,7 @@ do_download(struct sftp_conn *conn, const char *remote_path,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef WIN32_FIXME
|
||||
#if(0)//def WIN32_FIXME
|
||||
|
||||
_close(local_fd);
|
||||
|
||||
|
6
sftp.c
6
sftp.c
@ -75,11 +75,11 @@ typedef void EditLine;
|
||||
|
||||
#ifdef WIN32_FIXME
|
||||
|
||||
#define mkdir(a, b) _mkdir(a)
|
||||
// #define mkdir(a, b) _mkdir(a)
|
||||
|
||||
#define FAIL(X) if (X) goto fail
|
||||
|
||||
extern int sfd_start;
|
||||
//extern int sfd_start;
|
||||
|
||||
#endif
|
||||
|
||||
@ -2308,8 +2308,6 @@ connect_to_server(char *path, char **args, int *in, int *out)
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
si.hStdInput = sfd_to_handle(sockout[0]);
|
||||
si.hStdOutput = sfd_to_handle(sockin[1]);//GetStdHandle(STD_OUTPUT_HANDLE);//sfd_to_handle(sockin[1]);
|
||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.dwFlags = STARTF_USESTDHANDLES;
|
||||
|
Loading…
x
Reference in New Issue
Block a user