]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Don't return frontend as SLAPI_BACKEND, return actual backend instead
[openldap] / servers / slapd / slapi / slapi_utils.c
index 8c17edc3e68daa931e0d3199945fc4a1988c7621..f2ac0cf24b3db170e46e1939af21af88caf0610c 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2002-2004 The OpenLDAP Foundation.
+ * Copyright 2002-2005 The OpenLDAP Foundation.
  * Portions Copyright 1997,2002-2003 IBM Corporation.
  * All rights reserved.
  *
 #include <ac/stdarg.h>
 #include <ac/ctype.h>
 #include <ac/unistd.h>
-#include <ldap_pvt.h>
 
 #include <slap.h>
 #include <slapi.h>
 
 #include <netdb.h>
 
+#ifdef LDAP_SLAPI
+
 /*
  * server start time (should we use a struct timeval also in slapd?
  */
@@ -49,7 +50,6 @@ struct slapi_condvar {
        ldap_pvt_thread_mutex_t mutex;
 };
 
-#ifdef LDAP_SLAPI
 static int checkBVString(const struct berval *bv)
 {
        int i;
@@ -63,7 +63,6 @@ static int checkBVString(const struct berval *bv)
 
        return 1;
 }
-#endif /* LDAP_SLAPI */
 
 /*
  * This function converts an array of pointers to berval objects to
@@ -111,7 +110,6 @@ slapi_str2entry(
        char            *s, 
        int             flags )
 {
-#ifdef LDAP_SLAPI
        Slapi_Entry     *e = NULL;
        char            *pTmpS;
 
@@ -122,9 +120,6 @@ slapi_str2entry(
        }
 
        return e;
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
@@ -132,7 +127,6 @@ slapi_entry2str(
        Slapi_Entry     *e, 
        int             *len ) 
 {
-#ifdef LDAP_SLAPI
        char            *ret;
 
        ldap_pvt_thread_mutex_lock( &entry2str_mutex );
@@ -140,29 +134,39 @@ slapi_entry2str(
        ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
 
        return ret;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_entry_get_dn( Slapi_Entry *e ) 
 {
-#ifdef LDAP_SLAPI
        return e->e_name.bv_val;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_x_entry_get_id( Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
        return e->e_id;
-#else
-       return NOID;
-#endif /* LDAP_SLAPI */
+}
+
+static int
+slapi_int_dn_pretty( struct berval *in, struct berval *out )
+{
+       Syntax          *syntax = slap_schema.si_syn_distinguishedName;
+
+       assert( syntax != NULL );
+
+       return (syntax->ssyn_pretty)( syntax, in, out, NULL );
+}
+
+static int
+slapi_int_dn_normalize( struct berval *in, struct berval *out )
+{
+       MatchingRule    *mr = slap_schema.si_mr_distinguishedNameMatch;
+       Syntax          *syntax = slap_schema.si_syn_distinguishedName;
+
+       assert( mr != NULL );
+
+       return (mr->smr_normalize)( 0, syntax, mr, in, out, NULL );
 }
 
 void 
@@ -170,24 +174,19 @@ slapi_entry_set_dn(
        Slapi_Entry     *e, 
        char            *ldn )
 {
-#ifdef LDAP_SLAPI
        struct berval   dn = BER_BVNULL;
 
        dn.bv_val = ldn;
        dn.bv_len = strlen( ldn );
 
-       dnPrettyNormal( NULL, &dn, &e->e_name, &e->e_nname, NULL );
-#endif /* LDAP_SLAPI */
+       slapi_int_dn_pretty( &dn, &e->e_name );
+       slapi_int_dn_normalize( &dn, &e->e_nname );
 }
 
 Slapi_Entry *
 slapi_entry_dup( Slapi_Entry *e ) 
 {
-#ifdef LDAP_SLAPI
        return entry_dup( e );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -195,7 +194,6 @@ slapi_entry_attr_delete(
        Slapi_Entry     *e,             
        char            *type ) 
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        const char              *text;
 
@@ -208,27 +206,19 @@ slapi_entry_attr_delete(
        } else {
                return -1;      /* something went wrong */
        }
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Entry *
 slapi_entry_alloc( void ) 
 {
-#ifdef LDAP_SLAPI
        return (Slapi_Entry *)slapi_ch_calloc( 1, sizeof(Slapi_Entry) );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
 slapi_entry_free( Slapi_Entry *e ) 
 {
-#ifdef LDAP_SLAPI
-       entry_free( e );
-#endif /* LDAP_SLAPI */
+       if ( e != NULL )
+               entry_free( e );
 }
 
 int 
@@ -237,7 +227,6 @@ slapi_entry_attr_merge(
        char            *type, 
        struct berval   **vals ) 
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        const char              *text;
        BerVarray               bv;
@@ -257,9 +246,6 @@ slapi_entry_attr_merge(
        ch_free( bv );
 
        return rc;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
@@ -268,7 +254,6 @@ slapi_entry_attr_find(
        char            *type, 
        Slapi_Attr      **attr ) 
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        const char              *text;
        int                     rc;
@@ -284,15 +269,11 @@ slapi_entry_attr_find(
        }
 
        return 0;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -318,15 +299,11 @@ slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type )
        }
 
        return NULL;
-#else
-       return -1;
-#endif
 }
 
 int
 slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -343,15 +320,11 @@ slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type )
        }
 
        return slapi_value_get_int( attr->a_vals );
-#else
-       return 0;
-#endif
 }
 
-int
+long
 slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -368,15 +341,11 @@ slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type )
        }
 
        return slapi_value_get_long( attr->a_vals );
-#else
-       return 0;
-#endif
 }
 
-int
+unsigned int
 slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -393,15 +362,11 @@ slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type )
        }
 
        return slapi_value_get_uint( attr->a_vals );
-#else
-       return 0;
-#endif
 }
 
-int
+unsigned long
 slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -418,15 +383,11 @@ slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type )
        }
 
        return slapi_value_get_ulong( attr->a_vals );
-#else
-       return 0;
-#endif
 }
 
 int
 slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
 {
-#ifdef LDAP_SLAPI
        struct berval bv;
        AttributeDescription *ad = NULL;
        const char *text;
@@ -447,15 +408,11 @@ slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value )
        bv.bv_len = strlen( value );
 
        return ( slapi_attr_value_find( attr, &bv ) != -1 );
-#else
-       return 0;
-#endif
 }
 
 void
 slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value)
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        const char              *text;
        int                     rc;
@@ -472,90 +429,69 @@ slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value
                bv.bv_len = strlen(value);
                attr_merge_normalize_one( e, ad, &bv, NULL );
        }
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l)
 {
-#ifdef LDAP_SLAPI
        char buf[64];
 
        snprintf( buf, sizeof( buf ), "%d", l );
        slapi_entry_attr_set_charptr( e, type, buf );
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l)
 {
-#ifdef LDAP_SLAPI
        char buf[64];
 
        snprintf( buf, sizeof( buf ), "%u", l );
        slapi_entry_attr_set_charptr( e, type, buf );
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l)
 {
-#ifdef LDAP_SLAPI
        char buf[64];
 
        snprintf( buf, sizeof( buf ), "%ld", l );
        slapi_entry_attr_set_charptr( e, type, buf );
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l)
 {
-#ifdef LDAP_SLAPI
        char buf[64];
 
        snprintf( buf, sizeof( buf ), "%lu", l );
        slapi_entry_attr_set_charptr( e, type, buf );
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_is_rootdse( const char *dn )
 {
-#ifdef LDAP_SLAPI
        return ( dn == NULL || dn[0] == '\0' );
-#else
-       return 0;
-#endif
 }
 
 int
-slapi_entry_has_children(const Slapi_Entry *e)
+slapi_entry_has_children( const Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
-       Connection *pConn;
-       Operation *op;
+       Slapi_PBlock *pb;
        int hasSubordinates = 0;
 
-       pConn = slapi_int_init_connection( NULL, LDAP_REQ_SEARCH );
-       if ( pConn == NULL ) {
-               return 0;
-       }
+       pb = slapi_pblock_new();
+       slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
 
-       op = (Operation *)pConn->c_pending_ops.stqh_first;
-       op->o_bd = select_backend( (struct berval *)&e->e_nname, 0, 0 );
-       if ( op->o_bd == NULL ) {
-               return 0;
-       }
+       slapi_pblock_set( pb, SLAPI_TARGET_DN, slapi_entry_get_dn( (Entry *)e ) );
 
-       op->o_bd->be_has_subordinates( op, (Entry *)e, &hasSubordinates );
+       pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0, 0 );
+       if ( pb->pb_op->o_bd != NULL ) {
+               pb->pb_op->o_bd->be_has_subordinates( pb->pb_op, (Entry *)e, &hasSubordinates );
+       }
 
-       slapi_int_connection_destroy( &pConn );
+       slapi_pblock_destroy( pb );
 
        return ( hasSubordinates == LDAP_COMPARE_TRUE );
-#else
-       return 0;
-#endif
 }
 
 /*
@@ -567,12 +503,11 @@ slapi_entry_has_children(const Slapi_Entry *e)
  */
 size_t slapi_entry_size(Slapi_Entry *e)
 {
-#ifdef LDAP_SLAPI
        size_t size;
        Attribute *a;
        int i;
 
-       for ( size = 0, a = e->e_attrs; a != NULL; a->a_next ) {
+       for ( size = 0, a = e->e_attrs; a != NULL; a = a->a_next ) {
                for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
                        size += a->a_vals[i].bv_len + 1;
                }
@@ -582,9 +517,6 @@ size_t slapi_entry_size(Slapi_Entry *e)
        size -= (size % 1024);
 
        return size;
-#else
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -598,13 +530,13 @@ size_t slapi_entry_size(Slapi_Entry *e)
 int
 slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
 {
-#ifdef LDAP_SLAPI
        Modification            mod;
        const char              *text;
        int                     rc;
        char                    textbuf[SLAP_TEXT_BUFLEN];
 
        mod.sm_op = LDAP_MOD_ADD;
+       mod.sm_flags = 0;
        mod.sm_desc = NULL;
        mod.sm_type.bv_val = (char *)type;
        mod.sm_type.bv_len = strlen( type );
@@ -630,28 +562,20 @@ slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals )
 
        rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
 
-       ch_free( mod.sm_values );
+       slapi_ch_free( (void **)&mod.sm_values );
 
        return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
 {
-#ifdef LDAP_SLAPI
        return slapi_entry_add_values( e, type, vals );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        const char              *text;
        int                     rc;
@@ -662,21 +586,18 @@ slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs)
        }
 
        return attr_merge_normalize( e, ad, *vs, NULL );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **vals )
 {
-#ifdef LDAP_SLAPI
        Modification            mod;
        const char              *text;
        int                     rc;
        char                    textbuf[SLAP_TEXT_BUFLEN];
 
        mod.sm_op = LDAP_MOD_DELETE;
+       mod.sm_flags = 0;
        mod.sm_desc = NULL;
        mod.sm_type.bv_val = (char *)type;
        mod.sm_type.bv_len = strlen( type );
@@ -692,7 +613,7 @@ slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **val
        }
 
        if ( vals[0] == NULL ) {
-               /* SLAPI doco says LDAP_OPERATIONS_ERROR but LDAP_OTHER is better */
+               /* SLAPI doco says LDApb_opERATIONS_ERROR but LDAP_OTHER is better */
                return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
        }
 
@@ -704,38 +625,26 @@ slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **val
 
        rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
 
