httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r629101 [2/4] - /httpd/mod_ftp/trunk/modules/ftp/
Date Tue, 19 Feb 2008 14:03:38 GMT

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=629101&r1=629100&r2=629101&view=diff
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Tue Feb 19 06:03:35 2008
@@ -36,15 +36,15 @@
 #define FTP_APR_EADDRINUSE (APR_OS_START_SYSERR + WSAEADDRINUSE)
 #else
 #define FTP_APR_EADDRINUSE EADDRINUSE
-#endif /* WIN32 */
+#endif                          /* WIN32 */
 
 extern ap_filter_rec_t *ftp_content_length_filter_handle;
 
 static apr_hash_t *FTPMethodHash;
 static apr_pool_t *FTPMethodPool;
 
-FTP_DECLARE(void) ftp_hook_cmd_any(const char *key, ftp_hook_fn *pf, 
-                                   const char *alias, int order, 
+FTP_DECLARE(void) ftp_hook_cmd_any(const char *key, ftp_hook_fn *pf,
+                                   const char *alias, int order,
                                    int flags, const char *help)
 {
     ftp_cmd_entry *cmd, *curr;
@@ -63,9 +63,10 @@
     cmd->help = help;
 
     if (!FTPMethodHash) {
-        /* Should never get here.  If a user tries to load an extension
-         * module before the core FTP module is loaded, they should get
-         * an undefined symbol.
+        /*
+         * Should never get here.  If a user tries to load an extension
+         * module before the core FTP module is loaded, they should get an
+         * undefined symbol.
          */
         fprintf(stderr, "Could not process registration for %s.", key);
         return;
@@ -85,52 +86,58 @@
             cmd->next = curr->next;
             curr->next = cmd;
         }
-    }             
+    }
     else {
         apr_hash_set(FTPMethodHash, key, APR_HASH_KEY_STRING, cmd);
     }
 
-    /* Only limit commands that are implemented and access checked 
-     * (not aliases).  PASS is a special case, it is verified after
-     * invocation, login isn't needed prior to processing.
+    /*
+     * Only limit commands that are implemented and access checked (not
+     * aliases).  PASS is a special case, it is verified after invocation,
+     * login isn't needed prior to processing.
      */
     if (pf && (flags & FTP_NEED_LOGIN)) {
         ap_method_register(FTPMethodPool, key);
-    }   
+    }
     ap_method_register(FTPMethodPool, "PASS");
-}       
+}
 
-static int ftp_run_handler(request_rec *r, struct ftp_cmd_entry *cmd, 
+static int ftp_run_handler(request_rec *r, struct ftp_cmd_entry *cmd,
                            const char *arg)
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     request_rec *rr;
     int res;
 
-     /* Set the authorization header and the user name for all
-      * requests.  This information may not be needed for all   
-      * requests, but is required for logging purposes.
-      */
+    /*
+     * Set the authorization header and the user name for all requests.  This
+     * information may not be needed for all   requests, but is required for
+     * logging purposes.
+     */
     ftp_set_authorization(r);
 
-    /* Run the header parser hook for mod_setenv.  For conditional
-     * logging, etc */
+    /*
+     * Run the header parser hook for mod_setenv.  For conditional logging,
+     * etc
+     */
     ap_run_header_parser(r);
 
-    /* Run a subrequest before the command is run.  This allows us to
-     * check if a command is allowed for the user's current location */
+    /*
+     * Run a subrequest before the command is run.  This allows us to check
+     * if a command is allowed for the user's current location
+     */
     if ((res = ftp_set_uri(r, fc->cwd))) {
         return res;
     }
 
     rr = ap_sub_req_method_uri(r->method, r->uri, r, NULL);
-    
-    /* XXX - JKS
-     *
-     * This will check authz for the *CURRENT* location.  For commands
-     * where the URI can change, the command handler will need to rerun
-     * the auth/authz checks to ensure the user also has permission for
-     * the new URI.
+
+    /*
+     * XXX - JKS
+     * 
+     * This will check authz for the *CURRENT* location.  For commands where the
+     * URI can change, the command handler will need to rerun the auth/authz
+     * checks to ensure the user also has permission for the new URI.
      */
     if ((rr->status == HTTP_UNAUTHORIZED &&
          (cmd->flags & FTP_NEED_LOGIN)) ||
@@ -151,22 +158,22 @@
     }
     else if (res == DECLINED && cmd->next) {
         return ftp_run_handler(r, cmd->next, arg);
-    }   
+    }
     else {
         return FTP_REPLY_COMMAND_UNRECOGNIZED;
     }
 }
 
-const char * ftp_get_cmd_alias(const char *key)
+const char *ftp_get_cmd_alias(const char *key)
 {
     ftp_cmd_entry *cmd;
- 
+
     if (!FTPMethodHash) {
-        return key; 
+        return key;
     }
 
     cmd = apr_hash_get(FTPMethodHash, key, APR_HASH_KEY_STRING);
-    
+
     if (cmd && cmd->alias) {
         return (const char *) cmd->alias;
     }
@@ -175,7 +182,7 @@
 }
 
 /* ftp_parse2: Parse a FTP request that is expected to have 2 arguments.
- *                 
+ *
  * Arguments: pool - Pool to allocate from
  *            cmd  - The complete request (e.g. GET /foo.html)
  *            a1   - The first argument
@@ -184,11 +191,11 @@
  * Returns: 1 on error or 0 on success, a1 and a2 are modified to point
  *          to the correct values.
  */
-static int ftp_parse2(apr_pool_t *pool, const char *cmd, char **a1, char **a2)
+static int ftp_parse2(apr_pool_t *t *pool, const char *cmd, char **a1, char **a2)
 {
     *a1 = ap_getword_white(pool, &cmd);
     *a2 = apr_pstrdup(pool, cmd);
-    if(!*a1 || !*a2) {
+    if (!*a1 || !*a2) {
         return 1;
     }
     return 0;
@@ -200,19 +207,19 @@
     ftp_cmd_entry *cmd;
     char *method, *arg = NULL;
     int res;
- 
+
     if (!FTPMethodHash) {
-        return FTP_REPLY_LOCAL_ERROR; 
+        return FTP_REPLY_LOCAL_ERROR;
     }
 
     cmd = apr_hash_get(FTPMethodHash, key, APR_HASH_KEY_STRING);
-    
+
     if (cmd) {
 
-        /* Commands must have been traslated to their real
-         * equivilants back in ftp_read_request_line, by the
-         * ftp_get_cmd_alias function above.
-         *
+        /*
+         * Commands must have been traslated to their real equivilants back
+         * in ftp_read_request_line, by the ftp_get_cmd_alias function above.
+         * 
          * XXX: recursive aliases are unsupported
          */
         if (cmd->pf == NULL) {
@@ -226,14 +233,14 @@
         }
         else {
             res = ftp_parse2(r->pool, r->the_request,
-                                 &method, &arg);
-            if ((!(cmd->flags &  FTP_TAKE0) && !arg) || res)
+                             &method, &arg);
+            if ((!(cmd->flags & FTP_TAKE0) && !arg) || res)
                 return FTP_REPLY_LOCAL_ERROR;
-                
+
             return ftp_run_handler(r, cmd, arg);
         }
     }
-        
+
     return FTP_REPLY_COMMAND_UNRECOGNIZED;
 }
 
@@ -242,7 +249,7 @@
     ftp_cmd_entry *cmd;
 
     cmd = apr_hash_get(FTPMethodHash, key, APR_HASH_KEY_STRING);
-    
+
     /* Return true if cmd should abort an active data connection */
     return (cmd && (cmd->flags & FTP_DATA_INTR));
 }
@@ -266,23 +273,24 @@
         return FTP_REPLY_COMMAND_NOT_IMPL_PARAM;
     }
 
-    /* RFC 2228 states these arguments are case insensitive.
-     * draft-murray-auth-ftp-ssl-06.txt defined these 4 AUTH mechanisms.
-     * TLS or TLS-C  will encrypt the control connection, leaving the
-     * data channel clear.  SSL or TLS-P will encrypt both the control
-     * and data connections.
-     * As it evolved to publication, all but "TLS" were dropped from RFC4217,
-     * as RFC 2228 previously insisted that PROT defaults to 'C'lear text.
+    /*
+     * RFC 2228 states these arguments are case insensitive.
+     * draft-murray-auth-ftp-ssl-06.txt defined these 4 AUTH mechanisms. TLS
+     * or TLS-C  will encrypt the control connection, leaving the data
+     * channel clear.  SSL or TLS-P will encrypt both the control and data
+     * connections. As it evolved to publication, all but "TLS" were dropped
+     * from RFC4217, as RFC 2228 previously insisted that PROT defaults to
+     * 'C'lear text.
      */
