... so that ServerTokens doesn't affect what gets logged to the error
log at startup (or any other place where we want the description of
the server instead of the banner to be written over the network).

This patch axes ap_get_server_version() so that third-party modules
will be forced to make a choice in post-2.2.x versions -- call
ap_get_server_banner() to retrieve the string suitable for sending
over the network (as controlled by ServerTokens) or call
ap_get_server_description() to retrieve the string that describes the
server version and certain plug-in modules.

I haven't actually changed the returned strings with this patch, but
instead would like to see any comments on the direction.  The two
functions are present and all httpd code has been modified to call the
proper function, which is also subject to a useful review.  What about
status pages?  Is the server version and module configuration somehow
more private than the status page itself, such that they should use
ap_get_server_banner() as in the current patch?
Index: server/mpm/winnt/service.c
===================================================================
--- server/mpm/winnt/service.c  (revision 438471)
+++ server/mpm/winnt/service.c  (working copy)
@@ -436,7 +436,7 @@
 
     /* Time to fix up the description, upon each successful restart
      */
-    full_description = ap_get_server_version();
+    full_description = ap_get_server_description();
 
     if ((osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
           && (osver.dwMajorVersion > 4)
Index: server/mpm/winnt/mpm_winnt.c
===================================================================
--- server/mpm/winnt/mpm_winnt.c        (revision 438471)
+++ server/mpm/winnt/mpm_winnt.c        (working copy)
@@ -1705,7 +1705,7 @@
         /* A real-honest to goodness parent */
         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                      "%s configured -- resuming normal operations",
-                     ap_get_server_version());
+                     ap_get_server_description());
         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                      "Server built: %s", ap_get_server_built());
 
Index: server/mpm/mpmt_os2/mpmt_os2.c
===================================================================
--- server/mpm/mpmt_os2/mpmt_os2.c      (revision 438471)
+++ server/mpm/mpmt_os2/mpmt_os2.c      (working copy)
@@ -207,7 +207,7 @@
     int listener_num, num_listeners, slot;
     ULONG rc;
 
-    printf("%s \n", ap_get_server_version());
+    printf("%s \n", ap_get_server_description());
     set_signals();
 
     if (ap_setup_listeners(ap_server_conf) < 1) {
@@ -270,7 +270,7 @@
     ap_scoreboard_image->global->restart_time = apr_time_now();
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/mpm/netware/mpm_netware.c
===================================================================
--- server/mpm/netware/mpm_netware.c    (revision 438471)
+++ server/mpm/netware/mpm_netware.c    (working copy)
@@ -723,7 +723,7 @@
     request_count = 0;
 
     ClearScreen (getscreenhandle());
-    printf("%s \n", ap_get_server_version());
+    printf("%s \n", ap_get_server_description());
 
     for (i=0;i<SERVER_NUM_STATUS;i++) {
         status_array[i] = 0;
@@ -793,7 +793,7 @@
     ap_listen_rec *lr;
     module **m;
 
-    printf("%s\n", ap_get_server_version());
+    printf("%s\n", ap_get_server_description());
     if (ap_my_addrspace && (ap_my_addrspace[0] != 'O') && (ap_my_addrspace[1] 
!= 'S'))
         printf("   Running in address space %s\n", ap_my_addrspace);
 
@@ -899,7 +899,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
             "%s configured -- resuming normal operations",
-            ap_get_server_version());
+            ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
             "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
@@ -1204,7 +1204,7 @@
             restart();
         }
         else if (!strnicmp("VERSION",&szcommandLine[iCommandLen],3)) {
-            printf("Server version: %s\n", ap_get_server_version());
+            printf("Server version: %s\n", ap_get_server_description());
             printf("Server built:   %s\n", ap_get_server_built());
         }
         else if (!strnicmp("MODULES",&szcommandLine[iCommandLen],3)) {
Index: server/mpm/beos/beos.c
===================================================================
--- server/mpm/beos/beos.c      (revision 438471)
+++ server/mpm/beos/beos.c      (working copy)
@@ -935,7 +935,7 @@
      */
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
 
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
Index: server/mpm/prefork/prefork.c
===================================================================
--- server/mpm/prefork/prefork.c        (revision 438471)
+++ server/mpm/prefork/prefork.c        (working copy)
@@ -976,7 +976,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/mpm/worker/worker.c
===================================================================
--- server/mpm/worker/worker.c  (revision 438471)
+++ server/mpm/worker/worker.c  (working copy)
@@ -1737,7 +1737,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/mpm/experimental/event/event.c
===================================================================
--- server/mpm/experimental/event/event.c       (revision 438471)
+++ server/mpm/experimental/event/event.c       (working copy)
@@ -1988,7 +1988,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                  "%s configured -- resuming normal operations",
-                 ap_get_server_version());
+                 ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                  "Server built: %s", ap_get_server_built());
 
