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