Blob Blame History Raw
From 106d93c6e03bfdf1bfc4f2691562b4855a1d4763 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Mon, 20 May 2019 22:42:47 +0200
Subject: [PATCH 49/64] BE/LDAP: Call be_refresh_ctx_init() in the provider
 libraries, not in back end

Since later patches will pass different parameters to
be_refresh_ctx_init(), let's call the init function in the provider
libraries not directly in the back end.

Related:
https://pagure.io/SSSD/sssd/issue/4012

Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit 9d49c90ceb7388333c8682f4cbd6842ec236b9de)

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/providers/ad/ad_init.c        |  2 +-
 src/providers/data_provider_be.c  |  8 --------
 src/providers/ipa/ipa_init.c      |  2 +-
 src/providers/ldap/ldap_common.h  |  2 +-
 src/providers/ldap/ldap_init.c    |  2 +-
 src/providers/ldap/sdap_refresh.c | 17 +++++++++++++----
 6 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
index 302bcae7d..42c2f150a 100644
--- a/src/providers/ad/ad_init.c
+++ b/src/providers/ad/ad_init.c
@@ -408,7 +408,7 @@ static errno_t ad_init_misc(struct be_ctx *be_ctx,
         return ret;
     }
 
-    ret = sdap_refresh_init(be_ctx->refresh_ctx, sdap_id_ctx);
+    ret = sdap_refresh_init(be_ctx, sdap_id_ctx);
     if (ret != EOK && ret != EEXIST) {
         DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
               "will not work [%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 8dbddbb5f..d13654b8b 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -522,14 +522,6 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
-    /* Initialize be_refresh periodic task. */
-    be_ctx->refresh_ctx = be_refresh_ctx_init(be_ctx);
-    if (be_ctx->refresh_ctx == NULL) {
-        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
-        ret = ENOMEM;
-        goto done;
-    }
-
     ret = dp_init(be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid);
     if (ret != EOK) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup data provider "
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 6818e2171..b3060e228 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -594,7 +594,7 @@ static errno_t ipa_init_misc(struct be_ctx *be_ctx,
         }
     }
 
-    ret = sdap_refresh_init(be_ctx->refresh_ctx, sdap_id_ctx);
+    ret = sdap_refresh_init(be_ctx, sdap_id_ctx);
     if (ret != EOK && ret != EEXIST) {
         DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
               "will not work [%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index 04548a388..f30b67eb3 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -362,7 +362,7 @@ struct sdap_id_ctx *
 sdap_id_ctx_new(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
                 struct sdap_service *sdap_service);
 
-errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
+errno_t sdap_refresh_init(struct be_ctx *be_ctx,
                           struct sdap_id_ctx *id_ctx);
 
 errno_t sdap_init_certmap(TALLOC_CTX *mem_ctx, struct sdap_id_ctx *id_ctx);
diff --git a/src/providers/ldap/ldap_init.c b/src/providers/ldap/ldap_init.c
index 352f0b656..489e1c225 100644
--- a/src/providers/ldap/ldap_init.c
+++ b/src/providers/ldap/ldap_init.c
@@ -432,7 +432,7 @@ static errno_t ldap_init_misc(struct be_ctx *be_ctx,
     }
 
     /* Setup periodical refresh of expired records */
-    ret = sdap_refresh_init(be_ctx->refresh_ctx, id_ctx);
+    ret = sdap_refresh_init(be_ctx, id_ctx);
     if (ret != EOK && ret != EEXIST) {
         DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh will not work "
               "[%d]: %s\n", ret, sss_strerror(ret));
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index 6d6c43e20..457df8be2 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -255,12 +255,19 @@ static errno_t sdap_refresh_netgroups_recv(struct tevent_req *req)
     return sdap_refresh_recv(req);
 }
 
-errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
+errno_t sdap_refresh_init(struct be_ctx *be_ctx,
                           struct sdap_id_ctx *id_ctx)
 {
     errno_t ret;
 
-    ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_USERS,
+    be_ctx->refresh_ctx = be_refresh_ctx_init(be_ctx);
+    if (be_ctx->refresh_ctx == NULL) {
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
+        return ENOMEM;
+    }
+
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
+                            BE_REFRESH_TYPE_USERS,
                             sdap_refresh_users_send,
                             sdap_refresh_users_recv,
                             id_ctx);
@@ -269,7 +276,8 @@ errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
               "will not work [%d]: %s\n", ret, strerror(ret));
     }
 
-    ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_GROUPS,
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
+                            BE_REFRESH_TYPE_USERS,
                             sdap_refresh_groups_send,
                             sdap_refresh_groups_recv,
                             id_ctx);
@@ -278,7 +286,8 @@ errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
               "will not work [%d]: %s\n", ret, strerror(ret));
     }
 
-    ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
+                            BE_REFRESH_TYPE_USERS,
                             sdap_refresh_netgroups_send,
                             sdap_refresh_netgroups_recv,
                             id_ctx);
-- 
2.20.1