>From 7e8d4e2d7587949deef689ce54c4cd7a370d2008 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 12 Aug 2013 15:06:18 +0000
Subject: [PATCH 3/3] Make LDAP extra attributes available to IPA and AD

https://fedorahosted.org/sssd/ticket/2073
---
 src/config/etc/sssd.api.d/sssd-ad.conf  |  1 +
 src/config/etc/sssd.api.d/sssd-ipa.conf |  1 +
 src/providers/ad/ad_common.c            | 11 +++++-----
 src/providers/ipa/ipa_common.c          | 11 +++++-----
 src/providers/ldap/ldap_options.c       | 38 --------------------------------
 src/providers/ldap/sdap.c               | 39 +++++++++++++++++++++++++++++++++
 src/providers/ldap/sdap.h               |  8 +++++++
 7 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/src/config/etc/sssd.api.d/sssd-ad.conf b/src/config/etc/sssd.api.d/sssd-ad.conf
index aa20ca0bb5b70818525d61a1480a6b56bd8c4e48..ed0189618e137d1a4b48cecd328b797e99201ad2 100644
--- a/src/config/etc/sssd.api.d/sssd-ad.conf
+++ b/src/config/etc/sssd.api.d/sssd-ad.conf
@@ -54,6 +54,7 @@ ldap_id_mapping = bool, None, false
 ldap_user_search_base = str, None, false
 ldap_user_search_scope = str, None, false
 ldap_user_search_filter = str, None, false
+ldap_user_extra_attrs = str, None, false
 ldap_user_object_class = str, None, false
 ldap_user_name = str, None, false
 ldap_user_uid_number = str, None, false
diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index 9259d99792131d332cc9ccc4cf69739308e4695c..3a3f6a4cf9586b2a81844e38498ba86b504f1f52 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -61,6 +61,7 @@ ldap_id_mapping = bool, None, false
 ldap_user_search_base = str, None, false
 ldap_user_search_scope = str, None, false
 ldap_user_search_filter = str, None, false
