3.4. 在 LDAP 搜索过滤器中使用匹配规则


匹配规则指定目录服务器如何将属性中存储的值与搜索过滤器中的值进行比较。匹配规则与属性语法相关。当属性语法定义属性值的格式时,匹配的规则定义如何比较和索引格式。匹配规则也定义如何生成索引密钥。

匹配的规则是一个 schema 元素,它有一个对象标识符(OID)。目录服务器中的所有属性都定义了匹配的规则。有关匹配规则类型的更多信息,请参阅 匹配规则类型。通过在搜索过滤器中指定匹配规则,您可以使用与 schema 中属性定义的匹配规则匹配的规则搜索属性值。

具有可扩展匹配规则的过滤器具有以下语法:

(<attribute>:<matching_rule>:=<value>)

其中:

  • <attribute > 是一个属于您搜索的条目的属性,如 cn,mail,name
  • <matching_rule > 是一个字符串,其中包含您要根据所需语法用于匹配属性值的规则的名称或 OID。例如,case ExactMatch 匹配规则。
  • <value > 是属性值或关系运算符,加上要搜索的属性值。

匹配的规则必须与您搜索的属性的语法兼容。您可以为一个定义不区分大小写的匹配规则的属性运行区分大小写的搜索。例如,name 属性在 schema 定义中具有预定义的 caseIgnoreMatch equality 匹配规则。带有过滤器 (name=Daniel) 的基本等同性搜索会检索包含 名称 属性值(如 DAnieldaniel、Daniel )的条目。带有匹配规则过滤器 (name:caseExactMatch:=Daniel) 的平等搜索会检索只包含 name 属性值 Daniel 的条目。

为 Directory 服务器定义的许多匹配规则与语言代码相关,并设置国际化的合计订单。例如,OID 2.16.840.1.113730.3.3.2.17.1 标识 Finnish collation 顺序。有关支持的国际化订单的完整列表,请参阅 语言排序匹配规则 和语言 子字符串匹配规则

3.4.1. 匹配规则类型

没有指定匹配规则的搜索过滤器,如(employeeNumber>=500)或(sncategorieserson),使用其 schema 定义中属性语法定义的匹配规则。您可以为 schema 定义中的属性定义以下匹配规则类型:

相等
EQUALITY 匹配规则指定如何为相等匹配比较两个值。例如,如何处理 FredFRED 等字符串。更新操作使用 EQUALITY 规则来生成索引密钥。使用过滤器(如 (name=Fred) )搜索操作,使用 EQUALITY 规则将过滤器中的值与条目中的值进行比较。
排序
ORDERING 匹配规则指定如何比较两个值,以确定一个值是否大于或等于另一个值。搜索过滤器,设置一个范围,如 (employeeNumber>=500)(attribute value),使用 ORDERING 规则。具有 ORDERING 规则顺序排列相等值的属性的索引。
SUBSTR
SUBSTR 匹配规则指定如何比较子字符串值。子字符串搜索过滤器,如 (name requireed),使用 SUBSTR 规则。子字符串(sub)索引使用 SUBSTR 规则来生成索引密钥。

除了相等、排序和子字符串匹配规则外,您还可以在搜索过滤器中指定大约和其他可扩展匹配规则。

重要

目录需要匹配的规则来支持搜索或索引对应的搜索过滤器或索引类型。例如,属性必须具有与 EQUALITY 匹配规则,才能支持该属性的相等搜索过滤器和 eq 索引。属性必须具有 ORDERING 匹配规则和 EQUALITY 匹配规则,才能支持范围搜索过滤器和索引范围搜索。

如果搜索操作对没有对应的匹配规则的属性使用了搜索过滤器,则目录服务器会拒绝带有 PROTOCOL_ERRORUNWILLING_TO_PERFORM 的搜索操作。

匹配规则和自定义属性

例如,您要创建一个带有 IA5 String (7-bit ASCII)语法的自定义属性 MyFirstName,在 schema 定义中创建一个 EQUALITY 匹配规则 caseExactIA5Match。带有过滤器 (MyFirstName=Fred) 的搜索返回条目仅具有 MyFirstName 值等于 Fred ;但是,FredFREDfred 是所有有效的 IA5 String 值。如果您希望搜索返回属性值的所有变体,您必须在搜索过滤器中定义 MyFirstName 属性,以使用相等匹配规则 caseIgnoreIA5Match 或明确指定匹配的规则 (MyFirstName:caseIgnoreIA5Match:=Fred)

3.4.2. 常用的匹配规则

以下是常用匹配规则的列表:

Expand
匹配规则描述对象标识符(OID)兼容语法

