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