kakwa / ldapcherry

Web UI for managing users and groups in multiple directory services.
MIT License
225 stars 70 forks source link

username broken when added to group #4

Closed rooty0 closed 7 years ago

rooty0 commented 7 years ago

I have following setup:

- ldap.group_attr.member = "%(dn)s"
+ ldap.group_attr.memberUid = "%(uid)s"

There is a user with Uid "max.wellgrand" in my ldap. I have a role with a single group attached to it, when I'm trying to add the user to a role (to group), I'm getting following: Alt text

So "[u'max.wellgrand']" is a string, should be just "max.wellgrand".

Per my investigation I found that this bug related to following: File: backendLdap.py function: add_to_groups string attrs = tmp[1]

attrs = 
{
u'cn': [u'Max Wellgrand'],
u'objectClass': [u'hostObject', u'person',u'organizationalPerson',u'posixAccount',u'inetOrgPerson', u'shadowAccount', u'ldapPublicKey'],
u'loginShell': [u'/bin/bash'],
u'userPassword': [u'ELaa7oav1aep6z'],
u'uidNumber': [u'9001'],
u'gidNumber': [u'9001'],
u'sn': [u'max.wellgrand'],
u'homeDirectory': [u'/home/max.wellgrand'],
u'mail': [u'max.wellgrand@domain.com'],
u'sshPublicKey': [u'mie7xeePiphiok111111'],
u'uid': [u'max.wellgrand']
}

So uid key is actually a list, what's happening here:

>>> attr
'memberUid'
>>> group_attrs[attr] % attrs
"[u'max.wellgrand']"

python's format part does not convert list to string and as a result it becomes broken

It works out of box because default configuration uses dn and dn = tmp[0] is string and not list.

I'm not sure what the best fix for this yet, for know I just hardcoded fix for myself like following: attrs['uid'] = attrs['uid'][0]

So as far as I understood, python-ldap lib returns values as a list and not string (feature).

rooty0 commented 7 years ago
dn = tmp[0]
attrs = tmp[1]

Alt text

rooty0 commented 7 years ago

See PR for a fix, not sure if this the best way to do it