static void sdap_sudo_periodical_first_refresh_done(struct tevent_req *req) { struct tevent_req *subreq = NULL; /* req from sdap_sudo_full_refresh_send() */ struct sdap_sudo_ctx *sudo_ctx = NULL; time_t delay; int dp_error = DP_ERR_OK; int error = EOK; int ret; ret = sdap_sudo_timer_recv(req, req, &subreq); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Sudo timer failed [%d]: %s\n", ret, strerror(ret))); goto schedule; } ret = sdap_sudo_full_refresh_recv(subreq, &dp_error, &error); if (dp_error != DP_ERR_OK || error != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Periodical full refresh of sudo rules " "failed [dp_error: %d] ([%d]: %s)\n", dp_error, error, strerror(error))); goto schedule; } schedule: sudo_ctx = tevent_req_callback_data(req, struct sdap_sudo_ctx); talloc_zfree(req); /* full refresh */ delay = dp_opt_get_int(sudo_ctx->id_ctx->opts->basic, SDAP_SUDO_FULL_REFRESH_INTERVAL); if (delay == 0) { /* runtime configuration change? */ DEBUG(SSSDBG_TRACE_FUNC, ("Periodical full refresh of sudo rules " "is disabled\n")); return; } ret = sdap_sudo_schedule_full_refresh(sudo_ctx, delay); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Full periodical refresh will not work.\n")); } /* smart refresh */ delay = dp_opt_get_int(sudo_ctx->id_ctx->opts->basic, SDAP_SUDO_SMART_REFRESH_INTERVAL); if (delay == 0) { /* runtime configuration change? */ DEBUG(SSSDBG_TRACE_FUNC, ("Periodical smart refresh of sudo rules " "is disabled\n")); return; } ret = sdap_sudo_schedule_smart_refresh(sudo_ctx, delay); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Smart periodical refresh will not work.\n")); } }
static void sdap_sudo_periodical_first_refresh_done(struct tevent_req *req) { struct tevent_req *subreq = NULL; /* req from sdap_sudo_full_refresh_send() */ struct sdap_sudo_ctx *sudo_ctx = NULL; time_t delay; time_t timeout; int dp_error = DP_ERR_OK; int error = EOK; int ret; ret = sdap_sudo_timer_recv(req, req, &subreq); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Sudo timer failed [%d]: %s\n", ret, strerror(ret)); goto schedule; } ret = sdap_sudo_full_refresh_recv(subreq, &dp_error, &error); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Periodical full refresh of sudo rules " "failed [%d]: %s)\n", ret, strerror(ret)); goto schedule; } if (dp_error != DP_ERR_OK || error != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Periodical full refresh of sudo rules " "failed [dp_error: %d] ([%d]: %s)\n", dp_error, error, strerror(error)); goto schedule; } schedule: sudo_ctx = tevent_req_callback_data(req, struct sdap_sudo_ctx); if (sudo_ctx->first_refresh_timer == req) { sudo_ctx->first_refresh_timer = NULL; } talloc_zfree(req); /* full refresh */ delay = dp_opt_get_int(sudo_ctx->id_ctx->opts->basic, SDAP_SUDO_FULL_REFRESH_INTERVAL); if (delay == 0) { /* runtime configuration change? */ DEBUG(SSSDBG_TRACE_FUNC, "Periodical full refresh of sudo rules " "is disabled\n"); return; } /* if we are offline, we will try to perform another full refresh */ if (dp_error == DP_ERR_OFFLINE) { sudo_ctx->full_refresh_attempts++; timeout = delay; delay = sudo_ctx->full_refresh_attempts << 1; if (delay > SUDO_MAX_FIRST_REFRESH_DELAY) { delay = SUDO_MAX_FIRST_REFRESH_DELAY; } DEBUG(SSSDBG_TRACE_FUNC, "Data provider is offline. " "Scheduling another full refresh in %ld minutes.\n", delay); ret = sdap_sudo_schedule_refresh(sudo_ctx, sudo_ctx, SDAP_SUDO_REFRESH_FULL, sdap_sudo_periodical_first_refresh_done, delay * 60, timeout, &sudo_ctx->first_refresh_timer); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Unable to schedule full refresh of sudo " "rules! Periodical updates will not work!\n"); } /* also setup online callback to make sure the refresh is fired as soon * as possible */ ret = be_add_online_cb(sudo_ctx->id_ctx->be, sudo_ctx->id_ctx->be, sdap_sudo_full_refresh_online_cb, sudo_ctx, &sudo_ctx->first_refresh_online_cb); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Could not set up online callback\n"); } return; } ret = sdap_sudo_schedule_full_refresh(sudo_ctx, delay); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Full periodical refresh will not work.\n"); } /* smart refresh */ delay = dp_opt_get_int(sudo_ctx->id_ctx->opts->basic, SDAP_SUDO_SMART_REFRESH_INTERVAL); if (delay == 0) { /* runtime configuration change? */ DEBUG(SSSDBG_TRACE_FUNC, "Periodical smart refresh of sudo rules " "is disabled\n"); return; } ret = sdap_sudo_schedule_smart_refresh(sudo_ctx, delay); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Smart periodical refresh will not work.\n"); } }