コード例 #1
0
ファイル: sss_cache.c プロジェクト: celestian/sssd
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;
}
コード例 #2
0
ファイル: tools_util.c プロジェクト: hujon/sssd
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;
}
コード例 #3
0
ファイル: sss_seed.c プロジェクト: PallaviKumariJha/SSSD
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;
}