]> git.sur5r.net Git - openldap/blob - doc/man/man5/slapo-rwm.5
20815ddcfb0f21f5ebd2e11ecd3bb420f160413a
[openldap] / doc / man / man5 / slapo-rwm.5
1 .TH SLAPO-RWM 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2004 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$
6 .\"
7 .\" Portions of this document should probably be moved to slapd-ldap(5)
8 .\" and maybe manual pages for librewrite.
9 .\"
10 .SH NAME
11 slapo-rwm \- rewrite/remap overlay
12 .SH SYNOPSIS
13 ETCDIR/slapd.conf
14 .SH DESCRIPTION
15 The
16 .B rwm
17 overlay to
18 .BR slapd (8)
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
22 .BR slapd-ldap (5),
23 or locally, in conjunction with the relay backend described in
24 .BR slapd-relay (5).
25 .SH MAPPING
26 An important feature of the
27 .B rwm
28 overlay is the capability to map objectClasses and attributeTypes
29 from the local set (or a subset of it) to a foreign set, and vice versa.
30 This is accomplished by means of the 
31 .B rwm-map
32 directive.
33 .TP
34 .B rwm-map "{attribute | objectclass} [<local name> | *] {<foreign name> | *}"
35 Map attributeTypes and objectClasses from the foreign server to
36 different values on the local slapd.
37 The reason is that some attributes might not be part of the local
38 slapd's schema, some attribute names might be different but serve the
39 same purpose, etc.
40 If local or foreign name is `*', the name is preserved.
41 If local name is omitted, the foreign name is removed.
42 Unmapped names are preseved if both local and foreign name are `*',
43 and removed if local name is omitted and foreign name is `*'.
44 .LP
45 The local 
46 .I objectClasses 
47 and 
48 .I attributeTypes 
49 must be defined in the local schema; the foreign ones do not have to.
50 Note, however, that the decision whether to rewrite or not attributeTypes
51 with 
52 .IR "distinguishedName syntax" ,
53 requires the knowledge of the attributeType syntax.
54 See the REWRITING section for details.
55 .LP
56 Note that when mapping DN-valued attributes from local to remote,
57 first the DN is rewritten, and then the attributeType is mapped;
58 while mapping from remote to local, first the attributeType is mapped,
59 and then the DN is rewritten.
60 As such, it is important that the local attributeType is appropriately
61 defined as using the distinguishedName syntax.
62 Also, note that there are DN-related syntaxes, like nameAndOptionalUID,
63 whose values are currenlty not rewritten.
64 .SH SUFFIX MASSAGING
65 A basic feature of the
66 .B rwm
67 overlay is the capability to perform suffix massaging between a virtual
68 and a real naming context by means of the 
69 .B rwm-suffixmassage
70 directive.
71 .TP
72 .B rwm-suffixmassage "[<virtual naming context>]" "<real naming context>"
73 Shortcut to implement naming context rewriting; the trailing part
74 of the DN is rewritten from the virtual to the real naming context
75 in the bindDN, searchDN, searchFilterAttrDN, compareDN, compareAttrDN,
76 addDN, addAttrDN, modifyDN, modifyAttrDN, modrDN, newSuperiorDN,
77 deleteDN, exopPasswdDN, and from the real to the virtual naming context
78 in the searchEntryDN, searchAttrDN and matchedDN rewrite contexts.
79 By default no rewriting occurs for the searchFilter 
80 and for the referralAttrDN and referralDN rewrite contexts.
81 If no \fI<virtual naming context>\fP is given, the first suffix of the
82 database is used; this requires the 
83 .B rwm-suffixmassage
84 directive be defined \fIafter\fP the database
85 .B suffix
86 directive.
87 The
88 .B rwm-suffixmassage
89 directive automatically sets the
90 .B rwm-rewriteEngine
91 to
92 .BR ON .
93 .LP
94 See the REWRITING section for details.
95 .SH REWRITING
96 A string is rewritten according to a set of rules, called a `rewrite
97 context'.
98 The rules are based on POSIX (''extended'') regular expressions with
99 substring matching; basic variable substitution and map resolution 
100 of substrings is allowed by specific mechanisms detailed in the following.
101 The behavior of pattern matching/substitution can be altered by a set
102 of flags.
103 .LP
104 .RS
105 .nf
106 <rewrite context> ::= <rewrite rule> [...]
107 <rewrite rule> ::= <pattern> <action> [<flags>]
108 .fi
109 .RE
110 .LP
111 The underlying concept is to build a lightweight rewrite module
112 for the slapd server (initially dedicated to the LDAP backend):
113 .LP
114 .SH Passes
115 An incoming string is matched agains a set of 
116 .IR rewriteRules .
117 Rules are made of a 
118 .IR "regex match pattern" , 
119
120 .I "substitution pattern"
121 and a set of actions, described by a set of 
122 .IR "optional flags" .
123 In case of match, string rewriting is performed according to the
124 substitution pattern that allows to refer to substrings matched in the
125 incoming string.
126 The actions, if any, are finally performed.
127 Each rule is executed recursively, unless altered by specific action 
128 flags; see "Action Flags" for details.
129 A default limit on the recursion level is set, and can be altered
130 by the
131 .B rwm-rewriteMaxPasses
132 directive, as detailed in the "Additional Configuration Syntax" section.
133 The substitution pattern allows map resolution of substrings.
134 A map is a generic object that maps a substitution pattern to a value.
135 The flags are divided in "Pattern Matching Flags" and "Action Flags";
136 the former alter the regex match pattern behavior, while the latter
137 alter the actions that are taken after substitution.
138 .SH "Pattern Matching Flags"
139 .TP
140 .B `C'
141 honors case in matching (default is case insensitive)
142 .TP
143 .B `R'
144 use POSIX ''basic'' regular expressions (default is ''extended'')
145 .TP
146 .B `M{n}'
147 allow no more than
148 .B n
149 recursive passes for a specific rule; does not alter the max total count
150 of passes, so it can only enforce a stricter limit for a specific rule.
151 .SH "Action Flags"
152 .TP
153 .B `:'
154 apply the rule once only (default is recursive)
155 .TP
156 .B `@'
157 stop applying rules in case of match; the current rule is still applied 
158 recursively; combine with `:' to apply the current rule only once 
159 and then stop.
160 .TP
161 .B `#'
162 stop current operation if the rule matches, and issue an `unwilling to
163 perform' error.
164 .TP
165 .B `G{n}'
166 jump
167 .B n
168 rules back and forth (watch for loops!).
169 Note that `G{1}' is implicit in every rule.
170 .TP
171 .B `I'
172 ignores errors in rule; this means, in case of error, e.g. issued by a
173 map, the error is treated as a missed match.
174 The `unwilling to perform' is not overridden.
175 .TP
176 .B `U{n}'
177 uses
178 .B
179 n
180 as return code if the rule matches; the flag does not alter the recursive
181 behavior of the rule, so, to have it performed only once, it must be used 
182 in combination with `:', e.g.
183 .B `:U{16}'
184 returns the value `16' after exactly one execution of the rule, if the
185 pattern matches.
186 As a consequence, its behavior is equivalent to `@', with the return
187 code set to
188 .BR n ;
189 or, in other words, `@' is equivalent to `U{0}'.
190 By convention, the freely available codes are above 16 included;
191 the others are reserved.
192 .LP
193 The ordering of the flags can be significant.
194 For instance: `IG{2}' means ignore errors and jump two lines ahead
195 both in case of match and in case of error, while `G{2}I' means ignore
196 errors, but jump two lines ahead only in case of match.
197 .LP
198 More flags (mainly Action Flags) will be added as needed.
199 .SH "Pattern Matching"
200 See
201 .BR regex (7)
202 and/or
203 .BR re_format (7).
204 .SH "Substitution Pattern Syntax"
205 Everything starting with `$' requires substitution;
206 .LP
207 the only obvious exception is `$$', which is turned into a single `$';
208 .LP
209 the basic substitution is `$<d>', where `<d>' is a digit;
210 0 means the whole string, while 1-9 is a submatch, as discussed in 
211 .BR regex (7)
212 and/or
213 .BR re_format (7).
214 .LP
215 a `$' followed by a `{' invokes an advanced substitution.
216 The pattern is:
217 .LP
218 .RS
219 `$' `{' [ <operator> ] <name> `(' <substitution> `)' `}'
220 .RE
221 .LP
222 where <name> must be a legal name for the map, i.e.
223 .LP
224 .RS
225 .nf
226 <name> ::= [a-z][a-z0-9]* (case insensitive)
227 <operator> ::= `>' `|' `&' `&&' `*' `**' `$'
228 .fi
229 .RE
230 .LP
231 and <substitution> must be a legal substitution
232 pattern, with no limits on the nesting level.
233 .LP
234 The operators are:
235 .TP
236 .B >
237 sub-context invocation; <name> must be a legal, already defined
238 rewrite context name
239 .TP
240 .B |
241 external command invocation; <name> must refer to a legal, already
242 defined command name (NOT IMPLEMENTED YET)
243 .TP
244 .B &
245 variable assignment; <name> defines a variable in the running
246 operation structure which can be dereferenced later; operator
247 .B &
248 assigns a variable in the rewrite context scope; operator
249 .B &&
250 assigns a variable that scopes the entire session, e.g. its value
251 can be derefenced later by other rewrite contexts
252 .TP
253 .B *
254 variable dereferencing; <name> must refer to a variable that is
255 defined and assigned for the running operation; operator
256 .B *
257 dereferences a variable scoping the rewrite context; operator
258 .B **
259 dereferences a variable scoping the whole session, e.g. the value
260 is passed across rewrite contexts
261 .TP
262 .B $
263 parameter dereferencing; <name> must refer to an existing parameter;
264 the idea is to make some run-time parameters set by the system
265 available to the rewrite engine, as the client host name, the bind DN
266 if any, constant parameters initialized at config time, and so on;
267 no parameter is currently set by either 
268 .B back\-ldap
269 or
270 .BR back\-meta ,
271 but constant parameters can be defined in the configuration file
272 by using the
273 .B rewriteParam
274 directive.
275 .LP
276 Substitution escaping has been delegated to the `$' symbol, 
277 which is used instead of `\e' in string substitution patterns
278 because `\e' is already escaped by slapd's low level parsing routines;
279 as a consequence, regex escaping requires
280 two `\e' symbols, e.g. `\fB.*\e.foo\e.bar\fP' must
281 be written as `\fB.*\e\e.foo\e\e.bar\fP'.
282 .\"
283 .\" The symbol can be altered at will by redefining the related macro in
284 .\" "rewrite-int.h".
285 .\"
286 .SH "Rewrite Context"
287 A rewrite context is a set of rules which are applied in sequence.
288 The basic idea is to have an application initialize a rewrite
289 engine (think of Apache's mod_rewrite ...) with a set of rewrite
290 contexts; when string rewriting is required, one invokes the
291 appropriate rewrite context with the input string and obtains the
292 newly rewritten one if no errors occur.
293 .LP
294 Each basic server operation is associated to a rewrite context;
295 they are divided in two main groups: client \-> server and
296 server \-> client rewriting.
297 .LP
298 client -> server:
299 .LP
300 .RS
301 .nf
302 (default)            if defined and no specific context 
303                      is available
304 bindDN               bind
305 searchDN             search
306 searchFilter         search
307 searchFilterAttrDN   search
308 compareDN            compare
309 compareAttrDN        compare AVA
310 addDN                add
311 addAttrDN            add AVA (DN portion of "ref" excluded)
312 modifyDN             modify
313 modifyAttrDN         modify AVA (DN portion of "ref" excluded)
314 referralAttrDN       add/modify DN portion of referrals
315                      (default to none)
316 modrDN               modrdn
317 newSuperiorDN        modrdn
318 deleteDN             delete
319 exopPasswdDN         passwd exop DN
320 .fi
321 .RE
322 .LP
323 server -> client:
324 .LP
325 .RS
326 .nf
327 searchEntryDN        search (only if defined; no default;
328                      acts on DN of search entries)
329 searchAttrDN         search AVA (only if defined; defaults
330                      to searchEntryDN; acts on DN-syntax
331                      attributes of search results)
332 matchedDN            all ops (only if applicable; defaults
333                      to searchEntryDN)
334 referralDN           all ops (only if applicable; defaults
335                      to none)
336 .fi
337 .RE
338 .LP
339 .SH "Basic Configuration Syntax"
340 All rewrite/remap directives start with the prefix
341 .BR rwm- ;
342 for backwards compatibility with the historical
343 .BR slapd-ldap (5)
344 and
345 .BR slapd-meta (5)
346 builtin rewrite/remap capabilities, the prefix may be omitted, 
347 but this practice is strongly discouraged.
348 .TP
349 .B rwm-rewriteEngine { on | off }
350 If `on', the requested rewriting is performed; if `off', no
351 rewriting takes place (an easy way to stop rewriting without
352 altering too much the configuration file).
353 .TP
354 .B rwm-rewriteContext <context name> "[ alias <aliased context name> ]"
355 <Context name> is the name that identifies the context, i.e. the name
356 used by the application to refer to the set of rules it contains.
357 It is used also to reference sub contexts in string rewriting.
358 A context may aliase another one.
359 In this case the alias context contains no rule, and any reference to
360 it will result in accessing the aliased one.
361 .TP
362 .B rwm-rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
363 Determines how a string can be rewritten if a pattern is matched.
364 Examples are reported below.
365 .SH "Additional Configuration Syntax"
366 .TP
367 .B rwm-rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
368 Allows to define a map that transforms substring rewriting into
369 something else.
370 The map is referenced inside the substitution pattern of a rule.
371 .TP
372 .B rwm-rewriteParam <param name> <param value>
373 Sets a value with global scope, that can be dereferenced by the
374 command `${$paramName}'.
375 .TP
376 .B rwm-rewriteMaxPasses <number of passes> [<number of passes per rule>]
377 Sets the maximum number of total rewriting passes that can be
378 performed in a single rewrite operation (to avoid loops).
379 A safe default is set to 100; note that reaching this limit is still
380 treated as a success; recursive invocation of rules is simply 
381 interrupted.
382 The count applies to the rewriting operation as a whole, not 
383 to any single rule; an optional per-rule limit can be set.
384 This limit is overridden by setting specific per-rule limits
385 with the `M{n}' flag.
386 .SH "REWRITE CONFIGURATION EXAMPLES"
387 .nf
388 # set to `off' to disable rewriting
389 rwm-rewriteEngine on
390
391 # the rules the "suffixmassage" directive implies
392 rwm-rewriteEngine on
393 # all dataflow from client to server referring to DNs
394 rwm-rewriteContext default
395 rwm-rewriteRule "(.*)<virtualnamingcontext>$" "$1<realnamingcontext>" ":"
396 # empty filter rule
397 rwm-rewriteContext searchFilter
398 # all dataflow from server to client
399 rwm-rewriteContext searchEntryDN
400 rwm-rewriteRule "(.*)<realnamingcontext>$" "$1<virtualnamingcontext>" ":"
401 rwm-rewriteContext searchAttrDN alias searchEntryDN
402 rwm-rewriteContext matchedDN alias searchEntryDN
403
404 # Everything defined here goes into the `default' context.
405 # This rule changes the naming context of anything sent
406 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
407
408 rwm-rewriteRule "(.*)dc=home,[ ]?dc=net$"
409             "$1dc=OpenLDAP, dc=org"  ":"
410
411 # since a pretty/normalized DN does not include spaces
412 # after rdn separators, e.g. `,', this rule suffices:
413
414 rwm-rewriteRule "(.*)dc=home,dc=net$"
415             "$1dc=OpenLDAP,dc=org"  ":"
416
417 # Start a new context (ends input of the previous one).
418 # This rule adds blanks between DN parts if not present.
419 rwm-rewriteContext  addBlanks
420 rwm-rewriteRule     "(.*),([^ ].*)" "$1, $2"
421
422 # This one eats blanks
423 rwm-rewriteContext  eatBlanks
424 rwm-rewriteRule     "(.*), (.*)" "$1,$2"
425
426 # Here control goes back to the default rewrite
427 # context; rules are appended to the existing ones.
428 # anything that gets here is piped into rule `addBlanks'
429 rwm-rewriteContext  default
430 rwm-rewriteRule     ".*" "${>addBlanks($0)}" ":"
431
432 .\" # Anything with `uid=username' is looked up in
433 .\" # /etc/passwd for gecos (I know it's nearly useless,
434 .\" # but it is there just as a guideline to implementing
435 .\" # custom maps).
436 .\" # Note the `I' flag that leaves `uid=username' in place 
437 .\" # if `username' does not have a valid account, and the
438 .\" # `:' that forces the rule to be processed exactly once.
439 .\" rwm-rewriteContext  uid2Gecos
440 .\" rwm-rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
441 .\"                 "$1cn=$2{xpasswd},$3"      "I:"
442 .\" 
443 .\" # Finally, in a bind, if one uses a `uid=username' DN,
444 .\" # it is rewritten in `cn=name surname' if possible.
445 .\" rwm-rewriteContext  bindDN
446 .\" rwm-rewriteRule     ".*" "${>addBlanks(${>uid2Gecos($0)})}" ":"
447 .\" 
448 # Rewrite the search base according to `default' rules.
449 rwm-rewriteContext  searchDN alias default
450
451 # Search results with OpenLDAP DN are rewritten back with
452 # `dc=home,dc=net' naming context, with spaces eaten.
453 rwm-rewriteContext  searchEntryDN
454 rwm-rewriteRule     "(.*[^ ],)?[ ]?dc=OpenLDAP,[ ]?dc=org$"
455                 "${>eatBlanks($1)}dc=home,dc=net"    ":"
456
457 # Bind with email instead of full DN: we first need
458 # an ldap map that turns attributes into a DN (the
459 # argument used when invoking the map is appended to 
460 # the URI and acts as the filter portion)
461 rwm-rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
462
463 # Then we need to detect DN made up of a single email,
464 # e.g. `mail=someone@example.com'; note that the rule
465 # in case of match stops rewriting; in case of error,
466 # it is ignored.  In case we are mapping virtual
467 # to real naming contexts, we also need to rewrite
468 # regular DNs, because the definition of a bindDN
469 # rewrite context overrides the default definition.
470 rwm-rewriteContext bindDN
471 rwm-rewriteRule "^mail=[^,]+@[^,]+$" "${attr2dn($0)}" ":@I"
472
473 # This is a rather sophisticated example. It massages a
474 # search filter in case who performs the search has
475 # administrative privileges.  First we need to keep
476 # track of the bind DN of the incoming request, which is
477 # stored in a variable called `binddn' with session scope,
478 # and left in place to allow regular binding:
479 rwm-rewriteContext  bindDN
480 rwm-rewriteRule     ".+" "${&&binddn($0)}$0" ":"
481
482 # A search filter containing `uid=' is rewritten only
483 # if an appropriate DN is bound.
484 # To do this, in the first rule the bound DN is
485 # dereferenced, while the filter is decomposed in a
486 # prefix, in the value of the `uid=<arg>' AVA, and 
487 # in a suffix. A tag `<>' is appended to the DN. 
488 # If the DN refers to an entry in the `ou=admin' subtree, 
489 # the filter is rewritten OR-ing the `uid=<arg>' with
490 # `cn=<arg>'; otherwise it is left as is. This could be
491 # useful, for instance, to allow apache's auth_ldap-1.4
492 # module to authenticate users with both `uid' and
493 # `cn', but only if the request comes from a possible
494 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
495 rwm-rewriteContext searchFilter
496 rwm-rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
497   "${**binddn}<>${&prefix($1)}${&arg($2)}${&suffix($3)}"
498   ":I"
499 rwm-rewriteRule "^[^,]+,ou=admin,dc=home,dc=net$"
500   "${*prefix}|(uid=${*arg})(cn=${*arg})${*suffix}" ":@I"
501 rwm-rewriteRule ".*<>$" "${*prefix}uid=${*arg}${*suffix}" ":"
502
503 # This example shows how to strip unwanted DN-valued
504 # attribute values from a search result; the first rule
505 # matches DN values below "ou=People,dc=example,dc=com";
506 # in case of match the rewriting exits successfully.
507 # The second rule matches everything else and causes
508 # the value to be rejected.
509 rwm-rewriteContext searchEntryDN
510 rwm-rewriteRule ".+,ou=People,dc=example,dc=com$" "$0" ":@"
511 rwm-rewriteRule ".*" "" "#"
512 .fi
513 .SH "MAPPING EXAMPLES"
514 The following directives map the object class `groupOfNames' to
515 the object class `groupOfUniqueNames' and the attribute type
516 `member' to the attribute type `uniqueMember':
517 .LP
518 .RS
519 .nf
520 map objectclass groupOfNames groupOfUniqueNames
521 map attribute uniqueMember member
522 .fi
523 .RE
524 .LP
525 This presents a limited attribute set from the foreign
526 server:
527 .LP
528 .RS
529 .nf
530 map attribute cn *
531 map attribute sn *
532 map attribute manager *
533 map attribute description *
534 map attribute *
535 .fi
536 .RE
537 .LP
538 These lines map cn, sn, manager, and description to themselves, and 
539 any other attribute gets "removed" from the object before it is sent 
540 to the client (or sent up to the LDAP server).  This is obviously a 
541 simplistic example, but you get the point.
542 .SH FILES
543 .TP
544 ETCDIR/slapd.conf
545 default slapd configuration file
546 .SH SEE ALSO
547 .BR slapd.conf (5),
548 .BR slapd\-ldap (5),
549 .BR slapd\-meta (5),
550 .BR slapd\-relay (5),
551 .BR slapd (8),
552 .BR regex (7),
553 .BR re_format (7).
554 .SH AUTHOR
555 Pierangelo Masarati; based on back-ldap rewrite/remap features
556 by Howard Chu, Pierangelo Masarati.