Blame SOURCES/0041-responders-add-callback-to-schedule_get_domains_task.patch

bac598
From e07eeea7df55ede36ac0978ac904c1bb11188265 Mon Sep 17 00:00:00 2001
bac598
From: Sumit Bose <sbose@redhat.com>
bac598
Date: Wed, 20 Jan 2021 17:48:44 +0100
bac598
Subject: [PATCH 41/42] responders: add callback to schedule_get_domains_task()
bac598
MIME-Version: 1.0
bac598
Content-Type: text/plain; charset=UTF-8
bac598
Content-Transfer-Encoding: 8bit
bac598
bac598
To allow responders to run dedicated code at the end of the initial
bac598
getDomains request a callback is added.
bac598
bac598
Resolves: https://github.com/SSSD/sssd/issues/5469
bac598
bac598
Reviewed-by: Tomáš Halman <thalman@redhat.com>
bac598
---
bac598
 src/responder/autofs/autofssrv.c             |  2 +-
bac598
 src/responder/common/responder.h             |  5 ++++-
bac598
 src/responder/common/responder_get_domains.c | 12 +++++++++++-
bac598
 src/responder/ifp/ifpsrv.c                   |  2 +-
bac598
 src/responder/nss/nsssrv.c                   |  3 ++-
bac598
 src/responder/pac/pacsrv.c                   |  2 +-
bac598
 src/responder/pam/pamsrv.c                   |  3 ++-
bac598
 src/responder/ssh/sshsrv.c                   |  2 +-
bac598
 src/responder/sudo/sudosrv.c                 |  2 +-
bac598
 src/tests/cmocka/test_responder_common.c     |  2 +-
bac598
 10 files changed, 25 insertions(+), 10 deletions(-)
bac598
bac598
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
bac598
index 27de1b44a..130eaf775 100644
bac598
--- a/src/responder/autofs/autofssrv.c
bac598
+++ b/src/responder/autofs/autofssrv.c
bac598
@@ -142,7 +142,7 @@ autofs_process_init(TALLOC_CTX *mem_ctx,
bac598
         goto fail;
bac598
     }
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL, NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto fail;
bac598
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
bac598
index f83ba1bc0..ff0559c08 100644
bac598
--- a/src/responder/common/responder.h
bac598
+++ b/src/responder/common/responder.h
bac598
@@ -366,10 +366,13 @@ errno_t sss_dp_get_account_domain_recv(TALLOC_CTX *mem_ctx,
bac598
                                        struct tevent_req *req,
bac598
                                        char **_domain);
bac598
 
bac598
+typedef void (get_domains_callback_fn_t)(void *);
bac598
 errno_t schedule_get_domains_task(TALLOC_CTX *mem_ctx,
bac598
                                   struct tevent_context *ev,
bac598
                                   struct resp_ctx *rctx,
bac598
-                                  struct sss_nc_ctx *optional_ncache);
bac598
+                                  struct sss_nc_ctx *optional_ncache,
bac598
+                                  get_domains_callback_fn_t *callback,
bac598
+                                  void *callback_pvt);
bac598
 
bac598
 errno_t csv_string_to_uid_array(TALLOC_CTX *mem_ctx, const char *csv_string,
bac598
                                 bool allow_sss_loop,
bac598
diff --git a/src/responder/common/responder_get_domains.c b/src/responder/common/responder_get_domains.c
bac598
index e551b0fff..12b6e9028 100644
bac598
--- a/src/responder/common/responder_get_domains.c
bac598
+++ b/src/responder/common/responder_get_domains.c
bac598
@@ -430,6 +430,8 @@ static errno_t check_last_request(struct resp_ctx *rctx, const char *hint)
bac598
 struct get_domains_state {
bac598
     struct resp_ctx *rctx;
bac598
     struct sss_nc_ctx *optional_ncache;
bac598
+    get_domains_callback_fn_t *callback;
bac598
+    void *callback_pvt;
bac598
 };
bac598
 
bac598
 static void get_domains_at_startup_done(struct tevent_req *req)
bac598
@@ -462,6 +464,10 @@ static void get_domains_at_startup_done(struct tevent_req *req)
bac598
         }
bac598
     }
bac598
 
bac598
+    if (state->callback != NULL) {
bac598
+        state->callback(state->callback_pvt);
bac598
+    }
bac598
+
bac598
     talloc_free(state);
bac598
     return;
bac598
 }
