diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2011-09-21 10:39:06 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-09-28 09:22:48 -0400 |
commit | 920b227ac810f1a1964bbecfdc4d871a1cfd07ac (patch) | |
tree | 0f17ba43a9cff0cfc8a4d962c45234fd31e84302 /src | |
parent | 3b6d344d84274e2aa3616c74237035b0e8a2eaaf (diff) | |
download | sssd-920b227ac810f1a1964bbecfdc4d871a1cfd07ac.tar.gz sssd-920b227ac810f1a1964bbecfdc4d871a1cfd07ac.tar.bz2 sssd-920b227ac810f1a1964bbecfdc4d871a1cfd07ac.zip |
Add sysdb interface to get name aliases
Diffstat (limited to 'src')
-rw-r--r-- | src/db/sysdb.c | 60 | ||||
-rw-r--r-- | src/db/sysdb.h | 5 |
2 files changed, 64 insertions, 1 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 7d030d83..eafa7fdc 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -2410,7 +2410,7 @@ errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, if (strcasecmp(rdn_attr, ldap_attr) != 0) { /* Multiple entries, and the RDN attribute doesn't match. * We have no way of resolving this deterministically, - * so we'll punt. + * so we'll use the first value as a fallback. */ DEBUG(3, ("The entry has multiple names and the RDN attribute does " "not match. Will use the first value as fallback.\n")); @@ -2450,6 +2450,64 @@ done: return ret; } +/* + * An entity with multiple names would have multiple SYSDB_NAME attributes + * after being translated into sysdb names using a map. + * Given a primary name returned by sysdb_attrs_primary_name(), this function + * returns the other SYSDB_NAME attribute values so they can be saved as + * SYSDB_NAME_ALIAS into cache. + */ +errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx, + struct sysdb_attrs *attrs, + const char *primary, + const char ***_aliases) +{ + TALLOC_CTX *tmp_ctx = NULL; + struct ldb_message_element *sysdb_name_el; + size_t i, ai; + errno_t ret; + const char **aliases = NULL; + const char *name; + + if (_aliases == NULL) return EINVAL; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } + + ret = sysdb_attrs_get_el(attrs, + SYSDB_NAME, + &sysdb_name_el); + if (sysdb_name_el->num_values == 0) { + ret = EINVAL; + goto done; + } + + aliases = talloc_array(tmp_ctx, const char *, + sysdb_name_el->num_values); + if (!aliases) { + ret = ENOMEM; + goto done; + } + + ai = 0; + for (i=0; i < sysdb_name_el->num_values; i++) { + name = (const char *)sysdb_name_el->values[i].data; + if (strcmp(primary, name) != 0) { + aliases[ai] = name; + ai++; + } + } + + aliases[ai] = NULL; + ret = EOK; +done: + *_aliases = talloc_steal(mem_ctx, aliases); + talloc_free(tmp_ctx); + return ret; +} + errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, struct sysdb_attrs **attr_list, diff --git a/src/db/sysdb.h b/src/db/sysdb.h index ee1c8681..fc53e38d 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -46,6 +46,7 @@ #define SYSDB_NETGROUP_CLASS "netgroup" #define SYSDB_NAME "name" +#define SYSDB_NAME_ALIAS "nameAlias" #define SYSDB_OBJECTCLASS "objectClass" #define SYSDB_NEXTID "nextID" @@ -229,6 +230,10 @@ errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs, const char *ldap_attr, const char **_primary); +errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx, + struct sysdb_attrs *attrs, + const char *primary, + const char ***_aliases); errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx, struct sysdb_attrs **attr_list, |