summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-09-21 20:01:28 +0200
committerJakub Hrozek <jhrozek@redhat.com>2012-09-24 18:18:30 +0200
commitf17d26a8db285622a5cd5f21c7488b62eedc2cf8 (patch)
tree76d03fe08802e2823f6ccc76cfcfca0e5a9cdb14
parentc7efe2545f691fc81478e0cfe61a43bbc83acc72 (diff)
downloadsssd-f17d26a8db285622a5cd5f21c7488b62eedc2cf8.tar.gz
sssd-f17d26a8db285622a5cd5f21c7488b62eedc2cf8.tar.bz2
sssd-f17d26a8db285622a5cd5f21c7488b62eedc2cf8.zip
AUTOFS: Add entry objects below map objects
https://fedorahosted.org/sssd/ticket/1506 Changes how the new autofs entry objects are handled. Instead of creating the entry on the cn=autofs,cn=custom level, the entry is created below the map it belongs to.
-rw-r--r--src/db/sysdb.h1
-rw-r--r--src/db/sysdb_autofs.c166
-rw-r--r--src/db/sysdb_autofs.h24
-rw-r--r--src/db/sysdb_ops.c19
-rw-r--r--src/providers/ldap/sdap_async_autofs.c134
-rw-r--r--src/tests/sysdb-tests.c48
6 files changed, 172 insertions, 220 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 4e458173..f74fceec 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -687,7 +687,6 @@ enum sysdb_member_type {
SYSDB_MEMBER_GROUP,
SYSDB_MEMBER_NETGROUP,
SYSDB_MEMBER_SERVICE,
- SYSDB_MEMBER_AUTOFSENTRY
};
int sysdb_add_group_member(struct sysdb_ctx *sysdb,
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index df5f3398..b3df33f6 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -24,7 +24,9 @@
#include "db/sysdb_private.h"
#include "db/sysdb_autofs.h"
-struct ldb_dn *
+#define SYSDB_TMPL_AUTOFS_ENTRY SYSDB_NAME"=%s,"SYSDB_TMPL_CUSTOM
+
+static struct ldb_dn *
sysdb_autofsmap_dn(TALLOC_CTX *mem_ctx,
struct sysdb_ctx *sysdb,
const char *map_name)
@@ -33,29 +35,27 @@ sysdb_autofsmap_dn(TALLOC_CTX *mem_ctx,
map_name, AUTOFS_MAP_SUBDIR);
}
-struct ldb_dn *
+static struct ldb_dn *
sysdb_autofsentry_dn(TALLOC_CTX *mem_ctx,
struct sysdb_ctx *sysdb,
+ const char *map_name,
const char *entry_name)
{
- return sysdb_custom_dn(sysdb, mem_ctx, sysdb->domain->name,
- entry_name, AUTOFS_ENTRY_SUBDIR);
-}
-
-static char *
-sysdb_autofsmap_strdn(TALLOC_CTX *mem_ctx,
- struct sysdb_ctx *sysdb,
- const char *map_name)
-{
+ errno_t ret;
+ char *clean_name;
struct ldb_dn *dn;
- char *strdn;
- dn = sysdb_autofsmap_dn(mem_ctx, sysdb, map_name);
- if (!dn) return NULL;
+ ret = sysdb_dn_sanitize(NULL, entry_name, &clean_name);
+ if (ret != EOK) {
+ return NULL;
+ }
+
+ dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_AUTOFS_ENTRY,
+ clean_name, map_name, AUTOFS_MAP_SUBDIR,
+ sysdb->domain->name);
+ talloc_free(clean_name);
- strdn = talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn));
- talloc_free(dn);
- return strdn;
+ return dn;
}
errno_t
@@ -208,12 +208,15 @@ done:
errno_t
sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx,
+ const char *map,
const char *key,
const char *value,
struct sysdb_attrs *attrs)
{
errno_t ret;
TALLOC_CTX *tmp_ctx;
+ struct ldb_message *msg;
+ struct ldb_dn *dn;
DEBUG(SSSDBG_TRACE_FUNC,
("Adding autofs entry [%s] - [%s]\n", key, value));
@@ -260,20 +263,48 @@ sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx,
goto done;
}
- ret = sysdb_store_custom(sysdb_ctx, key, AUTOFS_ENTRY_SUBDIR, attrs);
- if (ret != EOK) {
- DEBUG(SSSDBG_OP_FAILURE, ("sysdb_store_custom failed [%d]: %s\n",
- ret, strerror(ret)));
+ dn = sysdb_autofsentry_dn(tmp_ctx, sysdb_ctx, map, key);
+ if (!dn) {
+ ret = ENOMEM;
goto done;
}
- ret = EOK;
+ msg = ldb_msg_new(tmp_ctx);
+ if (!msg) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ msg->dn = dn;
+ msg->elements = attrs->a;
+ msg->num_elements = attrs->num;
+
+ ret = ldb_add(sysdb_ctx->ldb, msg);
+ ret = sysdb_error_to_errno(ret);
done:
talloc_free(tmp_ctx);
return ret;
}
errno_t
+sysdb_del_autofsentry(struct sysdb_ctx *sysdb_ctx,
+ const char *map,
+ const char *key)
+{
+ struct ldb_dn *dn;
+ errno_t ret;
+
+ dn = sysdb_autofsentry_dn(sysdb_ctx, sysdb_ctx, map, key);
+ if (!dn) {
+ return ENOMEM;
+ }
+
+ ret = sysdb_delete_entry(sysdb_ctx, dn, true);
+ talloc_free(dn);
+ return ret;
+}
+
+errno_t
sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
struct sysdb_ctx *sysdb,
const char *mapname,
@@ -288,7 +319,7 @@ sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
NULL };
size_t count;
struct ldb_message **msgs;
- char *mapdn;
+ struct ldb_dn *mapdn;
DEBUG(SSSDBG_TRACE_FUNC, ("Getting entries for map %s\n", mapname));
@@ -297,21 +328,21 @@ sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
return ENOMEM;
}
- mapdn = sysdb_autofsmap_strdn(tmp_ctx, sysdb, mapname);
+ mapdn = sysdb_autofsmap_dn(tmp_ctx, sysdb, mapname);
if (!mapdn) {
ret = ENOMEM;
goto done;
}
- filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=%s))",
- SYSDB_AUTOFS_ENTRY_OC, SYSDB_MEMBEROF, mapdn);
+ filter = talloc_asprintf(tmp_ctx, "(objectclass=%s)",
+ SYSDB_AUTOFS_ENTRY_OC);
if (!filter) {
ret = ENOMEM;
goto done;
}
- ret = sysdb_search_custom(tmp_ctx, sysdb, filter, AUTOFS_ENTRY_SUBDIR,
- attrs, &count, &msgs);
+ ret = sysdb_search_entry(tmp_ctx, sysdb, mapdn, LDB_SCOPE_ONELEVEL,
+ filter, attrs, &count, &msgs);
if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, ("sysdb search failed: %d\n", ret));
goto done;
@@ -333,85 +364,6 @@ done:
}
errno_t
-sysdb_map_entry_name(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
- const char *entry_dn, char **_name)
-{
- return sysdb_get_rdn(sysdb, mem_ctx, entry_dn, NULL, _name);
-}
-
-errno_t
-sysdb_autofs_map_update_members(struct sysdb_ctx *sysdb,
- const char *mapname,
- const char *const *add_entries,
- const char *const *del_entries)
-{
- errno_t ret, sret;
- int i;
- bool in_transaction = false;
-
- TALLOC_CTX *tmp_ctx = talloc_new(NULL);
- if(!tmp_ctx) {
- return ENOMEM;
- }
-
- ret = sysdb_transaction_start(sysdb);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("Failed to start update transaction\n"));
- goto done;
- }
-
- in_transaction = true;
-
- if (add_entries) {
- /* Add the all te add_entries to the map */
- for (i = 0; add_entries[i]; i++) {
- ret = sysdb_add_group_member(sysdb, mapname, add_entries[i],
- SYSDB_MEMBER_AUTOFSENTRY);
- if (ret != EOK) {
- DEBUG(SSSDBG_MINOR_FAILURE,
- ("Could not add entry [%s] to map [%s]. "
- "Skipping.\n", add_entries[i], mapname));
- /* Continue on, we should try to finish the rest */
- }
- }
- }
-
- if (del_entries) {
- /* Add the all te del_entries to the map */
- for (i = 0; del_entries[i]; i++) {
- ret = sysdb_remove_group_member(sysdb, mapname, del_entries[i],
- SYSDB_MEMBER_AUTOFSENTRY);
- if (ret != EOK) {
- DEBUG(SSSDBG_MINOR_FAILURE,
- ("Could not del entry [%s] to map [%s]. "
- "Skipping.\n", del_entries[i], mapname));
- /* Continue on, we should try to finish the rest */
- }
- }
- }
-
- ret = sysdb_transaction_commit(sysdb);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
- goto done;
- }
-
- in_transaction = false;
- ret = EOK;
-
-done:
- if (in_transaction) {
- sret = sysdb_transaction_cancel(sysdb);
- if (sret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
- }
- }
- talloc_free(tmp_ctx);
- return ret;
-}
-
-errno_t
sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb,
const char *name,
struct sysdb_attrs *attrs,
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
index b18d505b..616c2cbd 100644
--- a/src/db/sysdb_autofs.h
+++ b/src/db/sysdb_autofs.h
@@ -35,16 +35,6 @@
#define SYSDB_AUTOFS_ENTRY_KEY "automountKey"
#define SYSDB_AUTOFS_ENTRY_VALUE "automountInformation"
-struct ldb_dn *
-sysdb_autofsmap_dn(TALLOC_CTX *mem_ctx,
- struct sysdb_ctx *sysdb,
- const char *map_name);
-
-struct ldb_dn *
-sysdb_autofsentry_dn(TALLOC_CTX *mem_ctx,
- struct sysdb_ctx *sysdb,
- const char *entry_name);
-
errno_t
sysdb_save_autofsmap(struct sysdb_ctx *sysdb_ctx,
const char *name,
@@ -65,9 +55,14 @@ sysdb_delete_autofsmap(struct sysdb_ctx *sysdb_ctx,
errno_t
sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx,
+ const char *map,
const char *key,
const char *value,
struct sysdb_attrs *attrs);
+errno_t
+sysdb_del_autofsentry(struct sysdb_ctx *sysdb_ctx,
+ const char *map,
+ const char *key);
errno_t
sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
@@ -76,15 +71,6 @@ sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
size_t *_count,
struct ldb_message ***_entries);
-errno_t sysdb_map_entry_name(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
- const char *entry_dn, char **_name);
-
-errno_t
-sysdb_autofs_map_update_members(struct sysdb_ctx *sysdb,
- const char *mapname,
- const char *const *add_entries,
- const char *const *del_entries);
-
errno_t
sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb,
const char *name,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 33abd06b..52da27d3 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1790,21 +1790,6 @@ sysdb_group_membership_mod(struct sysdb_ctx *sysdb,
ret = ENOMEM;
goto done;
}
- } else if (type == SYSDB_MEMBER_AUTOFSENTRY) {
- /* FIXME - I don't like autofs specific stuff in sysdb_ops.c
- * Maybe we should introduce sysdb_common.c ?
- */
- member_dn = sysdb_autofsentry_dn(tmp_ctx, sysdb, member);
- if (!member_dn) {
- ret = ENOMEM;
- goto done;
- }
-
- group_dn = sysdb_autofsmap_dn(tmp_ctx, sysdb, group);
- if (!group_dn) {
- ret = ENOMEM;
- goto done;
- }
} else {
ret = EINVAL;
goto done;
@@ -3117,10 +3102,6 @@ errno_t sysdb_remove_attrs(struct sysdb_ctx *sysdb,
case SYSDB_MEMBER_SERVICE:
msg->dn = sysdb_svc_dn(sysdb, msg, sysdb->domain->name, name);
break;
-
- case SYSDB_MEMBER_AUTOFSENTRY:
- msg->dn = sysdb_autofsmap_dn(msg, sysdb, name);
- break;
}
if (!msg->dn) {
ret = ENOMEM;
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
index 9c8337d3..8bfabda2 100644
--- a/src/providers/ldap/sdap_async_autofs.c
+++ b/src/providers/ldap/sdap_async_autofs.c
@@ -28,6 +28,11 @@
#include "db/sysdb_autofs.h"
#include "providers/ldap/ldap_common.h"
+enum autofs_map_op {
+ AUTOFS_MAP_OP_ADD,
+ AUTOFS_MAP_OP_DEL
+};
+
/* ====== Utility functions ====== */
static const char *
get_autofs_map_name(struct sysdb_attrs *map, struct sdap_options *opts)
@@ -60,9 +65,11 @@ get_autofs_entry_key(struct sysdb_attrs *entry, struct sdap_options *opts)
}
static errno_t
-save_autofs_entry(struct sysdb_ctx *sysdb,
- struct sdap_options *opts,
- struct sysdb_attrs *entry)
+mod_autofs_entry(struct sysdb_ctx *sysdb,
+ const char *map,
+ struct sdap_options *opts,
+ struct sysdb_attrs *entry,
+ enum autofs_map_op mod_op)
{
const char *key;
const char *value;
@@ -79,20 +86,27 @@ save_autofs_entry(struct sysdb_ctx *sysdb,
if (el->num_values == 0) return EINVAL;
else value = (const char *)el->values[0].data;
- ret = sysdb_save_autofsentry(sysdb, key, value, NULL);
- if (ret != EOK) {
- return ret;
+ switch (mod_op) {
+ case AUTOFS_MAP_OP_ADD:
+ ret = sysdb_save_autofsentry(sysdb, map, key, value, NULL);
+ break;
+ case AUTOFS_MAP_OP_DEL:
+ ret = sysdb_del_autofsentry(sysdb, map, key);
+ break;
}
- return EOK;
+ return ret;
}
static errno_t
-save_autofs_entries(struct sysdb_ctx *sysdb,
- struct sdap_options *opts,
- char **add_entries,
- struct sysdb_attrs **entries,
- size_t num_entries)
+mod_autofs_entries(struct sysdb_ctx *sysdb,
+ struct sdap_options *opts,
+ const char *map,
+ char **mod_entries,
+ struct sysdb_attrs **entries,
+ size_t num_entries,
+ enum autofs_map_op mod_op)
+
{
errno_t ret, tret;
const char *key;
@@ -108,8 +122,12 @@ save_autofs_entries(struct sysdb_ctx *sysdb,
}
in_transaction = true;
- for (i=0; add_entries[i]; i++) {
+ /* Loop through entry names.. */
+ for (i=0; mod_entries[i]; i++) {
for (j=0; j < num_entries; j++) {
+ /* get a pointer to sysdb_attrs of an entry that is not
+ * cached, skip names that are not in **entries
+ */
key = get_autofs_entry_key(entries[j], opts);
if (!key) {
DEBUG(SSSDBG_MINOR_FAILURE,
@@ -117,14 +135,14 @@ save_autofs_entries(struct sysdb_ctx *sysdb,
return EINVAL;
}
- if (strcmp(add_entries[i], key)) {
+ if (strcmp(mod_entries[i], key)) {
continue;
}
- ret = save_autofs_entry(sysdb, opts, entries[j]);
+ ret = mod_autofs_entry(sysdb, map, opts, entries[j], mod_op);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
- ("Cannot save autofs entry [%d]: %s. Ignoring.\n",
+ ("Cannot modify autofs entry [%d]: %s. Ignoring.\n",
ret, strerror(ret)));
continue;
}
@@ -154,6 +172,30 @@ done:
}
static errno_t
+save_autofs_entries(struct sysdb_ctx *sysdb,
+ struct sdap_options *opts,
+ const char *map,
+ char **add_entries,
+ struct sysdb_attrs **entries,
+ size_t num_entries)
+{
+ return mod_autofs_entries(sysdb, opts, map, add_entries,
+ entries, num_entries, AUTOFS_MAP_OP_ADD);
+}
+
+static errno_t
+del_autofs_entries(struct sysdb_ctx *sysdb,
+ struct sdap_options *opts,
+ const char *map,
+ char **add_entries,
+ struct sysdb_attrs **entries,
+ size_t num_entries)
+{
+ return mod_autofs_entries(sysdb, opts, map, add_entries,
+ entries, num_entries, AUTOFS_MAP_OP_DEL);
+}
+
+static errno_t
save_autofs_map(struct sysdb_ctx *sysdb,
struct sss_domain_info *dom,
struct sdap_options *opts,
@@ -751,8 +793,9 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
errno_t ret, tret;
bool in_transaction = false;
TALLOC_CTX *tmp_ctx;
- struct ldb_message *sysdb_map;
- struct ldb_message_element *map_members = NULL;
+ struct ldb_message **entries = NULL;
+ size_t count;
+ const char *val;
char **sysdb_entrylist;
char **ldap_entrylist;
char **add_entries;
@@ -782,8 +825,8 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
}
}
- ret = sysdb_get_map_byname(tmp_ctx, state->sysdb, state->mapname,
- &sysdb_map);
+ ret = sysdb_autofs_entries_by_map(tmp_ctx, state->sysdb, state->mapname,
+ &count, &entries);
if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE,
("cache lookup for the map failed [%d]: %s\n",
@@ -791,30 +834,32 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
goto done;
}
- if (sysdb_map) {
- map_members = ldb_msg_find_element(sysdb_map, SYSDB_MEMBER);
- }
-
- if (!map_members || map_members->num_values == 0) {
+ if (count == 0) {
/* No map members for this map in sysdb currently */
sysdb_entrylist = NULL;
} else {
- sysdb_entrylist = talloc_array(state, char *, map_members->num_values+1);
+ sysdb_entrylist = talloc_array(state, char *, count+1);
if (!sysdb_entrylist) {
ret = ENOMEM;
goto done;
}
/* Get a list of the map members by name only */
- for (i=0; i < map_members->num_values; i++) {
- ret = sysdb_map_entry_name(sysdb_entrylist, state->sysdb,
- (const char *) map_members->values[i].data,
- &sysdb_entrylist[i]);
- if (ret != EOK) {
+ for (i=0; i < count; i++) {
+ val = ldb_msg_find_attr_as_string(entries[i],
+ SYSDB_AUTOFS_ENTRY_KEY, NULL);
+ if (!val) {
+ DEBUG(SSSDBG_MINOR_FAILURE, ("An entry with no value?\n"));
+ continue;
+ }
+
+ sysdb_entrylist[i] = talloc_strdup(sysdb_entrylist, val);
+ if (!sysdb_entrylist[i]) {
+ ret = ENOMEM;
goto done;
}
}
- sysdb_entrylist[map_members->num_values] = NULL;
+ sysdb_entrylist[count] = NULL;
}
/* Find the differences between the sysdb and LDAP lists
@@ -845,8 +890,8 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
/* Create entries that don't exist yet */
if (add_entries && add_entries[0]) {
ret = save_autofs_entries(state->sysdb, state->opts,
- add_entries, state->entries,
- state->entries_count);
+ state->mapname, add_entries,
+ state->entries, state->entries_count);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
("Cannot save autofs entries [%d]: %s\n",
@@ -855,17 +900,20 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
}
}
- /* Save the memberships */
- DEBUG(SSSDBG_TRACE_FUNC, ("Updating memberships for %s\n", state->mapname));
- ret = sysdb_autofs_map_update_members(state->sysdb, state->mapname,
- (const char *const *) add_entries,
- (const char *const *) del_entries);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("Membership update failed [%d]: %s\n",
- ret, strerror(ret)));
- goto done;
+ /* Delete entries that don't exist anymore */
+ if (del_entries && del_entries[0]) {
+ ret = del_autofs_entries(state->sysdb, state->opts,
+ state->mapname, del_entries,
+ state->entries, state->entries_count);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE,
+ ("Cannot delete autofs entries [%d]: %s\n",
+ ret, strerror(ret)));
+ goto done;
+ }
}
+
ret = sysdb_transaction_commit(state->sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 429df541..ffcef835 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -3704,13 +3704,10 @@ START_TEST(test_autofs_store_entry_in_map)
errno_t ret;
int ii;
const int limit = 10;
- const char *add_entries[limit+1];
ret = setup_sysdb_tests(&test_ctx);
fail_if(ret != EOK, "Could not set up the test");
- add_entries[limit] = NULL;
-
autofsmapname = talloc_asprintf(test_ctx, "testmap%d", _i);
fail_if(autofsmapname == NULL, "Out of memory\n");
@@ -3722,18 +3719,11 @@ START_TEST(test_autofs_store_entry_in_map)
autofsval = talloc_asprintf(test_ctx, "testserver:/testval%d", ii);
fail_if(autofsval == NULL, "Out of memory\n");
- ret = sysdb_save_autofsentry(test_ctx->sysdb, autofskey,
+ ret = sysdb_save_autofsentry(test_ctx->sysdb, autofsmapname, autofskey,
autofsval, NULL);
fail_if(ret != EOK, "Could not save autofs entry %s", autofskey);
-
- add_entries[ii] = autofskey;
}
- ret = sysdb_autofs_map_update_members(test_ctx->sysdb, autofsmapname,
- (const char *const *) add_entries,
- NULL);
- fail_if(ret != EOK, "Could not add entries to map %s\n");
-
talloc_free(test_ctx);
}
END_TEST
@@ -3783,18 +3773,13 @@ START_TEST(test_autofs_key_duplicate)
autofsval = talloc_asprintf(test_ctx, "testserver:/testval%d", _i);
fail_if(autofsval == NULL, "Out of memory\n");
- ret = sysdb_save_autofsentry(test_ctx->sysdb, autofskey,
+ ret = sysdb_save_autofsentry(test_ctx->sysdb, autofsmapname, autofskey,
autofsval, NULL);
fail_if(ret != EOK, "Could not save autofs entry %s", autofskey);
talloc_free(test_ctx);
}
END_TEST
-#if 0
-/*
- * Disabled due to
- * https://fedorahosted.org/sssd/ticket/1506
- */
START_TEST(test_autofs_get_duplicate_keys)
{
struct sysdb_test_ctx *test_ctx;
@@ -3805,6 +3790,8 @@ START_TEST(test_autofs_get_duplicate_keys)
NULL };
size_t count;
struct ldb_message **msgs;
+ struct ldb_dn *dn;
+ const char *filter;
const int expected = 10;
ret = setup_sysdb_tests(&test_ctx);
@@ -3813,18 +3800,23 @@ START_TEST(test_autofs_get_duplicate_keys)
autofskey = talloc_asprintf(test_ctx, "testkey");
fail_if(autofskey == NULL, "Out of memory\n");
- ret = sysdb_search_custom_by_name(test_ctx, test_ctx->sysdb,
- autofskey, AUTOFS_ENTRY_SUBDIR,
- attrs, &count, &msgs);
- fail_if(ret != EOK, "sysdb search failed\n");
- fail_if(count != expected, "Expected %d maps with name %s, found %d\n",
- expected, autofskey, count);
+ filter = talloc_asprintf(test_ctx, "(&(objectclass=%s)(%s=%s))",
+ SYSDB_AUTOFS_ENTRY_OC, SYSDB_NAME, autofskey);
+ fail_if(filter == NULL, "Out of memory\n");
+
+ dn = ldb_dn_new_fmt(test_ctx, test_ctx->sysdb->ldb, SYSDB_TMPL_CUSTOM_SUBTREE,
+ AUTOFS_MAP_SUBDIR, test_ctx->sysdb->domain->name);
+ fail_if(dn == NULL, "Out of memory\n");
+
+ ret = sysdb_search_entry(test_ctx, test_ctx->sysdb, dn, LDB_SCOPE_SUBTREE,
+ filter, attrs, &count, &msgs);
+ fail_if(count != expected, "Found %d entries with name %s, expected %d\n",
+ count, autofskey, expected);
talloc_free(test_ctx);
}
END_TEST
-#endif
-#endif
+#endif /* BUILD_AUTOFS */
Suite *create_sysdb_suite(void)
{
@@ -4068,13 +4060,7 @@ Suite *create_sysdb_suite(void)
tcase_add_loop_test(tc_subdomain, test_autofs_key_duplicate,
TEST_AUTOFS_MAP_BASE, TEST_AUTOFS_MAP_BASE+10);
-#if 0
-/*
- * Disabled due to
- * https://fedorahosted.org/sssd/ticket/1506
- */
tcase_add_test(tc_subdomain, test_autofs_get_duplicate_keys);
-#endif
suite_add_tcase(s, tc_autofs);
#endif