Beispiel #1
0
static int setup_db(struct tools_ctx *ctx)
{
    char *confdb_path;
    int ret;

    confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
    if (confdb_path == NULL) {
        return ENOMEM;
    }

    /* Connect to the conf db */
    ret = confdb_init(ctx, &ctx->confdb, confdb_path);
    if (ret != EOK) {
        DEBUG(1, ("Could not initialize connection to the confdb\n"));
        return ret;
    }

    ret = sssd_domain_init(ctx, ctx->confdb, "local", DB_PATH, &ctx->local);
    if (ret != EOK) {
        SYSDB_VERSION_ERROR(ret);
        DEBUG(1, ("Could not initialize connection to the sysdb\n"));
        return ret;
    }
    ctx->sysdb = ctx->local->sysdb;

    talloc_free(confdb_path);
    return EOK;
}
Beispiel #2
0
static errno_t init_domains(struct cache_tool_ctx *ctx,
                            const char *domain)
{
    char *confdb_path;
    int ret;
    struct sss_domain_info *dinfo;

    confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
    if (confdb_path == NULL) {
        return ENOMEM;
    }

    /* Connect to the conf db */
    ret = confdb_init(ctx, &ctx->confdb, confdb_path);
    talloc_free(confdb_path);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE,
              "Could not initialize connection to the confdb\n");
        return ret;
    }

    if (domain) {
        ret = sssd_domain_init(ctx, ctx->confdb,
                               domain, DB_PATH, &ctx->domains);
        if (ret != EOK) {
            SYSDB_VERSION_ERROR(ret);
            DEBUG(SSSDBG_CRIT_FAILURE,
                  "Could not initialize connection to the sysdb\n");
            return ret;
        }

    } else {
        ret = confdb_get_domains(ctx->confdb, &ctx->domains);
        if (ret != EOK) {
            DEBUG(SSSDBG_CRIT_FAILURE, "Could not initialize domains\n");
            return ret;
        }

        ret = sysdb_init(ctx, ctx->domains);
        SYSDB_VERSION_ERROR(ret);
        if (ret != EOK) {
            DEBUG(SSSDBG_CRIT_FAILURE,
                  "Could not initialize connection to the sysdb\n");
            return ret;
        }
    }

    for (dinfo = ctx->domains; dinfo; dinfo = get_next_domain(dinfo, 0)) {
        ret = sss_names_init(ctx, ctx->confdb, dinfo->name, &dinfo->names);
        if (ret != EOK) {
            DEBUG(SSSDBG_CRIT_FAILURE, "sss_names_init() failed\n");
            return ret;
        }
    }

    return EOK;
}
Beispiel #3
0
static int seed_init_db(TALLOC_CTX *mem_ctx,
                        const char *domain_name,
                        struct confdb_ctx **_confdb,
                        struct sss_domain_info **_domain,
                        struct sysdb_ctx **_sysdb)
{
    TALLOC_CTX *tmp_ctx = NULL;
    char *confdb_path = NULL;
    struct confdb_ctx *confdb = NULL;
    struct sss_domain_info *domain = NULL;
    int ret = EOK;

    tmp_ctx = talloc_new(NULL);
    if (tmp_ctx == NULL) {
        ret = ENOMEM;
        goto done;
    }

    /* setup confdb */
    confdb_path = talloc_asprintf(tmp_ctx, "%s/%s", DB_PATH, CONFDB_FILE);
    if (confdb_path == NULL) {
        ret = ENOMEM;
        goto done;
    }

    ret = confdb_init(tmp_ctx, &confdb, confdb_path);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE,
              ("Could not initialize connection to the confdb\n"));
        ERROR("Could not initialize connection to the confdb\n");
        goto done;
    }

    ret = sssd_domain_init(tmp_ctx, confdb, domain_name, DB_PATH, &domain);
    if (ret != EOK) {
        SYSDB_VERSION_ERROR(ret);
        DEBUG(SSSDBG_CRIT_FAILURE,
              ("Could not initialize connection to domain '%s' in sysdb.%s\n",
               domain_name, ret == ENOENT ? " Domain not found." : ""));
        ERROR("Could not initialize connection to domain '%1$s' in sysdb.%2$s\n",
              domain_name, ret == ENOENT ? " Domain not found." : "");

        goto done;
    }

    *_confdb = talloc_steal(mem_ctx, confdb);
    *_domain = domain;
    *_sysdb = domain->sysdb;

done:
    talloc_free(tmp_ctx);
    return ret;
}
Beispiel #4
0
void setup_simple(void)
{
    errno_t ret;
    char *conf_db;
    const char *val[2];
    val[1] = NULL;

    fail_unless(test_ctx == NULL, "Simple context already initialized.");
    test_ctx = talloc_zero(NULL, struct simple_test_ctx);
    fail_unless(test_ctx != NULL, "Cannot create simple test context.");

    test_ctx->ev = tevent_context_init(test_ctx);
    fail_unless(test_ctx->ev != NULL, "Cannot create tevent context.");

    test_ctx->ctx = talloc_zero(test_ctx, struct simple_ctx);
    fail_unless(test_ctx->ctx != NULL, "Cannot create simple context.");

    /* Create tests directory if it doesn't exist */
    /* (relative to current dir) */
    ret = mkdir(TESTS_PATH, 0775);
    fail_if(ret == -1 && errno != EEXIST,
            "Could not create %s directory", TESTS_PATH);

    conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
    fail_if(conf_db == NULL, "Out of memory, aborting!");
    DEBUG(SSSDBG_TRACE_LIBS, "CONFDB: %s\n", conf_db);

    /* Connect to the conf db */
    ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
    fail_if(ret != EOK, "Could not initialize connection to the confdb");

    val[0] = "LOCAL";
    ret = confdb_add_param(test_ctx->confdb, true,
                           "config/sssd", "domains", val);
    fail_if(ret != EOK, "Could not initialize domains placeholder");

    val[0] = "local";
    ret = confdb_add_param(test_ctx->confdb, true,
                           "config/domain/LOCAL", "id_provider", val);
    fail_if(ret != EOK, "Could not initialize provider");

    val[0] = "TRUE";
    ret = confdb_add_param(test_ctx->confdb, true,
                           "config/domain/LOCAL", "enumerate", val);
    fail_if(ret != EOK, "Could not initialize LOCAL domain");

    val[0] = "TRUE";
    ret = confdb_add_param(test_ctx->confdb, true,
                           "config/domain/LOCAL", "cache_credentials", val);
    fail_if(ret != EOK, "Could not initialize LOCAL domain");

    ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
                           TESTS_PATH, &test_ctx->ctx->domain);
    fail_if(ret != EOK, "Could not initialize connection to the sysdb (%d)", ret);
    test_ctx->sysdb = test_ctx->ctx->domain->sysdb;
    test_ctx->ctx->domain->case_sensitive = true;
    test_ctx->ctx->domain->mpg = false; /* Simulate an LDAP domain better */

    /* be_ctx */
    test_ctx->be_ctx = talloc_zero(test_ctx, struct be_ctx);
    fail_if(test_ctx->be_ctx == NULL, "Unable to setup be_ctx");

    test_ctx->be_ctx->cdb = test_ctx->confdb;
    test_ctx->be_ctx->ev = test_ctx->ev;
    test_ctx->be_ctx->conf_path = "config/domain/LOCAL";
    test_ctx->be_ctx->domain = test_ctx->ctx->domain;

    test_ctx->ctx->be_ctx = test_ctx->be_ctx;

    ret = sss_names_init(test_ctx->ctx->domain, test_ctx->confdb,
                         "LOCAL", &test_ctx->be_ctx->domain->names);
    fail_if(ret != EOK, "Unable to setup domain names (%d)", ret);
}