dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0038-AD-Implement-background-refresh-for-AD-domains.patch

d6181b
From 10e3f8bddc8dd4799c0da68aebf09aa3435950f5 Mon Sep 17 00:00:00 2001
d6181b
From: Jakub Hrozek <jhrozek@redhat.com>
d6181b
Date: Wed, 24 Apr 2019 20:52:11 +0200
d6181b
Subject: [PATCH 38/48] AD: Implement background refresh for AD domains
d6181b
d6181b
Split out the actual useful functionality from the AD account handler
d6181b
into a tevent request. This tevent request is then subsequently used by
d6181b
a new ad_refresh module.
d6181b
d6181b
Related:
d6181b
https://pagure.io/SSSD/sssd/issue/4012
d6181b
d6181b
Reviewed-by: Sumit Bose <sbose@redhat.com>
d6181b
---
d6181b
 Makefile.am                   |   5 +-
d6181b
 src/providers/ad/ad_common.h  |   4 +
d6181b
 src/providers/ad/ad_id.c      | 140 +++++++++++++----
d6181b
 src/providers/ad/ad_id.h      |  10 ++
d6181b
 src/providers/ad/ad_init.c    |   2 +-
d6181b
 src/providers/ad/ad_refresh.c | 283 ++++++++++++++++++++++++++++++++++
d6181b
 6 files changed, 412 insertions(+), 32 deletions(-)
d6181b
 create mode 100644 src/providers/ad/ad_refresh.c
d6181b
d6181b
diff --git a/Makefile.am b/Makefile.am
d6181b
index 043a7ebb4..f9f17904e 100644
d6181b
--- a/Makefile.am
d6181b
+++ b/Makefile.am
d6181b
@@ -4502,7 +4502,10 @@ libsss_ad_la_SOURCES = \
d6181b
     src/providers/ad/ad_gpo_ndr.c \
d6181b
     src/providers/ad/ad_srv.c \
d6181b
     src/providers/ad/ad_subdomains.c \
d6181b
-    src/providers/ad/ad_domain_info.c
d6181b
+    src/providers/ad/ad_domain_info.c \
d6181b
+    src/providers/ad/ad_refresh.c \
d6181b
+    $(NULL)
d6181b
+
d6181b
 
d6181b
 if BUILD_SUDO
d6181b
 libsss_ad_la_SOURCES += \
d6181b
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
d6181b
index e224254e1..75f11de2e 100644
d6181b
--- a/src/providers/ad/ad_common.h
d6181b
+++ b/src/providers/ad/ad_common.h
d6181b
@@ -224,4 +224,8 @@ errno_t ad_inherit_opts_if_needed(struct dp_option *parent_opts,
d6181b
                                   struct confdb_ctx *cdb,
d6181b
                                   const char *subdom_conf_path,
d6181b
                                   int opt_id);
d6181b
+
d6181b
+errno_t ad_refresh_init(struct be_ctx *be_ctx,
d6181b
+                        struct ad_id_ctx *id_ctx);
d6181b
+
d6181b
 #endif /* AD_COMMON_H_ */
d6181b
diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c
d6181b
index c3bda1662..eb6e36824 100644
d6181b
--- a/src/providers/ad/ad_id.c
d6181b
+++ b/src/providers/ad/ad_id.c
d6181b
@@ -360,44 +360,36 @@ get_conn_list(TALLOC_CTX *mem_ctx, struct ad_id_ctx *ad_ctx,
d6181b
     return clist;
d6181b
 }
d6181b
 
d6181b
-struct ad_account_info_handler_state {
d6181b
-    struct sss_domain_info *domain;
d6181b
-    struct dp_reply_std reply;
d6181b
+struct ad_account_info_state {
d6181b
+    const char *err_msg;
d6181b
+    int dp_error;
d6181b
 };
d6181b
 
d6181b
-static void ad_account_info_handler_done(struct tevent_req *subreq);
d6181b
+static void ad_account_info_done(struct tevent_req *subreq);
d6181b
 
d6181b
 struct tevent_req *
d6181b
-ad_account_info_handler_send(TALLOC_CTX *mem_ctx,
d6181b
-                              struct ad_id_ctx *id_ctx,
d6181b
-                              struct dp_id_data *data,
d6181b
-                              struct dp_req_params *params)
d6181b
+ad_account_info_send(TALLOC_CTX *mem_ctx,
d6181b
+                     struct be_ctx *be_ctx,
d6181b
+                     struct ad_id_ctx *id_ctx,
d6181b
+                     struct dp_id_data *data)
d6181b
 {
d6181b
-    struct ad_account_info_handler_state *state;
d6181b
-    struct sdap_id_conn_ctx **clist;
d6181b
-    struct sdap_id_ctx *sdap_id_ctx;
d6181b
-    struct sss_domain_info *domain;
d6181b
+    struct sss_domain_info *domain = NULL;
d6181b
+    struct ad_account_info_state *state = NULL;
d6181b
+    struct tevent_req *req = NULL;
d6181b
+    struct tevent_req *subreq = NULL;
d6181b
+    struct sdap_id_conn_ctx **clist = NULL;
d6181b
+    struct sdap_id_ctx *sdap_id_ctx = NULL;
d6181b
     struct sdap_domain *sdom;
d6181b
-    struct tevent_req *subreq;
d6181b
-    struct tevent_req *req;
d6181b
-    struct be_ctx *be_ctx;
d6181b
     errno_t ret;
d6181b
 
d6181b
-    sdap_id_ctx = id_ctx->sdap_id_ctx;
d6181b
-    be_ctx = params->be_ctx;
d6181b
-
d6181b
     req = tevent_req_create(mem_ctx, &state,
d6181b
-                            struct ad_account_info_handler_state);
d6181b
+                            struct ad_account_info_state);
d6181b
     if (req == NULL) {
d6181b
         DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
d6181b
         return NULL;
d6181b
     }
d6181b
 
d6181b
-    if (sdap_is_enum_request(data)) {
d6181b
-        DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
d6181b
-        ret = EOK;
d6181b
-        goto immediately;
d6181b
-    }
d6181b
+    sdap_id_ctx = id_ctx->sdap_id_ctx;
d6181b
 
d6181b
     domain = be_ctx->domain;
d6181b
     if (strcasecmp(data->domain, be_ctx->domain->name) != 0) {
d6181b
@@ -406,6 +398,7 @@ ad_account_info_handler_send(TALLOC_CTX *mem_ctx,
d6181b
     }
d6181b
 
d6181b
     if (domain == NULL) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unknown domain\n");
d6181b
         ret = EINVAL;
d6181b
         goto immediately;
d6181b
     }
d6181b
@@ -413,6 +406,7 @@ ad_account_info_handler_send(TALLOC_CTX *mem_ctx,
d6181b
     /* Determine whether to connect to GC, LDAP or try both. */
d6181b
     clist = get_conn_list(state, id_ctx, domain, data);
d6181b
     if (clist == NULL) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create conn list\n");
d6181b
         ret = EIO;
d6181b
         goto immediately;
d6181b
     }
d6181b
@@ -423,14 +417,100 @@ ad_account_info_handler_send(TALLOC_CTX *mem_ctx,
d6181b
         goto immediately;
d6181b
     }
d6181b
 
d6181b
-    state->domain = sdom->dom;
d6181b
-
d6181b
     subreq = ad_handle_acct_info_send(state, data, sdap_id_ctx,
d6181b
                                       id_ctx->ad_options, sdom, clist);
d6181b
     if (subreq == NULL) {
d6181b
         ret = ENOMEM;
d6181b
         goto immediately;
d6181b
     }
d6181b
+    tevent_req_set_callback(subreq, ad_account_info_done, req);
d6181b
+    return req;
d6181b
+
d6181b
+immediately:
d6181b
+    tevent_req_error(req, ret);
d6181b
+    tevent_req_post(req, be_ctx->ev);
d6181b
+    return req;
d6181b
+}
d6181b
+
d6181b
+static void ad_account_info_done(struct tevent_req *subreq)
d6181b
+{
d6181b
+    struct ad_account_info_state *state = NULL;
d6181b
+    struct tevent_req *req = NULL;
d6181b
+    errno_t ret;
d6181b
+
d6181b
+    req = tevent_req_callback_data(subreq, struct tevent_req);
d6181b
+    state = tevent_req_data(req, struct ad_account_info_state);
d6181b
+
d6181b
+    ret = ad_handle_acct_info_recv(subreq, &state->dp_error, &state->err_msg);
d6181b
+    if (ret != EOK) {
d6181b
+        DEBUG(SSSDBG_OP_FAILURE,
d6181b
+              "ad_handle_acct_info_recv failed [%d]: %s\n",
d6181b
+              ret, sss_strerror(ret));
d6181b
+        /* The caller wouldn't fail either, just report the error up */
d6181b
+    }
d6181b
+    talloc_zfree(subreq);
d6181b
+    tevent_req_done(req);
d6181b
+}
d6181b
+
d6181b
+errno_t ad_account_info_recv(struct tevent_req *req,
d6181b
+                             int *_dp_error,
d6181b
+                             const char **_err_msg)
d6181b
+{
d6181b
+    struct ad_account_info_state *state = NULL;
d6181b
+
d6181b
+    state = tevent_req_data(req, struct ad_account_info_state);
d6181b
+
d6181b
+    if (_err_msg != NULL) {
d6181b
+        *_err_msg = state->err_msg;
d6181b
+    }
d6181b
+
d6181b
+    if (_dp_error) {
d6181b
+        *_dp_error = state->dp_error;
d6181b
+    }
d6181b
+
d6181b
+
d6181b
+    TEVENT_REQ_RETURN_ON_ERROR(req);
d6181b
+
d6181b
+    return EOK;
d6181b
+}
d6181b
+
d6181b
+struct ad_account_info_handler_state {
d6181b
+    struct sss_domain_info *domain;
d6181b
+    struct dp_reply_std reply;
d6181b
+};
d6181b
+
d6181b
+static void ad_account_info_handler_done(struct tevent_req *subreq);
d6181b
+
d6181b
+struct tevent_req *
d6181b
+ad_account_info_handler_send(TALLOC_CTX *mem_ctx,
d6181b
+                              struct ad_id_ctx *id_ctx,
d6181b
+                              struct dp_id_data *data,
d6181b
+                              struct dp_req_params *params)
d6181b
+{
d6181b
+    struct ad_account_info_handler_state *state;
d6181b
+    struct tevent_req *subreq;
d6181b
+    struct tevent_req *req;
d6181b
+    errno_t ret;
d6181b
+
d6181b
+
d6181b
+    req = tevent_req_create(mem_ctx, &state,
d6181b
+                            struct ad_account_info_handler_state);
d6181b
+    if (req == NULL) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
d6181b
+        return NULL;
d6181b
+    }
d6181b
+
d6181b
+    if (sdap_is_enum_request(data)) {
d6181b
+        DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
d6181b
+        ret = EOK;
d6181b
+        goto immediately;
d6181b
+    }
d6181b
+
d6181b
+    subreq = ad_account_info_send(state, params->be_ctx, id_ctx, data);
d6181b
+    if (subreq == NULL) {
d6181b
+        ret = ENOMEM;
d6181b
+        goto immediately;
d6181b
+    }
d6181b
 
