]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/config.c
ea78c2037b6b6ce344b9f67a23759c526d6f3361
[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-2005 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 new_target( 
39         metatarget_t    *mt )
40 {
41         struct ldapmapping      *mapping;
42         char                    *rargv[ 3 ];
43
44         memset( mt, 0, sizeof( metatarget_t ) );
45
46         mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
47         if ( mt->mt_rwmap.rwm_rw == NULL ) {
48                 return -1;
49         }
50
51
52         /*
53          * the filter rewrite as a string must be disabled
54          * by default; it can be re-enabled by adding rules;
55          * this creates an empty rewriteContext
56          */
57         rargv[ 0 ] = "rewriteContext";
58         rargv[ 1 ] = "searchFilter";
59         rargv[ 2 ] = NULL;
60         rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
61
62         rargv[ 0 ] = "rewriteContext";
63         rargv[ 1 ] = "default";
64         rargv[ 2 ] = NULL;
65         rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
66
67         ldap_back_map_init( &mt->mt_rwmap.rwm_at, &mapping );
68
69         return 0;
70 }
71
72 static int
73 check_true_false( char *str )
74 {
75         if ( strcasecmp( str, "true" ) == 0 || strcasecmp( str, "yes" ) == 0 ) {
76                 return 1;
77         }
78
79         if ( strcasecmp( str, "false" ) == 0 || strcasecmp( str, "no" ) == 0 ) {
80                 return 0;
81         }
82
83         return -1;
84 }
85
86
87 int
88 meta_back_db_config(
89                 BackendDB       *be,
90                 const char      *fname,
91                 int             lineno,
92                 int             argc,
93                 char            **argv
94 )
95 {
96         metainfo_t      *mi = ( metainfo_t * )be->be_private;
97
98         assert( mi != NULL );
99
100         /* URI of server to query */
101         if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
102                 int             i = mi->mi_ntargets;
103 #if 0
104                 int             j;
105 #endif /* uncomment if uri MUST be a branch of suffix */
106                 LDAPURLDesc     *ludp, *tmpludp;
107                 struct berval   dn;
108                 int             rc;
109                 int             c;
110                 
111                 switch ( argc ) {
112                 case 1:
113                         Debug( LDAP_DEBUG_ANY,
114         "%s: line %d: missing URI "
115         "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
116                                 fname, lineno, 0 );
117                         return 1;
118
119                 case 2:
120                         break;
121
122                 default:
123                         Debug( LDAP_DEBUG_ANY,
124         "%s: line %d: too many args "
125         "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
126                                 fname, lineno, 0 );
127                         return 1;
128                 }
129
130                 if ( be->be_nsuffix == NULL ) {
131                         Debug( LDAP_DEBUG_ANY,
132         "%s: line %d: the suffix must be defined before any target.\n",
133                                 fname, lineno, 0 );
134                         return 1;
135                 }
136                 
137                 ++mi->mi_ntargets;
138
139                 mi->mi_targets = ( metatarget_t * )ch_realloc( mi->mi_targets, 
140                         sizeof( metatarget_t ) * mi->mi_ntargets );
141                 if ( mi->mi_targets == NULL ) {
142                         Debug( LDAP_DEBUG_ANY,
143         "%s: line %d: out of memory while storing server name"
144         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
145                                 fname, lineno, 0 );
146                         return 1;
147                 }
148
149                 if ( new_target( &mi->mi_targets[ i ] ) != 0 ) {
150                         Debug( LDAP_DEBUG_ANY,
151         "%s: line %d: unable to init server"
152         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
153                                 fname, lineno, 0 );
154                         return 1;
155                 }
156
157                 mi->mi_targets[ i ].mt_nretries = mi->mi_nretries;
158                 mi->mi_targets[ i ].mt_flags = mi->mi_flags;
159                 mi->mi_targets[ i ].mt_version = mi->mi_version;
160
161                 for ( c = 0; c < LDAP_BACK_OP_LAST; c++ ) {
162                         mi->mi_targets[ i ].mt_timeout[ c ] = mi->mi_timeout[ c ];
163                 }
164
165                 /*
166                  * uri MUST be legal!
167                  */
168                 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t" ) != LDAP_SUCCESS ) {
169                         Debug( LDAP_DEBUG_ANY,
170         "%s: line %d: unable to parse URI"
171         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
172                                 fname, lineno, 0 );
173                         return 1;
174                 }
175
176                 /*
177                  * uri MUST have the <dn> part!
178                  */
179                 if ( ludp->lud_dn == NULL ) {
180                         Debug( LDAP_DEBUG_ANY,
181         "%s: line %d: missing <naming context> "
182         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
183                                 fname, lineno, 0 );
184                         return 1;
185
186                 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
187                         int     j = -1;
188
189                         for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
190                                 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
191                                         break;
192                                 }
193                         }
194
195                         if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
196                                 Debug( LDAP_DEBUG_ANY,
197                 "%s: line %d: missing <naming context> "
198                 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
199                                         fname, lineno, 0 );
200                                 return 1;
201                         }
202                 }
203
204                 /*
205                  * copies and stores uri and suffix
206                  */
207                 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
208                 rc = dnPrettyNormal( NULL, &dn, &mi->mi_targets[ i ].mt_psuffix,
209                         &mi->mi_targets[ i ].mt_nsuffix, NULL );
210                 if( rc != LDAP_SUCCESS ) {
211                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
212                                 "target \"%s\" DN is invalid\n",
213                                 fname, lineno, argv[ 1 ] );
214                         return( 1 );
215                 }
216
217                 ludp->lud_dn[ 0 ] = '\0';
218
219                 switch ( ludp->lud_scope ) {
220                 case LDAP_SCOPE_DEFAULT:
221                         mi->mi_targets[ i ].mt_scope = LDAP_SCOPE_SUBTREE;
222                         break;
223
224                 case LDAP_SCOPE_SUBTREE:
225 #ifdef LDAP_SCOPE_SUBORDINATE
226                 case LDAP_SCOPE_SUBORDINATE:
227 #endif /* LDAP_SCOPE_SUBORDINATE */
228                         mi->mi_targets[ i ].mt_scope = ludp->lud_scope;
229                         break;
230
231                 default:
232                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
233                                 "invalid scope for target \"%s\"\n",
234                                 fname, lineno, argv[ 1 ] );
235                         return( 1 );
236                 }
237
238                 /* check all, to apply the scope check on the first one */
239                 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
240                         if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
241                                 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
242                                         "multiple URIs must have "
243                                         "no DN part\n",
244                                         fname, lineno, 0 );
245                                 return( 1 );
246
247                         }
248                 }
249
250                 mi->mi_targets[ i ].mt_uri = ldap_url_list2urls( ludp );
251                 ldap_free_urllist( ludp );
252                 if ( mi->mi_targets[ i ].mt_uri == NULL) {
253                         Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
254                                 fname, lineno, 0 );
255                         return( 1 );
256                 }
257                 
258                 /*
259                  * uri MUST be a branch of suffix!
260                  */
261 #if 0 /* too strict a constraint */
262                 if ( select_backend( &mi->mi_targets[ i ].suffix, 0, 0 ) != be ) {
263                         Debug( LDAP_DEBUG_ANY,
264         "%s: line %d: <naming context> of URI does not refer to current backend"
265         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
266                                 fname, lineno, 0 );
267                         return 1;
268                 }
269 #else
270                 /*
271                  * uri MUST be a branch of a suffix!
272                  */
273                 if ( select_backend( &mi->mi_targets[ i ].mt_nsuffix, 0, 0 ) == NULL ) {
274                         Debug( LDAP_DEBUG_ANY,
275         "%s: line %d: <naming context> of URI does not resolve to a backend"
276         " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
277                                 fname, lineno, 0 );
278                         return 1;
279                 }
280 #endif
281
282         /* default target directive */
283         } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
284                 int             i = mi->mi_ntargets - 1;
285                 
286                 if ( argc == 1 ) {
287                         if ( i < 0 ) {
288                                 Debug( LDAP_DEBUG_ANY,
289         "%s: line %d: \"default-target\" alone need be"
290         " inside a \"uri\" directive\n",
291                                         fname, lineno, 0 );
292                                 return 1;
293                         }
294                         mi->mi_defaulttarget = i;
295
296                 } else {
297                         if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
298                                 if ( i >= 0 ) {
299                                         Debug( LDAP_DEBUG_ANY,
300         "%s: line %d: \"default-target none\""
301         " should go before uri definitions\n",
302                                                 fname, lineno, 0 );
303                                 }
304                                 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
305
306                         } else {
307                                 
308                                 if ( lutil_atoi( &mi->mi_defaulttarget, argv[ 1 ] ) != 0
309                                         || mi->mi_defaulttarget < 0
310                                         || mi->mi_defaulttarget >= i - 1 )
311                                 {
312                                         Debug( LDAP_DEBUG_ANY,
313         "%s: line %d: illegal target number %d\n",
314                                                 fname, lineno, mi->mi_defaulttarget );
315                                         return 1;
316                                 }
317                         }
318                 }
319                 
320         /* ttl of dn cache */
321         } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
322                 if ( argc != 2 ) {
323                         Debug( LDAP_DEBUG_ANY,
324         "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
325                                 fname, lineno, 0 );
326                         return 1;
327                 }
328                 
329                 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
330                         mi->mi_cache.ttl = META_DNCACHE_FOREVER;
331
332                 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
333                         mi->mi_cache.ttl = META_DNCACHE_DISABLED;
334
335                 } else {
336                         unsigned long   t;
337
338                         if ( lutil_parse_time( argv[ 1 ], &t ) != 0 ) {
339                                 Debug( LDAP_DEBUG_ANY,
340         "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
341                                         fname, lineno, argv[ 1 ] );
342                                 return 1;
343                         }
344                         mi->mi_cache.ttl = (time_t)t;
345                 }
346
347         /* network timeout when connecting to ldap servers */
348         } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
349                 unsigned long   t;
350
351                 if ( argc != 2 ) {
352                         Debug( LDAP_DEBUG_ANY,
353         "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
354                                 fname, lineno, 0 );
355                         return 1;
356                 }
357
358                 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
359                         Debug( LDAP_DEBUG_ANY,
360         "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
361                                 fname, lineno, argv[ 1 ] );
362                         return 1;
363
364                 }
365
366                 mi->mi_network_timeout = (int)t;
367
368         /* name to use for meta_back_group */
369         } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
370                         || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
371         {
372                 int             i = mi->mi_ntargets - 1;
373                 struct berval   dn;
374
375                 if ( i < 0 ) {
376                         Debug( LDAP_DEBUG_ANY,
377         "%s: line %d: need \"uri\" directive first\n",
378                                 fname, lineno, 0 );
379                         return 1;
380                 }
381                 
382                 if ( argc != 2 ) {
383                         Debug( LDAP_DEBUG_ANY,
384         "%s: line %d: missing name in \"binddn <name>\" line\n",
385                                 fname, lineno, 0 );
386                         return 1;
387                 }
388
389                 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
390                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
391                                 "\"binddn\" statement is deprecated; "
392                                 "use \"acl-authcDN\" instead\n",
393                                 fname, lineno, 0 );
394                         /* FIXME: some day we'll need to throw an error */
395                 }
396
397                 dn.bv_val = argv[ 1 ];
398                 dn.bv_len = strlen( argv[ 1 ] );
399                 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ].mt_binddn,
400                         NULL ) != LDAP_SUCCESS )
401                 {
402                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
403                                         "bind DN '%s' is invalid\n",
404                                         fname, lineno, argv[ 1 ] );
405                         return( 1 );
406                 }
407
408         /* password to use for meta_back_group */
409         } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
410                         || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
411         {
412                 int             i = mi->mi_ntargets - 1;
413
414                 if ( i < 0 ) {
415                         Debug( LDAP_DEBUG_ANY,
416         "%s: line %d: need \"uri\" directive first\n",
417                                 fname, lineno, 0 );
418                         return 1;
419                 }
420                 
421                 if ( argc != 2 ) {
422                         Debug( LDAP_DEBUG_ANY,
423         "%s: line %d: missing password in \"bindpw <password>\" line\n",
424                             fname, lineno, 0 );
425                         return 1;
426                 }
427
428                 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
429                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
430                                 "\"bindpw\" statement is deprecated; "
431                                 "use \"acl-passwd\" instead\n",
432                                 fname, lineno, 0 );
433                         /* FIXME: some day we'll need to throw an error */
434                 }
435
436                 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_bindpw );
437                 
438         /* save bind creds for referral rebinds? */
439         } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
440                 if ( argc > 2 ) {
441                         Debug( LDAP_DEBUG_ANY,
442         "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
443                             fname, lineno, 0 );
444                         return( 1 );
445                 }
446
447                 if ( argc == 1 ) {
448                         Debug( LDAP_DEBUG_ANY,
449         "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
450                             fname, lineno, 0 );
451                         mi->mi_flags |= LDAP_BACK_F_SAVECRED;
452
453                 } else {
454                         switch ( check_true_false( argv[ 1 ] ) ) {
455                         case 0:
456                                 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
457                                 break;
458
459                         case 1:
460                                 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
461                                 break;
462
463                         default:
464                                 Debug( LDAP_DEBUG_ANY,
465         "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
466                                     fname, lineno, argv[ 1 ] );
467                                 return 1;
468                         }
469                 }
470
471         } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
472                 unsigned        *flagsp = mi->mi_ntargets ?
473                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
474                                 : &mi->mi_flags;
475
476                 if ( argc != 2 ) {
477                         Debug( LDAP_DEBUG_ANY,
478         "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
479                                 fname, lineno, 0 );
480                         return( 1 );
481                 }
482
483                 /* this is the default; we add it because the default might change... */
484                 switch ( check_true_false( argv[ 1 ] ) ) {
485                 case 1:
486                         *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
487                         break;
488
489                 case 0:
490                         *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
491                         break;
492
493                 default:
494                         Debug( LDAP_DEBUG_ANY,
495                 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
496                                 fname, lineno, argv[ 1 ] );
497                         return( 1 );
498                 }
499         
500         } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
501                 unsigned        *flagsp = mi->mi_ntargets ?
502                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
503                                 : &mi->mi_flags;
504
505                 if ( argc != 2 ) {
506                         Debug( LDAP_DEBUG_ANY,
507                 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
508                                 fname, lineno, 0 );
509                         return( 1 );
510                 }
511
512                 /* start */
513                 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
514                         *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
515         
516                 /* try start tls */
517                 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
518                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
519                         *flagsp |= LDAP_BACK_F_USE_TLS;
520         
521                 /* propagate start tls */
522                 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
523                         *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
524                 
525                 /* try start tls */
526                 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
527                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
528                         *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
529
530                 } else {
531                         Debug( LDAP_DEBUG_ANY,
532                 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
533                                 fname, lineno, argv[ 1 ] );
534                         return( 1 );
535                 }
536
537         } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
538                 unsigned        *flagsp = mi->mi_ntargets ?
539                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
540                                 : &mi->mi_flags;
541
542                 if ( argc != 2 ) {
543                         Debug( LDAP_DEBUG_ANY,
544                 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
545                                 fname, lineno, 0 );
546                         return( 1 );
547                 }
548
549                 switch ( check_true_false( argv[ 1 ] ) ) {
550                 case 0:
551                         *flagsp &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
552                         break;
553
554                 case 1:
555                         *flagsp |= LDAP_BACK_F_SUPPORT_T_F;
556                         break;
557
558                 default:
559                         if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
560                                 *flagsp |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
561
562                         } else {
563                                 Debug( LDAP_DEBUG_ANY,
564         "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
565                                         fname, lineno, argv[ 1 ] );
566                                 return 1;
567                         }
568                         break;
569                 }
570
571         /* onerr? */
572         } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
573                 if ( argc != 2 ) {
574                         Debug( LDAP_DEBUG_ANY,
575         "%s: line %d: \"onerr {CONTINUE|stop}\" takes 1 argument\n",
576                                 fname, lineno, 0 );
577                         return( 1 );
578                 }
579
580                 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
581                         mi->mi_flags &= ~META_BACK_F_ONERR_STOP;
582
583                 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
584                         mi->mi_flags |= META_BACK_F_ONERR_STOP;
585
586                 } else {
587                         Debug( LDAP_DEBUG_ANY,
588         "%s: line %d: \"onerr {CONTINUE|stop}\": invalid arg \"%s\".\n",
589                                 fname, lineno, argv[ 1 ] );
590                         return 1;
591                 }
592
593         /* bind-defer? */
594         } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0 ) {
595                 if ( argc != 2 ) {
596                         Debug( LDAP_DEBUG_ANY,
597         "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\" takes 1 argument\n",
598                                 fname, lineno, 0 );
599                         return( 1 );
600                 }
601
602                 switch ( check_true_false( argv[ 1 ] ) ) {
603                 case 0:
604                         mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
605                         break;
606
607                 case 1:
608                         mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
609                         break;
610
611                 default:
612                         Debug( LDAP_DEBUG_ANY,
613         "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
614                                 fname, lineno, argv[ 1 ] );
615                         return 1;
616                 }
617
618         } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
619                 char    *sep;
620                 time_t  *tv = mi->mi_ntargets ?
621                                 mi->mi_targets[ mi->mi_ntargets - 1 ].mt_timeout
622                                 : mi->mi_timeout;
623                 int     c;
624
625                 if ( argc < 2 ) {
626                         Debug( LDAP_DEBUG_ANY,
627         "%s: line %d: \"timeout [{add|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
628                                 fname, lineno, 0 );
629                         return( 1 );
630                 }
631
632                 for ( c = 1; c < argc; c++ ) {
633                         time_t          *t = NULL;
634                         unsigned long   val;
635
636                         sep = strchr( argv[ c ], '=' );
637                         if ( sep != NULL ) {
638                                 size_t  len = sep - argv[ c ];
639
640                                 if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
641                                         t = &tv[ LDAP_BACK_OP_ADD ];
642                                 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
643                                         t = &tv[ LDAP_BACK_OP_DELETE ];
644                                 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
645                                         t = &tv[ LDAP_BACK_OP_MODIFY ];
646                                 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
647                                         t = &tv[ LDAP_BACK_OP_MODRDN ];
648                                 } else {
649                                         char    buf[ SLAP_TEXT_BUFLEN ];
650                                         snprintf( buf, sizeof( buf ),
651                                                 "unknown operation \"%s\" for timeout #%d",
652                                                 argv[ c ], c );
653                                         Debug( LDAP_DEBUG_ANY,
654                                                 "%s: line %d: %s.\n",
655                                                 fname, lineno, buf );
656                                         return 1;
657                                 }
658                                 sep++;
659         
660                         } else {
661                                 sep = argv[ c ];
662                         }
663         
664                         if ( lutil_parse_time( sep, &val ) != 0 ) {
665                                 Debug( LDAP_DEBUG_ANY,
666                 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
667                                         fname, lineno, sep );
668                                 return 1;
669                         }
670                 
671                         if ( t ) {
672                                 *t = (time_t)val;
673         
674                         } else {
675                                 int     i;
676         
677                                 for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
678                                         tv[ i ] = (time_t)val;
679                                 }
680                         }
681                 }
682         
683         /* name to use as pseudo-root dn */
684         } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
685                 int             i = mi->mi_ntargets - 1;
686                 struct berval   dn;
687
688                 if ( i < 0 ) {
689                         Debug( LDAP_DEBUG_ANY,
690         "%s: line %d: need \"uri\" directive first\n",
691                                 fname, lineno, 0 );
692                         return 1;
693                 }
694                 
695                 if ( argc != 2 ) {
696                         Debug( LDAP_DEBUG_ANY,
697         "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
698                                 fname, lineno, 0 );
699                         return 1;
700                 }
701
702                 dn.bv_val = argv[ 1 ];
703                 dn.bv_len = strlen( argv[ 1 ] );
704                 if ( dnNormalize( 0, NULL, NULL, &dn,
705                         &mi->mi_targets[ i ].mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
706                 {
707                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
708                                         "pseudoroot DN '%s' is invalid\n",
709                                         fname, lineno, argv[ 1 ] );
710                         return( 1 );
711                 }
712
713         /* password to use as pseudo-root */
714         } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
715                 int             i = mi->mi_ntargets - 1;
716
717                 if ( i < 0 ) {
718                         Debug( LDAP_DEBUG_ANY,
719         "%s: line %d: need \"uri\" directive first\n",
720                                 fname, lineno, 0 );
721                         return 1;
722                 }
723                 
724                 if ( argc != 2 ) {
725                         Debug( LDAP_DEBUG_ANY,
726         "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
727                             fname, lineno, 0 );
728                         return 1;
729                 }
730                 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_pseudorootpw );
731         
732         /* dn massaging */
733         } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
734                 BackendDB       *tmp_be;
735                 int             i = mi->mi_ntargets - 1, rc;
736                 struct berval   dn, nvnc, pvnc, nrnc, prnc;
737
738                 if ( i < 0 ) {
739                         Debug( LDAP_DEBUG_ANY,
740         "%s: line %d: need \"uri\" directive first\n",
741                                 fname, lineno, 0 );
742                         return 1;
743                 }
744                 
745                 /*
746                  * syntax:
747                  * 
748                  *      suffixmassage <suffix> <massaged suffix>
749                  *
750                  * the <suffix> field must be defined as a valid suffix
751                  * (or suffixAlias?) for the current database;
752                  * the <massaged suffix> shouldn't have already been
753                  * defined as a valid suffix or suffixAlias for the 
754                  * current server
755                  */
756                 if ( argc != 3 ) {
757                         Debug( LDAP_DEBUG_ANY,
758         "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
759                                 fname, lineno, 0 );
760                         return 1;
761                 }
762
763                 ber_str2bv( argv[ 1 ], 0, 0, &dn );
764                 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
765                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
766                                         "suffix '%s' is invalid\n",
767                                         fname, lineno, argv[ 1 ] );
768                         return 1;
769                 }
770                 
771                 tmp_be = select_backend( &nvnc, 0, 0 );
772                 if ( tmp_be != NULL && tmp_be != be ) {
773                         Debug( LDAP_DEBUG_ANY, 
774         "%s: line %d: suffix already in use by another backend in"
775         " \"suffixMassage <suffix> <massaged suffix>\"\n",
776                                 fname, lineno, 0 );
777                         free( pvnc.bv_val );
778                         free( nvnc.bv_val );
779                         return 1;                                               
780                 }
781
782                 ber_str2bv( argv[ 2 ], 0, 0, &dn );
783                 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
784                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
785                                 "massaged suffix '%s' is invalid\n",
786                                 fname, lineno, argv[ 2 ] );
787                         free( pvnc.bv_val );
788                         free( nvnc.bv_val );
789                         return 1;
790                 }
791         
792 #if 0   
793                 tmp_be = select_backend( &nrnc, 0, 0 );
794                 if ( tmp_be != NULL ) {
795                         Debug( LDAP_DEBUG_ANY,
796         "%s: line %d: massaged suffix already in use by another backend in" 
797         " \"suffixMassage <suffix> <massaged suffix>\"\n",
798                                 fname, lineno, 0 );
799                         free( pvnc.bv_val );
800                         free( nvnc.bv_val );
801                         free( prnc.bv_val );
802                         free( nrnc.bv_val );
803                         return 1;
804                 }
805 #endif
806                 
807                 /*
808                  * The suffix massaging is emulated by means of the
809                  * rewrite capabilities
810                  * FIXME: no extra rewrite capabilities should be added
811                  * to the database
812                  */
813                 rc = suffix_massage_config( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
814                                 &pvnc, &nvnc, &prnc, &nrnc );
815
816                 free( pvnc.bv_val );
817                 free( nvnc.bv_val );
818                 free( prnc.bv_val );
819                 free( nrnc.bv_val );
820
821                 return rc;
822                 
823         /* rewrite stuff ... */
824         } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
825                 int             i = mi->mi_ntargets - 1;
826
827                 if ( i < 0 ) {
828                         Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
829                                 "statement outside target definition.\n",
830                                 fname, lineno, 0 );
831                         return 1;
832                 }
833                 
834                 return rewrite_parse( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
835                                 fname, lineno, argc, argv );
836
837         /* objectclass/attribute mapping */
838         } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
839                 int             i = mi->mi_ntargets - 1;
840
841                 if ( i < 0 ) {
842                         Debug( LDAP_DEBUG_ANY,
843         "%s: line %d: need \"uri\" directive first\n",
844                                 fname, lineno, 0 );
845                         return 1;
846                 }
847
848                 return ldap_back_map_config( &mi->mi_targets[ i ].mt_rwmap.rwm_oc, 
849                                 &mi->mi_targets[ i ].mt_rwmap.rwm_at,
850                                 fname, lineno, argc, argv );
851
852         } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
853                 int             i = mi->mi_ntargets - 1;
854                 int             nretries = META_RETRY_UNDEFINED;
855
856                 if ( argc != 2 ) {
857                         Debug( LDAP_DEBUG_ANY,
858         "%s: line %d: need value in \"nretries <value>\"\n",
859                                 fname, lineno, 0 );
860                         return 1;
861                 }
862
863                 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
864                         nretries = META_RETRY_FOREVER;
865
866                 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
867                         nretries = META_RETRY_NEVER;
868
869                 } else {
870                         if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
871                                 Debug( LDAP_DEBUG_ANY,
872         "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
873                                         fname, lineno, argv[ 1 ] );
874                                 return 1;
875                         }
876                 }
877
878                 if ( i < 0 ) {
879                         mi->mi_nretries = nretries;
880
881                 } else {
882                         mi->mi_targets[ i ].mt_nretries = nretries;
883                 }
884
885         /* anything else */
886         } else {
887                 return SLAP_CONF_UNKNOWN;
888         }
889         return 0;
890 }
891
892 int
893 ldap_back_map_config(
894                 struct ldapmap  *oc_map,
895                 struct ldapmap  *at_map,
896                 const char      *fname,
897                 int             lineno,
898                 int             argc,
899                 char            **argv )
900 {
901         struct ldapmap          *map;
902         struct ldapmapping      *mapping;
903         char                    *src, *dst;
904         int                     is_oc = 0;
905
906         if ( argc < 3 || argc > 4 ) {
907                 Debug( LDAP_DEBUG_ANY,
908         "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
909                         fname, lineno, 0 );
910                 return 1;
911         }
912
913         if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
914                 map = oc_map;
915                 is_oc = 1;
916
917         } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
918                 map = at_map;
919
920         } else {
921                 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
922                         "\"map {objectclass | attribute} [<local> | *] "
923                         "{<foreign> | *}\"\n",
924                         fname, lineno, 0 );
925                 return 1;
926         }
927
928         if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
929                 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
930                         map->drop_missing = ( argc < 4 );
931                         return 0;
932                 }
933                 src = dst = argv[ 3 ];
934
935         } else if ( argc < 4 ) {
936                 src = "";
937                 dst = argv[ 2 ];
938
939         } else {
940                 src = argv[ 2 ];
941                 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
942         }
943
944         if ( ( map == at_map )
945                         && ( strcasecmp( src, "objectclass" ) == 0
946                         || strcasecmp( dst, "objectclass" ) == 0 ) )
947         {
948                 Debug( LDAP_DEBUG_ANY,
949                         "%s: line %d: objectclass attribute cannot be mapped\n",
950                         fname, lineno, 0 );
951         }
952
953         mapping = (struct ldapmapping *)ch_calloc( 2,
954                 sizeof(struct ldapmapping) );
955         if ( mapping == NULL ) {
956                 Debug( LDAP_DEBUG_ANY,
957                         "%s: line %d: out of memory\n",
958                         fname, lineno, 0 );
959                 return 1;
960         }
961         ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
962         ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
963         mapping[ 1 ].src = mapping[ 0 ].dst;
964         mapping[ 1 ].dst = mapping[ 0 ].src;
965
966         /*
967          * schema check
968          */
969         if ( is_oc ) {
970                 if ( src[ 0 ] != '\0' ) {
971                         if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
972                                 Debug( LDAP_DEBUG_ANY,
973         "%s: line %d: warning, source objectClass '%s' "
974         "should be defined in schema\n",
975                                         fname, lineno, src );
976
977                                 /*
978                                  * FIXME: this should become an err
979                                  */
980                                 goto error_return;
981                         }
982                 }
983
984                 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
985                         Debug( LDAP_DEBUG_ANY,
986         "%s: line %d: warning, destination objectClass '%s' "
987         "is not defined in schema\n",
988                                 fname, lineno, dst );
989                 }
990         } else {
991                 int                     rc;
992                 const char              *text = NULL;
993                 AttributeDescription    *ad = NULL;
994
995                 if ( src[ 0 ] != '\0' ) {
996                         rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
997                         if ( rc != LDAP_SUCCESS ) {
998                                 Debug( LDAP_DEBUG_ANY,
999         "%s: line %d: warning, source attributeType '%s' "
1000         "should be defined in schema\n",
1001                                         fname, lineno, src );
1002
1003                                 /*
1004                                  * FIXME: this should become an err
1005                                  */
1006                                 /*
1007                                  * we create a fake "proxied" ad 
1008                                  * and add it here.
1009                                  */
1010
1011                                 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1012                                                 &ad, &text, SLAP_AD_PROXIED );
1013                                 if ( rc != LDAP_SUCCESS ) {
1014                                         char    buf[ SLAP_TEXT_BUFLEN ];
1015
1016                                         snprintf( buf, sizeof( buf ),
1017                                                 "source attributeType \"%s\": %d (%s)",
1018                                                 src, rc, text ? text : "" );
1019                                         Debug( LDAP_DEBUG_ANY,
1020                                                 "%s: line %d: %s\n",
1021                                                 fname, lineno, buf );
1022                                         goto error_return;
1023                                 }
1024                         }
1025
1026                         ad = NULL;
1027                 }
1028
1029                 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1030                 if ( rc != LDAP_SUCCESS ) {
1031                         Debug( LDAP_DEBUG_ANY,
1032         "%s: line %d: warning, destination attributeType '%s' "
1033         "is not defined in schema\n",
1034                                 fname, lineno, dst );
1035
1036                         /*
1037                          * we create a fake "proxied" ad 
1038                          * and add it here.
1039                          */
1040
1041                         rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1042                                         &ad, &text, SLAP_AD_PROXIED );
1043                         if ( rc != LDAP_SUCCESS ) {
1044                                 char    buf[ SLAP_TEXT_BUFLEN ];
1045
1046                                 snprintf( buf, sizeof( buf ),
1047                                         "source attributeType \"%s\": %d (%s)\n",
1048                                         dst, rc, text ? text : "" );
1049                                 Debug( LDAP_DEBUG_ANY,
1050                                         "%s: line %d: %s\n",
1051                                         fname, lineno, buf );
1052                                 return 1;
1053                         }
1054                 }
1055         }
1056
1057         if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1058                         || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1059         {
1060                 Debug( LDAP_DEBUG_ANY,
1061                         "%s: line %d: duplicate mapping found" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1062                         fname, lineno, 0 );
1063                 goto error_return;
1064         }
1065
1066         if ( src[ 0 ] != '\0' ) {
1067                 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1068                                         mapping_cmp, mapping_dup );
1069         }
1070         avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1071                                 mapping_cmp, mapping_dup );
1072
1073         return 0;
1074
1075 error_return:;
1076         if ( mapping ) {
1077                 ch_free( mapping[ 0 ].src.bv_val );
1078                 ch_free( mapping[ 0 ].dst.bv_val );
1079                 ch_free( mapping );
1080         }
1081
1082         return 1;
1083 }
1084
1085
1086 #ifdef ENABLE_REWRITE
1087 static char *
1088 suffix_massage_regexize( const char *s )
1089 {
1090         char *res, *ptr;
1091         const char *p, *r;
1092         int i;
1093
1094         if ( s[ 0 ] == '\0' ) {
1095                 return ch_strdup( "^(.+)$" );
1096         }
1097
1098         for ( i = 0, p = s; 
1099                         ( r = strchr( p, ',' ) ) != NULL; 
1100                         p = r + 1, i++ )
1101                 ;
1102
1103         res = ch_calloc( sizeof( char ),
1104                         strlen( s )
1105                         + STRLENOF( "((.+),)?" )
1106                         + STRLENOF( "[ ]?" ) * i
1107                         + STRLENOF( "$" ) + 1 );
1108
1109         ptr = lutil_strcopy( res, "((.+),)?" );
1110         for ( i = 0, p = s;
1111                         ( r = strchr( p, ',' ) ) != NULL;
1112                         p = r + 1 , i++ ) {
1113                 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1114                 ptr = lutil_strcopy( ptr, "[ ]?" );
1115
1116                 if ( r[ 1 ] == ' ' ) {
1117                         r++;
1118                 }
1119         }
1120         ptr = lutil_strcopy( ptr, p );
1121         ptr[ 0 ] = '$';
1122         ptr++;
1123         ptr[ 0 ] = '\0';
1124
1125         return res;
1126 }
1127
1128 static char *
1129 suffix_massage_patternize( const char *s, const char *p )
1130 {
1131         ber_len_t       len;
1132         char            *res, *ptr;
1133
1134         len = strlen( p );
1135
1136         if ( s[ 0 ] == '\0' ) {
1137                 len++;
1138         }
1139
1140         res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1141         if ( res == NULL ) {
1142                 return NULL;
1143         }
1144
1145         ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1146         if ( s[ 0 ] == '\0' ) {
1147                 ptr[ 0 ] = ',';
1148                 ptr++;
1149         }
1150         lutil_strcopy( ptr, p );
1151
1152         return res;
1153 }
1154
1155 int
1156 suffix_massage_config( 
1157                 struct rewrite_info *info,
1158                 struct berval *pvnc,
1159                 struct berval *nvnc,
1160                 struct berval *prnc,
1161                 struct berval *nrnc
1162 )
1163 {
1164         char *rargv[ 5 ];
1165         int line = 0;
1166
1167         rargv[ 0 ] = "rewriteEngine";
1168         rargv[ 1 ] = "on";
1169         rargv[ 2 ] = NULL;
1170         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1171
1172         rargv[ 0 ] = "rewriteContext";
1173         rargv[ 1 ] = "default";
1174         rargv[ 2 ] = NULL;
1175         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1176
1177         rargv[ 0 ] = "rewriteRule";
1178         rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1179         rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1180         rargv[ 3 ] = ":";
1181         rargv[ 4 ] = NULL;
1182         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1183         ch_free( rargv[ 1 ] );
1184         ch_free( rargv[ 2 ] );
1185
1186         if ( BER_BVISEMPTY( pvnc ) ) {
1187                 rargv[ 0 ] = "rewriteRule";
1188                 rargv[ 1 ] = "^$";
1189                 rargv[ 2 ] = prnc->bv_val;
1190                 rargv[ 3 ] = ":";
1191                 rargv[ 4 ] = NULL;
1192                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1193         }
1194         
1195         rargv[ 0 ] = "rewriteContext";
1196         rargv[ 1 ] = "searchEntryDN";
1197         rargv[ 2 ] = NULL;
1198         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1199
1200         rargv[ 0 ] = "rewriteRule";
1201         rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1202         rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1203         rargv[ 3 ] = ":";
1204         rargv[ 4 ] = NULL;
1205         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1206         ch_free( rargv[ 1 ] );
1207         ch_free( rargv[ 2 ] );
1208
1209         if ( BER_BVISEMPTY( prnc ) ) {
1210                 rargv[ 0 ] = "rewriteRule";
1211                 rargv[ 1 ] = "^$";
1212                 rargv[ 2 ] = pvnc->bv_val;
1213                 rargv[ 3 ] = ":";
1214                 rargv[ 4 ] = NULL;
1215                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1216         }
1217         
1218         /* backward compatibility */
1219         rargv[ 0 ] = "rewriteContext";
1220         rargv[ 1 ] = "searchResult";
1221         rargv[ 2 ] = "alias";
1222         rargv[ 3 ] = "searchEntryDN";
1223         rargv[ 4 ] = NULL;
1224         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1225         
1226         rargv[ 0 ] = "rewriteContext";
1227         rargv[ 1 ] = "matchedDN";
1228         rargv[ 2 ] = "alias";
1229         rargv[ 3 ] = "searchEntryDN";
1230         rargv[ 4 ] = NULL;
1231         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1232
1233         rargv[ 0 ] = "rewriteContext";
1234         rargv[ 1 ] = "searchAttrDN";
1235         rargv[ 2 ] = "alias";
1236         rargv[ 3 ] = "searchEntryDN";
1237         rargv[ 4 ] = NULL;
1238         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1239
1240         /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1241          * see servers/slapd/overlays/rwm.h for details */
1242         rargv[ 0 ] = "rewriteContext";
1243         rargv[ 1 ] = "referralAttrDN";
1244         rargv[ 2 ] = NULL;
1245         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1246
1247         rargv[ 0 ] = "rewriteContext";
1248         rargv[ 1 ] = "referralDN";
1249         rargv[ 2 ] = NULL;
1250         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1251         
1252         return 0;
1253 }
1254 #endif /* ENABLE_REWRITE */
1255