[CalendarServer-changes] [8855] CalendarServer/branches/users/gaya/ldapdirectorybacker

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 13 15:10:40 PDT 2012


Revision: 8855
          http://trac.macosforge.org/projects/calendarserver/changeset/8855
Author:   gaya at apple.com
Date:     2012-03-13 15:10:39 -0700 (Tue, 13 Mar 2012)
Log Message:
-----------
cleanup std config

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

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist	2012-03-13 21:12:22 UTC (rev 8854)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest.plist	2012-03-13 22:10:39 UTC (rev 8855)
@@ -1144,8 +1144,24 @@
                 <!-- user vCards  -->
 				<key>people</key>
 				<dict>
+                    <key>rdn</key>
+                    <string>ou=people</string>
+                    <key>filter</key>
+                    <string></string>
+                    <!-- map from ab query to indexed ldap attribute.  If unindexed, too slow.  -->
+                    <key>vcardPropToLdapAttrMap</key>
+                    <dict>
+                        <key>FN</key>
+                        <string>cn</string>
+                        <key>EMAIL</key>
+                        <string>mail</string>
+                        <key>TEL</key>
+                        <string>telephoneNumber</string>
+                        <key>UID</key>
+                        <string>appleDSID</string>
+                    </dict>
                     <!-- map ldap attributes to ds attribute types.  -->
-					<key>ldapDSAttrMap</key>
+					<key>ldapAttrToDSAttrMap</key>
 					<dict>
 						<key>givenName</key>
 						<string>FirstName</string>
@@ -1201,56 +1217,7 @@
 						<key>appleManager</key>
 						<string>dsAttrTypeNative:appleManager</string>
 					</dict>
-					<key>rdn</key>
-					<string>ou=people</string>
-					<key>filter</key>
-					<string></string>
-                    <!-- map from ab query to indexed ldap attribute.  If unindexed, too slow.  -->
-					<key>searchMap</key>
-					<dict>
-						<key>FN</key>
-						<string>cn</string>
-						<key>EMAIL</key>
-						<string>mail</string>
-						<key>TEL</key>
-						<string>telephoneNumber</string>
-						<key>UID</key>
-						<string>appleDSID</string>
-					</dict>
 				</dict>
-                <!-- people vCards for another server.  Unused  -->
-				<key>people - 2</key>
-				<dict>
-					<key>ldapDSAttrMap</key>
-					<dict>
-						<key>givenName</key>
-						<string>FirstName</string>
-						<key>sn</key>
-						<string>LastName</string>
-						<key>cn</key>
-						<array>
-							<string>RealName</string>
-							<string>RecordName</string>
-						</array>
-						<key>mail</key>
-						<string>EMailAddress</string>
-						<key>uid</key>
-						<string>GeneratedUID</string>
-					</dict>
-					<key>rdn</key>
-					<string>ou=People</string>
-					<key>filter</key>
-					<string></string>
-					<key>searchMap</key>
-					<dict>
-						<key>FN</key>
-						<string>cn</string>
-						<key>EMAIL</key>
-						<string>mail</string>
-						<key>UID</key>
-						<string>uid</string>
-					</dict>
-				</dict>
                 <!-- mailing list vCards.  Should mark as "company" or use vCard 4.0 types  -->
 				<key>distribution list</key>
 				<dict>
@@ -1260,7 +1227,7 @@
 					<string>(objectClass=appleGroup)</string>
 					<key>getAllAttributes</key>
 					<false/>
-					<key>searchMap</key>
+					<key>vcardPropToLdapAttrMap</key>
 					<dict>
 						<key>EMAIL</key>
 						<string>appleGroupEmail</string>
@@ -1269,7 +1236,7 @@
 						<key>UID</key>
 						<string>appleDSID</string>
 					</dict>
-					<key>ldapDSAttrMap</key>
+					<key>ldapAttrToDSAttrMap</key>
 					<dict>
 						<key>cn</key>
 						<string>RecordName</string>
