]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/config.c
import fix to ITS#4071
[openldap] / servers / slapd / back-ldap / config.c
index bba917a4cc94558bc0a7f18616c7975718343b96..6d80e96153bf2884732c2176c38476a46f663d34 100644 (file)
@@ -1,38 +1,24 @@
 /* config.c - ldap backend configuration file routine */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/* This is an altered version */
-/*
- * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
- * 
- * Permission is granted to anyone to use this software for any purpose
- * on any computer system, and to alter it and redistribute it, subject
- * to the following restrictions:
- * 
- * 1. The author is not responsible for the consequences of use of this
- *    software, no matter how awful, even if they arise from flaws in it.
- * 
- * 2. The origin of this software must not be misrepresented, either by
- *    explicit claim or by omission.  Since few users ever read sources,
- *    credits should appear in the documentation.
- * 
- * 3. Altered versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.  Since few users
- *    ever read sources, credits should appear in the documentation.
- * 
- * 4. This notice may not be removed or altered.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
+ * Copyright 2003-2005 The OpenLDAP Foundation.
+ * Portions Copyright 1999-2003 Howard Chu.
+ * Portions Copyright 2000-2003 Pierangelo Masarati.
+ * All rights reserved.
  *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
- * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
- * 
- * This software is being modified by Pierangelo Masarati.
- * The previously reported conditions apply to the modified code as well.
- * Changes in the original code are highlighted where required.
- * Credits for the original code go to the author, Howard Chu.
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
  */
 
 #include "portable.h"
@@ -45,6 +31,9 @@
 #include "slap.h"
 #include "back-ldap.h"
 #include "lutil.h"
+#undef ldap_debug
+/* for advanced URL parsing */
+#include "../../../libraries/libldap/ldap-int.h"
 
 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
 
@@ -84,15 +73,88 @@ ldap_back_db_config(
 
        /* URI of server to query (preferred over "server" directive) */
        } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
+               LDAPURLDesc     *tmpludp;
+               int             urlrc, i;
+
                if (argc != 2) {
-                       fprintf( stderr,
-       "%s: line %d: missing address in \"uri <address>\" line\n",
-                           fname, lineno );
+                       fprintf( stderr, "%s: line %d: "
+                               "missing uri "
+                               "in \"uri <uri>\" line\n",
+                               fname, lineno );
                        return( 1 );
                }
