changeset 219:b9584a877daf

2003-7-9 Brian Masney <masneyb@gftp.org> * lib/sshv2.c - if we are logging in to the server, and the message size is too big from the server, assume that an error message follows and log the ASCII text to the log window * src/gtk/options_dialog.c - make sure the value is set properly for the textcomboedt option types (the FTP proxy server type uses this) * lib/rfc2068.c - HTTP proxy bug fixes. Also, moved rfc2068_connect() call to rfc2068_send_command() and removed it from the now unneeded places. Also, fix in call to HEAD command * src/text/gftp-text.c - fixed NULL pointer deference in changing directory * docs/sample.gftp/gftprc - enable require SSH user/pass by default
author masneyb
date Wed, 09 Jul 2003 23:25:57 +0000
parents de6a2e8e51cb
children 6de9a8280aa4
files ChangeLog TODO docs/sample.gftp/gftprc lib/rfc2068.c lib/sshv2.c src/gtk/options_dialog.c src/text/gftp-text.c
diffstat 7 files changed, 140 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jul 09 23:25:56 2003 +0000
+++ b/ChangeLog	Wed Jul 09 23:25:57 2003 +0000
@@ -1,3 +1,20 @@
+2003-7-9 Brian Masney <masneyb@gftp.org>
+	* lib/sshv2.c - if we are logging in to the server, and the message 
+	size is too big from the server, assume that an error message follows
+	and log the ASCII text to the log window
+
+	* src/gtk/options_dialog.c - make sure the value is set properly for
+	the textcomboedt option types (the FTP proxy server type uses this)
+
+	* lib/rfc2068.c - HTTP proxy bug fixes. Also, moved rfc2068_connect()
+	call to rfc2068_send_command() and removed it from the now unneeded
+	places. Also, fix in call to HEAD command
+
+	* src/text/gftp-text.c - fixed NULL pointer deference in changing 
+	directory
+
+	* docs/sample.gftp/gftprc - enable require SSH user/pass by default
+
 2003-7-9 Brian Masney <masneyb@gftp.org>
 	* lib/config_file.c (gftp_write_config_file) - fix for writing out
 	list items to the config file. 
@@ -1230,7 +1247,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.110 2003/07/09 23:25:53 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.111 1997/01/01 09:22:34 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/TODO	Wed Jul 09 23:25:56 2003 +0000
+++ b/TODO	Wed Jul 09 23:25:57 2003 +0000
@@ -3,11 +3,10 @@
 version of gFTP, please email me about it.
 
 *** TODO FOR 2.0.15 ***
-* Check for memory leaks with dmalloc
-* HTTP - I am getting complaints about HTTP proxy support is busted
+* gftp_get_line() - returns 0 if the line lengh is the length of the current 
+  buffer
 * Override options on a per site basis (backend is done, I just have to make
   a user interface for the gtk+ port)
-* Finish going through my email and check GNOME's Bugzilla
 *** END TODO FOR 2.0.15
 
 * I need to be able to send an event from the core library to the presentation
--- a/docs/sample.gftp/gftprc	Wed Jul 09 23:25:56 2003 +0000
+++ b/docs/sample.gftp/gftprc	Wed Jul 09 23:25:57 2003 +0000
@@ -230,7 +230,7 @@
 ssh2_sftp_path=
 
 # Require a username/password for SSH connections
-ssh_need_userpass=0
+ssh_need_userpass=1
 
 # Use the ssh-askpass utility to supply the remote password
 ssh_use_askpass=0
--- a/lib/rfc2068.c	Wed Jul 09 23:25:56 2003 +0000
+++ b/lib/rfc2068.c	Wed Jul 09 23:25:57 2003 +0000
@@ -47,6 +47,49 @@
 };
 
 