@@ -1286,10 +1253,42 @@
 						<string>EMailAddress</string>
 					</dict>
 				</dict>
+                <!-- people vCards for another server.  Unused
+                <key>people - 2</key>
+                <dict>
+                    <key>ldapAttrToDSAttrMap</key>
+                    <dict>
+                        <key>givenName</key>
+                        <string>FirstName</string>
+                        <key>sn</key>
+                        <string>LastName</string>
+                        <key>cn</key>
+                        <array>
+                            <string>RealName</string>
+                            <string>RecordName</string>
+                        </array>
+                        <key>mail</key>
+                        <string>EMailAddress</string>
+                        <key>uid</key>
+                        <string>GeneratedUID</string>
+                    </dict>
+                    <key>rdn</key>
+                    <string>ou=People</string>
+                    <key>filter</key>
+                    <string></string>
+                    <key>vcardPropToLdapAttrMap</key>
+                    <dict>
+                        <key>FN</key>
+                        <string>cn</string>
+                        <key>EMAIL</key>
+                        <string>mail</string>
+                        <key>UID</key>
+                        <string>uid</string>
+                    </dict>
+                </dict>
+                -->
 			</dict>
 		</dict>
-
    </dict>
-
   </dict>
 </plist>

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py	2012-03-13 21:12:22 UTC (rev 8854)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectory.py	2012-03-13 22:10:39 UTC (rev 8855)
@@ -220,7 +220,7 @@
         # config.
         attrSet = set()
 
-        if self.rdnSchema["guidAttr"]:
+        if self.rdnSchema.get("guidAttr"):
             attrSet.add(self.rdnSchema["guidAttr"])
         for recordType in self.recordTypes():
             if self.rdnSchema[recordType]["attr"]:
@@ -239,7 +239,7 @@
             attrSet.add(self.groupSchema["nestedGroupsAttr"])
         if self.groupSchema["memberIdAttr"]:
             attrSet.add(self.groupSchema["memberIdAttr"])
-        if self.rdnSchema["users"]["loginEnabledAttr"]:
+        if self.rdnSchema.get("users") and self.rdnSchema["users"]["loginEnabledAttr"]:
             attrSet.add(self.rdnSchema["users"]["loginEnabledAttr"])
         if self.resourceSchema["resourceInfoAttr"]:
             attrSet.add(self.resourceSchema["resourceInfoAttr"])
@@ -489,8 +489,10 @@
             self.log_error("LDAP filter error: %s %s" % (e, filterstr))
         except ldap.SIZELIMIT_EXCEEDED, e:
             self.log_error("LDAP size limited exceeded: %s sizelimit %s (#results=%d)" % (e, sizelimit, len(s.allResults), ))
+        except ldap.TIMELIMIT_EXCEEDED, e:
+            self.log_error("LDAP timeout %s timeout %s (#results=%d)" % (e, timeout, len(s.allResults), ))
         except ldap.TIMEOUT, e:
