slapd-meta.5 32.8 KB
Newer Older
1
.TH SLAPD-META 5 "RELEASEDATE" "OpenLDAP LDVERSION"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
.\" Copyright 1998-2006 The OpenLDAP Foundation, All Rights Reserved.
3
4
5
6
7
8
9
10
.\" Copying restrictions apply.  See the COPYRIGHT file.
.\" Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
.\" $OpenLDAP$
.\"
.\" Portions of this document should probably be moved to slapd-ldap(5)
.\" and maybe manual pages for librewrite.
.\"
.SH NAME
11
slapd-meta \- metadirectory backend
12
13
14
15
16
17
18
19
20
21
22
23
24
.SH SYNOPSIS
ETCDIR/slapd.conf
.SH DESCRIPTION
The
.B meta
backend to
.BR slapd (8)
performs basic LDAP proxying with respect to a set of remote LDAP
servers, called "targets".
The information contained in these servers can be presented as
belonging to a single Directory Information Tree (DIT).
.LP
A basic knowledge of the functionality of the
Pierangelo Masarati's avatar
Pierangelo Masarati committed
25
.BR slapd\-ldap (5)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
backend is recommended.
This backend has been designed as an enhancement of the ldap backend.
The two backends share many features (actually they also share
portions of code).
While the
.B ldap
backend is intended to proxy operations directed to a single server, the
.B meta
backend is mainly intended for proxying of multiple servers and possibly
naming context masquerading.
These features, although useful in many scenarios, may result in
excessive overhead for some applications, so its use should be
carefully considered.
In the examples section, some typical scenarios will be discussed.
40
41
42
43
44
45
46

.LP
Note: When looping back to the same instance of \fBslapd\fP(8), 
each connection requires a new thread; as a consequence, \fBslapd\fP(8)
must be compiled with thread support, and the \fBthreads\fP parameter 
may need some tuning; in those cases, unless the multiple target feature
is required, one may consider using \fBslapd-relay\fP(5) instead, 
Kurt Zeilenga's avatar
Kurt Zeilenga committed
47
which performs the relayed operation internally and thus reuses 
48
49
the same connection.

50
.SH EXAMPLES
Pierangelo Masarati's avatar
Pierangelo Masarati committed
51
There are examples in various places in this document, as well as in the
52
53
slapd/back-meta/data/ directory in the OpenLDAP source tree.
.SH CONFIGURATION
Pierangelo Masarati's avatar
Pierangelo Masarati committed
54
55
56
These
.B slapd.conf
options apply to the META backend database.
57
58
That is, they must follow a "database meta" line and come before any
subsequent "backend" or "database" lines.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
59
60
61
Other database options are described in the
.BR slapd.conf (5)
manual page.
62
.LP
63
64
Note: In early versions of back-ldap and back-meta it was recommended to always set
.LP
65
.RS
66
.nf
67
lastmod  off
68
.fi
69
.RE
70
.LP
71
72
73
74
for every
.B ldap
and
.B meta
75
76
77
78
79
80
81
82
database.
This is because operational attributes related to entry creation and
modification should not be proxied, as they could be mistakenly written
to the target server(s), generating an error.
The current implementation automatically sets lastmod to off, so its use
is redundant and should be omitted, because the lastmod directive will
be deprecated in the future.

Pierangelo Masarati's avatar
Pierangelo Masarati committed
83
.SH SPECIAL CONFIGURATION DIRECTIVES
84
85
86
87
88
Target configuration starts with the "uri" directive.
All the configuration directives that are not specific to targets
should be defined first for clarity, including those that are common
to all backends.
They are:
Pierangelo Masarati's avatar
Pierangelo Masarati committed
89

90
91
92
93
94
95
96
97
.TP
.B default-target none
This directive forces the backend to reject all those operations
that must resolve to a single target in case none or multiple
targets are selected.
They include: add, delete, modify, modrdn; compare is not included, as
well as bind since, as they don't alter entries, in case of multiple
matches an attempt is made to perform the operation on any candidate
Pierangelo Masarati's avatar
Pierangelo Masarati committed
98
target, with the constraint that at most one must succeed.
99
100
This directive can also be used when processing targets to mark a
specific target as default.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
101

