Skip to content

Commit 256b894

Browse files
committed
Add optional DN truncating operation
1 parent bcb898d commit 256b894

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ In order to use the *zabbix-ldap-sync* script we need to create a configuration
9090
* `filteruser` = The ldap filter to get the users in OpenLDAP mode, by default `(&(objectClass=posixAccount)(uid=%s))`
9191
* `groupattribute` = The attribute used for membership in a group in OpenLDAP mode, by default `memberUid`
9292
* `userattribute` = The attribute for users in openldap mode, by default `uid`
93+
* `truncatedn` - If set to true the distinguished name (DN) will be truncated to the first component (by default false). Group members are usually defined as `full-path-DN`. If your ldap server just uses the `login` names to reference group members (i.e. FreeIPA) you can use this functionality to solve problems with broken searches. Example: `uid=testuser,cn=users,cn=accounts,dc=example,dc=com` cut to `uid=testuser`
9394
9495
#### [zabbix]
9596
* `server` - Zabbix URL

lib/ldapconn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, config):
3131
self.user_filter = config.ldap_user_filter
3232
self.verbose = config.verbose
3333
self.openldap_type = config.openldap_type
34+
self.openldap_truncatedn = config.openldap_truncatedn
3435

3536
self.logger = logging.getLogger(self.__class__.__name__)
3637
# Log from pyldap
@@ -111,6 +112,10 @@ def get_group_members_ldap(self, result: list):
111112
for memberid in users[self.group_member_attribute]:
112113
memberid = memberid.decode("utf-8")
113114

115+
if self.openldap_truncatedn:
116+
self.logger.debug('Distinguished name truncated from %s to %s' % (memberid, memberid.split(',')[0]))
117+
memberid = memberid.split(',')[0]
118+
114119
if self.openldap_type == "groupofnames":
115120
filter = "(objectClass=*)"
116121
# memberid is user dn

lib/zabbixldapconf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def __init__(self, config: str):
7373
fallback='(&(objectClass=posixAccount)(uid=%s))', raw=True)
7474
self.openldap_groupattribute = parser.get('openldap', 'groupattribute', fallback='memberUid', raw=True)
7575
self.openldap_userattribute = parser.get('openldap', 'userattribute', fallback='uid', raw=True)
76-
76+
self.openldap_truncatedn = ZabbixLDAPConf.try_get_item_bool(parser, 'openldap', 'truncatedn', False)
77+
7778
self.zbx_server = parser.get('zabbix', 'server')
7879

7980
self.zbx_ignore_tls_errors = ZabbixLDAPConf.try_get_item_bool(parser, 'zabbix', 'ignore_tls_errors', False)

0 commit comments

Comments
 (0)