d6181b
     tevent_req_set_callback(subreq, ad_account_info_handler_done, req);
d6181b
 
d6181b
@@ -451,13 +531,13 @@ static void ad_account_info_handler_done(struct tevent_req *subreq)
d6181b
     struct ad_account_info_handler_state *state;
d6181b
     struct tevent_req *req;
d6181b
     const char *err_msg;
d6181b
-    int dp_error;
d6181b
+    int dp_error = DP_ERR_FATAL;
d6181b
     errno_t ret;
d6181b
 
d6181b
     req = tevent_req_callback_data(subreq, struct tevent_req);
d6181b
     state = tevent_req_data(req, struct ad_account_info_handler_state);
d6181b
 
d6181b
-    ret = ad_handle_acct_info_recv(subreq, &dp_error, &err_msg);
d6181b
+    ret = ad_account_info_recv(subreq, &dp_error, &err_msg);
d6181b
     talloc_zfree(subreq);
d6181b
 
d6181b
     /* TODO For backward compatibility we always return EOK to DP now. */
d6181b
@@ -466,8 +546,8 @@ static void ad_account_info_handler_done(struct tevent_req *subreq)
d6181b
 }
d6181b
 
d6181b
 errno_t ad_account_info_handler_recv(TALLOC_CTX *mem_ctx,
d6181b
-                                      struct tevent_req *req,
d6181b
-                                      struct dp_reply_std *data)
d6181b
+                                     struct tevent_req *req,
d6181b
+                                     struct dp_reply_std *data)
d6181b
 {
d6181b
     struct ad_account_info_handler_state *state = NULL;
d6181b
 
d6181b
diff --git a/src/providers/ad/ad_id.h b/src/providers/ad/ad_id.h
d6181b
index 5154393c5..19cc54eec 100644
d6181b
--- a/src/providers/ad/ad_id.h
d6181b
+++ b/src/providers/ad/ad_id.h
d6181b
@@ -33,6 +33,16 @@ errno_t ad_account_info_handler_recv(TALLOC_CTX *mem_ctx,
d6181b
                                       struct tevent_req *req,
d6181b
                                       struct dp_reply_std *data);
d6181b
 
d6181b
+struct tevent_req *
d6181b
+ad_account_info_send(TALLOC_CTX *mem_ctx,
d6181b
+                     struct be_ctx *be_ctx,
d6181b
+                     struct ad_id_ctx *id_ctx,
d6181b
+                     struct dp_id_data *data);
d6181b
+
d6181b
+errno_t ad_account_info_recv(struct tevent_req *req,
d6181b
+                             int *_dp_error,
d6181b
+                             const char **_err_msg);
d6181b
+
d6181b
 struct tevent_req *
d6181b
 ad_handle_acct_info_send(TALLOC_CTX *mem_ctx,
d6181b
                          struct dp_id_data *ar,
d6181b
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
d6181b
index b8ebaea2f..42c17de00 100644
d6181b
--- a/src/providers/ad/ad_init.c
d6181b
+++ b/src/providers/ad/ad_init.c
d6181b
@@ -408,7 +408,7 @@ static errno_t ad_init_misc(struct be_ctx *be_ctx,
d6181b
         return ret;
d6181b
     }
d6181b
 
d6181b
-    ret = sdap_refresh_init(be_ctx, sdap_id_ctx);
d6181b
+    ret = ad_refresh_init(be_ctx, ad_id_ctx);
d6181b
     if (ret != EOK && ret != EEXIST) {
d6181b
         DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh "
d6181b
               "will not work [%d]: %s\n", ret, sss_strerror(ret));
d6181b
diff --git a/src/providers/ad/ad_refresh.c b/src/providers/ad/ad_refresh.c
d6181b
new file mode 100644
d6181b
index 000000000..ee541056f
d6181b
--- /dev/null
d6181b
+++ b/src/providers/ad/ad_refresh.c
d6181b
@@ -0,0 +1,283 @@
d6181b
+/*
d6181b
+    Copyright (C) 2019 Red Hat
d6181b
+
d6181b
+    This program is free software; you can redistribute it and/or modify
d6181b
+    it under the terms of the GNU General Public License as published by
d6181b
+    the Free Software Foundation; either version 3 of the License, or
d6181b
+    (at your option) any later version.
d6181b
+
d6181b
+    This program is distributed in the hope that it will be useful,
d6181b
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
d6181b
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d6181b
+    GNU General Public License for more details.
d6181b
+
d6181b
+    You should have received a copy of the GNU General Public License
d6181b
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
d6181b
+*/
d6181b
+
d6181b
+#include <talloc.h>
d6181b
+#include <tevent.h>
d6181b
+
d6181b
+#include "providers/ad/ad_common.h"
d6181b
+#include "providers/ad/ad_id.h"
d6181b
+
d6181b
+struct ad_refresh_state {
d6181b
+    struct tevent_context *ev;
d6181b
+    struct be_ctx *be_ctx;
d6181b
+    struct dp_id_data *account_req;
d6181b
+    struct ad_id_ctx *id_ctx;
d6181b
+    char **names;
d6181b
+    size_t index;
d6181b
+};
d6181b
+
d6181b
+static errno_t ad_refresh_step(struct tevent_req *req);
d6181b
+static void ad_refresh_done(struct tevent_req *subreq);
d6181b
+
d6181b
+static struct tevent_req *ad_refresh_send(TALLOC_CTX *mem_ctx,
d6181b
+                                            struct tevent_context *ev,
d6181b
+                                            struct be_ctx *be_ctx,
d6181b
+                                            struct sss_domain_info *domain,
d6181b
+                                            int entry_type,
d6181b
+                                            char **names,
d6181b
+                                            void *pvt)
d6181b
+{
d6181b
+    struct ad_refresh_state *state = NULL;
d6181b
+    struct tevent_req *req = NULL;
d6181b
+    errno_t ret;
d6181b
+    uint32_t filter_type;
d6181b
+
d6181b
+    req = tevent_req_create(mem_ctx, &state,
d6181b
+                            struct ad_refresh_state);
d6181b
+    if (req == NULL) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
d6181b
+        return NULL;
d6181b
+    }
d6181b
+
d6181b
+    if (names == NULL) {
d6181b
+        ret = EOK;
d6181b
+        goto immediately;
d6181b
+    }
d6181b
+
d6181b
+    state->ev = ev;
d6181b
+    state->be_ctx = be_ctx;
d6181b
+    state->id_ctx = talloc_get_type(pvt, struct ad_id_ctx);
d6181b
+    state->names = names;
d6181b
+    state->index = 0;
d6181b
+
d6181b
+    switch (entry_type) {
d6181b
+    case BE_REQ_NETGROUP:
d6181b
+        filter_type = BE_FILTER_NAME;
d6181b
+        break;
d6181b
+    case BE_REQ_USER:
d6181b
+    case BE_REQ_GROUP:
d6181b
+        filter_type = BE_FILTER_SECID;
d6181b
+        break;
d6181b
+    default:
d6181b
+        ret = EINVAL;
d6181b
+        goto immediately;
d6181b
+    }
d6181b
+
d6181b
+    state->account_req = be_refresh_acct_req(state, entry_type,
d6181b
+                                             filter_type, domain);
d6181b
+    if (state->account_req == NULL) {
d6181b
+        ret = ENOMEM;
d6181b
+        goto immediately;
d6181b
+    }
d6181b
+
d6181b
+    ret = ad_refresh_step(req);
d6181b
+    if (ret == EOK) {
d6181b
+        DEBUG(SSSDBG_TRACE_FUNC, "Nothing to refresh\n");
d6181b
+        goto immediately;
d6181b
+    } else if (ret != EAGAIN) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "ad_refresh_step() failed "
d6181b
+                                   "[%d]: %s\n", ret, sss_strerror(ret));
d6181b
+        goto immediately;
d6181b
+    }
d6181b
+
d6181b
+    return req;
d6181b
+
d6181b
+immediately:
d6181b
+    if (ret == EOK) {
d6181b
+        tevent_req_done(req);
d6181b
+    } else {
d6181b
+        tevent_req_error(req, ret);
d6181b
+    }
d6181b
+    tevent_req_post(req, ev);
d6181b
+
d6181b
+    return req;
d6181b
+}
d6181b
+
d6181b
+static errno_t ad_refresh_step(struct tevent_req *req)
d6181b
+{
d6181b
+    struct ad_refresh_state *state = NULL;
d6181b
+    struct tevent_req *subreq = NULL;
d6181b
+    errno_t ret;
d6181b
+
d6181b
+    state = tevent_req_data(req, struct ad_refresh_state);
d6181b
+
d6181b
+    if (state->names == NULL) {
d6181b
+        ret = EOK;
d6181b
+        goto done;
d6181b
+    }
d6181b
+
d6181b
+    state->account_req->filter_value = state->names[state->index];
d6181b
+    if (state->account_req->filter_value == NULL) {
d6181b
+        ret = EOK;
d6181b
+        goto done;
d6181b
+    }
d6181b
+
d6181b
+    DEBUG(SSSDBG_TRACE_FUNC, "Issuing refresh of %s %s\n",
d6181b
+          be_req2str(state->account_req->entry_type),
d6181b
+          state->account_req->filter_value);
d6181b
+
d6181b
+    subreq = ad_account_info_send(state, state->be_ctx, state->id_ctx,
d6181b
+                                  state->account_req);
d6181b
+    if (subreq == NULL) {
d6181b
+        ret = ENOMEM;
d6181b
+        goto done;
d6181b
+    }
d6181b
+
d6181b
+    tevent_req_set_callback(subreq, ad_refresh_done, req);
d6181b
+
d6181b
+    state->index++;
d6181b
+    ret = EAGAIN;
d6181b
+
d6181b
+done:
d6181b
+    return ret;
d6181b
+}
d6181b
+
d6181b
+static void ad_refresh_done(struct tevent_req *subreq)
d6181b
+{
d6181b
+    struct ad_refresh_state *state = NULL;
d6181b
+    struct tevent_req *req = NULL;
d6181b
+    const char *err_msg = NULL;
d6181b
+    errno_t dp_error;
d6181b
+    errno_t ret;
d6181b
+
d6181b
+    req = tevent_req_callback_data(subreq, struct tevent_req);
d6181b
+    state = tevent_req_data(req, struct ad_refresh_state);
d6181b
+
d6181b
+    ret = ad_account_info_recv(subreq, &dp_error, &err_msg);
d6181b
+    talloc_zfree(subreq);
d6181b
+    if (ret != EOK) {
d6181b
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to refresh %s [dp_error: %d, "
d6181b
+              "errno: %d]: %s\n", be_req2str(state->account_req->entry_type),
d6181b
+              dp_error, ret, err_msg);
d6181b
+        goto done;
d6181b
+    }
d6181b
+
d6181b
+    ret = ad_refresh_step(req);
d6181b
+    if (ret == EAGAIN) {
d6181b
+        return;
d6181b
+    }
d6181b
+
d6181b
+done:
d6181b
+    if (ret != EOK) {
d6181b
+        tevent_req_error(req, ret);
d6181b
+        return;
d6181b
+    }
d6181b
+
d6181b
+    tevent_req_done(req);
d6181b
+}
d6181b
+
d6181b
+static errno_t ad_refresh_recv(struct tevent_req *req)
d6181b
+{
d6181b
+    TEVENT_REQ_RETURN_ON_ERROR(req);
d6181b
+
d6181b
+    return EOK;
d6181b
+}
d6181b
+
d6181b
+static struct tevent_req *
d6181b
+ad_refresh_users_send(TALLOC_CTX *mem_ctx,
d6181b
+                      struct tevent_context *ev,
d6181b
+                      struct be_ctx *be_ctx,
d6181b
+                      struct sss_domain_info *domain,
d6181b
+                      char **names,
d6181b
+                      void *pvt)
d6181b
+{
d6181b
+    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
d6181b
+                           BE_REQ_USER, names, pvt);
d6181b
+}
d6181b
+
d6181b
+static errno_t ad_refresh_users_recv(struct tevent_req *req)
d6181b
+{
d6181b
+    return ad_refresh_recv(req);
d6181b
+}
d6181b
+
d6181b
+static struct tevent_req *
d6181b
+ad_refresh_groups_send(TALLOC_CTX *mem_ctx,
d6181b
+                       struct tevent_context *ev,
d6181b
+                       struct be_ctx *be_ctx,
d6181b
+                       struct sss_domain_info *domain,
d6181b
+                       char **names,
d6181b
+                       void *pvt)
d6181b
+{
d6181b
+    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
d6181b
+                           BE_REQ_GROUP, names, pvt);
d6181b
+}
d6181b
+
d6181b
+static errno_t ad_refresh_groups_recv(struct tevent_req *req)
d6181b
+{
d6181b
+    return ad_refresh_recv(req);
d6181b
+}
d6181b
+
d6181b
+static struct tevent_req *
d6181b
+ad_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
d6181b
+                          struct tevent_context *ev,
d6181b
+                          struct be_ctx *be_ctx,
d6181b
+                          struct sss_domain_info *domain,
d6181b
+                          char **names,
d6181b
+                          void *pvt)
d6181b
+{
d6181b
+    return ad_refresh_send(mem_ctx, ev, be_ctx, domain,
d6181b
+                           BE_REQ_NETGROUP, names, pvt);
d6181b
+}
d6181b
+
d6181b
+static errno_t ad_refresh_netgroups_recv(struct tevent_req *req)
d6181b
+{
d6181b
+    return ad_refresh_recv(req);
d6181b
+}
d6181b
+
d6181b
+errno_t ad_refresh_init(struct be_ctx *be_ctx,
d6181b
+                        struct ad_id_ctx *id_ctx)
d6181b
+{
d6181b
+    errno_t ret;
d6181b
+
d6181b
+    ret = be_refresh_ctx_init(be_ctx, SYSDB_SID_STR);
d6181b
+    if (ret != EOK) {
d6181b
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
d6181b
+        return ret;
d6181b
+    }
d6181b
+
d6181b
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
d6181b
+                            BE_REFRESH_TYPE_USERS,
d6181b
+                            ad_refresh_users_send,
d6181b
+                            ad_refresh_users_recv,
d6181b
+                            id_ctx);
d6181b
+    if (ret != EOK && ret != EEXIST) {
d6181b
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of users "
d6181b
+              "will not work [%d]: %s\n", ret, strerror(ret));
d6181b
+    }
d6181b
+
d6181b
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
d6181b
+                            BE_REFRESH_TYPE_GROUPS,
d6181b
+                            ad_refresh_groups_send,
d6181b
+                            ad_refresh_groups_recv,
d6181b
+                            id_ctx);
d6181b
+    if (ret != EOK && ret != EEXIST) {
d6181b
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of groups "
d6181b
+              "will not work [%d]: %s\n", ret, strerror(ret));
d6181b
+    }
d6181b
+
d6181b
+    ret = be_refresh_add_cb(be_ctx->refresh_ctx,
d6181b
+                            BE_REFRESH_TYPE_NETGROUPS,
d6181b
+                            ad_refresh_netgroups_send,
d6181b
+                            ad_refresh_netgroups_recv,
d6181b
+                            id_ctx);
d6181b
+    if (ret != EOK && ret != EEXIST) {
d6181b
+        DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of netgroups "
d6181b
+              "will not work [%d]: %s\n", ret, strerror(ret));
d6181b
+    }
d6181b
+
d6181b
+    return ret;
d6181b
+}
d6181b
-- 
d6181b
2.20.1
d6181b