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

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 17 19:23:49 PDT 2012


Revision: 9146
          http://trac.macosforge.org/projects/calendarserver/changeset/9146
Author:   gaya at apple.com
Date:     2012-04-17 19:23:46 -0700 (Tue, 17 Apr 2012)
Log Message:
-----------
add finding of locations, resources

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest2.plist
    CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest2.plist
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest2.plist	2012-04-17 20:51:14 UTC (rev 9145)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/conf/carddav-ldaptest2.plist	2012-04-18 02:23:46 UTC (rev 9146)
@@ -1018,103 +1018,6 @@
     <dict>
         <key>Enabled</key>
         <true/>
-        <!-- twistedcaldav.directory.opendirectorybacker.OpenDirectoryBackingService ->
-        <key>type</key>
-        <string>twistedcaldav.directory.opendirectorybacker.OpenDirectoryBackingService</string>
-        <key>params</key>
-        <dict>
-     	  <!- - Search for people records ->
-          <key>queryPeopleRecords</key>
-          <true/>
-     	  <!- Search for people records in this directory service node ->
-          <key>peopleNode</key>
-          <string>/Search/Contacts</string>
-     	  <!- Search for user records ->
-          <key>queryUserRecords</key>
-          <true/>
-          <key>userNode</key>
-     	  <!- Search for user records in this directory service node ->
-          <string>/Search</string>
-      	  <!- query in directory service local node ->
-          <key>queryDSLocal</key>
-          <false/>
-      	  <!- minutes to keep directory service local node in memory before refresh ->
-          <key>dsLocalCacheTimeout</key>
-          <integer>30</integer>
-     	  <!- approx. maximum number of records returned from a directory service query ->
-          <key>maxDSQueryRecords</key>
-          <integer>0</integer> <!- use 0 to have server calculate the maximum based on MaxAddressBookQueryResults, MaxAddressBookMultigetHrefs keys ->
-     	  <!- ignore system records like "root" when creating vCards ->
-          <key>ignoreSystemRecords</key>
-          <true/>
-       	  <!- fake the eTag.  If false all directory service attributes are used to calculate the eTag ->
-          <key>fakeETag</key>
-          <true/>
-          <key>generateSimpleUIDs</key>
-          <true/>
-          <key>appleInternalServer</key>
-          <false/>
-          <key>addDSAttrXProperties</key>
-          <false/>
-          <!- add this key to use additional directory service attributes in queries.  Needed for some queries with directory service templates.
-          <key>additionalAttributes</key>
-          <array>
-            <string>dsAttrTypeNative:appleAIMPreferred</string>
-            <string>dsAttrTypeNative:appleManager</string>
-          </array>
-          ->
-          <!- add this key to limit directory service attributes used to make vCard properties
-          		When using directory service templates, list should include only mapped attributes.
-          <key>allowedAttributes</key>
-          <array>
-            <string>dsAttrTypeStandard:AddressLine1</string>
-            <string>dsAttrTypeStandard:AddressLine2</string>
-            <string>dsAttrTypeStandard:AddressLine3</string>
-            <string>dsAttrTypeStandard:Birthday</string>
-            <string>dsAttrTypeStandard:Building</string>
-            <string>dsAttrTypeStandard:City</string>
-            <string>dsAttrTypeStandard:Comment</string>
-            <string>dsAttrTypeStandard:Country</string>
-            <string>dsAttrTypeStandard:CreationTimestamp</string>
-            <string>dsAttrTypeStandard:Department</string>
-            <string>dsAttrTypeStandard:EMailAddress</string>
-            <string>dsAttrTypeStandard:EMailContacts</string>
-            <string>dsAttrTypeStandard:FirstName</string>
-            <string>dsAttrTypeStandard:HomePhoneNumber</string>
-            <string>dsAttrTypeStandard:IMHandle</string>
-            <string>dsAttrTypeStandard:JPEGPhoto</string>
-            <string>dsAttrTypeStandard:JobTitle</string>
-            <string>dsAttrTypeStandard:LastName</string>
-            <string>dsAttrTypeStandard:MapCoordinates</string>
-            <string>dsAttrTypeStandard:MiddleName</string>
-            <string>dsAttrTypeStandard:MobileNumber</string>
-            <string>dsAttrTypeStandard:ModificationTimestamp</string>
-            <string>dsAttrTypeStandard:NamePrefix</string>
-            <string>dsAttrTypeStandard:NameSuffix</string>
-            <string>dsAttrTypeStandard:NickName</string>
-            <string>dsAttrTypeStandard:Note</string>
-            <string>dsAttrTypeStandard:OrganizationInfo</string>
-            <string>dsAttrTypeStandard:OrganizationName</string>
-            <string>dsAttrTypeStandard:PGPPublicKey</string>
-            <string>dsAttrTypeStandard:PagerNumber</string>
-            <string>dsAttrTypeStandard:PhoneContacts</string>
-            <string>dsAttrTypeStandard:PhoneNumber</string>
-            <string>dsAttrTypeStandard:PostalAddress</string>
-            <string>dsAttrTypeStandard:PostalAddressContacts</string>
-            <string>dsAttrTypeStandard:PostalCode</string>
-            <string>dsAttrTypeStandard:Relationships</string>
-            <string>dsAttrTypeStandard:State</string>
-            <string>dsAttrTypeStandard:Street</string>
-            <string>dsAttrTypeStandard:URL</string>
-            <string>dsAttrTypeStandard:UserCertificate</string>
-            <string>dsAttrTypeStandard:UserPKCS12Data</string>
-            <string>dsAttrTypeStandard:UserSMIMECertificate</string>
-            <string>dsAttrTypeStandard:WeblogURI</string>
-          </array>
-          ->
-        </dict>
-        -->
-        <!-- twistedcaldav.directory.opendirectorybacker.OpenDirectoryBackingService -->
  		<key>type</key>
 		<string>twistedcaldav.directory.ldapdirectorybacker.LdapDirectoryBackingService</string>
 		<key>params</key>
