You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2007/12/07 19:05:10 UTC

svn commit: r602169 - /httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c

Author: wrowe
Date: Fri Dec  7 10:05:09 2007
New Revision: 602169

URL: http://svn.apache.org/viewvc?rev=602169&view=rev
Log:
Clean up PORT and EPRT, spare us a redundant call to apr_socket_addr_get,
and emit the 'low numbered port' error log entry only for EACCES faults.


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?rev=602169&r1=602168&r2=602169&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Fri Dec  7 10:05:09 2007
@@ -1701,6 +1701,7 @@
     apr_sockaddr_t *sa;
     apr_socket_t *s;
     apr_status_t rv;
+    apr_port_t local_port;
     char *arg_tok, *ip_addr;
     apr_int32_t family;
     apr_port_t port;
@@ -1747,15 +1748,13 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    apr_socket_addr_get(&sa, APR_LOCAL, s);
-
     if (fsc->active_min != -1) {
-        short port_num = fsc->active_min + 
-                   ((int) (rand() % (fsc->active_max - fsc->active_min + 1)));
-        sa->port = port_num;
+        local_port = fsc->active_min +
+                     (apr_port_t)(rand() % (fsc->active_max -
+                                            fsc->active_min + 1));
     }
     else {
-        sa->port = 0;
+        local_port = 0;
     }
 
     /* XXX: Anything special to handle IPv6 ip_addr string where c->remote_ip
@@ -1767,22 +1766,24 @@
 #endif
        ) {
         apr_sockaddr_info_get(&sa, c->local_ip, family,
-                              sa->port, 0, c->pool);
+                              local_port, 0, c->pool);
     }
     else {
         /* If the family differs, it's difficult to map the EPRT origin IP */
         apr_sockaddr_info_get(&sa, NULL, family,
-                              sa->port, 0, c->pool);
+                              local_port, 0, c->pool);
     }
 
     apr_socket_opt_set(s, APR_SO_REUSEADDR, 1);
     rv = apr_socket_bind(s, sa);
 
     if (rv != APR_SUCCESS) {
-        if (sa->port < 1024)
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
-                          "Couldn't bind to low numbered port (<1024) socket");
+#ifdef EACCES
+        if (sa->port < 1024 && rv == EACCES)
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                          "Couldn't bind to low numbered port (<1024)");
         else
+#endif
             ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
                          "Couldn't bind to socket");
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
@@ -1842,8 +1843,9 @@
     apr_sockaddr_t *sa;
     apr_socket_t *s;
     apr_status_t rv;
+    apr_port_t local_port;
+    apr_port_t port;
     char *ip_addr, tc;
-    short port;
     int res, val[6];
 
     if (fc->all_epsv) {
@@ -1909,33 +1911,33 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    apr_socket_addr_get(&sa, APR_LOCAL, s);
-
     if (fsc->active_min != -1) {
-        short port_num = fsc->active_min + 
-                   ((int) (rand() % (fsc->active_max - fsc->active_min + 1)));
-        sa->port = port_num;
+        local_port = fsc->active_min + 
+                     (apr_port_t)(rand() % (fsc->active_max -
+                                            fsc->active_min + 1));
     }
     else {
-        sa->port = 0;
+        local_port = 0;
     }
 
     if (c->local_addr->family == APR_INET) {
         apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
-                              sa->port, 0, c->pool);
+                              local_port, 0, c->pool);
     }
     else {
         apr_sockaddr_info_get(&sa, NULL, APR_INET,
-                              sa->port, 0, c->pool);
+                              local_port, 0, c->pool);
     }
     apr_socket_opt_set(s, APR_SO_REUSEADDR, 1);
     rv = apr_socket_bind(s, sa);
 
     if (rv != APR_SUCCESS) {
-        if (sa->port < 1024)
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
-                          "Couldn't bind to low numbered port (<1024) socket");
+#ifdef EACCES
+        if (sa->port < 1024 && rv == EACCES)
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                          "Couldn't bind to low numbered port (<1024)");
         else
+#endif
             ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
                          "Couldn't bind to socket");
         return FTP_REPLY_CANNOT_OPEN_DATACONN;