diff -u modules.old/dclist.c modules/dclist.c --- modules.old/dclist.c 2010-07-15 10:40:49.000000000 +0200 +++ modules/dclist.c 2011-01-07 12:33:50.000000000 +0100 @@ -545,8 +545,12 @@ void free_dclist(struct dclist *dclist) { - if (dclist->uri) - free((void *) dclist->uri); + if (dclist->uri){ + for(; dclist->cnt > 0; dclist->cnt--){ + free(dclist->uri[dclist->cnt-1]); + } + } + free(dclist->uri); free(dclist); } @@ -599,8 +603,8 @@ char buf[MAX_ERR_BUF]; char *dn_uri, *esc_uri; char *domain; - char *list; - int numdcs; + char **list; + int tot_numdcs = 0; int ret; if (strcmp(uri, "ldap:///") && strcmp(uri, "ldaps:///")) { @@ -679,10 +683,11 @@ list = NULL; for (ludp = &ludlist; *ludp != NULL;) { LDAPURLDesc *lud = *ludp; - size_t req_len, len; + size_t req_len; char *request = NULL; - char *tmp; - int i; + char **tmplist; + int start,i; + int numdcs; if (!lud->lud_dn && !lud->lud_dn[0] && (!lud->lud_host || !lud->lud_host[0])) { @@ -726,36 +731,48 @@ dclist_mutex_unlock(); free(request); - len = strlen(lud->lud_scheme); - len += sizeof("://"); - len *= numdcs; +// len *= numdcs; + start = tot_numdcs; + tot_numdcs += numdcs; for (i = 0; i < numdcs; i++) { if (dcs[i].ttl > 0 && dcs[i].ttl < min_ttl) min_ttl = dcs[i].ttl; - len += strlen(dcs[i].hostname); - if (dcs[i].port > 0) - len += sizeof(":65535"); } - tmp = realloc(list, len); - if (!tmp) { + tmplist = realloc(list, sizeof(char *)*tot_numdcs+1); + if (!tmplist) { char *estr = strerror_r(errno, buf, MAX_ERR_BUF); error(logopt, "realloc: %s", estr); goto out_error; } + list = tmplist; - if (!list) - memset(tmp, 0, len); - else - strcat(tmp, " "); +// if (!list) +// memset(tmp, 0, len); +// else +// strcat(tmp, " "); for (i = 0; i < numdcs; i++) { - if (i > 0) - strcat(tmp, " "); - strcat(tmp, lud->lud_scheme); + char *tmp; + size_t len; + + len = strlen(lud->lud_scheme); + len += sizeof("://"); + len += strlen(dcs[i].hostname); + if (dcs[i].port > 0) + len += sizeof(":65535"); + tmp = malloc(sizeof(char)*len+1); + if( !tmp ){ + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); + error(logopt, "malloc: %s", estr); + goto out_error; + } + strcpy(tmp, lud->lud_scheme); strcat(tmp, "://"); strcat(tmp, dcs[i].hostname); + list[start++] = tmp; + list[start] = 0; if (dcs[i].port > 0) { char port[7]; ret = snprintf(port, 7, ":%d", dcs[i].port); @@ -767,7 +784,6 @@ strcat(tmp, port); } } - list = tmp; *ludp = lud->lud_next; ber_memfree(domain); @@ -777,12 +793,18 @@ dclist->expire = time(NULL) + min_ttl; dclist->uri = list; + dclist->cnt = tot_numdcs; return dclist; out_error: - if (list) - free(list); + if (list){ + char *tmp = list[0]; + while (tmp){ + free(tmp); + } + free(list); + } if (domain) ber_memfree(domain); ldap_free_urldesc(ludlist); diff -u modules.old/lookup_ldap.c modules/lookup_ldap.c --- modules.old/lookup_ldap.c 2010-07-15 10:40:49.000000000 +0200 +++ modules/lookup_ldap.c 2011-01-07 12:40:11.000000000 +0100 @@ -571,9 +571,8 @@ if (!strstr(this->uri, ":///")) uri = strdup(this->uri); else { - if (dclist) - uri = strdup(dclist->uri); - else { + int i = 0; + if (!dclist){ struct dclist *tmp; tmp = get_dc_list(logopt, this->uri); if (!tmp) { @@ -581,8 +580,17 @@ continue; } dclist = tmp; - uri = strdup(dclist->uri); } + while(dclist->uri[i] != NULL){ + uri = dclist->uri[i++]; + debug(logopt, "trying server uri %s", uri); + ldap = connect_to_server(logopt, uri, ctxt); + if (ldap) { + info(logopt, "connected to uri %s", uri); + break; + } + } + if(ldap) break; } if (!uri) { if (dclist) { @@ -644,9 +652,12 @@ } uris_mutex_lock(ctxt); - if (ctxt->dclist) - uri = strdup(ctxt->dclist->uri); - else if (ctxt->uri) + if (ctxt->dclist){ +/* this is probably wrong - not what we want */ +// uri = strdup(ctxt->dclist->uri); + uris_mutex_unlock(ctxt); + goto find_server; + } else if (ctxt->uri) uri = strdup(ctxt->uri->uri); else { uris_mutex_unlock(ctxt);