diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2011-11-16 13:57:26 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-12-16 14:46:16 -0500 |
commit | 70a33bdf7db34fe4d1ba194cf9ea28c758719b4b (patch) | |
tree | 4f93e18380fe1ca2d41fca0b5c8fb9d8b77ee781 /src/providers/ldap/sdap_async.c | |
parent | b3b42c49656e192787a983aaa8b9ec744ba4cb9d (diff) | |
download | sssd-70a33bdf7db34fe4d1ba194cf9ea28c758719b4b.tar.gz sssd-70a33bdf7db34fe4d1ba194cf9ea28c758719b4b.tar.xz sssd-70a33bdf7db34fe4d1ba194cf9ea28c758719b4b.zip |
Refactor saving sdap entities
There was too much code duplication between
sdap_save_{user,group,netgroup}. This patch removes the most egregious ones.
Diffstat (limited to 'src/providers/ldap/sdap_async.c')
-rw-r--r-- | src/providers/ldap/sdap_async.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c index b1177e274..98291e6e2 100644 --- a/src/providers/ldap/sdap_async.c +++ b/src/providers/ldap/sdap_async.c @@ -1983,3 +1983,83 @@ done: return ret; } +errno_t +sdap_attrs_add_ldap_attr(struct sysdb_attrs *ldap_attrs, + const char *attr_name, + const char *attr_desc, + bool multivalued, + const char *name, + struct sysdb_attrs *attrs) +{ + errno_t ret; + struct ldb_message_element *el; + const char *objname = name ?: "object"; + const char *desc = attr_desc ?: attr_name; + unsigned int num_values, i; + + ret = sysdb_attrs_get_el(ldap_attrs, attr_name, &el); + if (ret) { + DEBUG(SSSDBG_OP_FAILURE, ("Could not get %s from the " + "list of the LDAP attributes [%d]: %s\n", ret, strerror(ret))); + return ret; + } + + if (el->num_values == 0) { + DEBUG(SSSDBG_TRACE_INTERNAL, ("%s is not available " + "for [%s].\n", desc, objname)); + } else { + num_values = multivalued ? el->num_values : 1; + for (i = 0; i < num_values; i++) { + DEBUG(SSSDBG_TRACE_INTERNAL, ("Adding %s [%s] to attributes " + "of [%s].\n", desc, el->values[i].data, objname)); + + ret = sysdb_attrs_add_string(attrs, attr_name, + (const char *) el->values[i].data); + if (ret) { + return ret; + } + } + } + + return EOK; +} + + +errno_t +sdap_save_all_names(const char *name, + struct sysdb_attrs *ldap_attrs, + struct sysdb_attrs *attrs) +{ + const char **aliases = NULL; + errno_t ret; + TALLOC_CTX *tmp_ctx; + int i; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_attrs_get_aliases(tmp_ctx, ldap_attrs, name, &aliases); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Failed to get the alias list")); + goto done; + } + + for (i = 0; aliases[i]; i++) { + ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, + aliases[i]); + if (ret) { + DEBUG(SSSDBG_OP_FAILURE, ("Failed to add alias [%s] into the " + "attribute list\n", aliases[i])); + goto done; + } + } + + ret = EOK; +done: + talloc_free(tmp_ctx); + return ret; +} + |