#define WM_RET_ERR_CNT ( WM_APP_BASE+406 )
#define WM_LS_RET_ERR_CNT ( WM_APP_BASE+407 )
+static int list = 0;
static int verbose = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
static int statistics = 1;
static int portnumber = 0;
+static int prev_stats_len = 0;
static char *password = NULL;
static int errs = 0;
/* GUI Adaptation - Sept 2000 */
static void tell_char(FILE * stream, char c);
static void tell_str(FILE * stream, char *str);
static void tell_user(FILE * stream, char *fmt, ...);
-static void send_char_msg(unsigned int msg_id, char c);
-static void send_str_msg(unsigned int msg_id, char *str);
static void gui_update_stats(char *name, unsigned long size,
int percentage, unsigned long elapsed);
+/*
+ * The maximum amount of queued data we accept before we stop and
+ * wait for the server to process some.
+ */
+#define MAX_SCP_BUFSIZE 16384
+
void logevent(char *string)
{
}
char *keystr, char *fingerprint)
{
int ret;
+ HANDLE hin;
+ DWORD savemode, i;
static const char absentmsg[] =
"The server's host key is not cached in the registry. You\n"
"%s\n"
"If you trust this host, enter \"y\" to add the key to\n"
"PuTTY's cache and carry on connecting.\n"
- "If you do not trust this host, enter \"n\" to abandon the\n"
- "connection.\n" "Continue connecting? (y/n) ";
+ "If you want to carry on connecting just once, without\n"
+ "adding the key to the cache, enter \"n\".\n"
+ "If you do not trust this host, press Return to abandon the\n"
+ "connection.\n"
+ "Store key in cache? (y/n) ";
static const char wrongmsg[] =
"WARNING - POTENTIAL SECURITY BREACH!\n"
"The new key fingerprint is:\n"
"%s\n"
"If you were expecting this change and trust the new key,\n"
- "enter Yes to update PuTTY's cache and continue connecting.\n"
+ "enter \"y\" to update PuTTY's cache and continue connecting.\n"
"If you want to carry on connecting but without updating\n"
- "the cache, enter No.\n"
+ "the cache, enter \"n\".\n"
"If you want to abandon the connection completely, press\n"
"Return to cancel. Pressing Return is the ONLY guaranteed\n"
"safe choice.\n"
if (ret == 0) /* success - key matched OK */
return;
+
if (ret == 2) { /* key was different */
fprintf(stderr, wrongmsg, fingerprint);
fflush(stderr);
- if (fgets(line, sizeof(line), stdin) &&
- line[0] != '\0' && line[0] != '\n') {
- if (line[0] == 'y' || line[0] == 'Y')
- store_host_key(host, port, keytype, keystr);
- } else {
- fprintf(stderr, abandoned);
- fflush(stderr);
- exit(0);
- }
}
if (ret == 1) { /* key was absent */
fprintf(stderr, absentmsg, fingerprint);
- if (fgets(line, sizeof(line), stdin) &&
- (line[0] == 'y' || line[0] == 'Y'))
+ fflush(stderr);
+ }
+
+ hin = GetStdHandle(STD_INPUT_HANDLE);
+ GetConsoleMode(hin, &savemode);
+ SetConsoleMode(hin, (savemode | ENABLE_ECHO_INPUT |
+ ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
+ ReadFile(hin, line, sizeof(line) - 1, &i, NULL);
+ SetConsoleMode(hin, savemode);
+
+ if (line[0] != '\0' && line[0] != '\r' && line[0] != '\n') {
+ if (line[0] == 'y' || line[0] == 'Y')
store_host_key(host, port, keytype, keystr);
- else {
- fprintf(stderr, abandoned);
- exit(0);
- }
+ } else {
+ fprintf(stderr, abandoned);
+ exit(0);
+ }
+}
+
+/*
+ * Ask whether the selected cipher is acceptable (since it was
+ * below the configured 'warn' threshold).
+ * cs: 0 = both ways, 1 = client->server, 2 = server->client
+ */
+void askcipher(char *ciphername, int cs)
+{
+ HANDLE hin;
+ DWORD savemode, i;
+
+ static const char msg[] =
+ "The first %scipher supported by the server is\n"
+ "%s, which is below the configured warning threshold.\n"
+ "Continue with connection? (y/n) ";
+ static const char abandoned[] = "Connection abandoned.\n";
+
+ char line[32];
+
+ fprintf(stderr, msg,
+ (cs == 0) ? "" :
+ (cs == 1) ? "client-to-server " :
+ "server-to-client ",
+ ciphername);
+ fflush(stderr);
+
+ hin = GetStdHandle(STD_INPUT_HANDLE);
+ GetConsoleMode(hin, &savemode);
+ SetConsoleMode(hin, (savemode | ENABLE_ECHO_INPUT |
+ ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
+ ReadFile(hin, line, sizeof(line) - 1, &i, NULL);
+ SetConsoleMode(hin, savemode);
+
+ if (line[0] == 'y' || line[0] == 'Y') {
+ return;
+ } else {
+ fprintf(stderr, abandoned);
+ exit(0);
}
}
va_end(ap);
strcat(str, "\n");
tell_str(stderr, str);
+ errs++;
+
+ if (gui_mode) {
+ unsigned int msg_id = WM_RET_ERR_CNT;
+ if (list)
+ msg_id = WM_LS_RET_ERR_CNT;
+ while (!PostMessage
+ ((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
+ 0 /*lParam */ ))SleepEx(1000, TRUE);
+ }
exit(1);
}
va_end(ap);
strcat(str, "\n");
tell_str(stderr, str);
+ errs++;
+
+ if (gui_mode) {
+ unsigned int msg_id = WM_RET_ERR_CNT;
+ if (list)
+ msg_id = WM_LS_RET_ERR_CNT;
+ while (!PostMessage
+ ((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
+ 0 /*lParam */ ))SleepEx(1000, TRUE);
+ }
exit(1);
}
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 */
-void from_backend(int is_stderr, char *data, int datalen)
+int from_backend(int is_stderr, char *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
unsigned len = (unsigned) datalen;
*/
if (is_stderr) {
fwrite(data, 1, len, stderr);
- return;
+ return 0;
}
inbuf_head = 0;
* If this is before the real session begins, just return.
*/
if (!outptr)
- return;
+ return 0;
if (outlen > 0) {
unsigned used = outlen;
memcpy(pending + pendlen, p, len);
pendlen += len;
}
+
+ return 0;
+}
+static int scp_process_network_event(void)
+{
+ fd_set readfds;
+
+ FD_ZERO(&readfds);
+ FD_SET(scp_ssh_socket, &readfds);
+ if (select(1, &readfds, NULL, NULL, NULL) < 0)
+ return 0; /* doom */
+ select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
+ return 1;
}
static int ssh_scp_recv(unsigned char *buf, int len)
{
}
while (outlen > 0) {
- fd_set readfds;
-
- FD_ZERO(&readfds);
- FD_SET(scp_ssh_socket, &readfds);
- if (select(1, &readfds, NULL, NULL, NULL) < 0)
+ if (!scp_process_network_event())
return 0; /* doom */
- select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
}
return len;
va_end(ap);
strcat(str, "\n");
tell_str(stderr, str);
+ errs++;
if (back != NULL && back->socket() != NULL) {
char ch;
back->special(TS_EOF);
ssh_scp_recv(&ch, 1);
}
+
+ if (gui_mode) {
+ unsigned int msg_id = WM_RET_ERR_CNT;
+ if (list)
+ msg_id = WM_LS_RET_ERR_CNT;
+ while (!PostMessage
+ ((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
+ 0 /*lParam */ ))SleepEx(1000, TRUE);
+ }
+
exit(1);
}
ssh_scp_init();
if (verbose && realhost != NULL)
tell_user(stderr, "Connected to %s\n", realhost);
+ sfree(realhost);
}
/*
unsigned long eta;
char etastr[10];
int pct;
+ int len;
/* GUI Adaptation - Sept 2000 */
if (gui_mode)
pct = (int) (100.0 * (float) done / size);
- printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
- name, done / 1024, ratebs / 1024.0, etastr, pct);
+ len = printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
+ name, done / 1024, ratebs / 1024.0, etastr, pct);
+ if (len < prev_stats_len)
+ printf("%*s", prev_stats_len - len, "");
+ prev_stats_len = len;
if (done == size)
printf("\n");
if (response())
return;
- if (statistics) {
- stat_bytes = 0;
- stat_starttime = time(NULL);
- stat_lasttime = 0;
- }
+ stat_bytes = 0;
+ stat_starttime = time(NULL);
+ stat_lasttime = 0;
for (i = 0; i < size; i += 4096) {
char transbuf[4096];
DWORD j, k = 4096;
+ int bufsize;
+
if (i + k > size)
k = size - i;
if (!ReadFile(f, transbuf, k, &j, NULL) || j != k) {
printf("\n");
bump("%s: Read error", src);
}
- back->send(transbuf, k);
+ bufsize = back->send(transbuf, k);
if (statistics) {
stat_bytes += k;
if (time(NULL) != stat_lasttime || i + k == size) {
stat_starttime, stat_lasttime);
}
}
+
+ /*
+ * If the network transfer is backing up - that is, the
+ * remote site is not accepting data as fast as we can
+ * produce it - then we must loop on network events until
+ * we have space in the buffer again.
+ */
+ while (bufsize > MAX_SCP_BUFSIZE) {
+ if (!scp_process_network_event())
+ bump("%s: Network error occurred", src);
+ bufsize = back->sendbuffer();
+ }
}
CloseHandle(f);
back->send("", 1);
- if (statistics) {
- stat_bytes = 0;
- stat_starttime = time(NULL);
- stat_lasttime = 0;
- if ((stat_name = strrchr(namebuf, '/')) == NULL)
- stat_name = namebuf;
- else
- stat_name++;
- if (strrchr(stat_name, '\\') != NULL)
- stat_name = strrchr(stat_name, '\\') + 1;
- }
+ stat_bytes = 0;
+ stat_starttime = time(NULL);
+ stat_lasttime = 0;
+ if ((stat_name = strrchr(namebuf, '/')) == NULL)
+ stat_name = namebuf;
+ else
+ stat_name++;
+ if (strrchr(stat_name, '\\') != NULL)
+ stat_name = strrchr(stat_name, '\\') + 1;
for (i = 0; i < size; i += 4096) {
char transbuf[4096];
int main(int argc, char *argv[])
{
int i;
- int list = 0;
default_protocol = PROT_TELNET;