[SSSD] [PATCH] RFC2307bis initgroups: fix nested groups processing (1.6 and 1.5 backport)

Jakub Hrozek jhrozek at redhat.com
Fri Oct 28 15:08:34 UTC 2011


John Hodrien found out that due to incorrectly written loop, SSSD would go
into infinite loop if it processed the same group on two different levels
of membership.
-------------- next part --------------
>From fe860cf997a43026c8b52e845316b3a225ec2dd4 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Fri, 28 Oct 2011 17:03:03 +0200
Subject: [PATCH] RFC2307bis initgroups: fix nested groups processing

Due to incorrectly written loop, SSSD would go into infitite loop if it
processed the same group on two different levels of membership.
---
 src/providers/ldap/sdap_async_accounts.c |   53 ++++++++++++++++++-----------
 1 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/src/providers/ldap/sdap_async_accounts.c b/src/providers/ldap/sdap_async_accounts.c
index 6f1e528..e6027f8 100644
--- a/src/providers/ldap/sdap_async_accounts.c
+++ b/src/providers/ldap/sdap_async_accounts.c
@@ -5558,17 +5558,23 @@ static void rfc2307bis_nested_groups_process(struct tevent_req *subreq)
          * Move on to the next group
          */
         state->group_iter++;
-        if (state->group_iter < state->num_groups) {
-            do {
-                ret = rfc2307bis_nested_groups_step(req);
-                if (ret != EOK && ret != EAGAIN) {
-                    tevent_req_error(req, ret);
-                    return;
-                }
-            } while (ret == EOK);
+        while (state->group_iter < state->num_groups) {
+            ret = rfc2307bis_nested_groups_step(req);
+            if (ret == EAGAIN) {
+                /* Looking up parent groups.. */
+                return;
+            } else if (ret != EOK) {
+                tevent_req_error(req, ret);
+                return;
+            }
+
             /* EOK means this group has already been processed
-             * in another level */
-        } else {
+             * in another nesting level */
+            state->group_iter++;
+        }
+
+        if (state->group_iter == state->num_groups) {
+            /* All groups processed. Done. */
             tevent_req_done(req);
         }
         return;
@@ -5613,18 +5619,25 @@ static void rfc2307bis_nested_groups_done(struct tevent_req *subreq)
     }
 
     state->group_iter++;
-    if (state->group_iter < state->num_groups) {
-        do {
-            ret = rfc2307bis_nested_groups_step(req);
-            if (ret != EOK && ret != EAGAIN) {
-                tevent_req_error(req, ret);
-                return;
-            }
-        } while (ret == EOK);
+    while (state->group_iter < state->num_groups) {
+        ret = rfc2307bis_nested_groups_step(req);
+        if (ret == EAGAIN) {
+            /* Looking up parent groups.. */
+            return;
+        } else if (ret != EOK) {
+            tevent_req_error(req, ret);
+            return;
+        }
+
         /* EOK means this group has already been processed
-         * in another level */
-    } else {
+         * in another nesting level */
+        state->group_iter++;
+    }
+
+    if (state->group_iter == state->num_groups) {
+        /* All groups processed. Done. */
         tevent_req_done(req);
+        return;
     }
 }
 
-- 
1.7.6.4



More information about the sssd-devel mailing list