aboutsummaryrefslogtreecommitdiff
path: root/libssh/client.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2006-11-12 00:57:48 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2006-11-12 00:57:48 +0000
commitff273b26b366c1aa2502b3a9828b256cc8d04a06 (patch)
tree00176cf184e0ff22c427ae38768a35b694d918ef /libssh/client.c
parent4442e0e26206a1242a0a9268de5e2731c439e34e (diff)
downloadlibssh-ff273b26b366c1aa2502b3a9828b256cc8d04a06.tar.gz
libssh-ff273b26b366c1aa2502b3a9828b256cc8d04a06.tar.xz
libssh-ff273b26b366c1aa2502b3a9828b256cc8d04a06.zip
oops, forgot to verify that it compiled fine
also, published changes from Norbert including lots of session->fd checks git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@81 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/client.c')
-rw-r--r--libssh/client.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/libssh/client.c b/libssh/client.c
index 6bceb709..da4636a2 100644
--- a/libssh/client.c
+++ b/libssh/client.c
@@ -36,7 +36,7 @@ char *ssh_get_banner(SSH_SESSION *session){
char buffer[128];
int i = 0;
while (i < 127) {
- if(read(session->fd, &buffer[i], 1)<=0){
+ if(session->fd >=0 && read(session->fd, &buffer[i], 1)<=0){
ssh_set_error(session,SSH_FATAL,"Remote host closed connection");
return NULL;
}
@@ -232,6 +232,7 @@ int ssh_connect(SSH_SESSION *session){
ssh_set_error(session,SSH_FATAL,"Must set options before connect");
return SSH_ERROR;
}
+ session->alive=0;
session->client=1;
ssh_crypto_init();
if(options->fd==-1 && !options->host){
@@ -249,43 +250,63 @@ int ssh_connect(SSH_SESSION *session){
session->fd=fd;
session->alive=1;
if(!(session->serverbanner=ssh_get_banner(session))){
- close(fd);
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
set_status(options,0.4);
ssh_say(2,"banner : %s\n",session->serverbanner);
/* here we analyse the different protocols the server allows */
if(ssh_analyze_banner(session,&ssh1,&ssh2)){
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
/* here we decide which version of the protocol to use */
if(ssh2 && options->ssh2allowed)
session->version=2;
+ else if(ssh1 && options->ssh1allowed)
+ session->version=1;
else {
- if(ssh1 && options->ssh1allowed)
- session->version=1;
- else {
- ssh_set_error(session,SSH_FATAL,
- "no version of SSH protocol usable (banner: %s)",
- session->serverbanner);
- return -1;
- }
+ ssh_set_error(session,SSH_FATAL,
+ "no version of SSH protocol usable (banner: %s)",
+ session->serverbanner);
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
+ return -1;
}
ssh_send_banner(session,0);
set_status(options,0.5);
switch(session->version){
case 2:
if(ssh_get_kex(session,0)){
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
set_status(options,0.6);
ssh_list_kex(&session->server_kex);
if(set_kex(session)){
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
ssh_send_kex(session,0);
set_status(options,0.8);
if(dh_handshake(session)){
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
set_status(options,1.0);
@@ -293,6 +314,10 @@ int ssh_connect(SSH_SESSION *session){
break;
case 1:
if(ssh_get_kex1(session)){
+ if(session->fd>=0)
+ close(session->fd);
+ session->fd=-1;
+ session->alive=0;
return -1;
}
set_status(options,0.6);