-    if ((strcasecmp(arg, "SSL") == 0) || 
+    if ((strcasecmp(arg, "SSL") == 0) ||
         (strcasecmp(arg, "TLS-P") == 0)) {
 
         fc->prot = FTP_PROT_PRIVATE;
         fc->auth = FTP_AUTH_SSL;
     }
-    else if ((strcasecmp(arg, "TLS") == 0) || 
+    else if ((strcasecmp(arg, "TLS") == 0) ||
              (strcasecmp(arg, "TLS-C") == 0)) {
-      
+
         fc->prot = FTP_PROT_CLEAR;
         fc->auth = FTP_AUTH_TLS;
     }
@@ -324,17 +332,18 @@
     /* Handle special case where the URI is / */
     if (r->uri[0] == '/' && !r->uri[1]) {
         apr_cpystrn(fc->cwd, r->uri, APR_PATH_MAX + 1);
-         
+
         if (dconf->readme) {
 
-            /* We do not inherit readme messages.  If this readme was
-             * not specifically meant for us, we skip it.  The exception
-             * to the rule is if FTPReadmeMessage was placed in the
-             * global server configuration.
+            /*
+             * We do not inherit readme messages.  If this readme was not
+             * specifically meant for us, we skip it.  The exception to the
+             * rule is if FTPReadmeMessage was placed in the global server
+             * configuration.
              */
             if (!dconf->path ||
                 !strncmp(dconf->path, r->filename,
-                        strlen(r->filename) - 1)) {
+                         strlen(r->filename) - 1)) {
 
                 if (dconf->readme_isfile) {
                     ftp_show_file(c->output_filters, r->pool,
@@ -343,7 +352,7 @@
                 }
                 else {
                     char outbuf[BUFSIZ];
-                
+
                     ftp_message_generate(fc, dconf->readme, outbuf,
                                          sizeof(outbuf));
                     ftp_reply(fc, c->output_filters, r->pool,
@@ -359,7 +368,7 @@
 
     /* Check access permissions for the new directory. */
     if (!((rr->status == HTTP_OK) || (rr->status == HTTP_MOVED_PERMANENTLY))) {
-        fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED, 
+        fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                           r->parsed_uri.path);
         ap_destroy_sub_req(rr);
         return FTP_REPLY_FILE_NOT_FOUND;
@@ -373,12 +382,13 @@
         }
         else {
             apr_cpystrn(fc->cwd, r->parsed_uri.path, APR_PATH_MAX + 1);
-            
+
             if (dconf->readme) {
-                /* We do not inherit readme messages.  If this readme was
-                 * not specifically meant for us, we skip it.  The exception
-                 * to the rule is if FTPReadmeMessage was placed in the
-                 * global server configuration.
+                /*
+                 * We do not inherit readme messages.  If this readme was not
+                 * specifically meant for us, we skip it.  The exception to
+                 * the rule is if FTPReadmeMessage was placed in the global
+                 * server configuration.
                  */
                 if (!dconf->path ||
                     !strncmp(dconf->path, r->filename,
@@ -428,15 +438,16 @@
     request_rec *rr;
     apr_status_t rv;
     int res, response;
-    
+
     if ((res = ftp_set_uri(r, arg))) {
         return res;
     }
 
     rr = ap_sub_req_method_uri(r->method, r->uri, r, NULL);
 
-    /* If the user does not have permission to view the file, do
-     * not let them delete it.
+    /*
+     * If the user does not have permission to view the file, do not let them
+     * delete it.
      */
     if ((rr->status == HTTP_UNAUTHORIZED) || (rr->status == HTTP_FORBIDDEN)) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
@@ -445,7 +456,7 @@
     }
     /* We do have permission, and the file exists.  Try to remove. */
     else if (rr->finfo.filetype == APR_DIR) {
-        
+
         rv = apr_dir_remove(r->filename, r->pool);
 
         if (rv != APR_SUCCESS) {
@@ -453,16 +464,17 @@
             char *err = apr_strerror(rv, error_str, sizeof(error_str));
             fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                               err);
-               
+
             response = FTP_REPLY_FILE_NOT_FOUND;
-        } else {
+        }
+        else {
             response = FTP_REPLY_COMPLETED;
         }
     }
     else if (rr->finfo.filetype == APR_REG) {
-        
+
         rv = apr_file_remove(r->filename, r->pool);
-        
+
         if (rv != APR_SUCCESS) {
             /* Call to apr_file_remove failed */
             char error_str[120];
@@ -479,7 +491,7 @@
         /* File does not exist */
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOSUCHFILE,
                                           r->parsed_uri.path);
-        response = FTP_REPLY_FILE_NOT_FOUND;   
+        response = FTP_REPLY_FILE_NOT_FOUND;
     }
     ap_destroy_sub_req(rr);
     return response;
@@ -511,7 +523,8 @@
             fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOTIMPL, arg);
             return FTP_REPLY_COMMAND_NOT_IMPLEMENTED;
         }
-    } else {
+    }
+    else {
         apr_status_t rv;
         apr_bucket_brigade *bb;
         apr_hash_index_t *hi;
@@ -524,35 +537,35 @@
         buf = apr_psprintf(r->pool, "%d-%s" CRLF, FTP_REPLY_HELP_MESSAGE,
                            "The following commands are recognized "
                            "(* =>'s unimplemented).");
-        
-        for (hi = apr_hash_first(r->pool, FTPMethodHash), i = 0; hi; 
+
+        for (hi = apr_hash_first(r->pool, FTPMethodHash), i = 0; hi;
              hi = apr_hash_next(hi), i++) {
-            
+
             apr_hash_this(hi, NULL, NULL, &val);
-            cmd = (struct ftp_cmd_entry *)val;
+            cmd = (struct ftp_cmd_entry *) val;
 
             if (cmd->alias) {
                 ftp_cmd_entry *basecmd;
                 basecmd = apr_hash_get(FTPMethodHash, cmd->alias, APR_HASH_KEY_STRING);
-    
+
                 if (basecmd && basecmd->pf)
                     supported = ' ';
                 else
                     supported = '*';
-            } 
+            }
             else if (cmd->pf)
                 supported = ' ';
             else
                 supported = '*';
 
-            method = apr_psprintf(r->pool, "   %c%-4s", 
+            method = apr_psprintf(r->pool, "   %c%-4s",
                                   supported, cmd->key);
 
             buf = apr_pstrcat(r->pool, buf, method, NULL);
-            
-            if (((i + 1) % 8) == 0 )
+
+            if (((i + 1) % 8) == 0)
                 buf = apr_pstrcat(r->pool, buf, CRLF, NULL);
-        }       
+        }
 
         buf = apr_pstrcat(r->pool, buf, CRLF, NULL);
 
@@ -571,15 +584,15 @@
         return FTP_REPLY_HELP_MESSAGE;
     }
 }
-    
+
 static int ftp_cmd_nlst(request_rec *r, const char *arg);
 
 static int ftp_cmd_list(request_rec *r, const char *arg)
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     conn_rec *cdata;
     request_rec *rr;
     apr_bucket_brigade *bb;
@@ -594,7 +607,7 @@
     const char *test, *sl;
 
     while ((word = ap_getword_white(r->pool, &arg)) != NULL) {
-        if(word[0] != '-')
+        if (word[0] != '-')
             break;
         if (ap_strchr(word, 'l')) {
             dashl = 1;
@@ -609,19 +622,21 @@
 
     if (ap_strchr_c(arg, '*') != NULL) {
         /* Prevent DOS attacks, only allow one segment to have a wildcard */
-        int found = 0;           /* The number of segments with a wildcard */
-        const char *pos = arg;   /* Pointer for iterating over the string */
-        
+        int found = 0;          /* The number of segments with a wildcard */
+        const char *pos = arg;  /* Pointer for iterating over the string */
+
         while (*pos != '\0') {
             if (*pos == '*') {
-                /* We found a wildcard in this segment.  Increment the count
-                 * and move the pointer to the beginning of the next 
-                 * segment */
+                /*
+                 * We found a wildcard in this segment.  Increment the count
+                 * and move the pointer to the beginning of the next segment
+                 */
                 found++;
                 while (*pos != '\0' && *pos != '/') {
                     pos++;
                 }
-            } else {
+            }
+            else {
                 /* Nothing here, move on */
                 pos++;
             }
@@ -629,7 +644,7 @@
 
         /* In the future this can be configurable */
         if (found > 1) {
-            ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, 0,
+            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, 0,
                          "Ignoring directory listing request for %s", arg);
             fc->response_notes = apr_psprintf(r->pool,
                                               FTP_MSG_PERM_DENIED, arg);
@@ -659,20 +674,20 @@
     }
 
     ap_destroy_sub_req(rr);
- 
-    if(arg[0] == '\0') {
+
+    if (arg[0] == '\0') {
         pattern = apr_pstrcat(r->pool, r->filename, "/*", NULL);
     }
     else {
         pattern = r->filename;
     }
-    
+
 #ifdef FTP_DEBUG
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Pattern: %s", pattern);
 #endif
 
     /* Construct the sorted array of directory contents */
-    if((direntry = ftp_direntry_get(r, pattern)) == NULL) {
+    if ((direntry = ftp_direntry_get(r, pattern)) == NULL) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOSUCHFILE, arg);
         return FTP_REPLY_FILE_NOT_FOUND;
     }
@@ -680,7 +695,7 @@
     fc->response_notes = FTP_MSG_OPENASCII;
     ftp_send_response(r, FTP_REPLY_FILE_STATUS_OK);
 
-    if ( !(cdata = ftp_open_dataconn(r, 1)) ) {
+    if (!(cdata = ftp_open_dataconn(r, 1))) {
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
@@ -699,7 +714,7 @@
     }
     else {
         /* Handle case 2 & 3 */
-        for (dirp = direntry; dirp; dirp=dirp->next) {
+        for (dirp = direntry; dirp; dirp = dirp->next) {
             if (dirp->child)
                 decend = 1;
         }
@@ -714,13 +729,13 @@
         }
 
         for (test = dirp->name; (sl = ap_strchr_c(test, '/')); test = sl + 1)
-        /* noop */ ;
+             /* noop */ ;
 
         if (!strcmp(".", test)) {
             continue;
         }
 
-        buf = apr_psprintf(r->pool, 
+        buf = apr_psprintf(r->pool,
                            "%10s%5d %-8s %-8s%9" APR_OFF_T_FMT " %s %s"
                            CRLF, dirp->modestring, dirp->nlink,
                            dirp->username, dirp->groupname,
@@ -730,29 +745,29 @@
                                buf, nbytes);
         fc->traffic += nbytes;
     }
-    
+
     if (decend) {
-        for (dirp = direntry; dirp; dirp=dirp->next) {
+        for (dirp = direntry; dirp; dirp = dirp->next) {
             if (dirp->modestring[0] == 'd' && dirp->child) {
                 ftp_direntry *decend;
-                
+
                 /* Iterate through the sub directory */
                 buf = apr_psprintf(r->pool, CRLF "%s:" CRLF, dirp->name);
                 nbytes = strlen(buf);
                 rv = apr_brigade_write(bb, ap_filter_flush,
                                        cdata->output_filters, buf, nbytes);
                 fc->traffic += nbytes;
-                
+
                 buf = apr_pstrcat(r->pool, "total 0" CRLF, NULL);
                 nbytes = strlen(buf);
-                rv = apr_brigade_write(bb, ap_filter_flush, 
+                rv = apr_brigade_write(bb, ap_filter_flush,
                                        cdata->output_filters, buf, nbytes);
                 fc->traffic += nbytes;
-                
+
                 for (decend = dirp->child; decend; decend = decend->next) {
                     for (test = dirp->name; (sl = ap_strchr_c(test, '/'));
-                                             test = sl + 1)
-                    /* noop */ ;
+                         test = sl + 1)
+                         /* noop */ ;
 
                     if (!strcmp(".", test)) {
                         continue;
@@ -762,11 +777,11 @@
                                        APR_OFF_T_FMT " %s %s" CRLF,
                                        decend->modestring, decend->nlink,
                                        decend->username, decend->groupname,
-                                       decend->size, decend->datestring, 
+                                       decend->size, decend->datestring,
                                        decend->name);
                     nbytes = strlen(buf);
                     rv = apr_brigade_write(bb, ap_filter_flush,
-                                           cdata->output_filters, buf, 
+                                           cdata->output_filters, buf,
                                            nbytes);
                     fc->traffic += nbytes;
                 }
@@ -843,18 +858,19 @@
     dconf = ftp_get_module_config(rr->per_dir_config);
     dirperms = dconf->dirperms;
     ap_destroy_sub_req(rr);
-    
+
     if (dirperms == APR_OS_DEFAULT)
         dirperms = FTP_DEFAULT_UMASK;
 
-    /* In the config phase, ->fileperms was a negative umask.
-     * for operation, exchange this with a positive protections
-     * to pass to the apr_dir_make protection flag.
+    /*
+     * In the config phase, ->fileperms was a negative umask. for operation,
+     * exchange this with a positive protections to pass to the apr_dir_make
+     * protection flag.
      */
     dirperms = (APR_UREAD | APR_UWRITE | APR_UEXECUTE |
                 APR_GREAD | APR_GWRITE | APR_GEXECUTE |
                 APR_WREAD | APR_WWRITE | APR_WEXECUTE)
-              & ~dirperms;
+        & ~dirperms;
     rv = apr_dir_make(r->filename, dirperms, r->pool);
 
     if (rv != APR_SUCCESS) {
@@ -875,8 +891,8 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     conn_rec *cdata;
     request_rec *rr;
     int res;
@@ -891,7 +907,7 @@
     const char *test, *sl;
 
     while ((word = ap_getword_white(r->pool, &arg)) != NULL) {
-        if(word[0] != '-')
+        if (word[0] != '-')
             break;
         if (ap_strchr(word, 'l')) {
             dashl = 1;
@@ -909,7 +925,7 @@
             break;
     }
     arg = word;
-    
+
     if ((res = ftp_set_uri(r, arg))) {
         return res;
     }
@@ -921,11 +937,11 @@
 
         /* Rerun the subrequest */
         ap_destroy_sub_req(rr);
-        rr = ap_sub_req_method_uri(r->method, r->uri, r, NULL);   
+        rr = ap_sub_req_method_uri(r->method, r->uri, r, NULL);
     }
-    
+
     if (rr->status != HTTP_OK) {
-        fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED, 
+        fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                           r->parsed_uri.path);
         ap_destroy_sub_req(rr);
         return FTP_REPLY_FILE_NOT_FOUND;
@@ -944,7 +960,7 @@
 #endif
 
     /* Construct the sorted array of directory contents */
-    if((direntry = ftp_direntry_get(r, pattern)) == NULL) {
+    if ((direntry = ftp_direntry_get(r, pattern)) == NULL) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOSUCHFILE, arg);
         return FTP_REPLY_FILE_NOT_FOUND;
     }
@@ -960,7 +976,7 @@
 
     for (dirp = direntry; dirp; dirp = dirp->next) {
         for (test = dirp->name; (sl = ap_strchr_c(test, '/')); test = sl + 1)
-        /* noop */ ;
+             /* noop */ ;
 
         if (!strcmp(".", test)) {
             continue;
@@ -970,18 +986,18 @@
             dirp->modestring[0] != 'd') {
             buf = apr_psprintf(r->pool, "%s" CRLF, dirp->name);
             nbytes = strlen(buf);
-            rv = apr_brigade_write(bb, ap_filter_flush, 
+            rv = apr_brigade_write(bb, ap_filter_flush,
                                    cdata->output_filters, buf, nbytes);
-            fc->traffic += nbytes;            
-        }   
+            fc->traffic += nbytes;
+        }
     }
- 
+
     /* If the brigade is empty, just send an eos */
     if (APR_BRIGADE_EMPTY(bb)) {
         b = apr_bucket_eos_create(c->bucket_alloc);
         APR_BRIGADE_INSERT_TAIL(bb, b);
     }
-        
+
     /* Flush the brigade down the filter chain */
     b = apr_bucket_flush_create(cdata->bucket_alloc);
     APR_BRIGADE_INSERT_TAIL(bb, b);
@@ -1010,8 +1026,8 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     core_server_config *ftpcore = NULL;
     char *userdir = NULL;
     ftp_dir_config *dconf;
@@ -1025,22 +1041,26 @@
         return FTP_REPLY_BAD_SEQUENCE;
     }
 
-    /* Reset the possibly mauled ap_document_root and our cwd
-     * with each attempt to finish logging in.
+    /*
+     * Reset the possibly mauled ap_document_root and our cwd with each
+     * attempt to finish logging in.
      */
     r->server = fc->orig_server;
     apr_cpystrn(fc->cwd, "/", APR_PATH_MAX + 1);
 
-    /* By this point we have already extracted the arguments, so rewrite
-     * the original request to not include the password */
+    /*
+     * By this point we have already extracted the arguments, so rewrite the
+     * original request to not include the password
+     */
     r->the_request = apr_pstrdup(r->pool, "PASS xxx");
 
     userpass = apr_psprintf(r->pool, "%s:%s", fc->user, arg);
     fc->authorization = apr_psprintf(fc->login_pool, "Basic %s",
                                      ap_pbase64encode(r->pool, userpass));
 
-    /* This is normally set in the dispatcher, but since we just read
-     * the password, we need to reset the auth header and r->user
+    /*
+     * This is normally set in the dispatcher, but since we just read the
+     * password, we need to reset the auth header and r->user
      */
     ftp_set_authorization(r);
 
@@ -1053,70 +1073,70 @@
         ftpserver = apr_pcalloc(fc->login_pool, sizeof(*ftpserver));
         memcpy(ftpserver, r->server, sizeof(*ftpserver));
 
-        /* We need to count the number of modules in order to know
-         * how big an array to allocate.  There is a variable in
-         * the server for this, but it isn't exported, so we are
-         * stuck doing this.  I guess this could be a static variable
-         * that we compute once, but it shouldn't be that expensive
-         * to do it this way.
+        /*
+         * We need to count the number of modules in order to know how big an
+         * array to allocate.  There is a variable in the server for this,
+         * but it isn't exported, so we are stuck doing this.  I guess this
+         * could be a static variable that we compute once, but it shouldn't
+         * be that expensive to do it this way.
          */
         for (i = 0; ap_loaded_modules[i]; i++);
         conf_vector = apr_pcalloc(fc->login_pool, sizeof(void *) * i);
 
         for (modp = ap_top_module; modp; modp = modp->next) {
-            /* This is a hack.  Basically, to keep the user in thier
-             * own directory, we are re-writing the DocumentRoot when
-             * the user logs in.  To do this, we copy the entire
-             * server_rec for this Vhost, and then we copy the whole
-             * module_config for that server.  For the core module,
-             * we don't just copy the pointer, instead we create a new
-             * core_server_config, copy the old one to it, and change
-             * the docroot.  Yuck.
+            /*
+             * This is a hack.  Basically, to keep the user in thier own
+             * directory, we are re-writing the DocumentRoot when the user
+             * logs in.  To do this, we copy the entire server_rec for this
+             * Vhost, and then we copy the whole module_config for that
+             * server.  For the core module, we don't just copy the pointer,
+             * instead we create a new core_server_config, copy the old one
+             * to it, and change the docroot.  Yuck.
              */
             if (modp == &core_module) {
                 core_server_config *core;
 
                 ftpcore = apr_pcalloc(fc->login_pool, sizeof(*ftpcore));
-                core = 
-                     ap_get_module_config(r->server->module_config, modp);
+                core =
+                    ap_get_module_config(r->server->module_config, modp);
                 *ftpcore = *core;
                 ap_set_module_config(conf_vector, modp, ftpcore);
             }
             else {
-                ap_set_module_config(conf_vector, modp, 
-                     ap_get_module_config(r->server->module_config, modp));
+                ap_set_module_config(conf_vector, modp,
+                      ap_get_module_config(r->server->module_config, modp));
             }
         }
-        ftpserver->module_config = (ap_conf_vector_t *)conf_vector;
+        ftpserver->module_config = (ap_conf_vector_t *) conf_vector;
         r->server = ftpserver;
     }
 
     if (fsc->docrootenv) {
         const char *docroot;
 
-        /* Invoke a request that forces auth to occur,
-         * Then check for an fsc->docrootenv that translates 
-         * to a valid envvar.
+        /*
+         * Invoke a request that forces auth to occur, Then check for an
+         * fsc->docrootenv that translates to a valid envvar.
          */
         rr = ap_sub_req_method_uri(r->method, "/", r, NULL);
         docroot = apr_table_get(rr->subprocess_env, fsc->docrootenv);
-    
+
         if (!docroot || !*docroot) {
-            ap_log_perror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0,
+            ap_log_perror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0,
                           r->pool,
-                          "Warning: Document Root variable from FTPDocRootEnv [%s] "
-                          "was empty or not found, using default DocumentRoot",
+                  "Warning: Document Root variable from FTPDocRootEnv [%s] "
+                       "was empty or not found, using default DocumentRoot",
                           fsc->docrootenv);
         }
-        else if (((rv = apr_filepath_merge(&tmppath, NULL, docroot, 
+        else if (((rv = apr_filepath_merge(&tmppath, NULL, docroot,
                                            APR_FILEPATH_TRUENAME |
-                                           APR_FILEPATH_NOTRELATIVE, 
+                                           APR_FILEPATH_NOTRELATIVE,
                                            fc->login_pool)) != APR_SUCCESS)
-              || (rv = APR_ENOTDIR, !ap_is_directory(r->pool, tmppath))) {
+                 || (rv = APR_ENOTDIR, !ap_is_directory(r->pool, tmppath))) {
             ap_log_perror(APLOG_MARK, APLOG_WARNING, rv,
                           r->pool,
-                          "Warning: Document Root [%s] from FTPDocRootEnv [%s] "
-                          "is invalid or does not exist, using default DocumentRoot",
+                      "Warning: Document Root [%s] from FTPDocRootEnv [%s] "
+                 "is invalid or does not exist, using default DocumentRoot",
                           docroot, fsc->docrootenv);
         }
         else {
@@ -1134,7 +1154,7 @@
         if (userdir) {
 
             rr = ap_sub_req_method_uri(r->method, userdir, r, NULL);
-            
+
             if (rr->finfo.filetype == APR_DIR &&
                 (rr->status == HTTP_OK ||
                  rr->status == HTTP_MOVED_PERMANENTLY)) {
@@ -1148,10 +1168,10 @@
                 if (fsc->options & FTP_OPT_CREATEHOMEDIRS) {
 
                     if (rr->finfo.filetype == APR_NOFILE && rr->filename
-                        && ap_is_directory(rr->pool, 
-                              ap_make_dirstr_parent(rr->pool, rr->filename))) {
+                        && ap_is_directory(rr->pool,
+                           ap_make_dirstr_parent(rr->pool, rr->filename))) {
 
-                        rv = apr_dir_make(rr->filename, APR_OS_DEFAULT, 
+                        rv = apr_dir_make(rr->filename, APR_OS_DEFAULT,
                                           r->pool);
 
                         if (rv != APR_SUCCESS) {
@@ -1165,30 +1185,32 @@
                             /* The new directory was created. */
                             tmppath = apr_pstrcat(r->pool, userdir, "/", NULL);
                             apr_cpystrn(fc->cwd, tmppath, APR_PATH_MAX + 1);
-                            ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO,
+                            ap_log_error(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO,
                                          0, r->server, "Created home "
                                          "directory (%s) for user %s",
                                          rr->filename, fc->user);
                         }
-                    } else {
-                        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 
-                                     0, r->server, 
+                    }
+                    else {
+                        ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO,
+                                     0, r->server,
                                      "Home directory for user %s not "
-                                     "found.  Using \"/\"", fc->user); 
-                
+                                     "found.  Using \"/\"", fc->user);
+
                     }
                 }
                 else {
-                    ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0,
+                    ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0,
                                  r->server, "Home directory for "
-                                 "user %s not found.  Using \"/\"", 
+                                 "user %s not found.  Using \"/\"",
                                  fc->user);
                 }
-            } else {
-                
-                ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0,
+            }
+            else {
+
+                ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0,
                              r->server, "Permission denied entering"
-                             " home directory for user %s.  Using \"/\"", 
+                             " home directory for user %s.  Using \"/\"",
                              fc->user);
             }
 
@@ -1197,15 +1219,16 @@
     }
 
     if (fsc->jailuser) {
-        /* If we didn't set cwd the Jailed user can't be allowed to log in.
-         * The cwd was set to userdir if it existed or was created above,
-         * but we must ignore the trailing slash.
+        /*
+         * If we didn't set cwd the Jailed user can't be allowed to log in.
+         * The cwd was set to userdir if it existed or was created above, but
+         * we must ignore the trailing slash.
          */
         if (!userdir || (strncmp(userdir, fc->cwd, strlen(userdir)) != 0)) {
             goto pass_try_again;
         }
-        ftpcore->ap_document_root = apr_pstrcat(fc->login_pool, 
-                  ftpcore->ap_document_root, userdir, NULL);
+        ftpcore->ap_document_root = apr_pstrcat(fc->login_pool,
+                                  ftpcore->ap_document_root, userdir, NULL);
         apr_cpystrn(fc->cwd, "/", APR_PATH_MAX + 1);
     }
 
@@ -1214,33 +1237,33 @@
 
     dconf = ftp_get_module_config(rr->per_dir_config);
 
-    if (rr->status == HTTP_OK) {      
-        /* We now must iterate over the entire scoreboard checking to see
-         * if we have another server that can handle an incoming request.
-         * If we don't see another server in the ready state, that means
-         * we are the last available server, and must send the client a
-         * message that the server is full.
-         *
-         * For those wondering, there is a race condition here that could
-         * cause a client to be put in the accept queue, but we should be
-         * able to recover from this once a client disconnects.
-         *
-         * This has a few side effects:
-         * - We can really only service Max - 1 FTP sessions concurrently.
+    if (rr->status == HTTP_OK) {
+        /*
+         * We now must iterate over the entire scoreboard checking to see if
+         * we have another server that can handle an incoming request. If we
+         * don't see another server in the ready state, that means we are the
+         * last available server, and must send the client a message that the
+         * server is full.
+         * 
+         * For those wondering, there is a race condition here that could cause
+         * a client to be put in the accept queue, but we should be able to
+         * recover from this once a client disconnects.
+         * 
+         * This has a few side effects: - We can really only service Max - 1 FTP
+         * sessions concurrently.
          * 
-         * - If a hybid server is heavily loaded, such that all servers 
-         *   are busy serving HTTP traffic, it is possible to starve FTP
-         *   requests, since when we check the scoreboard, all servers will
-         *   be busy.
+         * - If a hybid server is heavily loaded, such that all servers are busy
+         * serving HTTP traffic, it is possible to starve FTP requests, since
+         * when we check the scoreboard, all servers will be busy.
          */
         ftp_loginlimit_t limrv;
-        
-        if ((fsc->options & FTP_OPT_CHECKMAXCLIENTS) && 
+
+        if ((fsc->options & FTP_OPT_CHECKMAXCLIENTS) &&
             ftp_check_maxclients(r)) {
             ap_destroy_sub_req(rr);
             fc->response_notes = apr_pstrdup(r->pool,
                                              "Maximum number of concurrent "
-                                             "sessions reached, closing connection.");
+                                   "sessions reached, closing connection.");
             fc->close_connection = 1;
 
             return FTP_REPLY_SERVICE_NOT_AVAILABLE;
@@ -1249,54 +1272,54 @@
         limrv = ftp_limitlogin_check(fc->user, r);
         /* I love switch */
         switch (limrv) {
-            case FTP_LIMIT_HIT_PERSERVER:
-                ap_destroy_sub_req(rr);
-                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
-                             r->server, "FTP per server login limit hit for %s",
-                             fc->user);
+        case FTP_LIMIT_HIT_PERSERVER:
+            ap_destroy_sub_req(rr);
+            ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, 0,
+                         r->server, "FTP per server login limit hit for %s",
+                         fc->user);
 
-                fc->response_notes = apr_pstrdup(r->pool,
-                                                 "Maximum number of concurrent "
-                                                 "sessions reached, closing connection.");
-                fc->close_connection = 1;
-                return FTP_REPLY_SERVICE_NOT_AVAILABLE;
-
-            case FTP_LIMIT_HIT_PERUSER:
-                ap_destroy_sub_req(rr);
-                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
-                             r->server, "FTP per user login limit hit for %s",
-                             fc->user);
+            fc->response_notes = apr_pstrdup(r->pool,
+                                             "Maximum number of concurrent "
+                                   "sessions reached, closing connection.");
+            fc->close_connection = 1;
+            return FTP_REPLY_SERVICE_NOT_AVAILABLE;
 
-                fc->response_notes = apr_pstrdup(r->pool,
-                                                 "Maximum number of concurrent "
-                                                 "sessions reached, closing connection.");
-                fc->close_connection = 1;
-                return FTP_REPLY_SERVICE_NOT_AVAILABLE;
-
-            case FTP_LIMIT_HIT_PERIP:
-                ap_destroy_sub_req(rr);
-                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
-                             r->server, "FTP per IP login limit hit for %s",
-                             fc->user);
-                
-                fc->response_notes = apr_pstrdup(r->pool,
-                                                 "Maximum number of concurrent "
-                                                 "sessions reached, closing connection.");
-                fc->close_connection = 1;
-                return FTP_REPLY_SERVICE_NOT_AVAILABLE;
-                
-            case FTP_LIMIT_ERROR:
-                ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
-                             r->server, "Error accessing DB for user %s; no login limit in effect",
-                             fc->user);
-                break;
+        case FTP_LIMIT_HIT_PERUSER:
+            ap_destroy_sub_req(rr);
+            ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, 0,
+                         r->server, "FTP per user login limit hit for %s",
+                         fc->user);
+
+            fc->response_notes = apr_pstrdup(r->pool,
+                                             "Maximum number of concurrent "
+                                   "sessions reached, closing connection.");
+            fc->close_connection = 1;
+            return FTP_REPLY_SERVICE_NOT_AVAILABLE;
+
+        case FTP_LIMIT_HIT_PERIP:
+            ap_destroy_sub_req(rr);
+            ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, 0,
+                         r->server, "FTP per IP login limit hit for %s",
+                         fc->user);
 
-            case FTP_LIMIT_OK:
-            default:
-                break;
+            fc->response_notes = apr_pstrdup(r->pool,
+                                             "Maximum number of concurrent "
+                                   "sessions reached, closing connection.");
+            fc->close_connection = 1;
+            return FTP_REPLY_SERVICE_NOT_AVAILABLE;
+
+        case FTP_LIMIT_ERROR:
+            ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, 0,
+                         r->server, "Error accessing DB for user %s; no login limit in effect",
+                         fc->user);
+            break;
+
+        case FTP_LIMIT_OK:
+        default:
+            break;
         }
 
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_INFO, 0,
                      r->server, "FTP LOGIN FROM %s as %s",
                      c->remote_ip, fc->user);
 
@@ -1308,10 +1331,10 @@
             }
             else {
                 char outbuf[BUFSIZ];
-                
-                ftp_message_generate(fc, dconf->readme, outbuf, 
+
+                ftp_message_generate(fc, dconf->readme, outbuf,
                                      sizeof(outbuf));
-                ftp_reply(fc, c->output_filters, r->pool, 
+                ftp_reply(fc, c->output_filters, r->pool,
                           FTP_REPLY_USER_LOGGED_IN, 1, outbuf);
             }
         }
@@ -1322,31 +1345,32 @@
     }
 
     ap_destroy_sub_req(rr);
-    
-    /* Here we return the generic FTP_REPLY_NOT_LOGGED_IN error (530),
-     * but it may have been because of a varity of reasons.  If the 
-     * return status is 401 HTTP_UNAUTHORIZED, then the username/password
-     * combination was incorrect.  If we get a HTTP_FORBIDDEN, it is
-     * likely that the access checkers failed because the location
-     * was configured with 'deny from all'.
+
+    /*
+     * Here we return the generic FTP_REPLY_NOT_LOGGED_IN error (530), but it
+     * may have been because of a varity of reasons.  If the return status is
+     * 401 HTTP_UNAUTHORIZED, then the username/password combination was
+     * incorrect.  If we get a HTTP_FORBIDDEN, it is likely that the access
+     * checkers failed because the location was configured with 'deny from
+     * all'.
      */
     if (strcmp(fc->user, "anonymous") == 0) {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0,
-                     r->server, 
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0,
+                     r->server,
                      "ANONYMOUS FTP LOGIN REFUSED FROM %s",
                      c->remote_ip);
     }
     else {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0,
-                     r->server, "FTP LOGIN REFUSED FROM %s, %s", 
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0,
+                     r->server, "FTP LOGIN REFUSED FROM %s, %s",
                      c->remote_ip, fc->user);
     }
 pass_try_again:
     if (++fc->login_attempts == fsc->max_login_attempts) {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, 
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, 0,
                      r->server, "repeated login failures from %s",
                      c->remote_ip);
-        
+
         fc->response_notes = apr_pstrdup(r->pool,
                                          "Maximum login attempts reached, "
                                          "closing connection.");
@@ -1355,8 +1379,10 @@
         return FTP_REPLY_SERVICE_NOT_AVAILABLE;
     }
 
-    /* Sleep one second for every failed login attempt.  This is
-     * a common practice among FTP servers to prevent DOS attacks */
+    /*
+     * Sleep one second for every failed login attempt.  This is a common
+     * practice among FTP servers to prevent DOS attacks
+     */
     apr_sleep(fc->login_attempts * APR_USEC_PER_SEC);
 
     fc->user = ftp_unknown_username;
@@ -1367,11 +1393,11 @@
 }
 
 static int init_pasv_socket(request_rec *r, int bindfamily,
-                            const char *bindaddr)
+                                const char *bindaddr)
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     apr_sockaddr_t *sa;
     apr_socket_t *s;
     apr_status_t rv;
