Skip to content

Commit

Permalink
Merge pull request #61 from GOID1989/GOID1989-patch-1
Browse files Browse the repository at this point in the history
option to truncate dn
  • Loading branch information
scoopex authored Nov 13, 2023
2 parents bcb898d + 256b894 commit abe339c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ In order to use the *zabbix-ldap-sync* script we need to create a configuration
* `filteruser` = The ldap filter to get the users in OpenLDAP mode, by default `(&(objectClass=posixAccount)(uid=%s))`
* `groupattribute` = The attribute used for membership in a group in OpenLDAP mode, by default `memberUid`
* `userattribute` = The attribute for users in openldap mode, by default `uid`
* `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`
#### [zabbix]
* `server` - Zabbix URL
Expand Down
5 changes: 5 additions & 0 deletions lib/ldapconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, config):
self.user_filter = config.ldap_user_filter
self.verbose = config.verbose
self.openldap_type = config.openldap_type
self.openldap_truncatedn = config.openldap_truncatedn

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

if self.openldap_truncatedn:
self.logger.debug('Distinguished name truncated from %s to %s' % (memberid, memberid.split(',')[0]))
memberid = memberid.split(',')[0]

if self.openldap_type == "groupofnames":
filter = "(objectClass=*)"
# memberid is user dn
Expand Down
3 changes: 2 additions & 1 deletion lib/zabbixldapconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def __init__(self, config: str):
fallback='(&(objectClass=posixAccount)(uid=%s))', raw=True)
self.openldap_groupattribute = parser.get('openldap', 'groupattribute', fallback='memberUid', raw=True)
self.openldap_userattribute = parser.get('openldap', 'userattribute', fallback='uid', raw=True)

self.openldap_truncatedn = ZabbixLDAPConf.try_get_item_bool(parser, 'openldap', 'truncatedn', False)

self.zbx_server = parser.get('zabbix', 'server')

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

0 comments on commit abe339c

Please sign in to comment.