Blame SOURCES/0031-LDAP-Remove-the-legacy-POSIX-check-itself.patch

ca1eb8
From 5fcce16c212037b5193556dc2f6bcb7e4d7f0f85 Mon Sep 17 00:00:00 2001
ca1eb8
From: Jakub Hrozek <jhrozek@redhat.com>
ca1eb8
Date: Sat, 30 Jun 2018 13:21:18 +0200
ca1eb8
Subject: [PATCH] LDAP: Remove the legacy POSIX check itself
ca1eb8
MIME-Version: 1.0
ca1eb8
Content-Type: text/plain; charset=UTF-8
ca1eb8
Content-Transfer-Encoding: 8bit
ca1eb8
ca1eb8
This code is no longer needed now.
ca1eb8
ca1eb8
Related:
ca1eb8
https://pagure.io/SSSD/sssd/issue/3755
ca1eb8
ca1eb8
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ca1eb8
(cherry picked from commit 5b2b6493dfb3c1f2cb945356e34c70d8c5d64185)
ca1eb8
ca1eb8
DOWNSTREAM:
ca1eb8
Resolves: rhbz#1582975 - The search filter for detecting POSIX attributes in global catalog is too broad and can cause a high load on the servers
ca1eb8
---
ca1eb8
 src/providers/ad/ad_common.c     |   2 -
ca1eb8
 src/providers/ldap/ldap_common.c |  17 ---
ca1eb8
 src/providers/ldap/ldap_common.h |   7 --
ca1eb8
 src/providers/ldap/sdap.h        |   1 -
ca1eb8
 src/providers/ldap/sdap_async.c  | 174 -------------------------------
ca1eb8
 src/providers/ldap/sdap_async.h  |  13 ---
ca1eb8
 6 files changed, 214 deletions(-)
ca1eb8
ca1eb8
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
ca1eb8
index eaf0814f1aaf51a5085e992efa633240f32c498e..6d395cfb1d4148e803a656a8f7205fe13570085b 100644
ca1eb8
--- a/src/providers/ad/ad_common.c
ca1eb8
+++ b/src/providers/ad/ad_common.c
ca1eb8
@@ -1388,7 +1388,6 @@ ad_gc_conn_list(TALLOC_CTX *mem_ctx, struct ad_id_ctx *ad_ctx,
ca1eb8
         clist[cindex] = ad_ctx->gc_ctx;
ca1eb8
         clist[cindex]->ignore_mark_offline = true;
ca1eb8
         clist[cindex]->no_mpg_user_fallback = true;
ca1eb8
-        clist[cindex]->check_posix_attrs = true;
ca1eb8
         cindex++;
ca1eb8
     }
ca1eb8
 
ca1eb8
@@ -1435,7 +1434,6 @@ ad_user_conn_list(TALLOC_CTX *mem_ctx,
ca1eb8
             && IS_SUBDOMAIN(dom)) {
ca1eb8
         clist[cindex] = ad_ctx->gc_ctx;
ca1eb8
         clist[cindex]->ignore_mark_offline = true;
ca1eb8
-        clist[cindex]->check_posix_attrs = true;
ca1eb8
         cindex++;
ca1eb8
     }
ca1eb8
 
ca1eb8
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
ca1eb8
index a0a9b8523310b2551ee992f8d0c2e369dafaa56d..9cd8ec09c7fdc6bd1c8d64da150178f483f2a5a3 100644
ca1eb8
--- a/src/providers/ldap/ldap_common.c
ca1eb8
+++ b/src/providers/ldap/ldap_common.c
ca1eb8
@@ -884,20 +884,3 @@ sdap_id_ctx_new(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
ca1eb8
 
ca1eb8
     return sdap_ctx;
ca1eb8
 }
