From ddd1acc327ef2ede6ba22c46611b85eab4042621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Wed, 13 Dec 2017 16:09:26 +0000 Subject: [PATCH] Passing the client directly will allow clearing it from op --- servers/lloadd/bind.c | 77 +++++++++++++++++++----------------- servers/lloadd/lload.h | 4 +- servers/lloadd/proto-lload.h | 8 ++-- servers/lloadd/upstream.c | 24 +++++------ 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/servers/lloadd/bind.c b/servers/lloadd/bind.c index 612e53d498..3b6bb225a9 100644 --- a/servers/lloadd/bind.c +++ b/servers/lloadd/bind.c @@ -333,9 +333,12 @@ request_bind( LloadConnection *client, LloadOperation *op ) } int -handle_bind_response( LloadOperation *op, BerElement *ber ) +handle_bind_response( + LloadConnection *client, + LloadOperation *op, + BerElement *ber ) { - LloadConnection *client = op->o_client, *upstream = op->o_upstream; + LloadConnection *upstream = op->o_upstream; BerValue response; BerElement *copy; ber_int_t result; @@ -407,14 +410,16 @@ done: ber_free( ber, 1 ); return LDAP_SUCCESS; } - return forward_final_response( op, ber ); + return forward_final_response( client, op, ber ); } #ifdef LDAP_API_FEATURE_VERIFY_CREDENTIALS int -handle_vc_bind_response( LloadOperation *op, BerElement *ber ) +handle_vc_bind_response( + LloadConnection *client, + LloadOperation *op, + BerElement *ber ) { - LloadConnection *c = op->o_client; BerElement *output; BerValue matched, diagmsg, creds = BER_BVNULL, controls = BER_BVNULL; ber_int_t result; @@ -447,16 +452,16 @@ handle_vc_bind_response( LloadOperation *op, BerElement *ber ) "connid=%lu, result=%d\n", op->o_client_msgid, op->o_client_connid, result ); - CONNECTION_LOCK(c); + CONNECTION_LOCK(client); if ( tag == LDAP_TAG_EXOP_VERIFY_CREDENTIALS_COOKIE ) { - if ( !BER_BVISNULL( &c->c_vc_cookie ) ) { - ber_memfree( c->c_vc_cookie.bv_val ); + if ( !BER_BVISNULL( &client->c_vc_cookie ) ) { + ber_memfree( client->c_vc_cookie.bv_val ); } - tag = ber_scanf( ber, "o", &c->c_vc_cookie ); + tag = ber_scanf( ber, "o", &client->c_vc_cookie ); if ( tag == LBER_ERROR ) { rc = -1; - CONNECTION_UNLOCK_INCREF(c); + CONNECTION_UNLOCK_INCREF(client); goto done; } tag = ber_peek_tag( ber, &len ); @@ -466,7 +471,7 @@ handle_vc_bind_response( LloadOperation *op, BerElement *ber ) tag = ber_scanf( ber, "m", &creds ); if ( tag == LBER_ERROR ) { rc = -1; - CONNECTION_UNLOCK_INCREF(c); + CONNECTION_UNLOCK_INCREF(client); goto done; } tag = ber_peek_tag( ber, &len ); @@ -476,51 +481,51 @@ handle_vc_bind_response( LloadOperation *op, BerElement *ber ) tag = ber_scanf( ber, "m", &controls ); if ( tag == LBER_ERROR ) { rc = -1; - CONNECTION_UNLOCK_INCREF(c); + CONNECTION_UNLOCK_INCREF(client); goto done; } } - if ( c->c_state == LLOAD_C_BINDING ) { + if ( client->c_state == LLOAD_C_BINDING ) { switch ( result ) { case LDAP_SASL_BIND_IN_PROGRESS: break; case LDAP_SUCCESS: default: { - c->c_state = LLOAD_C_READY; - c->c_type = LLOAD_C_OPEN; + client->c_state = LLOAD_C_READY; + client->c_type = LLOAD_C_OPEN; if ( result != LDAP_SUCCESS ) { - ber_memfree( c->c_auth.bv_val ); - BER_BVZERO( &c->c_auth ); + ber_memfree( client->c_auth.bv_val ); + BER_BVZERO( &client->c_auth ); } else if ( !ber_bvstrcasecmp( - &c->c_auth, &lloadd_identity ) ) { - c->c_type = LLOAD_C_PRIVILEGED; + &client->c_auth, &lloadd_identity ) ) { + client->c_type = LLOAD_C_PRIVILEGED; } - if ( !BER_BVISNULL( &c->c_vc_cookie ) ) { - ber_memfree( c->c_vc_cookie.bv_val ); - BER_BVZERO( &c->c_vc_cookie ); + if ( !BER_BVISNULL( &client->c_vc_cookie ) ) { + ber_memfree( client->c_vc_cookie.bv_val ); + BER_BVZERO( &client->c_vc_cookie ); } - if ( !BER_BVISNULL( &c->c_sasl_bind_mech ) ) { - ber_memfree( c->c_sasl_bind_mech.bv_val ); - BER_BVZERO( &c->c_sasl_bind_mech ); + if ( !BER_BVISNULL( &client->c_sasl_bind_mech ) ) { + ber_memfree( client->c_sasl_bind_mech.bv_val ); + BER_BVZERO( &client->c_sasl_bind_mech ); } break; } } } else { - assert( c->c_state == LLOAD_C_INVALID || - c->c_state == LLOAD_C_CLOSING ); + assert( client->c_state == LLOAD_C_INVALID || + client->c_state == LLOAD_C_CLOSING ); } - CONNECTION_UNLOCK_INCREF(c); + CONNECTION_UNLOCK_INCREF(client); - ldap_pvt_thread_mutex_lock( &c->c_io_mutex ); - output = c->c_pendingber; + ldap_pvt_thread_mutex_lock( &client->c_io_mutex ); + output = client->c_pendingber; if ( output == NULL && (output = ber_alloc()) == NULL ) { rc = -1; - ldap_pvt_thread_mutex_unlock( &c->c_io_mutex ); + ldap_pvt_thread_mutex_unlock( &client->c_io_mutex ); goto done; } - c->c_pendingber = output; + client->c_pendingber = output; rc = ber_printf( output, "t{tit{eOOtO}tO}", LDAP_TAG_MESSAGE, LDAP_TAG_MSGID, op->o_client_msgid, LDAP_RES_BIND, @@ -528,16 +533,16 @@ handle_vc_bind_response( LloadOperation *op, BerElement *ber ) LDAP_TAG_SASL_RES_CREDS, BER_BV_OPTIONAL( &creds ), LDAP_TAG_CONTROLS, BER_BV_OPTIONAL( &controls ) ); - ldap_pvt_thread_mutex_unlock( &c->c_io_mutex ); + ldap_pvt_thread_mutex_unlock( &client->c_io_mutex ); if ( rc >= 0 ) { - connection_write_cb( -1, 0, c ); + connection_write_cb( -1, 0, client ); rc = 0; } done: - CONNECTION_LOCK_DECREF(c); + CONNECTION_LOCK_DECREF(client); operation_destroy_from_client( op ); - CONNECTION_UNLOCK_OR_DESTROY(c); + CONNECTION_UNLOCK_OR_DESTROY(client); ber_free( ber, 1 ); return rc; } diff --git a/servers/lloadd/lload.h b/servers/lloadd/lload.h index 92f2efd0d1..57954f4763 100644 --- a/servers/lloadd/lload.h +++ b/servers/lloadd/lload.h @@ -148,7 +148,9 @@ struct LloadBackend { LDAP_CIRCLEQ_ENTRY(LloadBackend) b_next; }; -typedef int (*LloadOperationHandler)( LloadOperation *op, BerElement *ber ); +typedef int (*LloadOperationHandler)( LloadConnection *client, + LloadOperation *op, + BerElement *ber ); typedef int (*RequestHandler)( LloadConnection *c, LloadOperation *op ); typedef struct lload_exop_handlers_t { struct berval oid; diff --git a/servers/lloadd/proto-lload.h b/servers/lloadd/proto-lload.h index 61b901317c..b0249391a7 100644 --- a/servers/lloadd/proto-lload.h +++ b/servers/lloadd/proto-lload.h @@ -50,8 +50,8 @@ LDAP_SLAPD_F (void) backends_destroy( void ); * bind.c */ LDAP_SLAPD_F (int) request_bind( LloadConnection *c, LloadOperation *op ); -LDAP_SLAPD_F (int) handle_bind_response( LloadOperation *op, BerElement *ber ); -LDAP_SLAPD_F (int) handle_vc_bind_response( LloadOperation *op, BerElement *ber ); +LDAP_SLAPD_F (int) handle_bind_response( LloadConnection *client, LloadOperation *op, BerElement *ber ); +LDAP_SLAPD_F (int) handle_vc_bind_response( LloadConnection *client, LloadOperation *op, BerElement *ber ); /* * client.c @@ -151,8 +151,8 @@ LDAP_SLAPD_F (void) operations_timeout( evutil_socket_t s, short what, void *arg /* * upstream.c */ -LDAP_SLAPD_F (int) forward_final_response( LloadOperation *op, BerElement *ber ); -LDAP_SLAPD_F (int) forward_response( LloadOperation *op, BerElement *ber ); +LDAP_SLAPD_F (int) forward_final_response( LloadConnection *client, LloadOperation *op, BerElement *ber ); +LDAP_SLAPD_F (int) forward_response( LloadConnection *client, LloadOperation *op, BerElement *ber ); LDAP_SLAPD_F (LloadConnection *) upstream_init( ber_socket_t s, LloadBackend *b ); LDAP_SLAPD_F (void) upstream_destroy( LloadConnection *c ); diff --git a/servers/lloadd/upstream.c b/servers/lloadd/upstream.c index 966e6e0dfa..bd05de3997 100644 --- a/servers/lloadd/upstream.c +++ b/servers/lloadd/upstream.c @@ -25,9 +25,8 @@ #include "lload.h" int -forward_response( LloadOperation *op, BerElement *ber ) +forward_response( LloadConnection *client, LloadOperation *op, BerElement *ber ) { - LloadConnection *c = op->o_client; BerElement *output; BerValue response, controls = BER_BVNULL; ber_tag_t tag, response_tag; @@ -45,29 +44,32 @@ forward_response( LloadOperation *op, BerElement *ber ) lload_msgtype2str( response_tag ), op->o_client_connid, op->o_client_msgid ); - ldap_pvt_thread_mutex_lock( &c->c_io_mutex ); - output = c->c_pendingber; + ldap_pvt_thread_mutex_lock( &client->c_io_mutex ); + output = client->c_pendingber; if ( output == NULL && (output = ber_alloc()) == NULL ) { ber_free( ber, 1 ); - ldap_pvt_thread_mutex_unlock( &c->c_io_mutex ); + ldap_pvt_thread_mutex_unlock( &client->c_io_mutex ); return -1; } - c->c_pendingber = output; + client->c_pendingber = output; ber_printf( output, "t{titOtO}", LDAP_TAG_MESSAGE, LDAP_TAG_MSGID, op->o_client_msgid, response_tag, &response, LDAP_TAG_CONTROLS, BER_BV_OPTIONAL( &controls ) ); - ldap_pvt_thread_mutex_unlock( &c->c_io_mutex ); + ldap_pvt_thread_mutex_unlock( &client->c_io_mutex ); ber_free( ber, 1 ); - connection_write_cb( -1, 0, c ); + connection_write_cb( -1, 0, client ); return 0; } int -forward_final_response( LloadOperation *op, BerElement *ber ) +forward_final_response( + LloadConnection *client, + LloadOperation *op, + BerElement *ber ) { int rc; @@ -75,7 +77,7 @@ forward_final_response( LloadOperation *op, BerElement *ber ) "connid=%lu msgid=%d finishing up with a request for " "client connid=%lu\n", op->o_upstream_connid, op->o_upstream_msgid, op->o_client_connid ); - rc = forward_response( op, ber ); + rc = forward_response( client, op, ber ); CONNECTION_LOCK_DECREF(op->o_upstream); operation_destroy_from_upstream( op ); CONNECTION_UNLOCK_INCREF(op->o_upstream); @@ -223,7 +225,7 @@ handle_one_response( LloadConnection *c ) ldap_pvt_thread_mutex_unlock( &op->o_link_mutex ); if ( client ) { - rc = handler( op, ber ); + rc = handler( client, op, ber ); CONNECTION_LOCK_DECREF(client); op->o_client_refcnt--; if ( !op->o_client_refcnt ) {