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/12 19:30:25 UTC

svn commit: r603696 - in /httpd/mod_ftp/trunk: include/mod_ftp.h modules/ftp/ftp_commands.c modules/ftp/ftp_data_connection.c modules/ftp/ftp_request.c

Author: wrowe
Date: Wed Dec 12 10:30:25 2007
New Revision: 603696

URL: http://svn.apache.org/viewvc?rev=603696&view=rev
Log:
Add ftp_reset_dataconn() for performing ->csock cleanup.


Modified:
    httpd/mod_ftp/trunk/include/mod_ftp.h
    httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
    httpd/mod_ftp/trunk/modules/ftp/ftp_data_connection.c
    httpd/mod_ftp/trunk/modules/ftp/ftp_request.c

Modified: httpd/mod_ftp/trunk/include/mod_ftp.h
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/include/mod_ftp.h?rev=603696&r1=603695&r2=603696&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/include/mod_ftp.h (original)
+++ httpd/mod_ftp/trunk/include/mod_ftp.h Wed Dec 12 10:30:25 2007
@@ -304,15 +304,15 @@
     int all_epsv;             /* EPSV ALL command issued (refuse all others) */
     apr_socket_t *csock;      /* The local data socket we connect/accept on */
     apr_socket_t *datasock;   /* The remote data socket we send/recv on */
-    apr_sockaddr_t *clientsa;
+    apr_sockaddr_t *clientsa; /* The remote sa of this data connection */
     apr_time_t passive_created; /* Passive creation time or (-1) for active */
 
     /* Look-ahead for "next" command */
     apr_socket_t *cntlsock;   /* The control socket to watch for next cmd */
     apr_pool_t *next_pool;    /* Storage to get us to the next request_rec */
-    apr_bucket_brigade *next_bb;
-    char *next_request;
-    apr_size_t next_reqsize;
+    apr_bucket_brigade *next_bb; /* Holding brigade for request look-ahead */
+    char *next_request;       /* The next control command */
+    apr_size_t next_reqsize;  /* Size of the next control command */
 };
 
 #define FTP_DEFAULT_UMASK (APR_GWRITE | APR_WWRITE)
@@ -357,13 +357,18 @@
 apr_status_t ftp_read_ahead_request(ftp_connection *fc);
 apr_status_t ftp_reply(ftp_connection *fc, ap_filter_t *out_filter, 
                        apr_pool_t *p, int n, int l, const char *fmt, ...);
-conn_rec *ftp_open_dataconn(request_rec *r, int write_not_read);
 apr_status_t ftp_show_file(ap_filter_t *out_filter, apr_pool_t *p, int code, 
                            ftp_connection *fc, const char *file);
 void ftp_send_response(request_rec *r, int res);
-void ftp_data_init(conn_rec *c, ftp_connection *fc);
 apr_status_t ftp_ssl_init(conn_rec *c);
 int ftp_have_ssl(void);
+
+/* Routines specific to the FTP data connections
+ * 
+ * ftp_data_connection.c 
+ */
+void ftp_reset_dataconn(ftp_connection *fc);
+conn_rec *ftp_open_dataconn(request_rec *r, int write_not_read);
 
 /* FTP command handlers registration.
  */

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=603696&r1=603695&r2=603696&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Wed Dec 12 10:30:25 2007
@@ -1376,12 +1376,6 @@
     apr_port_t port;
     int tries = 0;
 
-    if (fc->csock) {
-        apr_socket_close(fc->csock);
-        fc->csock = NULL;
-        fc->passive_created = -1;
-    }
-
     apr_sockaddr_info_get(&sa, bindaddr, bindfamily, 0, 0, c->pool);
 
 #if APR_MAJOR_VERSION < 1
@@ -1485,6 +1479,8 @@
     const char *addr;
     int family = 0;
 
+    ftp_reset_dataconn(fc);
+
     if (strcasecmp(arg, "ALL") == 0) {
         /* A contract to never respond to other data connection methods */
         fc->all_epsv = 1;
@@ -1584,6 +1580,8 @@
     const char *addr;
     int family;
 
+    ftp_reset_dataconn(fc);
+
     if (fc->all_epsv) {
         fc->response_notes = apr_pstrdup(r->pool, "Restricted by EPSV ALL ");
         return FTP_REPLY_BAD_SEQUENCE;
@@ -1700,17 +1698,13 @@
     apr_port_t port;
     int res;
 
+    ftp_reset_dataconn(fc);
+
     if (fc->all_epsv) {
         fc->response_notes = apr_pstrdup(r->pool, "Restricted by EPSV ALL ");
         return FTP_REPLY_BAD_SEQUENCE;
     }
 
-    if (fc->csock) {
-        apr_socket_close(fc->csock);
-        fc->csock = NULL;
-        fc->passive_created = -1;
-    }
-
     arg_tok = apr_pstrdup(c->pool, arg);
     if ((res = ftp_eprt_decode(&family, &ip_addr, &port, arg_tok))
             != FTP_REPLY_COMMAND_OK) {
@@ -1834,15 +1828,11 @@
     char *ip_addr, tc;
     int res, val[6];
 
+    ftp_reset_dataconn(fc);
+
     if (fc->all_epsv) {
         fc->response_notes = apr_pstrdup(r->pool, "Restricted by EPSV ALL ");
         return FTP_REPLY_BAD_SEQUENCE;
-    }
-
-    if (fc->csock) {
-        apr_socket_close(fc->csock);
-        fc->csock = NULL;
-        fc->passive_created = -1;
     }
 
     if ((res = sscanf(arg, "%d,%d,%d,%d,%d,%d%c", &val[0], &val[1], &val[2],

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_data_connection.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_data_connection.c?rev=603696&r1=603695&r2=603696&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_data_connection.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_data_connection.c Wed Dec 12 10:30:25 2007
@@ -24,6 +24,20 @@
 #include "mod_ftp.h"
 
 /*
+ * ftp_reset_dataconn: Close any data channel listen/connect socket and
+ *                     clear all data channel state from ftp_connection
+ */
+void ftp_reset_dataconn(ftp_connection *fc)
+{
+    if (fc->csock) {
+        apr_socket_close(fc->csock);
+        fc->csock = NULL;
+    }
+    fc->clientsa = NULL;
+    fc->passive_created = -1;
+}
+
+/*
  * ftp_open_datasock: If we are in passive mode we accept and return a 
  *                    socket.  If we are in active mode, a socket is
  *                    created based on the fc->clientsa sockaddr and 
@@ -96,9 +110,6 @@
 
         /* activity on client socket, attempt an accept() */
         rv = apr_socket_accept(&s, fc->csock, c->pool);
-
-        /* fc->clientsa used for PORT, so assign it NULL for the PASV command. */
-        fc->clientsa = NULL;
 
         res = apr_socket_close(fc->csock);
         fc->csock = NULL;

Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_request.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_request.c?rev=603696&r1=603695&r2=603696&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_request.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_request.c Wed Dec 12 10:30:25 2007
@@ -60,9 +60,7 @@
                     > apr_time_from_sec(fsc->timeout_data))) {
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
                      "Timeout waiting to use passive port (closing data connection).");
-        apr_socket_close(fc->csock);
-        fc->csock = NULL;
-        fc->passive_created = -1;
+        ftp_reset_dataconn(fc);
     }
 
     ftp_send_response(r, res);