summaryrefslogtreecommitdiffstats
path: root/src/db/sysdb.c
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2011-03-22 17:42:55 -0400
committerStephen Gallagher <sgallagh@redhat.com>2011-03-23 05:05:31 -0400
commit201ab94ecdf62e68928f90c30e9eb28a1800e3dd (patch)
tree7d27a4793a372b5dd242bbe0094f14d548312e12 /src/db/sysdb.c
parente46e4f3e5fe568b660ed54d2862d31bc243b4278 (diff)
downloadsssd-201ab94ecdf62e68928f90c30e9eb28a1800e3dd.tar.gz
sssd-201ab94ecdf62e68928f90c30e9eb28a1800e3dd.tar.xz
sssd-201ab94ecdf62e68928f90c30e9eb28a1800e3dd.zip
Add sysdb_attrs_primary_name_list() routine
This routine will replace the use of sysdb_attrs_to_list() for any case where we're trying to get the name of the entry. It's a necessary precaution in case the name is multi-valued.
Diffstat (limited to 'src/db/sysdb.c')
-rw-r--r--src/db/sysdb.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index dd70d5c74..3cdf1203b 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -2142,3 +2142,56 @@ done:
talloc_free(tmpctx);
return ret;
}
+
+errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb,
+ TALLOC_CTX *mem_ctx,
+ struct sysdb_attrs **attr_list,
+ size_t attr_count,
+ const char *ldap_attr,
+ char ***name_list)
+{
+ errno_t ret;
+ size_t i, j;
+ char **list;
+ const char *name;
+
+ /* Assume that every entry has a primary name */
+ list = talloc_array(mem_ctx, char *, attr_count+1);
+ if (!list) {
+ return ENOMEM;
+ }
+
+ j = 0;
+ for (i = 0; i < attr_count; i++) {
+ ret = sysdb_attrs_primary_name(sysdb,
+ attr_list[i],
+ ldap_attr,
+ &name);
+ if (ret != EOK) {
+ DEBUG(1, ("Could not determine primary name\n"));
+ /* Skip and continue. Don't advance 'j' */
+ continue;
+ }
+
+ list[j] = talloc_strdup(list, name);
+ if (!list[j]) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ j++;
+ }
+
+ /* NULL-terminate the list */
+ list[j] = NULL;
+
+ *name_list = list;
+
+ ret = EOK;
+
+done:
+ if (ret != EOK) {
+ talloc_free(list);
+ }
+ return ret;
+}