Skip to content

Commit 367476c

Browse files
committed
Temporary fixes in scp.exe to have a working solution
1 parent 27d9e5b commit 367476c

File tree

2 files changed

+81
-15
lines changed

2 files changed

+81
-15
lines changed

contrib/win32/openssh/Win32-OpenSSH.sln

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.24720.0
4+
VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssh", "ssh.vcxproj", "{74E69D5E-A1EF-46EA-9173-19A412774104}"
77
ProjectSection(ProjectDependencies) = postProject
@@ -95,6 +95,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssh-add", "ssh-add.vcxproj"
9595
{8660C2FE-9874-432D-B047-E042BB41DBE0} = {8660C2FE-9874-432D-B047-E042BB41DBE0}
9696
EndProjectSection
9797
EndProject
98+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scp", "scp.vcxproj", "{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}"
99+
ProjectSection(ProjectDependencies) = postProject
100+
{05E1115F-8529-46D0-AAAF-52A404CE79A7} = {05E1115F-8529-46D0-AAAF-52A404CE79A7}
101+
{8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} = {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4}
102+
{DD483F7D-C553-4740-BC1A-903805AD0174} = {DD483F7D-C553-4740-BC1A-903805AD0174}
103+
{0D02F0F0-013B-4EE3-906D-86517F3822C0} = {0D02F0F0-013B-4EE3-906D-86517F3822C0}
104+
{8660C2FE-9874-432D-B047-E042BB41DBE0} = {8660C2FE-9874-432D-B047-E042BB41DBE0}
105+
EndProjectSection
106+
EndProject
98107
Global
99108
GlobalSection(SolutionConfigurationPlatforms) = preSolution
100109
Debug|x64 = Debug|x64
@@ -223,6 +232,14 @@ Global
223232
{029797FF-C986-43DE-95CD-2E771E86AEBC}.Release|x64.Build.0 = Release|x64
224233
{029797FF-C986-43DE-95CD-2E771E86AEBC}.Release|x86.ActiveCfg = Release|Win32
225234
{029797FF-C986-43DE-95CD-2E771E86AEBC}.Release|x86.Build.0 = Release|Win32
235+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Debug|x64.ActiveCfg = Debug|x64
236+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Debug|x64.Build.0 = Debug|x64
237+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Debug|x86.ActiveCfg = Debug|Win32
238+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Debug|x86.Build.0 = Debug|Win32
239+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Release|x64.ActiveCfg = Release|x64
240+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Release|x64.Build.0 = Release|x64
241+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Release|x86.ActiveCfg = Release|Win32
242+
{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}.Release|x86.Build.0 = Release|Win32
226243
EndGlobalSection
227244
GlobalSection(SolutionProperties) = preSolution
228245
HideSolutionNode = FALSE

scp.c

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,59 @@ do_local_cmd(arglist *a)
708708
#endif
709709
}
710710

711+
static int pipe_counter = 1;
712+
/* create overlapped supported pipe */
713+
BOOL CreateOverlappedPipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES sa, DWORD size) {
714+
HANDLE read_handle = INVALID_HANDLE_VALUE, write_handle = INVALID_HANDLE_VALUE;
715+
char pipe_name[MAX_PATH];
716+
717+
/* create name for named pipe */
718+
if (-1 == sprintf_s(pipe_name, MAX_PATH, "\\\\.\\Pipe\\W32SCPPipe.%08x.%08x",
719+
GetCurrentProcessId(), pipe_counter++)) {
720+
debug("pipe - ERROR sprintf_s %d", errno);
721+
goto error;
722+
}
723+
724+
read_handle = CreateNamedPipeA(pipe_name,
725+
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
726+
PIPE_TYPE_BYTE | PIPE_WAIT,
727+
1,
728+
4096,
729+
4096,
730+
0,
731+
sa);
732+
if (read_handle == INVALID_HANDLE_VALUE) {
733+
debug("pipe - CreateNamedPipe() ERROR:%d", errno);
734+
goto error;
735+
}
736+
737+
/* connect to named pipe */
738+
write_handle = CreateFileA(pipe_name,
739+
GENERIC_WRITE,
740+
0,
741+
sa,
742+
OPEN_EXISTING,
743+
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
744+
NULL);
745+
if (write_handle == INVALID_HANDLE_VALUE) {
746+
debug("pipe - ERROR CreateFile() :%d", errno);
747+
goto error;
748+
}
749+
750+
*hReadPipe = read_handle;
751+
*hWritePipe = write_handle;
752+
return TRUE;
753+
754+
error:
755+
if (read_handle)
756+
CloseHandle(read_handle);
757+
if (write_handle)
758+
CloseHandle(write_handle);
759+
760+
return FALSE;
761+
762+
}
763+
711764
/*
712765
* This function executes the given command as the specified user on the
713766
* given host. This returns < 0 if execution fails, and >= 0 otherwise. This
@@ -814,7 +867,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
814867
sa.lpSecurityDescriptor = NULL;
815868
/* command processor output redirected to a nameless pipe */
816869

