]> andersk Git - mod-vhost-ldap.git/commitdiff
Use built-in ldap_bv2escaped_filter_value instead of a custom escaping function.
authorAnders Kaseorg <andersk@mit.edu>
Sat, 8 Mar 2008 00:21:43 +0000 (00:21 +0000)
committerAnders Kaseorg <andersk@mit.edu>
Sat, 8 Mar 2008 00:21:43 +0000 (00:21 +0000)
git-svn-id: svn://scripts.mit.edu/server/common/oursrc/httpdmods@688 db9d59ff-b01e-0410-9b1a-cd9a8c06840f

mod_vhost_ldap.c

index 3282e8f5f85a24af4499d36f63ae25137a90aeae..19fbdf1b3c564711a435ac5d22cb29c9eb3bde90 100644 (file)
@@ -419,25 +419,6 @@ command_rec mod_vhost_ldap_cmds[] = {
     {NULL}
 };
 
-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)
 {
@@ -455,7 +436,7 @@ static int mod_vhost_ldap_translate_name(request_rec *r)
     int result = 0;
     const char *dn = NULL;
     char *cgi;
-    const char *hostname = NULL, *s_hostname = NULL;
+    const char *hostname = NULL;
     int is_fallback = 0;
 
     reqc =
@@ -483,7 +464,7 @@ start_over:
     }
 
     hostname = r->hostname;
-    if (hostname == NULL)
+    if (hostname == NULL || hostname[0] == '\0')
        goto null;
 
 fallback:
@@ -491,8 +472,12 @@ fallback:
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
                   "[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,
                                       attributes, filtbuf, &dn, &vals);
This page took 0.038063 seconds and 5 git commands to generate.