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