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