Blob Blame History Raw
From f035dee4d63ebe96a8435778e4c8ce413e8c025b Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 21 May 2019 12:09:24 +0200
Subject: [PATCH 50/64] BE: Pass in attribute to look up with instead of
 hardcoding SYSDB_NAME

In later patches, we will implement refreshes for AD or IPA which might
refresh objects that do not have a name yet, but always do have a different
attribute, like a SID or a uniqueID. In this case, it's better to use that
different attribute instead of name.

This patch allows the caller to tell the refresh module which attribute
to use.

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

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

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/providers/be_refresh.c        | 12 ++++++++----
 src/providers/be_refresh.h        |  3 ++-
 src/providers/ldap/sdap_refresh.c |  2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
index c7b048a95..66cc4cf98 100644
--- a/src/providers/be_refresh.c
+++ b/src/providers/be_refresh.c
@@ -89,6 +89,7 @@ done:
 
 static errno_t be_refresh_get_values(TALLOC_CTX *mem_ctx,
                                      enum be_refresh_type type,
+                                     const char *attr_name,
                                      struct sss_domain_info *domain,
                                      time_t period,
                                      char ***_values)
@@ -116,7 +117,7 @@ static errno_t be_refresh_get_values(TALLOC_CTX *mem_ctx,
     }
 
     ret = be_refresh_get_values_ex(mem_ctx, domain, period,
-                                   base_dn, SYSDB_NAME, _values);
+                                   base_dn, attr_name, _values);
 
     talloc_free(base_dn);
     return ret;
@@ -131,10 +132,12 @@ struct be_refresh_cb {
 };
 
 struct be_refresh_ctx {
+    const char *attr_name;
     struct be_refresh_cb callbacks[BE_REFRESH_TYPE_SENTINEL];
 };
 
-struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx)
+struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx,
+                                           const char *attr_name)
 {
     struct be_refresh_ctx *ctx = NULL;
     uint32_t refresh_interval;
@@ -145,6 +148,7 @@ struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx)
         return NULL;
     }
 
+    ctx->attr_name = attr_name;
     ctx->callbacks[BE_REFRESH_TYPE_USERS].name = "users";
     ctx->callbacks[BE_REFRESH_TYPE_GROUPS].name = "groups";
     ctx->callbacks[BE_REFRESH_TYPE_NETGROUPS].name = "netgroups";
@@ -284,8 +288,8 @@ static errno_t be_refresh_step(struct tevent_req *req)
             goto done;
         }
 
-        ret = be_refresh_get_values(state, state->index, state->domain,
-                                    state->period, &values);
+        ret = be_refresh_get_values(state, state->index, state->ctx->attr_name,
+                                    state->domain, state->period, &values);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to obtain DN list [%d]: %s\n",
                                         ret, sss_strerror(ret));
diff --git a/src/providers/be_refresh.h b/src/providers/be_refresh.h
index 664f01816..8c7b1d0ba 100644
--- a/src/providers/be_refresh.h
+++ b/src/providers/be_refresh.h
@@ -52,7 +52,8 @@ enum be_refresh_type {
 
 struct be_refresh_ctx;
 
-struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx);
+struct be_refresh_ctx *be_refresh_ctx_init(struct be_ctx *be_ctx,
+                                           const char *attr_name);
 
 errno_t be_refresh_add_cb(struct be_refresh_ctx *ctx,
                           enum be_refresh_type type,
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index 457df8be2..ed04da36a 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -260,7 +260,7 @@ errno_t sdap_refresh_init(struct be_ctx *be_ctx,
 {
     errno_t ret;
 
-    be_ctx->refresh_ctx = be_refresh_ctx_init(be_ctx);
+    be_ctx->refresh_ctx = be_refresh_ctx_init(be_ctx, SYSDB_NAME);
     if (be_ctx->refresh_ctx == NULL) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
         return ENOMEM;
-- 
2.20.1