httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r522703 - /httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
Date Tue, 27 Mar 2007 01:53:35 GMT
Author: wrowe
Date: Mon Mar 26 18:53:34 2007
New Revision: 522703

URL: http://svn.apache.org/viewvc?view=rev&rev=522703
Log:
In order to add EPSV, it makes sense to refactor PASV handling into args and
presentation v.s. the actual passive bind.

Modified:
    httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c?view=diff&rev=522703&r1=522702&r2=522703
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Mon Mar 26 18:53:34 2007
@@ -1369,7 +1369,8 @@
     return FTP_REPLY_NOT_LOGGED_IN;
 }
 
-static int ftp_cmd_pasv(request_rec *r, const char *arg)
+static int init_pasv_socket(request_rec *r, int bindfamily,
+                            const char *bindaddr)
 {
     ftp_connection *fc = ftp_get_module_config(r->request_config);
     conn_rec *c = r->connection;
@@ -1377,11 +1378,9 @@
         ftp_get_module_config(c->base_server->module_config);
     apr_sockaddr_t *sa;
     apr_socket_t *s;
-    apr_port_t port;
     apr_status_t rv;
-    char *a, *period;
-    short high, low; 
-    int tries, found_port;
+    apr_port_t port;
+    int found_port;
 
     if (fc->csock) {
         apr_socket_close(fc->csock);
@@ -1389,36 +1388,7 @@
         fc->passive_created = -1;
     }
 
-    if (fsc->pasv_bindaddr) {
-        apr_sockaddr_info_get(&sa, fsc->pasv_bindaddr, fsc->pasv_bindfamily,
-                              0, 0, c->pool);
-    }
-    else if (c->local_addr->family == APR_INET) {
-        apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
-                              0, 0, c->pool);
-    }
-#if APR_HAVE_IPV6
-    else if (c->local_addr->family == AF_INET6 &&
-        IN6_IS_ADDR_V4MAPPED((struct in6_addr *)c->local_addr->ipaddr_ptr)) {
-         /* httpd assures us local_ip is in ipv4 notation for mapped addrs */
-        apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
-                              0, 0, c->pool);
-    }
-    else if (c->local_addr->family == AF_INET6) {
-        apr_sockaddr_info_get(&sa, c->local_ip, APR_INET6,
-                              0, 0, c->pool);
-        /* XXX: Really this is bogus and perhaps should simply fail */
-    }
-#endif
-    else {
-        /* XXX: The code below is wrong since the 'null' address 
-         * will be 0,0,0,0 not an explicit address.  We MUST resolve
-         * 0.0.0.0 to an explicit port in the IPv4 provider list.
-         */
-        apr_sockaddr_info_get(&sa, NULL, APR_INET,
-                              0, 0, c->pool);
-        /* XXX: Perhaps we should simply fail?  Or copy c->local_addr? */
-    }
+    apr_sockaddr_info_get(&sa, bindaddr, bindfamily, 0, 0, c->pool);
 
 #if APR_MAJOR_VERSION < 1
     rv = apr_socket_create_ex(&s, sa->family, SOCK_STREAM,
@@ -1450,9 +1420,10 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    found_port = 0;
     port = fsc->pasv_min;
-    while (!found_port) {
+    for (found_port = 0; !found_port; )
+    {
+        int tries;
 
         sa->port = port; /* Magic here when port = 0 */
 
@@ -1508,6 +1479,50 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
+    fc->csock = s;
+    fc->passive_created = apr_time_now();
+    return 0;
+}
+
+
+static int ftp_cmd_pasv(request_rec *r, const char *arg)
+{
+    ftp_connection *fc = ftp_get_module_config(r->request_config);
+    conn_rec *c = r->connection;
+    ftp_server_config *fsc = 
+        ftp_get_module_config(c->base_server->module_config);
+    int res;
+    apr_sockaddr_t *sa;
+    apr_socket_t *s;
+    char *report_addr, *period;
+    apr_port_t port;
+    short high, low; 
+    const char *addr;
+    int family;
+
+    if (fsc->pasv_bindaddr) {
+        addr = fsc->pasv_bindaddr;
+        family = fsc->pasv_bindfamily;
+    }
+#if APR_HAVE_IPV6
+    else if (c->local_addr->family == AF_INET6 &&
+        IN6_IS_ADDR_V4MAPPED((struct in6_addr *)c->local_addr->ipaddr_ptr)) {
+        /* httpd assures us local_ip is in ipv4 notation for mapped addrs */
+        addr = c->local_ip;
+        family = APR_INET;
+    }
+#endif
+    else {
+        addr = c->local_ip;
+        family = c->local_addr->family;
+    }
+
+    if ( ( res = init_pasv_socket(r, family, addr) ) ) {
+        return res;
+    }
+
+    s = fc->csock;
+
     apr_socket_addr_get(&sa, APR_LOCAL, s);
 
     /* pasv_addr is an ADVERTISED address, not related to the true
@@ -1515,10 +1530,10 @@
      * of servers hiding behind load balancers, vpn's, nat, etc.
      */
     if (fsc->pasv_addr) {
-        a = apr_pstrdup(c->pool, fsc->pasv_addr);
+        report_addr = apr_pstrdup(r->pool, fsc->pasv_addr);
     }
     else if (fsc->pasv_bindaddr && (fsc->pasv_bindfamily == APR_INET)) {
-        a = apr_pstrdup(c->pool, fsc->pasv_bindaddr);
+        report_addr = apr_pstrdup(r->pool, fsc->pasv_bindaddr);
     }
     else if ((c->local_addr->family == AF_INET)
 #if APR_HAVE_IPV6
@@ -1526,7 +1541,8 @@
           && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)c->local_addr->ipaddr_ptr))
 #endif
              ) {
-        a = apr_pstrdup(c->pool, c->local_ip);
+        /* httpd assures us local_ip is in ipv4 notation for mapped addrs */
+        report_addr = apr_pstrdup(r->pool, c->local_ip);
     }
     else {
         /* a bogus answer, which will not be translated below,
@@ -1534,11 +1550,11 @@
          * original, same address.  Suggested as an early solution
          * at http://cr.yp.to/ftp/retr.html
          */
-        a = "127,555,555,555";
+        report_addr = "127,555,555,555";
     }
 
     /* Translate x.x.x.x to x,x,x,x */
-    while ((period = strstr(a, ".")) != NULL) {
+    while ((period = strstr(report_addr, ".")) != NULL) {
         *period = ',';
     }
 
@@ -1547,10 +1563,7 @@
     low = (port & 0x00ff); 
     fc->response_notes = apr_psprintf(r->pool,
                                      "Entering Passive Mode (%s,%u,%u)",
-                                     a, high, low);
-    fc->csock = s;
-    fc->passive_created = apr_time_now();
-
+                                     report_addr, high, low);
     return FTP_REPLY_PASSIVE_MODE;
 }
 



Mime
View raw message