@@ -166,7 +166,7 @@ def initialize_ldap_connection(self, context, connection):
166166 base_dn = None
167167
168168 try :
169- ldap_server = ldap3 .Server (connection .host , use_ssl = True , port = 636 , tls = tls )
169+ ldap_server = ldap3 .Server (connection .host , use_ssl = True , port = 636 , tls = tls , get_info = ldap3 . ALL )
170170 ldap_connection = ldap3 .Connection (
171171 ldap_server ,
172172 user = f"{ connection .domain } \\ { connection .username } " ,
@@ -178,19 +178,9 @@ def initialize_ldap_connection(self, context, connection):
178178 context .log .success ("Connected to LDAP over SSL (LDAPS)." )
179179
180180 try :
181- ldap_connection .search (
182- search_base = "" ,
183- search_filter = "(objectClass=*)" ,
184- search_scope = ldap3 .BASE ,
185- attributes = ["defaultNamingContext" ],
186- )
187- if ldap_connection .entries :
188- base_dn = ldap_connection .entries [0 ]["defaultNamingContext" ].value
189- context .log .success (f"Retrieved base DN over LDAPS: { base_dn } " )
190- else :
191- context .log .warning ("defaultNamingContext not found in Root DSE. Falling back to domain name derivation." )
181+ base_dn = ldap_server .info .other .get ("defaultNamingContext" , [None ])[0 ]
192182 except Exception as e :
193- context .log .warning (f"Failed to query Root DSE for defaultNamingContext over LDAPS : { e } " )
183+ context .log .warning (f"Failed to query Root DSE for defaultNamingContext over plaintext LDAP : { e } " )
194184
195185 if not base_dn :
196186 domain_parts = connection .domain .split ("." )
@@ -205,7 +195,7 @@ def initialize_ldap_connection(self, context, connection):
205195 context .log .info ("Falling back to plain LDAP..." )
206196
207197 try :
208- ldap_server = ldap3 .Server (connection .host , use_ssl = False , port = 389 )
198+ ldap_server = ldap3 .Server (connection .host , use_ssl = False , port = 389 , get_info = ldap3 . ALL )
209199 ldap_connection = ldap3 .Connection (
210200 ldap_server ,
211201 user = f"{ connection .domain } \\ { connection .username } " ,
@@ -217,19 +207,9 @@ def initialize_ldap_connection(self, context, connection):
217207 context .log .info ("Connected to LDAP successfully (plaintext)." )
218208
219209 try :
220- ldap_connection .search (
221- search_base = "" ,
222- search_filter = "(objectClass=*)" ,
223- search_scope = ldap3 .BASE ,
224- attributes = ["defaultNamingContext" ],
225- )
226- if ldap_connection .entries :
227- base_dn = ldap_connection .entries [0 ]["defaultNamingContext" ].value
228- context .log .success (f"Retrieved base DN over plain LDAP: { base_dn } " )
229- else :
230- context .log .warning ("defaultNamingContext not found in Root DSE. Falling back to domain name derivation." )
210+ base_dn = ldap_server .info .other .get ("defaultNamingContext" , [None ])[0 ]
231211 except Exception as e :
232- context .log .warning (f"Failed to query Root DSE for defaultNamingContext over plain LDAP: { e } " )
212+ context .log .warning (f"Failed to query Root DSE for defaultNamingContext over plaintext LDAP: { e } " )
233213
234214 if not base_dn :
235215 domain_parts = connection .domain .split ("." )
0 commit comments