-               if (li->url != NULL)
-                       ch_free(li->url);
-               li->url = ch_strdup(argv[1]);
+               if ( li->url != NULL ) {
+                       ch_free( li->url );
+               }
+               if ( li->lud != NULL ) {
+                       ldap_free_urldesc( li->lud );
+               }
+
+               urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
+               if ( urlrc != LDAP_URL_SUCCESS ) {
+                       char    *why;
+
+                       switch ( urlrc ) {
+                       case LDAP_URL_ERR_MEM:
+                               why = "no memory";
+                               break;
+                       case LDAP_URL_ERR_PARAM:
+                               why = "parameter is bad";
+                               break;
+                       case LDAP_URL_ERR_BADSCHEME:
+                               why = "URL doesn't begin with \"[c]ldap[si]://\"";
+                               break;
+                       case LDAP_URL_ERR_BADENCLOSURE:
+                               why = "URL is missing trailing \">\"";
+                               break;
+                       case LDAP_URL_ERR_BADURL:
+                               why = "URL is bad";
+                       case LDAP_URL_ERR_BADHOST:
+                               why = "host/port is bad";
+                               break;
+                       case LDAP_URL_ERR_BADATTRS:
+                               why = "bad (or missing) attributes";
+                               break;
+                       case LDAP_URL_ERR_BADSCOPE:
+                               why = "scope string is invalid (or missing)";
+                               break;
+                       case LDAP_URL_ERR_BADFILTER:
+                               why = "bad or missing filter";
+                               break;
+                       case LDAP_URL_ERR_BADEXTS:
+                               why = "bad or missing extensions";
+                               break;
+                       default:
+                               why = "unknown reason";
+                               break;
+                       }
+                       fprintf( stderr, "%s: line %d: "
+                                       "unable to parse uri \"%s\" "
+                                       "in \"uri <uri>\" line: %s\n",
+                                       fname, lineno, argv[ 1 ], why );
+                       return 1;
+               }
+
+               for ( i = 0, tmpludp = li->lud;
+                               tmpludp;
+                               i++, tmpludp = tmpludp->lud_next )
+               {
+                       if ( ( tmpludp->lud_dn != NULL
+                                               && tmpludp->lud_dn[0] != '\0' )
+                                       || tmpludp->lud_attrs != NULL
+                                       || tmpludp->lud_filter != NULL
+                                       || tmpludp->lud_exts != NULL )
+                       {
+                               fprintf( stderr, "%s: line %d: "
+                                               "warning, only protocol, "
+                                               "host and port allowed "
+                                               "in \"uri <uri>\" statement "
+                                               "for uri #%d of \"%s\"\n",
+                                               fname, lineno, i, argv[1] );
+                       }
+               }
+
+               li->url = ch_strdup( argv[ 1 ] );
 
        /* name to use for ldap_back_group */
        } else if ( strcasecmp( argv[0], "binddn" ) == 0 ) {
@@ -102,7 +164,7 @@ ldap_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->binddn = ch_strdup(argv[1]);
+               ber_str2bv( argv[1], 0, 1, &li->binddn );
 
        /* password to use for ldap_back_group */
        } else if ( strcasecmp( argv[0], "bindpw" ) == 0 ) {
@@ -112,8 +174,30 @@ ldap_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               li->bindpw = ch_strdup(argv[1]);
-       
+               ber_str2bv( argv[1], 0, 1, &li->bindpw );
+
+#ifdef LDAP_BACK_PROXY_AUTHZ
+       /* name to use for proxyAuthz propagation */
+       } else if ( strcasecmp( argv[0], "proxyauthzdn" ) == 0 ) {
+               if (argc != 2) {
+                       fprintf( stderr,
+       "%s: line %d: missing name in \"proxyauthzdn <name>\" line\n",
+                           fname, lineno );
+                       return( 1 );
+               }
+               ber_str2bv( argv[1], 0, 1, &li->proxyauthzdn );
+
+       /* password to use for proxyAuthz propagation */
+       } else if ( strcasecmp( argv[0], "proxyauthzpw" ) == 0 ) {
+               if (argc != 2) {
+                       fprintf( stderr,
+       "%s: line %d: missing password in \"proxyauthzpw <password>\" line\n",
+                           fname, lineno );
+                       return( 1 );
+               }
+               ber_str2bv( argv[1], 0, 1, &li->proxyauthzpw );
+#endif /* LDAP_BACK_PROXY_AUTHZ */
+
        /* save bind creds for referral rebinds? */
        } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
                if (argc != 1) {
@@ -132,7 +216,8 @@ ldap_back_db_config(
                            fname, lineno );
                        return( 1 );
                }
-               load_extop( (struct berval *)&slap_EXOP_WHOAMI, ldap_back_exop_whoami );
+               load_extop( (struct berval *)&slap_EXOP_WHOAMI,
+                       0, ldap_back_exop_whoami );
        
        /* dn massaging */
        } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
@@ -162,7 +247,7 @@ ldap_back_db_config(
                }
                
                ber_str2bv( argv[1], 0, 0, &bvnc );
-               if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc ) != LDAP_SUCCESS ) {
+               if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
                        fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
                                fname, lineno, bvnc.bv_val );
                        return( 1 );
@@ -180,7 +265,7 @@ ldap_back_db_config(
                }
 
                ber_str2bv( argv[2], 0, 0, &brnc );
-               if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc ) != LDAP_SUCCESS ) {
+               if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
                        fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
                                fname, lineno, brnc.bv_val );
                        free( nvnc.bv_val );
@@ -211,7 +296,8 @@ ldap_back_db_config(
                 * FIXME: no extra rewrite capabilities should be added
                 * to the database
                 */
-               rc = suffix_massage_config( li->rwinfo, &pvnc, &nvnc, &prnc, &nrnc );
+               rc = suffix_massage_config( li->rwmap.rwm_rw,
+                               &pvnc, &nvnc, &prnc, &nrnc );
                free( nvnc.bv_val );
                free( pvnc.bv_val );
                free( nrnc.bv_val );
@@ -220,17 +306,18 @@ ldap_back_db_config(
                return( rc );
 
 #else /* !ENABLE_REWRITE */
-               ber_bvarray_add( &li->suffix_massage, &pvnc );
-               ber_bvarray_add( &li->suffix_massage, &nvnc );
+               ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &pvnc );
+               ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nvnc );
                
