All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ondrej Valousek <webserv@s3group.cz>
To: Ian Kent <ikent@redhat.com>
Cc: "autofs@linux.kernel.org" <autofs@linux.kernel.org>
Subject: Re: autofs misbehaves when DNS RRs returns more ldap servers
Date: Fri, 07 Jan 2011 14:12:58 +0100	[thread overview]
Message-ID: <4D27115A.9010805@s3group.cz> (raw)
In-Reply-To: <1294322864.2852.3.camel@perseus>


[-- Attachment #1.1: Type: text/plain, Size: 482 bytes --]

  On 06.01.2011 15:07, Ian Kent wrote:
> Thanks for the suggestions.
> I'm still on leave so things are still going slowly for now, but I'll
> get to it.
Hi Ian,

Please find the attached patch which fixes the problem for me.
I also changed the "dclist" structure definition from:

struct dclist {
         time_t expire;
         const char *uri;
};

into:

struct dclist {
         time_t expire;
         char **uri;
         int cnt;
};

Hope you'll find it useful :-) .
Ondrej

[-- Attachment #1.2: Type: text/html, Size: 1090 bytes --]

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 4286 bytes --]

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);

[-- Attachment #3: Type: text/plain, Size: 140 bytes --]

_______________________________________________
autofs mailing list
autofs@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/autofs

  reply	other threads:[~2011-01-07 13:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-27 12:36 autofs misbehaves when DNS RRs returns more ldap servers Ondrej Valousek
2010-12-28  2:24 ` Ian Kent
2011-01-03 10:14   ` Ondrej Valousek
2011-01-06  7:09     ` Ian Kent
2011-01-06  8:48       ` Ondrej Valousek
2011-01-06 14:07         ` Ian Kent
2011-01-07 13:12           ` Ondrej Valousek [this message]
2011-01-11  6:32             ` Ian Kent
2011-02-02 14:40             ` Ondrej Valousek
2011-02-08  3:56               ` Ian Kent
2011-02-08  9:16                 ` Ondrej Valousek
2011-02-09  3:50                   ` Ian Kent
2011-02-09 14:57                     ` Wolfe, Allan
2011-02-09 16:40                       ` Ondrej Valousek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D27115A.9010805@s3group.cz \
    --to=webserv@s3group.cz \
    --cc=autofs@linux.kernel.org \
    --cc=ikent@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.