]> andersk Git - mod-vhost-ldap.git/blobdiff - mod_vhost_ldap.c
Simplify construction of wildcard hostnames.
[mod-vhost-ldap.git] / mod_vhost_ldap.c
index 4401fa3c35e130797362d3b23697b3da166c6c10..3282e8f5f85a24af4499d36f63ae25137a90aeae 100644 (file)
@@ -483,6 +483,8 @@ start_over:
     }
 
     hostname = r->hostname;
+    if (hostname == NULL)
+       goto null;
 
 fallback:
 
@@ -505,19 +507,19 @@ fallback:
     }
 
     if ((result == LDAP_NO_SUCH_OBJECT)) {
-       char* parent_hostname = apr_pstrdup(r->pool, hostname);
-       do {
-           parent_hostname = strchr(parent_hostname + 1, '.');
-       } while (parent_hostname && parent_hostname[-1] != '*');
-       if (parent_hostname) {
-           *(--parent_hostname) = '*';
+       if (strcmp(hostname, "*") != 0) {
+           if (strncmp(hostname, "*.", 2) == 0)
+               hostname += 2;
+           hostname += strcspn(hostname, ".");
+           hostname = apr_pstrcat(r->pool, "*", hostname, NULL);
            ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
                          "[mod_vhost_ldap.c] translate: "
                          "virtual host not found, trying wildcard %s",
-                         parent_hostname);
-           hostname = parent_hostname;
+                         hostname);
            goto fallback;
        }
+
+    null:
        if (conf->fallback && (is_fallback++ <= 0)) {
            ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
                          "[mod_vhost_ldap.c] translate: "
This page took 0.208522 seconds and 4 git commands to generate.