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