Lainkes 0 Posted May 16, 2022 Hello, I need to check the user credentials against an LDAP server (Novell eDIr). But I have no idea how to start. Can anyone help me out how to achieve this? Most articles are very old, or are for Microsoft AD. Thanks in advance. Lainkes Share this post Link to post
FredS 138 Posted May 16, 2022 2 hours ago, Lainkes said: how to achieve this Use the ldap_bind_sW function (winldap.h) Share this post Link to post
Lainkes 0 Posted May 17, 2022 This is for c++. How can I use this in Delphi? Can you get me in the right direction? This is new for me. Thanks Share this post Link to post
Vandrovnik 214 Posted May 17, 2022 Hello, many years ago, I have used something like this for Novell eDir: function LdapOverPrihlaseni(aUserName, aPassword: string): boolean; var Ldap: TLDAPSend; begin result:=false; if aPassword='' then exit; Ldap:=TLDAPSend.Create; try Ldap.UserName:=aUserName; Ldap.Password:=aPassword; Ldap.TargetHost:=Config.LdapHost; // 'novell.xxxxx.cz'; Ldap.TargetPort:=Config.LdapPort; // '389'; Ldap.AutoTLS:=true; if Ldap.Login then begin if Ldap.Bind then begin result:=true; end; end; finally FreeAndNil(Ldap); end; end; ldapsend.pas was part of Synapse. Share this post Link to post
Lainkes 0 Posted May 17, 2022 Thanks for the info. I downloaded the files. How can I add these now in Delphi to use in my project? Thanks for your feedback Share this post Link to post
Lainkes 0 Posted May 17, 2022 In the mean time I made it work. The connection seems to be ok. But the last step is to retrieve a field from the LDAP. How can I do that? I need the language of the person. Thanks in advance Share this post Link to post
FredS 138 Posted May 17, 2022 1 hour ago, Lainkes said: retrieve a field Use ldap_search_sW Share this post Link to post
Lainkes 0 Posted May 17, 2022 I used the solution of Vandrovnik. So there I don't know how to retrieve a value from a field. Share this post Link to post
FredS 138 Posted May 17, 2022 5 hours ago, Vandrovnik said: ldapsend.pas 9 minutes ago, Lainkes said: there I don't know I don't use that unit, you'll need to figure out how searches are made using it. Share this post Link to post
Lainkes 0 Posted May 17, 2022 And how can I convert your solution to Delphi? What pas file do I need to use in my project? Share this post Link to post
Vandrovnik 214 Posted May 17, 2022 function LdapGetAttribute(aUserFqdn: string; aAttrib: string): string; var Ldap: TLDAPSend; Attribs: tStringList; Cn, Base: string; begin result:=''; Ldap:=TLDAPSend.Create; try Ldap.UserName:=Config.LdapUser; Ldap.Password:=Config.LdapPassword; Ldap.TargetHost:=Config.LdapHost; Ldap.TargetPort:=Config.LdapPort; Ldap.AutoTLS:=true; if Ldap.Login then begin if Ldap.Bind then begin Attribs:=tStringList.Create; try Attribs.Add(aAttrib); RozdelLdap(aUserFqdn, Cn, Base); // cn=Valek,ou=OOOO,o=XXX -> cn=Valek + ou=OOOO,o=XXX Ldap.Search(Base, false, '('+Cn+')', Attribs); if (Ldap.SearchResult.Count>0)and(Ldap.SearchResult[0].Attributes.Count>0) then begin result:=Ldap.SearchResult[0].Attributes[0].Text; end; finally FreeAndNil(Attribs); end; end; end; finally FreeAndNil(Ldap); end; end; Share this post Link to post
Lainkes 0 Posted May 17, 2022 Thanks for your answer. I'm struggeling with RozdelLdap What is that function? Delphi does not recognise it. Share this post Link to post
Vandrovnik 214 Posted May 17, 2022 (edited) 26 minutes ago, Lainkes said: Thanks for your answer. I'm struggeling with RozdelLdap What is that function? Delphi does not recognise it. It was my function. It takes a string in the form "cn=Valek,ou=OOOO,o=XXX" and divides it to Cn "cn=Valek" and Base "ou=OOOO,o=XXX" (I was dividing it using the first coma in the input string.) Edited May 17, 2022 by Vandrovnik Share this post Link to post
Lainkes 0 Posted May 17, 2022 Can you explain this Attribs.Add(aAttrib); Is aAttrib the field that I need? In my case the language field? Share this post Link to post
Vandrovnik 214 Posted May 17, 2022 Just now, Lainkes said: Can you explain this Attribs.Add(aAttrib); Is aAttrib the field that I need? In my case the language field? Yes, but I do not know its name. Share this post Link to post
Lainkes 0 Posted May 17, 2022 I made it work. Thanks a lot for all your help. Share this post Link to post