c操作ldap
来源:互联网 发布:精神出轨 知乎 编辑:程序博客网 时间:2024/06/06 03:10
http://blog.csdn.net/lxt643755936/article/details/8196515
#include "stdafx.h"
#include <windows.h>
#include <winldap.h>
#include <stdio.h>
#pragma comment(lib,"crypt32.lib")
#pragma comment(lib,"Wldap32.lib")
LDAP *ld;
LDAPMessage *res,*e;
char *dn, *a, *sdn, **vals;
BerElement *ptr;
char *host="192.168.0.237";
int port=389;
char * rdn="cn=root,dc=example,dc=com";
char * passwd="123456";
int connect()
{
ld = ldap_open(host,port);
if (ld==NULL)
printf("connect failed\n");
else
printf("connect success\n");
if(ldap_simple_bind_s(ld,"cn=root,dc=example,dc=com","123456")!=LDAP_SUCCESS)
ldap_perror( ld, "ldap_simple_bind_s" );
else
printf("bind success\n");
}
int search()
{
sdn="dc=example,dc=com";
if (ldap_search_s(ld,sdn,LDAP_SCOPE_SUBTREE,"(objectclass=*)",NULL,0,&res)
!= LDAP_SUCCESS)
{
ldap_perror(ld,"ldap_search_s");
return -1;
}
for(e=ldap_first_entry(ld,res);e!=NULL;e=ldap_next_entry(ld,e))
{
dn=ldap_get_dn(ld,e);
printf("dn: %s \n",dn);
ldap_memfree( dn );
for ( a = ldap_first_attribute( ld, e, &ptr );a != NULL;a = ldap_next_attribute( ld, e, ptr ) )
{
//printf( "attr= %s: ",a );
vals = ldap_get_values( ld, e, a );
for ( int i = 0; vals[i] != NULL; i++ )
printf(" %s=%s \n",a,vals[i]);
ldap_value_free( vals );
}
printf("\n");
}
ldap_msgfree(res);
}
int modify()
{
char *passwd[] = {"654321",NULL};
LDAPMod mod1 = {LDAP_MOD_REPLACE,"esmaPassword",passwd};
LDAPMod *lmod[] = {&mod1,NULL};
sdn = "uid=zyh,cn=Teachers,cn=Users,dc=example,dc=com";
if (ldap_modify_s(ld,sdn,lmod)!=LDAP_SUCCESS)
{
ldap_perror( ld, "ldap_modify_s" );
return( -1 );
}
else
{
printf("modify success\n");
}
}
int add()
{
char *cn_values[] = {"ea",NULL};
char *sn_values[] = {"ea",NULL};
char *userPassword_values[] = {"123456",NULL};
char *objectClass_values[] = {"person",NULL};
sdn = "cn=ea,dc=example,dc=com";
LDAPMod mod0 = {LDAP_MOD_ADD,"cn",cn_values};
LDAPMod mod1 = {LDAP_MOD_ADD,"sn",sn_values};
LDAPMod mod2 = {LDAP_MOD_ADD,"objectClass",objectClass_values};
LDAPMod mod3 = {LDAP_MOD_ADD,"userPassword",userPassword_values};
LDAPMod *lmod[] = {&mod0,&mod1,&mod2,&mod3,NULL};
if(ldap_add_s(ld,sdn,lmod)!=LDAP_SUCCESS)
{
ldap_perror(ld,"ldap_add_s error");
return( -1 );
}
else
{
printf("add success\n");
}
}
int del()
{
if( ldap_delete_s(ld,"cn=ea,dc=example,dc=com") == -1)
{
ldap_perror(ld,"ldap_delete_s");
return (-1);
}
else
{
printf("delete success\n");
}
}
int main(int argv,int argc[])
{
connect();
search();
//modify();
//add();
//del();
ldap_unbind(ld);
return 0;
}
- c操作ldap
- c操作ldap
- 用C语言操作LDAP服务器
- 用C语言操作LDAP服务器
- 用C语言操作LDAP服务器
- 用C语言操作LDAP服务器
- 用c语言对ldap进行操作
- 用C语言操作LDAP服务器
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- 使用 Python-LDAP 操作 LDAP
- LDAP操作例子
- Java LDAP操作
- JAVA_基本LDAP操作
- Java操作Ldap
- JAVA操作Ldap示例
- 第一篇
- 敏捷十三
- C#Math类
- Sybase 函数
- iframe跨域访问session丢失问题解决办法
- c操作ldap
- Objective-C语法之代码块的使用
- 山东大学(威海)CSDN高校俱乐部2013年春季学期第一次会员大会
- sybase基础知识_Join,outer,inner
- 草稿test
- TouchXML libxml/tree.h not found(xcode4.5解决方案)
- windows下LDAP的配置
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- Fragment(XXFragment) not attached to Activity 异常。