From e5a37f2125f73aaedc9b771790a169c6b4a4a890 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 23 Jun 2004 01:04:52 +0000 Subject: [PATCH] SLAPD_DISCONNECT v -1 cleanup misc other cleanup --- servers/slapd/abandon.c | 5 +-- servers/slapd/add.c | 6 +-- servers/slapd/bind.c | 5 +-- servers/slapd/connection.c | 79 +++++++++++++++++++++++--------------- servers/slapd/dn.c | 3 +- servers/slapd/extended.c | 6 +-- servers/slapd/result.c | 26 +++++++------ servers/slapd/search.c | 30 +++++++++------ 8 files changed, 94 insertions(+), 66 deletions(-) diff --git a/servers/slapd/abandon.c b/servers/slapd/abandon.c index 10dab8d82c..a0cba25f79 100644 --- a/servers/slapd/abandon.c +++ b/servers/slapd/abandon.c @@ -57,9 +57,8 @@ do_abandon( Operation *op, SlapReply *rs ) #else Debug( LDAP_DEBUG_ANY, "do_abandon: ber_scanf failed\n", 0, 0 ,0 ); #endif - send_ldap_discon( op, rs, - LDAP_PROTOCOL_ERROR, "decoding error" ); - return -1; + send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); + return SLAPD_DISCONNECT; } if( get_ctrls( op, rs, 0 ) != LDAP_SUCCESS ) { diff --git a/servers/slapd/add.c b/servers/slapd/add.c index da0ae87789..9b4734ed9c 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -82,7 +82,7 @@ do_add( Operation *op, SlapReply *rs ) Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - return -1; + return SLAPD_DISCONNECT; } e = (Entry *) ch_calloc( 1, sizeof(Entry) ); @@ -130,7 +130,7 @@ do_add( Operation *op, SlapReply *rs ) Debug( LDAP_DEBUG_ANY, "do_add: decoding error\n", 0, 0, 0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto done; } @@ -168,7 +168,7 @@ do_add( Operation *op, SlapReply *rs ) Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto done; } diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index eb5ead1044..57e164751d 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -41,8 +41,7 @@ int do_bind( Operation *op, - SlapReply *rs -) + SlapReply *rs ) { BerElement *ber = op->o_ber; ber_int_t version; @@ -117,7 +116,7 @@ do_bind( Debug( LDAP_DEBUG_ANY, "bind: ber_scanf failed\n", 0, 0, 0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto cleanup; } diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 3e9b90805c..7271677d8f 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -948,7 +948,7 @@ void connection_done( Connection *c ) static void * connection_operation( void *ctx, void *arg_v ) { - int rc = SLAPD_DISCONNECT; + int rc = LDAP_OTHER; Operation *op = arg_v; SlapReply rs = {REP_RESULT}; ber_tag_t tag = op->o_tag; @@ -966,6 +966,36 @@ connection_operation( void *ctx, void *arg_v ) op->o_threadctx = ctx; + switch ( tag ) { + case LDAP_REQ_BIND: + case LDAP_REQ_UNBIND: + case LDAP_REQ_ADD: + case LDAP_REQ_DELETE: + case LDAP_REQ_MODRDN: + case LDAP_REQ_MODIFY: + case LDAP_REQ_COMPARE: + case LDAP_REQ_SEARCH: + case LDAP_REQ_ABANDON: + case LDAP_REQ_EXTENDED: + break; + default: +#ifdef NEW_LOGGING + LDAP_LOG( CONNECTION, INFO, "connection_operation: " + "conn %lu unknown LDAP request 0x%lx\n", + conn->c_connid, tag, 0 ); +#else + Debug( LDAP_DEBUG_ANY, "connection_operation: " + "conn %lu unknown LDAP request 0x%lx\n", + conn->c_connid, tag, 0 ); +#endif + op->o_tag = LBER_ERROR; + rs.sr_err = LDAP_PROTOCOL_ERROR; + rs.sr_text = "unknown LDAP request"; + send_ldap_disconnect( op, &rs ); + rc = SLAPD_DISCONNECT; + goto operations_error; + } + if( conn->c_sasl_bind_in_progress && tag != LDAP_REQ_BIND ) { #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, ERR, @@ -978,6 +1008,7 @@ connection_operation( void *ctx, void *arg_v ) #endif send_ldap_error( op, &rs, LDAP_OPERATIONS_ERROR, "SASL bind in progress" ); + rc = LDAP_OPERATIONS_ERROR; goto operations_error; } @@ -1053,29 +1084,15 @@ connection_operation( void *ctx, void *arg_v ) break; default: -#ifdef NEW_LOGGING - LDAP_LOG( CONNECTION, INFO, - "connection_operation: conn %lu unknown LDAP request 0x%lx\n", - conn->c_connid, tag, 0 ); -#else - Debug( LDAP_DEBUG_ANY, "unknown LDAP request 0x%lx\n", - tag, 0, 0 ); -#endif - op->o_tag = LBER_ERROR; - rs.sr_err = LDAP_PROTOCOL_ERROR; - rs.sr_text = "unknown LDAP request"; - send_ldap_disconnect( op, &rs ); - rc = -1; - break; + /* not reachable */ + assert( 0 ); } -#ifdef SLAPD_MONITOR - oldtag = tag; -#endif /* SLAPD_MONITOR */ +operations_error: if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR; -operations_error: ldap_pvt_thread_mutex_lock( &num_ops_mutex ); + num_ops_completed++; #ifdef SLAPD_MONITOR switch (oldtag) { @@ -1109,6 +1126,9 @@ operations_error: case LDAP_REQ_EXTENDED: num_ops_completed_[SLAP_OP_EXTENDED]++; break; + default: + /* not reachable */ + assert( 0 ); } #endif /* SLAPD_MONITOR */ ldap_pvt_thread_mutex_unlock( &num_ops_mutex ); @@ -1116,7 +1136,6 @@ operations_error: if ( op->o_cancel == SLAP_CANCEL_REQ ) { op->o_cancel = LDAP_TOO_LATE; } - while ( op->o_cancel != SLAP_CANCEL_NONE && op->o_cancel != SLAP_CANCEL_DONE ) { @@ -1128,14 +1147,17 @@ operations_error: ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null ); if ( op->o_cancel != SLAP_CANCEL_ACK && - ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) { + ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) + { slap_sl_mem_detach( ctx, memctx ); + } else if (( op->o_sync_slog_size != -1 )) { slap_sl_mem_detach( ctx, memctx ); LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); LDAP_STAILQ_NEXT(op, o_next) = NULL; conn->c_n_ops_executing--; conn->c_n_ops_completed++; + } else { LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); LDAP_STAILQ_NEXT(op, o_next) = NULL; @@ -1161,9 +1183,7 @@ operations_error: } connection_resched( conn ); - ldap_pvt_thread_mutex_unlock( &conn->c_mutex ); - return NULL; } @@ -1174,11 +1194,12 @@ int connection_client_setup( ldap_pvt_thread_start_t *func, void *arg ) { + int rc; Connection *c; - if ( connection_init( s, (Listener *)&dummy_list, "", "", CONN_IS_CLIENT, 0, NULL ) < 0 ) { - return -1; - } + rc = connection_init( s, (Listener *)&dummy_list, "", "", + CONN_IS_CLIENT, 0, NULL ); + if ( rc < 0 ) return -1; c = connection_get( s ); c->c_clientfunc = func; @@ -1190,15 +1211,13 @@ int connection_client_setup( } void connection_client_enable( - ber_socket_t s -) + ber_socket_t s ) { slapd_set_read( s, 1 ); } void connection_client_stop( - ber_socket_t s -) + ber_socket_t s ) { Connection *c; diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 6702e8dc18..e6d268ac78 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -918,6 +918,7 @@ int dnX509peerNormalize( void *ssl, struct berval *dn ) { - return ldap_pvt_tls_get_peer_dn( ssl, dn, (LDAPDN_rewrite_dummy *)LDAPDN_rewrite, 0 ); + return ldap_pvt_tls_get_peer_dn( ssl, dn, + (LDAPDN_rewrite_dummy *)LDAPDN_rewrite, 0 ); } #endif diff --git a/servers/slapd/extended.c b/servers/slapd/extended.c index 0abb6db23d..27a06ad87c 100644 --- a/servers/slapd/extended.c +++ b/servers/slapd/extended.c @@ -163,7 +163,7 @@ do_extended( op->o_protocol, 0 ,0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "requires LDAPv3" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto done; } @@ -175,7 +175,7 @@ do_extended( Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto done; } @@ -211,7 +211,7 @@ do_extended( Debug( LDAP_DEBUG_ANY, "do_extended: ber_scanf failed\n", 0, 0 ,0 ); #endif send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" ); - rs->sr_err = -1; + rs->sr_err = SLAPD_DISCONNECT; goto done; } } diff --git a/servers/slapd/result.c b/servers/slapd/result.c index af9510da36..c8a6d17785 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -524,7 +524,6 @@ send_ldap_disconnect( Operation *op, SlapReply *rs ) rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL ); #endif - if ( op->o_protocol < LDAP_VERSION3 ) { rs->sr_rspoid = NULL; rs->sr_tag = req2res( op->o_tag ); @@ -614,11 +613,15 @@ slap_send_ldap_result( Operation *op, SlapReply *rs ) */ if ( op->o_pb != NULL ) { slapi_int_pblock_set_operation( op->o_pb, op ); - slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err ); - slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text ); - slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, + (void *)rs->sr_err ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, + (void *)rs->sr_text ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, + (void *)rs->sr_matched ); - (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN, op->o_pb ); + (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN, + op->o_pb ); } #endif /* LDAP_SLAPI */ @@ -949,7 +952,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs ) #endif if ( op->o_res_ber == NULL ) ber_free_buf( ber ); - send_ldap_error( op, rs, LDAP_OTHER, "encoding description error"); + send_ldap_error( op, rs, LDAP_OTHER, + "encoding description error"); goto error_return; } finish = 1; @@ -992,7 +996,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs ) #endif if ( op->o_res_ber == NULL ) ber_free_buf( ber ); - send_ldap_error( op, rs, LDAP_OTHER, "encoding description error"); + send_ldap_error( op, rs, LDAP_OTHER, + "encoding description error"); goto error_return; } } @@ -1147,7 +1152,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs ) #endif if ( op->o_res_ber == NULL ) ber_free_buf( ber ); - send_ldap_error( op, rs, LDAP_OTHER, "encoding description error" ); + send_ldap_error( op, rs, LDAP_OTHER, + "encoding description error" ); attrs_free( aa ); goto error_return; } @@ -1232,9 +1238,7 @@ slap_send_search_entry( Operation *op, SlapReply *rs ) for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) { rc = compute_evaluator( &ctx, anp->an_name.bv_val, rs->sr_entry, slapi_int_compute_output_ber ); - if ( rc == 1 ) { - break; - } + if ( rc == 1 ) break; } } else { /* diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 1783c9619f..4738f5dfcc 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -47,8 +47,8 @@ static void call_search_postop_plugins( Operation *op ); int do_search( Operation *op, /* info about the op to which we're responding */ - SlapReply *rs /* all the response data we'll send */ -) { + SlapReply *rs /* all the response data we'll send */ ) +{ struct berval base = BER_BVNULL; ber_len_t siz, off, i; int manageDSAit; @@ -164,6 +164,7 @@ do_search( if( rs->sr_err == SLAPD_DISCONNECT ) { rs->sr_err = LDAP_PROTOCOL_ERROR; send_ldap_disconnect( op, rs ); + rs->sr_err = SLAPD_DISCONNECT; } else { send_ldap_result( op, rs ); } @@ -427,19 +428,24 @@ do_search( #endif /* LDAP_SLAPI */ return_results:; + if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) return rs->sr_err; + if ( ( op->o_sync_slog_size != -1 ) ) return rs->sr_err; - if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) - return rs->sr_err; - - if ( ( op->o_sync_slog_size != -1 ) ) - return rs->sr_err; - - if( !BER_BVISNULL( &op->o_req_dn ) ) slap_sl_free( op->o_req_dn.bv_val, op->o_tmpmemctx ); - if( !BER_BVISNULL( &op->o_req_ndn ) ) slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx ); + if( !BER_BVISNULL( &op->o_req_dn ) ) { + slap_sl_free( op->o_req_dn.bv_val, op->o_tmpmemctx ); + } + if( !BER_BVISNULL( &op->o_req_ndn ) ) { + slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx ); + } - if( !BER_BVISNULL( &op->ors_filterstr ) ) op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); + if( !BER_BVISNULL( &op->ors_filterstr ) ) { + op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); + } if( op->ors_filter != NULL) filter_free_x( op, op->ors_filter ); - if( op->ors_attrs != NULL ) op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx ); + if( op->ors_attrs != NULL ) { + op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx ); + } + #ifdef LDAP_SLAPI if( attrs != NULL) op->o_tmpfree( attrs, op->o_tmpmemctx ); #endif /* LDAP_SLAPI */ -- 2.39.5