From f11b580e2e105a3facac81ffc81659fbaeaadddc Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Wed, 2 Mar 2016 13:22:07 +0000 Subject: [PATCH] Merge r1729930, r1729931 from trunk: hostname: Test and log useragent_host per-request across various modules, including the scoreboard, expression and rewrite engines, setenvif, authz_host, access_compat, custom logging, ssl and REMOTE_HOST variables. PR55348 [William Rowe] This is the complete change set which applies cleanly to 2.4.x as well, the server/scoreboard.c will follow, which does not apply due to drift. A rather ugly patch since the code was refactored recently to exclude the simple patch for 2.4.x, illustrated below. Completes the changeset r1729930 and resolves all 2.4.19-dev corrections, but other 2.5.0-dev specific changes may still be needed on trunk. --- server/scoreboard.c (revision 1729907) +++ server/scoreboard.c (working copy) @@ -491,9 +491,8 @@ ws->conn_bytes = 0; } if (r) { - const char *client = ap_get_remote_host(c, r->per_dir_config, - REMOTE_NOLOOKUP, NULL); - if (!client || !strcmp(client, c->client_ip)) { + const char *client; + if (!(client = ap_get_useragent_host(r, REMOTE_NOLOOKUP, NULL))) { apr_cpystrn(ws->client, r->useragent_ip, sizeof(ws->client)); } else { Submitted by: wrowe Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1733282 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 5 +++++ STATUS | 11 ----------- modules/aaa/mod_access_compat.c | 6 ++---- modules/aaa/mod_authz_host.c | 5 +---- modules/arch/netware/mod_nw_ssl.c | 3 +-- modules/mappers/mod_rewrite.c | 3 +-- modules/metadata/mod_setenvif.c | 3 +-- modules/proxy/ajp_header.c | 2 +- modules/ssl/ssl_engine_vars.c | 3 +-- server/scoreboard.c | 17 ++++++++++------- server/util_expr_eval.c | 3 +-- server/util_script.c | 2 +- 12 files changed, 25 insertions(+), 38 deletions(-) diff --git a/CHANGES b/CHANGES index 49f74c70a2..d92c65a6f1 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,11 @@ Changes with Apache 2.4.19 + *) hostname: Test and log useragent_host per-request across various modules, + including the scoreboard, expression and rewrite engines, setenvif, + authz_host, access_compat, custom logging, ssl and REMOTE_HOST variables. + PR55348 [William Rowe] + *) core: Track the useragent_host per-request when mod_remoteip or similar modules track a per-request useragent_ip. Modules should be updated to inquire for ap_get_useragent_host() in place of ap_get_remote_host(). diff --git a/STATUS b/STATUS index 2dfe74ca2e..b58ebad882 100644 --- a/STATUS +++ b/STATUS @@ -112,17 +112,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) hostname: Test and log useragent_host per-request across various modules, - including the scoreboard, expression and rewrite engines, setenvif, - authz_host, access_compat, custom logging, ssl and REMOTE_HOST variables. - PR55348 [William Rowe] - Trunk version of patch: - http://svn.apache.org/r1729930 - http://svn.apache.org/r1729931 - Trunk patch r1729930 applies, modulo CHANGES - Backport patch to r1729931 is noted in the commit log message - Requires r1729929 to be applied. - +1: wrowe, ylavic, icing PATCHES PROPOSED TO BACKPORT FROM TRUNK: diff --git a/modules/aaa/mod_access_compat.c b/modules/aaa/mod_access_compat.c index 46d8da0e53..30238033c9 100644 --- a/modules/aaa/mod_access_compat.c +++ b/modules/aaa/mod_access_compat.c @@ -276,10 +276,8 @@ static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method) if (!gothost) { int remotehost_is_ip; - remotehost = ap_get_remote_host(r->connection, - r->per_dir_config, - REMOTE_DOUBLE_REV, - &remotehost_is_ip); + remotehost = ap_get_useragent_host(r, REMOTE_DOUBLE_REV, + &remotehost_is_ip); if ((remotehost == NULL) || remotehost_is_ip) { gothost = 1; diff --git a/modules/aaa/mod_authz_host.c b/modules/aaa/mod_authz_host.c index 83fc6e6c71..dc1a73e854 100644 --- a/modules/aaa/mod_authz_host.c +++ b/modules/aaa/mod_authz_host.c @@ -168,10 +168,7 @@ static authz_status host_check_authorization(request_rec *r, const char *remotehost = NULL; int remotehost_is_ip; - remotehost = ap_get_remote_host(r->connection, - r->per_dir_config, - REMOTE_DOUBLE_REV, - &remotehost_is_ip); + remotehost = ap_get_useragent_host(r, REMOTE_DOUBLE_REV, &remotehost_is_ip); if ((remotehost == NULL) || remotehost_is_ip) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01753) diff --git a/modules/arch/netware/mod_nw_ssl.c b/modules/arch/netware/mod_nw_ssl.c index 8e392a7f01..fc8af9889e 100644 --- a/modules/arch/netware/mod_nw_ssl.c +++ b/modules/arch/netware/mod_nw_ssl.c @@ -1020,8 +1020,7 @@ char *ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, else if (strcEQ(var, "REMOTE_ADDR")) result = r->useragent_ip; else if (strcEQ(var, "REMOTE_HOST")) - result = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME, NULL); + result = ap_get_useragent_host(r, REMOTE_NAME, NULL); else if (strcEQ(var, "REMOTE_IDENT")) result = ap_get_remote_logname(r); else if (strcEQ(var, "REMOTE_USER")) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 5593d82f1f..ddc2904b7f 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -443,8 +443,7 @@ static void do_rewritelog(request_rec *r, int level, char *perdir, if (!APLOG_R_IS_LEVEL(r, APLOG_DEBUG + level)) return; - rhost = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NOLOOKUP, NULL); + rhost = ap_get_useragent_host(r, REMOTE_NOLOOKUP, NULL); rname = ap_get_remote_logname(r); for (redir=0, req=r; req->prev; req = req->prev) { diff --git a/modules/metadata/mod_setenvif.c b/modules/metadata/mod_setenvif.c index db58b601f3..c56ef50318 100644 --- a/modules/metadata/mod_setenvif.c +++ b/modules/metadata/mod_setenvif.c @@ -531,8 +531,7 @@ static int match_headers(request_rec *r) val = r->connection->local_ip; break; case SPECIAL_REMOTE_HOST: - val = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME, NULL); + val = ap_get_useragent_host(r, REMOTE_NAME, NULL); break; case SPECIAL_REQUEST_URI: val = r->uri; diff --git a/modules/proxy/ajp_header.c b/modules/proxy/ajp_header.c index 74ae09ade9..67353a70e4 100644 --- a/modules/proxy/ajp_header.c +++ b/modules/proxy/ajp_header.c @@ -239,7 +239,7 @@ static apr_status_t ajp_marshal_into_msgb(ajp_msg_t *msg, num_headers = t->nelts; } - remote_host = (char *)ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_HOST, NULL); + remote_host = (char *)ap_get_useragent_host(r, REMOTE_HOST, NULL); ajp_msg_reset(msg); diff --git a/modules/ssl/ssl_engine_vars.c b/modules/ssl/ssl_engine_vars.c index a6b0d0da15..093a69bed3 100644 --- a/modules/ssl/ssl_engine_vars.c +++ b/modules/ssl/ssl_engine_vars.c @@ -221,8 +221,7 @@ char *ssl_var_lookup(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, else if (strcEQ(var, "REMOTE_ADDR")) result = r->useragent_ip; else if (strcEQ(var, "REMOTE_HOST")) - result = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME, NULL); + result = ap_get_useragent_host(r, REMOTE_NAME, NULL); else if (strcEQ(var, "REMOTE_IDENT")) result = ap_get_remote_logname(r); else if (strcEQ(var, "REMOTE_USER")) diff --git a/server/scoreboard.c b/server/scoreboard.c index 8040fc6a83..7dc6ae25a6 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -510,15 +510,18 @@ static int update_child_status_internal(int child_num, else if (r) { copy_request(ws->request, sizeof(ws->request), r); } - if (r || c) { - val = ap_get_remote_host(c, r? r->per_dir_config : NULL, - REMOTE_NOLOOKUP, NULL); - if (r && (!val || !strcmp(val, c->client_ip))) { + if (r) { + if (!(val = ap_get_useragent_host(r, REMOTE_NOLOOKUP, NULL))) apr_cpystrn(ws->client, r->useragent_ip, sizeof(ws->client)); - } - else { + else + apr_cpystrn(ws->client, val, sizeof(ws->client)); + } + else if (c) { + if (!(val = ap_get_remote_host(c, c->base_server->lookup_defaults, + REMOTE_NOLOOKUP, NULL))) + apr_cpystrn(ws->client, c->client_ip, sizeof(ws->client)); + else apr_cpystrn(ws->client, val, sizeof(ws->client)); - } } if (s) { if (c) { diff --git a/server/util_expr_eval.c b/server/util_expr_eval.c index d85706c23d..fbb3f6b94c 100644 --- a/server/util_expr_eval.c +++ b/server/util_expr_eval.c @@ -1348,8 +1348,7 @@ static const char *request_var_fn(ap_expr_eval_ctx_t *ctx, const void *data) case 3: return r->filename; case 4: - return ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME, NULL); + return ap_get_useragent_host(r, REMOTE_NAME, NULL); case 5: return ap_get_remote_logname(r); case 6: diff --git a/server/util_script.c b/server/util_script.c index 60ef39656f..c8cda24415 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -240,7 +240,7 @@ AP_DECLARE(void) ap_add_common_vars(request_rec *r) apr_table_addn(e, "SERVER_PORT", apr_psprintf(r->pool, "%u", ap_get_server_port(r))); add_unless_null(e, "REMOTE_HOST", - ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL)); + ap_get_useragent_host(r, REMOTE_HOST, NULL)); apr_table_addn(e, "REMOTE_ADDR", r->useragent_ip); apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r)); /* Apache */ apr_table_setn(e, "REQUEST_SCHEME", ap_http_scheme(r)); -- 2.50.1