@@ -1145,50 +1048,64 @@
                 <string>o=apple.com,o=email</string>
                 <key>queries</key>
                 <array>
-                    <!-- people vCards for another server. -->
+                    <!-- people vCards -->
                     <dict>
-                        <key>rdn</key>
-                        <string>ou=People</string>
-                        <key>filter</key>
-                        <string></string>
+                        <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>additionalVCardProps</key>
+                            <dict>
+                                <key>KIND</key>         <string>individual</string>
+                                <key>NOTE</key>         <string>individual</string>
+                            </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>
+                            <key>givenName</key>    <string>FirstName</string>
+                            <key>sn</key>           <string>LastName</string>
+                            <key>cn</key>           <string>RealName</string>
+                            <key>mail</key>         <string>EMailAddress</string>
+                            <key>uid</key>          <string>GeneratedUID</string>
                         </dict>
                         <key>vcardPropToLdapAttrMap</key>
                         <dict>
-                            <key>FN</key>
-                            <string>cn</string>
-                            <key>EMAIL</key>
-                            <string>mail</string>
-                            <key>UID</key>
-                            <string>uid</string>
+                            <key>FN</key>       <string>cn</string>
+                            <key>EMAIL</key>    <string>mail</string>
+                            <key>UID</key>      <string>uid</string>
                         </dict>
                     </dict>
-                    <!-- group vCards for another server.
+                    <!-- distribution list (group) vCards shown by 10.6-7 clients as persons. Members are in NOTE. Does not hide groups below because UID different -->
                     <dict>
-                        <key>rdn</key>
-                        <string>ou=Groups</string>
-                        <key>filter</key>
-                        <string></string>
+                        <key>rdn</key>      <string>ou=Groups</string>
+                        <key>filter</key>   <string>(|(mail=*)(uniqueMember=*))</string> <!-- add a filter to skip uninteresting groups -->
                         <key>additionalVCardProps</key>