-       ch_free( mod.sm_values );
+       slapi_ch_free( (void **)&mod.sm_values );
 
        return rc;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
 {
-#ifdef LDAP_SLAPI
        return slapi_entry_delete_values( e, type, vals );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
 {
-#ifdef LDAP_SLAPI
        return slapi_entry_attr_merge( e, (char *)type, vals );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        AttributeDescription    *ad = NULL;
        int                     rc;
        const char              *text;
@@ -751,30 +660,22 @@ slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value
        }
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
 {
-#ifdef LDAP_SLAPI
        Slapi_Value val;
 
        val.bv_val = (char *)value;
        val.bv_len = strlen( value );
 
        return slapi_entry_add_value( e, type, &val );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
 {
-#ifdef LDAP_SLAPI
        Slapi_Value *vals[2];
        Slapi_Value val;
 
@@ -784,26 +685,17 @@ slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value)
        vals[1] = NULL;
 
        return slapi_entry_delete_values_sv( e, type, vals );   
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
-
 int
 slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
 {
-#ifdef LDAP_SLAPI
        return slapi_entry_attr_merge( e, (char *)type, vals );
-#else
-       return -1;
-#endif
 }
 
 int
 slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
 {
-#ifdef LDAP_SLAPI
        if ( e == NULL ) {
                return -1;
        }
@@ -811,15 +703,11 @@ slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr )
        *attr = e->e_attrs;
 
        return ( *attr != NULL ) ? 0 : -1;
-#else
-       return -1;
-#endif
 }
 
 int
 slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr )
 {
-#ifdef LDAP_SLAPI
        if ( e == NULL ) {
                return -1;
        }
@@ -831,15 +719,11 @@ slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **
        *attr = prevattr->a_next;
 
        return ( *attr != NULL ) ? 0 : -1;
-#else
-       return -1;
-#endif
 }
 
 int
 slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
        int rc;
@@ -864,9 +748,6 @@ slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **val
        }
        
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 /* 
@@ -878,7 +759,6 @@ slapi_attr_get_values(
        Slapi_Attr      *attr, 
        struct berval   ***vals ) 
 {
-#ifdef LDAP_SLAPI
        int             i, j;
        struct berval   **bv;
 
@@ -899,15 +779,11 @@ slapi_attr_get_values(
        *vals = (struct berval **)bv;
 
        return 0;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_dn_normalize( char *dn ) 
 {
-#ifdef LDAP_SLAPI
        struct berval   bdn;
        struct berval   pdn;
 
@@ -916,20 +792,16 @@ slapi_dn_normalize( char *dn )
        bdn.bv_val = dn;
        bdn.bv_len = strlen( dn );
 
-       if ( dnPretty( NULL, &bdn, &pdn, NULL ) != LDAP_SUCCESS ) {
+       if ( slapi_int_dn_pretty( &bdn, &pdn ) != LDAP_SUCCESS ) {
                return NULL;
        }
 
        return pdn.bv_val;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_dn_normalize_case( char *dn ) 
 {
-#ifdef LDAP_SLAPI
        struct berval   bdn;
        struct berval   ndn;
 
@@ -938,14 +810,11 @@ slapi_dn_normalize_case( char *dn )
        bdn.bv_val = dn;
        bdn.bv_len = strlen( dn );
 
-       if ( dnNormalize( 0, NULL, NULL, &bdn, &ndn, NULL ) != LDAP_SUCCESS ) {
+       if ( slapi_int_dn_normalize( &bdn, &ndn ) != LDAP_SUCCESS ) {
                return NULL;
        }
 
        return ndn.bv_val;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -953,7 +822,6 @@ slapi_dn_issuffix(
        char            *dn, 
        char            *suffix )
 {
-#ifdef LDAP_SLAPI
        struct berval   bdn, ndn;
        struct berval   bsuffix, nsuffix;
        int rc;
@@ -984,9 +852,6 @@ slapi_dn_issuffix(
        slapi_ch_free( (void **)&nsuffix.bv_val );
 
        return rc;
-#else /* LDAP_SLAPI */
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 int
@@ -994,7 +859,6 @@ slapi_dn_isparent(
        const char      *parentdn,
        const char      *childdn )
 {
-#ifdef LDAP_SLAPI
        struct berval   assertedParentDN, normalizedAssertedParentDN;
        struct berval   childDN, normalizedChildDN;
        struct berval   normalizedParentDN;
@@ -1034,9 +898,6 @@ slapi_dn_isparent(
        slapi_ch_free( (void **)&normalizedChildDN.bv_val );
 
        return ( match == 0 );
-#else
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -1046,7 +907,6 @@ slapi_dn_isparent(
 char *
 slapi_dn_parent( const char *_dn )
 {
-#ifdef LDAP_SLAPI
        struct berval   dn, prettyDN;
        struct berval   parentDN;
 
@@ -1074,9 +934,27 @@ slapi_dn_parent( const char *_dn )
        }
 
        return slapi_ch_strdup( parentDN.bv_val );
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
+}
+
+int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *ldn )
+{
+       struct berval   ndn;
+       Backend         *be;
+
+       if ( slapi_is_rootdse( ldn ) ) {
+               return 0;
+       }
+
+       /* according to spec should already be normalized */
+       ndn.bv_len = strlen( ldn );
+       ndn.bv_val = ldn;
+
+       be = select_backend( &pb->pb_op->o_req_ndn, 0, 0 );
+       if ( be == NULL ) {
+               return 0;
+       }
+
+       return be_issuffix( be, &ndn );
 }
 
 /*
@@ -1084,85 +962,75 @@ slapi_dn_parent( const char *_dn )
  * an empty string, if the DN has no parent, or if the
  * DN is the suffix of the backend database
  */
-char *slapi_dn_beparent( Slapi_PBlock *pb, const char *_dn )
+char *slapi_dn_beparent( Slapi_PBlock *pb, const char *ldn )
 {
-#ifdef LDAP_SLAPI
        Backend         *be;
        struct berval   dn, prettyDN;
        struct berval   normalizedDN, parentDN;
+       char            *parent = NULL;
 
-       if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 )
-               be = NULL;
+       if ( pb == NULL ) {
+               return NULL;
+       }
 
-       dn.bv_val = (char *)_dn;
-       dn.bv_len = strlen( _dn );
+       PBLOCK_ASSERT_OP( pb, 0 );
 
-       if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) {
+       if ( slapi_is_rootdse( ldn ) ) {
                return NULL;
        }
 
-       if ( be != NULL && be_issuffix( be, &normalizedDN ) ) {
-               slapi_ch_free( (void **)&prettyDN.bv_val );
-               slapi_ch_free( (void **)&normalizedDN.bv_val );
+       dn.bv_val = (char *)ldn;
+       dn.bv_len = strlen( ldn );
+
+       if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) {
                return NULL;
        }
 
-       dnParent( &prettyDN, &parentDN );
+       be = select_backend( &pb->pb_op->o_req_ndn, 0, 0 );
 
-       slapi_ch_free( (void **)&prettyDN.bv_val );
-       slapi_ch_free( (void **)&normalizedDN.bv_val );
+       if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) {
+               dnParent( &prettyDN, &parentDN );
 
-       if ( parentDN.bv_len == 0 ) {
-               return NULL;
+               if ( parentDN.bv_len != 0 )
+                       parent = slapi_ch_strdup( parentDN.bv_val );
        }
 
-       return slapi_ch_strdup( parentDN.bv_val );
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
+       slapi_ch_free_string( &prettyDN.bv_val );
+       slapi_ch_free_string( &normalizedDN.bv_val );
+
+       return parent;
 }
 
 char *
 slapi_dn_ignore_case( char *dn )
 {       
-#ifdef LDAP_SLAPI
        return slapi_dn_normalize_case( dn );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_ch_malloc( unsigned long size ) 
 {
-#ifdef LDAP_SLAPI
        return ch_malloc( size );       
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
 slapi_ch_free( void **ptr ) 
 {
-#ifdef LDAP_SLAPI
+       if ( ptr == NULL || *ptr == NULL )
+               return;
        ch_free( *ptr );
        *ptr = NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
 slapi_ch_free_string( char **ptr ) 
 {
-#ifdef LDAP_SLAPI
        slapi_ch_free( (void **)ptr );
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_ch_array_free( char **arrayp )
 {
-#ifdef LDAP_SLAPI
        char **p;
 
        if ( arrayp != NULL ) {
@@ -1171,13 +1039,11 @@ slapi_ch_array_free( char **arrayp )
                }
                slapi_ch_free( (void **)&arrayp );
        }
-#endif
 }
 
 struct berval *
 slapi_ch_bvdup(const struct berval *v)
 {
-#ifdef LDAP_SLAPI
        struct berval *bv;
 
        bv = (struct berval *) slapi_ch_malloc( sizeof(struct berval) );
@@ -1186,15 +1052,11 @@ slapi_ch_bvdup(const struct berval *v)
        AC_MEMCPY( bv->bv_val, v->bv_val, bv->bv_len );
 
        return bv;
-#else
-       return NULL;
-#endif
 }
 
 struct berval **
 slapi_ch_bvecdup(const struct berval **v)
 {
-#ifdef LDAP_SLAPI
        int i;
        struct berval **rv;
 
@@ -1213,9 +1075,6 @@ slapi_ch_bvecdup(const struct berval **v)
        rv[i] = NULL;
 
        return rv;
-#else
-       return NULL;
-#endif
 }
 
 char *
@@ -1223,11 +1082,7 @@ slapi_ch_calloc(
        unsigned long nelem, 
        unsigned long size ) 
 {
-#ifdef LDAP_SLAPI
        return ch_calloc( nelem, size );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
@@ -1235,31 +1090,19 @@ slapi_ch_realloc(
        char *block, 
        unsigned long size ) 
 {
-#ifdef LDAP_SLAPI
        return ch_realloc( block, size );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char *
 slapi_ch_strdup( char *s ) 
 {
-#ifdef LDAP_SLAPI
        return ch_strdup( (const char *)s );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 size_t
 slapi_ch_stlen( char *s ) 
 {
-#ifdef LDAP_SLAPI
        return strlen( (const char *)s );
-#else /* LDAP_SLAPI */
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -1269,7 +1112,6 @@ slapi_control_present(
        struct berval   **val, 
        int             *iscritical ) 
 {
-#ifdef LDAP_SLAPI
        int             i;
        int             rc = 0;
 
@@ -1288,30 +1130,6 @@ slapi_control_present(
 
                rc = 1;
                if ( controls[i]->ldctl_value.bv_len != 0 ) {
-                       /*
-                        * FIXME: according to 6.1 specification,
-                        *    "The val output parameter is set
-                        *    to point into the controls array.
-                        *    A copy of the control value is
-                        *    not made."
-                        */
-#if 0
-                       struct berval   *pTmpBval;
-
-                       pTmpBval = (struct berval *)slapi_ch_malloc( sizeof(struct berval));
-                       if ( pTmpBval == NULL ) {
-                               rc = 0;
-                       } else {
-                               pTmpBval->bv_len = controls[i]->ldctl_value.bv_len;
-                               pTmpBval->bv_val = controls[i]->ldctl_value.bv_val;
-                               if ( val ) {
-                                       *val = pTmpBval;
-                               } else {
-                                       slapi_ch_free( (void **)&pTmpBval );
-                                       rc = 0;
-                               }
-                       }
-#endif /* 0 */
                        if ( val ) {
                                *val = &controls[i]->ldctl_value;
                        }
@@ -1325,12 +1143,8 @@ slapi_control_present(
        }
 
        return rc;
-#else /* LDAP_SLAPI */
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
-#ifdef LDAP_SLAPI
 static void
 slapControlMask2SlapiControlOp(slap_mask_t slap_mask,
        unsigned long *slapi_mask)
@@ -1398,7 +1212,7 @@ slapiControlOp2SlapControlMask(unsigned long slapi_mask,
        if ( slapi_mask & SLAPI_OPERATION_ABANDON )
                *slap_mask |= SLAP_CTRL_ABANDON;
 
-       *slap_mask |= SLAP_CTRL_FRONTEND;
+       *slap_mask |= SLAP_CTRL_GLOBAL;
 }
 
 static int
@@ -1411,20 +1225,17 @@ slapi_int_parse_control(
 
        return LDAP_SUCCESS;
 }
-#endif /* LDAP_SLAPI */
 
 void 
 slapi_register_supported_control(
        char            *controloid, 
        unsigned long   controlops )
 {
-#ifdef LDAP_SLAPI
        slap_mask_t controlmask;
 
        slapiControlOp2SlapControlMask( controlops, &controlmask );
 
-       register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control );
-#endif /* LDAP_SLAPI */
+       register_supported_control( controloid, controlmask, NULL, slapi_int_parse_control, NULL );
 }
 
 int 
@@ -1432,7 +1243,6 @@ slapi_get_supported_controls(
        char            ***ctrloidsp, 
        unsigned long   **ctrlopsp ) 
 {
-#ifdef LDAP_SLAPI
        int i, rc;
 
        rc = get_supported_controls( ctrloidsp, (slap_mask_t **)ctrlopsp );
@@ -1446,15 +1256,11 @@ slapi_get_supported_controls(
        }
 
        return LDAP_SUCCESS;
-#else /* LDAP_SLAPI */
-       return 1;
-#endif /* LDAP_SLAPI */
 }
 
 LDAPControl *
 slapi_dup_control( LDAPControl *ctrl )
 {
-#ifdef LDAP_SLAPI
        LDAPControl *ret;
 
        ret = (LDAPControl *)slapi_ch_malloc( sizeof(*ret) );
@@ -1463,39 +1269,29 @@ slapi_dup_control( LDAPControl *ctrl )
        ret->ldctl_iscritical = ctrl->ldctl_iscritical;
 
        return ret;
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
 slapi_register_supported_saslmechanism( char *mechanism )
 {
-#ifdef LDAP_SLAPI
        /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */
        slapi_log_error( SLAPI_LOG_FATAL, "slapi_register_supported_saslmechanism",
                        "OpenLDAP does not support dynamic registration of SASL mechanisms\n" );
-#endif /* LDAP_SLAPI */
 }
 
 char **
 slapi_get_supported_saslmechanisms( void )
 {
-#ifdef LDAP_SLAPI
        /* FIXME -- can not get the saslmechanism without a connection. */
        slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_supported_saslmechanisms",
                        "can not get the SASL mechanism list "
                        "without a connection\n" );
        return NULL;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 char **
 slapi_get_supported_extended_ops( void )
 {
-#ifdef LDAP_SLAPI
        int             i, j, k;
        char            **ppExtOpOID = NULL;
        int             numExtOps = 0;
@@ -1534,9 +1330,6 @@ slapi_get_supported_extended_ops( void )
        ppExtOpOID[ i + k ] = NULL;
 
        return ppExtOpOID;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
@@ -1548,43 +1341,27 @@ slapi_send_ldap_result(
        int             nentries, 
        struct berval   **urls ) 
 {
-#ifdef LDAP_SLAPI
-       Operation       *op;
-       struct berval   *s;
-       char            *extOID = NULL;
-       struct berval   *extValue = NULL;
-       int             rc;
-       SlapReply       rs = { REP_RESULT };
+       SlapReply       *rs;
 
-       slapi_pblock_get( pb, SLAPI_OPERATION, &op );
+       PBLOCK_ASSERT_OP( pb, 0 );
 
-       rs.sr_err = err;
-       rs.sr_matched = matched;
-       rs.sr_text = text;
-       rs.sr_ref = NULL;
-       rs.sr_ctrls = NULL;
+       rs = pb->pb_rs;
 
-       slapi_pblock_get( pb, SLAPI_RESCONTROLS, &rs.sr_ctrls );
+       rs->sr_err = err;
+       rs->sr_matched = matched;
+       rs->sr_text = text;
+       rs->sr_ref = NULL;
 
        if ( err == LDAP_SASL_BIND_IN_PROGRESS ) {
-               slapi_pblock_get( pb, SLAPI_BIND_RET_SASLCREDS, (void *) &rs.sr_sasldata );
-               send_ldap_sasl( op, &rs );
-               return;
-       }
+               send_ldap_sasl( pb->pb_op, rs );
+       } else if ( rs->sr_rspoid != NULL ) {
+               send_ldap_extended( pb->pb_op, rs );
+       } else {
+               if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
+                       rs->sr_nentries = nentries;
 
-       slapi_pblock_get( pb, SLAPI_EXT_OP_RET_OID, &extOID );
-       if ( extOID != NULL ) {
-               rs.sr_rspoid = extOID;
-               slapi_pblock_get( pb, SLAPI_EXT_OP_RET_VALUE, &rs.sr_rspdata );
-               send_ldap_extended( op, &rs );
-               return;
+               send_ldap_result( pb->pb_op, rs );
        }
-
-       if (op->o_tag == LDAP_REQ_SEARCH)
-               rs.sr_nentries = nentries;
-
-       send_ldap_result( op, &rs );
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -1595,29 +1372,31 @@ slapi_send_ldap_search_entry(
        char            **attrs, 
        int             attrsonly )
 {
-#ifdef LDAP_SLAPI
-       Operation       *pOp;
-       SlapReply       rs = { REP_RESULT };
-       int             i;
-       AttributeName   *an = NULL;
-       const char      *text;
+       SlapReply               rs = { REP_SEARCH };
+       int                     i = 0;
+       AttributeName           *an = NULL;
+       const char              *text;
+       int                     rc;
+
+       assert( pb->pb_op != NULL );
 
        if ( attrs != NULL ) {
                for ( i = 0; attrs[ i ] != NULL; i++ ) {
                        ; /* empty */
                }
-       } else {
-               i = 0;
        }
 
-       if ( i > 0 ) {
-               an = (AttributeName *) ch_malloc( (i+1) * sizeof(AttributeName) );
+       if ( i ) {
+               an = (AttributeName *) slapi_ch_malloc( (i+1) * sizeof(AttributeName) );
                for ( i = 0; attrs[i] != NULL; i++ ) {
-                       an[i].an_name.bv_val = ch_strdup( attrs[i] );
+                       an[i].an_name.bv_val = attrs[i];
                        an[i].an_name.bv_len = strlen( attrs[i] );
                        an[i].an_desc = NULL;
-                       if( slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text ) != LDAP_SUCCESS)
+                       rs.sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
+                       if ( rs.sr_err != LDAP_SUCCESS) {
+                               slapi_ch_free( (void **)&an );
                                return -1;
+                       }
                }
                an[i].an_name.bv_len = 0;
                an[i].an_name.bv_val = NULL;
@@ -1629,18 +1408,16 @@ slapi_send_ldap_search_entry(
        rs.sr_ref = NULL;
        rs.sr_ctrls = ectrls;
        rs.sr_attrs = an;
+       rs.sr_operational_attrs = NULL;
        rs.sr_entry = e;
        rs.sr_v2ref = NULL;
        rs.sr_flags = 0;
 
-       if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp ) != 0 ) {
-               return LDAP_OTHER;
-       }
+       rc = send_search_entry( pb->pb_op, &rs );
 
-       return send_search_entry( pOp, &rs );
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
+       slapi_ch_free( (void **)&an );
+
+       return rc;
 }
 
 int 
@@ -1652,8 +1429,6 @@ slapi_send_ldap_search_reference(
        struct berval   **v2refs
        )
 {
-#ifdef LDAP_SLAPI
-       Operation       *pOp;
        SlapReply       rs = { REP_SEARCHREF };
        int             rc;
 
@@ -1668,6 +1443,7 @@ slapi_send_ldap_search_reference(
 
        rs.sr_ctrls = ectrls;
        rs.sr_attrs = NULL;
+       rs.sr_operational_attrs = NULL;
        rs.sr_entry = e;
 
        if ( v2refs != NULL ) {
@@ -1680,32 +1456,18 @@ slapi_send_ldap_search_reference(
                rs.sr_v2ref = NULL;
        }
 
-       if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp ) != 0 ) {
-               return LDAP_OTHER;
-       }
-
-       rc = send_search_reference( pOp, &rs );
-
-       if ( rs.sr_ref != NULL )
-               slapi_ch_free( (void **)&rs.sr_ref );
+       rc = send_search_reference( pb->pb_op, &rs );
 
-       if ( rs.sr_v2ref != NULL )
-               slapi_ch_free( (void **)&rs.sr_v2ref );
+       slapi_ch_free( (void **)&rs.sr_ref );
+       slapi_ch_free( (void **)&rs.sr_v2ref );
 
        return rc;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Filter *
 slapi_str2filter( char *str ) 
 {
-#ifdef LDAP_SLAPI
        return str2filter( str );
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 void 
@@ -1713,15 +1475,12 @@ slapi_filter_free(
        Slapi_Filter    *f, 
        int             recurse ) 
 {
-#ifdef LDAP_SLAPI
        filter_free( f );
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Filter *
 slapi_filter_dup( Slapi_Filter *filter )
 {
-#ifdef LDAP_SLAPI
        Filter *f;
 
        f = (Filter *) slapi_ch_malloc( sizeof(Filter) );
@@ -1793,15 +1552,11 @@ slapi_filter_dup( Slapi_Filter *filter )
        }
 
        return f;
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int 
 slapi_filter_get_choice( Slapi_Filter *f )
 {
-#ifdef LDAP_SLAPI
        int             rc;
 
        if ( f != NULL ) {
@@ -1811,9 +1566,6 @@ slapi_filter_get_choice( Slapi_Filter *f )
        }
 
        return rc;
-#else /* LDAP_SLAPI */
-       return -1;              /* invalid filter type */
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -1822,7 +1574,6 @@ slapi_filter_get_ava(
        char            **type, 
        struct berval   **bval )
 {
-#ifdef LDAP_SLAPI
        int             ftype;
        int             rc = LDAP_SUCCESS;
 
@@ -1848,15 +1599,11 @@ slapi_filter_get_ava(
        }
 
        return rc;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Filter *
 slapi_filter_list_first( Slapi_Filter *f )
 {
-#ifdef LDAP_SLAPI
        int             ftype;
 
        if ( f == NULL ) {
@@ -1871,9 +1618,6 @@ slapi_filter_list_first( Slapi_Filter *f )
        } else {
                return NULL;
        }
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Filter *
@@ -1881,7 +1625,6 @@ slapi_filter_list_next(
        Slapi_Filter    *f, 
        Slapi_Filter    *fprev )
 {
-#ifdef LDAP_SLAPI
        int             ftype;
 
        if ( f == NULL ) {
@@ -1897,15 +1640,11 @@ slapi_filter_list_next(
        }
 
        return NULL;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
 {
-#ifdef LDAP_SLAPI
        if ( f == NULL ) {
                return -1;
        }
@@ -1933,16 +1672,51 @@ slapi_filter_get_attribute_type( Slapi_Filter *f, char **type )
        }
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
+}
+
+int
+slapi_x_filter_set_attribute_type( Slapi_Filter *f, const char *type )
+{
+       AttributeDescription **adp, *ad = NULL;
+       const char *text;
+       int rc;
+
+       if ( f == NULL ) {
+               return -1;
+       }
+
+       switch ( f->f_choice ) {
+       case LDAP_FILTER_GE:
+       case LDAP_FILTER_LE:
+       case LDAP_FILTER_EQUALITY:
+       case LDAP_FILTER_APPROX:
+               adp = &f->f_av_desc;
+               break;
+       case LDAP_FILTER_SUBSTRINGS:
+               adp = &f->f_sub_desc;
+               break;
+       case LDAP_FILTER_PRESENT:
+               adp = &f->f_desc;
+               break;
+       case LDAP_FILTER_EXT:
+               adp = &f->f_mr_desc;
+               break;
+       default:
+               /* Complex filters need not apply. */
+               return -1;
+       }
+
+       rc = slap_str2ad( type, &ad, &text );
+       if ( rc == LDAP_SUCCESS )
+               *adp = ad;
+
+       return ( rc == LDAP_SUCCESS ) ? 0 : -1;
 }
 
 int
 slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
        char ***any, char **final )
 {
-#ifdef LDAP_SLAPI
        int i;
 
        if ( f->f_choice != LDAP_FILTER_SUBSTRINGS ) {
@@ -1971,15 +1745,11 @@ slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
        *final = f->f_sub_final.bv_val ? slapi_ch_strdup(f->f_sub_final.bv_val) : NULL;
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Filter *
 slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 )
 {
-#ifdef LDAP_SLAPI
        Slapi_Filter *f = NULL;
 
        if ( ftype == LDAP_FILTER_AND ||
@@ -1994,9 +1764,6 @@ slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 )
        }
 
        return f;
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int
@@ -2005,7 +1772,6 @@ slapi_x_filter_append( int ftype,
        Slapi_Filter **pNextFilter,
        Slapi_Filter *filterToAppend )
 {
-#ifdef LDAP_SLAPI
        if ( ftype == LDAP_FILTER_AND ||
             ftype == LDAP_FILTER_OR ||
             ftype == LDAP_FILTER_NOT )
@@ -2026,7 +1792,6 @@ slapi_x_filter_append( int ftype,
 
                return 0;
        }
-#endif /* LDAP_SLAPI */
        return -1;
 }
 
@@ -2034,7 +1799,6 @@ int
 slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
        int verify_access )
 {
-#ifdef LDAP_SLAPI
        Operation *op;
        int rc;
 
@@ -2044,13 +1808,13 @@ slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
        }
 
        if ( verify_access ) {
-               rc = slapi_pblock_get(pb, SLAPI_OPERATION, (void *)&op);
-               if ( rc != 0 ) {
+               op = pb->pb_op;
+               if ( op == NULL )
                        return LDAP_PARAM_ERROR;
-               }
        } else {
                op = NULL;
        }
+
        /*
         * According to acl.c it is safe to call test_filter() with
         * NULL arguments...
@@ -2072,25 +1836,17 @@ slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
        }
 
        return rc;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int
 slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f)
 {
-#ifdef LDAP_SLAPI
        return slapi_filter_test( NULL, e, f, 0 );
-#else
-       return -1;
-#endif
 }
 
 int
 slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code )
 {
-#ifdef LDAP_SLAPI
        switch ( f->f_choice ) {
        case LDAP_FILTER_AND:
        case LDAP_FILTER_NOT:
@@ -2130,37 +1886,6 @@ slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_c
        }
 
        return -1;
-#else
-       *error_code = SLAPI_FILTER_UNKNOWN_FILTER_TYPE;
-       return -1;
-#endif /* LDAP_SLAPI */
-}
-
-int 
-slapi_send_ldap_extended_response(
-       Connection      *conn, 
-       Operation       *op,
-       int             errornum, 
-       char            *respName,
-       struct berval   *response )
-{
-#ifdef LDAP_SLAPI
-       SlapReply       rs;
-
-       rs.sr_err = errornum;
-       rs.sr_matched = NULL;
-       rs.sr_text = NULL;
-       rs.sr_ref = NULL;
-       rs.sr_ctrls = NULL;
-       rs.sr_rspoid = respName;
-       rs.sr_rspdata = response;
-
-       send_ldap_extended( op, &rs );
-
-       return LDAP_SUCCESS;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int 
@@ -2168,14 +1893,10 @@ slapi_pw_find(
        struct berval   **vals, 
        struct berval   *v ) 
 {
-#ifdef LDAP_SLAPI
        /*
         * FIXME: what's the point?
         */
        return 1;
-#else /* LDAP_SLAPI */
-       return 1;
-#endif /* LDAP_SLAPI */
 }
 
 #define MAX_HOSTNAME 512
@@ -2183,7 +1904,6 @@ slapi_pw_find(
 char *
 slapi_get_hostname( void ) 
 {
-#ifdef LDAP_SLAPI
        char            *hn = NULL;
        static int      been_here = 0;   
        static char     *static_hn = NULL;
@@ -2220,9 +1940,6 @@ slapi_get_hostname( void )
        hn = ch_strdup( static_hn );
 
        return hn;
-#else /* LDAP_SLAPI */
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -2237,7 +1954,6 @@ slapi_log_error(
        char            *fmt, 
        ... ) 
 {
-#ifdef LDAP_SLAPI
        int             rc = LDAP_SUCCESS;
        va_list         arglist;
 
@@ -2246,16 +1962,12 @@ slapi_log_error(
        va_end( arglist );
 
        return rc;
-#else /* LDAP_SLAPI */
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 
 unsigned long
 slapi_timer_current_time( void ) 
 {
-#ifdef LDAP_SLAPI
        static int      first_time = 1;
 #if !defined (_WIN32)
        struct timeval  now;
@@ -2292,9 +2004,6 @@ slapi_timer_current_time( void )
        QueryPerformanceCounter( &now );
        return (1000000*(now.QuadPart-base_time.QuadPart))/performance_freq.QuadPart;
 #endif /* _WIN32 */
-#else /* LDAP_SLAPI */
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -2303,13 +2012,9 @@ slapi_timer_current_time( void )
 unsigned long
 slapi_timer_get_time( char *label ) 
 {
-#ifdef LDAP_SLAPI
        unsigned long start = slapi_timer_current_time();
-       printf("%10ld %10ld usec %s\n", start, 0, label);
+       printf("%10ld %10d usec %s\n", start, 0, label);
        return start;
-#else /* LDAP_SLAPI */
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -2320,343 +2025,96 @@ slapi_timer_elapsed_time(
        char *label,
        unsigned long start ) 
 {
-#ifdef LDAP_SLAPI
        unsigned long stop = slapi_timer_current_time();
        printf ("%10ld %10ld usec %s\n", stop, stop - start, label);
-#endif /* LDAP_SLAPI */
 }
 
 void
 slapi_free_search_results_internal( Slapi_PBlock *pb ) 
 {
-#ifdef LDAP_SLAPI
        Slapi_Entry     **entries;
        int             k = 0, nEnt = 0;
 
        slapi_pblock_get( pb, SLAPI_NENTRIES, &nEnt );
        slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries );
-       if ( nEnt == 0 ) {
-               return;
-       }
-       
-       if ( entries == NULL ) {
+       if ( nEnt == 0 || entries == NULL ) {
                return;
        }
-       
+
        for ( k = 0; k < nEnt; k++ ) {
                slapi_entry_free( entries[k] );
+               entries[k] = NULL;
        }
        
        slapi_ch_free( (void **)&entries );
-#endif /* LDAP_SLAPI */
 }
 
-#ifdef LDAP_SLAPI
-/*
- * Internal API to prime a Slapi_PBlock with a Backend.
- */
-static int slapi_int_pblock_set_backend( Slapi_PBlock *pb, Backend *be )
+int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
 {
-       int rc;
-       
-       rc = slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-       
-       if ( be != NULL ) {
-               rc = slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
-
-       return LDAP_SUCCESS;
-}
+       if ( pb == NULL )
+               return LDAP_PARAM_ERROR;
 
-/*
- * If oldStyle is TRUE, then a value suitable for setting to
- * the deprecated SLAPI_CONN_AUTHTYPE value is returned 
- * (pointer to static storage).
- *
- * If oldStyle is FALSE, then a value suitable for setting to
- * the new SLAPI_CONN_AUTHMETHOD will be returned, which is
- * a pointer to allocated memory and will include the SASL
- * mechanism (if any).
- */
-static char *Authorization2AuthType( AuthorizationInformation *authz, int is_tls, int oldStyle )
-{
-       size_t len;
-       char *authType;
+       if ( pb->pb_conn == NULL )
+               return LDAP_PARAM_ERROR;
 
-       switch ( authz->sai_method ) {
-       case LDAP_AUTH_SASL:
-               if ( oldStyle ) {
-                       authType = SLAPD_AUTH_SASL;
-               } else {
-                       len = sizeof(SLAPD_AUTH_SASL) + authz->sai_mech.bv_len;
-                       authType = slapi_ch_malloc( len );
-                       snprintf( authType, len, "%s%s", SLAPD_AUTH_SASL, authz->sai_mech.bv_val );
-               }
-               break;
-       case LDAP_AUTH_SIMPLE:
-               authType = oldStyle ? SLAPD_AUTH_SIMPLE : slapi_ch_strdup( SLAPD_AUTH_SIMPLE );
-               break;
-       case LDAP_AUTH_NONE:
-               authType = oldStyle ? SLAPD_AUTH_NONE : slapi_ch_strdup( SLAPD_AUTH_NONE );
-               break;
-       default:
-               authType = NULL;
-               break;
-       }
-       if ( is_tls && authType == NULL ) {
-               authType = oldStyle ? SLAPD_AUTH_SSL : slapi_ch_strdup( SLAPD_AUTH_SSL );
-       }
+#ifdef HAVE_TLS
+       *isSSL = pb->pb_conn->c_is_tls;
+#else
+       *isSSL = 0;
+#endif
 
-       return authType;
+       return LDAP_SUCCESS;
 }
 
 /*
- * Internal API to prime a Slapi_PBlock with a Connection.
+ * DS 5.x compatability API follow
  */
-static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn )
-{
-       char *connAuthType;
-       int rc;
 
-       rc = slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
+{
+       AttributeType *at;
 
-       if ( strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_CONN_CLIENTIP, (void *)&conn->c_peer_name.bv_val[3] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       } else if ( strncmp( conn->c_peer_name.bv_val, "PATH=", 5 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_X_CONN_CLIENTPATH, (void *)&conn->c_peer_name.bv_val[5] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+       if ( attr == NULL )
+               return LDAP_PARAM_ERROR;
 
-       if ( strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_CONN_SERVERIP, (void *)&conn->c_sock_name.bv_val[3] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       } else if ( strncmp( conn->c_sock_name.bv_val, "PATH=", 5 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_X_CONN_SERVERPATH, (void *)&conn->c_sock_name.bv_val[5] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+       at = attr->a_desc->ad_type;
 
-#ifdef LDAP_CONNECTIONLESS
-       rc = slapi_pblock_set( pb, SLAPI_X_CONN_IS_UDP, (void *)conn->c_is_udp );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-#endif
+       *flags = SLAPI_ATTR_FLAG_STD_ATTR;
 
-       rc = slapi_pblock_set( pb, SLAPI_CONN_ID, (void *)conn->c_connid );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       if ( is_at_single_value( at ) )
+               *flags |= SLAPI_ATTR_FLAG_SINGLE;
+       if ( is_at_operational( at ) )
+               *flags |= SLAPI_ATTR_FLAG_OPATTR;
+       if ( is_at_obsolete( at ) )
+               *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
+       if ( is_at_collective( at ) )
+               *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
+       if ( is_at_no_user_mod( at ) )
+               *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
 
-       /* Returns pointer to static string */
-       connAuthType = Authorization2AuthType( &conn->c_authz,
-#ifdef HAVE_TLS
-               conn->c_is_tls,
-#else
-               0,
-#endif
-               1 );
-       if ( connAuthType != NULL ) {
-               rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHTYPE, (void *)connAuthType);
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+       return LDAP_SUCCESS;
+}
 
-       /* Returns pointer to allocated string */
-       connAuthType = Authorization2AuthType( &conn->c_authz,
-#ifdef HAVE_TLS
-               conn->c_is_tls,
-#else
-               0,
-#endif
-               0 );
-       if ( connAuthType != NULL ) {
-               rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHMETHOD, (void *)connAuthType);
-               /* slapi_pblock_set dups this itself */
-               slapi_ch_free( (void **)&connAuthType );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
+{
+       unsigned long flags;
 
-       if ( conn->c_authz.sai_dn.bv_val != NULL ) {
-               /* slapi_pblock_set dups this itself */
-               rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)conn->c_authz.sai_dn.bv_val);
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+       if ( slapi_attr_get_flags( attr, &flags ) != 0 )
+               return 0;
+       return (flags & flag) ? 1 : 0;
+}
 
-       rc = slapi_pblock_set(pb, SLAPI_X_CONN_SSF, (void *)conn->c_ssf);
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+Slapi_Attr *slapi_attr_new( void )
+{
+       Attribute *ad;
 
-       rc = slapi_pblock_set(pb, SLAPI_X_CONN_SASL_CONTEXT,
-               ( conn->c_sasl_authctx != NULL ? conn->c_sasl_authctx :
-                                                conn->c_sasl_sockctx ) );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       ad = (Attribute  *)slapi_ch_calloc( 1, sizeof(*ad) );
 
-       return rc;
+       return ad;
 }
-#endif /* LDAP_SLAPI */
 
-/*
- * Internal API to prime a Slapi_PBlock with an Operation.
- */
-int slapi_int_pblock_set_operation( Slapi_PBlock *pb, Operation *op )
+Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
 {
-#ifdef LDAP_SLAPI
-       int isRoot = 0;
-       int isUpdateDn = 0;
-       int rc;
-       char *opAuthType;
-
-       if ( op->o_bd != NULL ) {
-               isRoot = be_isroot( op );
-               isUpdateDn = be_isupdate( op );
-       }
-
-       rc = slapi_int_pblock_set_backend( pb, op->o_bd );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_int_pblock_set_connection( pb, op->o_conn );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPINITIATED_TIME, (void *)op->o_time );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION_ID, (void *)op->o_opid );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION_TYPE, (void *)op->o_tag );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void *)isUpdateDn );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls );
-       if ( rc != LDAP_SUCCESS)
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_DN, (void *)op->o_ndn.bv_val );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_get( pb, SLAPI_CONN_AUTHMETHOD, (void *)&opAuthType );
-       if ( rc == LDAP_SUCCESS && opAuthType != NULL ) {
-               /* Not quite sure what the point of this is. */
-               rc = slapi_pblock_set( pb, SLAPI_OPERATION_AUTHTYPE, (void *)opAuthType );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
-
-       return LDAP_SUCCESS;
-#else
-       return -1;
-#endif
-}
-
-int slapi_is_connection_ssl( Slapi_PBlock *pb, int *isSSL )
-{
-#ifdef LDAP_SLAPI
-       Connection *conn;
-
-       slapi_pblock_get( pb, SLAPI_CONNECTION, &conn );
-#ifdef HAVE_TLS
-       *isSSL = conn->c_is_tls;
-#else
-       *isSSL = 0;
-#endif
-
-       return LDAP_SUCCESS;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
-}
-
-/*
- * DS 5.x compatability API follow
- */
-
-int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags )
-{
-#ifdef LDAP_SLAPI
-       AttributeType *at;
-
-       if ( attr == NULL )
-               return LDAP_PARAM_ERROR;
-
-       at = attr->a_desc->ad_type;
-
-       *flags = SLAPI_ATTR_FLAG_STD_ATTR;
-
-       if ( is_at_single_value( at ) )
-               *flags |= SLAPI_ATTR_FLAG_SINGLE;
-       if ( is_at_operational( at ) )
-               *flags |= SLAPI_ATTR_FLAG_OPATTR;
-       if ( is_at_obsolete( at ) )
-               *flags |= SLAPI_ATTR_FLAG_OBSOLETE;
-       if ( is_at_collective( at ) )
-               *flags |= SLAPI_ATTR_FLAG_COLLECTIVE;
-       if ( is_at_no_user_mod( at ) )
-               *flags |= SLAPI_ATTR_FLAG_NOUSERMOD;
-
-       return LDAP_SUCCESS;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
-}
-
-int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag )
-{
-#ifdef LDAP_SLAPI
-       unsigned long flags;
-
-       if ( slapi_attr_get_flags( attr, &flags ) != 0 )
-               return 0;
-       return (flags & flag) ? 1 : 0;
-#else
-       return 0;
-#endif /* LDAP_SLAPI */
-}
-
-Slapi_Attr *slapi_attr_new( void )
-{
-#ifdef LDAP_SLAPI
-       Attribute *ad;
-
-       ad = (Attribute  *)slapi_ch_calloc( 1, sizeof(*ad) );
-
-       return ad;
-#else
-       return NULL;
-#endif
-}
-
-Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
-{
-#ifdef LDAP_SLAPI
        const char *text;
        AttributeDescription *ad = NULL;
 
@@ -2671,38 +2129,53 @@ Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type )
        a->a_flags = 0;
 
        return a;
-#else
-       return NULL;
-#endif
 }
 
 void slapi_attr_free( Slapi_Attr **a )
 {
-#ifdef LDAP_SLAPI
        attr_free( *a );
        *a = NULL;
-#endif
 }
 
 Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr )
 {
-#ifdef LDAP_SLAPI
        return attr_dup( (Slapi_Attr *)attr );
-#else
-       return NULL;
-#endif
 }
 
 int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v )
 {
-#ifdef LDAP_SLAPI
-       /*
-        * FIXME: here we may lose alignment between a_vals/a_nvals
-        */
-       return value_add_one( &a->a_vals, (Slapi_Value *)v );
-#else
-       return -1;
-#endif
+       struct berval nval;
+       struct berval *nvalp;
+       int rc;
+       AttributeDescription *desc = a->a_desc;
+
+       if ( desc->ad_type->sat_equality &&
+            desc->ad_type->sat_equality->smr_normalize ) {
+               rc = (*desc->ad_type->sat_equality->smr_normalize)(
+                       SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
+                       desc->ad_type->sat_syntax,
+                       desc->ad_type->sat_equality,
+                       (Slapi_Value *)v, &nval, NULL );
+               if ( rc != LDAP_SUCCESS ) {
+                       return rc;
+               }
+               nvalp = &nval;
+       } else {
+               nvalp = NULL;
+       }
+
+       rc = value_add_one( &a->a_vals, (Slapi_Value *)v );
+       if ( rc == 0 && nvalp != NULL ) {
+               rc = value_add_one( &a->a_nvals, nvalp );
+       } else {
+               a->a_nvals = a->a_vals;
+       }
+
+       if ( nvalp != NULL ) {
+               slapi_ch_free_string( &nval.bv_val );
+       }
+
+       return rc;
 }
 
 int slapi_attr_type2plugin( const char *type, void **pi )
@@ -2714,7 +2187,6 @@ int slapi_attr_type2plugin( const char *type, void **pi )
 
 int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
 {
-#ifdef LDAP_SLAPI
        if ( attr == NULL ) {
                return LDAP_PARAM_ERROR;
        }
@@ -2722,28 +2194,20 @@ int slapi_attr_get_type( const Slapi_Attr *attr, char **type )
        *type = attr->a_desc->ad_cname.bv_val;
 
        return LDAP_SUCCESS;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp )
 {
-#ifdef LDAP_SLAPI
        if ( attr == NULL ) {
                return LDAP_PARAM_ERROR;
        }
        *oidp = attr->a_desc->ad_type->sat_oid;
 
        return LDAP_SUCCESS;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct berval *v2 )
 {
-#ifdef LDAP_SLAPI
        MatchingRule *mr;
        int ret;
        int rc;
@@ -2757,14 +2221,10 @@ int slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const st
                return -1;
 
        return ( ret == 0 ) ? 0 : -1;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
 {
-#ifdef LDAP_SLAPI
        MatchingRule *mr;
        struct berval *bv;
        int j;
@@ -2786,13 +2246,11 @@ int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
                        return 0;
                }
        }
-#endif /* LDAP_SLAPI */
        return -1;
 }
 
 int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *a1 = NULL;
        AttributeDescription *a2 = NULL;
        const char *text;
@@ -2826,72 +2284,44 @@ int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
        }
 
        return ret;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_types_equivalent( const char *t1, const char *t2 )
 {
-#ifdef LDAP_SLAPI
-       return slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT );
-#else
-       return -1;
-#endif
+       return ( slapi_attr_type_cmp( t1, t2, SLAPI_TYPE_CMP_EXACT ) == 0 );
 }
 
 int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v )
 {
-#ifdef LDAP_SLAPI
        return slapi_valueset_first_value( &a->a_vals, v );
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v )
 {
-#ifdef LDAP_SLAPI
        return slapi_valueset_next_value( &a->a_vals, hint, v );
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues )
 {
-#ifdef LDAP_SLAPI
        *numValues = slapi_valueset_count( &a->a_vals );
 
        return 0;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs )
 {
-#ifdef LDAP_SLAPI
        *vs = &((Slapi_Attr *)a)->a_vals;
 
        return 0;
-#else
-       return -1;
-#endif
 }
 
 int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals )
 {
-#ifdef LDAP_SLAPI
        return slapi_attr_get_values( a, vals );
-#else
-       return -1;
-#endif
 }
 
 char *slapi_attr_syntax_normalize( const char *s )
 {
-#ifdef LDAP_SLAPI
        AttributeDescription *ad = NULL;
        const char *text;
 
@@ -2900,101 +2330,65 @@ char *slapi_attr_syntax_normalize( const char *s )
        }
 
        return ad->ad_cname.bv_val;
-#else
-       return -1;
-#endif
 }
 
 Slapi_Value *slapi_value_new( void )
 {
-#ifdef LDAP_SLAPI
        struct berval *bv;
 
        bv = (struct berval *)slapi_ch_malloc( sizeof(*bv) );
 
        return bv;
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_new_berval(const struct berval *bval)
 {
-#ifdef LDAP_SLAPI
        return ber_dupbv( NULL, (struct berval *)bval );
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_new_value(const Slapi_Value *v)
 {
-#ifdef LDAP_SLAPI
        return slapi_value_new_berval( v );
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_new_string(const char *s)
 {
-#ifdef LDAP_SLAPI
        struct berval bv;
 
        bv.bv_val = (char *)s;
        bv.bv_len = strlen( s );
 
        return slapi_value_new_berval( &bv );
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_init(Slapi_Value *val)
 {
-#ifdef LDAP_SLAPI
        val->bv_val = NULL;
        val->bv_len = 0;
 
        return val;
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval)
 {
-#ifdef LDAP_SLAPI
        return ber_dupbv( v, bval );
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
 {
-#ifdef LDAP_SLAPI
        v->bv_val = slapi_ch_strdup( (char *)s );
        v->bv_len = strlen( s );
 
        return v;
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_dup(const Slapi_Value *v)
 {
-#ifdef LDAP_SLAPI
        return slapi_value_new_value( v );
-#else
-       return NULL;
-#endif
 }
 
 void slapi_value_free(Slapi_Value **value)
 {
-#ifdef LDAP_SLAPI      
        if ( value == NULL ) {
                return;
        }
@@ -3003,21 +2397,15 @@ void slapi_value_free(Slapi_Value **value)
                slapi_ch_free( (void **)&(*value)->bv_val );
                slapi_ch_free( (void **)value );
        }
-#endif
 }
 
 const struct berval *slapi_value_get_berval( const Slapi_Value *value )
 {
-#ifdef LDAP_SLAPI
        return value;
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval )
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) {
                return NULL;
        }
@@ -3027,26 +2415,18 @@ Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bv
        slapi_value_init_berval( value, (struct berval *)bval );
 
        return value;
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) {
                return NULL;
        }
        return slapi_value_set_berval( value, vfrom );
-#else
-       return NULL;
-#endif
 }
 
 Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) {
                return NULL;
        }
@@ -3058,141 +2438,97 @@ Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len)
        AC_MEMCPY( value->bv_val, val, len );
 
        return value;
-#else
-       return NULL;
-#endif
 }
 
 int slapi_value_set_string(Slapi_Value *value, const char *strVal)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) {
                return -1;
        }
        slapi_value_set( value, (void *)strVal, strlen( strVal ) );
        return 0;
-#else
-       return NULL;
-#endif
 }
 
 int slapi_value_set_int(Slapi_Value *value, int intVal)
 {
-#ifdef LDAP_SLAPI
        char buf[64];
 
        snprintf( buf, sizeof( buf ), "%d", intVal );
 
        return slapi_value_set_string( value, buf );
-#else
-       return -1;
-#endif
 }
 
 const char *slapi_value_get_string(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) return NULL;
        if ( value->bv_val == NULL ) return NULL;
        if ( !checkBVString( value ) ) return NULL;
 
        return value->bv_val;
-#else
-       return NULL;
-#endif
 }
 
 int slapi_value_get_int(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) return 0;
        if ( value->bv_val == NULL ) return 0;
        if ( !checkBVString( value ) ) return 0;
 
        return (int)strtol( value->bv_val, NULL, 10 );
-#else
-       return NULL;
-#endif
 }
 
 unsigned int slapi_value_get_uint(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) return 0;
        if ( value->bv_val == NULL ) return 0;
        if ( !checkBVString( value ) ) return 0;
 
        return (unsigned int)strtoul( value->bv_val, NULL, 10 );
-#else
-       return NULL;
-#endif
 }
 
 long slapi_value_get_long(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) return 0;
        if ( value->bv_val == NULL ) return 0;
        if ( !checkBVString( value ) ) return 0;
 
        return strtol( value->bv_val, NULL, 10 );
-#else
-       return NULL;
-#endif
 }
 
 unsigned long slapi_value_get_ulong(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL ) return 0;
        if ( value->bv_val == NULL ) return 0;
        if ( !checkBVString( value ) ) return 0;
 
        return strtoul( value->bv_val, NULL, 10 );
-#else
-       return NULL;
-#endif
 }
 
 size_t slapi_value_get_length(const Slapi_Value *value)
 {
-#ifdef LDAP_SLAPI
        if ( value == NULL )
                return 0;
 
        return (size_t) value->bv_len;
-#else
-       return 0;
-#endif
 }
 
 int slapi_value_compare(const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2)
 {
-#ifdef LDAP_SLAPI
        return slapi_attr_value_cmp( a, v1, v2 );
-#else
-       return -1;
-#endif
 }
 
 /* A ValueSet is a container for a BerVarray. */
 Slapi_ValueSet *slapi_valueset_new( void )
 {
-#ifdef LDAP_SLAPI
        Slapi_ValueSet *vs;
 
        vs = (Slapi_ValueSet *)slapi_ch_malloc( sizeof( *vs ) );
        *vs = NULL;
 
        return vs;
-#else
-       return NULL;
-#endif
 }
 
 void slapi_valueset_free(Slapi_ValueSet *vs)
 {
-#ifdef LDAP_SLAPI
        if ( vs != NULL ) {
                BerVarray vp = *vs;
 
@@ -3201,23 +2537,19 @@ void slapi_valueset_free(Slapi_ValueSet *vs)
 
                *vs = NULL;
        }
-#endif
 }
 
 void slapi_valueset_init(Slapi_ValueSet *vs)
 {
-#ifdef LDAP_SLAPI
        if ( vs != NULL && *vs == NULL ) {
                *vs = (Slapi_ValueSet)slapi_ch_calloc( 1, sizeof(struct berval) );
                (*vs)->bv_val = NULL;
                (*vs)->bv_len = 0;
        }
-#endif
 }
 
 void slapi_valueset_done(Slapi_ValueSet *vs)
 {
-#ifdef LDAP_SLAPI
        BerVarray vp;
 
        if ( vs == NULL )
@@ -3228,31 +2560,23 @@ void slapi_valueset_done(Slapi_ValueSet *vs)
                slapi_ch_free( (void **)&vp->bv_val );
        }
        /* but don't free *vs or vs */
-#endif
 }
 
 void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
 {
-#ifdef LDAP_SLAPI
        struct berval bv;
 
        ber_dupbv( &bv, (Slapi_Value *)addval );
        ber_bvarray_add( vs, &bv );
-#endif
 }
 
 int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
 {
-#ifdef LDAP_SLAPI
        return slapi_valueset_next_value( vs, 0, v );
-#else
-       return -1;
-#endif
 }
 
 int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
 {
-#ifdef LDAP_SLAPI
        int i;
        BerVarray vp;
 
@@ -3267,14 +2591,12 @@ int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
                        return index + 1;
                }
        }
-#endif
 
        return -1;
 }
 
 int slapi_valueset_count( const Slapi_ValueSet *vs )
 {
-#ifdef LDAP_SLAPI
        int i;
        BerVarray vp;
 
@@ -3287,40 +2609,35 @@ int slapi_valueset_count( const Slapi_ValueSet *vs )
                ;
 
        return i;
-#else
-       return 0;
-#endif
 
 }
 
 void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
 {
-#ifdef LDAP_SLAPI
        BerVarray vp;
 
        for ( vp = *vs2; vp->bv_val != NULL; vp++ ) {
                slapi_valueset_add_value( vs1, vp );
        }
-#endif
 }
 
 int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
        struct berval *val, int access )
 {
-#ifdef LDAP_SLAPI
-       Backend *be;
-       Connection *conn;
-       Operation *op;
-       int ret;
+       int rc;
        slap_access_t slap_access;
        AttributeDescription *ad = NULL;
        const char *text;
 
-       ret = slap_str2ad( attr, &ad, &text );
-       if ( ret != LDAP_SUCCESS ) {
-               return ret;
+       rc = slap_str2ad( attr, &ad, &text );
+       if ( rc != LDAP_SUCCESS ) {
+               return rc;
        }
 
+       /*
+        * Whilst the SLAPI access types are arranged as a bitmask, the
+        * documentation indicates that they are to be used separately.
+        */
        switch ( access & SLAPI_ACL_ALL ) {
        case SLAPI_ACL_COMPARE:
                slap_access = ACL_COMPARE;
@@ -3332,76 +2649,50 @@ int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
                slap_access = ACL_READ;
                break;
        case SLAPI_ACL_WRITE:
+               slap_access = ACL_WRITE;
+               break;
        case SLAPI_ACL_DELETE:
+               slap_access = ACL_WDEL;
+               break;
        case SLAPI_ACL_ADD:
-       case SLAPI_ACL_SELF:
-               slap_access = ACL_WRITE;
+               slap_access = ACL_WADD;
                break;
+       case SLAPI_ACL_SELF:  /* not documented */
+       case SLAPI_ACL_PROXY: /* not documented */
        default:
                return LDAP_INSUFFICIENT_ACCESS;
                break;
        }
 
-       if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be ) != 0 ) {
-               return LDAP_PARAM_ERROR;
-       }
-
-       if ( slapi_pblock_get( pb, SLAPI_CONNECTION, (void *)&conn ) != 0 ) {
-               return LDAP_PARAM_ERROR;
-       }
+       assert( pb->pb_op != NULL );
 
