Blame SOURCES/0058-IPA-Implement-background-refresh-for-IPA-domains.patch

8d3578
From 7c4055f0701c9be44f478a713c45e43e5d5914a9 Mon Sep 17 00:00:00 2001
8d3578
From: Jakub Hrozek <jhrozek@redhat.com>
8d3578
Date: Wed, 8 May 2019 14:39:23 +0200
8d3578
Subject: [PATCH 58/64] IPA: Implement background refresh for IPA domains
8d3578
8d3578
Split out the actual useful functionality from the IPA account lookup
8d3578
handler into a tevent request. This tevent request is then used in a new
8d3578
ipa_refresh module.
8d3578
8d3578
Related:
8d3578
https://pagure.io/SSSD/sssd/issue/4012
8d3578
8d3578
Reviewed-by: Sumit Bose <sbose@redhat.com>
8d3578
(cherry picked from commit d76756ef472da9593c691f94186d09226bb49916)
8d3578
8d3578
Reviewed-by: Sumit Bose <sbose@redhat.com>
8d3578
---
8d3578
 Makefile.am                     |   1 +
8d3578
 src/providers/ipa/ipa_common.h  |   3 +
8d3578
 src/providers/ipa/ipa_id.c      | 140 +++++++++++++----
8d3578
 src/providers/ipa/ipa_id.h      |   8 +
8d3578
 src/providers/ipa/ipa_init.c    |   2 +-
8d3578
 src/providers/ipa/ipa_refresh.c | 264 ++++++++++++++++++++++++++++++++
8d3578
 6 files changed, 386 insertions(+), 32 deletions(-)
8d3578
 create mode 100644 src/providers/ipa/ipa_refresh.c
8d3578
8d3578
diff --git a/Makefile.am b/Makefile.am
8d3578
index 7d83b6847..e74de422d 100644
8d3578
--- a/Makefile.am
8d3578
+++ b/Makefile.am
8d3578
@@ -4171,6 +4171,7 @@ libsss_ipa_la_SOURCES = \
8d3578
     src/providers/ipa/ipa_srv.c \
8d3578
     src/providers/ipa/ipa_idmap.c \
8d3578
     src/providers/ipa/ipa_dn.c \
8d3578
+    src/providers/ipa/ipa_refresh.c \
8d3578
     src/providers/ad/ad_opts.c \
8d3578
     src/providers/ad/ad_common.c \
8d3578
     src/providers/ad/ad_dyndns.c \
8d3578
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
8d3578
index 31e671eb5..6bb1739ef 100644
8d3578
--- a/src/providers/ipa/ipa_common.h
8d3578
+++ b/src/providers/ipa/ipa_common.h
8d3578
@@ -301,4 +301,7 @@ errno_t ipa_get_host_attrs(struct dp_option *ipa_options,
8d3578
                            struct sysdb_attrs **hosts,
8d3578
                            struct sysdb_attrs **_ipa_host);
8d3578
 
8d3578
+errno_t ipa_refresh_init(struct be_ctx *be_ctx,
8d3578
+                         struct ipa_id_ctx *id_ctx);
8d3578
+
8d3578
 #endif /* _IPA_COMMON_H_ */
8d3578
diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
8d3578
index e644af5ff..9abee34cb 100644
8d3578
--- a/src/providers/ipa/ipa_id.c
8d3578
+++ b/src/providers/ipa/ipa_id.c
8d3578
@@ -1344,43 +1344,39 @@ ipa_decide_account_info_type(struct dp_id_data *data, struct be_ctx *be_ctx)
8d3578
     return IPA_ACCOUNT_INFO_OTHER;
8d3578
 }
8d3578
 
