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