X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=psftp.c;h=1612b3b202695a0617d8917db637c54025aa8ca6;hb=6c81ee6706f75ccab7bc285d00139126524cce36;hp=de1964e8a303ffd8bef60c070e04a7c5ef96a610;hpb=69303f2d3e815470863808456be37f55947c9522;p=PuTTY.git diff --git a/psftp.c b/psftp.c index de1964e8..1612b3b2 100644 --- a/psftp.c +++ b/psftp.c @@ -40,14 +40,6 @@ static Config cfg; * Higher-level helper functions used in commands. */ -/* - * Determine whether a string is entirely composed of dots. - */ -static int is_dots(char *str) -{ - return str[strspn(str, ".")] == '\0'; -} - /* * Attempt to canonify a pathname starting from the pwd. If * canonification fails, at least fall back to returning a _valid_ @@ -291,10 +283,19 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart, ournames = sresize(ournames, namesize, struct fxp_name *); } for (i = 0; i < names->nnames; i++) - if (!is_dots(names->names[i].filename) && + if (strcmp(names->names[i].filename, ".") && + strcmp(names->names[i].filename, "..") && (!wildcard || wc_match(wildcard, - names->names[i].filename))) - ournames[nnames++] = fxp_dup_name(&names->names[i]); + names->names[i].filename))) { + if (!vet_filename(names->names[i].filename)) { + printf("ignoring potentially dangerous server-" + "supplied filename '%s'\n", + names->names[i].filename); + } else { + ournames[nnames++] = + fxp_dup_name(&names->names[i]); + } + } fxp_free_names(names); } sftp_register(req = fxp_close_send(dirhandle)); @@ -767,6 +768,23 @@ int sftp_cmd_quit(struct sftp_command *cmd) return -1; } +int sftp_cmd_close(struct sftp_command *cmd) +{ + if (back == NULL) { + printf("psftp: not connected to a host; use \"open host.name\"\n"); + return 0; + } + + if (back != NULL && back->socket(backhandle) != NULL) { + char ch; + back->special(backhandle, TS_EOF); + sftp_recvdata(&ch, 1); + } + do_sftp_cleanup(); + + return 0; +} + /* * List a directory. If no arguments are given, list pwd; otherwise * list the directory given in words[1]. @@ -1631,6 +1649,14 @@ static struct sftp_cmd_lookup { " use commas to separate different modifiers (\"u+rwx,g+s\").\n", sftp_cmd_chmod }, + { + "close", TRUE, "finish your SFTP session but do not quit PSFTP", + "\n" + " Terminates your SFTP session, but does not quit the PSFTP\n" + " program. You can then use \"open\" to start another SFTP\n" + " session, to the same server or to a different one.\n", + sftp_cmd_close + }, { "del", TRUE, "delete a file", " \n" @@ -1866,7 +1892,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags) printf("psftp> "); line = fgetline(fp); } else { - line = ssh_sftp_get_cmdline("psftp> "); + line = ssh_sftp_get_cmdline("psftp> ", back == NULL); } if (!line || !*line) { @@ -2004,6 +2030,8 @@ void do_sftp_cleanup() sftp_recvdata(&ch, 1); back->free(backhandle); sftp_cleanup_request(); + back = NULL; + backhandle = NULL; } if (pwd) { sfree(pwd); @@ -2577,12 +2605,10 @@ int psftp_main(int argc, char *argv[]) back->special(backhandle, TS_EOF); sftp_recvdata(&ch, 1); } + do_sftp_cleanup(); random_save_seed(); cmdline_cleanup(); console_provide_logctx(NULL); - do_sftp_cleanup(); - backhandle = NULL; - back = NULL; sk_cleanup(); return 0;