-# Copyright (C) 2014 Ipsilon Project Contributors
-#
-# See the file named COPYING for the project license
+# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
from ipsilon.info.common import InfoProviderBase
from ipsilon.info.common import InfoProviderInstaller
raise Exception('No unique user object could be found!')
data = dict()
for name, value in result[0][1].iteritems():
- if type(value) is list and len(value) == 1:
+ if isinstance(value, list) and len(value) == 1:
value = value[0]
data[name] = value
return data
reply = dict()
try:
ldapattrs = self._get_user_data(conn, dn)
- self.debug(ldapattrs)
+ self.debug('LDAP attrs for %s: %s' % (dn, ldapattrs))
userattrs, extras = self.mapper.map_attributes(ldapattrs)
groups = self._get_user_groups(conn, base, username)
reply = userattrs
reply['_groups'] = groups
reply['_extras'] = {'ldap': extras}
except Exception, e: # pylint: disable=broad-except
- self.error(e)
+ self.error('Error fetching/mapping LDAP user data: %s' % e)
return reply
def get_user_attrs(self, user):
try:
- conn = self._ldap_bind()
dn = self.user_dn_tmpl % {'username': user}
+ except ValueError as e:
+ self.error(
+ 'DN generation failed with template %s, user %s: %s'
+ % (self.user_dn_tmpl, user, e)
+ )
+ return {}
+ except Exception as e: # pylint: disable=broad-except
+ self.error(
+ 'Unhandled error generating DN from %s, user %s: %s'
+ % (self.user_dn_tmpl, user, e)
+ )
+ return {}
+
+ try:
+ conn = self._ldap_bind()
base = self.base_dn
return self.get_user_data_from_conn(conn, dn, base, user)
- except Exception, e: # pylint: disable=broad-except
- self.error(e)
+ except ldap.LDAPError as e:
+ self.error(
+ 'LDAP search failed for DN %s on base %s: %s' %
+ (dn, base, e)
+ )
+ return {}
+ except Exception as e: # pylint: disable=broad-except
+ self.error(
+ 'Unhandled LDAP error for DN %s on base %s: %s' %
+ (dn, base, e)
+ )
return {}
group.add_argument('--info-ldap-base-dn', action='store',
help='LDAP Base DN')
- def configure(self, opts):
+ def configure(self, opts, changes):
if opts['info_ldap'] != 'yes':
return
config['server url'] = opts['info_ldap_server_url']
elif 'ldap_server_url' in opts:
config['server url'] = opts['ldap_server_url']
- config = {'bind dn': opts['info_ldap_bind_dn']}
- config = {'bind password': opts['info_ldap_bind_pwd']}
- config = {'user dn template': opts['info_ldap_user_dn_template']}
if 'info_ldap_bind_dn' in opts:
config['bind dn'] = opts['info_ldap_bind_dn']
if 'info_ldap_bind_pwd' in opts:
config['user dn template'] = opts['info_ldap_user_dn_template']
elif 'ldap_bind_dn_template' in opts:
config['user dn template'] = opts['ldap_bind_dn_template']
- config['tls'] = 'Demand'
+ if 'info_ldap_tls_level' in opts and opts['info_ldap_tls_level']:
+ config['tls'] = opts['info_ldap_tls_level']
+ elif 'ldap_tls_level' in opts and opts['ldap_tls_level']:
+ config['tls'] = opts['ldap_tls_level']
+ else:
+ config['tls'] = 'Demand'
if 'info_ldap_base_dn' in opts and opts['info_ldap_base_dn']:
config['base dn'] = opts['info_ldap_base_dn']
elif 'ldap_base_dn' in opts and opts['ldap_base_dn']: