X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/70e5d0fd16d26307b670972cdfd2a12c21a06572..a6253970d63f1b9f3c9d31a9bc8cfab3cdd3be3f:/ssh.c?ds=sidebyside diff --git a/ssh.c b/ssh.c index 442d35a3..c52301eb 100644 --- a/ssh.c +++ b/ssh.c @@ -166,7 +166,7 @@ static const char *const ssh2_disconnect_reasons[] = { #define translate(x) if (type == x) return #x #define translatec(x,ctx) if (type == x && (pkt_ctx & ctx)) return #x -char *ssh1_pkt_type(int type) +static char *ssh1_pkt_type(int type) { translate(SSH1_MSG_DISCONNECT); translate(SSH1_SMSG_PUBLIC_KEY); @@ -211,7 +211,7 @@ char *ssh1_pkt_type(int type) translate(SSH1_CMSG_AUTH_CCARD_RESPONSE); return "unknown"; } -char *ssh2_pkt_type(int pkt_ctx, int type) +static char *ssh2_pkt_type(int pkt_ctx, int type) { translate(SSH2_MSG_DISCONNECT); translate(SSH2_MSG_IGNORE); @@ -291,23 +291,6 @@ enum { PKT_END, PKT_INT, PKT_CHAR, PKT_DATA, PKT_STR, PKT_BIGNUM }; typedef struct ssh_tag *Ssh; -extern char *x11_init(Socket *, char *, void *, void *); -extern void x11_close(Socket); -extern int x11_send(Socket, char *, int); -extern void *x11_invent_auth(char *, int, char *, int); -extern void x11_unthrottle(Socket s); -extern void x11_override_throttle(Socket s, int enable); -extern int x11_get_screen_number(char *display); - -extern char *pfd_newconnect(Socket * s, char *hostname, int port, void *c); -extern char *pfd_addforward(char *desthost, int destport, char *srcaddr, - int port, void *backhandle); -extern void pfd_close(Socket s); -extern int pfd_send(Socket s, char *data, int len); -extern void pfd_confirm(Socket s); -extern void pfd_unthrottle(Socket s); -extern void pfd_override_throttle(Socket s, int enable); - static void ssh2_pkt_init(Ssh, int pkt_type); static void ssh2_pkt_addbool(Ssh, unsigned char value); static void ssh2_pkt_adduint32(Ssh, unsigned long value); @@ -642,7 +625,7 @@ struct ssh_tag { #define logevent(s) logevent(ssh->frontend, s) /* logevent, only printf-formatted. */ -void logeventf(Ssh ssh, char *fmt, ...) +static void logeventf(Ssh ssh, char *fmt, ...) { va_list ap; char *buf; @@ -1861,7 +1844,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c) s->i = -1; } else if (s->i < sizeof(s->version) - 1) s->version[s->i++] = c; - } else if (c == '\n') + } else if (c == '\012') break; } @@ -1911,7 +1894,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c) sha_string(&ssh->exhashbase, s->vstring, strcspn(s->vstring, "\r\n")); sprintf(vlog, "We claim version: %s", verstring); logevent(vlog); - strcat(verstring, "\n"); + strcat(verstring, "\012"); logevent("Using SSH protocol version 2"); sk_write(ssh->s, verstring, strlen(verstring)); ssh->protocol = ssh2_protocol; @@ -1927,7 +1910,7 @@ static int do_ssh_init(Ssh ssh, unsigned char c) sshver); sprintf(vlog, "We claim version: %s", verstring); logevent(vlog); - strcat(verstring, "\n"); + strcat(verstring, "\012"); logevent("Using SSH protocol version 1"); sk_write(ssh->s, verstring, strlen(verstring)); @@ -2142,7 +2125,7 @@ static void ssh_throttle_all(Ssh ssh, int enable, int bufsize) */ /* Set up a username or password input loop on a given buffer. */ -void setup_userpass_input(Ssh ssh, char *buffer, int buflen, int echo) +static void setup_userpass_input(Ssh ssh, char *buffer, int buflen, int echo) { ssh->userpass_input_buffer = buffer; ssh->userpass_input_buflen = buflen; @@ -2156,7 +2139,7 @@ void setup_userpass_input(Ssh ssh, char *buffer, int buflen, int echo) * buffer), <0 for failure (user hit ^C/^D, bomb out and exit), 0 * for inconclusive (keep waiting for more input please). */ -int process_userpass_input(Ssh ssh, unsigned char *in, int inlen) +static int process_userpass_input(Ssh ssh, unsigned char *in, int inlen) { char c; @@ -3036,6 +3019,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt) logevent("Requesting X11 forwarding"); ssh->x11auth = x11_invent_auth(proto, sizeof(proto), data, sizeof(data)); + x11_get_real_auth(ssh->x11auth, cfg.x11_display); if (ssh->v1_local_protoflags & SSH1_PROTOFLAG_SCREEN_NUMBER) { send_packet(ssh, SSH1_CMSG_X11_REQUEST_FORWARDING, PKT_STR, proto, PKT_STR, data, @@ -4959,6 +4943,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt) ssh2_pkt_addstring(ssh, "password"); ssh2_pkt_addbool(ssh, FALSE); ssh2_pkt_addstring(ssh, s->password); + memset(s->password, 0, sizeof(s->password)); ssh2_pkt_defer(ssh); /* * We'll include a string that's an exact multiple of the @@ -5084,6 +5069,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt) logevent("Requesting X11 forwarding"); ssh->x11auth = x11_invent_auth(proto, sizeof(proto), data, sizeof(data)); + x11_get_real_auth(ssh->x11auth, cfg.x11_display); ssh2_pkt_init(ssh, SSH2_MSG_CHANNEL_REQUEST); ssh2_pkt_adduint32(ssh, ssh->mainchan->remoteid); ssh2_pkt_addstring(ssh, "x11-req"); @@ -5603,8 +5589,8 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt) unsigned i = ssh2_pkt_getuint32(ssh); struct ssh_channel *c; c = find234(ssh->channels, &i, ssh_channelfind); - if (!c) - continue; /* nonexistent channel */ + if (!c || c->closes) + continue; /* nonexistent or closing channel */ c->v.v2.remwindow += ssh2_pkt_getuint32(ssh); s->try_send = TRUE; } else if (ssh->pktin.type == SSH2_MSG_CHANNEL_OPEN_CONFIRMATION) { @@ -5825,7 +5811,10 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt) * Try to send data on all channels if we can. */ for (i = 0; NULL != (c = index234(ssh->channels, i)); i++) { - int bufsize = ssh2_try_send(c); + int bufsize; + if (c->closes) + continue; /* don't send on closing channels */ + bufsize = ssh2_try_send(c); if (bufsize == 0) { switch (c->type) { case CHAN_MAINSESSION: @@ -5943,6 +5932,8 @@ static char *ssh_init(void *frontend_handle, void **backend_handle, ssh->overall_bufsize = 0; ssh->fallback_cmd = 0; + ssh->protocol = NULL; + p = connect_to_host(ssh, host, port, realhost, nodelay); if (p != NULL) return p; @@ -6104,7 +6095,7 @@ void *new_sock_channel(void *handle, Socket s) * This is called when stdout/stderr (the entity to which * from_backend sends data) manages to clear some backlog. */ -void ssh_unthrottle(void *handle, int bufsize) +static void ssh_unthrottle(void *handle, int bufsize) { Ssh ssh = (Ssh) handle; if (ssh->version == 1) {