On Mon, Nov 17, 2003 at 08:56:28PM +0100, Andr� Malo wrote:
> * Colm MacCarthaigh <[EMAIL PROTECTED]> wrote:
> 
> > "unconfigured". Or make it a hard error, and have no fallback.
> 
> I'd prefer the latter. FWIW.

Same here. It probably breaks a lot of lame configs though, all the
same ... patch attached.

-- 
Colm MacC�rthaigh                        Public Key: [EMAIL PROTECTED]
Index: include/http_vhost.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/http_vhost.h,v
retrieving revision 1.15
diff -u -r1.15 http_vhost.h
--- include/http_vhost.h        3 Feb 2003 17:52:53 -0000       1.15
+++ include/http_vhost.h        17 Nov 2003 21:53:36 -0000
@@ -74,9 +74,11 @@
  * the run-time vhost lookups
  * @param p The pool to allocate out of
  * @param main_server The start of the virtual host list
+ * @return return OK if vhost had a valid ServerName,
+ * return HTTP_INTERNAL_SERVER_ERROR otherwise
  * @deffunc ap_fini_vhost_config(apr_pool_t *p, server_rec *main_server)
  */
-AP_DECLARE(void) ap_fini_vhost_config(apr_pool_t *p, server_rec *main_server);
+AP_DECLARE(int) ap_fini_vhost_config(apr_pool_t *p, server_rec *main_server);
 
 /**
  * handle addresses in <VirtualHost> statement
Index: include/httpd.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/httpd.h,v
retrieving revision 1.201
diff -u -r1.201 httpd.h
--- include/httpd.h     2 Nov 2003 20:37:03 -0000       1.201
+++ include/httpd.h     17 Nov 2003 21:53:36 -0000
@@ -1638,13 +1638,6 @@
 #endif /* _OSD_POSIX */
 
 /**
- * Determine the local host name for the current machine
- * @param p The pool to allocate from
- * @return A copy of the local host name
- */
-char *ap_get_local_host(apr_pool_t *p);
-
-/**
  * Log an assertion to the error log
  * @param szExp The assertion that failed
  * @param szFile The file the assertion is in
Index: server/main.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/main.c,v
retrieving revision 1.146
diff -u -r1.146 main.c
--- server/main.c       8 Sep 2003 16:39:04 -0000       1.146
+++ server/main.c       17 Nov 2003 21:53:37 -0000
@@ -585,7 +585,10 @@
                                 process->pconf, ptemp);
     if (rv == OK) {
         ap_fixup_virtual_hosts(pconf, server_conf);
-        ap_fini_vhost_config(pconf, server_conf);
+        if (ap_fini_vhost_config(pconf, server_conf) != OK) {
+            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Configuration 
failed\n");
+            destroy_and_exit_process(process, 1);
+        }
         apr_hook_sort_all();
         if (configtestonly) {
             ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
@@ -651,7 +654,10 @@
             destroy_and_exit_process(process, 1);
         }
         ap_fixup_virtual_hosts(pconf, server_conf);
-        ap_fini_vhost_config(pconf, server_conf);
+        if (ap_fini_vhost_config(pconf, server_conf) != OK) {
+            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Configuration 
failed\n");
+            destroy_and_exit_process(process, 1);
+        }
         apr_hook_sort_all();
         apr_pool_clear(plog);
         if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
Index: server/util.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/util.c,v
retrieving revision 1.142
diff -u -r1.142 util.c
--- server/util.c       3 Sep 2003 19:27:09 -0000       1.142
+++ server/util.c       17 Nov 2003 21:53:37 -0000
@@ -1948,55 +1948,6 @@
     return apr_pstrdup(a, (void *) p->h_name);
 }
 
-char *ap_get_local_host(apr_pool_t *a)
-{
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif
-    char str[MAXHOSTNAMELEN + 1];
-    char *server_hostname = NULL;
-    struct hostent *p;
-
-#ifdef BEOS_R5
-    if (gethostname(str, sizeof(str) - 1) == 0)
-#else
-    if (gethostname(str, sizeof(str) - 1) != 0)
-#endif
-    {
-        ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a,
-                     "%s: gethostname() failed to determine ServerName",
-                     ap_server_argv0);
-    }
-    else 
-    {
-        str[sizeof(str) - 1] = '\0';
-        /* TODO: Screaming for APR-ization */
-        if ((!(p = gethostbyname(str))) 
-            || (!(server_hostname = find_fqdn(a, p)))) {
-            /* Recovery - return the default servername by IP: */
-            if (p && p->h_addr_list[0]) {
-                apr_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
-                server_hostname = apr_pstrdup(a, str);
-                /* We will drop through to report the IP-named server */
-            }
-        }
-        else {
-            /* Since we found a fdqn, return it with no logged message. */
-            return server_hostname;
-        }
-    }
-
-    if (!server_hostname) 
-        server_hostname = apr_pstrdup(a, "127.0.0.1");
-
-    ap_log_perror(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, a,
-                 "%s: Could not determine the server's fully qualified "
-                 "domain name, using %s for ServerName",
-                 ap_server_argv0, server_hostname);
-             
-    return server_hostname;
-}
-
 /* simple 'pool' alloc()ing glue to apr_base64.c
  */
 AP_DECLARE(char *) ap_pbase64decode(apr_pool_t *p, const char *bufcoded)
