From: Guenter Knauf Date: Fri, 23 Jul 2010 04:04:29 +0000 (+0000) Subject: Applied accepted backport 164538. X-Git-Tag: 2.0.64~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22862d9d29f5adfd911798c8b805a119d97f43c9;p=thirdparty%2Fapache%2Fhttpd.git Applied accepted backport 164538. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.0.x@966953 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/STATUS b/STATUS index 95d071875f1..1e9e1ce4648 100644 --- a/STATUS +++ b/STATUS @@ -118,13 +118,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * Backport 164538: add ap_vhost_iterate_given_conn(). - Trunk version of patch: - http://svn.apache.org/viewvc?view=rev&revision=164538 - Backport version for 2.0.x of patch: - http://people.apache.org/~fuankg/diffs/httpd-2.0.x-ap_vhost_iterate_given_conn.diff - +1: fuankg, wrowe, pgollucci - * core output filter, CVE-2009-1891, consuming CPU after client disconnects Patch in 2.2.x branch: http://svn.apache.org/viewvc?view=revision&revision=791454 diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 8ba7f5c4f41..a370480316a 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -87,6 +87,7 @@ * 20020903.11 (2.0.55-dev) added trace_enable to core_server_config * 20020903.12 (2.0.56-dev) added ap_get_server_revision / ap_version_t * 20020903.13 (2.0.62-dev) Add *ftp_directory_charset to proxy_dir_conf + * 20020903.14 (2.0.64-dev) added ap_vhost_iterate_given_conn */ #define MODULE_MAGIC_COOKIE 0x41503230UL /* "AP20" */ @@ -94,7 +95,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20020903 #endif -#define MODULE_MAGIC_NUMBER_MINOR 13 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 14 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/http_vhost.h b/include/http_vhost.h index c3745f9a662..1acfd95f3b8 100644 --- a/include/http_vhost.h +++ b/include/http_vhost.h @@ -52,6 +52,30 @@ const char *ap_parse_vhost_addrs(apr_pool_t *p, const char *hostname, server_rec const char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, const char *arg); +/** + * Callback function for every Name Based Virtual Host. + * @param baton Opaque user object + * @param conn The current Connection + * @param s The current Server + * @see ap_vhost_iterate_given_conn + * @return 0 on success, any non-zero return will stop the iteration. + */ +typedef int(*ap_vhost_iterate_conn_cb)(void* baton, conn_rec* conn, server_rec* s); + +/** + * For every virtual host on this connection, call func_cb. + * @param conn The current connection + * @param func_cb Function called for every Name Based Virtual Host for this + * connection. + * @param baton Opaque object passed to func_cb. + * @return The return value from func_cb. + * @note If func_cb returns non-zero, the function will return at this point, + * and not continue iterating the virtual hosts. + */ +AP_DECLARE(int) ap_vhost_iterate_given_conn(conn_rec *conn, + ap_vhost_iterate_conn_cb func_cb, + void* baton); + /** * given an ip address only, give our best guess as to what vhost it is * @param conn The current connection diff --git a/server/vhost.c b/server/vhost.c index e1b4deed170..edab75a5c78 100644 --- a/server/vhost.c +++ b/server/vhost.c @@ -984,6 +984,57 @@ AP_DECLARE(void) ap_update_vhost_from_headers(request_rec *r) } +/** + * For every virtual host on this connection, call func_cb. + */ +AP_DECLARE(int) ap_vhost_iterate_given_conn(conn_rec *conn, + ap_vhost_iterate_conn_cb func_cb, + void* baton) +{ + server_rec *s; + server_rec *last_s; + name_chain *src; + apr_port_t port; + int rv = 0; + + if (conn->vhost_lookup_data) { + last_s = NULL; + port = conn->local_addr->port; + + for (src = conn->vhost_lookup_data; src; src = src->next) { + server_addr_rec *sar; + + /* We only consider addresses on the name_chain which have a + * matching port. + */ + sar = src->sar; + if (sar->host_port != 0 && port != sar->host_port) { + continue; + } + + s = src->server; + + if (s == last_s) { + /* we've already done a callback for this vhost. */ + continue; + } + + last_s = s; + + rv = func_cb(baton, conn, s); + + if (rv != 0) { + break; + } + } + } + else { + rv = func_cb(baton, conn, conn->base_server); + } + + return rv; +} + /* Called for a new connection which has a known local_addr. Note that the * new connection is assumed to have conn->server == main server. */