diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-09-21 20:01:28 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-09-24 18:18:30 +0200 |
commit | f17d26a8db285622a5cd5f21c7488b62eedc2cf8 (patch) | |
tree | 76d03fe08802e2823f6ccc76cfcfca0e5a9cdb14 /src/db | |
parent | c7efe2545f691fc81478e0cfe61a43bbc83acc72 (diff) | |
download | sssd-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.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/sysdb.h | 1 | ||||
-rw-r--r-- | src/db/sysdb_autofs.c | 166 | ||||
-rw-r--r-- | src/db/sysdb_autofs.h | 24 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 19 |
4 files changed, 64 insertions, 146 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; |