Index: squid/src/cf.data.pre diff -c squid/src/cf.data.pre:1.245.2.58 squid/src/cf.data.pre:1.245.2.59 *** squid/src/cf.data.pre:1.245.2.58 Fri Jan 30 16:09:12 2004 --- squid/src/cf.data.pre Tue Feb 3 07:33:40 2004 *************** *** 1070,1075 **** --- 1070,1092 ---- connection then turn this off. DOC_END + NAME: ftp_telnet_protocol + TYPE: onoff + DEFAULT: on + LOC: Config.Ftp.telnet + DOC_START + The FTP protocol is officially defined to use the telnet protocol + as transport channel for the control connection. However, many + implemenations are broken and does not respect this aspect of + the FTP protocol. + + If you have trouble accessing files with ASCII code 255 in the + path or similar problems involving this ASCII code then you can + try setting this directive to off. If that helps report to the + operator of the FTP server in question that their FTP server + is broken and does not follow the FTP standard. + DOC_END + NAME: cache_dns_program TYPE: string IFDEF: USE_DNSSERVERS Index: squid/src/ftp.c diff -c squid/src/ftp.c:1.316.2.11 squid/src/ftp.c:1.316.2.12 *** squid/src/ftp.c:1.316.2.11 Sun Dec 14 05:12:07 2003 --- squid/src/ftp.c Tue Feb 3 07:33:40 2004 *************** *** 1131,1146 **** /* ====================================================================== */ static void ftpWriteCommand(const char *buf, FtpStateData * ftpState) { debug(9, 5) ("ftpWriteCommand: %s\n", buf); safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup(buf); comm_write(ftpState->ctrl.fd, ! xstrdup(buf), ! strlen(buf), ftpWriteCommandCallback, ftpState, xfree); --- 1131,1185 ---- /* ====================================================================== */ + /* escapes any IAC (0xFF) characters. Returns a new string */ + static char * + escapeIAC(const char *buf) + { + int n; + char *ret; + unsigned const char *p; + unsigned char *r; + for (p = (unsigned const char *) buf, n = 1; *p; n++, p++) + if (*p == 255) + n++; + ret = xmalloc(n); + for (p = (unsigned const char *) buf, r = (unsigned char *) ret; *p; p++) { + *r++ = *p; + if (*p == 255) + *r++ = 255; + } + *r++ = '0円'; + assert((r - (unsigned char *) ret) == n); + return ret; + } + + /* removes any telnet options. Same string returned */ + static char * + decodeTelnet(char *buf) + { + char *p = buf; + while ((p = strstr(p, "377円377円")) != NULL) { + p++; + memmove(p, p + 1, strlen(p + 1) + 1); + } + return buf; + } + static void ftpWriteCommand(const char *buf, FtpStateData * ftpState) { + char *ebuf; debug(9, 5) ("ftpWriteCommand: %s\n", buf); + if (Config.Ftp.telnet) + ebuf = escapeIAC(buf); + else + ebuf = xstrdup(buf); safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup(buf); comm_write(ftpState->ctrl.fd, ! ebuf, ! strlen(ebuf), ftpWriteCommandCallback, ftpState, xfree); *************** *** 1219,1224 **** --- 1258,1265 ---- list = memAllocate(MEM_WORDLIST); list->key = xmalloc(linelen - offset); xstrncpy(list->key, s + offset, linelen - offset); + if (Config.Ftp.telnet) + decodeTelnet(list->key); debug(9, 7) ("%d %s\n", code, list->key); *tail = list; tail = &list->next; Index: squid/src/structs.h diff -c squid/src/structs.h:1.408.2.21 squid/src/structs.h:1.408.2.22 *** squid/src/structs.h:1.408.2.21 Fri Jan 30 16:09:12 2004 --- squid/src/structs.h Tue Feb 3 07:33:40 2004 *************** *** 628,633 **** --- 628,634 ---- char *anon_user; int passive; int sanitycheck; + int telnet; } Ftp; refresh_t *Refresh; struct _cacheSwap {