Made channel_open_session partially asynchronous
Этот коммит содержится в:
родитель
77baa2df15
Коммит
8d1faa0dbc
@ -46,6 +46,9 @@ struct ssh_channel_struct {
|
|||||||
int exit_status;
|
int exit_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail);
|
||||||
|
|
||||||
void channel_handle(ssh_session session, int type);
|
void channel_handle(ssh_session session, int type);
|
||||||
ssh_channel channel_new(ssh_session session);
|
ssh_channel channel_new(ssh_session session);
|
||||||
int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
int channel_default_bufferize(ssh_channel channel, void *data, int len,
|
||||||
|
@ -114,6 +114,64 @@ uint32_t ssh_channel_new_id(ssh_session session) {
|
|||||||
return ++(session->maxchannel);
|
return ++(session->maxchannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @brief handle a SSH_PACKET_CHANNEL_OPEN_CONFIRMATION packet
|
||||||
|
* Constructs the channel object.
|
||||||
|
*/
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){
|
||||||
|
uint32_t channelid=0;
|
||||||
|
uint32_t tmp;
|
||||||
|
ssh_channel channel;
|
||||||
|
(void)type;
|
||||||
|
(void)user;
|
||||||
|
enter_function();
|
||||||
|
ssh_log(session,SSH_LOG_PACKET,"Received SSH2_MSG_CHANNEL_OPEN_CONFIRMATION");
|
||||||
|
|
||||||
|
buffer_get_u32(packet, &channelid);
|
||||||
|
channelid=ntohl(channelid);
|
||||||
|
channel=ssh_channel_from_local(session,channelid);
|
||||||
|
if(channel==NULL){
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"Unknown channel id %lu",
|
||||||
|
(long unsigned int) channelid);
|
||||||
|
/* TODO: Set error marking in channel object */
|
||||||
|
leave_function();
|
||||||
|
return SSH_PACKET_USED;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_get_u32(packet, &tmp);
|
||||||
|
channel->remote_channel = ntohl(tmp);
|
||||||
|
|
||||||
|
buffer_get_u32(packet, &tmp);
|
||||||
|
channel->remote_window = ntohl(tmp);
|
||||||
|
|
||||||
|
buffer_get_u32(packet,&tmp);
|
||||||
|
channel->remote_maxpacket=ntohl(tmp);
|
||||||
|
|
||||||
|
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||||
|
"Received a CHANNEL_OPEN_CONFIRMATION for channel %d:%d",
|
||||||
|
channel->local_channel,
|
||||||
|
channel->remote_channel);
|
||||||
|
ssh_log(session, SSH_LOG_PROTOCOL,
|
||||||
|
"Remote window : %lu, maxpacket : %lu",
|
||||||
|
(long unsigned int) channel->remote_window,
|
||||||
|
(long unsigned int) channel->remote_maxpacket);
|
||||||
|
|
||||||
|
channel->open = 1;
|
||||||
|
leave_function();
|
||||||
|
return SSH_PACKET_USED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: implement and comment */
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail){
|
||||||
|
(void)packet;
|
||||||
|
(void)user;
|
||||||
|
(void)type;
|
||||||
|
(void)session;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int channel_open(ssh_channel channel, const char *type_c, int window,
|
static int channel_open(ssh_channel channel, const char *type_c, int window,
|
||||||
int maxpacket, ssh_buffer payload) {
|
int maxpacket, ssh_buffer payload) {
|
||||||
ssh_session session = channel->session;
|
ssh_session session = channel->session;
|
||||||
@ -164,44 +222,16 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
|
|||||||
"Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %d",
|
"Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %d",
|
||||||
type_c, channel->local_channel);
|
type_c, channel->local_channel);
|
||||||
|
|
||||||
if (packet_wait(session, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, 1) != SSH_OK) {
|
/* Todo: fix this into a correct loop */
|
||||||
leave_function();
|
/* wait until channel is opened by server */
|
||||||
return -1;
|
while(!channel->open){
|
||||||
|
ssh_handle_packets(session);
|
||||||
}
|
}
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
|
|
||||||
|
/* TODO: put this into the correct packet handler */
|
||||||
switch(session->in_packet.type) {
|
switch(session->in_packet.type) {
|
||||||
case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:
|
|
||||||
buffer_get_u32(session->in_buffer, &tmp);
|
|
||||||
|
|
||||||
if (channel->local_channel != ntohl(tmp)) {
|
|
||||||
ssh_set_error(session, SSH_FATAL,
|
|
||||||
"Server answered with sender channel number %lu instead of given %u",
|
|
||||||
(long unsigned int) ntohl(tmp),
|
|
||||||
channel->local_channel);
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
buffer_get_u32(session->in_buffer, &tmp);
|
|
||||||
channel->remote_channel = ntohl(tmp);
|
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &tmp);
|
|
||||||
channel->remote_window = ntohl(tmp);
|
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer,&tmp);
|
|
||||||
channel->remote_maxpacket=ntohl(tmp);
|
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
|
||||||
"Received a CHANNEL_OPEN_CONFIRMATION for channel %d:%d",
|
|
||||||
channel->local_channel,
|
|
||||||
channel->remote_channel);
|
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
|
||||||
"Remote window : %lu, maxpacket : %lu",
|
|
||||||
(long unsigned int) channel->remote_window,
|
|
||||||
(long unsigned int) channel->remote_maxpacket);
|
|
||||||
|
|
||||||
channel->open = 1;
|
|
||||||
leave_function();
|
|
||||||
return 0;
|
|
||||||
case SSH2_MSG_CHANNEL_OPEN_FAILURE:
|
case SSH2_MSG_CHANNEL_OPEN_FAILURE:
|
||||||
{
|
{
|
||||||
ssh_string error_s;
|
ssh_string error_s;
|
||||||
@ -229,11 +259,6 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
|
|||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
ssh_set_error(session, SSH_FATAL,
|
|
||||||
"Received unknown packet %d\n", session->in_packet.type);
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
|
@ -82,8 +82,8 @@ ssh_packet_callback default_packet_handlers[]= {
|
|||||||
NULL, //#define SSH2_MSG_REQUEST_FAILURE 82
|
NULL, //#define SSH2_MSG_REQUEST_FAILURE 82
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 83-89
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 83-89
|
||||||
NULL, //#define SSH2_MSG_CHANNEL_OPEN 90
|
NULL, //#define SSH2_MSG_CHANNEL_OPEN 90
|
||||||
NULL, //#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
ssh_packet_channel_open_conf, //#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
||||||
NULL, //#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
|
ssh_packet_channel_open_fail, //#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
|
||||||
channel_rcv_change_window, //#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
|
channel_rcv_change_window, //#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
|
||||||
channel_rcv_data, //#define SSH2_MSG_CHANNEL_DATA 94
|
channel_rcv_data, //#define SSH2_MSG_CHANNEL_DATA 94
|
||||||
channel_rcv_data, //#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
|
channel_rcv_data, //#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user