5 commits - pykolab/auth pykolab/cli pykolab/imap pykolab/wap_client

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Fri Aug 1 22:11:47 CEST 2014


 pykolab/auth/ldap/__init__.py             |  180 ++++++++++++++++--------------
 pykolab/cli/cmd_count_domain_mailboxes.py |    6 -
 pykolab/imap/__init__.py                  |   10 +
 pykolab/wap_client/__init__.py            |   16 ++
 4 files changed, 117 insertions(+), 95 deletions(-)

New commits:
commit 13661b09f90b461f5d8e0fd6f73d7639b09fbe9e
Merge: eb2c8e7 5aa6b40
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Aug 1 22:11:44 2014 +0200

    Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab



commit eb2c8e73da5af5fd02244963055fcb7e26993adb
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Aug 1 22:09:46 2014 +0200

    Update the list of short acl rights (read, write, etc.)

diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 0b2b8cd..f52dc9f 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -320,11 +320,15 @@ class IMAP(object):
             Set an ACL entry on a folder.
         """
         short_rights = {
-                'all': 'lrswipkxtecda',
+                'all': 'lrsedntxakcpiw',
+                'append': 'wip',
+                'full': 'lrswipkxtecdn',
+                'read': 'lrs',
                 'read-only': 'lrs',
-                'read-write': 'lrswited',
+                'read-write': 'lrswitedn',
+                'post': 'p',
                 'semi-full': 'lrswit',
-                'full': 'lrswipkxtecd'
+                'write': 'lrswite',
             }
 
         if short_rights.has_key(acl):


commit 55de288c17e7b7861b7473a1c3e5c7e5bcda7248
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Aug 1 22:09:11 2014 +0200

    Make sure we apply access control, including when no access control is specified (remove the default acl)

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 7bfccd7..752b4fc 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1215,46 +1215,45 @@ class LDAP(pykolab.base.Base):
                 folder_path = entry['cn']
 
         folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute')
+        if folderacl_entry_attribute == None:
+            folderacl_entry_attribute = 'acl'
 
-        if not folderacl_entry_attribute == None:
-            if not entry.has_key(folderacl_entry_attribute):
-                entry[folderacl_entry_attribute] = self.get_entry_attribute(
-                        entry['id'],
-                        folderacl_entry_attribute
-                    )
-
-            if not entry[folderacl_entry_attribute] == None:
-                # Parse it before assigning it
-                entry['kolabmailfolderaclentry'] = []
-                if not isinstance(entry[folderacl_entry_attribute], list):
-                    entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ]
+        if not entry.has_key(folderacl_entry_attribute):
+            entry[folderacl_entry_attribute] = self.get_entry_attribute(
+                    entry['id'],
+                    folderacl_entry_attribute
+                )
 
-                for acl_entry in entry[folderacl_entry_attribute]:
-                    acl_access = acl_entry.split()[-1]
-                    aci_subject = ' '.join(acl_entry.split()[:-1])
+        if not entry[folderacl_entry_attribute] == None:
+            # Parse it before assigning it
+            entry['kolabfolderaclentry'] = []
+            if not isinstance(entry[folderacl_entry_attribute], list):
+                entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ]
 
-                    log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
+            for acl_entry in entry[folderacl_entry_attribute]:
+                acl_access = acl_entry.split()[-1]
+                aci_subject = ' '.join(acl_entry.split()[:-1])
 
-                    access_lookup_dict = {
-                            'read': 'lrs',
-                            'post': 'p',
-                            'append': 'wip',
-                            'write': 'lrswite',
-                            'all': 'lrsedntxakcpiw'
-                        }
+                log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
 
-                    if access_lookup_dict.has_key(acl_access):
-                        acl_access = access_lookup_dict[acl_access]
+                access_lookup_dict = {
+                        'all': 'lrsedntxakcpiw',
+                        'append': 'wip',
+                        'full': 'lrswipkxtecdn',
+                        'read': 'lrs',
+                        'read-only': 'lrs',
+                        'read-write': 'lrswitedn',
+                        'post': 'p',
+                        'semi-full': 'lrswit',
+                        'write': 'lrswite',
+                    }
 
-                    log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
+                if access_lookup_dict.has_key(acl_access):
+                    acl_access = access_lookup_dict[acl_access]
 
-                    entry['kolabmailfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access))
+                log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
 
-        if not entry.has_key('kolabmailfolderaclentry'):
-            entry['kolabmailfolderaclentry'] = self.get_entry_attribute(
-                    entry['id'],
-                    'kolabmailfolderaclentry'
-                )
+                entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access))
 
         if not self.imap.shared_folder_exists(folder_path):
             self.imap.shared_folder_create(folder_path, server)
@@ -1267,12 +1266,14 @@ class LDAP(pykolab.base.Base):
                     entry['kolabfoldertype']
                 )
 
-        if entry.has_key('kolabmailfolderaclentry') and \
-                not entry['kolabmailfolderaclentry'] == None:
+        if entry.has_key('kolabfolderaclentry') and \
+                not entry['kolabfolderaclentry'] == None:
 
             self.imap._set_kolab_mailfolder_acls(
-                    entry['kolabmailfolderaclentry']
+                    entry['kolabfolderaclentry']
                 )
+        else:
+            self.imap.set_acl(folder_path, 'anyone', '')
 
         if entry.has_key(delivery_address_attribute) and \
                 not entry[delivery_address_attribute] == None:
@@ -1593,46 +1594,45 @@ class LDAP(pykolab.base.Base):
                 folder_path = entry['cn']
 
         folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute')
+        if folderacl_entry_attribute == None:
+            folderacl_entry_attribute = 'acl'
 
-        if not folderacl_entry_attribute == None:
-            if not entry.has_key(folderacl_entry_attribute):
-                entry[folderacl_entry_attribute] = self.get_entry_attribute(
-                        entry['id'],
-                        folderacl_entry_attribute
-                    )
-
-            if not entry[folderacl_entry_attribute] == None:
-                # Parse it before assigning it
-                entry['kolabmailfolderaclentry'] = []
-                if not isinstance(entry[folderacl_entry_attribute], list):
-                    entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ]
+        if not entry.has_key(folderacl_entry_attribute):
+            entry[folderacl_entry_attribute] = self.get_entry_attribute(
+                    entry['id'],
+                    folderacl_entry_attribute
+                )
 
-                for acl_entry in entry[folderacl_entry_attribute]:
-                    acl_access = acl_entry.split()[-1]
-                    aci_subject = ' '.join(acl_entry.split()[:-1])
+        if not entry[folderacl_entry_attribute] == None:
+            # Parse it before assigning it
+            entry['kolabfolderaclentry'] = []
+            if not isinstance(entry[folderacl_entry_attribute], list):
+                entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ]
 
-                    log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
+            for acl_entry in entry[folderacl_entry_attribute]:
+                acl_access = acl_entry.split()[-1]
+                aci_subject = ' '.join(acl_entry.split()[:-1])
 
-                    access_lookup_dict = {
-                            'read': 'lrs',
-                            'post': 'p',
-                            'append': 'wip',
-                            'write': 'lrswite',
-                            'all': 'lrsedntxakcpiw'
-                        }
+                log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
 
-                    if access_lookup_dict.has_key(acl_access):
-                        acl_access = access_lookup_dict[acl_access]
+                access_lookup_dict = {
+                        'all': 'lrsedntxakcpiw',
+                        'append': 'wip',
+                        'full': 'lrswipkxtecdn',
+                        'read': 'lrs',
+                        'read-only': 'lrs',
+                        'read-write': 'lrswitedn',
+                        'post': 'p',
+                        'semi-full': 'lrswit',
+                        'write': 'lrswite',
+                    }
 
-                    log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
+                if access_lookup_dict.has_key(acl_access):
+                    acl_access = access_lookup_dict[acl_access]
 
-                    entry['kolabmailfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access))
+                log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8)
 
-        if not entry.has_key('kolabmailfolderaclentry'):
-            entry['kolabmailfolderaclentry'] = self.get_entry_attribute(
-                    entry['id'],
-                    'kolabmailfolderaclentry'
-                )
+                entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access))
 
         if not self.imap.shared_folder_exists(folder_path):
             self.imap.shared_folder_create(folder_path, server)
@@ -1644,20 +1644,21 @@ class LDAP(pykolab.base.Base):
                     folder_path,
                     entry['kolabfoldertype']
                 )
+        else:
+            self.imap.set_acl(folder_path, 'anyone', '')
 
-        if entry.has_key(delivery_address_attribute) and \
-                not entry[delivery_address_attribute] == None:
-            self.imap.set_acl(folder_path, 'anyone', 'p')
-
-        if entry.has_key('kolabmailfolderaclentry') and \
-                not entry['kolabmailfolderaclentry'] == None:
+        if entry.has_key('kolabfolderaclentry') and \
+                not entry['kolabfolderaclentry'] == None:
 
             self.imap._set_kolab_mailfolder_acls(
-                    entry['kolabmailfolderaclentry']
+                    entry['kolabfolderaclentry']
                 )
+        else:
+            self.imap.set_acl(folder_path, 'anyone', '')
 
-        #if server == None:
-            #self.entry_set_attribute(mailserver_attribute, server)
+        if entry.has_key(delivery_address_attribute) and \
+                not entry[delivery_address_attribute] == None:
+            self.imap.set_acl(folder_path, 'anyone', 'p')
 
     def _change_modify_user(self, entry, change):
         """
