Compare commits

..

No commits in common. "cbb97ae726bb0d5f3381a765b16754595251685b" and "e8de509346ccd05b1d820be77671ca0d1d103962" have entirely different histories.

View file

@ -30,13 +30,11 @@ class LdapServer:
con = 0 con = 0
def __init__(self, uri, dn=None, pwd=None, v2=None, def __init__(self, uri, dn=None, pwd=None, v2=None, raiseOnError=False, logger=False):
raiseOnError=False, logger=False, checkCert=True):
self.uri = uri self.uri = uri
self.dn = dn self.dn = dn
self.pwd = pwd self.pwd = pwd
self.raiseOnError = raiseOnError self.raiseOnError = raiseOnError
self.checkCert = checkCert
if v2: if v2:
self.v2 = True self.v2 = True
if logger: if logger:
@ -53,8 +51,6 @@ class LdapServer:
""" Start connection to LDAP server """ """ Start connection to LDAP server """
if self.con == 0: if self.con == 0:
try: try:
if not self.checkCert:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
con = ldap.initialize(self.uri) con = ldap.initialize(self.uri)
if self.v2: if self.v2:
con.protocol_version = ldap.VERSION2 # pylint: disable=no-member con.protocol_version = ldap.VERSION2 # pylint: disable=no-member
@ -389,8 +385,7 @@ class LdapClient:
# Load configuration option types only here to avoid global # Load configuration option types only here to avoid global
# dependency of ldap module with config one. # dependency of ldap module with config one.
# pylint: disable=import-outside-toplevel from mylib.config import StringOption, PasswordOption # pylint: disable=import-outside-toplevel
from mylib.config import BooleanOption, StringOption, PasswordOption
section = self._config.add_section( section = self._config.add_section(
self._config_section, self._config_section,
@ -406,9 +401,6 @@ class LdapClient:
PasswordOption, 'bindpwd', PasswordOption, 'bindpwd',
comment='LDAP Bind password (set to "keyring" to use XDG keyring)', comment='LDAP Bind password (set to "keyring" to use XDG keyring)',
username_option='binddn', keyring_value='keyring') username_option='binddn', keyring_value='keyring')
section.add_option(
BooleanOption, 'checkcert', default=True,
comment='Check LDAP certificate')
return section return section
@ -421,7 +413,7 @@ class LdapClient:
log.info("Connect to LDAP server %s as %s", uri, binddn if binddn else 'annonymous') log.info("Connect to LDAP server %s as %s", uri, binddn if binddn else 'annonymous')
self._conn = LdapServer( self._conn = LdapServer(
uri, dn=binddn, pwd=self._get_option('bindpwd'), uri, dn=binddn, pwd=self._get_option('bindpwd'),
checkCert=self._get_option('checkcert'), raiseOnError=True raiseOnError=True
) )
# Reset cache # Reset cache
self._cached_objects = {} self._cached_objects = {}
@ -697,8 +689,6 @@ class LdapClient:
:param changes: The changes as returned by get_changes :param changes: The changes as returned by get_changes
""" """
if changes is None:
return False
assert self._conn or self.initialize() assert self._conn or self.initialize()
return self._conn.update_need( return self._conn.update_need(
changes[0], changes[1], changes[0], changes[1],