From 1e603d8a3e77b0771f9d68475f34c91e3e133657 Mon Sep 17 00:00:00 2001 From: brectanus Date: Tue, 11 Sep 2007 18:01:28 +0000 Subject: [PATCH] Detect and use new API calls to get the server version/banner when available. --- CHANGES | 2 ++ apache2/apache2.h | 15 +++++++++++++++ apache2/mod_security2.c | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 34a98ee0..47e31409 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ ?? ??? 2007 - 2.5.0-trunk ------------------------- + * Used new API calls to get the server version/banner when available. + * Allow mod_rpaf and mod_extract_forwarded2 to work before ModSecurity. * Quiet some compiler warnings. diff --git a/apache2/apache2.h b/apache2/apache2.h index c0f9abe2..4cd86c4c 100644 --- a/apache2/apache2.h +++ b/apache2/apache2.h @@ -13,6 +13,8 @@ #include "http_core.h" #include "http_request.h" +#include "httpd.h" +#include "ap_release.h" #include #include @@ -30,6 +32,19 @@ APR_DECLARE_OPTIONAL_FN(void, modsec_register_variable, unsigned int is_cacheable, unsigned int availability)); #endif +/* ap_get_server_version() is gone in 2.3.0. + * It was replaced by two calls in 2.2.4 and higher: + * ap_get_server_banner() + * ap_get_server_description() + */ +#if (AP_SERVER_MAJORVERSION_NUMBER > 2) \ + || ((AP_SERVER_MAJORVERSION_NUMBER == 2)&& (AP_SERVER_MINORVERSION_NUMBER > 2)) \ + || ((AP_SERVER_MAJORVERSION_NUMBER == 2) && (AP_SERVER_MINORVERSION_NUMBER == 2) && (AP_SERVER_PATCHLEVEL_NUMBER >= 4)) +#define apache_get_server_version() ap_get_server_banner() +#else +#define apache_get_server_version() ap_get_server_version() +#endif + /* Configuration functions. */ diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c index da783d53..eb10cce8 100644 --- a/apache2/mod_security2.c +++ b/apache2/mod_security2.c @@ -379,7 +379,8 @@ static apr_status_t change_server_signature(server_rec *s) { if (new_server_signature == NULL) return 0; - server_version = (char *)ap_get_server_version(); + server_version = (char *)apache_get_server_version(); + if (server_version == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, s, "SecServerSignature: Apache returned null as signature."); @@ -442,7 +443,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t } /* Store the original server signature */ - real_server_signature = apr_pstrdup(mp, ap_get_server_version()); + real_server_signature = apr_pstrdup(mp, apache_get_server_version()); /* Make some space in the server signature for later */ if (new_server_signature != NULL) {