]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/memberof.c
ITS#5484,ITS#5451
[openldap] / servers / slapd / overlays / memberof.c
index df834c88b007a24598d1a3cedabddd1ed8cbbdc8..09edce82b7f6f662703849bf90c0132c9c61f8a2 100644 (file)
@@ -194,7 +194,7 @@ memberof_saved_member_free( void *key, void *data )
 static BerVarray
 memberof_saved_member_get( Operation *op, void *keyp )
 {
-       BerVarray       vals;
+       void            *vals;
        BerVarray       *key = (BerVarray *)keyp;
 
        assert( op != NULL );
@@ -204,10 +204,8 @@ memberof_saved_member_get( Operation *op, void *keyp )
                *key = NULL;
 
        } else {
-               ldap_pvt_thread_pool_getkey( op->o_threadctx,
-                               key, (void **)&vals, NULL );
                ldap_pvt_thread_pool_setkey( op->o_threadctx,
-                               key, NULL, NULL );
+                               key, NULL, 0, &vals, NULL );
        }
 
        return vals;
@@ -232,8 +230,13 @@ memberof_saved_member_set( Operation *op, void *keyp, BerVarray vals )
                *key = saved_vals;
 
        } else {
+               void    *old_vals = NULL;
+
                ldap_pvt_thread_pool_setkey( op->o_threadctx, key,
-                               saved_vals, memberof_saved_member_free );
+                               saved_vals, memberof_saved_member_free, &old_vals, NULL );
+               if ( old_vals != NULL ) {
+                       ber_bvarray_free( old_vals );
+               }
        }
 }
 
