]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/config.c
41b9adfabed27abc38df58bfac2af6781ff51e02
[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                 if ( argc != 2 ) {
350                         Debug( LDAP_DEBUG_ANY,
351         "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
352                                 fname, lineno, 0 );
353                         return 1;
354                 }
355
356                 if ( lutil_atoi( &mi->mi_network_timeout, argv[ 1 ] ) ) {
357                         Debug( LDAP_DEBUG_ANY,
358         "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
359                                 fname, lineno, argv[ 1 ] );
360                         return 1;
361
362                 } else if ( mi->mi_network_timeout < 0 ) {
363                         Debug( LDAP_DEBUG_ANY,
364         "%s: line %d: ilegal negative timeout in \"network-timeout <seconds>\" line\n",
365                                 fname, lineno, argv[ 1 ] );
366                         return 1;
367                 }
368
369         /* name to use for meta_back_group */
370         } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
371                         || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
372         {
373                 int             i = mi->mi_ntargets - 1;
374                 struct berval   dn;
375
376                 if ( i < 0 ) {
377                         Debug( LDAP_DEBUG_ANY,
378         "%s: line %d: need \"uri\" directive first\n",
379                                 fname, lineno, 0 );
380                         return 1;
381                 }
382                 
383                 if ( argc != 2 ) {
384                         Debug( LDAP_DEBUG_ANY,
385         "%s: line %d: missing name in \"binddn <name>\" line\n",
386                                 fname, lineno, 0 );
387                         return 1;
388                 }
389
390                 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
391                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
392                                 "\"binddn\" statement is deprecated; "
393                                 "use \"acl-authcDN\" instead\n",
394                                 fname, lineno, 0 );
395                         /* FIXME: some day we'll need to throw an error */
396                 }
397
398                 dn.bv_val = argv[ 1 ];
399                 dn.bv_len = strlen( argv[ 1 ] );
400                 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ].mt_binddn,
401                         NULL ) != LDAP_SUCCESS )
402                 {
403                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
404                                         "bind DN '%s' is invalid\n",
405                                         fname, lineno, argv[ 1 ] );
406                         return( 1 );
407                 }
408
409         /* password to use for meta_back_group */
410         } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
411                         || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
412         {
413                 int             i = mi->mi_ntargets - 1;
414
415                 if ( i < 0 ) {
416                         Debug( LDAP_DEBUG_ANY,
417         "%s: line %d: need \"uri\" directive first\n",
418                                 fname, lineno, 0 );
419                         return 1;
420                 }
421                 
422                 if ( argc != 2 ) {
423                         Debug( LDAP_DEBUG_ANY,
424         "%s: line %d: missing password in \"bindpw <password>\" line\n",
425                             fname, lineno, 0 );
426                         return 1;
427                 }
428
429                 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
430                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
431                                 "\"bindpw\" statement is deprecated; "
432                                 "use \"acl-passwd\" instead\n",
433                                 fname, lineno, 0 );
434                         /* FIXME: some day we'll need to throw an error */
435                 }
436
437                 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_bindpw );
438                 
439         /* save bind creds for referral rebinds? */
440         } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
441                 if ( argc > 2 ) {
442                         Debug( LDAP_DEBUG_ANY,
443         "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
444                             fname, lineno, 0 );
445                         return( 1 );
446                 }
447
448                 if ( argc == 1 ) {
449                         Debug( LDAP_DEBUG_ANY,
450         "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
451                             fname, lineno, 0 );
452                         mi->mi_flags |= LDAP_BACK_F_SAVECRED;
453
454                 } else {
455                         switch ( check_true_false( argv[ 1 ] ) ) {
456                         case 0:
457                                 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
458                                 break;
459
460                         case 1:
461                                 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
462                                 break;
463
464                         default:
465                                 Debug( LDAP_DEBUG_ANY,
466         "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
467                                     fname, lineno, argv[ 1 ] );
468                                 return 1;
469                         }
470                 }
471
472         } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
473                 unsigned        *flagsp = mi->mi_ntargets ?
474                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
475                                 : &mi->mi_flags;
476
477                 if ( argc != 2 ) {
478                         Debug( LDAP_DEBUG_ANY,
479         "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
480                                 fname, lineno, 0 );
481                         return( 1 );
482                 }
483
484                 /* this is the default; we add it because the default might change... */
485                 switch ( check_true_false( argv[ 1 ] ) ) {
486                 case 1:
487                         *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
488                         break;
489
490                 case 0:
491                         *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
492                         break;
493
494                 default:
495                         Debug( LDAP_DEBUG_ANY,
496                 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
497                                 fname, lineno, argv[ 1 ] );
498                         return( 1 );
499                 }
500         
501         } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
502                 unsigned        *flagsp = mi->mi_ntargets ?
503                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
504                                 : &mi->mi_flags;
505
506                 if ( argc != 2 ) {
507                         Debug( LDAP_DEBUG_ANY,
508                 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
509                                 fname, lineno, 0 );
510                         return( 1 );
511                 }
512
513                 /* start */
514                 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
515                         *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
516         
517                 /* try start tls */
518                 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
519                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
520                         *flagsp |= LDAP_BACK_F_USE_TLS;
521         
522                 /* propagate start tls */
523                 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
524                         *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
525                 
526                 /* try start tls */
527                 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
528                         *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
529                         *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
530
531                 } else {
532                         Debug( LDAP_DEBUG_ANY,
533                 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
534                                 fname, lineno, argv[ 1 ] );
535                         return( 1 );
536                 }
537
538         } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
539                 unsigned        *flagsp = mi->mi_ntargets ?
540                                 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
541                                 : &mi->mi_flags;
542
543                 if ( argc != 2 ) {
544                         Debug( LDAP_DEBUG_ANY,
545                 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
546                                 fname, lineno, 0 );
547                         return( 1 );
548                 }
549
550                 switch ( check_true_false( argv[ 1 ] ) ) {
551                 case 0:
552                         *flagsp &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
553                         break;
554
555                 case 1:
556                         *flagsp |= LDAP_BACK_F_SUPPORT_T_F;
557                         break;
558
559                 default:
560                         if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
561                                 *flagsp |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
562
563                         } else {
564                                 Debug( LDAP_DEBUG_ANY,
565         "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
566                                         fname, lineno, argv[ 1 ] );
567                                 return 1;
568                         }
569                         break;
570                 }
571
572         /* onerr? */
573         } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
574                 if ( argc != 2 ) {
575                         Debug( LDAP_DEBUG_ANY,
576         "%s: line %d: \"onerr {CONTINUE|stop}\" takes 1 argument\n",
577                                 fname, lineno, 0 );
578                         return( 1 );
579                 }
580
581                 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
582                         mi->mi_flags &= ~META_BACK_F_ONERR_STOP;
583
584                 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
585                         mi->mi_flags |= META_BACK_F_ONERR_STOP;
586
587                 } else {
588                         Debug( LDAP_DEBUG_ANY,
589         "%s: line %d: \"onerr {CONTINUE|stop}\": invalid arg \"%s\".\n",
590                                 fname, lineno, argv[ 1 ] );
591                         return 1;
592                 }
593
594         /* bind-defer? */
595         } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0 ) {
596                 if ( argc != 2 ) {
597                         Debug( LDAP_DEBUG_ANY,
598         "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\" takes 1 argument\n",
599                                 fname, lineno, 0 );
600                         return( 1 );
601                 }
602
603                 switch ( check_true_false( argv[ 1 ] ) ) {
604                 case 0:
605                         mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
606                         break;
607
608                 case 1:
609                         mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
610                         break;
611
612                 default:
613                         Debug( LDAP_DEBUG_ANY,
614         "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
615                                 fname, lineno, argv[ 1 ] );
616                         return 1;
617                 }
618
619         } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
620                 char    *sep;
621                 time_t  *tv = mi->mi_ntargets ?
622                                 mi->mi_targets[ mi->mi_ntargets - 1 ].mt_timeout
623                                 : mi->mi_timeout;
624                 int     c;
625
626                 if ( argc < 2 ) {
627                         Debug( LDAP_DEBUG_ANY,
628         "%s: line %d: \"timeout [{add|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
629                                 fname, lineno, 0 );
630                         return( 1 );
631                 }
632
633                 for ( c = 1; c < argc; c++ ) {
634                         time_t          *t = NULL;
635                         unsigned long   val;
636
637                         sep = strchr( argv[ c ], '=' );
638                         if ( sep != NULL ) {
639                                 size_t  len = sep - argv[ c ];
640
641                                 if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
642                                         t = &tv[ LDAP_BACK_OP_ADD ];
643                                 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
644                                         t = &tv[ LDAP_BACK_OP_DELETE ];
645                                 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
646                                         t = &tv[ LDAP_BACK_OP_MODIFY ];
647                                 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
648                                         t = &tv[ LDAP_BACK_OP_MODRDN ];
649                                 } else {
650                                         char    buf[ SLAP_TEXT_BUFLEN ];
651                                         snprintf( buf, sizeof( buf ),
652                                                 "unknown operation \"%s\" for timeout #%d",
653                                                 argv[ c ], c );
654                                         Debug( LDAP_DEBUG_ANY,
655                                                 "%s: line %d: %s.\n",
656                                                 fname, lineno, buf );
657                                         return 1;
658                                 }
659                                 sep++;
660         
661                         } else {
662                                 sep = argv[ c ];
663                         }
664         
665                         if ( lutil_parse_time( sep, &val ) != 0 ) {
666                                 Debug( LDAP_DEBUG_ANY,
667                 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
668                                         fname, lineno, sep );
669                                 return 1;
670                         }
671                 
672                         if ( t ) {
673                                 *t = (time_t)val;
674         
675                         } else {
676                                 int     i;
677         
678                                 for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
679                                         tv[ i ] = (time_t)val;
680                                 }
681                         }
682                 }
683         
684         /* name to use as pseudo-root dn */
685         } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
686                 int             i = mi->mi_ntargets - 1;
687                 struct berval   dn;
688
689                 if ( i < 0 ) {
690                         Debug( LDAP_DEBUG_ANY,
691         "%s: line %d: need \"uri\" directive first\n",
692                                 fname, lineno, 0 );
693                         return 1;
694                 }
695                 
696                 if ( argc != 2 ) {
697                         Debug( LDAP_DEBUG_ANY,
698         "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
699                                 fname, lineno, 0 );
700                         return 1;
701                 }
702
703                 dn.bv_val = argv[ 1 ];
704                 dn.bv_len = strlen( argv[ 1 ] );
705                 if ( dnNormalize( 0, NULL, NULL, &dn,
706                         &mi->mi_targets[ i ].mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
707                 {
708                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
709                                         "pseudoroot DN '%s' is invalid\n",
710                                         fname, lineno, argv[ 1 ] );
711                         return( 1 );
712                 }
713
714         /* password to use as pseudo-root */
715         } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
716                 int             i = mi->mi_ntargets - 1;
717
718                 if ( i < 0 ) {
719                         Debug( LDAP_DEBUG_ANY,
720         "%s: line %d: need \"uri\" directive first\n",
721                                 fname, lineno, 0 );
722                         return 1;
723                 }
724                 
725                 if ( argc != 2 ) {
726                         Debug( LDAP_DEBUG_ANY,
727         "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
728                             fname, lineno, 0 );
729                         return 1;
730                 }
731                 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_pseudorootpw );
732         
733         /* dn massaging */
734         } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
735                 BackendDB       *tmp_be;
736                 int             i = mi->mi_ntargets - 1, rc;
737                 struct berval   dn, nvnc, pvnc, nrnc, prnc;
738
739                 if ( i < 0 ) {
740                         Debug( LDAP_DEBUG_ANY,
741         "%s: line %d: need \"uri\" directive first\n",
742                                 fname, lineno, 0 );
743                         return 1;
744                 }
745                 
746                 /*
747                  * syntax:
748                  * 
749                  *      suffixmassage <suffix> <massaged suffix>
750                  *
751                  * the <suffix> field must be defined as a valid suffix
752                  * (or suffixAlias?) for the current database;
753                  * the <massaged suffix> shouldn't have already been
754                  * defined as a valid suffix or suffixAlias for the 
755                  * current server
756                  */
757                 if ( argc != 3 ) {
758                         Debug( LDAP_DEBUG_ANY,
759         "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
760                                 fname, lineno, 0 );
761                         return 1;
762                 }
763
764                 ber_str2bv( argv[ 1 ], 0, 0, &dn );
765                 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
766                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
767                                         "suffix '%s' is invalid\n",
768                                         fname, lineno, argv[ 1 ] );
769                         return 1;
770                 }
771                 
772                 tmp_be = select_backend( &nvnc, 0, 0 );
773                 if ( tmp_be != NULL && tmp_be != be ) {
774                         Debug( LDAP_DEBUG_ANY, 
775         "%s: line %d: suffix already in use by another backend in"
776         " \"suffixMassage <suffix> <massaged suffix>\"\n",
777                                 fname, lineno, 0 );
778                         free( pvnc.bv_val );
779                         free( nvnc.bv_val );
780                         return 1;                                               
781                 }
782
783                 ber_str2bv( argv[ 2 ], 0, 0, &dn );
784                 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
785                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
786                                 "massaged suffix '%s' is invalid\n",
787                                 fname, lineno, argv[ 2 ] );
788                         free( pvnc.bv_val );
789                         free( nvnc.bv_val );
790                         return 1;
791                 }
792         
793 #if 0   
794                 tmp_be = select_backend( &nrnc, 0, 0 );
795                 if ( tmp_be != NULL ) {
796                         Debug( LDAP_DEBUG_ANY,
797         "%s: line %d: massaged suffix already in use by another backend in" 
798         " \"suffixMassage <suffix> <massaged suffix>\"\n",
799                                 fname, lineno, 0 );
800                         free( pvnc.bv_val );
801                         free( nvnc.bv_val );
802                         free( prnc.bv_val );
803                         free( nrnc.bv_val );
804                         return 1;
805                 }
806 #endif
807                 
808                 /*
809                  * The suffix massaging is emulated by means of the
810                  * rewrite capabilities
811                  * FIXME: no extra rewrite capabilities should be added
812                  * to the database
813                  */
814                 rc = suffix_massage_config( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
815                                 &pvnc, &nvnc, &prnc, &nrnc );
816
817                 free( pvnc.bv_val );
818                 free( nvnc.bv_val );
819                 free( prnc.bv_val );
820                 free( nrnc.bv_val );
821
822                 return rc;
823                 
824         /* rewrite stuff ... */
825         } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
826                 int             i = mi->mi_ntargets - 1;
827
828                 if ( i < 0 ) {
829                         Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
830                                 "statement outside target definition.\n",
831                                 fname, lineno, 0 );
832                         return 1;
833                 }
834                 
835                 return rewrite_parse( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
836                                 fname, lineno, argc, argv );
837
838         /* objectclass/attribute mapping */
839         } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
840                 int             i = mi->mi_ntargets - 1;
841
842                 if ( i < 0 ) {
843                         Debug( LDAP_DEBUG_ANY,
844         "%s: line %d: need \"uri\" directive first\n",
845                                 fname, lineno, 0 );
846                         return 1;
847                 }
848
849                 return ldap_back_map_config( &mi->mi_targets[ i ].mt_rwmap.rwm_oc, 
850                                 &mi->mi_targets[ i ].mt_rwmap.rwm_at,
851                                 fname, lineno, argc, argv );
852
853         } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
854                 int             i = mi->mi_ntargets - 1;
855                 int             nretries = META_RETRY_UNDEFINED;
856
857                 if ( argc != 2 ) {
858                         Debug( LDAP_DEBUG_ANY,
859         "%s: line %d: need value in \"nretries <value>\"\n",
860                                 fname, lineno, 0 );
861                         return 1;
862                 }
863
864                 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
865                         nretries = META_RETRY_FOREVER;
866
867                 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
868                         nretries = META_RETRY_NEVER;
869
870                 } else {
871                         if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
872                                 Debug( LDAP_DEBUG_ANY,
873         "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
874                                         fname, lineno, argv[ 1 ] );
875                                 return 1;
876                         }
877                 }
878
879                 if ( i < 0 ) {
880                         mi->mi_nretries = nretries;
881
882                 } else {
883                         mi->mi_targets[ i ].mt_nretries = nretries;
884                 }
885
886         /* anything else */
887         } else {
888                 return SLAP_CONF_UNKNOWN;
889         }
890         return 0;
891 }
892
893 int
894 ldap_back_map_config(
895                 struct ldapmap  *oc_map,
896                 struct ldapmap  *at_map,
897                 const char      *fname,
898                 int             lineno,
899                 int             argc,
900                 char            **argv )
901 {
902         struct ldapmap          *map;
903         struct ldapmapping      *mapping;
904         char                    *src, *dst;
905         int                     is_oc = 0;
906
907         if ( argc < 3 || argc > 4 ) {
908                 Debug( LDAP_DEBUG_ANY,
909         "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
910                         fname, lineno, 0 );
911                 return 1;
912         }
913
914         if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
915                 map = oc_map;
916                 is_oc = 1;
917
918         } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
919                 map = at_map;
920
921         } else {
922                 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
923                         "\"map {objectclass | attribute} [<local> | *] "
924                         "{<foreign> | *}\"\n",
925                         fname, lineno, 0 );
926                 return 1;
927         }
928
929         if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
930                 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
931                         map->drop_missing = ( argc < 4 );
932                         return 0;
933                 }
934                 src = dst = argv[ 3 ];
935
936         } else if ( argc < 4 ) {
937                 src = "";
938                 dst = argv[ 2 ];
939
940         } else {
941                 src = argv[ 2 ];
942                 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
943         }
944
945         if ( ( map == at_map )
946                         && ( strcasecmp( src, "objectclass" ) == 0
947                         || strcasecmp( dst, "objectclass" ) == 0 ) )
948         {
949                 Debug( LDAP_DEBUG_ANY,
950                         "%s: line %d: objectclass attribute cannot be mapped\n",
951                         fname, lineno, 0 );
952         }
953
954         mapping = (struct ldapmapping *)ch_calloc( 2,
955                 sizeof(struct ldapmapping) );
956         if ( mapping == NULL ) {
957                 Debug( LDAP_DEBUG_ANY,
958                         "%s: line %d: out of memory\n",
959                         fname, lineno, 0 );
960                 return 1;
961         }
962         ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
963         ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
964         mapping[ 1 ].src = mapping[ 0 ].dst;
965         mapping[ 1 ].dst = mapping[ 0 ].src;
966
967         /*
968          * schema check
969          */
970         if ( is_oc ) {
971                 if ( src[ 0 ] != '\0' ) {
972                         if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
973                                 Debug( LDAP_DEBUG_ANY,
974         "%s: line %d: warning, source objectClass '%s' "
975         "should be defined in schema\n",
976                                         fname, lineno, src );
977
978                                 /*
979                                  * FIXME: this should become an err
980                                  */
981                                 goto error_return;
982                         }
983                 }
984
985                 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
986                         Debug( LDAP_DEBUG_ANY,
987         "%s: line %d: warning, destination objectClass '%s' "
988         "is not defined in schema\n",
989                                 fname, lineno, dst );
990                 }
991         } else {
992                 int                     rc;
993                 const char              *text = NULL;
994                 AttributeDescription    *ad = NULL;
995
996                 if ( src[ 0 ] != '\0' ) {
997                         rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
998                         if ( rc != LDAP_SUCCESS ) {
999                                 Debug( LDAP_DEBUG_ANY,
1000         "%s: line %d: warning, source attributeType '%s' "
1001         "should be defined in schema\n",
1002                                         fname, lineno, src );
1003
1004                                 /*
1005                                  * FIXME: this should become an err
1006                                  */
1007                                 /*
1008                                  * we create a fake "proxied" ad 
1009                                  * and add it here.
1010                                  */
1011
1012                                 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1013                                                 &ad, &text, SLAP_AD_PROXIED );
1014                                 if ( rc != LDAP_SUCCESS ) {
1015                                         char    buf[ SLAP_TEXT_BUFLEN ];
1016
1017                                         snprintf( buf, sizeof( buf ),
1018                                                 "source attributeType \"%s\": %d (%s)",
1019                                                 src, rc, text ? text : "" );
1020                                         Debug( LDAP_DEBUG_ANY,
1021                                                 "%s: line %d: %s\n",
1022                                                 fname, lineno, buf );
1023                                         goto error_return;
1024                                 }
1025                         }
1026
1027                         ad = NULL;
1028                 }
1029
1030                 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1031                 if ( rc != LDAP_SUCCESS ) {
1032                         Debug( LDAP_DEBUG_ANY,
1033         "%s: line %d: warning, destination attributeType '%s' "
1034         "is not defined in schema\n",
1035                                 fname, lineno, dst );
1036
1037                         /*
1038                          * we create a fake "proxied" ad 
1039                          * and add it here.
1040                          */
1041
1042                         rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1043                                         &ad, &text, SLAP_AD_PROXIED );
1044                         if ( rc != LDAP_SUCCESS ) {
1045                                 char    buf[ SLAP_TEXT_BUFLEN ];
1046
1047                                 snprintf( buf, sizeof( buf ),
1048                                         "source attributeType \"%s\": %d (%s)\n",
1049                                         dst, rc, text ? text : "" );
1050                                 Debug( LDAP_DEBUG_ANY,
1051                                         "%s: line %d: %s\n",
1052                                         fname, lineno, buf );
1053                                 return 1;
1054                         }
1055                 }
1056         }
1057
1058         if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1059                         || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1060         {
1061                 Debug( LDAP_DEBUG_ANY,
1062                         "%s: line %d: duplicate mapping found" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1063                         fname, lineno, 0 );
1064                 goto error_return;
1065         }
1066
1067         if ( src[ 0 ] != '\0' ) {
1068                 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1069                                         mapping_cmp, mapping_dup );
1070         }
1071         avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1072                                 mapping_cmp, mapping_dup );
1073
1074         return 0;
1075
1076 error_return:;
1077         if ( mapping ) {
1078                 ch_free( mapping[ 0 ].src.bv_val );
1079                 ch_free( mapping[ 0 ].dst.bv_val );
1080                 ch_free( mapping );
1081         }
1082
1083         return 1;
1084 }
1085
1086
1087 #ifdef ENABLE_REWRITE
1088 static char *
1089 suffix_massage_regexize( const char *s )
1090 {
1091         char *res, *ptr;
1092         const char *p, *r;
1093         int i;
1094
1095         if ( s[ 0 ] == '\0' ) {
1096                 return ch_strdup( "^(.+)$" );
1097         }
1098
1099         for ( i = 0, p = s; 
1100                         ( r = strchr( p, ',' ) ) != NULL; 
1101                         p = r + 1, i++ )
1102                 ;
1103
1104         res = ch_calloc( sizeof( char ),
1105                         strlen( s )
1106                         + STRLENOF( "((.+),)?" )
1107                         + STRLENOF( "[ ]?" ) * i
1108                         + STRLENOF( "$" ) + 1 );
1109
1110         ptr = lutil_strcopy( res, "((.+),)?" );
1111         for ( i = 0, p = s;
1112                         ( r = strchr( p, ',' ) ) != NULL;
1113                         p = r + 1 , i++ ) {
1114                 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1115                 ptr = lutil_strcopy( ptr, "[ ]?" );
1116
1117                 if ( r[ 1 ] == ' ' ) {
1118                         r++;
1119                 }
1120         }
1121         ptr = lutil_strcopy( ptr, p );
1122         ptr[ 0 ] = '$';
1123         ptr++;
1124         ptr[ 0 ] = '\0';
1125
1126         return res;
1127 }
1128
1129 static char *
1130 suffix_massage_patternize( const char *s, const char *p )
1131 {
1132         ber_len_t       len;
1133         char            *res, *ptr;
1134
1135         len = strlen( p );
1136
1137         if ( s[ 0 ] == '\0' ) {
1138                 len++;
1139         }
1140
1141         res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1142         if ( res == NULL ) {
1143                 return NULL;
1144         }
1145
1146         ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1147         if ( s[ 0 ] == '\0' ) {
1148                 ptr[ 0 ] = ',';
1149                 ptr++;
1150         }
1151         lutil_strcopy( ptr, p );
1152
1153         return res;
1154 }
1155
1156 int
1157 suffix_massage_config( 
1158                 struct rewrite_info *info,
1159                 struct berval *pvnc,
1160                 struct berval *nvnc,
1161                 struct berval *prnc,
1162                 struct berval *nrnc
1163 )
1164 {
1165         char *rargv[ 5 ];
1166         int line = 0;
1167
1168         rargv[ 0 ] = "rewriteEngine";
1169         rargv[ 1 ] = "on";
1170         rargv[ 2 ] = NULL;
1171         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1172
1173         rargv[ 0 ] = "rewriteContext";
1174         rargv[ 1 ] = "default";
1175         rargv[ 2 ] = NULL;
1176         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1177
1178         rargv[ 0 ] = "rewriteRule";
1179         rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1180         rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1181         rargv[ 3 ] = ":";
1182         rargv[ 4 ] = NULL;
1183         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1184         ch_free( rargv[ 1 ] );
1185         ch_free( rargv[ 2 ] );
1186
1187         if ( BER_BVISEMPTY( pvnc ) ) {
1188                 rargv[ 0 ] = "rewriteRule";
1189                 rargv[ 1 ] = "^$";
1190                 rargv[ 2 ] = prnc->bv_val;
1191                 rargv[ 3 ] = ":";
1192                 rargv[ 4 ] = NULL;
1193                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1194         }
1195         
1196         rargv[ 0 ] = "rewriteContext";
1197         rargv[ 1 ] = "searchEntryDN";
1198         rargv[ 2 ] = NULL;
1199         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1200
1201         rargv[ 0 ] = "rewriteRule";
1202         rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1203         rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1204         rargv[ 3 ] = ":";
1205         rargv[ 4 ] = NULL;
1206         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1207         ch_free( rargv[ 1 ] );
1208         ch_free( rargv[ 2 ] );
1209
1210         if ( BER_BVISEMPTY( prnc ) ) {
1211                 rargv[ 0 ] = "rewriteRule";
1212                 rargv[ 1 ] = "^$";
1213                 rargv[ 2 ] = pvnc->bv_val;
1214                 rargv[ 3 ] = ":";
1215                 rargv[ 4 ] = NULL;
1216                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1217         }
1218         
1219         /* backward compatibility */
1220         rargv[ 0 ] = "rewriteContext";
1221         rargv[ 1 ] = "searchResult";
1222         rargv[ 2 ] = "alias";
1223         rargv[ 3 ] = "searchEntryDN";
1224         rargv[ 4 ] = NULL;
1225         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1226         
1227         rargv[ 0 ] = "rewriteContext";
1228         rargv[ 1 ] = "matchedDN";
1229         rargv[ 2 ] = "alias";
1230         rargv[ 3 ] = "searchEntryDN";
1231         rargv[ 4 ] = NULL;
1232         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1233
1234         rargv[ 0 ] = "rewriteContext";
1235         rargv[ 1 ] = "searchAttrDN";
1236         rargv[ 2 ] = "alias";
1237         rargv[ 3 ] = "searchEntryDN";
1238         rargv[ 4 ] = NULL;
1239         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1240
1241         /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1242          * see servers/slapd/overlays/rwm.h for details */
1243         rargv[ 0 ] = "rewriteContext";
1244         rargv[ 1 ] = "referralAttrDN";
1245         rargv[ 2 ] = NULL;
1246         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1247
1248         rargv[ 0 ] = "rewriteContext";
1249         rargv[ 1 ] = "referralDN";
1250         rargv[ 2 ] = NULL;
1251         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1252         
1253         return 0;
1254 }
1255 #endif /* ENABLE_REWRITE */
1256