static void * dds_expire_fn( void *ctx, void *arg ) { struct re_s *rtask = arg; dds_info_t *di = rtask->arg; assert( di->di_expire_task == rtask ); (void)dds_expire( ctx, di ); ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) { ldap_pvt_runqueue_stoptask( &slapd_rq, rtask ); } ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); return NULL; }
void* kinit_qtask( void *ctx, void *arg ) { struct re_s *rtask = arg; kinit_data *kid = (kinit_data*)rtask->arg; krb5_error_code rc; krb5_creds creds; int nextcheck, remaining, renew=0; Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "kinit_qtask: running TGT check\n" ); memset(&creds, 0, sizeof(creds)); renew = kinit_check_tgt(kid, &remaining); if (renew > 0) { if (renew==1) { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "kinit_qtask: Trying to renew TGT: "); rc = krb5_get_renewed_creds(kid->ctx, &creds, kid->princ, kid->ccache, NULL); if (rc!=0) { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "Failed\n" ); log_krb5_errmsg( kid->ctx, "kinit_qtask, Renewal failed: krb5_get_renewed_creds", rc ); renew++; } else { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "Success\n" ); krb5_cc_initialize(kid->ctx, kid->ccache, creds.client); krb5_cc_store_cred(kid->ctx, kid->ccache, &creds); krb5_free_cred_contents(kid->ctx, &creds); renew=kinit_check_tgt(kid, &remaining); } } if (renew > 1) { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "kinit_qtask: Trying to get new TGT: "); rc = krb5_get_init_creds_keytab( kid->ctx, &creds, kid->princ, kid->keytab, 0, NULL, kid->opts); if (rc) { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "Failed\n" ); log_krb5_errmsg(kid->ctx, "krb5_get_init_creds_keytab", rc); } else { Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "Success\n" ); renew=kinit_check_tgt(kid, &remaining); } krb5_free_cred_contents(kid->ctx, &creds); } } if (renew == 0) { nextcheck = remaining-30; } else { nextcheck = 60; } ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) { ldap_pvt_runqueue_stoptask( &slapd_rq, rtask ); } Log(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "kinit_qtask: Next TGT check in %dh:%02dm:%02ds\n", nextcheck/3600, (nextcheck%3600)/60, nextcheck%60); rtask->interval.tv_sec = nextcheck; ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 ); slap_wake_listener(); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); return NULL; }
void* asyncmeta_timeout_loop(void *ctx, void *arg) { struct re_s* rtask = arg; a_metainfo_t *mi = rtask->arg; bm_context_t *bc, *onext; time_t current_time = slap_get_time(); int i, j; LDAP_STAILQ_HEAD(BCList, bm_context_t) timeout_list; LDAP_STAILQ_INIT( &timeout_list ); Debug( asyncmeta_debug, "asyncmeta_timeout_loop[%p] start at [%ld] \n", rtask, current_time ); void *oldctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx, 0); for (i=0; i<mi->mi_num_conns; i++) { a_metaconn_t * mc= &mi->mi_conns[i]; ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex ); for (bc = LDAP_STAILQ_FIRST(&mc->mc_om_list); bc; bc = onext) { onext = LDAP_STAILQ_NEXT(bc, bc_next); if (bc->bc_active > 0) { continue; } if (bc->op->o_abandon ) { /* set our memctx */ bc->op->o_threadctx = ctx; bc->op->o_tid = ldap_pvt_thread_pool_tid( ctx ); slap_sl_mem_setctx(ctx, bc->op->o_tmpmemctx); Operation *op = bc->op; LDAP_STAILQ_REMOVE(&mc->mc_om_list, bc, bm_context_t, bc_next); mc->pending_ops--; for (j=0; j<mi->mi_ntargets; j++) { if (bc->candidates[j].sr_msgid >= 0) { a_metasingleconn_t *msc = &mc->mc_conns[j]; if ( op->o_tag == LDAP_REQ_SEARCH ) { msc->msc_active++; asyncmeta_back_cancel( mc, op, bc->candidates[ j ].sr_msgid, j ); msc->msc_active--; } } } asyncmeta_clear_bm_context(bc); continue; } if (bc->bc_invalid) { LDAP_STAILQ_REMOVE(&mc->mc_om_list, bc, bm_context_t, bc_next); mc->pending_ops--; LDAP_STAILQ_INSERT_TAIL( &timeout_list, bc, bc_next); continue; } if (bc->timeout && bc->stoptime < current_time) { Operation *op = bc->op; LDAP_STAILQ_REMOVE(&mc->mc_om_list, bc, bm_context_t, bc_next); mc->pending_ops--; LDAP_STAILQ_INSERT_TAIL( &timeout_list, bc, bc_next); for (j=0; j<mi->mi_ntargets; j++) { if (bc->candidates[j].sr_msgid >= 0) { a_metasingleconn_t *msc = &mc->mc_conns[j]; asyncmeta_set_msc_time(msc); if ( op->o_tag == LDAP_REQ_SEARCH ) { msc->msc_active++; asyncmeta_back_cancel( mc, op, bc->candidates[ j ].sr_msgid, j ); msc->msc_active--; } } } } } ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex ); for (bc = LDAP_STAILQ_FIRST(&timeout_list); bc; bc = onext) { Operation *op = bc->op; SlapReply *rs = &bc->rs; int timeout_err; const char *timeout_text; onext = LDAP_STAILQ_NEXT(bc, bc_next); LDAP_STAILQ_REMOVE(&timeout_list, bc, bm_context_t, bc_next); /* set our memctx */ bc->op->o_threadctx = ctx; bc->op->o_tid = ldap_pvt_thread_pool_tid( ctx ); slap_sl_mem_setctx(ctx, bc->op->o_tmpmemctx); if (bc->searchtime) { timeout_err = LDAP_TIMELIMIT_EXCEEDED; } else { timeout_err = op->o_protocol >= LDAP_VERSION3 ? LDAP_ADMINLIMIT_EXCEEDED : LDAP_OTHER; } if ( bc->bc_invalid ) { timeout_text = "Operation is invalid - target connection has been reset"; } else { a_metasingleconn_t *log_msc = &mc->mc_conns[0]; Debug( asyncmeta_debug, "asyncmeta_timeout_loop:Timeout op %s loop[%p], " "current_time:%ld, op->o_time:%ld msc: %p, " "msc->msc_binding_time: %x, msc->msc_flags:%x \n", bc->op->o_log_prefix, rtask, current_time, bc->op->o_time, log_msc, (unsigned int)log_msc->msc_binding_time, log_msc->msc_mscflags ); if (bc->searchtime) { timeout_text = NULL; } else { timeout_text = "Operation timed out"; } for (j=0; j<mi->mi_ntargets; j++) { if (bc->candidates[j].sr_msgid >= 0) { a_metatarget_t *mt = mi->mi_targets[j]; if (!META_BACK_TGT_QUARANTINE( mt ) || bc->candidates[j].sr_type == REP_RESULT) { continue; } if (mt->mt_isquarantined > LDAP_BACK_FQ_NO) { timeout_err = LDAP_UNAVAILABLE; } else { mt->mt_timeout_ops++; if ((mi->mi_max_timeout_ops > 0) && (mt->mt_timeout_ops > mi->mi_max_timeout_ops)) { timeout_err = LDAP_UNAVAILABLE; rs->sr_err = timeout_err; if (mt->mt_isquarantined == LDAP_BACK_FQ_NO) asyncmeta_quarantine(op, mi, rs, j); } } } } } rs->sr_err = timeout_err; rs->sr_text = timeout_text; if (!bc->op->o_abandon ) { asyncmeta_send_ldap_result( bc, bc->op, &bc->rs ); } asyncmeta_clear_bm_context(bc); } ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex ); if (mi->mi_idle_timeout) { for (j=0; j<mi->mi_ntargets; j++) { a_metasingleconn_t *msc = &mc->mc_conns[j]; if ( msc->msc_active > 0 ) { continue; } if (mc->pending_ops > 0) { continue; } current_time = slap_get_time(); if (msc->msc_ld && msc->msc_time > 0 && msc->msc_time + mi->mi_idle_timeout < current_time) { asyncmeta_clear_one_msc(NULL, mc, j, 1, __FUNCTION__); } } } ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex ); } slap_sl_mem_setctx(ctx, oldctx); current_time = slap_get_time(); Debug( asyncmeta_debug, "asyncmeta_timeout_loop[%p] stop at [%ld] \n", rtask, current_time ); ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) { ldap_pvt_runqueue_stoptask( &slapd_rq, rtask ); } rtask->interval.tv_sec = 1; rtask->interval.tv_usec = 0; ldap_pvt_runqueue_resched(&slapd_rq, rtask, 0); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); return NULL; }
static int dds_cfgen( ConfigArgs *c ) { slap_overinst *on = (slap_overinst *)c->bi; dds_info_t *di = on->on_bi.bi_private; int rc = 0; unsigned long t; if ( c->op == SLAP_CONFIG_EMIT ) { char buf[ SLAP_TEXT_BUFLEN ]; struct berval bv; switch( c->type ) { case DDS_STATE: c->value_int = !DDS_OFF( di ); break; case DDS_MAXTTL: lutil_unparse_time( buf, sizeof( buf ), di->di_max_ttl ); ber_str2bv( buf, 0, 0, &bv ); value_add_one( &c->rvalue_vals, &bv ); break; case DDS_MINTTL: if ( di->di_min_ttl ) { lutil_unparse_time( buf, sizeof( buf ), di->di_min_ttl ); ber_str2bv( buf, 0, 0, &bv ); value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } break; case DDS_DEFAULTTTL: if ( di->di_default_ttl ) { lutil_unparse_time( buf, sizeof( buf ), di->di_default_ttl ); ber_str2bv( buf, 0, 0, &bv ); value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } break; case DDS_INTERVAL: if ( di->di_interval ) { lutil_unparse_time( buf, sizeof( buf ), di->di_interval ); ber_str2bv( buf, 0, 0, &bv ); value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } break; case DDS_TOLERANCE: if ( di->di_tolerance ) { lutil_unparse_time( buf, sizeof( buf ), di->di_tolerance ); ber_str2bv( buf, 0, 0, &bv ); value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } break; case DDS_MAXDYNAMICOBJS: if ( di->di_max_dynamicObjects > 0 ) { c->value_int = di->di_max_dynamicObjects; } else { rc = 1; } break; default: rc = 1; break; } return rc; } else if ( c->op == LDAP_MOD_DELETE ) { switch( c->type ) { case DDS_STATE: di->di_flags &= ~DDS_FOFF; break; case DDS_MAXTTL: di->di_min_ttl = DDS_RF2589_DEFAULT_TTL; break; case DDS_MINTTL: di->di_min_ttl = 0; break; case DDS_DEFAULTTTL: di->di_default_ttl = 0; break; case DDS_INTERVAL: di->di_interval = 0; break; case DDS_TOLERANCE: di->di_tolerance = 0; break; case DDS_MAXDYNAMICOBJS: di->di_max_dynamicObjects = 0; break; default: rc = 1; break; } return rc; } switch ( c->type ) { case DDS_STATE: if ( c->value_int ) { di->di_flags &= ~DDS_FOFF; } else { di->di_flags |= DDS_FOFF; } break; case DDS_MAXTTL: if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg), "DDS unable to parse dds-max-ttl \"%s\"", c->argv[ 1 ] ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t < DDS_RF2589_DEFAULT_TTL || t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-max-ttl=%lu; must be between %d and %d", t, DDS_RF2589_DEFAULT_TTL, DDS_RF2589_MAX_TTL ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } di->di_max_ttl = (time_t)t; break; case DDS_MINTTL: if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg), "DDS unable to parse dds-min-ttl \"%s\"", c->argv[ 1 ] ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-min-ttl=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t == 0 ) { di->di_min_ttl = DDS_RF2589_DEFAULT_TTL; } else { di->di_min_ttl = (time_t)t; } break; case DDS_DEFAULTTTL: if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg), "DDS unable to parse dds-default-ttl \"%s\"", c->argv[ 1 ] ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-default-ttl=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t == 0 ) { di->di_default_ttl = DDS_RF2589_DEFAULT_TTL; } else { di->di_default_ttl = (time_t)t; } break; case DDS_INTERVAL: if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg), "DDS unable to parse dds-interval \"%s\"", c->argv[ 1 ] ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t <= 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-interval=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t < 60 ) { Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_NOTICE, "%s: dds-interval=%lu may be too small.\n", c->log, t ); } di->di_interval = (time_t)t; if ( di->di_expire_task ) { ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); if ( ldap_pvt_runqueue_isrunning( &slapd_rq, di->di_expire_task ) ) { ldap_pvt_runqueue_stoptask( &slapd_rq, di->di_expire_task ); } di->di_expire_task->interval.tv_sec = DDS_INTERVAL( di ); ldap_pvt_runqueue_resched( &slapd_rq, di->di_expire_task, 0 ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } break; case DDS_TOLERANCE: if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg), "DDS unable to parse dds-tolerance \"%s\"", c->argv[ 1 ] ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } if ( t > DDS_RF2589_MAX_TTL ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-tolerance=%lu", t ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } di->di_tolerance = (time_t)t; break; case DDS_MAXDYNAMICOBJS: if ( c->value_int < 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "DDS invalid dds-max-dynamicObjects=%d", c->value_int ); Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "%s: %s.\n", c->log, c->cr_msg ); return 1; } di->di_max_dynamicObjects = c->value_int; break; default: rc = 1; break; } return rc; }