1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2002 --
-- ACT-Europe --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
------------------------------------------------------------------------------
-- $Id: test_ldap.adb,v 1.4 2004/11/10 13:55:31 obry Exp $:
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with AWS.LDAP.Client;
procedure Test_LDAP is
use Ada;
use Ada.Strings.Unbounded;
use AWS;
use type AWS.LDAP.Client.LDAP_Message;
Directory : LDAP.Client.Directory;
Response_Set : LDAP.Client.LDAP_Message;
Message : LDAP.Client.LDAP_Message;
BER : aliased LDAP.Client.BER_Element;
Host : String := "ldap.nyu.edu";
User_DN : String := "";
User_PW : String := "";
Base_DN : String := "o=New York University,st=New York,c=US";
Filter : String := "(sn=DUPON*)";
begin -- LDAP_Test
Directory := LDAP.Client.Init (Host);
LDAP.Client.Bind (Directory, User_DN, User_PW);
Response_Set := LDAP.Client.Search
(Directory, Base_DN, Filter, LDAP.Client.LDAP_Scope_Subtree,
LDAP.Client.Attributes
("cn", "sn", "telephonenumber"));
-- Get first entry
Message := LDAP.Client.First_Entry (Directory, Response_Set);
Text_IO.Put_Line
("Found "
& Natural'Image (LDAP.Client.Count_Entries (Directory, Message)));
while Message /= LDAP.Client.Null_LDAP_Message loop
Text_IO.New_Line;
Text_IO.Put_Line ("Found DN " & LDAP.Client.Get_DN (Directory, Message));
Text_IO.Put_Line
(" UFN "
& LDAP.Client.DN2UFN (LDAP.Client.Get_DN (Directory, Message)));
-- Test Explode_DN
declare
Set : LDAP.Client.String_Set
:= LDAP.Client.Explode_DN
(LDAP.Client.Get_DN (Directory, Message), No_Types => False);
begin
for K in Set'Range loop
Text_IO.Put_Line (" -> " & To_String (Set (K)));
end loop;
end;
-- Output all attributes
declare
Attrs : Unbounded_String;
begin
Attrs := To_Unbounded_String
(LDAP.Client.First_Attribute (Directory, Message,
BER'Unchecked_Access));
loop
Text_IO.Put (" " & To_String (Attrs));
declare
RS : LDAP.Client.String_Set := LDAP.Client.Get_Values
(Directory, Message, To_String (Attrs));
begin
for K in RS'Range loop
Text_IO.Put (" " & To_String (RS (K)));
end loop;
end;
Text_IO.New_Line;
Attrs := To_Unbounded_String
(LDAP.Client.Next_Attribute (Directory, Message, BER));
-- Exit when no more attributes
exit when Attrs = Null_Unbounded_String;
end loop;
LDAP.Client.Free (BER);
end;
-- Get the next entry
Message := LDAP.Client.Next_Entry (Directory, Message);
end loop;
-- Free memory
LDAP.Client.Free (Message);
LDAP.Client.Unbind (Directory);
end Test_LDAP;
|