--------------------- PatchSet 1377 Date: 2005/05/15 14:42:19 Author: rmartinez Branch: squid3-ipv6 Tag: (none) Log: PASV mode support in IPv6. Brackets on url when needed Members: src/ftp.cc:1.26.2.3->1.26.2.4 Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.26.2.3 retrieving revision 1.26.2.4 diff -u -r1.26.2.3 -r1.26.2.4 --- squid3/src/ftp.cc 5 May 2005 09:20:32 -0000 1.26.2.3 +++ squid3/src/ftp.cc 15 May 2005 14:42:19 -0000 1.26.2.4 @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.26.2.3 2005/05/05 09:20:32 rmartinez Exp $ + * $Id: ftp.cc,v 1.26.2.4 2005/05/15 14:42:19 rmartinez Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1320,12 +1320,17 @@ ftpState->title_url.append("@"); } - ftpState->title_url.append(request->host); - if (request->port != urlDefaultPort(PROTO_FTP)) { + if (NEEDS_BRACKETS(request->host)) ftpState->title_url.append("["); + ftpState->title_url.append(request->host); + if (NEEDS_BRACKETS(request->host)) ftpState->title_url.append("]"); ftpState->title_url.append(":"); ftpState->title_url.append(xitoa(request->port)); } + else + { + ftpState->title_url.append(request->host); + } ftpState->title_url.append (request->urlpath); @@ -2188,6 +2193,9 @@ { int code = ftpState->ctrl.replycode; int h1, h2, h3, h4; +#ifdef INET6 + int h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16; +#endif int p1, p2; int n; u_short port; @@ -2208,17 +2216,36 @@ buf = ftpState->ctrl.last_reply + strcspn(ftpState->ctrl.last_reply, "0123456789"); +#ifdef INET6 + n = sscanf(buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", + &h1, &h2, &h3, &h4, + &h5, &h6, &h7, &h8, + &h9, &h10, &h11, &h12, + &h13, &h14, &h15, &h16, + &p1, &p2); + if (n != 18 || p1 < 0 || p2 < 0 || p1 > 255 || p2 > 255) { +#else n = sscanf(buf, "%d,%d,%d,%d,%d,%d", &h1, &h2, &h3, &h4, &p1, &p2); if (n != 6 || p1 < 0 || p2 < 0 || p1 > 255 || p2 > 255) { +#endif debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } +#ifdef INET6 +// FIXME.. is it according to PASV mode on IPv6 ?. + snprintf(ipaddr, 1024, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + h1, h2, h3, h4, + h5, h6, h7, h8, + h9, h10, h11, h12, + h13, h14, h15, h16); +#else snprintf(ipaddr, 1024, "%d.%d.%d.%d", h1, h2, h3, h4); +#endif - if (!safe_inet_addr(ipaddr, NULL)) { + if (!SAFE_INET_ADDR(ipaddr, NULL)) { debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; @@ -2363,9 +2390,19 @@ addrptr = (unsigned char *) &ADDR_FROM_SA(addr); portptr = (unsigned char *) &PORT_FROM_SA(addr); +#ifdef INET6 +// FIXME?....is this rigth on IPv6 ? + snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", + addrptr[0], addrptr[1], addrptr[2], addrptr[3], + addrptr[4], addrptr[5], addrptr[6], addrptr[7], + addrptr[8], addrptr[9], addrptr[10], addrptr[11], + addrptr[12], addrptr[13], addrptr[14], addrptr[15], + portptr[0], portptr[1]); +#else snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d\r\n", addrptr[0], addrptr[1], addrptr[2], addrptr[3], portptr[0], portptr[1]); +#endif ftpWriteCommand(cbuf, ftpState); ftpState->state = SENT_PORT; } @@ -2428,7 +2465,7 @@ ftpState->data.port = ntohs(PORT_FROM_SA(details->peer)); - ftpState->data.host = xstrdup(INET_NTOA(ADDR_FROM_SA(details->peer))); + ftpState->data.host = xstrdup(SA_NTOA(details->peer)); commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); @@ -3152,10 +3189,12 @@ strcat(loginbuf, "@"); } - snprintf(buf, MAX_URL, "%s://%s%s%s%s%s", + snprintf(buf, MAX_URL, "%s://%s%s%s%s%s%s%s", ProtocolStr[request->protocol], + NEEDS_BRACKETS(request->host) ? "[": null_string, loginbuf, request->host, + NEEDS_BRACKETS(request->host) ? "]": null_string, portbuf, "/%2f", request->urlpath.buf());