@@ -407,6 +410,7 @@ memberof_value_modify(
        slap_callback   cb = { NULL, slap_null_cb, NULL, NULL };
        Modifications   mod[ 2 ] = { { { 0 } } }, *ml;
        struct berval   values[ 4 ], nvalues[ 4 ];
+       int             mcnt = 0;
 
        op2.o_tag = LDAP_REQ_MODIFY;
 
@@ -418,23 +422,28 @@ memberof_value_modify(
        op2.o_callback = &cb;
        op2.o_dn = op->o_bd->be_rootdn;
        op2.o_ndn = op->o_bd->be_rootndn;
+       op2.orm_modlist = NULL;
+
+       if ( !BER_BVISNULL( &mo->mo_ndn ) ) {
+               ml = &mod[ mcnt ];
+               ml->sml_numvals = 1;
+               ml->sml_values = &values[ 0 ];
+               ml->sml_values[ 0 ] = mo->mo_dn;
+               BER_BVZERO( &ml->sml_values[ 1 ] );
+               ml->sml_nvalues = &nvalues[ 0 ];
+               ml->sml_nvalues[ 0 ] = mo->mo_ndn;
+               BER_BVZERO( &ml->sml_nvalues[ 1 ] );
+               ml->sml_desc = slap_schema.si_ad_modifiersName;
+               ml->sml_type = ml->sml_desc->ad_cname;
+               ml->sml_op = LDAP_MOD_REPLACE;
+               ml->sml_flags = SLAP_MOD_INTERNAL;
+               ml->sml_next = op2.orm_modlist;
+               op2.orm_modlist = ml;
+
+               mcnt++;
+       }
 
-       ml = &mod[ 0 ];
-       ml->sml_numvals = 1;
-       ml->sml_values = &values[ 0 ];
-       ml->sml_values[ 0 ] = mo->mo_dn;
-       BER_BVZERO( &ml->sml_values[ 1 ] );
-       ml->sml_nvalues = &nvalues[ 0 ];
-       ml->sml_nvalues[ 0 ] = mo->mo_ndn;
-       BER_BVZERO( &ml->sml_nvalues[ 1 ] );
-       ml->sml_desc = slap_schema.si_ad_modifiersName;
-       ml->sml_type = ml->sml_desc->ad_cname;
-       ml->sml_op = LDAP_MOD_REPLACE;
-       ml->sml_flags = SLAP_MOD_INTERNAL;
-       ml->sml_next = NULL;
-       op2.orm_modlist = ml;
-
-       ml = &mod[ 1 ];
+       ml = &mod[ mcnt ];
        ml->sml_numvals = 1;
        ml->sml_values = &values[ 2 ];
        BER_BVZERO( &ml->sml_values[ 1 ] );
@@ -443,14 +452,14 @@ memberof_value_modify(
        ml->sml_desc = ad;
        ml->sml_type = ml->sml_desc->ad_cname;
        ml->sml_flags = SLAP_MOD_INTERNAL;
-       ml->sml_next = NULL;
-       op2.orm_modlist->sml_next = ml;
+       ml->sml_next = op2.orm_modlist;
+       op2.orm_modlist = ml;
 
        if ( new_ndn != NULL ) {
                assert( !BER_BVISNULL( new_dn ) );
                assert( !BER_BVISNULL( new_ndn ) );
 
-               ml = &mod[ 1 ];
+               ml = &mod[ mcnt ];
                ml->sml_op = LDAP_MOD_ADD;
 
                ml->sml_values[ 0 ] = *new_dn;
@@ -460,24 +469,32 @@ memberof_value_modify(
                if ( rs2.sr_err != LDAP_SUCCESS ) {
                        char buf[ SLAP_TEXT_BUFLEN ];
                        snprintf( buf, sizeof( buf ),
-                               "memberof_value_modify %s=\"%s\" failed err=%d",
-                               ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
+                               "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
+                               ad->ad_cname.bv_val, new_dn->bv_val, rs2.sr_err,
+                               rs2.sr_text ? rs2.sr_text : "" );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s\n",
+                               op->o_log_prefix, buf, 0 );
                }
 
-               assert( op2.orm_modlist == &mod[ 0 ] );
-               assert( op2.orm_modlist->sml_next == &mod[ 1 ] );
-               ml = op2.orm_modlist->sml_next->sml_next;
+               assert( op2.orm_modlist == &mod[ mcnt ] );
+               assert( mcnt == 0 || op2.orm_modlist->sml_next == &mod[ 0 ] );
+               ml = op2.orm_modlist->sml_next;
+               if ( mcnt == 1 ) {
+                       assert( ml == &mod[ 0 ] );
+                       ml = ml->sml_next;
+               }
                if ( ml != NULL ) {
                        slap_mods_free( ml, 1 );
                }
+
+               mod[ 0 ].sml_next = NULL;
        }
 
        if ( old_ndn != NULL ) {
                assert( !BER_BVISNULL( old_dn ) );
                assert( !BER_BVISNULL( old_ndn ) );
 
-               ml = &mod[ 1 ];
+               ml = &mod[ mcnt ];
                ml->sml_op = LDAP_MOD_DELETE;
 
                ml->sml_values[ 0 ] = *old_dn;
@@ -487,14 +504,19 @@ memberof_value_modify(
                if ( rs2.sr_err != LDAP_SUCCESS ) {
                        char buf[ SLAP_TEXT_BUFLEN ];
                        snprintf( buf, sizeof( buf ),
-                               "memberof_value_modify %s=\"%s\" failed err=%d",
-                               ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s\n", op->o_log_prefix, buf, 0 );
+                               "memberof_value_modify %s=\"%s\" failed err=%d text=%s",
+                               ad->ad_cname.bv_val, old_dn->bv_val, rs2.sr_err,
+                               rs2.sr_text ? rs2.sr_text : "" );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s\n",
+                               op->o_log_prefix, buf, 0 );
                }
 
-               assert( op2.orm_modlist == &mod[ 0 ] );
-               assert( op2.orm_modlist->sml_next == &mod[ 1 ] );
-               ml = op2.orm_modlist->sml_next->sml_next;
+               assert( op2.orm_modlist == &mod[ mcnt ] );
+               ml = op2.orm_modlist->sml_next;
+               if ( mcnt == 1 ) {
+                       assert( ml == &mod[ 0 ] );
+                       ml = ml->sml_next;
+               }
                if ( ml != NULL ) {
                        slap_mods_free( ml, 1 );
                }
@@ -1205,6 +1227,7 @@ memberof_res_delete( Operation *op, SlapReply *rs )
                                        NULL, NULL );
                }
 
+               memberof_saved_member_set( op, &saved_memberof_vals, NULL );
                ber_bvarray_free( vals );
        }
 
@@ -1218,6 +1241,7 @@ memberof_res_delete( Operation *op, SlapReply *rs )
                                                NULL, NULL );
                        }
 
+                       memberof_saved_member_set( op, &saved_member_vals, NULL );
                        ber_bvarray_free( vals );
                }
        }
@@ -1489,7 +1513,7 @@ memberof_db_init(
        ConfigReply     *cr )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
-       memberof_t      tmp_mo = { 0 }, *mo;
+       memberof_t              *mo;
 
        mo = (memberof_t *)ch_calloc( 1, sizeof( memberof_t ) );
 
@@ -1937,7 +1961,7 @@ memberof_db_open(
                }
        }
 
-       if ( BER_BVISNULL( &mo->mo_dn ) ) {
+       if ( BER_BVISNULL( &mo->mo_dn ) && !BER_BVISNULL( &be->be_rootdn ) ) {
                ber_dupbv( &mo->mo_dn, &be->be_rootdn );
                ber_dupbv( &mo->mo_ndn, &be->be_rootndn );
        }