-                         <dict>
-                            <key>X-ADDRESSBOOKSERVER-KIND</key>
-                            <string>group</string>
+                            <dict>
+                                <key>KIND</key>         <string>group</string>
+                            </dict>
+                        <key>ldapAttrToDSAttrMap</key>
+                        <dict>
+                            <key>givenName</key>    <string>FirstName</string>
+                            <key>sn</key>           <string>LastName</string>
+                            <key>description</key>  <string>RealName</string>
+                            <key>cn</key>           <string>RecordName</string>
+                            <key>mail</key>         <string>EMailAddress</string>
+                            <key>uniqueMember</key> <string>Comment</string>
                         </dict>
+                        <key>vcardPropToLdapAttrMap</key>
+                        <dict>
+                            <key>FN</key>       <string>cn</string>
+                            <key>EMAIL</key>    <string>mail</string>
+                            <key>UID</key>      <string>cn</string>
+                        </dict>
+                    </dict>
+                    <!-- group vCards NOT shown 10.6-7 clients. Hopefully, future client will show these. Client can expand members with exact query on group member UID -->
+                    <dict>
+                        <key>rdn</key>      <string>ou=Groups</string>
+                        <key>filter</key>   <string>(|(mail=*)(uniqueMember=*))</string> <!-- add a filter to skip uninteresting groups -->
+                        <key>additionalVCardProps</key>
+                         <dict>
+                            <key>X-ADDRESSBOOKSERVER-KIND</key> <string>group</string>
+                            <key>KIND</key>                     <string>group</string>
+                       </dict>
                         <key>ldapAttrTransforms</key>
                         <dict>
                             <key>uniqueMember</key>
@@ -1199,74 +1116,62 @@
                         </dict>
                         <key>ldapAttrToDSAttrMap</key>
                         <dict>
-                            <key>givenName</key>
-                            <string>FirstName</string>
-                            <key>sn</key>
-                            <string>LastName</string>
-                            <key>description</key>
-                            <array>
-                                <string>RealName</string>
-                            </array>
-                            <key>cn</key>
-                            <array>
-                                <string>GeneratedUID</string>
-                            </array>
-                            <key>mail</key>
-                            <string>EMailAddress</string>
-                            <key>uniqueMember</key>
-                            <string>GroupMembers</string>
+                            <key>givenName</key>    <string>FirstName</string>
+                            <key>sn</key>           <string>LastName</string>
+                            <key>description</key>  <string>RealName</string>
+                            <key>cn</key>           <string>GeneratedUID</string>
+                            <key>mail</key>         <string>EMailAddress</string>
+                            <key>uniqueMember</key> <string>GroupMembers</string>
                         </dict>
                         <key>vcardPropToLdapAttrMap</key>
                         <dict>
-                            <key>FN</key>
-                            <string>cn</string>
-                            <key>EMAIL</key>
-                            <string>mail</string>
-                            <key>UID</key>
-                            <string>cn</string>
+                            <key>FN</key>       <string>cn</string>
+                            <key>EMAIL</key>    <string>mail</string>
+                            <key>UID</key>      <string>cn</string>
                         </dict>
                     </dict>
-                    -->
-                    <!-- distribution list vCards for another server. Cannot use with groups because UID/href is not unique -->
+                    <!-- group vCards shown by 10.6-7 clients as persons.  Future client should show as location.  Need to add Map URL or GEO -->
                     <dict>