@@ -1418,12 +1444,12 @@
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
-    /* XXX: should pick an arbitrary port within the acceptable range,
-     * but dodge the throttle timer on the first reloop (init tries = -1?)
+    /*
+     * XXX: should pick an arbitrary port within the acceptable range, but
+     * dodge the throttle timer on the first reloop (init tries = -1?)
      */
     port = fsc->pasv_min;
-    while (1)
-    {
+    while (1) {
         /* Magic here when port == 0, accepts an ephemeral port assignment */
         sa->port = port;
         sa->sa.sin.sin_port = htons(port);
@@ -1439,9 +1465,9 @@
             return FTP_REPLY_CANNOT_OPEN_DATACONN;
         }
 
-        /* If we are using a range, increment the port, and continue.  If
-         * we have reached the top of the range start over at the 
-         * beginning 
+        /*
+         * If we are using a range, increment the port, and continue.  If we
+         * have reached the top of the range start over at the beginning
          */
         if (port != 0) {
             if (port < fsc->pasv_max) {
@@ -1450,17 +1476,18 @@
             }
             port = fsc->pasv_min;
             /* Fall through into throttle */
-        } 
-        
-        /* Under high load we may have many sockets in TIME_WAIT, causing
-         * bind to fail with EADDRINUSE.  In these conditions we throttle
-         * the system by sleeping before we attempt to bind again within
-         * our acceptable port range
+        }
+
+        /*
+         * Under high load we may have many sockets in TIME_WAIT, causing
+         * bind to fail with EADDRINUSE.  In these conditions we throttle the
+         * system by sleeping before we attempt to bind again within our
+         * acceptable port range
          */
         ++tries;
         ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
                      "Couldn't find port within range for passive "
-                     "connection.  Restarting at %d (retry %d)", port, tries);
+                   "connection.  Restarting at %d (retry %d)", port, tries);
         apr_sleep(tries * APR_USEC_PER_SEC);
     }
 
