From: wessels <> Date: Thu, 30 Oct 1997 05:39:51 +0000 (+0000) Subject: Fix FTP errors. Now we actually send back an error page. X-Git-Tag: SQUID_3_0_PRE1~4633 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b991691760f53817608a10e0cabe676bc6e82dcb;p=thirdparty%2Fsquid.git Fix FTP errors. Now we actually send back an error page. Also fixed some logic problems with CWD A; CWD B; RETR C/D stuff --- diff --git a/src/enums.h b/src/enums.h index 3e56ec37d9..ab02cf3091 100644 --- a/src/enums.h +++ b/src/enums.h @@ -39,6 +39,7 @@ typedef enum { ERR_NO_RELAY, ERR_ZERO_SIZE_OBJECT, ERR_FTP_DISABLED, + ERR_FTP_FAILURE, ERR_ACCESS_DENIED, ERR_MAX } err_type; diff --git a/src/errorpage.cc b/src/errorpage.cc index 07fbda20ab..6e4d54dec9 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.92 1997/10/29 05:19:57 wessels Exp $ + * $Id: errorpage.cc,v 1.93 1997/10/29 22:39:51 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -49,6 +49,7 @@ const char *err_string[] = "ERR_NO_RELAY", "ERR_ZERO_SIZE_OBJECT", "ERR_FTP_DISABLED", + "ERR_FTP_FAILURE", "ERR_ACCESS_DENIED", "ERR_MAX" }; @@ -179,6 +180,20 @@ errorConvert(char token, ErrorState * err) snprintf(buf, CVT_BUF_SZ, "%s", mkrfc1123(squid_curtime)); p = buf; break; + case 'f': + /* FTP REQUEST LINE */ + if (err->ftp.request) + p = err->ftp.request; + else + p = ""; + break; + case 'F': + /* FTP REPLY LINE */ + if (err->ftp.request) + p = err->ftp.reply; + else + p = ""; + break; /* * e - errno x * E - strerror() x @@ -192,6 +207,8 @@ errorConvert(char token, ErrorState * err) * h - cache hostname x * d - seconds elapsed since request received * p - URL port # x + * f - FTP request line x + * F - FTP reply line x */ default: p = "%UNKNOWN%"; diff --git a/src/ftp.cc b/src/ftp.cc index faac3d754b..0463237aaa 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.155 1997/10/28 21:59:05 wessels Exp $ + * $Id: ftp.cc,v 1.156 1997/10/29 22:39:52 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -96,7 +96,8 @@ typedef struct _Ftpdata { off_t offset; FREE *freefunc; wordlist *message; - char *last_message; + char *last_command; + char *last_reply; int replycode; } ctrl; struct { @@ -200,7 +201,8 @@ ftpStateFree(int fd, void *data) wordlistDestroy(&ftpState->ctrl.message); if (ftpState->cwd_message) wordlistDestroy(&ftpState->cwd_message); - safe_free(ftpState->ctrl.last_message); + safe_free(ftpState->ctrl.last_reply); + safe_free(ftpState->ctrl.last_command); safe_free(ftpState->title_url); safe_free(ftpState->filepath); safe_free(ftpState->data.host); @@ -367,7 +369,7 @@ ftpListParseParts(const char *buf, int flags) tokens[i], tokens[i + 1], tokens[i + 2]); if ((t = strstr(buf, sbuf))) { p->date = xstrdup(sbuf); - if (BIT_TEST(flags, FTP_SKIP_WHITESPACE)) { + if (EBIT_TEST(flags, FTP_SKIP_WHITESPACE)) { t += strlen(sbuf); while (strchr(w_space, *t)) t++; @@ -937,6 +939,8 @@ static void ftpWriteCommand(const char *buf, FtpStateData * ftpState) { debug(9, 5) ("ftpWriteCommand: %s\n", buf); + safe_free(ftpState->ctrl.last_command); + ftpState->ctrl.last_command = xstrdup(buf); comm_write(ftpState->ctrl.fd, xstrdup(buf), strlen(buf), @@ -1090,8 +1094,8 @@ ftpReadControlReply(int fd, void *data) return; } for (W = &ftpState->ctrl.message; *W && (*W)->next; W = &(*W)->next); - safe_free(ftpState->ctrl.last_message); - ftpState->ctrl.last_message = (*W)->key; + safe_free(ftpState->ctrl.last_reply); + ftpState->ctrl.last_reply = (*W)->key; safe_free(*W); ftpState->ctrl.offset = 0; FTP_SM_FUNCS[ftpState->state] (ftpState); @@ -1226,6 +1230,9 @@ ftpReadCwd(FtpStateData * ftpState) xfree(w->key); xfree(w); ftpSendCwd(ftpState); + } else if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) { + /* CWD FAILED */ + ftpFail(ftpState); } else { /* CWD FAILED */ while (w) { @@ -1252,7 +1259,7 @@ ftpReadMdtm(FtpStateData * ftpState) int code = ftpState->ctrl.replycode; debug(9, 3) ("This is ftpReadMdtm\n"); if (code == 213) { - ftpState->mdtm = parse_iso3307_time(ftpState->ctrl.last_message); + ftpState->mdtm = parse_iso3307_time(ftpState->ctrl.last_reply); } else if (code < 0) { ftpFail(ftpState); } @@ -1269,7 +1276,7 @@ ftpReadSize(FtpStateData * ftpState) int code = ftpState->ctrl.replycode; debug(9, 3) ("This is ftpReadSize\n"); if (code == 213) { - ftpState->size = atoi(ftpState->ctrl.last_message); + ftpState->size = atoi(ftpState->ctrl.last_reply); } else if (code < 0) { ftpFail(ftpState); } @@ -1311,7 +1318,7 @@ ftpReadPasv(FtpStateData * ftpState) int n; u_short port; int fd = ftpState->data.fd; - char *buf = ftpState->ctrl.last_message; + char *buf = ftpState->ctrl.last_reply; LOCAL_ARRAY(char, junk, 1024); debug(9, 3) ("This is ftpReadPasv\n"); if (code != 227) { @@ -1393,7 +1400,7 @@ ftpRestOrList(FtpStateData * ftpState) ftpWriteCommand(cbuf, ftpState); ftpState->state = SENT_LIST; } else if (ftpState->restart_offset > 0) { - snprintf(cbuf, 1024, "REST\r\n"); + snprintf(cbuf, 1024, "REST %d\r\n", ftpState->restart_offset); ftpWriteCommand(cbuf, ftpState); ftpState->state = SENT_REST; } else { @@ -1505,7 +1512,17 @@ ftpReadQuit(FtpStateData * ftpState) static void ftpFail(FtpStateData * ftpState) { + /* XXX NEED TO SEND BACK SOME CONTENT! */ + ErrorState *err; debug(9, 3) ("ftpFail\n"); + err = xcalloc(1, sizeof(ErrorState)); + err->type = ERR_FTP_FAILURE; + err->http_status = HTTP_INTERNAL_SERVER_ERROR; + err->request = requestLink(ftpState->request); + err->ftp.request = ftpState->ctrl.last_command; + err->ftp.reply = ftpState->ctrl.last_reply; + errorAppendEntry(ftpState->entry, err); + storeAbort(ftpState->entry, 0); comm_close(ftpState->ctrl.fd); } diff --git a/src/structs.h b/src/structs.h index 1e748e189e..25c5f3a367 100644 --- a/src/structs.h +++ b/src/structs.h @@ -884,4 +884,8 @@ struct _ErrorState { ERCB *callback; void *callback_data; int flags; + struct { + char *request; + char *reply; + } ftp; };