使用C访问Active Directory

时间:2013-06-06 07:40:05

标签: c active-directory ldap openldap

我在http://www-archive.mozilla.org/directory/csdk-docs/example.htm的代码中进行了一些修改后尝试了以下代码。

# 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, "user@mydomain.com", "***" ); 
   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工作,现在该怎么办?有没有其他包来执行代码?

1 个答案:

答案 0 :(得分:0)

如果您正在Windows上寻找除openldap之外的其他选项。您可以尝试winldap,有关更多信息,您可以访问他们的msdn页面,也有一些例子可以帮助您。

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