]> git.sur5r.net Git - openldap/blob - doc/man/man5/slapd-meta.5
Happy New Year!
[openldap] / doc / man / man5 / slapd-meta.5
1 .TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" Copyright 1998-2005 The OpenLDAP Foundation, All Rights Reserved.
3 .\" Copying restrictions apply.  See the COPYRIGHT file.
4 .\" Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
5 .\" $OpenLDAP$
6 .\"
7 .\" Portions of this document should probably be moved to slapd-ldap(5)
8 .\" and maybe manual pages for librewrite.
9 .\"
10 .SH NAME
11 slapd-meta \- metadirectory backend
12 .SH SYNOPSIS
13 ETCDIR/slapd.conf
14 .SH DESCRIPTION
15 The
16 .B meta
17 backend to
18 .BR slapd (8)
19 performs basic LDAP proxying with respect to a set of remote LDAP
20 servers, called "targets".
21 The information contained in these servers can be presented as
22 belonging to a single Directory Information Tree (DIT).
23 .LP
24 A basic knowledge of the functionality of the
25 .BR slapd\-ldap (5)
26 backend is recommended.
27 This backend has been designed as an enhancement of the ldap backend.
28 The two backends share many features (actually they also share
29 portions of code).
30 While the
31 .B ldap
32 backend is intended to proxy operations directed to a single server, the
33 .B meta
34 backend is mainly intended for proxying of multiple servers and possibly
35 naming context masquerading.
36 These features, although useful in many scenarios, may result in
37 excessive overhead for some applications, so its use should be
38 carefully considered.
39 In the examples section, some typical scenarios will be discussed.
40 .SH EXAMPLES
41 There are examples in various places in this document, as well as in the
42 slapd/back-meta/data/ directory in the OpenLDAP source tree.
43 .SH CONFIGURATION
44 These
45 .B slapd.conf
46 options apply to the META backend database.
47 That is, they must follow a "database meta" line and come before any
48 subsequent "backend" or "database" lines.
49 Other database options are described in the
50 .BR slapd.conf (5)
51 manual page.
52 .LP
53 Note: as with the
54 .B ldap
55 backend, operational attributes related to entry creation/modification
56 should not be used, as they would be passed to the target servers,
57 generating an error.
58 Moreover, it makes little sense to use such attributes in proxying, as
59 the proxy server doesn't actually store data, so it should have no
60 knowledge of such attributes.
61 While code to strip the modification attributes has been put in place
62 (and #ifdef'd), it implies unmotivated overhead.
63 So it is strongly recommended to set
64 .RS
65 lastmod  off
66 .RE
67 for every
68 .B ldap
69 and
70 .B meta
71 backend.
72 .SH SPECIAL CONFIGURATION DIRECTIVES
73 Target configuration starts with the "uri" directive.
74 All the configuration directives that are not specific to targets
75 should be defined first for clarity, including those that are common
76 to all backends.
77 They are:
78 .TP
79 .B default-target none
80 This directive forces the backend to reject all those operations
81 that must resolve to a single target in case none or multiple
82 targets are selected.
83 They include: add, delete, modify, modrdn; compare is not included, as
84 well as bind since, as they don't alter entries, in case of multiple
85 matches an attempt is made to perform the operation on any candidate
86 target, with the constraint that at most one must succeed.
87 This directive can also be used when processing targets to mark a
88 specific target as default.
89 .TP
90 .B dncache-ttl {forever|disabled|<ttl>}
91 This directive sets the time-to-live of the DN cache.
92 This caches the target that holds a given DN to speed up target
93 selection in case multiple targets would result from an uncached
94 search; forever means cache never expires; disabled means no DN
95 caching; otherwise a valid ( > 0 ) ttl in seconds is required.
96 .SH TARGET SPECIFICATION
97 Target specification starts with a "uri" directive:
98 .TP
99 .B uri <protocol>://[<host>[:<port>]]/<naming context>
100 The "server" directive that was allowed in the LDAP backend (although
101 deprecated) has been completely discarded in the Meta backend.
102 The <protocol> part can be anything
103 .BR ldap_initialize (3)
104 accepts ({ldap|ldaps|ldapi} and variants); <host> and <port> may be
105 omitted, defaulting to whatever is set in
106 .BR ldap.conf (5).
107 The <naming context> part is mandatory.
108 It must end with one of the naming contexts defined for the backend,
109 e.g.:
110 .LP
111 .RS
112 .nf
113 suffix "\fBdc=foo,dc=com\fP"
114 uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
115 .fi
116
117 .RE
118 .RS
119 The <naming context> part doesn't need to be unique across the targets;
120 it may also match one of the values of the "suffix" directive.
121 Multiple URIs may be defined in a single argument.  The URIs must
122 be separated by TABs (e.g. '\\t'; commas or spaces, unlike back-ldap,
123 will not work,
124 because they are legal in the <naming context>, and we don't want to use
125 URL-encoded <namimg context>s), and the additional URIs must have
126 no <naming context> part.  This causes the underlying library
127 to contact the first server of the list that responds.
128 .RE
129 .TP
130 .B default-target [<target>]
131 The "default-target" directive can also be used during target specification.
132 With no arguments it marks the current target as the default.
133 The optional number marks target <target> as the default one, starting
134 from 1.
135 Target <target> must be defined.
136 .TP
137 .B binddn "<administrative DN for access control purposes>"
138 This directive, as in the LDAP backend, allows to define the DN that is
139 used to query the target server for acl checking; it should have read
140 access on the target server to attributes used on the proxy for acl
141 checking.
142 There is no risk of giving away such values; they are only used to
143 check permissions.
144 .TP
145 .B bindpw <password for access control purposes>
146 This directive sets the password for acl checking in conjunction
147 with the above mentioned "binddn" directive.
148 .TP
149 .B rebind-as-user
150 If this option is given, the client's bind credentials are remembered
151 for rebinds when chasing referrals.
152 .TP
153 .B pseudorootdn "<substitute DN in case of rootdn bind>"
154 This directive, if present, sets the DN that will be substituted to
155 the bind DN if a bind with the backend's "rootdn" succeeds.
156 The true "rootdn" of the target server ought not be used; an arbitrary
157 administrative DN should used instead.
158 .TP
159 .B pseudorootpw "<substitute password in case of rootdn bind>"
160 This directive sets the credential that will be used in case a bind
161 with the backend's "rootdn" succeeds, and the bind is propagated to
162 the target using the "pseudorootdn" DN.
163 .LP
164 Note: cleartext credentials must be supplied here; as a consequence,
165 using the pseudorootdn/pseudorootpw directives is inherently unsafe.
166 .TP
167 .B rewrite* ...
168 The rewrite options are described in the "REWRITING" section.
169 .TP
170 .B suffixmassage "<virtual naming context>" "<real naming context>"
171 All the directives starting with "rewrite" refer to the rewrite engine
172 that has been added to slapd.
173 The "suffixmassage" directive was introduced in the LDAP backend to
174 allow suffix massaging while proxying.
175 It has been obsoleted by the rewriting tools.
176 However, both for backward compatibility and for ease of configuration
177 when simple suffix massage is required, it has been preserved.
178 It wraps the basic rewriting instructions that perform suffix
179 massaging.  See the "REWRITING" section for a detailed list 
180 of the rewrite rules it implies.
181 .LP
182 Note: this also fixes a flaw in suffix massaging, which operated
183 on (case insensitive) DNs instead of normalized DNs,
184 so "dc=foo, dc=com" would not match "dc=foo,dc=com".
185 .LP
186 See the "REWRITING" section.
187 .TP
188 .B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
189 This maps object classes and attributes as in the LDAP backend.
190 See
191 .BR slapd-ldap (5).
192 .SH SCENARIOS
193 A powerful (and in some sense dangerous) rewrite engine has been added
194 to both the LDAP and Meta backends.
195 While the former can gain limited beneficial effects from rewriting
196 stuff, the latter can become an amazingly powerful tool.
197 .LP
198 Consider a couple of scenarios first.
199 .LP
200 1) Two directory servers share two levels of naming context;
201 say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
202 Then, an unambiguous Meta database can be configured as:
203 .LP
204 .RS
205 .nf
206 database meta
207 suffix   "\fBdc=foo,dc=com\fP"
208 uri      "ldap://a.foo.com/dc=a,\fBdc=foo,dc=com\fP"
209 uri      "ldap://b.foo.com/dc=b,\fBdc=foo,dc=com\fP"
210 .fi
211 .RE
212 .LP
213 Operations directed to a specific target can be easily resolved
214 because there are no ambiguities.
215 The only operation that may resolve to multiple targets is a search
216 with base "dc=foo,dc=com" and scope at least "one", which results in
217 spawning two searches to the targets.
218 .LP
219 2a) Two directory servers don't share any portion of naming context,
220 but they'd present as a single DIT
221 [Caveat: uniqueness of (massaged) entries among the two servers is
222 assumed; integrity checks risk to incur in excessive overhead and have
223 not been implemented].
224 Say we have "dc=bar,dc=org" and "o=Foo,c=US",
225 and we'd like them to appear as branches of "dc=foo,dc=com", say
226 "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
227 Then we need to configure our Meta backend as:
228 .LP
229 .RS
230 .nf
231 database      meta
232 suffix        "dc=foo,dc=com"
233
234 uri           "ldap://a.bar.com/\fBdc=a,dc=foo,dc=com\fP"
235 suffixmassage "\fBdc=a,dc=foo,dc=com\fP" "dc=bar,dc=org"
236
237 uri           "ldap://b.foo.com/\fBdc=b,dc=foo,dc=com\fP"
238 suffixmassage "\fBdc=b,dc=foo,dc=com\fP" "o=Foo,c=US"
239 .fi
240 .RE
241 .LP
242 Again, operations can be resolved without ambiguity, although
243 some rewriting is required.
244 Notice that the virtual naming context of each target is a branch of
245 the database's naming context; it is rewritten back and forth when
246 operations are performed towards the target servers.
247 What "back and forth" means will be clarified later.
248 .LP
249 When a search with base "dc=foo,dc=com" is attempted, if the 
250 scope is "base" it fails with "no such object"; in fact, the
251 common root of the two targets (prior to massaging) does not
252 exist.
253 If the scope is "one", both targets are contacted with the base
254 replaced by each target's base; the scope is derated to "base".
255 In general, a scope "one" search is honored, and the scope is derated,
256 only when the incoming base is at most one level lower of a target's
257 naming context (prior to massaging).
258 .LP
259 Finally, if the scope is "sub" the incoming base is replaced
260 by each target's unmassaged naming context, and the scope
261 is not altered.
262 .LP
263 2b) Consider the above reported scenario with the two servers
264 sharing the same naming context:
265 .LP
266 .RS
267 .nf
268 database      meta
269 suffix        "\fBdc=foo,dc=com\fP"
270
271 uri           "ldap://a.bar.com/\fBdc=foo,dc=com\fP"
272 suffixmassage "\fBdc=foo,dc=com\fP" "dc=bar,dc=org"
273
274 uri           "ldap://b.foo.com/\fBdc=foo,dc=com\fP"
275 suffixmassage "\fBdc=foo,dc=com\fP" "o=Foo,c=US"
276 .fi
277 .RE
278 .LP
279 All the previous considerations hold, except that now there is
280 no way to unambiguously resolve a DN.
281 In this case, all the operations that require an unambiguous target
282 selection will fail unless the DN is already cached or a default
283 target has been set.
284 Practical configurations may result as a combination of all the
285 above scenarios.
286 .SH ACLs
287 Note on ACLs: at present you may add whatever ACL rule you desire
288 to to the Meta (and LDAP) backends.
289 However, the meaning of an ACL on a proxy may require some
290 considerations.
291 Two philosophies may be considered:
292 .LP
293 a) the remote server dictates the permissions; the proxy simply passes
294 back what it gets from the remote server.
295 .LP
296 b) the remote server unveils "everything"; the proxy is responsible
297 for protecting data from unauthorized access.
298 .LP
299 Of course the latter sounds unreasonable, but it is not.
300 It is possible to imagine scenarios in which a remote host discloses
301 data that can be considered "public" inside an intranet, and a proxy
302 that connects it to the internet may impose additional constraints.
303 To this purpose, the proxy should be able to comply with all the ACL
304 matching criteria that the server supports.
305 This has been achieved with regard to all the criteria supported by
306 slapd except a special subtle case (please drop me a note if you can
307 find other exceptions: <ando@openldap.org>).
308 The rule
309 .LP
310 .RS
311 .nf
312 access to dn="<dn>" attr=<attr>
313        by dnattr=<dnattr> read
314        by * none
315 .fi
316 .RE
317 .LP
318 cannot be matched iff the attribute that is being requested, <attr>,
319 is NOT <dnattr>, and the attribute that determines membership,
320 <dnattr>, has not been requested (e.g. in a search)
321 .LP
322 In fact this ACL is resolved by slapd using the portion of entry it
323 retrieved from the remote server without requiring any further
324 intervention of the backend, so, if the <dnattr> attribute has not
325 been fetched, the match cannot be assessed because the attribute is
326 not present, not because no value matches the requirement!
327 .LP
328 Note on ACLs and attribute mapping: ACLs are applied to the mapped
329 attributes; for instance, if the attribute locally known as "foo" is
330 mapped to "bar" on a remote server, then local ACLs apply to attribute
331 "foo" and are totally unaware of its remote name.
332 The remote server will check permissions for "bar", and the local
333 server will possibly enforce additional restrictions to "foo".
334 .\"
335 .\" If this section is moved, also update the reference in
336 .\" libraries/librewrite/RATIONALE.
337 .\"
338 .SH REWRITING
339 A string is rewritten according to a set of rules, called a `rewrite
340 context'.
341 The rules are based on POSIX (''extended'') regular expressions (regex)
342 with substring matching; basic variable substitution and map resolution 
343 of substrings is allowed by specific mechanisms detailed in the following.
344 The behavior of pattern matching/substitution can be altered by a set
345 of flags.
346 .LP
347 The underlying concept is to build a lightweight rewrite module
348 for the slapd server (initially dedicated to the LDAP backend).
349 .SH Passes
350 An incoming string is matched agains a set of rules.
351 Rules are made of a regex match pattern, a substitution pattern
352 and a set of actions, described by a set of flags.
353 In case of match a string rewriting is performed according to the
354 substitution pattern that allows to refer to substrings matched in the
355 incoming string.
356 The actions, if any, are finally performed.
357 The substitution pattern allows map resolution of substrings.
358 A map is a generic object that maps a substitution pattern to a value.
359 The flags are divided in "Pattern matching Flags" and "Action Flags";
360 the former alter the regex match pattern behaviorm while the latter
361 alter the action that is taken after substitution.
362 .SH "Pattern Matching Flags"
363 .TP
364 .B `C'
365 honors case in matching (default is case insensitive)
366 .TP
367 .B `R'
368 use POSIX ''basic'' regular expressions (default is ''extended'')
369 .TP
370 .B `M{n}'
371 allow no more than
372 .B n
373 recursive passes for a specific rule; does not alter the max total count
374 of passes, so it can only enforce a stricter limit for a specific rule.
375 .SH "Action Flags"
376 .TP
377 .B `:'
378 apply the rule once only (default is recursive)
379 .TP
380 .B `@'
381 stop applying rules in case of match; the current rule is still applied 
382 recursively; combine with `:' to apply the current rule only once 
383 and then stop.
384 .TP
385 .B `#'
386 stop current operation if the rule matches, and issue an `unwilling to
387 perform' error.
388 .TP
389 .B `G{n}'
390 jump
391 .B n
392 rules back and forth (watch for loops!).
393 Note that `G{1}' is implicit in every rule.
394 .TP
395 .B `I'
396 ignores errors in rule; this means, in case of error, e.g. issued by a
397 map, the error is treated as a missed match.
398 The `unwilling to perform' is not overridden.
399 .TP
400 .B `U{n}'
401 uses
402 .B
403 n
404 as return code if the rule matches; the flag does not alter the recursive
405 behavior of the rule, so, to have it performed only once, it must be used 
406 in combination with `:', e.g.
407 .B `:U{16}'
408 returns the value `16' after exactly one execution of the rule, if the
409 pattern matches.
410 As a consequence, its behavior is equivalent to `@', with the return
411 code set to
412 .BR n ;
413 or, in other words, `@' is equivalent to `U{0}'.
414 By convention, the freely available codes are above 16 included;
415 the others are reserved.
416 .LP
417 The ordering of the flags can be significant.
418 For instance: `IG{2}' means ignore errors and jump two lines ahead
419 both in case of match and in case of error, while `G{2}I' means ignore
420 errors, but jump two lines ahead only in case of match.
421 .LP
422 More flags (mainly Action Flags) will be added as needed.
423 .SH "Pattern matching:"
424 See
425 .BR regex (7)
426 and/or
427 .BR re_format (7).
428 .SH "Substitution Pattern Syntax:"
429 Everything starting with `%' requires substitution;
430 .LP
431 the only obvious exception is `%%', which is left as is;
432 .LP
433 the basic substitution is `%d', where `d' is a digit;
434 0 means the whole string, while 1-9 is a submatch;
435 .LP
436 a `%' followed by a `{' invokes an advanced substitution.
437 The pattern is:
438 .LP
439 .RS
440 `%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
441 .RE
442 .LP
443 where <name> must be a legal name for the map, i.e.
444 .LP
445 .RS
446 .nf
447 <name> ::= [a-z][a-z0-9]* (case insensitive)
448 <op> ::= `>' `|' `&' `&&' `*' `**' `$'
449 .fi
450 .RE
451 .LP
452 and <substitution> must be a legal substitution
453 pattern, with no limits on the nesting level.
454 .LP
455 The operators are:
456 .TP
457 .B >
458 sub context invocation; <name> must be a legal, already defined
459 rewrite context name
460 .TP
461 .B |
462 external command invocation; <name> must refer to a legal, already
463 defined command name (NOT IMPL.)
464 .TP
465 .B &
466 variable assignment; <name> defines a variable in the running
467 operation structure which can be dereferenced later; operator
468 .B &
469 assigns a variable in the rewrite context scope; operator
470 .B &&
471 assigns a variable that scopes the entire session, e.g. its value
472 can be derefenced later by other rewrite contexts
473 .TP
474 .B *
475 variable dereferencing; <name> must refer to a variable that is
476 defined and assigned for the running operation; operator
477 .B *
478 dereferences a variable scoping the rewrite context; operator
479 .B **
480 dereferences a variable scoping the whole session, e.g. the value
481 is passed across rewrite contexts
482 .TP
483 .B $
484 parameter dereferencing; <name> must refer to an existing parameter;
485 the idea is to make some run-time parameters set by the system
486 available to the rewrite engine, as the client host name, the bind DN
487 if any, constant parameters initialized at config time, and so on;
488 no parameter is currently set by either 
489 .B back\-ldap
490 or
491 .BR back\-meta ,
492 but constant parameters can be defined in the configuration file
493 by using the
494 .B rewriteParam
495 directive.
496 .LP
497 Substitution escaping has been delegated to the `%' symbol, 
498 which is used instead of `\e' in string substitution patterns
499 because `\e' is already escaped by slapd's low level parsing routines;
500 as a consequence, regex escaping requires two `\e' symbols,
501 e.g. `\fB.*\e.foo\e.bar\fP' must be written as `\fB.*\e\e.foo\e\e.bar\fP'.
502 .\"
503 .\" The symbol can be altered at will by redefining the related macro in
504 .\" "rewrite-int.h".
505 .\"
506 .SH "Rewrite context:"
507 A rewrite context is a set of rules which are applied in sequence.
508 The basic idea is to have an application initialize a rewrite
509 engine (think of Apache's mod_rewrite ...) with a set of rewrite
510 contexts; when string rewriting is required, one invokes the
511 appropriate rewrite context with the input string and obtains the
512 newly rewritten one if no errors occur.
513 .LP
514 Each basic server operation is associated to a rewrite context;
515 they are divided in two main groups: client \-> server and
516 server \-> client rewriting.
517 .LP
518 client -> server:
519 .LP
520 .RS
521 .nf
522 (default)            if defined and no specific context 
523                      is available
524 bindDN               bind
525 searchBase           search
526 searchFilter         search
527 searchFilterAttrDN   search
528 compareDN            compare
529 compareAttrDN        compare AVA
530 addDN                add
531 addAttrDN            add AVA
532 modifyDN             modify
533 modifyAttrDN         modify AVA
534 modrDN               modrdn
535 newSuperiorDN        modrdn
536 deleteDN             delete
537 exopPasswdDN         passwd exop DN if proxy
538 .fi
539 .RE
540 .LP
541 server -> client:
542 .LP
543 .RS
544 .nf
545 searchResult         search (only if defined; no default;
546                      acts on DN and DN-syntax attributes 
547                      of search results)
548 searchAttrDN         search AVA
549 matchedDN            all ops (only if applicable)
550 .fi
551 .RE
552 .LP
553 .SH "Basic configuration syntax"
554 .TP
555 .B rewriteEngine { on | off }
556 If `on', the requested rewriting is performed; if `off', no
557 rewriting takes place (an easy way to stop rewriting without
558 altering too much the configuration file).
559 .TP
560 .B rewriteContext <context name> "[ alias <aliased context name> ]"
561 <Context name> is the name that identifies the context, i.e. the name
562 used by the application to refer to the set of rules it contains.
563 It is used also to reference sub contexts in string rewriting.
564 A context may aliase another one.
565 In this case the alias context contains no rule, and any reference to
566 it will result in accessing the aliased one.
567 .TP
568 .B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
569 Determines how a string can be rewritten if a pattern is matched.
570 Examples are reported below.
571 .SH "Additional configuration syntax:"
572 .TP
573 .B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
574 Allows to define a map that transforms substring rewriting into
575 something else.
576 The map is referenced inside the substitution pattern of a rule.
577 .TP
578 .B rewriteParam <param name> <param value>
579 Sets a value with global scope, that can be dereferenced by the
580 command `%{$paramName}'.
581 .TP
582 .B rewriteMaxPasses <number of passes> [<number of passes per rule>]
583 Sets the maximum number of total rewriting passes that can be
584 performed in a single rewrite operation (to avoid loops).
585 A safe default is set to 100; note that reaching this limit is still
586 treated as a success; recursive invocation of rules is simply 
587 interrupted.
588 The count applies to the rewriting operation as a whole, not 
589 to any single rule; an optional per-rule limit can be set.
590 This limit is overridden by setting specific per-rule limits
591 with the `M{n}' flag.
592 .SH "Configuration examples:"
593 .nf
594 # set to `off' to disable rewriting
595 rewriteEngine on
596
597 # the rules the "suffixmassage" directive implies
598 rewriteEngine on
599 # all dataflow from client to server referring to DNs
600 rewriteContext default
601 rewriteRule "(.*)<virtualnamingcontext>$" "%1<realnamingcontext>" ":"
602 # empty filter rule
603 rewriteContext searchFilter
604 # all dataflow from server to client
605 rewriteContext searchResult
606 rewriteRule "(.*)<realnamingcontext>$" "%1<virtualnamingcontext>" ":"
607 rewriteContext searchAttrDN alias searchResult
608 rewriteContext matchedDN alias searchResult
609
610 # Everything defined here goes into the `default' context.
611 # This rule changes the naming context of anything sent
612 # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
613
614 rewriteRule "(.*)dc=home,[ ]?dc=net"
615             "%1dc=OpenLDAP, dc=org"  ":"
616
617 # since a pretty/normalized DN does not include spaces
618 # after rdn separators, e.g. `,', this rule suffices:
619
620 rewriteRule "(.*)dc=home,dc=net"
621             "%1dc=OpenLDAP,dc=org"  ":"
622
623 # Start a new context (ends input of the previous one).
624 # This rule adds blanks between DN parts if not present.
625 rewriteContext  addBlanks
626 rewriteRule     "(.*),([^ ].*)" "%1, %2"
627
628 # This one eats blanks
629 rewriteContext  eatBlanks
630 rewriteRule     "(.*),[ ](.*)" "%1,%2"
631
632 # Here control goes back to the default rewrite
633 # context; rules are appended to the existing ones.
634 # anything that gets here is piped into rule `addBlanks'
635 rewriteContext  default
636 rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
637
638 .\" # Anything with `uid=username' is looked up in
639 .\" # /etc/passwd for gecos (I know it's nearly useless,
640 .\" # but it is there just as a guideline to implementing
641 .\" # custom maps).
642 .\" # Note the `I' flag that leaves `uid=username' in place 
643 .\" # if `username' does not have a valid account, and the
644 .\" # `:' that forces the rule to be processed exactly once.
645 .\" rewriteContext  uid2Gecos
646 .\" rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
647 .\"                 "%1cn=%2{xpasswd},%3"      "I:"
648 .\" 
649 .\" # Finally, in a bind, if one uses a `uid=username' DN,
650 .\" # it is rewritten in `cn=name surname' if possible.
651 .\" rewriteContext  bindDN
652 .\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
653 .\" 
654 # Rewrite the search base according to `default' rules.
655 rewriteContext  searchBase alias default
656
657 # Search results with OpenLDAP DN are rewritten back with
658 # `dc=home,dc=net' naming context, with spaces eaten.
659 rewriteContext  searchResult
660 rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
661                 "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
662
663 # Bind with email instead of full DN: we first need
664 # an ldap map that turns attributes into a DN (the
665 # argument used when invoking the map is appended to 
666 # the URI and acts as the filter portion)
667 rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
668
669 # Then we need to detect DN made up of a single email,
670 # e.g. `mail=someone@example.com'; note that the rule
671 # in case of match stops rewriting; in case of error,
672 # it is ignored.  In case we are mapping virtual
673 # to real naming contexts, we also need to rewrite
674 # regular DNs, because the definition of a bindDn
675 # rewrite context overrides the default definition.
676 rewriteContext bindDN
677 rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
678
679 # This is a rather sophisticated example. It massages a
680 # search filter in case who performs the search has
681 # administrative privileges.  First we need to keep
682 # track of the bind DN of the incoming request, which is
683 # stored in a variable called `binddn' with session scope,
684 # and left in place to allow regular binding:
685 rewriteContext  bindDN
686 rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
687
688 # A search filter containing `uid=' is rewritten only
689 # if an appropriate DN is bound.
690 # To do this, in the first rule the bound DN is
691 # dereferenced, while the filter is decomposed in a
692 # prefix, in the value of the `uid=<arg>' AVA, and 
693 # in a suffix. A tag `<>' is appended to the DN. 
694 # If the DN refers to an entry in the `ou=admin' subtree, 
695 # the filter is rewritten OR-ing the `uid=<arg>' with
696 # `cn=<arg>'; otherwise it is left as is. This could be
697 # useful, for instance, to allow apache's auth_ldap-1.4
698 # module to authenticate users with both `uid' and
699 # `cn', but only if the request comes from a possible
700 # `cn=Web auth,ou=admin,dc=home,dc=net' user.
701 rewriteContext searchFilter
702 rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
703   "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
704   ":I"
705 rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
706   "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
707 rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
708
709 # This example shows how to strip unwanted DN-valued
710 # attribute values from a search result; the first rule
711 # matches DN values below "ou=People,dc=example,dc=com";
712 # in case of match the rewriting exits successfully.
713 # The second rule matches everything else and causes
714 # the value to be rejected.
715 rewriteContext searchResult
716 rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
717 rewriteRule ".*" "" "#"
718 .fi
719 .SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
720 In case the rewritten DN is an LDAP URI, the operation is initiated
721 towards the host[:port] indicated in the uri, if it does not refer
722 to the local server.
723 E.g.:
724 .LP
725 .nf
726   rewriteRule '^cn=root,.*' '%0'                     'G{3}'
727   rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
728   rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
729   rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
730 .fi
731 .LP
732 (Rule 1 is simply there to illustrate the `G{n}' action; it could have
733 been written:
734 .LP
735 .nf
736   rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
737 .fi
738 .LP
739 with the advantage of saving one rewrite pass ...)
740 .SH PROXY CACHE OVERLAY
741 The proxy cache overlay 
742 allows caching of LDAP search requests (queries) in a local database.
743 See 
744 .BR slapo-pcache (5)
745 for details.
746 .SH FILES
747 .TP
748 ETCDIR/slapd.conf
749 default slapd configuration file
750 .SH SEE ALSO
751 .BR slapd.conf (5),
752 .BR slapd\-ldap (5),
753 .BR slapo\-pcache (5),
754 .BR slapd (8),
755 .BR regex (7),
756 .BR re_format (7).
757 .SH AUTHOR
758 Pierangelo Masarati, based on back-ldap by Howard Chu