AND 匹配

执行位 匹配项.

1.2.840.113556.1.4.803

通常与 整数和数字 字符串一起使用。目录服务器自动将数字字符串转换为整数。

OR 匹配

执行位 OR 匹配。

1.2.840.113556.1.4.804

通常与 整数和数字 字符串一起使用。目录服务器自动将数字字符串转换为整数。

booleanMatch

评估要匹配的值是否为 TRUEFALSE

2.5.13.13

布尔值

caseExactIA5Match

对值进行区分大小写的比较。

1.3.6.1.4.1.1466.109.114.1

IA5 语法、URI

caseExactMatch

对值进行区分大小写的比较。

2.5.13.5

目录字符串, 可打印字符串, OID

caseExactOrderingMatch

允许区分大小写的搜索(小于和大于)。

2.5.13.6

目录字符串, 可打印字符串, OID

caseExactSubstringsMatch

执行区分大小写的子字符串和索引搜索。

2.5.13.7

目录字符串, 可打印字符串, OID

caseIgnoreIA5Match

执行值不区分大小写的比较。

1.3.6.1.4.1.1466.109.114.2

IA5 语法、URI

caseIgnoreIA5SubstringsMatch

对子字符串和索引执行不区分大小写的搜索。

1.3.6.1.4.1.1466.109.114.3

IA5 语法、URI

caseIgnoreListMatch

执行值不区分大小写的比较。

2.5.13.11

邮政地址

caseIgnoreListSubstringsMatch

对子字符串和索引执行不区分大小写的搜索。

2.5.13.12

邮政地址

caseIgnoreMatch

执行值不区分大小写的比较。

2.5.13.2

目录字符串, 可打印字符串, OID

caseIgnoreOrderingMatch

允许不区分大小写的搜索(小于和大于)。

2.5.13.3

目录字符串, 可打印字符串, OID

caseIgnoreSubstringsMatch

对子字符串和索引执行不区分大小写的搜索。

2.5.13.4

目录字符串, 可打印字符串, OID

distinguishedNameMatch

比较可分辨名称值。

2.5.13.1

可区分名称(DN)

generalizedTimeMatch

比较采用常规时间格式的值。

2.5.13.27

常规时间

generalizedTimeOrderingMatch

允许对采用 Generalized Time 格式的值进行范围搜索(不超过和大于)。

2.5.13.28

常规时间

integerMatch

评估整数值。

2.5.13.14

整数

integerOrderingMatch

允许对整数值进行范围搜索(小于和大于)。

2.5.13.15

整数

keywordMatch

将给定的搜索值与属性值中的字符串进行比较。

2.5.13.33

目录字符串

numericStringMatch

比较更常规的数字值。

2.5.13.8

数字字符串

numericStringOrderingMatch

对更常规的数字值支持范围搜索(小于和大于)。

2.5.13.9

数字字符串

numericStringSubstringMatch

比较更常规的数字值。

2.5.13.10

数字字符串

objectIdentifierMatch

比较对象标识符(OID)值。

2.5.13.0

对象标识符(OID)

octetStringMatch

评估 octet 字符串值。

2.5.13.17

octet String

octetStringOrderingMatch

在一系列 octet 字符串值上支持范围搜索(小于和大于)。

2.5.13.18

octet String

telephoneNumberMatch

评估电话号码值。

2.5.13.20

电话号码

telephoneNumberSubstringsMatch

对电话号码值执行子字符串和索引搜索。

2.5.13.21

电话号码

uniqueMemberMatch

将 Name & Optional UID 语法的断言值与语法的属性值进行比较

2.5.13.23

名称和可选 UID

wordMatch

将给定的搜索值与属性值中的字符串进行比较。此匹配规则区分大小写。

2.5.13.32

目录字符串

3.4.3. 语言排序匹配规则

对于国际搜索,您可以使用以下语言排序匹配规则:

Expand
匹配规则对象标识符(OID)

English (Case Exact Ordering Match)

2.16.840.1.113730.3.3.2.11.3

Albanian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.44.1

