X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=ssh.c;h=b4d3884b10dc40a7d2a3f9b8bed002f3dd66ce72;hb=33c58dd91b8350bd47b363786a3f39587cf8ead6;hp=c419a89dd05f83860b991f05d4a66ef9d9650fde;hpb=b631c1e18e2abb89e8fb8fdf02140f399a1a99c9;p=PuTTY.git diff --git a/ssh.c b/ssh.c index c419a89d..b4d3884b 100644 --- a/ssh.c +++ b/ssh.c @@ -588,14 +588,6 @@ struct outstanding_channel_request { struct outstanding_channel_request *next; }; -/* - * little structure to keep track of outstanding WINDOW_ADJUSTs - */ -struct winadj { - struct winadj *next; - unsigned size; -}; - /* * 2-3-4 tree storing channels. */ @@ -6579,6 +6571,21 @@ static void ssh2_channel_init(struct ssh_channel *c) bufchain_init(&c->v.v2.outbuffer); } +/* + * Construct the common parts of a CHANNEL_OPEN. + */ +static struct Packet *ssh2_chanopen_init(struct ssh_channel *c, char *type) +{ + struct Packet *pktout; + + pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_OPEN); + ssh2_pkt_addstring(pktout, type); + ssh2_pkt_adduint32(pktout, c->localid); + ssh2_pkt_adduint32(pktout, c->v.v2.locwindow);/* our window size */ + ssh2_pkt_adduint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ + return pktout; +} + /* * CHANNEL_FAILURE doesn't come with any indication of what message * caused it, so we have to keep track of the outstanding @@ -9121,11 +9128,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, "Opening direct-tcpip channel to %s:%d in place of session", conf_get_str(ssh->conf, CONF_ssh_nc_host), conf_get_int(ssh->conf, CONF_ssh_nc_port)); - s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_OPEN); - ssh2_pkt_addstring(s->pktout, "direct-tcpip"); - ssh2_pkt_adduint32(s->pktout, ssh->mainchan->localid); - ssh2_pkt_adduint32(s->pktout, ssh->mainchan->v.v2.locwindow);/* our window size */ - ssh2_pkt_adduint32(s->pktout, OUR_V2_MAXPKT); /* our max pkt size */ + s->pktout = ssh2_chanopen_init(ssh->mainchan, "direct-tcpip"); ssh2_pkt_addstring(s->pktout, conf_get_str(ssh->conf, CONF_ssh_nc_host)); ssh2_pkt_adduint32(s->pktout, conf_get_int(ssh->conf, CONF_ssh_nc_port)); /* @@ -9160,11 +9163,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, ssh->mainchan = snew(struct ssh_channel); ssh->mainchan->ssh = ssh; ssh2_channel_init(ssh->mainchan); - s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_OPEN); - ssh2_pkt_addstring(s->pktout, "session"); - ssh2_pkt_adduint32(s->pktout, ssh->mainchan->localid); - ssh2_pkt_adduint32(s->pktout, ssh->mainchan->v.v2.locwindow);/* our window size */ - ssh2_pkt_adduint32(s->pktout, OUR_V2_MAXPKT); /* our max pkt size */ + s->pktout = ssh2_chanopen_init(ssh->mainchan, "session"); ssh2_pkt_send(ssh, s->pktout); crWaitUntilV(pktin); if (pktin->type != SSH2_MSG_CHANNEL_OPEN_CONFIRMATION) { @@ -9226,100 +9225,92 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, */ ssh_setup_portfwd(ssh, ssh->conf); - /* - * Send the CHANNEL_REQUESTS for the main channel. Each one is - * handled by its own little asynchronous co-routine. - */ + if (ssh->mainchan && !ssh->ncmode) { + /* + * Send the CHANNEL_REQUESTS for the main session channel. + * Each one is handled by its own little asynchronous + * co-routine. + */ - /* - * Potentially enable X11 forwarding. - */ - /* - * Potentially enable X11 forwarding. - */ - if (ssh->mainchan && !ssh->ncmode && conf_get_int(ssh->conf, CONF_x11_forward) && - (ssh->x11disp = x11_setup_display(conf_get_str(ssh->conf, CONF_x11_display), - conf_get_int(ssh->conf, CONF_x11_auth), ssh->conf))) - ssh2_setup_x11(ssh->mainchan, NULL, NULL); + /* Potentially enable X11 forwarding. */ + if (conf_get_int(ssh->conf, CONF_x11_forward) && + (ssh->x11disp = + x11_setup_display(conf_get_str(ssh->conf, CONF_x11_display), + conf_get_int(ssh->conf, CONF_x11_auth), + ssh->conf))) + ssh2_setup_x11(ssh->mainchan, NULL, NULL); - /* - * Potentially enable agent forwarding. - */ - if (ssh->mainchan && !ssh->ncmode && conf_get_int(ssh->conf, CONF_agentfwd) && agent_exists()) - ssh2_setup_agent(ssh->mainchan, NULL, NULL); + /* Potentially enable agent forwarding. */ + if (conf_get_int(ssh->conf, CONF_agentfwd) && agent_exists()) + ssh2_setup_agent(ssh->mainchan, NULL, NULL); - /* - * Now allocate a pty for the session. - */ - if (ssh->mainchan && !ssh->ncmode && !conf_get_int(ssh->conf, CONF_nopty)) { - ssh2_setup_pty(ssh->mainchan, NULL, NULL); - } else { - ssh->editing = ssh->echoing = 1; - } + /* Now allocate a pty for the session. */ + if (!conf_get_int(ssh->conf, CONF_nopty)) + ssh2_setup_pty(ssh->mainchan, NULL, NULL); - /* - * Send environment variables. - */ - if (ssh->mainchan && !ssh->ncmode) - ssh2_setup_env(ssh->mainchan, NULL, NULL); + /* Send environment variables. */ + ssh2_setup_env(ssh->mainchan, NULL, NULL); - /* - * Start a shell or a remote command. We may have to attempt - * this twice if the config data has provided a second choice - * of command. - */ - if (ssh->mainchan && !ssh->ncmode) while (1) { - int subsys; - char *cmd; + /* + * Start a shell or a remote command. We may have to attempt + * this twice if the config data has provided a second choice + * of command. + */ + while (1) { + int subsys; + char *cmd; - if (ssh->fallback_cmd) { - subsys = conf_get_int(ssh->conf, CONF_ssh_subsys2); - cmd = conf_get_str(ssh->conf, CONF_remote_cmd2); - } else { - subsys = conf_get_int(ssh->conf, CONF_ssh_subsys); - cmd = conf_get_str(ssh->conf, CONF_remote_cmd); - } + if (ssh->fallback_cmd) { + subsys = conf_get_int(ssh->conf, CONF_ssh_subsys2); + cmd = conf_get_str(ssh->conf, CONF_remote_cmd2); + } else { + subsys = conf_get_int(ssh->conf, CONF_ssh_subsys); + cmd = conf_get_str(ssh->conf, CONF_remote_cmd); + } - if (subsys) { - s->pktout = ssh2_chanreq_init(ssh->mainchan, "subsystem", - ssh2_response_authconn, NULL); - ssh2_pkt_addstring(s->pktout, cmd); - } else if (*cmd) { - s->pktout = ssh2_chanreq_init(ssh->mainchan, "exec", - ssh2_response_authconn, NULL); - ssh2_pkt_addstring(s->pktout, cmd); - } else { - s->pktout = ssh2_chanreq_init(ssh->mainchan, "shell", - ssh2_response_authconn, NULL); - } - ssh2_pkt_send(ssh, s->pktout); + if (subsys) { + s->pktout = ssh2_chanreq_init(ssh->mainchan, "subsystem", + ssh2_response_authconn, NULL); + ssh2_pkt_addstring(s->pktout, cmd); + } else if (*cmd) { + s->pktout = ssh2_chanreq_init(ssh->mainchan, "exec", + ssh2_response_authconn, NULL); + ssh2_pkt_addstring(s->pktout, cmd); + } else { + s->pktout = ssh2_chanreq_init(ssh->mainchan, "shell", + ssh2_response_authconn, NULL); + } + ssh2_pkt_send(ssh, s->pktout); - crWaitUntilV(pktin); + crWaitUntilV(pktin); - if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) { - if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) { - bombout(("Unexpected response to shell/command request:" - " packet type %d", pktin->type)); + if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) { + if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) { + bombout(("Unexpected response to shell/command request:" + " packet type %d", pktin->type)); + crStopV; + } + /* + * We failed to start the command. If this is the + * fallback command, we really are finished; if it's + * not, and if the fallback command exists, try falling + * back to it before complaining. + */ + if (!ssh->fallback_cmd && + *conf_get_str(ssh->conf, CONF_remote_cmd2)) { + logevent("Primary command failed; attempting fallback"); + ssh->fallback_cmd = TRUE; + continue; + } + bombout(("Server refused to start a shell/command")); crStopV; + } else { + logevent("Started a shell/command"); } - /* - * We failed to start the command. If this is the - * fallback command, we really are finished; if it's - * not, and if the fallback command exists, try falling - * back to it before complaining. - */ - if (!ssh->fallback_cmd && - *conf_get_str(ssh->conf, CONF_remote_cmd2)) { - logevent("Primary command failed; attempting fallback"); - ssh->fallback_cmd = TRUE; - continue; - } - bombout(("Server refused to start a shell/command")); - crStopV; - } else { - logevent("Started a shell/command"); + break; } - break; + } else { + ssh->editing = ssh->echoing = TRUE; } ssh->state = SSH_STATE_SESSION; @@ -9328,13 +9319,6 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, if (ssh->eof_needed) ssh_special(ssh, TS_EOF); - /* - * All the initial channel requests are done, so install the default - * response handler. - */ - ssh->packet_dispatch[SSH2_MSG_CHANNEL_SUCCESS] = ssh2_msg_channel_response; - ssh->packet_dispatch[SSH2_MSG_CHANNEL_FAILURE] = ssh2_msg_channel_response; - /* * Transfer data! */ @@ -10170,11 +10154,7 @@ void ssh_send_port_open(void *channel, char *hostname, int port, char *org) /* PKT_STR, , */ PKT_END); } else { - pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_OPEN); - ssh2_pkt_addstring(pktout, "direct-tcpip"); - ssh2_pkt_adduint32(pktout, c->localid); - ssh2_pkt_adduint32(pktout, c->v.v2.locwindow);/* our window size */ - ssh2_pkt_adduint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ + pktout = ssh2_chanopen_init(c, "direct-tcpip"); ssh2_pkt_addstring(pktout, hostname); ssh2_pkt_adduint32(pktout, port); /*