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