bac598
@@ -489,7 +495,9 @@ static void get_domains_at_startup(struct tevent_context *ev,
bac598
 errno_t schedule_get_domains_task(TALLOC_CTX *mem_ctx,
bac598
                                   struct tevent_context *ev,
bac598
                                   struct resp_ctx *rctx,
bac598
-                                  struct sss_nc_ctx *optional_ncache)
bac598
+                                  struct sss_nc_ctx *optional_ncache,
bac598
+                                  get_domains_callback_fn_t *callback,
bac598
+                                  void *callback_pvt)
bac598
 {
bac598
     struct tevent_immediate *imm;
bac598
     struct get_domains_state *state;
bac598
@@ -500,6 +508,8 @@ errno_t schedule_get_domains_task(TALLOC_CTX *mem_ctx,
bac598
     }
bac598
     state->rctx = rctx;
bac598
     state->optional_ncache = optional_ncache;
bac598
+    state->callback = callback;
bac598
+    state->callback_pvt = callback_pvt;
bac598
 
bac598
     imm = tevent_create_immediate(mem_ctx);
bac598
     if (imm == NULL) {
bac598
diff --git a/src/responder/ifp/ifpsrv.c b/src/responder/ifp/ifpsrv.c
bac598
index 7407ee07b..ee1452728 100644
bac598
--- a/src/responder/ifp/ifpsrv.c
bac598
+++ b/src/responder/ifp/ifpsrv.c
bac598
@@ -266,7 +266,7 @@ int ifp_process_init(TALLOC_CTX *mem_ctx,
bac598
         return EIO;
bac598
     }
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL, NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE,
bac598
               "schedule_get_domains_tasks failed.\n");
bac598
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
bac598
index e80104e3d..2b7958e80 100644
bac598
--- a/src/responder/nss/nsssrv.c
bac598
+++ b/src/responder/nss/nsssrv.c
bac598
@@ -557,7 +557,8 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
bac598
     }
bac598
     responder_set_fd_limit(fd_limit);
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, nctx->rctx->ncache);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, nctx->rctx->ncache,
bac598
+                                    NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto fail;
bac598
diff --git a/src/responder/pac/pacsrv.c b/src/responder/pac/pacsrv.c
bac598
index 217f83c26..96935150b 100644
bac598
--- a/src/responder/pac/pacsrv.c
bac598
+++ b/src/responder/pac/pacsrv.c
bac598
@@ -129,7 +129,7 @@ int pac_process_init(TALLOC_CTX *mem_ctx,
bac598
         goto fail;
bac598
     }
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL, NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto fail;
bac598
diff --git a/src/responder/pam/pamsrv.c b/src/responder/pam/pamsrv.c
bac598
index de1620e82..8b1ce2e92 100644
bac598
--- a/src/responder/pam/pamsrv.c
bac598
+++ b/src/responder/pam/pamsrv.c
bac598
@@ -246,7 +246,8 @@ static int pam_process_init(TALLOC_CTX *mem_ctx,
bac598
     }
bac598
     responder_set_fd_limit(fd_limit);
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, pctx->rctx->ncache);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, pctx->rctx->ncache,
bac598
+                                    NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto done;
bac598
diff --git a/src/responder/ssh/sshsrv.c b/src/responder/ssh/sshsrv.c
bac598
index 6072a702c..e79a0438c 100644
bac598
--- a/src/responder/ssh/sshsrv.c
bac598
+++ b/src/responder/ssh/sshsrv.c
bac598
@@ -126,7 +126,7 @@ int ssh_process_init(TALLOC_CTX *mem_ctx,
bac598
         goto fail;
bac598
     }
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL, NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto fail;
bac598
diff --git a/src/responder/sudo/sudosrv.c b/src/responder/sudo/sudosrv.c
bac598
index 5951b17b1..dc4a44b2f 100644
bac598
--- a/src/responder/sudo/sudosrv.c
bac598
+++ b/src/responder/sudo/sudosrv.c
bac598
@@ -102,7 +102,7 @@ int sudo_process_init(TALLOC_CTX *mem_ctx,
bac598
         goto fail;
bac598
     }
bac598
 
bac598
-    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
bac598
+    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL, NULL, NULL);
bac598
     if (ret != EOK) {
bac598
         DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
bac598
         goto fail;
bac598
diff --git a/src/tests/cmocka/test_responder_common.c b/src/tests/cmocka/test_responder_common.c
bac598
index 5fc0d712d..29356253b 100644
bac598
--- a/src/tests/cmocka/test_responder_common.c
bac598
+++ b/src/tests/cmocka/test_responder_common.c
bac598
@@ -265,7 +265,7 @@ void test_schedule_get_domains_task(void **state)
bac598
     ret = schedule_get_domains_task(dummy_ncache_ptr,
bac598
                                     parse_inp_ctx->rctx->ev,
bac598
                                     parse_inp_ctx->rctx,
bac598
-                                    dummy_ncache_ptr);
bac598
+                                    dummy_ncache_ptr, NULL, NULL);
bac598
     assert_int_equal(ret, EOK);
bac598
 
bac598
     ret = test_ev_loop(parse_inp_ctx->tctx);
bac598
-- 
bac598
2.21.3
bac598