[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'), os.path.join(extracted_app_folder, 'scripts/remove'),
args=[app_instance_name], env=env_dict_remove args=[app_instance_name], env=env_dict_remove
)[0] )[0]
# Here again, calling hook_exec could fail miserably, or get # Here again, calling hook_exec could fail miserably, or get
# manually interrupted (by mistake or because script was stuck) # manually interrupted (by mistake or because script was stuck)
# In that case we still want to proceed with the rest of the # 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 from yunohost.utils.ldap import _get_ldap_interface
ldap = _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 # Somehow this is needed otherwise the PAM thing doesn't forget about the
# old loginShell value ? # old loginShell value ?
@ -46,7 +46,7 @@ def user_ssh_disallow(username):
from yunohost.utils.ldap import _get_ldap_interface from yunohost.utils.ldap import _get_ldap_interface
ldap = _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 # Somehow this is needed otherwise the PAM thing doesn't forget about the
# old loginShell value ? # 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)) logger.warn("Error when trying to inject '%s' -> '%s' into ldap: %s" % (rdn, attr_dict, e))
admin_dict = { admin_dict = {
'cn': 'admin', 'cn': ['admin'],
'uid': 'admin', 'uid': ['admin'],
'description': 'LDAP Administrator', 'description': ['LDAP Administrator'],
'gidNumber': '1007', 'gidNumber': ['1007'],
'uidNumber': '1007', 'uidNumber': ['1007'],
'homeDirectory': '/home/admin', 'homeDirectory': ['/home/admin'],
'loginShell': '/bin/bash', 'loginShell': ['/bin/bash'],
'objectClass': ['organizationalRole', 'posixAccount', 'simpleSecurityObject'], 'objectClass': ['organizationalRole', 'posixAccount', 'simpleSecurityObject'],
'userPassword': 'yunohost' 'userPassword': ['yunohost']
} }
ldap.update('cn=admin', admin_dict) ldap.update('cn=admin', admin_dict)
@ -140,7 +140,7 @@ def tools_adminpw(new_password, check_strength=True):
ldap = _get_ldap_interface() ldap = _get_ldap_interface()
try: try:
ldap.update("cn=admin", {"userPassword": new_hash, }) ldap.update("cn=admin", {"userPassword": [ new_hash ], })
except: except:
logger.exception('unable to change admin password') logger.exception('unable to change admin password')
raise YunohostError('admin_password_change_failed') 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) fullname = '%s %s' % (firstname, lastname)
attr_dict = { attr_dict = {
'objectClass': ['mailAccount', 'inetOrgPerson', 'posixAccount', 'userPermissionYnh'], 'objectClass': ['mailAccount', 'inetOrgPerson', 'posixAccount', 'userPermissionYnh'],
'givenName': firstname, 'givenName': [firstname],
'sn': lastname, 'sn': [lastname],
'displayName': fullname, 'displayName': [fullname],
'cn': fullname, 'cn': [fullname],
'uid': username, 'uid': [username],
'mail': mail, 'mail': mail, # NOTE: this one seems to be already a list
'maildrop': username, 'maildrop': [username],
'mailuserquota': mailbox_quota, 'mailuserquota': [mailbox_quota],
'userPassword': _hash_user_password(password), 'userPassword': [_hash_user_password(password)],
'gidNumber': uid, 'gidNumber': [uid],
'uidNumber': uid, 'uidNumber': [uid],
'homeDirectory': '/home/' + username, 'homeDirectory': ['/home/' + username],
'loginShell': '/bin/false' 'loginShell': ['/bin/false']
} }
# If it is the first user, add some aliases # 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 # Get modifications from arguments
new_attr_dict = {} new_attr_dict = {}
if firstname: if firstname:
new_attr_dict['givenName'] = firstname # TODO: Validate new_attr_dict['givenName'] = [firstname] # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = firstname + ' ' + user['sn'][0] new_attr_dict['cn'] = new_attr_dict['displayName'] = [firstname + ' ' + user['sn'][0]]
if lastname: if lastname:
new_attr_dict['sn'] = lastname # TODO: Validate new_attr_dict['sn'] = [lastname] # TODO: Validate
new_attr_dict['cn'] = new_attr_dict['displayName'] = user['givenName'][0] + ' ' + lastname new_attr_dict['cn'] = new_attr_dict['displayName'] = [user['givenName'][0] + ' ' + lastname]
if lastname and firstname: 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: if change_password:
# Ensure sufficiently complex password # Ensure sufficiently complex password
assert_password_is_strong_enough("user", change_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: if mail:
main_domain = _get_maindomain() 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'] new_attr_dict['maildrop'] = user['maildrop']
if mailbox_quota is not None: if mailbox_quota is not None:
new_attr_dict['mailuserquota'] = mailbox_quota new_attr_dict['mailuserquota'] = [mailbox_quota]
operation_logger.start() operation_logger.start()