]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_utils.c
Unify use of BDB lockers
[openldap] / servers / slapd / slapi / slapi_utils.c
index 6b03416dc2fdab9387556646d59161c81403e7e5..6feae2bf7b37bb84c2805d4a9aba852a32b0af50 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2002-2006 The OpenLDAP Foundation.
+ * Copyright 2002-2007 The OpenLDAP Foundation.
  * Portions Copyright 1997,2002-2003 IBM Corporation.
  * All rights reserved.
  *
@@ -205,7 +205,7 @@ slapi_entry_attr_delete(
 Slapi_Entry *
 slapi_entry_alloc( void ) 
 {
-       return (Slapi_Entry *)slapi_ch_calloc( 1, sizeof(Slapi_Entry) );
+       return (Slapi_Entry *)entry_alloc();
 }
 
 void 
@@ -1041,14 +1041,7 @@ slapi_ch_array_free( char **arrayp )
 struct berval *
 slapi_ch_bvdup(const struct berval *v)
 {
-       struct berval *bv;
-
-       bv = (struct berval *) slapi_ch_malloc( sizeof(struct berval) );
-       bv->bv_len = v->bv_len;
-       bv->bv_val = slapi_ch_malloc( bv->bv_len );
-       AC_MEMCPY( bv->bv_val, v->bv_val, bv->bv_len );
-
-       return bv;
+       return ber_dupbv(NULL, (struct berval *)v);
 }
 
 struct berval **
@@ -1356,8 +1349,13 @@ slapi_send_ldap_result(
        } else {
                if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
                        rs->sr_nentries = nentries;
+               if ( urls != NULL )
+                       bvptr2obj( urls, &rs->sr_ref );
 
                send_ldap_result( pb->pb_op, rs );
+
+               if ( urls != NULL )
+                       slapi_ch_free( (void **)&rs->sr_ref );
        }
 }
 
@@ -1370,7 +1368,7 @@ slapi_send_ldap_search_entry(
        int             attrsonly )
 {
        SlapReply               rs = { REP_SEARCH };
-       int                     i = 0;
+       int                     i = 0, j = 0;
        AttributeName           *an = NULL;
        const char              *text;
        int                     rc;
@@ -1384,19 +1382,17 @@ slapi_send_ldap_search_entry(
        }
 
        if ( i ) {
-               an = (AttributeName *) slapi_ch_malloc( (i+1) * sizeof(AttributeName) );
+               an = (AttributeName *) slapi_ch_calloc( i + 1, sizeof(AttributeName) );
                for ( i = 0; attrs[i] != NULL; i++ ) {
-                       an[i].an_name.bv_val = attrs[i];
-                       an[i].an_name.bv_len = strlen( attrs[i] );
-                       an[i].an_desc = NULL;
-                       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[j].an_name.bv_val = attrs[i];
+                       an[j].an_name.bv_len = strlen( attrs[i] );
+                       an[j].an_desc = NULL;
+                       if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &text ) == LDAP_SUCCESS) {
+                               j++;
                        }
                }
-               an[i].an_name.bv_len = 0;
-               an[i].an_name.bv_val = NULL;
+               an[j].an_name.bv_len = 0;
+               an[j].an_name.bv_val = NULL;
        }
 
        rs.sr_err = LDAP_SUCCESS;
@@ -2532,6 +2528,9 @@ int slapi_valueset_count( const Slapi_ValueSet *vs )
 
        vp = *vs;
 
+       if ( vp == NULL )
+               return 0;
+
        for ( i = 0; vp[i].bv_val != NULL; i++ )
                ;
 
@@ -2608,7 +2607,7 @@ int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char
        if ( pb == NULL || pb->pb_op == NULL )
                return LDAP_PARAM_ERROR;
 
-       ml = slapi_int_ldapmods2modifications( mods );
+       ml = slapi_int_ldapmods2modifications( pb->pb_op, mods );
        if ( ml == NULL ) {
                return LDAP_OTHER;
        }
@@ -2678,7 +2677,7 @@ LDAPMod **slapi_int_modifications2ldapmods( Modifications *modlist )
  * 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 ( Operation *op, LDAPMod **mods )
 {
        Modifications *modlist = NULL, **modtail;
        LDAPMod **modp;
@@ -2747,7 +2746,7 @@ Modifications *slapi_int_ldapmods2modifications ( LDAPMod **mods )
                modtail = &mod->sml_next;
        }
 
-       if ( slap_mods_check( modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
+       if ( slap_mods_check( op, modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
                slap_mods_free( modlist, 1 );
                modlist = NULL;
        }
@@ -3119,7 +3118,7 @@ int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
 
        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,
+               rc = entry_schema_check( pb->pb_op, e, NULL, 0, 0,
                        &text, textbuf, textlen );
        }
        pb->pb_op->o_bd = be_orig;