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