changeset 215:3d6e024dbf31

2003-7-7 Brian Masney <masneyb@gftp.org> * configure.in src/gtk/Makefile.am src/text/Makefile.am - if the OpenSSL libraries are available on the system, link them in and define USE_SSL. The generic SSL engine and the HTTPS protocol checks for this * lib/protocols.c (gftp_get_line) - small fix * lib/rfc2068.c - fixed several bugs in the handling of chunked messages that are spread across multiple packets (the HTTPS protocol unconvered all of these) * lib/sslcommon.c - several fixes and cleanups
author masneyb
date Tue, 08 Jul 2003 02:09:30 +0000
parents 6041bc2373e3
children 3a20cfd0c920
files ChangeLog configure.in lib/protocols.c lib/rfc2068.c lib/sslcommon.c src/gtk/Makefile.am src/text/Makefile.am
diffstat 7 files changed, 90 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jul 07 15:15:15 2003 +0000
+++ b/ChangeLog	Tue Jul 08 02:09:30 2003 +0000
@@ -1,3 +1,17 @@
+2003-7-7 Brian Masney <masneyb@gftp.org>
+	* configure.in src/gtk/Makefile.am src/text/Makefile.am - if the 
+	OpenSSL libraries are available on the system, link them in and
+	define USE_SSL. The generic SSL engine and the HTTPS protocol checks
+	for this
+
+	* lib/protocols.c (gftp_get_line) - small fix
+
+	* lib/rfc2068.c - fixed several bugs in the handling of chunked 
+	messages that are spread across multiple packets (the HTTPS protocol
+	unconvered all of these)
+
+	* lib/sslcommon.c - several fixes and cleanups
+
 2003-7-6 Brian Masney <masneyb@gftp.org>
 	* lib/configure.in - check for getdtablesize()
 
@@ -1193,7 +1207,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.108 2003/07/06 14:24:52 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.109 2003/07/08 02:09:27 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/configure.in	Mon Jul 07 15:15:15 2003 +0000
+++ b/configure.in	Tue Jul 08 02:09:30 2003 +0000
@@ -19,6 +19,10 @@
               [  --disable-textport	  Disable compiling the text port], 
               enable_textport=$enableval, 
               enable_textport="yes")
+AC_ARG_ENABLE(ssl, 
+              [  --disable-ssl		Disable SSL support], 
+              enable_ssl=$enableval, 
+              enable_ssl="yes")
 
 AC_SUBST(PACKAGE)
 AC_SUBST(VERSION)
@@ -260,6 +264,21 @@
 AC_SUBST(GTHREAD_LIBS)
 AC_SUBST(GFTP_GTK)
 
+SSL_LIBS=""
+if test "x$enable_ssl" = "xyes" ; then
+	AC_CHECK_HEADERS(openssl/ssl.h ssl.h)
+
+	if test $ac_cv_header_openssl_ssl_h = yes -o $ac_cv_header_ssl_h = yes ; then
+		AC_CHECK_LIB(ssl, SSL_library_init, SSL_LIBS="-lcrypto -lssl")
+
+		if test "x$SSL_LIBS" != "x" ; then
+			AC_DEFINE(USE_SSL, 1, 
+                                  [define if you want to enable SSL support])
+		fi
+	fi
+fi
+AC_SUBST(SSL_LIBS)
+
 AM_GNU_GETTEXT
 
-AC_OUTPUT(Makefile docs/Makefile docs/sample.gftp/Makefile lib/Makefile src/gftp src/Makefile src/gtk/Makefile src/text/Makefile gftp.spec intl/Makefile po/Makefile.in intl/Makefile po/Makefile.in)
+AC_OUTPUT(Makefile docs/Makefile docs/sample.gftp/Makefile lib/Makefile src/gftp src/Makefile src/gtk/Makefile src/text/Makefile gftp.spec intl/Makefile po/Makefile.in)
--- a/lib/protocols.c	Mon Jul 07 15:15:15 2003 +0000
+++ b/lib/protocols.c	Tue Jul 08 02:09:30 2003 +0000
@@ -2073,8 +2073,8 @@
               (*rbuf)->eof = 1;
             }
 
-          (*rbuf)->buffer[ret + (*rbuf)->cur_bufsize] = '\0';
           (*rbuf)->cur_bufsize += ret;
+          (*rbuf)->curpos[(*rbuf)->cur_bufsize] = '\0';
         }
     }
   while (retval == GFTP_ERETRYABLE);
