>From 2281410185205ab3fc483f4c45b1b1378b62c331 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Fri, 25 Sep 2015 07:05:30 -0400
Subject: [PATCH] SDAP: rem warning - sizelimit exceeded in POSIX check

Add new parameter 'flags' to sdap_get_generic_ext_send_ext() which can
be set to suppress warning about 'sizelimit exceeded'.

Resolves:
https://fedorahosted.org/sssd/ticket/2804
---
 src/providers/ldap/sdap_async.c | 78 +++++++++++++++++++++++++++++------------
 1 file changed, 56 insertions(+), 22 deletions(-)

diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c
index 97c9ea5df61a6516ca74bb73edc9a116b1266c71..0044ea9c319af08a87fa59e89559851ad6e8abc5 100644
--- a/src/providers/ldap/sdap_async.c
+++ b/src/providers/ldap/sdap_async.c
@@ -1164,6 +1164,8 @@ struct sdap_get_generic_ext_state {
     void *cb_data;
 
     bool allow_paging;
+
+    unsigned int flags;
 };
 
 static errno_t sdap_get_generic_ext_step(struct tevent_req *req);
@@ -1172,23 +1174,26 @@ static void sdap_get_generic_op_finished(struct sdap_op *op,
                                          struct sdap_msg *reply,
                                          int error, void *pvt);
 
+#define WARN_SIZELIMIT 1
+
 static struct tevent_req *
-sdap_get_generic_ext_send(TALLOC_CTX *memctx,
-                          struct tevent_context *ev,
-                          struct sdap_options *opts,
-                          struct sdap_handle *sh,
-                          const char *search_base,
-                          int scope,
-                          const char *filter,
-                          const char **attrs,
-                          int attrsonly,
-                          LDAPControl **serverctrls,
-                          LDAPControl **clientctrls,
-                          int sizelimit,
-                          int timeout,
-                          bool allow_paging,
-                          sdap_parse_cb parse_cb,
-                          void *cb_data)
+sdap_get_generic_ext_send_ext(TALLOC_CTX *memctx,
+                              struct tevent_context *ev,
+                              struct sdap_options *opts,
+                              struct sdap_handle *sh,
+                              const char *search_base,
+                              int scope,
+                              const char *filter,
+                              const char **attrs,
+                              int attrsonly,
+                              LDAPControl **serverctrls,
+                              LDAPControl **clientctrls,
+                              int sizelimit,
+                              int timeout,
+                              bool allow_paging,
+                              sdap_parse_cb parse_cb,
+                              void *cb_data,
+                              unsigned int flags)
 {
     errno_t ret;
     struct sdap_get_generic_ext_state *state;
@@ -1215,6 +1220,7 @@ sdap_get_generic_ext_send(TALLOC_CTX *memctx,
     state->parse_cb = parse_cb;
     state->cb_data = cb_data;
     state->clientctrls = clientctrls;
+    state->flags = flags;
 
     if (state->sh == NULL || state->sh->ldap == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE,
@@ -1282,6 +1288,31 @@ sdap_get_generic_ext_send(TALLOC_CTX *memctx,
     return req;
 }
 
+static struct tevent_req *
+sdap_get_generic_ext_send(TALLOC_CTX *memctx,
+                          struct tevent_context *ev,
+                          struct sdap_options *opts,
+                          struct sdap_handle *sh,
+                          const char *search_base,
+                          int scope,
+                          const char *filter,
+                          const char **attrs,
+                          int attrsonly,
+                          LDAPControl **serverctrls,
+                          LDAPControl **clientctrls,
+                          int sizelimit,
+                          int timeout,
+                          bool allow_paging,
+                          sdap_parse_cb parse_cb,
+                          void *cb_data)
+{
+    return sdap_get_generic_ext_send_ext(memctx, ev, opts, sh, search_base,
+                                         scope, filter, attrs, attrsonly,
+                                         serverctrls, clientctrls, sizelimit,
+                                         timeout, allow_paging, parse_cb,
+                                         cb_data, WARN_SIZELIMIT);
+}
+
 static errno_t sdap_get_generic_ext_step(struct tevent_req *req)
 {
     struct sdap_get_generic_ext_state *state =
@@ -1500,8 +1531,11 @@ static void sdap_get_generic_op_finished(struct sdap_op *op,
 
         if (result == LDAP_SIZELIMIT_EXCEEDED) {
             /* Try to return what we've got */
-            DEBUG(SSSDBG_MINOR_FAILURE,
-                  "LDAP sizelimit was exceeded, returning incomplete data\n");
+            if (state->flags & WARN_SIZELIMIT) {
+                DEBUG(SSSDBG_MINOR_FAILURE,
+                      "LDAP sizelimit was exceeded, "
+                      "returning incomplete data\n");
+            }
         } else if (result == LDAP_INAPPROPRIATE_MATCHING) {
             /* This error should only occur when we're testing for
              * specialized functionality like the ldap matching rule
@@ -1708,7 +1742,8 @@ struct tevent_req *sdap_get_and_parse_generic_send(TALLOC_CTX *memctx,
     subreq = sdap_get_generic_ext_send(state, ev, opts, sh, search_base,
                                        scope, filter, attrs, false, NULL,
                                        NULL, sizelimit, timeout, allow_paging,
-                                       sdap_get_and_parse_generic_parse_entry, state);
+                                       sdap_get_and_parse_generic_parse_entry,
+                                       state);
     if (!subreq) {
         talloc_zfree(req);
         return NULL;
@@ -2617,14 +2652,13 @@ static errno_t sdap_posix_check_next(struct tevent_req *req)
           "Searching for POSIX attributes with base [%s]\n",
            state->search_bases[state->base_iter]->basedn);
 
-    subreq = sdap_get_generic_ext_send(state, state->ev, state->opts,
+    subreq = sdap_get_generic_ext_send_ext(state, state->ev, state->opts,
                                  state->sh,
                                  state->search_bases[state->base_iter]->basedn,
                                  LDAP_SCOPE_SUBTREE, state->filter,
                                  state->attrs, false,
                                  NULL, NULL, 1, state->timeout,
-                                 false, sdap_posix_check_parse,
-                                 state);
+                                 false, sdap_posix_check_parse, state, 0);
     if (subreq == NULL) {
         return ENOMEM;
     }
-- 
2.4.3

