Ejemplo n.º 1
0
static int sdap_sudo_schedule_smart_refresh(struct sdap_sudo_ctx *sudo_ctx,
                                            time_t delay)
{
    struct sdap_id_ctx *id_ctx = sudo_ctx->id_ctx;
    struct tevent_req *req = NULL;
    struct timeval tv;

    /* schedule new refresh */
    tv = tevent_timeval_current_ofs(delay, 0);
    req = sdap_sudo_timer_send(sudo_ctx, id_ctx->be->ev, sudo_ctx,
                               tv, delay, sdap_sudo_smart_refresh_send);
    if (req == NULL) {
        DEBUG(SSSDBG_OP_FAILURE, ("Unable to schedule smart refresh of sudo "
              "rules!\n"));
        return ENOMEM;
    }

    tevent_req_set_callback(req, sdap_sudo_periodical_smart_refresh_done,
                            sudo_ctx);

    DEBUG(SSSDBG_TRACE_FUNC, ("Smart refresh scheduled at: %lld\n",
                              (long long)tv.tv_sec));

    return EOK;
}
Ejemplo n.º 2
0
static int sdap_sudo_schedule_refresh(TALLOC_CTX *mem_ctx,
                                      struct sdap_sudo_ctx *sudo_ctx,
                                      enum sdap_sudo_refresh_type refresh,
                                      tevent_req_fn callback,
                                      time_t delay,
                                      time_t timeout,
                                      struct tevent_req **_req)
{
    struct tevent_req *req = NULL;
    sdap_sudo_timer_fn_t send_fn = NULL;
    const char *name = NULL;
    struct timeval when;

    when = tevent_timeval_current_ofs(delay, 0);

    switch (refresh) {
    case SDAP_SUDO_REFRESH_FULL:
        send_fn = sdap_sudo_full_refresh_send;
        name = "Full refresh";
        break;
    case SDAP_SUDO_REFRESH_SMART:
        send_fn = sdap_sudo_smart_refresh_send;
        name = "Smart refresh";
        break;
    case SDAP_SUDO_REFRESH_RULES:
        DEBUG(SSSDBG_OP_FAILURE, "Rules refresh can't be scheduled!\n");
        return EINVAL;
    default:
        DEBUG(SSSDBG_CRIT_FAILURE, "Unknown refresh type [%d].\n", refresh);
        return EINVAL;
    }



    req = sdap_sudo_timer_send(mem_ctx, sudo_ctx->id_ctx->be->ev, sudo_ctx,
                               when, timeout, send_fn);
    if (req == NULL) {
        return ENOMEM;
    }

    tevent_req_set_callback(req, callback, sudo_ctx);

    DEBUG(SSSDBG_TRACE_FUNC, "%s scheduled at: %lld\n",
                              name, (long long)when.tv_sec);

    if (_req != NULL) {
        *_req = req;
    }

    return EOK;
}
Ejemplo n.º 3
0
static int sdap_sudo_setup_periodical_refresh(struct sdap_sudo_ctx *sudo_ctx)
{
    struct sdap_id_ctx *id_ctx = sudo_ctx->id_ctx;
    struct tevent_req *req;
    time_t smart_default;
    time_t smart_interval;
    time_t full_interval;
    time_t last_full;
    struct timeval tv;
    int ret;

    smart_interval = dp_opt_get_int(id_ctx->opts->basic,
                                    SDAP_SUDO_SMART_REFRESH_INTERVAL);

    full_interval = dp_opt_get_int(id_ctx->opts->basic,
                                   SDAP_SUDO_FULL_REFRESH_INTERVAL);

    if (smart_interval == 0 && full_interval == 0) {
        smart_default = id_ctx->opts->basic[SDAP_SUDO_SMART_REFRESH_INTERVAL].def_val.number;

        DEBUG(SSSDBG_MINOR_FAILURE, ("At least one periodical update has to be "
              "enabled. Setting smart refresh interval to default value (%d).\n",
              smart_default));

        ret = dp_opt_set_int(id_ctx->opts->basic,
                             SDAP_SUDO_SMART_REFRESH_INTERVAL,
                             smart_default);
        if (ret != EOK) {
            return ret;
        }
    }

    if (full_interval <= smart_interval) {
        DEBUG(SSSDBG_MINOR_FAILURE, ("Full refresh interval has to be greater"
              "than smart refresh interval. Periodical full refresh will be "
              "disabled.\n"));
        ret = dp_opt_set_int(id_ctx->opts->basic,
                             SDAP_SUDO_FULL_REFRESH_INTERVAL,
                             0);
        if (ret != EOK) {
            return ret;
        }
    }

    ret = sysdb_sudo_get_last_full_refresh(id_ctx->be->sysdb, &last_full);
    if (ret != EOK) {
        return ret;
    }

    if (last_full == 0) {
        /* If this is the first startup, we need to kick off
         * an refresh immediately, to close a window where
         * clients requesting sudo information won't get an
         * immediate reply with no entries
         */
        tv = tevent_timeval_current();
    } else {
        /* At least one update has previously run,
         * so clients will get cached data.
         * We will delay the refresh so we don't slow
         * down the startup process if this is happening
         * during system boot.
         */

        /* delay at least by 10s */
        tv = tevent_timeval_current_ofs(10, 0);
    }

    req = sdap_sudo_timer_send(sudo_ctx, id_ctx->be->ev, sudo_ctx,
                               tv, full_interval,
                               sdap_sudo_full_refresh_send);
    if (req == NULL) {
        DEBUG(SSSDBG_OP_FAILURE, ("Unable to schedule full refresh of sudo "
              "rules! Periodical updates will not work!\n"));
        return ENOMEM;
    }

    tevent_req_set_callback(req, sdap_sudo_periodical_first_refresh_done,
                            sudo_ctx);

    DEBUG(SSSDBG_TRACE_FUNC, ("Full refresh scheduled at: %lld\n",
                              (long long)tv.tv_sec));

    return EOK;
}