mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-25 15:04:54 +02:00
Disabling inheritance of parent handles in sftp.exe. Code cleanup in sftp-server.exe
This commit is contained in:
parent
beb8dc53c5
commit
472992786d
@ -26,10 +26,6 @@
|
|||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* We support only client side kerberos on Windows.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
void strmode(mode_t mode, char *p);
|
void strmode(mode_t mode, char *p);
|
||||||
void strmode_from_attrib(unsigned attrib, char *p);
|
void strmode_from_attrib(unsigned attrib, char *p);
|
||||||
|
@ -17,19 +17,6 @@
|
|||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* We support only client side kerberos on Windows.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
#undef GSSAPI
|
|
||||||
#undef KRB5
|
|
||||||
|
|
||||||
#define true 1
|
|
||||||
#define false 0
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/param.h> /* MIN */
|
#include <sys/param.h> /* MIN */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -232,9 +219,7 @@ errno_to_portable(int unixerrno)
|
|||||||
case ENOENT:
|
case ENOENT:
|
||||||
case ENOTDIR:
|
case ENOTDIR:
|
||||||
case EBADF:
|
case EBADF:
|
||||||
#ifndef WIN32_FIXME
|
|
||||||
case ELOOP:
|
case ELOOP:
|
||||||
#endif
|
|
||||||
ret = SSH2_FX_NO_SUCH_FILE;
|
ret = SSH2_FX_NO_SUCH_FILE;
|
||||||
break;
|
break;
|
||||||
case EPERM:
|
case EPERM:
|
||||||
@ -726,12 +711,8 @@ process_open(u_int32_t id)
|
|||||||
char *name;
|
char *name;
|
||||||
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE;
|
||||||
|
|
||||||
// #ifdef WIN32_FIXME
|
|
||||||
// name = buffer_get_string_local8_from_utf8(&iqueue, NULL);
|
|
||||||
//#else
|
|
||||||
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 )
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 )
|
||||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
//#endif /* WIN32_FIXME */
|
|
||||||
|
|
||||||
if ((r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
|
if ((r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */
|
||||||
(r = decode_attrib(iqueue, &a)) != 0)
|
(r = decode_attrib(iqueue, &a)) != 0)
|
||||||
@ -740,14 +721,14 @@ process_open(u_int32_t id)
|
|||||||
debug3("request %u: open flags %d", id, pflags);
|
debug3("request %u: open flags %d", id, pflags);
|
||||||
flags = flags_from_portable(pflags);
|
flags = flags_from_portable(pflags);
|
||||||
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
|
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666;
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
char resolvedname[MAXPATHLEN];
|
char resolvedname[MAXPATHLEN];
|
||||||
if (realpathWin32i(name, resolvedname))
|
if (realpathWin32i(name, resolvedname))
|
||||||
{
|
{
|
||||||
free(name);
|
free(name);
|
||||||
name = strdup(resolvedname);
|
name = strdup(resolvedname);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
logit("open \"%s\" flags %s mode 0%o",
|
logit("open \"%s\" flags %s mode 0%o",
|
||||||
name, string_from_portable(pflags), mode);
|
name, string_from_portable(pflags), mode);
|
||||||
@ -882,27 +863,26 @@ process_do_stat(u_int32_t id, int do_lstat)
|
|||||||
char *name;
|
char *name;
|
||||||
int r, status = SSH2_FX_FAILURE;
|
int r, status = SSH2_FX_FAILURE;
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
char resolvedname[MAXPATHLEN];
|
char resolvedname[MAXPATHLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
|
|
||||||
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0)
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0)
|
||||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
|
|
||||||
if (realpathWin32i(name, resolvedname))
|
if (realpathWin32i(name, resolvedname)) {
|
||||||
{
|
free(name);
|
||||||
free(name);
|
name = strdup(resolvedname);
|
||||||
name = strdup(resolvedname);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
debug3("request %u: %sstat", id, do_lstat ? "l" : "");
|
debug3("request %u: %sstat", id, do_lstat ? "l" : "");
|
||||||
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
|
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
|
||||||
r = stat(name, &st);
|
r = stat(name, &st);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1957,21 +1937,6 @@ sftp_server_usage(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32_FIXME
|
|
||||||
DWORD select_in_handle( HANDLE in_handle)
|
|
||||||
{
|
|
||||||
//DWORD rc = WaitForSingleObject (in_handle, 0);
|
|
||||||
//if (rc == WAIT_OBJECT_0)
|
|
||||||
// return 1;
|
|
||||||
//else
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
DWORD bytesavail = 0 ;
|
|
||||||
PeekNamedPipe(in_handle, NULL,0, NULL, &bytesavail, NULL );
|
|
||||||
return bytesavail;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
||||||
{
|
{
|
||||||
@ -2113,14 +2078,10 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
|||||||
fatal("%s: sshbuf_new failed", __func__);
|
fatal("%s: sshbuf_new failed", __func__);
|
||||||
if ((oqueue = sshbuf_new()) == NULL)
|
if ((oqueue = sshbuf_new()) == NULL)
|
||||||
fatal("%s: sshbuf_new failed", __func__);
|
fatal("%s: sshbuf_new failed", __func__);
|
||||||
#if(0)//def WIN32_FIXME
|
|
||||||
//rset = (fd_set *)xmalloc(sizeof(fd_set));
|
|
||||||
//wset = (fd_set *)xmalloc(sizeof(fd_set));
|
|
||||||
#else
|
|
||||||
set_size = howmany(max + 1, NFDBITS) * sizeof(fd_mask);
|
set_size = howmany(max + 1, NFDBITS) * sizeof(fd_mask);
|
||||||
rset = xmalloc(set_size);
|
rset = xmalloc(set_size);
|
||||||
wset = xmalloc(set_size);
|
wset = xmalloc(set_size);
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (homedir != NULL) {
|
if (homedir != NULL) {
|
||||||
|
3
sftp.c
3
sftp.c
@ -2226,6 +2226,9 @@ connect_to_server(char *path, char **args, int *in, int *out)
|
|||||||
strncat(fullCmd, args[i], MAX_PATH);
|
strncat(fullCmd, args[i], MAX_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fcntl(pout[1], F_SETFD, FD_CLOEXEC);
|
||||||
|
fcntl(pin[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assign sockets to StartupInfo.
|
* Assign sockets to StartupInfo.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user