Showing posts with label LDAP. Show all posts
Showing posts with label LDAP. Show all posts

Thursday, April 30, 2009

LDAP安装过程

前段时间在看LDAP方面的东西,最近重装了Ubuntu之后开始在自己的机器上装一个OpenLDAP。
装的过程中遇到不少问题,不过通过Google的帮忙,全部得到解决。下面装安装过程记录如下:

Berkeley DB 安装需要注意的地方
今天在装OpenLdap,结果要求先装上Berkeley DB,于是就先装BDB了。
按照Linux下安装软件三部曲,进行安装,但是在执行第一步configure时就报出下面这个错误:

Berkeley DB should not be built in the top-level or dist directories.

加上-prefix=/usr/local/BerkeleyDB之后问题同样存在,于是到网上去找了一个解决方案。具体方法如下:
# tar xvfz db-4.4.16.tar.gz
# cd db-4.4.16/build_unix/
# ../dist/configure -prefix=/usr/local/BerkeleyDB
# make
# sudo make install

BerkeleyDB安装完毕之后继续安装OpenLdap,但是configure时又出如下问题:
configure: error: BDB/HDB: BerkeleyDB not available

BerkeleyDB已经安装好了,为什么仍然出现这个错误呢? 继续Google之,发现解决方法如下:
$export CPPFLAGS="-I/usr/local/BerkeleyDB/include"
$export LDFLAGS="-L/usr/local/BerkeleyDB/lib"

需要注意的是上面两个命令需要以root身份执行。
执行完之后,继续configurate,这次还是有错,这次错误变成了:
configure: error: Berkeley DB version mismatch

增加下面一行之后,安装正确.
export LD_LIBRARY_PATH="/usr/local/ssl/lib:/usr/local/BerkeleyDB/lib"


