1 .TH SLAPO-RWM 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2014 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>
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
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 .B rwm-drop-unrequested-attrs {yes|no}
94 Set this to "yes", if the
96 overlay should drop attributes that are not explicitly requested
97 by a search operation.
98 When this is set to "no", the
100 overlay will leave all attributes in place, so that subsequent modules
101 can further manipulate them.
102 In any case, unrequested attributes will be omitted from search results
103 by the frontend, when the search entry response package is encoded.
104 The default value of this setting is "yes".
106 A basic feature of the
108 overlay is the capability to perform suffix massaging between a virtual
109 and a real naming context by means of the
110 .B rwm\-suffixmassage
112 This, in conjunction with proxy backends,
116 or with the relay backend,
117 .BR slapd\-relay (5),
118 allows to create virtual views of databases.
119 A distinguishing feature of this overlay is that, when instantiated
120 before any database, it can modify the DN of requests
123 For this reason, rules that rewrite the empty DN ("")
124 or the subschemaSubentry DN (usually "cn=subschema"),
125 would prevent clients from reading the root DSE or the DSA's schema.
127 .B rwm\-suffixmassage "[<virtual naming context>]" "<real naming context>"
128 Shortcut to implement naming context rewriting; the trailing part
129 of the DN is rewritten from the virtual to the real naming context
130 in the bindDN, searchDN, searchFilterAttrDN, compareDN, compareAttrDN,
131 addDN, addAttrDN, modifyDN, modifyAttrDN, modrDN, newSuperiorDN,
132 deleteDN, exopPasswdDN, and from the real to the virtual naming context
133 in the searchEntryDN, searchAttrDN and matchedDN rewrite contexts.
134 By default no rewriting occurs for the searchFilter
135 and for the referralAttrDN and referralDN rewrite contexts.
136 If no \fI<virtual naming context>\fP is given, the first suffix of the
137 database is used; this requires the
138 .B rwm\-suffixmassage
139 directive be defined \fIafter\fP the database
143 .B rwm\-suffixmassage
144 directive automatically sets the
145 .B rwm\-rewriteEngine
149 See the REWRITING section for details.
151 A string is rewritten according to a set of rules, called a `rewrite
153 The rules are based on POSIX (''extended'') regular expressions with
154 substring matching; basic variable substitution and map resolution
155 of substrings is allowed by specific mechanisms detailed in the following.
156 The behavior of pattern matching/substitution can be altered by a set
161 <rewrite context> ::= <rewrite rule> [...]
162 <rewrite rule> ::= <pattern> <action> [<flags>]
166 The underlying concept is to build a lightweight rewrite module
167 for the slapd server (initially dedicated to the LDAP backend):
170 An incoming string is matched against a set of
173 .IR "regex match pattern" ,
175 .I "substitution pattern"
176 and a set of actions, described by a set of
177 .IR "optional flags" .
178 In case of match, string rewriting is performed according to the
179 substitution pattern that allows to refer to substrings matched in the
181 The actions, if any, are finally performed.
182 Each rule is executed recursively, unless altered by specific action
183 flags; see "Action Flags" for details.
184 A default limit on the recursion level is set, and can be altered
186 .B rwm\-rewriteMaxPasses
187 directive, as detailed in the "Additional Configuration Syntax" section.
188 The substitution pattern allows map resolution of substrings.
189 A map is a generic object that maps a substitution pattern to a value.
190 The flags are divided in "Pattern Matching Flags" and "Action Flags";
191 the former alter the regex match pattern behavior, while the latter
192 alter the actions that are taken after substitution.
193 .SH "Pattern Matching Flags"
196 honors case in matching (default is case insensitive)
199 use POSIX ''basic'' regular expressions (default is ''extended'')
204 recursive passes for a specific rule; does not alter the max total count
205 of passes, so it can only enforce a stricter limit for a specific rule.
209 apply the rule once only (default is recursive)
212 stop applying rules in case of match; the current rule is still applied
213 recursively; combine with `:' to apply the current rule only once
217 stop current operation if the rule matches, and issue an `unwilling to
223 rules back and forth (watch for loops!).
224 Note that `G{1}' is implicit in every rule.
227 ignores errors in rule; this means, in case of error, e.g. issued by a
228 map, the error is treated as a missed match.
229 The `unwilling to perform' is not overridden.
235 as return code if the rule matches; the flag does not alter the recursive
236 behavior of the rule, so, to have it performed only once, it must be used
237 in combination with `:', e.g.
239 returns the value `32' (indicating noSuchObject) after exactly
240 one execution of the rule, if the pattern matches.
241 As a consequence, its behavior is equivalent to `@', with the return
244 or, in other words, `@' is equivalent to `U{0}'.
245 Positive errors are allowed, indicating the related LDAP error codes
246 as specified in \fIdraft-ietf-ldapbis-protocol\fP.
248 The ordering of the flags can be significant.
249 For instance: `IG{2}' means ignore errors and jump two lines ahead
250 both in case of match and in case of error, while `G{2}I' means ignore
251 errors, but jump two lines ahead only in case of match.
253 More flags (mainly Action Flags) will be added as needed.
254 .SH "Pattern Matching"
259 .SH "Substitution Pattern Syntax"
260 Everything starting with `$' requires substitution;
262 the only obvious exception is `$$', which is turned into a single `$';
264 the basic substitution is `$<d>', where `<d>' is a digit;
265 0 means the whole string, while 1-9 is a submatch, as discussed in
270 a `$' followed by a `{' invokes an advanced substitution.
274 `$' `{' [ <operator> ] <name> `(' <substitution> `)' `}'
277 where <name> must be a legal name for the map, i.e.
281 <name> ::= [a-z][a-z0-9]* (case insensitive)
282 <operator> ::= `>' `|' `&' `&&' `*' `**' `$'
286 and <substitution> must be a legal substitution
287 pattern, with no limits on the nesting level.
292 sub-context invocation; <name> must be a legal, already defined
296 external command invocation; <name> must refer to a legal, already
297 defined command name (NOT IMPLEMENTED YET)
300 variable assignment; <name> defines a variable in the running
301 operation structure which can be dereferenced later; operator
303 assigns a variable in the rewrite context scope; operator
305 assigns a variable that scopes the entire session, e.g. its value
306 can be dereferenced later by other rewrite contexts
309 variable dereferencing; <name> must refer to a variable that is
310 defined and assigned for the running operation; operator
312 dereferences a variable scoping the rewrite context; operator
314 dereferences a variable scoping the whole session, e.g. the value
315 is passed across rewrite contexts
318 parameter dereferencing; <name> must refer to an existing parameter;
319 the idea is to make some run-time parameters set by the system
320 available to the rewrite engine, as the client host name, the bind DN
321 if any, constant parameters initialized at config time, and so on;
322 no parameter is currently set by either
326 but constant parameters can be defined in the configuration file
331 Substitution escaping has been delegated to the `$' symbol,
332 which is used instead of `\e' in string substitution patterns
333 because `\e' is already escaped by slapd's low level parsing routines;
334 as a consequence, regex escaping requires
335 two `\e' symbols, e.g. `\fB.*\e.foo\e.bar\fP' must
336 be written as `\fB.*\e\e.foo\e\e.bar\fP'.
338 .\" The symbol can be altered at will by redefining the related macro in
341 .SH "Rewrite Context"
342 A rewrite context is a set of rules which are applied in sequence.
343 The basic idea is to have an application initialize a rewrite
344 engine (think of Apache's mod_rewrite ...) with a set of rewrite
345 contexts; when string rewriting is required, one invokes the
346 appropriate rewrite context with the input string and obtains the
347 newly rewritten one if no errors occur.
349 Each basic server operation is associated to a rewrite context;
350 they are divided in two main groups: client \-> server and
351 server \-> client rewriting.
357 (default) if defined and no specific context
362 searchFilterAttrDN search
364 compareAttrDN compare AVA
366 addAttrDN add AVA (DN portion of "ref" excluded)
368 modifyAttrDN modify AVA (DN portion of "ref" excluded)
369 referralAttrDN add/modify DN portion of referrals
371 renameDN modrdn (the old DN)
372 newSuperiorDN modrdn (the new parent DN, if any)
373 newRDN modrdn (the new relative DN)
375 exopPasswdDN password modify extended operation DN
383 searchEntryDN search (only if defined; no default;
384 acts on DN of search entries)
385 searchAttrDN search AVA (only if defined; defaults
386 to searchEntryDN; acts on DN-syntax
387 attributes of search results)
388 matchedDN all ops (only if applicable; defaults
390 referralDN all ops (only if applicable; defaults
395 .SH "Basic Configuration Syntax"
396 All rewrite/remap directives start with the prefix
398 for backwards compatibility with the historical
402 builtin rewrite/remap capabilities, the prefix may be omitted,
403 but this practice is strongly discouraged.
405 .B rwm\-rewriteEngine { on | off }
406 If `on', the requested rewriting is performed; if `off', no
407 rewriting takes place (an easy way to stop rewriting without
408 altering too much the configuration file).
410 .B rwm\-rewriteContext <context name> "[ alias <aliased context name> ]"
411 <Context name> is the name that identifies the context, i.e. the name
412 used by the application to refer to the set of rules it contains.
413 It is used also to reference sub contexts in string rewriting.
414 A context may alias another one.
415 In this case the alias context contains no rule, and any reference to
416 it will result in accessing the aliased one.
418 .B rwm\-rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
419 Determines how a string can be rewritten if a pattern is matched.
420 Examples are reported below.
421 .SH "Additional Configuration Syntax"
423 .B rwm\-rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
424 Allows to define a map that transforms substring rewriting into
426 The map is referenced inside the substitution pattern of a rule.
428 .B rwm\-rewriteParam <param name> <param value>
429 Sets a value with global scope, that can be dereferenced by the
430 command `${$paramName}'.
432 .B rwm\-rewriteMaxPasses <number of passes> [<number of passes per rule>]
433 Sets the maximum number of total rewriting passes that can be
434 performed in a single rewrite operation (to avoid loops).
435 A safe default is set to 100; note that reaching this limit is still
436 treated as a success; recursive invocation of rules is simply
438 The count applies to the rewriting operation as a whole, not
439 to any single rule; an optional per-rule limit can be set.
440 This limit is overridden by setting specific per-rule limits
441 with the `M{n}' flag.
444 Currently, few maps are builtin but additional map types may be
445 registered at runtime.
449 .B LDAP <URI> [bindwhen=<when>] [version=<version>] [binddn=<DN>] [credentials=<cred>]
452 map expands a value by performing a simple LDAP search.
453 Its configuration is based on a mandatory URI, whose
455 portion must contain exactly one attribute
458 to fetch the DN of an entry).
459 If a multi-valued attribute is used, only the first value is considered.
463 determines when the connection is established.
464 It can take the values
469 respectively indicating that the connection should be created at startup,
470 when required, or any time it is used.
471 In the former two cases, the connection is cached, while in the latter
472 a fresh new one is used all times. This is the default.
478 represent the DN and the password that is used to perform an authenticated
479 simple bind before performing the search operation; if not given,
480 an anonymous connection is used.
484 can be 2 or 3 to indicate the protocol version that must be used.
491 map expands a value by performing an internal LDAP search.
492 Its configuration is based on a mandatory URI, which must begin with
494 (i.e., it must be an LDAP URI and it must not specify a host).
498 portion must contain exactly one attribute, and if
499 a multi-valued attribute is used, only the first value is considered.
501 .SH "REWRITE CONFIGURATION EXAMPLES"
503 # set to `off' to disable rewriting
504 rwm\-rewriteEngine on
506 # the rules the "suffixmassage" directive implies
507 rwm\-rewriteEngine on
508 # all dataflow from client to server referring to DNs
509 rwm\-rewriteContext default
510 rwm\-rewriteRule "(.+,)?<virtualnamingcontext>$" "$1<realnamingcontext>" ":"
512 rwm\-rewriteContext searchFilter
513 # all dataflow from server to client
514 rwm\-rewriteContext searchEntryDN
515 rwm\-rewriteRule "(.+,)?<realnamingcontext>$" "$1<virtualnamingcontext>" ":"
516 rwm\-rewriteContext searchAttrDN alias searchEntryDN
517 rwm\-rewriteContext matchedDN alias searchEntryDN
519 rwm\-rewriteContext referralAttrDN
520 rwm\-rewriteContext referralDN
522 # Everything defined here goes into the `default' context.
523 # This rule changes the naming context of anything sent
524 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
526 rwm\-rewriteRule "(.+,)?dc=home,[ ]?dc=net$"
527 "$1dc=OpenLDAP, dc=org" ":"
529 # since a pretty/normalized DN does not include spaces
530 # after rdn separators, e.g. `,', this rule suffices:
532 rwm\-rewriteRule "(.+,)?dc=home,dc=net$"
533 "$1dc=OpenLDAP,dc=org" ":"
535 # Start a new context (ends input of the previous one).
536 # This rule adds blanks between DN parts if not present.
537 rwm\-rewriteContext addBlanks
538 rwm\-rewriteRule "(.*),([^ ].*)" "$1, $2"
540 # This one eats blanks
541 rwm\-rewriteContext eatBlanks
542 rwm\-rewriteRule "(.*), (.*)" "$1,$2"
544 # Here control goes back to the default rewrite
545 # context; rules are appended to the existing ones.
546 # anything that gets here is piped into rule `addBlanks'
547 rwm\-rewriteContext default
548 rwm\-rewriteRule ".*" "${>addBlanks($0)}" ":"
550 .\" # Anything with `uid=username' is looked up in
551 .\" # /etc/passwd for gecos (I know it's nearly useless,
552 .\" # but it is there just as a guideline to implementing
554 .\" # Note the `I' flag that leaves `uid=username' in place
555 .\" # if `username' does not have a valid account, and the
556 .\" # `:' that forces the rule to be processed exactly once.
557 .\" rwm\-rewriteContext uid2Gecos
558 .\" rwm\-rewriteRule "(.*)uid=([a\-z0\-9]+),(.+)"
559 .\" "$1cn=$2{xpasswd},$3" "I:"
561 .\" # Finally, in a bind, if one uses a `uid=username' DN,
562 .\" # it is rewritten in `cn=name surname' if possible.
563 .\" rwm\-rewriteContext bindDN
564 .\" rwm\-rewriteRule ".*" "${>addBlanks(${>uid2Gecos($0)})}" ":"
566 # Rewrite the search base according to `default' rules.
567 rwm\-rewriteContext searchDN alias default
569 # Search results with OpenLDAP DN are rewritten back with
570 # `dc=home,dc=net' naming context, with spaces eaten.
571 rwm\-rewriteContext searchEntryDN
572 rwm\-rewriteRule "(.*[^ ],)?[ ]?dc=OpenLDAP,[ ]?dc=org$"
573 "${>eatBlanks($1)}dc=home,dc=net" ":"
575 # Bind with email instead of full DN: we first need
576 # an ldap map that turns attributes into a DN (the
577 # argument used when invoking the map is appended to
578 # the URI and acts as the filter portion)
579 rwm\-rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
581 # Then we need to detect DN made up of a single email,
582 # e.g. `mail=someone@example.com'; note that the rule
583 # in case of match stops rewriting; in case of error,
584 # it is ignored. In case we are mapping virtual
585 # to real naming contexts, we also need to rewrite
586 # regular DNs, because the definition of a bindDN
587 # rewrite context overrides the default definition.
588 rwm\-rewriteContext bindDN
589 rwm\-rewriteRule "^mail=[^,]+@[^,]+$" "${attr2dn($0)}" ":@I"
591 # This is a rather sophisticated example. It massages a
592 # search filter in case who performs the search has
593 # administrative privileges. First we need to keep
594 # track of the bind DN of the incoming request, which is
595 # stored in a variable called `binddn' with session scope,
596 # and left in place to allow regular binding:
597 rwm\-rewriteContext bindDN
598 rwm\-rewriteRule ".+" "${&&binddn($0)}$0" ":"
600 # A search filter containing `uid=' is rewritten only
601 # if an appropriate DN is bound.
602 # To do this, in the first rule the bound DN is
603 # dereferenced, while the filter is decomposed in a
604 # prefix, in the value of the `uid=<arg>' AVA, and
605 # in a suffix. A tag `<>' is appended to the DN.
606 # If the DN refers to an entry in the `ou=admin' subtree,
607 # the filter is rewritten OR-ing the `uid=<arg>' with
608 # `cn=<arg>'; otherwise it is left as is. This could be
609 # useful, for instance, to allow apache's auth_ldap-1.4
610 # module to authenticate users with both `uid' and
611 # `cn', but only if the request comes from a possible
612 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
613 rwm\-rewriteContext searchFilter
614 rwm\-rewriteRule "(.*\e\e()uid=([a\-z0\-9_]+)(\e\e).*)"
615 "${**binddn}<>${&prefix($1)}${&arg($2)}${&suffix($3)}"
617 rwm\-rewriteRule "^[^,]+,ou=admin,dc=home,dc=net$"
618 "${*prefix}|(uid=${*arg})(cn=${*arg})${*suffix}" ":@I"
619 rwm\-rewriteRule ".*<>$" "${*prefix}uid=${*arg}${*suffix}" ":"
621 # This example shows how to strip unwanted DN-valued
622 # attribute values from a search result; the first rule
623 # matches DN values below "ou=People,dc=example,dc=com";
624 # in case of match the rewriting exits successfully.
625 # The second rule matches everything else and causes
626 # the value to be rejected.
627 rwm\-rewriteContext searchEntryDN
628 rwm\-rewriteRule ".+,ou=People,dc=example,dc=com$" "$0" ":@"
629 rwm\-rewriteRule ".*" "" "#"
631 .SH "MAPPING EXAMPLES"
632 The following directives map the object class `groupOfNames' to
633 the object class `groupOfUniqueNames' and the attribute type
634 `member' to the attribute type `uniqueMember':
638 map objectclass groupOfNames groupOfUniqueNames
639 map attribute uniqueMember member
643 This presents a limited attribute set from the foreign
650 map attribute manager *
651 map attribute description *
656 These lines map cn, sn, manager, and description to themselves, and
657 any other attribute gets "removed" from the object before it is sent
658 to the client (or sent up to the LDAP server). This is obviously a
659 simplistic example, but you get the point.
663 default slapd configuration file
666 .BR slapd\-config (5),
669 .BR slapd\-relay (5),
674 Pierangelo Masarati; based on back-ldap rewrite/remap features
675 by Howard Chu, Pierangelo Masarati.