Blob Blame History Raw
From 441e05790e5efec4928af3d0f93c4eba72d979ae Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 25 Jun 2019 15:01:15 +0200
Subject: [PATCH 61/64] IPA/AD/SDAP/BE: Generate refresh callbacks with a macro

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

The per-object type refresh functions are more or less boilerplate code.
Even though macro-generated code should be used very rarely, here the
generated code does not contain any logic at all so it makese sense to
generate it with macros.

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

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/providers/ad/ad_refresh.c     | 71 ++-----------------------------
 src/providers/be_refresh.h        | 20 +++++++++
 src/providers/ipa/ipa_refresh.c   | 71 ++-----------------------------
 src/providers/ldap/sdap_refresh.c | 71 ++-----------------------------
 4 files changed, 32 insertions(+), 201 deletions(-)

diff --git a/src/providers/ad/ad_refresh.c b/src/providers/ad/ad_refresh.c
index ed51b305a..0c2ebce5e 100644
--- a/src/providers/ad/ad_refresh.c
+++ b/src/providers/ad/ad_refresh.c
@@ -188,73 +188,10 @@ static errno_t ad_refresh_recv(struct tevent_req *req)
     return EOK;
 }
 
-static struct tevent_req *
-ad_refresh_initgroups_send(TALLOC_CTX *mem_ctx,
-                           struct tevent_context *ev,
-                           struct be_ctx *be_ctx,
-                           struct sss_domain_info *domain,
-                           char **names,
-                           void *pvt)
-{
-    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_INITGROUPS, names, pvt);
-}
-
-static errno_t ad_refresh_initgroups_recv(struct tevent_req *req)
-{
-    return ad_refresh_recv(req);
-}
-
-static struct tevent_req *
-ad_refresh_users_send(TALLOC_CTX *mem_ctx,
-                      struct tevent_context *ev,
-                      struct be_ctx *be_ctx,
-                      struct sss_domain_info *domain,
-                      char **names,
-                      void *pvt)
-{
-    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_USER, names, pvt);
-}
-
-static errno_t ad_refresh_users_recv(struct tevent_req *req)
-{
-    return ad_refresh_recv(req);
-}
-
-static struct tevent_req *
-ad_refresh_groups_send(TALLOC_CTX *mem_ctx,
-                       struct tevent_context *ev,
-                       struct be_ctx *be_ctx,
-                       struct sss_domain_info *domain,
-                       char **names,
-                       void *pvt)
-{
-    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_GROUP, names, pvt);
-}
-
-static errno_t ad_refresh_groups_recv(struct tevent_req *req)
-{
-    return ad_refresh_recv(req);
-}
-
-static struct tevent_req *
-ad_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 ad_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_NETGROUP, names, pvt);
-}
-
-static errno_t ad_refresh_netgroups_recv(struct tevent_req *req)
-{
-    return ad_refresh_recv(req);
-}
+REFRESH_SEND_RECV_FNS(ad_refresh_initgroups, ad_refresh, BE_REQ_INITGROUPS);
+REFRESH_SEND_RECV_FNS(ad_refresh_users, ad_refresh, BE_REQ_USER);
+REFRESH_SEND_RECV_FNS(ad_refresh_groups, ad_refresh, BE_REQ_GROUP);
+REFRESH_SEND_RECV_FNS(ad_refresh_netgroups, ad_refresh, BE_REQ_NETGROUP);
 
 errno_t ad_refresh_init(struct be_ctx *be_ctx,
                         struct ad_id_ctx *id_ctx)
diff --git a/src/providers/be_refresh.h b/src/providers/be_refresh.h
index 42d73d938..68be40118 100644
--- a/src/providers/be_refresh.h
+++ b/src/providers/be_refresh.h
@@ -29,6 +29,26 @@
 /* solve circular dependency */
 struct be_ctx;
 
+#define REFRESH_SEND_RECV_FNS(outer_base, inner_base, req_type) \
+                                                                \
+static struct tevent_req *                                      \
+outer_base ##_send(TALLOC_CTX *mem_ctx,                         \
+                   struct tevent_context *ev,                   \
+                   struct be_ctx *be_ctx,                       \
+                   struct sss_domain_info *domain,              \
+                   char **names,                                \
+                   void *pvt)                                   \
+{                                                               \
+    return inner_base ##_send(mem_ctx, ev,                      \
+                              be_ctx, domain,                   \
+                              req_type, names, pvt);            \
+}                                                               \
+                                                                \
+static errno_t outer_base ##_recv(struct tevent_req *req)       \
+{                                                               \
+    return inner_base ##_recv(req);                             \
+}                                                               \
+
 /**
  * name_list contains SYSDB_NAME of all expired records.
  */
