Example #1
0
errno_t krb5_install_offline_callback(struct be_ctx *be_ctx,
                                      struct krb5_ctx *krb5_ctx)
{
    int ret;
    struct remove_info_files_ctx *ctx;
    const char *krb5_realm;

    if (krb5_ctx->service == NULL || krb5_ctx->service->name == NULL) {
        DEBUG(1, ("Missing KDC service name!\n"));
        return EINVAL;
    }

    ctx = talloc_zero(krb5_ctx, struct remove_info_files_ctx);
    if (ctx == NULL) {
        DEBUG(1, ("talloc_zfree failed.\n"));
        return ENOMEM;
    }

    krb5_realm = dp_opt_get_cstring(krb5_ctx->opts, KRB5_REALM);
    if (krb5_realm == NULL) {
        DEBUG(1, ("Missing krb5_realm option!\n"));
        ret = EINVAL;
        goto done;
    }

    ctx->realm = talloc_strdup(ctx, krb5_realm);
    if (ctx->realm == NULL) {
        DEBUG(1, ("talloc_strdup failed!\n"));
        ret = ENOMEM;
        goto done;
    }

    ctx->be_ctx = be_ctx;
    ctx->kdc_service_name = krb5_ctx->service->name;
    if (krb5_ctx->kpasswd_service == NULL) {
        ctx->kpasswd_service_name =NULL;
    } else {
        ctx->kpasswd_service_name = krb5_ctx->kpasswd_service->name;
    }

    ret = be_add_offline_cb(ctx, be_ctx, remove_krb5_info_files_callback, ctx,
                            NULL);
    if (ret != EOK) {
        DEBUG(1, ("be_add_offline_cb failed.\n"));
        goto done;
    }

    ret = EOK;

done:
    if (ret != EOK) {
        talloc_zfree(ctx);
    }

    return ret;
}
Example #2
0
errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
                        struct be_ctx *be_ctx,
                        time_t period,
                        time_t first_delay,
                        time_t enabled_delay,
                        time_t random_offset,
                        time_t timeout,
                        enum be_ptask_offline offline,
                        time_t max_backoff,
                        be_ptask_send_t send_fn,
                        be_ptask_recv_t recv_fn,
                        void *pvt,
                        const char *name,
                        struct be_ptask **_task)
{
    struct be_ptask *task = NULL;
    errno_t ret;

    if (be_ctx == NULL || period == 0 || send_fn == NULL || recv_fn == NULL
        || name == NULL) {
        return EINVAL;
    }

    task = talloc_zero(mem_ctx, struct be_ptask);
    if (task == NULL) {
        ret = ENOMEM;
        goto done;
    }

    task->ev = be_ctx->ev;
    task->be_ctx = be_ctx;
    task->period = period;
    task->orig_period = period;
    task->first_delay = first_delay;
    task->enabled_delay = enabled_delay;
    task->random_offset = random_offset;
    task->ro_seed = time(NULL) * getpid();
    task->max_backoff = max_backoff;
    task->timeout = timeout;
    task->offline = offline;
    task->send_fn = send_fn;
    task->recv_fn = recv_fn;
    task->pvt = pvt;
    task->name = talloc_strdup(task, name);
    if (task->name == NULL) {
        ret = ENOMEM;
        goto done;
    }

    task->enabled = true;

    talloc_set_destructor((TALLOC_CTX*)task, be_ptask_destructor);

    if (offline == BE_PTASK_OFFLINE_DISABLE) {
        /* install offline and online callbacks */
        ret = be_add_online_cb(task, be_ctx, be_ptask_online_cb, task, NULL);
        if (ret != EOK) {
            DEBUG(SSSDBG_OP_FAILURE,
                  "Unable to install online callback [%d]: %s\n",
                  ret, sss_strerror(ret));
            goto done;
        }

        ret = be_add_offline_cb(task, be_ctx, be_ptask_offline_cb, task, NULL);
        if (ret != EOK) {
            DEBUG(SSSDBG_OP_FAILURE,
                  "Unable to install offline callback [%d]: %s\n",
                  ret, sss_strerror(ret));
            goto done;
        }
    }

    DEBUG(SSSDBG_TRACE_FUNC, "Periodic task [%s] was created\n", task->name);

    be_ptask_schedule(task, BE_PTASK_FIRST_DELAY, BE_PTASK_SCHEDULE_FROM_NOW);

    if (_task != NULL) {
        *_task = task;
    }

    ret = EOK;

done:
    if (ret != EOK) {
        talloc_free(task);
    }

    return ret;
}