X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/514702987c9252fcb0ab98882a6603b3bd0505ce..5a8afc787bcaafabd3aee68b6dac341962801b57:/psftp.c diff --git a/psftp.c b/psftp.c index a278260b..3fdfa45a 100644 --- a/psftp.c +++ b/psftp.c @@ -32,6 +32,9 @@ static int do_sftp_init(void); */ char *pwd, *homedir; +static Backend *back; +static void *backhandle; +static Config cfg; /* ---------------------------------------------------------------------- * Higher-level helper functions used in commands. @@ -830,7 +833,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", - strcspn(modebegin, ","), modebegin, *mode); + strcspn(modebegin, ","), modebegin); return 0; } perms &= subset; @@ -1446,45 +1449,48 @@ static int verbose = 0; */ void fatalbox(char *fmt, ...) { - char str[0x100]; /* Make the size big enough */ + char *str, *str2; 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); - strcat(str, "\n"); - fputs(str, stderr); + fputs(str2, stderr); + sfree(str2); 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); - strcpy(str, "Fatal:"); - vsprintf(str + strlen(str), fmt, ap); + str = dupvprintf(fmt, ap); + str2 = dupcat("Fatal: ", str, "\n", NULL); + sfree(str); va_end(ap); - strcat(str, "\n"); - fputs(str, stderr); + fputs(str2, stderr); + sfree(str2); 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); - strcpy(str, "Fatal:"); - vsprintf(str + strlen(str), fmt, ap); + str = dupvprintf(fmt, ap); + str2 = dupcat("Fatal: ", str, "\n", NULL); + sfree(str); va_end(ap); - strcat(str, "\n"); - fputs(str, stderr); + fputs(str2, stderr); + sfree(str2); 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, @@ -1522,7 +1528,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 */ -int from_backend(void *frontend, int is_stderr, char *data, int datalen) +int from_backend(void *frontend, int is_stderr, const char *data, int datalen) { unsigned char *p = (unsigned char *) data; unsigned len = (unsigned) datalen; @@ -1717,7 +1723,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) /* * Enact command-line overrides. */ - cmdline_run_saved(); + cmdline_run_saved(&cfg); /* * Trim leading whitespace off the hostname if it's there. @@ -1767,6 +1773,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) } 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); @@ -1822,11 +1829,14 @@ static int psftp_connect(char *userhost, char *user, int portnumber) 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; } + 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); @@ -1836,11 +1846,11 @@ static int psftp_connect(char *userhost, char *user, int portnumber) void cmdline_error(char *p, ...) { va_list ap; - fprintf(stderr, "pscp: "); + fprintf(stderr, "psftp: "); va_start(ap, p); vfprintf(stderr, p, ap); va_end(ap); - fputc('\n', stderr); + fprintf(stderr, "\n try typing \"psftp -h\" for help\n"); exit(1); } @@ -1855,6 +1865,7 @@ int main(int argc, char *argv[]) int mode = 0; int modeflags = 0; char *batchfile = NULL; + int errors = 0; flags = FLAG_STDERR | FLAG_INTERACTIVE; cmdline_tooltype = TOOLTYPE_FILETRANSFER; @@ -1864,6 +1875,7 @@ int main(int argc, char *argv[]) userhost = user = NULL; + errors = 0; for (i = 1; i < argc; i++) { int ret; if (argv[i][0] != '-') { @@ -1873,7 +1885,7 @@ int main(int argc, char *argv[]) userhost = dupstr(argv[i]); continue; } - ret = cmdline_process_param(argv[i], i+1