mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
Use consistend return values for packet_wait() functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@462 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -161,7 +161,7 @@ int channel_change_pty_size1(CHANNEL *channel, int cols, int rows) {
|
|||||||
|
|
||||||
ssh_log(session, SSH_LOG_RARE, "Change pty size send");
|
ssh_log(session, SSH_LOG_RARE, "Change pty size send");
|
||||||
|
|
||||||
if (packet_wait(session, SSH_SMSG_SUCCESS, 1) < 0) {
|
if (packet_wait(session, SSH_SMSG_SUCCESS, 1) != SSH_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ int ssh_service_request(SSH_SESSION *session, const char *service) {
|
|||||||
packet_send(session);
|
packet_send(session);
|
||||||
ssh_log(session, SSH_LOG_PACKET,
|
ssh_log(session, SSH_LOG_PACKET,
|
||||||
"Sent SSH_MSG_SERVICE_REQUEST (service %s)\n", service);
|
"Sent SSH_MSG_SERVICE_REQUEST (service %s)\n", service);
|
||||||
if(packet_wait(session,SSH2_MSG_SERVICE_ACCEPT,1)){
|
if (packet_wait(session,SSH2_MSG_SERVICE_ACCEPT,1) != SSH_OK) {
|
||||||
ssh_set_error(session,SSH_FATAL,"did not receive SERVICE_ACCEPT");
|
ssh_set_error(session,SSH_FATAL,"did not receive SERVICE_ACCEPT");
|
||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ int ssh_get_kex(SSH_SESSION *session, int server_kex) {
|
|||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
|
||||||
if (packet_wait(session, SSH2_MSG_KEXINIT, 1)) {
|
if (packet_wait(session, SSH2_MSG_KEXINIT, 1) != SSH_OK) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -624,7 +624,7 @@ int ssh_get_kex1(SSH_SESSION *session) {
|
|||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_PUBLIC_KEY");
|
ssh_log(session, SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_PUBLIC_KEY");
|
||||||
if (packet_wait(session, SSH_SMSG_PUBLIC_KEY, 1)) {
|
if (packet_wait(session, SSH_SMSG_PUBLIC_KEY, 1) != SSH_OK) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -760,7 +760,7 @@ int ssh_get_kex1(SSH_SESSION *session) {
|
|||||||
session->next_crypto = NULL;
|
session->next_crypto = NULL;
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_SUCCESS");
|
ssh_log(session, SSH_LOG_PROTOCOL, "Waiting for a SSH_SMSG_SUCCESS");
|
||||||
if (packet_wait(session,SSH_SMSG_SUCCESS,1)) {
|
if (packet_wait(session,SSH_SMSG_SUCCESS,1) != SSH_OK) {
|
||||||
char buffer[1024] = {0};
|
char buffer[1024] = {0};
|
||||||
snprintf(buffer, sizeof(buffer),
|
snprintf(buffer, sizeof(buffer),
|
||||||
"Key exchange failed: %s", ssh_get_error(session));
|
"Key exchange failed: %s", ssh_get_error(session));
|
||||||
|
|||||||
203
libssh/packet.c
203
libssh/packet.c
@@ -662,105 +662,120 @@ void packet_parse(SSH_SESSION *session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SSH1
|
#ifdef HAVE_SSH1
|
||||||
static int packet_wait1(SSH_SESSION *session,int type,int blocking){
|
static int packet_wait1(SSH_SESSION *session, int type, int blocking) {
|
||||||
enter_function();
|
|
||||||
ssh_log(session,SSH_LOG_PROTOCOL,"packet_wait1 waiting for %d",type);
|
enter_function();
|
||||||
while(1){
|
|
||||||
if ((packet_read1(session) != SSH_OK) ||
|
ssh_log(session, SSH_LOG_PROTOCOL, "packet_wait1 waiting for %d", type);
|
||||||
(packet_translate(session) != SSH_OK)) {
|
|
||||||
leave_function();
|
do {
|
||||||
return -1;
|
if ((packet_read1(session) != SSH_OK) ||
|
||||||
}
|
(packet_translate(session) != SSH_OK)) {
|
||||||
ssh_log(session,SSH_LOG_PACKET,"packet_wait 1 received a type %d packet",session->in_packet.type);
|
leave_function();
|
||||||
switch(session->in_packet.type){
|
return SSH_ERROR;
|
||||||
case SSH_MSG_DISCONNECT:
|
|
||||||
packet_parse(session);
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
case SSH_SMSG_STDOUT_DATA:
|
|
||||||
case SSH_SMSG_STDERR_DATA:
|
|
||||||
case SSH_SMSG_EXITSTATUS:
|
|
||||||
if (channel_handle1(session,type) < 0) {
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SSH_MSG_DEBUG:
|
|
||||||
case SSH_MSG_IGNORE:
|
|
||||||
break;
|
|
||||||
/* case SSH2_MSG_CHANNEL_CLOSE:
|
|
||||||
packet_parse(session);
|
|
||||||
break;;
|
|
||||||
*/
|
|
||||||
default:
|
|
||||||
if(type && (type != session->in_packet.type)){
|
|
||||||
ssh_set_error(session,SSH_FATAL,"waitpacket(): Received a %d type packet, was waiting for a %d\n",session->in_packet.type,type);
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
leave_function();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(blocking==0){
|
|
||||||
leave_function();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
leave_function();
|
ssh_log(session, SSH_LOG_PACKET, "packet_wait1() received a type %d packet",
|
||||||
return 0;
|
session->in_packet.type);
|
||||||
|
switch (session->in_packet.type) {
|
||||||
|
case SSH_MSG_DISCONNECT:
|
||||||
|
packet_parse(session);
|
||||||
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
case SSH_SMSG_STDOUT_DATA:
|
||||||
|
case SSH_SMSG_STDERR_DATA:
|
||||||
|
case SSH_SMSG_EXITSTATUS:
|
||||||
|
if (channel_handle1(session,type) < 0) {
|
||||||
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SSH_MSG_DEBUG:
|
||||||
|
case SSH_MSG_IGNORE:
|
||||||
|
break;
|
||||||
|
/* case SSH2_MSG_CHANNEL_CLOSE:
|
||||||
|
packet_parse(session);
|
||||||
|
break;;
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
if (type && (type != session->in_packet.type)) {
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"packet_wait1(): Received a %d type packet, but expected %d\n",
|
||||||
|
session->in_packet.type, type);
|
||||||
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blocking == 0) {
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
} while(1);
|
||||||
|
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_SSH1 */
|
#endif /* HAVE_SSH1 */
|
||||||
static int packet_wait2(SSH_SESSION *session,int type,int blocking){
|
|
||||||
int ret;
|
static int packet_wait2(SSH_SESSION *session, int type, int blocking) {
|
||||||
enter_function();
|
int rc = SSH_ERROR;
|
||||||
while(1){
|
|
||||||
ret=packet_read2(session);
|
enter_function();
|
||||||
if(ret != SSH_OK){
|
do {
|
||||||
leave_function();
|
rc = packet_read2(session);
|
||||||
return ret;
|
if (rc != SSH_OK) {
|
||||||
}
|
leave_function();
|
||||||
if (packet_translate(session) != SSH_OK) {
|
return rc;
|
||||||
leave_function();
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
switch(session->in_packet.type){
|
|
||||||
case SSH2_MSG_DISCONNECT:
|
|
||||||
packet_parse(session);
|
|
||||||
ssh_log(session, SSH_LOG_PACKET, "received disconnect packet");
|
|
||||||
leave_function();
|
|
||||||
return SSH_ERROR;
|
|
||||||
case SSH2_MSG_CHANNEL_WINDOW_ADJUST:
|
|
||||||
case SSH2_MSG_CHANNEL_DATA:
|
|
||||||
case SSH2_MSG_CHANNEL_EXTENDED_DATA:
|
|
||||||
case SSH2_MSG_CHANNEL_REQUEST:
|
|
||||||
case SSH2_MSG_CHANNEL_EOF:
|
|
||||||
case SSH2_MSG_CHANNEL_CLOSE:
|
|
||||||
packet_parse(session);
|
|
||||||
break;
|
|
||||||
case SSH2_MSG_IGNORE:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if(type && (type != session->in_packet.type)){
|
|
||||||
ssh_set_error(session,SSH_FATAL,"waitpacket(): Received a %d type packet, was waiting for a %d\n",session->in_packet.type,type);
|
|
||||||
leave_function();
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
leave_function();
|
|
||||||
return SSH_OK;
|
|
||||||
}
|
|
||||||
if(blocking==0){
|
|
||||||
leave_function();
|
|
||||||
return SSH_OK; //shouldn't it return SSH_AGAIN here ?
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
leave_function();
|
if (packet_translate(session) != SSH_OK) {
|
||||||
return SSH_OK;
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
switch (session->in_packet.type) {
|
||||||
|
case SSH2_MSG_DISCONNECT:
|
||||||
|
packet_parse(session);
|
||||||
|
ssh_log(session, SSH_LOG_PACKET, "received disconnect packet");
|
||||||
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
case SSH2_MSG_CHANNEL_WINDOW_ADJUST:
|
||||||
|
case SSH2_MSG_CHANNEL_DATA:
|
||||||
|
case SSH2_MSG_CHANNEL_EXTENDED_DATA:
|
||||||
|
case SSH2_MSG_CHANNEL_REQUEST:
|
||||||
|
case SSH2_MSG_CHANNEL_EOF:
|
||||||
|
case SSH2_MSG_CHANNEL_CLOSE:
|
||||||
|
packet_parse(session);
|
||||||
|
break;
|
||||||
|
case SSH2_MSG_IGNORE:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (type && (type != session->in_packet.type)) {
|
||||||
|
ssh_set_error(session, SSH_FATAL,
|
||||||
|
"packet_wait2(): Received a %d type packet, but expected a %d\n",
|
||||||
|
session->in_packet.type, type);
|
||||||
|
leave_function();
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
if (blocking == 0) {
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK; //shouldn't it return SSH_AGAIN here ?
|
||||||
|
}
|
||||||
|
} while(1);
|
||||||
|
|
||||||
|
leave_function();
|
||||||
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
int packet_wait(SSH_SESSION *session, int type, int block){
|
|
||||||
|
int packet_wait(SSH_SESSION *session, int type, int block) {
|
||||||
#ifdef HAVE_SSH1
|
#ifdef HAVE_SSH1
|
||||||
if(session->version==1)
|
if (session->version == 1) {
|
||||||
return packet_wait1(session,type,block);
|
return packet_wait1(session, type, block);
|
||||||
else
|
}
|
||||||
#endif
|
#endif
|
||||||
return packet_wait2(session,type,block);
|
return packet_wait2(session, type, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ static int dh_handshake_server(SSH_SESSION *session){
|
|||||||
PUBLIC_KEY *pub;
|
PUBLIC_KEY *pub;
|
||||||
PRIVATE_KEY *prv;
|
PRIVATE_KEY *prv;
|
||||||
BUFFER *buf=buffer_new();
|
BUFFER *buf=buffer_new();
|
||||||
if(packet_wait(session, SSH2_MSG_KEXDH_INIT ,1))
|
if (packet_wait(session, SSH2_MSG_KEXDH_INIT, 1) != SSH_OK)
|
||||||
return -1;
|
return -1;
|
||||||
e=buffer_get_ssh_string(session->in_buffer);
|
e=buffer_get_ssh_string(session->in_buffer);
|
||||||
if(!e){
|
if(!e){
|
||||||
|
|||||||
Reference in New Issue
Block a user