martin: server/imapd kolab-ldap.patch,NONE,1.1 Makefile,1.13,1.14

cvs at intevation.de cvs at intevation.de
Thu Jul 15 21:45:32 CEST 2004


Author: martin

Update of /kolabrepository/server/imapd
In directory doto:/tmp/cvs-serv10197

Modified Files:
	Makefile 
Added Files:
	kolab-ldap.patch 
Log Message:
Martin K.: LDAP support in Cyrus IMAPD. Required for flexible UID. Fully workable version. Needs more testing


--- NEW FILE: kolab-ldap.patch ---
--- ./lib/imapoptions.orig	2004-07-12 14:18:31.000000000 +0200
+++ ./lib/imapoptions	2004-07-12 14:19:22.000000000 +0200
@@ -823,7 +823,7 @@
    mailbox hierarchy.  The default is to use the netnews separator
    character '.'. */
 
-{ "virtdomains", "off", ENUM("off", "userid", "on") }
+{ "virtdomains", "off", ENUM("off", "userid", "ldap", "on") }
 /* Enable virtual domain support.  If enabled, the user's domain will
    be determined by splitting a fully qualified userid at the last '@'
    or '%' symbol.  If the userid is unqualified, and the virtdomains
--- ./lib/imapopts.c.orig	2004-07-12 14:15:09.000000000 +0200
+++ ./lib/imapopts.c	2004-07-13 16:31:09.580924368 +0200
@@ -183,7 +183,7 @@
   { IMAPOPT_USERPREFIX, "userprefix", 0, {(void *)("Other Users")}, OPT_STRING, {  { NULL, IMAP_ENUM_ZERO } } },
   { IMAPOPT_UNIX_GROUP_ENABLE, "unix_group_enable", 0, {(void*)1}, OPT_SWITCH, {  { NULL, IMAP_ENUM_ZERO } } },
   { IMAPOPT_UNIXHIERARCHYSEP, "unixhierarchysep", 0, {(void*)0}, OPT_SWITCH, {  { NULL, IMAP_ENUM_ZERO } } },
-  { IMAPOPT_VIRTDOMAINS, "virtdomains", 0, {(void *)(IMAP_ENUM_VIRTDOMAINS_OFF)}, OPT_ENUM, { { "off" , IMAP_ENUM_VIRTDOMAINS_OFF }, { "userid" , IMAP_ENUM_VIRTDOMAINS_USERID }, { "on" , IMAP_ENUM_VIRTDOMAINS_ON },  { NULL, IMAP_ENUM_ZERO } } },
+  { IMAPOPT_VIRTDOMAINS, "virtdomains", 0, {(void *)(IMAP_ENUM_VIRTDOMAINS_OFF)}, OPT_ENUM, { { "off" , IMAP_ENUM_VIRTDOMAINS_OFF }, { "userid" , IMAP_ENUM_VIRTDOMAINS_USERID }, { "ldap" , IMAP_ENUM_VIRTDOMAINS_LDAP }, { "on" , IMAP_ENUM_VIRTDOMAINS_ON },  { NULL, IMAP_ENUM_ZERO } } },
 
   { IMAPOPT_LAST, NULL, 0, { NULL }, OPT_NOTOPT, {  { NULL, IMAP_ENUM_ZERO } } }
 
--- ./lib/imapopts.h.orig	2004-07-12 14:16:36.000000000 +0200
+++ ./lib/imapopts.h	2004-07-13 16:31:09.580924368 +0200
@@ -185,6 +185,7 @@
 
   IMAP_ENUM_VIRTDOMAINS_OFF = 0,
   IMAP_ENUM_VIRTDOMAINS_USERID,
+  IMAP_ENUM_VIRTDOMAINS_LDAP,
   IMAP_ENUM_VIRTDOMAINS_ON,
 
 };
--- ./imap/global.c.orig	2004-07-12 14:25:03.000000000 +0200
+++ ./imap/global.c	2004-07-13 17:31:50.780377912 +0200
@@ -52,6 +52,9 @@
 #include <netinet/in.h>
 #include <sys/stat.h>
 
+#include <ldap.h>
+#include <lber.h>
+
 #if HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -349,6 +352,18 @@
     char *domain = NULL;
     int len = strlen(user);
     char buf[81];
+    const char *uri;
+    const char *base;
+    const char *binddn;
+    const char *bindpw;
+    struct timeval timeout;
+    char filter[255];
+    LDAP *handle;
+    LDAPMessage *res;
+    LDAPMessage *entry;
+    char ** vals;
+
+    int rc;
 
     /* check for domain */
     if (config_virtdomains &&
@@ -367,6 +382,37 @@
     }
 
     if (config_virtdomains) {
+        if (config_virtdomains == IMAP_ENUM_VIRTDOMAINS_LDAP) {
+           uri = config_getstring(IMAPOPT_LDAP_URI);
+           base = config_getstring(IMAPOPT_LDAP_BASE);
+           binddn = config_getstring(IMAPOPT_LDAP_BIND_DN);
+           bindpw = config_getstring(IMAPOPT_LDAP_PASSWORD);
+           timeout.tv_sec = config_getint(IMAPOPT_LDAP_TIME_LIMIT);
+           timeout.tv_usec = 0;
+	   sprintf(filter, "(uid=%s)", user);
+           rc = ldap_initialize(&handle, uri);
+	   if (rc != LDAP_SUCCESS) {
+                syslog(LOG_ERR, "ldap_initialize failed (%s)", uri);
+           } else {
+	        rc = ldap_simple_bind_s(handle, binddn, bindpw);
+	        if (rc != LDAP_SUCCESS) {
+                     syslog(LOG_ERR, "ldap_simple_bind() failed %d (%s)", rc, ldap_err2string(rc));
+                     ldap_unbind(handle);
+	        } else {
+	             rc = ldap_search_st(handle, base, LDAP_SCOPE_SUBTREE, filter, NULL, 0, &timeout, &res);
+                     if (rc != LDAP_SUCCESS) {
+                          syslog(LOG_ERR, "ldap_search_st failed %d (%s)", rc, ldap_err2string(rc));
+                     } else {
+	                  if ( (entry = ldap_first_entry(handle, res)) != NULL ) {
+			       // read mail attribute from entry
+			       if ( (vals = ldap_get_values(handle, entry, "mail")) ) {
+  				    if (strchr(vals[0], '@')) return auth_canonifyid(vals[0], 0) ;
+			       }			       	
+   	                  }
+                     }
+                }
+           }
+        }
 	if (domain) {
 	    if (config_defdomain && !strcasecmp(config_defdomain, domain+1)) {
 		*domain = '\0'; /* trim the default domain */
--- ./configure.orig	2004-07-13 17:06:40.865919800 +0200
+++ ./configure	2004-07-13 17:06:52.175200528 +0200
@@ -14348,7 +14348,7 @@
 done
 
 IMAP_COM_ERR_LIBS="${COM_ERR_LIBS}"
-IMAP_LIBS="${LIB_SASL} ${LIBS}"
+IMAP_LIBS="${LIB_SASL} -lldap -llber ${LIBS}"
 
 
 

Index: Makefile
===================================================================
RCS file: /kolabrepository/server/imapd/Makefile,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Makefile	15 Jul 2004 14:37:22 -0000	1.13
+++ Makefile	15 Jul 2004 19:45:30 -0000	1.14
@@ -15,10 +15,12 @@
  
 all: imapd-$(VERSION)-$(RELEASE).src.rpm
 	$(RPM) -ihv imapd-$(VERSION)-$(RELEASE).src.rpm
+
 	cp $(KOLABCVSDIR)/imapd.annotate.patch $(KOLABRPMSRC)/imapd/
-	cp $(KOLABCVSDIR)/kolab.patch $(KOLABRPMSRC)/imapd/
-        
-	cd $(KOLABRPMSRC)/imapd && patch < $(KOLABCVSDIR)/kolab.patch && $(RPM) -ba imapd.spec --define 'with_group yes' --define 'with_vhost_hack yes' --define 'with_annotate yes'
+	cp $(KOLABCVSDIR)/kolab.patch $(KOLABRPMSRC)/imapd/           # Patch for imapd.spec
+	cp $(KOLABCVSDIR)/kolab-ldap.patch $(KOLABRPMSRC)/imapd/      
+
+	cd $(KOLABRPMSRC)/imapd && patch < $(KOLABCVSDIR)/kolab.patch && $(RPM) -ba imapd.spec --define 'with_group yes' --define 'with_vhost_hack yes' --define 'with_annotate yes' --define 'with_ldap yes'
 
 imapd-$(VERSION)-$(RELEASE).src.rpm:
 	wget -c $(KOLABPKGURI)/imapd-$(VERSION)-$(RELEASE).src.rpm





More information about the commits mailing list