]> git.sur5r.net Git - openldap/blobdiff - doc/man/man5/slapd-meta.5
clarify what rewrite rules suffixmassage corresponds to
[openldap] / doc / man / man5 / slapd-meta.5
index 26a1085b3175ef509cbe1e1267256572f9aeb945..a8d50a63750d3f620318782d4058ed5bd99c468b 100644 (file)
@@ -1,5 +1,5 @@
-.TH SLAPD_META 5 "30 April 2002" "OpenLDAP LDVERSION"
-.\" Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+.TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
+.\" Copyright 1998-2004 The OpenLDAP Foundation, All Rights Reserved.
 .\" Copying restrictions apply.  See the COPYRIGHT file.
 .\" Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
 .\" $OpenLDAP$
@@ -8,7 +8,7 @@
 .\" and maybe manual pages for librewrite.
 .\"
 .SH NAME
-slapd_meta \- metadirectory backend
+slapd-meta \- metadirectory backend
 .SH SYNOPSIS
 ETCDIR/slapd.conf
 .SH DESCRIPTION
@@ -61,11 +61,9 @@ knowledge of such attributes.
 While code to strip the modification attributes has been put in place
 (and #ifdef'd), it implies unmotivated overhead.
 So it is strongly recommended to set
-.LP
-.nf
-       lastmod         off
-.fi
-.LP
+.RS
+lastmod  off
+.RE
 for every
 .B ldap
 and
@@ -101,20 +99,27 @@ Target specification starts with a "uri" directive:
 .B uri <protocol>://[<host>[:<port>]]/<naming context>
 The "server" directive that was allowed in the LDAP backend (although
 deprecated) has been discarded in the Meta backend.
-The <protocol> part can be anything ldap_initialize(3) accepts
-({ldap|ldaps|ldapi} and variants); <host> and <port> may be omitted,
-defaulting to whatever is set in /etc/ldap.conf.
+The <protocol> part can be anything
+.BR ldap_initialize (3)
+accepts ({ldap|ldaps|ldapi} and variants); <host> and <port> may be
+omitted, defaulting to whatever is set in /etc/ldap.conf.
 The <naming context> part is mandatory.
 It must end with one of the naming contexts defined for the backend,
 e.g.:
 .LP
+.RS
 .nf
-  suffix "\fBdc=foo,dc=com\fP"
-  uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
+suffix "\fBdc=foo,dc=com\fP"
+uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
 .fi
+.RE
 .LP
 The <naming context> part doesn't need to be unique across the targets;
 it may also match one of the values of the "suffix" directive.
+Multiple URIs may be defined in a single argument.  The URIs must
+be separated by TABs (e.g. '\\t'), and the additional URIs must have
+no <naming context> part.  This causes the underlying library
+to contact the first server of the list that responds.
 .TP
 .B default-target [<target>]
 The "default-target" directive can also be used during target specification.
@@ -135,6 +140,10 @@ check permissions.
 This directive sets the password for acl checking in conjunction
 with the above mentioned "binddn" directive.
 .TP
+.B rebind-as-user
+If this option is given, the client's bind credentials are remembered
+for rebinds when chasing referrals.
+.TP
 .B pseudorootdn "<substitute DN in case of rootdn bind>"
 This directive, if present, sets the DN that will be substituted to
 the bind DN if a bind with the backend's "rootdn" succeeds.
@@ -161,7 +170,8 @@ It has been obsoleted by the rewriting tools.
 However, both for backward compatibility and for ease of configuration
 when simple suffix massage is required, it has been preserved.
 It wraps the basic rewriting instructions that perform suffix
-massaging.
+massaging.  See the "REWRITING" section for a detailed list 
+of the rewrite rules it implies.
 .LP
 Note: this also fixes a flaw in suffix massaging, which operated
 on (case insensitive) DNs instead of normalized DNs,
@@ -169,7 +179,7 @@ so "dc=foo, dc=com" would not match "dc=foo,dc=com".
 .LP
 See the "REWRITING" section.
 .TP
-.B map {objectClass|attribute} {<source>|*} [<dest>|*]
+.B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
 This maps object classes and attributes as in the LDAP backend.
 See
 .BR slapd-ldap (5).
@@ -185,12 +195,14 @@ Consider a couple of scenarios first.
 say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
 Then, an unambiguous Meta database can be configured as:
 .LP
+.RS
 .nf
-  database meta
-  suffix   "dc=foo,dc=com"
-  uri      "ldap://a.foo.com/dc=a,dc=foo,dc=com"
-  uri      "ldap://b.foo.com/dc=b,dc=foo,dc=com"
+database meta
+suffix   "\fBdc=foo,dc=com\fP"
+uri      "ldap://a.foo.com/dc=a,\fBdc=foo,dc=com\fP"
+uri      "ldap://b.foo.com/dc=b,\fBdc=foo,dc=com\fP"
 .fi
+.RE
 .LP
 Operations directed to a specific target can be easily resolved
 because there are no ambiguities.
@@ -208,16 +220,18 @@ and we'd like them to appear as branches of "dc=foo,dc=com", say
 "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
 Then we need to configure our Meta backend as:
 .LP
+.RS
 .nf
-  database     meta
-  suffix       "dc=foo,dc=com"
-  
-  uri          "ldap://a.bar.com/dc=a,dc=foo,dc=com"
-  suffixmassage        "dc=a,dc=foo,dc=com" "dc=bar,dc=org"
-       
-  uri          "ldap://b.foo.com/dc=b,dc=foo,dc=com"
-  suffixmassage        "dc=b,dc=foo,dc=com" "o=Foo,c=US"
+database      meta
+suffix        "dc=foo,dc=com"
+
+uri           "ldap://a.bar.com/\fBdc=a,dc=foo,dc=com\fP"
+suffixmassage "\fBdc=a,dc=foo,dc=com\fP" "dc=bar,dc=org"
+
+uri           "ldap://b.foo.com/\fBdc=b,dc=foo,dc=com\fP"
+suffixmassage "\fBdc=b,dc=foo,dc=com\fP" "o=Foo,c=US"
 .fi
+.RE
 .LP
 Again, operations can be resolved without ambiguity, although
 some rewriting is required.
@@ -243,22 +257,26 @@ is not altered.
 2b) Consider the above reported scenario with the two servers
 sharing the same naming context:
 .LP
+.RS
 .nf
-  database     meta
-  suffix       "dc=foo,dc=com"
-  
-  uri          "ldap://a.bar.com/dc=foo,dc=com"
-  suffixmassage        "dc=foo,dc=com" "dc=bar,dc=org"
-       
-  uri          "ldap://b.foo.com/dc=foo,dc=com"
-  suffixmassage        "dc=foo,dc=com" "o=Foo,c=US"
+database      meta
+suffix        "\fBdc=foo,dc=com\fP"
+
+uri           "ldap://a.bar.com/\fBdc=foo,dc=com\fP"
+suffixmassage "\fBdc=foo,dc=com\fP" "dc=bar,dc=org"
+
+uri           "ldap://b.foo.com/\fBdc=foo,dc=com\fP"
+suffixmassage "\fBdc=foo,dc=com\fP" "o=Foo,c=US"
 .fi
+.RE
 .LP
 All the previous considerations hold, except that now there is
 no way to unambiguously resolve a DN.
 In this case, all the operations that require an unambiguous target
 selection will fail unless the DN is already cached or a default
 target has been set.
+Practical configurations may result as a combination of all the
+above scenarios.
 .SH ACLs
 Note on ACLs: at present you may add whatever ACL rule you desire
 to to the Meta (and LDAP) backends.
@@ -283,11 +301,13 @@ slapd except a special subtle case (please drop me a note if you can
 find other exceptions: <ando@openldap.org>).
 The rule
 .LP
+.RS
 .nf
-  access to dn="<dn>" attr=<attr>
-        by dnattr=<dnattr> read
-        by * none
+access to dn="<dn>" attr=<attr>
+       by dnattr=<dnattr> read
+       by * none
 .fi
+.RE
 .LP
 cannot be matched iff the attribute that is being requested, <attr>,
 is NOT <dnattr>, and the attribute that determines membership,