8d3578
-struct ipa_account_info_handler_state {
8d3578
+struct ipa_account_info_state {
8d3578
     enum ipa_account_info_type type;
8d3578
-    struct dp_reply_std reply;
8d3578
+
8d3578
+    const char *err_msg;
8d3578
+    int dp_error;
8d3578
 };
8d3578
 
8d3578
-static void ipa_account_info_handler_done(struct tevent_req *subreq);
8d3578
+static void ipa_account_info_done(struct tevent_req *subreq);
8d3578
 
8d3578
 struct tevent_req *
8d3578
-ipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
8d3578
-                              struct ipa_id_ctx *id_ctx,
8d3578
-                              struct dp_id_data *data,
8d3578
-                              struct dp_req_params *params)
8d3578
+ipa_account_info_send(TALLOC_CTX *mem_ctx,
8d3578
+                      struct be_ctx *be_ctx,
8d3578
+                      struct ipa_id_ctx *id_ctx,
8d3578
+                      struct dp_id_data *data)
8d3578
 {
8d3578
-    struct ipa_account_info_handler_state *state;
8d3578
+    struct ipa_account_info_state *state = NULL;
8d3578
+    struct tevent_req *req = NULL;
8d3578
     struct tevent_req *subreq = NULL;
8d3578
-    struct tevent_req *req;
8d3578
     errno_t ret;
8d3578
 
8d3578
     req = tevent_req_create(mem_ctx, &state,
8d3578
-                            struct ipa_account_info_handler_state);
8d3578
+                            struct ipa_account_info_state);
8d3578
     if (req == NULL) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
8d3578
         return NULL;
8d3578
     }
8d3578
 
8d3578
-    state->type = ipa_decide_account_info_type(data, params->be_ctx);
8d3578
-
8d3578
-    if (sdap_is_enum_request(data)) {
8d3578
-        DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
8d3578
-        ret = EOK;
8d3578
-        goto immediately;
8d3578
-    }
8d3578
+    state->type = ipa_decide_account_info_type(data, be_ctx);
8d3578
 
8d3578
     switch (state->type) {
8d3578
     case IPA_ACCOUNT_INFO_SUBDOMAIN:
8d3578
         /* Subdomain lookups are handled differently on server and client. */
8d3578
-        subreq = ipa_subdomain_account_send(state, params->ev, id_ctx, data);
8d3578
+        subreq = ipa_subdomain_account_send(state, be_ctx->ev, id_ctx, data);
8d3578
         break;
8d3578
     case IPA_ACCOUNT_INFO_NETGROUP:
8d3578
         if (data->filter_type != BE_FILTER_NAME) {
8d3578
@@ -1388,11 +1384,11 @@ ipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
8d3578
             goto immediately;
8d3578
         }
8d3578
 
8d3578
-        subreq = ipa_id_get_netgroup_send(state, params->ev, id_ctx,
8d3578
+        subreq = ipa_id_get_netgroup_send(state, be_ctx->ev, id_ctx,
8d3578
                                           data->filter_value);
8d3578
         break;
8d3578
     case IPA_ACCOUNT_INFO_OTHER:
8d3578
-        subreq = ipa_id_get_account_info_send(state, params->ev, id_ctx, data);
8d3578
+        subreq = ipa_id_get_account_info_send(state, be_ctx->ev, id_ctx, data);
8d3578
         break;
8d3578
     }
8d3578
 
8d3578
@@ -1400,7 +1396,99 @@ ipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
     }
8d3578
+    tevent_req_set_callback(subreq, ipa_account_info_done, req);
8d3578
+    return req;
8d3578
+
8d3578
+immediately:
8d3578
+    tevent_req_error(req, ret);
8d3578
+    tevent_req_post(req, be_ctx->ev);
8d3578
+    return req;
8d3578
+}
8d3578
+
8d3578
+static void ipa_account_info_done(struct tevent_req *subreq)
8d3578
+{
8d3578
+    struct ipa_account_info_state *state = NULL;
8d3578
+    struct tevent_req *req = NULL;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    req = tevent_req_callback_data(subreq, struct tevent_req);
8d3578
+    state = tevent_req_data(req, struct ipa_account_info_state);
8d3578
+
8d3578
+    switch (state->type) {
8d3578
+    case IPA_ACCOUNT_INFO_SUBDOMAIN:
8d3578
+        ret = ipa_subdomain_account_recv(subreq, &state->dp_error);
8d3578
+        break;
8d3578
+    case IPA_ACCOUNT_INFO_NETGROUP:
8d3578
+        ret = ipa_id_get_netgroup_recv(subreq, &state->dp_error);
8d3578
+        break;
8d3578
+    case IPA_ACCOUNT_INFO_OTHER:
8d3578
+        ret = ipa_id_get_account_info_recv(subreq, &state->dp_error);
8d3578
+        break;
8d3578
+    default:
8d3578
+        ret = EINVAL;
8d3578
+        break;
8d3578
+    }
8d3578
+    talloc_zfree(subreq);
8d3578
+
8d3578
+    if (ret != EOK) {
8d3578
+        tevent_req_error(req, ret);
8d3578
+        return;
8d3578
+    }
8d3578
+
8d3578
+    tevent_req_done(req);
8d3578
+}
8d3578
 