--- a/lib/rfc2068.c	Mon Jul 07 15:15:15 2003 +0000
+++ b/lib/rfc2068.c	Tue Jul 08 02:09:30 2003 +0000
@@ -718,9 +718,9 @@
 static ssize_t 
 rfc2068_chunked_read (gftp_request * request, void *ptr, size_t size, int fd)
 {
-  size_t read_size, begin_ptr_len;
+  size_t read_size, begin_ptr_len, current_size;
+  char *stpos, *crlfpos;
   rfc2068_params * params;
-  char *stpos, *endpos;
   void *read_ptr_pos;
   ssize_t retval;
 
@@ -766,13 +766,13 @@
 
   if (read_size > 0 && !params->eof)
     {
+      read_size--; /* decrement by one so that we can put the NUL character in
+                      the buffer */
       retval = params->real_read_function (request, read_ptr_pos, read_size, fd);
 
       if (retval > 0)
         params->read_bytes += retval;
       else if (retval == 0)
-        params->eof = 1;
-      else if (retval < 0)
         return (retval);
 
       if (params->chunk_size > 0 && retval > 0)
@@ -786,12 +786,32 @@
   else
     retval = begin_ptr_len;
 
+  ((char *) ptr)[retval] = '\0';
+
   if (!params->chunked_transfer || retval <= 0)
     return (retval);
 
   stpos = (char *) ptr;
   while (params->chunk_size == 0)
     {
+      current_size = retval - (stpos - (char *) ptr);
+      if (current_size < 5)
+        {
+          /* The current chunk size is split between multiple packets.
+             Save this chunk and read the next */
+
+          params->extra_read_buffer = g_malloc (current_size + 1);
+          memcpy (params->extra_read_buffer, stpos, current_size);
+          params->extra_read_buffer[current_size] = '\0';
+          params->extra_read_buffer_len = current_size;
+          retval -= current_size;
+
+          if (retval == 0)
+            return (rfc2068_chunked_read (request, ptr, size, fd));
+          else
+            return (retval);
+        }
+
       if (*stpos != '\r' || *(stpos + 1) != '\n')
         {
           request->logging_function (gftp_logging_recv, request,
@@ -800,25 +820,16 @@
           return (GFTP_EFATAL);
         }
 
-      for (endpos = stpos + 2; 
-           *endpos != '\n' && endpos < stpos + retval;
-           endpos++);
-
-      if (*endpos != '\n')
+      if ((crlfpos = strstr (stpos + 2, "\r\n")) == NULL)
         {
-          /* The current chunk size is split between multiple packets.
-             Save this chunk and read the next */
-
-          params->extra_read_buffer = g_malloc (retval + 1);
-          memcpy (params->extra_read_buffer, ptr, retval);
-          params->extra_read_buffer[retval] = '\0';
-          params->extra_read_buffer_len = retval;
-          return (rfc2068_chunked_read (request, ptr, size, fd));
+          request->logging_function (gftp_logging_recv, request,
+                                     _("Received wrong response from server, disconnecting\nExpecting a carriage return and line feed after the chunk size in the server response\n"));
+          gftp_disconnect (request);
+          return (GFTP_EFATAL);
         }
 
-      *endpos = '\0';
-      if (*(endpos - 1) == '\r')
-        *(endpos - 1) = '\0';
+      *crlfpos = '\0';
+      crlfpos++; /* advance to line feed */
 
       if (sscanf (stpos + 2, "%lx", &params->chunk_size) != 1)
         {
@@ -829,6 +840,9 @@
           return (GFTP_EFATAL);
         }
 
+      retval -= crlfpos - (char *) stpos + 1;
+      current_size -= crlfpos - (char *) stpos + 1;
+
       if (params->chunk_size == 0)
         {
           if (params->eof)
@@ -838,9 +852,7 @@
           return (retval);
         }
 
-      retval -= endpos - (char *) stpos + 1;
-
-      memmove (stpos, endpos + 1, retval - (stpos - (char *) ptr));
+      memmove (stpos, crlfpos + 1, current_size);
 
       params->chunk_size -= retval;
       if (params->chunk_size < 0)
--- a/lib/sslcommon.c	Mon Jul 07 15:15:15 2003 +0000
+++ b/lib/sslcommon.c	Tue Jul 08 02:09:30 2003 +0000
@@ -169,7 +169,7 @@
             break;
         }
     }
- 
+
   if (!ok && (subj = X509_get_subject_name (cert)) &&
       X509_NAME_get_text_by_NID (subj, NID_commonName, data, 256) > 0)
     {
@@ -249,7 +249,7 @@
 {
   int i;
 
-#ifdef G_MAJOR_VERSION == 1
+#if G_MAJOR_VERSION == 1
   /* Thread setup isn't supported in glib 1.2 yet */
   return;
 #endif
@@ -330,6 +330,7 @@
     {
       request->logging_function (gftp_logging_error, request,
                                  _("Error: SSL engine was not initialized\n"));
+      gftp_disconnect (request);
       return (GFTP_EFATAL);
     }
 
@@ -346,6 +347,7 @@
     {
       request->logging_function (gftp_logging_error, request,
                                  _("Error setting up SSL connection (BIO object)\n"));
+      gftp_disconnect (request);
       return (GFTP_EFATAL);
     }
 
@@ -355,6 +357,7 @@
     {
       request->logging_function (gftp_logging_error, request,
                                  _("Error setting up SSL connection (SSL object)\n"));
+      gftp_disconnect (request);
       return (GFTP_EFATAL);
     }
 
@@ -362,7 +365,10 @@
   SSL_set_ex_data (request->ssl, gftp_ssl_get_index (), request);
 
   if (SSL_connect (request->ssl) <= 0)
-    return (GFTP_EFATAL);
+    {
+      gftp_disconnect (request);
+      return (GFTP_EFATAL);
+    }
 
   if ((ret = gftp_ssl_post_connection_check (request)) != X509_V_OK)
     {
@@ -370,6 +376,7 @@
         request->logging_function (gftp_logging_error, request,
                                    _("Error with peer certificate: %s\n"),
                                    X509_verify_cert_error_string (ret));
+      gftp_disconnect (request);
       return (GFTP_EFATAL);
     }
 
@@ -404,19 +411,17 @@
           err = SSL_get_error (request->ssl, ret);
           if (errno == EINTR)
             {
-              if (request != NULL && request->cancel)
+              if (request->cancel)
                 break;
               else
                 continue;
              }
  
-          if (request != NULL)
-            {
-              request->logging_function (gftp_logging_error, request,
+          request->logging_function (gftp_logging_error, request,
                                    _("Error: Could not read from socket: %s\n"),
                                     g_strerror (errno));
-              gftp_disconnect (request);
-            }
+          gftp_disconnect (request);
+
           return (GFTP_ERETRYABLE);
         }
     }
@@ -458,13 +463,11 @@
                 continue;
              }
  
-          if (request != NULL)
-            {
-              request->logging_function (gftp_logging_error, request,
+          request->logging_function (gftp_logging_error, request,
                                     _("Error: Could not write to socket: %s\n"),
                                     g_strerror (errno));
-              gftp_disconnect (request);
-            }
+          gftp_disconnect (request);
+
           return (GFTP_ERETRYABLE);
         }
       ptr += w_ret;
--- a/src/gtk/Makefile.am	Mon Jul 07 15:15:15 2003 +0000
+++ b/src/gtk/Makefile.am	Tue Jul 08 02:09:30 2003 +0000
@@ -6,6 +6,6 @@
                      gftp-gtk.c menu-items.c misc-gtk.c mkdir_dialog.c \
                      options_dialog.c rename_dialog.c transfer.c view_dialog.c
 INCLUDES = @GTK_CFLAGS@ @PTHREAD_CFLAGS@ -DSHARE_DIR=\"$(datadir)/gftp\" -DLOCALE_DIR=\"$(localedir)\" -I../../intl
-LDADD = ../../lib/libgftp.a @GTK_LIBS@ @PTHREAD_LIBS@ @EXTRA_LIBS@ @GTHREAD_LIBS@
+LDADD = ../../lib/libgftp.a @GTK_LIBS@ @PTHREAD_LIBS@ @EXTRA_LIBS@ @GTHREAD_LIBS@ @SSL_LIBS@
 noinst_HEADERS = gftp-gtk.h
 localedir = $(datadir)/locale
--- a/src/text/Makefile.am	Mon Jul 07 15:15:15 2003 +0000
+++ b/src/text/Makefile.am	Tue Jul 08 02:09:30 2003 +0000
@@ -4,6 +4,6 @@
 EXTRA_PROGRAMS = gftp-text
 gftp_text_SOURCES=gftp-text.c 
 INCLUDES=@GLIB_CFLAGS@ -DSHARE_DIR=\"$(datadir)/gftp\" -DLOCALE_DIR=\"$(localedir)\" -I../../intl
-LDADD = ../../lib/libgftp.a @GLIB_LIBS@ @EXTRA_LIBS@ @READLINE_LIBS@
+LDADD = ../../lib/libgftp.a @GLIB_LIBS@ @EXTRA_LIBS@ @READLINE_LIBS@ @SSL_LIBS@
 noinst_HEADERS=gftp-text.h
 localedir=$(datadir)/locale