

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in net.sourceforge.lists.courier-maildrop[maildropl] ldap fallback patch| From | Sent On | Attachments |
|---|---|---|
| Eric AUGE | Aug 2, 2002 6:46 am | .patch |
| Sam Varshavchik | Aug 5, 2002 8:29 pm | |
| Devin Rubia | Aug 6, 2002 7:41 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [maildropl] ldap fallback patch | Actions... |
|---|---|---|
| From: | Eric AUGE (eric...@cw.com) | |
| Date: | Aug 2, 2002 6:46:03 am | |
| List: | net.sourceforge.lists.courier-maildrop | |
| Attachments: | ||
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi Sam,
I sent you a mail few days ago, about a quick patch i've done to allow 'hostname' keyword to handle more than one server in the LDAP part of the code. (i.e. hostname ldapserv1,ldapserv2,ldapserv3,ldapserv4).
This patch adds a fallback on the next server in the list if the previous
one doesn't answer and if timeout elapsed, the code browse the server list
'retry' times before returning 'user unknown' (new keyword in
maildropldap.config -> 'retry').
old mail:
[snipped] ... I just did a small patch for 1.4.0 version, which provides the ability to have ... hostname ldap1.mydomain.com,ldap2.mydomain.com,ldap3.mydomain.com ... retry 3 ...
in the maildropldap.config file.
which allows the ldap code part to fallback on another LDAP server if the search timeouted on one server. The retry is how many times it need to browse the servers list before saying that all servers are dead.
I hope this could help and be part of maildrop code. Many thanks, ... [snipped]
I hope it could help some other maildrop's users, that's why i'm sending it to the maildrop users list.
You can contact me if any questions/problems/comments/etc... Thanks.
Best Regards,
Eric.
- ---- Eric AUGE
NB: attached the patch. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) Comment: For info see http://www.gnupg.org
iD8DBQE9SothL/U5psk9l1gRAmzZAKDSoBXaYiIXxRb9+g/nsPyf9m7BoACgn65A bjPiUL66R9CCHsK4Q6Ruq1w= =H0Xz -----END PGP SIGNATURE-----
diff -r -u --exclude='Makefile*' --exclude='aclocal*' --exclude='config.h*'
--exclude='configure*' maildrop-1.4.0/maildrop/mdldap.c
maildrop-1.4.0-fb/maildrop/mdldap.c
--- maildrop-1.4.0/maildrop/mdldap.c 2002-06-09 17:26:19.000000000 +0200
+++ maildrop-1.4.0-fb/maildrop/mdldap.c 2002-07-31 13:48:44.000000000 +0200
@@ -16,17 +16,46 @@
LDAPMessage *entry;
char *tmp_filter,*filter;
char *dn;
- char **values;
- int size;
+ char **values,**list=NULL,**ptr=NULL;
+ int size,version,rc,rtr=1;
mdldaprec *rec = NULL;
int needbind = 0;
char *mail_filter;
struct timeval tv;
- ldap = ldap_init(cfg->hostname,cfg->port); - if ( !ldap ) + version = LDAP_VERSION3; + if(ldap_set_option(NULL,LDAP_OPT_PROTOCOL_VERSION, &version) == -1) { + perror("ldap_set_option()"); + return NULL; + } + + /* parsing the list of hostname */ + list = parse_ldapserv(cfg->hostname); + + if (!list) return NULL;
+ ptr=list; + +/* label for going back if timeouted */ +retry: + + if (!*ptr && (rtr >= cfg->retry) && (cfg->retry != 0)) { + free_list(list); + return NULL; + } + + if ((!*ptr && (cfg->retry == 0)) || (!*ptr && (rtr < cfg->retry))) { + rtr++; + ptr=list; + } + + ldap = ldap_init(*ptr,cfg->port); + if ( !ldap ) { + free_list(list); + return NULL; + } + if ( cfg->binddn && cfg->bindpw ) { needbind = 1; @@ -66,7 +95,10 @@ ldap_unbind(ldap); free(mail_filter); free(filter); - return NULL; + fprintf(stderr,"%s timeouted..\n",*ptr); + ptr++; + goto retry; + /* return NULL; */ }
entry = ldap_first_entry(ldap,result); @@ -77,6 +109,7 @@ ldap_unbind(ldap); free(mail_filter); free(filter); + free_list (list); return NULL; }
@@ -149,6 +182,7 @@
free(mail_filter); free(filter); + free_list(list);
return rec;
}
diff -r -u --exclude='Makefile*' --exclude='aclocal*' --exclude='config.h*'
--exclude='configure*' maildrop-1.4.0/maildrop/mdldapconfig.c
maildrop-1.4.0-fb/maildrop/mdldapconfig.c
--- maildrop-1.4.0/maildrop/mdldapconfig.c 2001-01-28 20:59:20.000000000 +0100
+++ maildrop-1.4.0-fb/maildrop/mdldapconfig.c 2002-07-31 13:48:03.000000000
+0200
@@ -35,6 +35,8 @@
cfg->timeout = LDAP_DEFAULT_TIMEOUT;
+ cfg->retry = LDAP_DEFAULT_RETRY; + while ( fgets(buf,1024,fp) ) { sscanf(buf,"%s %s",var,val); @@ -72,6 +74,9 @@
if ( !strcasecmp(var,"timeout") ) cfg->timeout = atoi(val); + + if ( !strcasecmp(var,"retry") ) + cfg->retry = atoi(val);
if ( !strcasecmp(var,"default_uidnumber") ) cfg->default_uidnumber = atoi(val); @@ -134,3 +139,67 @@
*cfg = NULL;
}
+
+/*
+ * ldap fallback parsing function
+ * return a char ** list of hostname
+ * or NULL if it fails.
+ * the Field separator is ','
+ */
+
+char **parse_ldapserv(char *line) {
+ char **retme=NULL,**yaptr=NULL,**tmpret;
+ char *ptr=NULL,*copy=NULL;
+ int i=0,cnt=0;
+
+ if (!line)
+ return retme;
+
+ ptr=line;
+ while(*ptr++)
+ if (*ptr == ',')
+ cnt++;
+
+ if(!cnt) {
+ fprintf(stderr,"count is null\n");
+ retme=(char **)malloc(2*sizeof(char *));
+ *retme=strdup(line);
+ *(retme+1)=NULL;
+ return retme;
+ }
+
+ ptr=NULL;
+ retme=(char **)malloc((++cnt)+1*sizeof(char *));
+ if (!retme)
+ return retme;
+
+ /* filling of NULL values */
+ for(i=0;i<cnt+1;i++)
+ *(retme+i)=NULL;
+
+ yaptr=retme;
+ copy=strdup(line);
+
+ while((ptr=strchr(copy,','))!=NULL) {
+ *ptr='\0';
+ *retme=copy;
+ copy=ptr+1;
+ *retme++;
+ *retme=copy;
+ }
+ fprintf(stderr,"end of parse_ldapserv\n");
+ return yaptr;
+}
+
+int free_list(char **list) {
+ char **save;
+
+ save=list;
+ if (!list)
+ return (-1);
+
+ free(*list);
+
+ free (save);
+ return (0);
+}
diff -r -u --exclude='Makefile*' --exclude='aclocal*' --exclude='config.h*'
--exclude='configure*' maildrop-1.4.0/maildrop/mdldapconfig.h
maildrop-1.4.0-fb/maildrop/mdldapconfig.h
--- maildrop-1.4.0/maildrop/mdldapconfig.h 2001-01-28 20:59:20.000000000 +0100
+++ maildrop-1.4.0-fb/maildrop/mdldapconfig.h 2002-07-30 16:29:59.000000000
+0200
@@ -16,6 +16,7 @@
#define LDAP_DEFAULT_HOMEDIRECTORY_ATTR "homedirectory"
#define LDAP_DEFAULT_QUOTA_ATTR "quota"
#define LDAP_DEFAULT_TIMEOUT 5
+#define LDAP_DEFAULT_RETRY 3
typedef struct { char *hostname; @@ -38,9 +39,12 @@ int default_gidnumber;
int timeout; + int retry; } mdldapconfig;
mdldapconfig *get_ldap_config(char *configfile); +char **parse_ldapserv(char *line); +int free_list(char **list);
#ifdef __cplusplus }








.patch