mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 08:14:24 +02:00
SFTP fixes
1.Fixed df command that shows the disk space utilization. 2.Fixed the realpath to take care of edge cases where path size is less than 2. 3.Fixed the "dir " bug 4.Fixed the "dir e:\test" bug 5.Fixed the memory leak in wmain_sshd.c
This commit is contained in:
parent
743a94da26
commit
144ece5347
@ -37,6 +37,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <Shlwapi.h>
|
#include <Shlwapi.h>
|
||||||
#include "misc_internal.h"
|
#include "misc_internal.h"
|
||||||
|
#include "inc\dlfcn.h"
|
||||||
|
|
||||||
int usleep(unsigned int useconds)
|
int usleep(unsigned int useconds)
|
||||||
{
|
{
|
||||||
@ -114,51 +115,6 @@ explicit_bzero(void *b, size_t len) {
|
|||||||
SecureZeroMemory(b, len);
|
SecureZeroMemory(b, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int statvfs(const char *path, struct statvfs *buf) {
|
|
||||||
DWORD sectorsPerCluster;
|
|
||||||
DWORD bytesPerSector;
|
|
||||||
DWORD freeClusters;
|
|
||||||
DWORD totalClusters;
|
|
||||||
|
|
||||||
if (GetDiskFreeSpace(path, §orsPerCluster, &bytesPerSector,
|
|
||||||
&freeClusters, &totalClusters) == TRUE)
|
|
||||||
{
|
|
||||||
debug3("path : [%s]", path);
|
|
||||||
debug3("sectorsPerCluster : [%lu]", sectorsPerCluster);
|
|
||||||
debug3("bytesPerSector : [%lu]", bytesPerSector);
|
|
||||||
debug3("bytesPerCluster : [%lu]", sectorsPerCluster * bytesPerSector);
|
|
||||||
debug3("freeClusters : [%lu]", freeClusters);
|
|
||||||
debug3("totalClusters : [%lu]", totalClusters);
|
|
||||||
|
|
||||||
buf->f_bsize = sectorsPerCluster * bytesPerSector;
|
|
||||||
buf->f_frsize = sectorsPerCluster * bytesPerSector;
|
|
||||||
buf->f_blocks = totalClusters;
|
|
||||||
buf->f_bfree = freeClusters;
|
|
||||||
buf->f_bavail = freeClusters;
|
|
||||||
buf->f_files = -1;
|
|
||||||
buf->f_ffree = -1;
|
|
||||||
buf->f_favail = -1;
|
|
||||||
buf->f_fsid = 0;
|
|
||||||
buf->f_flag = 0;
|
|
||||||
buf->f_namemax = MAX_PATH - 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
debug3("ERROR: Cannot get free space for [%s]. Error code is : %d.\n",
|
|
||||||
path, GetLastError());
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int fstatvfs(int fd, struct statvfs *buf) {
|
|
||||||
errno = ENOTSUP;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "inc\dlfcn.h"
|
|
||||||
HMODULE dlopen(const char *filename, int flags) {
|
HMODULE dlopen(const char *filename, int flags) {
|
||||||
return LoadLibraryA(filename);
|
return LoadLibraryA(filename);
|
||||||
}
|
}
|
||||||
@ -655,7 +611,7 @@ char *
|
|||||||
realpath(const char *path, char resolved[MAX_PATH]) {
|
realpath(const char *path, char resolved[MAX_PATH]) {
|
||||||
char tempPath[MAX_PATH];
|
char tempPath[MAX_PATH];
|
||||||
|
|
||||||
if (*path == '/' && *(path + 2) == ':')
|
if ( (strlen(path) >= 2) && (path[0] == '/') && (path[2] == ':') )
|
||||||
strncpy(resolved, path + 1, strlen(path)); // skip the first '/'
|
strncpy(resolved, path + 1, strlen(path)); // skip the first '/'
|
||||||
else
|
else
|
||||||
strncpy(resolved, path, strlen(path) + 1);
|
strncpy(resolved, path, strlen(path) + 1);
|
||||||
@ -679,7 +635,6 @@ realpath(const char *path, char resolved[MAX_PATH]) {
|
|||||||
#define IO_REPARSE_TAG_SIS (0x80000007L) // winnt ntifs
|
#define IO_REPARSE_TAG_SIS (0x80000007L) // winnt ntifs
|
||||||
#define REPARSE_MOUNTPOINT_HEADER_SIZE 8
|
#define REPARSE_MOUNTPOINT_HEADER_SIZE 8
|
||||||
|
|
||||||
|
|
||||||
typedef struct _REPARSE_DATA_BUFFER {
|
typedef struct _REPARSE_DATA_BUFFER {
|
||||||
ULONG ReparseTag;
|
ULONG ReparseTag;
|
||||||
USHORT ReparseDataLength;
|
USHORT ReparseDataLength;
|
||||||
@ -779,3 +734,50 @@ ResolveLink(wchar_t * tLink, wchar_t *ret, DWORD * plen, DWORD Flags) {
|
|||||||
CloseHandle(fileHandle);
|
CloseHandle(fileHandle);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int statvfs(const char *path, struct statvfs *buf) {
|
||||||
|
DWORD sectorsPerCluster;
|
||||||
|
DWORD bytesPerSector;
|
||||||
|
DWORD freeClusters;
|
||||||
|
DWORD totalClusters;
|
||||||
|
|
||||||
|
wchar_t* path_utf16 = utf8_to_utf16(sanitized_path(path));
|
||||||
|
if (GetDiskFreeSpaceW(path_utf16, §orsPerCluster, &bytesPerSector,
|
||||||
|
&freeClusters, &totalClusters) == TRUE)
|
||||||
|
{
|
||||||
|
debug3("path : [%s]", path);
|
||||||
|
debug3("sectorsPerCluster : [%lu]", sectorsPerCluster);
|
||||||
|
debug3("bytesPerSector : [%lu]", bytesPerSector);
|
||||||
|
debug3("bytesPerCluster : [%lu]", sectorsPerCluster * bytesPerSector);
|
||||||
|
debug3("freeClusters : [%lu]", freeClusters);
|
||||||
|
debug3("totalClusters : [%lu]", totalClusters);
|
||||||
|
|
||||||
|
buf->f_bsize = sectorsPerCluster * bytesPerSector;
|
||||||
|
buf->f_frsize = sectorsPerCluster * bytesPerSector;
|
||||||
|
buf->f_blocks = totalClusters;
|
||||||
|
buf->f_bfree = freeClusters;
|
||||||
|
buf->f_bavail = freeClusters;
|
||||||
|
buf->f_files = -1;
|
||||||
|
buf->f_ffree = -1;
|
||||||
|
buf->f_favail = -1;
|
||||||
|
buf->f_fsid = 0;
|
||||||
|
buf->f_flag = 0;
|
||||||
|
buf->f_namemax = MAX_PATH - 1;
|
||||||
|
|
||||||
|
free(path_utf16);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug3("ERROR: Cannot get free space for [%s]. Error code is : %d.\n",
|
||||||
|
path, GetLastError());
|
||||||
|
|
||||||
|
free(path_utf16);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fstatvfs(int fd, struct statvfs *buf) {
|
||||||
|
errno = ENOTSUP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -112,8 +112,12 @@ int sshd_main(int argc, wchar_t **wargv) {
|
|||||||
w32posix_initialize();
|
w32posix_initialize();
|
||||||
if (getenv("SSHD_REMSOC"))
|
if (getenv("SSHD_REMSOC"))
|
||||||
is_child = 1;
|
is_child = 1;
|
||||||
|
|
||||||
/* change current directory to sshd.exe root */
|
/* change current directory to sshd.exe root */
|
||||||
_wchdir(utf8_to_utf16(w32_programdir()));
|
wchar_t* path_utf16 = utf8_to_utf16(w32_programdir());
|
||||||
|
_wchdir(path_utf16);
|
||||||
|
free(path_utf16);
|
||||||
|
|
||||||
return main(argc, argv);
|
return main(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
sftp.c
10
sftp.c
@ -322,10 +322,14 @@ local_do_shell(const char *args)
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
/* execute via system call in Windows*/
|
/* execute via system call in Windows*/
|
||||||
if (!*args) {
|
if (!*args) {
|
||||||
/* TODO - support unicode ComSpec */
|
|
||||||
args = (char *) getenv("ComSpec"); // get name of Windows cmd shell
|
args = (char *) getenv("ComSpec"); // get name of Windows cmd shell
|
||||||
|
} else {
|
||||||
|
convertToBackslash((char *) args);
|
||||||
}
|
}
|
||||||
system(args); // execute the shell or cmd given
|
|
||||||
|
wchar_t* path_utf16 = utf8_to_utf16(args);
|
||||||
|
_wsystem(path_utf16); // execute the shell or cmd given
|
||||||
|
free(path_utf16);
|
||||||
#else /* !WINDOWS */
|
#else /* !WINDOWS */
|
||||||
int status;
|
int status;
|
||||||
char *shell;
|
char *shell;
|
||||||
@ -1513,7 +1517,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
|
|||||||
* convert '\\' to '/' in Windows styled paths.
|
* convert '\\' to '/' in Windows styled paths.
|
||||||
* else they get treated as escape sequence in makeargv
|
* else they get treated as escape sequence in makeargv
|
||||||
*/
|
*/
|
||||||
convertToForwardslash(cmd);
|
convertToForwardslash((char *)cmd);
|
||||||
#endif
|
#endif
|
||||||
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
||||||
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user