-       if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&op ) != 0 ) {
-               return LDAP_PARAM_ERROR;
+       if ( access_allowed( pb->pb_op, e, ad, val, slap_access, NULL ) ) {
+               return LDAP_SUCCESS;
        }
 
-       ret = access_allowed( op, e, ad, val, slap_access, NULL );
-
-       return ret ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
-#else
-       return LDAP_UNWILLING_TO_PERFORM;
-#endif
+       return LDAP_INSUFFICIENT_ACCESS;
 }
 
 int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char **errbuf)
 {
-#ifdef LDAP_SLAPI
-       Operation *op;
        int rc = LDAP_SUCCESS;
-       Modifications *ml, *mp;
+       Modifications *ml;
 
-       if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&op ) != 0 ) {
+       if ( pb == NULL || pb->pb_op == NULL )
                return LDAP_PARAM_ERROR;
-       }
 
        ml = slapi_int_ldapmods2modifications( mods );
        if ( ml == NULL ) {
                return LDAP_OTHER;
        }
 
-       for ( mp = ml; mp != NULL; mp = mp->sml_next ) {
-               rc = slap_bv2ad( &mp->sml_type, &mp->sml_desc, (const char **)errbuf );
-               if ( rc != LDAP_SUCCESS ) {
-                       break;
-               }
-       }
-
        if ( rc == LDAP_SUCCESS ) {
-               rc = acl_check_modlist( op, e, ml ) ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
+               rc = acl_check_modlist( pb->pb_op, e, ml ) ? LDAP_SUCCESS : LDAP_INSUFFICIENT_ACCESS;
        }
 
