]> git.sur5r.net Git - openldap/blob - doc/man/man5/slapd-meta.5
92a694ea72c059fb6b658545bd90d4487354afbf
[openldap] / doc / man / man5 / slapd-meta.5
1 .TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2010 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 to slapd
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 The proxy instance of
42 .BR slapd (8)
43 must contain schema information for the attributes and objectClasses
44 used in filters, request DN and request-related data in general.
45 It should also contain schema information for the data returned
46 by the proxied server.
47 It is the responsibility of the proxy administrator to keep the schema
48 of the proxy lined up with that of the proxied server.
49
50 .LP
51 Note: When looping back to the same instance of \fBslapd\fP(8), 
52 each connection requires a new thread; as a consequence, \fBslapd\fP(8)
53 must be compiled with thread support, and the \fBthreads\fP parameter 
54 may need some tuning; in those cases, unless the multiple target feature
55 is required, one may consider using \fBslapd\-relay\fP(5) instead, 
56 which performs the relayed operation internally and thus reuses 
57 the same connection.
58
59 .SH EXAMPLES
60 There are examples in various places in this document, as well as in the
61 slapd/back\-meta/data/ directory in the OpenLDAP source tree.
62 .SH CONFIGURATION
63 These
64 .B slapd.conf
65 options apply to the META backend database.
66 That is, they must follow a "database meta" line and come before any
67 subsequent "backend" or "database" lines.
68 Other database options are described in the
69 .BR slapd.conf (5)
70 manual page.
71 .LP
72 Note: In early versions of back-ldap and back-meta it was recommended to always set
73 .LP
74 .RS
75 .nf
76 lastmod  off
77 .fi
78 .RE
79 .LP
80 for 
81 .B ldap
82 and
83 .B meta
84 databases.
85 This was required because operational attributes related to entry creation 
86 and modification should not be proxied, as they could be mistakenly written
87 to the target server(s), generating an error.
88 The current implementation automatically sets lastmod to \fBoff\fP, 
89 so its use is redundant and should be omitted.
90
91 .SH SPECIAL CONFIGURATION DIRECTIVES
92 Target configuration starts with the "uri" directive.
93 All the configuration directives that are not specific to targets
94 should be defined first for clarity, including those that are common
95 to all backends.
96 They are:
97
98 .TP
99 .B conn\-ttl <time>
100 This directive causes a cached connection to be dropped an recreated
101 after a given ttl, regardless of being idle or not.
102
103 .TP
104 .B default\-target none
105 This directive forces the backend to reject all those operations
106 that must resolve to a single target in case none or multiple
107 targets are selected.
108 They include: add, delete, modify, modrdn; compare is not included, as
109 well as bind since, as they don't alter entries, in case of multiple
110 matches an attempt is made to perform the operation on any candidate
111 target, with the constraint that at most one must succeed.
112 This directive can also be used when processing targets to mark a
113 specific target as default.
114
115 .TP
116 .B dncache\-ttl {DISABLED|forever|<ttl>}
117 This directive sets the time-to-live of the DN cache.
118 This caches the target that holds a given DN to speed up target
119 selection in case multiple targets would result from an uncached
120 search; forever means cache never expires; disabled means no DN
121 caching; otherwise a valid ( > 0 ) ttl is required, in the format
122 illustrated for the 
123 .B idle\-timeout
124 directive.
125
126 .TP
127 .B onerr {CONTINUE|report|stop}
128 This directive allows to select the behavior in case an error is returned
129 by one target during a search.
130 The default, \fBcontinue\fP, consists in continuing the operation, 
131 trying to return as much data as possible.
132 If the value is set to \fBstop\fP, the search is terminated as soon 
133 as an error is returned by one target, and the error is immediately 
134 propagated to the client.
135 If the value is set to \fBreport\fP, the search is continuated to the end
136 but, in case at least one target returned an error code, the first
137 non-success error code is returned.
138
139 .TP
140 .B norefs <NO|yes>
141 If
142 .BR yes ,
143 do not return search reference responses.
144 By default, they are returned unless request is LDAPv2.
145 If set before any target specification, it affects all targets, unless
146 overridden by any per-target directive.
147
148 .TP
149 .B noundeffilter <NO|yes>
150 If
151 .BR yes ,
152 return success instead of searching if a filter is undefined or contains
153 undefined portions.
154 By default, the search is propagated after replacing undefined portions
155 with
156 .BR (!(objectClass=*)) ,
157 which corresponds to the empty result set.
158 If set before any target specification, it affects all targets, unless
159 overridden by any per-target directive.
160
161 .TP
162 .B protocol\-version {0,2,3}
163 This directive indicates what protocol version must be used to contact
164 the remote server.
165 If set to 0 (the default), the proxy uses the same protocol version 
166 used by the client, otherwise the requested protocol is used.
167 The proxy returns \fIunwillingToPerform\fP if an operation that is 
168 incompatible with the requested protocol is attempted.
169 If set before any target specification, it affects all targets, unless
170 overridden by any per-target directive.
171
172 .TP
173 .B pseudoroot\-bind\-defer {YES|no}
174 This directive, when set to 
175 .BR yes ,
176 causes the authentication to the remote servers with the pseudo-root
177 identity (the identity defined in each
178 .B idassert-bind
179 directive) to be deferred until actually needed by subsequent operations.
180 Otherwise, all binds as the rootdn are propagated to the targets.
181
182 .TP
183 .B quarantine <interval>,<num>[;<interval>,<num>[...]]
184 Turns on quarantine of URIs that returned
185 .IR LDAP_UNAVAILABLE ,
186 so that an attempt to reconnect only occurs at given intervals instead
187 of any time a client requests an operation.
188 The pattern is: retry only after at least
189 .I interval
190 seconds elapsed since last attempt, for exactly
191 .I num
192 times; then use the next pattern.
193 If
194 .I num
195 for the last pattern is "\fB+\fP", it retries forever; otherwise, 
196 no more retries occur.
197 This directive must appear before any target specification;
198 it affects all targets with the same pattern.
199
200 .TP
201 .B rebind\-as\-user {NO|yes}
202 If this option is given, the client's bind credentials are remembered
203 for rebinds, when trying to re-establish a broken connection,
204 or when chasing a referral, if 
205 .B chase\-referrals
206 is set to
207 .IR yes .
208
209 .TP
210 .B session\-tracking\-request {NO|yes}
211 Adds session tracking control for all requests.
212 The client's IP and hostname, and the identity associated to each request,
213 if known, are sent to the remote server for informational purposes.
214 This directive is incompatible with setting \fIprotocol\-version\fP to 2.
215 If set before any target specification, it affects all targets, unless
216 overridden by any per-target directive.
217
218 .TP
219 .B single\-conn {NO|yes}
220 Discards current cached connection when the client rebinds.
221
222 .TP
223 .B use\-temporary\-conn {NO|yes}
224 when set to 
225 .BR yes ,
226 create a temporary connection whenever competing with other threads
227 for a shared one; otherwise, wait until the shared connection is available.
228
229 .SH TARGET SPECIFICATION
230 Target specification starts with a "uri" directive:
231
232 .TP
233 .B uri <protocol>://[<host>]/<naming context> [...]
234 The <protocol> part can be anything
235 .BR ldap_initialize (3)
236 accepts ({ldap|ldaps|ldapi} and variants); the <host> may be
237 omitted, defaulting to whatever is set in
238 .BR ldap.conf (5).
239 The <naming context> part is \fImandatory\fP for the first URI,
240 but it \fImust be omitted\fP for subsequent ones, if any.
241 The naming context part must be within the naming context defined for the backend,
242 e.g.:
243 .LP
244 .RS
245 .nf
246 suffix "\fBdc=foo,dc=com\fP"
247 uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
248 .fi
249
250 .RE
251 .RS
252 The <naming context> part doesn't need to be unique across the targets;
253 it may also match one of the values of the "suffix" directive.
254 Multiple URIs may be defined in a single URI statement.
255 The additional URIs must be separate arguments and must not have any
256 <naming context> part.  This causes the underlying library
257 to contact the first server of the list that responds.
258 For example, if \fIl1.foo.com\fP and \fIl2.foo.com\fP are shadows
259 of the same server, the directive
260 .LP
261 .nf
262 suffix "\fBdc=foo,dc=com\fP"
263 uri    "ldap://l1.foo.com/\fBdc=foo,dc=com\fP" "ldap://l2.foo.com/"
264 .fi
265
266 .RE
267 .RS
268 causes \fIl2.foo.com\fP to be contacted whenever \fIl1.foo.com\fP
269 does not respond.
270 In that case, the URI list is internally rearranged, by moving unavailable
271 URIs to the end, so that further connection attempts occur with respect to
272 the last URI that succeeded.
273 .RE
274
275 .TP
276 .B acl\-authcDN "<administrative DN for access control purposes>"
277 DN which is used to query the target server for acl checking,
278 as in the LDAP backend; it is supposed to have read access 
279 on the target server to attributes used on the proxy for acl checking.
280 There is no risk of giving away such values; they are only used to
281 check permissions.
282 .B The acl\-authcDN identity is by no means implicitly used by the proxy 
283 .B when the client connects anonymously.
284
285 .TP
286 .B acl\-passwd <password>
287 Password used with the
288 .B 
289 acl\-authcDN
290 above.
291
292 .TP
293 .B bind\-timeout <microseconds>
294 This directive defines the timeout, in microseconds, used when polling
295 for response after an asynchronous bind connection.  The initial call
296 to ldap_result(3) is performed with a trade-off timeout of 100000 us;
297 if that results in a timeout exceeded, subsequent calls use the value
298 provided with
299 .BR bind\-timeout .
300 The default value is used also for subsequent calls if
301 .B bind\-timeout
302 is not specified.
303 If set before any target specification, it affects all targets, unless
304 overridden by any per-target directive.
305
306 .TP
307 .B chase\-referrals {YES|no}
308 enable/disable automatic referral chasing, which is delegated to the
309 underlying libldap, with rebinding eventually performed if the
310 \fBrebind\-as\-user\fP directive is used.  The default is to chase referrals.
311 If set before any target specification, it affects all targets, unless
312 overridden by any per-target directive.
313
314 .TP
315 .B default\-target [<target>]
316 The "default\-target" directive can also be used during target specification.
317 With no arguments it marks the current target as the default.
318 The optional number marks target <target> as the default one, starting
319 from 1.
320 Target <target> must be defined.
321
322 .TP
323 .B idassert\-authzFrom <authz-regexp>
324 if defined, selects what
325 .I local
326 identities are authorized to exploit the identity assertion feature.
327 The string
328 .B <authz-regexp>
329 follows the rules defined for the
330 .I authzFrom
331 attribute.
332 See 
333 .BR slapd.conf (5),
334 section related to
335 .BR authz\-policy ,
336 for details on the syntax of this field.
337
338 .HP
339 .hy 0
340 .B idassert\-bind
341 .B bindmethod=none|simple|sasl [binddn=<simple DN>] [credentials=<simple password>]
342 .B [saslmech=<SASL mech>] [secprops=<properties>] [realm=<realm>]
343 .B [authcId=<authentication ID>] [authzId=<authorization ID>]
344 .B [authz={native|proxyauthz}] [mode=<mode>] [flags=<flags>]
345 .B [starttls=no|yes|critical]
346 .B [tls_cert=<file>]
347 .B [tls_key=<file>]
348 .B [tls_cacert=<file>]
349 .B [tls_cacertdir=<path>]
350 .B [tls_reqcert=never|allow|try|demand]
351 .B [tls_ciphersuite=<ciphers>]
352 .B [tls_protocol_min=<version>]
353 .B [tls_crlcheck=none|peer|all]
354 .RS
355 Allows to define the parameters of the authentication method that is 
356 internally used by the proxy to authorize connections that are 
357 authenticated by other databases.
358 The identity defined by this directive, according to the properties
359 associated to the authentication method, is supposed to have auth access 
360 on the target server to attributes used on the proxy for authentication
361 and authorization, and to be allowed to authorize the users.
362 This requires to have
363 .B proxyAuthz
364 privileges on a wide set of DNs, e.g.
365 .BR authzTo=dn.subtree:"" ,
366 and the remote server to have
367 .B authz\-policy
368 set to
369 .B to
370 or
371 .BR both .
372 See
373 .BR slapd.conf (5)
374 for details on these statements and for remarks and drawbacks about
375 their usage.
376 The supported bindmethods are
377
378 \fBnone|simple|sasl\fP
379
380 where
381 .B none
382 is the default, i.e. no \fIidentity assertion\fP is performed.
383
384 The authz parameter is used to instruct the SASL bind to exploit 
385 .B native 
386 SASL authorization, if available; since connections are cached,
387 this should only be used when authorizing with a fixed identity
388 (e.g. by means of the 
389 .B authzDN
390 or
391 .B authzID
392 parameters).
393 Otherwise, the default
394 .B proxyauthz
395 is used, i.e. the proxyAuthz control (Proxied Authorization, RFC 4370)
396 is added to all operations.
397
398 The supported modes are:
399
400 \fB<mode> := {legacy|anonymous|none|self}\fP
401
402 If 
403 .B <mode>
404 is not present, and 
405 .B authzId
406 is given, the proxy always authorizes that identity.
407 .B <authorization ID>
408 can be 
409
410 \fBu:<user>\fP
411
412 \fB[dn:]<DN>\fP
413
414 The former is supposed to be expanded by the remote server according 
415 to the authz rules; see
416 .BR slapd.conf (5)
417 for details.
418 In the latter case, whether or not the 
419 .B dn:
420 prefix is present, the string must pass DN validation and normalization.
421
422 The default mode is 
423 .BR legacy ,
424 which implies that the proxy will either perform a simple bind as the
425 .I authcDN
426 or a SASL bind as the
427 .I authcID
428 and assert the client's identity when it is not anonymous.
429 Direct binds are always proxied.
430 The other modes imply that the proxy will always either perform a simple bind 
431 as the
432 .IR authcDN
433 or a SASL bind as the
434 .IR authcID ,
435 unless restricted by
436 .BR idassert\-authzFrom
437 rules (see below), in which case the operation will fail;
438 eventually, it will assert some other identity according to
439 .BR <mode> .
440 Other identity assertion modes are
441 .BR anonymous
442 and
443 .BR self ,
444 which respectively mean that the 
445 .I empty 
446 or the 
447 .IR client 's 
448 identity
449 will be asserted;
450 .BR none ,
451 which means that no proxyAuthz control will be used, so the
452 .I authcDN
453 or the
454 .I authcID
455 identity will be asserted.
456 For all modes that require the use of the
457 .I proxyAuthz 
458 control, on the remote server the proxy identity must have appropriate 
459 .I authzTo
460 permissions, or the asserted identities must have appropriate
461 .I authzFrom 
462 permissions.  Note, however, that the ID assertion feature is mostly 
463 useful when the asserted identities do not exist on the remote server.
464
465 Flags can be
466
467 \fBoverride,[non\-]prescriptive,proxy\-authz\-[non\-]critical\fP
468
469 When the 
470 .B override
471 flag is used, identity assertion takes place even when the database
472 is authorizing for the identity of the client, i.e. after binding
473 with the provided identity, and thus authenticating it, the proxy
474 performs the identity assertion using the configured identity and
475 authentication method.
476
477 When the
478 .B prescriptive
479 flag is used (the default), operations fail with
480 \fIinappropriateAuthentication\fP
481 for those identities whose assertion is not allowed by the
482 .B idassert\-authzFrom
483 patterns.
484 If the 
485 .B non\-prescriptive
486 flag is used, operations are performed anonymously for those identities 
487 whose assertion is not allowed by the
488 .B idassert\-authzFrom
489 patterns.
490
491 When the
492 .B proxy\-authz\-non\-critical
493 flag is used (the default), the proxyAuthz control is not marked as critical,
494 in violation of RFC 4370.  Use of
495 .B proxy\-authz\-critical
496 is recommended.
497
498 The TLS settings default to the same as the main slapd TLS settings,
499 except for
500 .B tls_reqcert
501 which defaults to "demand".
502
503 The identity associated to this directive is also used for privileged
504 operations whenever \fBidassert\-bind\fP is defined and \fBacl\-bind\fP
505 is not.  See \fBacl\-bind\fP for details.
506 .RE
507
508 .TP
509 .B idle\-timeout <time>
510 This directive causes a cached connection to be dropped an recreated
511 after it has been idle for the specified time.
512 The value can be specified as
513
514 [<d>d][<h>h][<m>m][<s>[s]]
515
516 where <d>, <h>, <m> and <s> are respectively treated as days, hours, 
517 minutes and seconds.
518 If set before any target specification, it affects all targets, unless
519 overridden by any per-target directive.
520
521 .TP
522 .B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
523 This maps object classes and attributes as in the LDAP backend.
524 See
525 .BR slapd\-ldap (5).
526
527 .TP
528 .B network\-timeout <time>
529 Sets the network timeout value after which
530 .BR poll (2)/ select (2) 
531 following a 
532 .BR connect (2) 
533 returns in case of no activity.
534 The value is in seconds, and it can be specified as for
535 .BR idle\-timeout .
536 If set before any target specification, it affects all targets, unless
537 overridden by any per-target directive.
538
539 .TP
540 .B nretries {forever|never|<nretries>}
541 This directive defines how many times a bind should be retried
542 in case of temporary failure in contacting a target.  If defined
543 before any target specification, it applies to all targets (by default,
544 .BR 3
545 times);
546 the global value can be overridden by redefinitions inside each target
547 specification.
548
549 .TP
550 .B pseudorootdn "<substitute DN in case of rootdn bind>"
551 Deprecated; use
552 .B idassert\-bind
553 instead.
554
555 .TP
556 .B pseudorootpw "<substitute password in case of rootdn bind>"
557 Deprecated; use
558 .B idassert\-bind
559 instead.
560
561 .TP
562 .B rewrite* ...
563 The rewrite options are described in the "REWRITING" section.
564
565 .TP
566 .B subtree\-exclude "<DN>"
567 This directive instructs back-meta to ignore the current target
568 for operations whose requestDN is subordinate to
569 .BR DN .
570 There may be multiple occurrences of the
571 .B subtree\-exclude
572 directive for each of the targets.
573
574 .TP
575 .B suffixmassage "<virtual naming context>" "<real naming context>"
576 All the directives starting with "rewrite" refer to the rewrite engine
577 that has been added to slapd.
578 The "suffixmassage" directive was introduced in the LDAP backend to
579 allow suffix massaging while proxying.
580 It has been obsoleted by the rewriting tools.
581 However, both for backward compatibility and for ease of configuration
582 when simple suffix massage is required, it has been preserved.
583 It wraps the basic rewriting instructions that perform suffix
584 massaging.  See the "REWRITING" section for a detailed list 
585 of the rewrite rules it implies.
586
587 .TP
588 .B t\-f\-support {NO|yes|discover}
589 enable if the remote server supports absolute filters
590 (see \fIdraft-zeilenga-ldap-t-f\fP for details).
591 If set to
592 .BR discover ,
593 support is detected by reading the remote server's root DSE.
594 If set before any target specification, it affects all targets, unless
595 overridden by any per-target directive.
596
597 .TP
598 .B timeout [<op>=]<val> [...]
599 This directive allows to set per-operation timeouts.
600 Operations can be
601
602 \fB<op> ::= bind, add, delete, modrdn, modify, compare, search\fP
603
604 The overall duration of the \fBsearch\fP operation is controlled either
605 by the \fBtimelimit\fP parameter or by server-side enforced
606 time limits (see \fBtimelimit\fP and \fBlimits\fP in
607 .BR slapd.conf (5)
608 for details).
609 This \fBtimeout\fP parameter controls how long the target can be 
610 irresponsive before the operation is aborted.
611 Timeout is meaningless for the remaining operations,
612 \fBunbind\fP and \fBabandon\fP, which do not imply any response,
613 while it is not yet implemented in currently supported \fBextended\fP 
614 operations.
615 If no operation is specified, the timeout \fBval\fP affects all
616 supported operations.
617 If specified before any target definition, it affects all targets
618 unless overridden by per-target directives.
619
620 Note: if the timeout is exceeded, the operation is cancelled
621 (according to the \fBcancel\fP directive);
622 the protocol does not provide any means to rollback operations,
623 so the client will not be notified about the result of the operation,
624 which may eventually succeeded or not.
625 In case the timeout is exceeded during a bind operation, the connection
626 is destroyed, according to RFC4511.
627
628 .TP
629 .B tls {[try\-]start|[try\-]propagate}
630 execute the StartTLS extended operation when the connection is initialized;
631 only works if the URI directive protocol scheme is not \fBldaps://\fP.
632 \fBpropagate\fP issues the StartTLS operation only if the original
633 connection did.
634 The \fBtry\-\fP prefix instructs the proxy to continue operations
635 if the StartTLS operation failed; its use is highly deprecated.
636 If set before any target specification, it affects all targets, unless
637 overridden by any per-target directive.
638
639 .SH SCENARIOS
640 A powerful (and in some sense dangerous) rewrite engine has been added
641 to both the LDAP and Meta backends.
642 While the former can gain limited beneficial effects from rewriting
643 stuff, the latter can become an amazingly powerful tool.
644 .LP
645 Consider a couple of scenarios first.
646 .LP
647 1) Two directory servers share two levels of naming context;
648 say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
649 Then, an unambiguous Meta database can be configured as:
650 .LP
651 .RS
652 .nf
653 database meta
654 suffix   "\fBdc=foo,dc=com\fP"
655 uri      "ldap://a.foo.com/dc=a,\fBdc=foo,dc=com\fP"
656 uri      "ldap://b.foo.com/dc=b,\fBdc=foo,dc=com\fP"
657 .fi
658 .RE
659 .LP
660 Operations directed to a specific target can be easily resolved
661 because there are no ambiguities.
662 The only operation that may resolve to multiple targets is a search
663 with base "dc=foo,dc=com" and scope at least "one", which results in
664 spawning two searches to the targets.
665 .LP
666 2a) Two directory servers don't share any portion of naming context,
667 but they'd present as a single DIT
668 [Caveat: uniqueness of (massaged) entries among the two servers is
669 assumed; integrity checks risk to incur in excessive overhead and have
670 not been implemented].
671 Say we have "dc=bar,dc=org" and "o=Foo,c=US",
672 and we'd like them to appear as branches of "dc=foo,dc=com", say
673 "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
674 Then we need to configure our Meta backend as:
675 .LP
676 .RS
677 .nf
678 database      meta
679 suffix        "dc=foo,dc=com"
680
681 uri           "ldap://a.bar.com/\fBdc=a,dc=foo,dc=com\fP"
682 suffixmassage "\fBdc=a,dc=foo,dc=com\fP" "dc=bar,dc=org"
683
684 uri           "ldap://b.foo.com/\fBdc=b,dc=foo,dc=com\fP"
685 suffixmassage "\fBdc=b,dc=foo,dc=com\fP" "o=Foo,c=US"
686 .fi
687 .RE
688 .LP
689 Again, operations can be resolved without ambiguity, although
690 some rewriting is required.
691 Notice that the virtual naming context of each target is a branch of
692 the database's naming context; it is rewritten back and forth when
693 operations are performed towards the target servers.
694 What "back and forth" means will be clarified later.
695 .LP
696 When a search with base "dc=foo,dc=com" is attempted, if the 
697 scope is "base" it fails with "no such object"; in fact, the
698 common root of the two targets (prior to massaging) does not
699 exist.
700 If the scope is "one", both targets are contacted with the base
701 replaced by each target's base; the scope is derated to "base".
702 In general, a scope "one" search is honored, and the scope is derated,
703 only when the incoming base is at most one level lower of a target's
704 naming context (prior to massaging).
705 .LP
706 Finally, if the scope is "sub" the incoming base is replaced
707 by each target's unmassaged naming context, and the scope
708 is not altered.
709 .LP
710 2b) Consider the above reported scenario with the two servers
711 sharing the same naming context:
712 .LP
713 .RS
714 .nf
715 database      meta
716 suffix        "\fBdc=foo,dc=com\fP"
717
718 uri           "ldap://a.bar.com/\fBdc=foo,dc=com\fP"
719 suffixmassage "\fBdc=foo,dc=com\fP" "dc=bar,dc=org"
720
721 uri           "ldap://b.foo.com/\fBdc=foo,dc=com\fP"
722 suffixmassage "\fBdc=foo,dc=com\fP" "o=Foo,c=US"
723 .fi
724 .RE
725 .LP
726 All the previous considerations hold, except that now there is
727 no way to unambiguously resolve a DN.
728 In this case, all the operations that require an unambiguous target
729 selection will fail unless the DN is already cached or a default
730 target has been set.
731 Practical configurations may result as a combination of all the
732 above scenarios.
733 .SH ACLs
734 Note on ACLs: at present you may add whatever ACL rule you desire
735 to to the Meta (and LDAP) backends.
736 However, the meaning of an ACL on a proxy may require some
737 considerations.
738 Two philosophies may be considered:
739 .LP
740 a) the remote server dictates the permissions; the proxy simply passes
741 back what it gets from the remote server.
742 .LP
743 b) the remote server unveils "everything"; the proxy is responsible
744 for protecting data from unauthorized access.
745 .LP
746 Of course the latter sounds unreasonable, but it is not.
747 It is possible to imagine scenarios in which a remote host discloses
748 data that can be considered "public" inside an intranet, and a proxy
749 that connects it to the internet may impose additional constraints.
750 To this purpose, the proxy should be able to comply with all the ACL
751 matching criteria that the server supports.
752 This has been achieved with regard to all the criteria supported by
753 slapd except a special subtle case (please drop me a note if you can
754 find other exceptions: <ando@openldap.org>).
755 The rule
756 .LP
757 .RS
758 .nf
759 access to dn="<dn>" attrs=<attr>
760        by dnattr=<dnattr> read
761        by * none
762 .fi
763 .RE
764 .LP
765 cannot be matched iff the attribute that is being requested, <attr>,
766 is NOT <dnattr>, and the attribute that determines membership,
767 <dnattr>, has not been requested (e.g. in a search)
768 .LP
769 In fact this ACL is resolved by slapd using the portion of entry it
770 retrieved from the remote server without requiring any further
771 intervention of the backend, so, if the <dnattr> attribute has not
772 been fetched, the match cannot be assessed because the attribute is
773 not present, not because no value matches the requirement!
774 .LP
775 Note on ACLs and attribute mapping: ACLs are applied to the mapped
776 attributes; for instance, if the attribute locally known as "foo" is
777 mapped to "bar" on a remote server, then local ACLs apply to attribute
778 "foo" and are totally unaware of its remote name.
779 The remote server will check permissions for "bar", and the local
780 server will possibly enforce additional restrictions to "foo".
781 .\"
782 .\" If this section is moved, also update the reference in
783 .\" libraries/librewrite/RATIONALE.
784 .\"
785 .SH REWRITING
786 A string is rewritten according to a set of rules, called a `rewrite
787 context'.
788 The rules are based on POSIX (''extended'') regular expressions (regex)
789 with substring matching; basic variable substitution and map resolution 
790 of substrings is allowed by specific mechanisms detailed in the following.
791 The behavior of pattern matching/substitution can be altered by a set
792 of flags.
793 .LP
794 The underlying concept is to build a lightweight rewrite module
795 for the slapd server (initially dedicated to the LDAP backend).
796 .SH Passes
797 An incoming string is matched against a set of rules.
798 Rules are made of a regex match pattern, a substitution pattern
799 and a set of actions, described by a set of flags.
800 In case of match a string rewriting is performed according to the
801 substitution pattern that allows to refer to substrings matched in the
802 incoming string.
803 The actions, if any, are finally performed.
804 The substitution pattern allows map resolution of substrings.
805 A map is a generic object that maps a substitution pattern to a value.
806 The flags are divided in "Pattern matching Flags" and "Action Flags";
807 the former alter the regex match pattern behavior while the latter
808 alter the action that is taken after substitution.
809 .SH "Pattern Matching Flags"
810 .TP
811 .B `C'
812 honors case in matching (default is case insensitive)
813 .TP
814 .B `R'
815 use POSIX ''basic'' regular expressions (default is ''extended'')
816 .TP
817 .B `M{n}'
818 allow no more than
819 .B n
820 recursive passes for a specific rule; does not alter the max total count
821 of passes, so it can only enforce a stricter limit for a specific rule.
822 .SH "Action Flags"
823 .TP
824 .B `:'
825 apply the rule once only (default is recursive)
826 .TP
827 .B `@'
828 stop applying rules in case of match; the current rule is still applied 
829 recursively; combine with `:' to apply the current rule only once 
830 and then stop.
831 .TP
832 .B `#'
833 stop current operation if the rule matches, and issue an `unwilling to
834 perform' error.
835 .TP
836 .B `G{n}'
837 jump
838 .B n
839 rules back and forth (watch for loops!).
840 Note that `G{1}' is implicit in every rule.
841 .TP
842 .B `I'
843 ignores errors in rule; this means, in case of error, e.g. issued by a
844 map, the error is treated as a missed match.
845 The `unwilling to perform' is not overridden.
846 .TP
847 .B `U{n}'
848 uses
849 .B
850 n
851 as return code if the rule matches; the flag does not alter the recursive
852 behavior of the rule, so, to have it performed only once, it must be used 
853 in combination with `:', e.g.
854 .B `:U{16}'
855 returns the value `16' after exactly one execution of the rule, if the
856 pattern matches.
857 As a consequence, its behavior is equivalent to `@', with the return
858 code set to
859 .BR n ;
860 or, in other words, `@' is equivalent to `U{0}'.
861 By convention, the freely available codes are above 16 included;
862 the others are reserved.
863 .LP
864 The ordering of the flags can be significant.
865 For instance: `IG{2}' means ignore errors and jump two lines ahead
866 both in case of match and in case of error, while `G{2}I' means ignore
867 errors, but jump two lines ahead only in case of match.
868 .LP
869 More flags (mainly Action Flags) will be added as needed.
870 .SH "Pattern matching:"
871 See
872 .BR regex (7)
873 and/or
874 .BR re_format (7).
875 .SH "Substitution Pattern Syntax:"
876 Everything starting with `%' requires substitution;
877 .LP
878 the only obvious exception is `%%', which is left as is;
879 .LP
880 the basic substitution is `%d', where `d' is a digit;
881 0 means the whole string, while 1-9 is a submatch;
882 .LP
883 a `%' followed by a `{' invokes an advanced substitution.
884 The pattern is:
885 .LP
886 .RS
887 `%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
888 .RE
889 .LP
890 where <name> must be a legal name for the map, i.e.
891 .LP
892 .RS
893 .nf
894 <name> ::= [a-z][a-z0-9]* (case insensitive)
895 <op> ::= `>' `|' `&' `&&' `*' `**' `$'
896 .fi
897 .RE
898 .LP
899 and <substitution> must be a legal substitution
900 pattern, with no limits on the nesting level.
901 .LP
902 The operators are:
903 .TP
904 .B >
905 sub context invocation; <name> must be a legal, already defined
906 rewrite context name
907 .TP
908 .B |
909 external command invocation; <name> must refer to a legal, already
910 defined command name (NOT IMPL.)
911 .TP
912 .B &
913 variable assignment; <name> defines a variable in the running
914 operation structure which can be dereferenced later; operator
915 .B &
916 assigns a variable in the rewrite context scope; operator
917 .B &&
918 assigns a variable that scopes the entire session, e.g. its value
919 can be dereferenced later by other rewrite contexts
920 .TP
921 .B *
922 variable dereferencing; <name> must refer to a variable that is
923 defined and assigned for the running operation; operator
924 .B *
925 dereferences a variable scoping the rewrite context; operator
926 .B **
927 dereferences a variable scoping the whole session, e.g. the value
928 is passed across rewrite contexts
929 .TP
930 .B $
931 parameter dereferencing; <name> must refer to an existing parameter;
932 the idea is to make some run-time parameters set by the system
933 available to the rewrite engine, as the client host name, the bind DN
934 if any, constant parameters initialized at config time, and so on;
935 no parameter is currently set by either 
936 .B back\-ldap
937 or
938 .BR back\-meta ,
939 but constant parameters can be defined in the configuration file
940 by using the
941 .B rewriteParam
942 directive.
943 .LP
944 Substitution escaping has been delegated to the `%' symbol, 
945 which is used instead of `\e' in string substitution patterns
946 because `\e' is already escaped by slapd's low level parsing routines;
947 as a consequence, regex escaping requires two `\e' symbols,
948 e.g. `\fB.*\e.foo\e.bar\fP' must be written as `\fB.*\e\e.foo\e\e.bar\fP'.
949 .\"
950 .\" The symbol can be altered at will by redefining the related macro in
951 .\" "rewrite-int.h".
952 .\"
953 .SH "Rewrite context:"
954 A rewrite context is a set of rules which are applied in sequence.
955 The basic idea is to have an application initialize a rewrite
956 engine (think of Apache's mod_rewrite ...) with a set of rewrite
957 contexts; when string rewriting is required, one invokes the
958 appropriate rewrite context with the input string and obtains the
959 newly rewritten one if no errors occur.
960 .LP
961 Each basic server operation is associated to a rewrite context;
962 they are divided in two main groups: client \-> server and
963 server \-> client rewriting.
964 .LP
965 client \-> server:
966 .LP
967 .RS
968 .nf
969 (default)            if defined and no specific context 
970                      is available
971 bindDN               bind
972 searchBase           search
973 searchFilter         search
974 searchFilterAttrDN   search
975 compareDN            compare
976 compareAttrDN        compare AVA
977 addDN                add
978 addAttrDN            add AVA
979 modifyDN             modify
980 modifyAttrDN         modify AVA
981 modrDN               modrdn
982 newSuperiorDN        modrdn
983 deleteDN             delete
984 exopPasswdDN         password modify extended operation DN if proxy
985 .fi
986 .RE
987 .LP
988 server \-> client:
989 .LP
990 .RS
991 .nf
992 searchResult         search (only if defined; no default;
993                      acts on DN and DN-syntax attributes 
994                      of search results)
995 searchAttrDN         search AVA
996 matchedDN            all ops (only if applicable)
997 .fi
998 .RE
999 .LP
1000 .SH "Basic configuration syntax"
1001 .TP
1002 .B rewriteEngine { on | off }
1003 If `on', the requested rewriting is performed; if `off', no
1004 rewriting takes place (an easy way to stop rewriting without
1005 altering too much the configuration file).
1006 .TP
1007 .B rewriteContext <context name> "[ alias <aliased context name> ]"
1008 <Context name> is the name that identifies the context, i.e. the name
1009 used by the application to refer to the set of rules it contains.
1010 It is used also to reference sub contexts in string rewriting.
1011 A context may alias another one.
1012 In this case the alias context contains no rule, and any reference to
1013 it will result in accessing the aliased one.
1014 .TP
1015 .B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
1016 Determines how a string can be rewritten if a pattern is matched.
1017 Examples are reported below.
1018 .SH "Additional configuration syntax:"
1019 .TP
1020 .B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
1021 Allows to define a map that transforms substring rewriting into
1022 something else.
1023 The map is referenced inside the substitution pattern of a rule.
1024 .TP
1025 .B rewriteParam <param name> <param value>
1026 Sets a value with global scope, that can be dereferenced by the
1027 command `%{$paramName}'.
1028 .TP
1029 .B rewriteMaxPasses <number of passes> [<number of passes per rule>]
1030 Sets the maximum number of total rewriting passes that can be
1031 performed in a single rewrite operation (to avoid loops).
1032 A safe default is set to 100; note that reaching this limit is still
1033 treated as a success; recursive invocation of rules is simply 
1034 interrupted.
1035 The count applies to the rewriting operation as a whole, not 
1036 to any single rule; an optional per-rule limit can be set.
1037 This limit is overridden by setting specific per-rule limits
1038 with the `M{n}' flag.
1039 .SH "Configuration examples:"
1040 .nf
1041 # set to `off' to disable rewriting
1042 rewriteEngine on
1043
1044 # the rules the "suffixmassage" directive implies
1045 rewriteEngine on
1046 # all dataflow from client to server referring to DNs
1047 rewriteContext default
1048 rewriteRule "(.*)<virtualnamingcontext>$" "%1<realnamingcontext>" ":"
1049 # empty filter rule
1050 rewriteContext searchFilter
1051 # all dataflow from server to client
1052 rewriteContext searchResult
1053 rewriteRule "(.*)<realnamingcontext>$" "%1<virtualnamingcontext>" ":"
1054 rewriteContext searchAttrDN alias searchResult
1055 rewriteContext matchedDN alias searchResult
1056
1057 # Everything defined here goes into the `default' context.
1058 # This rule changes the naming context of anything sent
1059 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
1060
1061 rewriteRule "(.*)dc=home,[ ]?dc=net"
1062             "%1dc=OpenLDAP, dc=org"  ":"
1063
1064 # since a pretty/normalized DN does not include spaces
1065 # after rdn separators, e.g. `,', this rule suffices:
1066
1067 rewriteRule "(.*)dc=home,dc=net"
1068             "%1dc=OpenLDAP,dc=org"  ":"
1069
1070 # Start a new context (ends input of the previous one).
1071 # This rule adds blanks between DN parts if not present.
1072 rewriteContext  addBlanks
1073 rewriteRule     "(.*),([^ ].*)" "%1, %2"
1074
1075 # This one eats blanks
1076 rewriteContext  eatBlanks
1077 rewriteRule     "(.*),[ ](.*)" "%1,%2"
1078
1079 # Here control goes back to the default rewrite
1080 # context; rules are appended to the existing ones.
1081 # anything that gets here is piped into rule `addBlanks'
1082 rewriteContext  default
1083 rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
1084
1085 .\" # Anything with `uid=username' is looked up in
1086 .\" # /etc/passwd for gecos (I know it's nearly useless,
1087 .\" # but it is there just as a guideline to implementing
1088 .\" # custom maps).
1089 .\" # Note the `I' flag that leaves `uid=username' in place 
1090 .\" # if `username' does not have a valid account, and the
1091 .\" # `:' that forces the rule to be processed exactly once.
1092 .\" rewriteContext  uid2Gecos
1093 .\" rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
1094 .\"                 "%1cn=%2{xpasswd},%3"      "I:"
1095 .\" 
1096 .\" # Finally, in a bind, if one uses a `uid=username' DN,
1097 .\" # it is rewritten in `cn=name surname' if possible.
1098 .\" rewriteContext  bindDN
1099 .\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
1100 .\" 
1101 # Rewrite the search base according to `default' rules.
1102 rewriteContext  searchBase alias default
1103
1104 # Search results with OpenLDAP DN are rewritten back with
1105 # `dc=home,dc=net' naming context, with spaces eaten.
1106 rewriteContext  searchResult
1107 rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
1108                 "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
1109
1110 # Bind with email instead of full DN: we first need
1111 # an ldap map that turns attributes into a DN (the
1112 # argument used when invoking the map is appended to 
1113 # the URI and acts as the filter portion)
1114 rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
1115
1116 # Then we need to detect DN made up of a single email,
1117 # e.g. `mail=someone@example.com'; note that the rule
1118 # in case of match stops rewriting; in case of error,
1119 # it is ignored.  In case we are mapping virtual
1120 # to real naming contexts, we also need to rewrite
1121 # regular DNs, because the definition of a bindDn
1122 # rewrite context overrides the default definition.
1123 rewriteContext bindDN
1124 rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
1125
1126 # This is a rather sophisticated example. It massages a
1127 # search filter in case who performs the search has
1128 # administrative privileges.  First we need to keep
1129 # track of the bind DN of the incoming request, which is
1130 # stored in a variable called `binddn' with session scope,
1131 # and left in place to allow regular binding:
1132 rewriteContext  bindDN
1133 rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
1134
1135 # A search filter containing `uid=' is rewritten only
1136 # if an appropriate DN is bound.
1137 # To do this, in the first rule the bound DN is
1138 # dereferenced, while the filter is decomposed in a
1139 # prefix, in the value of the `uid=<arg>' AVA, and 
1140 # in a suffix. A tag `<>' is appended to the DN. 
1141 # If the DN refers to an entry in the `ou=admin' subtree, 
1142 # the filter is rewritten OR-ing the `uid=<arg>' with
1143 # `cn=<arg>'; otherwise it is left as is. This could be
1144 # useful, for instance, to allow apache's auth_ldap-1.4
1145 # module to authenticate users with both `uid' and
1146 # `cn', but only if the request comes from a possible
1147 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
1148 rewriteContext searchFilter
1149 rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
1150   "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
1151   ":I"
1152 rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
1153   "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
1154 rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
1155
1156 # This example shows how to strip unwanted DN-valued
1157 # attribute values from a search result; the first rule
1158 # matches DN values below "ou=People,dc=example,dc=com";
1159 # in case of match the rewriting exits successfully.
1160 # The second rule matches everything else and causes
1161 # the value to be rejected.
1162 rewriteContext searchResult
1163 rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
1164 rewriteRule ".*" "" "#"
1165 .fi
1166 .SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
1167 In case the rewritten DN is an LDAP URI, the operation is initiated
1168 towards the host[:port] indicated in the uri, if it does not refer
1169 to the local server.
1170 E.g.:
1171 .LP
1172 .nf
1173   rewriteRule '^cn=root,.*' '%0'                     'G{3}'
1174   rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
1175   rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
1176   rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
1177 .fi
1178 .LP
1179 (Rule 1 is simply there to illustrate the `G{n}' action; it could have
1180 been written:
1181 .LP
1182 .nf
1183   rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
1184 .fi
1185 .LP
1186 with the advantage of saving one rewrite pass ...)
1187
1188 .SH ACCESS CONTROL
1189 The
1190 .B meta
1191 backend does not honor all ACL semantics as described in
1192 .BR slapd.access (5).
1193 In general, access checking is delegated to the remote server(s).
1194 Only
1195 .B read (=r)
1196 access to the
1197 .B entry
1198 pseudo-attribute and to the other attribute values of the entries
1199 returned by the
1200 .B search
1201 operation is honored, which is performed by the frontend.
1202
1203 .SH PROXY CACHE OVERLAY
1204 The proxy cache overlay 
1205 allows caching of LDAP search requests (queries) in a local database.
1206 See 
1207 .BR slapo\-pcache (5)
1208 for details.
1209 .SH FILES
1210 .TP
1211 ETCDIR/slapd.conf
1212 default slapd configuration file
1213 .SH SEE ALSO
1214 .BR slapd.conf (5),
1215 .BR slapd\-ldap (5),
1216 .BR slapo\-pcache (5),
1217 .BR slapd (8),
1218 .BR regex (7),
1219 .BR re_format (7).
1220 .SH AUTHOR
1221 Pierangelo Masarati, based on back-ldap by Howard Chu