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");
}