-       /* Careful when freeing the modlist because it has pointers into the mods array. */
-       for ( ; ml != NULL; ml = mp ) {
-               mp = ml->sml_next;
-
-               /* just free the containing array */
-               slapi_ch_free( (void **)&ml->sml_values );
-               slapi_ch_free( (void **)&ml );
-       }
+       slap_mods_free( ml, 1 );
 
        return rc;
-#else
-       return LDAP_UNWILLING_TO_PERFORM;
-#endif
 }
 
 /*
@@ -3412,9 +2703,8 @@ int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char
  * 
  * This function must also be called before slap_mods_check().
  */
-LDAPMod **slapi_int_modifications2ldapmods(Modifications **pmodlist)
+LDAPMod **slapi_int_modifications2ldapmods( Modifications **pmodlist )
 {
-#ifdef LDAP_SLAPI
        Modifications *ml, *modlist;
        LDAPMod **mods, *modp;
        int i, j;
@@ -3424,31 +2714,31 @@ LDAPMod **slapi_int_modifications2ldapmods(Modifications **pmodlist)
        for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
                ;
 
-       mods = (LDAPMod **)ch_malloc( (i + 1) * sizeof(LDAPMod *) );
+       mods = (LDAPMod **)slapi_ch_malloc( (i + 1) * sizeof(LDAPMod *) );
 
        for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
-               mods[i] = (LDAPMod *)ch_malloc( sizeof(LDAPMod) );
+               mods[i] = (LDAPMod *)slapi_ch_malloc( sizeof(LDAPMod) );
                modp = mods[i];
                modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
-
-               /* Take ownership of original type. */
-               modp->mod_type = ml->sml_type.bv_val;
+               modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
                ml->sml_type.bv_val = NULL;
 
                if ( ml->sml_values != NULL ) {
                        for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
                                ;
-                       modp->mod_bvalues = (struct berval **)ch_malloc( (j + 1) *
+                       modp->mod_bvalues = (struct berval **)slapi_ch_malloc( (j + 1) *
                                sizeof(struct berval *) );
                        for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
+                               modp->mod_bvalues[j] = (struct berval *)slapi_ch_malloc(
+                                               sizeof(struct berval) );
                                /* Take ownership of original values. */
-                               modp->mod_bvalues[j] = (struct berval *)ch_malloc( sizeof(struct berval) );
                                modp->mod_bvalues[j]->bv_len = ml->sml_values[j].bv_len;
                                modp->mod_bvalues[j]->bv_val = ml->sml_values[j].bv_val;
                                ml->sml_values[j].bv_len = 0;
                                ml->sml_values[j].bv_val = NULL;
                        }
                        modp->mod_bvalues[j] = NULL;
+                       slapi_ch_free( (void **)&ml->sml_values );
                } else {
                        modp->mod_bvalues = NULL;
                }
@@ -3457,222 +2747,102 @@ LDAPMod **slapi_int_modifications2ldapmods(Modifications **pmodlist)
 
        mods[i] = NULL;
 
-       slap_mods_free( modlist );
+       slap_mods_free( modlist, 1 );
        *pmodlist = NULL;
 
        return mods;
-#else
-       return NULL;
-#endif
 }
 
 /*
  * Convert a potentially modified array of LDAPMods back to a
- * Modification list. 
- * 
- * The returned Modification list contains pointers into the
- * LDAPMods array; the latter MUST be freed with
- * slapi_int_free_ldapmods() (see below).
+ * Modification list. Unfortunately the values need to be
+ * duplicated because slap_mods_check() will try to free them
+ * before prettying (and we can't easily get out of calling
+ * slap_mods_check() because we need normalized values).
  */
-Modifications *slapi_int_ldapmods2modifications (LDAPMod **mods)
+Modifications *slapi_int_ldapmods2modifications ( LDAPMod **mods )
 {
-#ifdef LDAP_SLAPI
-       Modifications *modlist = NULL, **modtail;
-       LDAPMod **modp;
-
-       modtail = &modlist;
-
-       for( modp = mods; *modp != NULL; modp++ ) {
-               Modifications *mod;
-               int i;
-               char **p;
-               struct berval **bvp;
-
-               mod = (Modifications *) ch_malloc( sizeof(Modifications) );
-               mod->sml_op = (*modp)->mod_op & (~LDAP_MOD_BVALUES);
-               mod->sml_type.bv_val = (*modp)->mod_type;
-               mod->sml_type.bv_len = strlen( mod->sml_type.bv_val );
-               mod->sml_desc = NULL;
-               mod->sml_next = NULL;
-
-               if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) {
-                       for( i = 0, bvp = (*modp)->mod_bvalues; bvp != NULL && *bvp != NULL; bvp++, i++ )
-                               ;
-               } else {
-                       for( i = 0, p = (*modp)->mod_values; p != NULL && *p != NULL; p++, i++ )
-                               ;
-               }
-
-               if ( i == 0 ) {
-                       mod->sml_values = NULL;
-               } else {
-                       mod->sml_values = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) );
-
-                       /* NB: This implicitly trusts a plugin to return valid modifications. */
-                       if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) {
-                               for( i = 0, bvp = (*modp)->mod_bvalues; bvp != NULL && *bvp != NULL; bvp++, i++ ) {
-                                       mod->sml_values[i].bv_val = (*bvp)->bv_val;
-                                       mod->sml_values[i].bv_len = (*bvp)->bv_len;
-                               }
-                       } else {
-                               for( i = 0, p = (*modp)->mod_values; p != NULL && *p != NULL; p++, i++ ) {
-                                       mod->sml_values[i].bv_val = *p;
-                                       mod->sml_values[i].bv_len = strlen( *p );
-                               }
-                       }
-                       mod->sml_values[i].bv_val = NULL;
-                       mod->sml_values[i].bv_len = 0;
-               }
-               mod->sml_nvalues = NULL;
-
-               *modtail = mod;
-               modtail = &mod->sml_next;
-       }
-       
-       return modlist;
-#else
-       return NULL;
-#endif 
-}
-
-/*
- * This function only frees the parts of the mods array that
- * are not shared with the Modification list that was created
- * by slapi_int_ldapmods2modifications(). 
- *
- */
-void slapi_int_free_ldapmods (LDAPMod **mods)
-{
-#ifdef LDAP_SLAPI
-       int i, j;
-
-       if (mods == NULL)
-               return;
-
-       for ( i = 0; mods[i] != NULL; i++ ) {
-               /*
-                * Don't free values themselves; they're owned by the
-                * Modification list. Do free the containing array.
-                */
-               if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
-                       for ( j = 0; mods[i]->mod_values != NULL && mods[i]->mod_values[j] != NULL; j++ ) {
-                               ch_free( mods[i]->mod_values[j] );
-                       }
-                       ch_free( mods[i]->mod_values );
-               } else {
-                       ch_free( mods[i]->mod_values );
-               }
-               /* Don't free type, for same reasons. */
-               ch_free( mods[i] );
-       }
-       ch_free( mods );
-#endif /* LDAP_SLAPI */
-}
-
-/*
- * Sun ONE DS 5.x computed attribute support. Computed attributes
- * allow for dynamically generated operational attributes, a very
- * useful thing indeed.
- */
-
-/*
- * Write the computed attribute to a BerElement. Complementary 
- * functions need to be defined for anything that replaces 
- * op->o_callback->sc_sendentry, if you wish to make computed
- * attributes available to it.
- */
-int slapi_int_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e)
-{
-#ifdef LDAP_SLAPI
-       Operation *op = NULL;
-       BerElement *ber;
-       AttributeDescription *desc = NULL;
-       int rc;
-       int i;
-
-       if ( c == NULL ) {
-               return 1;
-       }
-
-       if ( a == NULL ) {
-               return 1;
-       }
+       Modifications *modlist = NULL, **modtail;
+       LDAPMod **modp;
+       char textbuf[SLAP_TEXT_BUFLEN];
+       const char *text;
 
-       if ( e == NULL ) {
-               return 1;
+       if ( mods == NULL ) {
+               return NULL;
        }
 
-       rc = slapi_pblock_get( c->cac_pb, SLAPI_OPERATION, (void *)&op );
-       if ( rc != 0 || op == NULL ) {
-               return rc;
-       }
+       modtail = &modlist;
 
-       ber = (BerElement *)c->cac_private;
-       desc = a->a_desc;
+       for ( modp = mods; *modp != NULL; modp++ ) {
+               Modifications *mod;
+               LDAPMod *lmod = *modp;
+               int i;
+               const char *text;
+               AttributeDescription *ad = NULL;
 
-       if ( c->cac_attrs == NULL ) {
-               /* All attrs request, skip operational attributes */
-               if ( is_at_operational( desc->ad_type ) ) {
-                       return 0;
+               if ( slap_str2ad( lmod->mod_type, &ad, &text ) != LDAP_SUCCESS ) {
+                       continue;
                }
-       } else {
-               /* Specific attrs requested */
-               if ( is_at_operational( desc->ad_type ) ) {
-                       if ( !c->cac_opattrs && !ad_inlist( desc, c->cac_attrs ) ) {
-                               return 0;
+
+               mod = (Modifications *) slapi_ch_malloc( sizeof(Modifications) );
+               mod->sml_op = lmod->mod_op & ~(LDAP_MOD_BVALUES);
+               mod->sml_flags = 0;
+               mod->sml_type = ad->ad_cname;
+               mod->sml_desc = ad;
+               mod->sml_next = NULL;
+
+               i = 0;
+               if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
+                       if ( lmod->mod_bvalues != NULL ) {
+                               while ( lmod->mod_bvalues[i] != NULL )
+                                       i++;
                        }
                } else {
-                       if ( !c->cac_userattrs && !ad_inlist( desc, c->cac_attrs ) ) {
-                               return 0;
+                       if ( lmod->mod_values != NULL ) {
+                               while ( lmod->mod_values[i] != NULL )
+                                       i++;
                        }
                }
-       }
-
-       if ( !access_allowed( op, e, desc, NULL, ACL_READ, &c->cac_acl_state) ) {
-               slapi_log_error( SLAPI_LOG_ACL, "slapi_int_compute_output_ber",
-                       "acl: access to attribute %s not allowed\n",
-                       desc->ad_cname.bv_val );
-               return 0;
-       }
 
-       rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
-       if (rc == -1 ) {
-               slapi_log_error( SLAPI_LOG_BER, "slapi_int_compute_output_ber",
-                       "ber_printf failed\n");
-               return 1;
-       }
+               if ( i == 0 ) {
+                       mod->sml_values = NULL;
+               } else {
+                       mod->sml_values = (BerVarray) slapi_ch_malloc( (i + 1) * sizeof(struct berval) );
 
-       if ( !c->cac_attrsonly ) {
-               for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
-                       if ( !access_allowed( op, e,
-                               desc, &a->a_vals[i], ACL_READ, &c->cac_acl_state)) {
-                               slapi_log_error( SLAPI_LOG_ACL, "slapi_int_compute_output_ber",
-                                       "conn %lu "
-                                       "acl: access to %s, value %d not allowed\n",
-                                       op->o_connid, desc->ad_cname.bv_val, i  );
-                               continue;
-                       }
-       
-                       if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
-                               slapi_log_error( SLAPI_LOG_BER, "slapi_int_compute_output_ber",
-                                       "ber_printf failed\n");
-                               return 1;
+                       /* NB: This implicitly trusts a plugin to return valid modifications. */
+                       if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
+                               for ( i = 0; lmod->mod_bvalues[i] != NULL; i++ ) {
+                                       ber_dupbv( &mod->sml_values[i], lmod->mod_bvalues[i] );
+                               }
+                       } else {
+                               for ( i = 0; lmod->mod_values[i] != NULL; i++ ) {
+                                       mod->sml_values[i].bv_val = slapi_ch_strdup( lmod->mod_values[i] );
+                                       mod->sml_values[i].bv_len = strlen( lmod->mod_values[i] );
+                               }
                        }
+                       mod->sml_values[i].bv_val = NULL;
+                       mod->sml_values[i].bv_len = 0;
                }
+               mod->sml_nvalues = NULL;
+
+               *modtail = mod;
+               modtail = &mod->sml_next;
        }
 
-       if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
-               slapi_log_error( SLAPI_LOG_BER, "slapi_int_compute_output_ber",
-                       "ber_printf failed\n" );
-               return 1;
+       if ( slap_mods_check( modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
+               slap_mods_free( modlist, 1 );
+               modlist = NULL;
        }
 
-       return 0;
-#else
-       return 1;
-#endif
+       return modlist;
 }
 
+/*
+ * Sun ONE DS 5.x computed attribute support. Computed attributes
+ * allow for dynamically generated operational attributes, a very
+ * useful thing indeed.
+ */
+
 /*
  * For some reason Sun don't use the normal plugin mechanism
  * registration path to register an "evaluator" function (an
@@ -3684,9 +2854,9 @@ int slapi_int_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_
  */
 int slapi_compute_add_evaluator(slapi_compute_callback_t function)
 {
-#ifdef LDAP_SLAPI
        Slapi_PBlock *pPlugin = NULL;
        int rc;
+       int type = SLAPI_PLUGIN_OBJECT;
 
        pPlugin = slapi_pblock_new();
        if ( pPlugin == NULL ) {
@@ -3694,7 +2864,7 @@ int slapi_compute_add_evaluator(slapi_compute_callback_t function)
                goto done;
        }
 
-       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)SLAPI_PLUGIN_OBJECT );
+       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
        if ( rc != LDAP_SUCCESS ) {
                goto done;
        }
@@ -3704,7 +2874,7 @@ int slapi_compute_add_evaluator(slapi_compute_callback_t function)
                goto done;
        }
 
-       rc = slapi_int_register_plugin( NULL, pPlugin );
+       rc = slapi_int_register_plugin( frontendDB, pPlugin );
        if ( rc != 0 ) {
                rc = LDAP_OTHER;
                goto done;
@@ -3719,9 +2889,6 @@ done:
        }
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -3729,9 +2896,9 @@ done:
  */
 int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
 {
-#ifdef LDAP_SLAPI
        Slapi_PBlock *pPlugin = NULL;
        int rc;
+       int type = SLAPI_PLUGIN_OBJECT;
 
        pPlugin = slapi_pblock_new();
        if ( pPlugin == NULL ) {
@@ -3739,7 +2906,7 @@ int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
                goto done;
        }
 
-       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)SLAPI_PLUGIN_OBJECT );
+       rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type );
        if ( rc != LDAP_SUCCESS ) {
                goto done;
        }
@@ -3749,7 +2916,7 @@ int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function)
                goto done;
        }
 