Index: server/mpm/experimental/threadpool/threadpool.c
===================================================================
--- server/mpm/experimental/threadpool/threadpool.c     (revision 438471)
+++ server/mpm/experimental/threadpool/threadpool.c     (working copy)
@@ -1778,7 +1778,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/mpm/experimental/perchild/perchild.c
===================================================================
--- server/mpm/experimental/perchild/perchild.c (revision 438471)
+++ server/mpm/experimental/perchild/perchild.c (working copy)
@@ -1314,7 +1314,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                  "%s configured -- resuming normal operations",
-                 ap_get_server_version());
+                 ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                  "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/mpm/experimental/leader/leader.c
===================================================================
--- server/mpm/experimental/leader/leader.c     (revision 438471)
+++ server/mpm/experimental/leader/leader.c     (working copy)
@@ -1529,7 +1529,7 @@
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                 "%s configured -- resuming normal operations",
-                ap_get_server_version());
+                ap_get_server_description());
     ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
                 "Server built: %s", ap_get_server_built());
 #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
Index: server/core.c
===================================================================
--- server/core.c       (revision 438471)
+++ server/core.c       (working copy)
@@ -2580,7 +2580,7 @@
 
     if (conf->server_signature == srv_sig_withmail) {
         return apr_pstrcat(r->pool, prefix, "<address>",
-                           ap_get_server_version(),
+                           ap_get_server_banner(),
                            " Server at <a href=\"",
                            ap_is_url(r->server->server_admin) ? "" : "mailto:";,
                            ap_escape_html(r->pool, r->server->server_admin),
@@ -2590,7 +2590,7 @@
                            "</address>\n", NULL);
     }
 