Index: server/vhost.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/vhost.c,v
retrieving revision 1.79
diff -u -r1.79 vhost.c
--- server/vhost.c      3 Feb 2003 17:53:20 -0000       1.79
+++ server/vhost.c      17 Nov 2003 21:53:37 -0000
@@ -76,6 +76,7 @@
 #include "http_vhost.h"
 #include "http_protocol.h"
 #include "http_core.h"
+#include "http_main.h"
 
 #if APR_HAVE_ARPA_INET_H
 #include <arpa/inet.h>
@@ -556,7 +557,7 @@
 }
 
 /* compile the tables and such we need to do the run-time vhost lookups */
-AP_DECLARE(void) ap_fini_vhost_config(apr_pool_t *p, server_rec *main_s)
+AP_DECLARE(int) ap_fini_vhost_config(apr_pool_t *p, server_rec *main_s)
 {
     server_addr_rec *sar;
     int has_default_vhost_addr;
@@ -570,8 +571,14 @@
     /* Main host first */
     s = main_s;
 
+    /* If the user was silly enough not to set a ServerName, consider
+     * it a hard error. Doing otherwise is confusing and unpredictable.
+     */
     if (!s->server_hostname) {
-        s->server_hostname = ap_get_local_host(p);
+        ap_log_perror(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, p,
+                      "%s: Could not determine a ServerName",
+                      ap_server_argv0);
+        return HTTP_INTERNAL_SERVER_ERROR;
     }
 
     /* initialize the tails */
@@ -660,45 +667,14 @@
             }
         }
 
-        /* Ok now we want to set up a server_hostname if the user was
-         * silly enough to forget one.
-         * XXX: This is silly we should just crash and burn.
+        /* If the user was silly enough not to set a ServerName, consider
+         * it a hard error. Doing otherwise is confusing and unpredictable.
          */
         if (!s->server_hostname) {
-            if (has_default_vhost_addr) {
-                s->server_hostname = main_s->server_hostname;
-            }
-            else if (!s->addrs) {
-                /* what else can we do?  at this point this vhost has
-                    no configured name, probably because they used
-                    DNS in the VirtualHost statement.  It's disabled
-                    anyhow by the host matching code.  -djg */
-                s->server_hostname =
-                    apr_pstrdup(p, "bogus_host_without_forward_dns");
-            }
-            else {
-                apr_status_t rv;
-                char *hostname;
-
-                rv = apr_getnameinfo(&hostname, s->addrs->host_addr, 0);
-                if (rv == APR_SUCCESS) {
-                    s->server_hostname = apr_pstrdup(p, hostname);
-                }
-                else {
-                    /* again, what can we do?  They didn't specify a
-                       ServerName, and their DNS isn't working. -djg */
-                    char *ipaddr_str;
-
-                    apr_sockaddr_ip_get(&ipaddr_str, s->addrs->host_addr);
-                    ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_s,
-                                 "Failed to resolve server name "
-                                 "for %s (check DNS) -- or specify an explicit "
-                                 "ServerName",
-                                 ipaddr_str);
-                    s->server_hostname =
-                        apr_pstrdup(p, "bogus_host_without_reverse_dns");
-                }
-            }
+            ap_log_perror(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, p,
+                          "%s: Could not determine a ServerName",
+                          ap_server_argv0);
+            return HTTP_INTERNAL_SERVER_ERROR;
         }
     }
 
@@ -718,6 +694,8 @@
         apr_file_open_stderr(&thefile, p);
         dump_vhost_config(thefile);
     }
+
+    return OK;
 }
 
 

Reply via email to