-                        <key>rdn</key>
-                        <string>ou=Groups</string>
-                        <key>filter</key>
-                        <string></string>
-                        <key>additionalVCardProps</key>
-                         <dict>
-                            <key>X-ABShowAs</key>
-                            <string>COMPANY</string>
+                        <key>rdn</key>      <string>ou=places</string>
+                        <key>filter</key>   <string>(objectClass=apple-resource)</string>
+                        <!-- map from ab query to indexed ldap attribute.  If unindexed, too slow.  -->
+                         <key>additionalVCardProps</key>
+                            <dict>
+                                <key>KIND</key> <string>location</string>
+                                <key>NOTE</key> <string>location</string>
+                            </dict>
+                        <key>ldapAttrToDSAttrMap</key>
+                        <dict>
+                            <key>apple-realname</key>       <string>RealName</string>
+                            <key>apple-generateduid</key>   <string>GeneratedUID</string>
+                            <key>apple-mapguid</key>        <string>URL</string>
+                            <key>apple-capacity</key>       <string>URL</string>
                         </dict>
+                        <key>vcardPropToLdapAttrMap</key>
+                        <dict>
+                            <key>FN</key>       <string>apple-realname</string>
+                            <key>UID</key>      <string>uid</string>
+                        </dict>
+                    </dict>
+                    <!-- calendarresource vCards shown by 10.6-7 clients as persons.  Just for testing only, at this point in time -->
+                    <dict>
+                        <key>rdn</key>      <string>ou=resources</string>
+                        <key>filter</key>   <string>(objectClass=apple-resource)</string>
+                         <key>additionalVCardProps</key>
+                            <dict>
+                                <key>KIND</key> <string>calendarresource</string>
+                                <key>NOTE</key> <string>location</string>
+                            </dict>
                         <key>ldapAttrToDSAttrMap</key>
                         <dict>
-                            <key>givenName</key>
-                            <string>FirstName</string>
-                            <key>sn</key>
-                            <string>LastName</string>
-                            <key>description</key>
-                            <array>
-                                <string>RealName</string>
-                            </array>
-                            <key>cn</key>
-                            <array>
-                                <string>GeneratedUID</string>
-                            </array>
-                            <key>mail</key>
-                            <string>EMailAddress</string>
-                            <key>uniqueMember</key>
-                            <string>Comment</string>
+                            <key>apple-realname</key>       <string>RealName</string>
+                            <key>apple-generateduid</key>   <string>GeneratedUID</string>
                         </dict>
                         <key>vcardPropToLdapAttrMap</key>
                         <dict>
-                            <key>FN</key>
-                            <array>
-                                <string>cn</string>
-                            </array>
-                            <key>EMAIL</key>
-                            <string>mail</string>
-                            <key>UID</key>
-                            <string>cn</string>
+                            <key>FN</key>       <string>cn</string>
+                            <key>EMAIL</key>    <string>mail</string>
+                            <key>UID</key>      <string>uid</string>
                         </dict>
                     </dict>
                 </array>

Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py	2012-04-17 20:51:14 UTC (rev 9145)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py	2012-04-18 02:23:46 UTC (rev 9146)
@@ -29,7 +29,7 @@
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 
 from twistedcaldav.config import config
-from twistedcaldav.directory.ldapdirectory import LdapDirectoryService
+from twistedcaldav.directory.ldapdirectory import LdapDirectoryService, normalizeDNstr
 from twistedcaldav.directory.opendirectorybacker import ABDirectoryQueryResult, dsFilterFromAddressBookFilter, propertiesInAddressBookQuery
 
 
@@ -62,6 +62,7 @@
                 ),
 
             },
+            "removeDuplicateUIDs":True,      # remove vCards with duplicate UIDs
             "appleInternalServer":False,    # does magic in ABDirectoryQueryResult
             "maxQueryResults":0,            # max records returned
             "fakeETag":True,                # eTag is fake, otherwise it is md5(all attributes)
@@ -86,6 +87,8 @@
         del params["maxQueryResults"]
         fakeETag=params["fakeETag"]
         del params["fakeETag"]
+        removeDuplicateUIDs=params["removeDuplicateUIDs"]
+        del params["removeDuplicateUIDs"]
 
         
         #standardize ds attributes type names
