diff lib/sshv2.c @ 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 a85a097bbb02
line wrap: on
line diff
--- 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);