MEMBEROF_IS_BOTH = (MEMBEROF_IS_GROUP|MEMBEROF_IS_MEMBER)
} memberof_is_t;
-/*
- * failover storage for member attribute values of groups being deleted
- * handles [no]thread cases.
- */
-static BerVarray saved_member_vals;
-static BerVarray saved_memberof_vals;
-
static void
memberof_saved_member_free( void *key, void *data )
{
typedef struct memberof_cookie_t {
AttributeDescription *ad;
- void *key;
+ BerVarray vals;
int foundit;
} memberof_cookie_t;
+typedef struct memberof_cbinfo_t {
+ slap_overinst *on;
+ BerVarray member;
+ BerVarray memberof;
+} memberof_cbinfo_t;
+
static int
memberof_isGroupOrMember_cb( Operation *op, SlapReply *rs )
{
if ( rs->sr_type == REP_SEARCH ) {
memberof_cookie_t *mc;
Attribute *a;
- BerVarray vals = NULL;
mc = (memberof_cookie_t *)op->o_callback->sc_private;
mc->foundit = 1;
a = attr_find( rs->sr_entry->e_attrs, mc->ad );
if ( a != NULL ) {
- vals = a->a_nvals;
+ ber_bvarray_dup_x( &mc->vals, a->a_nvals, op->o_tmpmemctx );
}
- memberof_saved_member_set( op, mc->key, vals );
-
if ( a && attr_find( a->a_next, mc->ad ) != NULL ) {
Debug( LDAP_DEBUG_ANY,
"%s: memberof_saveMember_cb(\"%s\"): "
* attribute values of groups being deleted.
*/
static int
-memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp )
+memberof_isGroupOrMember( Operation *op, memberof_is_t *iswhatp, memberof_cbinfo_t *mci )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
Operation op2 = *op;
SlapReply rs2 = { REP_RESULT };
slap_callback cb = { 0 };
- memberof_cookie_t mc;
+ BackendInfo *bi = op->o_bd->bd_info;
AttributeName an[ 2 ];
memberof_is_t iswhat = MEMBEROF_IS_NONE;
+ memberof_cookie_t mc;
assert( iswhatp != NULL );
assert( *iswhatp != MEMBEROF_IS_NONE );
if ( *iswhatp & MEMBEROF_IS_GROUP ) {
mc.ad = mo->mo_ad_member;
- mc.key = &saved_member_vals;
mc.foundit = 0;
+ mc.vals = NULL;
an[ 0 ].an_desc = mo->mo_ad_member;
an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
op2.ors_filterstr = mo->mo_groupFilterstr;
op2.o_bd->bd_info = (BackendInfo *)on->on_info;
(void)op->o_bd->be_search( &op2, &rs2 );
- op2.o_bd->bd_info = (BackendInfo *)on;
+ op2.o_bd->bd_info = bi;
if ( mc.foundit ) {
iswhat |= MEMBEROF_IS_GROUP;
+ mci->member = mc.vals;
- } else {
- memberof_saved_member_set( op, mc.key, NULL );
}
}
if ( *iswhatp & MEMBEROF_IS_MEMBER ) {
mc.ad = mo->mo_ad_memberof;
- mc.key = &saved_memberof_vals;
mc.foundit = 0;
+ mc.vals = NULL;
an[ 0 ].an_desc = mo->mo_ad_memberof;
an[ 0 ].an_name = an[ 0 ].an_desc->ad_cname;
op2.ors_filterstr = mo->mo_memberFilterstr;
op2.o_bd->bd_info = (BackendInfo *)on->on_info;
(void)op->o_bd->be_search( &op2, &rs2 );
- op2.o_bd->bd_info = (BackendInfo *)on;
+ op2.o_bd->bd_info = bi;
if ( mc.foundit ) {
iswhat |= MEMBEROF_IS_MEMBER;
+ mci->memberof = mc.vals;
- } else {
- memberof_saved_member_set( op, mc.key, NULL );
}
}
struct berval *new_dn,
struct berval *new_ndn )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ memberof_cbinfo_t *mci = op->o_callback->sc_private;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
Operation op2 = *op;
op2.o_req_dn = *ndn;
op2.o_req_ndn = *ndn;
- op2.o_bd->bd_info = (BackendInfo *)on->on_info;
-
op2.o_callback = &cb;
op2.o_dn = op->o_bd->be_rootdn;
op2.o_ndn = op->o_bd->be_rootndn;
* not optimal in terms of performance. At least it would
* move towards self-repairing capabilities. */
- op2.o_bd->bd_info = (BackendInfo *)on;
-
return rs2.sr_err;
}
+static int
+memberof_cleanup( Operation *op, SlapReply *rs )
+{
+ slap_callback *sc = op->o_callback;
+ memberof_cbinfo_t *mci = sc->sc_private;
+
+ op->o_callback = sc->sc_next;
+ if ( mci->memberof )
+ ber_bvarray_free_x( mci->memberof, op->o_tmpmemctx );
+ if ( mci->member )
+ ber_bvarray_free_x( mci->member, op->o_tmpmemctx );
+ op->o_tmpfree( sc, op->o_tmpmemctx );
+ return 0;
+}
+
+static int memberof_res_add( Operation *op, SlapReply *rs );
+static int memberof_res_delete( Operation *op, SlapReply *rs );
+static int memberof_res_modify( Operation *op, SlapReply *rs );
+static int memberof_res_modrdn( Operation *op, SlapReply *rs );
+
static int
memberof_op_add( Operation *op, SlapReply *rs )
{
int rc = SLAP_CB_CONTINUE;
int i;
struct berval save_dn, save_ndn;
+ slap_callback *sc;
+ memberof_cbinfo_t *mci;
if ( op->ora_e->e_attrs == NULL ) {
/* FIXME: global overlay; need to deal with */
}
rc = SLAP_CB_CONTINUE;
-
+
+ sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
+ sc->sc_private = sc+1;
+ sc->sc_response = memberof_res_add;
+ sc->sc_cleanup = memberof_cleanup;
+ mci = sc->sc_private;
+ mci->on = on;
+ mci->member = NULL;
+ mci->memberof = NULL;
+ sc->sc_next = op->o_callback;
+ op->o_callback = sc;
+
done:;
op->o_dn = save_dn;
op->o_ndn = save_ndn;
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;
}
- memberof_isGroupOrMember( op, &iswhat );
+ sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
+ sc->sc_private = sc+1;
+ sc->sc_response = memberof_res_delete;
+ sc->sc_cleanup = memberof_cleanup;
+ mci = sc->sc_private;
+ mci->on = on;
+ mci->member = NULL;
+ mci->memberof = NULL;
+
+ memberof_isGroupOrMember( op, &iswhat, mci );
+
+ sc->sc_next = op->o_callback;
+ op->o_callback = sc;
return SLAP_CB_CONTINUE;
}
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
Modifications **mlp, **mmlp = NULL;
- int rc = SLAP_CB_CONTINUE;
+ 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;
if ( MEMBEROF_REVERSE( mo ) ) {
for ( mlp = &op->orm_modlist; *mlp; mlp = &(*mlp)->sml_next ) {
save_dn = op->o_dn;
save_ndn = op->o_ndn;
+ mcis.on = on;
- if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
+ if ( memberof_isGroupOrMember( op, &iswhat, &mcis ) == LDAP_SUCCESS
&& ( iswhat & MEMBEROF_IS_GROUP ) )
{
Modifications *ml;
- int save_member = 0;
for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
if ( ml->sml_desc == mo->mo_ad_member ) {
}
}
- if ( save_member ) {
- BerVarray vals = NULL;
-
- op->o_dn = op->o_bd->be_rootdn;
- op->o_ndn = op->o_bd->be_rootndn;
- op->o_bd->bd_info = (BackendInfo *)on->on_info;
- rc = backend_attribute( op, NULL, &op->o_req_ndn,
- mo->mo_ad_member, &vals, ACL_READ );
- op->o_bd->bd_info = (BackendInfo *)on;
- if ( rc == LDAP_SUCCESS && vals != NULL ) {
- memberof_saved_member_set( op, &saved_member_vals, vals );
- ber_bvarray_free_x( vals, op->o_tmpmemctx );
- }
- }
if ( MEMBEROF_DANGLING_CHECK( mo )
&& !get_relax( op ) )
op->o_bd->bd_info = (BackendInfo *)on;
}
+ sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
+ sc->sc_private = sc+1;
+ sc->sc_response = memberof_res_modify;
+ sc->sc_cleanup = memberof_cleanup;
+ mci = sc->sc_private;
+ mci->on = on;
+ mci->member = NULL;
+ mci->memberof = NULL;
+
+ if ( save_member ) {
+ op->o_dn = op->o_bd->be_rootdn;
+ op->o_ndn = op->o_bd->be_rootndn;
+ op->o_bd->bd_info = (BackendInfo *)on->on_info;
+ rc = backend_attribute( op, NULL, &op->o_req_ndn,
+ mo->mo_ad_member, &mci->member, ACL_READ );
+ op->o_bd->bd_info = (BackendInfo *)on;
+ }
+
+ sc->sc_next = op->o_callback;
+ op->o_callback = sc;
+
rc = SLAP_CB_CONTINUE;
done:;
return rc;
}
+static int
+memberof_op_modrdn( Operation *op, SlapReply *rs )
+{
+ slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ slap_callback *sc;
+ memberof_cbinfo_t *mci;
+
+ sc = op->o_tmpalloc( sizeof(slap_callback)+sizeof(*mci), op->o_tmpmemctx );
+ sc->sc_private = sc+1;
+ sc->sc_response = memberof_res_modrdn;
+ sc->sc_cleanup = memberof_cleanup;
+ mci = sc->sc_private;
+ mci->on = on;
+ mci->member = NULL;
+ mci->memberof = NULL;
+
+ sc->sc_next = op->o_callback;
+ op->o_callback = sc;
+
+ return SLAP_CB_CONTINUE;
+}
+
/*
* response callback that adds memberof values when a group is added.
*/
static int
memberof_res_add( Operation *op, SlapReply *rs )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ memberof_cbinfo_t *mci = op->o_callback->sc_private;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
int i;
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ return SLAP_CB_CONTINUE;
+ }
+
if ( MEMBEROF_REVERSE( mo ) ) {
Attribute *ma;
ma = attr_find( op->ora_e->e_attrs, mo->mo_ad_memberof );
if ( ma != NULL ) {
- Operation op2 = *op;
- SlapReply rs2 = { 0 };
+ char relax = op->o_relax;
/* relax is required to allow to add
* a non-existing member */
- op2.o_relax = SLAP_CONTROL_CRITICAL;
+ op->o_relax = SLAP_CONTROL_CRITICAL;
for ( i = 0; !BER_BVISNULL( &ma->a_nvals[ i ] ); i++ ) {
/* the modification is attempted
* with the original identity */
- (void)memberof_value_modify( &op2, &rs2,
+ (void)memberof_value_modify( op, rs,
&ma->a_nvals[ i ], mo->mo_ad_member,
NULL, NULL, &op->o_req_dn, &op->o_req_ndn );
}
static int
memberof_res_delete( Operation *op, SlapReply *rs )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ memberof_cbinfo_t *mci = op->o_callback->sc_private;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
BerVarray vals;
int i;
- vals = memberof_saved_member_get( op, &saved_member_vals );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ return SLAP_CB_CONTINUE;
+ }
+
+ vals = mci->member;
if ( vals != NULL ) {
for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
(void)memberof_value_modify( op, rs,
&op->o_req_dn, &op->o_req_ndn,
NULL, NULL );
}
-
- memberof_saved_member_set( op, &saved_memberof_vals, NULL );
- ber_bvarray_free( vals );
}
if ( MEMBEROF_REFINT( mo ) ) {
- vals = memberof_saved_member_get( op, &saved_memberof_vals );
+ vals = mci->memberof;
if ( vals != NULL ) {
for ( i = 0; !BER_BVISNULL( &vals[ i ] ); i++ ) {
(void)memberof_value_modify( op, rs,
&op->o_req_dn, &op->o_req_ndn,
NULL, NULL );
}
-
- memberof_saved_member_set( op, &saved_member_vals, NULL );
- ber_bvarray_free( vals );
}
}
static int
memberof_res_modify( Operation *op, SlapReply *rs )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ memberof_cbinfo_t *mci = op->o_callback->sc_private;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
int i, rc;
BerVarray vals;
memberof_is_t iswhat = MEMBEROF_IS_GROUP;
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ return SLAP_CB_CONTINUE;
+ }
+
if ( MEMBEROF_REVERSE( mo ) ) {
for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
if ( ml->sml_desc == mo->mo_ad_memberof ) {
}
}
- if ( memberof_isGroupOrMember( op, &iswhat ) == LDAP_SUCCESS
+ if ( memberof_isGroupOrMember( op, &iswhat, mci ) == LDAP_SUCCESS
&& ( iswhat & MEMBEROF_IS_GROUP ) )
{
for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
/* fall thru */
case LDAP_MOD_REPLACE:
- vals = memberof_saved_member_get( op, &saved_member_vals );
+ vals = mci->member;
/* delete all ... */
if ( vals != NULL ) {
&op->o_req_dn, &op->o_req_ndn,
NULL, NULL );
}
- ber_bvarray_free_x( vals, op->o_tmpmemctx );
}
if ( ml->sml_op == LDAP_MOD_DELETE || !ml->sml_values ) {
/*
* response callback that adds/deletes member values when a group member
- * is modified.
+ * is renamed.
*/
static int
-memberof_res_rename( Operation *op, SlapReply *rs )
+memberof_res_modrdn( Operation *op, SlapReply *rs )
{
- slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+ memberof_cbinfo_t *mci = op->o_callback->sc_private;
+ slap_overinst *on = mci->on;
memberof_t *mo = (memberof_t *)on->on_bi.bi_private;
struct berval newPDN, newDN = BER_BVNULL, newPNDN, newNDN;
struct berval save_dn, save_ndn;
memberof_is_t iswhat = MEMBEROF_IS_GROUP;
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ return SLAP_CB_CONTINUE;
+ }
+
if ( MEMBEROF_REFINT( mo ) ) {
iswhat |= MEMBEROF_IS_MEMBER;
}
op->o_req_dn = newNDN;
op->o_req_ndn = newNDN;
- rc = memberof_isGroupOrMember( op, &iswhat );
+ rc = memberof_isGroupOrMember( op, &iswhat, mci );
op->o_req_dn = save_dn;
op->o_req_ndn = save_ndn;
return SLAP_CB_CONTINUE;
}
-static int
-memberof_response( Operation *op, SlapReply *rs )
-{
- if ( rs->sr_err != LDAP_SUCCESS ) {
- return SLAP_CB_CONTINUE;
- }
-
- switch ( op->o_tag ) {
- case LDAP_REQ_ADD:
- return memberof_res_add( op, rs );
-
- case LDAP_REQ_DELETE:
- return memberof_res_delete( op, rs );
-
- case LDAP_REQ_MODIFY:
- return memberof_res_modify( op, rs );
-
- case LDAP_REQ_MODDN:
- return memberof_res_rename( op, rs );
-
- default:
- return SLAP_CB_CONTINUE;
- }
-}
static int
memberof_db_init(
memberof.on_bi.bi_op_add = memberof_op_add;
memberof.on_bi.bi_op_delete = memberof_op_delete;
memberof.on_bi.bi_op_modify = memberof_op_modify;
-
- memberof.on_response = memberof_response;
+ memberof.on_bi.bi_op_modrdn = memberof_op_modrdn;
memberof.on_bi.bi_cf_ocs = mo_ocs;