Ejemplo n.º 1
0
/*
 * Public interface for adding users
 */
int useradd(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    int ret;

    ret = sysdb_add_user(sysdb, data->name, data->uid, data->gid,
                         data->gecos, data->home, data->shell, NULL, 0);
    if (ret) {
        goto done;
    }

    if (data->addgroups) {
        struct ldb_dn *member_dn;

        member_dn = sysdb_user_dn(sysdb, mem_ctx,
                                  data->domain->name, data->name);
        if (!member_dn) {
            ret = ENOMEM;
            goto done;
        }

        ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
        if (ret) {
            goto done;
        }
    }

    flush_nscd_cache(mem_ctx, NSCD_DB_PASSWD);
    flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);

done:
    return ret;
}
Ejemplo n.º 2
0
static int seed_cache_user(struct seed_ctx *sctx)
{
    bool in_transaction = false;
    int ret = EOK;
    errno_t sret;

    ret = sysdb_transaction_start(sctx->sysdb);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE, ("sysdb transaction start failure\n"));
        goto done;
    }

    in_transaction = true;

    if (sctx->user_cached == false) {
        ret = sysdb_add_user(sctx->sysdb, sctx->domain, sctx->uctx->name,
                             sctx->uctx->uid, sctx->uctx->gid,
                             sctx->uctx->gecos, sctx->uctx->home,
                             sctx->uctx->shell, NULL, NULL, 0, 0);
        if (ret != EOK) {
            DEBUG(SSSDBG_OP_FAILURE,
                  ("Failed to add user to the cache. (%d)[%s]\n",
                   ret, strerror(ret)));
            ERROR("Failed to create user cache entry\n");
            goto done;
        }
    }

    ret = sysdb_cache_password(sctx->sysdb, sctx->domain, sctx->uctx->name,
                               sctx->uctx->password);
    if (ret != EOK) {
        DEBUG(SSSDBG_OP_FAILURE, ("Failed to cache password. (%d)[%s]\n",
                                  ret, strerror(ret)));
        ERROR("Failed to cache password\n");
        goto done;
    }

    ret = sysdb_transaction_commit(sctx->sysdb);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE, ("sysdb transaction commit failure\n"));
        goto done;
    }

    in_transaction = false;

done:
    if (in_transaction == true) {
        sret = sysdb_transaction_cancel(sctx->sysdb);
        if (sret != EOK) {
            DEBUG(SSSDBG_OP_FAILURE, ("Failed to cancel transaction\n"));
        }
    }

    return ret;
}
Ejemplo n.º 3
0
static void create_users(TALLOC_CTX *mem_ctx,
                         struct sss_domain_info *domain)
{
    errno_t ret;
    char *fqname;

    for (int i = 0; i < 2; i++) {
        fqname = sss_create_internal_fqname(mem_ctx,
                                            users[i].name,
                                            domain->name);
        assert_non_null(fqname);

        ret = sysdb_add_user(domain, users[i].name, users[i].uid, users[i].gid,
                             fqname, NULL, "/bin/bash", domain->name,
                             NULL, 30, time(NULL));
        talloc_free(fqname);
        assert_int_equal(ret, EOK);
    }
}
Ejemplo n.º 4
0
/*
 * Public interface for adding users
 */
int useradd(TALLOC_CTX *mem_ctx,
            struct ops_ctx *data)
{
    int ret;

    data->sysdb_fqname = sss_create_internal_fqname(data,
                                                    data->name,
                                                    data->domain->name);
    if (data->sysdb_fqname == NULL) {
        ret = ENOMEM;
        goto done;
    }

    ret = sysdb_add_user(data->domain, data->sysdb_fqname, data->uid, data->gid,
                         data->gecos, data->home, data->shell,
                         NULL, NULL, 0, 0);
    if (ret) {
        goto done;
    }

    if (data->addgroups) {
        struct ldb_dn *member_dn;

        member_dn = sysdb_user_dn(mem_ctx, data->domain, data->sysdb_fqname);
        if (!member_dn) {
            ret = ENOMEM;
            goto done;
        }

        ret = add_to_groups(data, member_dn);
        if (ret) {
            goto done;
        }
    }

    flush_nscd_cache(NSCD_DB_PASSWD);
    flush_nscd_cache(NSCD_DB_GROUP);

done:
    return ret;
}