Skip to content

Commit

Permalink
portalapi: tweak ldap management to handle anonymous queries, eg to f…
Browse files Browse the repository at this point in the history
…etch domain list as ynh-portal
  • Loading branch information
alexAubin committed Nov 13, 2023
1 parent 7fe950d commit 7703ca2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/utils/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _get_ldap_interface():
global _ldap_interface

if _ldap_interface is None:
_ldap_interface = LDAPInterface(user="root")
_ldap_interface = LDAPInterface()

return _ldap_interface

Expand Down Expand Up @@ -76,12 +76,17 @@ def _destroy_ldap_interface():

class LDAPInterface:

def __init__(self, user="root", password=None):
def __init__(self, user=None, password=None):

if user == "root":
logger.debug("initializing root ldap interface")
self.userdn = ROOTDN
self._connect = lambda con: con.sasl_non_interactive_bind_s("EXTERNAL")
if user is None:
if os.getuid() == 0:
logger.debug(f"initializing root ldap interface")
self.userdn = ROOTDN.format(uid=uid, gid=gid)
self._connect = lambda con: con.sasl_non_interactive_bind_s("EXTERNAL")
else:
logger.debug(f"initializing anonymous ldap interface")
self.userdn = ""
self._connect = lambda con: None
else:
logger.debug("initializing user ldap interface")
self.userdn = USERDN.format(username=user)
Expand Down

0 comments on commit 7703ca2

Please sign in to comment.