-               ber_bvarray_add( &li->suffix_massage, &prnc );
-               ber_bvarray_add( &li->suffix_massage, &nrnc );
+               ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &prnc );
+               ber_bvarray_add( &li->rwmap.rwm_suffix_massage, &nrnc );
 #endif /* !ENABLE_REWRITE */
 
        /* rewrite stuff ... */
        } else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) {
 #ifdef ENABLE_REWRITE
-               return rewrite_parse( li->rwinfo, fname, lineno, argc, argv );
+               return rewrite_parse( li->rwmap.rwm_rw,
+                               fname, lineno, argc, argv );
 
 #else /* !ENABLE_REWRITE */
                fprintf( stderr, "%s: line %d: rewrite capabilities "
@@ -239,14 +326,13 @@ ldap_back_db_config(
                
        /* objectclass/attribute mapping */
        } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
-               return ldap_back_map_config( &li->oc_map, &li->at_map,
+               return ldap_back_map_config( &li->rwmap.rwm_oc,
+                               &li->rwmap.rwm_at,
                                fname, lineno, argc, argv );
 
        /* anything else */
        } else {
-               fprintf( stderr, "%s: line %d: unknown directive \"%s\" "
-                       "in ldap database definition (ignored)\n",
-                   fname, lineno, argv[0] );
+               return SLAP_CONF_UNKNOWN;
        }
        return 0;
 }
@@ -339,6 +425,7 @@ ldap_back_map_config(
                                /*
                                 * FIXME: this should become an err
                                 */
+                               goto error_return;
                        }
                }
 
@@ -364,6 +451,7 @@ ldap_back_map_config(
                                /*
                                 * FIXME: this should become an err
                                 */
+                               goto error_return;
                        }
 
                        ad = NULL;
@@ -384,7 +472,6 @@ ldap_back_map_config(
                fprintf( stderr,
                        "%s: line %d: duplicate mapping found (ignored)\n",
                        fname, lineno );
-               /* FIXME: free stuff */
                goto error_return;
        }
 