@@ -1482,8 +1509,8 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     int res;
     apr_sockaddr_t *sa;
     const char *addr;
@@ -1498,18 +1525,18 @@
 
     ftp_reset_dataconn(fc);
 
-    /* Why don't pasv_bindaddr/bindfamily appear below?
-     * These directives provide an override which the client
-     * is informed of, while EPSV only informs the client of
-     * the port to use, not a family, and never an address.
-     * FTPEPSVIgnoreFamily should offer sufficient customization.
+    /*
+     * Why don't pasv_bindaddr/bindfamily appear below? These directives
+     * provide an override which the client is informed of, while EPSV only
+     * informs the client of the port to use, not a family, and never an
+     * address. FTPEPSVIgnoreFamily should offer sufficient customization.
      */
-    if (!*arg || ((arg[0] == '1' || arg[0] == '2') && !arg[1] 
-                      && fsc->epsv_ignore_family)) {
+    if (!*arg || ((arg[0] == '1' || arg[0] == '2') && !arg[1]
+                  && fsc->epsv_ignore_family)) {
 #if APR_HAVE_IPV6
         if (c->local_addr->family == AF_INET6 &&
-                 IN6_IS_ADDR_V4MAPPED((struct in6_addr *)
-                                      c->local_addr->ipaddr_ptr)) {
+            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;
@@ -1551,8 +1578,7 @@
             addr = c->local_ip;
             family = AF_INET6;
         }
-        else
-        {
+        else {
             return FTP_REPLY_BAD_PROTOCOL;
         }
     }
@@ -1561,14 +1587,14 @@
         return FTP_REPLY_BAD_PROTOCOL;
     }
 
-    if ( ( res = init_pasv_socket(r, family, addr) ) ) {
+    if ((res = init_pasv_socket(r, family, addr))) {
         return res;
     }
 
     apr_socket_addr_get(&sa, APR_LOCAL, fc->csock);
 
     fc->response_notes = apr_psprintf(r->pool,
-                                     "Entering Extended Passive Mode (|||%u|)",
+                                  "Entering Extended Passive Mode (|||%u|)",
                                       sa->port);
 
     return FTP_REPLY_EXTENDED_PASSIVE_MODE;
@@ -1579,14 +1605,14 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     int res;
     apr_sockaddr_t *sa;
     apr_socket_t *s;
     char *report_addr, *period;
     apr_port_t port;
-    short high, low; 
+    short high, low;
     const char *addr;
     int family;
 
@@ -1603,7 +1629,7 @@
     }
 #if APR_HAVE_IPV6
     else if (c->local_addr->family == AF_INET6 &&
-        IN6_IS_ADDR_V4MAPPED((struct in6_addr *)c->local_addr->ipaddr_ptr)) {
+      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;
@@ -1614,16 +1640,17 @@
         family = c->local_addr->family;
     }
 
-    if ( ( res = init_pasv_socket(r, family, addr) ) ) {
+    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
-     * address.  It should always be evaluated first for the benefit
-     * of servers hiding behind load balancers, vpn's, nat, etc.
+    /*
+     * pasv_addr is an ADVERTISED address, not related to the true address.
+     * It should always be evaluated first for the benefit of servers hiding
+     * behind load balancers, vpn's, nat, etc.
      */
     if (fsc->pasv_addr) {
         report_addr = apr_pstrdup(r->pool, fsc->pasv_addr);
@@ -1633,18 +1660,18 @@
     }
     else if ((c->local_addr->family == AF_INET)
 #if APR_HAVE_IPV6
-          || (c->local_addr->family == AF_INET6
-          && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)c->local_addr->ipaddr_ptr))
+             || (c->local_addr->family == AF_INET6
+                 && IN6_IS_ADDR_V4MAPPED((struct in6_addr *) c->local_addr->ipaddr_ptr))
 #endif
-             ) {
+        ) {
         /* 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,
-         * wherein clients can choose to connect back to the
-         * original, same address.  Suggested as an early solution
-         * at http://cr.yp.to/ftp/retr.html
+        /*
+         * a bogus answer, which will not be translated below, wherein
+         * clients can choose to connect back to the original, same address.
+         * Suggested as an early solution at http://cr.yp.to/ftp/retr.html
          */
         report_addr = "127,555,555,555";
     }
