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