817-
rc = CreatePipe ( &hstdout[0], &hstdout[1], &sa, 0 ) ;
870+
rc = CreateOverlappedPipe( &hstdout[0], &hstdout[1], &sa, 0 ) ;
818871
/* read from this fd to get data from ssh.exe*/
819872

820873
// make scp's pipe read handle not inheritable by ssh
@@ -830,7 +883,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
830883
*fdin = _open_osfhandle((intptr_t)hstdout[0],0);
831884
_setmode (*fdin, O_BINARY); // set this file handle for binary I/O
832885

833-
rc = CreatePipe ( &hstdin[0], &hstdin[1], &sa, 0 ) ;
886+
rc = CreateOverlappedPipe( &hstdin[0], &hstdin[1], &sa, 0 ) ;
834887
/* write to this fd to get data into ssh.exe*/
835888

836889
// make scp's pipe write handle not inheritable by ssh
@@ -1033,11 +1086,7 @@ int pflag, iamremote, iamrecursive, targetshouldbedirectory;
10331086
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
10341087

10351088
int response(void);
1036-
#ifdef WIN32_FIXME
1037-
void rsource(char *, struct _stati64 *);
1038-
#else
10391089
void rsource(char *, struct stat *);
1040-
#endif
10411090

10421091
void sink(int, char *[]);
10431092
void source(int, char *[]);
@@ -1439,7 +1488,7 @@ tolocal(int argc, char **argv)
14391488
void
14401489
source(int argc, char *argv[])
14411490
{
1442-
struct _stati64 stb;
1491+
struct stat stb;
14431492
static BUF buffer;
14441493
BUF *bp;
14451494
off_t i;
@@ -1520,7 +1569,7 @@ source(int argc, char *argv[])
15201569

15211570
if (_sopen_s(&fd, name, O_RDONLY | O_BINARY, _SH_DENYNO, 0) != 0) {
15221571
// in NT, we have to check if it is a directory
1523-
if (_stati64(name, &stb) >= 0) {
1572+
if (stat(name, &stb) >= 0) {
15241573
goto switchpoint;
15251574
}
15261575
else
@@ -1692,7 +1741,7 @@ next: if (fd != -1) (void)_close(fd);
16921741
free(filenames[ii]);
16931742
}
16941743

1695-
void rsource(char *name, struct _stati64 *statp)
1744+
void rsource(char *name, struct stat *statp)
16961745
{
16971746
SCPDIR *dirp;
16981747
struct scp_dirent *dp;
@@ -1754,7 +1803,7 @@ void sink(int argc, char *argv[])
17541803
{
17551804
// DWORD dwread;
17561805
static BUF buffer;
1757-
struct _stati64 stb;
1806+
struct stat stb;
17581807
enum { YES, NO, DISPLAYED } wrerr;
17591808
BUF *bp;
17601809
size_t i, j, size;
@@ -1812,7 +1861,7 @@ void sink(int argc, char *argv[])
18121861

18131862
(void)_write(remout, "", 1);
18141863

1815-
if (_stati64(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
1864+
if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
18161865
targisdir = 1;
18171866

18181867
for (first = 1;; first = 0) {
@@ -1912,7 +1961,7 @@ void sink(int argc, char *argv[])
19121961
np = namebuf;
19131962
} else
19141963
np = targ;
1915-
exists = _stati64(np, &stb) == 0;
1964+
exists = stat(np, &stb) == 0;
19161965
if (buf[0] == 'D') {
19171966
int mod_flag = pflag;
19181967
if (exists) {
@@ -2807,9 +2856,9 @@ char *win32colon(char *cp)
28072856

28082857
void verifydir(char *cp)
28092858
{
2810-
struct _stati64 stb;
2859+
struct stat stb;
28112860

2812-
if (!_stati64(cp, &stb)) {
2861+
if (!stat(cp, &stb)) {
28132862
if (S_ISDIR(stb.st_mode))
28142863
return;
28152864
errno = ENOTDIR;

0 commit comments

Comments
 (0)