]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/config.c
1c0b5f672726950468b5cea5a1f4f22b92668a94
[openldap] / servers / slapd / back-meta / config.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2007 The OpenLDAP Foundation.
5  * Portions Copyright 2001-2003 Pierangelo Masarati.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by the Howard Chu for inclusion
19  * in OpenLDAP Software and subsequently enhanced by Pierangelo
20  * Masarati.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26
27 #include <ac/string.h>
28 #include <ac/socket.h>
29
30 #include "slap.h"
31 #include "lutil.h"
32 #include "../back-ldap/back-ldap.h"
33 #undef ldap_debug       /* silence a warning in ldap-int.h */
34 #include "../../../libraries/libldap/ldap-int.h"
35 #include "back-meta.h"
36
37 static int
38 meta_back_new_target( 
39         metatarget_t    **mtp )
40 {
41         char                    *rargv[ 3 ];
42         metatarget_t            *mt;
43
44         *mtp = NULL;
45
46         mt = ch_calloc( sizeof( metatarget_t ), 1 );
47
48         mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
49         if ( mt->mt_rwmap.rwm_rw == NULL ) {
50                 ch_free( mt );
51                 return -1;
52         }
53
54         /*
55          * the filter rewrite as a string must be disabled
56          * by default; it can be re-enabled by adding rules;
57          * this creates an empty rewriteContext
58          */
59         rargv[ 0 ] = "rewriteContext";
60         rargv[ 1 ] = "searchFilter";
61         rargv[ 2 ] = NULL;
62         rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
63
64         rargv[ 0 ] = "rewriteContext";
65         rargv[ 1 ] = "default";
66         rargv[ 2 ] = NULL;
67         rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
68
69         ldap_pvt_thread_mutex_init( &mt->mt_uri_mutex );
70
71         mt->mt_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
72         mt->mt_idassert_authmethod = LDAP_AUTH_NONE;
73         mt->mt_idassert_tls = SB_TLS_DEFAULT;
74
75         /* by default, use proxyAuthz control on each operation */
76         mt->mt_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
77
78         *mtp = mt;
79
80         return 0;
81 }
82
83 static int
84 check_true_false( char *str )
85 {
86         if ( strcasecmp( str, "true" ) == 0 || strcasecmp( str, "yes" ) == 0 ) {
87                 return 1;
88         }
89
90         if ( strcasecmp( str, "false" ) == 0 || strcasecmp( str, "no" ) == 0 ) {
91                 return 0;
92         }
93
94         return -1;
95 }
96
97
98 int
99 meta_back_db_config(
100                 BackendDB       *be,
101                 const char      *fname,
102                 int             lineno,
103                 int             argc,
104                 char            **argv
105 )
106 {
107         metainfo_t      *mi = ( metainfo_t * )be->be_private;
108
109         assert( mi != NULL );
110
111         /* URI of server to query */
112         if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
113                 int             i = mi->mi_ntargets;
114                 LDAPURLDesc     *ludp, *tmpludp;
115                 struct berval   dn;
116                 int             rc;
117                 int             c;
118                 BackendDB       *tmp_bd;
119
120                 metatarget_t    *mt;
121                 
122                 switch ( argc ) {
123                 case 1:
124                         Debug( LDAP_DEBUG_ANY,
125         "%s: line %d: missing URI "
126         "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
127                                 fname, lineno, 0 );
128                         return 1;
129
130                 case 2:
131                         break;
132
133                 default:
134                         Debug( LDAP_DEBUG_ANY,
135         "%s: line %d: too many args "
136         "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
137                                 fname, lineno, 0 );
138                         return 1;
139                 }
140
141                 if ( be->be_nsuffix == NULL ) {
142                         Debug( LDAP_DEBUG_ANY,
143         "%s: line %d: the suffix must be defined before any target.\n",
144                                 fname, lineno, 0 );
145                         return 1;
146                 }
147                 
148                 ++mi->mi_ntargets;
149
150                 mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets, 
151                         sizeof( metatarget_t * ) * mi->mi_ntargets );
152                 if ( mi->mi_targets == NULL ) {
153                         Debug( LDAP_DEBUG_ANY,
154         "%s: line %d: out of memory while storing server name"
155         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
156                                 fname, lineno, 0 );
157                         return 1;
158                 }
159
160                 if ( meta_back_new_target( &mi->mi_targets[ i ] ) != 0 ) {
161                         Debug( LDAP_DEBUG_ANY,
162         "%s: line %d: unable to init server"
163         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
164                                 fname, lineno, 0 );
165                         return 1;
166                 }
167
168                 mt = mi->mi_targets[ i ];
169
170                 mt->mt_rebind_f = mi->mi_rebind_f;
171                 mt->mt_urllist_f = mi->mi_urllist_f;
172                 mt->mt_urllist_p = mt;
173
174                 mt->mt_nretries = mi->mi_nretries;
175                 mt->mt_quarantine = mi->mi_quarantine;
176                 if ( META_BACK_QUARANTINE( mi ) ) {
177                         ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
178                 }
179                 mt->mt_flags = mi->mi_flags;
180                 mt->mt_version = mi->mi_version;
181                 mt->mt_network_timeout = mi->mi_network_timeout;
182                 mt->mt_bind_timeout = mi->mi_bind_timeout;
183                 for ( c = 0; c < SLAP_OP_LAST; c++ ) {
184                         mt->mt_timeout[ c ] = mi->mi_timeout[ c ];
185                 }
186
187                 /*
188                  * uri MUST be legal!
189                  */
190                 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t",
191                         LDAP_PVT_URL_PARSE_NONE ) != LDAP_SUCCESS )
192                 {
193                         Debug( LDAP_DEBUG_ANY,
194         "%s: line %d: unable to parse URI"
195         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
196                                 fname, lineno, 0 );
197                         return 1;
198                 }
199
200                 /*
201                  * uri MUST have the <dn> part!
202                  */
203                 if ( ludp->lud_dn == NULL ) {
204                         Debug( LDAP_DEBUG_ANY,
205         "%s: line %d: missing <naming context> "
206         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
207                                 fname, lineno, 0 );
208                         return 1;
209
210                 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
211                         int     j = -1;
212
213                         for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
214                                 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
215                                         break;
216                                 }
217                         }
218
219                         if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
220                                 Debug( LDAP_DEBUG_ANY,
221                 "%s: line %d: missing <naming context> "
222                 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
223                                         fname, lineno, 0 );
224                                 return 1;
225                         }
226                 }
227
228                 /*
229                  * copies and stores uri and suffix
230                  */
231                 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
232                 rc = dnPrettyNormal( NULL, &dn, &mt->mt_psuffix,
233                         &mt->mt_nsuffix, NULL );
234                 if( rc != LDAP_SUCCESS ) {
235                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
236                                 "target \"%s\" DN is invalid\n",
237                                 fname, lineno, argv[ 1 ] );
238                         return( 1 );
239                 }
240
241                 ludp->lud_dn[ 0 ] = '\0';
242
243                 switch ( ludp->lud_scope ) {
244                 case LDAP_SCOPE_DEFAULT:
245                         mt->mt_scope = LDAP_SCOPE_SUBTREE;
246                         break;
247
248                 case LDAP_SCOPE_SUBTREE:
249                 case LDAP_SCOPE_SUBORDINATE:
250                         mt->mt_scope = ludp->lud_scope;
251                         break;
252
253                 default:
254                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
255                                 "invalid scope for target \"%s\"\n",
256                                 fname, lineno, argv[ 1 ] );
257                         return( 1 );
258                 }
259
260                 /* check all, to apply the scope check on the first one */
261                 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
262                         if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
263                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
264                                         "multiple URIs must have "
265                                         "no DN part\n",
266                                         fname, lineno, 0 );
267                                 return( 1 );
268
269                         }
270                 }
271
272                 mt->mt_uri = ldap_url_list2urls( ludp );
273                 ldap_free_urllist( ludp );
274                 if ( mt->mt_uri == NULL) {
275                         Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
276                                 fname, lineno, 0 );
277                         return( 1 );
278                 }
279                 
280                 /*
281                  * uri MUST be a branch of suffix!
282                  */
283                 tmp_bd = select_backend( &mt->mt_nsuffix, 0 );
284                 if ( tmp_bd == NULL || tmp_bd->be_private != be->be_private )
285                 {
286                         Debug( LDAP_DEBUG_ANY,
287         "%s: line %d: <naming context> of URI does not resolve to this database.\n",
288                                 fname, lineno, 0 );
289                         return 1;
290                 }
291
292         /* subtree-exclude */
293         } else if ( strcasecmp( argv[ 0 ], "subtree-exclude" ) == 0 ) {
294                 int             i = mi->mi_ntargets - 1;
295                 struct berval   dn, ndn;
296
297                 if ( i < 0 ) {
298                         Debug( LDAP_DEBUG_ANY,
299         "%s: line %d: need \"uri\" directive first\n",
300                                 fname, lineno, 0 );
301                         return 1;
302                 }
303                 
304                 switch ( argc ) {
305                 case 1:
306                         Debug( LDAP_DEBUG_ANY,
307         "%s: line %d: missing DN in \"subtree-exclude <DN>\" line\n",
308                             fname, lineno, 0 );
309                         return 1;
310
311                 case 2:
312                         break;
313
314                 default:
315                         Debug( LDAP_DEBUG_ANY,
316         "%s: line %d: too many args in \"subtree-exclude <DN>\" line\n",
317                             fname, lineno, 0 );
318                         return 1;
319                 }
320
321                 ber_str2bv( argv[ 1 ], 0, 0, &dn );
322                 if ( dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL )
323                         != LDAP_SUCCESS )
324                 {
325                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
326                                         "subtree-exclude DN=\"%s\" is invalid\n",
327                                         fname, lineno, argv[ 1 ] );
328                         return( 1 );
329                 }
330
331                 if ( !dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_nsuffix ) ) {
332                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
333                                         "subtree-exclude DN=\"%s\" "
334                                         "must be subtree of target\n",
335                                         fname, lineno, argv[ 1 ] );
336                         ber_memfree( ndn.bv_val );
337                         return( 1 );
338                 }
339
340                 if ( mi->mi_targets[ i ]->mt_subtree_exclude != NULL ) {
341                         int             j;
342
343                         for ( j = 0; !BER_BVISNULL( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ); j++ )
344                         {
345                                 if ( dnIsSuffix( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ], &ndn ) ) {
346                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
347                                                         "subtree-exclude DN=\"%s\" "
348                                                         "is suffix of another subtree-exclude\n",
349                                                         fname, lineno, argv[ 1 ] );
350                                         /* reject, because it might be superior
351                                          * to more than one subtree-exclude */
352                                         ber_memfree( ndn.bv_val );
353                                         return( 1 );
354
355                                 } else if ( dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ) ) {
356                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
357                                                         "another subtree-exclude is suffix of "
358                                                         "subtree-exclude DN=\"%s\"\n",
359                                                         fname, lineno, argv[ 1 ] );
360                                         ber_memfree( ndn.bv_val );
361                                         return( 0 );
362                                 }
363                         }
364                 }
365
366                 ber_bvarray_add( &mi->mi_targets[ i ]->mt_subtree_exclude, &ndn );
367
368         /* default target directive */
369         } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
370                 int             i = mi->mi_ntargets - 1;
371                 
372                 if ( argc == 1 ) {
373                         if ( i < 0 ) {
374                                 Debug( LDAP_DEBUG_ANY,
375         "%s: line %d: \"default-target\" alone need be"
376         " inside a \"uri\" directive\n",
377                                         fname, lineno, 0 );
378                                 return 1;
379                         }
380                         mi->mi_defaulttarget = i;
381
382                 } else {
383                         if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
384                                 if ( i >= 0 ) {
385                                         Debug( LDAP_DEBUG_ANY,
386         "%s: line %d: \"default-target none\""
387         " should go before uri definitions\n",
388                                                 fname, lineno, 0 );
389                                 }
390                                 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
391
392                         } else {
393                                 
394                                 if ( lutil_atoi( &mi->mi_defaulttarget, argv[ 1 ] ) != 0
395                                         || mi->mi_defaulttarget < 0
396                                         || mi->mi_defaulttarget >= i - 1 )
397                                 {
398                                         Debug( LDAP_DEBUG_ANY,
399         "%s: line %d: illegal target number %d\n",
400                                                 fname, lineno, mi->mi_defaulttarget );
401                                         return 1;
402                                 }
403                         }
404                 }
405                 
406         /* ttl of dn cache */
407         } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
408                 if ( argc != 2 ) {
409                         Debug( LDAP_DEBUG_ANY,
410         "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
411                                 fname, lineno, 0 );
412                         return 1;
413                 }
414                 
415                 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
416                         mi->mi_cache.ttl = META_DNCACHE_FOREVER;
417
418                 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
419                         mi->mi_cache.ttl = META_DNCACHE_DISABLED;
420
421                 } else {
422                         unsigned long   t;
423
424                         if ( lutil_parse_time( argv[ 1 ], &t ) != 0 ) {
425                                 Debug( LDAP_DEBUG_ANY,
426         "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
427                                         fname, lineno, argv[ 1 ] );
428                                 return 1;
429                         }
430                         mi->mi_cache.ttl = (time_t)t;
431                 }
432
433         /* network timeout when connecting to ldap servers */
434         } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
435                 unsigned long   t;
436                 time_t          *tp = mi->mi_ntargets ?
437                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_network_timeout
438                                 : &mi->mi_network_timeout;
439
440                 if ( argc != 2 ) {
441                         Debug( LDAP_DEBUG_ANY,
442         "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
443                                 fname, lineno, 0 );
444                         return 1;
445                 }
446
447                 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
448                         Debug( LDAP_DEBUG_ANY,
449         "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
450                                 fname, lineno, argv[ 1 ] );
451                         return 1;
452
453                 }
454
455                 *tp = (time_t)t;
456
457         /* idle timeout when connecting to ldap servers */
458         } else if ( strcasecmp( argv[ 0 ], "idle-timeout" ) == 0 ) {
459                 unsigned long   t;
460
461                 switch ( argc ) {
462                 case 1:
463                         Debug( LDAP_DEBUG_ANY,
464         "%s: line %d: missing timeout value in \"idle-timeout <seconds>\" line\n",
465                                 fname, lineno, 0 );
466                         return 1;
467                 case 2:
468                         break;
469                 default:
470                         Debug( LDAP_DEBUG_ANY,
471         "%s: line %d: extra cruft after timeout value in \"idle-timeout <seconds>\" line\n",
472                                 fname, lineno, 0 );
473                         return 1;
474                 }
475
476                 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
477                         Debug( LDAP_DEBUG_ANY,
478         "%s: line %d: unable to parse timeout \"%s\" in \"idle-timeout <seconds>\" line\n",
479                                 fname, lineno, argv[ 1 ] );
480                         return 1;
481
482                 }
483
484                 mi->mi_idle_timeout = (time_t)t;
485
486         /* conn ttl */
487         } else if ( strcasecmp( argv[ 0 ], "conn-ttl" ) == 0 ) {
488                 unsigned long   t;
489
490                 switch ( argc ) {
491                 case 1:
492                         Debug( LDAP_DEBUG_ANY,
493         "%s: line %d: missing ttl value in \"conn-ttl <seconds>\" line\n",
494                                 fname, lineno, 0 );
495                         return 1;
496                 case 2:
497                         break;
498                 default:
499                         Debug( LDAP_DEBUG_ANY,
500         "%s: line %d: extra cruft after ttl value in \"conn-ttl <seconds>\" line\n",
501                                 fname, lineno, 0 );
502                         return 1;
503                 }
504
505                 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
506                         Debug( LDAP_DEBUG_ANY,
507         "%s: line %d: unable to parse ttl \"%s\" in \"conn-ttl <seconds>\" line\n",
508                                 fname, lineno, argv[ 1 ] );
509                         return 1;
510
511                 }
512
513                 mi->mi_conn_ttl = (time_t)t;
514
515         /* bind timeout when connecting to ldap servers */
516         } else if ( strcasecmp( argv[ 0 ], "bind-timeout" ) == 0 ) {
517                 unsigned long   t;
518                 struct timeval  *tp = mi->mi_ntargets ?
519                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_bind_timeout
520                                 : &mi->mi_bind_timeout;
521
522                 switch ( argc ) {
523                 case 1:
524                         Debug( LDAP_DEBUG_ANY,
525         "%s: line %d: missing timeout value in \"bind-timeout <microseconds>\" line\n",
526                                 fname, lineno, 0 );
527                         return 1;
528                 case 2:
529                         break;
530                 default:
531                         Debug( LDAP_DEBUG_ANY,
532         "%s: line %d: extra cruft after timeout value in \"bind-timeout <microseconds>\" line\n",
533                                 fname, lineno, 0 );
534                         return 1;
535                 }
536
537                 if ( lutil_atoul( &t, argv[ 1 ] ) != 0 ) {
538                         Debug( LDAP_DEBUG_ANY,
539         "%s: line %d: unable to parse timeout \"%s\" in \"bind-timeout <microseconds>\" line\n",
540                                 fname, lineno, argv[ 1 ] );
541                         return 1;
542
543                 }
544
545                 tp->tv_sec = t/1000000;
546                 tp->tv_usec = t%1000000;
547
548         /* name to use for meta_back_group */
549         } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
550                         || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
551         {
552                 int             i = mi->mi_ntargets - 1;
553                 struct berval   dn;
554
555                 if ( i < 0 ) {
556                         Debug( LDAP_DEBUG_ANY,
557         "%s: line %d: need \"uri\" directive first\n",
558                                 fname, lineno, 0 );
559                         return 1;
560                 }
561                 
562                 if ( argc != 2 ) {
563                         Debug( LDAP_DEBUG_ANY,
564         "%s: line %d: missing name in \"binddn <name>\" line\n",
565                                 fname, lineno, 0 );
566                         return 1;
567                 }
568
569                 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
570                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
571                                 "\"binddn\" statement is deprecated; "
572                                 "use \"acl-authcDN\" instead\n",
573                                 fname, lineno, 0 );
574                         /* FIXME: some day we'll need to throw an error */
575                 }
576
577                 ber_str2bv( argv[ 1 ], 0, 0, &dn );
578                 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ]->mt_binddn,
579                         NULL ) != LDAP_SUCCESS )
580                 {
581                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
582                                         "bind DN '%s' is invalid\n",
583                                         fname, lineno, argv[ 1 ] );
584                         return( 1 );
585                 }
586
587         /* password to use for meta_back_group */
588         } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
589                         || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
590         {
591                 int             i = mi->mi_ntargets - 1;
592
593                 if ( i < 0 ) {
594                         Debug( LDAP_DEBUG_ANY,
595         "%s: line %d: need \"uri\" directive first\n",
596                                 fname, lineno, 0 );
597                         return 1;
598                 }
599                 
600                 if ( argc != 2 ) {
601                         Debug( LDAP_DEBUG_ANY,
602         "%s: line %d: missing password in \"bindpw <password>\" line\n",
603                             fname, lineno, 0 );
604                         return 1;
605                 }
606
607                 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
608                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
609                                 "\"bindpw\" statement is deprecated; "
610                                 "use \"acl-passwd\" instead\n",
611                                 fname, lineno, 0 );
612                         /* FIXME: some day we'll need to throw an error */
613                 }
614
615                 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_bindpw );
616                 
617         /* save bind creds for referral rebinds? */
618         } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
619                 if ( argc > 2 ) {
620                         Debug( LDAP_DEBUG_ANY,
621         "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
622                             fname, lineno, 0 );
623                         return( 1 );
624                 }
625
626                 if ( argc == 1 ) {
627                         Debug( LDAP_DEBUG_ANY,
628         "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
629                             fname, lineno, 0 );
630                         mi->mi_flags |= LDAP_BACK_F_SAVECRED;
631
632                 } else {
633                         switch ( check_true_false( argv[ 1 ] ) ) {
634                         case 0:
635                                 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
636                                 break;
637
638                         case 1:
639                                 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
640                                 break;
641
642                         default:
643                                 Debug( LDAP_DEBUG_ANY,
644         "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
645                                     fname, lineno, argv[ 1 ] );
646                                 return 1;
647                         }
648                 }
649
650         } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
651                 unsigned        *flagsp = mi->mi_ntargets ?
652                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
653                                 : &mi->mi_flags;
654
655                 if ( argc != 2 ) {
656                         Debug( LDAP_DEBUG_ANY,
657         "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
658                                 fname, lineno, 0 );
659                         return( 1 );
660                 }
661
662                 /* this is the default; we add it because the default might change... */
663                 switch ( check_true_false( argv[ 1 ] ) ) {
664                 case 1:
665                         *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
666                         break;
667
668                 case 0:
669                         *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
670                         break;
671
672                 default:
673                         Debug( LDAP_DEBUG_ANY,
674                 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
675                                 fname, lineno, argv[ 1 ] );
676                         return( 1 );
677                 }
678         
679         } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
680                 unsigned        *flagsp = mi->mi_ntargets ?
681                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
682                                 : &mi->mi_flags;
683
684                 if ( argc != 2 ) {
685                         Debug( LDAP_DEBUG_ANY,
686                 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
687                                 fname, lineno, 0 );
688                         return( 1 );
689                 }
690
691                 /* start */
692                 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
693                         *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
694         
695                 /* try start tls */
696                 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
697                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
698                         *flagsp |= LDAP_BACK_F_USE_TLS;
699         
700                 /* propagate start tls */
701                 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
702                         *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
703                 
704                 /* try start tls */
705                 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
706                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
707                         *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
708
709                 } else {
710                         Debug( LDAP_DEBUG_ANY,
711                 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
712                                 fname, lineno, argv[ 1 ] );
713                         return( 1 );
714                 }
715
716         } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
717                 unsigned        *flagsp = mi->mi_ntargets ?
718                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
719                                 : &mi->mi_flags;
720
721                 if ( argc != 2 ) {
722                         Debug( LDAP_DEBUG_ANY,
723                 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
724                                 fname, lineno, 0 );
725                         return( 1 );
726                 }
727
728                 switch ( check_true_false( argv[ 1 ] ) ) {
729                 case 0:
730                         *flagsp &= ~LDAP_BACK_F_T_F_MASK2;
731                         break;
732
733                 case 1:
734                         *flagsp |= LDAP_BACK_F_T_F;
735                         break;
736
737                 default:
738                         if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
739                                 *flagsp |= LDAP_BACK_F_T_F_DISCOVER;
740
741                         } else {
742                                 Debug( LDAP_DEBUG_ANY,
743         "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
744                                         fname, lineno, argv[ 1 ] );
745                                 return 1;
746                         }
747                         break;
748                 }
749
750         /* onerr? */
751         } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
752                 if ( argc != 2 ) {
753                         Debug( LDAP_DEBUG_ANY,
754         "%s: line %d: \"onerr {CONTINUE|report|stop}\" takes 1 argument\n",
755                                 fname, lineno, 0 );
756                         return( 1 );
757                 }
758
759                 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
760                         mi->mi_flags &= ~META_BACK_F_ONERR_MASK;
761
762                 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
763                         mi->mi_flags |= META_BACK_F_ONERR_STOP;
764
765                 } else if ( strcasecmp( argv[ 1 ], "report" ) == 0 ) {
766                         mi->mi_flags |= META_BACK_F_ONERR_REPORT;
767
768                 } else {
769                         Debug( LDAP_DEBUG_ANY,
770         "%s: line %d: \"onerr {CONTINUE|report|stop}\": invalid arg \"%s\".\n",
771                                 fname, lineno, argv[ 1 ] );
772                         return 1;
773                 }
774
775         /* bind-defer? */
776         } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0
777                 || strcasecmp( argv[ 0 ], "root-bind-defer" ) == 0 )
778         {
779                 if ( argc != 2 ) {
780                         Debug( LDAP_DEBUG_ANY,
781         "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\" takes 1 argument\n",
782                                 fname, lineno, 0 );
783                         return( 1 );
784                 }
785
786                 switch ( check_true_false( argv[ 1 ] ) ) {
787                 case 0:
788                         mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
789                         break;
790
791                 case 1:
792                         mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
793                         break;
794
795                 default:
796                         Debug( LDAP_DEBUG_ANY,
797         "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
798                                 fname, lineno, argv[ 1 ] );
799                         return 1;
800                 }
801
802         /* single-conn? */
803         } else if ( strcasecmp( argv[ 0 ], "single-conn" ) == 0 ) {
804                 if ( argc != 2 ) {
805                         Debug( LDAP_DEBUG_ANY,
806         "%s: line %d: \"single-conn {FALSE|true}\" takes 1 argument\n",
807                                 fname, lineno, 0 );
808                         return( 1 );
809                 }
810
811                 if ( mi->mi_ntargets > 0 ) {
812                         Debug( LDAP_DEBUG_ANY,
813         "%s: line %d: \"single-conn\" must appear before target definitions\n",
814                                 fname, lineno, 0 );
815                         return( 1 );
816                 }
817
818                 switch ( check_true_false( argv[ 1 ] ) ) {
819                 case 0:
820                         mi->mi_flags &= ~LDAP_BACK_F_SINGLECONN;
821                         break;
822
823                 case 1:
824                         mi->mi_flags |= LDAP_BACK_F_SINGLECONN;
825                         break;
826
827                 default:
828                         Debug( LDAP_DEBUG_ANY,
829         "%s: line %d: \"single-conn {FALSE|true}\": invalid arg \"%s\".\n",
830                                 fname, lineno, argv[ 1 ] );
831                         return 1;
832                 }
833
834         /* use-temporaries? */
835         } else if ( strcasecmp( argv[ 0 ], "use-temporary-conn" ) == 0 ) {
836                 if ( argc != 2 ) {
837                         Debug( LDAP_DEBUG_ANY,
838         "%s: line %d: \"use-temporary-conn {FALSE|true}\" takes 1 argument\n",
839                                 fname, lineno, 0 );
840                         return( 1 );
841                 }
842
843                 if ( mi->mi_ntargets > 0 ) {
844                         Debug( LDAP_DEBUG_ANY,
845         "%s: line %d: \"use-temporary-conn\" must appear before target definitions\n",
846                                 fname, lineno, 0 );
847                         return( 1 );
848                 }
849
850                 switch ( check_true_false( argv[ 1 ] ) ) {
851                 case 0:
852                         mi->mi_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
853                         break;
854
855                 case 1:
856                         mi->mi_flags |= LDAP_BACK_F_USE_TEMPORARIES;
857                         break;
858
859                 default:
860                         Debug( LDAP_DEBUG_ANY,
861         "%s: line %d: \"use-temporary-conn {FALSE|true}\": invalid arg \"%s\".\n",
862                                 fname, lineno, argv[ 1 ] );
863                         return 1;
864                 }
865
866         /* privileged connections pool max size ? */
867         } else if ( strcasecmp( argv[ 0 ], "conn-pool-max" ) == 0 ) {
868                 if ( argc != 2 ) {
869                         Debug( LDAP_DEBUG_ANY,
870         "%s: line %d: \"conn-pool-max <n>\" takes 1 argument\n",
871                                 fname, lineno, 0 );
872                         return( 1 );
873                 }
874
875                 if ( mi->mi_ntargets > 0 ) {
876                         Debug( LDAP_DEBUG_ANY,
877         "%s: line %d: \"conn-pool-max\" must appear before target definitions\n",
878                                 fname, lineno, 0 );
879                         return( 1 );
880                 }
881
882                 if ( lutil_atoi( &mi->mi_conn_priv_max, argv[1] )
883                         || mi->mi_conn_priv_max < LDAP_BACK_CONN_PRIV_MIN
884                         || mi->mi_conn_priv_max > LDAP_BACK_CONN_PRIV_MAX )
885                 {
886                         Debug( LDAP_DEBUG_ANY,
887         "%s: line %d: \"conn-pool-max <n>\": invalid arg \"%s\".\n",
888                                 fname, lineno, argv[ 1 ] );
889                         return 1;
890                 }
891
892         } else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
893                 unsigned        flag = 0;
894                 unsigned        *flagsp = mi->mi_ntargets ?
895                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
896                                 : &mi->mi_flags;
897
898                 if ( argc != 2 ) {
899                         Debug( LDAP_DEBUG_ANY,
900         "%s: line %d: \"cancel {abandon|ignore|exop}\" takes 1 argument\n",
901                                 fname, lineno, 0 );
902                         return( 1 );
903                 }
904
905                 if ( strcasecmp( argv[ 1 ], "abandon" ) == 0 ) {
906                         flag = LDAP_BACK_F_CANCEL_ABANDON;
907
908                 } else if ( strcasecmp( argv[ 1 ], "ignore" ) == 0 ) {
909                         flag = LDAP_BACK_F_CANCEL_IGNORE;
910
911                 } else if ( strcasecmp( argv[ 1 ], "exop" ) == 0 ) {
912                         flag = LDAP_BACK_F_CANCEL_EXOP;
913
914                 } else if ( strcasecmp( argv[ 1 ], "exop-discover" ) == 0 ) {
915                         flag = LDAP_BACK_F_CANCEL_EXOP_DISCOVER;
916
917                 } else {
918                         Debug( LDAP_DEBUG_ANY,
919         "%s: line %d: \"cancel {abandon|ignore|exop[-discover]}\": unknown mode \"%s\" \n",
920                                 fname, lineno, argv[ 1 ] );
921                         return( 1 );
922                 }
923
924                 *flagsp &= ~LDAP_BACK_F_CANCEL_MASK2;
925                 *flagsp |= flag;
926
927         } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
928                 char    *sep;
929                 time_t  *tv = mi->mi_ntargets ?
930                                 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_timeout
931                                 : mi->mi_timeout;
932                 int     c;
933
934                 if ( argc < 2 ) {
935                         Debug( LDAP_DEBUG_ANY,
936         "%s: line %d: \"timeout [{add|bind|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
937                                 fname, lineno, 0 );
938                         return( 1 );
939                 }
940
941                 for ( c = 1; c < argc; c++ ) {
942                         time_t          *t = NULL;
943                         unsigned long   val;
944
945                         sep = strchr( argv[ c ], '=' );
946                         if ( sep != NULL ) {
947                                 size_t  len = sep - argv[ c ];
948
949                                 if ( strncasecmp( argv[ c ], "bind", len ) == 0 ) {
950                                         t = &tv[ SLAP_OP_BIND ];
951                                 /* unbind makes little sense */
952                                 } else if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
953                                         t = &tv[ SLAP_OP_ADD ];
954                                 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
955                                         t = &tv[ SLAP_OP_DELETE ];
956                                 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
957                                         t = &tv[ SLAP_OP_MODRDN ];
958                                 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
959                                         t = &tv[ SLAP_OP_MODIFY ];
960                                 } else if ( strncasecmp( argv[ c ], "compare", len ) == 0 ) {
961                                         t = &tv[ SLAP_OP_COMPARE ];
962                                 } else if ( strncasecmp( argv[ c ], "search", len ) == 0 ) {
963                                         t = &tv[ SLAP_OP_SEARCH ];
964                                 /* abandon makes little sense */
965 #if 0                           /* not implemented yet */
966                                 } else if ( strncasecmp( argv[ c ], "extended", len ) == 0 ) {
967                                         t = &tv[ SLAP_OP_EXTENDED ];
968 #endif
969                                 } else {
970                                         char    buf[ SLAP_TEXT_BUFLEN ];
971                                         snprintf( buf, sizeof( buf ),
972                                                 "unknown/unhandled operation \"%s\" for timeout #%d",
973                                                 argv[ c ], c - 1 );
974                                         Debug( LDAP_DEBUG_ANY,
975                                                 "%s: line %d: %s.\n",
976                                                 fname, lineno, buf );
977                                         return 1;
978                                 }
979                                 sep++;
980         
981                         } else {
982                                 sep = argv[ c ];
983                         }
984         
985                         if ( lutil_parse_time( sep, &val ) != 0 ) {
986                                 Debug( LDAP_DEBUG_ANY,
987                 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
988                                         fname, lineno, sep );
989                                 return 1;
990                         }
991                 
992                         if ( t ) {
993                                 *t = (time_t)val;
994         
995                         } else {
996                                 int     i;
997         
998                                 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
999                                         tv[ i ] = (time_t)val;
1000                                 }
1001                         }
1002                 }
1003         
1004         /* name to use as pseudo-root dn */
1005         } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
1006                 int             i = mi->mi_ntargets - 1;
1007
1008                 if ( i < 0 ) {
1009                         Debug( LDAP_DEBUG_ANY,
1010         "%s: line %d: need \"uri\" directive first\n",
1011                                 fname, lineno, 0 );
1012                         return 1;
1013                 }
1014                 
1015                 if ( argc != 2 ) {
1016                         Debug( LDAP_DEBUG_ANY,
1017         "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
1018                                 fname, lineno, 0 );
1019                         return 1;
1020                 }
1021
1022                 /*
1023                  * exact replacement:
1024                  *
1025
1026 idassert-bind   bindmethod=simple
1027                 binddn=<pseudorootdn>
1028                 credentials=<pseudorootpw>
1029                 mode=none
1030                 flags=non-prescriptive
1031 idassert-authzFrom      "dn:<rootdn>"
1032
1033                  * so that only when authc'd as <rootdn> the proxying occurs
1034                  * rebinding as the <pseudorootdn> without proxyAuthz.
1035                  */
1036
1037                 Debug( LDAP_DEBUG_ANY,
1038                         "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1039                         "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1040                         fname, lineno, 0 );
1041
1042                 {
1043                         char    binddn[ SLAP_TEXT_BUFLEN ];
1044                         char    *cargv[] = {
1045                                 "idassert-bind",
1046                                 "bindmethod=simple",
1047                                 NULL,
1048                                 "mode=none",
1049                                 "flags=non-prescriptive",
1050                                 NULL
1051                         };
1052                         int     cargc = 5;
1053                         int     rc;
1054
1055                         if ( BER_BVISNULL( &be->be_rootndn ) ) {
1056                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"rootdn\" must be defined first.\n",
1057                                         fname, lineno, 0 );
1058                                 return 1;
1059                         }
1060
1061                         if ( snprintf( binddn, sizeof( binddn ), "binddn=%s", argv[ 1 ] ) >= sizeof( binddn ) ) {
1062                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootdn\" too long.\n",
1063                                         fname, lineno, 0 );
1064                                 return 1;
1065                         }
1066                         cargv[ 2 ] = binddn;
1067
1068                         rc = slap_idassert_parse_cf( fname, lineno, cargc, cargv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1069                         if ( rc == 0 ) {
1070                                 struct berval   bv;
1071
1072                                 if ( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz != NULL ) {
1073                                         Debug( LDAP_DEBUG_ANY, "%s: line %d: \"idassert-authzFrom\" already defined (discarded).\n",
1074                                                 fname, lineno, 0 );
1075                                         ber_bvarray_free( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz );
1076                                         mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz = NULL;
1077                                 }
1078
1079                                 assert( !BER_BVISNULL( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authcDN ) );
1080
1081                                 bv.bv_len = STRLENOF( "dn:" ) + be->be_rootndn.bv_len;
1082                                 bv.bv_val = ber_memalloc( bv.bv_len + 1 );
1083                                 AC_MEMCPY( bv.bv_val, "dn:", STRLENOF( "dn:" ) );
1084                                 AC_MEMCPY( &bv.bv_val[ STRLENOF( "dn:" ) ], be->be_rootndn.bv_val, be->be_rootndn.bv_len + 1 );
1085
1086                                 ber_bvarray_add( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz, &bv );
1087                         }
1088
1089                         return rc;
1090                 }
1091
1092         /* password to use as pseudo-root */
1093         } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
1094                 int             i = mi->mi_ntargets - 1;
1095
1096                 if ( i < 0 ) {
1097                         Debug( LDAP_DEBUG_ANY,
1098         "%s: line %d: need \"uri\" directive first\n",
1099                                 fname, lineno, 0 );
1100                         return 1;
1101                 }
1102                 
1103                 if ( argc != 2 ) {
1104                         Debug( LDAP_DEBUG_ANY,
1105         "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
1106                             fname, lineno, 0 );
1107                         return 1;
1108                 }
1109
1110                 Debug( LDAP_DEBUG_ANY,
1111                         "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1112                         "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1113                         fname, lineno, 0 );
1114
1115                 if ( BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_authcDN ) ) {
1116                         Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"pseudorootdn\" must be defined first.\n",
1117                                 fname, lineno, 0 );
1118                         return 1;
1119                 }
1120
1121                 if ( !BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_passwd ) ) {
1122                         memset( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val, 0,
1123                                 mi->mi_targets[ i ]->mt_idassert_passwd.bv_len );
1124                         ber_memfree( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val );
1125                 }
1126                 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_targets[ i ]->mt_idassert_passwd );
1127
1128         /* idassert-bind */
1129         } else if ( strcasecmp( argv[ 0 ], "idassert-bind" ) == 0 ) {
1130                 if ( mi->mi_ntargets == 0 ) {
1131                         Debug( LDAP_DEBUG_ANY,
1132                                 "%s: line %d: \"idassert-bind\" "
1133                                 "must appear inside a target specification.\n",
1134                                 fname, lineno, 0 );
1135                         return 1;
1136                 }
1137
1138                 return slap_idassert_parse_cf( fname, lineno, argc, argv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1139
1140         /* idassert-authzFrom */
1141         } else if ( strcasecmp( argv[ 0 ], "idassert-authzFrom" ) == 0 ) {
1142                 if ( mi->mi_ntargets == 0 ) {
1143                         Debug( LDAP_DEBUG_ANY,
1144                                 "%s: line %d: \"idassert-bind\" "
1145                                 "must appear inside a target specification.\n",
1146                                 fname, lineno, 0 );
1147                         return 1;
1148                 }
1149
1150                 switch ( argc ) {
1151                 case 2:
1152                         break;
1153
1154                 case 1:
1155                         Debug( LDAP_DEBUG_ANY,
1156                                 "%s: line %d: missing <id> in \"idassert-authzFrom <id>\".\n",
1157                                 fname, lineno, 0 );
1158                         return 1;
1159
1160                 default:
1161                         Debug( LDAP_DEBUG_ANY,
1162                                 "%s: line %d: extra cruft after <id> in \"idassert-authzFrom <id>\".\n",
1163                                 fname, lineno, 0 );
1164                         return 1;
1165                 }
1166
1167                 return slap_idassert_authzfrom_parse_cf( fname, lineno, argv[ 1 ], &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1168
1169         /* quarantine */
1170         } else if ( strcasecmp( argv[ 0 ], "quarantine" ) == 0 ) {
1171                 char                    buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1172                 slap_retry_info_t       *ri = mi->mi_ntargets ?
1173                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine
1174                                 : &mi->mi_quarantine;
1175
1176                 if ( ( mi->mi_ntargets == 0 && META_BACK_QUARANTINE( mi ) )
1177                         || ( mi->mi_ntargets > 0 && META_BACK_TGT_QUARANTINE( mi->mi_targets[ mi->mi_ntargets - 1 ] ) ) )
1178                 {
1179                         Debug( LDAP_DEBUG_ANY,
1180                                 "%s: line %d: quarantine already defined.\n",
1181                                 fname, lineno, 0 );
1182                         return 1;
1183                 }
1184
1185                 switch ( argc ) {
1186                 case 2:
1187                         break;
1188
1189                 case 1:
1190                         Debug( LDAP_DEBUG_ANY,
1191                                 "%s: line %d: missing arg in \"quarantine <pattern list>\".\n",
1192                                 fname, lineno, 0 );
1193                         return 1;
1194
1195                 default:
1196                         Debug( LDAP_DEBUG_ANY,
1197                                 "%s: line %d: extra cruft after \"quarantine <pattern list>\".\n",
1198                                 fname, lineno, 0 );
1199                         return 1;
1200                 }
1201
1202                 if ( ri != &mi->mi_quarantine ) {
1203                         ri->ri_interval = NULL;
1204                         ri->ri_num = NULL;
1205                 }
1206
1207                 if ( mi->mi_ntargets > 0 && !META_BACK_QUARANTINE( mi ) ) {
1208                         ldap_pvt_thread_mutex_init( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine_mutex );
1209                 }
1210
1211                 if ( slap_retry_info_parse( argv[ 1 ], ri, buf, sizeof( buf ) ) ) {
1212                         Debug( LDAP_DEBUG_ANY,
1213                                 "%s line %d: %s.\n",
1214                                 fname, lineno, buf );
1215                         return 1;
1216                 }
1217
1218                 if ( mi->mi_ntargets ) {
1219                         mi->mi_flags |= LDAP_BACK_F_QUARANTINE;
1220
1221                 } else {
1222                         mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags |= LDAP_BACK_F_QUARANTINE;
1223                 }
1224
1225         /* session tracking request */
1226         } else if ( strcasecmp( argv[ 0 ], "session-tracking-request" ) == 0 ) {
1227                 unsigned        *flagsp = mi->mi_ntargets ?
1228                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
1229                                 : &mi->mi_flags;
1230
1231                 if ( argc != 2 ) {
1232                         Debug( LDAP_DEBUG_ANY,
1233         "%s: line %d: \"session-tracking-request {TRUE|false}\" needs 1 argument.\n",
1234                                 fname, lineno, 0 );
1235                         return( 1 );
1236                 }
1237
1238                 /* this is the default; we add it because the default might change... */
1239                 switch ( check_true_false( argv[ 1 ] ) ) {
1240                 case 1:
1241                         *flagsp |= LDAP_BACK_F_ST_REQUEST;
1242                         break;
1243
1244                 case 0:
1245                         *flagsp &= ~LDAP_BACK_F_ST_REQUEST;
1246                         break;
1247
1248                 default:
1249                         Debug( LDAP_DEBUG_ANY,
1250                 "%s: line %d: \"session-tracking-request {TRUE|false}\": unknown argument \"%s\".\n",
1251                                 fname, lineno, argv[ 1 ] );
1252                         return( 1 );
1253                 }
1254         
1255         /* dn massaging */
1256         } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
1257                 BackendDB       *tmp_be;
1258                 int             i = mi->mi_ntargets - 1, rc;
1259                 struct berval   dn, nvnc, pvnc, nrnc, prnc;
1260
1261                 if ( i < 0 ) {
1262                         Debug( LDAP_DEBUG_ANY,
1263         "%s: line %d: need \"uri\" directive first\n",
1264                                 fname, lineno, 0 );
1265                         return 1;
1266                 }
1267                 
1268                 /*
1269                  * syntax:
1270                  * 
1271                  *      suffixmassage <suffix> <massaged suffix>
1272                  *
1273                  * the <suffix> field must be defined as a valid suffix
1274                  * (or suffixAlias?) for the current database;
1275                  * the <massaged suffix> shouldn't have already been
1276                  * defined as a valid suffix or suffixAlias for the 
1277                  * current server
1278                  */
1279                 if ( argc != 3 ) {
1280                         Debug( LDAP_DEBUG_ANY,
1281         "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
1282                                 fname, lineno, 0 );
1283                         return 1;
1284                 }
1285
1286                 ber_str2bv( argv[ 1 ], 0, 0, &dn );
1287                 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1288                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1289                                         "suffix '%s' is invalid\n",
1290                                         fname, lineno, argv[ 1 ] );
1291                         return 1;
1292                 }
1293                 
1294                 tmp_be = select_backend( &nvnc, 0 );
1295                 if ( tmp_be != NULL && tmp_be != be ) {
1296                         Debug( LDAP_DEBUG_ANY, 
1297         "%s: line %d: suffix already in use by another backend in"
1298         " \"suffixMassage <suffix> <massaged suffix>\"\n",
1299                                 fname, lineno, 0 );
1300                         free( pvnc.bv_val );
1301                         free( nvnc.bv_val );
1302                         return 1;                                               
1303                 }
1304
1305                 ber_str2bv( argv[ 2 ], 0, 0, &dn );
1306                 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1307                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1308                                 "massaged suffix '%s' is invalid\n",
1309                                 fname, lineno, argv[ 2 ] );
1310                         free( pvnc.bv_val );
1311                         free( nvnc.bv_val );
1312                         return 1;
1313                 }
1314         
1315 #if 0   
1316                 tmp_be = select_backend( &nrnc, 0 );
1317                 if ( tmp_be != NULL ) {
1318                         Debug( LDAP_DEBUG_ANY,
1319         "%s: line %d: massaged suffix already in use by another backend in" 
1320         " \"suffixMassage <suffix> <massaged suffix>\"\n",
1321                                 fname, lineno, 0 );
1322                         free( pvnc.bv_val );
1323                         free( nvnc.bv_val );
1324                         free( prnc.bv_val );
1325                         free( nrnc.bv_val );
1326                         return 1;
1327                 }
1328 #endif
1329                 
1330                 /*
1331                  * The suffix massaging is emulated by means of the
1332                  * rewrite capabilities
1333                  * FIXME: no extra rewrite capabilities should be added
1334                  * to the database
1335                  */
1336                 rc = suffix_massage_config( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1337                                 &pvnc, &nvnc, &prnc, &nrnc );
1338
1339                 free( pvnc.bv_val );
1340                 free( nvnc.bv_val );
1341                 free( prnc.bv_val );
1342                 free( nrnc.bv_val );
1343
1344                 return rc;
1345                 
1346         /* rewrite stuff ... */
1347         } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
1348                 int             i = mi->mi_ntargets - 1;
1349
1350                 if ( i < 0 ) {
1351                         Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
1352                                 "statement outside target definition.\n",
1353                                 fname, lineno, 0 );
1354                         return 1;
1355                 }
1356                 
1357                 return rewrite_parse( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1358                                 fname, lineno, argc, argv );
1359
1360         /* objectclass/attribute mapping */
1361         } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
1362                 int             i = mi->mi_ntargets - 1;
1363
1364                 if ( i < 0 ) {
1365                         Debug( LDAP_DEBUG_ANY,
1366         "%s: line %d: need \"uri\" directive first\n",
1367                                 fname, lineno, 0 );
1368                         return 1;
1369                 }
1370
1371                 return ldap_back_map_config( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc, 
1372                                 &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
1373                                 fname, lineno, argc, argv );
1374
1375         } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
1376                 int             i = mi->mi_ntargets - 1;
1377                 int             nretries = META_RETRY_UNDEFINED;
1378
1379                 if ( argc != 2 ) {
1380                         Debug( LDAP_DEBUG_ANY,
1381         "%s: line %d: need value in \"nretries <value>\"\n",
1382                                 fname, lineno, 0 );
1383                         return 1;
1384                 }
1385
1386                 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
1387                         nretries = META_RETRY_FOREVER;
1388
1389                 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
1390                         nretries = META_RETRY_NEVER;
1391
1392                 } else {
1393                         if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
1394                                 Debug( LDAP_DEBUG_ANY,
1395         "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
1396                                         fname, lineno, argv[ 1 ] );
1397                                 return 1;
1398                         }
1399                 }
1400
1401                 if ( i < 0 ) {
1402                         mi->mi_nretries = nretries;
1403
1404                 } else {
1405                         mi->mi_targets[ i ]->mt_nretries = nretries;
1406                 }
1407
1408         } else if ( strcasecmp( argv[ 0 ], "protocol-version" ) == 0 ) {
1409                 int     *version = mi->mi_ntargets ?
1410                                 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_version
1411                                 : &mi->mi_version;
1412
1413                 if ( argc != 2 ) {
1414                         Debug( LDAP_DEBUG_ANY,
1415         "%s: line %d: need value in \"protocol-version <version>\"\n",
1416                                 fname, lineno, 0 );
1417                         return 1;
1418                 }
1419
1420                 if ( lutil_atoi( version, argv[ 1 ] ) != 0 ) {
1421                         Debug( LDAP_DEBUG_ANY,
1422         "%s: line %d: unable to parse version \"%s\" in \"protocol-version <version>\"\n",
1423                                 fname, lineno, argv[ 1 ] );
1424                         return 1;
1425                 }
1426
1427                 if ( *version != 0 && ( *version < LDAP_VERSION_MIN || *version > LDAP_VERSION_MAX ) ) {
1428                         Debug( LDAP_DEBUG_ANY,
1429         "%s: line %d: unsupported version \"%s\" in \"protocol-version <version>\"\n",
1430                                 fname, lineno, argv[ 1 ] );
1431                         return 1;
1432                 }
1433
1434         /* anything else */
1435         } else {
1436                 return SLAP_CONF_UNKNOWN;
1437         }
1438         return 0;
1439 }
1440
1441 int
1442 ldap_back_map_config(
1443                 struct ldapmap  *oc_map,
1444                 struct ldapmap  *at_map,
1445                 const char      *fname,
1446                 int             lineno,
1447                 int             argc,
1448                 char            **argv )
1449 {
1450         struct ldapmap          *map;
1451         struct ldapmapping      *mapping;
1452         char                    *src, *dst;
1453         int                     is_oc = 0;
1454
1455         if ( argc < 3 || argc > 4 ) {
1456                 Debug( LDAP_DEBUG_ANY,
1457         "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
1458                         fname, lineno, 0 );
1459                 return 1;
1460         }
1461
1462         if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
1463                 map = oc_map;
1464                 is_oc = 1;
1465
1466         } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
1467                 map = at_map;
1468
1469         } else {
1470                 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
1471                         "\"map {objectclass | attribute} [<local> | *] "
1472                         "{<foreign> | *}\"\n",
1473                         fname, lineno, 0 );
1474                 return 1;
1475         }
1476
1477         if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
1478                 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
1479                         map->drop_missing = ( argc < 4 );
1480                         goto success_return;
1481                 }
1482                 src = dst = argv[ 3 ];
1483
1484         } else if ( argc < 4 ) {
1485                 src = "";
1486                 dst = argv[ 2 ];
1487
1488         } else {
1489                 src = argv[ 2 ];
1490                 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
1491         }
1492
1493         if ( ( map == at_map )
1494                 && ( strcasecmp( src, "objectclass" ) == 0
1495                         || strcasecmp( dst, "objectclass" ) == 0 ) )
1496         {
1497                 Debug( LDAP_DEBUG_ANY,
1498                         "%s: line %d: objectclass attribute cannot be mapped\n",
1499                         fname, lineno, 0 );
1500         }
1501
1502         mapping = (struct ldapmapping *)ch_calloc( 2,
1503                 sizeof(struct ldapmapping) );
1504         if ( mapping == NULL ) {
1505                 Debug( LDAP_DEBUG_ANY,
1506                         "%s: line %d: out of memory\n",
1507                         fname, lineno, 0 );
1508                 return 1;
1509         }
1510         ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
1511         ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
1512         mapping[ 1 ].src = mapping[ 0 ].dst;
1513         mapping[ 1 ].dst = mapping[ 0 ].src;
1514
1515         /*
1516          * schema check
1517          */
1518         if ( is_oc ) {
1519                 if ( src[ 0 ] != '\0' ) {
1520                         if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
1521                                 Debug( LDAP_DEBUG_ANY,
1522         "%s: line %d: warning, source objectClass '%s' "
1523         "should be defined in schema\n",
1524                                         fname, lineno, src );
1525
1526                                 /*
1527                                  * FIXME: this should become an err
1528                                  */
1529                                 goto error_return;
1530                         }
1531                 }
1532
1533                 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
1534                         Debug( LDAP_DEBUG_ANY,
1535         "%s: line %d: warning, destination objectClass '%s' "
1536         "is not defined in schema\n",
1537                                 fname, lineno, dst );
1538                 }
1539         } else {
1540                 int                     rc;
1541                 const char              *text = NULL;
1542                 AttributeDescription    *ad = NULL;
1543
1544                 if ( src[ 0 ] != '\0' ) {
1545                         rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
1546                         if ( rc != LDAP_SUCCESS ) {
1547                                 Debug( LDAP_DEBUG_ANY,
1548         "%s: line %d: warning, source attributeType '%s' "
1549         "should be defined in schema\n",
1550                                         fname, lineno, src );
1551
1552                                 /*
1553                                  * FIXME: this should become an err
1554                                  */
1555                                 /*
1556                                  * we create a fake "proxied" ad 
1557                                  * and add it here.
1558                                  */
1559
1560                                 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1561                                                 &ad, &text, SLAP_AD_PROXIED );
1562                                 if ( rc != LDAP_SUCCESS ) {
1563                                         char    buf[ SLAP_TEXT_BUFLEN ];
1564
1565                                         snprintf( buf, sizeof( buf ),
1566                                                 "source attributeType \"%s\": %d (%s)",
1567                                                 src, rc, text ? text : "" );
1568                                         Debug( LDAP_DEBUG_ANY,
1569                                                 "%s: line %d: %s\n",
1570                                                 fname, lineno, buf );
1571                                         goto error_return;
1572                                 }
1573                         }
1574
1575                         ad = NULL;
1576                 }
1577
1578                 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1579                 if ( rc != LDAP_SUCCESS ) {
1580                         Debug( LDAP_DEBUG_ANY,
1581         "%s: line %d: warning, destination attributeType '%s' "
1582         "is not defined in schema\n",
1583                                 fname, lineno, dst );
1584
1585                         /*
1586                          * we create a fake "proxied" ad 
1587                          * and add it here.
1588                          */
1589
1590                         rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1591                                         &ad, &text, SLAP_AD_PROXIED );
1592                         if ( rc != LDAP_SUCCESS ) {
1593                                 char    buf[ SLAP_TEXT_BUFLEN ];
1594
1595                                 snprintf( buf, sizeof( buf ),
1596                                         "source attributeType \"%s\": %d (%s)\n",
1597                                         dst, rc, text ? text : "" );
1598                                 Debug( LDAP_DEBUG_ANY,
1599                                         "%s: line %d: %s\n",
1600                                         fname, lineno, buf );
1601                                 return 1;
1602                         }
1603                 }
1604         }
1605
1606         if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1607                         || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1608         {
1609                 Debug( LDAP_DEBUG_ANY,
1610                         "%s: line %d: duplicate mapping found.\n",
1611                         fname, lineno, 0 );
1612                 goto error_return;
1613         }
1614
1615         if ( src[ 0 ] != '\0' ) {
1616                 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1617                                         mapping_cmp, mapping_dup );
1618         }
1619         avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1620                                 mapping_cmp, mapping_dup );
1621
1622 success_return:;
1623         if ( !is_oc && map->map == NULL ) {
1624                 /* only init if required */
1625                 ldap_back_map_init( map, &mapping );
1626         }
1627
1628         return 0;
1629
1630 error_return:;
1631         if ( mapping ) {
1632                 ch_free( mapping[ 0 ].src.bv_val );
1633                 ch_free( mapping[ 0 ].dst.bv_val );
1634                 ch_free( mapping );
1635         }
1636
1637         return 1;
1638 }
1639
1640
1641 #ifdef ENABLE_REWRITE
1642 static char *
1643 suffix_massage_regexize( const char *s )
1644 {
1645         char *res, *ptr;
1646         const char *p, *r;
1647         int i;
1648
1649         if ( s[ 0 ] == '\0' ) {
1650                 return ch_strdup( "^(.+)$" );
1651         }
1652
1653         for ( i = 0, p = s; 
1654                         ( r = strchr( p, ',' ) ) != NULL; 
1655                         p = r + 1, i++ )
1656                 ;
1657
1658         res = ch_calloc( sizeof( char ),
1659                         strlen( s )
1660                         + STRLENOF( "((.+),)?" )
1661                         + STRLENOF( "[ ]?" ) * i
1662                         + STRLENOF( "$" ) + 1 );
1663
1664         ptr = lutil_strcopy( res, "((.+),)?" );
1665         for ( i = 0, p = s;
1666                         ( r = strchr( p, ',' ) ) != NULL;
1667                         p = r + 1 , i++ ) {
1668                 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1669                 ptr = lutil_strcopy( ptr, "[ ]?" );
1670
1671                 if ( r[ 1 ] == ' ' ) {
1672                         r++;
1673                 }
1674         }
1675         ptr = lutil_strcopy( ptr, p );
1676         ptr[ 0 ] = '$';
1677         ptr++;
1678         ptr[ 0 ] = '\0';
1679
1680         return res;
1681 }
1682
1683 static char *
1684 suffix_massage_patternize( const char *s, const char *p )
1685 {
1686         ber_len_t       len;
1687         char            *res, *ptr;
1688
1689         len = strlen( p );
1690
1691         if ( s[ 0 ] == '\0' ) {
1692                 len++;
1693         }
1694
1695         res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1696         if ( res == NULL ) {
1697                 return NULL;
1698         }
1699
1700         ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1701         if ( s[ 0 ] == '\0' ) {
1702                 ptr[ 0 ] = ',';
1703                 ptr++;
1704         }
1705         lutil_strcopy( ptr, p );
1706
1707         return res;
1708 }
1709
1710 int
1711 suffix_massage_config( 
1712                 struct rewrite_info *info,
1713                 struct berval *pvnc,
1714                 struct berval *nvnc,
1715                 struct berval *prnc,
1716                 struct berval *nrnc
1717 )
1718 {
1719         char *rargv[ 5 ];
1720         int line = 0;
1721
1722         rargv[ 0 ] = "rewriteEngine";
1723         rargv[ 1 ] = "on";
1724         rargv[ 2 ] = NULL;
1725         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1726
1727         rargv[ 0 ] = "rewriteContext";
1728         rargv[ 1 ] = "default";
1729         rargv[ 2 ] = NULL;
1730         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1731
1732         rargv[ 0 ] = "rewriteRule";
1733         rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1734         rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1735         rargv[ 3 ] = ":";
1736         rargv[ 4 ] = NULL;
1737         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1738         ch_free( rargv[ 1 ] );
1739         ch_free( rargv[ 2 ] );
1740
1741         if ( BER_BVISEMPTY( pvnc ) ) {
1742                 rargv[ 0 ] = "rewriteRule";
1743                 rargv[ 1 ] = "^$";
1744                 rargv[ 2 ] = prnc->bv_val;
1745                 rargv[ 3 ] = ":";
1746                 rargv[ 4 ] = NULL;
1747                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1748         }
1749         
1750         rargv[ 0 ] = "rewriteContext";
1751         rargv[ 1 ] = "searchEntryDN";
1752         rargv[ 2 ] = NULL;
1753         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1754
1755         rargv[ 0 ] = "rewriteRule";
1756         rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1757         rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1758         rargv[ 3 ] = ":";
1759         rargv[ 4 ] = NULL;
1760         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1761         ch_free( rargv[ 1 ] );
1762         ch_free( rargv[ 2 ] );
1763
1764         if ( BER_BVISEMPTY( prnc ) ) {
1765                 rargv[ 0 ] = "rewriteRule";
1766                 rargv[ 1 ] = "^$";
1767                 rargv[ 2 ] = pvnc->bv_val;
1768                 rargv[ 3 ] = ":";
1769                 rargv[ 4 ] = NULL;
1770                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1771         }
1772         
1773         /* backward compatibility */
1774         rargv[ 0 ] = "rewriteContext";
1775         rargv[ 1 ] = "searchResult";
1776         rargv[ 2 ] = "alias";
1777         rargv[ 3 ] = "searchEntryDN";
1778         rargv[ 4 ] = NULL;
1779         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1780         
1781         rargv[ 0 ] = "rewriteContext";
1782         rargv[ 1 ] = "matchedDN";
1783         rargv[ 2 ] = "alias";
1784         rargv[ 3 ] = "searchEntryDN";
1785         rargv[ 4 ] = NULL;
1786         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1787
1788         rargv[ 0 ] = "rewriteContext";
1789         rargv[ 1 ] = "searchAttrDN";
1790         rargv[ 2 ] = "alias";
1791         rargv[ 3 ] = "searchEntryDN";
1792         rargv[ 4 ] = NULL;
1793         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1794
1795         /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1796          * see servers/slapd/overlays/rwm.h for details */
1797         rargv[ 0 ] = "rewriteContext";
1798         rargv[ 1 ] = "referralAttrDN";
1799         rargv[ 2 ] = NULL;
1800         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1801
1802         rargv[ 0 ] = "rewriteContext";
1803         rargv[ 1 ] = "referralDN";
1804         rargv[ 2 ] = NULL;
1805         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1806         
1807         return 0;
1808 }
1809 #endif /* ENABLE_REWRITE */
1810