sftp-server running on windows writes incoming file from linux client… (#502)

This commit is contained in:
vthiebaut10 2021-04-28 17:56:51 -04:00 committed by GitHub
parent cd1e7d6f9d
commit 83927cbe02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -81,7 +81,7 @@ if (Test-Path $sshAgentRegPath)
$moduliPath = Join-Path $PSScriptRoot "moduli"
if (Test-Path $moduliPath -PathType Leaf)
{
Repair-ModuliFilePermission -FilePath $moduliPath @psBoundParameters
Repair-ModuliFilePermission -FilePath $moduliPath @psBoundParameters -confirm:$false
}
#register etw provider

View File

@ -673,6 +673,37 @@ WriteCompletionRoutine(_In_ DWORD dwErrorCode,
*((__int64*)&lpOverlapped->Offset) += dwNumberOfBytesTransfered;
}
int
fileio_write_wrapper(struct w32_io* pio, const void* buf, size_t bytes_to_copy)
{
int bytes_written = 0;
if (bytes_to_copy <= WRITE_BUFFER_SIZE) {
bytes_written = fileio_write(pio, buf, bytes_to_copy);
return bytes_written;
}
void* chunk_buf = NULL;
int chunk_count = 0;
int bytes_copied = -1;
int chunk_size = 0;
for (int i = 0; i < bytes_to_copy; i += WRITE_BUFFER_SIZE, chunk_count++) {
chunk_buf = (BYTE*)buf + chunk_count * WRITE_BUFFER_SIZE;
chunk_size = ((bytes_to_copy - i) >= WRITE_BUFFER_SIZE) ? WRITE_BUFFER_SIZE : (bytes_to_copy - i);
bytes_written = fileio_write(pio, chunk_buf, chunk_size);
if (bytes_written == -1)
return bytes_copied;
if (bytes_copied == -1)
bytes_copied = 0;
bytes_copied += bytes_written;
}
return bytes_copied;
}
/* write() implementation */
int
fileio_write(struct w32_io* pio, const void *buf, size_t max_bytes)

View File

@ -558,7 +558,7 @@ w32_write(int fd, const void *buf, size_t max)
if (fd_table.w32_ios[fd]->type == SOCK_FD)
return socketio_send(fd_table.w32_ios[fd], buf, max, 0);
return fileio_write(fd_table.w32_ios[fd], buf, max);
return fileio_write_wrapper(fd_table.w32_ios[fd], buf, max);
}
int

View File

@ -158,6 +158,7 @@ struct w32_io* fileio_afunix_socket();
int fileio_connect(struct w32_io*, char*);
struct w32_io* fileio_open(const char *pathname, int flags, mode_t mode);
int fileio_read(struct w32_io* pio, void *dst, size_t max);
int fileio_write_wrapper(struct w32_io* pio, const void* buf, size_t bytes_to_copy);
int fileio_write(struct w32_io* pio, const void *buf, size_t max);
int fileio_fstat(struct w32_io* pio, struct _stat64 *buf);
int fileio_stat(const char *path, struct _stat64 *buf);