mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-27 07:54:50 +02:00
Issues with chdir and input conversion.
This commit is contained in:
parent
2a8c0fe11a
commit
78306c910d
@ -11,4 +11,8 @@
|
|||||||
#define O_TRUNC 0x0200 // open and truncate
|
#define O_TRUNC 0x0200 // open and truncate
|
||||||
#define O_EXCL 0x0400 // open only if file doesn't already exist
|
#define O_EXCL 0x0400 // open only if file doesn't already exist
|
||||||
|
|
||||||
#define O_BINARY 0x8000 // file mode is binary (untranslated)
|
#define O_TEXT 0x4000 /* file mode is text (translated) */
|
||||||
|
#define O_BINARY 0x8000 /* file mode is binary (untranslated) */
|
||||||
|
#define O_WTEXT 0x10000 /* file mode is UTF16 (translated) */
|
||||||
|
#define O_U16TEXT 0x20000 /* file mode is UTF16 no BOM (translated) */
|
||||||
|
#define O_U8TEXT 0x40000 /* file mode is UTF8 no BOM (translated) */
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#define stat w32_stat
|
#define stat w32_stat
|
||||||
#define lstat w32_stat
|
#define lstat w32_stat
|
||||||
#define mkdir w32_mkdir
|
#define mkdir w32_mkdir
|
||||||
|
#define chdir w32_chdir
|
||||||
|
|
||||||
struct w32_stat {
|
struct w32_stat {
|
||||||
dev_t st_dev; /* ID of device containing file */
|
dev_t st_dev; /* ID of device containing file */
|
||||||
|
@ -52,6 +52,7 @@ long w32_lseek( int fd, long offset, int origin);
|
|||||||
int w32_isatty(int fd);
|
int w32_isatty(int fd);
|
||||||
FILE* w32_fdopen(int fd, const char *mode);
|
FILE* w32_fdopen(int fd, const char *mode);
|
||||||
int w32_mkdir(const char *pathname, unsigned short mode);
|
int w32_mkdir(const char *pathname, unsigned short mode);
|
||||||
|
int w32_chdir(const char *dirname);
|
||||||
|
|
||||||
/*common i/o*/
|
/*common i/o*/
|
||||||
#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__)
|
#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__)
|
||||||
@ -72,7 +73,6 @@ int w32_raise(int sig);
|
|||||||
int w32_kill(int pid, int sig);
|
int w32_kill(int pid, int sig);
|
||||||
FILE* w32_fopen_utf8(const char *, const char *);
|
FILE* w32_fopen_utf8(const char *, const char *);
|
||||||
|
|
||||||
|
|
||||||
/* Shutdown constants */
|
/* Shutdown constants */
|
||||||
#define SHUT_WR SD_SEND
|
#define SHUT_WR SD_SEND
|
||||||
#define SHUT_RD SD_RECEIVE
|
#define SHUT_RD SD_RECEIVE
|
||||||
|
@ -389,7 +389,7 @@ int w32_writev(int fd, const struct iovec *iov, int iovcnt) {
|
|||||||
CHECK_FD(fd);
|
CHECK_FD(fd);
|
||||||
|
|
||||||
for (i = 0; i < iovcnt; i++) {
|
for (i = 0; i < iovcnt; i++) {
|
||||||
int ret = write(fd, iov[i].iov_base, iov[i].iov_len);
|
int ret = w32_write(fd, iov[i].iov_base, iov[i].iov_len);
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
written += ret;
|
written += ret;
|
||||||
@ -418,7 +418,23 @@ w32_lseek(int fd, long offset, int origin) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
w32_mkdir(const char *pathname, unsigned short mode) {
|
w32_mkdir(const char *pathname, unsigned short mode) {
|
||||||
return _mkdir(pathname);
|
wchar_t wdirname[MAX_PATH];
|
||||||
|
|
||||||
|
if (MultiByteToWideChar(CP_UTF8, 0, pathname, -1, wdirname, MAX_PATH)) {
|
||||||
|
return _wmkdir(wdirname);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w32_chdir(const char *dirname) {
|
||||||
|
wchar_t wdirname[MAX_PATH];
|
||||||
|
|
||||||
|
if (MultiByteToWideChar(CP_UTF8, 0, dirname, -1, wdirname, MAX_PATH)) {
|
||||||
|
return _wchdir(wdirname);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
12
scp.c
12
scp.c
@ -1092,9 +1092,9 @@ main(int argc, char **argv)
|
|||||||
args.list = remote_remote_args.list = NULL;
|
args.list = remote_remote_args.list = NULL;
|
||||||
addargs(&args, "%s", ssh_program);
|
addargs(&args, "%s", ssh_program);
|
||||||
addargs(&args, "-x");
|
addargs(&args, "-x");
|
||||||
addargs(&args, "-oForwardAgent=no");
|
addargs(&args, "\"-oForwardAgent no\"");
|
||||||
addargs(&args, "-oPermitLocalCommand=no");
|
addargs(&args, "\"-oPermitLocalCommand no\"");
|
||||||
addargs(&args, "-oClearAllForwardings=yes");
|
addargs(&args, "\"-oClearAllForwardings yes\"");
|
||||||
|
|
||||||
fflag = tflag = 0;
|
fflag = tflag = 0;
|
||||||
while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
|
while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
|
||||||
@ -1127,8 +1127,8 @@ main(int argc, char **argv)
|
|||||||
addargs(&args, "%s", optarg);
|
addargs(&args, "%s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
addargs(&remote_remote_args, "-oBatchmode=yes");
|
addargs(&remote_remote_args, "\"-oBatchmode yes\"");
|
||||||
addargs(&args, "-oBatchmode=yes");
|
addargs(&args, "\"-oBatchmode yes\"");
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
limit_kbps = strtonum(optarg, 1, 100 * 1024 * 1024,
|
limit_kbps = strtonum(optarg, 1, 100 * 1024 * 1024,
|
||||||
@ -1347,7 +1347,7 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
freeargs(&alist);
|
freeargs(&alist);
|
||||||
addargs(&alist, "%s", ssh_program);
|
addargs(&alist, "%s", ssh_program);
|
||||||
addargs(&alist, "-x");
|
addargs(&alist, "-x");
|
||||||
addargs(&alist, "-oClearAllForwardings=yes");
|
addargs(&alist, "-\"oClearAllForwardings yes\"");
|
||||||
addargs(&alist, "-n");
|
addargs(&alist, "-n");
|
||||||
for (j = 0; j < remote_remote_args.num; j++) {
|
for (j = 0; j < remote_remote_args.num; j++) {
|
||||||
addargs(&alist, "%s",
|
addargs(&alist, "%s",
|
||||||
|
53
sftp.c
53
sftp.c
@ -73,7 +73,9 @@ typedef void EditLine;
|
|||||||
#define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
|
#define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
|
||||||
#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
|
#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
|
||||||
|
|
||||||
#ifdef WIN32_VS
|
#ifdef WINDOWS
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include "win32_dirent.h"
|
#include "win32_dirent.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1425,6 +1427,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
|
|||||||
glob_t g;
|
glob_t g;
|
||||||
|
|
||||||
path1 = path2 = NULL;
|
path1 = path2 = NULL;
|
||||||
|
|
||||||
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
|
||||||
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2);
|
||||||
if (ignore_errors != 0)
|
if (ignore_errors != 0)
|
||||||
@ -2104,7 +2107,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
|
|||||||
free(dir);
|
free(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WIN32_VS
|
#ifndef WINDOWS
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
setvbuf(infile, NULL, _IOLBF, 0);
|
setvbuf(infile, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
@ -2117,13 +2120,26 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
|
|||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
if (el == NULL) {
|
if (el == NULL) {
|
||||||
if (interactive)
|
if (interactive) {
|
||||||
printf("sftp> ");
|
wchar_t wcmd[2048];
|
||||||
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
|
printf("sftp> ");
|
||||||
if (interactive)
|
if (fgetws(wcmd, sizeof(cmd)/sizeof(wchar_t), infile) == NULL) {
|
||||||
printf("\n");
|
if (interactive)
|
||||||
break;
|
printf("\n");
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int needed;
|
||||||
|
if ((needed = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, NULL, 0, NULL, NULL)) == 0 ||
|
||||||
|
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wcmd, -1, cmd, needed, NULL, NULL) != needed)
|
||||||
|
fatal("failed to covert input arguments");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!interactive) { /* Echo command */
|
if (!interactive) { /* Echo command */
|
||||||
printf("sftp> %s", cmd);
|
printf("sftp> %s", cmd);
|
||||||
if (strlen(cmd) > 0 &&
|
if (strlen(cmd) > 0 &&
|
||||||
@ -2335,13 +2351,14 @@ main(int argc, char **argv)
|
|||||||
args.list = NULL;
|
args.list = NULL;
|
||||||
addargs(&args, "%s", ssh_program);
|
addargs(&args, "%s", ssh_program);
|
||||||
|
|
||||||
addargs(&args, "-oForwardX11 no");
|
addargs(&args, "\"-oForwardX11 no\"");
|
||||||
addargs(&args, "-oForwardAgent no");
|
addargs(&args, "\"-oForwardAgent no\"");
|
||||||
addargs(&args, "-oPermitLocalCommand no");
|
addargs(&args, "\"-oPermitLocalCommand no\"");
|
||||||
addargs(&args, "-oClearAllForwardings yes");
|
addargs(&args, "\"-oClearAllForwardings yes\"");
|
||||||
|
|
||||||
ll = SYSLOG_LEVEL_INFO;
|
ll = SYSLOG_LEVEL_INFO;
|
||||||
infile = stdin;
|
infile = stdin;
|
||||||
|
_setmode(_fileno(infile), O_U16TEXT);
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv,
|
while ((ch = getopt(argc, argv,
|
||||||
"1246afhpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) {
|
"1246afhpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) {
|
||||||
@ -2367,8 +2384,8 @@ main(int argc, char **argv)
|
|||||||
addargs(&args, "-%c", ch);
|
addargs(&args, "-%c", ch);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
addargs(&args, "-oPort %s", optarg);
|
addargs(&args, "\"-oPort %s\"", optarg);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
if (debug_level < 3) {
|
if (debug_level < 3) {
|
||||||
addargs(&args, "-v");
|
addargs(&args, "-v");
|
||||||
@ -2402,8 +2419,8 @@ main(int argc, char **argv)
|
|||||||
fatal("%s (%s).", strerror(errno), optarg);
|
fatal("%s (%s).", strerror(errno), optarg);
|
||||||
showprogress = 0;
|
showprogress = 0;
|
||||||
quiet = batchmode = 1;
|
quiet = batchmode = 1;
|
||||||
addargs(&args, "-obatchmode yes");
|
addargs(&args, "\"-obatchmode yes\"");
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
global_fflag = 1;
|
global_fflag = 1;
|
||||||
break;
|
break;
|
||||||
@ -2476,7 +2493,7 @@ main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Missing hostname\n");
|
fprintf(stderr, "Missing hostname\n");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
addargs(&args, "-oProtocol %d", sshver);
|
addargs(&args, "\"-oProtocol %d\"", sshver);
|
||||||
|
|
||||||
/* no subsystem if the server-spec contains a '/' */
|
/* no subsystem if the server-spec contains a '/' */
|
||||||
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
|
if (sftp_server == NULL || strchr(sftp_server, '/') == NULL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user