static unsigned long statsize = 0;
static int statperct = 0;
static unsigned long statelapsed = 0;
static unsigned long statsize = 0;
static int statperct = 0;
static unsigned long statelapsed = 0;
static void rsource(char *src);
static void sink(char *targ, char *src);
/* GUI Adaptation - Sept 2000 */
static void rsource(char *src);
static void sink(char *targ, char *src);
/* 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 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,
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,
-void begin_session(void) { }
-void logevent(char *string) { }
+void logevent(char *string)
+{
+}
+
+void ldisc_send(char *buf, int len)
+{
+ /*
+ * This is only here because of the calls to ldisc_send(NULL,
+ * 0) in ssh.c. Nothing in PSCP 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 verify_ssh_host_key(char *host, int port, char *keytype,
void verify_ssh_host_key(char *host, int port, char *keytype,
- "The server's host key is not cached in the registry. You\n"
- "have no guarantee that the server is the computer you\n"
- "think it is.\n"
- "The server's key fingerprint is:\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) ";
+ "The server's host key is not cached in the registry. You\n"
+ "have no guarantee that the server is the computer you\n"
+ "think it is.\n"
+ "The server's key fingerprint is:\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) ";
- "WARNING - POTENTIAL SECURITY BREACH!\n"
- "The server's host key does not match the one PuTTY has\n"
- "cached in the registry. This means that either the\n"
- "server administrator has changed the host key, or you\n"
- "have actually connected to another computer pretending\n"
- "to be the server.\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"
- "If you want to carry on connecting but without updating\n"
- "the cache, enter No.\n"
- "If you want to abandon the connection completely, press\n"
- "Return to cancel. Pressing Return is the ONLY guaranteed\n"
- "safe choice.\n"
- "Update cached key? (y/n, Return cancels connection) ";
+ "WARNING - POTENTIAL SECURITY BREACH!\n"
+ "The server's host key does not match the one PuTTY has\n"
+ "cached in the registry. This means that either the\n"
+ "server administrator has changed the host key, or you\n"
+ "have actually connected to another computer pretending\n"
+ "to be the server.\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"
+ "If you want to carry on connecting but without updating\n"
+ "the cache, enter No.\n"
+ "If you want to abandon the connection completely, press\n"
+ "Return to cancel. Pressing Return is the ONLY guaranteed\n"
+ "safe choice.\n"
+ "Update cached key? (y/n, Return cancels connection) ";
*/
ret = verify_host_key(host, port, keytype, keystr);
*/
ret = verify_host_key(host, port, keytype, keystr);
- if (ret == 0) /* success - key matched OK */
- return;
- if (ret == 2) { /* key was different */
- fprintf(stderr, wrongmsg, fingerprint);
- 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);
- exit(0);
- }
+ 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'))
- store_host_key(host, port, keytype, keystr);
- else {
- fprintf(stderr, abandoned);
- exit(0);
- }
+ if (ret == 1) { /* key was absent */
+ fprintf(stderr, absentmsg, fingerprint);
+ if (fgets(line, sizeof(line), stdin) &&
+ (line[0] == 'y' || line[0] == 'Y'))
+ store_host_key(host, port, keytype, keystr);
+ else {
+ fprintf(stderr, abandoned);
+ exit(0);
+ }
}
}
/* GUI Adaptation - Sept 2000 */
static void send_msg(HWND h, UINT message, WPARAM wParam)
{
}
}
/* GUI Adaptation - Sept 2000 */
static void send_msg(HWND h, UINT message, WPARAM wParam)
{
- while (!PostMessage( h, message, wParam, 0))
- SleepEx(1000,TRUE);
+ while (!PostMessage(h, message, wParam, 0))
+ SleepEx(1000, TRUE);
- if (stream == stderr) msg_id = WM_STD_ERR_CHAR;
- send_msg( (HWND)atoi(gui_hwnd), msg_id, (WPARAM)c );
+ if (stream == stderr)
+ msg_id = WM_STD_ERR_CHAR;
+ send_msg((HWND) atoi(gui_hwnd), msg_id, (WPARAM) c);
-static void gui_update_stats(char *name, unsigned long size, int percentage, unsigned long elapsed)
+static void gui_update_stats(char *name, unsigned long size,
+ int percentage, unsigned long elapsed)
- if (strcmp(name,statname) != 0)
- {
- for( i = 0; i < strlen(name); ++i )
- send_msg( (HWND)atoi(gui_hwnd), WM_STATS_CHAR, (WPARAM)name[i]);
- send_msg( (HWND)atoi(gui_hwnd), WM_STATS_CHAR, (WPARAM)'\n' );
- strcpy(statname,name);
+ if (strcmp(name, statname) != 0) {
+ for (i = 0; i < strlen(name); ++i)
+ send_msg((HWND) atoi(gui_hwnd), WM_STATS_CHAR,
+ (WPARAM) name[i]);
+ send_msg((HWND) atoi(gui_hwnd), WM_STATS_CHAR, (WPARAM) '\n');
+ strcpy(statname, name);
- if (statsize != size)
- {
- send_msg( (HWND)atoi(gui_hwnd), WM_STATS_SIZE, (WPARAM)size );
+ if (statsize != size) {
+ send_msg((HWND) atoi(gui_hwnd), WM_STATS_SIZE, (WPARAM) size);
- if (statelapsed != elapsed)
- {
- send_msg( (HWND)atoi(gui_hwnd), WM_STATS_ELAPSED, (WPARAM)elapsed );
+ if (statelapsed != elapsed) {
+ send_msg((HWND) atoi(gui_hwnd), WM_STATS_ELAPSED,
+ (WPARAM) elapsed);
- if (statperct != percentage)
- {
- send_msg( (HWND)atoi(gui_hwnd), WM_STATS_PERCENT, (WPARAM)percentage );
+ if (statperct != percentage) {
+ send_msg((HWND) atoi(gui_hwnd), WM_STATS_PERCENT,
+ (WPARAM) percentage);
-static unsigned char *outptr; /* where to put the data */
-static unsigned outlen; /* how much data required */
+static unsigned char *outptr; /* where to put the data */
+static unsigned outlen; /* how much data required */
-static unsigned pendlen=0, pendsize=0; /* length and phys. size of buffer */
-void from_backend(int is_stderr, char *data, int datalen) {
- unsigned char *p = (unsigned char *)data;
- unsigned len = (unsigned)datalen;
+static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
+void from_backend(int is_stderr, char *data, int datalen)
+{
+ unsigned char *p = (unsigned char *) data;
+ unsigned len = (unsigned) datalen;
- unsigned used = outlen;
- if (used > len) used = len;
- memcpy(outptr, p, used);
- outptr += used; outlen -= used;
- p += used; len -= used;
+ unsigned used = outlen;
+ if (used > len)
+ used = len;
+ memcpy(outptr, p, used);
+ outptr += used;
+ outlen -= used;
+ p += used;
+ len -= used;
- if (pendsize < pendlen + len) {
- pendsize = pendlen + len + 4096;
- pending = (pending ? realloc(pending, pendsize) :
- malloc(pendsize));
- if (!pending)
- fatalbox("Out of memory");
- }
- memcpy(pending+pendlen, p, len);
- pendlen += len;
+ if (pendsize < pendlen + len) {
+ pendsize = pendlen + len + 4096;
+ pending = (pending ? srealloc(pending, pendsize) :
+ smalloc(pendsize));
+ if (!pending)
+ fatalbox("Out of memory");
+ }
+ memcpy(pending + pendlen, p, len);
+ pendlen += len;
- 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);
+ 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);
- fd_set readfds;
- FD_ZERO(&readfds);
- FD_SET(scp_ssh_socket, &readfds);
- if (select(1, &readfds, NULL, NULL, NULL) < 0)
- return; /* doom */
- select_result((WPARAM)scp_ssh_socket, (LPARAM)FD_READ);
+ fd_set readfds;
+ FD_ZERO(&readfds);
+ FD_SET(scp_ssh_socket, &readfds);
+ if (select(1, &readfds, NULL, NULL, NULL) < 0)
+ return; /* doom */
+ select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
-static int get_password(const char *prompt, char *str, int maxlen)
+static int get_line(const char *prompt, char *str, int maxlen, int is_pw)
- DWORD savemode, i;
-
- if (password) {
- static int tried_once = 0;
-
- if (tried_once) {
- return 0;
- } else {
- strncpy(str, password, maxlen);
- str[maxlen-1] = '\0';
- tried_once = 1;
- return 1;
- }
+ DWORD savemode, newmode, i;
+
+ if (is_pw && password) {
+ static int tried_once = 0;
+
+ if (tried_once) {
+ return 0;
+ } else {
+ strncpy(str, password, maxlen);
+ str[maxlen - 1] = '\0';
+ tried_once = 1;
+ return 1;
+ }
bump("Cannot get standard input/output handles");
GetConsoleMode(hin, &savemode);
bump("Cannot get standard input/output handles");
GetConsoleMode(hin, &savemode);
- SetConsoleMode(hin, (savemode & (~ENABLE_ECHO_INPUT)) |
- ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT);
+ newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT;
+ if (is_pw)
+ newmode &= ~ENABLE_ECHO_INPUT;
+ else
+ newmode |= ENABLE_ECHO_INPUT;
+ SetConsoleMode(hin, newmode);
WriteFile(hout, prompt, strlen(prompt), &i, NULL);
WriteFile(hout, prompt, strlen(prompt), &i, NULL);
- ReadFile(hin, str, maxlen-1, &i, NULL);
+ ReadFile(hin, str, maxlen - 1, &i, NULL);
- WriteFile(hout, "\r\n", 2, &i, NULL);
+ if (is_pw)
+ WriteFile(hout, "\r\n", 2, &i, NULL);
- do_defaults(NULL, &cfg);
- strncpy(cfg.host, host, sizeof(cfg.host)-1);
- cfg.host[sizeof(cfg.host)-1] = '\0';
+ do_defaults(NULL, &cfg);
+ strncpy(cfg.host, host, sizeof(cfg.host) - 1);
+ cfg.host[sizeof(cfg.host) - 1] = '\0';
- strncpy(cfg.username, user, sizeof(cfg.username)-1);
- cfg.username[sizeof(cfg.username)-1] = '\0';
+ strncpy(cfg.username, user, sizeof(cfg.username) - 1);
+ cfg.username[sizeof(cfg.username) - 1] = '\0';
- bump("Empty user name");
+ namelen = 0;
+ if (GetUserName(user, &namelen) == FALSE)
+ bump("Empty user name");
+ user = smalloc(namelen * sizeof(char));
+ GetUserName(user, &namelen);
+ if (verbose)
+ tell_user(stderr, "Guessing user name: %s", user);
+ strncpy(cfg.username, user, sizeof(cfg.username) - 1);
+ cfg.username[sizeof(cfg.username) - 1] = '\0';
+ free(user);
* Update statistic information about current file.
*/
static void print_stats(char *name, unsigned long size, unsigned long done,
* Update statistic information about current file.
*/
static void print_stats(char *name, unsigned long size, unsigned long done,
- gui_update_stats(name, size, (int)(100 * (done*1.0/size)),
- (unsigned long)difftime(now, start));
+ gui_update_stats(name, size, (int) (100 * (done * 1.0 / size)),
+ (unsigned long) difftime(now, start));
pct = (int) (100.0 * (float) done / size);
printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
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);
+ name, done / 1024, ratebs / 1024.0, etastr, pct);
* Find a colon in str and return a pointer to the colon.
* This is used to separate hostname from filename.
*/
* Find a colon in str and return a pointer to the colon.
* This is used to separate hostname from filename.
*/
- empty. We also ignore a colon as second character because
- of filenames like f:myfile.txt. */
- if (str[0] == '\0' ||
- str[0] == ':' ||
- str[1] == ':')
+ empty. We also ignore a colon as second character because
+ of filenames like f:myfile.txt. */
+ if (str[0] == '\0' || str[0] == ':' || str[1] == ':')
do {
if (ssh_scp_recv(&ch, 1) <= 0)
bump("Protocol error: Lost connection");
rbuf[p++] = ch;
} while (p < sizeof(rbuf) && ch != '\n');
do {
if (ssh_scp_recv(&ch, 1) <= 0)
bump("Protocol error: Lost connection");
rbuf[p++] = ch;
} while (p < sizeof(rbuf) && ch != '\n');
time_t stat_starttime, stat_lasttime;
attr = GetFileAttributes(src);
time_t stat_starttime, stat_lasttime;
attr = GetFileAttributes(src);
run_err("%s: No such file or directory", src);
return;
}
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
if (recursive) {
run_err("%s: No such file or directory", src);
return;
}
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
if (recursive) {
- /*
- * Avoid . and .. directories.
- */
- char *p;
- p = strrchr(src, '/');
- if (!p)
- p = strrchr(src, '\\');
- if (!p)
- p = src;
- else
- p++;
- if (!strcmp(p, ".") || !strcmp(p, ".."))
- /* skip . and .. */;
- else
- rsource(src);
- } else {
+ /*
+ * Avoid . and .. directories.
+ */
+ char *p;
+ p = strrchr(src, '/');
+ if (!p)
+ p = strrchr(src, '\\');
+ if (!p)
+ p = src;
+ else
+ p++;
+ if (!strcmp(p, ".") || !strcmp(p, ".."))
+ /* skip . and .. */ ;
+ else
+ rsource(src);
+ } else {
- if (i + k > size) k = size - i;
- if (! ReadFile(f, transbuf, k, &j, NULL) || j != k) {
- if (statistics) printf("\n");
+ if (i + k > size)
+ k = size - i;
+ if (!ReadFile(f, transbuf, k, &j, NULL) || j != k) {
+ if (statistics)
+ printf("\n");
stat_lasttime = time(NULL);
print_stats(last, size, stat_bytes,
stat_starttime, stat_lasttime);
stat_lasttime = time(NULL);
print_stats(last, size, stat_bytes,
stat_starttime, stat_lasttime);
while (ok) {
if (strcmp(fdat.cFileName, ".") == 0 ||
strcmp(fdat.cFileName, "..") == 0) {
while (ok) {
if (strcmp(fdat.cFileName, ".") == 0 ||
strcmp(fdat.cFileName, "..") == 0) {
run_err("%s/%s: Name too long", src, fdat.cFileName);
} else {
sprintf(buf, "%s/%s", src, fdat.cFileName);
run_err("%s/%s: Name too long", src, fdat.cFileName);
} else {
sprintf(buf, "%s/%s", src, fdat.cFileName);
- case '\01': /* error */
- tell_user(stderr, "%s\n", buf+1);
+ case '\01': /* error */
+ tell_user(stderr, "%s\n", buf + 1);
- if (sscanf(buf, "T%ld %*d %ld %*d",
- &mtime, &atime) == 2) {
+ if (sscanf(buf, "T%ld %*d %ld %*d", &mtime, &atime) == 2) {
- if (sscanf(buf+1, "%u %lu %[^\n]", &mode, &size, namebuf) != 3)
+ if (sscanf(buf + 1, "%u %lu %[^\n]", &mode, &size, namebuf) != 3)
bump("Protocol error: Illegal file descriptor format");
/* Security fix: ensure the file ends up where we asked for it. */
if (targisdir) {
bump("Protocol error: Illegal file descriptor format");
/* Security fix: ensure the file ends up where we asked for it. */
if (targisdir) {
- if (! CreateDirectory(namebuf, NULL)) {
- run_err("%s: Cannot create directory",
- namebuf);
+ if (!CreateDirectory(namebuf, NULL)) {
+ run_err("%s: Cannot create directory", namebuf);
- if (wrerror) continue;
- if (! WriteFile(f, transbuf, k, &j, NULL) || j != k) {
+ if (wrerror)
+ continue;
+ if (!WriteFile(f, transbuf, k, &j, NULL) || j != k) {
stat_lasttime = time(NULL);
print_stats(stat_name, size, stat_bytes,
stat_starttime, stat_lasttime);
stat_lasttime = time(NULL);
print_stats(stat_name, size, stat_bytes,
stat_starttime, stat_lasttime);
*/
int len = strlen(src), dlen = strlen(fdat.cFileName);
if (len == dlen && !strcmp(src, fdat.cFileName)) {
*/
int len = strlen(src), dlen = strlen(fdat.cFileName);
if (len == dlen && !strcmp(src, fdat.cFileName)) {
- /* ok */;
- } else if (len > dlen+1 && src[len-dlen-1] == '\\' &&
- !strcmp(src+len-dlen, fdat.cFileName)) {
- /* ok */;
+ /* ok */ ;
+ } else if (len > dlen + 1 && src[len - dlen - 1] == '\\' &&
+ !strcmp(src + len - dlen, fdat.cFileName)) {
+ /* ok */ ;
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata))
bump("Unable to initialise WinSock");
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata))
bump("Unable to initialise WinSock");
printf(" -v show verbose messages\n");
printf(" -P port connect to specified port\n");
printf(" -pw passw login with specified password\n");
printf(" -v show verbose messages\n");
printf(" -P port connect to specified port\n");
printf(" -pw passw login with specified password\n");
- /* GUI Adaptation - Sept 2000 */
- printf(" -gui hWnd GUI mode with the windows handle for receiving messages\n");
+#if 0
+ /*
+ * -gui is an internal option, used by GUI front ends to get
+ * pscp to pass progress reports back to them. It's not an
+ * ordinary user-accessible option, so it shouldn't be part of
+ * the command-line help. The only people who need to know
+ * about it are programmers, and they can read the source.
+ */
+ printf
+ (" -gui hWnd GUI mode with the windows handle for receiving messages\n");
+#endif
- else if (strcmp(argv[i], "-h") == 0 ||
- strcmp(argv[i], "-?") == 0)
+ else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0)
- if (list) msg_id = WM_LS_RET_ERR_CNT;
- while (!PostMessage( (HWND)atoi(gui_hwnd), msg_id, (WPARAM)errs, 0/*lParam*/ ) )
- SleepEx(1000,TRUE);
+ if (list)
+ msg_id = WM_LS_RET_ERR_CNT;
+ while (!PostMessage
+ ((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
+ 0 /*lParam */ ))SleepEx(1000, TRUE);