@@ -313,8 +333,8 @@ server will possibly enforce additional restrictions to "foo".
 A string is rewritten according to a set of rules, called a `rewrite
 context'.
 The rules are based on Regular Expressions (POSIX regex) with
-substring matching; extensions are planned to allow basic variable
-substitution and map resolution of substrings.
+substring matching; basic variable substitution and map resolution 
+of substrings is allowed by specific mechanisms detailed in the following.
 The behavior of pattern matching/substitution can be altered by a set
 of flags.
 .LP
@@ -322,14 +342,17 @@ The underlying concept is to build a lightweight rewrite module
 for the slapd server (initially dedicated to the LDAP backend).
 .SH Passes
 An incoming string is matched agains a set of rules.
-Rules are made of a match pattern, a substitution pattern and a set of
-actions.
+Rules are made of a regex match pattern, a substitution pattern
+and a set of actions, described by a set of flags.
 In case of match a string rewriting is performed according to the
 substitution pattern that allows to refer to substrings matched in the
 incoming string.
 The actions, if any, are finally performed.
 The substitution pattern allows map resolution of substrings.
 A map is a generic object that maps a substitution pattern to a value.
+The flags are divided in "Pattern matching Flags" and "Action Flags";
+the former alter the regex match pattern behaviorm while the latter
+alter the action that is taken after substitution.
 .SH "Pattern Matching Flags"
 .TP
 .B `C'
@@ -337,60 +360,65 @@ honors case in matching (default is case insensitive)
 .TP
 .B `R'
 use POSIX Basic Regular Expressions (default is Extended)
+.TP
+.B `M{n}'
+allow no more than
+.B n
+recursive passes for a specific rule; does not alter the max total count
+of passes, so it can only enforce a stricter limit for a specific rule.
 .SH "Action Flags"
 .TP
 .B `:'
 apply the rule once only (default is recursive)
 .TP
 .B `@'
-stop applying rules in case of match.
+stop applying rules in case of match; the current rule is still applied 
+recursively; combine with `:' to apply the current rule only once 
+and then stop.
 .TP
 .B `#'
 stop current operation if the rule matches, and issue an `unwilling to
 perform' error.
 .TP
 .B `G{n}'
-jump n rules back and forth (watch for loops!).
+jump
+.B n
+rules back and forth (watch for loops!).
 Note that `G{1}' is implicit in every rule.
 .TP
 .B `I'
 ignores errors in rule; this means, in case of error, e.g. issued by a
 map, the error is treated as a missed match.
 The `unwilling to perform' is not overridden.
-.LP
-The ordering of the flags is significant.
+.TP
+.B `U{n}'
+uses
+.B
+n
+as return code if the rule matches; the flag does not alter the recursive
+behavior of the rule, so, to have it performed only once, it must be used 
+in combination with `:', e.g.
+.B `:U{16}'
+returns the value `16' after exactly one execution of the rule, if the
+pattern matches.
+As a consequence, its behavior is equivalent to `@', with the return
+code set to
+.BR n ;
+or, in other words, `@' is equivalent to `U{0}'.
+By convention, the freely available codes are above 16 included;
+the others are reserved.
+.LP
+The ordering of the flags can be significant.
 For instance: `IG{2}' means ignore errors and jump two lines ahead
 both in case of match and in case of error, while `G{2}I' means ignore
-errors, but jump thwo lines ahead only in case of match.
+errors, but jump two lines ahead only in case of match.
 .LP
 More flags (mainly Action Flags) will be added as needed.
 .SH "Pattern matching:"
 See
 .BR regex (7).
-.SH "String Substitution:"
-The string substitution happens according to a substitution pattern.
-.TP
-.B -
-substring substitution is allowed with the syntax `\ed' where `d' is a
-digit ranging 0-9 (0 is the full match).
-I see that 0-9 digit expansion is a widely accepted practise; however
-there is no technical reason to use such a strict limit.
-A syntax of the form `\e{ddd}' should be fine if there is any need to
-use a higher number of possible submatches.
-.TP
-.B -
-variable substitution will be allowed (at least when I figure out
-which kind of variable could be proficiently substituted)
-.TP
-.B -
-map lookup will be allowed (map lookup of substring matches in gdbm,
-ldap(!), math(?) and so on maps `a la sendmail'.
-.TP
-.B -
-subroutine invocation will make it possible to rewrite a submatch in
-terms of the output of another rewriteContext.
 .SH "Substitution Pattern Syntax:"
