Skip to content

Instantly share code, notes, and snippets.

@witsch
Last active November 29, 2016 13:55
Show Gist options
  • Save witsch/bc2de8308d4a2cc72aedeb60058177f2 to your computer and use it in GitHub Desktop.
Save witsch/bc2de8308d4a2cc72aedeb60058177f2 to your computer and use it in GitHub Desktop.
posixGroups support for Plone/Zope's `Products.LDAPUserFolder` (2.27)
diff --git a/Products/LDAPUserFolder/LDAPUserFolder.py b/Products/LDAPUserFolder/LDAPUserFolder.py
index 8402da3..60f9634 100644
--- Products/LDAPUserFolder/LDAPUserFolder.py
+++ Products/LDAPUserFolder/LDAPUserFolder.py
@@ -19,6 +19,7 @@ $Id$
import logging
import os
import random
+import re
try:
from hashlib import sha1 as sha_new
except ImportError:
@@ -962,7 +963,10 @@ class LDAPUserFolder(BasicUserFolder):
for dn in all_dns.keys():
try:
- user = self.getUserByDN(to_utf8(dn))
+ if 'uid=' in dn:
+ user = self.getUserByDN(to_utf8(dn))
+ else:
+ user = self.getUser(dn)
except:
user = None
@@ -1228,6 +1232,8 @@ class LDAPUserFolder(BasicUserFolder):
group_filter = '(|'
for g_name, m_name in GROUP_MEMBER_MAP.items():
+ if g_name == 'posixGroup':
+ dn, = re.search(r'uid=([^,]*),', dn).groups()
fltr = filter_format(f_template, (g_name, m_name, dn))
group_filter += fltr
diff --git a/Products/LDAPUserFolder/utils.py b/Products/LDAPUserFolder/utils.py
index 83d6f95..f6de93f 100644
--- Products/LDAPUserFolder/utils.py
+++ Products/LDAPUserFolder/utils.py
@@ -47,6 +47,7 @@ GROUP_MEMBER_MAP = { 'groupOfUniqueNames' : 'uniqueMember'
, 'accessGroup' : 'member'
, 'group' : 'member'
, 'univentionGroup' : 'uniqueMember'
+ , 'posixGroup' : 'memberUid'
}
GROUP_MEMBER_ATTRIBUTES = Set(list(GROUP_MEMBER_MAP.values()))
@witsch
Copy link
Author

witsch commented Nov 29, 2016

This is an updated version of David's patch as suggested in his Plone/Zope: Using LDAPUserFolder with posixGroups blog post.

The original patch has been working quite nicely for us for a couple of years. So thank you David! :)

However, once your user base does not exactly match the remainder of the user's DNs, e.g. when your users are organized hierarchically (and you're using a "subtree" scope to find them) simply adding self.users_base no longer works. The above version should do the trick...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment