Blame SOURCES/0014-SYSDB-Cache-selector-as-enum.patch

836b22
From d93b4fe14b0f72bd8311497d18204f153c104007 Mon Sep 17 00:00:00 2001
836b22
From: =?UTF-8?q?Pawe=C5=82=20Po=C5=82awski?= <ppolawsk@redhat.com>
836b22
Date: Fri, 13 Mar 2020 00:57:55 +0000
836b22
Subject: [PATCH 14/14] SYSDB: Cache selector as enum
836b22
MIME-Version: 1.0
836b22
Content-Type: text/plain; charset=UTF-8
836b22
Content-Transfer-Encoding: 8bit
836b22
836b22
Sysdb has two sources of cache: timestamp based and persistent.
836b22
This change changes implementation of that selector from
836b22
binary flag to enum.
836b22
836b22
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
836b22
836b22
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
836b22
---
836b22
 src/db/sysdb.h                         |  9 +++++---
836b22
 src/db/sysdb_search.c                  | 32 ++++++++++++++++++++++----
836b22
 src/providers/be_refresh.c             | 10 ++++----
836b22
 src/tests/cmocka/test_sysdb_ts_cache.c | 10 ++++----
836b22
 4 files changed, 43 insertions(+), 18 deletions(-)
836b22
836b22
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
836b22
index 0e6e9266b..beee710af 100644
836b22
--- a/src/db/sysdb.h
836b22
+++ b/src/db/sysdb.h
836b22
@@ -1217,14 +1217,17 @@ int sysdb_search_users(TALLOC_CTX *mem_ctx,
836b22
                        size_t *msgs_count,
836b22
                        struct ldb_message ***msgs);
836b22
 
836b22
-#define SYSDB_SEARCH_WITH_TS_ONLY_TS_FILTER     0x0001
836b22
-#define SYSDB_SEARCH_WITH_TS_ONLY_SYSDB_FILTER  0x0002
836b22
+enum sysdb_cache_type {
836b22
+    SYSDB_CACHE_TYPE_NONE,
836b22
+    SYSDB_CACHE_TYPE_TIMESTAMP,
836b22
+    SYSDB_CACHE_TYPE_PERSISTENT
836b22
+};
836b22
 
836b22
 errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
                                   struct sss_domain_info *domain,
836b22
                                   struct ldb_dn *base_dn,
836b22
                                   enum ldb_scope scope,
836b22
-                                  int optflags,
836b22
+                                  enum sysdb_cache_type search_cache,
836b22
                                   const char *filter,
836b22
                                   const char *attrs[],
836b22
                                   struct ldb_result **_result);
836b22
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
836b22
index a71c43112..6c89b4c98 100644
836b22
--- a/src/db/sysdb_search.c
836b22
+++ b/src/db/sysdb_search.c
836b22
@@ -639,7 +639,7 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
                                   struct sss_domain_info *domain,
836b22
                                   struct ldb_dn *base_dn,
836b22
                                   enum ldb_scope scope,
836b22
-                                  int optflags,
836b22
+                                  enum sysdb_cache_type search_cache,
836b22
                                   const char *filter,
836b22
                                   const char *attrs[],
836b22
                                   struct ldb_result **_res)
836b22
@@ -666,7 +666,8 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
         goto done;
836b22
     }
836b22
 
836b22
-    if (optflags & SYSDB_SEARCH_WITH_TS_ONLY_SYSDB_FILTER) {
836b22
+    switch (search_cache) {
836b22
+    case SYSDB_CACHE_TYPE_PERSISTENT: {
836b22
         /* We only care about searching the persistent db */
836b22
         ts_cache_res = talloc_zero(tmp_ctx, struct ldb_result);
836b22
         if (ts_cache_res == NULL) {
836b22
@@ -675,7 +676,14 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
         }
836b22
         ts_cache_res->count = 0;
836b22
         ts_cache_res->msgs = NULL;
836b22
-    } else {
836b22
+
836b22
+        break;
836b22
+    }
836b22
+
836b22
+    case SYSDB_CACHE_TYPE_TIMESTAMP:
836b22
+        /* FALLTHOUGH*/
836b22
+        SSS_ATTRIBUTE_FALLTHROUGH;
836b22
+    default: {
836b22
         /* Because the timestamp database does not contain all the
836b22
          * attributes, we need to search the persistent db for each
836b22
          * of the entries found and merge the results
836b22
@@ -708,9 +716,13 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
         if (ret != EOK) {
836b22
             goto done;
836b22
         }
836b22
+
836b22
+        break;
836b22
+    }
836b22
     }
836b22
 
836b22
-    if (optflags & SYSDB_SEARCH_WITH_TS_ONLY_TS_FILTER) {
836b22
+    switch (search_cache) {
836b22
+    case SYSDB_CACHE_TYPE_TIMESTAMP: {
836b22
         /* The filter only contains timestamp attrs, no need to search the
836b22
          * persistent db
836b22
          */
836b22
@@ -718,7 +730,14 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
             res->count = ts_cache_res->count;
836b22
             res->msgs = talloc_steal(res, ts_cache_res->msgs);
836b22
         }
836b22
-    } else {
836b22
+
836b22
+        break;
836b22
+    }
836b22
+
836b22
+    case SYSDB_CACHE_TYPE_PERSISTENT:
836b22
+        /* FALLTHOUGH*/
836b22
+        SSS_ATTRIBUTE_FALLTHROUGH;
836b22
+    default: {
836b22
         /* Because some of the attributes being searched might exist in the persistent
836b22
          * database only, we also search the persistent db
836b22
          */
836b22
@@ -738,6 +757,9 @@ errno_t sysdb_search_with_ts_attr(TALLOC_CTX *mem_ctx,
836b22
             ret = ENOMEM;
836b22
             goto done;
836b22
         }
836b22
+
836b22
+        break;
836b22
+    }
836b22
     }