102
.TP
103
.B dncache-ttl {DISABLED|forever|<ttl>}
Pierangelo Masarati's avatar
Pierangelo Masarati committed
104
105
This directive sets the time-to-live of the DN cache.
This caches the target that holds a given DN to speed up target
106
selection in case multiple targets would result from an uncached
Pierangelo Masarati's avatar
Pierangelo Masarati committed
107
search; forever means cache never expires; disabled means no DN
108
109
110
111
caching; otherwise a valid ( > 0 ) ttl is required, in the format
illustrated for the 
.B idle-timeout
directive.
112

113
114
115
116
117
.TP
.B conn-ttl <time>
This directive causes a cached connection to be dropped an recreated
after a given ttl, regardless of being idle or not.

118
119
120
121
122
123
124
125
126
127
.TP
.B onerr {CONTINUE|stop}
This directive allows to select the behavior in case an error is returned
by one target during a search.
The default, \fBcontinue\fP, consists in continuing the operation, 
trying to return as much data as possible.
If this statement is set to \fBstop\fP, the search is terminated as soon 
as an error is returned by one target, and the error is immediately 
propagated to the client.

128
129
130
131
132
133
134
135
136
137
138
.TP
.B protocol\-version {0,2,3}
This directive indicates what protocol version must be used to contact
the remote server.
If set to 0 (the default), the proxy uses the same protocol version 
used by the client, otherwise the requested protocol is used.
The proxy returns \fIunwillingToPerform\fP if an operation that is 
incompatible with the requested protocol is attempted.
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

139
140
141
142
143
144
145
.TP
.B pseudoroot-bind-defer {NO|yes}
This directive, when set to 
.BR yes ,
causes the authentication to the remote servers with the pseudo-root
identity to be deferred until actually needed by subsequent operations.

146
147
148
149
150
.TP
.B rebind-as-user {NO|yes}
If this option is given, the client's bind credentials are remembered
for rebinds when chasing referrals.

151
152
153
154
.TP
.B single\-conn {NO|yes}
Discards current cached connection when the client rebinds.

Pierangelo Masarati's avatar
Pierangelo Masarati committed
155
.SH TARGET SPECIFICATION
156
Target specification starts with a "uri" directive:
Pierangelo Masarati's avatar
Pierangelo Masarati committed
157

158
159
160
.TP
.B uri <protocol>://[<host>[:<port>]]/<naming context>
The "server" directive that was allowed in the LDAP backend (although
161
deprecated) has been completely discarded in the Meta backend.
Hallvard Furuseth's avatar
Hallvard Furuseth committed
162
163
164
The <protocol> part can be anything
.BR ldap_initialize (3)
accepts ({ldap|ldaps|ldapi} and variants); <host> and <port> may be
165
166
omitted, defaulting to whatever is set in
.BR ldap.conf (5).
167
168
169
170
The <naming context> part is mandatory.
It must end with one of the naming contexts defined for the backend,
e.g.:
.LP
171
.RS
172
.nf
173
174
suffix "\fBdc=foo,dc=com\fP"
uri    "ldap://x.foo.com/dc=x,\fBdc=foo,dc=com\fP"
175
.fi
176

177
.RE
178
.RS
179
180
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.
181
Multiple URIs may be defined in a single argument.  The URIs must
182
183
184
be separated by TABs (e.g. '\\t'; commas or spaces, unlike back-ldap,
will not work,
because they are legal in the <naming context>, and we don't want to use
Hallvard Furuseth's avatar
Hallvard Furuseth committed
185
URL-encoded <naming context>s), and the additional URIs must have
186
187
no <naming context> part.  This causes the underlying library
to contact the first server of the list that responds.
188
189
190
191
192
193
194
195
196
197
198
199
For example, if \fIl1.foo.com\fP and \fIl2.foo.com\fP are shadows
of the same server, the directive
.LP
.nf
suffix "\fBdc=foo,dc=com\fP"
uri    "ldap://l1.foo.com/\fBdc=foo,dc=com\fP	ldap://l2.foo.com/"
.fi

