From: Greg Brockman Date: Sun, 15 Aug 2010 14:27:58 +0000 (-0400) Subject: Deep clone server_rec using ap_fixup_virtual_host X-Git-Tag: scripts-rebased.r1608~3 X-Git-Url: http://andersk.mit.edu/gitweb/mod-vhost-ldap.git/commitdiff_plain/95222c7f8c1c56bafc1bf4d70d87d11eb8eeb116 Deep clone server_rec using ap_fixup_virtual_host 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. --- diff --git a/mod_vhost_ldap.c b/mod_vhost_ldap.c index 3c5cde9..54decbf 100644 --- a/mod_vhost_ldap.c +++ b/mod_vhost_ldap.c @@ -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; }