OpenLDAP中 Schema的详细介绍
本章讲述了如何扩展用户使用的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,你可以这位样划分目录树:
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).
(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 <name> { <oid> | <name>[:<suffix>] }
下面的例子定义了一组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 )