@@ -1656,15 +1683,15 @@
 
     port = sa->port;
     high = ((port & 0xff00) >> 8);
-    low = (port & 0x00ff); 
+    low = (port & 0x00ff);
     fc->response_notes = apr_psprintf(r->pool,
-                                     "Entering Passive Mode (%s,%u,%u)",
-                                     report_addr, high, low);
+                                      "Entering Passive Mode (%s,%u,%u)",
+                                      report_addr, high, low);
     return FTP_REPLY_PASSIVE_MODE;
 }
 
 static int ftp_cmd_pbsz(request_rec *r, const char *arg)
-{ 
+{
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     char *endp;
 
@@ -1678,8 +1705,10 @@
     }
 
     fc->pbsz = strtol(arg, &endp, 10);
-    /* Return 501 if we were unable to parse the argument or if
-     * there was a possibility of an overflow */
+    /*
+     * Return 501 if we were unable to parse the argument or if there was a
+     * possibility of an overflow
+     */
     if (((*arg == '\0') || (*endp != '\0')) || fc->pbsz < 0
         || fc->pbsz == LONG_MAX) {
         fc->response_notes = apr_pstrdup(r->pool, "Could not parse PBSZ "
@@ -1716,18 +1745,19 @@
 
     arg_tok = apr_pstrdup(fc->data_pool, arg);
     if ((res = ftp_eprt_decode(&family, &ip_addr, &port, arg_tok))
-            != FTP_REPLY_COMMAND_OK) {
+        != FTP_REPLY_COMMAND_OK) {
         fc->response_notes = apr_pstrdup(r->pool, "Invalid EPRT request");
         return res;
     }
 
 #if 0
     if ((fsc->active_min != -1) && (fsc->active_min < 1024)) {
-        /* Here's the case of low numbered port creation; the only way
-         * to accomplish this is either grant the apache user/group the
-         * right to bind to low numbered ports, or to have the parent
-         * running as root spin off socket fd's through a domain socket
-         * to all interested ftp worker processes.
+        /*
+         * Here's the case of low numbered port creation; the only way to
+         * accomplish this is either grant the apache user/group the right to
+         * bind to low numbered ports, or to have the parent running as root
+         * spin off socket fd's through a domain socket to all interested ftp
+         * worker processes.
          */
     }
 #endif
@@ -1758,8 +1788,8 @@
 
     if (fsc->active_min != -1) {
         sa->port = fsc->active_min +
-                     (apr_port_t)(rand() % (fsc->active_max -
-                                            fsc->active_min + 1));
+            (apr_port_t) (rand() % (fsc->active_max -
+                                    fsc->active_min + 1));
     }
     else {
         sa->port = 0;
@@ -1793,36 +1823,37 @@
                      1, ip_addr, port);
 #endif
         fc->response_notes = apr_pstrdup(r->pool,
-                     "Invalid EPRT command, unable to resolve request");
+                         "Invalid EPRT command, unable to resolve request");
         apr_socket_close(s);
         return FTP_REPLY_SYNTAX_ERROR;
     }
 
-    /* Open data connection only if the EPRT connection is to the client's
-     * IP address.
-     * All other EPRT connection requests are denied, unless disabled using:
-     *
-     *   FTPOptions AllowProxyPORT
-     *
-     * We must canonicalize the IP address first to compare it to our own
-     * idea of the client's IP address.
+    /*
+     * Open data connection only if the EPRT connection is to the client's IP
+     * address. All other EPRT connection requests are denied, unless
+     * disabled using:
+     * 
+     * FTPOptions AllowProxyPORT
+     * 
+     * We must canonicalize the IP address first to compare it to our own idea
+     * of the client's IP address.
      */
     if (!(fsc->options & FTP_OPT_ALLOWPROXYPORT)) {
         char *test_ip = "(unknown)";
         if (apr_sockaddr_ip_get(&test_ip, fc->clientsa) != APR_SUCCESS
-                || (strcasecmp(test_ip, c->remote_ip) != 0)) {
+            || (strcasecmp(test_ip, c->remote_ip) != 0)) {
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
                          "Rejected EPRT data connection request to %s "
                          "(doesn't match the client IP %s and "
                          "not configured to AllowProxyPORT)",
                          test_ip, c->remote_ip);
             fc->response_notes = apr_pstrdup(r->pool,
-                         "Invalid EPRT command, proxy EPRT is not permitted");
+                       "Invalid EPRT command, proxy EPRT is not permitted");
             apr_socket_close(s);
             return FTP_REPLY_SYNTAX_ERROR;
         }
     }
