sysdb-tests.c revision 88e7576d8bf00bfd0eaed8731b7eee1d6b6e05a1
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive System Database
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
fe64b2ba25510d8c9dba5560a2d537763566cf40nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
fe64b2ba25510d8c9dba5560a2d537763566cf40nd along with this program. If not, see <http://www.gnu.org/licenses/>.
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Create tests directory if it doesn't exist */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* (relative to current dir) */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Create an event context
117c1f888a14e73cdd821dc6c23eb0411144a41cnd * It will not be used except in confdb_init and sysdb_init
117c1f888a14e73cdd821dc6c23eb0411144a41cnd conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Connect to the conf db */
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener ret = confdb_get_domain(test_ctx->confdb, "local", &test_ctx->domain);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor fail("Could not initialize connection to the sysdb (%d)", ret);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor const char *username;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *groupname;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *shell;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe const char **attrlist;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen gecos = talloc_asprintf(data, "Test User %d", data->uid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive gecos = talloc_asprintf(data, "Test User %d", data->uid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive user_dn = sysdb_user_dn(data->ctx->sysdb, data, "LOCAL", data->username);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_entry(data->ctx->sysdb, user_dn, true);
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic int test_remove_user_by_uid(struct test_data *data)
bc4b55ec8f31569d606d5680d50189a355bcd7a6rbowenstatic int test_remove_nonexistent_group(struct test_data *data)
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic int test_remove_nonexistent_user(struct test_data *data)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd group_dn = sysdb_group_dn(data->ctx->sysdb, data, "LOCAL", data->groupname);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_entry(data->ctx->sysdb, group_dn, true);
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic int test_remove_group_by_gid(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *username;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username = talloc_asprintf(data, "testuser%d", data->uid);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dndstatic int test_remove_group_member(struct test_data *data)
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd const char *username;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd username = talloc_asprintf(data, "testuser%d", data->uid);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, data->uid);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_delete_custom(data, data->ctx->sysdb, data->ctx->domain,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirierstatic int test_search_all_users(struct test_data *data)
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier base_dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_TMPL_USER_BASE,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_search_entry(data, data->ctx->sysdb, base_dn,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_DOM_BASE,
627c978514c54179736d152923478be7c8707f9bnd ret = sysdb_delete_recursive(data, data->ctx->sysdb, dn, false);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(ret == EOK, "sysdb_delete_recursive returned [%d]", ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_memberof_store_group(struct test_data *data)
ed0dae472b518c553c923a86fb4322d4c50d86a6nd member = sysdb_group_strdn(data, data->ctx->domain->name,
bed3c2e56e8f3328e780200466b9d009093db468sf ret = sysdb_attrs_steal_string(attrs, SYSDB_MEMBER, member);
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl /* Setup */
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->username = talloc_asprintf(data, "testuser%d", _i);
909ce17e2bd0faef7b1c294f2307f009793fd493nd fail_if(ret != EOK, "Could not store user %s", data->username);
97a9a944b5887e91042b019776c41d5dd74557aferikabele data->username = talloc_asprintf(data, "testuser%d", _i);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener fail_if(ret != EOK, "Could not store user %s", data->username);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
da637bcae7b6e150470e701af29da5604a34a17erbowen data->groupname = talloc_asprintf(data, "testgroup%d", _i);
da637bcae7b6e150470e701af29da5604a34a17erbowen fail_if(ret != EOK, "Could not store POSIX group #%d", _i);
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
bed3c2e56e8f3328e780200466b9d009093db468sf data->username = talloc_asprintf(data, "testuser%d", _i);
bed3c2e56e8f3328e780200466b9d009093db468sf fail_if(ret != EOK, "Could not remove user %s", data->username);
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
bed3c2e56e8f3328e780200466b9d009093db468sf fail_if(ret != EOK, "Could not remove user with uid %d", _i);
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not remove group %s", data->groupname);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not remove group with gid %d", _i);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->username = talloc_asprintf(data, "testuser%d", _i);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_if(ret != EOK, "Could not add user %s", data->username);
604c89126c27104f659d7a51b0113e3bd435faf8fielding /* Setup */
22265f1724519886e2a2b5e0ebd61477506b7379noodl data->groupname = talloc_asprintf(data, "testgroup%d", _i);
604c89126c27104f659d7a51b0113e3bd435faf8fielding fail_if(ret != EOK, "Could not add group %s", data->groupname);
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *username;
9597f440430d8c876dd64f5f78066804650a18ecnoodl /* Setup */
9597f440430d8c876dd64f5f78066804650a18ecnoodl username = talloc_asprintf(test_ctx, "testuser%d", _i);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf fail("Invalid number of replies. Expected 1, got %d", res->count);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf uid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_UIDNUM, 0);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf /* Search for the user with the wrong case */
fb77c505254b6e9c925e23e734463e87574f8f40kess const char *groupname;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive /* Setup */
130d299c4b2b15be45532a176604c71fdc7bea5bnd groupname = talloc_asprintf(test_ctx, "testgroup%d", _i);
d1348237b33bc1755b9f1165eea52317465a7671nd fail("Invalid number of replies. Expected 1, got %d", res->count);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd gid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_GIDNUM, 0);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "Did not find the expected GID (found %d expected %d)",
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Search for the group with the wrong case */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive groupname = talloc_asprintf(test_ctx, "TESTGROUP%d", _i);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *e_groupname;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *groupname;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess /* Setup */
130d299c4b2b15be45532a176604c71fdc7bea5bnd groupname = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, 0);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive e_groupname = talloc_asprintf(test_ctx, "testgroup%d", _i);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Did not find the expected groupname (found %s expected %s)",
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *e_username;
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *username;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, 0);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess e_username = talloc_asprintf(test_ctx, "testuser%d", _i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Did not find the expected username (found %s expected %s)",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor "sysdb_enumgrent failed (%d: %s)",
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener /* 10 groups + 10 users (we're MPG) */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(res->count != 20, "Expected 20 users, got %d", res->count);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fb77c505254b6e9c925e23e734463e87574f8f40kess "sysdb_enumpwent failed (%d: %s)",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_if(res->count != 10, "Expected 10 users, got %d", res->count);
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen /* Setup */
8559a67073808d84d85bb5dd552d4247caafe709sf data->username = talloc_asprintf(data, "testuser%d", _i);
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(ret != EOK, "Could not modify user %s", data->username);
8559a67073808d84d85bb5dd552d4247caafe709sf const char *attrval;
8559a67073808d84d85bb5dd552d4247caafe709sf /* Setup */
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid number of entries, expected 1, got %d", res->count);
8559a67073808d84d85bb5dd552d4247caafe709sf attrval = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf /* Setup */
8559a67073808d84d85bb5dd552d4247caafe709sf data->groupname = talloc_asprintf(data, "testgroup%d", _i);
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(ret != EOK, "Could not modify group %s", data->groupname);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
9bcfc3697a91b5215893a7d0206865b13fc72148nd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier /* Setup */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh /* Setup */
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick /* Setup */
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->attrlist = talloc_array(test_ctx, const char *, 2);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(data->attrlist != NULL, "talloc_array failed");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(object_name != NULL, "talloc_asprintf failed");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = sysdb_search_custom_by_name(data, data->ctx->sysdb,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_if(ret != EOK, "Could not search custom object");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Wrong number of objects, exptected [1] got [%d]",
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Wrong number of results, expected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strcmp(data->msgs[0]->elements[0].name, TEST_ATTR_NAME) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong attribute name");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strncmp((const char *)data->msgs[0]->elements[0].values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong attribute value");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive data->attrlist = talloc_array(test_ctx, const char *, 3);
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive fail_unless(data->attrlist != NULL, "talloc_array failed");
59cd19c3d75e35ae820e23f6b0161910784fce4eslive object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010);
59cd19c3d75e35ae820e23f6b0161910784fce4eslive fail_unless(object_name != NULL, "talloc_asprintf failed");
59cd19c3d75e35ae820e23f6b0161910784fce4eslive ret = sysdb_search_custom_by_name(data, data->ctx->sysdb,
59cd19c3d75e35ae820e23f6b0161910784fce4eslive fail_if(ret != EOK, "Could not search custom object");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of objects, exptected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of results, expected [2] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Wrong attribute value");
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_ADD_NAME);
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_ADD_NAME);
fb109b84906e3ee61680aa289953c2f9e859354erbowen fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) "
fb109b84906e3ee61680aa289953c2f9e859354erbowen fail_unless(strncmp((const char *) el->values[0].data,
db2474c3448fc75c325aa43ba0144fced1a38c53rjung "Wrong attribute value");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick data->attrlist = talloc_array(test_ctx, const char *, 3);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(data->attrlist != NULL, "talloc_array failed");
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin fail_if(ret != EOK, "Could not search custom object");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "Wrong number of objects, exptected [10] got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
2bb4320391b88748dc6e851deca941b058231664rbowen fail_unless(ret == EOK, "Could not set up the test");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->username = talloc_asprintf(data, "testuser%d", _i);
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen fail_unless(ret == EOK, "sysdb_cache_password request failed [%d].", ret);
2bb4320391b88748dc6e851deca941b058231664rbowenstatic void cached_authentication_without_expiration(const char *username,
2bb4320391b88748dc6e851deca941b058231664rbowen const char *password,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
2bb4320391b88748dc6e851deca941b058231664rbowen ret = confdb_add_param(test_ctx->confdb, true, CONFDB_PAM_CONF_ENTRY,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == expected_result, "sysdb_cache_auth request does not "
2bb4320391b88748dc6e851deca941b058231664rbowen "return expected result [%d].",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(expire_date == 0, "Wrong expire date, expected [%d], got [%d]",
2bb4320391b88748dc6e851deca941b058231664rbowen fail_unless(delayed_until == -1, "Wrong delay, expected [%d], got [%d]",
2bb4320391b88748dc6e851deca941b058231664rbowenstatic void cached_authentication_with_expiration(const char *username,
ffb01336be79c64046b636e59fa8ddca8ec029edsf const char *password,
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin /* Setup */
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin fail_unless(ret == EOK, "Could not set up the test");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = confdb_add_param(test_ctx->confdb, true, CONFDB_PAM_CONF_ENTRY,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf DEBUG(9, ("Setting SYSDB_LAST_ONLINE_AUTH to [%lld].\n", (long long) now));
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen ret = sysdb_attrs_add_time_t(data->attrs, SYSDB_LAST_ONLINE_AUTH, now);
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen fail_unless(ret == EOK, "Could not modify user %s", data->username);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "sysdb_cache_auth request does not return expected "
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "Wrong expire date, expected [%d], got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(delayed_until == -1, "Wrong delay, expected [%d], got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfSTART_TEST (test_sysdb_cached_authentication_missing_password)
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin username = talloc_asprintf(tmp_ctx, "testuser%d", _i);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin fail_unless(username != NULL, "talloc_asprintf failed.");
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin cached_authentication_without_expiration(username, "abc", ENOENT);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin cached_authentication_with_expiration(username, "abc", ENOENT);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrinSTART_TEST (test_sysdb_cached_authentication_wrong_password)
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor username = talloc_asprintf(tmp_ctx, "testuser%d", _i);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin fail_unless(username != NULL, "talloc_asprintf failed.");
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin cached_authentication_without_expiration(username, "abc", EINVAL);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin cached_authentication_with_expiration(username, "abc", EINVAL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(username != NULL, "talloc_asprintf failed.");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cached_authentication_without_expiration(username, username, EOK);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cached_authentication_with_expiration(username, username, EOK);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_if(ret != EOK, "Could not modify group %s", data->groupname);
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->attrlist != NULL, "talloc_array failed");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd user_dn = sysdb_user_dn(data->ctx->sysdb, data, "LOCAL", ASQ_TEST_USER);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail_if(ret != EOK, "Failed to send ASQ search request.\n");
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail_unless(msgs_count == 10, "wrong number of results, "
97a9a944b5887e91042b019776c41d5dd74557aferikabele for (i = 0; i < msgs_count; i++) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele fail_unless(msgs[i]->num_elements == 1, "wrong number of elements, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "found [%d] expected [1]",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "wrong number of values, found [%d] expected [1]",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "wrong value, found [%.*s] expected [%s]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->attrlist != NULL, "talloc_array failed");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "wrong number of results, found [%d] expected [10]",
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess "wrong number of elements, found [%d] expected [1]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "wrong number of values, found [%d] expected [1]",
604c89126c27104f659d7a51b0113e3bd435faf8fielding (char *) data->msgs[i]->elements[0].values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "wrong value, found [%.*s] expected [%s]",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_replace_name(attrs, "foo", "foot");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener "sysdb_attrs_replace overwrites existing attribute");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_replace_name(attrs, "foo", "oof");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_replace failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_get_el failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(el->num_values == 0, "Attribute foo is not empty.");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_get_el failed");
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor "Wrong number of values for attribute oof, "
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(strncmp("bar", (char *) el->values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong value, expected [bar] got [%.*s]", el->values[0].length,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Setup */
fb77c505254b6e9c925e23e734463e87574f8f40kess data->groupname = talloc_asprintf(data, "testgroup%d", data->gid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (_i == 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(data->attrlist != NULL, "talloc_array failed.");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist[0] = talloc_asprintf(data, "testgroup%d", data->gid - 1);
9bcfc3697a91b5215893a7d0206865b13fc72148nd fail_if(ret != EOK, "Could not store POSIX group #%d", data->gid);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* Setup */
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->groupname = talloc_asprintf(data, "testgroup%d", data->gid);
8559a67073808d84d85bb5dd552d4247caafe709sf fail_unless(data->attrlist != NULL, "talloc_array failed.");
8559a67073808d84d85bb5dd552d4247caafe709sf data->attrlist[0] = talloc_asprintf(data, "testgroup%d", data->gid + 9);
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic fail_if(ret != EOK, "Could not store POSIX group #%d", data->gid);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* Setup */
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->username = talloc_asprintf(data, "testuser%d", data->uid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not store user %s", data->username);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->groupname = talloc_asprintf(data, "testgroup%d", _i + MBO_GROUP_BASE);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_if(ret != EOK, "Could not modify group %s", data->groupname);
9597f440430d8c876dd64f5f78066804650a18ecnoodlSTART_TEST (test_sysdb_memberof_check_memberuid_without_group_5)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->attrlist = talloc_array(data, const char *, 2);
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi fail_unless(data->attrlist != NULL, "tallo_array failed.");
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi "sysdb_search_group_by_gid found "
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi "already deleted group");
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail_if(ret != EOK, "Could not check group %d", data->gid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not check group %d", data->gid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of results, expected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
a850a44a7d6af013c766944483e00c2a1c8b183dnd "Wrong attribute name");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msg->elements[0].num_values == ((_i + 1) % 6),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
a850a44a7d6af013c766944483e00c2a1c8b183dnd fail_unless(data->attrlist != NULL, "tallo_array failed.");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_if(ret != EOK, "Could not check group %d", data->gid);
bea526116133aa3d7dabd1924bfc580b37fbf22aslive "Wrong number of results, expected [1] got [%d]",
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
bea526116133aa3d7dabd1924bfc580b37fbf22aslive "Wrong attribute name");
bea526116133aa3d7dabd1924bfc580b37fbf22aslive fail_unless(data->msg->elements[0].num_values == _i + 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, expected [%d] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist = talloc_array(data, const char *, 2);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin fail_unless(data->attrlist != NULL, "tallo_array failed.");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of results, expected [1] got [%d]",
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong attribute name");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of attribute values, expected [%d] got [%d]",
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrinSTART_TEST (test_sysdb_memberof_check_memberuid_loop_without_group_5)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist = talloc_array(data, const char *, 2);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(data->attrlist != NULL, "tallo_array failed.");
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "sysdb_search_group_by_gid_send found "
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin "already deleted group");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of results, expected [1] got [%d]",
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrin "Wrong attribute name");
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrin fail_unless(data->msg->elements[0].num_values == ((_i + 5) % 10),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, expected [%d] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Create a new user */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_add_user,27000,27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Verify the users were added */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getpwnam, 27000, 27010);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Create a new group */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_add_group, 28000, 28010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Verify the groups were added */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getgrnam, 28000, 28010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* sysdb_store_user allows setting attributes for existing users */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_store_user_existing, 27000, 27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* test the change */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_get_user_attr, 27000, 27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the other half by gid */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group_by_gid, 28000, 28010);
7a9fd3b88382052ae000d95ff0d35a1f318d6b23pquerna /* Remove the other half by uid */
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_user_by_uid, 27000, 27010);
7a9fd3b88382052ae000d95ff0d35a1f318d6b23pquerna /* Create a new user */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_store_user, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the users were added */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_getpwnam, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the users can be queried by UID */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_getpwuid, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Enumerate the users */
ee1af2aeb57527f33baa4737aa431e4aef997855rbowen /* Change their attribute */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_set_user_attr, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the change */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor tcase_add_loop_test(tc_sysdb, test_sysdb_get_user_attr, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Create a new group */
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen tcase_add_loop_test(tc_sysdb, test_sysdb_store_group, 28010, 28020);
50cb7e2b30597f481fee57bac945190f06ebcc58jorton /* Verify the groups were added */
97a9a944b5887e91042b019776c41d5dd74557aferikabele /* Verify the groups can be queried by GID */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getgrgid, 28010, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Enumerate the groups */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor /* Add some members to the groups */
e23d878014f00a27b043a25e59f809c7af497e5ctakashi tcase_add_loop_test(tc_sysdb, test_sysdb_add_group_member, 28010, 28020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Authenticate with missing cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication_missing_password,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Add a cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cache_password, 27010, 27011);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Authenticate against cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication_wrong_password,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication, 27010, 27011);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* ASQ search test */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_prepare_asq_test_user, 28011, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Test search with more than one result */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_test(tc_sysdb, test_sysdb_search_all_users);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the members from the groups */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_remove_group_member, 28010, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the users by name */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_user, 27010, 27020);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Remove the groups by name */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group, 28010, 28020);
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test the ignore_not_found parameter for users */
130d299c4b2b15be45532a176604c71fdc7bea5bnd tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_user);
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test the ignore_not_found parameter for groups */
130d299c4b2b15be45532a176604c71fdc7bea5bnd tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_group);
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test custom operations */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_loop_test(tc_sysdb, test_sysdb_store_custom, 29010, 29020);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_test(tc_sysdb, test_sysdb_search_custom_by_name);
6c5c651b0b97607b8c8b4965c1385c67699f217fnd tcase_add_test(tc_sysdb, test_sysdb_search_custom_update);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* test recursive delete */
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem/* Add all test cases to the test suite */
4bb78e7cdd53f50240cff4ad7a97c7ed36483797slive TCase *tc_memberof = tcase_create("SYSDB member/memberof/memberuid Tests");
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_group, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_user, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_add_group_member,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_check_memberuid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_group, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_test(tc_memberof, test_sysdb_memberof_close_loop);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_user, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_add_group_member,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_check_memberuid_loop,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem test_sysdb_memberof_check_memberuid_loop_without_group_5,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
97a9a944b5887e91042b019776c41d5dd74557aferikabele pc = poptGetContext(argv[0], argc, argv, long_options, 0);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test ldb file (%d) (%s)\n",
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test config ldb file (%d) (%s)\n",
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test config ldb file (%d) (%s)\n",