Jump to content
Sign in to follow this  
Lainkes

LDAP connection

Recommended Posts

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

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

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

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

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
1 hour ago, Lainkes said:

retrieve a field

Use

ldap_search_sW

 

Share this post


Link to post

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
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

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

 

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

Thanks for your answer.

I'm struggeling with 

RozdelLdap

What is that function? Delphi does not recognise it.

Share this post


Link to post
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 by Vandrovnik

Share this post


Link to post

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×