@@ -1772,11 +1773,18 @@ class LDAP(pykolab.base.Base):
                     'kolabfoldertype'
                 )
 
-        #if not entry.has_key('kolabmailfolderaclentry'):
-            #entry['kolabmailfolderaclentry'] = self.get_entry_attribute(
-                    #entry['id'],
-                    #'kolabmailfolderaclentry'
-                #)
+        folderacl_entry_attribute = conf.get('ldap', 'folderacl_entry_attribute')
+        if folderacl_entry_attribute == None:
+            folderacl_entry_attribute = 'acl'
+
+        if not entry.has_key(folderacl_entry_attribute):
+            entry['kolabfolderaclentry'] = self.get_entry_attribute(
+                    entry['id'],
+                    folderacl_entry_attribute
+                )
+        else:
+            entry['kolabfolderaclentry'] = entry[folderacl_entry_attribute]
+            del entry[folderacl_entry_attribute]
 
         if entry.has_key('kolabtargetfolder') and \
                 not entry['kolabtargetfolder'] == None:
@@ -1805,12 +1813,16 @@ class LDAP(pykolab.base.Base):
                     entry['kolabfoldertype']
                 )
 
-        if entry.has_key('kolabmailfolderaclentry') and \
-                not entry['kolabmailfolderaclentry'] == None:
+        if entry.has_key('kolabfolderaclentry') and \
+                not entry['kolabfolderaclentry'] == None:
 
             self.imap._set_kolab_mailfolder_acls(
-                    entry['kolabmailfolderaclentry']
+                    entry['kolabfolderaclentry']
                 )
