]> granicus.if.org Git - curl/commitdiff
Added more accurate error code returns from SFTP operations. Added test
authorDan Fandrich <dan@coneharvesters.com>
Thu, 30 Aug 2007 23:03:59 +0000 (23:03 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Thu, 30 Aug 2007 23:03:59 +0000 (23:03 +0000)
case 615 to test an SFTP upload failure.

CHANGES
RELEASE-NOTES
lib/ssh.c
tests/data/Makefile.am
tests/data/test615 [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 0f2bb3c76d366baccb937771c7c5cdfeb81e4340..9f723b5855468c5d80edf5e6e6fe917a9dc51ecb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -52,6 +52,9 @@ Dan F (30 August 2007)
 
 - Documented some newer error codes in libcurl-error(3)
 
+- Added more accurate error code returns from SFTP operations.  Added test
+  case 615 to test an SFTP upload failure.
+
 Dan F (28 August 2007)
 - Some minor internal type and const changes based on a splint scan.
 
index ea8a4baaf2c338e44a4807b80794008031dd97c0..66716a59e67fe9dcaaf085d0d442a26bfab16972 100644 (file)
@@ -20,6 +20,7 @@ This release includes the following changes:
  o builds and runs on OS/400
  o several error codes and options were marked as obsolete and subject to
    future removal (set CURL_NO_OLDIES to see if your application is using them)
+ o SFTP errors can return more specific error codes 
 
 This release includes the following bugfixes:
 
index 538d1d537aefdedd365c6e1268f9bb43c013a872..50ec429b3ed477a6638b01f18666443d7372e4fd 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -95,7 +95,6 @@
 #include "speedcheck.h"
 #include "getinfo.h"
 
-#include "strtoofft.h"
 #include "strequal.h"
 #include "sslgen.h"
 #include "connect.h"
@@ -166,15 +165,32 @@ kbd_callback(const char *name, int name_len, const char *instruction,
 
 static CURLcode sftp_libssh2_error_to_CURLE(unsigned long err)
 {
-  if (err == LIBSSH2_FX_OK)
-    return CURLE_OK;
+  switch (err) {
+    case LIBSSH2_FX_OK:
+      return CURLE_OK;
 
-  /* TODO: map some of the libssh2 errors to the more appropriate CURLcode
-     error code, and possibly add a few new SSH-related one. We must however
-     not return or even depend on libssh2 errors in the public libcurl API */
+    case LIBSSH2_FX_NO_SUCH_FILE:
+    case LIBSSH2_FX_NO_SUCH_PATH:
+      return CURLE_REMOTE_FILE_NOT_FOUND;
+
+    case LIBSSH2_FX_PERMISSION_DENIED:
+    case LIBSSH2_FX_WRITE_PROTECT:
+    case LIBSSH2_FX_LOCK_CONFlICT:
+      return CURLE_REMOTE_ACCESS_DENIED;
+
+    case LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM:
+    case LIBSSH2_FX_QUOTA_EXCEEDED:
+      return CURLE_REMOTE_DISK_FULL;
+
+    case LIBSSH2_FX_FILE_ALREADY_EXISTS:
+      return CURLE_REMOTE_FILE_EXISTS;
 
-  if (err == LIBSSH2_FX_NO_SUCH_FILE)
-    return CURLE_REMOTE_FILE_NOT_FOUND;
+    case LIBSSH2_FX_DIR_NOT_EMPTY:
+      return CURLE_QUOTE_ERROR;
+
+    default:
+      break;
+  }
 
   return CURLE_SSH;
 }
@@ -183,6 +199,11 @@ static CURLcode libssh2_session_error_to_CURLE(int err)
 {
   if (err == LIBSSH2_ERROR_ALLOC)
     return CURLE_OUT_OF_MEMORY;
+
+  /* TODO: map some more of the libssh2 errors to the more appropriate CURLcode
+     error code, and possibly add a few new SSH-related one. We must however
+     not return or even depend on libssh2 errors in the public libcurl API */
+
   return CURLE_SSH;
 }
 
@@ -1065,15 +1086,16 @@ static CURLcode ssh_statemach_act(struct connectdata *conn)
        *          same name as the last directory in the path.
        */
       sftp_scp->sftp_handle =
-      libssh2_sftp_open(sftp_scp->sftp_session, sftp_scp->path,
-                        LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
-                        data->set.new_file_perms);
+        libssh2_sftp_open(sftp_scp->sftp_session, sftp_scp->path,
+                          LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
+                          data->set.new_file_perms);
       if (!sftp_scp->sftp_handle) {
         if (libssh2_session_last_errno(sftp_scp->ssh_session) ==
             LIBSSH2_ERROR_EAGAIN) {
           break;
         } else {
           err = libssh2_sftp_last_error(sftp_scp->sftp_session);
+          failf(data, "Upload failed: %s", sftp_libssh2_strerror(err));
           if (sshc->secondCreateDirs) {
             state(conn, SSH_SFTP_CLOSE);
             sshc->actualCode = err;
index 5506cf2d1db35ac507fe1bbc394bb4cc2502f289..a8c7691e524d87c4842ad173dd118641e375aa1d 100644 (file)
@@ -43,4 +43,5 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46           \
  test296 test297 test298 test610 test611 test612 test406 test407 test408   \
  test409 test613 test614 test700 test701 test702 test704 test705 test703   \
  test706 test707 test350 test351 test352 test353 test289 test540 test354   \
- test231 test1000 test1001 test1002 test1003 test1004 test1005 test1006
+ test231 test1000 test1001 test1002 test1003 test1004 test1005 test1006    \
+ test615
diff --git a/tests/data/test615 b/tests/data/test615
new file mode 100644 (file)
index 0000000..1249826
--- /dev/null
@@ -0,0 +1,44 @@
+<testcase>
+<info>
+<keywords>
+SFTP
+SFTP put
+FAILURE
+</keywords>
+</info>
+
+#
+# Client-side
+<client>
+<server>
+sftp
+</server>
+<precheck>
+perl %SRCDIR/libtest/test613.pl prepare %PWD/log/test615.dir
+</precheck>
+ <name>
+SFTP put remote failure
+ </name>
+ <command>
+--key curl_client_key --pubkey curl_client_key.pub -u %USER: -T log/file615.txt sftp://%HOSTIP:%SSHPORT%PWD/log/test615.dir/rofile.txt
+</command>
+<postcheck>
+perl %SRCDIR/libtest/test613.pl postprocess %PWD/log/test615.dir
+</postcheck>
+<file name="log/file615.txt">
+Test data
+for ssh upload test
+</file>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+9
+</errorcode>
+<valgrind>
+disable
+</valgrind>
+</verify>
+</testcase>