-    
+
     fc->response_notes = apr_psprintf(r->pool, FTP_MSG_SUCCESS, r->method);
     fc->csock = s;
     return FTP_REPLY_COMMAND_OK;
@@ -1851,7 +1882,7 @@
     if ((res = sscanf(arg, "%d,%d,%d,%d,%d,%d%c", &val[0], &val[1], &val[2],
                       &val[3], &val[4], &val[5], &tc)) != 6) {
         fc->response_notes = apr_pstrdup(r->pool, "Invalid PORT request");
-        return FTP_REPLY_SYNTAX_ERROR;   
+        return FTP_REPLY_SYNTAX_ERROR;
     }
 
     ip_addr = apr_psprintf(fc->data_pool, "%d.%d.%d.%d",
@@ -1859,10 +1890,12 @@
 
     port = ((val[4] << 8) + val[5]);
 
-    /* Open data connection only if the PORT connection is to the client's IP address.
-     * All other PORT connection requests are denied, unless disabled using:
-     *
-     *   FTPOptions AllowProxyPORT 
+    /*
+     * Open data connection only if the PORT connection is to the client's IP
+     * address. All other PORT connection requests are denied, unless
+     * disabled using:
+     * 
+     * FTPOptions AllowProxyPORT
      */
     if (!(fsc->options & FTP_OPT_ALLOWPROXYPORT)) {
         if (strcasecmp(ip_addr, c->remote_ip) != 0) {
@@ -1872,22 +1905,23 @@
                          "not configured to AllowProxyPORT)",
                          ip_addr, c->remote_ip);
             fc->response_notes = apr_pstrdup(r->pool,
-                         "Invalid PORT command, proxy PORT is not permitted");
-            return FTP_REPLY_SYNTAX_ERROR;   
+                       "Invalid PORT command, proxy PORT is not permitted");
+            return FTP_REPLY_SYNTAX_ERROR;
         }
     }
-    
+
 #if 0
     if ((fsc->active_min != -1) && (fsc->active_min < 1024)) {
-        /* Here's the case of low numbered port creation; the only way
-         * to accomplish this is either grant the apache user/group the
-         * right to bind to low numbered ports, or to have the parent
-         * running as root spin off socket fd's through a domain socket
-         * to all interested ftp worker processes.
+        /*
+         * Here's the case of low numbered port creation; the only way to
+         * accomplish this is either grant the apache user/group the right to
+         * bind to low numbered ports, or to have the parent running as root
+         * spin off socket fd's through a domain socket to all interested ftp
+         * worker processes.
          */
     }
 #endif
-        
+
 #if APR_MAJOR_VERSION < 1
     rv = apr_socket_create_ex(&s, APR_INET, SOCK_STREAM, APR_PROTO_TCP,
                               fc->data_pool);