+        elif entry['kolabfolderaclentry'] in [None,[]]:
+            for ace in self.imap.list_acls(folder_path):
+                aci_subject = ace.split()[0]
+                self.imap.set_acl(folder_path, aci_subject, '')
 
         delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute')
         if entry.has_key(delivery_address_attribute) and \


commit 1289a04ec39066c32fa6905f528dc06f30684443
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Aug 1 22:07:42 2014 +0200

    Update for the new domain listing

diff --git a/pykolab/cli/cmd_count_domain_mailboxes.py b/pykolab/cli/cmd_count_domain_mailboxes.py
index 8aecd2d..958bccd 100644
--- a/pykolab/cli/cmd_count_domain_mailboxes.py
+++ b/pykolab/cli/cmd_count_domain_mailboxes.py
@@ -56,10 +56,8 @@ def execute(*args, **kw):
     domains = auth.list_domains()
 
     folders = []
-    for primary,secondaries in domains:
-        print "%s: %d" % (primary,len(imap.lm("user/%%@%s" % (primary))))
-        for secondary in secondaries:
-            print "%s: %d" % (secondary,len(imap.lm("user/%%@%s" % (secondary))))
+    for domain in domains.keys():
+        print "%s: %d" % (domain,len(imap.lm("user/%%@%s" % (domain))))
 
     null_realm = len(imap.lm("user/%%"))
 


commit 8c4c9e8643dc4489a42f22e5a25b737103169b5b
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Aug 1 21:49:39 2014 +0200

    Add group functions

diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index bf35f79..9549fe8 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -303,10 +303,18 @@ def group_form_value_generate_mail(params=None):
 
     return request('POST', 'group_form_value.generate_mail', params)
 
-def group_info():
-    group = utils.ask_question("Group email address")
-    group = request('GET', 'group.info?group=%s' % (group))
-    return group
+def group_find(params=None):
+    post = { 'search': { 'params': {} } }
+
+    for (k,v) in params.iteritems():
+        post['search']['params'][k] = { 'value': v, 'type': 'exact' }
+
+    return request('POST', 'group.find', post=json.dumps(post))
+
+def group_info(group=None):
+    if group == None:
+        group = utils.ask_question("group DN")
+    return request('GET', 'group.info', get={ 'id': group })
 
 def group_members_list(group=None):
     if group == None:




More information about the commits mailing list