]> git.sur5r.net Git - openldap/blob - doc/man/man5/slapd-meta.5
548e9a2bbcd5ea384930c1bea781119df966b4fe
[openldap] / doc / man / man5 / slapd-meta.5
1 .TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2005 The OpenLDAP Foundation, All Rights Reserved.
3 .\" Copying restrictions apply.  See the COPYRIGHT file.
4 .\" Copyright 2001, 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 slapd-meta \- metadirectory backend
12 .SH SYNOPSIS
13 ETCDIR/slapd.conf
14 .SH DESCRIPTION
15 The
16 .B meta
17 backend to
18 .BR slapd (8)
19 performs basic LDAP proxying with respect to a set of remote LDAP
20 servers, called "targets".
21 The information contained in these servers can be presented as
22 belonging to a single Directory Information Tree (DIT).
23 .LP
24 A basic knowledge of the functionality of the
25 .BR slapd\-ldap (5)
26 backend is recommended.
27 This backend has been designed as an enhancement of the ldap backend.
28 The two backends share many features (actually they also share
29 portions of code).
30 While the
31 .B ldap
32 backend is intended to proxy operations directed to a single server, the
33 .B meta
34 backend is mainly intended for proxying of multiple servers and possibly
35 naming context masquerading.
36 These features, although useful in many scenarios, may result in
37 excessive overhead for some applications, so its use should be
38 carefully considered.
39 In the examples section, some typical scenarios will be discussed.
40 .SH EXAMPLES
41 There are examples in various places in this document, as well as in the
42 slapd/back-meta/data/ directory in the OpenLDAP source tree.
43 .SH CONFIGURATION
44 These
45 .B slapd.conf
46 options apply to the META backend database.
47 That is, they must follow a "database meta" line and come before any
48 subsequent "backend" or "database" lines.
49 Other database options are described in the
50 .BR slapd.conf (5)
51 manual page.
52 .LP
53 Note: In early versions of back-ldap and back-meta it was recommended to always set
54 .LP
55 .RS
56 .nf
57 lastmod  off
58 .fi
59 .RE
60 .LP
61 for every
62 .B ldap
63 and
64 .B meta
65 database.
66 This is because operational attributes related to entry creation and
67 modification should not be proxied, as they could be mistakenly written
68 to the target server(s), generating an error.
69 The current implementation automatically sets lastmod to off, so its use
70 is redundant and should be omitted, because the lastmod directive will
71 be deprecated in the future.
72
73 .SH SPECIAL CONFIGURATION DIRECTIVES
74 Target configuration starts with the "uri" directive.
75 All the configuration directives that are not specific to targets
76 should be defined first for clarity, including those that are common
77 to all backends.
78 They are:
79
80 .TP
81 .B default-target none
82 This directive forces the backend to reject all those operations
83 that must resolve to a single target in case none or multiple
84 targets are selected.
85 They include: add, delete, modify, modrdn; compare is not included, as
86 well as bind since, as they don't alter entries, in case of multiple
87 matches an attempt is made to perform the operation on any candidate
88 target, with the constraint that at most one must succeed.
89 This directive can also be used when processing targets to mark a
90 specific target as default.
91
92 .TP
93 .B dncache-ttl {forever|disabled|<ttl>}
94 This directive sets the time-to-live of the DN cache.
95 This caches the target that holds a given DN to speed up target
96 selection in case multiple targets would result from an uncached
97 search; forever means cache never expires; disabled means no DN
98 caching; otherwise a valid ( > 0 ) ttl in seconds is required.
99
100 .TP
101 .B nretries {forever|never|<nretries>}
102 This directive defines how many times a bind should be retried
103 in case of temporary failure in contacting a target.  If defined
104 before any target specification, it applies to all targets (by default,
105 .BR never );
106 the global value can be overridden by redefinitions inside each target
107 specification.
108
109 .TP
110 .B onerr {CONTINUE|stop}
111 This directive allows to select the behavior in case an error is returned
112 by one target during a search.
113 The default, \fBcontinue\fP, consists in continuing the operation, 
114 trying to return as much data as possible.
115 If this statement is set to \fBstop\fP, the search is terminated as soon 
116 as an error is returned by one target, and the error is immediately 
117 propagated to the client.
118
119 .TP
120 .B rebind-as-user {NO|yes}
121 If this option is given, the client's bind credentials are remembered
122 for rebinds when chasing referrals.
123
124 .SH TARGET SPECIFICATION
125 Target specification starts with a "uri" directive:
126
127 .TP
128 .B uri <protocol>://[<host>[:<port>]]/<naming context>
129 The "server" directive that was allowed in the LDAP backend (although
130 deprecated) has been completely discarded in the Meta backend.
131 The <protocol> part can be anything
132 .BR ldap_initialize (3)
133 accepts ({ldap|ldaps|ldapi} and variants); <host> and <port> may be
134 omitted, defaulting to whatever is set in
135 .BR ldap.conf (5).
136 The <naming context> part is mandatory.
137 It must end with one of the naming contexts defined for the backend,
138 e.g.:
139 .LP
140 .RS
141 .nf
142 suffix "\fBdc=foo,dc=com\fP"
143 uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
144 .fi
145
146 .RE
147 .RS
148 The <naming context> part doesn't need to be unique across the targets;
149 it may also match one of the values of the "suffix" directive.
150 Multiple URIs may be defined in a single argument.  The URIs must
151 be separated by TABs (e.g. '\\t'; commas or spaces, unlike back-ldap,
152 will not work,
153 because they are legal in the <naming context>, and we don't want to use
154 URL-encoded <naming context>s), and the additional URIs must have
155 no <naming context> part.  This causes the underlying library
156 to contact the first server of the list that responds.
157 .RE
158
159 .TP
160 .B default-target [<target>]
161 The "default-target" directive can also be used during target specification.
162 With no arguments it marks the current target as the default.
163 The optional number marks target <target> as the default one, starting
164 from 1.
165 Target <target> must be defined.
166
167 .TP
168 .B acl-authcDN "<administrative DN for access control purposes>"
169 DN which is used to query the target server for acl checking,
170 as in the LDAP backend; it is supposed to have read access 
171 on the target server to attributes used on the proxy for acl checking.
172 There is no risk of giving away such values; they are only used to
173 check permissions.
174 .B The acl-authcDN identity is by no means implicitly used by the proxy 
175 .B when the client connects anonymously.
176
177 .TP
178 .B acl-passwd <password>
179 Password used with the
180 .B 
181 acl-authcDN
182 above.
183
184 .TP
185 .B chase-referrals {YES|no}
186 enable/disable automatic referral chasing, which is delegated to the
187 underlying libldap, with rebinding eventually performed if the
188 \fBrebind-as-user\fP directive is used.  The default is to chase referrals.
189 If set before any target specification, it affects all targets, unless
190 overridden by any per-target directive.
191
192 .TP
193 .B tls {[try-]start|[try-]propagate}
194 execute the start TLS extended operation when the connection is initialized;
195 only works if the URI directive protocol scheme is not \fBldaps://\fP.
196 \fBpropagate\fP issues the Start TLS exop only if the original
197 connection did.
198 The \fBtry-\fP prefix instructs the proxy to continue operations
199 if start TLS failed; its use is highly deprecated.
200 If set before any target specification, it affects all targets, unless
201 overridden by any per-target directive.
202
203 .TP
204 .B t-f-support {NO|yes|discover}
205 enable if the remote server supports absolute filters
206 (see \fIdraft-zeilenga-ldap-t-f\fP for details).
207 If set to
208 .BR discover ,
209 support is detected by reading the remote server's root DSE.
210 If set before any target specification, it affects all targets, unless
211 overridden by any per-target directive.
212
213 .TP
214 .B timeout [{add|delete|modify|modrdn}=]<val> [...]
215 This directive allows to set per-database, per-target and per-operation
216 timeouts.
217 If no operation is specified, it affects all.
218 Currently, only write operations are addressed, because searches
219 can already be limited by means of the
220 .B limits
221 directive (see 
222 .BR slapd.conf (5)
223 for details), and other operations are not supposed to incur into the
224 need for timeouts.
225 Note: if the timelimit is exceeded, the operation is abandoned;
226 the protocol does not provide any means to rollback the operation,
227 so the client will not know if the operation eventually succeeded or not.
228 If set before any target specification, it affects all targets, unless
229 overridden by any per-target directive.
230
231 .TP
232 .B pseudorootdn "<substitute DN in case of rootdn bind>"
233 This directive, if present, sets the DN that will be substituted to
234 the bind DN if a bind with the backend's "rootdn" succeeds.
235 The true "rootdn" of the target server ought not be used; an arbitrary
236 administrative DN should used instead.
237
238 .TP
239 .B pseudorootpw "<substitute password in case of rootdn bind>"
240 This directive sets the credential that will be used in case a bind
241 with the backend's "rootdn" succeeds, and the bind is propagated to
242 the target using the "pseudorootdn" DN.
243
244 Note: cleartext credentials must be supplied here; as a consequence,
245 using the pseudorootdn/pseudorootpw directives is inherently unsafe.
246
247 .TP
248 .B pseudoroot-bind-defer {NO|yes}
249 This directive, when set to 
250 .BR yes ,
251 causes the authentication to the remote servers with the pseudo-root
252 identity to be deferred until actually needed by subsequent operations.
253
254 .TP
255 .B rewrite* ...
256 The rewrite options are described in the "REWRITING" section.
257
258 .TP
259 .B suffixmassage "<virtual naming context>" "<real naming context>"
260 All the directives starting with "rewrite" refer to the rewrite engine
261 that has been added to slapd.
262 The "suffixmassage" directive was introduced in the LDAP backend to
263 allow suffix massaging while proxying.
264 It has been obsoleted by the rewriting tools.
265 However, both for backward compatibility and for ease of configuration
266 when simple suffix massage is required, it has been preserved.
267 It wraps the basic rewriting instructions that perform suffix
268 massaging.  See the "REWRITING" section for a detailed list 
269 of the rewrite rules it implies.
270 .LP
271 Note: this also fixes a flaw in suffix massaging, which operated
272 on (case insensitive) DNs instead of normalized DNs,
273 so "dc=foo, dc=com" would not match "dc=foo,dc=com".
274 .LP
275 See the "REWRITING" section.
276
277 .TP
278 .B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
279 This maps object classes and attributes as in the LDAP backend.
280 See
281 .BR slapd-ldap (5).
282 .SH SCENARIOS
283 A powerful (and in some sense dangerous) rewrite engine has been added
284 to both the LDAP and Meta backends.
285 While the former can gain limited beneficial effects from rewriting
286 stuff, the latter can become an amazingly powerful tool.
287 .LP
288 Consider a couple of scenarios first.
289 .LP
290 1) Two directory servers share two levels of naming context;
291 say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
292 Then, an unambiguous Meta database can be configured as:
293 .LP
294 .RS
295 .nf
296 database meta
297 suffix   "\fBdc=foo,dc=com\fP"
298 uri      "ldap://a.foo.com/dc=a,\fBdc=foo,dc=com\fP"
299 uri      "ldap://b.foo.com/dc=b,\fBdc=foo,dc=com\fP"
300 .fi
301 .RE
302 .LP
303 Operations directed to a specific target can be easily resolved
304 because there are no ambiguities.
305 The only operation that may resolve to multiple targets is a search
306 with base "dc=foo,dc=com" and scope at least "one", which results in
307 spawning two searches to the targets.
308 .LP
309 2a) Two directory servers don't share any portion of naming context,
310 but they'd present as a single DIT
311 [Caveat: uniqueness of (massaged) entries among the two servers is
312 assumed; integrity checks risk to incur in excessive overhead and have
313 not been implemented].
314 Say we have "dc=bar,dc=org" and "o=Foo,c=US",
315 and we'd like them to appear as branches of "dc=foo,dc=com", say
316 "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
317 Then we need to configure our Meta backend as:
318 .LP
319 .RS
320 .nf
321 database      meta
322 suffix        "dc=foo,dc=com"
323
324 uri           "ldap://a.bar.com/\fBdc=a,dc=foo,dc=com\fP"
325 suffixmassage "\fBdc=a,dc=foo,dc=com\fP" "dc=bar,dc=org"
326
327 uri           "ldap://b.foo.com/\fBdc=b,dc=foo,dc=com\fP"
328 suffixmassage "\fBdc=b,dc=foo,dc=com\fP" "o=Foo,c=US"
329 .fi
330 .RE
331 .LP
332 Again, operations can be resolved without ambiguity, although
333 some rewriting is required.
334 Notice that the virtual naming context of each target is a branch of
335 the database's naming context; it is rewritten back and forth when
336 operations are performed towards the target servers.
337 What "back and forth" means will be clarified later.
338 .LP
339 When a search with base "dc=foo,dc=com" is attempted, if the 
340 scope is "base" it fails with "no such object"; in fact, the
341 common root of the two targets (prior to massaging) does not
342 exist.
343 If the scope is "one", both targets are contacted with the base
344 replaced by each target's base; the scope is derated to "base".
345 In general, a scope "one" search is honored, and the scope is derated,
346 only when the incoming base is at most one level lower of a target's
347 naming context (prior to massaging).
348 .LP
349 Finally, if the scope is "sub" the incoming base is replaced
350 by each target's unmassaged naming context, and the scope
351 is not altered.
352 .LP
353 2b) Consider the above reported scenario with the two servers
354 sharing the same naming context:
355 .LP
356 .RS
357 .nf
358 database      meta
359 suffix        "\fBdc=foo,dc=com\fP"
360
361 uri           "ldap://a.bar.com/\fBdc=foo,dc=com\fP"
362 suffixmassage "\fBdc=foo,dc=com\fP" "dc=bar,dc=org"
363
364 uri           "ldap://b.foo.com/\fBdc=foo,dc=com\fP"
365 suffixmassage "\fBdc=foo,dc=com\fP" "o=Foo,c=US"
366 .fi
367 .RE
368 .LP
369 All the previous considerations hold, except that now there is
370 no way to unambiguously resolve a DN.
371 In this case, all the operations that require an unambiguous target
372 selection will fail unless the DN is already cached or a default
373 target has been set.
374 Practical configurations may result as a combination of all the
375 above scenarios.
376 .SH ACLs
377 Note on ACLs: at present you may add whatever ACL rule you desire
378 to to the Meta (and LDAP) backends.
379 However, the meaning of an ACL on a proxy may require some
380 considerations.
381 Two philosophies may be considered:
382 .LP
383 a) the remote server dictates the permissions; the proxy simply passes
384 back what it gets from the remote server.
385 .LP
386 b) the remote server unveils "everything"; the proxy is responsible
387 for protecting data from unauthorized access.
388 .LP
389 Of course the latter sounds unreasonable, but it is not.
390 It is possible to imagine scenarios in which a remote host discloses
391 data that can be considered "public" inside an intranet, and a proxy
392 that connects it to the internet may impose additional constraints.
393 To this purpose, the proxy should be able to comply with all the ACL
394 matching criteria that the server supports.
395 This has been achieved with regard to all the criteria supported by
396 slapd except a special subtle case (please drop me a note if you can
397 find other exceptions: <ando@openldap.org>).
398 The rule
399 .LP
400 .RS
401 .nf
402 access to dn="<dn>" attr=<attr>
403        by dnattr=<dnattr> read
404        by * none
405 .fi
406 .RE
407 .LP
408 cannot be matched iff the attribute that is being requested, <attr>,
409 is NOT <dnattr>, and the attribute that determines membership,
410 <dnattr>, has not been requested (e.g. in a search)
411 .LP
412 In fact this ACL is resolved by slapd using the portion of entry it
413 retrieved from the remote server without requiring any further
414 intervention of the backend, so, if the <dnattr> attribute has not
415 been fetched, the match cannot be assessed because the attribute is
416 not present, not because no value matches the requirement!
417 .LP
418 Note on ACLs and attribute mapping: ACLs are applied to the mapped
419 attributes; for instance, if the attribute locally known as "foo" is
420 mapped to "bar" on a remote server, then local ACLs apply to attribute
421 "foo" and are totally unaware of its remote name.
422 The remote server will check permissions for "bar", and the local
423 server will possibly enforce additional restrictions to "foo".
424 .\"
425 .\" If this section is moved, also update the reference in
426 .\" libraries/librewrite/RATIONALE.
427 .\"
428 .SH REWRITING
429 A string is rewritten according to a set of rules, called a `rewrite
430 context'.
431 The rules are based on POSIX (''extended'') regular expressions (regex)
432 with substring matching; basic variable substitution and map resolution 
433 of substrings is allowed by specific mechanisms detailed in the following.
434 The behavior of pattern matching/substitution can be altered by a set
435 of flags.
436 .LP
437 The underlying concept is to build a lightweight rewrite module
438 for the slapd server (initially dedicated to the LDAP backend).
439 .SH Passes
440 An incoming string is matched against a set of rules.
441 Rules are made of a regex match pattern, a substitution pattern
442 and a set of actions, described by a set of flags.
443 In case of match a string rewriting is performed according to the
444 substitution pattern that allows to refer to substrings matched in the
445 incoming string.
446 The actions, if any, are finally performed.
447 The substitution pattern allows map resolution of substrings.
448 A map is a generic object that maps a substitution pattern to a value.
449 The flags are divided in "Pattern matching Flags" and "Action Flags";
450 the former alter the regex match pattern behavior while the latter
451 alter the action that is taken after substitution.
452 .SH "Pattern Matching Flags"
453 .TP
454 .B `C'
455 honors case in matching (default is case insensitive)
456 .TP
457 .B `R'
458 use POSIX ''basic'' regular expressions (default is ''extended'')
459 .TP
460 .B `M{n}'
461 allow no more than
462 .B n
463 recursive passes for a specific rule; does not alter the max total count
464 of passes, so it can only enforce a stricter limit for a specific rule.
465 .SH "Action Flags"
466 .TP
467 .B `:'
468 apply the rule once only (default is recursive)
469 .TP
470 .B `@'
471 stop applying rules in case of match; the current rule is still applied 
472 recursively; combine with `:' to apply the current rule only once 
473 and then stop.
474 .TP
475 .B `#'
476 stop current operation if the rule matches, and issue an `unwilling to
477 perform' error.
478 .TP
479 .B `G{n}'
480 jump
481 .B n
482 rules back and forth (watch for loops!).
483 Note that `G{1}' is implicit in every rule.
484 .TP
485 .B `I'
486 ignores errors in rule; this means, in case of error, e.g. issued by a
487 map, the error is treated as a missed match.
488 The `unwilling to perform' is not overridden.
489 .TP
490 .B `U{n}'
491 uses
492 .B
493 n
494 as return code if the rule matches; the flag does not alter the recursive
495 behavior of the rule, so, to have it performed only once, it must be used 
496 in combination with `:', e.g.
497 .B `:U{16}'
498 returns the value `16' after exactly one execution of the rule, if the
499 pattern matches.
500 As a consequence, its behavior is equivalent to `@', with the return
501 code set to
502 .BR n ;
503 or, in other words, `@' is equivalent to `U{0}'.
504 By convention, the freely available codes are above 16 included;
505 the others are reserved.
506 .LP
507 The ordering of the flags can be significant.
508 For instance: `IG{2}' means ignore errors and jump two lines ahead
509 both in case of match and in case of error, while `G{2}I' means ignore
510 errors, but jump two lines ahead only in case of match.
511 .LP
512 More flags (mainly Action Flags) will be added as needed.
513 .SH "Pattern matching:"
514 See
515 .BR regex (7)
516 and/or
517 .BR re_format (7).
518 .SH "Substitution Pattern Syntax:"
519 Everything starting with `%' requires substitution;
520 .LP
521 the only obvious exception is `%%', which is left as is;
522 .LP
523 the basic substitution is `%d', where `d' is a digit;
524 0 means the whole string, while 1-9 is a submatch;
525 .LP
526 a `%' followed by a `{' invokes an advanced substitution.
527 The pattern is:
528 .LP
529 .RS
530 `%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
531 .RE
532 .LP
533 where <name> must be a legal name for the map, i.e.
534 .LP
535 .RS
536 .nf
537 <name> ::= [a-z][a-z0-9]* (case insensitive)
538 <op> ::= `>' `|' `&' `&&' `*' `**' `$'
539 .fi
540 .RE
541 .LP
542 and <substitution> must be a legal substitution
543 pattern, with no limits on the nesting level.
544 .LP
545 The operators are:
546 .TP
547 .B >
548 sub context invocation; <name> must be a legal, already defined
549 rewrite context name
550 .TP
551 .B |
552 external command invocation; <name> must refer to a legal, already
553 defined command name (NOT IMPL.)
554 .TP
555 .B &
556 variable assignment; <name> defines a variable in the running
557 operation structure which can be dereferenced later; operator
558 .B &
559 assigns a variable in the rewrite context scope; operator
560 .B &&
561 assigns a variable that scopes the entire session, e.g. its value
562 can be dereferenced later by other rewrite contexts
563 .TP
564 .B *
565 variable dereferencing; <name> must refer to a variable that is
566 defined and assigned for the running operation; operator
567 .B *
568 dereferences a variable scoping the rewrite context; operator
569 .B **
570 dereferences a variable scoping the whole session, e.g. the value
571 is passed across rewrite contexts
572 .TP
573 .B $
574 parameter dereferencing; <name> must refer to an existing parameter;
575 the idea is to make some run-time parameters set by the system
576 available to the rewrite engine, as the client host name, the bind DN
577 if any, constant parameters initialized at config time, and so on;
578 no parameter is currently set by either 
579 .B back\-ldap
580 or
581 .BR back\-meta ,
582 but constant parameters can be defined in the configuration file
583 by using the
584 .B rewriteParam
585 directive.
586 .LP
587 Substitution escaping has been delegated to the `%' symbol, 
588 which is used instead of `\e' in string substitution patterns
589 because `\e' is already escaped by slapd's low level parsing routines;
590 as a consequence, regex escaping requires two `\e' symbols,
591 e.g. `\fB.*\e.foo\e.bar\fP' must be written as `\fB.*\e\e.foo\e\e.bar\fP'.
592 .\"
593 .\" The symbol can be altered at will by redefining the related macro in
594 .\" "rewrite-int.h".
595 .\"
596 .SH "Rewrite context:"
597 A rewrite context is a set of rules which are applied in sequence.
598 The basic idea is to have an application initialize a rewrite
599 engine (think of Apache's mod_rewrite ...) with a set of rewrite
600 contexts; when string rewriting is required, one invokes the
601 appropriate rewrite context with the input string and obtains the
602 newly rewritten one if no errors occur.
603 .LP
604 Each basic server operation is associated to a rewrite context;
605 they are divided in two main groups: client \-> server and
606 server \-> client rewriting.
607 .LP
608 client -> server:
609 .LP
610 .RS
611 .nf
612 (default)            if defined and no specific context 
613                      is available
614 bindDN               bind
615 searchBase           search
616 searchFilter         search
617 searchFilterAttrDN   search
618 compareDN            compare
619 compareAttrDN        compare AVA
620 addDN                add
621 addAttrDN            add AVA
622 modifyDN             modify
623 modifyAttrDN         modify AVA
624 modrDN               modrdn
625 newSuperiorDN        modrdn
626 deleteDN             delete
627 exopPasswdDN         passwd exop DN if proxy
628 .fi
629 .RE
630 .LP
631 server -> client:
632 .LP
633 .RS
634 .nf
635 searchResult         search (only if defined; no default;
636                      acts on DN and DN-syntax attributes 
637                      of search results)
638 searchAttrDN         search AVA
639 matchedDN            all ops (only if applicable)
640 .fi
641 .RE
642 .LP
643 .SH "Basic configuration syntax"
644 .TP
645 .B rewriteEngine { on | off }
646 If `on', the requested rewriting is performed; if `off', no
647 rewriting takes place (an easy way to stop rewriting without
648 altering too much the configuration file).
649 .TP
650 .B rewriteContext <context name> "[ alias <aliased context name> ]"
651 <Context name> is the name that identifies the context, i.e. the name
652 used by the application to refer to the set of rules it contains.
653 It is used also to reference sub contexts in string rewriting.
654 A context may alias another one.
655 In this case the alias context contains no rule, and any reference to
656 it will result in accessing the aliased one.
657 .TP
658 .B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
659 Determines how a string can be rewritten if a pattern is matched.
660 Examples are reported below.
661 .SH "Additional configuration syntax:"
662 .TP
663 .B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
664 Allows to define a map that transforms substring rewriting into
665 something else.
666 The map is referenced inside the substitution pattern of a rule.
667 .TP
668 .B rewriteParam <param name> <param value>
669 Sets a value with global scope, that can be dereferenced by the
670 command `%{$paramName}'.
671 .TP
672 .B rewriteMaxPasses <number of passes> [<number of passes per rule>]
673 Sets the maximum number of total rewriting passes that can be
674 performed in a single rewrite operation (to avoid loops).
675 A safe default is set to 100; note that reaching this limit is still
676 treated as a success; recursive invocation of rules is simply 
677 interrupted.
678 The count applies to the rewriting operation as a whole, not 
679 to any single rule; an optional per-rule limit can be set.
680 This limit is overridden by setting specific per-rule limits
681 with the `M{n}' flag.
682 .SH "Configuration examples:"
683 .nf
684 # set to `off' to disable rewriting
685 rewriteEngine on
686
687 # the rules the "suffixmassage" directive implies
688 rewriteEngine on
689 # all dataflow from client to server referring to DNs
690 rewriteContext default
691 rewriteRule "(.*)<virtualnamingcontext>$" "%1<realnamingcontext>" ":"
692 # empty filter rule
693 rewriteContext searchFilter
694 # all dataflow from server to client
695 rewriteContext searchResult
696 rewriteRule "(.*)<realnamingcontext>$" "%1<virtualnamingcontext>" ":"
697 rewriteContext searchAttrDN alias searchResult
698 rewriteContext matchedDN alias searchResult
699
700 # Everything defined here goes into the `default' context.
701 # This rule changes the naming context of anything sent
702 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
703
704 rewriteRule "(.*)dc=home,[ ]?dc=net"
705             "%1dc=OpenLDAP, dc=org"  ":"
706
707 # since a pretty/normalized DN does not include spaces
708 # after rdn separators, e.g. `,', this rule suffices:
709
710 rewriteRule "(.*)dc=home,dc=net"
711             "%1dc=OpenLDAP,dc=org"  ":"
712
713 # Start a new context (ends input of the previous one).
714 # This rule adds blanks between DN parts if not present.
715 rewriteContext  addBlanks
716 rewriteRule     "(.*),([^ ].*)" "%1, %2"
717
718 # This one eats blanks
719 rewriteContext  eatBlanks
720 rewriteRule     "(.*),[ ](.*)" "%1,%2"
721
722 # Here control goes back to the default rewrite
723 # context; rules are appended to the existing ones.
724 # anything that gets here is piped into rule `addBlanks'
725 rewriteContext  default
726 rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
727
728 .\" # Anything with `uid=username' is looked up in
729 .\" # /etc/passwd for gecos (I know it's nearly useless,
730 .\" # but it is there just as a guideline to implementing
731 .\" # custom maps).
732 .\" # Note the `I' flag that leaves `uid=username' in place 
733 .\" # if `username' does not have a valid account, and the
734 .\" # `:' that forces the rule to be processed exactly once.
735 .\" rewriteContext  uid2Gecos
736 .\" rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
737 .\"                 "%1cn=%2{xpasswd},%3"      "I:"
738 .\" 
739 .\" # Finally, in a bind, if one uses a `uid=username' DN,
740 .\" # it is rewritten in `cn=name surname' if possible.
741 .\" rewriteContext  bindDN
742 .\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
743 .\" 
744 # Rewrite the search base according to `default' rules.
745 rewriteContext  searchBase alias default
746
747 # Search results with OpenLDAP DN are rewritten back with
748 # `dc=home,dc=net' naming context, with spaces eaten.
749 rewriteContext  searchResult
750 rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
751                 "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
752
753 # Bind with email instead of full DN: we first need
754 # an ldap map that turns attributes into a DN (the
755 # argument used when invoking the map is appended to 
756 # the URI and acts as the filter portion)
757 rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
758
759 # Then we need to detect DN made up of a single email,
760 # e.g. `mail=someone@example.com'; note that the rule
761 # in case of match stops rewriting; in case of error,
762 # it is ignored.  In case we are mapping virtual
763 # to real naming contexts, we also need to rewrite
764 # regular DNs, because the definition of a bindDn
765 # rewrite context overrides the default definition.
766 rewriteContext bindDN
767 rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
768
769 # This is a rather sophisticated example. It massages a
770 # search filter in case who performs the search has
771 # administrative privileges.  First we need to keep
772 # track of the bind DN of the incoming request, which is
773 # stored in a variable called `binddn' with session scope,
774 # and left in place to allow regular binding:
775 rewriteContext  bindDN
776 rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
777
778 # A search filter containing `uid=' is rewritten only
779 # if an appropriate DN is bound.
780 # To do this, in the first rule the bound DN is
781 # dereferenced, while the filter is decomposed in a
782 # prefix, in the value of the `uid=<arg>' AVA, and 
783 # in a suffix. A tag `<>' is appended to the DN. 
784 # If the DN refers to an entry in the `ou=admin' subtree, 
785 # the filter is rewritten OR-ing the `uid=<arg>' with
786 # `cn=<arg>'; otherwise it is left as is. This could be
787 # useful, for instance, to allow apache's auth_ldap-1.4
788 # module to authenticate users with both `uid' and
789 # `cn', but only if the request comes from a possible
790 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
791 rewriteContext searchFilter
792 rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
793   "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
794   ":I"
795 rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
796   "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
797 rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
798
799 # This example shows how to strip unwanted DN-valued
800 # attribute values from a search result; the first rule
801 # matches DN values below "ou=People,dc=example,dc=com";
802 # in case of match the rewriting exits successfully.
803 # The second rule matches everything else and causes
804 # the value to be rejected.
805 rewriteContext searchResult
806 rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
807 rewriteRule ".*" "" "#"
808 .fi
809 .SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
810 In case the rewritten DN is an LDAP URI, the operation is initiated
811 towards the host[:port] indicated in the uri, if it does not refer
812 to the local server.
813 E.g.:
814 .LP
815 .nf
816   rewriteRule '^cn=root,.*' '%0'                     'G{3}'
817   rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
818   rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
819   rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
820 .fi
821 .LP
822 (Rule 1 is simply there to illustrate the `G{n}' action; it could have
823 been written:
824 .LP
825 .nf
826   rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
827 .fi
828 .LP
829 with the advantage of saving one rewrite pass ...)
830
831 .SH ACCESS CONTROL
832 The
833 .B meta
834 backend does not honor all ACL semantics as described in
835 .BR slapd.access (5).
836 In general, access checking is delegated to the remote server(s).
837 Only
838 .B read (=r)
839 access to the
840 .B entry
841 pseudo-attribute and to the other attribute values of the entries
842 returned by the
843 .B search
844 operation is honored, which is performed by the frontend.
845
846 .SH PROXY CACHE OVERLAY
847 The proxy cache overlay 
848 allows caching of LDAP search requests (queries) in a local database.
849 See 
850 .BR slapo-pcache (5)
851 for details.
852 .SH FILES
853 .TP
854 ETCDIR/slapd.conf
855 default slapd configuration file
856 .SH SEE ALSO
857 .BR slapd.conf (5),
858 .BR slapd\-ldap (5),
859 .BR slapo\-pcache (5),
860 .BR slapd (8),
861 .BR regex (7),
862 .BR re_format (7).
863 .SH AUTHOR
864 Pierangelo Masarati, based on back-ldap by Howard Chu