11.4. Handling Extensible Match Filters
Note
11.4.1. How the Server Handles the Filter
- First, the server finds the plug-in associated with this OID, if an association between the OID and plug-in has already been made.If no association has been made, the server attempts to find a matching rule plug-in that handles the OID. Refer to Section 11.2.3, “How the Server Associates Plug-ins with OIDs”, for details.
- The server then attempts to generate a list of search result candidates from the indexes. In a new Slapi_PBlock parameter block:
- The server puts the filter object in the
SLAPI_PLUGIN_OBJECTparameter and calls the filter index function (specified in theSLAPI_PLUGIN_MR_FILTER_INDEX_FNparameter). - The server checks the value of the
SLAPI_PLUGIN_MR_QUERY_OPERATORparameter. If the operator is a known type (such as SLAPI_OP_EQUAL), the server will use the operator when searching the index for candidates. For details, refer to Section 11.4.2, “Query Operators in Matching Rules”. - The server sets the
SLAPI_PLUGIN_MR_VALUESparameter to each of the values specified in the filter and calls the indexer function (which is specified in theSLAPI_PLUGIN_MR_INDEX_FNparameter) to generate the key (specified in theSLAPI_PLUGIN_MR_KEYSparameter). - The server uses the keys and the query operator to find potential candidates in the indexes.
The server considers all entries to be potential candidates if at least one of the following is true:- The matching rule plug-in has no indexer function (specified in the
SLAPI_PLUGIN_MR_INDEX_FNparameter). - No index applies to the search (for example, if the query operator does not correspond to an index).
- No keys are generated for the specified values.
- For each candidate entry, the server performs the following tasks to determine if the entry matches the search filter:
- The server calls the filter matching function (which is specified in the
SLAPI_PLUGIN_MR_FILTER_MATCH_FNparameter), passing in the filter object, the entry, and the attributes of the entry. - If the entry does not match, but the search request also specifies that the attributes in the DN should be searched, the server calls the filter matching function again, passing in the filter object, the entry, and the attributes in the DN.
- The server then checks the value returned by the filter matching function:
- If the function returns 0, the entry matched the search filter.
- If the function returns -1, the entry did not match the search filter.
- If the function returns an LDAP error code (a positive value), an error occurred.
- If the entry matches the filter, the server verifies that the entry is in the scope of the search before returning the entry to the LDAP client as a search result.
11.4.2. Query Operators in Matching Rules
SLAPI_PLUGIN_MR_QUERY_OPERATOR parameter to determine which operator is specified. The following table lists the possible values for this parameter.
Table 11.3. Query Operators in Extensible Match Filters
| Operator | Description |
|---|---|
SLAPI_OP_LESS | < |
SLAPI_OP_LESS_OR_EQUAL | <= |
SLAPI_OP_EQUAL | = |
SLAPI_OP_GREATER_OR_EQUAL | >= |
SLAPI_OP_GREATER | > |
SLAPI_OP_EQUAL, the server attempts to find the keys in the index that match the value specified in the search filter. In the case of the other query operators, the server attempts to find ranges of keys that match the value.
11.4.3. Writing a Filter Factory Function
- Get the OID from the
SLAPI_PLUGIN_MR_OIDparameter and determine whether that OID is supported by your plug-in.- If the OID is not supported, you need to return the result code
LDAP_UNAVAILABLE_CRITICAL_EXTENSION. The server will send this back to the client. - If the OID is supported, continue with this process.
- Get and check the values of the
SLAPI_PLUGIN_MR_TYPEandSLAPI_PLUGIN_MR_VALUEparameters.The values of these parameters are the attribute type and value specified in the extensible match filter. - You can also get any data that you set in the
SLAPI_PLUGIN_PRIVATEparameter during initialization. Refer to Section 11.7, “Writing an Initialization Function”. - Create a filter object, and include the following information:
- The official OID of the matching rule. [Optional].
- The attribute type specified in the filter.
- The value specified in the filter.
- Any additional data that you want made available to the filter index function (for example, the query operator, if specified in the filter).
The server will call your filter index function at a later time to extract this information from the filter object. - Set the following parameters:
- Set the
SLAPI_PLUGIN_MR_OIDparameter to the official OID of the matching rule if the value of that parameter is not the official OID. [Optional]. - Set the
SLAPI_PLUGIN_OBJECTparameter to the filter object. - Set the
SLAPI_PLUGIN_MR_FILTER_INDEX_FNparameter to the filter index function if you have set up indexes based on this matching rule. (cf. Section 11.4.5, “Writing a Filter Index Function”) [Optional]. - Set the
SLAPI_PLUGIN_MR_FILTER_MATCH_FNparameter to the filter matching function. Refer to Section 11.4.7, “Writing a Filter Matching Function”. - Set the
SLAPI_PLUGIN_DESTROY_FNparameter to the function responsible for freeing the filter object, if you have defined this function. [Optional]. Refer to Section 11.6, “Writing a Destructor Function”, for details.
- Return 0 (or the result code LDAP_SUCCESS) if everything completed successfully.
11.4.4. Getting and Setting Parameters in Filter Factory Functions
Table 11.4. Input and Output Parameters Available to a Filter Factory Function
| Parameter Name | Data Type | Description |
|---|---|---|
SLAPI_PLUGIN_MR_OID | char * | Input parameter. Matching rule OID (if any) specified in the extensible match filter. |
SLAPI_PLUGIN_MR_TYPE | char * | Input parameter. Attribute type (if any) specified in the extensible match filter. |
SLAPI_PLUGIN_MR_VALUE | struct berval * | Input parameter. Value specified in the extensible match filter. |
SLAPI_PLUGIN_PRIVATE | void * | Input parameter. Pointer to any private data originally specified in the initialization function. Refer to Section 11.7, “Writing an Initialization Function”, for details. |
SLAPI_PLUGIN_MR_FILTER_MATCH_FN | mrFilterMatchFn (function pointer) | Output parameter. Name of the function called by the server to match an entry's attribute values against the value in the extensible search filter. |
SLAPI_PLUGIN_MR_FILTER_INDEX_FN | void * (function pointer) | Output parameter. Name of the function called by the server to generate a list of keys used for indexing a set of values. |
SLAPI_PLUGIN_DESTROY_FN | void * (function pointer) | Output parameter. Name of the function to be called to free the filter object. |
SLAPI_PLUGIN_OBJECT | void * | Output parameter. Pointer to the filter object created by your factory function. |
11.4.5. Writing a Filter Index Function
- Get the filter object from the
SLAPI_PLUGIN_OBJECTparameter (if the parameter is set). - Using data from the object, determine and set the values of the following parameters:
SLAPI_PLUGIN_MR_OID- Set to the official OID of the matching rule.SLAPI_PLUGIN_MR_TYPE- Set to the attribute type in the filter object.SLAPI_PLUGIN_MR_VALUES- Set to the values in the filter object.SLAPI_PLUGIN_MR_QUERY_OPERATOR- Set to the query operator that corresponds to this search filter. Refer to Section 11.4.2, “Query Operators in Matching Rules”, for possible values for this parameter.SLAPI_PLUGIN_OBJECT- Set to the filter object.SLAPI_PLUGIN_MR_INDEX_FN- Set to the indexer function. Refer to Section 11.3.5, “Writing the Indexer Function”.
- Return 0 (or the result code LDAP_SUCCESS) if everything completed successfully.
11.4.6. Getting and Setting Parameters in Filter Index Functions
Table 11.5. Input and Output Parameters Available to a Filter Index Function
| Parameter Name | Data Type | Description |
|---|---|---|
SLAPI_PLUGIN_OBJECT | void * | Input and Output parameter. Pointer to the filter object created by the factory function. For details, refer to Section 11.4.3, “Writing a Filter Factory Function”. |
SLAPI_PLUGIN_MR_QUERY_OPERATOR | int | Output parameter. Query operator used by the server to determine how to compare the keys generated from SLAPI_PLUGIN_MR_VALUES and SLAPI_PLUGIN_MR_INDEX_FN against keys in the index. For a list of possible values for this parameter, refer to Section 11.4.2, “Query Operators in Matching Rules”. |
SLAPI_PLUGIN_MR_OID | char * | Output parameter. Official matching rule OID (if any) specified in the extensible match filter. |
SLAPI_PLUGIN_MR_TYPE | char * | Output parameter. Attribute type (if any) specified in the extensible match filter. |
SLAPI_PLUGIN_MR_VALUES | struct berval ** | Output parameter. Pointer to an array of berval structures containing the values specified in the extensible match filter. |
SLAPI_PLUGIN_MR_INDEX_FN | void * (function pointer) | Output parameter. Name of the function called by the server to generate a list of keys used for indexing a set of values. |
11.4.7. Writing a Filter Matching Function
#include “slapi-plugin.h”
typedef int (*mrFilterMatchFn) (void* filter, Slapi_Entry* entry, Slapi_Attr* attrs);
filteris a pointer to the filter object.entryis a pointer to the Section 14.22, “Slapi_Entry” entry that should be compared against the filter.attrsis the first Slapi_Attr attribute in the entry or in the set of DN attributes. (The extensible match filter might specify that the attributes in the DN of an entry should also be included in the search.)
- From the filter object, get the attribute type, the values, and the query operator.
- Find the corresponding attribute in the attributes passed into the function. Remember to search for subtypes of an attribute (for example,
cn=lang-ja) in the filter and in the attributes specified byattrs.You can call the slapi_attr_type_cmp() function to compare the attribute in the filter against the attributes passed in as arguments. - Using the query operator to determine how the values should be compared, compare the values from the filter against the values in the attribute.
- Return one of the following values:
- 0 if the values of the attribute match the value specified in the filter.
- -1 if the values do not match.
- An LDAP error code (a positive number) if an error occurred.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.