From 65c5e584bae660d44c427c80536e82c4f99b2a80 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Apr 30 2014 13:36:44 +0000 Subject: Ticket 47792 - code cleanup https://fedorahosted.org/389/ticket/47792 Reviewed by: rmeggins(Thanks!) (cherry picked from commit d341b7734648e71c1b1ded398971c23b6fbdc1fb) --- diff --git a/ldap/servers/plugins/chainingdb/cb_add.c b/ldap/servers/plugins/chainingdb/cb_add.c index 07b90fa..03d0fc9 100644 --- a/ldap/servers/plugins/chainingdb/cb_add.c +++ b/ldap/servers/plugins/chainingdb/cb_add.c @@ -54,23 +54,22 @@ int chaining_back_add ( Slapi_PBlock *pb ) { - - Slapi_Backend *be; - Slapi_Entry *e; - cb_backend_instance *cb; - LDAPControl **serverctrls=NULL; - LDAPControl **ctrls=NULL; - int rc,parse_rc,msgid,i; - LDAP *ld=NULL; - char **referrals=NULL; - LDAPMod ** mods; - LDAPMessage * res; - char * matched_msg, *error_msg; - const char *dn = NULL; - Slapi_DN *sdn = NULL; - char *cnxerrbuf=NULL; - time_t endtime = 0; - cb_outgoing_conn *cnx; + cb_outgoing_conn *cnx; + Slapi_Backend *be; + Slapi_Entry *e; + cb_backend_instance *cb; + LDAPControl **serverctrls = NULL; + LDAPControl **ctrls = NULL; + LDAPMod **mods; + LDAPMessage *res; + LDAP *ld = NULL; + Slapi_DN *sdn = NULL; + const char *dn = NULL; + char **referrals = NULL; + char *matched_msg, *error_msg; + char *cnxerrbuf = NULL; + time_t endtime = 0; + int rc, parse_rc, msgid, i; if ( (rc=cb_forward_operation(pb)) != LDAP_SUCCESS ) { cb_send_ldap_result( pb, rc, NULL, "Remote data access disabled", 0, NULL ); @@ -85,7 +84,7 @@ chaining_back_add ( Slapi_PBlock *pb ) /* Check wether the chaining BE is available or not */ if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){ - return -1; + return -1; } slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn ); @@ -108,8 +107,8 @@ chaining_back_add ( Slapi_PBlock *pb ) cb_eliminate_illegal_attributes(cb,e); if ((rc = slapi_entry2mods ((const Slapi_Entry *)e, NULL, &mods)) != LDAP_SUCCESS) { - cb_send_ldap_result( pb, rc,NULL,NULL, 0, NULL); - return -1; + cb_send_ldap_result( pb, rc,NULL,NULL, 0, NULL); + return -1; } /* Grab a connection handle */ @@ -118,12 +117,11 @@ chaining_back_add ( Slapi_PBlock *pb ) static int warned_get_conn = 0; if (!warned_get_conn) { slapi_log_error(SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "cb_get_connection failed (%d) %s\n", - rc, ldap_err2string(rc)); + "cb_get_connection failed (%d) %s\n", + rc, ldap_err2string(rc)); warned_get_conn = 1; } - cb_send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, - cnxerrbuf, 0, NULL); + cb_send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, cnxerrbuf, 0, NULL); ldap_mods_free(mods, 1); slapi_ch_free_string(&cnxerrbuf); /* ping the farm. @@ -135,23 +133,23 @@ chaining_back_add ( Slapi_PBlock *pb ) /* Control management */ if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH)) != LDAP_SUCCESS ) { - cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); + cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); - return -1; + return -1; } - if ( slapi_op_abandoned( pb )) { - cb_release_op_connection(cb->pool,ld,0); + 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); - return -1; - } + return -1; + } /* heart-beat management */ if (cb->max_idle_time>0) - endtime=current_time() + cb->max_idle_time; + endtime=current_time() + cb->max_idle_time; /* Send LDAP operation to the remote host */ rc = ldap_add_ext( ld, dn, mods, ctrls, NULL, &msgid ); @@ -161,10 +159,9 @@ chaining_back_add ( Slapi_PBlock *pb ) if ( rc != LDAP_SUCCESS ) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "ldap_add_ext failed -- %s\n", ldap_err2string(rc) ); + "ldap_add_ext failed -- %s\n", ldap_err2string(rc) ); - cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ENDUSERMSG, 0, NULL ); + cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ENDUSERMSG, 0, NULL ); cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); ldap_mods_free(mods,1); return -1; @@ -183,31 +180,31 @@ chaining_back_add ( Slapi_PBlock *pb ) return -1; } - rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); - switch ( rc ) { - case -1: - cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, - ldap_err2string(rc), 0, NULL); + rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); + switch ( rc ) { + case -1: + 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); - return -1; + return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { + /* + * does not respond. give up and return a + * error to the client. + */ - /* does not respond. give up and return a*/ - /* error to the client. */ - - /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, + /*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)); ldap_mods_free(mods,1); if (res) ldap_msgfree(res); - return -1; + return -1; } #ifdef CB_YIELD DS_Sleep(PR_INTERVAL_NO_WAIT); @@ -219,20 +216,19 @@ chaining_back_add ( Slapi_PBlock *pb ) referrals=NULL; parse_rc = ldap_parse_result( ld, res, &rc, &matched_msg, - &error_msg, &referrals, &serverctrls, 1 ); + &error_msg, &referrals, &serverctrls, 1 ); if ( parse_rc != LDAP_SUCCESS ) { static int warned_parse_rc = 0; if (!warned_parse_rc) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - ldap_err2string(parse_rc)); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + ldap_err2string(parse_rc)); warned_parse_rc = 1; } - cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ENDUSERMSG, 0, NULL ); + 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); @@ -250,10 +246,10 @@ chaining_back_add ( Slapi_PBlock *pb ) static int warned_rc = 0; if (!warned_rc && error_msg) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - error_msg ); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + error_msg ); warned_rc = 1; } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); @@ -276,22 +272,20 @@ chaining_back_add ( Slapi_PBlock *pb ) /* 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_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); if (serverctrls) - ldap_controls_free(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_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 ); + slapi_pblock_set( pb, SLAPI_ADD_ENTRY, NULL ); return 0; } } - /* Never reached */ } diff --git a/ldap/servers/plugins/chainingdb/cb_delete.c b/ldap/servers/plugins/chainingdb/cb_delete.c index 09972b2..97807ef 100644 --- a/ldap/servers/plugins/chainingdb/cb_delete.c +++ b/ldap/servers/plugins/chainingdb/cb_delete.c @@ -54,20 +54,19 @@ int chaining_back_delete ( Slapi_PBlock *pb ) { - - Slapi_Backend * be; - cb_backend_instance *cb; - LDAPControl **ctrls, **serverctrls; - int rc,parse_rc,msgid,i; - LDAP *ld=NULL; - char **referrals=NULL; - LDAPMessage * res; - const char *dn = NULL; - Slapi_DN *sdn = NULL; - char *matched_msg, *error_msg; - char *cnxerrbuf=NULL; - time_t endtime = 0; - cb_outgoing_conn *cnx; + cb_outgoing_conn *cnx; + Slapi_Backend *be; + cb_backend_instance *cb; + LDAPControl **ctrls, **serverctrls; + LDAPMessage *res; + LDAP *ld = NULL; + Slapi_DN *sdn = NULL; + const char *dn = NULL; + char **referrals = NULL; + char *matched_msg, *error_msg; + char *cnxerrbuf = NULL; + time_t endtime = 0; + int rc, parse_rc, msgid, i; if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) { cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL ); @@ -94,6 +93,7 @@ chaining_back_delete ( Slapi_PBlock *pb ) if (cb->local_acl && !cb->associated_be_is_disabled) { char * errbuf=NULL; Slapi_Entry *te = slapi_entry_alloc(); + slapi_entry_set_sdn(te, sdn); /* sdn: copied */ rc = cb_access_allowed (pb, te, NULL, NULL, SLAPI_ACL_DELETE,&errbuf); slapi_entry_free(te); @@ -127,25 +127,24 @@ chaining_back_delete ( Slapi_PBlock *pb ) } /* - * Control management - */ - - if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { - cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); - cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - return -1; - } + * Control management + */ + if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { + cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); + cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); + return -1; + } - if ( slapi_op_abandoned( pb )) { - cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); - return -1; - } + if ( slapi_op_abandoned( pb )) { + cb_release_op_connection(cb->pool,ld,0); + if ( NULL != ctrls) + ldap_controls_free(ctrls); + return -1; + } /* heart-beat management */ if (cb->max_idle_time>0) - endtime=current_time() + cb->max_idle_time; + endtime=current_time() + cb->max_idle_time; /* * Send LDAP operation to the remote host @@ -153,43 +152,39 @@ chaining_back_delete ( Slapi_PBlock *pb ) 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); + 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)); - return -1; + return -1; } while ( 1 ) { - - if (cb_check_forward_abandon(cb,pb,ld,msgid)) { - return -1; + if (cb_check_forward_abandon(cb,pb,ld,msgid)) { + return -1; } - rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); - switch ( rc ) { - case -1: - cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ldap_err2string(rc), 0, NULL); + rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); + switch ( rc ) { + case -1: + 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); - return -1; + return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { + /* does not respond. give up and return a error to the client. */ - /* does not respond. give up and return a*/ - /* error to the client. */ - - /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, + /*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); - return -1; + return -1; } #ifdef CB_YIELD DS_Sleep(PR_INTERVAL_NO_WAIT); @@ -198,15 +193,15 @@ chaining_back_delete ( Slapi_PBlock *pb ) default: matched_msg=error_msg=NULL; parse_rc = ldap_parse_result( ld, res, &rc, &matched_msg, - &error_msg, &referrals, &serverctrls, 1 ); + &error_msg, &referrals, &serverctrls, 1 ); if ( parse_rc != LDAP_SUCCESS ) { static int warned_parse_rc = 0; if (!warned_parse_rc) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - ldap_err2string(parse_rc) ); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + ldap_err2string(parse_rc) ); warned_parse_rc = 1; } cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, @@ -227,10 +222,10 @@ chaining_back_delete ( Slapi_PBlock *pb ) static int warned_rc = 0; if (!warned_rc && error_msg) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - error_msg ); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + error_msg ); warned_rc = 1; } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); @@ -248,18 +243,18 @@ chaining_back_delete ( Slapi_PBlock *pb ) cb_release_op_connection(cb->pool,ld,0); - /* 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); + /* 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_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 ); + return 0; } } diff --git a/ldap/servers/plugins/chainingdb/cb_modify.c b/ldap/servers/plugins/chainingdb/cb_modify.c index 65acb58..12d36da 100644 --- a/ldap/servers/plugins/chainingdb/cb_modify.c +++ b/ldap/servers/plugins/chainingdb/cb_modify.c @@ -56,21 +56,20 @@ static void cb_remove_illegal_mods(cb_backend_instance * inst, LDAPMod **mods); int chaining_back_modify ( Slapi_PBlock *pb ) { - - Slapi_Backend *be; - cb_backend_instance *cb; - LDAPControl **ctrls, **serverctrls; - int rc,parse_rc,msgid,i; - LDAP *ld=NULL; - char **referrals=NULL; - LDAPMod ** mods; - LDAPMessage * res; - const char *dn = NULL; - Slapi_DN *sdn = NULL; - char *matched_msg, *error_msg; - char *cnxerrbuf=NULL; - time_t endtime = 0; - cb_outgoing_conn *cnx; + cb_outgoing_conn *cnx; + Slapi_Backend *be; + cb_backend_instance *cb; + LDAPControl **ctrls, **serverctrls; + LDAPMod ** mods; + LDAPMessage *res; + LDAP *ld = NULL; + Slapi_DN *sdn = NULL; + const char *dn = NULL; + char **referrals=NULL; + char *matched_msg, *error_msg; + char *cnxerrbuf=NULL; + time_t endtime = 0; + int rc, parse_rc, msgid, i; if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) { cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL ); @@ -79,7 +78,6 @@ chaining_back_modify ( Slapi_PBlock *pb ) slapi_pblock_get( pb, SLAPI_BACKEND, &be ); cb = cb_get_instance(be); - cb_update_monitor_info(pb,cb,SLAPI_OPERATION_MODIFY); /* Check wether the chaining BE is available or not */ @@ -94,13 +92,11 @@ chaining_back_modify ( Slapi_PBlock *pb ) slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM,"modify: target:<%s>\n",dn); } - - ctrls=serverctrls=NULL; + ctrls = serverctrls = NULL; slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods ); slapi_pblock_get( pb, SLAPI_REQCONTROLS, &ctrls ); /* Check acls */ - if ( cb->local_acl && !cb->associated_be_is_disabled ) { char * errbuf=NULL; Slapi_Entry *te = slapi_entry_alloc(); @@ -126,8 +122,7 @@ chaining_back_modify ( Slapi_PBlock *pb ) rc, ldap_err2string(rc)); warned_get_conn = 1; } - cb_send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, - cnxerrbuf, 0, NULL); + cb_send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, cnxerrbuf, 0, NULL); slapi_ch_free_string(&cnxerrbuf); /* ping the farm. * If the farm is unreachable, we increment the counter */ @@ -136,91 +131,88 @@ chaining_back_modify ( Slapi_PBlock *pb ) } /* Control management */ - if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { - cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); - cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - /* Don't free mods here: are freed at the do_modify level */ - return -1; - } - - 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 ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { + cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); + cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); + /* Don't free mods here: are freed at the do_modify level */ + return -1; + } + + 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); - return -1; - } + ldap_controls_free(ctrls); + return -1; + } /* Remove illegal attributes from the mods */ cb_remove_illegal_mods(cb,mods); /* heart-beat management */ if (cb->max_idle_time>0) - endtime=current_time() + cb->max_idle_time; + endtime=current_time() + cb->max_idle_time; /* 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); + 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)); - return -1; + return -1; } while ( 1 ) { - - if (cb_check_forward_abandon(cb,pb,ld,msgid)) { + if (cb_check_forward_abandon(cb,pb,ld,msgid)) { /* connection handle released */ - return -1; + return -1; } - rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); - switch ( rc ) { - case -1: - cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ldap_err2string(rc), 0, NULL); + rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); + switch ( rc ) { + case -1: + 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); - return -1; + return -1; case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { + /* does not respond. give up and return a error to the client. */ - /* does not respond. give up and return a*/ - /* error to the client. */ - - /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, + /*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); - return -1; + return -1; } #ifdef CB_YIELD - DS_Sleep(PR_INTERVAL_NO_WAIT); + DS_Sleep(PR_INTERVAL_NO_WAIT); #endif - break; - default: + break; + default: matched_msg=error_msg=NULL; serverctrls=NULL; parse_rc = ldap_parse_result( ld, res, &rc, &matched_msg, - &error_msg, &referrals, &serverctrls, 1 ); + &error_msg, &referrals, &serverctrls, 1 ); if ( parse_rc != LDAP_SUCCESS ) { static int warned_parse_rc = 0; if (!warned_parse_rc) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - ldap_err2string(parse_rc)); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + ldap_err2string(parse_rc)); warned_parse_rc = 1; } cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ENDUSERMSG, 0, 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); @@ -237,10 +229,10 @@ chaining_back_modify ( Slapi_PBlock *pb ) static int warned_rc = 0; if (!warned_rc && error_msg) { slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - error_msg ); + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + error_msg ); warned_rc = 1; } cb_send_ldap_result( pb, rc, matched_msg, ENDUSERMSG, 0, refs); @@ -261,20 +253,20 @@ chaining_back_modify ( Slapi_PBlock *pb ) /* 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_pblock_set( pb, SLAPI_ADD_RESCONTROL, serverctrls[i]); /* SLAPI_ADD_RESCONTROL dups controls */ if (serverctrls) - ldap_controls_free(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_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 ); + return 0; } } - /* Never reached */ /* return 0; */ } @@ -283,30 +275,28 @@ chaining_back_modify ( Slapi_PBlock *pb ) static void cb_remove_illegal_mods(cb_backend_instance *inst, LDAPMod **mods) { - int i, j; - LDAPMod *tmp; + int i, j; + LDAPMod *tmp; if ( inst->illegal_attributes != NULL ) { /* Unlikely to happen */ - - slapi_rwlock_wrlock(inst->rwl_config_lock); + slapi_rwlock_wrlock(inst->rwl_config_lock); for (j=0; inst->illegal_attributes[j]; j++) { - for ( i = 0; mods && mods[i] != NULL; i++ ) { + for ( i = 0; mods && mods[i] != NULL; i++ ) { if (slapi_attr_types_equivalent(inst->illegal_attributes[j],mods[i]->mod_type)) { - tmp = mods[i]; - for ( j = i; mods[j] != NULL; j++ ) { - mods[j] = mods[j + 1]; - } - slapi_ch_free( (void**)&(tmp->mod_type) ); - if ( tmp->mod_bvalues != NULL ) { - ber_bvecfree( tmp->mod_bvalues ); - } - slapi_ch_free( (void**)&tmp ); - i--; + tmp = mods[i]; + for ( j = i; mods[j] != NULL; j++ ) { + mods[j] = mods[j + 1]; + } + slapi_ch_free( (void**)&(tmp->mod_type) ); + if ( tmp->mod_bvalues != NULL ) { + ber_bvecfree( tmp->mod_bvalues ); + } + slapi_ch_free( (void**)&tmp ); + i--; } } } - - slapi_rwlock_unlock(inst->rwl_config_lock); + slapi_rwlock_unlock(inst->rwl_config_lock); } } diff --git a/ldap/servers/plugins/chainingdb/cb_modrdn.c b/ldap/servers/plugins/chainingdb/cb_modrdn.c index 1ce6c60..21903f7 100644 --- a/ldap/servers/plugins/chainingdb/cb_modrdn.c +++ b/ldap/servers/plugins/chainingdb/cb_modrdn.c @@ -54,46 +54,47 @@ int chaining_back_modrdn ( Slapi_PBlock *pb ) { - Slapi_Backend * be; - cb_backend_instance *cb; - LDAPControl **ctrls, **serverctrls; - int rc,parse_rc,msgid,i; - LDAP *ld=NULL; - char **referrals=NULL; - LDAPMessage *res; - char *matched_msg, *error_msg; - char *ndn = NULL; - Slapi_DN *sdn = NULL; - int deleteoldrdn = 0; - Slapi_DN *newsuperior = NULL; - char *newrdn = NULL; - char * cnxerrbuf=NULL; - time_t endtime = 0; - cb_outgoing_conn *cnx; - - if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) { - cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL ); - return -1; - } + cb_outgoing_conn *cnx; + Slapi_Backend *be; + cb_backend_instance *cb; + LDAPControl **ctrls, **serverctrls; + LDAPMessage *res; + LDAP *ld = NULL; + Slapi_DN *newsuperior = NULL; + Slapi_DN *sdn = NULL; + char **referrals = NULL; + char *matched_msg, *error_msg; + char *ndn = NULL; + char *newrdn = NULL; + char *cnxerrbuf = NULL; + time_t endtime = 0; + int deleteoldrdn = 0; + int rc, parse_rc, msgid, i; + + + if ( LDAP_SUCCESS != (rc=cb_forward_operation(pb) )) { + cb_send_ldap_result( pb, rc, NULL, "Chaining forbidden", 0, NULL ); + return -1; + } - slapi_pblock_get( pb, SLAPI_BACKEND, &be ); - cb = cb_get_instance(be); + slapi_pblock_get( pb, SLAPI_BACKEND, &be ); + cb = cb_get_instance(be); - cb_update_monitor_info(pb,cb,SLAPI_OPERATION_MODRDN); + cb_update_monitor_info(pb,cb,SLAPI_OPERATION_MODRDN); - /* Check wether the chaining BE is available or not */ - if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){ - return -1; - } + /* Check wether the chaining BE is available or not */ + if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){ + return -1; + } - slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn ); - /* newrdn is passed to ldap_rename, which does not require case-ignored - * newrdn. */ - slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn ); - slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior ); - slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &deleteoldrdn ); + slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn ); + /* newrdn is passed to ldap_rename, which does not require case-ignored + * newrdn. */ + slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn ); + slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior ); + slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &deleteoldrdn ); - ndn = (char *)slapi_sdn_get_ndn(sdn); + ndn = (char *)slapi_sdn_get_ndn(sdn); if (cb->local_acl && !cb->associated_be_is_disabled) { /* * Check local acls @@ -111,7 +112,7 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) slapi_ch_free((void **)&errbuf); return -1; } - } + } /* * Grab a connection handle @@ -135,80 +136,77 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) } /* - * Control management - */ - - if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { - cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); - cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); - return -1; - } + * Control management + */ + if ( (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH )) != LDAP_SUCCESS ) { + cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); + cb_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); + return -1; + } - if ( slapi_op_abandoned( pb )) { - cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); - return -1; - } + if ( slapi_op_abandoned( pb )) { + cb_release_op_connection(cb->pool,ld,0); + if ( NULL != ctrls) + ldap_controls_free(ctrls); + return -1; + } /* heart-beat management */ if (cb->max_idle_time>0) - endtime=current_time() + cb->max_idle_time; + endtime=current_time() + cb->max_idle_time; /* * 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); + 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)); - return -1; + return -1; } while ( 1 ) { - - if (cb_check_forward_abandon(cb,pb,ld,msgid)) { - return -1; + if (cb_check_forward_abandon(cb,pb,ld,msgid)) { + return -1; } rc = ldap_result( ld, msgid, 0, &cb->abandon_timeout, &res ); switch ( rc ) { case -1: - cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, - ldap_err2string(rc), 0, NULL); + 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); - return -1; + return -1; + case 0: if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { + /* does not respond. give up and return a error to the client. */ - /* does not respond. give up and return a*/ - /* error to the client. */ - - /*cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, + /*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_release_op_connection(cb->pool,ld,CB_LDAP_CONN_ERROR(rc)); if (res) ldap_msgfree(res); - return -1; + return -1; } #ifdef CB_YIELD - DS_Sleep(PR_INTERVAL_NO_WAIT); + DS_Sleep(PR_INTERVAL_NO_WAIT); #endif break; + default: matched_msg=error_msg=NULL; parse_rc = ldap_parse_result( ld, res, &rc, &matched_msg, - &error_msg, &referrals, &serverctrls, 1 ); + &error_msg, &referrals, &serverctrls, 1 ); if ( parse_rc != LDAP_SUCCESS ) { static int warned_parse_rc = 0; @@ -259,18 +257,18 @@ chaining_back_modrdn ( Slapi_PBlock *pb ) cb_release_op_connection(cb->pool,ld,0); - /* 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); + /* 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_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 ); + return 0; } } diff --git a/ldap/servers/plugins/chainingdb/cb_search.c b/ldap/servers/plugins/chainingdb/cb_search.c index a27e767..faca2e3 100644 --- a/ldap/servers/plugins/chainingdb/cb_search.c +++ b/ldap/servers/plugins/chainingdb/cb_search.c @@ -54,31 +54,30 @@ int chainingdb_build_candidate_list ( Slapi_PBlock *pb ) -{ - - Slapi_Backend * be; - Slapi_Operation * op; - char *filter; - const char *target = NULL; - Slapi_DN *target_sdn = NULL; - int scope,attrsonly,sizelimit,timelimit,rc,searchreferral; - char **attrs=NULL; - LDAPControl **controls=NULL; - LDAPControl **ctrls=NULL; - LDAP *ld=NULL; - cb_backend_instance *cb = NULL; - cb_searchContext *ctx=NULL; - struct timeval timeout; - time_t optime; - int doit,parse_rc; - LDAPMessage *res=NULL; - char *matched_msg,*error_msg; - LDAPControl **serverctrls=NULL; - char **referrals=NULL; - char *cnxerrbuf=NULL; - time_t endbefore=0; - time_t endtime = 0; - cb_outgoing_conn *cnx; +{ + cb_backend_instance *cb = NULL; + cb_outgoing_conn *cnx; + cb_searchContext *ctx = NULL; + Slapi_Backend *be; + Slapi_Operation *op; + LDAPControl **serverctrls = NULL; + LDAPControl **controls = NULL; + LDAPControl **ctrls = NULL; + LDAPMessage *res = NULL; + LDAP *ld = NULL; + Slapi_DN *target_sdn = NULL; + const char *target = NULL; + char *filter; + char **attrs = NULL; + struct timeval timeout; + time_t optime; + time_t endbefore = 0; + time_t endtime = 0; + char *matched_msg, *error_msg; + char **referrals = NULL; + char *cnxerrbuf = NULL; + int scope, attrsonly, sizelimit, timelimit, searchreferral; + int rc, parse_rc, doit; slapi_pblock_get( pb, SLAPI_BACKEND, &be ); cb = cb_get_instance(be); @@ -92,53 +91,50 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) target = slapi_sdn_get_dn(target_sdn); if ( LDAP_SUCCESS != (parse_rc=cb_forward_operation(pb) )) { - /* Don't return errors */ - if (cb_debug_on()) { slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, "local search: base:<%s> scope:<%s> filter:<%s>\n",target, scope==LDAP_SCOPE_SUBTREE?"SUBTREE":scope==LDAP_SCOPE_ONELEVEL ? "ONE-LEVEL" : "BASE" , filter); } - ctx = (cb_searchContext *)slapi_ch_calloc(1,sizeof(cb_searchContext)); - ctx->type = CB_SEARCHCONTEXT_ENTRY; - ctx->data=NULL; - - slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); - return 0; - } + ctx = (cb_searchContext *)slapi_ch_calloc(1,sizeof(cb_searchContext)); + ctx->type = CB_SEARCHCONTEXT_ENTRY; + ctx->data=NULL; + slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); + + return 0; + } - cb_update_monitor_info(pb,cb,SLAPI_OPERATION_SEARCH); + cb_update_monitor_info(pb,cb,SLAPI_OPERATION_SEARCH); /* Check wether the chaining BE is available or not */ - if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){ - return -1; - } + if ( cb_check_availability( cb, pb ) == FARMSERVER_UNAVAILABLE ){ + return -1; + } if (cb_debug_on()) { - slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, - "chained search: base:<%s> scope:<%s> filter:<%s>\n",target, - scope==LDAP_SCOPE_SUBTREE?"SUBTREE":scope==LDAP_SCOPE_ONELEVEL ? "ONE-LEVEL" : "BASE" , filter); + slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, + "chained search: base:<%s> scope:<%s> filter:<%s>\n",target, + scope==LDAP_SCOPE_SUBTREE ? "SUBTREE": scope==LDAP_SCOPE_ONELEVEL ? "ONE-LEVEL" : "BASE", + filter); } - slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, &attrs ); - slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly ); - slapi_pblock_get( pb, SLAPI_REQCONTROLS, &controls ); - slapi_pblock_get( pb, SLAPI_SEARCH_TIMELIMIT, &timelimit ); - slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit ); - slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,NULL); - + slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, &attrs ); + slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly ); + slapi_pblock_get( pb, SLAPI_REQCONTROLS, &controls ); + slapi_pblock_get( pb, SLAPI_SEARCH_TIMELIMIT, &timelimit ); + slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit ); + slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,NULL); if ((scope != LDAP_SCOPE_BASE) && (scope != LDAP_SCOPE_ONELEVEL) && (scope != LDAP_SCOPE_SUBTREE)) { - cb_send_ldap_result( pb, LDAP_PROTOCOL_ERROR, NULL, "Bad scope", 0, NULL ); + cb_send_ldap_result( pb, LDAP_PROTOCOL_ERROR, NULL, "Bad scope", 0, NULL ); return 1; } searchreferral=cb->searchreferral; if (( scope != LDAP_SCOPE_BASE ) && ( searchreferral )) { - int i; struct berval bv,*bvals[2]; Slapi_Entry ** aciArray=(Slapi_Entry **) slapi_ch_malloc(2*sizeof(Slapi_Entry *)); @@ -168,9 +164,8 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) ctx = (cb_searchContext *)slapi_ch_calloc(1,sizeof(cb_searchContext)); ctx->type = CB_SEARCHCONTEXT_ENTRY; ctx->data=aciArray; - - slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); - return 0; + slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); + return 0; } /* @@ -184,9 +179,9 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) time_t now=current_time(); endbefore=optime + timelimit; if (now >= endbefore) { - cb_send_ldap_result( pb, LDAP_TIMELIMIT_EXCEEDED, NULL,NULL, 0, NULL); - slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, NULL ); - return 1; + cb_send_ldap_result( pb, LDAP_TIMELIMIT_EXCEEDED, NULL,NULL, 0, NULL); + slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, NULL ); + return 1; } timeout.tv_sec=(time_t)timelimit-(now-optime); timeout.tv_usec=0; @@ -200,20 +195,15 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) if ( (attrs == NULL) && operation_is_flag_set(op, OP_FLAG_INTERNAL) ) { attrs = cb->every_attribute; - - } - else - { + } else { int i; - if ( attrs != NULL ) - { + if ( attrs != NULL ) { for ( i = 0; attrs[i] != NULL; i++ ) { - if ( strcasecmp( "nsrole", attrs[i] ) == 0 ) - { + if ( strcasecmp( "nsrole", attrs[i] ) == 0 ){ attrs = cb->every_attribute; break; } - } + } } } @@ -245,19 +235,19 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) */ if ( LDAP_SUCCESS != (rc = cb_update_controls( pb,ld,&ctrls,CB_UPDATE_CONTROLS_ADDAUTH ))) { - cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); - cb_release_op_connection(cb->pool,ld,0); - return 1; - } - - if ( slapi_op_abandoned( pb )) { - cb_release_op_connection(cb->pool,ld,0); - if ( NULL != ctrls) - ldap_controls_free(ctrls); - return 1; + cb_send_ldap_result( pb, rc, NULL,NULL, 0, NULL); + cb_release_op_connection(cb->pool,ld,0); + return 1; + } + + if ( slapi_op_abandoned( pb )) { + cb_release_op_connection(cb->pool,ld,0); + if ( NULL != ctrls) + ldap_controls_free(ctrls); + return 1; } - ctx = (cb_searchContext *) slapi_ch_calloc(1,sizeof(cb_searchContext)); + ctx = (cb_searchContext *) slapi_ch_calloc(1,sizeof(cb_searchContext)); /* ** We need to store the connection handle in the search context @@ -276,14 +266,14 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) timeout.tv_sec=timeout.tv_usec=-1; /* heart-beat management */ - if (cb->max_idle_time>0) - endtime=current_time() + cb->max_idle_time; + if (cb->max_idle_time>0) + endtime=current_time() + cb->max_idle_time; - rc=ldap_search_ext(ld ,target,scope,filter,attrs,attrsonly, - ctrls, NULL, &timeout,sizelimit, &(ctx->msgid) ); + rc = ldap_search_ext(ld ,target,scope,filter,attrs,attrsonly, + ctrls, NULL, &timeout,sizelimit, &(ctx->msgid) ); - if ( NULL != ctrls) - ldap_controls_free(ctrls); + if ( NULL != ctrls) + ldap_controls_free(ctrls); if ( LDAP_SUCCESS != rc ) { cb_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL, ldap_err2string(rc), 0, NULL); @@ -299,136 +289,131 @@ chainingdb_build_candidate_list ( Slapi_PBlock *pb ) doit=1; while (doit) { + if (cb_check_forward_abandon(cb,pb,ctx->ld,ctx->msgid)) { + slapi_ch_free((void **) &ctx); + return 1; + } - if (cb_check_forward_abandon(cb,pb,ctx->ld,ctx->msgid)) { - slapi_ch_free((void **) &ctx); - return 1; - } + rc = ldap_result(ld,ctx->msgid,LDAP_MSG_ONE,&cb->abandon_timeout,&res); + switch ( rc ) { + case -1: + /* An error occurred. return now */ + rc = slapi_ldap_get_lderrno(ld,NULL,NULL); + /* tuck away some errors in a OPERATION_ERROR */ + if (CB_LDAP_CONN_ERROR(rc)) { + cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, + ldap_err2string( rc ), 0, NULL); + } else { + 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); + slapi_ch_free((void **)&ctx); + return 1; - rc=ldap_result(ld,ctx->msgid,LDAP_MSG_ONE,&cb->abandon_timeout,&res); - switch ( rc ) { - case -1: - /* An error occurred. return now */ - rc = slapi_ldap_get_lderrno(ld,NULL,NULL); - /* tuck away some errors in a OPERATION_ERROR */ - if (CB_LDAP_CONN_ERROR(rc)) { - cb_send_ldap_result(pb,LDAP_OPERATIONS_ERROR, NULL, - ldap_err2string( rc ), 0, NULL); - } else { - 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); - slapi_ch_free((void **)&ctx); - return 1; - case 0: - - /* Local timeout management */ - if (timelimit != -1) { - if (current_time() > endbefore) { - - slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, - "Local timeout expiration\n"); - - cb_send_ldap_result(pb,LDAP_TIMELIMIT_EXCEEDED, - NULL,NULL, 0, NULL); - /* Force connection close */ - cb_release_op_connection(cb->pool,ld,1); - if (res) - ldap_msgfree(res); - slapi_ch_free((void **)&ctx); - return 1; - } - } - /* heart-beat management */ - if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { - 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); - slapi_ch_free((void **)&ctx); - return 1; + case 0: + /* Local timeout management */ + if (timelimit != -1) { + if (current_time() > endbefore) { + slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, + "Local timeout expiration\n"); + cb_send_ldap_result(pb,LDAP_TIMELIMIT_EXCEEDED, + NULL,NULL, 0, NULL); + /* Force connection close */ + cb_release_op_connection(cb->pool,ld,1); + if (res) + ldap_msgfree(res); + slapi_ch_free((void **)&ctx); + return 1; } + } + /* heart-beat management */ + if ((rc=cb_ping_farm(cb,cnx,endtime)) != LDAP_SUCCESS) { + 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); + slapi_ch_free((void **)&ctx); + return 1; + } #ifdef CB_YIELD - DS_Sleep(PR_INTERVAL_NO_WAIT); + DS_Sleep(PR_INTERVAL_NO_WAIT); #endif - break; - case LDAP_RES_SEARCH_ENTRY: - case LDAP_RES_SEARCH_REFERENCE: - /* Some results received */ - /* don't parse result here */ - ctx->pending_result=res; - ctx->pending_result_type=rc; - doit=0; - break; - case LDAP_RES_SEARCH_RESULT: + break; + + case LDAP_RES_SEARCH_ENTRY: + case LDAP_RES_SEARCH_REFERENCE: + /* Some results received */ + /* don't parse result here */ + ctx->pending_result=res; + ctx->pending_result_type=rc; + doit = 0; + break; + + case LDAP_RES_SEARCH_RESULT: + matched_msg=NULL; + error_msg=NULL; + referrals=NULL; + serverctrls=NULL; + parse_rc=ldap_parse_result(ld,res,&rc,&matched_msg, + &error_msg,&referrals, &serverctrls, 0 ); + if ( parse_rc != LDAP_SUCCESS ) { + static int warned_parse_rc = 0; + if (!warned_parse_rc && error_msg) { + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + error_msg ); + warned_parse_rc = 1; + } + cb_send_ldap_result( pb, parse_rc, NULL, ENDUSERMSG, 0, NULL ); + rc=-1; + } else if ( rc != LDAP_SUCCESS ) { + static int warned_rc = 0; + if (!warned_rc) { + slapi_ldap_get_lderrno( ctx->ld, &matched_msg, &error_msg ); + slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, + "%s%s%s\n", + matched_msg?matched_msg:"", + (matched_msg&&(*matched_msg!='\0'))?": ":"", + error_msg ); + warned_rc = 1; + } + cb_send_ldap_result( pb, rc, NULL, ENDUSERMSG, 0, NULL); + /* BEWARE: matched_msg and error_msg points */ + /* to ld fields. */ matched_msg=NULL; error_msg=NULL; - referrals=NULL; - serverctrls=NULL; - parse_rc=ldap_parse_result(ld,res,&rc,&matched_msg, - &error_msg,&referrals, &serverctrls, 0 ); - if ( parse_rc != LDAP_SUCCESS ) { - static int warned_parse_rc = 0; - if (!warned_parse_rc && error_msg) { - slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - error_msg ); - warned_parse_rc = 1; - } - cb_send_ldap_result( pb, parse_rc, NULL, - ENDUSERMSG, 0, NULL ); - rc=-1; - } else if ( rc != LDAP_SUCCESS ) { - static int warned_rc = 0; - if (!warned_rc) { - slapi_ldap_get_lderrno( ctx->ld, - &matched_msg, &error_msg ); - slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM, - "%s%s%s\n", - matched_msg?matched_msg:"", - (matched_msg&&(*matched_msg!='\0'))?": ":"", - error_msg ); - warned_rc = 1; - } - cb_send_ldap_result( pb, rc, NULL, ENDUSERMSG, 0, NULL); - /* BEWARE: matched_msg and error_msg points */ - /* to ld fields. */ - matched_msg=NULL; - error_msg=NULL; - rc=-1; - } + 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); + if (rc != LDAP_SUCCESS) { + cb_release_op_connection(cb->pool,ld, + CB_LDAP_CONN_ERROR(rc)); + ldap_msgfree(res); + slapi_ch_free((void **)&ctx); + return -1; + } - slapi_ch_free((void **)&matched_msg); - slapi_ch_free((void **)&error_msg); - if (serverctrls) - ldap_controls_free(serverctrls); - if (referrals) - charray_free(referrals); - - if (rc!=LDAP_SUCCESS) { - cb_release_op_connection(cb->pool,ld, - CB_LDAP_CONN_ERROR(rc)); - ldap_msgfree(res); - slapi_ch_free((void **)&ctx); - return -1; - } - - /* Store the msg in the ctx */ - /* Parsed in iterate. */ - - ctx->pending_result=res; - ctx->pending_result_type=LDAP_RES_SEARCH_RESULT; - doit=0; + /* Store the msg in the ctx */ + /* Parsed in iterate. */ + ctx->pending_result = res; + ctx->pending_result_type = LDAP_RES_SEARCH_RESULT; + doit = 0; } } + slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); - slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET,ctx); return 0; }