projects
/
u
/
mdw
/
putty
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support for non-ISO-8859-1 X keysyms. So in particular, pterm in a
[u/mdw/putty]
/
psftp.c
diff --git
a/psftp.c
b/psftp.c
index
a278260
..
b9f6370
100644
(file)
--- a/
psftp.c
+++ b/
psftp.c
@@
-32,6
+32,9
@@
static int do_sftp_init(void);
*/
char *pwd, *homedir;
*/
char *pwd, *homedir;
+static Backend *back;
+static void *backhandle;
+static Config cfg;
/* ----------------------------------------------------------------------
* Higher-level helper functions used in commands.
/* ----------------------------------------------------------------------
* Higher-level helper functions used in commands.
@@
-242,8
+245,7
@@
int sftp_cmd_ls(struct sftp_command *cmd)
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
if (nnames + names->nnames >= namesize) {
namesize += names->nnames + 128;
- ournames =
- srealloc(ournames, namesize * sizeof(*ournames));
+ ournames = sresize(ournames, namesize, struct fxp_name *);
}
for (i = 0; i < names->nnames; i++)
}
for (i = 0; i < names->nnames; i++)
@@
-830,7
+832,7
@@
int sftp_cmd_chmod(struct sftp_command *cmd)
if (!(subset & 06777) && (perms &~ subset)) {
printf("chmod: file mode '%.*s' contains no user/group/other"
" specifier and permissions other than 't' \n",
if (!(subset & 06777) && (perms &~ subset)) {
printf("chmod: file mode '%.*s' contains no user/group/other"
" specifier and permissions other than 't' \n",
- strcspn(modebegin, ","), modebegin
, *mode
);
+ strcspn(modebegin, ","), modebegin);
return 0;
}
perms &= subset;
return 0;
}
perms &= subset;
@@
-931,10
+933,10
@@
static int sftp_cmd_lcd(struct sftp_command *cmd)
return 0;
}
return 0;
}
- currdir = s
malloc(256
);
+ currdir = s
newn(256, char
);
len = GetCurrentDirectory(256, currdir);
if (len > 256)
len = GetCurrentDirectory(256, currdir);
if (len > 256)
- currdir = sre
alloc(currdir, len
);
+ currdir = sre
size(currdir, len, char
);
GetCurrentDirectory(len, currdir);
printf("New local directory is %s\n", currdir);
sfree(currdir);
GetCurrentDirectory(len, currdir);
printf("New local directory is %s\n", currdir);
sfree(currdir);
@@
-947,10
+949,10
@@
static int sftp_cmd_lpwd(struct sftp_command *cmd)
char *currdir;
int len;
char *currdir;
int len;
- currdir = s
malloc(256
);
+ currdir = s
newn(256, char
);
len = GetCurrentDirectory(256, currdir);
if (len > 256)
len = GetCurrentDirectory(256, currdir);
if (len > 256)
- currdir = sre
alloc(currdir, len
);
+ currdir = sre
size(currdir, len, char
);
GetCurrentDirectory(len, currdir);
printf("Current local directory is %s\n", currdir);
sfree(currdir);
GetCurrentDirectory(len, currdir);
printf("Current local directory is %s\n", currdir);
sfree(currdir);
@@
-1251,7
+1253,7
@@
struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
}
fflush(stdout);
}
fflush(stdout);
- cmd = s
malloc(sizeof(struct sftp_command)
);
+ cmd = s
new(struct sftp_command
);
cmd->words = NULL;
cmd->nwords = 0;
cmd->wordssize = 0;
cmd->words = NULL;
cmd->nwords = 0;
cmd->wordssize = 0;
@@
-1263,7
+1265,7
@@
struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
char *ret;
linesize += 512;
char *ret;
linesize += 512;
- line = sre
alloc(line, linesize
);
+ line = sre
size(line, linesize, char
);
ret = fgets(line + linelen, linesize - linelen, fp);
if (!ret || (linelen == 0 && line[0] == '\0')) {
ret = fgets(line + linelen, linesize - linelen, fp);
if (!ret || (linelen == 0 && line[0] == '\0')) {
@@
-1295,7
+1297,7
@@
struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
* containing everything else on the line.
*/
cmd->nwords = cmd->wordssize = 2;
* containing everything else on the line.
*/
cmd->nwords = cmd->wordssize = 2;
- cmd->words = sre
alloc(cmd->words, cmd->wordssize * sizeof(char *)
);
+ cmd->words = sre
size(cmd->words, cmd->wordssize, char *
);
cmd->words[0] = "!";
cmd->words[1] = p+1;
} else {
cmd->words[0] = "!";
cmd->words[1] = p+1;
} else {
@@
-1338,8
+1340,7
@@
struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
*r = '\0';
if (cmd->nwords >= cmd->wordssize) {
cmd->wordssize = cmd->nwords + 16;
*r = '\0';
if (cmd->nwords >= cmd->wordssize) {
cmd->wordssize = cmd->nwords + 16;
- cmd->words =
- srealloc(cmd->words, cmd->wordssize * sizeof(char *));
+ cmd->words = sresize(cmd->words, cmd->wordssize, char *);
}
cmd->words[cmd->nwords++] = q;
}
}
cmd->words[cmd->nwords++] = q;
}
@@
-1446,45
+1447,48
@@
static int verbose = 0;
*/
void fatalbox(char *fmt, ...)
{
*/
void fatalbox(char *fmt, ...)
{
- char
str[0x100]; /* Make the size big enough */
+ char
*str, *str2;
va_list ap;
va_start(ap, fmt);
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal:");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
va_end(ap);
-
strcat(str, "\n"
);
-
fputs(str, stderr
);
+
fputs(str2, stderr
);
+
sfree(str2
);
cleanup_exit(1);
}
void modalfatalbox(char *fmt, ...)
{
cleanup_exit(1);
}
void modalfatalbox(char *fmt, ...)
{
- char
str[0x100]; /* Make the size big enough */
+ char
*str, *str2;
va_list ap;
va_start(ap, fmt);
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal:");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
va_end(ap);
-
strcat(str, "\n"
);
-
fputs(str, stderr
);
+
fputs(str2, stderr
);
+
sfree(str2
);
cleanup_exit(1);
}
cleanup_exit(1);
}
-void connection_fatal(char *fmt, ...)
+void connection_fatal(
void *frontend,
char *fmt, ...)
{
{
- char
str[0x100]; /* Make the size big enough */
+ char
*str, *str2;
va_list ap;
va_start(ap, fmt);
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal:");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
va_end(ap);
-
strcat(str, "\n"
);
-
fputs(str, stderr
);
+
fputs(str2, stderr
);
+
sfree(str2
);
cleanup_exit(1);
}
cleanup_exit(1);
}
-void ldisc_send(char *buf, int len, int interactive)
+void ldisc_send(
void *handle,
char *buf, int len, int interactive)
{
/*
* This is only here because of the calls to ldisc_send(NULL,
{
/*
* This is only here because of the calls to ldisc_send(NULL,
@@
-1522,7
+1526,7
@@
static unsigned char *outptr; /* where to put the data */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
-int from_backend(void *frontend, int is_stderr, char *data, int datalen)
+int from_backend(void *frontend, int is_stderr, c
onst c
har *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
@@
-1558,10
+1562,7
@@
int from_backend(void *frontend, int is_stderr, char *data, int datalen)
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
if (len > 0) {
if (pendsize < pendlen + len) {
pendsize = pendlen + len + 4096;
- pending = (pending ? srealloc(pending, pendsize) :
- smalloc(pendsize));
- if (!pending)
- fatalbox("Out of memory");
+ pending = sresize(pending, pendsize, unsigned char);
}
memcpy(pending + pendlen, p, len);
pendlen += len;
}
memcpy(pending + pendlen, p, len);
pendlen += len;
@@
-1717,7
+1718,7
@@
static int psftp_connect(char *userhost, char *user, int portnumber)
/*
* Enact command-line overrides.
*/
/*
* Enact command-line overrides.
*/
- cmdline_run_saved();
+ cmdline_run_saved(
&cfg
);
/*
* Trim leading whitespace off the hostname if it's there.
/*
* Trim leading whitespace off the hostname if it's there.
@@
-1767,6
+1768,7
@@
static int psftp_connect(char *userhost, char *user, int portnumber)
}
if (!cfg.username[0]) {
printf("login as: ");
}
if (!cfg.username[0]) {
printf("login as: ");
+ fflush(stdout);
if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
fprintf(stderr, "psftp: aborting\n");
cleanup_exit(1);
if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
fprintf(stderr, "psftp: aborting\n");
cleanup_exit(1);
@@
-1822,11
+1824,14
@@
static int psftp_connect(char *userhost, char *user, int portnumber)
back = &ssh_backend;
back = &ssh_backend;
- err = back->init(NULL, &backhandle,
cfg.host, cfg.port, &realhost,
0);
+ err = back->init(NULL, &backhandle,
&cfg, cfg.host, cfg.port, &realhost,
0);
if (err != NULL) {
fprintf(stderr, "ssh_init: %s\n", err);
return 1;
}
if (err != NULL) {
fprintf(stderr, "ssh_init: %s\n", err);
return 1;
}
+ logctx = log_init(NULL, &cfg);
+ back->provide_logctx(backhandle, logctx);
+ console_provide_logctx(logctx);
ssh_sftp_init();
if (verbose && realhost != NULL)
printf("Connected to %s\n", realhost);
ssh_sftp_init();
if (verbose && realhost != NULL)
printf("Connected to %s\n", realhost);
@@
-1836,11
+1841,11
@@
static int psftp_connect(char *userhost, char *user, int portnumber)
void cmdline_error(char *p, ...)
{
va_list ap;
void cmdline_error(char *p, ...)
{
va_list ap;
- fprintf(stderr, "ps
c
p: ");
+ fprintf(stderr, "ps
ft
p: ");
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
- fp
utc('\n', stderr
);
+ fp
rintf(stderr, "\n try typing \"psftp -h\" for help\n"
);
exit(1);
}
exit(1);
}
@@
-1855,6
+1860,7
@@
int main(int argc, char *argv[])
int mode = 0;
int modeflags = 0;
char *batchfile = NULL;
int mode = 0;
int modeflags = 0;
char *batchfile = NULL;
+ int errors = 0;
flags = FLAG_STDERR | FLAG_INTERACTIVE;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
flags = FLAG_STDERR | FLAG_INTERACTIVE;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
@@
-1864,6
+1870,7
@@
int main(int argc, char *argv[])
userhost = user = NULL;
userhost = user = NULL;
+ errors = 0;
for (i = 1; i < argc; i++) {
int ret;
if (argv[i][0] != '-') {
for (i = 1; i < argc; i++) {
int ret;
if (argv[i][0] != '-') {
@@
-1873,7
+1880,7
@@
int main(int argc, char *argv[])
userhost = dupstr(argv[i]);
continue;
}
userhost = dupstr(argv[i]);
continue;
}
- ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1);
+ ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1
, &cfg
);
if (ret == -2) {
cmdline_error("option \"%s\" requires an argument", argv[i]);
} else if (ret == 2) {
if (ret == -2) {
cmdline_error("option \"%s\" requires an argument", argv[i]);
} else if (ret == 2) {
@@
-1898,7
+1905,7
@@
int main(int argc, char *argv[])
i++;
break;
} else {
i++;
break;
} else {
-
usage(
);
+
cmdline_error("unknown option \"%s\"", argv[i]
);
}
}
argc -= i;
}
}
argc -= i;