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