Commit adda6f6f authored by Jim Jagielski's avatar Jim Jagielski
Browse files

Merge r1729929 from trunk:

Introduce an ap_get_useragent_host() accessor to replace the old
ap_get_remote_host() in most applications, but preserve the original
behavior for all ap_get_remote_host() consumers (mostly, because we
don't have the request_rec in the first place, and also to avoid any
unintended consequences).

This accessor continues to store the remote_host of connection based
uesr agents within the conn_rec for optimization.  Only where some
other module modifies the useragent_addr will we perform a per-request
query of the remote_host.

(Fixed compilation issues noted by Ranier, applies to 2.4.x trunk,
modulo CHANGES and ap_mmn.h)


Submitted by: wrowe
Reviewed/backported by: jim


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1733281 13f79535-47bb-0310-9956-ffa450edef68
parent 1252b46f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@

Changes with Apache 2.4.19

  *) 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().
     [William Rowe]

  *) core: fix a bug in <UnDefine ...> directive processing. When used, the last
     <Define...>'ed variable was also withdrawn. PR 59019
     [Christophe Jaillet]
+0 −9
Original line number Diff line number Diff line
@@ -112,15 +112,6 @@ RELEASE SHOWSTOPPERS:
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
  [ start all new proposals below, under PATCHES PROPOSED. ]

  *) 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().
     Trunk version of patch:
         http://svn.apache.org/r1729929
     Trunk patch to core.c/http_core.h applies, modulo CHANGES & ap_mmn.h
     Note: httpd.h comment r.e. realiging bit fields must be omitted.
     +1: wrowe, ylavic, icing

  *) 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.
+3 −1
Original line number Diff line number Diff line
@@ -465,6 +465,8 @@
 *                          add protocol to worker_score in scoreboard.h,
 *                          Add pre_close connection hook and 
 *                          ap_prep_lingering_close().
 * 20120211.56 (2.4.19-dev) Split useragent_host from the conn_rec into
 *                          the request_rec, with ap_get_useragent_host()
 */

#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -472,7 +474,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20120211
#endif
#define MODULE_MAGIC_NUMBER_MINOR 55                   /* 0...n */
#define MODULE_MAGIC_NUMBER_MINOR 56                   /* 0...n */

/**
 * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
+27 −1
Original line number Diff line number Diff line
@@ -158,6 +158,32 @@ AP_DECLARE(int) ap_allow_overrides(request_rec *r);
 */
AP_DECLARE(const char *) ap_document_root(request_rec *r);

/**
 * Lookup the remote user agent's DNS name or IP address
 * @ingroup get_remote_hostname
 * @param req The current request
 * @param type The type of lookup to perform.  One of:
 * <pre>
 *     REMOTE_HOST returns the hostname, or NULL if the hostname
 *                 lookup fails.  It will force a DNS lookup according to the
 *                 HostnameLookups setting.
 *     REMOTE_NAME returns the hostname, or the dotted quad if the
 *                 hostname lookup fails.  It will force a DNS lookup according
 *                 to the HostnameLookups setting.
 *     REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
 *                     never forced.
 *     REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
 *                   a double reverse lookup, regardless of the HostnameLookups
 *                   setting.  The result is the (double reverse checked)
 *                   hostname, or NULL if any of the lookups fail.
 * </pre>
 * @param str_is_ip unless NULL is passed, this will be set to non-zero on
 *        output when an IP address string is returned
 * @return The remote hostname (based on the request useragent_ip)
 */
AP_DECLARE(const char *) ap_get_useragent_host(request_rec *req, int type,
                                               int *str_is_ip);

/**
 * Lookup the remote client's DNS name or IP address
 * @ingroup get_remote_host
@@ -180,7 +206,7 @@ AP_DECLARE(const char *) ap_document_root(request_rec *r);
 * </pre>
 * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address
 *        string is returned
 * @return The remote hostname
 * @return The remote hostname (based on the connection client_ip)
 */
AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);

+9 −0
Original line number Diff line number Diff line
@@ -1046,6 +1046,15 @@ struct request_rec {
    apr_table_t *trailers_in;
    /** MIME trailer environment from the response */
    apr_table_t *trailers_out;

    /** Originator's DNS name, if known.  NULL if DNS hasn't been checked,
     *  "" if it has and no address was found.  N.B. Only access this though
     *  ap_get_useragent_host() */
    char *useragent_host;
    /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
     *  1 yes/success
     */
    int double_reverse;
};

/**
Loading