`

LDAP客户端解读

阅读更多
本文档的Copyleft归yfydz所有,使用GPL发布,可以自由拷贝、转载,转载时请保持文档的完整性,严禁用于任何商业用途。
msn: yfydz_no1@hotmail.com
来源:http://yfydz.cublog.cn
1. Openldap

       Openldap,www.openldap.org,提供了LDAP的免费版本,看的是2.1.22
2. 编译

       编译Openldap-2.1需要使用Berkeley DB 4.1库,可从http://www.sleepycat.com/download/index.shtml下载,目前最新稳定版本为db-4.1.25。此软件包的编译和普通包不同,如果是在UNIX系统下编译,需进行以下命令:
To do a standard UNIX build of Berkeley DB, change to the build_unix directory and then enter the following two commands:

../dist/configure

make

This will build the Berkeley DB library.

To install the Berkeley DB library, enter the following command:

make install

To rebuild Berkeley DB, enter:

make clean

make

If you change your mind about how Berkeley DB is to be configured, you must start from scratch by entering the following command:

make realclean

../dist/configure

make



编译完成后,将build_unix目录下*.h文件copy到/usr/include,build_unix/.libs/libdb-4.1.so文件copy到/usr/lib

      安装完BDB库后就可以编译Openldap:

      
./configure

       ./make depend

       ./make

       ./make test

       编译是需要openssl的支持,如果是openssl-0.9.6以上版本,编译不会出现问题,如果是0.9.5则有两个函数(宏)未定义:sk_new_null()、ERR_error_string_n()(librarys/libldap/tls.c)

       解决方法:

      
#define sk_new_null() sk_new(NULL)

       ERR_error_string_n() 用ERR_error_string代替
3. Openldap客户端

       Openldap客户端程序在openldap-2.1.22/clients/tools目录下,包括ldapcompare, ldapdelete, ldapmodify, ldapmodrdn, ldappasswd, ldapsearch, ldapwhoami等几个客户端程序。如果认证模式为用户名/口令模式,需要重点考虑ldapcompare, ldapmodify, ldappasswd三个程序。
ldapcompare.c
       所有这些程序都使用公共文件common.c,在其中定义了各种全局变量(即系统参数),一些公共函数,如帮助、选项解析等,比较重要有关认证的选项参数有:“-U”、“-w(口令)”、“-X(认证ID)”;其他比较重要的函数有:

tool_args():处理公共配置参数选项

tool_conn_setup():与LDAP服务器建立连接,该函数返回一个LDAP结构指针,出错将exit

tool_bind():根据DN,passwd等信息进行绑定LDAP指针中

tool_server_controls():设置服务器控制参数


一般LDAP访问过程:

… parse argument

tool_conn_setup():与LDAP服务器建立连接,该函数返回一个LDAP结构指针,出错将exit

…

tool_bind():根据DN,passwd等信息进行绑定LDAP指针中

…

if(needed)

tool_server_controls():设置服务器控制参数

…ldap operation

LDAP命令结果解析:

ldap_result()

ldap_parse_result()

ldap_parse_extended_result

…

free(resource)

ldap_unbind()
ldapcompare.c

       属于功能较简单的函数,main()函数中先处理命令行输入参数的处理,处理填入一struct berval结构参数中(内存动态分配),然后使用tool_ldap_setup建立LDAP连接,然后在确定password存入全局变量passwd中(该参数在tool_bind()函数中要使用),然后使用tool_bin()函数绑定,如果要设置一些参数,则使用tool_server_controls()函数设置,参数都为全局变量,然后调用docompare()函数进行信息比较,最后释放动态分配的内存空间,调用ldap_unbind()函数断开LDAP连接。

       Docompare()函数:直接调用ldap_compare_ext_s()函数得到结果

       程序特点:全局变量太多,必须深入到各函数中才知道还使用了哪些参数,可以考虑作为LDAP认证
ldapmodify.c

       该命令用于修改LDAP条目属性参数,可包括增加、删除和修改LDAP条目
ldappasswd.c

       该命令用于修改LDAP用户口令,协议只支持LDAPv3,重点是将新口令,老口令填充到一个struct berelement(librarys/liblber/lber-int.h)中,再转到struct berval结构中(使用ber_flatten2()函数),然后调用重点函数ldap_extended_operation()进行处理,该函数的第二参数使用LDAP_EXOP_MODIFY_PASSWD参数。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics