7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
|
unsigned char *pkblob_in_agent;
int keyi, nkeys;
char *pkblob, *alg, *commentp;
int pklen, alglen, commentlen;
int siglen, retlen, len;
char *q, *agentreq, *ret;
int try_send;
int num_env, env_left, env_ok;
struct Packet *pktout;
Filename *keyfile;
#ifndef NO_GSSAPI
struct ssh_gss_library *gsslib;
Ssh_gss_ctx gss_ctx;
Ssh_gss_buf gss_buf;
|
>
>
>
|
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
|
unsigned char *pkblob_in_agent;
int keyi, nkeys;
char *pkblob, *alg, *commentp;
int pklen, alglen, commentlen;
int siglen, retlen, len;
char *q, *agentreq, *ret;
int try_send;
int requested_x11;
int requested_agent;
int requested_tty;
int num_env, env_left, env_ok;
struct Packet *pktout;
Filename *keyfile;
#ifndef NO_GSSAPI
struct ssh_gss_library *gsslib;
Ssh_gss_ctx gss_ctx;
Ssh_gss_buf gss_buf;
|
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
|
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "simple@putty.projects.tartarus.org");
ssh2_pkt_addbool(s->pktout, 0); /* no reply */
ssh2_pkt_send(ssh, s->pktout);
}
/*
* 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))) {
logevent("Requesting X11 forwarding");
|
>
>
>
>
>
>
>
>
>
>
>
|
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
|
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "simple@putty.projects.tartarus.org");
ssh2_pkt_addbool(s->pktout, 0); /* no reply */
ssh2_pkt_send(ssh, s->pktout);
}
/*
* Enable port forwardings.
*/
ssh_setup_portfwd(ssh, ssh->conf);
/*
* Send the CHANNEL_REQUESTS for the main channel. We send them all
* and then start looking for responses, so it's important that the
* sending and receiving code below it is kept in sync.
*/
/*
* 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))) {
logevent("Requesting X11 forwarding");
|
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
|
* cookie into the log.
*/
dont_log_password(ssh, s->pktout, PKTLOG_BLANK);
ssh2_pkt_addstring(s->pktout, ssh->x11disp->remoteauthdatastring);
end_log_omission(ssh, s->pktout);
ssh2_pkt_adduint32(s->pktout, ssh->x11disp->screennum);
ssh2_pkt_send(ssh, s->pktout);
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to X11 forwarding request:"
" packet type %d", pktin->type));
crStopV;
}
logevent("X11 forwarding refused");
} else {
logevent("X11 forwarding enabled");
ssh->X11_fwd_enabled = TRUE;
}
}
/*
* Enable port forwardings.
*/
ssh_setup_portfwd(ssh, ssh->conf);
/*
* Potentially enable agent forwarding.
*/
if (ssh->mainchan && !ssh->ncmode && conf_get_int(ssh->conf, CONF_agentfwd) && agent_exists()) {
logevent("Requesting OpenSSH-style agent forwarding");
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "auth-agent-req@openssh.com");
ssh2_pkt_addbool(s->pktout, 1); /* want reply */
ssh2_pkt_send(ssh, s->pktout);
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to agent forwarding request:"
" packet type %d", pktin->type));
crStopV;
}
logevent("Agent forwarding refused");
} else {
logevent("Agent forwarding enabled");
ssh->agentfwd_enabled = TRUE;
}
}
/*
* Now allocate a pty for the session.
*/
if (ssh->mainchan && !ssh->ncmode && !conf_get_int(ssh->conf, CONF_nopty)) {
/* Unpick the terminal-speed string. */
/* XXX perhaps we should allow no speeds to be sent. */
|
|
<
<
<
<
<
<
<
<
<
|
<
<
<
<
|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
|
<
|
<
<
|
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
|
* cookie into the log.
*/
dont_log_password(ssh, s->pktout, PKTLOG_BLANK);
ssh2_pkt_addstring(s->pktout, ssh->x11disp->remoteauthdatastring);
end_log_omission(ssh, s->pktout);
ssh2_pkt_adduint32(s->pktout, ssh->x11disp->screennum);
ssh2_pkt_send(ssh, s->pktout);
s->requested_x11 = TRUE;
} else
s->requested_x11 = FALSE;
/*
* Potentially enable agent forwarding.
*/
if (ssh->mainchan && !ssh->ncmode && conf_get_int(ssh->conf, CONF_agentfwd) && agent_exists()) {
logevent("Requesting OpenSSH-style agent forwarding");
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "auth-agent-req@openssh.com");
ssh2_pkt_addbool(s->pktout, 1); /* want reply */
ssh2_pkt_send(ssh, s->pktout);
s->requested_agent = TRUE;
} else
s->requested_agent = FALSE;
/*
* Now allocate a pty for the session.
*/
if (ssh->mainchan && !ssh->ncmode && !conf_get_int(ssh->conf, CONF_nopty)) {
/* Unpick the terminal-speed string. */
/* XXX perhaps we should allow no speeds to be sent. */
|
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
|
ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_ISPEED);
ssh2_pkt_adduint32(s->pktout, ssh->ispeed);
ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_OSPEED);
ssh2_pkt_adduint32(s->pktout, ssh->ospeed);
ssh2_pkt_addstring_data(s->pktout, "\0", 1); /* TTY_OP_END */
ssh2_pkt_send(ssh, s->pktout);
ssh->state = SSH_STATE_INTERMED;
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to pty request:"
" packet type %d", pktin->type));
crStopV;
}
c_write_str(ssh, "Server refused to allocate pty\r\n");
ssh->editing = ssh->echoing = 1;
} else {
logeventf(ssh, "Allocated pty (ospeed %dbps, ispeed %dbps)",
ssh->ospeed, ssh->ispeed);
ssh->got_pty = TRUE;
}
} else {
ssh->editing = ssh->echoing = 1;
}
/*
* Send environment variables.
*
* Simplest thing here is to send all the requests at once, and
* then wait for a whole bunch of successes or failures.
*/
if (ssh->mainchan && !ssh->ncmode) {
char *key, *val;
s->num_env = 0;
for (val = conf_get_str_strs(ssh->conf, CONF_environmt, NULL, &key);
val != NULL;
val = conf_get_str_strs(ssh->conf, CONF_environmt, key, &key)) {
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "env");
ssh2_pkt_addbool(s->pktout, 1); /* want reply */
ssh2_pkt_addstring(s->pktout, key);
ssh2_pkt_addstring(s->pktout, val);
ssh2_pkt_send(ssh, s->pktout);
s->num_env++;
}
if (s->num_env) {
logeventf(ssh, "Sent %d environment variables", s->num_env);
s->env_ok = 0;
s->env_left = s->num_env;
while (s->env_left > 0) {
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to environment request:"
" packet type %d", pktin->type));
crStopV;
}
} else {
s->env_ok++;
}
s->env_left--;
}
if (s->env_ok == s->num_env) {
logevent("All environment variables successfully set");
} else if (s->env_ok == 0) {
logevent("All environment variables refused");
c_write_str(ssh, "Server refused to set environment variables\r\n");
} else {
logeventf(ssh, "%d environment variables refused",
s->num_env - s->env_ok);
c_write_str(ssh, "Server refused to set all environment variables\r\n");
}
}
}
/*
* 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.
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
|
ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_ISPEED);
ssh2_pkt_adduint32(s->pktout, ssh->ispeed);
ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_OSPEED);
ssh2_pkt_adduint32(s->pktout, ssh->ospeed);
ssh2_pkt_addstring_data(s->pktout, "\0", 1); /* TTY_OP_END */
ssh2_pkt_send(ssh, s->pktout);
ssh->state = SSH_STATE_INTERMED;
s->requested_tty = TRUE;
} else
s->requested_tty = FALSE;
/*
* Send environment variables.
*
* Simplest thing here is to send all the requests at once, and
* then wait for a whole bunch of successes or failures.
*/
s->num_env = 0;
if (ssh->mainchan && !ssh->ncmode) {
char *key, *val;
for (val = conf_get_str_strs(ssh->conf, CONF_environmt, NULL, &key);
val != NULL;
val = conf_get_str_strs(ssh->conf, CONF_environmt, key, &key)) {
s->pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_REQUEST);
ssh2_pkt_adduint32(s->pktout, ssh->mainchan->remoteid);
ssh2_pkt_addstring(s->pktout, "env");
ssh2_pkt_addbool(s->pktout, 1); /* want reply */
ssh2_pkt_addstring(s->pktout, key);
ssh2_pkt_addstring(s->pktout, val);
ssh2_pkt_send(ssh, s->pktout);
s->num_env++;
}
if (s->num_env)
logeventf(ssh, "Sent %d environment variables", s->num_env);
}
/*
* All CHANNEL_REQUESTs sent. Now collect up the replies. These
* must be in precisely the same order as the requests.
*/
if (s->requested_x11) {
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to X11 forwarding request:"
" packet type %d", pktin->type));
crStopV;
}
logevent("X11 forwarding refused");
} else {
logevent("X11 forwarding enabled");
ssh->X11_fwd_enabled = TRUE;
}
}
if (s->requested_agent) {
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to agent forwarding request:"
" packet type %d", pktin->type));
crStopV;
}
logevent("Agent forwarding refused");
} else {
logevent("Agent forwarding enabled");
ssh->agentfwd_enabled = TRUE;
}
}
if (s->requested_tty) {
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to pty request:"
" packet type %d", pktin->type));
crStopV;
}
c_write_str(ssh, "Server refused to allocate pty\r\n");
ssh->editing = ssh->echoing = 1;
} else {
logeventf(ssh, "Allocated pty (ospeed %dbps, ispeed %dbps)",
ssh->ospeed, ssh->ispeed);
ssh->got_pty = TRUE;
}
} else {
ssh->editing = ssh->echoing = 1;
}
if (s->num_env) {
s->env_ok = 0;
s->env_left = s->num_env;
while (s->env_left > 0) {
crWaitUntilV(pktin);
if (pktin->type != SSH2_MSG_CHANNEL_SUCCESS) {
if (pktin->type != SSH2_MSG_CHANNEL_FAILURE) {
bombout(("Unexpected response to environment request:"
" packet type %d", pktin->type));
crStopV;
}
} else {
s->env_ok++;
}
s->env_left--;
}
if (s->env_ok == s->num_env) {
logevent("All environment variables successfully set");
} else if (s->env_ok == 0) {
logevent("All environment variables refused");
c_write_str(ssh, "Server refused to set environment variables\r\n");
} else {
logeventf(ssh, "%d environment variables refused",
s->num_env - s->env_ok);
c_write_str(ssh, "Server refused to set all environment variables\r\n");
}
}
/*
* 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.
|