Init function complete

This commit is contained in:
Kloadut 2012-10-23 19:55:40 +02:00
parent bf5126af26
commit 516102d913
2 changed files with 51 additions and 2 deletions

View file

@ -12,6 +12,8 @@ import ldap.modlist as modlist
import json
import re
import getpass
if not __debug__:
import traceback
def colorize(astr, color):
@ -262,8 +264,9 @@ class YunoHostLDAP:
if result:
result_list = []
for dn, entry in result:
if 'dn' in attrs:
entry['dn'] = [dn]
if attrs != None:
if 'dn' in attrs:
entry['dn'] = [dn]
result_list.append(entry)
return result_list
else:
@ -293,6 +296,37 @@ class YunoHostLDAP:
return True
def update(self, rdn, attr_dict, new_rdn=False):
"""
Modify LDAP entry
Keyword arguments:
rdn -- DN without domain
attr_dict -- Dictionnary of attributes/values to add
new_rdn -- New RDN for modification
Returns:
Boolean | YunoHostError
"""
dn = rdn + ',' + self.base
actual_entry = self.search(base=dn, attrs=None)
if actual_entry[0]['userPassword']:
del actual_entry[0]['userPassword']
ldif = modlist.modifyModlist(actual_entry[0], attr_dict)
try:
if new_rdn:
self.conn.rename_s(dn, new_rdn)
dn = new_rdn + ',' + self.base
self.conn.modify_ext_s(dn, ldif)
except:
raise YunoHostError(169, _('An error occured during LDAP entry update'))
else:
return True
def validate_uniqueness(self, value_dict):
"""
Check uniqueness of values

View file

@ -13,3 +13,18 @@ def tools_init(args, connections):
for rdn, attr_dict in ldap_map['childs'].items():
yldap.add(rdn, attr_dict)
admin_dict = {
'cn': 'admin',
'uid': 'admin',
'description': 'LDAP Administrator',
'gidNumber': '1007',
'uidNumber': '1007',
'homeDirectory': '/home/admin',
'loginShell': '/bin/bash',
'objectClass': ['organizationalRole', 'posixAccount', 'simpleSecurityObject']
}
yldap.update('cn=admin', admin_dict)
return { 'Success' : _("LDAP successfully initialized") }