-    return apr_pstrcat(r->pool, prefix, "<address>", ap_get_server_version(),
+    return apr_pstrcat(r->pool, prefix, "<address>", ap_get_server_banner(),
                        " Server at ",
                        ap_escape_html(r->pool, ap_get_server_name(r)),
                        " Port ", sport,
@@ -2634,11 +2634,21 @@
     version->add_string = AP_SERVER_ADD_STRING;
 }
 
-AP_DECLARE(const char *) ap_get_server_version(void)
+static const char *get_server_version(void)
 {
     return (server_version ? server_version : AP_SERVER_BASEVERSION);
 }
 
+AP_DECLARE(const char *) ap_get_server_description(void)
+{
+    return get_server_version();
+}
+
+AP_DECLARE(const char *) ap_get_server_banner(void)
+{
+    return get_server_version();
+}
+
 AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char 
*component)
 {
     if (! version_locked) {
Index: server/mpm_common.c
===================================================================
--- server/mpm_common.c (revision 438471)
+++ server/mpm_common.c (working copy)
@@ -635,7 +635,7 @@
      * requests in their logs.
      */
     srequest = apr_pstrcat(p, "GET / HTTP/1.0\r\nUser-Agent: ",
-                           ap_get_server_version(),
+                           ap_get_server_banner(),
                            " (internal dummy connection)\r\n\r\n", NULL);
 
     /* Since some operating systems support buffering of data or entire
Index: server/util_script.c
===================================================================
--- server/util_script.c        (revision 438471)
+++ server/util_script.c        (working copy)
@@ -223,7 +223,7 @@
 #endif
 
     apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
-    apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
+    apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_banner());
     apr_table_addn(e, "SERVER_NAME",
                    ap_escape_html(r->pool, ap_get_server_name(r)));
     apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip);  /* Apache */
Index: server/main.c
===================================================================
--- server/main.c       (revision 438471)
+++ server/main.c       (working copy)
@@ -92,7 +92,7 @@
 
 static void show_compile_settings(void)
 {
-    printf("Server version: %s\n", ap_get_server_version());
+    printf("Server version: %s\n", ap_get_server_description());
     printf("Server built:   %s\n", ap_get_server_built());
     printf("Server's Module Magic Number: %u:%u\n",
            MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
@@ -569,7 +569,7 @@
             break;
 
         case 'v':
-            printf("Server version: %s\n", ap_get_server_version());
+            printf("Server version: %s\n", ap_get_server_description());
             printf("Server built:   %s\n", ap_get_server_built());
             destroy_and_exit_process(process, 0);
 
Index: modules/http/http_filters.c
===================================================================
--- modules/http/http_filters.c (revision 438471)
+++ modules/http/http_filters.c (working copy)
@@ -735,11 +735,11 @@
         if (server) {
             form_header_field(&h, "Server", server);
         } else {
-            form_header_field(&h, "Server", ap_get_server_version());
+            form_header_field(&h, "Server", ap_get_server_banner());
         }
     }
     else {
-        form_header_field(&h, "Server", ap_get_server_version());
+        form_header_field(&h, "Server", ap_get_server_banner());
     }
 
     /* unset so we don't send them again */
Index: modules/proxy/mod_proxy_balancer.c
===================================================================
--- modules/proxy/mod_proxy_balancer.c  (revision 438471)
+++ modules/proxy/mod_proxy_balancer.c  (working copy)
@@ -669,7 +669,7 @@
         ap_rputs("<body><h1>Load Balancer Manager for ", r);
         ap_rvputs(r, ap_get_server_name(r), "</h1>\n\n", NULL);
         ap_rvputs(r, "<dl><dt>Server Version: ",
-                  ap_get_server_version(), "</dt>\n", NULL);
+                  ap_get_server_banner(), "</dt>\n", NULL);
         ap_rvputs(r, "<dt>Server Built: ",
                   ap_get_server_built(), "\n</dt></dl>\n", NULL);
         balancer = (proxy_balancer *)conf->balancers->elts;
Index: modules/proxy/mod_proxy_connect.c
===================================================================
--- modules/proxy/mod_proxy_connect.c   (revision 438471)
+++ modules/proxy/mod_proxy_connect.c   (working copy)
@@ -224,7 +224,7 @@
                   "CONNECT %s HTTP/1.0" CRLF, r->uri);
         apr_socket_send(sock, buffer, &nbytes);
         nbytes = apr_snprintf(buffer, sizeof(buffer),
-                  "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
+                  "Proxy-agent: %s" CRLF CRLF, ap_get_server_banner());
         apr_socket_send(sock, buffer, &nbytes);
     }
     else {
@@ -235,7 +235,7 @@
         ap_xlate_proto_to_ascii(buffer, nbytes);
         apr_socket_send(client_socket, buffer, &nbytes);
         nbytes = apr_snprintf(buffer, sizeof(buffer),
-                  "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
+                  "Proxy-agent: %s" CRLF CRLF, ap_get_server_banner());
         ap_xlate_proto_to_ascii(buffer, nbytes);
         apr_socket_send(client_socket, buffer, &nbytes);
 #if 0
@@ -244,7 +244,7 @@
          */
         r->status = HTTP_OK;
         r->header_only = 1;
-        apr_table_set(r->headers_out, "Proxy-agent: %s", 
ap_get_server_version());
+        apr_table_set(r->headers_out, "Proxy-agent: %s", 
ap_get_server_banner());
         ap_rflush(r);
 #endif
     }
Index: modules/proxy/mod_proxy_ftp.c
===================================================================
--- modules/proxy/mod_proxy_ftp.c       (revision 438471)
+++ modules/proxy/mod_proxy_ftp.c       (working copy)
@@ -1662,7 +1662,7 @@
 
     apr_rfc822_date(dates, r->request_time);
     apr_table_setn(r->headers_out, "Date", dates);
-    apr_table_setn(r->headers_out, "Server", ap_get_server_version());
+    apr_table_setn(r->headers_out, "Server", ap_get_server_banner());
 
     /* set content-type */
     if (dirlisting) {
Index: modules/experimental/mod_example.c
===================================================================
--- modules/experimental/mod_example.c  (revision 438471)
+++ modules/experimental/mod_example.c  (working copy)
@@ -546,7 +546,7 @@
     ap_rputs("  </H1>\n", r);
     ap_rputs("  <P>\n", r);
     ap_rprintf(r, "  Apache HTTP Server version: \"%s\"\n",
-            ap_get_server_version());
+            ap_get_server_banner());
     ap_rputs("  <BR>\n", r);
     ap_rprintf(r, "  Server built: \"%s\"\n", ap_get_server_built());
     ap_rputs("  </P>\n", r);;
