Chinaunix首页 | 论坛 | 博客
  • 博客访问: 557692
  • 博文数量: 78
  • 博客积分: 2043
  • 博客等级: 大尉
  • 技术积分: 733
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-26 11:52
文章分类

全部博文(78)

文章存档

2011年(5)

2009年(64)

2008年(9)

分类: LINUX

2009-04-28 15:21:53

(文章来自OpenLDAP官方文档中的第九章,刚刚接触schema的设计,所以翻译一下,有助于理解里面很多的细节。里克。2007年6月18日)


本章讲述了如何扩展用户使用的schema。本章假设阅读者已经熟悉LDAP/X.500 信息模型。


一、schema文件




二、扩展schema

slapd使用的schema,可以扩展其他的语法,匹配规则,属性类型和对象类。本章将详细描述如何使用slapd定义好的语法和匹配规则为你的应用增加属性类型和类。slapd也可以支持附加的语法,匹配规则和系统schema,但这些需要一写编程,不在此讨论。

定义一个新的schema:
1、获得对象识别码obtain Object Identifer
2、选择一个命名前缀choose a name prefix
3、创建一个本地的schema文件
4、自定义属性类型
5、自定义对象类

1、对象识别码

每一个schema元素,有一个全局唯一的Object Identifier (OID)。OID也被用于标识其他对象。(They are commonly found in protocols described by ASN.1)。在项目中他们承担重要的角色。OIDs是分等级的。你的项目可以获得一个OID,然后进行细分。比如你的项目的OID是1.1,你可以这位样划分目录树:

Table 8.2: OID 层次举例
OIDAssignment
1.1Organization's OID
1.1.1SNMP Elements
1.1.2LDAP Elements
1.1.2.1AttributeTypes
1.1.2.1.1myAttribute
1.1.2.2ObjectClasses
1.1.2.2.1myObjectClass


根据你的OID,你可以为你的项目任意的设计OID结构树。不管你选择怎样的层次,都应该有一份分配等级。这可以是一个文本,或者像OpenLDAP OID Registry。()

更多关于OID识别码(和列表服务,)可以查看

你可以免费的获得OID, apply for an OID under the  (IANA) maintained Private Enterprise arc. Any private enterprise (organization) may request an OID to be assigned under this arc. Just fill out the  form at and your official OID will be sent to you usually within a few days. Your base OID will be something like 1.3.6.1.4.1.X where X is an integer.

Note:不用对IANA上的"MIB/SNMP"感到迷惑,这个表单提供了很多用途,包括识别LDAP schema元素。

当然,OID命名空间可以从国际权威那里得到。(比如 , )

2、名称前缀

为了给每一个schema元素添加识别码,你看需要给schema的元素至少起一个名字(textual name)。这个名字尽量是一个描述,而且不要和其他的名字重复。而且你选用的名字不能和present or future Standard Track names冲突。

为了减少(但是不能避免)潜在的名称冲突,方便的方法是用non-Standard Track来加名称前缀,比如可以描述你当前改动的字母(with a few letters to localize the changes to your organization)。organization, 越小,你的前缀相应的就要长一些。

在下面的例子中,我们选择了“my”作为名称前缀(为了节省空间),这样简短的名字适合非常大型,全球性的组织。通常,我们使用'deFirm' (German company) ,或者 'comExample' (elements associated with organization associated with example.com)。

3、本地schema文件

objectclass 和 attributeTypes 可以用来定义目录中实例的规则。通常我们创建一个包含自定义schema元素的文件。我们在/usr/local/etc/openldap/schema/local.schema创建一个名为local.schema的文件,然后在slapd.conf文件中加上这个文件:
        # include schema
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
# include local schema
include /usr/local/etc/openldap/schema/local.schema
(译者:ubuntu中的ldap安装位置稍有不一样,不可完全按照这个例子粘贴。)

4、属性类型说明Attribute Type Specification

attributetype 用于定义新的属性类型。比如,The directive uses the same Attribute Type Description (as defined in ) used by the attributeTypes attribute found in the subschema subentry。

属性类型描述Attribute Type Description的定义如下:

          AttributeTypeDescription = "(" whsp