@@ -121,6 +124,7 @@
         ### params for ABDirectoryQueryResult()
         self.fakeETag = fakeETag
         self.appleInternalServer = appleInternalServer
+        self.removeDuplicateUIDs = removeDuplicateUIDs
  
         super(LdapDirectoryBackingService, self).__init__(params)
         
@@ -184,6 +188,9 @@
             #dn = normalizeDNstr(dn)
             result = None
             try:
+                if "dn" not in ldapAttributes:
+                    ldapAttributes["dn"] = [normalizeDNstr(dn),]
+                
                 # make a dsRecordAttributes dict from the ldap attributes
                 dsRecordAttributes = {}
                 for ldapAttributeName, ldapAttributeValues in ldapAttributes.iteritems():
@@ -213,7 +220,7 @@
                                     transformedValues = []
                                     for ldapAttributeValue in ldapAttributeValues:
                                         transformedValue = ldapAttributeValue
-                                        for valuePart in ldapAttributeValue.lower().split(","):
+                                        for valuePart in normalizeDNstr(ldapAttributeValue).split(","):
                                             kvPair = valuePart.split("=")
                                             if len(kvPair) == 2:
                                                 for transform in transforms:
@@ -269,7 +276,7 @@
         Get vCards for a given addressBookFilter and addressBookQuery
         """
     
-        resultsDictionary = {}
+        results = {} if self.removeDuplicateUIDs else []
         limited = False
         
         #one ldap query for each rnd in queries
@@ -314,7 +321,7 @@
 
                 
                 # keep trying ldap query till we get results based on filter.  Especially when doing "all results" query
-                remainingMaxResults = maxResults - len(resultsDictionary) if maxResults else 0
+                remainingMaxResults = maxResults - len(results) if maxResults else 0
                 maxLdapResults = int(remainingMaxResults * 1.2)
     
                 while True:
@@ -328,15 +335,18 @@
                     
                     for uid, ldapQueryResult in ldapQueryResultsDictionary.iteritems():
 
-                        if uid in resultsDictionary:
+                        if self.removeDuplicateUIDs and uid in results:
                             self.log_info("Record skipped due to duplicate UID: %s" % (uid,))
                             continue
                     
                         if not addressBookFilter.match(ldapQueryResult.vCard()):
                             self.log_debug("doAddressBookQuery did not match filter: %s (%s)" % (ldapQueryResult.vCard().propertyValue("FN"), uid,))
                             continue
-                           
-                        resultsDictionary[uid] = ldapQueryResult                   
+                        
+                        if self.removeDuplicateUIDs:
+                            results[uid] = ldapQueryResult
+                        else:
+                            results += [ldapQueryResult,]              
 
                     
                     #no more results    
@@ -344,11 +354,11 @@
                         break;
                     
                     # more than requested results
-                    if maxResults and len(resultsDictionary) >= maxResults:
+                    if maxResults and len(results) >= maxResults:
                         break
                     
                     # more than max report results
-                    if len(resultsDictionary) >= config.MaxQueryWithDataResults:
+                    if len(results) >= config.MaxQueryWithDataResults:
                         break
                     
                     # more than self limit
@@ -360,12 +370,12 @@
                     if self.maxQueryResults and maxLdapResults > self.maxQueryResults:
                         maxLdapResults = self.maxQueryResults
                     
-                if maxResults and len(resultsDictionary) >= maxResults:
+                if maxResults and len(results) >= maxResults:
                     break
                 
         
-        limited = maxResults and len(resultsDictionary) >= maxResults
+        limited = maxResults and len(results) >= maxResults
                          
-        self.log_info("limited  %s len(resultsDictionary) %s" % (limited,len(resultsDictionary),))
-        returnValue((resultsDictionary.values(), limited,))        
+        self.log_info("limited  %s len(results) %s" % (limited,len(results),))
+        returnValue((results.values() if self.removeDuplicateUIDs else results, limited,))        
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120417/53d356ee/attachment-0001.html>


More information about the calendarserver-changes mailing list