Skip to content

Commit 332890c

Browse files
committed
WinSCP client now works with win32 sftp-server as readlink now supported in Win32 sftp-server
process_readlink() now implemented in Win32 sftp-server and linked directories can now be read and browsed. as a result opensource WinSCP client ( it has SFTP and SCP gui clients ) now works with our Win32 sftp-server.
1 parent 8c92d7b commit 332890c

File tree

2 files changed

+30
-51
lines changed

2 files changed

+30
-51
lines changed

sftp-common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,11 @@ char * get_inside_path(char * opath, BOOL bResolve, BOOL bMustExist)
559559

560560
return ipath;
561561
}
562+
563+
// if file is symbolic link, copy its link into "link" .
564+
int readlink(const char *path, char *link, int linklen)
565+
{
566+
strcpy_s(link, linklen, path);
567+
return 0;
568+
}
562569
#endif

sftp-server.c

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#ifdef WIN32_FIXME
2525
#undef GSSAPI
2626
#undef KRB5
27+
28+
#define true 1
29+
#define false 0
30+
2731
#endif
2832

2933
#include <sys/param.h> /* MIN */
@@ -98,6 +102,7 @@
98102
#define stat(PATH, BUF) _stat(PATH, BUF)
99103

100104
char * get_inside_path(char *, BOOL, BOOL);
105+
int readlink(const char *path, char *link, int linklen);
101106

102107
/*
103108
* Function to cut last slash (windows
@@ -1521,31 +1526,6 @@ if (realpathWin32i(newpath, resolvedname))
15211526
static void
15221527
process_readlink(u_int32_t id)
15231528
{
1524-
#ifdef WIN32_FIXME
1525-
1526-
/*
1527-
* Win32 code.
1528-
*/
1529-
1530-
//u_int32_t id;
1531-
1532-
char *request;
1533-
1534-
//id = get_int();
1535-
#ifndef WIN32_FIXME
1536-
// PRAGMA:TODO
1537-
request = get_string(NULL);
1538-
1539-
send_status(id, SSH2_FX_OP_UNSUPPORTED);
1540-
1541-
free(request);
1542-
#endif
1543-
1544-
#else
1545-
1546-
/*
1547-
* Original OpenSSH code.
1548-
*/
15491529
int r, len;
15501530
char buf[PATH_MAX];
15511531
char *path;
@@ -1555,6 +1535,16 @@ process_readlink(u_int32_t id)
15551535

15561536
debug3("request %u: readlink", id);
15571537
verbose("readlink \"%s\"", path);
1538+
1539+
#ifdef WIN32_FIXME
1540+
char resolvedname[MAXPATHLEN];
1541+
if (realpathWin32i(path, resolvedname))
1542+
{
1543+
free(path);
1544+
path = strdup(resolvedname);
1545+
}
1546+
#endif
1547+
15581548
if ((len = readlink(path, buf, sizeof(buf) - 1)) == -1)
15591549
send_status(id, errno_to_portable(errno));
15601550
else {
@@ -1566,37 +1556,13 @@ process_readlink(u_int32_t id)
15661556
send_names(id, 1, &s);
15671557
}
15681558
free(path);
1569-
#endif /* WIN32_FIXME */
1559+
15701560
}
15711561

15721562
static void
15731563
process_symlink(u_int32_t id)
15741564
{
1575-
#ifdef WIN32_FIXME
1576-
1577-
/*
1578-
* Win32 code.
1579-
*/
1580-
1581-
//u_int32_t id;
1582-
1583-
char *request;
15841565

1585-
//id = get_int();
1586-
#ifndef WIN32_FIXME
1587-
// PRAGMA:TODO
1588-
request = get_string(NULL);
1589-
1590-
send_status(id, SSH2_FX_OP_UNSUPPORTED);
1591-
1592-
free(request);
1593-
#endif
1594-
1595-
#else
1596-
1597-
/*
1598-
* Original OpenSSH code.
1599-
*/
16001566
char *oldpath, *newpath;
16011567
int r, status;
16021568

@@ -1606,13 +1572,19 @@ process_symlink(u_int32_t id)
16061572

16071573
debug3("request %u: symlink", id);
16081574
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath);
1575+
1576+
#ifdef WIN32_FIXME
1577+
send_status(id, SSH2_FX_OP_UNSUPPORTED);
1578+
#else
1579+
16091580
/* this will fail if 'newpath' exists */
16101581
r = symlink(oldpath, newpath);
16111582
status = (r == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
16121583
send_status(id, status);
1584+
#endif
1585+
16131586
free(oldpath);
16141587
free(newpath);
1615-
#endif
16161588
}
16171589

16181590
static void

0 commit comments

Comments
 (0)