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,你可以这位样划分目录树:

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



根据你的OID,你可以为你的项目任意的设计OID结构树。不管你选择怎样的层次,都应该有一份分配等级。这可以是一个文本,或者像OpenLDAP OID Registry。(http://www.openldap.org/faq/index.cgi?file=197

更多关于OID识别码(和列表服务,)可以查看http://www.alvestrand.no/harald/objectid/

你可以免费的获得OID, apply for an OID under the Internet Assigned Numbers Authority (IANA) maintained Private Enterprise arc. Any private enterprise (organization) may request an OID to be assigned under this arc. Just fill out the IANA form at http://www.iana.org/cgi-bin/enterprise.pl 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命名空间可以从国际权威那里得到。(比如 ANSI, BSI

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 RFC2252) 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
Name OID Description
boolean 1.3.6.1.4.1.1466.115.121.1.7 boolean value
directoryString 1.3.6.1.4.1.1466.115.121.1.15 Unicode (UTF-8) string
distinguishedName 1.3.6.1.4.1.1466.115.121.1.12 LDAP DN
integer 1.3.6.1.4.1.1466.115.121.1.27 integer
numericString 1.3.6.1.4.1.1466.115.121.1.36 numeric string
OID 1.3.6.1.4.1.1466.115.121.1.38 object identifier
octetString 1.3.6.1.4.1.1466.115.121.1.40 arbitary octets

Table 8.4: Commonly Used Matching Rules
Name Type Description
booleanMatch equality boolean
caseIgnoreMatch equality case insensitive, space insensitive
caseIgnoreOrderingMatch ordering case insensitive, space insensitive
caseIgnoreSubstringsMatch substrings case insensitive, space insensitive
caseExactMatch equality case sensitive, space insensitive
caseExactOrderingMatch ordering case sensitive, space insensitive
caseExactSubstringsMatch substrings case sensitive, space insensitive
distinguishedNameMatch equality distinguished name
integerMatch equality integer
integerOrderingMatch ordering integer
numericStringMatch equality numerical
numericStringOrderingMatch ordering numerical
numericStringSubstringsMatch substrings numerical
octetStringMatch equality octet string
octetStringOrderingStringMatch ordering octet string
octetStringSubstringsStringMatch ordering octet string
objectIdentiferMatch equality object 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属性类型(RFC2798)(或其子类型)来保存头像。当然你只能在图片符合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(RFC2079)后创建一个属性,或者创建一个子类型。

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 RFC2252) used by the objectClasses attribute found in the subschema subentry。

objectclass <RFC2252 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 <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 )


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值