X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/c0a8159289da8df577cc28be1f0c9f7f5c8d33c1..a832773496d46caa5e328d36a15b4918f24a804e:/plink.c diff --git a/plink.c b/plink.c index 91484c66..528eee65 100644 --- a/plink.c +++ b/plink.c @@ -29,7 +29,18 @@ void fatalbox(char *p, ...) WSACleanup(); cleanup_exit(1); } -void connection_fatal(char *p, ...) +void modalfatalbox(char *p, ...) +{ + va_list ap; + fprintf(stderr, "FATAL ERROR: "); + va_start(ap, p); + vfprintf(stderr, p, ap); + va_end(ap); + fputc('\n', stderr); + WSACleanup(); + cleanup_exit(1); +} +void connection_fatal(void *frontend, char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -58,11 +69,14 @@ DWORD orig_console_mode; WSAEVENT netevent; -int term_ldisc(int mode) +static Backend *back; +static void *backhandle; + +int term_ldisc(Terminal *term, int mode) { return FALSE; } -void ldisc_update(int echo, int edit) +void ldisc_update(void *frontend, int echo, int edit) { /* Update stdin read mode to reflect changes in line discipline. */ DWORD mode; @@ -153,7 +167,7 @@ void try_output(int is_stderr) } } -int from_backend(int is_stderr, char *data, int len) +int from_backend(void *frontend_handle, int is_stderr, char *data, int len) { HANDLE h = (is_stderr ? errhandle : outhandle); int osize, esize; @@ -185,14 +199,25 @@ static void usage(void) printf(" (\"host\" can also be a PuTTY saved session name)\n"); printf("Options:\n"); printf(" -v show verbose messages\n"); - printf(" -ssh force use of ssh protocol\n"); + printf(" -load sessname Load settings from saved session\n"); + printf(" -ssh -telnet -rlogin -raw\n"); + printf(" force use of a particular protocol (default SSH)\n"); printf(" -P port connect to specified port\n"); - printf(" -pw passw login with specified password\n"); + printf(" -l user connect with specified username\n"); printf(" -m file read remote command(s) from file\n"); + printf(" -batch disable all interactive prompts\n"); + printf("The following options only apply to SSH connections:\n"); + printf(" -pw passw login with specified password\n"); printf(" -L listen-port:host:port Forward local port to " "remote address\n"); printf(" -R listen-port:host:port Forward remote port to" " local address\n"); + printf(" -X -x enable / disable X11 forwarding\n"); + printf(" -A -a enable / disable agent forwarding\n"); + printf(" -t -T enable / disable pty allocation\n"); + printf(" -1 -2 force use of particular protocol version\n"); + printf(" -C enable compression\n"); + printf(" -i key private key file for authentication\n"); exit(1); } @@ -280,8 +305,6 @@ int main(int argc, char **argv) continue; } else if (!strcmp(p, "-batch")) { console_batch_mode = 1; - } else if (!strcmp(p, "-log")) { - logfile = "putty.log"; } } else if (*p) { if (!*cfg.host) { @@ -438,6 +461,21 @@ int main(int argc, char **argv) */ cfg.host[strcspn(cfg.host, ":")] = '\0'; + /* + * Remove any remaining whitespace from the hostname. + */ + { + int p1 = 0, p2 = 0; + while (cfg.host[p2] != '\0') { + if (cfg.host[p2] != ' ' && cfg.host[p2] != '\t') { + cfg.host[p1] = cfg.host[p2]; + p1++; + } + p2++; + } + cfg.host[p1] = '\0'; + } + if (!*cfg.remote_cmd_ptr) flags |= FLAG_INTERACTIVE; @@ -494,11 +532,14 @@ int main(int argc, char **argv) int nodelay = cfg.tcp_nodelay && (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); - error = back->init(cfg.host, cfg.port, &realhost, nodelay); + error = back->init(NULL, &backhandle, cfg.host, cfg.port, + &realhost, nodelay); if (error) { fprintf(stderr, "Unable to open connection:\n%s", error); return 1; } + logctx = log_init(NULL); + back->provide_logctx(backhandle, logctx); sfree(realhost); } connopen = 1; @@ -550,7 +591,7 @@ int main(int argc, char **argv) while (1) { int n; - if (!sending && back->sendok()) { + if (!sending && back->sendok(backhandle)) { /* * Create a separate thread to read from stdin. This is * a total pain, but I can't find another way to do it: @@ -642,11 +683,11 @@ int main(int argc, char **argv) } else if (n == 1) { reading = 0; noise_ultralight(idata.len); - if (connopen && back->socket() != NULL) { + if (connopen && back->socket(backhandle) != NULL) { if (idata.len > 0) { - back->send(idata.buffer, idata.len); + back->send(backhandle, idata.buffer, idata.len); } else { - back->special(TS_EOF); + back->special(backhandle, TS_EOF); } } } else if (n == 2) { @@ -658,8 +699,8 @@ int main(int argc, char **argv) bufchain_consume(&stdout_data, odata.lenwritten); if (bufchain_size(&stdout_data) > 0) try_output(0); - if (connopen && back->socket() != NULL) { - back->unthrottle(bufchain_size(&stdout_data) + + if (connopen && back->socket(backhandle) != NULL) { + back->unthrottle(backhandle, bufchain_size(&stdout_data) + bufchain_size(&stderr_data)); } } else if (n == 3) { @@ -671,22 +712,22 @@ int main(int argc, char **argv) bufchain_consume(&stderr_data, edata.lenwritten); if (bufchain_size(&stderr_data) > 0) try_output(1); - if (connopen && back->socket() != NULL) { - back->unthrottle(bufchain_size(&stdout_data) + + if (connopen && back->socket(backhandle) != NULL) { + back->unthrottle(backhandle, bufchain_size(&stdout_data) + bufchain_size(&stderr_data)); } } - if (!reading && back->sendbuffer() < MAX_STDIN_BACKLOG) { + if (!reading && back->sendbuffer(backhandle) < MAX_STDIN_BACKLOG) { SetEvent(idata.eventback); reading = 1; } - if ((!connopen || back->socket() == NULL) && + if ((!connopen || back->socket(backhandle) == NULL) && bufchain_size(&stdout_data) == 0 && bufchain_size(&stderr_data) == 0) break; /* we closed the connection */ } WSACleanup(); - exitcode = back->exitcode(); + exitcode = back->exitcode(backhandle); if (exitcode < 0) { fprintf(stderr, "Remote process exit code unavailable\n"); exitcode = 1; /* this is an error condition */