简体   繁体   English

Windows LDAP组用户以C或C ++(或Ada 95)检查

[英]Windows LDAP group-user checking in C or C++ (or Ada 95)

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. 我需要使用C或C ++的函数(实际上我需要在Ada 95中使用,但是可以使用-gnat05导入没有问题-我一定不能使用-gnat05开关)来检查LDAP网络组中是否存在用户。

For getting the username, I have the function GetEnv in C, which I can import in Ada 95 to: 为了获取用户名,我在C中具有函数GetEnv ,可以在Ada 95 GetEnv其导入到:

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). 因此,我需要在C或C ++中使用Boolean Check_LDAP_Authentication (char* Username)或类似的函数(甚至Check_LDAP_Authentication (Username : String) return Boolean在Ada中Check_LDAP_Authentication (Username : String) return Boolean )。 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? 我找到了有关如何编写LDAP查询以测试用户是否为组成员的文章? , which express quite well (using C#/VB.Net and System.DirectoryServices) what I need to do, just that I need an Ada 95 equivalent. ,它表达得很好(使用C#/ VB.Net和System.DirectoryServices),我需要做的只是我需要一个等效的Ada 95。

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. 据我了解,您将需要几个LDAP调用。 Why don't you write only a very thin binding in Ada95 to link with OpenLDAP ? 为什么不在Ada95中仅编写一个非常薄的绑定来链接OpenLDAP? Or directly a C code inspired from this small tutorial (but with the current OpenLDAP API) and call it from Ada ? 还是直接从此小型教程 (但使用当前的OpenLDAP API)中获得启发的C代码,并从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. 它不像使用现有的Ada库那样简单,但是应该可以解决。

Hope it helps 希望能帮助到你

First, your Command variable should be of type chars_ptr, too, and should contain a \\0 as end. 首先,您的Command变量也应为chars_ptr类型,并且应以\\ 0结尾。 If it worked for you, you just were lucky. 如果它对您有用,那么您就是幸运的。 Make sure to free the chars_ptr afterwards. 确保随后释放chars_ptr。 See http://www.dwheeler.com/lovelace/s16s2.htm for an example. 有关示例,请参见http://www.dwheeler.com/lovelace/s16s2.htm

There is a LDAP binding for Ada: http://savannah.nongnu.org/projects/adaldap/ - but it seems to be very inactive. Ada有一个LDAP绑定: http : //savannah.nongnu.org/projects/adaldap/-但它似乎非常不活跃。

AWS supports LDAP, too. AWS也支持LDAP。 See here for an example: http://www.adacore.com/wp-content/files/auto_update/aws-docs/aws.html#LDAP 参见此处的示例: http : //www.adacore.com/wp-content/files/auto_update/aws-docs/aws.html#LDAP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM