Skip to content

Commit 4729927

Browse files
committed
Disabling inheritance of parent handles in sftp.exe. Code cleanup in sftp-server.exe
1 parent beb8dc5 commit 4729927

File tree

3 files changed

+19
-59
lines changed

3 files changed

+19
-59
lines changed

sftp-common.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626

2727
#include "includes.h"
2828

29-
/*
30-
* We support only client side kerberos on Windows.
31-
*/
32-
3329
#ifdef WIN32_FIXME
3430
void strmode(mode_t mode, char *p);
3531
void strmode_from_attrib(unsigned attrib, char *p);

sftp-server.c

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717

1818
#include "includes.h"
1919

20-
/*
21-
* We support only client side kerberos on Windows.
22-
*/
23-
24-
#ifdef WIN32_FIXME
25-
#undef GSSAPI
26-
#undef KRB5
27-
28-
#define true 1
29-
#define false 0
30-
31-
#endif
32-
3320
#include <sys/param.h> /* MIN */
3421
#include <sys/types.h>
3522
#include <sys/stat.h>
@@ -232,9 +219,7 @@ errno_to_portable(int unixerrno)
232219
case ENOENT:
233220
case ENOTDIR:
234221
case EBADF:
235-
#ifndef WIN32_FIXME
236222
case ELOOP:
237-
#endif
238223
ret = SSH2_FX_NO_SUCH_FILE;
239224
break;
240225
case EPERM:
@@ -726,12 +711,8 @@ process_open(u_int32_t id)
726711
char *name;
727712
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
728713

729-
// #ifdef WIN32_FIXME
730-
// name = buffer_get_string_local8_from_utf8(&iqueue, NULL);
731-
//#else
732714
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 )
733715
fatal("%s: buffer error: %s", __func__, ssh_err(r));
734-
//#endif /* WIN32_FIXME */
735716

736717
if ((r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
737718
(r = decode_attrib(iqueue, &a)) != 0)
@@ -740,14 +721,14 @@ process_open(u_int32_t id)
740721
debug3("request %u: open flags %d", id, pflags);
741722
flags = flags_from_portable(pflags);
742723
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
743-
#ifdef WIN32_FIXME
724+
#ifdef WIN32_FIXME
744725
char resolvedname[MAXPATHLEN];
745726
if (realpathWin32i(name, resolvedname))
746727
{
747728
free(name);
748729
name = strdup(resolvedname);
749730
}
750-
#endif
731+
#endif
751732

752733
logit("open \"%s\" flags %s mode 0%o",
753734
name, string_from_portable(pflags), mode);
@@ -882,27 +863,26 @@ process_do_stat(u_int32_t id, int do_lstat)
882863
char *name;
883864
int r, status = SSH2_FX_FAILURE;
884865

885-
#ifdef WIN32_FIXME
886-
char resolvedname[MAXPATHLEN];
887-
#endif
866+
#ifdef WIN32_FIXME
867+
char resolvedname[MAXPATHLEN];
868+
#endif
888869

889870

890-
#ifdef WIN32_FIXME
871+
#ifdef WIN32_FIXME
891872

892-
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0)
873+
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0)
893874
fatal("%s: buffer error: %s", __func__, ssh_err(r));
894875

895-
if (realpathWin32i(name, resolvedname))
896-
{
897-
free(name);
898-
name = strdup(resolvedname);
899-
}
876+
if (realpathWin32i(name, resolvedname)) {
877+
free(name);
878+
name = strdup(resolvedname);
879+
}
900880

901-
debug3("request %u: %sstat", id, do_lstat ? "l" : "");
902-
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
903-
r = stat(name, &st);
881+
debug3("request %u: %sstat", id, do_lstat ? "l" : "");
882+
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
883+
r = stat(name, &st);
904884

905-
#else
885+
#else
906886

907887

908888

@@ -1957,21 +1937,6 @@ sftp_server_usage(void)
19571937
exit(1);
19581938
}
19591939

1960-
#ifdef WIN32_FIXME
1961-
DWORD select_in_handle( HANDLE in_handle)
1962-
{
1963-
//DWORD rc = WaitForSingleObject (in_handle, 0);
1964-
//if (rc == WAIT_OBJECT_0)
1965-
// return 1;
1966-
//else
1967-
// return 0;
1968-
1969-
DWORD bytesavail = 0 ;
1970-
PeekNamedPipe(in_handle, NULL,0, NULL, &bytesavail, NULL );
1971-
return bytesavail;
1972-
}
1973-
#endif
1974-
19751940
int
19761941
sftp_server_main(int argc, char **argv, struct passwd *user_pw)
19771942
{
@@ -2113,14 +2078,10 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
21132078
fatal("%s: sshbuf_new failed", __func__);
21142079
if ((oqueue = sshbuf_new()) == NULL)
21152080
fatal("%s: sshbuf_new failed", __func__);
2116-
#if(0)//def WIN32_FIXME
2117-
//rset = (fd_set *)xmalloc(sizeof(fd_set));
2118-
//wset = (fd_set *)xmalloc(sizeof(fd_set));
2119-
#else
2081+
21202082
set_size = howmany(max + 1, NFDBITS) * sizeof(fd_mask);
21212083
rset = xmalloc(set_size);
21222084
wset = xmalloc(set_size);
2123-
#endif
21242085

21252086

21262087
if (homedir != NULL) {

sftp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,9 @@ connect_to_server(char *path, char **args, int *in, int *out)
22262226
strncat(fullCmd, args[i], MAX_PATH);
22272227
}
22282228

2229+
fcntl(pout[1], F_SETFD, FD_CLOEXEC);
2230+
fcntl(pin[0], F_SETFD, FD_CLOEXEC);
2231+
22292232
/*
22302233
* Assign sockets to StartupInfo.
22312234
*/

0 commit comments

Comments
 (0)