numericoid whsp ; AttributeType identifier
[ "NAME" qdescrs ] ; name used in AttributeType
[ "DESC" qdstring ] ; description
[ "OBSOLETE" whsp ]
[ "SUP" woid ] ; derived from this other
; AttributeType
[ "EQUALITY" woid ; Matching Rule name
[ "ORDERING" woid ; Matching Rule name
[ "SUBSTR" woid ] ; Matching Rule name
[ "SYNTAX" whsp noidlen whsp ] ; Syntax OID
[ "SINGLE-VALUE" whsp ] ; default multi-valued
[ "COLLECTIVE" whsp ] ; default not collective
[ "NO-USER-MODIFICATION" whsp ]; default user modifiable
[ "USAGE" whsp AttributeUsage ]; default userApplications
whsp ")"

AttributeUsage =
"userApplications" /
"directoryOperation" /
"distributedOperation" / ; DSA-shared
"dSAOperation" ; DSA-specific, value depends on server
whsp是空格的意思(' ')。numericoid 是全局唯一的 OID,是带.的十进制形式 (e.g. 1.1.0), qdescrs有一个或几个意思, woid 可以使名称或者是 OID 可选择的一定长度的后缀(e.g {10})。

下面的例子,属性类型(attribute types) name 和 cn 是由core.schema中定义的。

        attributeType ( 2.5.4.41 NAME 'name'
DESC 'name(s) associated with the object'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
attributeType ( 2.5.4.3 NAME ( 'cn' 'commonName' )
DESC 'common name(s) assciated with the object'
SUP name )

注意:每一个定义的属性的OID,都提供一个短的名字,和一个简短的介绍,每一个名字都是OID的别名。当slapd返回记录的时候,返回的是第一个名字的类表。

第一个属性,name,holds values of directoryString (UTF-8 encoded Unicode) syntax。这个结构syntax 由OID定义。(1.3.6.1.4.1.1466.115.121.1.15 identifies the directoryString syntax)。

A length recommendation of 32768 is specified. Servers should support values of this length, but may support longer values The field does NOT specify a size constraint, so is ignored on servers (such as slapd) which don't impose such size limits. In addition, the equality and substring matching uses case ignore rules. Below are tables listing commonly used syntax and matching rules (OpenLDAP supports these and many more).
Table 8.3: Commonly Used Syntaxes
NameOIDDescription
boolean1.3.6.1.4.1.1466.115.121.1.7boolean value
directoryString1.3.6.1.4.1.1466.115.121.1.15Unicode (UTF-8) string
distinguishedName1.3.6.1.4.1.1466.115.121.1.12LDAP DN
integer1.3.6.1.4.1.1466.115.121.1.27integer
numericString1.3.6.1.4.1.1466.115.121.1.36numeric string
OID1.3.6.1.4.1.1466.115.121.1.38object identifier
octetString1.3.6.1.4.1.1466.115.121.1.40arbitary octets

Table 8.4: Commonly Used Matching Rules
NameTypeDescription
booleanMatchequalityboolean
caseIgnoreMatchequalitycase insensitive, space insensitive
caseIgnoreOrderingMatchorderingcase insensitive, space insensitive
caseIgnoreSubstringsMatchsubstringscase insensitive, space insensitive
caseExactMatchequalitycase sensitive, space insensitive
caseExactOrderingMatchorderingcase sensitive, space insensitive
caseExactSubstringsMatchsubstringscase sensitive, space insensitive
distinguishedNameMatchequalitydistinguished name
integerMatchequalityinteger
integerOrderingMatchorderinginteger
numericStringMatchequalitynumerical
numericStringOrderingMatchorderingnumerical
numericStringSubstringsMatchsubstringsnumerical
octetStringMatchequalityoctet string
octetStringOrderingStringMatchorderingoctet string
octetStringSubstringsStringMatchorderingoctet string
objectIdentiferMatchequalityobject identifier

第二个属性,cn,是name的子类型,集成了语法,匹配规则和name的用法。commonName 是另一个名字。

Neither attribute is restricted to a single value. Both are meant for usage by user applications. Neither is obsolete nor collective.


下面的部分定义两个例子

(1)myUniqueName

很多组织为用户保留唯一的名字(unique name),虽然用户可以使用displayName,但是这个属性(name)依旧由用户控制。而不是organization。我们可以从 inetorgperson.schema 拷贝displayName ,替换OID,name,和描述(description)。
attributetype ( 1.1.2.1.1 NAME 'myUniqueName'
DESC 'unique name with my organization'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
但是,如果我们要使name属性包含一个断言,这个属性可以被定义为name的子属性。
attributetype ( 1.1.2.1.1 NAME 'myUniqueName'
DESC 'unique name with my organization'
SUP name )
(2)myPhoto

很多的组织为每一个用户保留一个头像。myPhoto属性类型的定义可以用来保存用户的头像。当然用户可以选择jpegPhoto属性类型()(或其子类型)来保存头像。当然你只能在图片符合JPEG File Interchange Format时使用。
当然,一个使用八进制语法的属性类型可以这样的定义:
attributetype ( 1.1.2.1.2 NAME 'myPhoto'
DESC 'a photo (application defined format)'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
SINGLE-VALUE )
在这,语法中并没有置顶photo的格式(format),这里假设访问属性的应用可以对其值进行处理。

如果你想支持多种图片格式,你需要为每一个格式定义属性类型。为图片添加类型信息的前缀。或者使用ASN.1描述值,和use the ;binary transfer option

可以使图片属性能够保存URI,你可以在labeledURI()后创建一个属性,或者创建一个子类型。

attributetype ( 1.1.2.1.3 NAME 'myPhotoURI'
DESC 'URI and optional label referring to a photo'
SUP labeledURI )

5、Object Class描述

objectclasses 用来定义一个新的object class,The directive uses the same Object Class Description (as defined in ) used by the objectClasses attribute found in the subschema subentry。
objectclass < Object Class Description>
Object Class Description由下面的BNF定义:

ObjectClassDescription = "(" whsp
numericoid whsp ; ObjectClass identifier
[ "NAME" qdescrs ]
[ "DESC" qdstring ]
[ "OBSOLETE" whsp ]
[ "SUP" oids ] ; Superior ObjectClasses
[ ( "ABSTRACT" / "STRUCTURAL" / "AUXILIARY" ) whsp ]
; default structural
[ "MUST" oids ] ; AttributeTypes
[ "MAY" oids ] ; AttributeTypes
whsp ")"
(1)myPhotoObject

To define an auxiliary object class which allows myPhoto to be added to any existing entry。

objectclass ( 1.1.2.2.1 NAME 'myPhotoObject'
DESC 'mixin myPhoto'
AUXILIARY
MAY myPhoto )

(2)myPerson

如果你的组织想为每一个用户建立一个私有结构的对象类,你可以为已经存在的person类创建一个子类。比如inetOrgPerson类,然后添加你需要的属性。

objectclass ( 1.1.2.2.2 NAME 'myPerson'
DESC 'my person'
SUP inetOrgPerson
MUST ( myUniqueName $ givenName )
MAY myPhoto )
对象类集成了inetOrgPerson 的required/allowed属性类型。但是需要 (requires) myUniqueName,givenName和allows myPhoto。


6、OID宏

为了方便管理oids的使用,slapd支持对象识别码宏定义。objectIdentifier直接使用宏(name)和OID
。这个OID很可能就是从前面的OID宏派生来的。 slapd.conf语法:

objectIdentifier  {  | [:] }

下面的例子定义了一组OID宏,和他们使用的schema元素:

objectIdentifier myOID  1.1
objectIdentifier mySNMP myOID:1
objectIdentifier myLDAP myOID:2
objectIdentifier myAttributeType myLDAP:1
objectIdentifier myObjectClass myLDAP:2
attributetype ( myAttributeType:3 NAME 'myPhotoURI'
DESC 'URI and optional label referring to a photo'
SUP labeledURI )
objectclass ( myObjectClass:1 NAME 'myPhotoObject'
DESC 'mixin myPhoto'
AUXILIARY
MAY myPhoto )
阅读(9379) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~