From d3dcba691d796a3812f71bf85a77d80af4e3dd27 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Fri, 9 Mar 2001 20:30:34 +0000 Subject: [PATCH] tweak ap_get_remote_host() so that the caller can find out if she got back an IP address mod_access needed to know this, but the old code didn't handle IPv6 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88484 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_core.h | 6 ++++-- modules/aaa/mod_access.c | 6 ++++-- modules/loggers/mod_log_config.c | 2 +- modules/mappers/mod_rewrite.c | 4 ++-- modules/metadata/mod_setenvif.c | 2 +- modules/metadata/mod_usertrack.c | 2 +- server/core.c | 9 ++++++++- server/scoreboard.c | 2 +- server/util_script.c | 2 +- 9 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/http_core.h b/include/http_core.h index db9bf037b0..da40736327 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -184,10 +184,12 @@ AP_DECLARE(const char *) ap_document_root(request_rec *r); * setting. The result is the (double reverse checked) * hostname, or NULL if any of the lookups fail. * + * @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 - * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type) + * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip) */ -AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type); +AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip); /** * Retrieve the login name of the remote user. Undef if it could not be diff --git a/modules/aaa/mod_access.c b/modules/aaa/mod_access.c index 055bc43f0f..39440ff5cc 100644 --- a/modules/aaa/mod_access.c +++ b/modules/aaa/mod_access.c @@ -341,10 +341,12 @@ static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method) case T_HOST: if (!gothost) { + int remotehost_is_ip; + remotehost = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_DOUBLE_REV); + REMOTE_DOUBLE_REV, &remotehost_is_ip); - if ((remotehost == NULL) || is_ip(remotehost)) + if ((remotehost == NULL) || remotehost_is_ip) gothost = 1; else gothost = 2; diff --git a/modules/loggers/mod_log_config.c b/modules/loggers/mod_log_config.c index 150babfbf6..fbe7ec1ca7 100644 --- a/modules/loggers/mod_log_config.c +++ b/modules/loggers/mod_log_config.c @@ -303,7 +303,7 @@ static const char *constant_item(request_rec *dummy, char *stuff) static const char *log_remote_host(request_rec *r, char *a) { return ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME); + REMOTE_NAME, NULL); } static const char *log_remote_address(request_rec *r, char *a) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 4adddc50d0..96863d9bc4 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -3138,7 +3138,7 @@ static void rewritelog(request_rec *r, int level, const char *text, ...) } rhost = ap_get_remote_host(conn, r->server->module_config, - REMOTE_NOLOOKUP); + REMOTE_NOLOOKUP, NULL); if (rhost == NULL) { rhost = "UNKNOWN-HOST"; } @@ -3409,7 +3409,7 @@ static char *lookup_variable(request_rec *r, char *var) } else if (strcasecmp(var, "REMOTE_HOST") == 0) { result = (char *)ap_get_remote_host(r->connection, - r->per_dir_config, REMOTE_NAME); + r->per_dir_config, REMOTE_NAME, NULL); } else if (strcasecmp(var, "REMOTE_USER") == 0) { result = r->user; diff --git a/modules/metadata/mod_setenvif.c b/modules/metadata/mod_setenvif.c index c0a3d149c6..3e12a71367 100644 --- a/modules/metadata/mod_setenvif.c +++ b/modules/metadata/mod_setenvif.c @@ -402,7 +402,7 @@ static int match_headers(request_rec *r) break; case SPECIAL_REMOTE_HOST: val = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME); + REMOTE_NAME, NULL); break; case SPECIAL_REMOTE_USER: val = r->user; diff --git a/modules/metadata/mod_usertrack.c b/modules/metadata/mod_usertrack.c index 0e1cbd880d..dfe39f0875 100644 --- a/modules/metadata/mod_usertrack.c +++ b/modules/metadata/mod_usertrack.c @@ -138,7 +138,7 @@ static void make_cookie(request_rec *r) char cookiebuf[1024]; char *new_cookie; const char *rname = ap_get_remote_host(r->connection, r->per_dir_config, - REMOTE_NAME); + REMOTE_NAME, NULL); cookie_dir_rec *dcfg; dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module); diff --git a/server/core.c b/server/core.c index 070c4d1e09..962ad246ce 100644 --- a/server/core.c +++ b/server/core.c @@ -607,10 +607,14 @@ static APR_INLINE void do_double_reverse (conn_rec *conn) } AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, - int type) + int type, int *str_is_ip) { int hostname_lookups; + if (str_is_ip) { /* if caller wants to know */ + *str_is_ip = 0; + } + /* If we haven't checked the host name, and we want to */ if (dir_config) { hostname_lookups = @@ -667,6 +671,9 @@ AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, return NULL; } else { + if (str_is_ip) { /* if caller wants to know */ + *str_is_ip = 1; + } return conn->remote_ip; } } diff --git a/server/scoreboard.c b/server/scoreboard.c index 80277debaf..d93a84aaec 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -300,7 +300,7 @@ int ap_update_child_status(int child_num, int thread_num, int status, request_re if (r) { conn_rec *c = r->connection; apr_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config, - REMOTE_NOLOOKUP), sizeof(ss->client)); + REMOTE_NOLOOKUP, NULL), sizeof(ss->client)); if (r->the_request == NULL) { apr_cpystrn(ss->request, "NULL", sizeof(ss->request)); } else if (r->parsed_uri.password == NULL) { diff --git a/server/util_script.c b/server/util_script.c index 58fcf6be8f..875bec9c7a 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -247,7 +247,7 @@ AP_DECLARE(void) ap_add_common_vars(request_rec *r) apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip); /* Apache */ apr_table_addn(e, "SERVER_PORT", apr_psprintf(r->pool, "%u", ap_get_server_port(r))); - host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST); + host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL); if (host) { apr_table_addn(e, "REMOTE_HOST", host); } -- 2.50.1