我需要C或C++中的函數(實際上我需要在Ada 95中,但可以使用編譯指示導入而沒有問題 - 我不能使用-gnat05
交換機)檢查用戶是否在LDAP網絡組中。C或C++(或Ada 95)中的Windows LDAP組用戶檢查
用於獲取用戶名,我在C函數GetEnv
,我可以在阿達95導入到:
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;
所以我需要一個功能Boolean Check_LDAP_Authentication (char* Username)
或類似的東西在C或C++(或甚至在Ada中爲Check_LDAP_Authentication (Username : String) return Boolean
)。我該怎麼做?
在此先感謝。
更新
我發現How to write LDAP query to test if user is member of a group?後,表達相當不錯(使用C#/ VB.Net和的System.DirectoryServices)什麼,我需要做的,只是我需要一個阿達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");
}
我不相信運氣有一些東西,只是分析它爲什麼有效。我可能會環顧大草原和AWS代碼,也許我會得到一些提示。包括洞庫不是一個好主意(植樹種子,對吧?),但看看他們可以幫助。謝謝。 – Rego 2012-02-16 20:34:17
在Mac OS X Lion上運行你的代碼,使用適當的環境變量('USER'而不是'USERNAME'),會產生一個'Dereference_Error'。 – 2012-02-17 07:10:29
...但是'命令:常量字符串:=「USER」&ASCII.Nul;'似乎表現更好。儘管如此,我仍然不推薦(並且,我意識到,與您的實際問題無關)。 – 2012-02-17 12:32:01