aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure174
-rw-r--r--configure.in6
-rw-r--r--include/libssh/libssh.h13
-rw-r--r--libssh/kex.c6
-rw-r--r--libssh/options.c17
-rw-r--r--sample.c14
7 files changed, 183 insertions, 50 deletions
diff --git a/config.h.in b/config.h.in
index 4b54f23c..9cf951c5 100644
--- a/config.h.in
+++ b/config.h.in
@@ -172,4 +172,5 @@
#undef realloc
#undef HAVE_SSH1
-
+#undef HAVE_PTY_H
+#undef HAVE_STDINT_H
diff --git a/configure b/configure
index c8e8422c..dcc53c11 100755
--- a/configure
+++ b/configure
@@ -2934,14 +2934,13 @@ _ACEOF
fi
-
-echo "$as_me:$LINENO: checking for gethostbyname in -lresolv" >&5
-echo $ECHO_N "checking for gethostbyname in -lresolv... $ECHO_C" >&6
-if test "${ac_cv_lib_resolv_gethostbyname+set}" = set; then
+echo "$as_me:$LINENO: checking for library containing hstrerror" >&5
+echo $ECHO_N "checking for library containing hstrerror... $ECHO_C" >&6
+if test "${ac_cv_search_hstrerror+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lresolv $LIBS"
+ ac_func_search_save_LIBS=$LIBS
+ac_cv_search_hstrerror=no
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -2955,11 +2954,11 @@ extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
-char gethostbyname ();
+char hstrerror ();
int
main ()
{
-gethostbyname ();
+hstrerror ();
;
return 0;
}
@@ -2986,36 +2985,88 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- ac_cv_lib_resolv_gethostbyname=yes
+ ac_cv_search_hstrerror="none required"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_lib_resolv_gethostbyname=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_resolv_gethostbyname" >&5
-echo "${ECHO_T}$ac_cv_lib_resolv_gethostbyname" >&6
-if test $ac_cv_lib_resolv_gethostbyname = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBRESOLV 1
+if test "$ac_cv_search_hstrerror" = no; then
+ for ac_lib in nsl resolv; do
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
- LIBS="-lresolv $LIBS"
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char hstrerror ();
+int
+main ()
+{
+hstrerror ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_hstrerror="-l$ac_lib"
+break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_hstrerror" >&5
+echo "${ECHO_T}$ac_cv_search_hstrerror" >&6
+if test "$ac_cv_search_hstrerror" != no; then
+ test "$ac_cv_search_hstrerror" = "none required" || LIBS="$ac_cv_search_hstrerror $LIBS"
+fi
-echo "$as_me:$LINENO: checking for gethostbyname in -lnsl" >&5
-echo $ECHO_N "checking for gethostbyname in -lnsl... $ECHO_C" >&6
-if test "${ac_cv_lib_nsl_gethostbyname+set}" = set; then
+echo "$as_me:$LINENO: checking for library containing gethostbyname" >&5
+echo $ECHO_N "checking for library containing gethostbyname... $ECHO_C" >&6
+if test "${ac_cv_search_gethostbyname+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lnsl $LIBS"
+ ac_func_search_save_LIBS=$LIBS
+ac_cv_search_gethostbyname=no
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -3060,25 +3111,78 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- ac_cv_lib_nsl_gethostbyname=yes
+ ac_cv_search_gethostbyname="none required"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_lib_nsl_gethostbyname=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_nsl_gethostbyname" >&5
-echo "${ECHO_T}$ac_cv_lib_nsl_gethostbyname" >&6
-if test $ac_cv_lib_nsl_gethostbyname = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBNSL 1
+if test "$ac_cv_search_gethostbyname" = no; then
+ for ac_lib in nsl resolv; do
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
- LIBS="-lnsl $LIBS"
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char gethostbyname ();
+int
+main ()
+{
+gethostbyname ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_gethostbyname="-l$ac_lib"
+break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_gethostbyname" >&5
+echo "${ECHO_T}$ac_cv_search_gethostbyname" >&6
+if test "$ac_cv_search_gethostbyname" != no; then
+ test "$ac_cv_search_gethostbyname" = "none required" || LIBS="$ac_cv_search_gethostbyname $LIBS"
fi
@@ -3585,9 +3689,11 @@ done
+
+
for ac_header in fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h \
sys/time.h termios.h unistd.h openssl/aes.h openssl/blowfish.h zlib.h \
-sys/poll.h
+sys/poll.h stdint.h pty.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
diff --git a/configure.in b/configure.in
index 11c835c7..7d1a72ea 100644
--- a/configure.in
+++ b/configure.in
@@ -40,14 +40,14 @@ AC_C_BIGENDIAN
# Checks for libraries.
AC_CHECK_LIB([crypto], [BN_init])
AC_CHECK_LIB([z], [deflateInit_])
-AC_CHECK_LIB([resolv],[gethostbyname])
-AC_CHECK_LIB([nsl],[gethostbyname])
+AC_SEARCH_LIBS([hstrerror],[nsl resolv])
+AC_SEARCH_LIBS([gethostbyname],[nsl resolv])
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h \
sys/time.h termios.h unistd.h openssl/aes.h openssl/blowfish.h zlib.h \
-sys/poll.h ])
+sys/poll.h stdint.h pty.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index e3a0b652..8f1b21be 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -24,6 +24,9 @@ MA 02111-1307, USA. */
#include <unistd.h>
#include <sys/select.h> /* for fd_set * */
#include <sys/types.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#define LIBSSH_VERSION "libssh-0.2-dev"
#ifdef __cplusplus
@@ -40,10 +43,10 @@ typedef struct ssh_session SSH_SESSION;
typedef struct ssh_kbdint SSH_KBDINT;
/* integer values */
-typedef u_int32_t u32;
-typedef u_int16_t u16;
-typedef u_int64_t u64;
-typedef u_int8_t u8;
+typedef uint32_t u32;
+typedef uint16_t u16;
+typedef uint64_t u64;
+typedef uint8_t u8;
/* the offsets of methods */
#define SSH_KEX 0
@@ -109,7 +112,7 @@ void ssh_set_options(SSH_SESSION *session, SSH_OPTIONS *options);
int ssh_get_fd(SSH_SESSION *session);
/* client.c */
-int ssh_connect();
+int ssh_connect(SSH_SESSION *session);
void ssh_disconnect(SSH_SESSION *session);
int ssh_service_request(SSH_SESSION *session,char *service);
char *ssh_get_issue_banner(SSH_SESSION *session);
diff --git a/libssh/kex.c b/libssh/kex.c
index a7d3a175..6716fc92 100644
--- a/libssh/kex.c
+++ b/libssh/kex.c
@@ -287,13 +287,17 @@ static STRING *make_rsa1_string(STRING *e, STRING *n){
static void build_session_id1(SSH_SESSION *session, STRING *servern,
STRING *hostn){
MD5CTX *md5=md5_init();
+#ifdef DEBUG_CRYPTO
ssh_print_hexa("host modulus",hostn->string,string_len(hostn));
ssh_print_hexa("server modulus",servern->string,string_len(servern));
+#endif
md5_update(md5,hostn->string,string_len(hostn));
md5_update(md5,servern->string,string_len(servern));
md5_update(md5,session->server_kex.cookie,8);
md5_final(session->next_crypto->session_id,md5);
+#ifdef DEBUG_CRYPTO
ssh_print_hexa("session_id",session->next_crypto->session_id,MD5_DIGEST_LEN);
+#endif
}
STRING *encrypt_session_key(SSH_SESSION *session, PUBLIC_KEY *svrkey,
@@ -307,7 +311,9 @@ STRING *encrypt_session_key(SSH_SESSION *session, PUBLIC_KEY *svrkey,
memcpy(buffer,session->next_crypto->encryptkey,32);
memcpy(session->next_crypto->decryptkey,
session->next_crypto->encryptkey,32);
+#ifdef DEBUG_CRYPTO
ssh_print_hexa("session key",buffer,32);
+#endif
/* xor session key with session_id */
for (i=0;i<16;++i)
buffer[i]^=session->next_crypto->session_id[i];
diff --git a/libssh/options.c b/libssh/options.c
index e1c166d5..3695a83e 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -34,7 +34,11 @@ SSH_OPTIONS *ssh_options_new(){
option->port=22; /* set the default port */
option->fd=-1;
option->ssh2allowed=1;
+#ifdef HAVE_SSH1
+ option->ssh1allowed=1;
+#else
option->ssh1allowed=0;
+#endif
option->bindport=22;
return option;
}
@@ -283,7 +287,11 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){
char *identity=NULL;
char **save=malloc(argc * sizeof(char *));
int current=0;
+#ifdef HAVE_SSH1
+ int ssh1=1;
+#else
int ssh1=0;
+#endif
int ssh2=1;
int saveoptind=optind; /* need to save 'em */
@@ -384,13 +392,8 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){
ssh_options_set_bind(options,localaddr,0);
ssh_options_set_port(options,port);
options->bindport=port;
- if(ssh1){
- ssh_options_allow_ssh1(options,1);
- ssh_options_allow_ssh2(options,0);
- } else { // default behaviour
- ssh_options_allow_ssh1(options,0);
- ssh_options_allow_ssh2(options,1);
- }
+ ssh_options_allow_ssh1(options,ssh1);
+ ssh_options_allow_ssh2(options,ssh2);
if(!cont){
return -1;
diff --git a/sample.c b/sample.c
index 43a0b2ab..d1c0fb47 100644
--- a/sample.c
+++ b/sample.c
@@ -12,6 +12,7 @@ The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
+#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -20,7 +21,9 @@ clients must be made or how a client should react.
#include <sys/select.h>
#include <sys/time.h>
+#ifdef HAVE_PTY_H
#include <pty.h>
+#endif
#include <signal.h>
#include <errno.h>
#include <libssh/libssh.h>
@@ -77,6 +80,17 @@ int opts(int argc, char **argv){
return 0;
}
+#ifndef HAVE_PTY_H
+static void cfmakeraw(struct termios *termios_p){
+ termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+ termios_p->c_oflag &= ~OPOST;
+ termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ termios_p->c_cflag &= ~(CSIZE|PARENB);
+ termios_p->c_cflag |= CS8;
+}
+#endif
+
+
void do_cleanup(){
tcsetattr(0,TCSANOW,&terminal);
}