>From 8696088315cda39ef4c63eb99235c973fe840c72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 19 Feb 2015 12:04:09 +0100
Subject: [PATCH 4/8] be_refresh: add sdap_refresh_init

---
 src/providers/ad/ad_init.c        |  7 ++-----
 src/providers/ipa/ipa_init.c      |  7 ++-----
 src/providers/ldap/ldap_common.h  | 10 ++--------
 src/providers/ldap/ldap_init.c    |  7 ++-----
 src/providers/ldap/sdap_refresh.c | 32 +++++++++++++++++++++++++-------
 5 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
index 2de7e0a44015750c7a4c7980d4ebeb26736c4f02..ca2d49f624e9f7a9155e7f744fb41d6f4ec4b3b3 100644
--- a/src/providers/ad/ad_init.c
+++ b/src/providers/ad/ad_init.c
@@ -260,12 +260,9 @@ sssm_ad_id_init(struct be_ctx *bectx,
     }
 
     /* setup periodical refresh of expired records */
-    ret = be_refresh_add_cb(bectx->refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
-                            sdap_refresh_netgroups_send,
-                            sdap_refresh_netgroups_recv,
-                            ad_ctx->sdap_id_ctx);
+    ret = sdap_refresh_init(bectx->refresh_ctx, ad_ctx->sdap_id_ctx);
     if (ret != EOK && ret != EEXIST) {
-        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
               "will not work [%d]: %s\n", ret, strerror(ret));
     }
 
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 160d15cac42a1c1083722d656d369442e6ee4dd8..4b26e8baad4d0592729aec9a0b188ae89973fa98 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -354,12 +354,9 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
     }
 
     /* setup periodical refresh of expired records */
-    ret = be_refresh_add_cb(bectx->refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
-                            sdap_refresh_netgroups_send,
-                            sdap_refresh_netgroups_recv,
-                            sdap_ctx);
+    ret = sdap_refresh_init(bectx->refresh_ctx, sdap_ctx);
     if (ret != EOK && ret != EEXIST) {
-        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
               "will not work [%d]: %s\n", ret, strerror(ret));
     }
 
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index f8b4e014223b33da84f436a2be853139059f40e7..bf69489a79e903a98878edb53d372d2242df2b0f 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -324,13 +324,7 @@ struct sdap_id_ctx *
 sdap_id_ctx_new(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
                 struct sdap_service *sdap_service);
 
-struct tevent_req *sdap_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
-                                               struct tevent_context *ev,
-                                               struct be_ctx *be_ctx,
-                                               struct sss_domain_info *domain,
-                                               char **names,
-                                               void *pvt);
-
-errno_t sdap_refresh_netgroups_recv(struct tevent_req *req);
+errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
+                          struct sdap_id_ctx *id_ctx);
 
 #endif /* _LDAP_COMMON_H_ */
diff --git a/src/providers/ldap/ldap_init.c b/src/providers/ldap/ldap_init.c
index 8d5619779d38c0df5ec4761b4409c71e8976686c..39d96f92c86e21c1a3864228828f95a4351c3c6b 100644
--- a/src/providers/ldap/ldap_init.c
+++ b/src/providers/ldap/ldap_init.c
@@ -179,12 +179,9 @@ static int ldap_id_init_internal(struct be_ctx *bectx,
     }
 
     /* setup periodical refresh of expired records */
-    ret = be_refresh_add_cb(bectx->refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
-                            sdap_refresh_netgroups_send,
-                            sdap_refresh_netgroups_recv,
-                            ctx);
+    ret = sdap_refresh_init(bectx->refresh_ctx, ctx);
     if (ret != EOK && ret != EEXIST) {
-        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
               "will not work [%d]: %s\n", ret, strerror(ret));
     }
 
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index 29055359fc7855f6ad84bf55ea334d0932c0a8d1..e300e28b68aa87957a607259b6439ceca0796e7e 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -199,18 +199,36 @@ static errno_t sdap_refresh_recv(struct tevent_req *req)
     return EOK;
 }
 
-struct tevent_req *sdap_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
-                                               struct tevent_context *ev,
-                                               struct be_ctx *be_ctx,
-                                               struct sss_domain_info *domain,
-                                               char **names,
-                                               void *pvt)
+static struct tevent_req *
+sdap_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
+                            struct tevent_context *ev,
+                            struct be_ctx *be_ctx,
+                            struct sss_domain_info *domain,
+                            char **names,
+                            void *pvt)
 {
     return sdap_refresh_send(mem_ctx, ev, be_ctx, domain,
                              BE_REQ_NETGROUP, names, pvt);
 }
 
-errno_t sdap_refresh_netgroups_recv(struct tevent_req *req)
+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,
+                          struct sdap_id_ctx *id_ctx)
+{
+    errno_t ret;
+
+    ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
+                            sdap_refresh_netgroups_send,
+                            sdap_refresh_netgroups_recv,
+                            id_ctx);
+    if (ret != EOK && ret != EEXIST) {
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
+              "will not work [%d]: %s\n", ret, strerror(ret));
+    }
+
+    return ret;
+}
-- 
1.9.3