-            self.log_error("LDAP timeout %s timeout %s (#results=%d)" % (e, sizelimit, len(s.allResults), ))
+            self.log_error("LDAP timeout %s (#results=%d)" % (e, len(s.allResults), ))
         
         # change format, ignoring resultsType
         result = [resultItem for resultType, resultItem in s.allResults]

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py	2012-03-13 21:12:22 UTC (rev 8854)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py	2012-03-13 22:10:39 UTC (rev 8855)
@@ -65,10 +65,10 @@
                 "queryTypes": ("people",),
                 "people": {
                     "rdn":"ou=people",
-                    "searchMap" : { # maps vCard properties to searchable ldap attributes
+                    "vcardPropToLdapAttrMap" : { # maps vCard properties to searchable ldap attributes
                         "FN" : "cn",
                      },
-                    "ldapDSAttrMap" : { # maps ldap attributes to ds record types
+                    "ldapAttrToDSAttrMap" : { # maps ldap attributes to ds record types
                         "cn" : "dsAttrTypeStandard:RealName",
                      },
                 },
@@ -108,8 +108,8 @@
         # or we could just require dsAttrTypeStandard: prefix in the plist
         rdnSchema = params["rdnSchema"];
         for queryType in rdnSchema["queryTypes"]:
-            ldapDSAttrMap = rdnSchema[queryType]["ldapDSAttrMap"]
-            for ldapAttrName, dsAttrNames in ldapDSAttrMap.iteritems():
+            ldapAttrToDSAttrMap = rdnSchema[queryType]["ldapAttrToDSAttrMap"]
+            for ldapAttrName, dsAttrNames in ldapAttrToDSAttrMap.iteritems():
                 if not isinstance(dsAttrNames, list):
                     dsAttrNames = [dsAttrNames,]
                 
@@ -122,9 +122,9 @@
                 
                 # not needed, but tests code paths
                 if len(normalizedDSAttrNames) > 1:
-                    ldapDSAttrMap[ldapAttrName] = normalizedDSAttrNames
+                    ldapAttrToDSAttrMap[ldapAttrName] = normalizedDSAttrNames
                 else:
-                    ldapDSAttrMap[ldapAttrName] = normalizedDSAttrNames[0]
+                    ldapAttrToDSAttrMap[ldapAttrName] = normalizedDSAttrNames[0]
                
                 
         self.log_debug("_actuallyConfigure after clean: params=%s" % (params,))
@@ -173,7 +173,7 @@
          succeed(None)
                         
 
-    def _ldapAttributesForAddressBookQuery(self, addressBookQuery, ldapDSAttrMap ):
+    def _ldapAttributesForAddressBookQuery(self, addressBookQuery, ldapAttrToDSAttrMap ):
                         
         etagRequested, propertyNames = propertiesInAddressBookQuery( addressBookQuery )
         
@@ -181,13 +181,13 @@
             propertyNames = None
         
         if not propertyNames:
-            result = ldapDSAttrMap.keys()
+            result = ldapAttrToDSAttrMap.keys()
             self.log_debug("_ldapAttributesForAddressBookQuery returning all props=%s" % result)
         
         else:
             queryAttributes = []
             for prop in propertyNames:
-                searchAttr = ldapDSAttrMap.get()
+                searchAttr = ldapAttrToDSAttrMap.get()
                 if searchAttr:
                     print("adding attributes %r" % searchAttr)
                     if not isinstance(searchAttr, tuple):
@@ -217,21 +217,22 @@
         for queryType in self.rdnSchema["queryTypes"]:
 
             queryMap = self.rdnSchema[queryType]
-            searchMap = queryMap["searchMap"]
-            ldapDSAttrMap = queryMap["ldapDSAttrMap"]
+            vcardPropToLdapAttrMap = queryMap["vcardPropToLdapAttrMap"]
+            ldapAttrToDSAttrMap = queryMap["ldapAttrToDSAttrMap"]
 
-            allRecords, filterAttributes, dsFilter  = dsFilterFromAddressBookFilter( addressBookFilter, searchMap );
+            allRecords, filterAttributes, dsFilter  = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToLdapAttrMap );
             self.log_debug("vCardRecordsForAddressBookQuery: queryType=\"%s\" LDAP allRecords=%s, filterAttributes=%s, query=%s" % (queryType, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
     
             
             if allRecords:
                 dsFilter = None #  None expression == all Records
                 
-            clear = not allRecords and not dsFilter
+            # could stop query for all, but OK because of post filtering.
+            # clear = not allRecords and not dsFilter
             clear = False
                     
             if not clear:
-                queryAttributes = self._ldapAttributesForAddressBookQuery( addressBookQuery, ldapDSAttrMap )
+                queryAttributes = self._ldapAttributesForAddressBookQuery( addressBookQuery, ldapAttrToDSAttrMap )
                 attributes = filterAttributes + queryAttributes if queryAttributes else None
                 self.log_debug("vCardRecordsForAddressBookQuery: attributes=%s, queryAttributes=%s" % (attributes, queryAttributes,))
                 
@@ -242,7 +243,8 @@
                 rdn = queryMap["rdn"]
                 base =  ldap.dn.str2dn(rdn) + self.base
                 
-                #add additonal filter from config
+                filterstr = "(cn=*)"    # all query
+                #add additional filter from config
                 queryFilter = queryMap.get("filter")
                 if dsFilter and queryFilter:
                     filterstr = "(&%s%s)" % (queryFilter, dsFilter.generate())
@@ -274,7 +276,7 @@
                             ldapAttributeValues = [attr for attr in ldapAttributeValues if len(attr)]
                             
                             if len(ldapAttributeValues):
-                                dsAttributeNames = ldapDSAttrMap.get(ldapAttributeName)
+                                dsAttributeNames = ldapAttrToDSAttrMap.get(ldapAttributeName)
                                 if dsAttributeNames:
                                     
                                     if not isinstance(dsAttributeNames, list):

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py	2012-03-13 21:12:22 UTC (rev 8854)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py	2012-03-13 22:10:39 UTC (rev 8855)
@@ -427,7 +427,7 @@
         Get vCards for a given addressBookFilter and addressBookQuery
         """
     
-        allRecords, filterAttributes, dsFilter  = dsFilterFromAddressBookFilter( addressBookFilter, searchMap=VCardRecord.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
+        allRecords, filterAttributes, dsFilter  = dsFilterFromAddressBookFilter( addressBookFilter, vcardPropToLdapAttrMap=VCardRecord.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
         #print("allRecords = %s, query = %s" % (allRecords, "None" if dsFilter is None else dsFilter.generate(),))
         
         # testing:
@@ -490,7 +490,7 @@
     return (etagRequested, propertyNames if len(propertyNames) else None)
 
 
-def dsFilterFromAddressBookFilter(addressBookFilter, searchMap, allowedAttributes=None):
+def dsFilterFromAddressBookFilter(addressBookFilter, vcardPropToLdapAttrMap, allowedAttributes=None):
     """
     Convert the supplied addressbook-query into a ds expression tree.
 
@@ -701,7 +701,7 @@
 
             # get attribute strings from dsqueryAttributesForProperty list 
             #queryAttributes = list(set(VCardRecord.dsqueryAttributesForProperty.get(propFilter.filter_name, [])).intersection(set(self.allowedDSQueryAttributes)))
-            queryAttributes = searchMap.get(propFilter.filter_name, [])
+            queryAttributes = vcardPropToLdapAttrMap.get(propFilter.filter_name, [])
             if isinstance(queryAttributes, str):
                 queryAttributes = [queryAttributes,]
             if allowedAttributes:

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py	2012-03-13 21:12:22 UTC (rev 8854)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/stdconfig.py	2012-03-13 22:10:39 UTC (rev 8855)
@@ -238,23 +238,23 @@
         "authMethod": "LDAP",
         "rdnSchema": {
             "base": "dc=example,dc=com",
-            "guidAttr": None,
-            "users": {
+            "queryTypes": ("people", ),
+            "people": {
                 "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",
+                "vcardPropToLdapAttrMap" : { # maps address book query vCard properties to ldap attributes
+                    "givenName" : "FirstName",
+                    "sn" : "LastName",
+                    "cn" : "RealName",
+                    "uid" : "GeneratedUID",
+                    "mail" : "EMailAddress",
                 },
+                "ldapAttrToDSAttrMap" : { # maps ldap attributes to ds record attributes
+                    "FN" : "cn",
+                    "EMAIL" : "mail",
+                    "UID" : "uid",
+                },
             },
         },
     },
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120313/4a7cba24/attachment-0001.html>


More information about the calendarserver-changes mailing list