From 7a742e7fd1fbcb6875ac7614115006e90f4c91e8 Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Fri, 6 Apr 2001 14:25:54 +0000 Subject: [PATCH] Bugfixes to proxy_ftp.c -> in some places uri_addr was used instead of connect_addr - all hail cut and paste! PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88740 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/mod_proxy.c | 6 +----- modules/proxy/mod_proxy.h | 2 +- modules/proxy/proxy_ftp.c | 32 ++++++++++++++++++++------------ modules/proxy/proxy_http.c | 12 +++--------- modules/proxy/proxy_util.c | 8 ++++---- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index b95e787467..f780db3239 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -203,10 +203,8 @@ static int proxy_fixup(request_rec *r) /* canonicalise each specific scheme */ if (strncasecmp(url, "http:", 5) == 0) return ap_proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT); -#if FTP else if (strncasecmp(url, "ftp:", 4) == 0) return ap_proxy_ftp_canon(r, url + 4); -#endif p = strchr(url, ':'); if (p == NULL || p == url) @@ -387,10 +385,8 @@ static int proxy_handler(request_rec *r) return ap_proxy_connect_handler(r, url, NULL, 0); if (strcasecmp(scheme, "http") == 0) return ap_proxy_http_handler(r, url, NULL, 0); -#if FTP if (strcasecmp(scheme, "ftp") == 0) return ap_proxy_ftp_handler(r, url); -#endif else { ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server, "Neither CONNECT, HTTP or FTP for %s", @@ -721,7 +717,7 @@ static void register_hooks(apr_pool_t *p) ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST); /* filename-to-URI translation */ ap_hook_translate_name(proxy_trans, NULL, NULL, APR_HOOK_FIRST); -#ifdef FTP +#ifdef FTP_FILTER /* filters */ ap_register_output_filter("PROXY_SEND_DIR", ap_proxy_send_dir_filter, AP_FTYPE_CONNECTION); #endif diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 1435a2982d..93d5bd8c1e 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -259,6 +259,6 @@ int ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p); int ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p); int ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p); int ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr); -int ap_proxy_pre_http_connection(conn_rec *c); +int ap_proxy_pre_http_connection(conn_rec *c, request_rec *r); #endif /*MOD_PROXY_H*/ diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index a172ab4981..37cec42eef 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -198,12 +198,18 @@ static int ftp_getrc_msg(conn_rec *c, char *msgbuf, int msglen) apr_bucket *e; apr_bucket_brigade *bb = apr_brigade_create(c->pool); + bb = apr_brigade_create(c->pool); /* Tell http_filter to grab the data one line at a time. */ c->remain = 0; ap_get_brigade(c->input_filters, bb, AP_MODE_BLOCKING); + +/* FIXME: When reading the initial server response to the connect, there + * is a hang at this point... + */ + e = APR_BRIGADE_FIRST(bb); apr_bucket_read(e, (const char **)&response, &len, APR_BLOCK_READ); if (len == -1) { @@ -434,7 +440,7 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) { apr_pool_t *p = r->pool; apr_socket_t *sock, *local_sock, *remote_sock; - apr_sockaddr_t *uri_addr, *connect_addr; + apr_sockaddr_t *connect_addr; conn_rec *origin, *remote; int err; apr_bucket *e; @@ -442,7 +448,6 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) char *buf, *pasv, *connectname; apr_port_t connectport; char buffer[MAX_STRING_LEN]; - char *path, *strp, *parms; char *cwd = NULL; char *user = NULL; @@ -522,15 +527,14 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) "proxy: FTP connecting %s to %s:%d", url, connectname, connectport); /* do a DNS lookup for the destination host */ - err = apr_sockaddr_info_get(&uri_addr, connectname, APR_UNSPEC, connectport, 0, p); + err = apr_sockaddr_info_get(&connect_addr, connectname, APR_UNSPEC, connectport, 0, p); /* check if ProxyBlock directive on this host */ - if (OK != ap_proxy_checkproxyblock(r, conf, uri_addr)) { + if (OK != ap_proxy_checkproxyblock(r, conf, connect_addr)) { return ap_proxyerror(r, HTTP_FORBIDDEN, "Connect to remote machine blocked"); } -//return HTTP_NOT_IMPLEMENTED; /* * II: Make the Connection @@ -548,6 +552,7 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) connectname, NULL)); } + if ((apr_socket_create(&sock, APR_INET, SOCK_STREAM, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "proxy: error creating socket"); @@ -612,9 +617,9 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) /* handle a permanent error from the above loop */ if (failed) { apr_socket_close(sock); - return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_pstrcat(r->pool, - "Could not connect to remote machine: ", - r->parsed_uri.hostname, NULL)); + return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_psprintf(r->pool, + "Could not connect to remote machine: %s port %d", + connectname, connectport)); } } @@ -653,19 +658,20 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) */ /* set up the connection filters */ - ap_proxy_pre_http_connection(origin); + ap_proxy_pre_http_connection(origin, NULL); /* possible results: */ /* 120 Service ready in nnn minutes. */ /* 220 Service ready for new user. */ /* 421 Service not available, closing control connection. */ i = ftp_getrc_msg(origin, buffer, sizeof(buffer)); - ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL, - "FTP: initial connect returned status %d", i); + ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server, + "FTP: initial connect returned status %d", i); if (i == -1) { return ap_proxyerror(r, HTTP_BAD_GATEWAY, "Error reading from remote server"); } +return HTTP_NOT_IMPLEMENTED; #if 0 if (i == 120) { /* RFC2068 states: @@ -1319,7 +1325,7 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) } /* set up the connection filters */ - ap_proxy_pre_http_connection(remote); + ap_proxy_pre_http_connection(remote, NULL); /* @@ -1333,10 +1339,12 @@ int ap_proxy_ftp_handler(request_rec *r, char *url) /* send response */ r->sent_bodyct = 1; +#ifdef FTP_FILTER if (parms[0] == 'd') { /* insert directory filter */ ap_add_output_filter("PROXY_SEND_DIR", NULL, r, r->connection); } +#endif /* send body */ if (!r->header_only) { diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index 36bd77d164..d08f77a8cc 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -369,9 +369,8 @@ int ap_proxy_http_handler(request_rec *r, char *url, return HTTP_INTERNAL_SERVER_ERROR; } conf->id = r->connection->id; - /* allocate this out of the connection pool - the check on r->connection->id makes - * sure that this string does not live past the connection lifetime */ - conf->connectname = apr_pstrdup(r->connection->pool, connectname); + /* allocate this out of the config pool */ + conf->connectname = apr_pstrdup(r->server->process->pconf, connectname); conf->connectport = connectport; conf->client_socket = sock; @@ -387,7 +386,7 @@ int ap_proxy_http_handler(request_rec *r, char *url, */ /* set up the connection filters */ - ap_proxy_pre_http_connection(origin); + ap_proxy_pre_http_connection(origin, NULL); /* strip connection listed hop-by-hop headers from the request */ /* even though in theory a connection: close coming from the client @@ -555,10 +554,6 @@ int ap_proxy_http_handler(request_rec *r, char *url, ap_get_brigade(origin->input_filters, bb, AP_MODE_BLOCKING); e = APR_BRIGADE_FIRST(bb); - /* XXX FIXME: a bug exists where apr_bucket_read() is returning - * len=0 when the response line is expected... we try it up to - * 5 times - this has not fixed the problem though. - */ i = 5; len = 0; while (!len && i--) { @@ -678,7 +673,6 @@ int ap_proxy_http_handler(request_rec *r, char *url, APR_BRIGADE_INSERT_TAIL(bb, e); } -/* XXX FIXME - what about 304 et al responses that have no body and no content-length? */ /* send body */ if (!r->header_only) { const char *buf; diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 2a87f98d6b..e4b02fd410 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1073,11 +1073,11 @@ int ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, } /* set up the minimal filter set */ -int ap_proxy_pre_http_connection(conn_rec *c) +int ap_proxy_pre_http_connection(conn_rec *c, request_rec *r) { - ap_add_input_filter("HTTP_IN", NULL, NULL, c); - ap_add_input_filter("CORE_IN", NULL, NULL, c); - ap_add_output_filter("CORE", NULL, NULL, c); + ap_add_input_filter("HTTP_IN", NULL, r, c); + ap_add_input_filter("CORE_IN", NULL, r, c); + ap_add_output_filter("CORE", NULL, r, c); return OK; } -- 2.50.1