LDAP的Schema

LDAP的Schema
schema类似关系数据库的字段说明,包括字段名,数据类型,数据长度等等。系统有一些默认的schema,我的默认schema文件
在/usr/local/openldap/etc/openldap/schema下面,最重要的是core.schema。它定义了一些最基本的字段。
为了适应我们的应用,我们要创建自己的schema文件。我创建的shema文件如下:(文件名:kunmail.schema)

# kunmail-ldap v3 directory schema 

# written by  [email protected] 

# Attribute Type Definitions
attributetype ( 1.3.6.1.4.1.7914.1.2.1.1 NAME 'username' 
DESC 'name of the user on the mailsystem' 
EQUALITY caseIgnoreIA5Match 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.2 NAME 'vuid' 
DESC 'UID of the user on the mailsystem' 
EQUALITY integerMatch 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.3 NAME 'vgid' 
DESC 'GID of the user on the mailsystem' 
EQUALITY integerMatch 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.4 NAME 'maildir' 
DESC 'Path to the maildir/mbox on the mail system' 
EQUALITY caseExactMatch 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.5 NAME 'forwardAddr' 
SUBSTR caseIgnoreSubstringsMatch 
DESC 'Forward mail address' 
EQUALITY caseIgnoreIA5Match 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.6 NAME 'quota' 
DESC 'The amount of space the user can use until all further messages get bounced.' 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.44 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.7 NAME 'storeHost' 
DESC 'On which kunmail server the messagestore of this user is located.' 
EQUALITY caseIgnoreIA5Match 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.8 NAME 'delivery' 
DESC 'Program to execute for all incoming mails.' 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.9 NAME 'clearpw' 
DESC 'name of the user on the mailsystem' 
EQUALITY caseIgnoreIA5Match 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.10 NAME 'home' 
DESC 'Program to execute for all incoming mails.' 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.11 NAME 'mailReplyText' 
DESC 'A reply text for every incoming message' 
SUBSTR caseIgnoreSubstringsMatch 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.44{4096} 
SINGLE-value )
attributetype ( 1.3.6.1.4.1.7914.1.2.1.12 NAME 'active' 
DESC 'The status of a user account: active, nopop, disabled' 
EQUALITY integerMatch 
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 
SINGLE-value )
# Object Class Definitions
objectclass ( 1.3.6.1.4.1.7914.1.2.2.1 NAME 'kunmailUser' 
DESC 'KunMail-LDAP User' SUP top STRUCTURAL 
MUST ( username $ cn $ vuid $ vgid ) 
MAY ( maildir $ home $ clearpw $ 
forwardAddr $ quota $ 
storeHost $ delivery $ 
mailReplyText $ active ) )
现在来说说这个schema文件。 
开始部分是attributeType的定义,相当于字段定义。最后的objectclass是定义数据所包含的属性。 
这里kunmailUser这种数据,要包含maildir $ home $ clearpw $ forwardAddr $ quota $ storeHost $ delivery $ mailReplyText $ active
等可选项,还要包括username $ cn $ vuid $ vgid 必选项。 可选项用MAY()来包含,必选项用MUST()来包含。DESC是说明项。SUP表示父类(
有点像面向对象编程啊)top表示没有父类,他自己是顶级。STRUCTURAL是存储方式,不管他(我也说不清楚) 
接下来解释attributeType的说明项。 
第一个数字是表示序号,至少我是怎么认为的,也许不对,不过。。。管他。 
NAME是表示属性的名字 
DESC是说明 
下面表示的是匹配的方式,SUBSTR是字符串匹配,EQUALITY是相等性匹配,这些在openldap的admin guide里面有,不难看懂 
SYNTAX是表示字段的数据类型。这个admin guide里面也有说明。 
SINGLE-value表示这个属性只有一个值,有些属性可以有多个值,比如联系地址等。默认的话,是多值的。

schema准备好之后,我们要在配置文件中,把这个schema包含进去,让这个schema生效。 
在配置文件slapd.conf中间的开始部分加入这样的一句: 
include /usr/local/openldap/etc/openldap/schema/kunmail.schema
应该注意,上面这句话之前应确保有一句: 
include /usr/local/openldap/etc/openldap/schema/core.schema 
因为kunmail.schema里面有些东西是依赖core.schema的。

猜你喜欢

转载自maosijun.iteye.com/blog/1336395