.RE
.RS
causes \fIl2.foo.com\fP to be contacted whenever \fIl1.foo.com\fP
does not respond.
200
.RE
Pierangelo Masarati's avatar
Pierangelo Masarati committed
201

202
.TP
203
204
205
206
.B acl-authcDN "<administrative DN for access control purposes>"
DN which is used to query the target server for acl checking,
as in the LDAP backend; it is supposed to have read access 
on the target server to attributes used on the proxy for acl checking.
207
208
There is no risk of giving away such values; they are only used to
check permissions.
209
210
.B The acl-authcDN identity is by no means implicitly used by the proxy 
.B when the client connects anonymously.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
211

212
.TP
213
214
215
216
217
.B acl-passwd <password>
Password used with the
.B 
acl-authcDN
above.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
.TP
.B bind-timeout <microseconds>
This directive defines the timeout, in microseconds, used when polling
for response after an asynchronous bind connection.  The initial call
to ldap_result(3) is performed with a trade-off timeout of 100000 us;
if that results in a timeout exceeded, subsequent calls use the value
provided with
.BR bind-timeout .
The default value is used also for subsequent calls if
.B bind-timeout
is not specified.
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

Pierangelo Masarati's avatar
Pierangelo Masarati committed
233
234
235
236
237
.TP
.B chase-referrals {YES|no}
enable/disable automatic referral chasing, which is delegated to the
underlying libldap, with rebinding eventually performed if the
\fBrebind-as-user\fP directive is used.  The default is to chase referrals.
238
239
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
240
241

.TP
242
243
244
245
246
247
.B default-target [<target>]
The "default-target" directive can also be used during target specification.
With no arguments it marks the current target as the default.
The optional number marks target <target> as the default one, starting
from 1.
Target <target> must be defined.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
248
249

.TP
250
251
252
253
254
255
256
257
258
.B idle-timeout <time>
This directive causes a cached connection to be dropped an recreated
after it has been idle for the specified time.
The value can be specified as

[<d>d][<h>h][<m>m][<s>[s]]

where <d>, <h>, <m> and <s> are respectively treated as days, hours, 
minutes and seconds.
259
260
261
262
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

.TP
263
264
265
266
.B map "{attribute|objectclass} [<local name>|*] {<foreign name>|*}"
This maps object classes and attributes as in the LDAP backend.
See
.BR slapd-ldap (5).
Pierangelo Masarati's avatar
Pierangelo Masarati committed
267

268
.TP
269
270
271
272
273
274
275
276
.B nretries {forever|never|<nretries>}
This directive defines how many times a bind should be retried
in case of temporary failure in contacting a target.  If defined
before any target specification, it applies to all targets (by default,
.BR 3
times);
the global value can be overridden by redefinitions inside each target
specification.
277

278
.TP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
279
280
281
.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.
282
The true "rootdn" of the target server ought not be used; an arbitrary
Pierangelo Masarati's avatar
Pierangelo Masarati committed
283
administrative DN should used instead.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
284

285
.TP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
286
.B pseudorootpw "<substitute password in case of rootdn bind>"
287
288
This directive sets the credential that will be used in case a bind
with the backend's "rootdn" succeeds, and the bind is propagated to
Pierangelo Masarati's avatar
Pierangelo Masarati committed
289
the target using the "pseudorootdn" DN.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
290

Pierangelo Masarati's avatar
Pierangelo Masarati committed
291
292
Note: cleartext credentials must be supplied here; as a consequence,
using the pseudorootdn/pseudorootpw directives is inherently unsafe.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
293

294
295
296
.TP
.B rewrite* ...
The rewrite options are described in the "REWRITING" section.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
297