@@ -1903,9 +1937,9 @@
     }
 
     if (fsc->active_min != -1) {
-        local_port = fsc->active_min + 
-                     (apr_port_t)(rand() % (fsc->active_max -
-                                            fsc->active_min + 1));
+        local_port = fsc->active_min +
+            (apr_port_t) (rand() % (fsc->active_max -
+                                    fsc->active_min + 1));
     }
     else {
         local_port = 0;
@@ -1913,7 +1947,7 @@
 
     if (c->local_addr->family == APR_INET) {
         rv = apr_sockaddr_info_get(&sa, c->local_ip, APR_INET,
-                                  local_port, 0, fc->data_pool);
+                                   local_port, 0, fc->data_pool);
         if (!sa || rv) {
             ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
                           "Couldn't resolve explicit local socket address"
@@ -1972,10 +2006,11 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
 
-    /* Return 503 if the user has not done a AUTH command yet.
-     * Although RFC2228 and RFC4217 are very explicit that PBSZ must
-     * preceed PROT, it's entirely worthless in the context of TLS,
-     * and not even worth enforcing.
+    /*
+     * Return 503 if the user has not done a AUTH command yet. Although
+     * RFC2228 and RFC4217 are very explicit that PBSZ must preceed PROT,
+     * it's entirely worthless in the context of TLS, and not even worth
+     * enforcing.
      */
     if (fc->auth == FTP_AUTH_NONE) {
         return FTP_REPLY_BAD_SEQUENCE;
@@ -2027,14 +2062,13 @@
 
 #if APR_MAJOR_VERSION < 1
     fc->restart_point = apr_atoi64(arg);
-    endp = (char*)arg + strspn(arg, "0123456789");
+    endp = (char *) arg + strspn(arg, "0123456789");
     if (
 #else
     apr_status_t rv = apr_strtoff(&(fc->restart_point), arg, &endp, 10);
     if ((rv != APR_SUCCESS) ||
 #endif
-        (*arg == '\0') || (*endp != '\0') || (fc->restart_point < 0))
-    {
+        (*arg == '\0') || (*endp != '\0') || (fc->restart_point < 0)) {
         fc->response_notes = apr_pstrdup(r->pool, "REST requires a "
                                          "non-negative integer value");
         return FTP_REPLY_SYNTAX_ERROR;
@@ -2045,7 +2079,7 @@
                                       "transfer.", fc->restart_point);
     return FTP_REPLY_PENDING;
 }
-    
+
 static int ftp_cmd_retr(request_rec *r, const char *arg)
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
@@ -2069,14 +2103,14 @@
      * of the transfer is determined by the ftp_transfer_ok envar
      */
     apr_table_setn(r->subprocess_env, "do_transfer_log", "1");
-    
+
     if ((res = ftp_set_uri(r, rfile))) {
         return res;
     }
 
     /* If anything fails in the subrequest, simply return permission denied */
     rr = ap_sub_req_method_uri(r->method, rfile, r, NULL);
-    if (rr->status != HTTP_OK){
+    if (rr->status != HTTP_OK) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                           rfile);
         ap_destroy_sub_req(rr);
@@ -2084,13 +2118,13 @@
     }
     ap_destroy_sub_req(rr);
 
-    ftp_reply(fc, fc->connection->output_filters, r->pool, 
+    ftp_reply(fc, fc->connection->output_filters, r->pool,
               FTP_REPLY_FILE_STATUS_OK, 0,
-              apr_pstrcat(r->pool, "Opening ", 
-                          (fc->type == TYPE_A) ? "ASCII" : "BINARY", 
+              apr_pstrcat(r->pool, "Opening ",
+                          (fc->type == TYPE_A) ? "ASCII" : "BINARY",
                           " mode data connection for ", arg, NULL));
 
-    if ( !(cdata = ftp_open_dataconn(r, 1)) ) {
+    if (!(cdata = ftp_open_dataconn(r, 1))) {
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
@@ -2099,12 +2133,12 @@
     rinput_proto = r->proto_input_filters;
     routput = r->output_filters;
     routput_proto = r->proto_output_filters;
-    
+
     r->proto_input_filters = cdata->input_filters;
     r->input_filters = r->proto_input_filters;
     r->proto_output_filters = cdata->output_filters;
     r->output_filters = r->proto_output_filters;
-    
+
     ap_add_input_filter_handle(ftp_input_filter_handle, NULL, r, r->connection);
 
     r->connection = cdata;
@@ -2125,14 +2159,16 @@
 
     rr = ap_sub_req_method_uri("GET", rfile, r, NULL);
     if (rr->status != HTTP_OK) {
-        /* Should never get here since we have already run this
-         * subrequest, but better safe than sorry */
+        /*
+         * Should never get here since we have already run this subrequest,
+         * but better safe than sorry
+         */
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                           rfile);
         res = FTP_REPLY_FILE_NOT_FOUND;
         goto clean_up;
     }
-    
+
     /* If this is a resume request, set the "Range: {start}-" header */
     if (fc->restart_point > 0) {
         apr_table_setn(rr->headers_in, "Range",
@@ -2143,9 +2179,11 @@
         rr->assbackwards = 0;
     }
 
-    /* Filter manipulation.  We remove the subrequest filter so that
-     * the EOS buckets stay in tact.  We also add the content length
-     * filter so that we can record the bytes_sent */
+    /*
+     * Filter manipulation.  We remove the subrequest filter so that the EOS
+     * buckets stay in tact.  We also add the content length filter so that
+     * we can record the bytes_sent
+     */
     for (f = rr->output_filters; f; f = f->next) {
         if (strcasecmp(f->frec->name, "SUBREQ_CORE") == 0) {
             ap_remove_output_filter(f);
@@ -2156,36 +2194,38 @@
     ap_add_output_filter_handle(ftp_content_length_filter_handle, NULL,
                                 rr, rr->connection);
 
-    if ((res = ap_run_sub_req(rr)) != OK){
+    if ((res = ap_run_sub_req(rr)) != OK) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOSUCHFILE, arg);
         res = FTP_REPLY_FILE_NOT_FOUND;
     }
 
-    else {     
+    else {
         res = FTP_REPLY_DATA_CLOSE;
     }
 
     fc->restart_point = 0;
-    fc->traffic      += rr->bytes_sent;
-    fc->bytes        += rr->bytes_sent;
-    fc->files        += 1;
-    fc->transfers    += 1;
-
-    /* We use a subrequest here in an weird way, which causes some
-     * information to be lost.  Here we hack around that by setting
-     * values in r->main, but in the future, we may just want to do
-     * away with running the subrequest, and run the main request.
-     *
+    fc->traffic += rr->bytes_sent;
+    fc->bytes += rr->bytes_sent;
+    fc->files += 1;
+    fc->transfers += 1;
+
+    /*
+     * We use a subrequest here in an weird way, which causes some
+     * information to be lost.  Here we hack around that by setting values in
+     * r->main, but in the future, we may just want to do away with running
+     * the subrequest, and run the main request.
+     * 
      * There may be other values we need to save here.
      */
     rr->main->sent_bodyct = 1;
-    
-    /* Check to make sure the connection wasnt aborted */ 
+
+    /* Check to make sure the connection wasnt aborted */
     if (rr->connection->aborted || cdata->aborted) {
         rr->main->bytes_sent = 0;
         res = FTP_REPLY_TRANSFER_ABORTED;
         rr->main->connection->aborted = 0;
-    } else {
+    }
+    else {
         rr->main->bytes_sent = rr->bytes_sent;
     }
 
@@ -2201,8 +2241,8 @@
 
     /* Close the data connection, send confirmation, and return  */
     ap_lingering_close(cdata);
-    fc->datasock     = NULL;
-    fc->filter_mask  = 0;
+    fc->datasock = NULL;
+    fc->filter_mask = 0;
 
     return res;
 }
@@ -2238,7 +2278,7 @@
     }
 
     ap_destroy_sub_req(rr);
-    
+
     return response;
 }
 
@@ -2248,7 +2288,7 @@
     apr_status_t rv;
     int response, res;
     request_rec *rr;
-    
+
     if ((res = ftp_set_uri(r, arg))) {
         fc->rename_from[0] = '\0';
         return res;
@@ -2269,9 +2309,9 @@
     if (fc->rename_from[0] == '\0') {
         return FTP_REPLY_BAD_SEQUENCE;
     }
-    
+
     rv = apr_file_rename(fc->rename_from, r->filename, r->pool);
-    
+
     if (rv != APR_SUCCESS) {
         response = FTP_REPLY_LOCAL_ERROR;
     }
@@ -2343,7 +2383,8 @@
         response = FTP_REPLY_FILE_NOT_FOUND;
     }
     else {
-        /* XXX: big bug - going back to the beginning.  We should compute
+        /*
+         * XXX: big bug - going back to the beginning.  We should compute
          * size rather than stating the file... this could be done trivially
          * with a request to a null 'data' port which simply counts up the
          * bytes.  Will be implemented as a special-case of the ftp_core_data
@@ -2360,7 +2401,8 @@
 
 static int ftp_get_client_block(conn_rec *c, ap_input_mode_t mode,
                                 apr_bucket_brigade *bb,
-                                char *buffer, apr_size_t bufsiz, apr_size_t *len)
+                                char *buffer, apr_size_t bufsiz,
+                                apr_size_t *len)
 {
     apr_size_t total;
     apr_status_t rv;
@@ -2369,14 +2411,14 @@
 
     if (APR_BRIGADE_EMPTY(bb)) {
         if ((rv = ap_get_brigade(c->input_filters, bb, mode,
-                           APR_BLOCK_READ, bufsiz)) != APR_SUCCESS) {
+                                 APR_BLOCK_READ, bufsiz)) != APR_SUCCESS) {
             apr_brigade_destroy(bb);
             return rv;
         }
     }
-    
+
     b = APR_BRIGADE_FIRST(bb);
-    if (APR_BUCKET_IS_EOS(b)) {  /* From previous invocation */
+    if (APR_BUCKET_IS_EOS(b)) { /* From previous invocation */
         apr_bucket_delete(b);
         return APR_EOF;
     }
@@ -2387,7 +2429,7 @@
            && !APR_BUCKET_IS_EOS(b)) {
         apr_size_t len_read;
         apr_bucket *old;
-        
+
         if ((rv = apr_bucket_read(b, &tempbuf, &len_read,
                                   APR_BLOCK_READ)) != APR_SUCCESS) {
             return rv;
@@ -2399,16 +2441,16 @@
         memcpy(buffer, tempbuf, len_read);
         buffer += len_read;
         total += len_read;
-        
+
         old = b;
         b = APR_BUCKET_NEXT(b);
         apr_bucket_delete(old);
     }
-    
+
     *len = total;
     return APR_SUCCESS;
 }
-          
+
 /*
  * This handles all STOR and APPE requests
  */
@@ -2439,7 +2481,7 @@
 #endif
 
     apr_table_setn(r->subprocess_env, "do_transfer_log", "1");
-    
+
     if ((res = ftp_set_uri(r, arg))) {
         return res;
     }
@@ -2460,26 +2502,28 @@
     if (creatperms == APR_OS_DEFAULT)
         creatperms = FTP_DEFAULT_UMASK;
 
-    /* In the config phase, ->creatperms was a negative umask.
-     * for operation, exchange this with a positive protections
-     * to pass to the apr_file_open protection flag.
+    /*
+     * In the config phase, ->creatperms was a negative umask. for operation,
+     * exchange this with a positive protections to pass to the apr_file_open
+     * protection flag.
      */
     creatperms = (APR_UREAD | APR_UWRITE |
-                 APR_GREAD | APR_GWRITE |
-                 APR_WREAD | APR_WWRITE)
-              & ~creatperms;
+                  APR_GREAD | APR_GWRITE |
+                  APR_WREAD | APR_WWRITE)
+        & ~creatperms;
 
 #ifdef HAVE_FCHMOD
     fixmode = ftp_unix_perms2mode(creatperms);
     creatperms = 0;
 #endif
 
-    /* For the remainder of the operation, (openflag & APR_APPEND)
-     * reflects this was an append operation and we have no need
-     * to truncate.  Presume, if not append and our restart point
-     * is zero, that open(O_TRUNC) is supported and preferable.
+    /*
+     * For the remainder of the operation, (openflag & APR_APPEND) reflects
+     * this was an append operation and we have no need to truncate.
+     * Presume, if not append and our restart point is zero, that
+     * open(O_TRUNC) is supported and preferable.
      */
-    openflag = APR_WRITE|APR_CREATE;
+    openflag = APR_WRITE | APR_CREATE;
     if (strcmp(r->method, "APPE") == 0) {
         openflag |= APR_APPEND;
     }
@@ -2500,13 +2544,13 @@
     }
 
 #ifdef HAVE_FCHMOD
-    /* If we opened an existing file, we have nothing to
-     * do later in the code (leave fd as -1).
-     * If we created the file with perms zero, grab the
-     * fd and creatperms to adjust the perms when finished.
+    /*
+     * If we opened an existing file, we have nothing to do later in the code
+     * (leave fd as -1). If we created the file with perms zero, grab the fd
+     * and creatperms to adjust the perms when finished.
      */
-    if (apr_file_info_get(&finfo, APR_FINFO_PROT, file) 
-                 != APR_SUCCESS) {
+    if (apr_file_info_get(&finfo, APR_FINFO_PROT, file)
+        != APR_SUCCESS) {
         fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
                                           "Unable to perform file upload; "
                                           "failed to get fileinfo");
@@ -2515,24 +2559,26 @@
     }
     if (finfo.protection) {
         fd = -1;
-    } 
+    }
     else {
         apr_os_file_get(&fd, file);
     }
 #endif
 
-    /* Once the file is opened, non-append/non-truncate, we need to space
-     * forward to the restart point.  Unset the restart pointer once we
-     * have grabbed it to space forward.
+    /*
+     * Once the file is opened, non-append/non-truncate, we need to space
+     * forward to the restart point.  Unset the restart pointer once we have
+     * grabbed it to space forward.
      */
     if (!(openflag & (APR_APPEND | APR_TRUNCATE))) {
         apr_off_t restart = fc->restart_point;
         if (apr_file_seek(file, APR_SET, &restart) != APR_SUCCESS) {
             fc->response_notes = apr_psprintf(r->pool, FTP_MSG_PERM_DENIED,
-                                              "Unable to perform file upload; "
-                                              "failed to skip to restart point");
+                                         "Unable to perform file upload; "
+                                         "failed to skip to restart point");
 #ifdef HAVE_FCHMOD
-            if (fd != -1) fchmod(fd, fixmode);
+            if (fd != -1)
+                fchmod(fd, fixmode);
 #endif
             fc->restart_point = 0;
             return FTP_REPLY_FILE_NOT_FOUND;
@@ -2545,39 +2591,45 @@
     ftp_reply(fc, c->output_filters, r->pool, FTP_REPLY_FILE_STATUS_OK,
               0, reply);
 
-    /* Open the data connection to the client 
+    /*
+     * Open the data connection to the client
      */
-    if ( !(cdata = ftp_open_dataconn(r, 0)) ) {
+    if (!(cdata = ftp_open_dataconn(r, 0))) {
 #ifdef HAVE_FCHMOD
-        if (fd != -1) fchmod(fd, fixmode);
+        if (fd != -1)
+            fchmod(fd, fixmode);
 #endif
         return FTP_REPLY_CANNOT_OPEN_DATACONN;
     }
 
     bb = apr_brigade_create(r->pool, c->bucket_alloc);
     buffer = apr_palloc(r->pool, AP_IOBUFSIZE);
-    
-    while ((clientstatus = ftp_get_client_block(cdata, fc->type == TYPE_A 
-                                       ? AP_MODE_GETLINE : AP_MODE_READBYTES, 
-                                       bb, buffer, AP_IOBUFSIZE, &len)) ==
-                                       APR_SUCCESS) {
+
+    while ((clientstatus = ftp_get_client_block(cdata,
+                              fc->type == TYPE_A ? AP_MODE_GETLINE : AP_MODE_READBYTES,
+                              bb, buffer, AP_IOBUFSIZE, &len)) == APR_SUCCESS) {
 #ifndef WIN32
-        /* If we are in ASCII mode, translate to our own internal form.
-         * This means CRLF for windows and plain LF for Unicies */
+        /*
+         * If we are in ASCII mode, translate to our own internal form. This
+         * means CRLF for windows and plain LF for Unicies
+         */
         if ((fc->type == TYPE_A) && (len > 0)) {
-            /* 
-             * The last read may have been incomplete if we had activity
-             * on the control connection.  Watch out for trailing CR's
-             * from the last write, and back up the file a byte if one
-             * had been written for this now-leading LF. */
+            /*
+             * The last read may have been incomplete if we had activity on
+             * the control connection.  Watch out for trailing CR's from the
+             * last write, and back up the file a byte if one had been
+             * written for this now-leading LF.
+             */
             if (seen_cr && (*buffer == APR_ASCII_LF)) {
                 apr_off_t off = -1;
                 apr_file_seek(file, APR_CUR, &off);
                 --total;
             }
 
-            /* We may reach EOF without an ending newline.  Make sure we
-             * don't truncate any important data */
+            /*
+             * We may reach EOF without an ending newline.  Make sure we
+             * don't truncate any important data
+             */
             if ((len > 1) && (*(buffer + len - 2) == APR_ASCII_CR)) {
                 *(buffer + len - 2) = APR_ASCII_LF;
                 len--;
@@ -2588,7 +2640,7 @@
             }
         }
 
-#endif /* WIN32 */
+#endif                          /* WIN32 */
 
         rv = apr_file_write(file, buffer, &len);
         if (rv != APR_SUCCESS) {
@@ -2606,29 +2658,32 @@
         total += len;
     }
 
-    if ( (clientstatus != APR_SUCCESS && !APR_STATUS_IS_EOF(clientstatus))
-         || (cdata->aborted) ) {
+    if ((clientstatus != APR_SUCCESS && !APR_STATUS_IS_EOF(clientstatus))
+        || (cdata->aborted)) {
         status = FTP_REPLY_TRANSFER_ABORTED;
         cdata->aborted = 1;
     }
 
-    fc->traffic      += total;
-    fc->bytes        += total;
-    fc->files        += 1;
-    fc->transfers    += 1;
+    fc->traffic += total;
+    fc->bytes += total;
+    fc->files += 1;
+    fc->transfers += 1;
 
     /* Keep track of bytes sent for logging purposes. */
-    r->sent_bodyct    = 1;
-    r->bytes_sent     = total;
+    r->sent_bodyct = 1;
+    r->bytes_sent = total;
 
-    /* Once we have finished this upload - we need to reset the file perms
-     * to no longer hold a lock on the uploaded file...
+    /*
+     * Once we have finished this upload - we need to reset the file perms to
+     * no longer hold a lock on the uploaded file...
      */
 #ifdef HAVE_FCHMOD
-    if (fd != -1) fchmod(fd, fixmode);
+    if (fd != -1)
+        fchmod(fd, fixmode);
 #endif
 
-    /* and truncate anything beyond the end of the most recent upload
+    /*
+     * and truncate anything beyond the end of the most recent upload
      */
     if (!(openflag & (APR_APPEND | APR_TRUNCATE))) {
         /* use apr_file_seek to do apr_file_tell's... */
@@ -2643,11 +2698,11 @@
                          "STOR resume: failed to determine current file size for truncation");
         }
         else if (totsize <= restart) {
-            ; /* noop - nothing to truncate */
+            ;                   /* noop - nothing to truncate */
         }
         else if ((rv = apr_file_trunc(file, restart)) != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
-                         "STOR resume: failed to truncate remaining file contents");
+                 "STOR resume: failed to truncate remaining file contents");
         }
     }
 
@@ -2672,7 +2727,7 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
 
-    if (*arg && !arg[1]){
+    if (*arg && !arg[1]) {
         switch (*arg) {
         case 'A':
             fc->type = TYPE_A;
@@ -2684,8 +2739,8 @@
             return FTP_REPLY_COMMAND_OK;
         case 'E':
         case 'L':
-            fc->response_notes = 
-              apr_pstrcat(r->pool, "Type ", arg, " not implemented", NULL);
+            fc->response_notes =
+                apr_pstrcat(r->pool, "Type ", arg, " not implemented", NULL);
             return FTP_REPLY_COMMAND_NOT_IMPL_PARAM;
         }
     }
@@ -2697,8 +2752,8 @@
 {
     ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
     conn_rec *c = r->connection;
-    ftp_server_config *fsc = 
-        ftp_get_module_config(r->server->module_config);
+    ftp_server_config *fsc =
+    ftp_get_module_config(r->server->module_config);
     apr_time_t prev_timeout;
     apr_status_t rv;
     char *username;
@@ -2716,16 +2771,16 @@
 
     fc->user = username = apr_pstrdup(fc->login_pool, arg);
 
-    /* Identify virtual host (user@{hostname}) for named vhost lookup,
-     * and split from user name if so configured.
+    /*
+     * Identify virtual host (user@{hostname}) for named vhost lookup, and
+     * split from user name if so configured.
      */
-    if ((hostname = ap_strchr(username, '@')) != NULL)
-    {
-        /* Toggle to the Host:-based vhost's timeout mode to process
-         * this login request
+    if ((hostname = ap_strchr(username, '@')) != NULL) {
+        /*
+         * Toggle to the Host:-based vhost's timeout mode to process this
+         * login request
          */
-        if (fsc->options & FTP_OPT_VHOST_BY_USER)
-        {
+        if (fsc->options & FTP_OPT_VHOST_BY_USER) {
             r->hostname = hostname + 1;
 
             ap_update_vhost_from_headers(r);
@@ -2739,26 +2794,27 @@
     fsc = ftp_get_module_config(r->server->module_config);
     r->per_dir_config = r->server->lookup_defaults;
 
-    /* Now that we switched virtual hosts, it's time to determine if the
+    /*
+     * Now that we switched virtual hosts, it's time to determine if the
      * username fc->user's "@{hostname}" should be discarded
-     */  
+     */
     if ((hostname != NULL) && (fsc->options & FTP_OPT_STRIP_HOSTNAME))
-         *hostname = '\0';
+        *hostname = '\0';
 
-    /* We have nominally 'logged out', and also potentially changed
-     * virtual host contexts; reset to the proper timeout_login
+    /*
+     * We have nominally 'logged out', and also potentially changed virtual
+     * host contexts; reset to the proper timeout_login
      */
     rv = apr_socket_timeout_get(fc->cntlsock, &prev_timeout);
     if (rv != APR_SUCCESS || prev_timeout != fsc->timeout_login) {
-        rv = apr_socket_timeout_set(fc->cntlsock, 
+        rv = apr_socket_timeout_set(fc->cntlsock,
                                     fsc->timeout_login * APR_USEC_PER_SEC);
         if (rv != APR_SUCCESS)
             ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, r->server,
                          "Couldn't set SO_TIMEOUT socket option");
     }
 
-    if ((fsc->options & FTP_OPT_REQUIRESSL) && !fc->is_secure)
-    {
+    if ((fsc->options & FTP_OPT_REQUIRESSL) && !fc->is_secure) {
         r->hostname = fc->host = NULL;
         fc->user = ftp_unknown_username;
         fc->authorization = NULL;
@@ -2771,11 +2827,10 @@
     }
 
     /* TODO: these should really be configurable */
-    if ((strcmp(fc->user, "anonymous") == 0) || 
-        (strncmp(fc->user, "anonymous@", 10) == 0) || 
+    if ((strcmp(fc->user, "anonymous") == 0) ||
+        (strncmp(fc->user, "anonymous@", 10) == 0) ||
         (strcmp(fc->user, "guest") == 0) ||
-        (strncmp(fc->user, "guest@", 6) == 0))
-    {
+        (strncmp(fc->user, "guest@", 6) == 0)) {
         fc->response_notes = apr_pstrdup(r->pool,
                                          "Guest login ok, type your email "
                                          "address as the password");
@@ -2786,36 +2841,38 @@
         fc->response_notes = apr_psprintf(r->pool, "Password required for %s",
                                           fc->user);
     }
-    
+
     return FTP_REPLY_USER_OK;
 }
 
-void ftp_register_core_cmds(apr_pool_t *p) {
-    
-    /* Create the FTP command hash.  All external modules will need
-     * to make sure that their register hooks callbacks are called
-     * after the FTP module
+void ftp_register_core_cmds(apr_pool_t *p)
+{
+
+    /*
+     * Create the FTP command hash.  All external modules will need to make
+     * sure that their register hooks callbacks are called after the FTP
+     * module
      */
-    
+
     FTPMethodHash = apr_hash_make(p);
-    FTPMethodPool = p; /* The config pool */
+    FTPMethodPool = p;          /* The config pool */
 
     /* Register all of our core command handlers */
 
-    ftp_hook_cmd("ABOR", ftp_cmd_abor, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE0|FTP_DATA_INTR, 
+    ftp_hook_cmd("ABOR", ftp_cmd_abor, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE0 | FTP_DATA_INTR,
                  "(abort operation)");
-    
-    ftp_hook_cmd("ACCT", NULL, FTP_HOOK_LAST,            
-                 FTP_NEED_LOGIN|FTP_TAKE0,
+
+    ftp_hook_cmd("ACCT", NULL, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE0,
                  "(specify account)");
-    
+
     ftp_hook_cmd("ALLO", NULL, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "allocate storage (vacuously)");
-    
+
     ftp_hook_cmd("APPE", ftp_cmd_stor, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> file-name");
 
     /* AUTH does not require a user to be logged in */
@@ -2824,79 +2881,79 @@
                  "<sp> mechanism-name");
 
     ftp_hook_cmd("CDUP", ftp_cmd_cdup, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE0,
+                 FTP_NEED_LOGIN | FTP_TAKE0,
                  "change to parent directory");
 
     ftp_hook_cmd("CWD", ftp_cmd_cwd, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1, 
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "[ <sp> directory-name ]");
 
     ftp_hook_cmd("DELE", ftp_cmd_dele, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> file-name");
 
     ftp_hook_cmd("EPRT", ftp_cmd_eprt, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> <d>af<d>addr<d>port<d>");
 
-    ftp_hook_cmd("EPSV", ftp_cmd_epsv, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE0|FTP_TAKE1,
+    ftp_hook_cmd("EPSV", ftp_cmd_epsv, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE0 | FTP_TAKE1,
                  "[ <sp> af|ALL ]");
 
     ftp_hook_cmd("FEAT", ftp_cmd_feat, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE0,
+                 FTP_NEED_LOGIN | FTP_TAKE0,
                  "show server features");
 
-    ftp_hook_cmd("HELP", ftp_cmd_help, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE1, 
+    ftp_hook_cmd("HELP", ftp_cmd_help, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "[ <sp> <string> ]");
 
     ftp_hook_cmd("LIST", ftp_cmd_list, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE0|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE0 | FTP_TAKE1,
                  "[ <sp> path-name ]");
 
-    ftp_hook_cmd("LPRT", NULL, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+    ftp_hook_cmd("LPRT", NULL, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> af, hal, h1, h2, h3,..., pal, p1, p2...");
 
     ftp_hook_cmd("LPSV", NULL, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE0,
+                 FTP_NEED_LOGIN | FTP_TAKE0,
                  "(set server in passive mode)");
 
-    ftp_hook_cmd("MAIL", NULL, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE0,
+    ftp_hook_cmd("MAIL", NULL, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE0,
                  "(mail to user)");
 
     ftp_hook_cmd("MDTM", ftp_cmd_mdtm, FTP_HOOK_LAST,
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> path-name");
 
-    ftp_hook_cmd("MKD", ftp_cmd_mkd, FTP_HOOK_LAST, 
-                 FTP_NEED_LOGIN|FTP_TAKE1,
+    ftp_hook_cmd("MKD", ftp_cmd_mkd, FTP_HOOK_LAST,
+                 FTP_NEED_LOGIN | FTP_TAKE1,
                  "<sp> path-name");

[... 188 lines stripped ...]


Mime
View raw message