Forum > Networking and Web Programming
Synapse ldap - Usage or alternative
mm_coder:
Trying to use the synapse ldap to connect to a Windows DC.
Is anyone having luck using it?
The sample I'm drawing from is here. http://www.ararat.cz/synapse/doku.php/public:howto:ldapsample
procedure TForm1.Button1Click(Sender: TObject);
var
ldap: TLDAPsend;
l: TStringList;
begin
ldap:= TLDAPsend.Create;
l := TStringList.Create;
try
ldap.TargetHost := 'my-domain-controller-ip';
ldap.UserName 'ldap';
ldap.Password 'my-user-password';
ldap.Login;
ldap.Bind;
l.Add('displayname');
l.Add('description');
l.Add('givenName');
l.Add('*');
ldap.Search('dc=OpenLDAP,dc=org', False, '(objectclass=*)', l);
memo1.Lines.Add(LDAPResultdump(ldap.SearchResult));
ldap.Logout;
finally
ldap.Free;
l.Free;
end;
end;
I can get it to compile, but have nothing but "Result=0", pretty much no matter what I try.
Any hints appreciated.
Bret
abouchez:
I am just finishing a fork of this library, as part of mORMot.
More than a fork, in fact - almost a full rewrite.
We use it over MS AD and Samba/OpenLdap servers.
It supports Kerberos authentication, and all the needed crypto to access modern AD.
And of course, it works on Windows, Linux and Mac. ;)
Feedback is welcome - we expect a few fixes in the next days/weeks.
https://github.com/synopse/mORMot2/blob/master/src/net/mormot.net.ldap.pas
mm_coder:
Do you have samples of usage for LDAP?
mm_coder:
Again, referencing the following example:
http://www.ararat.cz/synapse/doku.php/public:howto:ldapsample
I have this working now, returning my base domain search values. If you create a new project and include all the synapse pascal unit files found in the "uses" clauses
procedure TForm1.Button1Click(Sender: TObject);
var
ldap: TLDAPsend;
l: TStringList;
al: TLDAPAttribute;
begin
ldap:= TLDAPsend.Create;
l := TStringList.Create;
al := TLDAPAttribute.Create ;
try
ldap.TargetHost := '192.168.40.50';
*************** Had to change user to a domain admin
*************** below works using a domain admin, but I assume I can use
************** a non admin user with the appropriate rights
ldap.UserName := 'administrator@internal.mydoamin.com';
ldap.Password := 'PASSWORD123';
if ldap.Login then
if ldap.Bind then
begin
ShowMessage('Connected to LDAP');
//l.Add('displayname');
//l.Add('description');
//l.Add('givenName');
l.Add('mail');
//l.Add('*');
ldap.Search('OU=Users,OU=MM,DC=internal,DC=yourdomain,DC=com', False, '(objectclass=Person)', l);
memo1.Lines.Add(LDAPResultDump(ldap.SearchResult));
//memo1.Lines.Add
ldap.Logout;
end;
finally
ldap.Free;
end;
end;
What I'm after is how to get the user and email elements of the ldap query.
I'm not smart enough to figure this out without a little help.
I think I need to instantiate a TDLDAP Attribute class and load them, or they are already loading, but I can't figure it out.
I'm thinking I need to loop through the results...rather than use the LDAPResultDump function, which
is described as primarily used for debugging in the source code comments.
Haven't done a lot of programming using classes; when I started they didn't exist, and I'm
slow to catch the concepts.
Any hints appreciated.
mm_coder:
Resolved. The debugger is your friend.
This library has very nice code and my compliments to it's author.
1. Added a Combobox to my form
2. Created the below procedure below the uses clause
procedure LDAPResult_GetEmail(const Value: TLDAPResultList; cb: TComboBox);
Ended up with the following.
I pass the ComboBox to the function and load there.
My Combobox has a list of whatever items you included in the below
l.Add('displayname'); 'will be in combobox
//l.Add('description'); 'not
//l.Add('givenName'); 'not
l.Add('mail'); 'will be in combobox
procedure TForm1.Button1Click(Sender: TObject);
var
ldap: TLDAPsend;
l: TStringList;
al: TLDAPAttribute;
s: string;
begin
ldap:= TLDAPsend.Create;
l := TStringList.Create;
al := TLDAPAttribute.Create ;
memo1.Lines.Clear ;
try
ldap.TargetHost := 'xxx.xx.xxx.xxx'; /your DC ip address
ldap.UserName := 'administrator@internal.domain.com';
ldap.Password := 'password';
if ldap.Login then
if ldap.Bind then
begin
ShowMessage('Connected to LDAP');
l.Add('displayname');
//l.Add('description');
//l.Add('givenName');
l.Add('mail');
//l.Add('*');
ldap.Search('OU=Users,OU=MM,DC=internal,DC=domain,DC=com', False, '(objectclass=*)', l);
LDAPResult_GetEmail (ldap.SearchResult, attributelist);
ldap.Logout;
end;
finally
ldap.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate ;
end;
procedure LDAPResult_GetEmail(const Value: TLDAPResultList; cb: TComboBox);
var
n, m, o: integer;
r: TLDAPResult;
a: TLDAPAttribute;
begin
for n := 0 to Value.Count - 1 do
begin
r := Value[n];
for m := 0 to r.Attributes.Count - 1 do
begin
a := r.Attributes[m];
for o := 0 to a.Count - 1 do
cb.Items.Add (a[0]);
end;
end;
end;
Navigation
[0] Message Index
[#] Next page