+ldap_user_extra_attrs = str, None, false
 ldap_user_object_class = str, None, false
 ldap_user_name = str, None, false
 ldap_user_uid_number = str, None, false
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
index 8528ad3dcdab58ff17c200b8f6f226cd50e8cfed..2607e766dcbb754f20be1aa91e93de8f95a89f2c 100644
--- a/src/providers/ad/ad_common.c
+++ b/src/providers/ad/ad_common.c
@@ -201,11 +201,12 @@ ad_create_sdap_options(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    ret = sdap_extend_map(id_opts,
-                          id_opts->user_map,
-                          SDAP_OPTS_USER, NULL,
-                          &id_opts->user_map,
-                          &id_opts->user_map_cnt);
+    ret = sdap_extend_map_with_list(id_opts, id_opts,
+                                    SDAP_USER_EXTRA_ATTRS,
+                                    id_opts->user_map,
+                                    SDAP_OPTS_USER,
+                                    &id_opts->user_map,
+                                    &id_opts->user_map_cnt);
     if (ret != EOK) {
         goto done;
     }
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 19de10d8bb92a4b3d0c8353eae128f3b4709a7af..f594de27a65ab1ff702d0c593a57e89bfd469532 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -547,11 +547,12 @@ int ipa_get_id_options(struct ipa_options *ipa_opts,
         goto done;
     }
 
-    ret = sdap_extend_map(ipa_opts->id,
-                          ipa_opts->id->user_map,
-                          SDAP_OPTS_USER, NULL,
-                          &ipa_opts->id->user_map,
-                          &ipa_opts->id->user_map_cnt);
+    ret = sdap_extend_map_with_list(ipa_opts->id, ipa_opts->id,
+                                    SDAP_USER_EXTRA_ATTRS,
+                                    ipa_opts->id->user_map,
+                                    SDAP_OPTS_USER,
+                                    &ipa_opts->id->user_map,
+                                    &ipa_opts->id->user_map_cnt);
     if (ret != EOK) {
         goto done;
     }
diff --git a/src/providers/ldap/ldap_options.c b/src/providers/ldap/ldap_options.c
index 11ed9c31f0fc03113e5f7ba58b5ce8b74fe6545a..eb00aab32a55c6841ebbf32d30f3a48722e8b165 100644
--- a/src/providers/ldap/ldap_options.c
+++ b/src/providers/ldap/ldap_options.c
@@ -23,44 +23,6 @@
 #include "providers/ldap/sdap_async_private.h"
 #include "util/crypto/sss_crypto.h"
 
-static int sdap_extend_map_with_list(TALLOC_CTX *mem_ctx,
-                                     struct sdap_options *opts,
-                                     int extra_attr_index,
-                                     struct sdap_attr_map *src_map,
-                                     size_t num_entries,
-                                     struct sdap_attr_map **_map,
-                                     size_t *_new_size)
-{
-    const char *extra_attrs;
-    char **extra_attrs_list;
-    errno_t ret;
-
-    extra_attrs = dp_opt_get_string(opts->basic, extra_attr_index);
-    if (extra_attrs == NULL) {
-        *_map = src_map;
-        *_new_size = num_entries;
-        return EOK;
-    }
-
-    /* split server parm into a list */
-    ret = split_on_separator(mem_ctx, extra_attrs, ',', true, true,
-                             &extra_attrs_list, NULL);
-    if (ret != EOK) {
-        DEBUG(SSSDBG_OP_FAILURE, "Failed to parse server list!\n");
-        return ret;
-    }
-
-    ret = sdap_extend_map(mem_ctx, src_map,
-                          num_entries, extra_attrs_list,
-                          _map, _new_size);
-    talloc_free(extra_attrs_list);
-    if (ret != EOK) {
-        return ret;
-    }
-
-    return EOK;
-}
-
 int ldap_get_options(TALLOC_CTX *memctx,
                      struct sss_domain_info *dom,
                      struct confdb_ctx *cdb,
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
index ea28e64cf585ca2f9ea21fe2249d1f6b299926e1..0d3f85c1c2390ca859e9cb3e4e8d63751629201a 100644
--- a/src/providers/ldap/sdap.c
+++ b/src/providers/ldap/sdap.c
@@ -129,6 +129,45 @@ int sdap_extend_map(TALLOC_CTX *memctx,
     return EOK;
 }
 
+int sdap_extend_map_with_list(TALLOC_CTX *mem_ctx,
+                              struct sdap_options *opts,
+                              int extra_attr_index,
+                              struct sdap_attr_map *src_map,
+                              size_t num_entries,
+                              struct sdap_attr_map **_map,
+                              size_t *_new_size)
+{
+    const char *extra_attrs;
+    char **extra_attrs_list;
+    errno_t ret;
+
+    extra_attrs = dp_opt_get_string(opts->basic, extra_attr_index);
+    if (extra_attrs == NULL) {
+        *_map = src_map;
+        *_new_size = num_entries;
+        return EOK;
+    }
+
+    /* split server parm into a list */
+    ret = split_on_separator(mem_ctx, extra_attrs, ',', true, true,
+                             &extra_attrs_list, NULL);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("Failed to parse server list!\n"));
+        return ret;
+    }
+
+
+    ret = sdap_extend_map(mem_ctx, src_map,
+                          num_entries, extra_attrs_list,
+                          _map, _new_size);
+    talloc_free(extra_attrs_list);
+    if (ret != EOK) {
+        return ret;
+    }
+
+    return EOK;
+}
+
 int sdap_get_map(TALLOC_CTX *memctx,
                  struct confdb_ctx *cdb,
                  const char *conf_path,
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 38eec1c4dcd10ea839457bbef442e5993a7bf762..fdf92eecf17548eb23b82c4f3a43ac7ba1695132 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -476,6 +476,14 @@ int sdap_extend_map(TALLOC_CTX *memctx,
                     struct sdap_attr_map **_map,
                     size_t *_new_size);
 
+int sdap_extend_map_with_list(TALLOC_CTX *mem_ctx,
+                              struct sdap_options *opts,
+                              int extra_attr_index,
+                              struct sdap_attr_map *src_map,
+                              size_t num_entries,
+                              struct sdap_attr_map **_map,
+                              size_t *_new_size);
+
 int sdap_get_map(TALLOC_CTX *memctx,
                  struct confdb_ctx *cdb,
                  const char *conf_path,
-- 
1.9.0

