[英]Windows LDAP group-user checking in C or C++ (or Ada 95)
我需要使用C或C ++的函數(實際上我需要在Ada 95中使用,但是可以使用-gnat05
導入沒有問題-我一定不能使用-gnat05
開關)來檢查LDAP網絡組中是否存在用戶。
為了獲取用戶名,我在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;
因此,我需要在C或C ++中使用Boolean Check_LDAP_Authentication (char* Username)
或類似的函數(甚至Check_LDAP_Authentication (Username : String) return Boolean
在Ada中Check_LDAP_Authentication (Username : String) return Boolean
)。 我該怎么做?
提前致謝。
更新資料
我找到了有關如何編寫LDAP查詢以測試用戶是否為組成員的文章? ,它表達得很好(使用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");
}
據我了解,您將需要幾個LDAP調用。 為什么不在Ada95中僅編寫一個非常薄的綁定來鏈接OpenLDAP? 還是直接從此小型教程 (但使用當前的OpenLDAP API)中獲得啟發的C代碼,並從Ada調用它?
對於第一個解決方案,我認為您需要致電
它不像使用現有的Ada庫那樣簡單,但是應該可以解決。
希望能幫助到你
首先,您的Command
變量也應為chars_ptr類型,並且應以\\ 0結尾。 如果它對您有用,那么您就是幸運的。 確保隨后釋放chars_ptr。 有關示例,請參見http://www.dwheeler.com/lovelace/s16s2.htm 。
Ada有一個LDAP綁定: http : //savannah.nongnu.org/projects/adaldap/-但它似乎非常不活躍。
AWS也支持LDAP。 參見此處的示例: http : //www.adacore.com/wp-content/files/auto_update/aws-docs/aws.html#LDAP
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.