+static int
+rfc2068_connect (gftp_request * request)
+{
+  char *proxy_hostname, *proxy_config;
+  rfc2068_params * params;
+  int proxy_port, ret;
+
+  g_return_val_if_fail (request != NULL, GFTP_EFATAL);
+  g_return_val_if_fail (request->protonum == GFTP_HTTP_NUM, GFTP_EFATAL);
+  g_return_val_if_fail (request->hostname != NULL, GFTP_EFATAL);
+
+  params = request->protocol_data;
+
+  if (request->datafd > 0)
+    return (0);
+
+  gftp_lookup_request_option (request, "proxy_config", &proxy_config);
+  gftp_lookup_request_option (request, "http_proxy_host", &proxy_hostname);
+  gftp_lookup_request_option (request, "http_proxy_port", &proxy_port);
+
+  if (proxy_config != NULL && strcmp (proxy_config, "ftp") == 0)
+    {
+      g_free (request->url_prefix);
+      request->url_prefix = g_strdup ("ftp");
+    }
+
+  if ((ret = gftp_connect_server (request, request->url_prefix, proxy_hostname, 
+                                  proxy_port)) < 0)
+    return (ret);
+
+  if (request->directory && *request->directory == '\0')
+    {
+      g_free (request->directory);
+      request->directory = NULL;
+    }
+
+  if (!request->directory)
+    request->directory = g_strdup ("/");
+
+  return (0);
+}
+
+
 static off_t 
 rfc2068_read_response (gftp_request * request)
 {
@@ -136,13 +179,16 @@
 rfc2068_send_command (gftp_request * request, const void *command, size_t len)
 {
   char *tempstr, *str, *proxy_hostname, *proxy_username, *proxy_password;
-  int proxy_port;
+  int proxy_port, conn_ret;
   ssize_t ret;
 
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);
   g_return_val_if_fail (request->protonum == GFTP_HTTP_NUM, GFTP_EFATAL);
   g_return_val_if_fail (command != NULL, GFTP_EFATAL);
 
+  if (request->datafd < 0 && (conn_ret = rfc2068_connect (request)) != 0)
+    return (conn_ret);
+
   tempstr = g_strdup_printf ("%sUser-Agent: %s\nHost: %s\n", (char *) command,
                              gftp_version, request->hostname);
 
@@ -198,49 +244,6 @@
 }
 
 
-static int
-rfc2068_connect (gftp_request * request)
-{
-  char *proxy_hostname, *proxy_config;
-  rfc2068_params * params;
-  int proxy_port, ret;
-
-  g_return_val_if_fail (request != NULL, GFTP_EFATAL);
-  g_return_val_if_fail (request->protonum == GFTP_HTTP_NUM, GFTP_EFATAL);
-  g_return_val_if_fail (request->hostname != NULL, GFTP_EFATAL);
-
-  params = request->protocol_data;
-
-  if (request->datafd > 0)
-    return (0);
-
-  gftp_lookup_request_option (request, "proxy_config", &proxy_config);
-  gftp_lookup_request_option (request, "http_proxy_host", &proxy_hostname);
-  gftp_lookup_request_option (request, "http_proxy_port", &proxy_port);
-
-  if (proxy_config != NULL && strcmp (proxy_config, "ftp") == 0)
-    {
-      g_free (request->url_prefix);
-      request->url_prefix = g_strdup ("ftp");
-    }
-
-  if ((ret = gftp_connect_server (request, request->url_prefix, proxy_hostname, 
-                                  proxy_port)) < 0)
-    return (ret);
-
-  if (request->directory && *request->directory == '\0')
-    {
-      g_free (request->directory);
-      request->directory = NULL;
-    }
-
-  if (!request->directory)
-    request->directory = g_strdup ("/");
-
-  return (0);
-}
-
-
 static void
 rfc2068_disconnect (gftp_request * request)
 {
@@ -267,8 +270,8 @@
 rfc2068_get_file (gftp_request * request, const char *filename, int fd,
                   off_t startsize)
 {
-  int restarted, ret, use_http11;
   char *tempstr, *oldstr, *pos;
+  int restarted, use_http11;
   rfc2068_params * params;
   off_t size;
 
@@ -283,9 +286,6 @@
   if (fd > 0)
     request->datafd = fd;
 
-  if (request->datafd < 0 && (ret = rfc2068_connect (request)) != 0)
-    return (ret);
-
   if (request->username == NULL || *request->username == '\0')
     tempstr = g_strconcat ("GET ", request->url_prefix, "://", 
                      request->hostname, "/", filename, 
@@ -390,7 +390,7 @@
 {
   rfc2068_params *params;
   char *tempstr, *pos;
-  int r, use_http11;
+  int use_http11;
   off_t ret;
 
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);
@@ -399,9 +399,6 @@
   params = request->protocol_data;
   gftp_lookup_request_option (request, "use_http11", &use_http11);
 
-  if (request->datafd < 0 && (r = rfc2068_connect (request)) < 0)
-    return (r);
-
   if (request->username == NULL || *request->username == '\0')
     tempstr = g_strconcat ("GET ", request->url_prefix, "://", 
                            request->hostname, "/", request->directory, 
@@ -442,7 +439,7 @@
 {
   rfc2068_params *params;
   char *tempstr, *pos;
-  int ret, use_http11;
+  int use_http11;
   off_t size;
 
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);
@@ -452,16 +449,14 @@
   params = request->protocol_data;
   gftp_lookup_request_option (request, "use_http11", &use_http11);
 
-  if (request->datafd < 0 && (ret = rfc2068_connect (request)) != 0)
-    return (ret);
-
   if (request->username == NULL || *request->username == '\0')
-    tempstr = g_strconcat ("HEAD ", request->url_prefix, request->hostname, "/",
-                           filename, 
+    tempstr = g_strconcat ("HEAD ", request->url_prefix, "://", 
+                           request->hostname, "/", filename, 
                            use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
   else
-    tempstr = g_strconcat ("HEAD ", request->url_prefix, request->username, 
-                           "@", request->hostname, "/", filename, 
+    tempstr = g_strconcat ("HEAD ", request->url_prefix, "://", 
+                           request->username, "@", request->hostname, "/", 
+                           filename, 
                            use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
 
   if ((pos = strstr (tempstr, "://")) != NULL)
@@ -609,7 +604,7 @@
 rfc2068_get_next_file (gftp_request * request, gftp_file * fle, int fd)
 {
   rfc2068_params * params;
-  char tempstr[255];
+  char tempstr[8192];
   ssize_t len;
   int ret;
 
@@ -650,6 +645,7 @@
       request->last_dir_entry = g_strdup_printf ("%s\n", tempstr);
       request->last_dir_entry_len = len + 1;
     }
+
   return (len);
 }
 
@@ -667,7 +663,7 @@
     {
       olddir = request->directory;
 
-      if (*directory != '/')
+      if (*directory != '/' && request->directory != NULL)
         {
           tempstr = g_strconcat (request->directory, "/", directory, NULL);
           request->directory = expand_path (tempstr);
--- a/lib/sshv2.c	Wed Jul 09 23:25:56 2003 +0000
+++ b/lib/sshv2.c	Wed Jul 09 23:25:57 2003 +0000
@@ -82,6 +82,7 @@
 
   gint32 id,				
          count;
+  unsigned int initialized : 1;
 #ifdef G_HAVE_GINT64
   gint64 offset;
 #else
@@ -596,8 +597,11 @@
 sshv2_read_response (gftp_request * request, sshv2_message * message,
                      int fd)
 {
+  char buf[6], error_buffer[255], *pos;
+  sshv2_params * params;
   ssize_t numread, rem;
-  char buf[5], *pos;
+
+  params = request->protocol_data;
 
   if (fd <= 0)
     fd = request->datafd;
@@ -611,14 +615,35 @@
       rem -= numread;
       pos += numread;
     }
+  buf[5] = '\0';
 
   memcpy (&message->length, buf, 4);
   message->length = ntohl (message->length);
   if (message->length > 34000)
     {
-      request->logging_function (gftp_logging_error, request,
+      if (params->initialized)
+        {
+          request->logging_function (gftp_logging_error, request,
                              _("Error: Message size %d too big from server\n"),
                              message->length);
+        }
+      else
+        {
+          request->logging_function (gftp_logging_error, request,
+                     _("There was an error initializing a SSH connection with the remote server. The error message from the remote server follows:\n"), buf);
+
+          request->logging_function (gftp_logging_error, request, "%s", buf);
+
+          while ((numread = gftp_fd_read (request, error_buffer, 
+                                          sizeof (error_buffer) - 1, 
+                                          fd)) > 0)
+            {
+              error_buffer[numread] = '\0';
+              request->logging_function (gftp_logging_error, request,
+                                         "%s", error_buffer);
+            }
+        }
+
       memset (message, 0, sizeof (*message));
       gftp_disconnect (request);
       return (GFTP_EFATAL);
@@ -816,6 +841,7 @@
   int version, ret, ssh_use_askpass, sshv2_use_sftp_subsys, fdm;
   char **args, *tempstr, *p1, p2, *exepath, *ssh2_sftp_path;
   struct servent serv_struct;
+  sshv2_params * params;
   sshv2_message message;
   pid_t child;
 
@@ -826,6 +852,8 @@
   if (request->datafd > 0)
     return (0);
 
+  params = request->protocol_data;
+
   request->logging_function (gftp_logging_misc, request,
 			     _("Opening SSH connection to %s\n"),
                              request->hostname);
@@ -900,20 +928,25 @@
     return (ret);
 
   memset (&message, 0, sizeof (message));
-  if ((ret = sshv2_read_response (request, &message, -1)) != SSH_FXP_VERSION)
+  ret = sshv2_read_response (request, &message, -1);
+  if (ret < 0)
+    {
+      sshv2_message_free (&message);
+      return (ret);
+    }
+  else if (ret != SSH_FXP_VERSION)
     {
       request->logging_function (gftp_logging_error, request,
-               _("Received wrong response from server, disconnecting\n"));
+                     _("Received wrong response from server, disconnecting\n"));
       sshv2_message_free (&message);
       gftp_disconnect (request);
 
-      if (ret < 0)
-        return (ret);
-      else
-        return (GFTP_ERETRYABLE);
+      return (GFTP_EFATAL);
     }
+
   sshv2_message_free (&message);
 
+  params->initialized = 1;
   request->logging_function (gftp_logging_misc, request,
                              _("Successfully logged into SSH server %s\n"),
                              request->hostname);
@@ -1077,7 +1110,6 @@
       sshv2_message_free (&message);
       gftp_disconnect (request);
       return (GFTP_EFATAL);
-        
     }
 
   memset (params->handle, 0, 4);
--- a/src/gtk/options_dialog.c	Wed Jul 09 23:25:56 2003 +0000
+++ b/src/gtk/options_dialog.c	Wed Jul 09 23:25:57 2003 +0000
@@ -286,6 +286,7 @@
 
   ret = g_strdup ("");
   len = 0;
+
   for (stpos = str; 
        (endpos = strstr (stpos, "%n")) != NULL;
        stpos = endpos + 2)
@@ -301,6 +302,13 @@
       *endpos = savechar;
     }
 
+  if (stpos != NULL && *stpos != '\0')
+    {
+      len += strlen (stpos);
+      ret = g_realloc (ret, len + 1);
+      strcat (ret, stpos);
+    }
+
   return (ret);
 }
 
@@ -313,6 +321,7 @@
 
   ret = g_strdup ("");
   len = 0;
+
   for (stpos = str; 
        (endpos = strchr (stpos, '\n')) != NULL;
        stpos = endpos + 1)
@@ -328,6 +337,13 @@
       *endpos = savechar;
     }
 
+  if (stpos != NULL && *stpos != '\0')
+    {
+      len += strlen (stpos);
+      ret = g_realloc (ret, len + 1);
+      strcat (ret, stpos);
+    }
+
   return (ret);
 }
 
@@ -463,13 +479,11 @@
     {
       wcstombs (tmp, (wchar_t *) GTK_TEXT (widdata->text)->text.wc, sizeof (tmp));
       newstr = tmp;
-      freeit = 0;
     }
   else
-    {
-      newstr = (char *) GTK_TEXT (widdata->text)->text.ch; 
-      freeit = 0;
-    }
+    newstr = (char *) GTK_TEXT (widdata->text)->text.ch; 
+
+  freeit = 0;
 #else
   textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widdata->text));
   len = gtk_text_buffer_get_char_count (textbuf);
--- a/src/text/gftp-text.c	Wed Jul 09 23:25:56 2003 +0000
+++ b/src/text/gftp-text.c	Wed Jul 09 23:25:57 2003 +0000
@@ -438,7 +438,7 @@
     }
   else if (request->protonum == GFTP_LOCAL_NUM)
     {
-      if (*command != '/')
+      if (*command != '/' && request->directory != NULL)
         {
           tempstr = g_strconcat (request->directory, "/", command, NULL);
           newdir = expand_path (tempstr);