Cleanup of SLAPI internal operation code; use frontendDB rather than

duplicating frontend code, and o->o_callback rather than overriding
entry send clalbacks.

Support for SLAPI internal operation plugins.
This commit is contained in:
Luke Howard 2005-07-23 12:03:13 +00:00
parent 9a1c8cdb88
commit 92df34238a
4 changed files with 350 additions and 699 deletions

View File

@ -44,6 +44,7 @@ LDAP_SLAPI_F (char **) slapi_get_supported_extended_ops LDAP_P((void));
/* slapi_ops.c */ /* slapi_ops.c */
LDAP_SLAPI_F (int) slapi_int_connection_init LDAP_P((Slapi_PBlock *pb, SlapReply *rs, int OpType, Connection **pConn)); LDAP_SLAPI_F (int) slapi_int_connection_init LDAP_P((Slapi_PBlock *pb, SlapReply *rs, int OpType, Connection **pConn));
LDAP_SLAPI_F (void) slapi_int_connection_destroy LDAP_P(( Connection **pConn )); LDAP_SLAPI_F (void) slapi_int_connection_destroy LDAP_P(( Connection **pConn ));
LDAP_SLAPI_F (int) slapi_int_response LDAP_P(( Slapi_Operation *op, SlapReply *rs ));
/* slapi_pblock.c */ /* slapi_pblock.c */
LDAP_SLAPI_F (void) slapi_pblock_check_params LDAP_P(( Slapi_PBlock *pb, int flag )); LDAP_SLAPI_F (void) slapi_pblock_check_params LDAP_P(( Slapi_PBlock *pb, int flag ));
@ -71,6 +72,9 @@ LDAP_SLAPI_F (int) slapi_int_free_object_extensions LDAP_P((int objecttype, void
LDAP_SLAPI_F (int) slapi_int_create_object_extensions LDAP_P((int objecttype, void *object)); LDAP_SLAPI_F (int) slapi_int_create_object_extensions LDAP_P((int objecttype, void *object));
LDAP_SLAPI_F (int) slapi_int_clear_object_extensions LDAP_P((int objecttype, void *object)); LDAP_SLAPI_F (int) slapi_int_clear_object_extensions LDAP_P((int objecttype, void *object));
/* slapi_overlay.c */
LDAP_SLAPI_F (int) slapi_int_overlay_init LDAP_P((void));
LDAP_END_DECL LDAP_END_DECL
#endif /* _PROTO_SLAPI_H */ #endif /* _PROTO_SLAPI_H */

File diff suppressed because it is too large Load Diff

View File

@ -32,20 +32,62 @@
static slap_overinst slapi; static slap_overinst slapi;
static int slapi_over_response( Operation *op, SlapReply *rs );
static int slapi_over_cleanup( Operation *op, SlapReply *rs );
static Slapi_PBlock * static Slapi_PBlock *
slapi_over_pblock_new ( Operation *op ) slapi_over_pblock_new ( Operation *op )
{ {
Slapi_PBlock *pb; Slapi_PBlock *pb;
pb = slapi_pblock_new(); pb = slapi_pblock_new();
if ( pb == NULL ) if ( pb == NULL ) {
return NULL; return NULL;
}
slapi_int_pblock_set_operation( pb, op ); slapi_int_pblock_set_operation( pb, op );
return pb; return pb;
} }
static int
slapi_op_internal_p( Operation *op, slap_callback *cb )
{
int internal_op = 0;
Slapi_PBlock *pb = NULL;
slap_callback *pcb;
/* Abstraction violating check for SLAPI internal operations */
/* allows pblock to remain consistent when invoking internal op plugins */
for ( pcb = op->o_callback; pcb != NULL; pcb = pcb->sc_next ) {
if ( pcb->sc_response == slapi_int_response ) {
pb = (Slapi_PBlock *)pcb->sc_private;
internal_op = 1;
break;
}
}
if ( cb != NULL ) {
if ( !internal_op ) {
cb->sc_response = slapi_over_response;
cb->sc_cleanup = slapi_over_cleanup;
} else {
cb->sc_response = NULL;
cb->sc_cleanup = NULL;
}
if ( pb == NULL ) {
pb = slapi_over_pblock_new( op );
}
cb->sc_private = pb;
cb->sc_next = op->o_callback;
op->o_callback = cb;
}
return internal_op;
}
static int static int
slapi_over_compute_output( slapi_over_compute_output(
computed_attr_context *c, computed_attr_context *c,
@ -53,10 +95,8 @@ slapi_over_compute_output(
Slapi_Entry *entry Slapi_Entry *entry
) )
{ {
int rc;
Attribute **a; Attribute **a;
AttributeDescription *desc; AttributeDescription *desc;
Operation *op = c->cac_op;
SlapReply *rs = (SlapReply *)c->cac_private; SlapReply *rs = (SlapReply *)c->cac_private;
if ( c == NULL || attribute == NULL || entry == NULL ) { if ( c == NULL || attribute == NULL || entry == NULL ) {
@ -103,6 +143,10 @@ slapi_over_aux_operational( Operation *op, SlapReply *rs )
computed_attr_context ctx; computed_attr_context ctx;
AttributeName *anp; AttributeName *anp;
if ( slapi_op_internal_p( op, NULL ) ) {
return SLAP_CB_CONTINUE;
}
ctx.cac_pb = slapi_over_pblock_new( op ); ctx.cac_pb = slapi_over_pblock_new( op );
ctx.cac_op = op; ctx.cac_op = op;
ctx.cac_private = rs; ctx.cac_private = rs;
@ -274,7 +318,6 @@ static int
slapi_op_bind_postop_init( Operation *op, SlapReply *rs ) slapi_op_bind_postop_init( Operation *op, SlapReply *rs )
{ {
Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
char *dn = NULL;
if ( rs->sr_err == LDAP_SUCCESS ) { if ( rs->sr_err == LDAP_SUCCESS ) {
/* fix for ITS#2971 */ /* fix for ITS#2971 */
@ -509,22 +552,28 @@ slapi_op_search_cleanup( Operation *op, SlapReply *rs )
struct slapi_op_info { struct slapi_op_info {
int soi_preop; /* preoperation plugin parameter */ int soi_preop; /* preoperation plugin parameter */
int soi_postop; /* postoperation plugin parameter */ int soi_postop; /* postoperation plugin parameter */
int soi_internal_preop; /* internal preoperation plugin parameter */
int soi_internal_postop; /* internal postoperation plugin parameter */
slap_response *soi_preop_init; /* preoperation pblock init function */ slap_response *soi_preop_init; /* preoperation pblock init function */
slap_response *soi_callback; /* preoperation result handler */ slap_response *soi_callback; /* preoperation result handler */
slap_response *soi_postop_init; /* postoperation pblock init function */ slap_response *soi_postop_init; /* postoperation pblock init function */
slap_response *soi_cleanup; /* cleanup function */ slap_response *soi_cleanup; /* cleanup function (not for internal ops) */
} slapi_op_dispatch_table[] = { } slapi_op_dispatch_table[] = {
{ {
SLAPI_PLUGIN_PRE_BIND_FN, SLAPI_PLUGIN_PRE_BIND_FN,
SLAPI_PLUGIN_POST_BIND_FN, SLAPI_PLUGIN_POST_BIND_FN,
0,
0,
slapi_op_bind_preop_init, slapi_op_bind_preop_init,
slapi_op_bind_callback, slapi_op_bind_callback,
slapi_op_bind_postop_init, slapi_op_bind_postop_init,
NULL NULL
}, },
{ {
SLAPI_PLUGIN_PRE_UNBIND_FN, /* UNBIND */ SLAPI_PLUGIN_PRE_UNBIND_FN,
SLAPI_PLUGIN_POST_UNBIND_FN, SLAPI_PLUGIN_POST_UNBIND_FN,
0,
0,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -533,6 +582,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_SEARCH_FN, SLAPI_PLUGIN_PRE_SEARCH_FN,
SLAPI_PLUGIN_POST_SEARCH_FN, SLAPI_PLUGIN_POST_SEARCH_FN,
0,
0,
slapi_op_search_init, slapi_op_search_init,
slapi_op_search_callback, slapi_op_search_callback,
NULL, NULL,
@ -541,6 +592,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_COMPARE_FN, SLAPI_PLUGIN_PRE_COMPARE_FN,
SLAPI_PLUGIN_POST_COMPARE_FN, SLAPI_PLUGIN_POST_COMPARE_FN,
0,
0,
slapi_op_compare_init, slapi_op_compare_init,
NULL, NULL,
NULL, NULL,
@ -549,6 +602,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_MODIFY_FN, SLAPI_PLUGIN_PRE_MODIFY_FN,
SLAPI_PLUGIN_POST_MODIFY_FN, SLAPI_PLUGIN_POST_MODIFY_FN,
SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN,
SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN,
slapi_op_modify_init, slapi_op_modify_init,
slapi_op_modify_callback, slapi_op_modify_callback,
NULL, NULL,
@ -557,6 +612,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_MODRDN_FN, SLAPI_PLUGIN_PRE_MODRDN_FN,
SLAPI_PLUGIN_POST_MODRDN_FN, SLAPI_PLUGIN_POST_MODRDN_FN,
SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN,
SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN,
slapi_op_modrdn_init, slapi_op_modrdn_init,
NULL, NULL,
NULL, NULL,
@ -565,6 +622,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_ADD_FN, SLAPI_PLUGIN_PRE_ADD_FN,
SLAPI_PLUGIN_POST_ADD_FN, SLAPI_PLUGIN_POST_ADD_FN,
SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN,
SLAPI_PLUGIN_INTERNAL_POST_ADD_FN,
slapi_op_add_init, slapi_op_add_init,
NULL, NULL,
NULL, NULL,
@ -573,6 +632,8 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_DELETE_FN, SLAPI_PLUGIN_PRE_DELETE_FN,
SLAPI_PLUGIN_POST_DELETE_FN, SLAPI_PLUGIN_POST_DELETE_FN,
SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN,
SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@ -581,12 +642,16 @@ struct slapi_op_info {
{ {
SLAPI_PLUGIN_PRE_ABANDON_FN, SLAPI_PLUGIN_PRE_ABANDON_FN,
SLAPI_PLUGIN_POST_ABANDON_FN, SLAPI_PLUGIN_POST_ABANDON_FN,
0,
0,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL NULL
}, },
{ {
0,
0,
0, 0,
0, 0,
NULL, NULL,
@ -686,18 +751,15 @@ slapi_op_func( Operation *op, SlapReply *rs )
Slapi_PBlock *pb; Slapi_PBlock *pb;
slap_operation_t which; slap_operation_t which;
struct slapi_op_info *opinfo; struct slapi_op_info *opinfo;
int rc, flags = 0; int rc;
slap_overinfo *oi; slap_overinfo *oi;
slap_overinst *on; slap_overinst *on;
slap_callback cb; slap_callback cb;
int internal_op;
int preop_type, postop_type;
/* if ( !slapi_plugins_used )
* We check for op->o_extensions to verify that we are not
* processing a SLAPI internal operation. XXX
*/
if ( op->o_hdr->oh_extensions == NULL ) {
return SLAP_CB_CONTINUE; return SLAP_CB_CONTINUE;
}
/* /*
* Find the SLAPI operation information for this LDAP * Find the SLAPI operation information for this LDAP
@ -712,23 +774,32 @@ slapi_op_func( Operation *op, SlapReply *rs )
} }
opinfo = &slapi_op_dispatch_table[which]; opinfo = &slapi_op_dispatch_table[which];
if ( opinfo == NULL || opinfo->soi_preop == 0 ) { if ( opinfo == NULL ) {
/* no SLAPI plugin types for this operation */ /* no SLAPI plugin types for this operation */
return SLAP_CB_CONTINUE; return SLAP_CB_CONTINUE;
} }
pb = slapi_over_pblock_new( op ); internal_op = slapi_op_internal_p( op, &cb );
if ( internal_op ) {
preop_type = opinfo->soi_internal_preop;
postop_type = opinfo->soi_internal_postop;
} else {
preop_type = opinfo->soi_preop;
postop_type = opinfo->soi_postop;
}
if ( preop_type == 0 ) {
/* no SLAPI plugin types for this operation */
rs->sr_err = SLAP_CB_CONTINUE;
goto cleanup;
}
pb = SLAPI_OPERATION_PBLOCK( op );
/* XXX we need to fill this out for MMR support */
slapi_pblock_set( pb, SLAPI_TARGET_ADDRESS, NULL ); slapi_pblock_set( pb, SLAPI_TARGET_ADDRESS, NULL );
slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, NULL ); slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, NULL );
slapi_pblock_set( pb, SLAPI_TARGET_DN, (void *)op->o_req_dn.bv_val ); slapi_pblock_set( pb, SLAPI_TARGET_DN, (void *)op->o_req_dn.bv_val );
cb.sc_response = slapi_over_response; /* call pre-entry/result plugins */
cb.sc_cleanup = slapi_over_cleanup; /* call post-entry/result plugins */
cb.sc_private = pb;
cb.sc_next = op->o_callback;
op->o_callback = &cb;
/* /*
* Call preoperation plugins * Call preoperation plugins
@ -739,7 +810,7 @@ slapi_op_func( Operation *op, SlapReply *rs )
goto cleanup; goto cleanup;
} }
rs->sr_err = slapi_int_call_plugins( op->o_bd, opinfo->soi_preop, pb ); rs->sr_err = slapi_int_call_plugins( op->o_bd, preop_type, pb );
/* /*
* soi_callback is responsible for examining the result code * soi_callback is responsible for examining the result code
@ -756,6 +827,8 @@ slapi_op_func( Operation *op, SlapReply *rs )
if ( rs->sr_err < 0 ) { if ( rs->sr_err < 0 ) {
slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rs->sr_err ); slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rs->sr_err );
goto cleanup; goto cleanup;
} else {
rs->sr_err = LDAP_SUCCESS;
} }
} else { } else {
rc = (opinfo->soi_callback)( op, rs ); rc = (opinfo->soi_callback)( op, rs );
@ -785,15 +858,18 @@ slapi_op_func( Operation *op, SlapReply *rs )
(opinfo->soi_postop_init)( op, rs ); (opinfo->soi_postop_init)( op, rs );
} }
slapi_int_call_plugins( op->o_bd, opinfo->soi_postop, pb ); slapi_int_call_plugins( op->o_bd, postop_type, pb );
cleanup: cleanup:
if ( opinfo->soi_cleanup != NULL ) { if ( !internal_op ) {
(opinfo->soi_cleanup)( op, rs ); if ( opinfo->soi_cleanup != NULL ) {
(opinfo->soi_cleanup)( op, rs );
}
slapi_pblock_destroy(pb);
cb.sc_private = NULL;
} }
op->o_callback = cb.sc_next; op->o_callback = cb.sc_next;
slapi_pblock_destroy(pb);
return rs->sr_err; return rs->sr_err;
} }
@ -803,16 +879,22 @@ slapi_over_extended( Operation *op, SlapReply *rs )
{ {
Slapi_PBlock *pb; Slapi_PBlock *pb;
SLAPI_FUNC callback; SLAPI_FUNC callback;
int sentResult = 0;
int rc; int rc;
struct berval reqdata = BER_BVNULL; struct berval reqdata = BER_BVNULL;
int internal_op;
slap_callback cb;
slapi_int_get_extop_plugin( &op->ore_reqoid, &callback ); slapi_int_get_extop_plugin( &op->ore_reqoid, &callback );
if ( callback == NULL ) { if ( callback == NULL ) {
return SLAP_CB_CONTINUE; return SLAP_CB_CONTINUE;
} }
pb = slapi_over_pblock_new( op ); internal_op = slapi_op_internal_p( op, &cb );
if ( internal_op ) {
return SLAP_CB_CONTINUE;
}
pb = SLAPI_OPERATION_PBLOCK( op );
if ( op->ore_reqdata != NULL ) { if ( op->ore_reqdata != NULL ) {
reqdata = *op->ore_reqdata; reqdata = *op->ore_reqdata;
@ -836,8 +918,7 @@ slapi_over_extended( Operation *op, SlapReply *rs )
rs->sr_err = rc; rs->sr_err = rc;
send_ldap_extended( op, rs ); send_ldap_extended( op, rs );
if ( rs->sr_rspoid != NULL ) slapi_ch_free_string( (char **)&rs->sr_rspoid );
slapi_ch_free_string( (char **)&rs->sr_rspoid );
if ( rs->sr_rspdata != NULL ) if ( rs->sr_rspdata != NULL )
ber_bvfree( rs->sr_rspdata ); ber_bvfree( rs->sr_rspdata );
@ -860,22 +941,24 @@ slapi_over_access_allowed(
int rc; int rc;
Slapi_PBlock *pb; Slapi_PBlock *pb;
slap_callback cb; slap_callback cb;
int internal_op;
pb = slapi_over_pblock_new( op ); internal_op = slapi_op_internal_p( op, &cb );
cb.sc_response = NULL; cb.sc_response = NULL;
cb.sc_cleanup = NULL; cb.sc_cleanup = NULL;
cb.sc_private = pb;
cb.sc_next = op->o_callback; pb = SLAPI_OPERATION_PBLOCK( op );
op->o_callback = &cb;
rc = slapi_int_access_allowed( op, e, desc, val, access, state ); rc = slapi_int_access_allowed( op, e, desc, val, access, state );
if ( rc != 0 ) { if ( rc ) {
rc = SLAP_CB_CONTINUE; rc = SLAP_CB_CONTINUE;
} }
op->o_callback = cb.sc_next; op->o_callback = cb.sc_next;
slapi_pblock_destroy( pb );
if ( !internal_op )
slapi_pblock_destroy( pb );
return rc; return rc;
} }
@ -919,7 +1002,15 @@ slapi_over_acl_group(
rc = be_entry_get_rw( op, gr_ndn, group_oc, group_at, 0, &e ); rc = be_entry_get_rw( op, gr_ndn, group_oc, group_at, 0, &e );
} }
if ( e != NULL ) { if ( e != NULL ) {
pb = slapi_over_pblock_new( op ); int internal_op;
slap_callback cb;
internal_op = slapi_op_internal_p( op, &cb );
cb.sc_response = NULL;
cb.sc_cleanup = NULL;
pb = SLAPI_OPERATION_PBLOCK( op );
slapi_pblock_set( pb, SLAPI_X_GROUP_ENTRY, (void *)e ); slapi_pblock_set( pb, SLAPI_X_GROUP_ENTRY, (void *)e );
slapi_pblock_set( pb, SLAPI_X_GROUP_OPERATION_DN, (void *)op_ndn->bv_val ); slapi_pblock_set( pb, SLAPI_X_GROUP_OPERATION_DN, (void *)op_ndn->bv_val );
@ -932,7 +1023,8 @@ slapi_over_acl_group(
else else
slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rc ); slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rc );
slapi_pblock_destroy( pb ); if ( !internal_op )
slapi_pblock_destroy( pb );
if ( e != target ) { if ( e != target ) {
be_entry_release_r( op, e ); be_entry_release_r( op, e );

View File

@ -226,7 +226,8 @@ void
slapi_entry_free( Slapi_Entry *e ) slapi_entry_free( Slapi_Entry *e )
{ {
#ifdef LDAP_SLAPI #ifdef LDAP_SLAPI
entry_free( e ); if ( e != NULL )
entry_free( e );
#endif /* LDAP_SLAPI */ #endif /* LDAP_SLAPI */
} }
@ -550,7 +551,7 @@ slapi_entry_has_children(const Slapi_Entry *e)
} }
op = conn->c_pending_ops.stqh_first; op = conn->c_pending_ops.stqh_first;
op->o_bd = select_backend( &e->e_ndn, 0, 0 ); op->o_bd = select_backend( &e->e_nname, 0, 0 );
if ( op->o_bd != NULL ) { if ( op->o_bd != NULL ) {
op->o_bd->be_has_subordinates( op, (Entry *)e, &hasSubordinates ); op->o_bd->be_has_subordinates( op, (Entry *)e, &hasSubordinates );
} }
@ -1154,6 +1155,8 @@ void
slapi_ch_free( void **ptr ) slapi_ch_free( void **ptr )
{ {
#ifdef LDAP_SLAPI #ifdef LDAP_SLAPI
if ( ptr == NULL || *ptr == NULL )
return;
ch_free( *ptr ); ch_free( *ptr );
*ptr = NULL; *ptr = NULL;
#endif /* LDAP_SLAPI */ #endif /* LDAP_SLAPI */
@ -2464,7 +2467,6 @@ static char *Authorization2AuthType( AuthorizationInformation *authz, int is_tls
static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn ) static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn )
{ {
char *connAuthType; char *connAuthType;
int rc;
slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn ); slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
@ -2536,7 +2538,6 @@ int slapi_int_pblock_set_operation( Slapi_PBlock *pb, Operation *op )
#ifdef LDAP_SLAPI #ifdef LDAP_SLAPI
int isRoot = 0; int isRoot = 0;
int isUpdateDn = 0; int isUpdateDn = 0;
int rc;
char *opAuthType; char *opAuthType;
void *existingOp = NULL; void *existingOp = NULL;
BackendDB *be_orig; BackendDB *be_orig;
@ -3508,7 +3509,7 @@ LDAPMod **slapi_int_modifications2ldapmods(Modifications **pmodlist)
* LDAPMods array; the latter MUST be freed with * LDAPMods array; the latter MUST be freed with
* slapi_int_free_ldapmods() (see below). * slapi_int_free_ldapmods() (see below).
*/ */
Modifications *slapi_int_ldapmods2modifications (LDAPMod **mods) Modifications *slapi_int_ldapmods2modifications ( LDAPMod **mods )
{ {
#ifdef LDAP_SLAPI #ifdef LDAP_SLAPI
Modifications *modlist = NULL, **modtail; Modifications *modlist = NULL, **modtail;
@ -3528,6 +3529,7 @@ Modifications *slapi_int_ldapmods2modifications (LDAPMod **mods)
const char *text; const char *text;
AttributeDescription *ad = NULL; AttributeDescription *ad = NULL;
/* Don't initialize attribute type if mods_check() is going to be called */
if ( slap_str2ad( (*modp)->mod_type, &ad, &text ) != LDAP_SUCCESS ) if ( slap_str2ad( (*modp)->mod_type, &ad, &text ) != LDAP_SUCCESS )
continue; continue;