Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
List overview
Download
389-commits
May 2014
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
389-commits@lists.fedoraproject.org
4 participants
64 discussions
Start a n
N
ew thread
ldap/servers
by Mark Reynolds
08 May '14
08 May '14
ldap/servers/plugins/memberof/memberof.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) New commits: commit 6816e1155b28fb65fe294099336c4acbbac8ad77 Author: Mark Reynolds <mreynolds(a)redhat.com> Date: Thu May 8 15:10:52 2014 -0400 Ticket 47793 - Server crashes if uniqueMember is invalid syntax and memberOf plugin is enabled. Bug Description: MemberOf assumes the DN value has the correct syntax, and does not check the normalized value of that DN. This leads to dereferencing a NULL pointer and crash. Fix Description: Check the normalized value, and log a proper error.
https://fedorahosted.org/389/ticket/47793
Reviewed by: nhosoi(Thanks!) diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c index f377105..1073b8e 100644 --- a/ldap/servers/plugins/memberof/memberof.c +++ b/ldap/servers/plugins/memberof/memberof.c @@ -1309,20 +1309,31 @@ memberof_modop_one_replace_r(Slapi_PBlock *pb, MemberOfConfig *config, char *op_str = 0; const char *op_to; const char *op_this; - Slapi_Value *to_dn_val; - Slapi_Value *this_dn_val; + Slapi_Value *to_dn_val = NULL; + Slapi_Value *this_dn_val = NULL; op_to = slapi_sdn_get_ndn(op_to_sdn); op_this = slapi_sdn_get_ndn(op_this_sdn); - to_dn_val = slapi_value_new_string(op_to); - this_dn_val = slapi_value_new_string(op_this); - if(this_dn_val == NULL || to_dn_val == NULL){ + /* Make sure we have valid DN's for the group(op_this) and the new member(op_to) */ + if(op_to && op_this){ + to_dn_val = slapi_value_new_string(op_to); + this_dn_val = slapi_value_new_string(op_this); + } + if(to_dn_val == NULL){ + const char *udn = op_to_sdn ? slapi_sdn_get_udn(op_to_sdn) : ""; slapi_log_error( SLAPI_LOG_FATAL, MEMBEROF_PLUGIN_SUBSYSTEM, - "memberof_modop_one_replace_r: failed to get DN values (NULL)\n"); + "memberof_modop_one_replace_r: failed to get DN value from " + "member value (%s)\n", udn); + goto bail; + } + if(this_dn_val == NULL){ + const char *udn = op_this_sdn ? slapi_sdn_get_udn(op_this_sdn) : ""; + slapi_log_error( SLAPI_LOG_FATAL, MEMBEROF_PLUGIN_SUBSYSTEM, + "memberof_modop_one_replace_r: failed to get DN value from" + "group (%s)\n", udn); goto bail; } - /* op_this and op_to are both case-normalized */ slapi_value_set_flags(this_dn_val, SLAPI_ATTR_FLAG_NORMALIZED_CIS); slapi_value_set_flags(to_dn_val, SLAPI_ATTR_FLAG_NORMALIZED_CIS);
1
0
0
0
Branch '389-ds-base-1.3.1' - ldap/servers
by Mark Reynolds
07 May '14
07 May '14
ldap/servers/plugins/chainingdb/cb_add.c | 76 ++++++++++++---------- ldap/servers/plugins/chainingdb/cb_close.c | 67 +++++++++++--------- ldap/servers/plugins/chainingdb/cb_delete.c | 58 +++++++++-------- ldap/servers/plugins/chainingdb/cb_modify.c | 60 +++++++++--------- ldap/servers/plugins/chainingdb/cb_modrdn.c | 61 +++++++++--------- ldap/servers/plugins/chainingdb/cb_search.c | 44 ++++--------- ldap/servers/slapd/plugin.c | 93 ++++++++++++++++++++++++++++ ldap/servers/slapd/slapi-plugin.h | 6 + ldap/servers/slapd/slapi-private.h | 34 ++++++++++ 9 files changed, 323 insertions(+), 176 deletions(-) New commits: commit ba53b5761f37074454723e83c70e5ec0ebd6ab6f Author: Mark Reynolds <mreynolds(a)redhat.com> Date: Wed May 7 12:29:03 2014 -0400 Ticket 47792 - database plugins need a way to call betxn plugins Bug Description: Database plugins like "chaining" register their own add/mod/delete/modrdn functions. These new operation functions do not call the be/betxn plugins. Fix Description: Created two new private functions to call the pre & post be/betxn plugins. Added these functions to the chaining plugin. Maybe in the future these functions will be made public(slapi api). Also fixed a harmless startup/initialization memory leak.
https://fedorahosted.org/389/ticket/47792
Jenkins: passed. Valgrind: passed. Reviewed by: rmeggins & lkrispenz (Thanks!!) (cherry picked from commit 9929b439b766e807ad77285e3b3babb514dde897) (cherry picked from commit 8eeb738475f9df8e204cc98e7f777a78b4cebc0a) diff --git a/ldap/servers/plugins/chainingdb/cb_add.c b/ldap/servers/plugins/chainingdb/cb_add.c index 03d0fc9..3fd35df 100644 --- a/ldap/servers/plugins/chainingdb/cb_add.c +++ b/ldap/servers/plugins/chainingdb/cb_add.c @@ -142,8 +142,18 @@ chaining_back_add ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); ldap_mods_free(mods,1); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); + return -1; + } + + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_mods_free(mods,1); + ldap_controls_free(ctrls); return -1; } @@ -154,8 +164,7 @@ chaining_back_add ( Slapi_PBlock *pb ) /* Send LDAP operation to the remote host */ rc = ldap_add_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, @@ -171,7 +180,6 @@ chaining_back_add ( Slapi_PBlock *pb ) * Poll the server for the results of the add operation. * Check for abandoned operation regularly. */ - while ( 1 ) { if (cb_check_forward_abandon(cb,pb,ld,msgid)) { @@ -186,11 +194,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; - case 0: + case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { /* * does not respond. give up and return a @@ -202,14 +209,14 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD DS_Sleep(PR_INTERVAL_NO_WAIT); #endif break; + default: serverctrls=NULL; matched_msg=error_msg=NULL; @@ -231,13 +238,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -255,36 +259,40 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } + /* Success */ ldap_mods_free(mods,1 ); cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); if (serverctrls) ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); - cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); - slapi_entry_free(e); - slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); - - return 0; + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); + cb_send_ldap_result( pb, rc, NULL, NULL, 0, NULL ); + if(rc == LDAP_SUCCESS){ + slapi_entry_free(e); + slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); + return 0; + } else { + return -1; + } } } /* Never reached */ diff --git a/ldap/servers/plugins/chainingdb/cb_close.c b/ldap/servers/plugins/chainingdb/cb_close.c index ecac585..5d812a0 100644 --- a/ldap/servers/plugins/chainingdb/cb_close.c +++ b/ldap/servers/plugins/chainingdb/cb_close.c @@ -47,34 +47,45 @@ ** Should be followed by a cleanup */ -int cb_back_close( Slapi_PBlock *pb ) +static void +free_cb_backend(cb_backend *cb) { - Slapi_Backend * be; - cb_backend_instance * inst; - int rc; - - slapi_pblock_get( pb, SLAPI_BACKEND, &be ); - if (be == NULL) { - - cb_backend * cb = cb_get_backend_type(); - CB_ASSERT(cb!=NULL); - - slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_modify_callback); - slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_modify_check_callback); - - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_add_callback); - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_add_check_callback); + if(cb){ + slapi_destroy_rwlock(cb->config.rwl_config_lock); + slapi_ch_free_string(&cb->pluginDN); + slapi_ch_free_string(&cb->configDN); + slapi_ch_array_free(cb->config.chainable_components); + slapi_ch_array_free(cb->config.chaining_components); + slapi_ch_array_free(cb->config.forward_ctrls); + slapi_ch_free((void **)&cb); + } +} - slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_search_callback); +int cb_back_close( Slapi_PBlock *pb ) +{ + Slapi_Backend *be; + cb_backend_instance *inst; + cb_backend *cb = cb_get_backend_type(); + int rc; - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->pluginDN, - LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_callback); + CB_ASSERT(cb != NULL); + slapi_pblock_get( pb, SLAPI_BACKEND, &be ); + if (be == NULL) { + slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_modify_callback); + slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_modify_check_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_add_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_add_check_callback); + slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_search_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->pluginDN, + LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_callback); + + free_cb_backend(cb); return 0; } @@ -84,15 +95,15 @@ int cb_back_close( Slapi_PBlock *pb ) { const char * betype = slapi_be_gettype(be); if (!betype || strcasecmp(betype,CB_CHAINING_BACKEND_TYPE)) { - - slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "Wrong database type.\n"); return 0; } } inst = cb_get_instance(be); - CB_ASSERT( inst!=NULL ); + CB_ASSERT( inst != NULL ); + free_cb_backend(cb); slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,"Stopping chaining database instance %s\n", inst->configDn); @@ -100,5 +111,5 @@ int cb_back_close( Slapi_PBlock *pb ) /* to clean up everything */ cb_instance_delete_config_callback(NULL, NULL,NULL, &rc, NULL, inst); - return 0; + return 0; } diff --git a/ldap/servers/plugins/chainingdb/cb_delete.c b/ldap/servers/plugins/chainingdb/cb_delete.c index 97807ef..1538589 100644 --- a/ldap/servers/plugins/chainingdb/cb_delete.c +++ b/ldap/servers/plugins/chainingdb/cb_delete.c @@ -137,7 +137,6 @@ chaining_back_delete ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -147,12 +146,20 @@ chaining_back_delete ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* - * Send LDAP operation to the remote host + * Call the backend preoperation plugins */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* + * Send LDAP operation to the remote host + */ rc = ldap_delete_ext( ld, dn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -171,8 +178,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -182,8 +188,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,"FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -207,13 +212,10 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -230,29 +232,29 @@ chaining_back_delete ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modify.c b/ldap/servers/plugins/chainingdb/cb_modify.c index 12d36da..db8a43c 100644 --- a/ldap/servers/plugins/chainingdb/cb_modify.c +++ b/ldap/servers/plugins/chainingdb/cb_modify.c @@ -106,7 +106,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -141,8 +141,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); /* Don't free mods here: are freed at the do_modify level */ - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return -1; } @@ -153,10 +152,19 @@ chaining_back_modify ( Slapi_PBlock *pb ) if (cb->max_idle_time>0) endtime=current_time() + cb->max_idle_time; + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* Send LDAP operation to the remote host */ rc = ldap_modify_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -176,8 +184,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -187,8 +194,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -214,13 +220,10 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -237,31 +240,30 @@ chaining_back_modify ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) + charray_free(referrals); ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); /* SLAPI_ADD_RESCONTROL dups controls */ - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modrdn.c b/ldap/servers/plugins/chainingdb/cb_modrdn.c index 21903f7..b84fe57 100644 --- a/ldap/servers/plugins/chainingdb/cb_modrdn.c +++ b/ldap/servers/plugins/chainingdb/cb_modrdn.c @@ -109,7 +109,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -147,7 +147,6 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -157,13 +156,22 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): pre betxn failed, error (%d)\n",ndn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + + /* * Send LDAP operation to the remote host */ rc = ldap_rename ( ld, ndn, newrdn, slapi_sdn_get_dn(newsuperior), deleteoldrdn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -182,8 +190,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: @@ -192,10 +199,9 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL);*/ - cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); + cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -221,13 +227,10 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -244,29 +247,29 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): post betxn failed, error (%d)\n",ndn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i]; i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_search.c b/ldap/servers/plugins/chainingdb/cb_search.c index faca2e3..9aecd26 100644 --- a/ldap/servers/plugins/chainingdb/cb_search.c +++ b/ldap/servers/plugins/chainingdb/cb_search.c @@ -242,8 +242,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return 1; } @@ -272,8 +271,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = ldap_search_ext(ld ,target,scope,filter,attrs,attrsonly, ctrls, NULL, &timeout,sizelimit, &(ctx->msgid) ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( LDAP_SUCCESS != rc ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -307,8 +305,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,rc, NULL, NULL,0,NULL); } cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; @@ -322,8 +319,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) NULL,NULL, 0, NULL); /* Force connection close */ cb_release_op_connection(cb->pool,ld,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -333,8 +329,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -391,12 +386,10 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = -1; } - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); if (rc != LDAP_SUCCESS) { cb_release_op_connection(cb->pool,ld, CB_LDAP_CONN_ERROR(rc)); @@ -547,8 +540,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) if (cb_check_forward_abandon(cb,pb,ctx->ld,ctx->msgid)) { /* cnx handle released */ - if (ctx->pending_result) - ldap_msgfree(ctx->pending_result); + ldap_msgfree(ctx->pending_result); slapi_ch_free((void **) &ctx); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,NULL ); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY,NULL); @@ -589,8 +581,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string( rc ), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -604,8 +595,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -751,12 +741,10 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) retcode=0; } - if (serverctrls) - ldap_controls_free(serverctrls); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_release_op_connection(cb->pool,ctx->ld,0); slapi_ch_free((void **)&ctx); diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index 1ca4dc5..eadc761 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -3228,3 +3228,96 @@ slapi_set_plugin_open_rootdn_bind(Slapi_PBlock *pb){ ptd_set_special_data(&(config->plgc_bind_subtrees), PLGC_DATA_BIND_ROOT); } + +/* + * Allow "database" plugins to call the backend/backend txn plugins. + */ +int +slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_PRE_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_preop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* + * Call the be preop plugins. + */ + plugin_call_plugins(pb, be_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* + * Call the betxn preop plugins. + */ + if (rc == LDAP_SUCCESS) { + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} + +int +slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_POST_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_POST_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_postop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* next, give the be txn plugins a crack at it */; + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* finally, give the be plugins a crack at it */ + plugin_call_plugins(pb, be_func); + if (rc == LDAP_SUCCESS) { + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index c021685..8a7640e 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -7013,6 +7013,12 @@ typedef struct slapi_plugindesc { corresponds to pb_search_ctrls */ #define SLAPI_SEARCH_CTRLS 198 +/* plugin be/betxn operations */ +#define SLAPI_PLUGIN_ADD_OP 199 +#define SLAPI_PLUGIN_MOD_OP 200 +#define SLAPI_PLUGIN_MODRDN_OP 201 +#define SLAPI_PLUGIN_DEL_OP 202 + #define SLAPI_RESULT_CODE 881 #define SLAPI_RESULT_TEXT 882 #define SLAPI_RESULT_MATCHED 883 diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h index 51329ba..5fa172a 100644 --- a/ldap/servers/slapd/slapi-private.h +++ b/ldap/servers/slapd/slapi-private.h @@ -1262,6 +1262,40 @@ void DS_Sleep(PRIntervalTime ticks); /* plugin.c */ int plugin_enabled(const char *plugin_name, void *identity); +/** + * For "database" plugins that need to call preoperation backend & backend txn plugins. + * This function should be called right before the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int operation); + +/** + * For "database" plugins that need to call postoperation backend & backend txn plugins. + * This function should be called right after the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int operation); + /* protect_db.c */ /* is_slapd_running() * returns 1 if slapd is running, 0 if not, -1 on error
1
0
0
0
Branch '389-ds-base-1.3.2' - ldap/servers
by Mark Reynolds
07 May '14
07 May '14
ldap/servers/plugins/chainingdb/cb_add.c | 76 ++++++++++++---------- ldap/servers/plugins/chainingdb/cb_close.c | 67 +++++++++++--------- ldap/servers/plugins/chainingdb/cb_delete.c | 58 +++++++++-------- ldap/servers/plugins/chainingdb/cb_modify.c | 60 +++++++++--------- ldap/servers/plugins/chainingdb/cb_modrdn.c | 61 +++++++++--------- ldap/servers/plugins/chainingdb/cb_search.c | 44 ++++--------- ldap/servers/slapd/plugin.c | 93 ++++++++++++++++++++++++++++ ldap/servers/slapd/slapi-plugin.h | 6 + ldap/servers/slapd/slapi-private.h | 34 ++++++++++ 9 files changed, 323 insertions(+), 176 deletions(-) New commits: commit 8eeb738475f9df8e204cc98e7f777a78b4cebc0a Author: Mark Reynolds <mreynolds(a)redhat.com> Date: Wed May 7 12:29:03 2014 -0400 Ticket 47792 - database plugins need a way to call betxn plugins Bug Description: Database plugins like "chaining" register their own add/mod/delete/modrdn functions. These new operation functions do not call the be/betxn plugins. Fix Description: Created two new private functions to call the pre & post be/betxn plugins. Added these functions to the chaining plugin. Maybe in the future these functions will be made public(slapi api). Also fixed a harmless startup/initialization memory leak.
https://fedorahosted.org/389/ticket/47792
Jenkins: passed. Valgrind: passed. Reviewed by: rmeggins & lkrispenz (Thanks!!) (cherry picked from commit 9929b439b766e807ad77285e3b3babb514dde897) diff --git a/ldap/servers/plugins/chainingdb/cb_add.c b/ldap/servers/plugins/chainingdb/cb_add.c index 03d0fc9..3fd35df 100644 --- a/ldap/servers/plugins/chainingdb/cb_add.c +++ b/ldap/servers/plugins/chainingdb/cb_add.c @@ -142,8 +142,18 @@ chaining_back_add ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); ldap_mods_free(mods,1); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); + return -1; + } + + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_mods_free(mods,1); + ldap_controls_free(ctrls); return -1; } @@ -154,8 +164,7 @@ chaining_back_add ( Slapi_PBlock *pb ) /* Send LDAP operation to the remote host */ rc = ldap_add_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, @@ -171,7 +180,6 @@ chaining_back_add ( Slapi_PBlock *pb ) * Poll the server for the results of the add operation. * Check for abandoned operation regularly. */ - while ( 1 ) { if (cb_check_forward_abandon(cb,pb,ld,msgid)) { @@ -186,11 +194,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; - case 0: + case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { /* * does not respond. give up and return a @@ -202,14 +209,14 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD DS_Sleep(PR_INTERVAL_NO_WAIT); #endif break; + default: serverctrls=NULL; matched_msg=error_msg=NULL; @@ -231,13 +238,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -255,36 +259,40 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } + /* Success */ ldap_mods_free(mods,1 ); cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); if (serverctrls) ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); - cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); - slapi_entry_free(e); - slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); - - return 0; + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); + cb_send_ldap_result( pb, rc, NULL, NULL, 0, NULL ); + if(rc == LDAP_SUCCESS){ + slapi_entry_free(e); + slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); + return 0; + } else { + return -1; + } } } /* Never reached */ diff --git a/ldap/servers/plugins/chainingdb/cb_close.c b/ldap/servers/plugins/chainingdb/cb_close.c index ecac585..5d812a0 100644 --- a/ldap/servers/plugins/chainingdb/cb_close.c +++ b/ldap/servers/plugins/chainingdb/cb_close.c @@ -47,34 +47,45 @@ ** Should be followed by a cleanup */ -int cb_back_close( Slapi_PBlock *pb ) +static void +free_cb_backend(cb_backend *cb) { - Slapi_Backend * be; - cb_backend_instance * inst; - int rc; - - slapi_pblock_get( pb, SLAPI_BACKEND, &be ); - if (be == NULL) { - - cb_backend * cb = cb_get_backend_type(); - CB_ASSERT(cb!=NULL); - - slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_modify_callback); - slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_modify_check_callback); - - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_add_callback); - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_add_check_callback); + if(cb){ + slapi_destroy_rwlock(cb->config.rwl_config_lock); + slapi_ch_free_string(&cb->pluginDN); + slapi_ch_free_string(&cb->configDN); + slapi_ch_array_free(cb->config.chainable_components); + slapi_ch_array_free(cb->config.chaining_components); + slapi_ch_array_free(cb->config.forward_ctrls); + slapi_ch_free((void **)&cb); + } +} - slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, - "(objectclass=*)",cb_config_search_callback); +int cb_back_close( Slapi_PBlock *pb ) +{ + Slapi_Backend *be; + cb_backend_instance *inst; + cb_backend *cb = cb_get_backend_type(); + int rc; - slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->pluginDN, - LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_callback); + CB_ASSERT(cb != NULL); + slapi_pblock_get( pb, SLAPI_BACKEND, &be ); + if (be == NULL) { + slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_modify_callback); + slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_modify_check_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_add_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_add_check_callback); + slapi_config_remove_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, cb->configDN, LDAP_SCOPE_BASE, + "(objectclass=*)",cb_config_search_callback); + slapi_config_remove_callback(SLAPI_OPERATION_ADD, DSE_FLAG_POSTOP, cb->pluginDN, + LDAP_SCOPE_SUBTREE, CB_CONFIG_INSTANCE_FILTER, cb_config_add_instance_callback); + + free_cb_backend(cb); return 0; } @@ -84,15 +95,15 @@ int cb_back_close( Slapi_PBlock *pb ) { const char * betype = slapi_be_gettype(be); if (!betype || strcasecmp(betype,CB_CHAINING_BACKEND_TYPE)) { - - slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "Wrong database type.\n"); return 0; } } inst = cb_get_instance(be); - CB_ASSERT( inst!=NULL ); + CB_ASSERT( inst != NULL ); + free_cb_backend(cb); slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,"Stopping chaining database instance %s\n", inst->configDn); @@ -100,5 +111,5 @@ int cb_back_close( Slapi_PBlock *pb ) /* to clean up everything */ cb_instance_delete_config_callback(NULL, NULL,NULL, &rc, NULL, inst); - return 0; + return 0; } diff --git a/ldap/servers/plugins/chainingdb/cb_delete.c b/ldap/servers/plugins/chainingdb/cb_delete.c index 97807ef..1538589 100644 --- a/ldap/servers/plugins/chainingdb/cb_delete.c +++ b/ldap/servers/plugins/chainingdb/cb_delete.c @@ -137,7 +137,6 @@ chaining_back_delete ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -147,12 +146,20 @@ chaining_back_delete ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* - * Send LDAP operation to the remote host + * Call the backend preoperation plugins */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* + * Send LDAP operation to the remote host + */ rc = ldap_delete_ext( ld, dn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -171,8 +178,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -182,8 +188,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,"FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -207,13 +212,10 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -230,29 +232,29 @@ chaining_back_delete ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modify.c b/ldap/servers/plugins/chainingdb/cb_modify.c index 12d36da..db8a43c 100644 --- a/ldap/servers/plugins/chainingdb/cb_modify.c +++ b/ldap/servers/plugins/chainingdb/cb_modify.c @@ -106,7 +106,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -141,8 +141,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); /* Don't free mods here: are freed at the do_modify level */ - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return -1; } @@ -153,10 +152,19 @@ chaining_back_modify ( Slapi_PBlock *pb ) if (cb->max_idle_time>0) endtime=current_time() + cb->max_idle_time; + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* Send LDAP operation to the remote host */ rc = ldap_modify_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -176,8 +184,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -187,8 +194,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -214,13 +220,10 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -237,31 +240,30 @@ chaining_back_modify ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) + charray_free(referrals); ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); /* SLAPI_ADD_RESCONTROL dups controls */ - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modrdn.c b/ldap/servers/plugins/chainingdb/cb_modrdn.c index 21903f7..b84fe57 100644 --- a/ldap/servers/plugins/chainingdb/cb_modrdn.c +++ b/ldap/servers/plugins/chainingdb/cb_modrdn.c @@ -109,7 +109,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -147,7 +147,6 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -157,13 +156,22 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): pre betxn failed, error (%d)\n",ndn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + + /* * Send LDAP operation to the remote host */ rc = ldap_rename ( ld, ndn, newrdn, slapi_sdn_get_dn(newsuperior), deleteoldrdn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -182,8 +190,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: @@ -192,10 +199,9 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL);*/ - cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); + cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -221,13 +227,10 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -244,29 +247,29 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): post betxn failed, error (%d)\n",ndn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i]; i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_search.c b/ldap/servers/plugins/chainingdb/cb_search.c index faca2e3..9aecd26 100644 --- a/ldap/servers/plugins/chainingdb/cb_search.c +++ b/ldap/servers/plugins/chainingdb/cb_search.c @@ -242,8 +242,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return 1; } @@ -272,8 +271,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = ldap_search_ext(ld ,target,scope,filter,attrs,attrsonly, ctrls, NULL, &timeout,sizelimit, &(ctx->msgid) ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( LDAP_SUCCESS != rc ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -307,8 +305,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,rc, NULL, NULL,0,NULL); } cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; @@ -322,8 +319,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) NULL,NULL, 0, NULL); /* Force connection close */ cb_release_op_connection(cb->pool,ld,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -333,8 +329,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -391,12 +386,10 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = -1; } - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); if (rc != LDAP_SUCCESS) { cb_release_op_connection(cb->pool,ld, CB_LDAP_CONN_ERROR(rc)); @@ -547,8 +540,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) if (cb_check_forward_abandon(cb,pb,ctx->ld,ctx->msgid)) { /* cnx handle released */ - if (ctx->pending_result) - ldap_msgfree(ctx->pending_result); + ldap_msgfree(ctx->pending_result); slapi_ch_free((void **) &ctx); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,NULL ); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY,NULL); @@ -589,8 +581,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string( rc ), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -604,8 +595,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -751,12 +741,10 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) retcode=0; } - if (serverctrls) - ldap_controls_free(serverctrls); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_release_op_connection(cb->pool,ctx->ld,0); slapi_ch_free((void **)&ctx); diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index b13ecbb..962276d 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -3275,3 +3275,96 @@ slapi_disordely_shutdown(PRBool set) } return (is_disordely_shutdown); } + +/* + * Allow "database" plugins to call the backend/backend txn plugins. + */ +int +slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_PRE_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_preop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* + * Call the be preop plugins. + */ + plugin_call_plugins(pb, be_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* + * Call the betxn preop plugins. + */ + if (rc == LDAP_SUCCESS) { + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} + +int +slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_POST_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_POST_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_postop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* next, give the be txn plugins a crack at it */; + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* finally, give the be plugins a crack at it */ + plugin_call_plugins(pb, be_func); + if (rc == LDAP_SUCCESS) { + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index 28e6b97..596d4db 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -7172,6 +7172,12 @@ typedef struct slapi_plugindesc { corresponds to pb_search_ctrls */ #define SLAPI_SEARCH_CTRLS 198 +/* plugin be/betxn operations */ +#define SLAPI_PLUGIN_ADD_OP 199 +#define SLAPI_PLUGIN_MOD_OP 200 +#define SLAPI_PLUGIN_MODRDN_OP 201 +#define SLAPI_PLUGIN_DEL_OP 202 + #define SLAPI_RESULT_CODE 881 #define SLAPI_RESULT_TEXT 882 #define SLAPI_RESULT_MATCHED 883 diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h index 47c4557..0094bea 100644 --- a/ldap/servers/slapd/slapi-private.h +++ b/ldap/servers/slapd/slapi-private.h @@ -1262,6 +1262,40 @@ void DS_Sleep(PRIntervalTime ticks); /* plugin.c */ int plugin_enabled(const char *plugin_name, void *identity); +/** + * For "database" plugins that need to call preoperation backend & backend txn plugins. + * This function should be called right before the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int operation); + +/** + * For "database" plugins that need to call postoperation backend & backend txn plugins. + * This function should be called right after the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int operation); + /* protect_db.c */ /* is_slapd_running() * returns 1 if slapd is running, 0 if not, -1 on error
1
0
0
0
ldap/servers
by Mark Reynolds
07 May '14
07 May '14
ldap/servers/plugins/chainingdb/cb_add.c | 76 ++++++++++++---------- ldap/servers/plugins/chainingdb/cb_close.c | 4 - ldap/servers/plugins/chainingdb/cb_delete.c | 58 +++++++++-------- ldap/servers/plugins/chainingdb/cb_modify.c | 60 +++++++++--------- ldap/servers/plugins/chainingdb/cb_modrdn.c | 61 +++++++++--------- ldap/servers/plugins/chainingdb/cb_search.c | 44 ++++--------- ldap/servers/slapd/plugin.c | 93 ++++++++++++++++++++++++++++ ldap/servers/slapd/slapi-plugin.h | 6 + ldap/servers/slapd/slapi-private.h | 34 ++++++++++ 9 files changed, 286 insertions(+), 150 deletions(-) New commits: commit 9929b439b766e807ad77285e3b3babb514dde897 Author: Mark Reynolds <mreynolds(a)redhat.com> Date: Wed May 7 12:29:03 2014 -0400 Ticket 47792 - database plugins need a way to call betxn plugins Bug Description: Database plugins like "chaining" register their own add/mod/delete/modrdn functions. These new operation functions do not call the be/betxn plugins. Fix Description: Created two new private functions to call the pre & post be/betxn plugins. Added these functions to the chaining plugin. Maybe in the future these functions will be made public(slapi api). Also fixed a harmless startup/initialization memory leak.
https://fedorahosted.org/389/ticket/47792
Jenkins: passed. Valgrind: passed. Reviewed by: rmeggins & lkrispenz (Thanks!!) diff --git a/ldap/servers/plugins/chainingdb/cb_add.c b/ldap/servers/plugins/chainingdb/cb_add.c index 03d0fc9..3fd35df 100644 --- a/ldap/servers/plugins/chainingdb/cb_add.c +++ b/ldap/servers/plugins/chainingdb/cb_add.c @@ -142,8 +142,18 @@ chaining_back_add ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); ldap_mods_free(mods,1); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); + return -1; + } + + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_mods_free(mods,1); + ldap_controls_free(ctrls); return -1; } @@ -154,8 +164,7 @@ chaining_back_add ( Slapi_PBlock *pb ) /* Send LDAP operation to the remote host */ rc = ldap_add_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, @@ -171,7 +180,6 @@ chaining_back_add ( Slapi_PBlock *pb ) * Poll the server for the results of the add operation. * Check for abandoned operation regularly. */ - while ( 1 ) { if (cb_check_forward_abandon(cb,pb,ld,msgid)) { @@ -186,11 +194,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; - case 0: + case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { /* * does not respond. give up and return a @@ -202,14 +209,14 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD DS_Sleep(PR_INTERVAL_NO_WAIT); #endif break; + default: serverctrls=NULL; matched_msg=error_msg=NULL; @@ -231,13 +238,10 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -255,36 +259,40 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } + /* Success */ ldap_mods_free(mods,1 ); cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_ADD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "add (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); if (serverctrls) ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); - cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); - slapi_entry_free(e); - slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); - - return 0; + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); + cb_send_ldap_result( pb, rc, NULL, NULL, 0, NULL ); + if(rc == LDAP_SUCCESS){ + slapi_entry_free(e); + slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); + return 0; + } else { + return -1; + } } } /* Never reached */ diff --git a/ldap/servers/plugins/chainingdb/cb_close.c b/ldap/servers/plugins/chainingdb/cb_close.c index e3b6726..71cf135 100644 --- a/ldap/servers/plugins/chainingdb/cb_close.c +++ b/ldap/servers/plugins/chainingdb/cb_close.c @@ -56,6 +56,7 @@ free_cb_backend(cb_backend *cb) slapi_ch_free_string(&cb->pluginDN); slapi_ch_free_string(&cb->configDN); slapi_ch_array_free(cb->config.chainable_components); + slapi_ch_array_free(cb->config.chaining_components); slapi_ch_array_free(cb->config.forward_ctrls); slapi_ch_free((void **)&cb); } @@ -68,8 +69,6 @@ int cb_back_close( Slapi_PBlock *pb ) cb_backend *cb = cb_get_backend_type(); int rc; - - slapi_pblock_get( pb, SLAPI_BACKEND, &be ); if (be == NULL) { @@ -103,6 +102,7 @@ int cb_back_close( Slapi_PBlock *pb ) const char *betype = slapi_be_gettype(be); if (!betype || strcasecmp(betype,CB_CHAINING_BACKEND_TYPE)) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "Wrong database type.\n"); + free_cb_backend(cb); return 0; } } diff --git a/ldap/servers/plugins/chainingdb/cb_delete.c b/ldap/servers/plugins/chainingdb/cb_delete.c index 97807ef..1538589 100644 --- a/ldap/servers/plugins/chainingdb/cb_delete.c +++ b/ldap/servers/plugins/chainingdb/cb_delete.c @@ -137,7 +137,6 @@ chaining_back_delete ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -147,12 +146,20 @@ chaining_back_delete ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* - * Send LDAP operation to the remote host + * Call the backend preoperation plugins */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* + * Send LDAP operation to the remote host + */ rc = ldap_delete_ext( ld, dn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -171,8 +178,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -182,8 +188,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL,"FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -207,13 +212,10 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -230,29 +232,29 @@ chaining_back_delete ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_DEL_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "delete (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modify.c b/ldap/servers/plugins/chainingdb/cb_modify.c index 12d36da..db8a43c 100644 --- a/ldap/servers/plugins/chainingdb/cb_modify.c +++ b/ldap/servers/plugins/chainingdb/cb_modify.c @@ -106,7 +106,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -141,8 +141,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); /* Don't free mods here: are freed at the do_modify level */ - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return -1; } @@ -153,10 +152,19 @@ chaining_back_modify ( Slapi_PBlock *pb ) if (cb->max_idle_time>0) endtime=current_time() + cb->max_idle_time; + /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): pre betxn failed, error (%d)\n",dn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + /* Send LDAP operation to the remote host */ rc = ldap_modify_ext( ld, dn, mods, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -176,8 +184,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { @@ -187,8 +194,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) ldap_err2string(rc), 0, NULL);*/ cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -214,13 +220,10 @@ chaining_back_modify ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -237,31 +240,30 @@ chaining_back_modify ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) + charray_free(referrals); ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); - /* Add control response sent by the farm server */ + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MOD_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modify (%s): post betxn failed, error (%d)\n",dn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i];i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); /* SLAPI_ADD_RESCONTROL dups controls */ - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_modrdn.c b/ldap/servers/plugins/chainingdb/cb_modrdn.c index 21903f7..b84fe57 100644 --- a/ldap/servers/plugins/chainingdb/cb_modrdn.c +++ b/ldap/servers/plugins/chainingdb/cb_modrdn.c @@ -109,7 +109,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, errbuf, 0, NULL ); - slapi_ch_free((void **)&errbuf); + slapi_ch_free_string(&errbuf); return -1; } } @@ -147,7 +147,6 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) ldap_controls_free(ctrls); return -1; } @@ -157,13 +156,22 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) endtime=current_time() + cb->max_idle_time; /* + * Call the backend preoperation plugins + */ + if((rc = slapi_plugin_call_preop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): pre betxn failed, error (%d)\n",ndn,rc); + cb_release_op_connection(cb->pool,ld,0); + ldap_controls_free(ctrls); + return -1; + } + + /* * Send LDAP operation to the remote host */ rc = ldap_rename ( ld, ndn, newrdn, slapi_sdn_get_dn(newsuperior), deleteoldrdn, ctrls, NULL, &msgid ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( rc != LDAP_SUCCESS ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -182,8 +190,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; case 0: @@ -192,10 +199,9 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL);*/ - cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); + cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, "FARM SERVER TEMPORARY UNAVAILABLE", 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); return -1; } #ifdef CB_YIELD @@ -221,13 +227,10 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(parse_rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free referrals */ - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); return -1; } @@ -244,29 +247,29 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); if (refs) ber_bvecfree(refs); - if (referrals) - charray_free(referrals); - if (serverctrls) - ldap_controls_free(serverctrls); + charray_free(referrals); + ldap_controls_free(serverctrls); return -1; } cb_release_op_connection(cb->pool,ld,0); + /* Call the backend postoperation plugins */ + if((rc = slapi_plugin_call_postop_be_plugins(pb, SLAPI_PLUGIN_MODRDN_OP))){ + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, "modrdn (%s): post betxn failed, error (%d)\n",ndn,rc); + } + /* Add control response sent by the farm server */ for (i=0; serverctrls && serverctrls[i]; i++) slapi_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); - if (serverctrls) - ldap_controls_free(serverctrls); - /* jarnou: free matched_msg, error_msg, and referrals if necessary */ - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL ); return 0; diff --git a/ldap/servers/plugins/chainingdb/cb_search.c b/ldap/servers/plugins/chainingdb/cb_search.c index faca2e3..9aecd26 100644 --- a/ldap/servers/plugins/chainingdb/cb_search.c +++ b/ldap/servers/plugins/chainingdb/cb_search.c @@ -242,8 +242,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) if ( slapi_op_abandoned( pb )) { cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); return 1; } @@ -272,8 +271,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = ldap_search_ext(ld ,target,scope,filter,attrs,attrsonly, ctrls, NULL, &timeout,sizelimit, &(ctx->msgid) ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + ldap_controls_free(ctrls); if ( LDAP_SUCCESS != rc ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -307,8 +305,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,rc, NULL, NULL,0,NULL); } cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; @@ -322,8 +319,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) NULL,NULL, 0, NULL); /* Force connection close */ cb_release_op_connection(cb->pool,ld,1); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -333,8 +329,7 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); slapi_ch_free((void **)&ctx); return 1; } @@ -391,12 +386,10 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) rc = -1; } - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - if (referrals) - charray_free(referrals); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + ldap_controls_free(serverctrls); + charray_free(referrals); if (rc != LDAP_SUCCESS) { cb_release_op_connection(cb->pool,ld, CB_LDAP_CONN_ERROR(rc)); @@ -547,8 +540,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) if (cb_check_forward_abandon(cb,pb,ctx->ld,ctx->msgid)) { /* cnx handle released */ - if (ctx->pending_result) - ldap_msgfree(ctx->pending_result); + ldap_msgfree(ctx->pending_result); slapi_ch_free((void **) &ctx); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,NULL ); slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY,NULL); @@ -589,8 +581,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string( rc ), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -604,8 +595,7 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); - if (res) - ldap_msgfree(res); + ldap_msgfree(res); cb_release_op_connection(cb->pool,ctx->ld,CB_LDAP_CONN_ERROR(rc)); slapi_ch_free((void **)&ctx); return -1; @@ -751,12 +741,10 @@ chainingdb_next_search_entry ( Slapi_PBlock *pb ) retcode=0; } - if (serverctrls) - ldap_controls_free(serverctrls); - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (referrals) - charray_free(referrals); + ldap_controls_free(serverctrls); + slapi_ch_free_string(&matched_msg); + slapi_ch_free_string(&error_msg); + charray_free(referrals); cb_release_op_connection(cb->pool,ctx->ld,0); slapi_ch_free((void **)&ctx); diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c index 4337db7..dde3ce5 100644 --- a/ldap/servers/slapd/plugin.c +++ b/ldap/servers/slapd/plugin.c @@ -4399,3 +4399,96 @@ slapi_plugin_running(Slapi_PBlock *pb) return rc; } + +/* + * Allow "database" plugins to call the backend/backend txn plugins. + */ +int +slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_PRE_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_PRE_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_preop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* + * Call the be preop plugins. + */ + plugin_call_plugins(pb, be_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* + * Call the betxn preop plugins. + */ + if (rc == LDAP_SUCCESS) { + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} + +int +slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int function) +{ + int be_func, betxn_func; + int rc = 0; + + switch(function){ + case SLAPI_PLUGIN_ADD_OP: + be_func = SLAPI_PLUGIN_BE_POST_ADD_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN; + break; + case SLAPI_PLUGIN_MOD_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODIFY_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN; + break; + case SLAPI_PLUGIN_MODRDN_OP: + be_func = SLAPI_PLUGIN_BE_POST_MODRDN_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN; + break; + case SLAPI_PLUGIN_DEL_OP: + be_func = SLAPI_PLUGIN_BE_POST_DELETE_FN; + betxn_func = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN; + break; + default: + /* invalid function */ + slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_postop_betxn_plugins", + "Invalid function specified - backend plugins will not be called.\n"); + return 0; + } + + /* next, give the be txn plugins a crack at it */; + plugin_call_plugins(pb, betxn_func); + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + + /* finally, give the be plugins a crack at it */ + plugin_call_plugins(pb, be_func); + if (rc == LDAP_SUCCESS) { + slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc); + } + + return rc; +} diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index 6b4d80e..c5a8dd3 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -7231,6 +7231,12 @@ typedef struct slapi_plugindesc { corresponds to pb_search_ctrls */ #define SLAPI_SEARCH_CTRLS 198 +/* plugin be/betxn operations */ +#define SLAPI_PLUGIN_ADD_OP 199 +#define SLAPI_PLUGIN_MOD_OP 200 +#define SLAPI_PLUGIN_MODRDN_OP 201 +#define SLAPI_PLUGIN_DEL_OP 202 + #define SLAPI_RESULT_CODE 881 #define SLAPI_RESULT_TEXT 882 #define SLAPI_RESULT_MATCHED 883 diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h index 3443425..5c374f6 100644 --- a/ldap/servers/slapd/slapi-private.h +++ b/ldap/servers/slapd/slapi-private.h @@ -1267,6 +1267,40 @@ void DS_Sleep(PRIntervalTime ticks); /* plugin.c */ int plugin_enabled(const char *plugin_name, void *identity); +/** + * For "database" plugins that need to call preoperation backend & backend txn plugins. + * This function should be called right before the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int operation); + +/** + * For "database" plugins that need to call postoperation backend & backend txn plugins. + * This function should be called right after the operation is performed. + * + * \param Slapi_PBLock object + * \param int operation + * + * Operations: + * SLAPI_PLUGIN_ADD_OP + * SLAPI_PLUGIN_MOD_OP + * SLAPI_PLUGIN_MODRDN_OP + * SLAPI_PLUGIN_DEL_OP + * + * \return zero on success, non-zero for failure + */ +int slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int operation); + /* protect_db.c */ /* is_slapd_running() * returns 1 if slapd is running, 0 if not, -1 on error
1
0
0
0
← Newer
1
2
3
4
5
6
7
Older →
Jump to page:
1
2
3
4
5
6
7
Results per page:
10
25
50
100
200