-       rc = slapi_int_register_plugin( NULL, pPlugin );
+       rc = slapi_int_register_plugin( frontendDB, pPlugin );
        if ( rc != 0 ) {
                rc = LDAP_OTHER;
                goto done;
@@ -3764,9 +2931,6 @@ done:
        }
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -3774,11 +2938,10 @@ done:
  */
 int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn)
 {
-#ifdef LDAP_SLAPI
        int rc = 0;
        slapi_compute_callback_t *pGetPlugin, *tmpPlugin;
 
-       rc = slapi_int_get_plugins( NULL, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
+       rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_COMPUTE_EVALUATOR_FN, (SLAPI_FUNC **)&tmpPlugin );
        if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
                /* Nothing to do; front-end should ignore. */
                return 0;
@@ -3799,35 +2962,24 @@ int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slap
        slapi_ch_free( (void **)&tmpPlugin );
 
        return rc;
-#else
-       return 1;
-#endif /* LDAP_SLAPI */
 }
 
-int compute_rewrite_search_filter(Slapi_PBlock *pb)
+int
+compute_rewrite_search_filter( Slapi_PBlock *pb )
 {
-#ifdef LDAP_SLAPI
-       Backend *be;
-       int rc;
-
-       rc = slapi_pblock_get( pb, SLAPI_BACKEND, (void *)&be );
-       if ( rc != 0 ) {
-               return rc;
-       }
+       if ( pb == NULL || pb->pb_op == NULL )
+               return LDAP_PARAM_ERROR;
 
-       return slapi_int_call_plugins( be, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
+       return slapi_int_call_plugins( pb->pb_op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb );
 }
 
 /*
  * New API to provide the plugin with access to the search
  * pblock. Have informed Sun DS team.
  */
-int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
+int
+slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
 {
-#ifdef LDAP_SLAPI
        if ( c == NULL )
                return -1;
 
@@ -3837,14 +2989,10 @@ int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb)
        *pb = c->cac_pb;
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 Slapi_Mutex *slapi_new_mutex( void )
 {
-#ifdef LDAP_SLAPI
        Slapi_Mutex *m;
 
        m = (Slapi_Mutex *)slapi_ch_malloc( sizeof(*m) );
@@ -3854,40 +3002,28 @@ Slapi_Mutex *slapi_new_mutex( void )
        }
 
        return m;
-#else
-       return NULL;
-#endif
 }
 
 void slapi_destroy_mutex( Slapi_Mutex *mutex )
 {
-#ifdef LDAP_SLAPI
        if ( mutex != NULL ) {
                ldap_pvt_thread_mutex_destroy( &mutex->mutex );
                slapi_ch_free( (void **)&mutex);
        }
-#endif
 }
 
 void slapi_lock_mutex( Slapi_Mutex *mutex )
 {
-#ifdef LDAP_SLAPI
        ldap_pvt_thread_mutex_lock( &mutex->mutex );
-#endif
 }
 
 int slapi_unlock_mutex( Slapi_Mutex *mutex )
 {
-#ifdef LDAP_SLAPI
        return ldap_pvt_thread_mutex_unlock( &mutex->mutex );
-#else
-       return -1;
-#endif
 }
 
 Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
 {
-#ifdef LDAP_SLAPI
        Slapi_CondVar *cv;
 
        if ( mutex == NULL ) {
@@ -3900,41 +3036,30 @@ Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex )
                return NULL;
        }
 
-       /* XXX struct copy */
        cv->mutex = mutex->mutex;
 
        return cv;