298
299
300
301
302
303
304
305
306
.TP
.B subtree-exclude "<DN>"
This directive instructs back-meta to ignore the current target
for operations whose requestDN is subordinate to
.BR DN .
There may be multiple occurrences of the
.B subtree-exclude
directive for each of the targets.

307
.TP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
308
.B suffixmassage "<virtual naming context>" "<real naming context>"
309
310
311
312
313
314
315
316
All the directives starting with "rewrite" refer to the rewrite engine
that has been added to slapd.
The "suffixmassage" directive was introduced in the LDAP backend to
allow suffix massaging while proxying.
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
317
318
massaging.  See the "REWRITING" section for a detailed list 
of the rewrite rules it implies.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
319

320
.TP
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
.B t-f-support {NO|yes|discover}
enable if the remote server supports absolute filters
(see \fIdraft-zeilenga-ldap-t-f\fP for details).
If set to
.BR discover ,
support is detected by reading the remote server's root DSE.
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

.TP
.B timeout [{add|delete|modify|modrdn}=]<seconds> [...]
This directive allows to set per-database, per-target and per-operation
timeouts.
If no operation is specified, it affects all.
Currently, only write operations are addressed, because searches
can already be limited by means of the
.B limits
directive (see 
.BR slapd.conf (5)
for details), and other operations are not supposed to incur into the
need for timeouts.
Note: if the timelimit is exceeded, the operation is abandoned;
the protocol does not provide any means to rollback the operation,
so the client will not know if the operation eventually succeeded or not.
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

.TP
.B tls {[try-]start|[try-]propagate}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
350
execute the StartTLS extended operation when the connection is initialized;
351
only works if the URI directive protocol scheme is not \fBldaps://\fP.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
352
\fBpropagate\fP issues the StartTLS operation only if the original
353
354
connection did.
The \fBtry-\fP prefix instructs the proxy to continue operations
Kurt Zeilenga's avatar
Kurt Zeilenga committed
355
if the StartTLS operation failed; its use is highly deprecated.
356
357
358
If set before any target specification, it affects all targets, unless
overridden by any per-target directive.