diff --git a/src/providers/ipa/ipa_refresh.c b/src/providers/ipa/ipa_refresh.c
index 7b05cf9e4..13c38dff9 100644
--- a/src/providers/ipa/ipa_refresh.c
+++ b/src/providers/ipa/ipa_refresh.c
@@ -168,73 +168,10 @@ static errno_t ipa_refresh_recv(struct tevent_req *req)
     return EOK;
 }
 
-static struct tevent_req *
-ipa_refresh_initgroups_send(TALLOC_CTX *mem_ctx,
-                            struct tevent_context *ev,
-                            struct be_ctx *be_ctx,
-                            struct sss_domain_info *domain,
-                            char **names,
-                            void *pvt)
-{
-    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_INITGROUPS, names, pvt);
-}
-
-static errno_t ipa_refresh_initgroups_recv(struct tevent_req *req)
-{
-    return ipa_refresh_recv(req);
-}
-
-static struct tevent_req *
-ipa_refresh_users_send(TALLOC_CTX *mem_ctx,
-                        struct tevent_context *ev,
-                        struct be_ctx *be_ctx,
-                        struct sss_domain_info *domain,
-                        char **names,
-                        void *pvt)
-{
-    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_USER, names, pvt);
-}
-
-static errno_t ipa_refresh_users_recv(struct tevent_req *req)
-{
-    return ipa_refresh_recv(req);
-}
-
-static struct tevent_req *
-ipa_refresh_groups_send(TALLOC_CTX *mem_ctx,
-                         struct tevent_context *ev,
-                         struct be_ctx *be_ctx,
-                         struct sss_domain_info *domain,
-                         char **names,
-                         void *pvt)
-{
-    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_GROUP, names, pvt);
-}
-
-static errno_t ipa_refresh_groups_recv(struct tevent_req *req)
-{
-    return ipa_refresh_recv(req);
-}
-
-static struct tevent_req *
-ipa_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 ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
-                           BE_REQ_NETGROUP, names, pvt);
-}
-
-static errno_t ipa_refresh_netgroups_recv(struct tevent_req *req)
-{
-    return ipa_refresh_recv(req);
-}
+REFRESH_SEND_RECV_FNS(ipa_refresh_initgroups, ipa_refresh, BE_REQ_INITGROUPS);
+REFRESH_SEND_RECV_FNS(ipa_refresh_users, ipa_refresh, BE_REQ_USER);
+REFRESH_SEND_RECV_FNS(ipa_refresh_groups, ipa_refresh, BE_REQ_GROUP);
+REFRESH_SEND_RECV_FNS(ipa_refresh_netgroups, ipa_refresh, BE_REQ_NETGROUP);
 
 errno_t ipa_refresh_init(struct be_ctx *be_ctx,
                          struct ipa_id_ctx *id_ctx)
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index ff4d2116d..4e464b2f6 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -186,73 +186,10 @@ static errno_t sdap_refresh_recv(struct tevent_req *req)
     return EOK;
 }
 
-static struct tevent_req *
-sdap_refresh_initgroups_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_INITGROUPS, names, pvt);
-}
-
-static errno_t sdap_refresh_initgroups_recv(struct tevent_req *req)
-{
-    return sdap_refresh_recv(req);
-}
-
-static struct tevent_req *
-sdap_refresh_users_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_USER, names, pvt);
-}
-
-static errno_t sdap_refresh_users_recv(struct tevent_req *req)
-{
-    return sdap_refresh_recv(req);
-}
-
-static struct tevent_req *
-sdap_refresh_groups_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_GROUP, names, pvt);
-}
-
-static errno_t sdap_refresh_groups_recv(struct tevent_req *req)
-{
-    return sdap_refresh_recv(req);
-}
-
-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);
-}
-
-static errno_t sdap_refresh_netgroups_recv(struct tevent_req *req)
-{
-    return sdap_refresh_recv(req);
-}
+REFRESH_SEND_RECV_FNS(sdap_refresh_initgroups, sdap_refresh, BE_REQ_INITGROUPS);
+REFRESH_SEND_RECV_FNS(sdap_refresh_users, sdap_refresh, BE_REQ_USER);
+REFRESH_SEND_RECV_FNS(sdap_refresh_groups, sdap_refresh, BE_REQ_GROUP);
+REFRESH_SEND_RECV_FNS(sdap_refresh_netgroups, sdap_refresh, BE_REQ_NETGROUP);
 
 errno_t sdap_refresh_init(struct be_ctx *be_ctx,
                           struct sdap_id_ctx *id_ctx)
-- 
2.20.1