From eda6e3d23ce49fe3c33fe8f0299939722b901868 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Mon, 5 Jun 2000 19:44:02 +0000 Subject: [PATCH] Add server tokens back to 2.0. Also bring forward the change to allow the PRODUCT_ONLY value for ServerTokens. This is relatively clean, all of the code lives in http_core, and when a module wants to add a token, they just call ap_add_version_component from the post_config hook. Actually ap_add_version_component can be done anytime after the config has been parsed, it just makes the most sense to do it in post_config IMHO. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85426 13f79535-47bb-0310-9956-ffa450edef68 --- STATUS | 4 +- include/httpd.h | 15 +---- modules/http/http_core.c | 76 +++++++++++++++++++++++++- server/mpm/dexter/dexter.c | 3 - server/mpm/mpmt_beos/mpmt_beos.c | 3 - server/mpm/mpmt_pthread/mpmt_pthread.c | 4 -- 6 files changed, 77 insertions(+), 28 deletions(-) diff --git a/STATUS b/STATUS index 1a615256a8..b8c2b38072 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ Apache 2.0 STATUS: -Last modified at [$Date: 2000/06/02 19:45:40 $] +Last modified at [$Date: 2000/06/05 19:43:57 $] Release: @@ -9,8 +9,6 @@ Release: 2.0a1 : released March 10, 2000 RELEASE SHOWSTOPPERS: - * Reimplement the server tokens - * Win32: Get mod_auth_digest working under win32 - APR_HAS_RANDOM should be defined on windows and there is a lib/apr/misc/win32/rand.c which is basically a copy of what diff --git a/include/httpd.h b/include/httpd.h index f820fc2c76..33ee09100b 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -365,24 +365,15 @@ extern "C" { #define APEXIT_CHILDINIT 0x3 #define APEXIT_CHILDFATAL 0xf -/* TODO: re-implement the server token/version stuff -- it's part of http_core - * it should be possible to do without touching http_main at all. (or else - * we haven't got enough module hooks) - */ - enum server_token_type { SrvTk_MIN, /* eg: Apache/1.3.0 */ SrvTk_OS, /* eg: Apache/1.3.0 (UNIX) */ - SrvTk_FULL /* eg: Apache/1.3.0 (UNIX) PHP/3.0 FooBar/1.2b */ + SrvTk_FULL, /* eg: Apache/1.3.0 (UNIX) PHP/3.0 FooBar/1.2b */ + SrvTk_PRODUCT_ONLY /* eg: Apache */ }; -#if 0 API_EXPORT(const char *) ap_get_server_version(void); -API_EXPORT(void) ap_add_version_component(const char *component); -#else -#define ap_get_server_version() (AP_SERVER_BASEVERSION) -#define ap_add_version_component(x) ((void)0) -#endif +API_EXPORT(void) ap_add_version_component(ap_pool_t pconf, const char *component); API_EXPORT(const char *) ap_get_server_built(void); /* Numeric release version identifier: MMNNFFRBB: major minor fix final beta diff --git a/modules/http/http_core.c b/modules/http/http_core.c index 4a948e296a..460c3a2f3a 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -2040,6 +2040,70 @@ static const char *set_bs2000_account(cmd_parms *cmd, void *dummy, char *name) * string. */ +static char *server_version = NULL; +static int version_locked = 0; +static enum server_token_type ap_server_tokens = SrvTk_FULL; + +static ap_status_t reset_version(void *dummy) +{ + version_locked = 0; + ap_server_tokens = SrvTk_FULL; + server_version = NULL; +} + +API_EXPORT(const char *) ap_get_server_version(void) +{ + return (server_version ? server_version : AP_SERVER_BASEVERSION); +} + +API_EXPORT(void) ap_add_version_component(ap_pool_t *pconf, const char *component) +{ + if (! version_locked) { + /* + * If the version string is null, register our cleanup to reset the + * pointer on pool destruction. We also know that, if NULL, + * we are adding the original SERVER_BASEVERSION string. + */ + if (server_version == NULL) { + ap_register_cleanup(pconf, NULL, reset_version, + ap_null_cleanup); + server_version = ap_pstrdup(pconf, component); + } + else { + /* + * Tack the given component identifier to the end of + * the existing string. + */ + server_version = ap_pstrcat(pconf, server_version, " ", + component, NULL); + } + } +} + +/* + * This routine adds the real server base identity to the version string, + * and then locks out changes until the next reconfig. + */ +static void ap_set_version(ap_pool_t *pconf) +{ + if (ap_server_tokens == SrvTk_PRODUCT_ONLY) { + ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT); + } + else if (ap_server_tokens == SrvTk_MIN) { + ap_add_version_component(pconf, AP_SERVER_BASEVERSION); + } + else { + ap_add_version_component(pconf, AP_SERVER_BASEVERSION " (" PLATFORM ")"); + } + /* + * Lock the server_version string if we're not displaying + * the full set of tokens + */ + if (ap_server_tokens != SrvTk_FULL) { + version_locked++; + } +} + static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); @@ -2047,18 +2111,18 @@ static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, char *arg) return err; } - /* TODO: reimplement the server token stuff. */ -#if 0 if (!strcasecmp(arg, "OS")) { ap_server_tokens = SrvTk_OS; } else if (!strcasecmp(arg, "Min") || !strcasecmp(arg, "Minimal")) { ap_server_tokens = SrvTk_MIN; } + else if (!strcasecmp(arg, "Prod") || !strcasecmp(arg, "ProductOnly")) { + ap_server_tokens = SrvTk_PRODUCT_ONLY; + } else { ap_server_tokens = SrvTk_FULL; } -#endif return NULL; } @@ -2532,6 +2596,11 @@ static const handler_rec core_handlers[] = { { NULL, NULL } }; +static void core_post_config(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s) +{ + ap_set_version(pconf); +} + static void core_open_logs(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s) { ap_open_logs(s, pconf); @@ -2545,6 +2614,7 @@ static unsigned short core_port(const request_rec *r) static void register_hooks(void) { + ap_hook_post_config(core_post_config,NULL,NULL,AP_HOOK_REALLY_FIRST); ap_hook_translate_name(core_translate,NULL,NULL,AP_HOOK_REALLY_LAST); ap_hook_process_connection(ap_process_http_connection,NULL,NULL, AP_HOOK_REALLY_LAST); diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index f360585e12..aadc7cf00f 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -164,9 +164,6 @@ static ap_lock_t *process_accept_mutex; static char *lock_fname; static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER; -/* Global, alas, so http_core can talk to us */ -enum server_token_type ap_server_tokens = SrvTk_FULL; - API_EXPORT(const server_rec *) ap_get_server_conf(void) { return (ap_server_conf); diff --git a/server/mpm/mpmt_beos/mpmt_beos.c b/server/mpm/mpmt_beos/mpmt_beos.c index c7e5b80145..2e8229c5a0 100644 --- a/server/mpm/mpmt_beos/mpmt_beos.c +++ b/server/mpm/mpmt_beos/mpmt_beos.c @@ -139,9 +139,6 @@ static int one_process = 0; int raise_sigstop_flags; #endif -/* Global, alas, so http_core can talk to us */ -enum server_token_type ap_server_tokens = SrvTk_FULL; - API_EXPORT(const server_rec *) ap_get_server_conf(void) { return (ap_server_conf); diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index cb1278e990..94bbed9c2c 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -161,10 +161,6 @@ static char *lock_fname; #define SAFE_ACCEPT(stmt) (stmt) #endif - -/* Global, alas, so http_core can talk to us */ -enum server_token_type ap_server_tokens = SrvTk_FULL; - API_EXPORT(const server_rec *) ap_get_server_conf(void) { return (ap_server_conf); -- 2.40.0