Index: modules/ssl/ssl_engine_vars.c
===================================================================
--- modules/ssl/ssl_engine_vars.c       (revision 438471)
+++ modules/ssl/ssl_engine_vars.c       (working copy)
@@ -192,7 +192,7 @@
         if (strlen(var) > 12 && strcEQn(var, "SSL_VERSION_", 12))
             result = ssl_var_lookup_ssl_version(p, var+12);
         else if (strcEQ(var, "SERVER_SOFTWARE"))
-            result = ap_get_server_version();
+            result = ap_get_server_banner();
         else if (strcEQ(var, "API_VERSION")) {
             result = apr_itoa(p, MODULE_MAGIC_NUMBER);
             resdup = FALSE;
Index: modules/mappers/mod_rewrite.c
===================================================================
--- modules/mappers/mod_rewrite.c       (revision 438471)
+++ modules/mappers/mod_rewrite.c       (working copy)
@@ -2006,7 +2006,7 @@
 
             case 'S':
                 if (!strcmp(var, "SERVER_SOFTWARE")) {
-                    result = ap_get_server_version();
+                    result = ap_get_server_banner();
                 }
                 break;
             }
Index: modules/generators/mod_status.c
===================================================================
--- modules/generators/mod_status.c     (revision 438471)
+++ modules/generators/mod_status.c     (working copy)
@@ -397,7 +397,7 @@
         ap_rputs("<h1>Apache Server Status for ", r);
         ap_rvputs(r, ap_get_server_name(r), "</h1>\n\n", NULL);
         ap_rvputs(r, "<dl><dt>Server Version: ",
-                  ap_get_server_version(), "</dt>\n", NULL);
+                  ap_get_server_banner(), "</dt>\n", NULL);
         ap_rvputs(r, "<dt>Server Built: ",
                   ap_get_server_built(), "\n</dt></dl><hr /><dl>\n", NULL);
         ap_rvputs(r, "<dt>Current Time: ",
Index: modules/generators/mod_info.c
===================================================================
--- modules/generators/mod_info.c       (revision 438471)
+++ modules/generators/mod_info.c       (working copy)
@@ -347,7 +347,7 @@
     ap_rprintf(r,
                "<dl><dt><strong>Server Version:</strong> "
                "<font size=\"+1\"><tt>%s</tt></font></dt>\n",
-               ap_get_server_version());
+               ap_get_server_banner());
     ap_rprintf(r,
                "<dt><strong>Server Built:</strong> "
                "<font size=\"+1\"><tt>%s</tt></font></dt>\n",
Index: modules/arch/netware/mod_nw_ssl.c
===================================================================
--- modules/arch/netware/mod_nw_ssl.c   (revision 438471)
+++ modules/arch/netware/mod_nw_ssl.c   (working copy)
@@ -1074,7 +1074,7 @@
             /* XXX-Can't get specific SSL info from NetWare */
             /*result = ssl_var_lookup_ssl_version(p, var+12);*/
         else if (strcEQ(var, "SERVER_SOFTWARE"))
-            result = ap_get_server_version();
+            result = ap_get_server_banner();
         else if (strcEQ(var, "API_VERSION")) {
             result = apr_itoa(p, MODULE_MAGIC_NUMBER);
             resdup = FALSE;
Index: include/httpd.h
===================================================================
--- include/httpd.h     (revision 438471)
+++ include/httpd.h     (working copy)
@@ -420,13 +420,22 @@
 AP_DECLARE(void) ap_get_server_revision(ap_version_t *version);
 
 /**
- * Get the server version string
- * @return The server version string
+ * Get the server banner in a form suitable for sending over the
+ * network (as controlled by the ServerTokens directive).
+ * @return The server banner
  */
-AP_DECLARE(const char *) ap_get_server_version(void);
+AP_DECLARE(const char *) ap_get_server_banner(void);
 
 /**
- * Add a component to the version string
+ * Get the server description in a form suitable for local displays
+ * or logging.  This includes the detailed server version and
+ * information about some modules.
+ * @return The server description
+ */
+AP_DECLARE(const char *) ap_get_server_description(void);
+
+/**
+ * Add a component to the server description and banner strings
  * @param pconf The pool to allocate the component from
  * @param component The string to add
  */

Reply via email to