Blame SOURCES/0133-TOOLS-sss_mc_refresh_nested_group-short-fqname-usage.patch

b2d430
From 1a1aaf46d1ee3ae4c9346c5c492520257c7c1b42 Mon Sep 17 00:00:00 2001
b2d430
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
b2d430
Date: Wed, 7 Sep 2016 14:43:13 +0200
b2d430
Subject: [PATCH 133/135] TOOLS: sss_mc_refresh_nested_group short/fqname usage
b2d430
MIME-Version: 1.0
b2d430
Content-Type: text/plain; charset=UTF-8
b2d430
Content-Transfer-Encoding: 8bit
b2d430
b2d430
We use shortname to refresh memory cache, but in case of nested groups,
b2d430
we used internal_fqname to refresh parent groups.
b2d430
b2d430
We also wrongly used the shortname for sysdb_search operation.
b2d430
Which caused error message to be printed when sss_usermod -a or
b2d430
sss_groupmod -a where called.
b2d430
b2d430
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
b2d430
---
b2d430
 src/tools/tools_mc_util.c | 66 +++++++++++++++++++++++++++++++++--------------
b2d430
 1 file changed, 47 insertions(+), 19 deletions(-)
b2d430
b2d430
diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c
b2d430
index 2516a1981ddd965d4cae8c469ed79aaef8fa7193..716e3760f67d958f2139adbb49998d9e352d23f4 100644
b2d430
--- a/src/tools/tools_mc_util.c
b2d430
+++ b/src/tools/tools_mc_util.c
b2d430
@@ -293,62 +293,90 @@ errno_t sss_mc_refresh_group(const char *groupname)
b2d430
     return sss_mc_refresh_ent(groupname, SSS_TOOLS_GROUP);
b2d430
 }
b2d430
 
b2d430
-errno_t sss_mc_refresh_nested_group(struct tools_ctx *tctx,
b2d430
-                                    const char *name)
b2d430
+static errno_t sss_mc_refresh_nested_group(struct tools_ctx *tctx,
b2d430
+                                           const char *shortname)
b2d430
 {
b2d430
     errno_t ret;
b2d430
-    struct ldb_message *msg;
b2d430
+    struct ldb_message *msg = NULL;
b2d430
     struct ldb_message_element *el;
b2d430
     const char *attrs[] = { SYSDB_MEMBEROF,
b2d430
                             SYSDB_NAME,
b2d430
                             NULL };
b2d430
     size_t i;
b2d430
-    char *parent_name;
b2d430
+    char *parent_internal_name;
b2d430
+    char *parent_outname;
b2d430
+    char *internal_name;
b2d430
+    TALLOC_CTX *tmpctx;
b2d430
 
b2d430
-    ret = sss_mc_refresh_group(name);
b2d430
+    tmpctx = talloc_new(tctx);
b2d430
+    if (tmpctx == NULL) {
b2d430
+        return ENOMEM;
b2d430
+    }
b2d430
+
b2d430
+    internal_name = sss_create_internal_fqname(tmpctx, shortname,
b2d430
+                                               tctx->local->name);
b2d430
+    if (internal_name == NULL) {
b2d430
+        ret = ENOMEM;
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    ret = sss_mc_refresh_group(shortname);
b2d430
     if (ret != EOK) {
b2d430
         DEBUG(SSSDBG_MINOR_FAILURE,
b2d430
-              "Cannot refresh group %s from memory cache\n", name);
b2d430
+              "Cannot refresh group %s from memory cache\n", shortname);
b2d430
         /* try to carry on */
b2d430
     }
b2d430
 
b2d430
-    ret = sysdb_search_group_by_name(tctx, tctx->local, name, attrs, &msg;;
b2d430
+    ret = sysdb_search_group_by_name(tmpctx, tctx->local, internal_name, attrs,
b2d430
+                                     &msg;;
b2d430
     if (ret) {
b2d430
         DEBUG(SSSDBG_OP_FAILURE,
b2d430
                "Search failed: %s (%d)\n", strerror(ret), ret);
b2d430
-        return ret;
b2d430
+        goto done;
b2d430
     }
b2d430
 
b2d430
     el = ldb_msg_find_element(msg, SYSDB_MEMBEROF);
b2d430
     if (!el || el->num_values == 0) {
b2d430
-        DEBUG(SSSDBG_TRACE_INTERNAL, "Group %s has no parents\n", name);
b2d430
-        talloc_free(msg);
b2d430
-        return EOK;
b2d430
+        DEBUG(SSSDBG_TRACE_INTERNAL, "Group %s has no parents\n",
b2d430
+              internal_name);
b2d430
+        ret = EOK;
b2d430
+        goto done;
b2d430
     }
b2d430
 
b2d430
     /* This group is nested. We need to invalidate all its parents, too */
b2d430
     for (i=0; i < el->num_values; i++) {
b2d430
-        ret = sysdb_group_dn_name(tctx->sysdb, tctx,
b2d430
+        ret = sysdb_group_dn_name(tctx->sysdb, tmpctx,
b2d430
                                   (const char *) el->values[i].data,
b2d430
-                                  &parent_name);
b2d430
+                                  &parent_internal_name);
b2d430
         if (ret != EOK) {
b2d430
             DEBUG(SSSDBG_MINOR_FAILURE, "Malformed DN [%s]? Skipping\n",
b2d430
                   (const char *) el->values[i].data);
b2d430
-            talloc_free(parent_name);
b2d430
+            talloc_free(parent_internal_name);
b2d430
             continue;
b2d430
         }
b2d430
 
b2d430
-        ret = sss_mc_refresh_group(parent_name);
b2d430
-        talloc_free(parent_name);
b2d430
+        parent_outname = sss_output_name(tmpctx, parent_internal_name,
b2d430
+                                         tctx->local->case_preserve, 0);
b2d430
+        if (parent_outname == NULL) {
b2d430
+            ret = ENOMEM;
b2d430
+            goto done;
b2d430
+        }
b2d430
+
b2d430
+        ret = sss_mc_refresh_group(parent_outname);
b2d430
+        talloc_free(parent_internal_name);
b2d430
+        talloc_free(parent_outname);
b2d430
         if (ret != EOK) {
b2d430
             DEBUG(SSSDBG_MINOR_FAILURE,
b2d430
-                  "Cannot refresh group %s from memory cache\n", name);
b2d430
+                  "Cannot refresh group %s from memory cache\n", parent_outname);
b2d430
             /* try to carry on */
b2d430
         }
b2d430
     }
b2d430
 
b2d430
-    talloc_free(msg);
b2d430
-    return EOK;
b2d430
+    ret = EOK;
b2d430
+
b2d430
+done:
b2d430
+    talloc_free(tmpctx);
b2d430
+    return ret;
b2d430
 }
b2d430
 
b2d430
 errno_t sss_mc_refresh_grouplist(struct tools_ctx *tctx,
b2d430
-- 
b2d430
2.7.4
b2d430