8d3578
+errno_t ipa_account_info_recv(struct tevent_req *req,
8d3578
+                              int *_dp_error)
8d3578
+{
8d3578
+    struct ipa_account_info_state *state = NULL;
8d3578
+
8d3578
+    state = tevent_req_data(req, struct ipa_account_info_state);
8d3578
+
8d3578
+    /* Fail the request after collecting the dp_error */
8d3578
+    if (_dp_error) {
8d3578
+        *_dp_error = state->dp_error;
8d3578
+    }
8d3578
+
8d3578
+    TEVENT_REQ_RETURN_ON_ERROR(req);
8d3578
+    return EOK;
8d3578
+}
8d3578
+
8d3578
+struct ipa_account_info_handler_state {
8d3578
+    struct dp_reply_std reply;
8d3578
+};
8d3578
+
8d3578
+static void ipa_account_info_handler_done(struct tevent_req *subreq);
8d3578
+
8d3578
+struct tevent_req *
8d3578
+ipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
8d3578
+                              struct ipa_id_ctx *id_ctx,
8d3578
+                              struct dp_id_data *data,
8d3578
+                              struct dp_req_params *params)
8d3578
+{
8d3578
+    struct ipa_account_info_handler_state *state;
8d3578
+    struct tevent_req *subreq = NULL;
8d3578
+    struct tevent_req *req;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    req = tevent_req_create(mem_ctx, &state,
8d3578
+                            struct ipa_account_info_handler_state);
8d3578
+    if (req == NULL) {
8d3578
+        DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
8d3578
+        return NULL;
8d3578
+    }
8d3578
+
8d3578
+    if (sdap_is_enum_request(data)) {
8d3578
+        DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
8d3578
+        ret = EOK;
8d3578
+        goto immediately;
8d3578
+    }
8d3578
+
8d3578
+    subreq = ipa_account_info_send(state, params->be_ctx, id_ctx, data);
8d3578
+    if (subreq == NULL) {
8d3578
+        ret = ENOMEM;
8d3578
+        goto immediately;
8d3578
+    }
8d3578
     tevent_req_set_callback(subreq, ipa_account_info_handler_done, req);
8d3578
 
8d3578
     return req;
8d3578
@@ -1425,17 +1513,7 @@ static void ipa_account_info_handler_done(struct tevent_req *subreq)
8d3578
     req = tevent_req_callback_data(subreq, struct tevent_req);
8d3578
     state = tevent_req_data(req, struct ipa_account_info_handler_state);
8d3578
 
8d3578
-    switch (state->type) {
8d3578
-    case IPA_ACCOUNT_INFO_SUBDOMAIN:
8d3578
-        ret = ipa_subdomain_account_recv(subreq, &dp_error);
8d3578
-        break;
8d3578
-    case IPA_ACCOUNT_INFO_NETGROUP:
8d3578
-        ret = ipa_id_get_netgroup_recv(subreq, &dp_error);
8d3578
-        break;
8d3578
-    case IPA_ACCOUNT_INFO_OTHER:
8d3578
-        ret = ipa_id_get_account_info_recv(subreq, &dp_error);
8d3578
-        break;
8d3578
-    }
8d3578
+    ret = ipa_account_info_recv(subreq, &dp_error);
8d3578
     talloc_zfree(subreq);
8d3578
 
8d3578
     /* TODO For backward compatibility we always return EOK to DP now. */
8d3578
diff --git a/src/providers/ipa/ipa_id.h b/src/providers/ipa/ipa_id.h
8d3578
index 4b2549882..fe9acfeef 100644
8d3578
--- a/src/providers/ipa/ipa_id.h
8d3578
+++ b/src/providers/ipa/ipa_id.h
8d3578
@@ -33,6 +33,14 @@
8d3578
 
8d3578
 #define IPA_DEFAULT_VIEW_NAME "Default Trust View"
8d3578
 
8d3578
+struct tevent_req *
8d3578
+ipa_account_info_send(TALLOC_CTX *mem_ctx,
8d3578
+                      struct be_ctx *be_ctx,
8d3578
+                      struct ipa_id_ctx *id_ctx,
8d3578
+                      struct dp_id_data *data);
8d3578
+errno_t ipa_account_info_recv(struct tevent_req *req,
8d3578
+                              int *_dp_error);
8d3578
+
8d3578
 struct tevent_req *
8d3578
 ipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
8d3578
                               struct ipa_id_ctx *id_ctx,
8d3578
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
8d3578
index b3060e228..cdfd11d7a 100644
8d3578
--- a/src/providers/ipa/ipa_init.c
8d3578
+++ b/src/providers/ipa/ipa_init.c
8d3578
@@ -594,7 +594,7 @@ static errno_t ipa_init_misc(struct be_ctx *be_ctx,
8d3578
         }
8d3578
     }
