sysdb-tests.c revision 09d7c105839bfc7447ea0f766413ed86675ca075
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht System Database
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maeder Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is free software; you can redistribute it and/or modify
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht it under the terms of the GNU General Public License as published by
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht the Free Software Foundation; either version 3 of the License, or
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht (at your option) any later version.
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is distributed in the hope that it will be useful,
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht but WITHOUT ANY WARRANTY; without even the implied warranty of
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht GNU General Public License for more details.
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht You should have received a copy of the GNU General Public License
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht along with this program. If not, see <http://www.gnu.org/licenses/>.
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define TEST_ATTR_UPDATE_VALUE "test_attr_update_value"
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define TEST_ATTR_ADD_NAME "test_attr_add_name"
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define TEST_ATTR_ADD_VALUE "test_attr_add_value"
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht#define CUSTOM_TEST_CONTAINER "custom_test_container"
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht#define CUSTOM_TEST_OBJECT "custom_test_object"
765f0ff34c8f2354a4e8a4fbb4467ec5e788c55fSimon Ulbrichtstatic int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
846ef0914b29a4806ca0444c116fd3cf267c4fb7Christian Maeder /* Create tests directory if it doesn't exist */
e90b8ee3fac5c932d83af2061579c6b57d528885Christian Maeder /* (relative to current dir) */
846ef0914b29a4806ca0444c116fd3cf267c4fb7Christian Maeder fail("Could not create %s directory", TESTS_PATH);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht test_ctx = talloc_zero(NULL, struct sysdb_test_ctx);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht fail("Could not allocate memory for test context");
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht /* Create an event context
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht * It will not be used except in confdb_init and sysdb_init
846ef0914b29a4806ca0444c116fd3cf267c4fb7Christian Maeder test_ctx->ev = tevent_context_init(test_ctx);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht /* Connect to the conf db */
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht fail("Could not initialize connection to the confdb");
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht ret = confdb_add_param(test_ctx->confdb, true,
8600e22385bce13c5d1048f7b955f9394a5d94d6Simon Ulbricht fail("Could not initialize domains placeholder");
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = confdb_add_param(test_ctx->confdb, true,
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht ret = confdb_add_param(test_ctx->confdb, true,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht ret = confdb_add_param(test_ctx->confdb, true,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht "config/domain/LOCAL", "cache_credentials", val);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht fail("Could not initialize connection to the sysdb (%d)", ret);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht#define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbrichtstatic int test_add_user(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht gecos = talloc_asprintf(data, "Test User %d", data->uid);
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht ret = sysdb_add_user(data->ctx->sysdb, data->ctx->domain, data->username,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_store_user(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht gecos = talloc_asprintf(data, "Test User %d", data->uid);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = sysdb_store_user(data->ctx->sysdb, data->ctx->domain,
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbrichtstatic int test_remove_user(struct test_data *data)
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbricht user_dn = sysdb_user_dn(data->ctx->sysdb, data,
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht ret = sysdb_delete_entry(data->ctx->sysdb, user_dn, true);
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbrichtstatic int test_remove_user_by_uid(struct test_data *data)
5917663ca76c8f8b60b767f7fb959f1d1609576bSimon Ulbrichtstatic int test_remove_nonexistent_group(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_remove_nonexistent_user(struct test_data *data)
5917663ca76c8f8b60b767f7fb959f1d1609576bSimon Ulbrichtstatic int test_add_group(struct test_data *data)
96a17035df49356b70d7ac14bd9f4d52a5f0308dSimon Ulbricht ret = sysdb_add_group(data->ctx->sysdb, data->ctx->domain,
30b3567d60173c99ef8db1f0a1d8bda73a4225fdSimon Ulbricht data->groupname, data->gid, data->attrs, 0, 0);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_add_incomplete_group(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_add_incomplete_group(data->ctx->sysdb,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_store_group(struct test_data *data)
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht ret = sysdb_store_group(data->ctx->sysdb, data->ctx->domain,
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht data->groupname, data->gid, data->attrs, -1, 0);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_remove_group(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht group_dn = sysdb_group_dn(data->ctx->sysdb, data,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_delete_entry(data->ctx->sysdb, group_dn, true);
3c606bbc21a488c9eaebbfcd833b0b31af25341aSimon Ulbrichtstatic int test_remove_group_by_gid(struct test_data *data)
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbrichtstatic int test_set_user_attr(struct test_data *data)
e3d7fd1b63d824960b1c17b6c7009d52d7528c1eChristian Maederstatic int test_add_group_member(struct test_data *data)
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maeder username = talloc_asprintf(data, "testuser%d", data->uid);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_add_group_member(data->ctx->sysdb, data->ctx->domain,
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbrichtstatic int test_remove_group_member(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht username = talloc_asprintf(data, "testuser%d", data->uid);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = sysdb_remove_group_member(data->ctx->sysdb, data->ctx->domain,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic int test_store_custom(struct test_data *data)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, data->uid);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht ret = sysdb_store_custom(data->ctx->sysdb, data->ctx->domain, object_name,
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtstatic int test_delete_custom(struct test_data *data)
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht ret = sysdb_delete_custom(data->ctx->sysdb, data->ctx->domain,
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbrichtstatic int test_search_all_users(struct test_data *data)
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht base_dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_TMPL_USER_BASE,
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht ret = sysdb_search_entry(data, data->ctx->sysdb, base_dn,
67c57fe89afed0947d5ff8fc8b04c4ace0b9595eSimon Ulbricht data->attrlist, &data->msgs_count, &data->msgs);
c3b1c9fa0aa53167405eb9a004137fb5e327fd4fSimon Ulbrichtstatic int test_delete_recursive(struct test_data *data)
c3b1c9fa0aa53167405eb9a004137fb5e327fd4fSimon Ulbricht dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_DOM_BASE,
9458e270eb4d18c8e76fdaa569023931ca7ca8dfSimon Ulbricht ret = sysdb_delete_recursive(data->ctx->sysdb, dn, false);
return ret;
int ret;
char *member;
if (!attrs) {
return ENOMEM;
if (!member) {
return ENOMEM;
return ret;
return ret;
int ret;
char *member;
if (!attrs) {
return ENOMEM;
if (!member) {
return ENOMEM;
return ret;
return ret;
return ret;
const char *description;
int ret;
return ret;
int ret;
return ret;
int ret;
return ret;
int ret;
const char *description;
if (!attrs) {
return ENOMEM;
if (ret) {
return ret;
return ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
char *membername;
int ret;
const char *username;
int ret;
if (ret) {
goto done;
goto done;
if (ret) {
goto done;
done:
const char *groupname;
int ret;
if (ret) {
goto done;
goto done;
if (ret) {
goto done;
done:
const char *e_groupname;
const char *groupname;
int ret;
if (ret) {
goto done;
goto done;
done:
int ret;
char *filter;
const char *e_username;
const char *username;
int ret;
if (ret) {
goto done;
goto done;
done:
int ret;
&res);
int ret;
&res);
int ret;
int ret;
char *filter;
_i);
int ret;
char *username;
const char *shell;
const char *attrval;
char *username;
int ret;
if (ret) {
goto done;
done:
int ret;
int ret;
const char *username;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
char *object_name;
int ret;
int ret;
char *object_name;
int ret;
int ret;
int ret;
const char *password,
int expected_result)
int ret;
0, expire_date);
const char *password,
int expected_result)
int ret;
char *username;
char *username;
char *username;
int ret;
int ret;
char *gid_str;
for (i = 0; i < msgs_count; i++) {
int ret;
char *uid_str;
int ret;
int ret;
int ret;
if (_i == 0) {
int ret;
if (_i == 0) {
int ret;
if (_i == 0) {
char *ghostname;
int ret;
char *ghostname_del;
char *ghostname_add;
int ret;
char *ghostname_rep;
char *ghostname_del;
char *ghostname_check;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
int ret;
char *ghostname;
int ret;
int ret, j;
char *expected;
int ret;
int ret;
if (exp_gh < 0) {
exp_gh = 0;
if (exp_gh) {
char *ghostname_del;
char *ghostname_add;
int ret;
char *ghostname_del;
char *ghostname_add;
int ret;
int ret;
char **list;
list[0]);
const char *name;
goto done;
goto done;
done:
const char *name;
goto done;
goto done;
done:
char **add_groups;
char **del_groups;
(const char *const *)add_groups,
(const char *const *)del_groups);
int ret;
const char *groupname;
char *parsed;
int ret;
int ret;
const char *netgrname;
int ret;
int ret;
int ret;
int ret;
const char *description;
const char *netgrname;
const char *attrval;
const char *strdn;
const char *received_user;
const char *received_group;
bool by_name,
const char *primary_name,
int port,
const char **aliases,
const char **protocols)
bool matched;
const char *ret_name;
int ret_port;
if (by_name) {
matched = false;
for (j = 0; aliases[j]; j++) {
matched = true;
matched = false;
for (j = 0; protocols[j]; j++) {
matched = true;
char *primary_name;
const char **aliases;
const char **protocols;
NULL);
const char **aliases;
const char **protocols;
const char *alias);
const char **aliases;
const char **protocols;
NULL);
bool enumerated;
const char *filter;
"name=subdomuser,cn=users,cn=test.sub,cn=sysdb");
"name=subdomuser,cn=users,cn=test.sub,cn=sysdb");
"name=subdomgroup,cn=groups,cn=test.sub,cn=sysdb");
#ifdef BUILD_AUTOFS
const char *autofsmapname;
const char *autofsmapname;
const char *autofsmapname;
const char *autofsmapname;
const char *autofsmapname;
const char *autofskey;
const char *autofsval;
int ii;
const char *autofsmapname;
const char *autofsmapname;
const char *autofskey;
const char *autofsval;
const char *autofskey;
NULL };
const char *filter;
#ifdef BUILD_AUTOFS
int opt;
int ret;
int failure_count;
int no_cleanup = 0;
switch(opt) {
if (!ldb_modules_path_is_set()) {
return EXIT_FAILURE;