Arabic (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.1.1

Belorussian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.2.1

Bulgarian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.3.1

Catalan (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.4.1

中文 - 简体(区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.49.1

中文 - 繁体(区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.50.1

Croatian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.22.1

Czech (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.5.1

Danish (区分大小写的排序匹配大小)

2.16.840.1.113730.3.3.2.6.1

Dutch (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.33.1

Dutch - Belgian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.34.1

英语 - 美国(区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.11.1

英语 - Canadian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.12.1

英语 - 爱尔兰(问题单不区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.14.1

Estonian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.16.1

Finnish (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.17.1

法语(区分大小写的排序匹配大小写)

2.16.840.1.113730.3.3.2.18.1

法语 - 比利利(区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.19.1

法语 - Canadian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.20.1

法语 - Swiss (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.21.1

德语(区分大小写的排序匹配大小)

2.16.840.1.113730.3.3.2.7.1

德语 - Austrian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.8.1

德语 - Swiss (区分大小写的排序匹配)

2.16.840.1.113730.3.3.2.9.1

Greek (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.10.1

Hebrew (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.27.1

Hungarian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.23.1

Icelandic (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.24.1

Italian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.25.1

Italian - Swiss (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.26.1

日语(区分大小写的排序匹配大小)

2.16.840.1.113730.3.3.2.28.1

韩语(Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.29.1

Latvian, Lettish (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.31.1

Lithuanian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.30.1

Macedonian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.32.1

Norwegian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.35.1

Norwegian - Bokmul (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.36.1

Norwegian - Nynorsk (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.37.1

polish (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.38.1

Romanian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.39.1

Russian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.40.1

Serbian - Cyrillic (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.45.1

Serbian - 拉丁语(Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.41.1

Slovak (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.42.1

Slovenian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.43.1

西班牙语(区分大小写的排序匹配大小写)

2.16.840.1.113730.3.3.2.15.1

Swedish (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.46.1

Turkish (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.47.1

Ukrainian (Case Insensitive Ordering Match)

2.16.840.1.113730.3.3.2.48.1

3.4.4. 语言子字符串匹配规则

对于国际搜索,您可以使用以下语言子字符串匹配规则:

Expand
匹配规则对象标识符(OID)

English (Case Exact Substring Match)

2.16.840.1.113730.3.3.2.11.3.6

Albanian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.44.1.6

Arabic (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.1.1.6

Belorussian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.2.1.6

Bulgarian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.3.1.6

Catalan (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.4.1.6

中文 - 简体(区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.49.1.6

中文 - 繁体(区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.50.1.6

Croatian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.22.1.6

Czech (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.5.1.6

Danish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.6.1.6

Dutch (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.33.1.6

Dutch - Belgian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.34.1.6

英语 - 美国(区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.11.1.6

英语 - Canadian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.12.1.6

英语 - 爱尔兰(问题单不区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.14.1.6

Estonian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.16.1.6

Finnish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.17.1.6

法语(区分大小写的子字符串匹配大小写)

2.16.840.1.113730.3.3.2.18.1.6

法语 - 比利福尼亚(区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.19.1.6

法语 - Canadian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.20.1.6

法语 - Swiss (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.21.1.6

德语(区分大小写的子字符串匹配大小写)

2.16.840.1.113730.3.3.2.7.1.6

德语 - Austrian (区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.8.1.6

德语 - Swiss (区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.9.1.6

Greek (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.10.1.6

Hebrew (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.27.1.6

Hungarian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.23.1.6

Icelandic (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.24.1.6

Italian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.25.1.6

Italian - Swiss (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.26.1.6

日语(区分大小写的子字符串匹配)

2.16.840.1.113730.3.3.2.28.1.6

韩语(Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.29.1.6

Latvian, Lettish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.31.1.6

Lithuanian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.30.1.6

Macedonian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.32.1.6

Norwegian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.35.1.6

Norwegian - Bokmul (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.36.1.6

Norwegian - Nynorsk (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.37.1.6

polish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.38.1.6

Romanian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.39.1.6

Russian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.40.1.6

Serbian - Cyrillic (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.45.1.6

Serbian - 拉丁语(Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.41.1.6

Slovak (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.42.1.6

Slovenian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.43.1.6

西班牙语(区分大小写的子字符串匹配大小写)

2.16.840.1.113730.3.3.2.15.1.6

Swedish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.46.1.6

Turkish (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.47.1.6

Ukrainian (Case Insensitive Substring Match)

2.16.840.1.113730.3.3.2.48.1.6

inchainMatch 匹配规则是搜索过滤器的可扩展匹配,用于在嵌套组中找到 LDAP 条目成员资格。目录服务器支持对象标识符(OID) 1.2.840.113556.1.4.1941chainMatch 中 的人类可读名称。

使用匹配规则仅限于带有可辨识名称(DN)语法的属性。您可以使用 chainMatch 匹配规则来执行以下搜索:

  • 搜索过滤器 (member:1.2.840.113556.1.4.1941:=uid=jdoe,ou=people,dc=example,dc=com) 找到用户 jdoe 是成员的所有直接或间接组。
  • 搜索过滤器 (manager:1.2.840.113556.1.4.1941:=uid=jsmith,ou=people,dc=example,dc=com) 找到其管理器是 jsmith 的所有直接或间接用户。
  • 搜索过滤器 (parentOrganization:1.2.840.113556.1.4.1941:=ou=ExampleCom,ou=europe,dc=example,dc=com) 找到 ExampleCom 所属的所有直接或间接机构。
  • 搜索过滤器 (memberof:1.2.840.113556.1.4.1941:=cn= marketing ,ou=groups,dc=example,dc=com) 找到 marketing 组的所有直接或间接成员。

请注意,出于性能的原因,您必须索引 成员managerparentOrganizationchainMatch 中的 memberof 属性。

目录服务器通过 In Chain 插件默认启用 inchainMatch 匹配规则。但是,在chainMatch 中的 compute 昂贵,只有 Directory Manager 默认具有在 chainMatch 中使用 的权限。要为其他用户授予权限,请修改 oid=1.2.840.113556.1.4.1941,cn=features,cn=config 条目中的访问控制指令(ACI)。如需了解更多详细信息,请参阅为 用户条目启用chainMatch 匹配规则

3.4.5.1. 为用户条目启用 inchainMatch 匹配规则

默认情况下,只有 Directory Manager 具有使用chainMatch 匹配规则的权限,因为 inchainMatch 昂贵。要为其他用户授予权限,请修改 oid=1.2.840.113556.1.4.1941,cn=features,cn=config 条目中的访问控制指令(ACI)。以下流程为 admin 用户授予 读取和 搜索 权限。

先决条件

  • uid=admin,ou=people,dc=example,dc=com 用户条目存在。
  • uid=jdoe,ou=people,dc=example,dc=com 用户条目存在,并属于 cn=Marketing_Germany,ou=groups,dc=example,dc=com 组。
  • cn=Marketing_Germany,ou=groups,dc=example,dc=com 组是 cn=Marketing_EU,ou=groups,dc=example,dc=com 组的嵌套组。

流程

  • 通过替换 oid=1.2.840.113556.1.4.1941,cn=config 条目中的默认 ACI,对 uid=admin,ou=people,dc=example,dc= com读取和 搜索 权限:

    # ldapmodify -D "cn=Directory Manager" -W -H ldap://server.example.com -x
    
    dn: oid=1.2.840.113556.1.4.1941,cn=features,cn=config
    changetype: modify
    replace: aci
    aci: (targetattr != "aci")(version 3.0; acl "InChain Matching Rule"; allow( read, search ) userdn = "ldap:///uid=admin,ou=people,dc=example,dc=com";)
    注意

    要获取多个用户的权限,请将这些用户添加到组中,并在 ACI 的绑定规则中将 groupdn 设为关键字。如需了解更多详细信息,请参阅 定义基于组的访问

验证

  • 搜索用户 uid=jdoe,ou=people,dc=example,dc=com 属于 admin 用户的组:

    $ ldapsearch -D "uid=admin,ou=people,dc=example,dc=com" ldap://server.example.com -W -xLL -b "dc=example,dc=com" "(member:1.2.840.113556.1.4.1941:=uid=jdoe,ou=people,dc=example,dc=com)" dn
    
       dn: cn=Marketing_EU,ou=groups,dc=example,dc=com
       dn: cn=Marketing_Germany,ou=groups,dc=example,dc=com

3.4.5.2. 禁用 inchainMatch 匹配规则

要实现 inchainMatch 匹配规则,目录服务器使用默认启用的 In Chain 插件。如果要在 chainMatch 中禁用,请使用 dsconf 工具禁用 In Chain 插件。

流程

  1. 检查 In Chain 插件是否已启用:

    # dsconf -D "cn=Directory Manager" ldap://server.example.com plugin show 'In Chain'
    dn: cn=In Chain,cn=plugins,cn=config
    cn: In Chain
    nsslapd-pluginDescription: inchain matching rule plugin
    nsslapd-pluginEnabled: on
    ...
  2. 禁用 In Chain 插件:

    # dsconf -D "cn=Directory Manager" ldap://server.example.com plugin set --enabled off 'In Chain'
    
    Successfully changed the cn=In Chain,cn=plugins,cn=config

    该命令为所有用户禁用 inchainMatch 匹配规则。

验证

  • 检查 Directory 服务器是否禁用了 In Chain 插件:

    # dsconf -D "cn=Directory Manager" ldap://server.example.com plugin show 'In Chain'
    dn: cn=In Chain,cn=plugins,cn=config
    cn: In Chain
    nsslapd-pluginDescription: inchain matching rule plugin
    nsslapd-pluginEnabled: off
    ...
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部