mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Ugly hack to disconnect ldap right after action processing is done
This commit is contained in:
parent
ff6343c53a
commit
322a60b306
2 changed files with 20 additions and 1 deletions
|
@ -526,6 +526,18 @@ class ActionsMap(object):
|
|||
logger.debug('action [%s] executed in %.3fs',
|
||||
log_id, stop - start)
|
||||
|
||||
# For some reason we need to do this now before the
|
||||
# garbage collector kicks in ...
|
||||
# ... because sometimes the ldap library is already half
|
||||
# gone when trying to properly close the ldap object
|
||||
# which leads to :
|
||||
# TypeError: "'NoneType' object is not callable" in <bound method Authenticator.__del__ of <moulinette.authenticators.ldap.Authenticator object at 0xabcdef123456>> ignored
|
||||
# (here the NoneType stuff refers to RequestControlTuples in ldapobject.py ...)
|
||||
# I got this when running `yunohost user list` (but not when running `yunohost domain list` for some reason)
|
||||
from moulinette.authenticators.ldap import Authenticator
|
||||
for i in Authenticator.instances:
|
||||
i().freecon()
|
||||
|
||||
@staticmethod
|
||||
def get_namespaces():
|
||||
"""
|
||||
|
|
|
@ -9,6 +9,7 @@ import crypt
|
|||
import ldap
|
||||
import ldap.sasl
|
||||
import ldap.modlist as modlist
|
||||
import weakref
|
||||
|
||||
from moulinette.core import MoulinetteError
|
||||
from moulinette.authenticators import BaseAuthenticator
|
||||
|
@ -33,11 +34,13 @@ class Authenticator(BaseAuthenticator):
|
|||
|
||||
"""
|
||||
|
||||
instances = []
|
||||
def __init__(self, name, uri, base_dn, user_rdn=None):
|
||||
logger.debug("initialize authenticator '%s' with: uri='%s', "
|
||||
"base_dn='%s', user_rdn='%s'", name, uri, base_dn, user_rdn)
|
||||
super(Authenticator, self).__init__(name)
|
||||
|
||||
self.__class__.instances.append(weakref.proxy(self))
|
||||
self.uri = uri
|
||||
self.basedn = base_dn
|
||||
if user_rdn:
|
||||
|
@ -52,10 +55,14 @@ class Authenticator(BaseAuthenticator):
|
|||
self.authenticate(None)
|
||||
|
||||
def __del__(self):
|
||||
self.freecon()
|
||||
|
||||
def freecon(self):
|
||||
"""Disconnect and free ressources"""
|
||||
if self.con:
|
||||
if self.con and hasattr(self.con, "_l"):
|
||||
self.con.unbind_s()
|
||||
|
||||
|
||||
# Implement virtual properties
|
||||
|
||||
vendor = 'ldap'
|
||||
|
|
Loading…
Add table
Reference in a new issue