[update in 2008-12-15]
今天重装Openldap再次遇到问题,通过Google找到一位兄弟的解决方案,特地补充进来,希望对于其它遇到相同问题朋友有用。
使用berkeleydb 4.7作为后端数据库时,安装Openldap过程中make这个过程会出现如下错误:
/bin/sh ../../..//libtool --tag=disable-shared --mode=compile cc -g -O2 -I../../../include -I../../../include -I.. -I./.. -I/ceno/lab/berkeleydb/include -c init.c
cc -g -O2 -I../../../include -I../../../include -I.. -I./.. -I/ceno/lab/berkeleydb/include -c init.c -o init.o
init.c: In function `bdb_db_open':
init.c:509: structure has no member named `lk_handle'
init.c: In function `bdb_back_initialize':
init.c:752: warning: passing arg 1 of `db_env_set_func_yield' from incompatible pointer type
make[3]: *** [init.lo] Error 1
make[3]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers/slapd/back-bdb'
make[2]: *** [.backend] Error 1
make[2]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers/slapd'
make[1]: *** [all-common] Error 1
make[1]: Leaving directory `/work/ceno/lab/openldap-2.4.11/servers'
make: *** [all-common] Error 1

现在的邮件列表有一个解决方法,不过这不是官方给出的解决方法,可能会在使用过程中引起其它问题:
http://www.openldap.org/lists/openldap-bugs/200805/msg00154.html

上述错误具体原因应该是berkeleydb 4.7中已经没有了lk_handle这个structure,而在Openldap中没有更新,导致该问题。
具体方法如下:
cd openldap-2.4.11/servers/slapd/back-bdb/
将init.c 和 cache.c中

#if DB_VERSION_FULL >= 0x04060012
改为
#if 0 && DB_VERSION_FULL >= 0x04060012
之后再make 就能通过了。


Openldap安装指南:http://www.openldap.org/doc/admin24/install.html

update 2009/03/13
今天查了些资料,把在安装过程中设置的几个参数搞明白了。
CPPFLAGS,LD_LIBRARY_PATH,LDFLAGS等参数需要在configure时指定,该参数会影响生成的Makefile文件。各参数的具体意义如下:

CPPFLAGS C/C++预处理器的命令行参数。
LDFLAGS 链接器的命令行参数。

LD_LIBRARY_PATH等PATH的意义如下:

CLASSPATH = specifies where the computer searches for java class libraries

LD_LIBRARY_PATH = specifies where the computer looks for dynamically-loaded libraries

PATH = specifies where the computer looks for executables

LIBPATH = also specifies where the computer looks for dynamically-loaded libraries (usually set just in case something doesn't support LD_LIBRARY_PATH)

update:
将文章从javaeye博客转移到目前这个博客中。

LDAP中的objectClass与Attribute

初学LDAP时关于objectClass和Attribute之间的关系总是困扰着我,找过许多的中文资料都没有得到答案。最近终于彻底弄明白了这个问题,决定记录下来,以让后学者少走弯路。非常奇妙的是他们之间的关系与Java里面的一些概念很相似,接下来我会结合Java 来讲讲LDAP中的objectClass与Attribute。
LDAP中每一个Entry必须属于某一个objectClass,用Java的方式来理解这个Entry对应着一个Instance,而 objectClass自然就是class了。
在Java中Class大致可以分为Abstract,concrete两种,只有concrete Class才能生成instance。而在LDAP中objectClass分为三种:Abstract,Structural,AUXIALIARY。具体定义如下:
* Abstract object classes are only intended to be extended by other object classes. An entry must not contain any abstract class unless it also contains a structural or auxiliary class that dervies from that abstract class (i.e., includes a non-abstract object class which has the abstract class in its inheritance chain). All entries must contain at least the "top" abstract object class, in the inheritance chain for their structural class. They may or may not contain other abstract classes in the inheritance chains for their structural class or any of their auxiliary classes.

* Structural object classes are intended to define the crux of what an entry represents. Every entry must include exactly one structural object class chain, and the root of that chain must ultimately be the "top" abstract object class. The structural object class for an entry is not allowed to be changed.

* Auxiliary object classes are intended to define additional qualities of entries. An entry may contain zero or more auxiliary classes, and the set of auxiliary classes associated with an entry may change over time.

简单描述就是:Abstract只用来被其它object class继承,只有当其被Structural object class继承时才出现。要定义一个Entry必须有且只有一个Structural类型的ObjectClass。 Top是一个顶级Abstract ObjectClass,里面定义了一个MUST Attribute:ObjectClass,这就决定了必须有一个其它的Structural ObjectClass才能定义一个Entry.其中ObjectClass又可以存在继承关系,该继承关系于Java中有点相似,子ObjectClass会继承父ObjectClass中的全部Attributes.

接下来看一看ObjectClass与Attribute的关系。
如同Java里面的一个类可以包括多个Field,在业务上可能会定义某些Field是必须的,另外一些是可选的。在LDAP中也存在类似关系,每一个ObjectClass都定义了一些Attribute,其Attribute仍然可以是ObjectClass。在这些Attriubte中分为两种类型MUST,MAY, MUST表示这个Entry必须包括的属性,MAY为可选。一个ObjectClass的Attribute也包括所有继承自父ObjectClass和自身定义的ObjectClass。
下面用一个类型进行说明:
objectclass ( 2.5.6.0 NAME 'top' ABSTRACT
MUST objectClass )
objectclass ( 1.3.6.1.4.1.1466.344 NAME 'dcObject'
DESC 'RFC2247: domain component object'
SUP top AUXILIARY
MUST dc )
上面是两个objectclass的定义,其中top为ABSTRACT,dcObject为AUXILIARY,这两个类型都不能定义Entry.下面这个LDIF文件在导入到LDAP时会出错:
dn: dc=java,dc=com
objectClass:dcObject
dc: java.com

要定义这个Entry必须找到一个STRUCTURAL类型的ObjectClass。
objectClasses: ( 2.5.6.4 NAME 'organization'
DESC 'RFC2256: an organization' SUP top STRUCTURAL
MUST o
MAY ( userPassword $ searchGuide $ seeAlso $ businessCategory
$ x121Address $ registeredAddress $ destinationIndicator
$ preferredDeliveryMethod $ telexNumber $ teletexTerminalIdentifier
$ telephoneNumber $ internationaliSDNNumber $ facsimileTelephoneNumber
$ street $ postOfficeBox $ postalCode $ postalAddress
$ physicalDeliveryOfficeName $ st $ l $ description ) )
这个objectClass的类型为STRUCTURAL,因此可以用来定义Entry.具体定义如下
dn: dc=java,dc=com
objectClass:dcObject
objectClass:organization
dc: java.com
o: java.com

其中dc:java.com为dcObject的MUST Attribute,o: java.com为organization的MUST Attribute。

ps:下文原来是放在javaeye的博客中,现在那边不再更新,将其转移到这里。