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