@@ -409,46 +496,35 @@ error_return:;
 
 static int
 ldap_back_exop_whoami(
-       Connection *conn,
        Operation *op,
-       struct berval *reqoid,
-       struct berval *reqdata,
-       char **rspoid,
-       struct berval **rspdata,
-       LDAPControl ***rspctrls,
-       const char **text,
-       BerVarray *refs )
+       SlapReply *rs )
 {
        struct berval *bv = NULL;
-       int rc = LDAP_SUCCESS;
 
-       if ( reqdata != NULL ) {
+       if ( op->oq_extended.rs_reqdata != NULL ) {
                /* no request data should be provided */
-               *text = "no request data expected";
-               return LDAP_PROTOCOL_ERROR;
+               rs->sr_text = "no request data expected";
+               return rs->sr_err = LDAP_PROTOCOL_ERROR;
        }
 
-       {
-               rc = backend_check_restrictions( conn->c_authz_backend,
-                       conn, op, (struct berval *)&slap_EXOP_WHOAMI, text );
-
-               if( rc != LDAP_SUCCESS ) return rc;
-       }
+       rs->sr_err = backend_check_restrictions( op, rs, 
+                       (struct berval *)&slap_EXOP_WHOAMI );
+       if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
 
        /* if auth'd by back-ldap and request is proxied, forward it */
-       if ( conn->c_authz_backend && !strcmp(conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &conn->c_ndn)) {
-               struct ldapinfo *li =
-                       (struct ldapinfo *)conn->c_authz_backend->be_private;
+       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)) {
                struct ldapconn *lc;
 
-               LDAPControl c, *ctrls[2] = {&c, NULL};
+               LDAPControl c, *ctrls[2] = {NULL, NULL};
                LDAPMessage *res;
                Operation op2 = *op;
                ber_int_t msgid;
+               int do_retry = 1;
 
-               op2.o_ndn = conn->c_ndn;
-               lc = ldap_back_getconn(li, conn, &op2);
-               if (!lc || !ldap_back_dobind( li, lc, conn, op )) {
+               ctrls[0] = &c;
+               op2.o_ndn = op->o_conn->c_ndn;
+               lc = ldap_back_getconn(&op2, rs);
+               if (!lc || !ldap_back_dobind( lc, op, rs )) {
                        return -1;
                }
                c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
@@ -458,28 +534,37 @@ ldap_back_exop_whoami(
                strcpy(c.ldctl_value.bv_val, "dn:");
                strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
 
-               rc = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
-               if (rc == LDAP_SUCCESS) {
+retry:
+               rs->sr_err = ldap_whoami(lc->ld, ctrls, NULL, &msgid);
+               if (rs->sr_err == LDAP_SUCCESS) {
                        if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
                                ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
-                                       &rc);
+                                       &rs->sr_err);
+                               if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
+                                       do_retry = 0;
+                                       if ( ldap_back_retry( lc, op, rs ))
+                                               goto retry;
+                               }
+                               ldap_back_freeconn( op, lc );
+                               lc = NULL;
+
                        } else {
-                               rc = ldap_parse_whoami(lc->ld, res, &bv);
+                               rs->sr_err = ldap_parse_whoami(lc->ld, res, &bv);
                                ldap_msgfree(res);
                        }
                }
                ch_free(c.ldctl_value.bv_val);
-               if (rc != LDAP_SUCCESS) {
-                       rc = ldap_back_map_result(rc);
+               if (rs->sr_err != LDAP_SUCCESS) {
+                       rs->sr_err = slap_map_api2result( rs );
                }
        } else {
        /* else just do the same as before */
                bv = (struct berval *) ch_malloc( sizeof(struct berval) );
                if( op->o_dn.bv_len ) {
-                       bv->bv_len = op->o_dn.bv_len + sizeof("dn:")-1;
+                       bv->bv_len = op->o_dn.bv_len + sizeof("dn:") - 1;
                        bv->bv_val = ch_malloc( bv->bv_len + 1 );
-                       AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:")-1 );
-                       AC_MEMCPY( &bv->bv_val[sizeof("dn:")-1], op->o_dn.bv_val,
+                       AC_MEMCPY( bv->bv_val, "dn:", sizeof("dn:") - 1 );
+                       AC_MEMCPY( &bv->bv_val[sizeof("dn:") - 1], op->o_dn.bv_val,
                                op->o_dn.bv_len );
                        bv->bv_val[bv->bv_len] = '\0';
                } else {
@@ -488,8 +573,8 @@ ldap_back_exop_whoami(
                }
        }
 
-       *rspdata = bv;
-       return rc;
+       rs->sr_rspdata = bv;
+       return rs->sr_err;
 }
 
 
@@ -501,14 +586,21 @@ suffix_massage_regexize( const char *s )
        const char *p, *r;
        int i;
 
+       if ( s[ 0 ] == '\0' ) {
+               return ch_strdup( "^(.+)$" );
+       }
+
        for ( i = 0, p = s; 
                        ( r = strchr( p, ',' ) ) != NULL; 
                        p = r + 1, i++ )
                ;
 
-       res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
+       res = ch_calloc( sizeof( char ), strlen( s )
+               + STRLENOF( "((.+),)?" )
+               + STRLENOF( "[ ]?" ) * i
+               + STRLENOF( "$" ) + 1 );
 
-       ptr = lutil_strcopy( res, "(.*)" );
+       ptr = lutil_strcopy( res, "((.+),)?" );
        for ( i = 0, p = s;
                        ( r = strchr( p, ',' ) ) != NULL;
                        p = r + 1 , i++ ) {
@@ -519,26 +611,37 @@ suffix_massage_regexize( const char *s )
                        r++;
                }
        }
-       lutil_strcopy( ptr, p );
+       ptr = lutil_strcopy( ptr, p );
+       ptr[ 0 ] = '$';
+       ptr++;
+       ptr[ 0 ] = '\0';
 
        return res;
 }
 
 static char *
-suffix_massage_patternize( const char *s )
+suffix_massage_patternize( const char *s, const char *p )
 {
        ber_len_t       len;
-       char            *res;
+       char            *res, *ptr;
 
-       len = strlen( s );
+       len = strlen( p );
+
+       if ( s[ 0 ] == '\0' ) {
+               len++;
+       }
 
        res = ch_calloc( sizeof( char ), len + sizeof( "%1" ) );
        if ( res == NULL ) {
                return NULL;
        }
 
-       strcpy( res, "%1" );
-       strcpy( res + sizeof( "%1" ) - 1, s );
+       ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
+       if ( s[ 0 ] == '\0' ) {
+               ptr[ 0 ] = ',';
+               ptr++;
+       }
+       ptr = lutil_strcopy( ptr, p );
 
        return res;
 }
@@ -567,12 +670,21 @@ suffix_massage_config(
 
        rargv[ 0 ] = "rewriteRule";
        rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
-       rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val );
+       rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
        rargv[ 3 ] = ":";
        rargv[ 4 ] = NULL;
        rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
        ch_free( rargv[ 1 ] );
        ch_free( rargv[ 2 ] );
+
+       if ( BER_BVISEMPTY( pvnc ) ) {
+               rargv[ 0 ] = "rewriteRule";
+               rargv[ 1 ] = "^$";
+               rargv[ 2 ] = prnc->bv_val;
+               rargv[ 3 ] = ":";
+               rargv[ 4 ] = NULL;
+               rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
+       }
        
        rargv[ 0 ] = "rewriteContext";
        rargv[ 1 ] = "searchResult";
