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