[fix] Ldap interface seems to expect lists everywhere now?

This commit is contained in:
Étienne Mollier 2019-08-14 16:28:40 +02:00 committed by Alexandre Aubin
parent 834b767000
commit 0a9f4d59cb
4 changed files with 32 additions and 31 deletions

View file

@ -865,6 +865,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
os.path.join(extracted_app_folder, 'scripts/remove'),
args=[app_instance_name], env=env_dict_remove
)[0]
# Here again, calling hook_exec could fail miserably, or get
# manually interrupted (by mistake or because script was stuck)
# In that case we still want to proceed with the rest of the

View file

@ -25,7 +25,7 @@ def user_ssh_allow(username):
from yunohost.utils.ldap import _get_ldap_interface
ldap = _get_ldap_interface()
ldap.update('uid=%s,ou=users' % username, {'loginShell': '/bin/bash'})
ldap.update('uid=%s,ou=users' % username, {'loginShell': ['/bin/bash']})
# Somehow this is needed otherwise the PAM thing doesn't forget about the
# old loginShell value ?
@ -46,7 +46,7 @@ def user_ssh_disallow(username):
from yunohost.utils.ldap import _get_ldap_interface
ldap = _get_ldap_interface()
ldap.update('uid=%s,ou=users' % username, {'loginShell': '/bin/false'})
ldap.update('uid=%s,ou=users' % username, {'loginShell': ['/bin/false']})
# Somehow this is needed otherwise the PAM thing doesn't forget about the
# old loginShell value ?

View file

@ -88,15 +88,15 @@ def tools_ldapinit():
logger.warn("Error when trying to inject '%s' -> '%s' into ldap: %s" % (rdn, attr_dict, e))
admin_dict = {
'cn': 'admin',
'uid': 'admin',
'description': 'LDAP Administrator',
'gidNumber': '1007',
'uidNumber': '1007',
'homeDirectory': '/home/admin',
'loginShell': '/bin/bash',
'cn': ['admin'],
'uid': ['admin'],
'description': ['LDAP Administrator'],
'gidNumber': ['1007'],
'uidNumber': ['1007'],
'homeDirectory': ['/home/admin'],
'loginShell': ['/bin/bash'],
'objectClass': ['organizationalRole', 'posixAccount', 'simpleSecurityObject'],
'userPassword': 'yunohost'
'userPassword': ['yunohost']
}
ldap.update('cn=admin', admin_dict)
@ -140,7 +140,7 @@ def tools_adminpw(new_password, check_strength=True):
ldap = _get_ldap_interface()
try:
ldap.update("cn=admin", {"userPassword": new_hash, })
ldap.update("cn=admin", {"userPassword": [ new_hash ], })
except:
logger.exception('unable to change admin password')
raise YunohostError('admin_password_change_failed')

View file

@ -178,19 +178,19 @@ def user_create(operation_logger, username, firstname, lastname, mail, password,
fullname = '%s %s' % (firstname, lastname)
attr_dict = {
'objectClass': ['mailAccount', 'inetOrgPerson', 'posixAccount', 'userPermissionYnh'],
'givenName': firstname,
'sn': lastname,
'displayName': fullname,
'cn': fullname,
'uid': username,
'mail': mail,
'maildrop': username,
'mailuserquota': mailbox_quota,
'userPassword': _hash_user_password(password),
'gidNumber': uid,
'uidNumber': uid,
'homeDirectory': '/home/' + username,
'loginShell': '/bin/false'
'givenName': [firstname],
'sn': [lastname],
'displayName': [fullname],
'cn': [fullname],
'uid': [username],
'mail': mail, # NOTE: this one seems to be already a list
'maildrop': [username],
'mailuserquota': [mailbox_quota],
'userPassword': [_hash_user_password(password)],
'gidNumber': [uid],
'uidNumber': [uid],
'homeDirectory': ['/home/' + username],
'loginShell': ['/bin/false']
}
# If it is the first user, add some aliases
@ -316,21 +316,21 @@ def user_update(operation_logger, username, firstname=None, lastname=None, mail=
# Get modifications from arguments
new_attr_dict = {}
if firstname:
new_attr_dict['givenName'] = firstname # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = firstname + ' ' + user['sn'][0]
new_attr_dict['givenName'] = [firstname] # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = [firstname + ' ' + user['sn'][0]]
if lastname:
new_attr_dict['sn'] = lastname # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = user['givenName'][0] + ' ' + lastname
new_attr_dict['sn'] = [lastname] # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = [user['givenName'][0] + ' ' + lastname]
if lastname and firstname:
new_attr_dict['cn'] = new_attr_dict['displayName'] = firstname + ' ' + lastname
new_attr_dict['cn'] = new_attr_dict['displayName'] = [firstname + ' ' + lastname]
if change_password:
# Ensure sufficiently complex password
assert_password_is_strong_enough("user", change_password)
new_attr_dict['userPassword'] = _hash_user_password(change_password)
new_attr_dict['userPassword'] = [_hash_user_password(change_password)]
if mail:
main_domain = _get_maindomain()
@ -395,7 +395,7 @@ def user_update(operation_logger, username, firstname=None, lastname=None, mail=
new_attr_dict['maildrop'] = user['maildrop']
if mailbox_quota is not None:
new_attr_dict['mailuserquota'] = mailbox_quota
new_attr_dict['mailuserquota'] = [mailbox_quota]
operation_logger.start()