From aa4e1f694cba25b49a5dbb143bd5cfb866e53e98 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Wed, 23 May 2012 05:50:36 -0400
Subject: [PATCH 2/2] Utilize attribute exclusion in LDAP initgroups

Previous patch added the possibility to exclude some attributes from a
map when building an attribute list to be sent to server. The original
reason for this functionality is the code handling LDAP initgroups. In
this code, there is no need to fetch members of groups in question. This
can save some performance since the list of members can be pretty long
in some cases.
---
 src/providers/ldap/sdap_async_initgroups.c |   60 +++++++++++++++++++++++++--
 1 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c
index afb1b5b49fb477ea2d6e5e18910e2262a0ca1cb2..9d753b96c0b71ea2cd03c04b816e3e1152d96c00 100644
--- a/src/providers/ldap/sdap_async_initgroups.c
+++ b/src/providers/ldap/sdap_async_initgroups.c
@@ -323,6 +323,7 @@ struct tevent_req *sdap_initgr_rfc2307_send(TALLOC_CTX *memctx,
 {
     struct tevent_req *req;
     struct sdap_initgr_rfc2307_state *state;
+    const char **attr_filter;
     char *clean_name;
     errno_t ret;
 
@@ -353,8 +354,17 @@ struct tevent_req *sdap_initgr_rfc2307_send(TALLOC_CTX *memctx,
         return NULL;
     }
 
+    attr_filter = talloc_array(state, const char *, 2);
+    if (!attr_filter) {
+        talloc_free(req);
+        return NULL;
+    }
+
+    attr_filter[0] = opts->group_map[SDAP_AT_GROUP_MEMBER].name;
+    attr_filter[1] = NULL;
+
     ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
-                               NULL, &state->attrs, NULL);
+                               attr_filter, &state->attrs, NULL);
     if (ret != EOK) {
         talloc_free(req);
         return NULL;
@@ -830,6 +840,7 @@ static errno_t sdap_initgr_nested_deref_search(struct tevent_req *req)
     struct sdap_attr_map_info *maps;
     const int num_maps = 1;
     const char **sdap_attrs;
+    const char **attr_filter;
     errno_t ret;
     int timeout;
     struct sdap_initgr_nested_state *state;
@@ -843,8 +854,17 @@ static errno_t sdap_initgr_nested_deref_search(struct tevent_req *req)
     maps[0].num_attrs = SDAP_OPTS_GROUP;
     maps[1].map = NULL;
 
+    attr_filter = talloc_array(state, const char *, 2);
+    if (!attr_filter) {
+        ret = ENOMEM;
+        goto fail;
+    }
+
+    attr_filter[0] = state->opts->group_map[SDAP_AT_GROUP_MEMBER].name;
+    attr_filter[1] = NULL;
+
     ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
-                               NULL, &sdap_attrs, NULL);
+                               attr_filter, &sdap_attrs, NULL);
     if (ret != EOK) goto fail;
 
     timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
@@ -1463,6 +1483,7 @@ static struct tevent_req *sdap_initgr_rfc2307bis_send(
     errno_t ret;
     struct tevent_req *req;
     struct sdap_initgr_rfc2307bis_state *state;
+    const char **attr_filter;
     char *clean_orig_dn;
 
     req = tevent_req_create(memctx, &state, struct sdap_initgr_rfc2307bis_state);
@@ -1495,8 +1516,17 @@ static struct tevent_req *sdap_initgr_rfc2307bis_send(
         return NULL;
     }
 
+    attr_filter = talloc_array(state, const char *, 2);
+    if (!attr_filter) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    attr_filter[0] = opts->group_map[SDAP_AT_GROUP_MEMBER].name;
+    attr_filter[1] = NULL;
+
     ret = build_attrs_from_map(state, opts->group_map, SDAP_OPTS_GROUP,
-                               NULL, &state->attrs, NULL);
+                               attr_filter, &state->attrs, NULL);
     if (ret != EOK) goto done;
 
     ret = sss_filter_sanitize(state, orig_dn, &clean_orig_dn);
@@ -2105,6 +2135,7 @@ static errno_t rfc2307bis_nested_groups_step(struct tevent_req *req)
 {
     errno_t ret;
     TALLOC_CTX *tmp_ctx = NULL;
+    const char **attr_filter;
     char *clean_orig_dn;
     hash_key_t key;
     hash_value_t value;
@@ -2168,8 +2199,17 @@ static errno_t rfc2307bis_nested_groups_step(struct tevent_req *req)
         goto done;
     }
 
+    attr_filter = talloc_array(state, const char *, 2);
+    if (!attr_filter) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    attr_filter[0] = state->opts->group_map[SDAP_AT_GROUP_MEMBER].name;
+    attr_filter[1] = NULL;
+
     ret = build_attrs_from_map(state, state->opts->group_map, SDAP_OPTS_GROUP,
-                               NULL, &state->attrs, NULL);
+                               attr_filter, &state->attrs, NULL);
     if (ret != EOK) {
         goto done;
     }
@@ -2461,6 +2501,7 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx,
 {
     struct tevent_req *req;
     struct sdap_get_initgr_state *state;
+    const char **attr_filter;
     int ret;
     char *clean_name;
 
@@ -2504,8 +2545,17 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx,
         return NULL;
     }
 
+    attr_filter = talloc_array(state, const char *, 2);
+    if (!attr_filter) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    attr_filter[0] = state->opts->group_map[SDAP_AT_GROUP_MEMBER].name;
+    attr_filter[1] = NULL;
+
     ret = build_attrs_from_map(state, state->opts->user_map, SDAP_OPTS_USER,
-                               NULL, &state->user_attrs, NULL);
+                               attr_filter, &state->user_attrs, NULL);
     if (ret) {
         talloc_zfree(req);
         return NULL;
-- 
1.7.7.6