Pierangelo Masarati's avatar
Pierangelo Masarati committed
359
.SH SCENARIOS
360
361
362
363
364
365
366
367
368
369
370
A powerful (and in some sense dangerous) rewrite engine has been added
to both the LDAP and Meta backends.
While the former can gain limited beneficial effects from rewriting
stuff, the latter can become an amazingly powerful tool.
.LP
Consider a couple of scenarios first.
.LP
1) Two directory servers share two levels of naming context;
say "dc=a,dc=foo,dc=com" and "dc=b,dc=foo,dc=com".
Then, an unambiguous Meta database can be configured as:
.LP
371
.RS
372
.nf
373
374
375
376
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"
377
.fi
378
.RE
379
380
381
382
383
384
385
386
.LP
Operations directed to a specific target can be easily resolved
because there are no ambiguities.
The only operation that may resolve to multiple targets is a search
with base "dc=foo,dc=com" and scope at least "one", which results in
spawning two searches to the targets.
.LP
2a) Two directory servers don't share any portion of naming context,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
387
but they'd present as a single DIT
388
389
[Caveat: uniqueness of (massaged) entries among the two servers is
assumed; integrity checks risk to incur in excessive overhead and have
Pierangelo Masarati's avatar
Pierangelo Masarati committed
390
391
not been implemented].
Say we have "dc=bar,dc=org" and "o=Foo,c=US",
392
393
394
395
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
396
.RS
397
.nf
398
399
400
401
402
403
404
405
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"
406
.fi
407
.RE
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
.LP
Again, operations can be resolved without ambiguity, although
some rewriting is required.
Notice that the virtual naming context of each target is a branch of
the database's naming context; it is rewritten back and forth when
operations are performed towards the target servers.
What "back and forth" means will be clarified later.
.LP
When a search with base "dc=foo,dc=com" is attempted, if the 
scope is "base" it fails with "no such object"; in fact, the
common root of the two targets (prior to massaging) does not
exist.
If the scope is "one", both targets are contacted with the base
replaced by each target's base; the scope is derated to "base".
In general, a scope "one" search is honored, and the scope is derated,
only when the incoming base is at most one level lower of a target's
naming context (prior to massaging).
.LP
Finally, if the scope is "sub" the incoming base is replaced
by each target's unmassaged naming context, and the scope
is not altered.
.LP
2b) Consider the above reported scenario with the two servers
sharing the same naming context:
.LP
433
.RS
434
.nf
435
436
437
438
439
440
441
442
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"
443
.fi
444
.RE
445
446
447
448
.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
Pierangelo Masarati's avatar
Pierangelo Masarati committed
449
selection will fail unless the DN is already cached or a default
450
target has been set.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
451
452
Practical configurations may result as a combination of all the
above scenarios.
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
.SH ACLs
Note on ACLs: at present you may add whatever ACL rule you desire
to to the Meta (and LDAP) backends.
However, the meaning of an ACL on a proxy may require some
considerations.
Two philosophies may be considered:
.LP
a) the remote server dictates the permissions; the proxy simply passes
back what it gets from the remote server.
.LP
b) the remote server unveils "everything"; the proxy is responsible
for protecting data from unauthorized access.
.LP
Of course the latter sounds unreasonable, but it is not.
It is possible to imagine scenarios in which a remote host discloses
data that can be considered "public" inside an intranet, and a proxy
that connects it to the internet may impose additional constraints.
To this purpose, the proxy should be able to comply with all the ACL
matching criteria that the server supports.
This has been achieved with regard to all the criteria supported by
slapd except a special subtle case (please drop me a note if you can
find other exceptions: <ando@openldap.org>).
The rule
.LP
477
.RS
478
.nf
479
480
481
access to dn="<dn>" attr=<attr>
       by dnattr=<dnattr> read
       by * none
