2013-06-06 487 views
0

http://www-archive.mozilla.org/directory/csdk-docs/example.htm的代碼中進行了一些修改後,我嘗試了以下代碼。使用C訪問Active Directory使用C

# include <stdio.h> 
# include "ldap.h" 
int main(int argc, char **argv) 
{ 
    LDAP *ld; 

    int rc; 
    /* Get a handle to an LDAP connection. */ 
    if ((ld = ldap_init("ipaddr", port)) == NULL) { 
    perror("ldap_init"); 
    return(1); 
    } 
    /* Bind anonymously to the LDAP server. */ 
    rc = ldap_simple_bind_s(ld, "[email protected]", "***"); 
    if (rc != LDAP_SUCCESS) { 
    fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc)); 
    return(1); 
    } 
    else 
    { 
    printf("Successful authentication"); 
    } 
} 

我沒有ldap.h頭文件。我試圖從openldap(v2.4.35)下載一個軟件包並解壓到包含頭文件的文件夾。我在執行過程中包含了這個文件夾,發現兩個文件缺少lber_types.h和ldap_features.h。我探索了這個包,發現了lber_types.hin和ldap_features.hin文件。我還從Internet上找到了一個信息,即lber_types和ldap_features頭文件是由Linux中的configure命令自動生成的。我在Windows上工作,現在該怎麼辦?是否有任何其他包來執行代碼?

回答

0

如果您在Windows上尋找除了openldap以外的其他選項。你可以試試winldap,更多信息你可以訪問他們的msdn頁面,也有一些例子可以幫助你。

http://msdn.microsoft.com/en-us/library/windows/desktop/aa367033(v=vs.85).aspx

+0

我發現,鏈接,以下。這裏給出的例子用於Visual C++。但它當然使用winldap.h頭文件。是否可以使用C程序的頭文件?我嘗試在代碼中使用該頭文件,並且包含了包含頭文件執行依賴項的文件夾,但是在我的cmd提示符下運行了一個很長的錯誤。示例錯誤如下所示:C:\ xxxxx \ winldap.h:384:0:錯誤:未知類型名稱'ULONG_PTR'。這裏有幫助嗎? –

相關問題