]> andersk Git - mod-vhost-ldap.git/commitdiff
Deep clone server_rec using ap_fixup_virtual_host
authorGreg Brockman <gdb@mit.edu>
Sun, 15 Aug 2010 14:27:58 +0000 (10:27 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Fri, 18 Mar 2011 06:30:16 +0000 (02:30 -0400)
This patch is largely a refactoring.  However, we effectively are now
doing a deep clone, as opposed to the somewhat-deep clone we used to
have using memcpy.

mod_vhost_ldap.c

index 3c5cde9f536fdb3be73c81c20e9c043cb834ea64..54decbf43a376b1c527782b4626e63aa4684fa2f 100644 (file)
@@ -434,14 +434,15 @@ command_rec mod_vhost_ldap_cmds[] = {
 #define FILTER_LENGTH MAX_STRING_LEN
 static int mod_vhost_ldap_translate_name(request_rec *r)
 {
+    server_rec *server;
+    const char *error;
     mod_vhost_ldap_request_t *reqc;
     int failures = 0;
     const char **vals = NULL;
     char filtbuf[FILTER_LENGTH];
     mod_vhost_ldap_config_t *conf =
        (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module);
-    core_server_config *core =
-        (core_server_config *)ap_get_module_config(r->server->module_config, &core_module);
+    core_server_config *core;
     util_ldap_connection_t *ldc = NULL;
     int result = 0;
     const char *dn = NULL;
@@ -453,6 +454,16 @@ static int mod_vhost_ldap_translate_name(request_rec *r)
     int sleep;
     struct berval hostnamebv, shostnamebv;
 
+    if ((error = ap_init_virtual_host(r->pool, "", r->server, &server)) != NULL) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
+                     "[mod_vhost_ldap.c]: Could not initialize a new VirtualHost: %s",
+                     error);
+       return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    core = core_module.create_server_config(r->pool, server);
+    ap_set_module_config(server->module_config, &core_module, core);
+
     reqc =
        (mod_vhost_ldap_request_t *)apr_pcalloc(r->pool, sizeof(mod_vhost_ldap_request_t));
     memset(reqc, 0, sizeof(mod_vhost_ldap_request_t)); 
@@ -633,35 +644,11 @@ null:
        return DECLINED;
     }
 
-    if ((r->server = apr_pmemdup(r->pool, r->server, sizeof(*r->server))) == NULL) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 
-                      "[mod_vhost_ldap.c] translate: "
-                      "translate failed; Unable to copy r->server structure");
-       return HTTP_INTERNAL_SERVER_ERROR;
-    }
-
-    r->server->server_hostname = reqc->name;
+    server->server_hostname = reqc->name;
 
     if (reqc->admin) {
-       r->server->server_admin = reqc->admin;
-    }
-
-    if ((r->server->module_config = apr_pmemdup(r->pool, r->server->module_config,
-                                               sizeof(void *) *
-                                               (total_modules + DYNAMIC_MODULE_LIMIT))) == NULL) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 
-                      "[mod_vhost_ldap.c] translate: "
-                      "translate failed; Unable to copy r->server->module_config structure");
-        return HTTP_INTERNAL_SERVER_ERROR;
-    }
-
-    if ((core = apr_pmemdup(r->pool, core, sizeof(*core))) == NULL) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, 
-                      "[mod_vhost_ldap.c] translate: "
-                      "translate failed; Unable to copy r->core structure");
-        return HTTP_INTERNAL_SERVER_ERROR;
+       server->server_admin = reqc->admin;
     }
-    ap_set_module_config(r->server->module_config, &core_module, core);
 
     /* Stolen from server/core.c */
 
@@ -686,6 +673,9 @@ null:
         core->ap_document_root = reqc->docroot;
     }
 
+    ap_fixup_virtual_host(r->pool, r->server, server);
+    r->server = server;
+
     /* Hack to allow post-processing by other modules (mod_rewrite, mod_alias) */
     return DECLINED;
 }
This page took 0.057528 seconds and 5 git commands to generate.