836b22
 
836b22
     *_res = talloc_steal(mem_ctx, res);
836b22
diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
836b22
index d503556a3..8fcfb86b4 100644
836b22
--- a/src/providers/be_refresh.c
836b22
+++ b/src/providers/be_refresh.c
836b22
@@ -35,7 +35,7 @@ static errno_t be_refresh_get_values_ex(TALLOC_CTX *mem_ctx,
836b22
                                         struct ldb_dn *base_dn,
836b22
                                         const char *key_attr,
836b22
                                         const char *value_attr,
836b22
-                                        int optflags,
836b22
+                                        enum sysdb_cache_type search_cache,
836b22
                                         char ***_values)
836b22
 {
836b22
     TALLOC_CTX *tmp_ctx = NULL;
836b22
@@ -65,7 +65,7 @@ static errno_t be_refresh_get_values_ex(TALLOC_CTX *mem_ctx,
836b22
 
836b22
     ret = sysdb_search_with_ts_attr(tmp_ctx, domain, base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    optflags,
836b22
+                                    search_cache,
836b22
                                     filter, attrs,
836b22
                                     &res;;
836b22
     if (ret != EOK) {
836b22
@@ -103,7 +103,7 @@ static errno_t be_refresh_get_values(TALLOC_CTX *mem_ctx,
836b22
     struct ldb_dn *base_dn = NULL;
836b22
     errno_t ret;
836b22
     const char *key_attr;
836b22
-    int optflags = SYSDB_SEARCH_WITH_TS_ONLY_TS_FILTER;
836b22
+    enum sysdb_cache_type search_cache = SYSDB_CACHE_TYPE_TIMESTAMP;
836b22
 
836b22
     switch (type) {
836b22
     case BE_REFRESH_TYPE_INITGROUPS:
836b22
@@ -121,7 +121,7 @@ static errno_t be_refresh_get_values(TALLOC_CTX *mem_ctx,
836b22
     case BE_REFRESH_TYPE_NETGROUPS:
836b22
         key_attr = SYSDB_CACHE_EXPIRE;
836b22
         // Netgroup will reside in persistent cache rather than timestamp one
836b22
-        optflags = SYSDB_SEARCH_WITH_TS_ONLY_SYSDB_FILTER;
836b22
+        search_cache = SYSDB_CACHE_TYPE_PERSISTENT;
836b22
         base_dn = sysdb_netgroup_base_dn(mem_ctx, domain);
836b22
         break;
836b22
     default:
836b22
@@ -136,7 +136,7 @@ static errno_t be_refresh_get_values(TALLOC_CTX *mem_ctx,
836b22
 
836b22
     ret = be_refresh_get_values_ex(mem_ctx, domain, period,
836b22
                                    base_dn, key_attr,
836b22
-                                   attr_name, optflags, _values);
836b22
+                                   attr_name, search_cache, _values);
836b22
 
836b22
     talloc_free(base_dn);
836b22
     return ret;
836b22
diff --git a/src/tests/cmocka/test_sysdb_ts_cache.c b/src/tests/cmocka/test_sysdb_ts_cache.c
836b22
index d2296d1b8..ae8b1b16c 100644
836b22
--- a/src/tests/cmocka/test_sysdb_ts_cache.c
836b22
+++ b/src/tests/cmocka/test_sysdb_ts_cache.c
836b22
@@ -1438,7 +1438,7 @@ static void test_sysdb_search_with_ts(void **state)
836b22
                                     test_ctx->tctx->dom,
836b22
                                     base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    0,
836b22
+                                    SYSDB_CACHE_TYPE_NONE,
836b22
                                     SYSDB_NAME"=*",
836b22
                                     attrs,
836b22
                                     &res;;
836b22
@@ -1523,7 +1523,7 @@ static void test_sysdb_search_with_ts(void **state)
836b22
                                     test_ctx->tctx->dom,
836b22
                                     base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    0,
836b22
+                                    SYSDB_CACHE_TYPE_NONE,
836b22
                                     filter,
836b22
                                     attrs,
836b22
                                     &res;;
836b22
@@ -1552,7 +1552,7 @@ static void test_sysdb_search_with_ts(void **state)
836b22
                                     test_ctx->tctx->dom,
836b22
                                     base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    SYSDB_SEARCH_WITH_TS_ONLY_TS_FILTER,
836b22
+                                    SYSDB_CACHE_TYPE_TIMESTAMP,
836b22
                                     filter,
836b22
                                     attrs,
836b22
                                     &res;;
836b22
@@ -1571,7 +1571,7 @@ static void test_sysdb_search_with_ts(void **state)
836b22
                                     test_ctx->tctx->dom,
836b22
                                     base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    SYSDB_SEARCH_WITH_TS_ONLY_SYSDB_FILTER,
836b22
+                                    SYSDB_CACHE_TYPE_PERSISTENT,
836b22
                                     filter,
836b22
                                     attrs,
836b22
                                     &res;;
836b22
@@ -1596,7 +1596,7 @@ static void test_sysdb_search_with_ts(void **state)
836b22
                                     test_ctx->tctx->dom,
836b22
                                     base_dn,
836b22
                                     LDB_SCOPE_SUBTREE,
836b22
-                                    0,
836b22
+                                    SYSDB_CACHE_TYPE_NONE,
836b22
                                     filter,
836b22
                                     attrs,
836b22
                                     &res;;
836b22
-- 
836b22
2.21.1
836b22