Index: server/common/oursrc/httpdmods/mod_vhost_ldap.c
===================================================================
--- server/common/oursrc/httpdmods/mod_vhost_ldap.c	(revision 680)
+++ server/common/oursrc/httpdmods/mod_vhost_ldap.c	(revision 688)
@@ -420,23 +420,4 @@
 };
 
-char *mod_vhost_ldap_escape(apr_pool_t *p, const char *source)
-{
-    char *target = apr_palloc(p, 3 * strlen(source) + 1);
-    char *result = target;
-    for (; *source; source++) {
-	switch (*source) {
-	    case '*': case '(': case ')': case '\\':
-		sprintf(target, "\\%02hhx", *source);
-		target += 3;
-		break;
-	    default:
-		*target++ = *source;
-		break;
-	}
-    }
-    *target = '\0';
-    return result;
-}
-
 #define FILTER_LENGTH MAX_STRING_LEN
 static int mod_vhost_ldap_translate_name(request_rec *r)
@@ -456,5 +437,5 @@
     const char *dn = NULL;
     char *cgi;
-    const char *hostname = NULL, *s_hostname = NULL;
+    const char *hostname = NULL;
     int is_fallback = 0;
 
@@ -484,5 +465,5 @@
 
     hostname = r->hostname;
-    if (hostname == NULL)
+    if (hostname == NULL || hostname[0] == '\0')
 	goto null;
 
@@ -492,6 +473,10 @@
 		   "[mod_vhost_ldap.c]: translating %s", r->uri);
 
-    s_hostname = mod_vhost_ldap_escape(r->pool, hostname);
-    apr_snprintf(filtbuf, FILTER_LENGTH, "(&(%s)(|(apacheServerName=%s)(apacheServerAlias=%s)))", conf->filter, s_hostname, s_hostname);
+    struct berval hostnamebv, shostnamebv;
+    ber_str2bv(hostname, 0, 0, &hostnamebv);
+    if (ldap_bv2escaped_filter_value(&hostnamebv, &shostnamebv) != 0)
+	goto null;
+    apr_snprintf(filtbuf, FILTER_LENGTH, "(&(%s)(|(apacheServerName=%s)(apacheServerAlias=%s)))", conf->filter, shostnamebv.bv_val, shostnamebv.bv_val);
+    ber_memfree(shostnamebv.bv_val);
 
     result = util_ldap_cache_getuserdn(r, ldc, conf->url, conf->basedn, conf->scope,
