summaryrefslogtreecommitdiffstats
path: root/src/db/sysdb.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-09-21 10:39:06 +0200
committerStephen Gallagher <sgallagh@redhat.com>2011-10-06 11:08:25 -0400
commitbcec4a854de207a4f399d14f936a21edc5575683 (patch)
treeb35506c7abd26d7b5e8306e44ed50960713318fc /src/db/sysdb.c
parentd7c7edcf4c7014dff3f84b5b56dbd4453cf608aa (diff)
downloadsssd-bcec4a854de207a4f399d14f936a21edc5575683.tar.gz
sssd-bcec4a854de207a4f399d14f936a21edc5575683.tar.xz
sssd-bcec4a854de207a4f399d14f936a21edc5575683.zip
Better handling for aliases
Add sysdb interface to get name aliases Add a sysdb_get_direct_parents function Store name aliases for users, groups Return users and groups based on alias https://fedorahosted.org/sssd/ticket/926 Fix typo in sysdb_get_direct_parents
Diffstat (limited to 'src/db/sysdb.c')
-rw-r--r--src/db/sysdb.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 42a4240f1..a1c16318c 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -2131,7 +2131,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"));
@@ -2171,6 +2171,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,