[CalendarServer-changes] [8832] CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 9 16:40:50 PST 2012


Revision: 8832
          http://trac.macosforge.org/projects/calendarserver/changeset/8832
Author:   gaya at apple.com
Date:     2012-03-09 16:40:50 -0800 (Fri, 09 Mar 2012)
Log Message:
-----------
first pass

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py
    CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
    CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py	2012-03-09 20:29:56 UTC (rev 8831)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py	2012-03-10 00:40:50 UTC (rev 8832)
@@ -40,7 +40,7 @@
     "LdapDirectoryService",
 ]
 
-import ldap
+import ldap, ldap.async
 from ldap.filter import escape_filter_chars as ldapEsc
 
 try:
@@ -468,23 +468,33 @@
 
 
     def timedSearch(self, base, scope, filterstr="(objectClass=*)",
-        attrlist=None):
+        attrlist=None, timeout=-1, sizelimit=0):
         """
         Execute an ldap.search_s( ); if it takes longer than the configured
         threshold, emit a log error.
         """
+        s = ldap.async.List( self.ldap )
+        s.startSearch( base, scope, filterStr=filterstr, attrList=attrlist, timeout=timeout, sizelimit=sizelimit, )
+        
         startTime = time.time()
         try:
-            result = self.ldap.search_s(base, scope, filterstr=filterstr,
-                attrlist=attrlist)
+            s.processResults()
+
         except ldap.SERVER_DOWN:
             self.log_error("LDAP server unavailable")
             raise HTTPError(StatusResponse(responsecode.SERVICE_UNAVAILABLE, "LDAP server unavailable"))
         except ldap.NO_SUCH_OBJECT:
-            result = []
+            pass
         except ldap.FILTER_ERROR, e:
             self.log_error("LDAP filter error: %s %s" % (e, filterstr))
-            result = []
+        except ldap.SIZELIMIT_EXCEEDED, e:
+            self.log_error("LDAP size limited exceeded: %s sizelimit %s (#results=%d)" % (e, sizelimit, len(s.allResults), ))
+        except ldap.TIMEOUT, e:
+            self.log_error("LDAP timeout %s timeout %s (#results=%d)" % (e, sizelimit, len(s.allResults), ))
+        
+        # change format, ignoring resultsType
+        result = [resultItem for resultType, resultItem in s.allResults]
+
         totalTime = time.time() - startTime
         if totalTime > self.warningThresholdSeconds:
             if filterstr and len(filterstr) > 100:

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py	2012-03-09 20:29:56 UTC (rev 8831)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py	2012-03-10 00:40:50 UTC (rev 8832)
@@ -214,7 +214,7 @@
         self._updateLock = MemcacheLock("OpenDirectoryBacker", self._updateLockPath)
         self._tmpDirAddressBookLock = MemcacheLock("OpenDirectoryBacker", self._tmpDirAddressBookLockPath)        
                 
-        # optimization so we don't have to always get create lock
+        # optimization so we don't have to always create lock
         self._triedCreateLock = False
         self._created = False
 
@@ -618,7 +618,7 @@
     
     def _getDSFilter(self, addressBookFilter):
         """
-        Convert the supplied addressbook-query into an expression tree.
+        Convert the supplied addressbook-query into a ds expression tree.
     
         @param filter: the L{Filter} for the addressbook-query to convert.
         @return: (needsAllRecords, espressionAttributes, expression) tuple
@@ -1002,7 +1002,7 @@
     @inlineCallbacks
     def vCardRecordsForAddressBookQuery(self, addressBookFilter, addressBookQuery, maxResults ):
         """
