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