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