1 .TH SLAPO-RWM 5 "2008/07/16" "OpenLDAP 2.4.11"
2 .\" Copyright 1998-2008 The OpenLDAP Foundation, All Rights Reserved.
3 .\" Copying restrictions apply. See the COPYRIGHT file.
4 .\" Copyright 2004, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
5 .\" $OpenLDAP: pkg/ldap/doc/man/man5/slapo-rwm.5,v 1.14.2.5 2008/05/19 23:44:27 quanah Exp $
7 .\" Portions of this document should probably be moved to slapd-ldap(5)
8 .\" and maybe manual pages for librewrite.
11 slapo-rwm \- rewrite/remap overlay to slapd
13 /etc/openldap/slapd.conf
19 performs basic DN/data rewrite and objectClass/attributeType mapping.
20 Its usage is mostly intended to provide virtual views of existing data
21 either remotely, in conjunction with the proxy backend described in
23 or locally, in conjunction with the relay backend described in
26 This overlay is experimental.
28 An important feature of the
30 overlay is the capability to map objectClasses and attributeTypes
31 from the local set (or a subset of it) to a foreign set, and vice versa.
32 This is accomplished by means of the
36 .B rwm-map "{attribute | objectclass} [<local name> | *] {<foreign name> | *}"
37 Map attributeTypes and objectClasses from the foreign server to
38 different values on the local slapd.
39 The reason is that some attributes might not be part of the local
40 slapd's schema, some attribute names might be different but serve the
42 If local or foreign name is `*', the name is preserved.
43 If local name is omitted, the foreign name is removed.
44 Unmapped names are preserved if both local and foreign name are `*',
45 and removed if local name is omitted and foreign name is `*'.
51 must be defined in the local schema; the foreign ones do not have to,
52 but users are encouraged to explicitly define the remote attributeTypes
53 and the objectClasses they intend to map. All in all, when remapping
54 a remote server via back-ldap (\fBslapd-ldap\fP(5))
55 or back-meta (\fBslapd-meta\fP(5))
56 their definition can be easily obtained by querying the \fIsubschemaSubentry\fP
57 of the remote server; the problem should not exist when remapping a local
59 Note, however, that the decision whether to rewrite or not attributeTypes
61 .IR "distinguishedName syntax" ,
62 requires the knowledge of the attributeType syntax.
63 See the REWRITING section for details.
65 Note that when mapping DN-valued attributes from local to remote,
66 first the DN is rewritten, and then the attributeType is mapped;
67 while mapping from remote to local, first the attributeType is mapped,
68 and then the DN is rewritten.
69 As such, it is important that the local attributeType is appropriately
70 defined as using the distinguishedName syntax.
71 Also, note that there are DN-related syntaxes (i.e. compound types with
72 a portion that is DN-valued), like nameAndOptionalUID,
73 whose values are currently not rewritten.
75 If the foreign type of an attribute mapping is not defined on the local
76 server, it might be desirable to have the attribute values normalized after
77 the mapping process. Not normalizing the values can lead to wrong results,
80 overlay is used together with e.g. the
82 overlay. This normalization can be enabled by means of the
83 .B rwm-normalize-mapped-attrs
86 .B rwm-normalize-mapped-attrs {yes|no}
87 Set this to "yes", if the
89 overlay should try to normalize the values of attributes that are mapped from
90 an attribute type that is unknown to the local server. The default value of
93 A basic feature of the
95 overlay is the capability to perform suffix massaging between a virtual
96 and a real naming context by means of the
99 This, in conjunction with proxy backends,
103 or with the relay backend,
105 allows to create virtual views of databases.
106 A distinguishing feature of this overlay is that, when instantiated
107 before any database, it can modify the DN of requests
110 For this reason, rules that rewrite the empty DN ("")
111 or the subschemaSubentry DN (usually "cn=subschema"),
112 would prevent clients from reading the root DSE or the DSA's schema.
114 .B rwm-suffixmassage "[<virtual naming context>]" "<real naming context>"
115 Shortcut to implement naming context rewriting; the trailing part
116 of the DN is rewritten from the virtual to the real naming context
117 in the bindDN, searchDN, searchFilterAttrDN, compareDN, compareAttrDN,
118 addDN, addAttrDN, modifyDN, modifyAttrDN, modrDN, newSuperiorDN,
119 deleteDN, exopPasswdDN, and from the real to the virtual naming context
120 in the searchEntryDN, searchAttrDN and matchedDN rewrite contexts.
121 By default no rewriting occurs for the searchFilter
122 and for the referralAttrDN and referralDN rewrite contexts.
123 If no \fI<virtual naming context>\fP is given, the first suffix of the
124 database is used; this requires the
126 directive be defined \fIafter\fP the database
131 directive automatically sets the
136 See the REWRITING section for details.
138 A string is rewritten according to a set of rules, called a `rewrite
140 The rules are based on POSIX (''extended'') regular expressions with
141 substring matching; basic variable substitution and map resolution
142 of substrings is allowed by specific mechanisms detailed in the following.
143 The behavior of pattern matching/substitution can be altered by a set
148 <rewrite context> ::= <rewrite rule> [...]
149 <rewrite rule> ::= <pattern> <action> [<flags>]
153 The underlying concept is to build a lightweight rewrite module
154 for the slapd server (initially dedicated to the LDAP backend):
157 An incoming string is matched against a set of
160 .IR "regex match pattern" ,
162 .I "substitution pattern"
163 and a set of actions, described by a set of
164 .IR "optional flags" .
165 In case of match, string rewriting is performed according to the
166 substitution pattern that allows to refer to substrings matched in the
168 The actions, if any, are finally performed.
169 Each rule is executed recursively, unless altered by specific action
170 flags; see "Action Flags" for details.
171 A default limit on the recursion level is set, and can be altered
173 .B rwm-rewriteMaxPasses
174 directive, as detailed in the "Additional Configuration Syntax" section.
175 The substitution pattern allows map resolution of substrings.
176 A map is a generic object that maps a substitution pattern to a value.
177 The flags are divided in "Pattern Matching Flags" and "Action Flags";
178 the former alter the regex match pattern behavior, while the latter
179 alter the actions that are taken after substitution.
180 .SH "Pattern Matching Flags"
183 honors case in matching (default is case insensitive)
186 use POSIX ''basic'' regular expressions (default is ''extended'')
191 recursive passes for a specific rule; does not alter the max total count
192 of passes, so it can only enforce a stricter limit for a specific rule.
196 apply the rule once only (default is recursive)
199 stop applying rules in case of match; the current rule is still applied
200 recursively; combine with `:' to apply the current rule only once
204 stop current operation if the rule matches, and issue an `unwilling to
210 rules back and forth (watch for loops!).
211 Note that `G{1}' is implicit in every rule.
214 ignores errors in rule; this means, in case of error, e.g. issued by a
215 map, the error is treated as a missed match.
216 The `unwilling to perform' is not overridden.
222 as return code if the rule matches; the flag does not alter the recursive
223 behavior of the rule, so, to have it performed only once, it must be used
224 in combination with `:', e.g.
226 returns the value `32' (indicating noSuchObject) after exactly
227 one execution of the rule, if the pattern matches.
228 As a consequence, its behavior is equivalent to `@', with the return
231 or, in other words, `@' is equivalent to `U{0}'.
232 Positive errors are allowed, indicating the related LDAP error codes
233 as specified in \fIdraft-ietf-ldapbis-protocol\fP.
235 The ordering of the flags can be significant.
236 For instance: `IG{2}' means ignore errors and jump two lines ahead
237 both in case of match and in case of error, while `G{2}I' means ignore
238 errors, but jump two lines ahead only in case of match.
240 More flags (mainly Action Flags) will be added as needed.
241 .SH "Pattern Matching"
246 .SH "Substitution Pattern Syntax"
247 Everything starting with `$' requires substitution;
249 the only obvious exception is `$$', which is turned into a single `$';
251 the basic substitution is `$<d>', where `<d>' is a digit;
252 0 means the whole string, while 1-9 is a submatch, as discussed in
257 a `$' followed by a `{' invokes an advanced substitution.
261 `$' `{' [ <operator> ] <name> `(' <substitution> `)' `}'
264 where <name> must be a legal name for the map, i.e.
268 <name> ::= [a-z][a-z0-9]* (case insensitive)
269 <operator> ::= `>' `|' `&' `&&' `*' `**' `$'
273 and <substitution> must be a legal substitution
274 pattern, with no limits on the nesting level.
279 sub-context invocation; <name> must be a legal, already defined
283 external command invocation; <name> must refer to a legal, already
284 defined command name (NOT IMPLEMENTED YET)
287 variable assignment; <name> defines a variable in the running
288 operation structure which can be dereferenced later; operator
290 assigns a variable in the rewrite context scope; operator
292 assigns a variable that scopes the entire session, e.g. its value
293 can be dereferenced later by other rewrite contexts
296 variable dereferencing; <name> must refer to a variable that is
297 defined and assigned for the running operation; operator
299 dereferences a variable scoping the rewrite context; operator
301 dereferences a variable scoping the whole session, e.g. the value
302 is passed across rewrite contexts
305 parameter dereferencing; <name> must refer to an existing parameter;
306 the idea is to make some run-time parameters set by the system
307 available to the rewrite engine, as the client host name, the bind DN
308 if any, constant parameters initialized at config time, and so on;
309 no parameter is currently set by either
313 but constant parameters can be defined in the configuration file
318 Substitution escaping has been delegated to the `$' symbol,
319 which is used instead of `\e' in string substitution patterns
320 because `\e' is already escaped by slapd's low level parsing routines;
321 as a consequence, regex escaping requires
322 two `\e' symbols, e.g. `\fB.*\e.foo\e.bar\fP' must
323 be written as `\fB.*\e\e.foo\e\e.bar\fP'.
325 .\" The symbol can be altered at will by redefining the related macro in
328 .SH "Rewrite Context"
329 A rewrite context is a set of rules which are applied in sequence.
330 The basic idea is to have an application initialize a rewrite
331 engine (think of Apache's mod_rewrite ...) with a set of rewrite
332 contexts; when string rewriting is required, one invokes the
333 appropriate rewrite context with the input string and obtains the
334 newly rewritten one if no errors occur.
336 Each basic server operation is associated to a rewrite context;
337 they are divided in two main groups: client \-> server and
338 server \-> client rewriting.
344 (default) if defined and no specific context
349 searchFilterAttrDN search
351 compareAttrDN compare AVA
353 addAttrDN add AVA (DN portion of "ref" excluded)
355 modifyAttrDN modify AVA (DN portion of "ref" excluded)
356 referralAttrDN add/modify DN portion of referrals
361 exopPasswdDN password modify extended operation DN
369 searchEntryDN search (only if defined; no default;
370 acts on DN of search entries)
371 searchAttrDN search AVA (only if defined; defaults
372 to searchEntryDN; acts on DN-syntax
373 attributes of search results)
374 matchedDN all ops (only if applicable; defaults
376 referralDN all ops (only if applicable; defaults
381 .SH "Basic Configuration Syntax"
382 All rewrite/remap directives start with the prefix
384 for backwards compatibility with the historical
388 builtin rewrite/remap capabilities, the prefix may be omitted,
389 but this practice is strongly discouraged.
391 .B rwm-rewriteEngine { on | off }
392 If `on', the requested rewriting is performed; if `off', no
393 rewriting takes place (an easy way to stop rewriting without
394 altering too much the configuration file).
396 .B rwm-rewriteContext <context name> "[ alias <aliased context name> ]"
397 <Context name> is the name that identifies the context, i.e. the name
398 used by the application to refer to the set of rules it contains.
399 It is used also to reference sub contexts in string rewriting.
400 A context may alias another one.
401 In this case the alias context contains no rule, and any reference to
402 it will result in accessing the aliased one.
404 .B rwm-rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
405 Determines how a string can be rewritten if a pattern is matched.
406 Examples are reported below.
407 .SH "Additional Configuration Syntax"
409 .B rwm-rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
410 Allows to define a map that transforms substring rewriting into
412 The map is referenced inside the substitution pattern of a rule.
414 .B rwm-rewriteParam <param name> <param value>
415 Sets a value with global scope, that can be dereferenced by the
416 command `${$paramName}'.
418 .B rwm-rewriteMaxPasses <number of passes> [<number of passes per rule>]
419 Sets the maximum number of total rewriting passes that can be
420 performed in a single rewrite operation (to avoid loops).
421 A safe default is set to 100; note that reaching this limit is still
422 treated as a success; recursive invocation of rules is simply
424 The count applies to the rewriting operation as a whole, not
425 to any single rule; an optional per-rule limit can be set.
426 This limit is overridden by setting specific per-rule limits
427 with the `M{n}' flag.
430 Currently, few maps are builtin but additional map types may be
431 registered at runtime.
435 .B LDAP <URI> [bindwhen=<when>] [version=<version>] [binddn=<DN>] [credentials=<cred>]
438 map expands a value by performing a simple LDAP search.
439 Its configuration is based on a mandatory URI, whose
441 portion must contain exactly one attribute
444 to fetch the DN of an entry).
445 If a multi-valued attribute is used, only the first value is considered.
449 determines when the connection is established.
450 It can take the values
455 respectively indicating that the connection should be created at startup,
456 when required, or any time it is used.
457 In the former two cases, the connection is cached, while in the latter
458 a fresh new one is used all times. This is the default.
464 represent the DN and the password that is used to perform an authenticated
465 simple bind before performing the search operation; if not given,
466 an anonymous connection is used.
470 can be 2 or 3 to indicate the protocol version that must be used.
477 map expands a value by performing an internal LDAP search.
478 Its configuration is based on a mandatory URI, which must begin with
480 (i.e., it must be an LDAP URI and it must not specify a host).
484 portion must contain exactly one attribute, and if
485 a multi-valued attribute is used, only the first value is considered.
487 .SH "REWRITE CONFIGURATION EXAMPLES"
489 # set to `off' to disable rewriting
492 # the rules the "suffixmassage" directive implies
494 # all dataflow from client to server referring to DNs
495 rwm-rewriteContext default
496 rwm-rewriteRule "(.+,)?<virtualnamingcontext>$" "$1<realnamingcontext>" ":"
498 rwm-rewriteContext searchFilter
499 # all dataflow from server to client
500 rwm-rewriteContext searchEntryDN
501 rwm-rewriteRule "(.+,)?<realnamingcontext>$" "$1<virtualnamingcontext>" ":"
502 rwm-rewriteContext searchAttrDN alias searchEntryDN
503 rwm-rewriteContext matchedDN alias searchEntryDN
505 rwm-rewriteContext referralAttrDN
506 rwm-rewriteContext referralDN
508 # Everything defined here goes into the `default' context.
509 # This rule changes the naming context of anything sent
510 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
512 rwm-rewriteRule "(.+,)?dc=home,[ ]?dc=net$"
513 "$1dc=OpenLDAP, dc=org" ":"
515 # since a pretty/normalized DN does not include spaces
516 # after rdn separators, e.g. `,', this rule suffices:
518 rwm-rewriteRule "(.+,)?dc=home,dc=net$"
519 "$1dc=OpenLDAP,dc=org" ":"
521 # Start a new context (ends input of the previous one).
522 # This rule adds blanks between DN parts if not present.
523 rwm-rewriteContext addBlanks
524 rwm-rewriteRule "(.*),([^ ].*)" "$1, $2"
526 # This one eats blanks
527 rwm-rewriteContext eatBlanks
528 rwm-rewriteRule "(.*), (.*)" "$1,$2"
530 # Here control goes back to the default rewrite
531 # context; rules are appended to the existing ones.
532 # anything that gets here is piped into rule `addBlanks'
533 rwm-rewriteContext default
534 rwm-rewriteRule ".*" "${>addBlanks($0)}" ":"
536 .\" # Anything with `uid=username' is looked up in
537 .\" # /etc/passwd for gecos (I know it's nearly useless,
538 .\" # but it is there just as a guideline to implementing
540 .\" # Note the `I' flag that leaves `uid=username' in place
541 .\" # if `username' does not have a valid account, and the
542 .\" # `:' that forces the rule to be processed exactly once.
543 .\" rwm-rewriteContext uid2Gecos
544 .\" rwm-rewriteRule "(.*)uid=([a-z0-9]+),(.+)"
545 .\" "$1cn=$2{xpasswd},$3" "I:"
547 .\" # Finally, in a bind, if one uses a `uid=username' DN,
548 .\" # it is rewritten in `cn=name surname' if possible.
549 .\" rwm-rewriteContext bindDN
550 .\" rwm-rewriteRule ".*" "${>addBlanks(${>uid2Gecos($0)})}" ":"
552 # Rewrite the search base according to `default' rules.
553 rwm-rewriteContext searchDN alias default
555 # Search results with OpenLDAP DN are rewritten back with
556 # `dc=home,dc=net' naming context, with spaces eaten.
557 rwm-rewriteContext searchEntryDN
558 rwm-rewriteRule "(.*[^ ],)?[ ]?dc=OpenLDAP,[ ]?dc=org$"
559 "${>eatBlanks($1)}dc=home,dc=net" ":"
561 # Bind with email instead of full DN: we first need
562 # an ldap map that turns attributes into a DN (the
563 # argument used when invoking the map is appended to
564 # the URI and acts as the filter portion)
565 rwm-rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
567 # Then we need to detect DN made up of a single email,
568 # e.g. `mail=someone@example.com'; note that the rule
569 # in case of match stops rewriting; in case of error,
570 # it is ignored. In case we are mapping virtual
571 # to real naming contexts, we also need to rewrite
572 # regular DNs, because the definition of a bindDN
573 # rewrite context overrides the default definition.
574 rwm-rewriteContext bindDN
575 rwm-rewriteRule "^mail=[^,]+@[^,]+$" "${attr2dn($0)}" ":@I"
577 # This is a rather sophisticated example. It massages a
578 # search filter in case who performs the search has
579 # administrative privileges. First we need to keep
580 # track of the bind DN of the incoming request, which is
581 # stored in a variable called `binddn' with session scope,
582 # and left in place to allow regular binding:
583 rwm-rewriteContext bindDN
584 rwm-rewriteRule ".+" "${&&binddn($0)}$0" ":"
586 # A search filter containing `uid=' is rewritten only
587 # if an appropriate DN is bound.
588 # To do this, in the first rule the bound DN is
589 # dereferenced, while the filter is decomposed in a
590 # prefix, in the value of the `uid=<arg>' AVA, and
591 # in a suffix. A tag `<>' is appended to the DN.
592 # If the DN refers to an entry in the `ou=admin' subtree,
593 # the filter is rewritten OR-ing the `uid=<arg>' with
594 # `cn=<arg>'; otherwise it is left as is. This could be
595 # useful, for instance, to allow apache's auth_ldap-1.4
596 # module to authenticate users with both `uid' and
597 # `cn', but only if the request comes from a possible
598 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
599 rwm-rewriteContext searchFilter
600 rwm-rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
601 "${**binddn}<>${&prefix($1)}${&arg($2)}${&suffix($3)}"
603 rwm-rewriteRule "^[^,]+,ou=admin,dc=home,dc=net$"
604 "${*prefix}|(uid=${*arg})(cn=${*arg})${*suffix}" ":@I"
605 rwm-rewriteRule ".*<>$" "${*prefix}uid=${*arg}${*suffix}" ":"
607 # This example shows how to strip unwanted DN-valued
608 # attribute values from a search result; the first rule
609 # matches DN values below "ou=People,dc=example,dc=com";
610 # in case of match the rewriting exits successfully.
611 # The second rule matches everything else and causes
612 # the value to be rejected.
613 rwm-rewriteContext searchEntryDN
614 rwm-rewriteRule ".+,ou=People,dc=example,dc=com$" "$0" ":@"
615 rwm-rewriteRule ".*" "" "#"
617 .SH "MAPPING EXAMPLES"
618 The following directives map the object class `groupOfNames' to
619 the object class `groupOfUniqueNames' and the attribute type
620 `member' to the attribute type `uniqueMember':
624 map objectclass groupOfNames groupOfUniqueNames
625 map attribute uniqueMember member
629 This presents a limited attribute set from the foreign
636 map attribute manager *
637 map attribute description *
642 These lines map cn, sn, manager, and description to themselves, and
643 any other attribute gets "removed" from the object before it is sent
644 to the client (or sent up to the LDAP server). This is obviously a
645 simplistic example, but you get the point.
648 /etc/openldap/slapd.conf
649 default slapd configuration file
654 .BR slapd\-relay (5),
659 Pierangelo Masarati; based on back-ldap rewrite/remap features
660 by Howard Chu, Pierangelo Masarati.