]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/config.c
1b01ba800b800ee256c0ea013575d002726a65a9
[openldap] / servers / slapd / back-ldap / config.c
1 /* config.c - ldap backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by the Howard Chu for inclusion
18  * in OpenLDAP Software and subsequently enhanced by Pierangelo
19  * Masarati.
20  */
21 /* This is an altered version */
22 /*
23  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
24  * 
25  * Permission is granted to anyone to use this software for any purpose
26  * on any computer system, and to alter it and redistribute it, subject
27  * to the following restrictions:
28  * 
29  * 1. The author is not responsible for the consequences of use of this
30  *    software, no matter how awful, even if they arise from flaws in it.
31  * 
32  * 2. The origin of this software must not be misrepresented, either by
33  *    explicit claim or by omission.  Since few users ever read sources,
34  *    credits should appear in the documentation.
35  * 
36  * 3. Altered versions must be plainly marked as such, and must not be
37  *    misrepresented as being the original software.  Since few users
38  *    ever read sources, credits should appear in the documentation.
39  * 
40  * 4. This notice may not be removed or altered.
41  *
42  *
43  *
44  * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
45  * 
46  * This software is being modified by Pierangelo Masarati.
47  * The previously reported conditions apply to the modified code as well.
48  * Changes in the original code are highlighted where required.
49  * Credits for the original code go to the author, Howard Chu.
50  */
51
52 #include "portable.h"
53
54 #include <stdio.h>
55
56 #include <ac/string.h>
57 #include <ac/socket.h>
58
59 #include "slap.h"
60 #include "back-ldap.h"
61 #include "lutil.h"
62
63 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
64
65 int
66 ldap_back_db_config(
67     BackendDB   *be,
68     const char  *fname,
69     int         lineno,
70     int         argc,
71     char        **argv
72 )
73 {
74         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
75
76         if ( li == NULL ) {
77                 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
78                     fname, lineno );
79                 return( 1 );
80         }
81
82         /* server address to query (depricated, use "uri" directive) */
83         if ( strcasecmp( argv[0], "server" ) == 0 ) {
84                 if (argc != 2) {
85                         fprintf( stderr,
86         "%s: line %d: missing address in \"server <address>\" line\n",
87                             fname, lineno );
88                         return( 1 );
89                 }
90                 if (li->url != NULL)
91                         ch_free(li->url);
92                 li->url = ch_calloc(strlen(argv[1]) + 9, sizeof(char));
93                 if (li->url != NULL) {
94                         strcpy(li->url, "ldap://");
95                         strcat(li->url, argv[1]);
96                         strcat(li->url, "/");
97                 }
98
99         /* URI of server to query (preferred over "server" directive) */
100         } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
101                 if (argc != 2) {
102                         fprintf( stderr,
103         "%s: line %d: missing address in \"uri <address>\" line\n",
104                             fname, lineno );
105                         return( 1 );
106                 }
107                 if (li->url != NULL)
108                         ch_free(li->url);
109                 li->url = ch_strdup(argv[1]);
110
111         /* name to use for ldap_back_group */
112         } else if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
113                 if (argc != 2) {
114                         fprintf( stderr,
115         "%s: line %d: missing name in \"binddn <name>\" line\n",
116                             fname, lineno );
117                         return( 1 );
118                 }
119                 ber_str2bv( argv[1], 0, 1, &li->binddn );
120
121         /* password to use for ldap_back_group */
122         } else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
123                 if (argc != 2) {
124                         fprintf( stderr,
125         "%s: line %d: missing password in \"bindpw <password>\" line\n",
126                             fname, lineno );
127                         return( 1 );
128                 }
129                 ber_str2bv( argv[1], 0, 1, &li->bindpw );
130         
131         /* save bind creds for referral rebinds? */
132         } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
133                 if (argc != 1) {
134                         fprintf( stderr,
135         "%s: line %d: rebind-as-user takes no arguments\n",
136                             fname, lineno );
137                         return( 1 );
138                 }
139                 li->savecred = 1;
140         
141         /* intercept exop_who_am_i? */
142         } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
143                 if (argc != 1) {
144                         fprintf( stderr,
145         "%s: line %d: proxy-whoami takes no arguments\n",
146                             fname, lineno );
147                         return( 1 );
148                 }
149                 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
150                         0, ldap_back_exop_whoami );
151         
152         /* dn massaging */
153         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
154                 BackendDB *tmp_be;
155                 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
156 #ifdef ENABLE_REWRITE
157                 int rc;
158 #endif /* ENABLE_REWRITE */
159                 
160                 /*
161                  * syntax:
162                  * 
163                  *      suffixmassage <suffix> <massaged suffix>
164                  *
165                  * the <suffix> field must be defined as a valid suffix
166                  * (or suffixAlias?) for the current database;
167                  * the <massaged suffix> shouldn't have already been
168                  * defined as a valid suffix or suffixAlias for the 
169                  * current server
170                  */
171                 if ( argc != 3 ) {
172                         fprintf( stderr, "%s: line %d: syntax is"
173                                        " \"suffixMassage <suffix>"
174                                        " <massaged suffix>\"\n",
175                                 fname, lineno );
176                         return( 1 );
177                 }
178                 
179                 ber_str2bv( argv[1], 0, 0, &bvnc );
180                 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
181                         fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
182                                 fname, lineno, bvnc.bv_val );
183                         return( 1 );
184                 }
185                 tmp_be = select_backend( &nvnc, 0, 0 );
186                 if ( tmp_be != NULL && tmp_be != be ) {
187                         fprintf( stderr, "%s: line %d: suffix already in use"
188                                        " by another backend in"
189                                        " \"suffixMassage <suffix>"
190                                        " <massaged suffix>\"\n",
191                                 fname, lineno );
192                         free( nvnc.bv_val );
193                         free( pvnc.bv_val );
194                         return( 1 );
195                 }
196
197                 ber_str2bv( argv[2], 0, 0, &brnc );
198                 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
199                         fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
200                                 fname, lineno, brnc.bv_val );
201                         free( nvnc.bv_val );
202                         free( pvnc.bv_val );
203                         return( 1 );
204                 }
205
206 #if 0
207                 tmp_be = select_backend( &nrnc, 0, 0 );
208                 if ( tmp_be != NULL ) {
209                         fprintf( stderr, "%s: line %d: massaged suffix"
210                                        " already in use by another backend in" 
211                                        " \"suffixMassage <suffix>"
212                                        " <massaged suffix>\"\n",
213                                 fname, lineno );
214                         free( nvnc.bv_val );
215                         free( pvnc.bv_val );
216                         free( nrnc.bv_val );
217                         free( prnc.bv_val );
218                         return( 1 );
219                 }
220 #endif
221
222 #ifdef ENABLE_REWRITE
223                 /*
224                  * The suffix massaging is emulated by means of the
225                  * rewrite capabilities
226                  * FIXME: no extra rewrite capabilities should be added
227                  * to the database
228                  */
229                 rc = suffix_massage_config( li->rwmap.rwm_rw,
230                                 &pvnc, &nvnc, &prnc, &nrnc );
231                 free( nvnc.bv_val );
232                 free( pvnc.bv_val );
233                 free( nrnc.bv_val );
234                 free( prnc.bv_val );
235
236                 return( rc );
237
238 #else /* !ENABLE_REWRITE */
239                 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &pvnc );
240                 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nvnc );
241                 
242                 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &prnc );
243                 ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nrnc );
244 #endif /* !ENABLE_REWRITE */
245
246         /* rewrite stuff ... */
247         } else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) {
248 #ifdef ENABLE_REWRITE
249                 return rewrite_parse( li->rwmap.rwm_rw,
250                                 fname, lineno, argc, argv );
251
252 #else /* !ENABLE_REWRITE */
253                 fprintf( stderr, "%s: line %d: rewrite capabilities "
254                                 "are not enabled\n", fname, lineno );
255 #endif /* !ENABLE_REWRITE */
256                 
257         /* objectclass/attribute mapping */
258         } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
259                 return ldap_back_map_config( &li->rwmap.rwm_oc,
260                                 &li->rwmap.rwm_at,
261                                 fname, lineno, argc, argv );
262
263         /* anything else */
264         } else {
265                 fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
266                         "in ldap database definition (ignored)\n",
267                     fname, lineno, argv[0] );
268         }
269         return 0;
270 }
271
272 int
273 ldap_back_map_config(
274                 struct ldapmap  *oc_map,
275                 struct ldapmap  *at_map,
276                 const char      *fname,
277                 int             lineno,
278                 int             argc,
279                 char            **argv )
280 {
281         struct ldapmap          *map;
282         struct ldapmapping      *mapping;
283         char                    *src, *dst;
284         int                     is_oc = 0;
285
286         if ( argc < 3 || argc > 4 ) {
287                 fprintf( stderr,
288         "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
289                         fname, lineno );
290                 return 1;
291         }
292
293         if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
294                 map = oc_map;
295                 is_oc = 1;
296
297         } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
298                 map = at_map;
299
300         } else {
301                 fprintf( stderr, "%s: line %d: syntax is "
302                         "\"map {objectclass | attribute} [<local> | *] "
303                         "{<foreign> | *}\"\n",
304                         fname, lineno );
305                 return 1;
306         }
307
308         if ( strcmp( argv[2], "*" ) == 0 ) {
309                 if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
310                         map->drop_missing = ( argc < 4 );
311                         return 0;
312                 }
313                 src = dst = argv[3];
314
315         } else if ( argc < 4 ) {
316                 src = "";
317                 dst = argv[2];
318
319         } else {
320                 src = argv[2];
321                 dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
322         }
323
324         if ( ( map == at_map )
325                         && ( strcasecmp( src, "objectclass" ) == 0
326                         || strcasecmp( dst, "objectclass" ) == 0 ) )
327         {
328                 fprintf( stderr,
329                         "%s: line %d: objectclass attribute cannot be mapped\n",
330                         fname, lineno );
331         }
332
333         mapping = (struct ldapmapping *)ch_calloc( 2,
334                 sizeof(struct ldapmapping) );
335         if ( mapping == NULL ) {
336                 fprintf( stderr,
337                         "%s: line %d: out of memory\n",
338                         fname, lineno );
339                 return 1;
340         }
341         ber_str2bv( src, 0, 1, &mapping->src );
342         ber_str2bv( dst, 0, 1, &mapping->dst );
343         mapping[1].src = mapping->dst;
344         mapping[1].dst = mapping->src;
345
346         /*
347          * schema check
348          */
349         if ( is_oc ) {
350                 if ( src[0] != '\0' ) {
351                         if ( oc_bvfind( &mapping->src ) == NULL ) {
352                                 fprintf( stderr,
353         "%s: line %d: warning, source objectClass '%s' "
354         "should be defined in schema\n",
355                                         fname, lineno, src );
356
357                                 /*
358                                  * FIXME: this should become an err
359                                  */
360                         }
361                 }
362
363                 if ( oc_bvfind( &mapping->dst ) == NULL ) {
364                         fprintf( stderr,
365         "%s: line %d: warning, destination objectClass '%s' "
366         "is not defined in schema\n",
367                                 fname, lineno, dst );
368                 }
369         } else {
370                 int                     rc;
371                 const char              *text = NULL;
372                 AttributeDescription    *ad = NULL;
373
374                 if ( src[0] != '\0' ) {
375                         rc = slap_bv2ad( &mapping->src, &ad, &text );
376                         if ( rc != LDAP_SUCCESS ) {
377                                 fprintf( stderr,
378         "%s: line %d: warning, source attributeType '%s' "
379         "should be defined in schema\n",
380                                         fname, lineno, src );
381
382                                 /*
383                                  * FIXME: this should become an err
384                                  */
385                         }
386
387                         ad = NULL;
388                 }
389
390                 rc = slap_bv2ad( &mapping->dst, &ad, &text );
391                 if ( rc != LDAP_SUCCESS ) {
392                         fprintf( stderr,
393         "%s: line %d: warning, destination attributeType '%s' "
394         "is not defined in schema\n",
395                                 fname, lineno, dst );
396                 }
397         }
398
399         if ( (src[0] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
400                         || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
401         {
402                 fprintf( stderr,
403                         "%s: line %d: duplicate mapping found (ignored)\n",
404                         fname, lineno );
405                 /* FIXME: free stuff */
406                 goto error_return;
407         }
408
409         if ( src[0] != '\0' ) {
410                 avl_insert( &map->map, (caddr_t)mapping,
411                                         mapping_cmp, mapping_dup );
412         }
413         avl_insert( &map->remap, (caddr_t)&mapping[1],
414                                 mapping_cmp, mapping_dup );
415
416         return 0;
417
418 error_return:;
419         if ( mapping ) {
420                 ch_free( mapping->src.bv_val );
421                 ch_free( mapping->dst.bv_val );
422                 ch_free( mapping );
423         }
424
425         return 1;
426 }
427
428 static int
429 ldap_back_exop_whoami(
430         Operation *op,
431         SlapReply *rs )
432 {
433         struct berval *bv = NULL;
434
435         if ( op->oq_extended.rs_reqdata != NULL ) {
436                 /* no request data should be provided */
437                 rs->sr_text = "no request data expected";
438                 return rs->sr_err = LDAP_PROTOCOL_ERROR;
439         }
440
441         rs->sr_err = backend_check_restrictions( op, rs, 
442                         (struct berval *)&slap_EXOP_WHOAMI );
443         if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
444
445         /* if auth'd by back-ldap and request is proxied, forward it */
446         if ( op->o_conn->c_authz_backend && !strcmp(op->o_conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &op->o_conn->c_ndn)) {
447                 struct ldapconn *lc;
448
449                 LDAPControl c, *ctrls[2] = {NULL, NULL};
450                 LDAPMessage *res;
451                 Operation op2 = *op;
452                 ber_int_t msgid;
453
454                 ctrls[0] = &c;
455                 op2.o_ndn = op->o_conn->c_ndn;
456                 lc = ldap_back_getconn(&op2, rs);
457                 if (!lc || !ldap_back_dobind( lc, op, rs )) {
458                         return -1;
459                 }
460                 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
461                 c.ldctl_iscritical = 1;
462                 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
463                 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
464                 strcpy(c.ldctl_value.bv_val, "dn:");
465                 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
466
467                 rs->sr_err = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
468                 if (rs->sr_err == LDAP_SUCCESS) {
469                         if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
470                                 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
471                                         &rs->sr_err);
472                         } else {
473                                 rs->sr_err = ldap_parse_whoami(lc->ld, res, &bv);
474                                 ldap_msgfree(res);
475                         }
476                 }
477                 ch_free(c.ldctl_value.bv_val);
478                 if (rs->sr_err != LDAP_SUCCESS) {
479                         rs->sr_err = ldap_back_map_result(rs);
480                 }
481         } else {
482         /* else just do the same as before */
483                 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
484                 if( op->o_dn.bv_len ) {
485                         bv->bv_len = op->o_dn.bv_len + sizeof("dn:")-1;
486                         bv->bv_val = ch_malloc( bv->bv_len + 1 );
487                         AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:")-1 );
488                         AC_MEMCPY( &bv->bv_val[sizeof("dn:")-1], op->o_dn.bv_val,
489                                 op->o_dn.bv_len );
490                         bv->bv_val[bv->bv_len] = '\0';
491                 } else {
492                         bv->bv_len = 0;
493                         bv->bv_val = NULL;
494                 }
495         }
496
497         rs->sr_rspdata = bv;
498         return rs->sr_err;
499 }
500
501
502 #ifdef ENABLE_REWRITE
503 static char *
504 suffix_massage_regexize( const char *s )
505 {
506         char *res, *ptr;
507         const char *p, *r;
508         int i;
509
510         for ( i = 0, p = s; 
511                         ( r = strchr( p, ',' ) ) != NULL; 
512                         p = r + 1, i++ )
513                 ;
514
515         res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
516
517         ptr = lutil_strcopy( res, "(.*)" );
518         for ( i = 0, p = s;
519                         ( r = strchr( p, ',' ) ) != NULL;
520                         p = r + 1 , i++ ) {
521                 ptr = lutil_strncopy( ptr, p, r - p + 1 );
522                 ptr = lutil_strcopy( ptr, "[ ]?" );
523
524                 if ( r[ 1 ] == ' ' ) {
525                         r++;
526                 }
527         }
528         lutil_strcopy( ptr, p );
529
530         return res;
531 }
532
533 static char *
534 suffix_massage_patternize( const char *s )
535 {
536         ber_len_t       len;
537         char            *res;
538
539         len = strlen( s );
540
541         res = ch_calloc( sizeof( char ), len + sizeof( "%1" ) );
542         if ( res == NULL ) {
543                 return NULL;
544         }
545
546         strcpy( res, "%1" );
547         strcpy( res + sizeof( "%1" ) - 1, s );
548
549         return res;
550 }
551
552 int
553 suffix_massage_config( 
554                 struct rewrite_info *info,
555                 struct berval *pvnc,
556                 struct berval *nvnc,
557                 struct berval *prnc,
558                 struct berval *nrnc
559 )
560 {
561         char *rargv[ 5 ];
562         int line = 0;
563
564         rargv[ 0 ] = "rewriteEngine";
565         rargv[ 1 ] = "on";
566         rargv[ 2 ] = NULL;
567         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
568
569         rargv[ 0 ] = "rewriteContext";
570         rargv[ 1 ] = "default";
571         rargv[ 2 ] = NULL;
572         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
573
574         rargv[ 0 ] = "rewriteRule";
575         rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
576         rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val );
577         rargv[ 3 ] = ":";
578         rargv[ 4 ] = NULL;
579         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
580         ch_free( rargv[ 1 ] );
581         ch_free( rargv[ 2 ] );
582         
583         rargv[ 0 ] = "rewriteContext";
584         rargv[ 1 ] = "searchResult";
585         rargv[ 2 ] = NULL;
586         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
587         
588         rargv[ 0 ] = "rewriteRule";
589         rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
590         rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val );
591         rargv[ 3 ] = ":";
592         rargv[ 4 ] = NULL;
593         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
594         ch_free( rargv[ 1 ] );
595         ch_free( rargv[ 2 ] );
596
597 #if 0
598         /*
599          * FIXME: this is no longer required since now we map filters
600          * based on the parsed filter structure, so we can deal directly
601          * with attribute types and values.  The rewriteContext 
602          * "searchFilter" now refers to the value of attrbutes
603          * with DN syntax.
604          */
605
606         /*
607          * the filter should be rewritten as
608          * 
609          * rewriteRule
610          *      "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)"
611          *      "%1member=%2,dc=example,dc=com%3"
612          *
613          * where "o=Foo Bar, c=US" is the virtual naming context,
614          * and "dc=example, dc=com" is the real naming context
615          */
616         rargv[ 0 ] = "rewriteContext";
617         rargv[ 1 ] = "searchFilter";
618         rargv[ 2 ] = NULL;
619         rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
620
621 #if 1 /* rewrite filters */
622         {
623                 /*
624                  * Note: this is far more optimistic than desirable:
625                  * for any AVA value ending with the virtual naming
626                  * context the terminal part will be replaced by the
627                  * real naming context; a better solution would be to
628                  * walk the filter looking for DN-valued attributes,
629                  * and only rewrite those that require rewriting
630                  */
631                 char    vbuf_[BUFSIZ], *vbuf = vbuf_,
632                         rbuf_[BUFSIZ], *rbuf = rbuf_;
633                 int     len;
634
635                 len = snprintf( vbuf, sizeof( vbuf_ ), 
636                                 "(.*)%s\\)(.*)", nvnc->bv_val );
637                 if ( len == -1 ) {
638                         /* 
639                          * traditional behavior: snprintf returns -1 
640                          * if buffer is insufficient
641                          */
642                         return -1;
643
644                 } else if ( len >= (int)sizeof( vbuf_ ) ) {
645                         /* 
646                          * C99: snprintf returns the required size 
647                          */
648                         vbuf = ch_malloc( len + 1 );
649                         len = snprintf( vbuf, len,
650                                         "(.*)%s\\)(.*)", nvnc->bv_val );
651                         assert( len > 0 );
652                 }
653
654                 len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
655                                 nrnc->bv_val );
656                 if ( len == -1 ) {
657                         return -1;
658
659                 } else if ( len >= (int)sizeof( rbuf_ ) ) {
660                         rbuf = ch_malloc( len + 1 );
661                         len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
662                                         nrnc->bv_val );
663                         assert( len > 0 );
664                 }
665                 
666                 rargv[ 0 ] = "rewriteRule";
667                 rargv[ 1 ] = vbuf;
668                 rargv[ 2 ] = rbuf;
669                 rargv[ 3 ] = ":";
670                 rargv[ 4 ] = NULL;
671                 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
672
673                 if ( vbuf != vbuf_ ) {
674                         ch_free( vbuf );
675                 }
676
677                 if ( rbuf != rbuf_ ) {
678                         ch_free( rbuf );
679                 }
680         }
681 #endif /* rewrite filters */
682 #endif
683
684 #if 0 /*  "matched" is not normalized */
685         rargv[ 0 ] = "rewriteContext";
686         rargv[ 1 ] = "matchedDn";
687         rargv[ 2 ] = "alias";
688         rargv[ 3 ] = "searchResult";
689         rargv[ 4 ] = NULL;
690         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
691 #else /* normalize "matched" */
692
693         rargv[ 0 ] = "rewriteContext";
694         rargv[ 1 ] = "matchedDN";
695         rargv[ 2 ] = "alias";
696         rargv[ 3 ] = "searchResult";
697         rargv[ 4 ] = NULL;
698         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
699
700         rargv[ 0 ] = "rewriteContext";
701         rargv[ 1 ] = "searchAttrDN";
702         rargv[ 2 ] = "alias";
703         rargv[ 3 ] = "searchResult";
704         rargv[ 4 ] = NULL;
705         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
706
707 #if 0
708         rargv[ 0 ] = "rewriteRule";
709         rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
710         rargv[ 2 ] = suffix_massage_patternize( nvnc->bv_val );
711         rargv[ 3 ] = ":";
712         rargv[ 4 ] = NULL;
713         rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
714         ch_free( rargv[ 1 ] );
715         ch_free( rargv[ 2 ] );
716 #endif /* 0 */
717 #endif /* normalize "matched" */
718
719         return 0;
720 }
721 #endif /* ENABLE_REWRITE */