X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=psftp.c;h=784c81b1b88242871f5b76cd679f32adcbd757b1;hb=ef7a821bb19e657179cad5a383f3991c39a1c527;hp=1d331603cbf7f5ea67a641466ce1eba546c9d670;hpb=dd0f1e5cc7c5cc52d36a7c8e2fc6434887fd165e;p=PuTTY.git diff --git a/psftp.c b/psftp.c index 1d331603..784c81b1 100644 --- a/psftp.c +++ b/psftp.c @@ -68,7 +68,7 @@ struct sftp_packet *sftp_wait_for_reply(struct sftp_request *req) * canonification fails, at least fall back to returning a _valid_ * pathname (though it may be ugly, eg /home/simon/../foobar). */ -char *canonify(char *name) +char *canonify(const char *name) { char *fullname, *canonname; struct sftp_packet *pktin; @@ -77,7 +77,7 @@ char *canonify(char *name) if (name[0] == '/') { fullname = dupstr(name); } else { - char *slash; + const char *slash; if (pwd[strlen(pwd) - 1] == '/') slash = ""; else @@ -169,30 +169,6 @@ char *canonify(char *name) } } -/* - * Return a pointer to the portion of str that comes after the last - * slash (or backslash or colon, if `local' is TRUE). - */ -static char *stripslashes(char *str, int local) -{ - char *p; - - if (local) { - p = strchr(str, ':'); - if (p) str = p+1; - } - - p = strrchr(str, '/'); - if (p) str = p+1; - - if (local) { - p = strrchr(str, '\\'); - if (p) str = p+1; - } - - return str; -} - /* * qsort comparison routine for fxp_name structures. Sorts by real * file name. @@ -1011,7 +987,8 @@ int sftp_cmd_ls(struct sftp_command *cmd) struct fxp_names *names; struct fxp_name **ournames; int nnames, namesize; - char *dir, *cdir, *unwcdir, *wildcard; + const char *dir; + char *cdir, *unwcdir, *wildcard; struct sftp_packet *pktin; struct sftp_request *req; int i; @@ -1901,7 +1878,7 @@ static int sftp_cmd_pling(struct sftp_command *cmd) static int sftp_cmd_help(struct sftp_command *cmd); static struct sftp_cmd_lookup { - char *name; + const char *name; /* * For help purposes, there are two kinds of command: * @@ -1915,8 +1892,8 @@ static struct sftp_cmd_lookup { * contains the help that should double up for this command. */ int listed; /* do we list this in primary help? */ - char *shorthelp; - char *longhelp; + const char *shorthelp; + const char *longhelp; int (*obey) (struct sftp_command *); } sftp_lookup[] = { /* @@ -2139,7 +2116,7 @@ static struct sftp_cmd_lookup { } }; -const struct sftp_cmd_lookup *lookup_command(char *name) +const struct sftp_cmd_lookup *lookup_command(const char *name) { int i, j, k, cmp; @@ -2388,7 +2365,7 @@ void do_sftp_cleanup() } } -void do_sftp(int mode, int modeflags, char *batchfile) +int do_sftp(int mode, int modeflags, char *batchfile) { FILE *fp; int ret; @@ -2421,8 +2398,9 @@ void do_sftp(int mode, int modeflags, char *batchfile) fp = fopen(batchfile, "r"); if (!fp) { printf("Fatal: unable to open %s\n", batchfile); - return; + return 1; } + ret = 0; while (1) { struct sftp_command *cmd; cmd = sftp_getcmd(fp, mode, modeflags); @@ -2437,8 +2415,13 @@ void do_sftp(int mode, int modeflags, char *batchfile) } } fclose(fp); - + /* + * In batch mode, and if exit on command failure is enabled, + * any command failure causes the whole of PSFTP to fail. + */ + if (ret == 0 && !(modeflags & 2)) return 2; } + return 0; } /* ---------------------------------------------------------------------- @@ -2450,7 +2433,7 @@ static int verbose = 0; /* * Print an error message and perform a fatal exit. */ -void fatalbox(char *fmt, ...) +void fatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2464,7 +2447,7 @@ void fatalbox(char *fmt, ...) cleanup_exit(1); } -void modalfatalbox(char *fmt, ...) +void modalfatalbox(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2478,7 +2461,7 @@ void modalfatalbox(char *fmt, ...) cleanup_exit(1); } -void nonfatal(char *fmt, ...) +void nonfatal(const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2490,7 +2473,7 @@ void nonfatal(char *fmt, ...) fputs(str2, stderr); sfree(str2); } -void connection_fatal(void *frontend, char *fmt, ...) +void connection_fatal(void *frontend, const char *fmt, ...) { char *str, *str2; va_list ap; @@ -2505,16 +2488,7 @@ void connection_fatal(void *frontend, char *fmt, ...) cleanup_exit(1); } -void ldisc_send(void *handle, char *buf, int len, int interactive) -{ - /* - * This is only here because of the calls to ldisc_send(NULL, - * 0) in ssh.c. Nothing in PSFTP actually needs to use the - * ldisc as an ldisc. So if we get called with any real data, I - * want to know about it. - */ - assert(len == 0); -} +void ldisc_echoedit_update(void *handle) { } /* * In psftp, all agent requests should be synchronous, so this is a @@ -2673,6 +2647,9 @@ static void usage(void) printf(" -hostkey aa:bb:cc:...\n"); printf(" manually specify a host key (may be repeated)\n"); printf(" -batch disable all interactive prompts\n"); + printf(" -sshlog file\n"); + printf(" -sshrawlog file\n"); + printf(" log protocol details to a file\n"); cleanup_exit(1); } @@ -2875,7 +2852,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber) return 0; } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "psftp: "); @@ -2894,7 +2871,7 @@ const int share_can_be_upstream = FALSE; */ int psftp_main(int argc, char *argv[]) { - int i; + int i, ret; int portnumber = 0; char *userhost, *user; int mode = 0; @@ -2964,6 +2941,8 @@ int psftp_main(int argc, char *argv[]) argv += i; back = NULL; + platform_psftp_post_option_setup(); + /* * If the loaded session provides a hostname, and a hostname has not * otherwise been specified, pop it in `userhost' so that @@ -2990,7 +2969,7 @@ int psftp_main(int argc, char *argv[]) " to connect\n"); } - do_sftp(mode, modeflags, batchfile); + ret = do_sftp(mode, modeflags, batchfile); if (back != NULL && back->connected(backhandle)) { char ch; @@ -3004,5 +2983,5 @@ int psftp_main(int argc, char *argv[]) console_provide_logctx(NULL); sk_cleanup(); - return 0; + return ret; }