]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/memberof.c
check for NULL backend (ITS#6490)
[openldap] / servers / slapd / overlays / memberof.c
index ecb8e06ffd59f2c785df68129816eb7649a9d19b..3a38b6337336caf4a69710f329c90b5aca1490ac 100644 (file)
@@ -178,61 +178,6 @@ typedef enum memberof_is_t {
        MEMBEROF_IS_BOTH = (MEMBEROF_IS_GROUP|MEMBEROF_IS_MEMBER)
 } memberof_is_t;
 
-static void
-memberof_saved_member_free( void *key, void *data )
-{
-       ber_bvarray_free( (BerVarray)data );
-}
-
-static BerVarray
-memberof_saved_member_get( Operation *op, void *keyp )
-{
-       void            *vals;
-       BerVarray       *key = (BerVarray *)keyp;
-
-       assert( op != NULL );
-
-       if ( op->o_threadctx == NULL ) {
-               vals = *key;
-               *key = NULL;
-
-       } else {
-               ldap_pvt_thread_pool_setkey( op->o_threadctx,
-                               key, NULL, 0, &vals, NULL );
-       }
-
-       return vals;
-}
-
-static void
-memberof_saved_member_set( Operation *op, void *keyp, BerVarray vals )
-{
-       BerVarray       saved_vals = NULL;
-       BerVarray       *key = (BerVarray*)keyp;
-
-       assert( op != NULL );
-
-       if ( vals ) {
-               ber_bvarray_dup_x( &saved_vals, vals, NULL );
-       }
-
-       if ( op->o_threadctx == NULL ) {
-               if ( *key ) {
-                       ber_bvarray_free( *key );
-               }
-               *key = saved_vals;
-
-       } else {
-               void    *old_vals = NULL;
-
-               ldap_pvt_thread_pool_setkey( op->o_threadctx, key,
-                               saved_vals, memberof_saved_member_free, &old_vals, NULL );
-               if ( old_vals != NULL ) {
-                       ber_bvarray_free( old_vals );
-               }
-       }
-}
-
 typedef struct memberof_cookie_t {
        AttributeDescription    *ad;
        BerVarray               vals;
@@ -243,6 +188,7 @@ typedef struct memberof_cbinfo_t {
        slap_overinst *on;
        BerVarray member;
        BerVarray memberof;
+       memberof_is_t what;
 } memberof_cbinfo_t;
        
 static int
@@ -278,16 +224,8 @@ memberof_saveMember_cb( Operation *op, SlapReply *rs )
                a = attr_find( rs->sr_entry->e_attrs, mc->ad );
                if ( a != NULL ) {
                        ber_bvarray_dup_x( &mc->vals, a->a_nvals, op->o_tmpmemctx );
-               }
 
-               if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
-                       Debug( LDAP_DEBUG_ANY,
-                               "%s: memberof_saveMember_cb(\"%s\"): "
-                               "more than one occurrence of \"%s\" "
-                               "attribute.\n",
-                               op->o_log_prefix,
-                               rs->sr_entry->e_name.bv_val,
-                               mc->ad->ad_cname.bv_val );
+                       assert( attr_find( a->a_next, mc->ad ) == NULL );
                }
        }
 
@@ -299,7 +237,7 @@ memberof_saveMember_cb( Operation *op, SlapReply *rs )
  * attribute values of groups being deleted.
  */
 static int
-memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo_t *mci )
+memberof_isGroupOrMember( Operation *op, memberof_cbinfo_t *mci )
 {
        slap_overinst           *on = mci->on;
        memberof_t              *mo = (memberof_t *)on->on_bi.bi_private;
@@ -313,8 +251,7 @@ memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo
        memberof_is_t           iswhat = MEMBEROF_IS_NONE;
        memberof_cookie_t       mc;
 
-       assert( iswhatp != NULL );
-       assert( *iswhatp != MEMBEROF_IS_NONE );
+       assert( mci->what != MEMBEROF_IS_NONE );
 
        cb.sc_private = &mc;
        if ( op->o_tag == LDAP_REQ_DELETE ) {
@@ -338,7 +275,7 @@ memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo
        op2.ors_slimit = 1;
        op2.ors_tlimit = SLAP_NO_LIMIT;
 
-       if ( *iswhatp & MEMBEROF_IS_GROUP ) {
+       if ( mci->what & MEMBEROF_IS_GROUP ) {
                mc.ad = mo->mo_ad_member;
                mc.foundit = 0;
                mc.vals = NULL;
@@ -353,12 +290,12 @@ memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo
 
                if ( mc.foundit ) {
                        iswhat |= MEMBEROF_IS_GROUP;
-                       mci->member = mc.vals;
+                       if ( mc.vals ) mci->member = mc.vals;
 
                }
        }
 
-       if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
+       if ( mci->what & MEMBEROF_IS_MEMBER ) {
                mc.ad = mo->mo_ad_memberof;
                mc.foundit = 0;
                mc.vals = NULL;
@@ -373,12 +310,12 @@ memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo
 
                if ( mc.foundit ) {
                        iswhat |= MEMBEROF_IS_MEMBER;
-                       mci->memberof = mc.vals;
+                       if ( mc.vals ) mci->memberof = mc.vals;
 
                }
        }
 
-       *iswhatp = iswhat;
+       mci->what = iswhat;
 
        return LDAP_SUCCESS;
 }
@@ -448,6 +385,7 @@ memberof_value_modify(
        ml->sml_flags = SLAP_MOD_INTERNAL;
        ml->sml_next = op2.orm_modlist;
        op2.orm_modlist = ml;
+       op2.orm_no_opattrs = 0;
 
        if ( new_ndn != NULL ) {
                assert( !BER_BVISNULL( new_dn ) );
@@ -773,13 +711,9 @@ memberof_op_delete( Operation *op, SlapReply *rs )
        slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
        memberof_t      *mo = (memberof_t *)on->on_bi.bi_private;
 
-       memberof_is_t   iswhat = MEMBEROF_IS_GROUP;
        slap_callback *sc;
        memberof_cbinfo_t *mci;
 
-       if ( MEMBEROF_REFINT( mo ) ) {
-               iswhat = MEMBEROF_IS_BOTH;
-       }
 
        sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
        sc->sc_private = sc+1;
@@ -789,8 +723,12 @@ memberof_op_delete( Operation *op, SlapReply *rs )
        mci->on = on;
        mci->member = NULL;
        mci->memberof = NULL;
+       mci->what = MEMBEROF_IS_GROUP;
+       if ( MEMBEROF_REFINT( mo ) ) {
+               mci->what = MEMBEROF_IS_BOTH;
+       }
 
-       memberof_isGroupOrMember( op, &iswhat, mci );
+       memberof_isGroupOrMember( op, mci );
 
        sc->sc_next = op->o_callback;
        op->o_callback = sc;
@@ -807,7 +745,6 @@ memberof_op_modify( Operation *op, SlapReply *rs )
        Modifications   **mlp, **mmlp = NULL;
        int             rc = SLAP_CB_CONTINUE, save_member = 0;
        struct berval   save_dn, save_ndn;
-       memberof_is_t   iswhat = MEMBEROF_IS_GROUP;
        slap_callback *sc;
        memberof_cbinfo_t *mci, mcis;
 
@@ -825,9 +762,10 @@ memberof_op_modify( Operation *op, SlapReply *rs )
        save_dn = op->o_dn;
        save_ndn = op->o_ndn;
        mcis.on = on;
+       mcis.what = MEMBEROF_IS_GROUP;
 
-       if ( memberof_isGroupOrMember( op, &iswhat, &mcis ) == LDAP_SUCCESS
-               && ( iswhat & MEMBEROF_IS_GROUP ) )
+       if ( memberof_isGroupOrMember( op, &mcis ) == LDAP_SUCCESS
+               && ( mcis.what & MEMBEROF_IS_GROUP ) )
        {
                Modifications *ml;
 
@@ -1182,6 +1120,7 @@ done2:;
        mci->on = on;
        mci->member = NULL;
        mci->memberof = NULL;
+       mci->what = mcis.what;
 
        if ( save_member ) {
                op->o_dn = op->o_bd->be_rootdn;
@@ -1342,7 +1281,6 @@ memberof_res_modify( Operation *op, SlapReply *rs )
        int             i, rc;
        Modifications   *ml, *mml = NULL;
        BerVarray       vals;
-       memberof_is_t   iswhat = MEMBEROF_IS_GROUP;
 
        if ( rs->sr_err != LDAP_SUCCESS ) {
                return SLAP_CB_CONTINUE;
@@ -1410,8 +1348,7 @@ memberof_res_modify( Operation *op, SlapReply *rs )
                }
        }
 
-       if ( memberof_isGroupOrMember( op, &iswhat, mci ) == LDAP_SUCCESS
-                       && ( iswhat & MEMBEROF_IS_GROUP ) )
+       if ( mci->what & MEMBEROF_IS_GROUP )
        {
                for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
                        if ( ml->sml_desc != mo->mo_ad_member ) {
@@ -1486,14 +1423,14 @@ memberof_res_modrdn( Operation *op, SlapReply *rs )
        BerVarray       vals;
 
        struct berval   save_dn, save_ndn;
-       memberof_is_t   iswhat = MEMBEROF_IS_GROUP;
 
        if ( rs->sr_err != LDAP_SUCCESS ) {
                return SLAP_CB_CONTINUE;
        }
 
+       mci->what = MEMBEROF_IS_GROUP;
        if ( MEMBEROF_REFINT( mo ) ) {
-               iswhat |= MEMBEROF_IS_MEMBER;
+               mci->what |= MEMBEROF_IS_MEMBER;
        }
 
        if ( op->orr_nnewSup ) {
@@ -1510,11 +1447,11 @@ memberof_res_modrdn( Operation *op, SlapReply *rs )
 
        op->o_req_dn = newNDN;
        op->o_req_ndn = newNDN;
-       rc = memberof_isGroupOrMember( op, &iswhat, mci );
+       rc = memberof_isGroupOrMember( op, mci );
        op->o_req_dn = save_dn;
        op->o_req_ndn = save_ndn;
 
-       if ( rc != LDAP_SUCCESS || iswhat == MEMBEROF_IS_NONE ) {
+       if ( rc != LDAP_SUCCESS || mci->what == MEMBEROF_IS_NONE ) {
                goto done;
        }
 
@@ -1527,7 +1464,7 @@ memberof_res_modrdn( Operation *op, SlapReply *rs )
 
        build_new_dn( &newDN, &newPDN, &op->orr_newrdn, op->o_tmpmemctx ); 
 
-       if ( iswhat & MEMBEROF_IS_GROUP ) {
+       if ( mci->what & MEMBEROF_IS_GROUP ) {
                op->o_bd->bd_info = (BackendInfo *)on->on_info;
                rc = backend_attribute( op, NULL, &newNDN,
                                mo->mo_ad_member, &vals, ACL_READ );
@@ -1544,7 +1481,7 @@ memberof_res_modrdn( Operation *op, SlapReply *rs )
                }
        }
 
-       if ( MEMBEROF_REFINT( mo ) && ( iswhat & MEMBEROF_IS_MEMBER ) ) {
+       if ( MEMBEROF_REFINT( mo ) && ( mci->what & MEMBEROF_IS_MEMBER ) ) {
                op->o_bd->bd_info = (BackendInfo *)on->on_info;
                rc = backend_attribute( op, NULL, &newNDN,
                                mo->mo_ad_memberof, &vals, ACL_READ );