-        Get vCards for a given addressBookFilder and addressBookQuery
+        Get vCards for a given addressBookFilter and addressBookQuery
         """
     
         allRecords, filterAttributes, dsFilter  = self._getDSFilter( addressBookFilter );
@@ -1240,7 +1240,20 @@
                     self.attributes[key] = removeControlChars(values).decode("utf8")
             else:
                 self.attributes[key] = values
-                                                        
+                
+        # super needs recordname
+        recordName = self.firstValueForAttribute(dsattributes.kDSNAttrRecordName)
+        if not recordName:
+            recordName = self.firstValueForAttribute(dsattributes.kDS1AttrDistinguishedName)
+            if not recordName:
+                recordName = self.firstValueForAttribute(dsattributes.kDS1AttrLastName)
+            if not recordName:
+                recordName = self.firstValueForAttribute(dsattributes.kDS1AttrFirstName)
+            if not recordName:
+                recordName = self.firstValueForAttribute(dsattributes.kDS1AttrGeneratedUID)
+            recordAttributes[dsattributes.kDSNAttrRecordName] = recordName
+            self.attributes[dsattributes.kDSNAttrRecordName] = recordName
+
         # fill in  missing essential attributes used for filtering
         fullName = self.firstValueForAttribute(dsattributes.kDS1AttrDistinguishedName)
         if not fullName:
@@ -1506,6 +1519,7 @@
             # pyOpenDirectory always returns binary-encoded string                                       
                                                         
             for photo in self.valuesForAttribute(dsattributes.kDSNAttrJPEGPhoto):
+                photo = "".join("".join(photo.split("\r")).split("\n")) #get rid of line folding: for PHOTO
                 addUniqueProperty(vcard, Property("PHOTO", photo, params={"ENCODING": ["b",], "TYPE": ["JPEG",],}), None, dsattributes.kDSNAttrJPEGPhoto, photo)
     
     
@@ -1967,18 +1981,10 @@
     listProperties = deferredGenerator(listProperties)
     
 # utility
-#remove control characters because vCard does not support them
+#remove illegal XML
 def removeControlChars( utf8String ):
-    result = utf8String
-    for a in utf8String:
-        if '\x00' <= a <= '\x1F':
-            result = ""
-            for c in utf8String:
-                if '\x00' <= c <= '\x1F':
-                    pass 
-                else:
-                    result += c
-    #if utf8String != result: print ("changed %r to %r" % (utf8String, result))
+    result = ''.join([c for c in utf8String if c not in "\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"])
+    if utf8String != result: self.log_debug("changed %r to %r" % (utf8String, result))
     return result
 
 

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py	2012-03-09 20:29:56 UTC (rev 8831)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py	2012-03-10 00:40:50 UTC (rev 8832)
@@ -226,6 +226,41 @@
         "additionalAttributes" : [],
         "allowedAttributes" : [],
     },
+    "twistedcaldav.directory.ldapdirectorybacker.LdapDirectoryBackingService": {
+        "appleInternalServer": False,
+        "warningThresholdSeconds": 3,
+        "uri": "ldap://localhost/",
+        "tls": False,
+        "tlsCACertFile": None,
+        "tlsCACertDir": None,
+        "tlsRequireCert": None, # never, allow, try, demand, hard
+        "credentials": {
+            "dn": None,
+            "password": None,
+        },
+        "authMethod": "LDAP",
+        "rdnSchema": {
+            "base": "dc=example,dc=com",
+            "guidAttr": None,
+            "users": {
+                "rdn": "ou=People",
+                "attr": "uid", # used only to synthesize email address
+                "emailSuffix": None, # used only to synthesize email address
+                "filter": None, # additional filter for this type
+                "loginEnabledAttr" : "", # attribute controlling login
+                "loginEnabledValue" : "yes", # "True" value of above attribute
+                "calendarEnabledAttr" : "", # attribute controlling enabledForCalendaring
+                "calendarEnabledValue" : "yes", # "True" value of above attribute
+                "mapping" : { # maps internal record names to LDAP
+                    "recordName": "uid",
+                    "fullName" : "cn",
+                    "emailAddresses" : "mail",
+                    "firstName" : "givenName",
+                    "lastName" : "sn",
+                },
+            },
+        },
+    },
 }
 
 DEFAULT_CONFIG = {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120309/dfd400f5/attachment.html>


More information about the calendarserver-changes mailing list