-everything starting with `%' requires substitution;
+Everything starting with `%' requires substitution;
 .LP
 the only obvious exception is `%%', which is left as is;
 .LP
@@ -401,16 +429,18 @@ the basic substitution is `%d', where `d' is a digit;
 a `%' followed by a `{' invokes an advanced substitution.
 The pattern is:
 .LP
-.nf
-  `%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
-.fi
+.RS
+`%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
+.RE
 .LP
 where <name> must be a legal name for the map, i.e.
 .LP
+.RS
 .nf
-  <name> ::= [a-z][a-z0-9]* (case insensitive)
-  <op> ::= `>' `|' `&' `&&' `*' `**' `$'
+<name> ::= [a-z][a-z0-9]* (case insensitive)
+<op> ::= `>' `|' `&' `&&' `*' `**' `$'
 .fi
+.RE
 .LP
 and <substitution> must be a legal substitution
 pattern, with no limits on the nesting level.
@@ -482,26 +512,38 @@ server \-> client rewriting.
 .LP
 client -> server:
 .LP
+.RS
 .nf
-     (default)       if defined and no specific context 
+(default)            if defined and no specific context 
                      is available
-     bindDn          bind
-     searchBase      search
-     searchFilter    search
-     compareDn       compare
-     addDn           add
-     modifyDn        modify
-     modrDn          modrdn
-     newSuperiorDn   modrdn
-     deleteDn        delete
+bindDN               bind
+searchBase           search
+searchFilter         search
+searchFilterAttrDN   search
+compareDN            compare
+compareAttrDN        compare AVA
+addDN                add
+addAttrDN            add AVA
+modifyDN             modify
+modifyAttrDN         modify AVA
+modrDN               modrdn
+newSuperiorDN        modrdn
+deleteDN             delete
+exopPasswdDN         passwd exop DN if proxy
 .fi
+.RE
 .LP
 server -> client:
 .LP
+.RS
 .nf
-     searchResult    search (only if defined; no default)
-     matchedDn       all ops (only if defined; no default; NOT IMPL.)
+searchResult         search (only if defined; no default;
+                     acts on DN and DN-syntax attributes 
+                     of search results)
+searchAttrDN         search AVA
+matchedDN            all ops (only if applicable)
 .fi
+.RE
 .LP
 .SH "Basic configuration syntax"
 .TP
@@ -518,12 +560,12 @@ A context may aliase another one.
 In this case the alias context contains no rule, and any reference to
 it will result in accessing the aliased one.
 .TP
-.B rewriteRule "<regex pattern>" "<substitution pattern>" "[ <flags> ]"
-Determines how a tring can be rewritten if a pattern is matched.
+.B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
+Determines how a string can be rewritten if a pattern is matched.
 Examples are reported below.
 .SH "Additional configuration syntax:"
 .TP
-.B rewriteMap "<map name>" "<map type>" "[ <map attrs> ]"
+.B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
 Allows to define a map that transforms substring rewriting into
 something else.
 The map is referenced inside the substitution pattern of a rule.
@@ -532,108 +574,142 @@ The map is referenced inside the substitution pattern of a rule.
 Sets a value with global scope, that can be dereferenced by the
 command `%{$paramName}'.
 .TP
-.B rewriteMaxPasses <number of passes>
+.B rewriteMaxPasses <number of passes> [<number of passes per rule>]
 Sets the maximum number of total rewriting passes that can be
 performed in a single rewrite operation (to avoid loops).
+A safe default is set to 100; note that reaching this limit is still
+treated as a success; recursive invocation of rules is simply 
+interrupted.
+The count applies to the rewriting operation as a whole, not 
+to any single rule; an optional per-rule limit can be set.
+This limit is overridden by setting specific per-rule limits
+with the `M{n}' flag.
 .SH "Configuration examples:"
 .nf
-     # set to `off' to disable rewriting
-     rewriteEngine on
+# set to `off' to disable rewriting
+rewriteEngine on
 
-     # Everything defined here goes into the `default' context.
-     # This rule changes the naming context of anything sent
-     # to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
+# the rules the "suffixmassage" directive implies
+rewriteEngine on
+# all dataflow from client to server referring to DNs
+rewriteContext default
+rewriteRule "(.*)<virtualnamingcontext>$" "%1<realnamingcontext>" ":"
+# empty filter rule
+rewriteContext searchFilter
+# all dataflow from server to client
+rewriteContext searchResult
+rewriteRule "(.*)<realnamingcontext>$" "%1<virtualnamingcontext>" ":"
+rewriteContext searchAttrDN alias searchResult
+rewriteContext matchedDN alias searchResult
 
-     rewriteRule "(.*)dc=home,[ ]?dc=net"
-                 "%1dc=OpenLDAP, dc=org"  ":"
+# Everything defined here goes into the `default' context.
+# This rule changes the naming context of anything sent
+# to `dc=home,dc=net' to `dc=OpenLDAP, dc=org'
 
-     # since a pretty/normalized DN does not include spaces
-     # after rdn separators, e.g. `,', this rule suffices:
+rewriteRule "(.*)dc=home,[ ]?dc=net"
+            "%1dc=OpenLDAP, dc=org"  ":"
 
-     rewriteRule "(.*)dc=home,dc=net"
-                 "%1dc=OpenLDAP,dc=org"  ":"
+# since a pretty/normalized DN does not include spaces
+# after rdn separators, e.g. `,', this rule suffices:
 
-     # Start a new context (ends input of the previous one).
-     # This rule adds blanks between DN parts if not present.
-     rewriteContext  addBlanks
-     rewriteRule     "(.*),([^ ].*)" "%1, %2"
+rewriteRule "(.*)dc=home,dc=net"
+            "%1dc=OpenLDAP,dc=org"  ":"
 
-     # This one eats blanks
-     rewriteContext  eatBlanks
-     rewriteRule     "(.*),[ ](.*)" "%1,%2"
+# Start a new context (ends input of the previous one).
+# This rule adds blanks between DN parts if not present.
+rewriteContext  addBlanks
+rewriteRule     "(.*),([^ ].*)" "%1, %2"
 
-     # Here control goes back to the default rewrite
-     # context; rules are appended to the existing ones.
-     # anything that gets here is piped into rule `addBlanks'
-     rewriteContext  default
-     rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
+# This one eats blanks
+rewriteContext  eatBlanks
+rewriteRule     "(.*),[ ](.*)" "%1,%2"
 
-     # Anything with `uid=username' is looked up in
-     # /etc/passwd for gecos (I know it's nearly useless,
-     # but it is there just as a guideline to implementing
-     # custom maps).
-     # Note the `I' flag that leaves `uid=username' in place 
-     # if `username' does not have a valid account, and the
-     # `:' that forces the rule to be processed exactly once.
-     rewriteContext  uid2Gecos
-     rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
-                     "%1cn=%2{xpasswd},%3"      "I:"
+# Here control goes back to the default rewrite
+# context; rules are appended to the existing ones.
+# anything that gets here is piped into rule `addBlanks'
+rewriteContext  default
+rewriteRule     ".*" "%{>addBlanks(%0)}" ":"
 
-     # Finally, in a bind, if one uses a `uid=username' DN,
-     # it is rewritten in `cn=name surname' if possible.
-     rewriteContext  bindDn
-     rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
+.\" # Anything with `uid=username' is looked up in
+.\" # /etc/passwd for gecos (I know it's nearly useless,
+.\" # but it is there just as a guideline to implementing
+.\" # custom maps).
+.\" # Note the `I' flag that leaves `uid=username' in place 
+.\" # if `username' does not have a valid account, and the
+.\" # `:' that forces the rule to be processed exactly once.
+.\" rewriteContext  uid2Gecos
+.\" rewriteRule     "(.*)uid=([a-z0-9]+),(.+)"
+.\"                 "%1cn=%2{xpasswd},%3"      "I:"
+.\" 
+.\" # Finally, in a bind, if one uses a `uid=username' DN,
+.\" # it is rewritten in `cn=name surname' if possible.
+.\" rewriteContext  bindDN
+.\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
+.\" 
+# Rewrite the search base according to `default' rules.
+rewriteContext  searchBase alias default
 
-     # Rewrite the search base  according to `default' rules.
-     rewriteContext  searchBase alias default
+# Search results with OpenLDAP DN are rewritten back with
+# `dc=home,dc=net' naming context, with spaces eaten.
+rewriteContext  searchResult
+rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
+                "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
 
-     # Search results with OpenLDAP DN are rewritten back with
-     # `dc=home,dc=net' naming context, with spaces eaten.
-     rewriteContext  searchResult
-     rewriteRule     "(.*[^ ]?)[ ]?dc=OpenLDAP,[ ]?dc=org"
-                     "%{>eatBlanks(%1)}dc=home,dc=net"    ":"
+# Bind with email instead of full DN: we first need
+# an ldap map that turns attributes into a DN (the
+# argument used when invoking the map is appended to 
+# the URI and acts as the filter portion)
+rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
 
-     # Bind with email instead of full DN: we first need
-     # an ldap map that turns attributes into a DN (the
-     # filter is appended by the ldap map substitution):
-     rewriteMap ldap attr2dn "ldap://host/dc=my,dc=org?dn?sub"
+# Then we need to detect DN made up of a single email,
+# e.g. `mail=someone@example.com'; note that the rule
+# in case of match stops rewriting; in case of error,
+# it is ignored.  In case we are mapping virtual
+# to real naming contexts, we also need to rewrite
+# regular DNs, because the definition of a bindDn
+# rewrite context overrides the default definition.
+rewriteContext bindDN
+rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
 
-     # Then we need to detect emails; note that the rule
-     # in case of match stops rewriting; in case of error,
-     # it is ignored.  In case we are mapping virtual
-     # to real naming contexts, we also need to rewrite
-     # regular DNs, because the definition of a bindDn
-     # rewrite context overrides the default definition.
-     rewriteContext bindDn
-     rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" "@I"
+# This is a rather sophisticated example. It massages a
+# search filter in case who performs the search has
+# administrative privileges.  First we need to keep
+# track of the bind DN of the incoming request, which is
+# stored in a variable called `binddn' with session scope,
+# and left in place to allow regular binding:
+rewriteContext  bindDN
+rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
 
-     # This is a rather sophisticated example. It massages a
-     # search filter in case who performs the search has
-     # administrative privileges.  First we need to keep
-     # track of the bind DN of the incoming request:
-     rewriteContext  bindDn
-     rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
+# A search filter containing `uid=' is rewritten only
+# if an appropriate DN is bound.
+# To do this, in the first rule the bound DN is
+# dereferenced, while the filter is decomposed in a
+# prefix, in the value of the `uid=<arg>' AVA, and 
+# in a suffix. A tag `<>' is appended to the DN. 
+# If the DN refers to an entry in the `ou=admin' subtree, 
+# the filter is rewritten OR-ing the `uid=<arg>' with
+# `cn=<arg>'; otherwise it is left as is. This could be
+# useful, for instance, to allow apache's auth_ldap-1.4
+# module to authenticate users with both `uid' and
+# `cn', but only if the request comes from a possible
+# `cn=Web auth,ou=admin,dc=home,dc=net' user.
+rewriteContext searchFilter
+rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
+  "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
+  ":I"
+rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
+  "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
+rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
 
-     # A search filter containing `uid=' is rewritten only
-     # if an appropriate DN is bound.
-     # To do this, in the first rule the bound DN is
-     # dereferenced, while the filter is decomposed in a
-     # prefix, the argument of the `uid=', and in a
-     # suffix. A tag `<>' is appended to the DN. If the DN
-     # refers to an entry in the `ou=admin' subtree, the
-     # filter is rewritten OR-ing the `uid=<arg>' with
-     # `cn=<arg>'; otherwise it is left as is. This could be
-     # useful, for instance, to allow apache's auth_ldap-1.4
-     # module to authenticate users with both `uid' and
-     # `cn', but only if the request comes from a possible
-     # `dn: cn=Web auth, ou=admin, dc=home, dc=net' user.
-     rewriteContext searchFilter
-     rewriteRule "(.*\e\e()uid=([a-z0-9_]+)(\e\e).*)"
-       "%{**binddn}<>%{&prefix(%1)}%{&arg(%2)}%{&suffix(%3)}"
-       ":I"
-     rewriteRule "[^,]+,ou=admin,dc=home,dc=net"
-       "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" "@I"
-     rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
+# This example shows how to strip unwanted DN-valued
+# attribute values from a search result; the first rule
+# matches DN values below "ou=People,dc=example,dc=com";
+# in case of match the rewriting exits successfully.
+# The second rule matches everything else and causes
+# the value to be rejected.
+rewriteContext searchResult
+rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
+rewriteRule ".*" "" "#"
 .fi
 .SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
 In case the rewritten DN is an LDAP URI, the operation is initiated
@@ -643,23 +719,105 @@ E.g.:
 .LP
 .nf
   rewriteRule '^cn=root,.*' '%0'                     'G{3}'
-  rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' '@'
-  rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' '@'
-  rewriteRule '.*'          'ldap://ldap3.my.org/%0' '@'
+  rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
+  rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
+  rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
 .fi
 .LP
 (Rule 1 is simply there to illustrate the `G{n}' action; it could have
 been written:
 .LP
 .nf
-  rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' '@'
+  rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
 .fi
 .LP
 with the advantage of saving one rewrite pass ...)
+.SH PROXY CACHE OVERLAY
+The proxy cache overlay 
+allows caching of LDAP search requests (queries) in a local database.
+For an incoming query, the
+proxy cache determines its corresponding \fBtemplate\fP. If the template was
+specified as cacheable using the \fBproxytemplate\fP directive and the request is
+contained in a cached request, it is answered from the proxy cache. Otherwise,
+the search is performed as usual and cacheable search results are saved in the
+cache for use in future queries.
+.LP
+
+A template is defined by a filter string and an index identifying a set of
+attributes. The \fBtemplate string\fP for a query can be obtained by
+removing assertion values from the RFC 2254 representation of its search
+filter. A query belongs to a template if its template string and set of
+projected attributes correspond to a cacheable template. Examples of template strings are (mail=), (|(sn=)(cn=)), (&(sn=)(givenName=)).    
+
+.LP 
+The following cache specific directives can be used to configure the proxy
+cache: 
+.TP
+.B overlay proxycache
+This directive adds the proxycache overlay to the current backend. The
+proxycache overlay may be used with any backend but is intended for use
+with the
+.B ldap
+and
+.B meta
+backends.
+.TP
+.B proxycache <database> <max_entries> <numattrsets> <entry_limit> <cc_period> 
+The directive enables proxy caching in the current backend and sets general
+cache parameters. A <database> backend will be used internally to maintain
+the cached entries. The chosen database will need to be configured as well,
+as shown below. Cache replacement is invoked when the cache size grows to 
+<max_entries> entries and continues till the cache size drops below this size.
+<numattrsets> should be equal to the number of following \fBproxyattrset\fP
+directives. Queries are cached only if they correspond to a cacheable template
+(specified by the \fBproxytemplate\fP directive) and the number of entries
+returned is less than <entry_limit>. Consistency check is performed every
+<cc_period> duration (specified in secs). In each cycle queries with expired
+"time to live(\fBTTL\fP)" are removed. A sample cache configuration is: 
+.LP
+.RS
+proxycache \fBbdb 10000 1 50 100\fP
+.RE
+.TP
+.B proxyattrset <index> <attrs...>
+Used to associate a set of attributes <attrs..> with an <index>. Each attribute
+set is associated with an integer from 0 to <numattrsets>-1. These indices are
+used by the \fBproxytemplate\fP directive to define cacheable templates. 
+
+.TP
+.B proxytemplate <template_string> <attrset_index> <ttl> 
+Specifies a cacheable template and "time to live" (in sec) <ttl> of queries 
+belonging to the template. 
+
+.LP
+The following adds a template with filter string (&sn=)(givenName=)) and attributes mail, postaladdress, telephonenumber and a TTL of 1 hour. 
+.LP
+.RS
+.nf
+proxyattrset \fB0 mail postaladdress telephonenumber\fP
+proxytemplate \fB(&(sn=)(givenName=)) 0 3600\fP
+.fi
+.RE
+.LP
+Directives for configuring the underlying database must also be given, as
+shown here:
+.LP
+.RS
+.nf
+directory /var/tmp/cache
+cachesize 100
+.fi
+.RE
+.LP
+Any valid directives for the chosen database type may be used.
 .SH FILES
+.TP
 ETCDIR/slapd.conf
+default slapd configuration file
 .SH SEE ALSO
 .BR slapd.conf (5),
 .BR slapd\-ldap (5),
 .BR slapd (8),
 .BR regex (7).
+.SH AUTHOR
+Pierangelo Masarati, based on back-ldap by Howard Chu