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