@@ -581,122 +693,35 @@ suffix_massage_config(
        
        rargv[ 0 ] = "rewriteRule";
        rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
-       rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val );
+       rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
        rargv[ 3 ] = ":";
        rargv[ 4 ] = NULL;
        rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
        ch_free( rargv[ 1 ] );
        ch_free( rargv[ 2 ] );
 
-#if 0
-       /*
-        * FIXME: this is no longer required since now we map filters
-        * based on the parsed filter structure, so we can deal directly
-        * with attribute types and values.  The rewriteContext 
-        * "searchFilter" now refers to the value of attrbutes
-        * with DN syntax.
-        */
-
-       /*
-        * the filter should be rewritten as
-        * 
-        * rewriteRule
-        *      "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)"
-        *      "%1member=%2,dc=example,dc=com%3"
-        *
-        * where "o=Foo Bar, c=US" is the virtual naming context,
-        * and "dc=example, dc=com" is the real naming context
-        */
-       rargv[ 0 ] = "rewriteContext";
-       rargv[ 1 ] = "searchFilter";
-       rargv[ 2 ] = NULL;
-       rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
-
-#if 1 /* rewrite filters */
-       {
-               /*
-                * Note: this is far more optimistic than desirable:
-                * for any AVA value ending with the virtual naming
-                * context the terminal part will be replaced by the
-                * real naming context; a better solution would be to
-                * walk the filter looking for DN-valued attributes,
-                * and only rewrite those that require rewriting
-                */
-               char    vbuf_[BUFSIZ], *vbuf = vbuf_,
-                       rbuf_[BUFSIZ], *rbuf = rbuf_;
-               int     len;
-
-               len = snprintf( vbuf, sizeof( vbuf_ ), 
-                               "(.*)%s\\)(.*)", nvnc->bv_val );
-               if ( len == -1 ) {
-                       /* 
-                        * traditional behavior: snprintf returns -1 
-                        * if buffer is insufficient
-                        */
-                       return -1;
-
-               } else if ( len >= (int)sizeof( vbuf_ ) ) {
-                       /* 
-                        * C99: snprintf returns the required size 
-                        */
-                       vbuf = ch_malloc( len + 1 );
-                       len = snprintf( vbuf, len,
-                                       "(.*)%s\\)(.*)", nvnc->bv_val );
-                       assert( len > 0 );
-               }
-
-               len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
-                               nrnc->bv_val );
-               if ( len == -1 ) {
-                       return -1;
-
-               } else if ( len >= (int)sizeof( rbuf_ ) ) {
-                       rbuf = ch_malloc( len + 1 );
-                       len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
-                                       nrnc->bv_val );
-                       assert( len > 0 );
-               }
-               
+       if ( BER_BVISEMPTY( prnc ) ) {
                rargv[ 0 ] = "rewriteRule";
-               rargv[ 1 ] = vbuf;
-               rargv[ 2 ] = rbuf;
+               rargv[ 1 ] = "^$";
+               rargv[ 2 ] = pvnc->bv_val;
                rargv[ 3 ] = ":";
                rargv[ 4 ] = NULL;
                rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
-
-               if ( vbuf != vbuf_ ) {
-                       ch_free( vbuf );
-               }
-
-               if ( rbuf != rbuf_ ) {
-                       ch_free( rbuf );
-               }
        }
-#endif /* rewrite filters */
-#endif
-
-#if 0 /*  "matched" is not normalized */
+       
        rargv[ 0 ] = "rewriteContext";
-       rargv[ 1 ] = "matchedDn";
+       rargv[ 1 ] = "matchedDN";
        rargv[ 2 ] = "alias";
        rargv[ 3 ] = "searchResult";
        rargv[ 4 ] = NULL;
        rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
-#else /* normalize "matched" */
-       rargv[ 0 ] = "rewriteContext";
-       rargv[ 1 ] = "matchedDn";
-       rargv[ 2 ] = NULL;
-       rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
 
-       rargv[ 0 ] = "rewriteRule";
-       rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
-       rargv[ 2 ] = suffix_massage_patternize( nvnc->bv_val );
-       rargv[ 3 ] = ":";
+       rargv[ 0 ] = "rewriteContext";
+       rargv[ 1 ] = "searchAttrDN";
+       rargv[ 2 ] = "alias";
+       rargv[ 3 ] = "searchResult";
        rargv[ 4 ] = NULL;
        rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
-       ch_free( rargv[ 1 ] );
-       ch_free( rargv[ 2 ] );
-#endif /* normalize "matched" */
 
        return 0;
 }