I need a function in C or C++ (actually I need in Ada 95, but a pragma import can be used with no problem - I must not use the -gnat05
switch) to check if a user is present in a LDAP network group.
For getting the username, I have the function GetEnv
in C, which I can import in Ada 95 to:
function GetUsername return String is
function GetEnv (Variable : String) return Interfaces.C.Strings.chars_ptr;
pragma Import (C, GetEnv, "getenv");
Command : constant String := "USER" & ASCII.Nul;
Answer_Ptr : constant Interfaces.C.Strings.chars_ptr := GetEnv (Command);
Answer : constant String := Interfaces.C.Strings.Value (Answer_Ptr);
begin
return Answer;
end GetUsername;
So I need a function Boolean Check_LDAP_Authentication (char* Username)
or something like this in C or C++, (or even Check_LDAP_Authentication (Username : String) return Boolean
in Ada). How can I do it?
Thanks in advance.
Update
I found a post on How to write LDAP query to test if user is member of a group? , which express quite well (using C#/VB.Net and System.DirectoryServices) what I need to do, just that I need an Ada 95 equivalent.
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://dc=yourcompany,dc=com");
DirectorySearcher srch = new DirectorySearcher(rootEntry);
srch.SearchScope = SearchScope.Subtree;
srch.Filter = "(&(objectcategory=user)(sAMAccountName=yourusername)(memberof=CN=yourgroup,OU=yourOU,DC=yourcompany,DC=com))";
SearchResultCollection res = srch.FindAll();
if(res == null || res.Count <= 0)
{
Console.WriteLine("This user is *NOT* member of that group");
}
else
{
Console.WriteLine("This user is INDEED a member of that group");
}
For what I understood, you'll need several LDAP calls. Why don't you write only a very thin binding in Ada95 to link with OpenLDAP ? Or directly a C code inspired from this small tutorial (but with the current OpenLDAP API) and call it from Ada ?
For the first solution, I think you will need to call
It's not as straightforward as using an existing Ada library but that should do the trick.
Hope it helps
First, your Command
variable should be of type chars_ptr, too, and should contain a \\0 as end. If it worked for you, you just were lucky. Make sure to free the chars_ptr afterwards. See http://www.dwheeler.com/lovelace/s16s2.htm for an example.
There is a LDAP binding for Ada: http://savannah.nongnu.org/projects/adaldap/ - but it seems to be very inactive.
AWS supports LDAP, too. See here for an example: http://www.adacore.com/wp-content/files/auto_update/aws-docs/aws.html#LDAP
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.