proxy_ftp.c revision 7727f4c9a1ac856edd057f21c4b8dbf63c6c9eef
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/* FTP routines for Apache proxy */
#include "mod_proxy.h"
#define AUTODETECT_PWD
/*
* Decodes a '%' escaped string, and returns the number of characters
*/
static int decodeenc(char *x)
{
int i, j, ch;
if (x[0] == '\0')
return 0; /* special case for no characters */
for (i = 0, j = 0; x[i] != '\0'; i++, j++) {
/* decode it if not already done */
ch = x[i];
i += 2;
}
x[j] = ch;
}
x[j] = '\0';
return j;
}
/*
* checks an encoded ftp string for bad characters, namely, CR, LF or
* non-ascii character
*/
static int ftp_check_string(const char *x)
{
int i, ch = 0;
for (i = 0; x[i] != '\0'; i++) {
ch = x[i];
i += 2;
}
#if !APR_CHARSET_EBCDIC
#else /*APR_CHARSET_EBCDIC*/
#endif /*APR_CHARSET_EBCDIC*/
return 0;
}
return 1;
}
/*
* Canonicalise ftp URLs.
*/
{
apr_pool_t *p = r->pool;
const char *err;
/* */
url += 4;
}
else {
return DECLINED;
}
"proxy: FTP: canonicalising URL %s", url);
if (err)
return HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST;
/* now parse path/parameters args, according to rfc1738 */
/* N.B. if this isn't a true proxy request, then the URL path
* (but not query args) has already been decoded.
* This gives rise to the problem of a ; being decoded into the
* path.
*/
*(strp++) = '\0';
r->proxyreq);
return HTTP_BAD_REQUEST;
}
else
parms = "";
return HTTP_BAD_REQUEST;
if (!ftp_check_string(path))
return HTTP_BAD_REQUEST;
return HTTP_BAD_REQUEST;
}
else {
return HTTP_BAD_REQUEST;
}
}
/* now, rebuild URL */
else
sport[0] = '\0';
return OK;
}
/* we chop lines longer than 80 characters */
#define MAX_LINE_LEN 80
/*
* Reads response lines, returns both the ftp status code and
* remembers the response message in the supplied buffer
*/
{
int status;
char response[MAX_LINE_LEN];
char buff[5];
int eos;
return -1;
}
status = 0;
else
do {
return -1;
}
}
return status;
}
/* this is a filter that turns a raw ASCII directory listing into pretty HTML */
/* ideally, mod_proxy should simply send the raw directory list up the filter
* stack to mod_autoindex, which in theory should turn the raw ascii into
* pretty html along with all the bells and whistles it provides...
*
* all in good time...! :)
*/
typedef struct {
char buffer[MAX_STRING_LEN];
{
request_rec *r = f->r;
apr_pool_t *p = r->pool;
apr_bucket *e;
register int n;
if (!ctx) {
}
/* combine the stored and the new */
/* Save "scheme://site" prefix without password */
/* ... and path without query args */
/* Copy path, strip (all except the last) trailing slashes */
/* print "ftp://host/" */
"\n\n<HTML>\n<HEAD>\n<TITLE>%s%s</TITLE>\n"
"<BASE HREF=\"%s%s\">\n</HEAD>\n\n"
"<BODY>\n\n<H2>Directory of "
"<A HREF=\"/\">%s</A>/",
{
*dir = '\0';
else
++reldir;
/* print "path/" component */
*dir = '/';
}
/* If the caller has determined the current directory, and it differs */
/* from what the client requested, then show the real name */
} else {
}
/* print README */
if (readme) {
readme);
}
/* make sure page intro gets sent out */
e = apr_bucket_flush_create();
return rv;
}
}
/* loop through each line of directory */
char *filename;
int found = 0;
int eos = 0;
/* get a complete line */
/* if the buffer overruns - throw data away */
if (APR_BUCKET_IS_EOS(e)) {
eos = 1;
break;
}
return rv;
}
}
found = 1;
}
}
/* strncat works here, but apr_cpystrn does not - the last char gets chopped, dunno why */
/* apr_cpystrn(ctx->buffer+strlen(ctx->buffer), response, len);*/
}
/* EOS? jump to footer */
if (eos) {
break;
}
/* not complete? leave and try get some more */
if (!found) {
return APR_SUCCESS;
}
/* a symlink? */
do {
filename--;
} while (filename[0] != ' ');
*(filename++) = '\0';
*(link_ptr++) = '\0';
}
else if (ctx->buffer[0] == 'd' || ctx->buffer[0] == '-' || ctx->buffer[0] == 'l' || apr_isdigit(ctx->buffer[0])) {
int searchidx = 0;
int firstfile = 1;
*searchptr = '[';
*searchptr = ']';
}
*(filename++) = 0;
/* handle filenames with spaces in 'em */
firstfile = 0;
}
*(--filename) = ' ';
}
/* Special handling for '.' and '..' */
}
else {
}
}
else {
}
/* erase buffer for next time around */
e = apr_bucket_flush_create();
return rv;
}
}
e = apr_bucket_flush_create();
e = apr_bucket_eos_create();
return rv;
}
}
return APR_SUCCESS;
}
/* Common routine for failed authorization (i.e., missing or wrong password)
* to an ftp service. This causes most browsers to retry the request
* with username and password (which was presumably queried from the user)
* supplied in the Authorization: header.
* Note that we "invent" a realm name which consists of the
* ftp://user@host part of the reqest (sans password -if supplied but invalid-)
*/
{
r->proxyreq = PROXYREQ_NONE;
/* Log failed requests if they supplied a password
*/
if (log_it)
"proxy: missing or failed auth to %s",
apr_uri_unparse(r->pool,
&r->parsed_uri, APR_URI_UNP_OMITPATHINFO));
"\"", NULL));
return HTTP_UNAUTHORIZED;
}
/*
* Handles direct access of ftp:// URLs
* Original (Non-PASV) version from
* Troy Morrison <spiffnet@zoom.com>
* PASV added by Chuck
* Filters by [Graham Leggett <minfrin@sharp.fm>]
*/
{
apr_pool_t *p = r->pool;
conn_rec *c = r->connection;
int err;
apr_bucket *e;
char *buf, *connectname;
char buffer[MAX_STRING_LEN];
/* char *account = NULL; how to supply an account in a URL? */
int one = 1;
/* stuff for PASV mode */
char dates[AP_RFC822_DATE_LEN];
/* is this for us? */
if (proxyhost) {
return DECLINED; /* proxy connections are via HTTP */
}
"proxy: FTP: rejecting URL %s - not ftp:", url);
return DECLINED; /* only interested in FTP */
}
"proxy: FTP: serving URL %s", url);
/* create space for state information */
if (!backend) {
}
/*
* I: Who Do I Connect To?
* -----------------------
*
* Break up the URL to determine the host to connect to
*/
/* we only support GET and HEAD */
if (r->method_number != M_GET)
return HTTP_NOT_IMPLEMENTED;
/* We break the URL into host, port, path-search */
? r->parsed_uri.port
: apr_uri_default_port_for_scheme("ftp");
*(parms++) = '\0';
/* The "Authorization:" header must be checked first.
* We allow the user to "override" the URL-coded user [ & password ]
* in the Browsers' User&Password Dialog.
* NOTE that this is only marginally more secure than having the
* password travel in plain as part of the URL, because Basic Auth
* simply uuencodes the plain text password.
* But chances are still smaller that the URL is logged regularly.
*/
/* Note that this allocation has to be made from r->connection->pool
* because it has the lifetime of the connection. The other allocations
* are temporary and can be tossed away any time.
*/
r->ap_auth_type = "Basic";
}
}
}
else {
user = "anonymous";
password = "apache-proxy@";
}
/* do a DNS lookup for the destination host */
/* check if ProxyBlock directive on this host */
return ap_proxyerror(r, HTTP_FORBIDDEN,
"Connect to remote machine blocked");
}
/*
* II: Make the Connection
* -----------------------
*
* We have determined who to connect to. Now make the connection.
*/
/* get all the possible IP addresses for the destname and loop through them
* until we get a successful connection
*/
if (APR_SUCCESS != err) {
"DNS lookup failure for: ",
connectname, NULL));
}
"proxy: FTP: error creating socket");
return HTTP_INTERNAL_SERVER_ERROR;
}
if (conf->recv_buffer_size > 0
conf->recv_buffer_size))) {
"setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
}
#endif
#ifndef _OSD_POSIX /* BS2000 has this option "always on" */
"proxy: FTP: error setting reuseaddr option: setsockopt(SO_REUSEADDR)");
return HTTP_INTERNAL_SERVER_ERROR;
#endif /*_OSD_POSIX*/
}
/* Set a timeout on the socket */
"proxy: FTP: socket has been created");
/*
* At this point we have a list of one or more IP addresses of
* the machine to connect to. If configured, reorder this
* list so that the "best candidate" is first try. "best
* candidate" could mean the least loaded server, the fastest
* responding server, whatever.
*
* For now we do nothing, ie we get DNS round robin.
* XXX FIXME
*/
/* try each IP address until we connect successfully */
{
int failed = 1;
while (connect_addr) {
/* make the connection out of the socket */
/* if an error occurred, loop round and try again */
if (rv != APR_SUCCESS) {
continue;
}
/* if we get here, all is well */
failed = 0;
break;
}
/* handle a permanent error from the above loop */
if (failed) {
"Could not connect to remote machine: %s port %d",
}
}
/* the socket is now open, create a new connection */
if (!origin) {
/* the peer reset the connection already; ap_new_connection()
* closed the socket */
return HTTP_INTERNAL_SERVER_ERROR;
}
/* if a keepalive connection is floating around, close it first! */
/* we might support ftp keepalives later, but not now... */
if (backend->connection) {
}
"proxy: FTP: control connection complete");
/*
* III: Send Control Request
* -------------------------
*
* Log into the ftp server, send the username & password, change to the correct
* directory...
*/
/* set up the connection filters */
/* possible results: */
/* 120 Service ready in nnn minutes. */
/* 220 Service ready for new user. */
/* 421 Service not available, closing control connection. */
if (rc == -1) {
}
if (rc == 120) {
/* RFC2616 states:
* 14.37 Retry-After
*
* The Retry-After response-header field can be used with a 503 (Service
* Unavailable) response to indicate how long the service is expected to
* be unavailable to the requesting client. [...] The value of this field
* can be either an HTTP-date or an integer number of seconds (in decimal)
* after the time of the response.
* Retry-After = "Retry-After" ":" ( HTTP-date | delta-seconds )
*/
if (buffer[i]) {
}
}
if (rc != 220) {
}
"proxy: FTP: connected.");
e = apr_bucket_flush_create();
"proxy: FTP: USER %s", user);
/* possible results; 230, 331, 332, 421, 500, 501, 530 */
/* states: 1 - error, 2 - success; 3 - send password, 4,5 fail */
/* 230 User logged in, proceed. */
/* 331 User name okay, need password. */
/* 332 Need account for login. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* (This may include errors such as command line too long.) */
/* 501 Syntax error in parameters or arguments. */
/* 530 Not logged in. */
if (rc == -1) {
}
if (rc == 530) {
}
}
return ftp_unauthorized (r, 0);
}
e = apr_bucket_flush_create();
"proxy: FTP: PASS %s", password);
/* possible results 202, 230, 332, 421, 500, 501, 503, 530 */
/* 230 User logged in, proceed. */
/* 332 Need account for login. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 503 Bad sequence of commands. */
/* 530 Not logged in. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 332) {
return ap_proxyerror(r, HTTP_UNAUTHORIZED,
}
/* @@@ questionable -- we might as well return a 403 Forbidden here */
if (rc == 530) {
}
}
}
/* set the directory (walk directory component by component):
* this is what we must do if we don't know the OS type of the remote
* machine
*/
for (;;) {
break;
*strp = '\0';
e = apr_bucket_flush_create();
"proxy: FTP: CWD %s", path);
*strp = '/';
/* responses: 250, 421, 500, 501, 502, 530, 550 */
/* 250 Requested file action okay, completed. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
/* 550 Requested action not taken. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
}
if (rc != 250) {
}
}
parms = "A";
}
else {
parms = "I";
}
/* changed to make binary transfers the default */
/* set type to binary */
e = apr_bucket_flush_create();
"proxy: FTP: TYPE I");
/* responses: 200, 421, 500, 501, 504, 530 */
/* 200 Command okay. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 504 Command not implemented for that parameter. */
/* 530 Not logged in. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
}
/* Allow not implemented */
if (rc == 504) {
parms[0] = '\0';
}
/*
* IV: Make Data Connection?
* -------------------------
*
* Try EPSV, if that fails...
* try PASV, if that fails...
* try PORT.
*/
/*goto bypass;*/
/* set up data connection - EPSV */
{
char *remote_ip;
/* The EPSV command replaces PASV where both IPV4 and IPV6 is supported. Only
* the port is returned, the IP address is always the same as that on the
* control connection. Example:
* Entering Extended Passive Mode (|||6446|)
*/
e = apr_bucket_flush_create();
"proxy: FTP: EPSV");
/* possible results: 227, 421, 500, 501, 502, 530 */
/* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
}
else if (rc == 229) {
char *pstr;
char *tok_cntx;
}
else {
}
}
if (pstr) {
"proxy: FTP: EPSV contacting remote host on port %d",
"proxy: FTP: error creating EPSV socket");
return HTTP_INTERNAL_SERVER_ERROR;
}
conf->recv_buffer_size))) {
"proxy: FTP: setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
}
#endif
/* make the connection */
if (rv != APR_SUCCESS) {
}
else {
connect = 1;
}
}
else {
/* and try the regular way */
}
}
}
/* set up data connection - PASV */
if (!connect) {
e = apr_bucket_flush_create();
"proxy: FTP: PASV");
/* possible results: 227, 421, 500, 501, 502, 530 */
/* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
}
else if (rc == 227) {
char *pstr;
char *tok_cntx;
/* FIXME: Check PASV against RFC1123 */
}
else {
}
}
/* FIXME: Only supports IPV4 - fix in RFC2428 */
"proxy: FTP: PASV contacting host %d.%d.%d.%d:%d",
"proxy: error creating PASV socket");
return HTTP_INTERNAL_SERVER_ERROR;
}
conf->recv_buffer_size))) {
"proxy: FTP: setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
}
#endif
/* make the connection */
apr_sockaddr_info_get(&pasv_addr, apr_psprintf(p, "%d.%d.%d.%d", h3, h2, h1, h0), APR_INET, pasvport, 0, p);
if (rv != APR_SUCCESS) {
}
else {
connect = 1;
}
}
else {
/* and try the regular way */
}
}
}
/*bypass:*/
/* set up data connection - PORT */
if (!connect) {
char *local_ip;
"proxy: FTP: error creating local socket");
return HTTP_INTERNAL_SERVER_ERROR;
}
#ifndef _OSD_POSIX /* BS2000 has this option "always on" */
"proxy: FTP: error setting reuseaddr option");
return HTTP_INTERNAL_SERVER_ERROR;
#endif /*_OSD_POSIX*/
}
"proxy: FTP: error binding to ftp data socket %pI", local_addr);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* only need a short queue */
"proxy: FTP: error listening to ftp data socket %pI", local_addr);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* FIXME: Sent PORT here */
e = apr_bucket_flush_create();
/* possible results: 200, 421, 500, 501, 502, 530 */
/* 200 Command okay. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc != 200) {
}
use_port = 1;
}
else {
/* IPV6 FIXME:
* The EPRT command replaces PORT where both IPV4 and IPV6 is supported. The first
* number (1,2) indicates the protocol type. Examples:
* EPRT |1|132.235.1.2|6275|
* EPRT |2|1080::8:800:200C:417A|5282|
*/
return ap_proxyerror(r, HTTP_NOT_IMPLEMENTED, "Connect to IPV6 ftp server using EPRT not supported. Enable EPSV.");
}
}
/*
* V: Set The Headers
* -------------------
*
* Get the size of the request, set up the environment for HTTP.
*/
/* set request; "path" holds last path component */
/* TM - if len == 0 then it must be a directory (you can't RETR nothing) */
if (len == 0) {
parms = "d";
}
else {
e = apr_bucket_flush_create();
"proxy: FTP: SIZE %s", path);
"proxy: FTP: SIZE shows this is a directory");
parms = "d";
e = apr_bucket_flush_create();
"proxy: FTP: CWD %s", path);
/* possible results: 250, 421, 500, 501, 502, 530, 550 */
/* 250 Requested file action okay, completed. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
/* 550 Requested action not taken. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
}
if (rc != 250) {
}
path = "";
len = 0;
}
else if (i == 213) { /* Size command ok */
buffer[j] = '\0';
if (buffer[0] != '\0')
}
}
}
#ifdef AUTODETECT_PWD
e = apr_bucket_flush_create();
"proxy: FTP: PWD");
/* responses: 257, 500, 501, 502, 421, 550 */
/* 257 "<directory-name>" <commentary> */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 550 Requested action not taken. */
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
}
if (rc == 257) {
}
#endif /*AUTODETECT_PWD*/
if (parms[0] == 'd') {
if (len != 0)
else
}
else {
/* FIXME: Handle range requests - send REST */
"proxy: FTP: RETR %s", path);
}
e = apr_bucket_flush_create();
/* RETR: 110, 125, 150, 226, 250, 421, 425, 426, 450, 451, 500, 501, 530, 550
* NLST: 125, 150, 226, 250, 421, 425, 426, 450, 451, 500, 501, 502, 530 */
/* 110 Restart marker reply. */
/* 125 Data connection already open; transfer starting. */
/* 150 File status okay; about to open data connection. */
/* 226 Closing data connection. */
/* 250 Requested file action okay, completed. */
/* 421 Service not available, closing control connection. */
/* 425 Can't open data connection. */
/* 426 Connection closed; transfer aborted. */
/* 450 Requested file action not taken. */
/* 451 Requested action aborted. Local error in processing. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 530 Not logged in. */
/* 550 Requested action not taken. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
"proxy: FTP: RETR failed, trying LIST instead");
parms = "d";
e = apr_bucket_flush_create();
"proxy: FTP: CWD %s", path);
/* possible results: 250, 421, 500, 501, 502, 530, 550 */
/* 250 Requested file action okay, completed. */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 530 Not logged in. */
/* 550 Requested action not taken. */
if (rc == -1) {
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
}
if (rc != 250) {
}
#ifdef AUTODETECT_PWD
e = apr_bucket_flush_create();
"proxy: FTP: PWD");
/* responses: 257, 500, 501, 502, 421, 550 */
/* 257 "<directory-name>" <commentary> */
/* 421 Service not available, closing control connection. */
/* 500 Syntax error, command unrecognized. */
/* 501 Syntax error in parameters or arguments. */
/* 502 Command not implemented. */
/* 550 Requested action not taken. */
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
if (rc == 550) {
}
if (rc == 257) {
}
#endif /*AUTODETECT_PWD*/
e = apr_bucket_flush_create();
"proxy: FTP: LIST -lag");
if (rc == -1)
return ap_proxyerror(r, HTTP_BAD_GATEWAY,
"Error reading from remote server");
}
}
r->status_line = "200 OK";
/* set content-type */
if (parms[0] == 'd') {
r->content_type = "text/html";
}
else {
if (r->content_type) {
"proxy: FTP: Content-Type set to %s", r->content_type);
}
else {
r->content_type = ap_default_type(r);
}
/* We "trust" the ftp server to really serve (size) bytes... */
"proxy: FTP: Content-Length set to %s", size);
}
}
"proxy: FTP: Content-Type set to %s", r->content_type);
/* set content-encoding */
"proxy: FTP: Content-Encoding set to %s", r->content_encoding);
}
/* wait for connection */
if (use_port) {
for(;;)
{
continue;
}
else if (rv == APR_SUCCESS) {
break;
}
else {
"proxy: FTP: failed to accept data connection");
return HTTP_BAD_GATEWAY;
}
}
}
/* the transfer socket is now open, create a new connection */
remote = ap_run_create_connection(p, r->server, remote_sock, r->connection->id, r->connection->sbh);
if (!remote) {
/* the peer reset the connection already; ap_new_connection()
* closed the socket */
"proxy: FTP: an error occurred creating the transfer connection");
return HTTP_INTERNAL_SERVER_ERROR;
}
/* set up the connection filters */
/*
* VI: Receive the Response
* ------------------------
*
* Get response from the remote ftp socket, and pass it up the
* filter chain.
*/
/* send response */
r->sent_bodyct = 1;
if (parms[0] == 'd') {
/* insert directory filter */
}
/* send body */
if (!r->header_only) {
"proxy: FTP: start body send");
/* read the body, pass it to the output filters */
APR_BLOCK_READ, 0) == APR_SUCCESS) {
break;
}
/* Ack! Phbtt! Die! User aborted! */
break;
}
}
}
"proxy: FTP: Closing Data connection.");
"proxy: FTP: end body send");
/*
* VII: Clean Up
* -------------
*
* If there are no KeepAlives, or if the connection has been signalled
* to close, close the socket and clean up
*/
/* finish */
e = apr_bucket_flush_create();
"proxy: FTP: QUIT");
/* responses: 221, 500 */
/* 221 Service closing control connection. */
/* 500 Syntax error, command unrecognized. */
return OK;
}
static void ap_proxy_ftp_register_hook(apr_pool_t *p)
{
/* hooks */
/* filters */
}
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
NULL, /* command apr_table_t */
ap_proxy_ftp_register_hook /* register hooks */
};