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