From: Howard Chu Date: Mon, 15 Sep 2014 18:18:30 +0000 (+0100) Subject: Consolidate LDAP_TXN precheck X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=09137b6646aeb85d3d3ac58278ff7565211956b0;p=openldap Consolidate LDAP_TXN precheck This commit was accidentally omitted from previous push --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 54fce68498..03f415b494 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -45,49 +45,12 @@ bdb_add(Operation *op, SlapReply *rs ) LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS]; int num_ctrls = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug(LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_add) ": %s\n", op->ora_e->e_name.bv_val, 0, 0); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = 0; diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index d361de479a..a88e03c406 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -51,49 +51,12 @@ bdb_delete( Operation *op, SlapReply *rs ) int parent_is_glue = 0; int parent_is_leaf = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_delete) ": %s\n", op->o_req_dn.bv_val, 0, 0 ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = 0; diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 3a81d90217..540280ab5b 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -466,49 +466,12 @@ bdb_modify( Operation *op, SlapReply *rs ) int rc; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(bdb_modify) ": %s\n", op->o_req_dn.bv_val, 0, 0 ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = NULL; diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 2103591d21..42f5669483 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -60,50 +60,13 @@ bdb_modrdn( Operation *op, SlapReply *rs ) int parent_is_glue = 0; int parent_is_leaf = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn) "(%s,%s,%s)\n", op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = NULL; diff --git a/servers/slapd/back-mdb/add.c b/servers/slapd/back-mdb/add.c index b92e922ec7..36b76453d9 100644 --- a/servers/slapd/back-mdb/add.c +++ b/servers/slapd/back-mdb/add.c @@ -44,49 +44,12 @@ mdb_add(Operation *op, SlapReply *rs ) LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS]; int num_ctrls = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug(LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(mdb_add) ": %s\n", op->ora_e->e_name.bv_val, 0, 0); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = 0; diff --git a/servers/slapd/back-mdb/delete.c b/servers/slapd/back-mdb/delete.c index 9002fba056..77717aeb6c 100644 --- a/servers/slapd/back-mdb/delete.c +++ b/servers/slapd/back-mdb/delete.c @@ -43,49 +43,12 @@ mdb_delete( Operation *op, SlapReply *rs ) int parent_is_glue = 0; int parent_is_leaf = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(mdb_delete) ": %s\n", op->o_req_dn.bv_val, 0, 0 ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = 0; diff --git a/servers/slapd/back-mdb/modify.c b/servers/slapd/back-mdb/modify.c index c08e95cc69..9a261882b9 100644 --- a/servers/slapd/back-mdb/modify.c +++ b/servers/slapd/back-mdb/modify.c @@ -459,49 +459,12 @@ mdb_modify( Operation *op, SlapReply *rs ) LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS]; int num_ctrls = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(mdb_modify) ": %s\n", op->o_req_dn.bv_val, 0, 0 ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = NULL; diff --git a/servers/slapd/back-mdb/modrdn.c b/servers/slapd/back-mdb/modrdn.c index 3bf46ea69a..ba8c019209 100644 --- a/servers/slapd/back-mdb/modrdn.c +++ b/servers/slapd/back-mdb/modrdn.c @@ -55,50 +55,13 @@ mdb_modrdn( Operation *op, SlapReply *rs ) int parent_is_glue = 0; int parent_is_leaf = 0; -#ifdef LDAP_X_TXN - int settle = 0; -#endif - Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(mdb_modrdn) "(%s,%s,%s)\n", op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" ); #ifdef LDAP_X_TXN - if( op->o_txnSpec ) { - /* acquire connection lock */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - if( op->o_conn->c_txn == CONN_TXN_INACTIVE ) { - rs->sr_text = "invalid transaction identifier"; - rs->sr_err = LDAP_X_TXN_ID_INVALID; - goto txnReturn; - } else if( op->o_conn->c_txn == CONN_TXN_SETTLE ) { - settle=1; - goto txnReturn; - } - - if( op->o_conn->c_txn_backend == NULL ) { - op->o_conn->c_txn_backend = op->o_bd; - - } else if( op->o_conn->c_txn_backend != op->o_bd ) { - rs->sr_text = "transaction cannot span multiple database contexts"; - rs->sr_err = LDAP_AFFECTS_MULTIPLE_DSAS; - goto txnReturn; - } - - /* insert operation into transaction */ - - rs->sr_text = "transaction specified"; - rs->sr_err = LDAP_X_TXN_SPECIFY_OKAY; - -txnReturn: - /* release connection lock */ - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); - - if( !settle ) { - send_ldap_result( op, rs ); - return rs->sr_err; - } - } + if( op->o_txnSpec && txn_preop( op, rs )) + return rs->sr_err; #endif ctrls[num_ctrls] = NULL; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index c112e2fbaa..dca7de0736 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1096,6 +1096,7 @@ LDAP_SLAPD_F (struct berval *) get_supported_extop LDAP_P((int index)); LDAP_SLAPD_F ( SLAP_CTRL_PARSE_FN ) txn_spec_ctrl; LDAP_SLAPD_F ( SLAP_EXTOP_MAIN_FN ) txn_start_extop; LDAP_SLAPD_F ( SLAP_EXTOP_MAIN_FN ) txn_end_extop; +LDAP_SLAPD_F ( int ) txn_preop LDAP_P(( Operation *op, SlapReply *rs )); #endif /*