8d3578
 
8d3578
-    ret = sdap_refresh_init(be_ctx, sdap_id_ctx);
8d3578
+    ret = ipa_refresh_init(be_ctx, ipa_id_ctx);
8d3578
     if (ret != EOK && ret != EEXIST) {
8d3578
         DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
8d3578
               "will not work [%d]: %s\n", ret, sss_strerror(ret));
8d3578
diff --git a/src/providers/ipa/ipa_refresh.c b/src/providers/ipa/ipa_refresh.c
8d3578
new file mode 100644
8d3578
index 000000000..72051cfdd
8d3578
--- /dev/null
8d3578
+++ b/src/providers/ipa/ipa_refresh.c
8d3578
@@ -0,0 +1,264 @@
8d3578
+/*
8d3578
+    Copyright (C) 2019 Red Hat
8d3578
+
8d3578
+    This program is free software; you can redistribute it and/or modify
8d3578
+    it under the terms of the GNU General Public License as published by
8d3578
+    the Free Software Foundation; either version 3 of the License, or
8d3578
+    (at your option) any later version.
8d3578
+
8d3578
+    This program is distributed in the hope that it will be useful,
8d3578
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
8d3578
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8d3578
+    GNU General Public License for more details.
8d3578
+
8d3578
+    You should have received a copy of the GNU General Public License
8d3578
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
8d3578
+*/
8d3578
+
8d3578
+#include <talloc.h>
8d3578
+#include <tevent.h>
8d3578
+
8d3578
+#include "providers/ipa/ipa_common.h"
8d3578
+#include "providers/ipa/ipa_id.h"
8d3578
+
8d3578
+struct ipa_refresh_state {
8d3578
+    struct tevent_context *ev;
8d3578
+    struct be_ctx *be_ctx;
8d3578
+    struct dp_id_data *account_req;
8d3578
+    struct ipa_id_ctx *id_ctx;
8d3578
+    char **names;
8d3578
+    size_t index;
8d3578
+};
8d3578
+
8d3578
+static errno_t ipa_refresh_step(struct tevent_req *req);
8d3578
+static void ipa_refresh_done(struct tevent_req *subreq);
8d3578
+
8d3578
+static struct tevent_req *ipa_refresh_send(TALLOC_CTX *mem_ctx,
8d3578
+                                            struct tevent_context *ev,
8d3578
+                                            struct be_ctx *be_ctx,
8d3578
+                                            struct sss_domain_info *domain,
8d3578
+                                            int entry_type,
8d3578
+                                            char **names,
8d3578
+                                            void *pvt)
8d3578
+{
8d3578
+    struct ipa_refresh_state *state = NULL;
8d3578
+    struct tevent_req *req = NULL;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    req = tevent_req_create(mem_ctx, &state,
8d3578
+                            struct ipa_refresh_state);
8d3578
+    if (req == NULL) {
8d3578
+        DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
8d3578
+        return NULL;
8d3578
+    }
8d3578
+
8d3578
+    if (names == NULL) {
8d3578
+        ret = EOK;
8d3578
+        goto immediately;
8d3578
+    }
8d3578
+
8d3578
+    state->ev = ev;
8d3578
+    state->be_ctx = be_ctx;
8d3578
+    state->id_ctx = talloc_get_type(pvt, struct ipa_id_ctx);
8d3578
+    state->names = names;
8d3578
+    state->index = 0;
8d3578
+
8d3578
+    state->account_req = be_refresh_acct_req(state, entry_type,
8d3578
+                                             BE_FILTER_NAME, domain);
8d3578
+    if (state->account_req == NULL) {
8d3578
+        ret = ENOMEM;
8d3578
+        goto immediately;
8d3578
+    }
8d3578
+
8d3578
+    ret = ipa_refresh_step(req);
8d3578
+    if (ret == EOK) {
8d3578
+        DEBUG(SSSDBG_TRACE_FUNC, "Nothing to refresh\n");
8d3578
+        goto immediately;
8d3578
+    } else if (ret != EAGAIN) {
8d3578
+        DEBUG(SSSDBG_CRIT_FAILURE, "ipa_refresh_step() failed "
8d3578
+                                   "[%d]: %s\n", ret, sss_strerror(ret));
8d3578
+        goto immediately;
8d3578
+    }
8d3578
+
8d3578
+    return req;
8d3578
+
8d3578
+immediately:
8d3578
+    if (ret == EOK) {
8d3578
+        tevent_req_done(req);
8d3578
+    } else {
8d3578
+        tevent_req_error(req, ret);
8d3578
+    }
8d3578
+    tevent_req_post(req, ev);
8d3578
+
8d3578
+    return req;
8d3578
+}
8d3578
+
8d3578
+static errno_t ipa_refresh_step(struct tevent_req *req)
8d3578
+{
8d3578
+    struct ipa_refresh_state *state = NULL;
8d3578
+    struct tevent_req *subreq = NULL;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    state = tevent_req_data(req, struct ipa_refresh_state);
8d3578
+
8d3578
+    if (state->names == NULL) {
8d3578
+        ret = EOK;
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    state->account_req->filter_value = state->names[state->index];
8d3578
+    if (state->account_req->filter_value == NULL) {
8d3578
+        ret = EOK;
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    subreq = ipa_account_info_send(state, state->be_ctx, state->id_ctx,
8d3578
+                                  state->account_req);
8d3578
+    if (subreq == NULL) {
8d3578
+        ret = ENOMEM;
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    tevent_req_set_callback(subreq, ipa_refresh_done, req);
8d3578
+
8d3578
+    state->index++;
8d3578
+    ret = EAGAIN;
8d3578
+
8d3578
+done:
8d3578
+    return ret;
8d3578
+}
8d3578
+
8d3578
+static void ipa_refresh_done(struct tevent_req *subreq)
8d3578
+{
8d3578
+    struct ipa_refresh_state *state = NULL;
8d3578
+    struct tevent_req *req = NULL;
8d3578
+    errno_t dp_error;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    req = tevent_req_callback_data(subreq, struct tevent_req);
8d3578
+    state = tevent_req_data(req, struct ipa_refresh_state);
8d3578
+
8d3578
+    ret = ipa_account_info_recv(subreq, &dp_error);
8d3578
+    talloc_zfree(subreq);
8d3578
+    if (ret != EOK) {
8d3578
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to refresh %s [dp_error: %d, "
8d3578
+              "errno: %d]\n", be_req2str(state->account_req->entry_type),
8d3578
+              dp_error, ret);
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    ret = ipa_refresh_step(req);
8d3578
+    if (ret == EAGAIN) {
8d3578
+        return;
8d3578
+    }
8d3578
+
8d3578
+done:
8d3578
+    if (ret != EOK) {
8d3578
+        tevent_req_error(req, ret);
8d3578
+        return;
8d3578
+    }
8d3578
+
8d3578
+    tevent_req_done(req);
8d3578
+}
8d3578
+
8d3578
+static errno_t ipa_refresh_recv(struct tevent_req *req)
8d3578
+{
8d3578
+    TEVENT_REQ_RETURN_ON_ERROR(req);
8d3578
+
8d3578
+    return EOK;
8d3578
+}
8d3578
+
8d3578
+static struct tevent_req *
8d3578
+ipa_refresh_users_send(TALLOC_CTX *mem_ctx,
8d3578
+                        struct tevent_context *ev,
8d3578
+                        struct be_ctx *be_ctx,
8d3578
+                        struct sss_domain_info *domain,
8d3578
+                        char **names,
8d3578
+                        void *pvt)
8d3578
+{
8d3578
+    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
8d3578
+                           BE_REQ_USER, names, pvt);
8d3578
+}
8d3578
+
8d3578
+static errno_t ipa_refresh_users_recv(struct tevent_req *req)
8d3578
+{
8d3578
+    return ipa_refresh_recv(req);
8d3578
+}
8d3578
+
8d3578
+static struct tevent_req *
8d3578
+ipa_refresh_groups_send(TALLOC_CTX *mem_ctx,
8d3578
+                         struct tevent_context *ev,
8d3578
+                         struct be_ctx *be_ctx,
8d3578
+                         struct sss_domain_info *domain,
8d3578
+                         char **names,
8d3578
+                         void *pvt)
8d3578
+{
8d3578
+    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
8d3578
+                           BE_REQ_GROUP, names, pvt);
8d3578
+}
8d3578
+
8d3578
+static errno_t ipa_refresh_groups_recv(struct tevent_req *req)
8d3578
+{
8d3578
+    return ipa_refresh_recv(req);
8d3578
+}
8d3578
+
8d3578
+static struct tevent_req *
8d3578
+ipa_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
8d3578
+                            struct tevent_context *ev,
8d3578
+                            struct be_ctx *be_ctx,
8d3578
+                            struct sss_domain_info *domain,
8d3578
+                            char **names,
8d3578
+                            void *pvt)
8d3578
+{
8d3578
+    return ipa_refresh_send(mem_ctx, ev, be_ctx, domain,
8d3578
+                           BE_REQ_NETGROUP, names, pvt);
8d3578
+}
8d3578
+
8d3578
+static errno_t ipa_refresh_netgroups_recv(struct tevent_req *req)
8d3578
+{
8d3578
+    return ipa_refresh_recv(req);
8d3578
+}
8d3578
+
8d3578
+errno_t ipa_refresh_init(struct be_ctx *be_ctx,
8d3578
+                         struct ipa_id_ctx *id_ctx)
8d3578
+{
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    ret = be_refresh_ctx_init(be_ctx, SYSDB_NAME);
8d3578
+    if (ret != EOK) {
8d3578
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
8d3578
+                            BE_REFRESH_TYPE_USERS,
8d3578
+                            ipa_refresh_users_send,
8d3578
+                            ipa_refresh_users_recv,
8d3578
+                            id_ctx);
8d3578
+    if (ret != EOK && ret != EEXIST) {
8d3578
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of users "
8d3578
+              "will not work [%d]: %s\n", ret, strerror(ret));
8d3578
+    }
8d3578
+
8d3578
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
8d3578
+                            BE_REFRESH_TYPE_GROUPS,
8d3578
+                            ipa_refresh_groups_send,
8d3578
+                            ipa_refresh_groups_recv,
8d3578
+                            id_ctx);
8d3578
+    if (ret != EOK && ret != EEXIST) {
8d3578
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of groups "
8d3578
+              "will not work [%d]: %s\n", ret, strerror(ret));
8d3578
+    }
8d3578
+
8d3578
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
8d3578
+                            BE_REFRESH_TYPE_NETGROUPS,
8d3578
+                            ipa_refresh_netgroups_send,
8d3578
+                            ipa_refresh_netgroups_recv,
8d3578
+                            id_ctx);
8d3578
+    if (ret != EOK && ret != EEXIST) {
8d3578
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
8d3578
+              "will not work [%d]: %s\n", ret, strerror(ret));
8d3578
+    }
8d3578
+
8d3578
+    return ret;
8d3578
+}
8d3578
-- 
8d3578
2.20.1
8d3578