ca1eb8
-
ca1eb8
-bool should_run_posix_check(struct sdap_id_ctx *ctx,
ca1eb8
-                            struct sdap_id_conn_ctx *conn,
ca1eb8
-                            bool use_id_mapping,
ca1eb8
-                            bool posix_request)
ca1eb8
-{
ca1eb8
-    if (use_id_mapping == false &&
ca1eb8
-            posix_request == true &&
ca1eb8
-            ctx->opts->schema_type == SDAP_SCHEMA_AD &&
ca1eb8
-            conn->check_posix_attrs == true &&
ca1eb8
-            ctx->srv_opts &&
ca1eb8
-            ctx->srv_opts->posix_checked == false) {
ca1eb8
-        return true;
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    return false;
ca1eb8
-}
ca1eb8
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
ca1eb8
index 3de3568cb28c258c00f9b522c0b9120adca81d81..6c08d789b339424649c938b845e7118f5ea88f73 100644
ca1eb8
--- a/src/providers/ldap/ldap_common.h
ca1eb8
+++ b/src/providers/ldap/ldap_common.h
ca1eb8
@@ -59,8 +59,6 @@ struct sdap_id_conn_ctx {
ca1eb8
     bool ignore_mark_offline;
ca1eb8
     /* do not fall back to user lookups for mpg domains on this connection */
ca1eb8
     bool no_mpg_user_fallback;
ca1eb8
-    /* check if this connection contains POSIX attributes */
ca1eb8
-    bool check_posix_attrs;
ca1eb8
 };
ca1eb8
 
ca1eb8
 struct sdap_id_ctx {
ca1eb8
@@ -309,11 +307,6 @@ char *get_enterprise_principal_string_filter(TALLOC_CTX *mem_ctx,
ca1eb8
                                              const char *princ,
ca1eb8
                                              struct dp_option *sdap_basic_opts);
ca1eb8
 
ca1eb8
-bool should_run_posix_check(struct sdap_id_ctx *ctx,
ca1eb8
-                            struct sdap_id_conn_ctx *conn,
ca1eb8
-                            bool id_mapping,
ca1eb8
-                            bool posix_request);
ca1eb8
-
ca1eb8
 char *sdap_get_access_filter(TALLOC_CTX *mem_ctx,
ca1eb8
                              const char *base_filter);
ca1eb8
 
ca1eb8
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
ca1eb8
index e892c407103b18a296ae6baaf3dcfff11ca4bf31..0790544818633e26ee5a8fbdca556b8230b1df3f 100644
ca1eb8
--- a/src/providers/ldap/sdap.h
ca1eb8
+++ b/src/providers/ldap/sdap.h
ca1eb8
@@ -511,7 +511,6 @@ struct sdap_server_opts {
ca1eb8
     char *max_group_value;
ca1eb8
     char *max_service_value;
ca1eb8
     char *max_sudo_value;
ca1eb8
-    bool posix_checked;
ca1eb8
 };
ca1eb8
 
ca1eb8
 struct sdap_id_ctx;
ca1eb8
diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c
ca1eb8
index 1e77b1c3c612d28a7d1f7e686cbc0b094b07c89d..8fc832ae5720acac07b0e2a24255f6c5e3d6994b 100644
ca1eb8
--- a/src/providers/ldap/sdap_async.c
ca1eb8
+++ b/src/providers/ldap/sdap_async.c
ca1eb8
@@ -2572,180 +2572,6 @@ int sdap_asq_search_recv(struct tevent_req *req,
ca1eb8
     return EOK;
ca1eb8
 }
ca1eb8
 
ca1eb8
-/* ==POSIX attribute presence test================================= */
ca1eb8
-static void sdap_gc_posix_check_done(struct tevent_req *subreq);
ca1eb8
-static errno_t sdap_gc_posix_check_parse(struct sdap_handle *sh,
ca1eb8
-                                         struct sdap_msg *msg,
ca1eb8
-                                         void *pvt);
ca1eb8
-
ca1eb8
-struct sdap_gc_posix_check_state {
ca1eb8
-    struct tevent_context *ev;
ca1eb8
-    struct sdap_options *opts;
ca1eb8
-    struct sdap_handle *sh;
ca1eb8
-    int timeout;
ca1eb8
-
ca1eb8
-    const char **attrs;
ca1eb8
-    const char *filter;
ca1eb8
-
ca1eb8
-    bool has_posix;
ca1eb8
-};
ca1eb8
-
ca1eb8
-struct tevent_req *
ca1eb8
-sdap_gc_posix_check_send(TALLOC_CTX *memctx, struct tevent_context *ev,
ca1eb8
-                         struct sdap_options *opts, struct sdap_handle *sh,
ca1eb8
-                         int timeout)
ca1eb8
-{
ca1eb8
-    struct tevent_req *req = NULL;
ca1eb8
-    struct tevent_req *subreq = NULL;
ca1eb8
-    struct sdap_gc_posix_check_state *state;
ca1eb8
-    errno_t ret;
ca1eb8
-
ca1eb8
-    req = tevent_req_create(memctx, &state, struct sdap_gc_posix_check_state);
ca1eb8
-    if (req == NULL) {
ca1eb8
-        return NULL;
ca1eb8
-    }
ca1eb8
-    state->ev = ev;
ca1eb8
-    state->sh = sh;
ca1eb8
-    state->opts = opts;
ca1eb8
-    state->timeout = timeout;
ca1eb8
-
ca1eb8
-    state->attrs = talloc_array(state, const char *, 4);
ca1eb8
-    if (state->attrs == NULL) {
ca1eb8
-        ret = ENOMEM;
ca1eb8
-        goto fail;
ca1eb8
-    }
ca1eb8
-    state->attrs[0] = "objectclass";
ca1eb8
-    state->attrs[1] = opts->user_map[SDAP_AT_USER_UID].name;
ca1eb8
-    state->attrs[2] = opts->group_map[SDAP_AT_GROUP_GID].name;
ca1eb8
-    state->attrs[3] = NULL;
ca1eb8
-
ca1eb8
-    state->filter = talloc_asprintf(state,
ca1eb8
-        "(|(&(%s=*)(objectclass=%s))(&(%s=*)(objectclass=%s)))",
ca1eb8
-                                    opts->user_map[SDAP_AT_USER_UID].name,
ca1eb8
-                                    opts->user_map[SDAP_OC_USER].name,
ca1eb8
-                                    opts->group_map[SDAP_AT_GROUP_GID].name,
ca1eb8
-                                    opts->group_map[SDAP_OC_GROUP].name);
ca1eb8
-    if (state->filter == NULL) {
ca1eb8
-        ret = ENOMEM;
ca1eb8
-        goto fail;
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    subreq = sdap_get_generic_ext_send(state, state->ev, state->opts,
ca1eb8
-                                 state->sh,
ca1eb8
-                                 "",
ca1eb8
-                                 LDAP_SCOPE_SUBTREE, state->filter,
ca1eb8
-                                 state->attrs,
ca1eb8
-                                 NULL, NULL, 1, state->timeout,
ca1eb8
-                                 sdap_gc_posix_check_parse, state,
ca1eb8
-                                 SDAP_SRCH_FLG_SIZELIMIT_SILENT);
ca1eb8
-    if (subreq == NULL) {
ca1eb8
-        ret = ENOMEM;
ca1eb8
-        goto fail;
ca1eb8
-    }
ca1eb8
-    tevent_req_set_callback(subreq, sdap_gc_posix_check_done, req);
ca1eb8
-
ca1eb8
-    return req;
ca1eb8
-
ca1eb8
-fail:
ca1eb8
-    tevent_req_error(req, ret);
ca1eb8
-    tevent_req_post(req, ev);
ca1eb8
-    return req;
ca1eb8
-}
ca1eb8
-
ca1eb8
-static errno_t sdap_gc_posix_check_parse(struct sdap_handle *sh,
ca1eb8
-                                         struct sdap_msg *msg,
ca1eb8
-                                         void *pvt)
ca1eb8
-{
ca1eb8
-    struct berval **vals = NULL;
ca1eb8
-    struct sdap_gc_posix_check_state *state =
ca1eb8
-        talloc_get_type(pvt, struct sdap_gc_posix_check_state);
ca1eb8
-    char *dn;
ca1eb8
-    char *endptr;
ca1eb8
-
ca1eb8
-    dn = ldap_get_dn(sh->ldap, msg->msg);
ca1eb8
-    if (dn == NULL) {
ca1eb8
-        DEBUG(SSSDBG_TRACE_LIBS,
ca1eb8
-              "Search did not find any entry with POSIX attributes\n");
ca1eb8
-        goto done;
ca1eb8
-    }
ca1eb8
-    DEBUG(SSSDBG_TRACE_LIBS, "Found [%s] with POSIX attributes\n", dn);
ca1eb8
-    ldap_memfree(dn);
ca1eb8
-
ca1eb8
-    vals = ldap_get_values_len(sh->ldap, msg->msg,
ca1eb8
-                               state->opts->user_map[SDAP_AT_USER_UID].name);
ca1eb8
-    if (vals == NULL) {
ca1eb8
-        vals = ldap_get_values_len(sh->ldap, msg->msg,
ca1eb8
-                               state->opts->group_map[SDAP_AT_GROUP_GID].name);
ca1eb8
-        if (vals == NULL) {
ca1eb8
-            DEBUG(SSSDBG_TRACE_LIBS, "Entry does not have POSIX attrs?\n");
ca1eb8
-            goto done;
ca1eb8
-        }
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    if (vals[0] == NULL) {
ca1eb8
-        DEBUG(SSSDBG_TRACE_LIBS, "No value for POSIX attr\n");
ca1eb8
-        goto done;
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    errno = 0;
ca1eb8
-    strtouint32(vals[0]->bv_val, &endptr, 10);
ca1eb8
-    if (errno || *endptr || (vals[0]->bv_val == endptr)) {
ca1eb8
-        DEBUG(SSSDBG_MINOR_FAILURE,
ca1eb8
-              "POSIX attribute is not a number: %s\n", vals[0]->bv_val);
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    state->has_posix = true;
ca1eb8
-done:
ca1eb8
-    ldap_value_free_len(vals);
ca1eb8
-    return EOK;
ca1eb8
-}
ca1eb8
-
ca1eb8
-static void sdap_gc_posix_check_done(struct tevent_req *subreq)
ca1eb8
-{
ca1eb8
-    struct tevent_req *req = tevent_req_callback_data(subreq,
ca1eb8
-                                                      struct tevent_req);
ca1eb8
-    struct sdap_gc_posix_check_state *state =
ca1eb8
-        tevent_req_data(req, struct sdap_gc_posix_check_state);
ca1eb8
-    errno_t ret;
ca1eb8
-
ca1eb8
-    ret = sdap_get_generic_ext_recv(subreq, NULL, NULL, NULL);
ca1eb8
-    talloc_zfree(subreq);
ca1eb8
-    if (ret != EOK) {
ca1eb8
-        DEBUG(SSSDBG_OP_FAILURE,
ca1eb8
-              "sdap_get_generic_ext_recv failed [%d]: %s\n",
ca1eb8
-              ret, strerror(ret));
ca1eb8
-        tevent_req_error(req, ret);
ca1eb8
-        return;
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    /* Positive hit is definitive, no need to search other bases */
ca1eb8
-    if (state->has_posix == true) {
ca1eb8
-        DEBUG(SSSDBG_FUNC_DATA, "Server has POSIX attributes. Global Catalog will "
ca1eb8
-                                "be used for user and group lookups. Note that if "
ca1eb8
-                                "only a subset of POSIX attributes is present "
ca1eb8
-                                "in GC, the non-replicated attributes are "
ca1eb8
-                                "currently not read from the LDAP port\n");
ca1eb8
-        tevent_req_done(req);
ca1eb8
-        return;
ca1eb8
-    }
ca1eb8
-
ca1eb8
-    /* All bases done! */
ca1eb8
-    DEBUG(SSSDBG_TRACE_LIBS, "Cycled through all bases\n");
ca1eb8
-    tevent_req_done(req);
ca1eb8
-}
ca1eb8
-
ca1eb8
-int sdap_gc_posix_check_recv(struct tevent_req *req,
ca1eb8
-                             bool *_has_posix)
ca1eb8
-{
ca1eb8
-    struct sdap_gc_posix_check_state *state = tevent_req_data(req,
ca1eb8
-                                            struct sdap_gc_posix_check_state);
ca1eb8
-
ca1eb8
-    TEVENT_REQ_RETURN_ON_ERROR(req);
ca1eb8
-
ca1eb8
-    *_has_posix = state->has_posix;
ca1eb8
-    return EOK;
ca1eb8
-}
ca1eb8
-
ca1eb8
 /* ==Generic Deref Search============================================ */
ca1eb8
 enum sdap_deref_type {
ca1eb8
     SDAP_DEREF_OPENLDAP,
ca1eb8
diff --git a/src/providers/ldap/sdap_async.h b/src/providers/ldap/sdap_async.h
ca1eb8
index 6ca3ed8d82ea7e4cb049b1c65c639b2773b8c296..6d09aca7a3465df4503991f0dc82e2af3871ccd5 100644
ca1eb8
--- a/src/providers/ldap/sdap_async.h
ca1eb8
+++ b/src/providers/ldap/sdap_async.h
ca1eb8
@@ -281,19 +281,6 @@ int sdap_deref_search_recv(struct tevent_req *req,
ca1eb8
                            size_t *reply_count,
ca1eb8
                            struct sdap_deref_attrs ***reply);
ca1eb8
 
ca1eb8
-/*
ca1eb8
- * This request should only be ran against a Global Catalog connection
ca1eb8
- * because it uses a NULL search base to search all domains in the forest,
ca1eb8
- * which would return an error with an LDAP port:
ca1eb8
- *  https://technet.microsoft.com/en-us/library/cc755809(v=ws.10).aspx
ca1eb8
- */
ca1eb8
-struct tevent_req *
ca1eb8
-sdap_gc_posix_check_send(TALLOC_CTX *memctx, struct tevent_context *ev,
ca1eb8
-                         struct sdap_options *opts, struct sdap_handle *sh,
ca1eb8
-                         int timeout);
ca1eb8
-
ca1eb8
-int sdap_gc_posix_check_recv(struct tevent_req *req,
ca1eb8
-                             bool *_has_posix);
ca1eb8
 
ca1eb8
 struct tevent_req *
ca1eb8
 sdap_sd_search_send(TALLOC_CTX *memctx,
ca1eb8
-- 
ca1eb8
2.17.1
ca1eb8