mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-27 16:04:46 +02:00
Add multiple ../../.. support in sftp-server for changing directories or get/put
Before one could provide only one .. ; now it can be any numbers. cd ../../.. or get ../backup/myfile.c --- all these formations now work.
This commit is contained in:
parent
39c00bff7e
commit
6301972e69
@ -203,43 +203,34 @@ realpath(const char *path, char resolved[PATH_MAX])
|
||||
|
||||
#else
|
||||
|
||||
void backslashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '/')
|
||||
*str = '\\'; // convert forward slash to back slash
|
||||
str++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// convert back slash to forward slash
|
||||
void slashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '\\')
|
||||
*str = '/'; // convert back slash to forward slash
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
char *realpathWin32(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
size_t path_len;
|
||||
unsigned int lastSlash;
|
||||
char realpath[PATH_MAX];
|
||||
char * pch;
|
||||
|
||||
path_len = strlcpy(realpath, path+1, sizeof(realpath));
|
||||
|
||||
char * pchMac;
|
||||
pchMac = strstr (realpath, "._");
|
||||
if (pchMac != NULL)
|
||||
{
|
||||
pchMac[0] = '\0';
|
||||
pchMac++;
|
||||
pchMac++;
|
||||
strcat(realpath, pchMac);
|
||||
}
|
||||
|
||||
pch = strrchr(realpath, '/');
|
||||
lastSlash = pch - realpath + 1;
|
||||
if(path_len == lastSlash)
|
||||
{
|
||||
realpath[lastSlash-1] = '\0';
|
||||
}
|
||||
|
||||
pch = strrchr(realpath,'.');
|
||||
if(pch != NULL)
|
||||
{
|
||||
if (realpath[pch-realpath - 1] == '.')
|
||||
{
|
||||
realpath[pch - realpath - 2] = '\0';
|
||||
pch = strrchr(realpath, '/');
|
||||
if(pch != NULL)
|
||||
realpath[pch - realpath] = '\0';
|
||||
}
|
||||
}
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
@ -256,48 +247,21 @@ char *realpathWin32(const char *path, char resolved[PATH_MAX])
|
||||
return resolved;
|
||||
}
|
||||
|
||||
// like realpathWin32() but takes out the first slash so that windows systems can work on the actual file or directory
|
||||
char *realpathWin32i(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
size_t path_len;
|
||||
unsigned int lastSlash;
|
||||
char realpath[PATH_MAX];
|
||||
char * pch;
|
||||
|
||||
if (path[0] != '/') {
|
||||
// absolute form x:/abc/def given, no first slash to take out
|
||||
path_len = strlcpy(realpath, path, sizeof(realpath));
|
||||
strlcpy(resolved, path, sizeof(realpath));
|
||||
}
|
||||
else
|
||||
path_len = strlcpy(realpath, path + 1, sizeof(realpath));
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
|
||||
char * pchMac;
|
||||
pchMac = strstr(realpath, "._");
|
||||
if (pchMac != NULL)
|
||||
{
|
||||
pchMac[0] = '\0';
|
||||
pchMac++;
|
||||
pchMac++;
|
||||
strcat(realpath, pchMac);
|
||||
}
|
||||
|
||||
pch = strrchr(realpath, '/');
|
||||
lastSlash = pch - realpath + 1;
|
||||
if (path_len == lastSlash)
|
||||
{
|
||||
realpath[lastSlash - 1] = '\0';
|
||||
}
|
||||
|
||||
pch = strrchr(realpath, '.');
|
||||
if (pch != NULL)
|
||||
{
|
||||
if (realpath[pch - realpath - 1] == '.')
|
||||
{
|
||||
realpath[pch - realpath - 2] = '\0';
|
||||
pch = strrchr(realpath, '/');
|
||||
if (pch != NULL)
|
||||
realpath[pch - realpath] = '\0';
|
||||
}
|
||||
}
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
|
Loading…
x
Reference in New Issue
Block a user