changeset 64:29128554eb86

2002-11-23 Brian Masney <masneyb@gftp.org> * lib/sshv2.c - added more error checking so that the user won't get disconnected if they enter files or directories that don't exist
author masneyb
date Sat, 23 Nov 2002 14:34:25 +0000
parents 41b71c4e5076
children 4b5fec7711e9
files ChangeLog lib/sshv2.c
diffstat 2 files changed, 70 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Nov 23 13:45:05 2002 +0000
+++ b/ChangeLog	Sat Nov 23 14:34:25 2002 +0000
@@ -1,4 +1,8 @@
-2002-11-2333 Brian Masney <masneyb@gftp.org>
+2002-11-23 Brian Masney <masneyb@gftp.org>
+	* lib/sshv2.c - added more error checking so that the user won't get
+	disconnected if they enter files or directories that don't exist
+	
+2002-11-23 Brian Masney <masneyb@gftp.org>
 	* lib/local.c lib/rfc959.c lib/rfc2068.c lib/ssh.c lib/sshv2.c
 	lib/gftp.h - added swap_socks function to gftp_request structure
 
@@ -288,7 +292,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.38 2002/11/23 13:45:03 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.39 2002/11/23 14:34:24 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/sshv2.c	Sat Nov 23 13:45:05 2002 +0000
+++ b/lib/sshv2.c	Sat Nov 23 14:34:25 2002 +0000
@@ -455,6 +455,7 @@
   char *tempstr, *dir;
   gint32 num;
   size_t len;
+  int ret;
 
   g_return_val_if_fail (request != NULL, -2);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
@@ -488,7 +489,13 @@
     }
 
   memset (&message, 0, sizeof (message));
-  if (sshv2_read_response (request, &message, -1) != SSH_FXP_NAME)
+  ret = sshv2_read_response (request, &message, -1);
+  if (ret == SSH_FXP_STATUS)
+    {
+      sshv2_message_free (&message);
+      return (-2);
+    }
+  else if (ret != SSH_FXP_NAME)
     {
       request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));
@@ -503,6 +510,7 @@
 
   if ((request->directory = sshv2_buffer_get_string (request, &message)) == NULL)
     return (-2);
+
   sshv2_message_free (&message);
   return (0);
 }
@@ -656,9 +664,18 @@
       return (-1);
     }
 
-  sshv2_getcwd (request);
-  if (request->sockfd < 0)
-    return (-2);
+  if (sshv2_getcwd (request) < 0)
+    {
+      if (request->directory)
+        g_free (request->directory);
+
+      request->directory = g_strdup (".");
+      if (sshv2_getcwd (request) < 0)
+        {
+          gftp_disconnect (request);
+          return (-2);
+        }
+    }
 
   return (0);
 }
@@ -749,6 +766,7 @@
   sshv2_message message;
   char *tempstr;
   gint32 len;
+  int ret;
 
   g_return_val_if_fail (request != NULL, -2);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
@@ -776,7 +794,13 @@
   g_free (tempstr);
 
   memset (&message, 0, sizeof (message));
-  if (sshv2_read_response (request, &message, -1) != SSH_FXP_HANDLE)
+  ret = sshv2_read_response (request, &message, -1);
+  if (ret == SSH_FXP_STATUS)
+    {
+      sshv2_message_free (&message);
+      return (-2);
+    }
+  else if (ret != SSH_FXP_HANDLE)
     {
       request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));
@@ -1005,6 +1029,7 @@
   char *tempstr, *dir;
   gint32 num;
   size_t len;
+  int ret;
 
   g_return_val_if_fail (request != NULL, -2);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
@@ -1040,7 +1065,13 @@
       g_free (tempstr);
 
       memset (&message, 0, sizeof (message));
-      if (sshv2_read_response (request, &message, -1) != SSH_FXP_NAME)
+      ret = sshv2_read_response (request, &message, -1);
+      if (ret == SSH_FXP_STATUS)
+        {
+          sshv2_message_free (&message);
+          return (-2);
+        }
+      else if (ret != SSH_FXP_NAME)
         {
           request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));
@@ -1060,9 +1091,10 @@
         g_free (request->directory);
       request->directory = dir;
       sshv2_message_free (&message);
+      return (0);
     }
-  
-  return (0);
+  else
+    return (sshv2_getcwd (request));
 }
 
 
@@ -1445,6 +1477,7 @@
   gint32 len, highnum, lownum, attrs, num;
   sshv2_params * params;
   char *tempstr;
+  int serv_ret;
 #ifdef G_HAVE_GINT64
   gint64 ret;
 #endif
@@ -1484,7 +1517,13 @@
   g_free (tempstr);
 
   memset (&params->message, 0, sizeof (params->message));
-  if (sshv2_read_response (request, &params->message, -1) != SSH_FXP_ATTRS)
+  serv_ret = sshv2_read_response (request, &params->message, -1);
+  if (serv_ret == SSH_FXP_STATUS)
+    {
+      sshv2_message_free (&params->message);
+      return (-2);
+    }
+  else if (serv_ret != SSH_FXP_ATTRS)
     {
       request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));
@@ -1534,6 +1573,7 @@
   char *tempstr;
   size_t stlen;
   gint32 num;
+  int ret;
 
   g_return_val_if_fail (request != NULL, -2);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
@@ -1577,7 +1617,13 @@
 
   g_free (tempstr);
   memset (&message, 0, sizeof (message));
-  if (sshv2_read_response (request, &message, -1) != SSH_FXP_HANDLE)
+  ret = sshv2_read_response (request, &message, -1);
+  if (ret == SSH_FXP_STATUS)
+    {
+      sshv2_message_free (&message);
+      return (-2);
+    }
+  else if (ret != SSH_FXP_HANDLE)
     {
       request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));
@@ -1615,6 +1661,7 @@
   char *tempstr;
   size_t stlen;
   gint32 num;
+  int ret;
 
   g_return_val_if_fail (request != NULL, -2);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
@@ -1661,7 +1708,13 @@
 
   g_free (tempstr);
   memset (&message, 0, sizeof (message));
-  if (sshv2_read_response (request, &message, -1) != SSH_FXP_HANDLE)
+  ret = sshv2_read_response (request, &message, -1);
+  if (ret == SSH_FXP_STATUS)
+    {
+      sshv2_message_free (&message);
+      return (-2);
+    }
+  else if (ret != SSH_FXP_HANDLE)
     {
       request->logging_function (gftp_logging_error, request->user_data,
                      _("Received wrong response from server, disconnecting\n"));