diff --git a/ucs-school-umc-installer/umc/python/schoolinstaller/__init__.py b/ucs-school-umc-installer/umc/python/schoolinstaller/__init__.py index c4c182d..dfae54f 100644 --- a/ucs-school-umc-installer/umc/python/schoolinstaller/__init__.py +++ b/ucs-school-umc-installer/umc/python/schoolinstaller/__init__.py @@ -217,12 +217,12 @@ def umc(username, password, master, path='', options=None, flavor=None, command= def get_user_dn(username, password, master): """Get the LDAP DN for the given username.""" - result = umc(username, password, master, 'udm/query', {"objectProperty": "username", "objectPropertyValue": username}, 'users/user') - result = [ientry.get('$dn$') for ientry in result if ientry.get('username') == username] - try: - return result[0] - except IndexError: - pass + ssh = get_ssh_connection(username, password, master) + stdin, stdout, stderr = ssh.exec_command(' '.join([pipes.quote(x) for x in ['/usr/bin/sudo', '/usr/bin/univention-ldapsearch', '-LLLoldif-wrap=no', filter_format('(&(uid=%s)(objectClass=person))', [username]), 'dn']])) + for line in stdout.splitlines(): + match = re.match('^dn: (.*)\s*$', line) + if match: + return match.group(1) def create_ou_local(ou, displayName): @@ -579,6 +579,12 @@ class Instance(Base): except univention.uldap.ldap.LDAPError as err: MODULE.warn('LDAP connection to %s failed: %s' % (master, err)) return {'success': False, 'error': _('The LDAP connection to the master system %s failed.') % master} + except socket.gaierror as exc: + MODULE.warn('Could not connect to master system %s: %s' % (master, exc)) + return {'success': False, 'error': _('Cannot connect to the master domain controller system %s. Please make sure that the system is reachable. If not this could be due to wrong DNS nameserver settings.') % master} + except paramiko.SSHException as exc: + MODULE.warn('Could not connect to master system %s: %s' % (master, exc)) + return {'success': False, 'error': _('Cannot connect to the master domain controller system %s. It seems that the specified domain credentials are not valid.') % master} return {'success': True, 'schoolinfo': values}