--------------------- PatchSet 4423 Date: 2007/04/30 14:24:48 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Remainder of EPRT command and set groundwork for EPSV command addition. Members: src/ftp.cc:1.26.2.16->1.26.2.17 Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.26.2.16 retrieving revision 1.26.2.17 diff -u -r1.26.2.16 -r1.26.2.17 --- squid3/src/ftp.cc 30 Apr 2007 13:32:26 -0000 1.26.2.16 +++ squid3/src/ftp.cc 30 Apr 2007 14:24:48 -0000 1.26.2.17 @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.26.2.16 2007/04/30 13:32:26 amosjeffries Exp $ + * $Id: ftp.cc,v 1.26.2.17 2007/04/30 14:24:48 amosjeffries Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -72,7 +72,9 @@ SENT_TYPE, SENT_MDTM, SENT_SIZE, + SENT_EPRT, SENT_PORT, + SENT_EPSV, SENT_PASV, SENT_CWD, SENT_LIST, @@ -291,6 +293,8 @@ static FTPSM ftpReadEPRT; static FTPSM ftpSendPORT; static FTPSM ftpReadPORT; +//static FTPSM ftpSendEPSV; +static FTPSM ftpReadEPSV; static FTPSM ftpSendPasv; static FTPSM ftpReadPasv; static FTPSM ftpTraverseDirectory; @@ -355,6 +359,7 @@ ftpReadSize, /* SENT_SIZE */ ftpReadEPRT, /* SENT_EPRT */ ftpReadPORT, /* SENT_PORT */ + ftpReadEPSV, /* SENT_EPSV */ ftpReadPasv, /* SENT_PASV */ ftpReadCwd, /* SENT_CWD */ ftpReadList, /* SENT_LIST */ @@ -2198,7 +2203,7 @@ ftpReadSize(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; - debugs(9, 3, "This is ftpReadSize"); + debugs(9, 3, HERE); if (code == 213) { ftpState->unhack(); @@ -2218,6 +2223,25 @@ ftpSendPasv(ftpState); } +/* FIXME INET6 : EPASV command not yet coded. */ +/* +static void +ftpSendEPSV(FtpStateData* ftpstate) +{ + // TODO. +} +*/ + +static void +ftpReadEPSV(FtpStateData* ftpstate) +{ + /* FIXME INET6 : EPASV command not yet coded. */ + + /* Failover to PASV */ + ftpReadPasv(ftpstate); +} + + static void ftpSendPasv(FtpStateData * ftpState) { @@ -2581,15 +2605,17 @@ ftpSendEPRT(FtpStateData * ftpState) { int fd; + IPAddress addr; + char buf[MAX_IPSTRLEN]; debugs(9, 3, HERE); ftpState->flags.pasv_supported = 0; fd = ftpOpenListenSocket(ftpState, 0); - struct sockaddr_in6 addr; + struct sockaddr_in6 taddr; socklen_t addr_len = sizeof(struct sockaddr_in6); - if (getsockname(fd, (struct sockaddr *) &addr, &addr_len)) { + if (getsockname(fd, (struct sockaddr *) &taddr, &addr_len)) { debugs(9, 0, "ftpSendEPRT: getsockname(" << fd << ",..): " << xstrerror()); /* XXX Need to set error message */ @@ -2597,10 +2623,19 @@ return; } + if(addr_len == sizeof(struct sockaddr_in)) { + addr = *((struct sockaddr_in*)&taddr); + } +#if USE_IPV6 + else if(addr_len == sizeof(struct sockaddr_in6)) { + addr = *((struct sockaddr_in6*)&taddr); + } +#endif + /* RFC 2428 defines EPRT as IPv6 equivalent to IPv4 PORT command. */ /* Which can be used by EITHER protocol. */ - snprintf(cbuf, 1024, "EPRT |%d|%s|%d\r\n", - AF_INET6, + snprintf(cbuf, 1024, "EPRT |%d|%s|%d|\r\n", + addr.IsIPv4()?AF_INET:AF_INET6, addr.NtoA(buf,MAX_IPSTRLEN), addr.GetPort() ); @@ -2609,7 +2644,7 @@ } static void -ftpReadPort(FtpStateData * ftpState) +ftpReadEPRT(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; debugs(9, 3, HERE);