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