-#else  
-       return NULL;
-#endif
 }
 
 void slapi_destroy_condvar( Slapi_CondVar *cvar )
 {
-#ifdef LDAP_SLAPI
        if ( cvar != NULL ) {
                ldap_pvt_thread_cond_destroy( &cvar->cond );
                slapi_ch_free( (void **)&cvar );
        }
-#endif
 }
 
 int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout )
 {
-#ifdef LDAP_SLAPI
        if ( cvar == NULL ) {
                return -1;
        }
 
        return ldap_pvt_thread_cond_wait( &cvar->cond, &cvar->mutex );
-#else
-       return -1;
-#endif
 }
 
 int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
 {
-#ifdef LDAP_SLAPI
        if ( cvar == NULL ) {
                return -1;
        }
@@ -3944,9 +3069,6 @@ int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all )
        }
 
        return ldap_pvt_thread_cond_signal( &cvar->cond );
-#else
-       return -1;
-#endif
 }
 
 int slapi_int_access_allowed( Operation *op,
@@ -3956,27 +3078,34 @@ int slapi_int_access_allowed( Operation *op,
        slap_access_t access,
        AccessControlState *state )
 {
-#ifdef LDAP_SLAPI
        int rc, slap_access = 0;
        slapi_acl_callback_t *pGetPlugin, *tmpPlugin;
+       Slapi_PBlock *pb;
 
-       if ( op->o_pb == NULL ) {
+       pb = SLAPI_OPERATION_PBLOCK( op );
+       if ( pb == NULL ) {
                /* internal operation */
                return 1;
        }
 
        switch ( access ) {
-       case ACL_WRITE:
-               slap_access |= SLAPI_ACL_ADD | SLAPI_ACL_DELETE | SLAPI_ACL_WRITE;
+       case ACL_COMPARE:
+                slap_access |= SLAPI_ACL_COMPARE;
+               break;
+       case ACL_SEARCH:
+               slap_access |= SLAPI_ACL_SEARCH;
                break;
        case ACL_READ:
                slap_access |= SLAPI_ACL_READ;
                break;
-       case ACL_SEARCH:
-               slap_access |= SLAPI_ACL_SEARCH;
+       case ACL_WRITE:
+               slap_access |= SLAPI_ACL_WRITE;
                break;
-       case ACL_COMPARE:
-                slap_access = ACL_COMPARE;
+       case ACL_WDEL:
+               slap_access |= SLAPI_ACL_DELETE;
+               break;
+       case ACL_WADD:
+               slap_access |= SLAPI_ACL_ADD;
                break;
        default:
                break;
@@ -3988,8 +3117,6 @@ int slapi_int_access_allowed( Operation *op,
                return 1;
        }
 
-       slapi_int_pblock_set_operation( op->o_pb, op );
-
        rc = 1; /* default allow policy */
 
        for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) {
@@ -3997,8 +3124,8 @@ int slapi_int_access_allowed( Operation *op,
                 * 0    access denied
                 * 1    access granted
                 */
-               rc = (*pGetPlugin)( op->o_pb, entry, desc->ad_cname.bv_val,
-                                       val, slap_access, (void *)state );
+               rc = (*pGetPlugin)( pb, entry, desc->ad_cname.bv_val,
+                                   val, slap_access, (void *)state );
                if ( rc == 0 ) {
                        break;
                }
@@ -4007,9 +3134,6 @@ int slapi_int_access_allowed( Operation *op,
        slapi_ch_free( (void **)&tmpPlugin );
 
        return rc;
-#else
-       return 1;
-#endif /* LDAP_SLAPI */
 }
 
 /*
@@ -4017,7 +3141,6 @@ int slapi_int_access_allowed( Operation *op,
  */
 int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
 {
-#ifdef LDAP_SLAPI
        LDAPRDN lrdn;
        LDAPAVA *ava;
        int rc;
@@ -4045,14 +3168,10 @@ int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
        ldap_rdnfree(lrdn);
 
        return 0;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
 {
-#ifdef LDAP_SLAPI
        struct berval new_dn, parent_dn, newrdn;
 
        new_dn.bv_val = NULL;
@@ -4066,41 +3185,37 @@ char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
        build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
 
        return new_dn.bv_val;
-#else
-       return NULL;
-#endif /* LDAP_SLAPI */
 }
 
 int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
-       Backend *be;
+       Backend *be_orig;
        const char *text;
        char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
        size_t textlen = sizeof textbuf;
-       int rc;
+       int rc = LDAP_SUCCESS;
 
-       if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 )
-               return -1;
+       PBLOCK_ASSERT_OP( pb, 0 );
+
+       be_orig = pb->pb_op->o_bd;
 
-       rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
+       pb->pb_op->o_bd = select_backend( &e->e_nname, 0, 0 );
+       if ( pb->pb_op->o_bd != NULL ) {
+               rc = entry_schema_check( pb->pb_op, e, NULL, 0,
+                       &text, textbuf, textlen );
+       }
+       pb->pb_op->o_bd = be_orig;
 
        return ( rc == LDAP_SUCCESS ) ? 0 : 1;
-#else
-       return -1;
-#endif /* LDAP_SLAPI */
 }
 
 int slapi_entry_rdn_values_present( const Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
        LDAPDN dn;
        int rc;
        int i = 0, match = 0;
-       char *dn_str;
 
-       dn_str = slapi_entry_get_dn( (Slapi_Entry *) e );
-       rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 );
+       rc = ldap_bv2dn( &((Entry *)e)->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
        if ( rc != LDAP_SUCCESS ) {
                return 0;
        }
@@ -4121,20 +3236,14 @@ int slapi_entry_rdn_values_present( const Slapi_Entry *e )
        ldap_dnfree( dn );
 
        return ( i == match );
-#else
-       return 0;
-#endif /* LDAP_SLAPI */
 }
 
 int slapi_entry_add_rdn_values( Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
        LDAPDN dn;
        int i, rc;
-       char *dn_str;
 
-       dn_str = slapi_entry_get_dn( e );
-       rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 );
+       rc = ldap_bv2dn( &e->e_name, &dn, LDAP_DN_FORMAT_LDAPV3 );
        if ( rc != LDAP_SUCCESS ) {
                return rc;
        }
@@ -4161,16 +3270,11 @@ int slapi_entry_add_rdn_values( Slapi_Entry *e )
        ldap_dnfree( dn );
 
        return LDAP_SUCCESS;
-#else
-       return LDAP_OTHER;
-#endif /* LDAP_SLAPI */
 }
 
 const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
 {
-#ifdef LDAP_SLAPI
        Attribute *attr;
-       const char *uniqueid;
 
        attr = attr_find( e->e_attrs, slap_schema.si_ad_entryUUID );
        if ( attr == NULL ) {
@@ -4180,14 +3284,12 @@ const char *slapi_entry_get_uniqueid( const Slapi_Entry *e )
        if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
                return slapi_value_get_string( &attr->a_vals[0] );
        }
-#endif /* LDAP_SLAPI */
 
        return NULL;
 }
 
 void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
 {
-#ifdef LDAP_SLAPI
        struct berval bv;
 
        attr_delete ( &e->e_attrs, slap_schema.si_ad_entryUUID );
@@ -4195,6 +3297,204 @@ void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid )
        bv.bv_val = uniqueid;
        bv.bv_len = strlen( uniqueid );
        attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, &bv, NULL );
-#endif /* LDAP_SLAPI */
 }
 
+LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared )
+{
+       LDAP *ld;
+       char *url;
+       size_t size;
+       int rc;
+
+       size = sizeof("ldap:///");
+       if ( secure )
+               size++;
+       size += strlen( ldaphost );
+       if ( ldapport != 0 )
+               size += 32;
+
+       url = slapi_ch_malloc( size );
+
+       if ( ldapport != 0 ) {
+               sprintf( url, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
+       } else {
+               sprintf( url, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
+       }
+
+       rc = ldap_initialize( &ld, url );
+
+       slapi_ch_free_string( &url );
+
+       return ( rc == LDAP_SUCCESS ) ? ld : NULL;
+}
+
+void slapi_ldap_unbind( LDAP *ld )
+{
+       ldap_unbind_ext_s( ld, NULL, NULL );
+}
+
+int slapi_x_backend_get_flags( const Slapi_Backend *be, unsigned long *flags )
+{
+       if ( be == NULL )
+               return LDAP_PARAM_ERROR;
+
+       *flags = SLAP_DBFLAGS(be);
+
+       return LDAP_SUCCESS;
+}
+
+int
+slapi_int_count_controls( LDAPControl **ctrls )
+{
+       size_t i;
+
+       if ( ctrls == NULL )
+               return 0;
+
+       for ( i = 0; ctrls[i] != NULL; i++ )
+               ;
+
+       return i;
+}
+
+int
+slapi_op_abandoned( Slapi_PBlock *pb )
+{
+       if ( pb->pb_op == NULL )
+               return 0;
+
+       return ( pb->pb_op->o_abandon );
+}
+
+char *
+slapi_op_type_to_string(unsigned long type)
+{
+       char *str;
+
+       switch (type) {
+       case SLAPI_OPERATION_BIND:
+               str = "bind";
+               break;
+       case SLAPI_OPERATION_UNBIND:
+               str = "unbind";
+               break;
+       case SLAPI_OPERATION_SEARCH:
+               str = "search";
+               break;
+       case SLAPI_OPERATION_MODIFY:
+               str = "modify";
+               break;
+       case SLAPI_OPERATION_ADD:
+               str = "add";
+               break;
+       case SLAPI_OPERATION_DELETE:
+               str = "delete";
+               break;
+       case SLAPI_OPERATION_MODDN:
+               str = "modrdn";
+               break;
+       case SLAPI_OPERATION_COMPARE:
+               str = "compare";
+               break;
+       case SLAPI_OPERATION_ABANDON:
+               str = "abandon";
+               break;
+       case SLAPI_OPERATION_EXTENDED:
+               str = "extended";
+               break;
+       default:
+               str = "unknown operation type";
+               break;
+       }
+       return str;
+}
+
+unsigned long
+slapi_op_get_type(Slapi_Operation * op)
+{
+       unsigned long type;
+
+       switch ( op->o_tag ) {
+       case LDAP_REQ_BIND:
+               type = SLAPI_OPERATION_BIND;
+               break;
+       case LDAP_REQ_UNBIND:
+               type = SLAPI_OPERATION_UNBIND;
+               break;
+       case LDAP_REQ_SEARCH:
+               type = SLAPI_OPERATION_SEARCH;
+               break;
+       case LDAP_REQ_MODIFY:
+               type = SLAPI_OPERATION_MODIFY;
+               break;
+       case LDAP_REQ_ADD:
+               type = SLAPI_OPERATION_ADD;
+               break;
+       case LDAP_REQ_DELETE:
+               type = SLAPI_OPERATION_DELETE;
+               break;
+       case LDAP_REQ_MODRDN:
+               type = SLAPI_OPERATION_MODDN;
+               break;
+       case LDAP_REQ_COMPARE:
+               type = SLAPI_OPERATION_COMPARE;
+               break;
+       case LDAP_REQ_ABANDON:
+               type = SLAPI_OPERATION_ABANDON;
+               break;
+       case LDAP_REQ_EXTENDED:
+               type = SLAPI_OPERATION_EXTENDED;
+               break;
+       default:
+               type = SLAPI_OPERATION_NONE;
+               break;
+       }
+       return type;
+}
+
+void slapi_be_set_readonly( Slapi_Backend *be, int readonly )
+{
+       if ( be == NULL )
+               return;
+
+       if ( readonly )
+               be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
+       else
+               be->be_restrictops &= ~(SLAP_RESTRICT_OP_WRITES);
+}
+
+int slapi_be_get_readonly( Slapi_Backend *be )
+{
+       if ( be == NULL )
+               return 0;
+
+       return ( (be->be_restrictops & SLAP_RESTRICT_OP_WRITES) == SLAP_RESTRICT_OP_WRITES );
+}
+
+const char *slapi_x_be_get_updatedn( Slapi_Backend *be )
+{
+       if ( be == NULL )
+               return NULL;
+
+       return be->be_update_ndn.bv_val;
+}
+
+#if 0
+void
+slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag)
+{
+}
+
+void
+slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag)
+{
+}
+
+int
+slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag)
+{
+}
+#endif
+
+#endif /* LDAP_SLAPI */
+