diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-09-23 17:18:50 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-09-24 18:18:30 +0200 |
commit | e75a152157e054a2ed46acecbe8b5cfb9853773c (patch) | |
tree | ea6d942492af92e0f30a662a2fc5ec494e6d25ae | |
parent | f17d26a8db285622a5cd5f21c7488b62eedc2cf8 (diff) | |
download | sssd-e75a152157e054a2ed46acecbe8b5cfb9853773c.tar.gz sssd-e75a152157e054a2ed46acecbe8b5cfb9853773c.tar.bz2 sssd-e75a152157e054a2ed46acecbe8b5cfb9853773c.zip |
AUTOFS: Use both key and value in entry RDN
This patch switches from using just key in the RDN to using both key and
value. That is neccessary to allow multiple direct mounts in a single
map.
-rw-r--r-- | src/db/sysdb_autofs.c | 48 | ||||
-rw-r--r-- | src/db/sysdb_autofs.h | 3 | ||||
-rw-r--r-- | src/providers/ldap/sdap_async_autofs.c | 12 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 2 |
4 files changed, 51 insertions, 14 deletions
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c index b3df33f6..bf4e9b17 100644 --- a/src/db/sysdb_autofs.c +++ b/src/db/sysdb_autofs.c @@ -39,22 +39,42 @@ static struct ldb_dn * sysdb_autofsentry_dn(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, const char *map_name, - const char *entry_name) + const char *entry_name, + const char *entry_value) { errno_t ret; + TALLOC_CTX *tmp_ctx; char *clean_name; - struct ldb_dn *dn; + char *clean_value; + const char *rdn; + struct ldb_dn *dn = NULL; - ret = sysdb_dn_sanitize(NULL, entry_name, &clean_name); - if (ret != EOK) { + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { return NULL; } + ret = sysdb_dn_sanitize(tmp_ctx, entry_name, &clean_name); + if (ret != EOK) { + goto done; + } + + ret = sysdb_dn_sanitize(tmp_ctx, entry_value, &clean_value); + if (ret != EOK) { + goto done; + } + + rdn = talloc_asprintf(tmp_ctx, "%s%s", clean_name, clean_value); + if (!rdn) { + goto done; + } + dn = ldb_dn_new_fmt(mem_ctx, sysdb->ldb, SYSDB_TMPL_AUTOFS_ENTRY, - clean_name, map_name, AUTOFS_MAP_SUBDIR, + rdn, map_name, AUTOFS_MAP_SUBDIR, sysdb->domain->name); - talloc_free(clean_name); +done: + talloc_free(tmp_ctx); return dn; } @@ -217,6 +237,7 @@ sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx, TALLOC_CTX *tmp_ctx; struct ldb_message *msg; struct ldb_dn *dn; + const char *name; DEBUG(SSSDBG_TRACE_FUNC, ("Adding autofs entry [%s] - [%s]\n", key, value)); @@ -256,14 +277,20 @@ sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx, goto done; } - ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, key); + name = talloc_asprintf(tmp_ctx, "%s%s", key, value); + if (!name) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Could not set name attribute [%d]: %s\n", ret, strerror(ret))); goto done; } - dn = sysdb_autofsentry_dn(tmp_ctx, sysdb_ctx, map, key); + dn = sysdb_autofsentry_dn(tmp_ctx, sysdb_ctx, map, key, value); if (!dn) { ret = ENOMEM; goto done; @@ -289,12 +316,13 @@ done: errno_t sysdb_del_autofsentry(struct sysdb_ctx *sysdb_ctx, const char *map, - const char *key) + const char *key, + const char *value) { struct ldb_dn *dn; errno_t ret; - dn = sysdb_autofsentry_dn(sysdb_ctx, sysdb_ctx, map, key); + dn = sysdb_autofsentry_dn(sysdb_ctx, sysdb_ctx, map, key, value); if (!dn) { return ENOMEM; } diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h index 616c2cbd..c4b5253a 100644 --- a/src/db/sysdb_autofs.h +++ b/src/db/sysdb_autofs.h @@ -62,7 +62,8 @@ sysdb_save_autofsentry(struct sysdb_ctx *sysdb_ctx, errno_t sysdb_del_autofsentry(struct sysdb_ctx *sysdb_ctx, const char *map, - const char *key); + const char *key, + const char *value); errno_t sysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx, diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c index 8bfabda2..fdffd1d5 100644 --- a/src/providers/ldap/sdap_async_autofs.c +++ b/src/providers/ldap/sdap_async_autofs.c @@ -91,7 +91,7 @@ mod_autofs_entry(struct sysdb_ctx *sysdb, ret = sysdb_save_autofsentry(sysdb, map, key, value, NULL); break; case AUTOFS_MAP_OP_DEL: - ret = sysdb_del_autofsentry(sysdb, map, key); + ret = sysdb_del_autofsentry(sysdb, map, key, value); break; } @@ -794,6 +794,7 @@ sdap_autofs_setautomntent_save(struct tevent_req *req) bool in_transaction = false; TALLOC_CTX *tmp_ctx; struct ldb_message **entries = NULL; + struct sysdb_attrs **entries_attrs; size_t count; const char *val; char **sysdb_entrylist; @@ -902,9 +903,16 @@ sdap_autofs_setautomntent_save(struct tevent_req *req) /* Delete entries that don't exist anymore */ if (del_entries && del_entries[0]) { + ret = sysdb_msg2attrs(tmp_ctx, count, entries, &entries_attrs); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, + ("sysdb_msg2attrs failed: [%d]: %s\n", ret, strerror(ret))); + goto done; + } + ret = del_autofs_entries(state->sysdb, state->opts, state->mapname, del_entries, - state->entries, state->entries_count); + entries_attrs, count); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, ("Cannot delete autofs entries [%d]: %s\n", diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index ffcef835..83628af8 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -3801,7 +3801,7 @@ START_TEST(test_autofs_get_duplicate_keys) fail_if(autofskey == NULL, "Out of memory\n"); filter = talloc_asprintf(test_ctx, "(&(objectclass=%s)(%s=%s))", - SYSDB_AUTOFS_ENTRY_OC, SYSDB_NAME, autofskey); + SYSDB_AUTOFS_ENTRY_OC, SYSDB_AUTOFS_ENTRY_KEY, autofskey); fail_if(filter == NULL, "Out of memory\n"); dn = ldb_dn_new_fmt(test_ctx, test_ctx->sysdb->ldb, SYSDB_TMPL_CUSTOM_SUBTREE, |