Example #1
0
/*
 * Public interface for deleting users
 */
int userdel(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    struct ldb_dn *user_dn;
    int ret;

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

    user_dn = sysdb_user_dn(mem_ctx, data->domain, data->sysdb_fqname);
    if (!user_dn) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Could not construct a user DN\n");
        return ENOMEM;
    }

    ret = sysdb_delete_entry(sysdb, user_dn, false);
    if (ret) {
        DEBUG(SSSDBG_OP_FAILURE,
              "Removing user failed: %s (%d)\n", strerror(ret), ret);
    }

    flush_nscd_cache(NSCD_DB_PASSWD);
    flush_nscd_cache(NSCD_DB_GROUP);

    return ret;
}
Example #2
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;
}
Example #3
0
/*
 * Public interface for modifying users
 */
int usermod(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    struct sysdb_attrs *attrs = NULL;
    struct ldb_dn *member_dn = NULL;
    int ret;

    if (data->addgroups || data->rmgroups) {
        member_dn = sysdb_user_dn(sysdb, mem_ctx,
                                  data->domain->name, data->name);
        if (!member_dn) {
            return ENOMEM;
        }
    }

    ret = usermod_build_attrs(mem_ctx,
                              data->gecos,
                              data->home,
                              data->shell,
                              data->uid,
                              data->gid,
                              data->lock,
                              &attrs);
    if (ret != EOK) {
        return ret;
    }

    if (attrs->num != 0) {
        ret = sysdb_set_user_attr(sysdb, data->name, attrs, SYSDB_MOD_REP);
        if (ret) {
            return ret;
        }
    }

    if (data->rmgroups != NULL) {
        ret = remove_from_groups(mem_ctx, sysdb, data, member_dn);
        if (ret) {
            return ret;
        }
    }

    if (data->addgroups != NULL) {
        ret = add_to_groups(mem_ctx, sysdb, data, member_dn);
        if (ret) {
            return ret;
        }
    }

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

    return EOK;
}
Example #4
0
/*
 * Public interface for modifying groups
 */
int groupmod(TALLOC_CTX *mem_ctx,
             struct ops_ctx *data)
{
    struct sysdb_attrs *attrs = NULL;
    struct ldb_dn *member_dn = NULL;
    int ret;

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

    if (data->addgroups || data->rmgroups) {
        member_dn = sysdb_group_dn(mem_ctx, data->domain, data->sysdb_fqname);
        if (!member_dn) {
            return ENOMEM;
        }
    }

    if (data->gid != 0) {
        attrs = sysdb_new_attrs(mem_ctx);
        if (!attrs) {
            return ENOMEM;
        }
        ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, data->gid);
        if (ret) {
            return ret;
        }

        ret = sysdb_set_group_attr(data->domain, data->sysdb_fqname,
                                   attrs, SYSDB_MOD_REP);
        if (ret) {
            return ret;
        }
    }

    if (data->rmgroups != NULL) {
        ret = remove_from_groups(data, member_dn);
        if (ret) {
            return ret;
        }
    }

    if (data->addgroups != NULL) {
        ret = add_to_groups(data, member_dn);
        if (ret) {
            return ret;
        }
    }

    flush_nscd_cache(NSCD_DB_GROUP);

    return EOK;
}
Example #5
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;
}
Example #6
0
/*
 * Public interface for adding groups
 */
int groupadd(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    int ret;

    ret = sysdb_add_group(sysdb, data->name, data->gid, NULL, 0);
    if (ret == EOK) {
        flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
    }
    return ret;
}
Example #7
0
/*
 * Public interface for adding groups
 */
int groupadd(struct sysdb_ctx *sysdb,
             struct ops_ctx *data)
{
    int ret;

    ret = sysdb_add_group(sysdb, data->domain,
                          data->name, data->gid, NULL, 0, 0);
    if (ret == EOK) {
        flush_nscd_cache(NSCD_DB_GROUP);
    }
    return ret;
}
Example #8
0
/*
 * Public interface for deleting users
 */
int userdel(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    struct ldb_dn *user_dn;
    int ret;

    user_dn = sysdb_user_dn(sysdb, mem_ctx, data->domain, data->name);
    if (!user_dn) {
        DEBUG(1, ("Could not construct a user DN\n"));
        return ENOMEM;
    }

    ret = sysdb_delete_entry(sysdb, user_dn, false);
    if (ret) {
        DEBUG(2, ("Removing user failed: %s (%d)\n", strerror(ret), ret));
    }

    flush_nscd_cache(NSCD_DB_PASSWD);
    flush_nscd_cache(NSCD_DB_GROUP);

    return ret;
}
Example #9
0
/*
 * Public interface for adding groups
 */
int groupadd(struct ops_ctx *data)
{
    int ret;

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

    ret = sysdb_add_group(data->domain, data->sysdb_fqname, data->gid, NULL, 0, 0);
    if (ret == EOK) {
        flush_nscd_cache(NSCD_DB_GROUP);
    }
    return ret;
}
Example #10
0
/*
 * Public interface for deleting groups
 */
int groupdel(TALLOC_CTX *mem_ctx,
            struct sysdb_ctx *sysdb,
            struct ops_ctx *data)
{
    struct ldb_dn *group_dn;
    int ret;

    group_dn = sysdb_group_dn(sysdb, mem_ctx, data->domain, data->name);
    if (group_dn == NULL) {
        DEBUG(1, ("Could not construct a group DN\n"));
        return ENOMEM;
    }

    ret = sysdb_delete_entry(sysdb, group_dn, false);
    if (ret) {
        DEBUG(2, ("Removing group failed: %s (%d)\n", strerror(ret), ret));
    }

    flush_nscd_cache(NSCD_DB_GROUP);

    return ret;
}