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
Этот коммит содержится в:
родитель
4442e0e262
Коммит
ff273b26b3
13
config.h.in
13
config.h.in
@ -3,6 +3,9 @@
|
||||
/* Define to 1 if you have the `cfmakeraw' function. */
|
||||
#undef HAVE_CFMAKERAW
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
@ -15,8 +18,8 @@
|
||||
/* Define to 1 if you have the <gcrypt.h> header file. */
|
||||
#undef HAVE_GCRYPT_H
|
||||
|
||||
/* Define to 1 if you have the `gethostbyaddr' function. */
|
||||
#undef HAVE_GETHOSTBYADDR
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#undef HAVE_GETADDRINFO
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname' function. */
|
||||
#undef HAVE_GETHOSTBYNAME
|
||||
@ -64,9 +67,6 @@
|
||||
/* Define to 1 if you have the <openssl/des.h> header file. */
|
||||
#undef HAVE_OPENSSL_DES_H
|
||||
|
||||
/* Define to 1 if you have the <pam/pam_appl.h> header file. */
|
||||
#undef HAVE_PAM_PAM_APPL_H
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
#undef HAVE_POLL
|
||||
|
||||
@ -77,9 +77,6 @@
|
||||
and to 0 otherwise. */
|
||||
#undef HAVE_REALLOC
|
||||
|
||||
/* Define to 1 if you have the <security/pam_appl.h> header file. */
|
||||
#undef HAVE_SECURITY_PAM_APPL_H
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#undef HAVE_SELECT
|
||||
|
||||
|
@ -79,7 +79,7 @@ fi
|
||||
|
||||
AC_CHECK_LIB([z], [deflateInit_])
|
||||
AC_SEARCH_LIBS([hstrerror],[nsl resolv])
|
||||
AC_SEARCH_LIBS([getaddrinfo],[nsl resolv])
|
||||
AC_SEARCH_LIBS([getaddrinfo],[nsl socket])
|
||||
AC_SEARCH_LIBS([gethostbyname],[nsl resolv])
|
||||
|
||||
# Checks for header files.
|
||||
|
@ -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);
|
||||
|
@ -146,7 +146,7 @@ int ssh_connect_host(SSH_SESSION *session, const char *host, const char
|
||||
}
|
||||
freeaddrinfo(bind_ai);
|
||||
}
|
||||
if(timeout){
|
||||
if(timeout||usec){
|
||||
return ssh_connect_ai_timeout(session,host,port,ai,timeout,usec,s);
|
||||
}
|
||||
if(connect(s,ai->ai_addr,ai->ai_addrlen)<0){
|
||||
@ -178,9 +178,10 @@ int ssh_fd_poll(SSH_SESSION *session, int *write, int *except){
|
||||
FD_ZERO(&wdes);
|
||||
FD_ZERO(&edes);
|
||||
|
||||
if(!session->alive){
|
||||
if(!session->alive || session->fd<0){
|
||||
*except=1;
|
||||
*write=0;
|
||||
session->alive=0;
|
||||
return 0;
|
||||
}
|
||||
if(!session->data_to_read)
|
||||
|
@ -39,6 +39,8 @@ static int completeread(int fd, void *buffer, int len){
|
||||
int r;
|
||||
int total=0;
|
||||
int toread=len;
|
||||
if(fd<0)
|
||||
return SSH_ERROR;
|
||||
while((r=read(fd,buffer+total,toread))){
|
||||
if(r==-1)
|
||||
return SSH_ERROR;
|
||||
@ -76,6 +78,7 @@ static int socket_read(SSH_SESSION *session,int len){
|
||||
(r==0)?"Connection closed by remote host" : "Error reading socket");
|
||||
close(session->fd);
|
||||
session->fd=-1;
|
||||
session->alive=0;
|
||||
session->data_except=1;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
@ -91,7 +94,10 @@ static int socket_read(SSH_SESSION *session,int len){
|
||||
return SSH_AGAIN;
|
||||
session->data_to_read=0;
|
||||
/* read as much as we can */
|
||||
r=read(session->fd,buffer,sizeof(buffer));
|
||||
if(session->fd>0)
|
||||
r=read(session->fd,buffer,sizeof(buffer));
|
||||
else
|
||||
r=-1;
|
||||
if(r<=0){
|
||||
ssh_set_error(session,SSH_FATAL,
|
||||
(r==0)?"Connection closed by remote host" : "Error reading socket");
|
||||
@ -335,6 +341,8 @@ int packet_translate(SSH_SESSION *session){
|
||||
|
||||
static int atomic_write(int fd, void *buffer, int len){
|
||||
int written;
|
||||
if(fd<0)
|
||||
return SSH_ERROR;
|
||||
while(len >0) {
|
||||
written=write(fd,buffer,len);
|
||||
if(written==0 || written==-1)
|
||||
@ -352,9 +360,12 @@ static int packet_nonblocking_flush(SSH_SESSION *session){
|
||||
int w;
|
||||
ssh_fd_poll(session,&can_write,&except); /* internally sets data_to_write */
|
||||
while(session->data_to_write && buffer_get_rest_len(session->out_socket_buffer)>0){
|
||||
w=write(session->fd,buffer_get_rest(session->out_socket_buffer),
|
||||
if(session->fd<0){
|
||||
w=write(session->fd,buffer_get_rest(session->out_socket_buffer),
|
||||
buffer_get_rest_len(session->out_socket_buffer));
|
||||
session->data_to_write=0;
|
||||
session->data_to_write=0;
|
||||
} else
|
||||
w=-1; /* write failed */
|
||||
if(w<0){
|
||||
session->data_to_write=0;
|
||||
session->data_except=1;
|
||||
@ -376,6 +387,10 @@ static int packet_nonblocking_flush(SSH_SESSION *session){
|
||||
|
||||
/* blocking packet flush */
|
||||
static int packet_blocking_flush(SSH_SESSION *session){
|
||||
if(session->fd<0) {
|
||||
session->alive=0;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
if(session->data_except)
|
||||
return SSH_ERROR;
|
||||
if(buffer_get_rest(session->out_socket_buffer)==0)
|
||||
|
@ -43,6 +43,7 @@ SSH_SESSION *ssh_new() {
|
||||
session->next_crypto=crypto_new();
|
||||
session->maxchannel=FIRST_CHANNEL;
|
||||
session->fd=-1;
|
||||
session->alive=0;
|
||||
session->blocking=1;
|
||||
return session;
|
||||
}
|
||||
@ -96,8 +97,10 @@ void ssh_cleanup(SSH_SESSION *session){
|
||||
* \param session current ssh session
|
||||
*/
|
||||
void ssh_silent_disconnect(SSH_SESSION *session){
|
||||
close(session->fd);
|
||||
if(session->fd>=0)
|
||||
close(session->fd);
|
||||
session->alive=0;
|
||||
session->fd=-1;
|
||||
ssh_disconnect(session);
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user