]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ftp.cc
Merge form trunk
[thirdparty/squid.git] / src / ftp.cc
index a307bceba6eca4e8f05f853951c51e8c8c182483..69084870f19bb5ff9a91c27a71e38d9c85bc3732 100644 (file)
@@ -40,6 +40,7 @@
 #include "errorpage.h"
 #include "fde.h"
 #include "forward.h"
+#include "html_quote.h"
 #include "HttpHdrContRange.h"
 #include "HttpHeaderRange.h"
 #include "HttpHeader.h"
@@ -1853,18 +1854,24 @@ FtpStateData::loginFailed()
     ErrorState *err = NULL;
     const char *command, *reply;
 
-    if (state == SENT_USER || state == SENT_PASS) {
-        if (ctrl.replycode > 500) {
-            if (password_url)
+    if ((state == SENT_USER || state == SENT_PASS) && ctrl.replycode >= 400) {
+        if (ctrl.replycode == 421 || ctrl.replycode == 426) {
+            // 421/426 - Service Overload - retry permitted.
+            err = errorCon(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request);
+        } else if (ctrl.replycode >= 430 && ctrl.replycode <= 439) {
+            // 43x - Invalid or Credential Error - retry challenge required.
+            err = errorCon(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request);
+        } else if (ctrl.replycode >= 530 && ctrl.replycode <= 539) {
+            // 53x - Credentials Missing - retry challenge required
+            if (password_url) // but they were in the URI! major fail.
                 err = errorCon(ERR_FTP_FORBIDDEN, HTTP_FORBIDDEN, fwd->request);
             else
                 err = errorCon(ERR_FTP_FORBIDDEN, HTTP_UNAUTHORIZED, fwd->request);
-        } else if (ctrl.replycode == 421) {
-            err = errorCon(ERR_FTP_UNAVAILABLE, HTTP_SERVICE_UNAVAILABLE, fwd->request);
         }
     }
 
-    if (err) {
+    // any other problems are general falures.
+    if (!err) {
         ftpFail(this);
         return;
     }
@@ -3513,6 +3520,9 @@ ftpSendReply(FtpStateData * ftpState)
         http_code = HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    if (ftpState->request)
+        ftpState->request->detailError(err_code, code);
+
     err = errorCon(err_code, http_code, ftpState->request);
 
     if (ftpState->old_request)