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