482
.fi
483
.RE
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
.LP
cannot be matched iff the attribute that is being requested, <attr>,
is NOT <dnattr>, and the attribute that determines membership,
<dnattr>, has not been requested (e.g. in a search)
.LP
In fact this ACL is resolved by slapd using the portion of entry it
retrieved from the remote server without requiring any further
intervention of the backend, so, if the <dnattr> attribute has not
been fetched, the match cannot be assessed because the attribute is
not present, not because no value matches the requirement!
.LP
Note on ACLs and attribute mapping: ACLs are applied to the mapped
attributes; for instance, if the attribute locally known as "foo" is
mapped to "bar" on a remote server, then local ACLs apply to attribute
"foo" and are totally unaware of its remote name.
The remote server will check permissions for "bar", and the local
server will possibly enforce additional restrictions to "foo".
.\"
.\" If this section is moved, also update the reference in
.\" libraries/librewrite/RATIONALE.
.\"
.SH REWRITING
A string is rewritten according to a set of rules, called a `rewrite
context'.
508
509
The rules are based on POSIX (''extended'') regular expressions (regex)
with substring matching; basic variable substitution and map resolution 
510
of substrings is allowed by specific mechanisms detailed in the following.
511
512
513
514
515
516
The behavior of pattern matching/substitution can be altered by a set
of flags.
.LP
The underlying concept is to build a lightweight rewrite module
for the slapd server (initially dedicated to the LDAP backend).
.SH Passes
Hallvard Furuseth's avatar
Hallvard Furuseth committed
517
An incoming string is matched against a set of rules.
518
519
Rules are made of a regex match pattern, a substitution pattern
and a set of actions, described by a set of flags.
520
521
522
523
524
525
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.
526
The flags are divided in "Pattern matching Flags" and "Action Flags";
Hallvard Furuseth's avatar
Hallvard Furuseth committed
527
the former alter the regex match pattern behavior while the latter
528
alter the action that is taken after substitution.
529
530
531
532
533
534
.SH "Pattern Matching Flags"
.TP
.B `C'
honors case in matching (default is case insensitive)
.TP
.B `R'
535
use POSIX ''basic'' regular expressions (default is ''extended'')
536
537
538
539
540
541
.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.
542
543
544
545
546
547
.SH "Action Flags"
.TP
.B `:'
apply the rule once only (default is recursive)
.TP
.B `@'
548
549
550
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.
551
552
553
554
555
556
.TP
.B `#'
stop current operation if the rule matches, and issue an `unwilling to
perform' error.
.TP
.B `G{n}'
557
558
559
jump
.B n
rules back and forth (watch for loops!).
560
561
562
563
564
565
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.
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
.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.
583
.LP
584
The ordering of the flags can be significant.
585
586
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
Pierangelo Masarati's avatar
typo    
Pierangelo Masarati committed
587
errors, but jump two lines ahead only in case of match.
588
589
590
591
.LP
More flags (mainly Action Flags) will be added as needed.
.SH "Pattern matching:"
See
592
593
594
.BR regex (7)
and/or
.BR re_format (7).
Pierangelo Masarati's avatar
Pierangelo Masarati committed
595
.SH "Substitution Pattern Syntax:"
596
Everything starting with `%' requires substitution;
597
.LP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
598
the only obvious exception is `%%', which is left as is;
599
.LP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
600
the basic substitution is `%d', where `d' is a digit;
601
0 means the whole string, while 1-9 is a submatch;
602
.LP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
603
a `%' followed by a `{' invokes an advanced substitution.
604
605
The pattern is:
.LP
606
607
608
.RS
`%' `{' [ <op> ] <name> `(' <substitution> `)' `}'
.RE
609
610
611
.LP
where <name> must be a legal name for the map, i.e.
.LP
612
.RS
613
.nf
614
615
<name> ::= [a-z][a-z0-9]* (case insensitive)
<op> ::= `>' `|' `&' `&&' `*' `**' `$'
616
.fi
617
.RE
618
.LP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
619
620
and <substitution> must be a legal substitution
pattern, with no limits on the nesting level.
621
622
623
624
625
626
627
628
629
630
631
632
633
.LP
The operators are:
.TP
.B >
sub context invocation; <name> must be a legal, already defined
rewrite context name
.TP
.B |
external command invocation; <name> must refer to a legal, already
defined command name (NOT IMPL.)
.TP
.B &
variable assignment; <name> defines a variable in the running
Pierangelo Masarati's avatar
Pierangelo Masarati committed
634
635
636
637
638
operation structure which can be dereferenced later; operator
.B &
assigns a variable in the rewrite context scope; operator
.B &&
assigns a variable that scopes the entire session, e.g. its value
Hallvard Furuseth's avatar
Hallvard Furuseth committed
639
can be dereferenced later by other rewrite contexts
640
641
642
.TP
.B *
variable dereferencing; <name> must refer to a variable that is
Pierangelo Masarati's avatar
Pierangelo Masarati committed
643
644
645
646
647
648
defined and assigned for the running operation; operator
.B *
dereferences a variable scoping the rewrite context; operator
.B **
dereferences a variable scoping the whole session, e.g. the value
is passed across rewrite contexts
649
650
651
652
.TP
.B $
parameter dereferencing; <name> must refer to an existing parameter;
the idea is to make some run-time parameters set by the system
Pierangelo Masarati's avatar
Pierangelo Masarati committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
available to the rewrite engine, as the client host name, the bind DN
if any, constant parameters initialized at config time, and so on;
no parameter is currently set by either 
.B back\-ldap
or
.BR back\-meta ,
but constant parameters can be defined in the configuration file
by using the
.B rewriteParam
directive.
.LP
Substitution escaping has been delegated to the `%' symbol, 
which is used instead of `\e' in string substitution patterns
because `\e' is already escaped by slapd's low level parsing routines;
667
668
as a consequence, regex escaping requires two `\e' symbols,
e.g. `\fB.*\e.foo\e.bar\fP' must be written as `\fB.*\e\e.foo\e\e.bar\fP'.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
669
670
671
672
.\"
.\" The symbol can be altered at will by redefining the related macro in
.\" "rewrite-int.h".
.\"
673
674
675
676
677
678
679
680
.SH "Rewrite context:"
A rewrite context is a set of rules which are applied in sequence.
The basic idea is to have an application initialize a rewrite
engine (think of Apache's mod_rewrite ...) with a set of rewrite
contexts; when string rewriting is required, one invokes the
appropriate rewrite context with the input string and obtains the
newly rewritten one if no errors occur.
.LP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
681
682
683
Each basic server operation is associated to a rewrite context;
they are divided in two main groups: client \-> server and
server \-> client rewriting.
684
685
686
.LP
client -> server:
.LP
687
.RS
688
.nf
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
(default)            if defined and no specific context 
                     is available
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
Kurt Zeilenga's avatar
Kurt Zeilenga committed
704
exopPasswdDN         password modify extended operation DN if proxy
705
.fi
706
.RE
707
708
709
.LP
server -> client:
.LP
710
.RS
711
.nf
712
713
714
715
716
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)
717
.fi
718
.RE
719
720
721
722
723
724
725
726
.LP
.SH "Basic configuration syntax"
.TP
.B rewriteEngine { on | off }
If `on', the requested rewriting is performed; if `off', no
rewriting takes place (an easy way to stop rewriting without
altering too much the configuration file).
.TP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
727
.B rewriteContext <context name> "[ alias <aliased context name> ]"
728
729
730
<Context name> is the name that identifies the context, i.e. the name
used by the application to refer to the set of rules it contains.
It is used also to reference sub contexts in string rewriting.
Hallvard Furuseth's avatar
Hallvard Furuseth committed
731
A context may alias another one.
732
733
734
In this case the alias context contains no rule, and any reference to
it will result in accessing the aliased one.
.TP
735
.B rewriteRule "<regex match pattern>" "<substitution pattern>" "[ <flags> ]"
736
Determines how a string can be rewritten if a pattern is matched.
737
738
739
Examples are reported below.
.SH "Additional configuration syntax:"
.TP
740
.B rewriteMap "<map type>" "<map name>" "[ <map attrs> ]"
741
742
743
744
745
746
Allows to define a map that transforms substring rewriting into
something else.
The map is referenced inside the substitution pattern of a rule.
.TP
.B rewriteParam <param name> <param value>
Sets a value with global scope, that can be dereferenced by the
Pierangelo Masarati's avatar
Pierangelo Masarati committed
747
command `%{$paramName}'.
748
.TP
749
.B rewriteMaxPasses <number of passes> [<number of passes per rule>]
Pierangelo Masarati's avatar
Pierangelo Masarati committed
750
751
Sets the maximum number of total rewriting passes that can be
performed in a single rewrite operation (to avoid loops).
752
753
754
755
756
757
758
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.
759
760
.SH "Configuration examples:"
.nf
761
762
# set to `off' to disable rewriting
rewriteEngine on
Pierangelo Masarati's avatar
Pierangelo Masarati committed
763

764
765
766
767
768
769
770
771
772
773
774
775
776
# 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

777
778
779
# 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'
Pierangelo Masarati's avatar
Pierangelo Masarati committed
780

781
782
rewriteRule "(.*)dc=home,[ ]?dc=net"
            "%1dc=OpenLDAP, dc=org"  ":"
783

784
785
# since a pretty/normalized DN does not include spaces
# after rdn separators, e.g. `,', this rule suffices:
786

787
788
rewriteRule "(.*)dc=home,dc=net"
            "%1dc=OpenLDAP,dc=org"  ":"
789

790
791
792
793
# 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"
794

795
796
797
# This one eats blanks
rewriteContext  eatBlanks
rewriteRule     "(.*),[ ](.*)" "%1,%2"
798

799
800
801
802
803
# 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)}" ":"
804

805
806
807
808
809
810
811
812
813
814
815
816
817
.\" # 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.
818
.\" rewriteContext  bindDN
819
820
.\" rewriteRule     ".*" "%{>addBlanks(%{>uid2Gecos(%0)})}" ":"
.\" 
821
# Rewrite the search base according to `default' rules.
822
rewriteContext  searchBase alias default
823

824
825
826
827
828
# 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"    ":"
829

830
831
832
833
834
# 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"
835

836
837
838
839
840
841
842
# 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.
843
rewriteContext bindDN
844
rewriteRule "^mail=[^,]+@[^,]+$" "%{attr2dn(%0)}" ":@I"
845

846
847
848
849
850
851
# 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:
852
rewriteContext  bindDN
853
rewriteRule     ".+" "%{&&binddn(%0)}%0" ":"
854

855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
# 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"
873
  "%{*prefix}|(uid=%{*arg})(cn=%{*arg})%{*suffix}" ":@I"
874
rewriteRule ".*<>" "%{*prefix}uid=%{*arg}%{*suffix}" ":"
Pierangelo Masarati's avatar
Pierangelo Masarati committed
875
876
877
878
879
880
881
882

# 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
883
rewriteRule ".*,ou=People,dc=example,dc=com" "%0" ":@"
Pierangelo Masarati's avatar
Pierangelo Masarati committed
884
rewriteRule ".*" "" "#"
885
.fi
Pierangelo Masarati's avatar
Pierangelo Masarati committed
886
887
888
.SH "LDAP Proxy resolution (a possible evolution of slapd\-ldap(5)):"
In case the rewritten DN is an LDAP URI, the operation is initiated
towards the host[:port] indicated in the uri, if it does not refer
889
890
891
892
to the local server.
E.g.:
.LP
.nf
Pierangelo Masarati's avatar
Pierangelo Masarati committed
893
  rewriteRule '^cn=root,.*' '%0'                     'G{3}'
894
895
896
  rewriteRule '^cn=[a-l].*' 'ldap://ldap1.my.org/%0' ':@'
  rewriteRule '^cn=[m-z].*' 'ldap://ldap2.my.org/%0' ':@'
  rewriteRule '.*'          'ldap://ldap3.my.org/%0' ':@'
897
898
899
900
901
902
.fi
.LP
(Rule 1 is simply there to illustrate the `G{n}' action; it could have
been written:
.LP
.nf
903
  rewriteRule '^cn=root,.*' 'ldap://ldap3.my.org/%0' ':@'
904
905
906
.fi
.LP
with the advantage of saving one rewrite pass ...)
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922

.SH ACCESS CONTROL
The
.B meta
backend does not honor all ACL semantics as described in
.BR slapd.access (5).
In general, access checking is delegated to the remote server(s).
Only
.B read (=r)
access to the
.B entry
pseudo-attribute and to the other attribute values of the entries
returned by the
.B search
operation is honored, which is performed by the frontend.

923
924
925
.SH PROXY CACHE OVERLAY
The proxy cache overlay 
allows caching of LDAP search requests (queries) in a local database.
926
927
928
See 
.BR slapo-pcache (5)
for details.
Pierangelo Masarati's avatar
Pierangelo Masarati committed
929
.SH FILES
930
.TP
Pierangelo Masarati's avatar
Pierangelo Masarati committed
931
ETCDIR/slapd.conf
932
default slapd configuration file
Pierangelo Masarati's avatar
Pierangelo Masarati committed
933
.SH SEE ALSO
934
.BR slapd.conf (5),
Pierangelo Masarati's avatar
Pierangelo Masarati committed
935
.BR slapd\-ldap (5),
936
.BR slapo\-pcache (5),
937
.BR slapd (8),
938
939
.BR regex (7),
.BR re_format (7).
Howard Chu's avatar
Howard Chu committed
940
941
.SH AUTHOR
Pierangelo Masarati, based on back-ldap by Howard Chu